Skip to content

Wrong error message: SyntaxError: Cannot read property 'type' of undefined (0:0) #9226

@ups-ishii

Description

@ups-ishii

Environments:

  • Prettier Version: 2.1.2
  • Running Prettier via: CLI
  • Runtime: Node.js v12.16.1
  • Operating System: macOS

Steps to reproduce:

cat <<_EOF > sample.js
const p = {
  set name(){}
};
_EOF
npx prettier@2.1.2 sample.js

Expected behavior:

SyntaxError: setter must have exactly one formal parameter (2:3) is expected.

  • npx prettier@1.18.2 sample.js
sample.js[error] sample.js: SyntaxError: setter must have exactly one formal parameter (2:3)
[error]   1 | const p = {
[error] > 2 |   set name(){}
[error]     |   ^
[error]   3 | };
[error]   4 |

Actual behavior:

  • npx prettier@2.1.2 sample.js
sample.js[error] sample.js: SyntaxError: Cannot read property 'type' of undefined (0:0)
[error]   1 | const p = {
[error]   2 |   set name(){}
[error]   3 | };

FYI
It looks babel/parser throws right error but Prettier fails to parse the babel/parser error. may be.

  • npx @babel/parser sample.js
setter must have exactly one formal parameter (2:2)

Thank you

Metadata

Metadata

Assignees

Labels

lang:javascriptIssues affecting JSlocked-due-to-inactivityPlease open a new issue and fill out the template instead of commenting.scope:dependencyIssues that cannot be solved inside Prettier itself, and must be fixed in a dependency

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions