question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Bug: Method on numbers are not wrapped: `(1.2).toString()` becomes `1.2..toString()`

See original GitHub issue

The following code:

(1.2).toString()

Should remain as-is, or be converted to 1.2.toString(), but instead is converted to the following:

1.2..toString();

Specifically, there is an extra period after the decimal number

Here is an AST representing this case:

{
  "type": "ExpressionStatement",
  "expression": {
	"type": "CallExpression",
	"callee": {
	  "type": "MemberExpression",
	  "object": {
		"type": "Literal",
		"value": 1.2,
		"raw": "1.2"
	  },
	  "property": {
		"type": "Identifier",
		"name": "toString"
	  },
	  "computed": false
	},
	"arguments": []
  }
}

You can try it out on the escodegen demo website

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
agarand-godaddycommented, Jul 26, 2019

Yea, I was trying it out on the demo website, which is still on version 0.0.16-dev for some reason

It does work as expected on the adequate version, my bad!

1reaction
papandreoucommented, Jul 26, 2019

The raw and extra values attached to the nodes are just extra information about the lexical tokens of the original souce. They don’t affect the semantics of the ast. I’m not the maintainer of this project, but I’m fairly sure that it’s a non-goal to do a perfect round-trip.

Read more comments on GitHub >

github_iconTop Results From Across the Web

What happened inside of (1).toString() and ...
() is grouping operator, which returns the value of the expression inside it. Here in your case, it's 1 , a primitive number....
Read more >
Numbers
If we want to call a method directly on a number, like toString in the ... We can convert it to a number...
Read more >
Number.prototype.toString() - JavaScript - MDN Web Docs
The toString() method returns a string representing the specified number value.
Read more >
Object - OOUI - Documentation
Returns a string representation of the object. ... You can create a function to be called in place of the default toString() method....
Read more >
10.1. Preventing Cross Site Scripting Vulnerabilities
Use the HtmlUtils.HTML() function to wrap any string that is already HTML and must not be HTML-escaped. The function HtmlUtils.interpolateHtml() ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found