Skip to content

Commit

Permalink
review
Browse files Browse the repository at this point in the history
  • Loading branch information
liuxingbaoyu committed Jan 9, 2024
1 parent c336a27 commit 985dc49
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 17 deletions.
18 changes: 7 additions & 11 deletions packages/babel-parser/src/tokenizer/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,33 +283,29 @@ export default class State {
return new Position(this.curLine, this.pos - this.lineStart, this.pos);
}

clone(skipArrays?: boolean): State {
function maybeCopy(val: any[]) {
return skipArrays ? val : val.slice();
}

clone(): State {
const state = new State();
state.flags = this.flags;
state.curLine = this.curLine;
state.lineStart = this.lineStart;
state.startLoc = this.startLoc;
state.endLoc = this.endLoc;
state.errors = maybeCopy(this.errors);
state.errors = this.errors.slice();
state.potentialArrowAt = this.potentialArrowAt;
state.noArrowAt = maybeCopy(this.noArrowAt);
state.noArrowParamsConversionAt = maybeCopy(this.noArrowParamsConversionAt);
state.noArrowAt = this.noArrowAt.slice();
state.noArrowParamsConversionAt = this.noArrowParamsConversionAt.slice();
state.topicContext = this.topicContext;
state.labels = maybeCopy(this.labels);
state.labels = this.labels.slice();
state.commentsLen = this.commentsLen;
state.commentStack = maybeCopy(this.commentStack);
state.commentStack = this.commentStack.slice();
state.pos = this.pos;
state.type = this.type;
state.value = this.value;
state.start = this.start;
state.end = this.end;
state.lastTokEndLoc = this.lastTokEndLoc;
state.lastTokStartLoc = this.lastTokStartLoc;
state.context = maybeCopy(this.context);
state.context = this.context.slice();
state.firstInvalidTemplateEscapePos = this.firstInvalidTemplateEscapePos;
state.strictErrors = this.strictErrors;
state.tokensLength = this.tokensLength;
Expand Down
7 changes: 1 addition & 6 deletions packages/babel-parser/src/util/scope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,12 +194,7 @@ export default class ScopeHandler<IScope extends Scope = Scope> {
checkLocalExport(id: N.Identifier) {
const { name } = id;
const topLevelScope = this.scopeStack[0];
if (
!topLevelScope.names.has(name)
// In strict mode, scope.functions will always be empty.
// Modules are strict by default, but the `scriptMode` option
// can overwrite this behavior.
) {
if (!topLevelScope.names.has(name)) {
this.undefinedExports.set(name, id.loc.start);
}
}
Expand Down

0 comments on commit 985dc49

Please sign in to comment.