Skip to content

Commit

Permalink
refactor: avoid duplicate property access
Browse files Browse the repository at this point in the history
  • Loading branch information
JLHwung committed Nov 15, 2021
1 parent 29bcb4d commit d66ce16
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions packages/babel-parser/src/util/class-scope.js
Expand Up @@ -61,11 +61,12 @@ export default class ClassScopeHandler {
elementType: ClassElementTypes,
pos: number,
) {
const classScope = this.current();
let redefined = classScope.privateNames.has(name);
const { privateNames, loneAccessors, undefinedPrivateNames } =
this.current();
let redefined = privateNames.has(name);

if (elementType & CLASS_ELEMENT_KIND_ACCESSOR) {
const accessor = redefined && classScope.loneAccessors.get(name);
const accessor = redefined && loneAccessors.get(name);
if (accessor) {
const oldStatic = accessor & CLASS_ELEMENT_FLAG_STATIC;
const newStatic = elementType & CLASS_ELEMENT_FLAG_STATIC;
Expand All @@ -78,18 +79,18 @@ export default class ClassScopeHandler {
// they have the same placement (static or not).
redefined = oldKind === newKind || oldStatic !== newStatic;

if (!redefined) classScope.loneAccessors.delete(name);
if (!redefined) loneAccessors.delete(name);
} else if (!redefined) {
classScope.loneAccessors.set(name, elementType);
loneAccessors.set(name, elementType);
}
}

if (redefined) {
this.raise(pos, Errors.PrivateNameRedeclaration, name);
}

classScope.privateNames.add(name);
classScope.undefinedPrivateNames.delete(name);
privateNames.add(name);
undefinedPrivateNames.delete(name);
}

usePrivateName(name: string, pos: number) {
Expand Down

0 comments on commit d66ce16

Please sign in to comment.