Skip to content

Commit e039135

Browse files
fix: logic for cache
1 parent 1763c7d commit e039135

File tree

5 files changed

+29
-25
lines changed

5 files changed

+29
-25
lines changed

lib/ExternalModule.js

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ const { JAVASCRIPT_MODULE_TYPE_DYNAMIC } = require("./ModuleTypeConstants");
1515
const RuntimeGlobals = require("./RuntimeGlobals");
1616
const Template = require("./Template");
1717
const StaticExportsDependency = require("./dependencies/StaticExportsDependency");
18-
const { IS_LEGACY_IMPORT_ASSERTION } = require("./javascript/JavascriptParser");
1918
const createHash = require("./util/createHash");
2019
const extractUrlAndGlobal = require("./util/extractUrlAndGlobal");
2120
const makeSerializable = require("./util/makeSerializable");
@@ -172,8 +171,11 @@ const getSourceForImportExternal = (
172171
}
173172
const attributes =
174173
dependencyMeta && dependencyMeta.attributes
175-
? dependencyMeta.attributes[IS_LEGACY_IMPORT_ASSERTION]
176-
? `, { assert: ${JSON.stringify(dependencyMeta.attributes)} }`
174+
? dependencyMeta.attributes._isLegacyAssert
175+
? `, { assert: ${JSON.stringify(
176+
dependencyMeta.attributes,
177+
importAssertionReplacer
178+
)} }`
177179
: `, { with: ${JSON.stringify(dependencyMeta.attributes)} }`
178180
: "";
179181
if (!Array.isArray(moduleAndSpecifiers)) {
@@ -201,6 +203,19 @@ const getSourceForImportExternal = (
201203
};
202204
};
203205

206+
/**
207+
* @param {string} key key
208+
* @param {any | undefined} value value
209+
* @returns {undefined | string} replaced value
210+
*/
211+
const importAssertionReplacer = (key, value) => {
212+
if (key === "_isLegacyAssert") {
213+
return undefined;
214+
}
215+
216+
return value;
217+
};
218+
204219
/**
205220
* @extends {InitFragment<ChunkRenderContext>}
206221
*/
@@ -225,8 +240,11 @@ class ModuleExternalInitFragment extends InitFragment {
225240
super(
226241
`import * as ${identifier} from ${JSON.stringify(request)}${
227242
dependencyMeta && dependencyMeta.attributes
228-
? dependencyMeta.attributes[IS_LEGACY_IMPORT_ASSERTION]
229-
? ` assert ${JSON.stringify(dependencyMeta.attributes)}`
243+
? dependencyMeta.attributes._isLegacyAssert
244+
? ` assert ${JSON.stringify(
245+
dependencyMeta.attributes,
246+
importAssertionReplacer
247+
)}`
230248
: ` with ${JSON.stringify(dependencyMeta.attributes)}`
231249
: ""
232250
};\n`,

lib/NormalModuleFactory.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ const ModuleFactory = require("./ModuleFactory");
2020
const ModuleGraph = require("./ModuleGraph");
2121
const { JAVASCRIPT_MODULE_TYPE_AUTO } = require("./ModuleTypeConstants");
2222
const NormalModule = require("./NormalModule");
23-
const { IS_LEGACY_IMPORT_ASSERTION } = require("./javascript/JavascriptParser");
2423
const BasicEffectRulePlugin = require("./rules/BasicEffectRulePlugin");
2524
const BasicMatcherRulePlugin = require("./rules/BasicMatcherRulePlugin");
2625
const ObjectMatcherRulePlugin = require("./rules/ObjectMatcherRulePlugin");
@@ -231,12 +230,12 @@ const ruleSetCompiler = new RuleSetCompiler([
231230
new ObjectMatcherRulePlugin(
232231
"assert",
233232
"assertions",
234-
value => value[IS_LEGACY_IMPORT_ASSERTION]
233+
value => value && /** @type {any} */ (value)._isLegacyAssert !== undefined
235234
),
236235
new ObjectMatcherRulePlugin(
237236
"with",
238237
"assertions",
239-
value => !value[IS_LEGACY_IMPORT_ASSERTION]
238+
value => value && !(/** @type {any} */ (value)._isLegacyAssert)
240239
),
241240
new ObjectMatcherRulePlugin("descriptionData"),
242241
new BasicEffectRulePlugin("type"),

lib/dependencies/HarmonyImportDependencyParserPlugin.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@
66
"use strict";
77

88
const HotModuleReplacementPlugin = require("../HotModuleReplacementPlugin");
9-
const {
10-
IS_LEGACY_IMPORT_ASSERTION
11-
} = require("../javascript/JavascriptParser");
129
const InnerGraph = require("../optimize/InnerGraph");
1310
const ConstDependency = require("./ConstDependency");
1411
const HarmonyAcceptDependency = require("./HarmonyAcceptDependency");
@@ -87,7 +84,7 @@ function getAttributes(node) {
8784
? node.arguments[0].properties[0].key.name
8885
: /** @type {Literal} */ (node.arguments[0].properties[0].key).value;
8986
if (key === "assert") {
90-
result[IS_LEGACY_IMPORT_ASSERTION] = true;
87+
result._isLegacyAssert = true;
9188
}
9289
return result;
9390
}
@@ -113,7 +110,7 @@ function getAttributes(node) {
113110
result[key] = /** @type {string} */ (attribute.value.value);
114111
}
115112
if (isImportAssertion) {
116-
result[IS_LEGACY_IMPORT_ASSERTION] = true;
113+
result._isLegacyAssert = true;
117114
}
118115
return result;
119116
}

lib/javascript/JavascriptParser.js

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,7 @@ const BasicEvaluatedExpression = require("./BasicEvaluatedExpression");
9999
/** @typedef {Statement | ModuleDeclaration | Expression} StatementPathItem */
100100
/** @typedef {TODO} OnIdent */
101101

102-
/**
103-
* Import attributes using legacy `assert` keyword
104-
*/
105-
const IS_LEGACY_IMPORT_ASSERTION = Symbol("is legacy import assertion");
106-
107-
/** @typedef {Record<string, string> & Partial<Record<IS_LEGACY_IMPORT_ASSERTION, boolean>>} ImportAttributes */
102+
/** @typedef {Record<string, string> & { _isLegacyAssert?: boolean }} ImportAttributes */
108103

109104
/** @type {string[]} */
110105
const EMPTY_ARRAY = [];
@@ -4809,5 +4804,3 @@ module.exports.ALLOWED_MEMBER_TYPES_EXPRESSION =
48094804
ALLOWED_MEMBER_TYPES_EXPRESSION;
48104805
module.exports.ALLOWED_MEMBER_TYPES_CALL_EXPRESSION =
48114806
ALLOWED_MEMBER_TYPES_CALL_EXPRESSION;
4812-
module.exports.IS_LEGACY_IMPORT_ASSERTION =
4813-
/** @type {typeof IS_LEGACY_IMPORT_ASSERTION} */ (IS_LEGACY_IMPORT_ASSERTION);

types.d.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5250,7 +5250,6 @@ type IBigIntStats = IStatsBase<bigint> & {
52505250
ctimeNs: bigint;
52515251
birthtimeNs: bigint;
52525252
};
5253-
declare const IS_LEGACY_IMPORT_ASSERTION: unique symbol;
52545253
declare interface IStats {
52555254
isFile: () => boolean;
52565255
isDirectory: () => boolean;
@@ -5337,8 +5336,7 @@ type IgnorePluginOptions =
53375336
*/
53385337
checkResource: (resource: string, context: string) => boolean;
53395338
};
5340-
type ImportAttributes = Record<string, string> &
5341-
Partial<Record<typeof IS_LEGACY_IMPORT_ASSERTION, boolean>>;
5339+
type ImportAttributes = Record<string, string> & {};
53425340
declare interface ImportDependencyMeta {
53435341
attributes?: ImportAttributes;
53445342
}
@@ -6521,7 +6519,6 @@ declare class JavascriptParser extends Parser {
65216519
static ALLOWED_MEMBER_TYPES_ALL: 3;
65226520
static ALLOWED_MEMBER_TYPES_EXPRESSION: 2;
65236521
static ALLOWED_MEMBER_TYPES_CALL_EXPRESSION: 1;
6524-
static IS_LEGACY_IMPORT_ASSERTION: typeof IS_LEGACY_IMPORT_ASSERTION;
65256522
}
65266523

65276524
/**

0 commit comments

Comments
 (0)