Bug: Method on numbers are not wrapped: `(1.2).toString()` becomes `1.2..toString()`
See original GitHub issueThe 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:
- Created 4 years ago
- Comments:6 (3 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Yea, I was trying it out on the demo website, which is still on version
0.0.16-dev
for some reasonIt does work as expected on the adequate version, my bad!
The
raw
andextra
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.