Skip to content

Commit

Permalink
refactor: avoid uncessary property access
Browse files Browse the repository at this point in the history
  • Loading branch information
JLHwung committed Aug 5, 2020
1 parent bc7a811 commit 41e859d
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions packages/babel-parser/src/parser/expression.js
Expand Up @@ -1737,27 +1737,28 @@ export default class ExpressionParser extends LValParser {
}

const containsEsc = this.state.containsEsc;
this.parsePropertyName(prop, /* isPrivateNameAllowed */ false);
const key = this.parsePropertyName(prop, /* isPrivateNameAllowed */ false);

if (
!isPattern &&
!isGenerator &&
!containsEsc &&
this.maybeAsyncOrAccessorProp(prop)
) {
const keyName = key.name;
// https://tc39.es/ecma262/#prod-AsyncMethod
// https://tc39.es/ecma262/#prod-AsyncGeneratorMethod
if (prop.key.name === "async" && !this.hasPrecedingLineBreak()) {
if (keyName === "async" && !this.hasPrecedingLineBreak()) {
isAsync = true;
isGenerator = this.eat(tt.star);
this.parsePropertyName(prop, /* isPrivateNameAllowed */ false);
}
// get PropertyName[?Yield, ?Await] () { FunctionBody[~Yield, ~Await] }
// set PropertyName[?Yield, ?Await] ( PropertySetParameterList ) { FunctionBody[~Yield, ~Await] }
else if (prop.key.name === "get" || prop.key.name === "set") {
else if (keyName === "get" || keyName === "set") {
isAccessor = true;
isGenerator = this.eat(tt.star); // tt.star is allowed in `maybeAsyncOrAccessorProp`, we will throw in `parseObjectMethod` later
prop.kind = prop.key.name;
prop.kind = keyName;
this.parsePropertyName(prop, /* isPrivateNameAllowed */ false);
}
}
Expand Down

0 comments on commit 41e859d

Please sign in to comment.