From 50b3262063147523ca2f84dcac6ac525433c08be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Wed, 5 Aug 2020 15:39:45 -0400 Subject: [PATCH] refactor: avoid unnecessary property access (#11918) * refactor: avoid unnecessary property access * refactor: `else` is redundant because keyName is const --- packages/babel-parser/src/parser/expression.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/packages/babel-parser/src/parser/expression.js b/packages/babel-parser/src/parser/expression.js index 820620eb83..18353b957e 100644 --- a/packages/babel-parser/src/parser/expression.js +++ b/packages/babel-parser/src/parser/expression.js @@ -1737,7 +1737,7 @@ 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 && @@ -1745,19 +1745,20 @@ export default class ExpressionParser extends LValParser { !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") { + 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); } }