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.

[MemberExpression] Brackets are required when calling a method on a number

See original GitHub issue

Really excited about Prettier! I just ran it against our codebase here at Geckoboard and discovered a few edge case bugs. I’ll open issues for each of the bugs that I can generate a small repro case for.

You can call methods on a number using the following syntax:

(0).toLocaleString();

Prettier currently converts this to:

0.toLocaleString();

Which gives the following syntax error when run in Chrome:

Uncaught SyntaxError: Invalid or unexpected token

I would have expected the output to be:

(0).toLocaleString();

https://vjeux.github.io/prettier-browser/#{"content"%3A"(0).toLocaleString()%3B"%2C"options"%3A{"printWidth"%3A80%2C"tabWidth"%3A2%2C"useFlowParser"%3Afalse%2C"singleQuote"%3Afalse%2C"trailingComma"%3Afalse%2C"bracketSpacing"%3Afalse}}

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
vjeuxcommented, Jan 19, 2017

This is now fixed in 0.0.9

0reactions
vjeuxcommented, Jan 14, 2017

needsParens is not being called for the binary expression. I think that it’s because printMemberChain somehow skips it but I don’t understand enough of how it works to be sure.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Can a MemberExpression return a Method - Stack Overflow
I've tried using this with something like: var myClassObject = new MyClass(); Run(myClassObject, o => o.ReturnSomething, new object[ ...
Read more >
calling a method with parenthesis vs. no ... - Codecademy
So I keep running into this problem where I will call a method without parenthesis ... as a sort of mini-programme by virtue...
Read more >
Expressions — The Swift Programming Language (Swift 5.7)
Postfix expressions, like prefix and infix expressions, let you build up more complex expressions using postfixes such as function calls and member access....
Read more >
Tips & Tricks for Writing CUBEVALUE Formulas - Excel Campus
I call this the ice cube method because the CUBEVALUE formulas tend to be smooth ... For example, the following formula references the...
Read more >
ECMAScript Spec: 11. Expressions - Interglacial
The elements need not be literals; they are evaluated each time the array ... Call the [[Put]] method of Result(1) with arguments "length"...
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