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.

Member expression on number literal generates wrong output

See original GitHub issue
require("escodegen").generate({
            "type": "ExpressionStatement",
            "expression": {
                "type": "MemberExpression",
                "computed": false,
                "object": {
                    "type": "Literal",
                    "value": 4,
                    "raw": "4"
                },
                "property": {
                    "type": "Identifier",
                    "name": "foo"
                }
            }
        })
// => '4..foo;'

While it should output:

(4).foo;

Issue Analytics

  • State:closed
  • Created 10 years ago
  • Comments:10 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
michaelficarracommented, Jul 20, 2017

Ah, I think I see what you mean. Thanks, @dannycochran. The fix here would be to compile to

4 .foo;
0reactions
michaelficarracommented, Jul 22, 2017

@dannycochran I disagree. Those should be identical in an AST. The fact that they’re not due to raw on Literal is the problem.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Calling member function of number literal - javascript
I get the expected result "23.00" but when I try 23.toFixed(2) I get this error. SyntaxError: Invalid or unexpected token. Why do I ......
Read more >
Restrict template literal interpolation expressions to strings
When using string literals, any variables are coerced to strings, which can lead to undesirable behavior. As far as I can tell there's...
Read more >
User-defined literals (since C++11) - cppreference.com
Allows integer, floating-point, character, and string literals to produce objects of user-defined type by defining a user-defined suffix.
Read more >
Constant and Literal Data Types - Visual Basic - Microsoft Learn
A literal is a value that is expressed as itself rather than as a variable's ... The error results from the representation of...
Read more >
Scheme - Expressions
As noted in section Storage model, it is an error to alter a constant (i.e. the value of a literal expression) using a...
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