Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: do not eat get/set after async is parsed #11916

Merged
merged 1 commit into from Aug 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/babel-parser/src/parser/expression.js
Expand Up @@ -1754,7 +1754,7 @@ export default class ExpressionParser extends LValParser {
}
// get PropertyName[?Yield, ?Await] () { FunctionBody[~Yield, ~Await] }
// set PropertyName[?Yield, ?Await] ( PropertySetParameterList ) { FunctionBody[~Yield, ~Await] }
if (prop.key.name === "get" || prop.key.name === "set") {
else if (prop.key.name === "get" || prop.key.name === "set") {
isAccessor = true;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are 4 unnecessary member access. 2 unnecessary function call here that slow down on performance. Also 2x string comparison. No plans to optimize it?

Copy link
Contributor Author

@JLHwung JLHwung Aug 5, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Will address in another PR: #11918.

isGenerator = this.eat(tt.star); // tt.star is allowed in `maybeAsyncOrAccessorProp`, we will throw in `parseObjectMethod` later
prop.kind = prop.key.name;
Expand Down
@@ -0,0 +1,4 @@
({
async get() {},
async set() {}
})
@@ -0,0 +1,71 @@
{
"type": "File",
"start":0,"end":40,"loc":{"start":{"line":1,"column":0},"end":{"line":4,"column":2}},
"program": {
"type": "Program",
"start":0,"end":40,"loc":{"start":{"line":1,"column":0},"end":{"line":4,"column":2}},
"sourceType": "script",
"interpreter": null,
"body": [
{
"type": "ExpressionStatement",
"start":0,"end":40,"loc":{"start":{"line":1,"column":0},"end":{"line":4,"column":2}},
"expression": {
"type": "ObjectExpression",
"start":1,"end":39,"loc":{"start":{"line":1,"column":1},"end":{"line":4,"column":1}},
"properties": [
{
"type": "ObjectMethod",
"start":5,"end":19,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":16}},
"method": true,
"key": {
"type": "Identifier",
"start":11,"end":14,"loc":{"start":{"line":2,"column":8},"end":{"line":2,"column":11},"identifierName":"get"},
"name": "get"
},
"computed": false,
"kind": "method",
"id": null,
"generator": false,
"async": true,
"params": [],
"body": {
"type": "BlockStatement",
"start":17,"end":19,"loc":{"start":{"line":2,"column":14},"end":{"line":2,"column":16}},
"body": [],
"directives": []
}
},
{
"type": "ObjectMethod",
"start":23,"end":37,"loc":{"start":{"line":3,"column":2},"end":{"line":3,"column":16}},
"method": true,
"key": {
"type": "Identifier",
"start":29,"end":32,"loc":{"start":{"line":3,"column":8},"end":{"line":3,"column":11},"identifierName":"set"},
"name": "set"
},
"computed": false,
"kind": "method",
"id": null,
"generator": false,
"async": true,
"params": [],
"body": {
"type": "BlockStatement",
"start":35,"end":37,"loc":{"start":{"line":3,"column":14},"end":{"line":3,"column":16}},
"body": [],
"directives": []
}
}
],
"extra": {
"parenthesized": true,
"parenStart": 0
}
}
}
],
"directives": []
}
}