Skip to content

Commit

Permalink
fix scope
Browse files Browse the repository at this point in the history
  • Loading branch information
vankop committed Apr 10, 2024
1 parent c20e8a4 commit 9f6087f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 22 deletions.
26 changes: 12 additions & 14 deletions lib/dependencies/HarmonyImportDependencyParserPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const HarmonyImportSpecifierDependency = require("./HarmonyImportSpecifierDepend
/** @typedef {import("../javascript/BasicEvaluatedExpression")} BasicEvaluatedExpression */
/** @typedef {import("../javascript/JavascriptParser")} JavascriptParser */
/** @typedef {import("../javascript/JavascriptParser").Range} Range */
/** @typedef {import("../javascript/JavascriptParser").VariableInfoInterface} VariableInfoInterface */
/** @typedef {import("../optimize/InnerGraph").InnerGraph} InnerGraph */
/** @typedef {import("../optimize/InnerGraph").TopLevelSymbol} TopLevelSymbol */
/** @typedef {import("./HarmonyImportDependency")} HarmonyImportDependency */
Expand All @@ -47,6 +48,15 @@ const harmonySpecifierTag = Symbol("harmony import");
* @property {Record<string, any> | undefined} assertions
*/

/**
* @param {string|VariableInfoInterface|undefined} info rootInfo
* @returns {boolean} is harmonySpecifierTag
*/
function isHarmonySpecifierTag(info) {
if (!info || typeof info === "string") return false;
return info.tagInfo.tag === harmonySpecifierTag;
}

/**
* @param {ImportDeclaration | ExportNamedDeclaration | ExportAllDeclaration | (ImportExpression & { arguments?: ObjectExpression[] })} node node with assertions
* @returns {Record<string, any> | undefined} assertions
Expand Down Expand Up @@ -282,13 +292,7 @@ module.exports = class HarmonyImportDependencyParserPlugin {
if (!leftPartEvaluated) {
return;
} else if (leftPartEvaluated.isIdentifier()) {
const rootInfo = leftPartEvaluated.rootInfo;
if (
!rootInfo ||
!rootInfo.tagInfo ||
rootInfo.tagInfo.tag !== harmonySpecifierTag
)
return;
if (!isHarmonySpecifierTag(leftPartEvaluated.rootInfo)) return;
identifierEvaluated = leftPartEvaluated;
} else if (leftPartEvaluated.isFalsy() !== true) {
return;
Expand All @@ -303,13 +307,7 @@ module.exports = class HarmonyImportDependencyParserPlugin {
!identifierEvaluated &&
rightPartEvaluated.isIdentifier()
) {
const rootInfo = rightPartEvaluated.rootInfo;
if (
!rootInfo ||
!rootInfo.tagInfo ||
rootInfo.tagInfo.tag !== harmonySpecifierTag
)
return;
if (!isHarmonySpecifierTag(rightPartEvaluated.rootInfo)) return;
identifierEvaluated = rightPartEvaluated;
} else if (rightPartEvaluated.isFalsy() !== true) {
return;
Expand Down
4 changes: 3 additions & 1 deletion lib/javascript/JavascriptParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -3883,11 +3883,13 @@ class JavascriptParser extends Parser {
this.scope = {
topLevelScope: oldScope.topLevelScope,
inTry: false,
inGuardPosition: false,
inShorthand: false,
inTaggedTemplateTag: false,
isStrict: oldScope.isStrict,
isAsmJs: oldScope.isAsmJs,
definitions: oldScope.definitions.createChild()
definitions: oldScope.definitions.createChild(),
guards: oldScope.guards.createChild()
};

if (hasThis) {
Expand Down
13 changes: 6 additions & 7 deletions types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12930,7 +12930,6 @@ declare interface ScopeInfo {
inTry: boolean;
isStrict: boolean;
isAsmJs: boolean;
inTry: boolean;
inGuardPosition: boolean;
}
declare interface Selector<A, B> {
Expand Down Expand Up @@ -14791,6 +14790,12 @@ type WriteFileOptions =
declare interface WriteOnlySet<T> {
add: (item: T) => void;
}
declare abstract class WriteOnlyStackedSet<T> {
add(el: T): void;
has(el: T): boolean;
clear(): void;
createChild(): WriteOnlyStackedSet<any>;
}

declare interface WriteStreamOptions {
flags?: string;
Expand All @@ -14815,12 +14820,6 @@ declare interface WriteStreamOptions {
signal?: null | AbortSignal;
fs?: null | CreateWriteStreamFSImplementation;
}
declare abstract class WriteOnlyStackedSet<T> {
add(el: T): void;
has(el: T): boolean;
clear(): void;
createChild(): WriteOnlyStackedSet<any>;
}
type __TypeWebpackOptions = (data: object) =>
| string
| {
Expand Down

0 comments on commit 9f6087f

Please sign in to comment.