@atlaspack/transformer-js 3.2.3-canary.49 → 3.2.3-canary.491
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/JSTransformer.js +377 -87
- package/lib/types/JSTransformer.d.ts +14 -0
- package/package.json +17 -14
- package/src/{JSTransformer.js → JSTransformer.ts} +581 -185
package/lib/JSTransformer.js
CHANGED
|
@@ -4,8 +4,17 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
+
exports.loadCompiledCssInJsConfig = loadCompiledCssInJsConfig;
|
|
8
|
+
exports.loadTokensConfig = loadTokensConfig;
|
|
9
|
+
function _buildCache() {
|
|
10
|
+
const data = require("@atlaspack/build-cache");
|
|
11
|
+
_buildCache = function () {
|
|
12
|
+
return data;
|
|
13
|
+
};
|
|
14
|
+
return data;
|
|
15
|
+
}
|
|
7
16
|
function _sourceMap() {
|
|
8
|
-
const data = _interopRequireDefault(require("@
|
|
17
|
+
const data = _interopRequireDefault(require("@atlaspack/source-map"));
|
|
9
18
|
_sourceMap = function () {
|
|
10
19
|
return data;
|
|
11
20
|
};
|
|
@@ -25,6 +34,13 @@ function _rust() {
|
|
|
25
34
|
};
|
|
26
35
|
return data;
|
|
27
36
|
}
|
|
37
|
+
function _assert() {
|
|
38
|
+
const data = _interopRequireDefault(require("assert"));
|
|
39
|
+
_assert = function () {
|
|
40
|
+
return data;
|
|
41
|
+
};
|
|
42
|
+
return data;
|
|
43
|
+
}
|
|
28
44
|
function _browserslist() {
|
|
29
45
|
const data = _interopRequireDefault(require("browserslist"));
|
|
30
46
|
_browserslist = function () {
|
|
@@ -68,9 +84,15 @@ function _featureFlags() {
|
|
|
68
84
|
};
|
|
69
85
|
return data;
|
|
70
86
|
}
|
|
71
|
-
function
|
|
72
|
-
|
|
73
|
-
function
|
|
87
|
+
function _path() {
|
|
88
|
+
const data = _interopRequireWildcard(require("path"));
|
|
89
|
+
_path = function () {
|
|
90
|
+
return data;
|
|
91
|
+
};
|
|
92
|
+
return data;
|
|
93
|
+
}
|
|
94
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
95
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
74
96
|
const JSX_EXTENSIONS = {
|
|
75
97
|
jsx: true,
|
|
76
98
|
tsx: true
|
|
@@ -130,15 +152,25 @@ const CONFIG_SCHEMA = {
|
|
|
130
152
|
}
|
|
131
153
|
}]
|
|
132
154
|
},
|
|
155
|
+
addReactDisplayName: {
|
|
156
|
+
type: 'boolean'
|
|
157
|
+
},
|
|
133
158
|
magicComments: {
|
|
134
159
|
type: 'boolean'
|
|
135
160
|
},
|
|
136
161
|
unstable_inlineConstants: {
|
|
137
162
|
type: 'boolean'
|
|
163
|
+
},
|
|
164
|
+
jsx: {
|
|
165
|
+
type: 'object'
|
|
138
166
|
}
|
|
139
167
|
},
|
|
140
168
|
additionalProperties: false
|
|
141
169
|
};
|
|
170
|
+
|
|
171
|
+
// Mirrors the CONFIG_SCHEMA
|
|
172
|
+
|
|
173
|
+
const configCache = (0, _buildCache().createBuildCache)();
|
|
142
174
|
const SCRIPT_ERRORS = {
|
|
143
175
|
browser: {
|
|
144
176
|
message: 'Browser scripts cannot have imports or exports.',
|
|
@@ -155,52 +187,165 @@ const SCRIPT_ERRORS = {
|
|
|
155
187
|
};
|
|
156
188
|
|
|
157
189
|
// NOTE: Make sure this is in sync with the TypeScript definition in the @atlaspack/macros package.
|
|
190
|
+
|
|
191
|
+
const TOKENS_CONFIG_SCHEMA = {
|
|
192
|
+
type: 'object',
|
|
193
|
+
properties: {
|
|
194
|
+
shouldUseAutoFallback: {
|
|
195
|
+
type: 'boolean'
|
|
196
|
+
},
|
|
197
|
+
shouldForceAutoFallback: {
|
|
198
|
+
type: 'boolean'
|
|
199
|
+
},
|
|
200
|
+
forceAutoFallbackExemptions: {
|
|
201
|
+
type: 'array',
|
|
202
|
+
items: {
|
|
203
|
+
type: 'string'
|
|
204
|
+
}
|
|
205
|
+
},
|
|
206
|
+
defaultTheme: {
|
|
207
|
+
type: 'string',
|
|
208
|
+
enum: ['light', 'legacy-light']
|
|
209
|
+
},
|
|
210
|
+
tokenDataPath: {
|
|
211
|
+
type: 'string'
|
|
212
|
+
}
|
|
213
|
+
},
|
|
214
|
+
additionalProperties: false
|
|
215
|
+
};
|
|
216
|
+
async function legacyDetemineJsxConfig(config, options) {
|
|
217
|
+
let packageJson = await config.getPackage();
|
|
218
|
+
let isJSX, jsxPragma, jsxPragmaFrag, jsxImportSource, automaticJSXRuntime, reactRefresh;
|
|
219
|
+
if (config.isSource) {
|
|
220
|
+
var _packageJson$dependen2, _packageJson$devDepen2, _packageJson$peerDepe2, _await$config$getConf;
|
|
221
|
+
let reactLib;
|
|
222
|
+
if (packageJson !== null && packageJson !== void 0 && packageJson.alias && packageJson.alias['react']) {
|
|
223
|
+
// e.g.: `{ alias: { "react": "preact/compat" } }`
|
|
224
|
+
reactLib = 'react';
|
|
225
|
+
} else {
|
|
226
|
+
// Find a dependency that we can map to a JSX pragma
|
|
227
|
+
reactLib = Object.keys(JSX_PRAGMA).find(libName => {
|
|
228
|
+
var _packageJson$dependen, _packageJson$devDepen, _packageJson$peerDepe;
|
|
229
|
+
return (packageJson === null || packageJson === void 0 || (_packageJson$dependen = packageJson.dependencies) === null || _packageJson$dependen === void 0 ? void 0 : _packageJson$dependen[libName]) || (packageJson === null || packageJson === void 0 || (_packageJson$devDepen = packageJson.devDependencies) === null || _packageJson$devDepen === void 0 ? void 0 : _packageJson$devDepen[libName]) || (packageJson === null || packageJson === void 0 || (_packageJson$peerDepe = packageJson.peerDependencies) === null || _packageJson$peerDepe === void 0 ? void 0 : _packageJson$peerDepe[libName]);
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
reactRefresh = Boolean((packageJson === null || packageJson === void 0 || (_packageJson$dependen2 = packageJson.dependencies) === null || _packageJson$dependen2 === void 0 ? void 0 : _packageJson$dependen2.react) || (packageJson === null || packageJson === void 0 || (_packageJson$devDepen2 = packageJson.devDependencies) === null || _packageJson$devDepen2 === void 0 ? void 0 : _packageJson$devDepen2.react) || (packageJson === null || packageJson === void 0 || (_packageJson$peerDepe2 = packageJson.peerDependencies) === null || _packageJson$peerDepe2 === void 0 ? void 0 : _packageJson$peerDepe2.react));
|
|
233
|
+
const compilerOptions = (_await$config$getConf = await config.getConfigFrom(options.projectRoot + '/index', ['tsconfig.json', 'jsconfig.json'], {
|
|
234
|
+
readTracking: true
|
|
235
|
+
})) === null || _await$config$getConf === void 0 || (_await$config$getConf = _await$config$getConf.contents) === null || _await$config$getConf === void 0 ? void 0 : _await$config$getConf.compilerOptions;
|
|
236
|
+
|
|
237
|
+
// Use explicitly defined JSX options in tsconfig.json over inferred values from dependencies.
|
|
238
|
+
jsxPragma = (compilerOptions === null || compilerOptions === void 0 ? void 0 : compilerOptions.jsxFactory) || (
|
|
239
|
+
// @ts-expect-error TS7053
|
|
240
|
+
reactLib ? JSX_PRAGMA[reactLib].pragma : undefined);
|
|
241
|
+
jsxPragmaFrag = (compilerOptions === null || compilerOptions === void 0 ? void 0 : compilerOptions.jsxFragmentFactory) || (
|
|
242
|
+
// @ts-expect-error TS7053
|
|
243
|
+
reactLib ? JSX_PRAGMA[reactLib].pragmaFrag : undefined);
|
|
244
|
+
if ((compilerOptions === null || compilerOptions === void 0 ? void 0 : compilerOptions.jsx) === 'react-jsx' || (compilerOptions === null || compilerOptions === void 0 ? void 0 : compilerOptions.jsx) === 'react-jsxdev' || compilerOptions !== null && compilerOptions !== void 0 && compilerOptions.jsxImportSource) {
|
|
245
|
+
jsxImportSource = compilerOptions === null || compilerOptions === void 0 ? void 0 : compilerOptions.jsxImportSource;
|
|
246
|
+
automaticJSXRuntime = true;
|
|
247
|
+
} else if (reactLib) {
|
|
248
|
+
var _JSX_PRAGMA$effective, _packageJson$dependen3, _packageJson$devDepen3, _packageJson$peerDepe3, _semver$minVersion;
|
|
249
|
+
let effectiveReactLib = packageJson !== null && packageJson !== void 0 && packageJson.alias && packageJson.alias['react'] === 'preact/compat' ? 'preact' : reactLib;
|
|
250
|
+
// @ts-expect-error TS7053
|
|
251
|
+
let automaticVersion = (_JSX_PRAGMA$effective = JSX_PRAGMA[effectiveReactLib]) === null || _JSX_PRAGMA$effective === void 0 ? void 0 : _JSX_PRAGMA$effective.automatic;
|
|
252
|
+
let reactLibVersion = (packageJson === null || packageJson === void 0 || (_packageJson$dependen3 = packageJson.dependencies) === null || _packageJson$dependen3 === void 0 ? void 0 : _packageJson$dependen3[effectiveReactLib]) || (packageJson === null || packageJson === void 0 || (_packageJson$devDepen3 = packageJson.devDependencies) === null || _packageJson$devDepen3 === void 0 ? void 0 : _packageJson$devDepen3[effectiveReactLib]) || (packageJson === null || packageJson === void 0 || (_packageJson$peerDepe3 = packageJson.peerDependencies) === null || _packageJson$peerDepe3 === void 0 ? void 0 : _packageJson$peerDepe3[effectiveReactLib]);
|
|
253
|
+
// @ts-expect-error TS2322
|
|
254
|
+
reactLibVersion = reactLibVersion ? _semver().default.validRange(reactLibVersion) : null;
|
|
255
|
+
let minReactLibVersion = reactLibVersion !== null && reactLibVersion !== '*' ? // @ts-expect-error TS2345
|
|
256
|
+
(_semver$minVersion = _semver().default.minVersion(reactLibVersion)) === null || _semver$minVersion === void 0 ? void 0 : _semver$minVersion.toString() : null;
|
|
257
|
+
automaticJSXRuntime = automaticVersion && !(compilerOptions !== null && compilerOptions !== void 0 && compilerOptions.jsxFactory) && minReactLibVersion != null && _semver().default.satisfies(minReactLibVersion, automaticVersion, {
|
|
258
|
+
includePrerelease: true
|
|
259
|
+
});
|
|
260
|
+
if (automaticJSXRuntime) {
|
|
261
|
+
jsxImportSource = reactLib;
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
isJSX = Boolean((compilerOptions === null || compilerOptions === void 0 ? void 0 : compilerOptions.jsx) || jsxPragma);
|
|
265
|
+
}
|
|
266
|
+
return {
|
|
267
|
+
isJSX,
|
|
268
|
+
jsxPragma,
|
|
269
|
+
jsxPragmaFrag,
|
|
270
|
+
jsxImportSource,
|
|
271
|
+
automaticJSXRuntime,
|
|
272
|
+
reactRefresh
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
async function loadTokensConfig(config, options) {
|
|
276
|
+
const conf = await config.getConfigFrom(options.projectRoot + '/index', [], {
|
|
277
|
+
packageKey: '@atlaspack/transformer-tokens'
|
|
278
|
+
});
|
|
279
|
+
if (conf && conf.contents) {
|
|
280
|
+
_utils().validateSchema.diagnostic(TOKENS_CONFIG_SCHEMA, {
|
|
281
|
+
data: conf.contents,
|
|
282
|
+
source: () => options.inputFS.readFileSync(conf.filePath, 'utf8'),
|
|
283
|
+
filePath: conf.filePath,
|
|
284
|
+
prependKey: `/${(0, _diagnostic().encodeJSONKeyComponent)('@atlaspack/transformer-tokens')}`
|
|
285
|
+
}, '@atlaspack/transformer-tokens', 'Invalid config for @atlaspack/transformer-tokens');
|
|
286
|
+
|
|
287
|
+
// @ts-expect-error TS2339
|
|
288
|
+
const tokensConfig = conf.contents;
|
|
289
|
+
let resolvedConfig = {
|
|
290
|
+
shouldUseAutoFallback: tokensConfig.shouldUseAutoFallback ?? true,
|
|
291
|
+
shouldForceAutoFallback: tokensConfig.shouldForceAutoFallback ?? true,
|
|
292
|
+
forceAutoFallbackExemptions: tokensConfig.forceAutoFallbackExemptions ?? [],
|
|
293
|
+
defaultTheme: tokensConfig.defaultTheme ?? 'light',
|
|
294
|
+
tokenDataPath: _path().default.join(options.projectRoot, tokensConfig.tokenDataPath)
|
|
295
|
+
};
|
|
296
|
+
return resolvedConfig;
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
async function loadCompiledCssInJsConfig(config, options) {
|
|
300
|
+
const DEFAULT_IMPORT_SOURCES = ['@compiled/react', '@atlaskit/css'];
|
|
301
|
+
const conf = await config.getConfigFrom((0, _path().join)(options.projectRoot, 'index'), ['.compiledcssrc', '.compiledcssrc.json'], {
|
|
302
|
+
packageKey: '@atlaspack/transformer-compiled-css-in-js'
|
|
303
|
+
});
|
|
304
|
+
const resolvedBrowserslistEnv = (conf === null || conf === void 0 ? void 0 : conf.contents.browserslistEnv) ?? process.env.BROWSERSLIST_ENV ?? process.env.NODE_ENV ?? 'production';
|
|
305
|
+
const contents = {
|
|
306
|
+
...(conf === null || conf === void 0 ? void 0 : conf.contents),
|
|
307
|
+
importSources: [...DEFAULT_IMPORT_SOURCES, ...((conf === null || conf === void 0 ? void 0 : conf.contents.importSources) ?? [])],
|
|
308
|
+
extract: (conf === null || conf === void 0 ? void 0 : conf.contents.extract) && options.mode !== 'development',
|
|
309
|
+
// Use explicit env or process env (BROWSERSLIST_ENV/NODE_ENV). Default to "production"
|
|
310
|
+
// to match browserslist/caniuse defaults and the legacy Babel plugin behavior.
|
|
311
|
+
browserslistEnv: resolvedBrowserslistEnv
|
|
312
|
+
};
|
|
313
|
+
return contents;
|
|
314
|
+
}
|
|
158
315
|
var _default = exports.default = new (_plugin().Transformer)({
|
|
159
316
|
async loadConfig({
|
|
160
317
|
config,
|
|
161
318
|
options
|
|
162
319
|
}) {
|
|
163
|
-
|
|
164
|
-
let
|
|
320
|
+
var _conf$contents;
|
|
321
|
+
let conf = await config.getConfigFrom(options.projectRoot + '/index', [], {
|
|
322
|
+
packageKey: '@atlaspack/transformer-js'
|
|
323
|
+
});
|
|
324
|
+
if (conf && conf.contents) {
|
|
325
|
+
_utils().validateSchema.diagnostic(CONFIG_SCHEMA, {
|
|
326
|
+
data: conf.contents,
|
|
327
|
+
source: () => options.inputFS.readFileSync(conf.filePath, 'utf8'),
|
|
328
|
+
filePath: conf.filePath,
|
|
329
|
+
prependKey: `/${(0, _diagnostic().encodeJSONKeyComponent)('@atlaspack/transformer-js')}`
|
|
330
|
+
},
|
|
331
|
+
// FIXME
|
|
332
|
+
'@atlaspack/transformer-js', 'Invalid config for @atlaspack/transformer-js');
|
|
333
|
+
}
|
|
334
|
+
let packageJson = await config.getPackage();
|
|
335
|
+
let decorators, useDefineForClassFields;
|
|
336
|
+
let {
|
|
337
|
+
isJSX,
|
|
338
|
+
jsxPragma,
|
|
339
|
+
jsxPragmaFrag,
|
|
340
|
+
jsxImportSource,
|
|
341
|
+
automaticJSXRuntime,
|
|
342
|
+
reactRefresh
|
|
343
|
+
} = options.featureFlags.newJsxConfig ? (0, _rust().determineJsxConfiguration)(config.searchPath, config.isSource, conf === null || conf === void 0 || (_conf$contents = conf.contents) === null || _conf$contents === void 0 ? void 0 : _conf$contents.jsx, options.projectRoot) : await legacyDetemineJsxConfig(config, options);
|
|
165
344
|
if (config.isSource) {
|
|
166
|
-
var
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
reactLib = 'react';
|
|
171
|
-
} else {
|
|
172
|
-
// Find a dependency that we can map to a JSX pragma
|
|
173
|
-
reactLib = Object.keys(JSX_PRAGMA).find(libName => {
|
|
174
|
-
var _pkg$dependencies, _pkg$devDependencies, _pkg$peerDependencies;
|
|
175
|
-
return (pkg === null || pkg === void 0 || (_pkg$dependencies = pkg.dependencies) === null || _pkg$dependencies === void 0 ? void 0 : _pkg$dependencies[libName]) || (pkg === null || pkg === void 0 || (_pkg$devDependencies = pkg.devDependencies) === null || _pkg$devDependencies === void 0 ? void 0 : _pkg$devDependencies[libName]) || (pkg === null || pkg === void 0 || (_pkg$peerDependencies = pkg.peerDependencies) === null || _pkg$peerDependencies === void 0 ? void 0 : _pkg$peerDependencies[libName]);
|
|
176
|
-
});
|
|
177
|
-
}
|
|
178
|
-
reactRefresh = options.hmrOptions && options.mode === 'development' && Boolean((pkg === null || pkg === void 0 || (_pkg$dependencies2 = pkg.dependencies) === null || _pkg$dependencies2 === void 0 ? void 0 : _pkg$dependencies2.react) || (pkg === null || pkg === void 0 || (_pkg$devDependencies2 = pkg.devDependencies) === null || _pkg$devDependencies2 === void 0 ? void 0 : _pkg$devDependencies2.react) || (pkg === null || pkg === void 0 || (_pkg$peerDependencies2 = pkg.peerDependencies) === null || _pkg$peerDependencies2 === void 0 ? void 0 : _pkg$peerDependencies2.react));
|
|
179
|
-
const compilerOptions = (0, _featureFlags().getFeatureFlag)('granularTsConfigInvalidation') ? (_await$config$getConf = await config.getConfigFrom(options.projectRoot + '/index', ['tsconfig.json', 'jsconfig.json'], {
|
|
180
|
-
configKey: 'compilerOptions'
|
|
181
|
-
})) === null || _await$config$getConf === void 0 ? void 0 : _await$config$getConf.contents : (_await$config$getConf2 = await config.getConfigFrom(options.projectRoot + '/index', ['tsconfig.json', 'jsconfig.json'])) === null || _await$config$getConf2 === void 0 || (_await$config$getConf2 = _await$config$getConf2.contents) === null || _await$config$getConf2 === void 0 ? void 0 : _await$config$getConf2.compilerOptions;
|
|
182
|
-
|
|
183
|
-
// Use explicitly defined JSX options in tsconfig.json over inferred values from dependencies.
|
|
184
|
-
pragma = (compilerOptions === null || compilerOptions === void 0 ? void 0 : compilerOptions.jsxFactory) || (reactLib ? JSX_PRAGMA[reactLib].pragma : undefined);
|
|
185
|
-
pragmaFrag = (compilerOptions === null || compilerOptions === void 0 ? void 0 : compilerOptions.jsxFragmentFactory) || (reactLib ? JSX_PRAGMA[reactLib].pragmaFrag : undefined);
|
|
186
|
-
if ((compilerOptions === null || compilerOptions === void 0 ? void 0 : compilerOptions.jsx) === 'react-jsx' || (compilerOptions === null || compilerOptions === void 0 ? void 0 : compilerOptions.jsx) === 'react-jsxdev' || compilerOptions !== null && compilerOptions !== void 0 && compilerOptions.jsxImportSource) {
|
|
187
|
-
jsxImportSource = compilerOptions === null || compilerOptions === void 0 ? void 0 : compilerOptions.jsxImportSource;
|
|
188
|
-
automaticJSXRuntime = true;
|
|
189
|
-
} else if (reactLib) {
|
|
190
|
-
var _JSX_PRAGMA$effective, _pkg$dependencies3, _pkg$devDependencies3, _pkg$peerDependencies3, _semver$minVersion;
|
|
191
|
-
let effectiveReactLib = pkg !== null && pkg !== void 0 && pkg.alias && pkg.alias['react'] === 'preact/compat' ? 'preact' : reactLib;
|
|
192
|
-
let automaticVersion = (_JSX_PRAGMA$effective = JSX_PRAGMA[effectiveReactLib]) === null || _JSX_PRAGMA$effective === void 0 ? void 0 : _JSX_PRAGMA$effective.automatic;
|
|
193
|
-
let reactLibVersion = (pkg === null || pkg === void 0 || (_pkg$dependencies3 = pkg.dependencies) === null || _pkg$dependencies3 === void 0 ? void 0 : _pkg$dependencies3[effectiveReactLib]) || (pkg === null || pkg === void 0 || (_pkg$devDependencies3 = pkg.devDependencies) === null || _pkg$devDependencies3 === void 0 ? void 0 : _pkg$devDependencies3[effectiveReactLib]) || (pkg === null || pkg === void 0 || (_pkg$peerDependencies3 = pkg.peerDependencies) === null || _pkg$peerDependencies3 === void 0 ? void 0 : _pkg$peerDependencies3[effectiveReactLib]);
|
|
194
|
-
reactLibVersion = reactLibVersion ? _semver().default.validRange(reactLibVersion) : null;
|
|
195
|
-
let minReactLibVersion = reactLibVersion !== null && reactLibVersion !== '*' ? (_semver$minVersion = _semver().default.minVersion(reactLibVersion)) === null || _semver$minVersion === void 0 ? void 0 : _semver$minVersion.toString() : null;
|
|
196
|
-
automaticJSXRuntime = automaticVersion && !(compilerOptions !== null && compilerOptions !== void 0 && compilerOptions.jsxFactory) && minReactLibVersion != null && _semver().default.satisfies(minReactLibVersion, automaticVersion, {
|
|
197
|
-
includePrerelease: true
|
|
198
|
-
});
|
|
199
|
-
if (automaticJSXRuntime) {
|
|
200
|
-
jsxImportSource = reactLib;
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
isJSX = Boolean((compilerOptions === null || compilerOptions === void 0 ? void 0 : compilerOptions.jsx) || pragma);
|
|
345
|
+
var _await$config$getConf2;
|
|
346
|
+
const compilerOptions = (_await$config$getConf2 = await config.getConfigFrom(options.projectRoot + '/index', ['tsconfig.json', 'jsconfig.json'], {
|
|
347
|
+
readTracking: true
|
|
348
|
+
})) === null || _await$config$getConf2 === void 0 || (_await$config$getConf2 = _await$config$getConf2.contents) === null || _await$config$getConf2 === void 0 ? void 0 : _await$config$getConf2.compilerOptions;
|
|
204
349
|
decorators = compilerOptions === null || compilerOptions === void 0 ? void 0 : compilerOptions.experimentalDecorators;
|
|
205
350
|
useDefineForClassFields = compilerOptions === null || compilerOptions === void 0 ? void 0 : compilerOptions.useDefineForClassFields;
|
|
206
351
|
if (useDefineForClassFields === undefined && (compilerOptions === null || compilerOptions === void 0 ? void 0 : compilerOptions.target) != null) {
|
|
@@ -216,43 +361,88 @@ var _default = exports.default = new (_plugin().Transformer)({
|
|
|
216
361
|
|
|
217
362
|
// Check if we should ignore fs calls
|
|
218
363
|
// See https://github.com/defunctzombie/node-browser-resolve#skip
|
|
219
|
-
let ignoreFS =
|
|
220
|
-
let conf = await config.getConfigFrom(options.projectRoot + '/index', [], {
|
|
221
|
-
packageKey: '@atlaspack/transformer-js'
|
|
222
|
-
});
|
|
364
|
+
let ignoreFS = packageJson && packageJson.browser && typeof packageJson.browser === 'object' && packageJson.browser.fs === false;
|
|
223
365
|
let inlineEnvironment = config.isSource;
|
|
224
366
|
let inlineFS = !ignoreFS;
|
|
225
367
|
let inlineConstants = false;
|
|
226
368
|
let magicComments = false;
|
|
369
|
+
let addReactDisplayName = false;
|
|
370
|
+
let enableSsrTypeofReplacement = options.env.NATIVE_SSR_TYPEOF_REPLACEMENT === 'true';
|
|
371
|
+
let globalAliasingConfig = options.env.NATIVE_GLOBAL_ALIASING && JSON.parse(options.env.NATIVE_GLOBAL_ALIASING);
|
|
372
|
+
let enableLazyLoading = options.env.NATIVE_LAZY_LOADING === 'true';
|
|
373
|
+
let enableReactHooksRemoval = options.env.NATIVE_REACT_HOOKS_REMOVAL === 'true';
|
|
374
|
+
let enableReactAsyncImportLift = options.env.NATIVE_REACT_ASYNC_IMPORT_LIFT === 'true';
|
|
375
|
+
let reactAsyncLiftByDefault = options.env.REACT_ASYNC_IMPORT_LIFTING_BY_DEFAULT === 'true';
|
|
376
|
+
let reactAsyncLiftReportLevel = options.env.REACT_ASYNC_LIFT_REPORT_LEVEL || 'none';
|
|
377
|
+
let enableStaticPrevaluation = options.env.NATIVE_PREVALUATION === 'true';
|
|
378
|
+
let enableDeadReturnsRemoval = options.env.NATIVE_DEAD_RETURNS_REMOVAL === 'true';
|
|
379
|
+
let enableUnusedBindingsRemoval = options.env.NATIVE_UNUSED_BINDINGS_REMOVAL === 'true';
|
|
380
|
+
let syncDynamicImportConfig;
|
|
381
|
+
if (config.env.isTesseract() && options.env.SYNC_DYNAMIC_IMPORT_CONFIG) {
|
|
382
|
+
try {
|
|
383
|
+
let config = configCache.get('SYNC_DYNAMIC_IMPORT_CONFIG');
|
|
384
|
+
if (!config) {
|
|
385
|
+
var _config;
|
|
386
|
+
config = JSON.parse(options.env.SYNC_DYNAMIC_IMPORT_CONFIG);
|
|
387
|
+
(0, _assert().default)(typeof ((_config = config) === null || _config === void 0 ? void 0 : _config.entrypoint_filepath_suffix) === 'string');
|
|
388
|
+
(0, _assert().default)(Array.isArray(config.actual_require_paths));
|
|
389
|
+
(0, _assert().default)(typeof (config.activate_reject_on_unresolved_imports ?? false) === 'boolean');
|
|
390
|
+
configCache.set('SYNC_DYNAMIC_IMPORT_CONFIG', config);
|
|
391
|
+
}
|
|
392
|
+
syncDynamicImportConfig = config;
|
|
393
|
+
} catch {
|
|
394
|
+
// eslint-disable-next-line no-console
|
|
395
|
+
console.warn('Failed to parse SYNC_DYNAMIC_IMPORT_CONFIG to JSON or config shape did not match. Config will not be applied.');
|
|
396
|
+
const fallback = {
|
|
397
|
+
entrypoint_filepath_suffix: '__NO_MATCH__',
|
|
398
|
+
actual_require_paths: [],
|
|
399
|
+
activate_reject_on_unresolved_imports: false
|
|
400
|
+
};
|
|
401
|
+
|
|
402
|
+
// Set cache to fallback so we don't keep trying to parse.
|
|
403
|
+
configCache.set('SYNC_DYNAMIC_IMPORT_CONFIG', fallback);
|
|
404
|
+
syncDynamicImportConfig = fallback;
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
config.invalidateOnEnvChange('SYNC_DYNAMIC_IMPORT_CONFIG');
|
|
408
|
+
const tokensConfig = (0, _featureFlags().getFeatureFlag)('coreTokensAndCompiledCssInJsTransform') ? await loadTokensConfig(config, options) : undefined;
|
|
409
|
+
const compiledCssInJsConfig = (0, _featureFlags().getFeatureFlag)('coreTokensAndCompiledCssInJsTransform') ? await loadCompiledCssInJsConfig(config, options) : undefined;
|
|
227
410
|
if (conf && conf.contents) {
|
|
228
|
-
var _conf$
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
},
|
|
236
|
-
// FIXME
|
|
237
|
-
'@atlaspack/transformer-js', 'Invalid config for @atlaspack/transformer-js');
|
|
238
|
-
magicComments = ((_conf$contents = conf.contents) === null || _conf$contents === void 0 ? void 0 : _conf$contents.magicComments) ?? magicComments;
|
|
239
|
-
inlineEnvironment = ((_conf$contents2 = conf.contents) === null || _conf$contents2 === void 0 ? void 0 : _conf$contents2.inlineEnvironment) ?? inlineEnvironment;
|
|
240
|
-
inlineFS = ((_conf$contents3 = conf.contents) === null || _conf$contents3 === void 0 ? void 0 : _conf$contents3.inlineFS) ?? inlineFS;
|
|
241
|
-
inlineConstants = ((_conf$contents4 = conf.contents) === null || _conf$contents4 === void 0 ? void 0 : _conf$contents4.unstable_inlineConstants) ?? inlineConstants;
|
|
411
|
+
var _conf$contents2, _conf$contents3, _conf$contents4, _conf$contents5, _conf$contents6;
|
|
412
|
+
addReactDisplayName = ((_conf$contents2 = conf.contents) === null || _conf$contents2 === void 0 ? void 0 : _conf$contents2.addReactDisplayName) ?? addReactDisplayName;
|
|
413
|
+
magicComments = ((_conf$contents3 = conf.contents) === null || _conf$contents3 === void 0 ? void 0 : _conf$contents3.magicComments) ?? magicComments;
|
|
414
|
+
// @ts-expect-error TS2322
|
|
415
|
+
inlineEnvironment = ((_conf$contents4 = conf.contents) === null || _conf$contents4 === void 0 ? void 0 : _conf$contents4.inlineEnvironment) ?? inlineEnvironment;
|
|
416
|
+
inlineFS = ((_conf$contents5 = conf.contents) === null || _conf$contents5 === void 0 ? void 0 : _conf$contents5.inlineFS) ?? inlineFS;
|
|
417
|
+
inlineConstants = ((_conf$contents6 = conf.contents) === null || _conf$contents6 === void 0 ? void 0 : _conf$contents6.unstable_inlineConstants) ?? inlineConstants;
|
|
242
418
|
}
|
|
243
419
|
return {
|
|
244
420
|
isJSX,
|
|
245
421
|
automaticJSXRuntime,
|
|
246
422
|
jsxImportSource,
|
|
247
|
-
pragma,
|
|
248
|
-
pragmaFrag,
|
|
423
|
+
pragma: jsxPragma,
|
|
424
|
+
pragmaFrag: jsxPragmaFrag,
|
|
249
425
|
inlineEnvironment,
|
|
250
426
|
inlineFS,
|
|
251
427
|
inlineConstants,
|
|
428
|
+
addReactDisplayName,
|
|
252
429
|
reactRefresh,
|
|
253
430
|
decorators,
|
|
254
431
|
useDefineForClassFields,
|
|
255
|
-
magicComments
|
|
432
|
+
magicComments,
|
|
433
|
+
globalAliasingConfig,
|
|
434
|
+
enableSsrTypeofReplacement,
|
|
435
|
+
enableLazyLoading,
|
|
436
|
+
enableDeadReturnsRemoval,
|
|
437
|
+
enableUnusedBindingsRemoval,
|
|
438
|
+
enableStaticPrevaluation,
|
|
439
|
+
enableReactHooksRemoval,
|
|
440
|
+
syncDynamicImportConfig,
|
|
441
|
+
enableReactAsyncImportLift,
|
|
442
|
+
reactAsyncLiftByDefault,
|
|
443
|
+
reactAsyncLiftReportLevel,
|
|
444
|
+
tokensConfig,
|
|
445
|
+
compiledCssInJsConfig
|
|
256
446
|
};
|
|
257
447
|
},
|
|
258
448
|
async transform({
|
|
@@ -281,17 +471,22 @@ var _default = exports.default = new (_plugin().Transformer)({
|
|
|
281
471
|
for (let browser of browsers) {
|
|
282
472
|
let [name, version] = browser.split(' ');
|
|
283
473
|
if (BROWSER_MAPPING.hasOwnProperty(name)) {
|
|
474
|
+
// @ts-expect-error TS7053
|
|
284
475
|
name = BROWSER_MAPPING[name];
|
|
285
476
|
if (!name) {
|
|
286
477
|
continue;
|
|
287
478
|
}
|
|
288
479
|
}
|
|
289
480
|
let [major, minor = '0', patch = '0'] = version.split('-')[0].split('.');
|
|
481
|
+
// @ts-expect-error TS2345
|
|
290
482
|
if (isNaN(major) || isNaN(minor) || isNaN(patch)) {
|
|
291
483
|
continue;
|
|
292
484
|
}
|
|
293
485
|
let semverVersion = `${major}.${minor}.${patch}`;
|
|
486
|
+
|
|
487
|
+
// @ts-expect-error TS2345
|
|
294
488
|
if (targets[name] == null || _semver().default.gt(targets[name], semverVersion)) {
|
|
489
|
+
// @ts-expect-error TS7053
|
|
295
490
|
targets[name] = semverVersion;
|
|
296
491
|
}
|
|
297
492
|
}
|
|
@@ -306,6 +501,9 @@ var _default = exports.default = new (_plugin().Transformer)({
|
|
|
306
501
|
if (options.env.NODE_ENV != null) {
|
|
307
502
|
env.NODE_ENV = options.env.NODE_ENV;
|
|
308
503
|
}
|
|
504
|
+
if (process.env.ATLASPACK_BUILD_ENV === 'test') {
|
|
505
|
+
env.ATLASPACK_BUILD_ENV = 'test';
|
|
506
|
+
}
|
|
309
507
|
} else if (Array.isArray(config === null || config === void 0 ? void 0 : config.inlineEnvironment)) {
|
|
310
508
|
for (let match of (0, _utils().globMatch)(Object.keys(options.env), config.inlineEnvironment)) {
|
|
311
509
|
env[match] = String(options.env[match]);
|
|
@@ -323,23 +521,42 @@ var _default = exports.default = new (_plugin().Transformer)({
|
|
|
323
521
|
if (asset.type === 'ts') {
|
|
324
522
|
isJSX = false;
|
|
325
523
|
} else if (!isJSX) {
|
|
524
|
+
// @ts-expect-error TS7053
|
|
326
525
|
isJSX = Boolean(JSX_EXTENSIONS[asset.type]);
|
|
327
526
|
}
|
|
328
527
|
}
|
|
329
528
|
let macroAssets = [];
|
|
330
529
|
let {
|
|
530
|
+
// @ts-expect-error TS2339
|
|
331
531
|
dependencies,
|
|
532
|
+
// @ts-expect-error TS2339
|
|
332
533
|
code: compiledCode,
|
|
534
|
+
// @ts-expect-error TS2339
|
|
333
535
|
map,
|
|
536
|
+
// @ts-expect-error TS2339
|
|
334
537
|
shebang,
|
|
538
|
+
// @ts-expect-error TS2339
|
|
335
539
|
hoist_result,
|
|
540
|
+
// @ts-expect-error TS2339
|
|
336
541
|
symbol_result,
|
|
542
|
+
// @ts-expect-error TS2339
|
|
543
|
+
is_empty_or_empty_export,
|
|
544
|
+
// @ts-expect-error TS2339
|
|
337
545
|
needs_esm_helpers,
|
|
546
|
+
// @ts-expect-error TS2339
|
|
338
547
|
diagnostics,
|
|
548
|
+
// @ts-expect-error TS2339
|
|
339
549
|
used_env,
|
|
550
|
+
// @ts-expect-error TS2339
|
|
340
551
|
has_node_replacements,
|
|
552
|
+
// @ts-expect-error TS2339
|
|
341
553
|
is_constant_module,
|
|
342
|
-
|
|
554
|
+
// @ts-expect-error TS2339
|
|
555
|
+
conditions,
|
|
556
|
+
// @ts-expect-error TS2339
|
|
557
|
+
magic_comments,
|
|
558
|
+
// @ts-expect-error TS2339
|
|
559
|
+
style_rules
|
|
343
560
|
} = await (_rust().transformAsync || _rust().transform)({
|
|
344
561
|
filename: asset.filePath,
|
|
345
562
|
code,
|
|
@@ -350,7 +567,7 @@ var _default = exports.default = new (_plugin().Transformer)({
|
|
|
350
567
|
insert_node_globals: !asset.env.isNode() && asset.env.sourceType !== 'script',
|
|
351
568
|
node_replacer: asset.env.isNode(),
|
|
352
569
|
is_browser: asset.env.isBrowser(),
|
|
353
|
-
is_worker: asset.env.isWorker(),
|
|
570
|
+
is_worker: asset.env.isWorker() || asset.env.isTesseract(),
|
|
354
571
|
env,
|
|
355
572
|
is_type_script: asset.type === 'ts' || asset.type === 'tsx',
|
|
356
573
|
is_jsx: isJSX,
|
|
@@ -359,7 +576,7 @@ var _default = exports.default = new (_plugin().Transformer)({
|
|
|
359
576
|
automatic_jsx_runtime: Boolean(config === null || config === void 0 ? void 0 : config.automaticJSXRuntime),
|
|
360
577
|
jsx_import_source: config === null || config === void 0 ? void 0 : config.jsxImportSource,
|
|
361
578
|
is_development: options.mode === 'development',
|
|
362
|
-
react_refresh: asset.env.isBrowser() && !asset.env.isLibrary && !asset.env.isWorker() && !asset.env.isWorklet() &&
|
|
579
|
+
react_refresh: Boolean(asset.env.isBrowser() && !asset.env.isLibrary && !asset.env.isWorker() && !asset.env.isTesseract() && !asset.env.isWorklet() && (config === null || config === void 0 ? void 0 : config.reactRefresh) && options.hmrOptions && options.mode === 'development'),
|
|
363
580
|
decorators: Boolean(config === null || config === void 0 ? void 0 : config.decorators),
|
|
364
581
|
use_define_for_class_fields: Boolean(config === null || config === void 0 ? void 0 : config.useDefineForClassFields),
|
|
365
582
|
targets,
|
|
@@ -374,16 +591,33 @@ var _default = exports.default = new (_plugin().Transformer)({
|
|
|
374
591
|
standalone: asset.query.has('standalone'),
|
|
375
592
|
inline_constants: config.inlineConstants,
|
|
376
593
|
conditional_bundling: options.featureFlags.conditionalBundlingApi,
|
|
377
|
-
|
|
594
|
+
hmr_improvements: options.featureFlags.hmrImprovements,
|
|
595
|
+
add_display_name: Boolean(config.addReactDisplayName),
|
|
596
|
+
exports_rebinding_optimisation: options.featureFlags.exportsRebindingOptimisation,
|
|
597
|
+
magic_comments: Boolean(config === null || config === void 0 ? void 0 : config.magicComments) || (0, _featureFlags().getFeatureFlag)('supportWebpackChunkName'),
|
|
598
|
+
is_source: asset.isSource,
|
|
599
|
+
nested_promise_import_fix: options.featureFlags.nestedPromiseImportFix,
|
|
600
|
+
global_aliasing_config: config.globalAliasingConfig,
|
|
601
|
+
enable_ssr_typeof_replacement: Boolean(config.enableSsrTypeofReplacement),
|
|
602
|
+
enable_lazy_loading: Boolean(config.enableLazyLoading),
|
|
603
|
+
enable_dead_returns_removal: Boolean(config.enableDeadReturnsRemoval),
|
|
604
|
+
enable_unused_bindings_removal: Boolean(config.enableUnusedBindingsRemoval),
|
|
605
|
+
enable_static_prevaluation: Boolean(config.enableStaticPrevaluation),
|
|
606
|
+
enable_react_hooks_removal: Boolean(config.enableReactHooksRemoval),
|
|
607
|
+
enable_react_async_import_lift: Boolean(config.enableReactAsyncImportLift),
|
|
608
|
+
react_async_lift_by_default: Boolean(config.reactAsyncLiftByDefault),
|
|
609
|
+
react_async_lift_report_level: String(config.reactAsyncLiftReportLevel),
|
|
610
|
+
sync_dynamic_import_config: config.syncDynamicImportConfig,
|
|
611
|
+
enable_tokens_and_compiled_css_in_js_transform: (0, _featureFlags().getFeatureFlag)('coreTokensAndCompiledCssInJsTransform'),
|
|
612
|
+
tokens_config: config.tokensConfig,
|
|
613
|
+
compiled_css_in_js_config: config.compiledCssInJsConfig,
|
|
378
614
|
callMacro: asset.isSource ? async (err, src, exportName, args, loc) => {
|
|
379
615
|
let mod;
|
|
380
616
|
try {
|
|
381
617
|
mod = await options.packageManager.require(src, asset.filePath);
|
|
382
618
|
|
|
383
619
|
// Default interop for CommonJS modules.
|
|
384
|
-
if (exportName === 'default' && !mod.__esModule &&
|
|
385
|
-
// $FlowFixMe
|
|
386
|
-
Object.prototype.toString.call(config) !== '[object Module]') {
|
|
620
|
+
if (exportName === 'default' && !mod.__esModule && Object.prototype.toString.call(config) !== '[object Module]') {
|
|
387
621
|
mod = {
|
|
388
622
|
default: mod
|
|
389
623
|
};
|
|
@@ -399,7 +633,7 @@ var _default = exports.default = new (_plugin().Transformer)({
|
|
|
399
633
|
}
|
|
400
634
|
try {
|
|
401
635
|
if (typeof mod[exportName] === 'function') {
|
|
402
|
-
|
|
636
|
+
let ctx = {
|
|
403
637
|
// Allows macros to emit additional assets to add as dependencies (e.g. css).
|
|
404
638
|
addAsset(a) {
|
|
405
639
|
let k = String(macroAssets.length);
|
|
@@ -407,6 +641,7 @@ var _default = exports.default = new (_plugin().Transformer)({
|
|
|
407
641
|
if (asset.env.sourceMap) {
|
|
408
642
|
// Generate a source map that maps each line of the asset to the original macro call.
|
|
409
643
|
map = new (_sourceMap().default)(options.projectRoot);
|
|
644
|
+
// @ts-expect-error TS2304
|
|
410
645
|
let mappings = [];
|
|
411
646
|
let line = 1;
|
|
412
647
|
for (let i = 0; i <= a.content.length; i++) {
|
|
@@ -429,7 +664,9 @@ var _default = exports.default = new (_plugin().Transformer)({
|
|
|
429
664
|
if (originalMap) {
|
|
430
665
|
map.extends(originalMap);
|
|
431
666
|
} else {
|
|
432
|
-
|
|
667
|
+
if (!(0, _featureFlags().getFeatureFlag)('omitSourcesContentInMemory')) {
|
|
668
|
+
map.setSourceContent(asset.filePath, code.toString());
|
|
669
|
+
}
|
|
433
670
|
}
|
|
434
671
|
}
|
|
435
672
|
macroAssets.push({
|
|
@@ -458,7 +695,8 @@ var _default = exports.default = new (_plugin().Transformer)({
|
|
|
458
695
|
invalidateOnBuild() {
|
|
459
696
|
asset.invalidateOnBuild();
|
|
460
697
|
}
|
|
461
|
-
}
|
|
698
|
+
};
|
|
699
|
+
return mod[exportName].apply(ctx, args);
|
|
462
700
|
} else {
|
|
463
701
|
throw new Error(`"${exportName}" in "${src}" is not a function.`);
|
|
464
702
|
}
|
|
@@ -480,11 +718,10 @@ var _default = exports.default = new (_plugin().Transformer)({
|
|
|
480
718
|
} : null
|
|
481
719
|
});
|
|
482
720
|
if ((0, _featureFlags().getFeatureFlag)('conditionalBundlingApi')) {
|
|
483
|
-
asset.meta.conditions = conditions
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
}));
|
|
721
|
+
asset.meta.conditions = conditions;
|
|
722
|
+
}
|
|
723
|
+
if (style_rules) {
|
|
724
|
+
asset.meta.styleRules = style_rules;
|
|
488
725
|
}
|
|
489
726
|
if (is_constant_module) {
|
|
490
727
|
asset.meta.isConstantModule = true;
|
|
@@ -504,17 +741,22 @@ var _default = exports.default = new (_plugin().Transformer)({
|
|
|
504
741
|
|
|
505
742
|
// If there is an original source map, use it to remap to the original source location.
|
|
506
743
|
if (originalMap) {
|
|
507
|
-
location = (0, _utils().remapSourceLocation)(location, originalMap);
|
|
744
|
+
location = (0, _utils().remapSourceLocation)(location, originalMap, options.projectRoot);
|
|
508
745
|
}
|
|
509
746
|
return location;
|
|
510
747
|
};
|
|
511
748
|
if (diagnostics) {
|
|
512
|
-
let errors = diagnostics.filter(
|
|
513
|
-
|
|
749
|
+
let errors = diagnostics.filter(
|
|
750
|
+
// @ts-expect-error TS7006
|
|
751
|
+
d => d.severity === 'Error' || d.severity === 'SourceError' && asset.isSource);
|
|
752
|
+
let warnings = diagnostics.filter(
|
|
753
|
+
// @ts-expect-error TS7006
|
|
754
|
+
d => d.severity === 'Warning' || d.severity === 'SourceError' && !asset.isSource);
|
|
514
755
|
let convertDiagnostic = diagnostic => {
|
|
515
756
|
var _diagnostic$code_high;
|
|
516
757
|
let message = diagnostic.message;
|
|
517
758
|
if (message === 'SCRIPT_ERROR') {
|
|
759
|
+
// @ts-expect-error TS7053
|
|
518
760
|
let err = SCRIPT_ERRORS[asset.env.context];
|
|
519
761
|
message = (err === null || err === void 0 ? void 0 : err.message) || SCRIPT_ERRORS.browser.message;
|
|
520
762
|
}
|
|
@@ -526,6 +768,9 @@ var _default = exports.default = new (_plugin().Transformer)({
|
|
|
526
768
|
}],
|
|
527
769
|
hints: diagnostic.hints
|
|
528
770
|
};
|
|
771
|
+
if (diagnostic.name) {
|
|
772
|
+
res.name = diagnostic.name;
|
|
773
|
+
}
|
|
529
774
|
if (diagnostic.documentation_url) {
|
|
530
775
|
res.documentationURL = diagnostic.documentation_url;
|
|
531
776
|
}
|
|
@@ -537,6 +782,8 @@ var _default = exports.default = new (_plugin().Transformer)({
|
|
|
537
782
|
codeHighlights: [(0, _diagnostic().convertSourceLocationToHighlight)(asset.env.loc, 'The environment was originally created here')]
|
|
538
783
|
});
|
|
539
784
|
}
|
|
785
|
+
|
|
786
|
+
// @ts-expect-error TS7053
|
|
540
787
|
let err = SCRIPT_ERRORS[asset.env.context];
|
|
541
788
|
if (err) {
|
|
542
789
|
if (!res.hints) {
|
|
@@ -581,6 +828,7 @@ var _default = exports.default = new (_plugin().Transformer)({
|
|
|
581
828
|
env: {
|
|
582
829
|
context: 'web-worker',
|
|
583
830
|
sourceType: dep.source_type === 'Module' ? 'module' : 'script',
|
|
831
|
+
// @ts-expect-error TS2322
|
|
584
832
|
outputFormat,
|
|
585
833
|
loc
|
|
586
834
|
},
|
|
@@ -630,6 +878,13 @@ var _default = exports.default = new (_plugin().Transformer)({
|
|
|
630
878
|
});
|
|
631
879
|
} else if (dep.kind === 'File') {
|
|
632
880
|
asset.invalidateOnFileChange(dep.specifier);
|
|
881
|
+
} else if (dep.kind === 'Id') {
|
|
882
|
+
// Record parcelRequire calls so that the dev packager can add them as dependencies.
|
|
883
|
+
// This allows the HMR runtime to collect parents across async boundaries (through runtimes).
|
|
884
|
+
// TODO: ideally this would result as an actual dep in the graph rather than asset.meta.
|
|
885
|
+
asset.meta.hmrDeps ??= [];
|
|
886
|
+
(0, _assert().default)(Array.isArray(asset.meta.hmrDeps));
|
|
887
|
+
asset.meta.hmrDeps.push(dep.specifier);
|
|
633
888
|
} else {
|
|
634
889
|
let meta = {
|
|
635
890
|
kind: dep.kind
|
|
@@ -677,6 +932,12 @@ var _default = exports.default = new (_plugin().Transformer)({
|
|
|
677
932
|
outputFormat,
|
|
678
933
|
loc: convertLoc(dep.loc)
|
|
679
934
|
};
|
|
935
|
+
if ((0, _featureFlags().getFeatureFlag)('supportWebpackChunkName')) {
|
|
936
|
+
let chunkName = magic_comments[dep.specifier];
|
|
937
|
+
if (chunkName) {
|
|
938
|
+
meta.chunkName = chunkName;
|
|
939
|
+
}
|
|
940
|
+
}
|
|
680
941
|
}
|
|
681
942
|
|
|
682
943
|
// Always bundle helpers, even with includeNodeModules: false, except if this is a library.
|
|
@@ -696,6 +957,7 @@ var _default = exports.default = new (_plugin().Transformer)({
|
|
|
696
957
|
idx = dep.specifier.indexOf('/', idx + 1);
|
|
697
958
|
}
|
|
698
959
|
let module = idx >= 0 ? dep.specifier.slice(0, idx) : dep.specifier;
|
|
960
|
+
// @ts-expect-error TS7053
|
|
699
961
|
range = _package.default.dependencies[module];
|
|
700
962
|
}
|
|
701
963
|
asset.addDependency({
|
|
@@ -707,6 +969,7 @@ var _default = exports.default = new (_plugin().Transformer)({
|
|
|
707
969
|
meta,
|
|
708
970
|
resolveFrom: isHelper ? __filename : undefined,
|
|
709
971
|
range,
|
|
972
|
+
// @ts-expect-error TS2322
|
|
710
973
|
env
|
|
711
974
|
});
|
|
712
975
|
}
|
|
@@ -718,10 +981,12 @@ var _default = exports.default = new (_plugin().Transformer)({
|
|
|
718
981
|
exported,
|
|
719
982
|
local,
|
|
720
983
|
loc,
|
|
721
|
-
is_esm
|
|
984
|
+
is_esm,
|
|
985
|
+
is_static_binding_safe
|
|
722
986
|
} of hoist_result.exported_symbols) {
|
|
723
987
|
asset.symbols.set(exported, local, convertLoc(loc), {
|
|
724
|
-
isEsm: is_esm
|
|
988
|
+
isEsm: is_esm,
|
|
989
|
+
isStaticBindingSafe: is_static_binding_safe
|
|
725
990
|
});
|
|
726
991
|
}
|
|
727
992
|
|
|
@@ -753,7 +1018,20 @@ var _default = exports.default = new (_plugin().Transformer)({
|
|
|
753
1018
|
let dep = deps.get(source);
|
|
754
1019
|
if (!dep) continue;
|
|
755
1020
|
if (local === '*' && imported === '*') {
|
|
756
|
-
|
|
1021
|
+
// When a module has both `import * as ns from 'x'` and
|
|
1022
|
+
// `export * from 'x'`, they share a single dep (merged by the
|
|
1023
|
+
// core). The namespace import binding ('*' → local, isWeak:false)
|
|
1024
|
+
// set by imported_symbols is strictly more inclusive than the
|
|
1025
|
+
// wildcard re-export ('*' → '*', isWeak:true) for symbol
|
|
1026
|
+
// propagation, so don't overwrite it. Instead, flag the dep so
|
|
1027
|
+
// that symbol propagation still treats it as a wildcard
|
|
1028
|
+
// re-exporter.
|
|
1029
|
+
let existingStar = dep.symbols.get('*');
|
|
1030
|
+
if ((0, _featureFlags().getFeatureFlag)('fixExportStarNamespaceOverwrite') && existingStar && existingStar.local !== '*') {
|
|
1031
|
+
dep.meta.hasExportStar = true;
|
|
1032
|
+
} else {
|
|
1033
|
+
dep.symbols.set('*', '*', convertLoc(loc), true);
|
|
1034
|
+
}
|
|
757
1035
|
} else {
|
|
758
1036
|
var _dep$symbols$get;
|
|
759
1037
|
let reExportName = ((_dep$symbols$get = dep.symbols.get(imported)) === null || _dep$symbols$get === void 0 ? void 0 : _dep$symbols$get.local) ?? `$${asset.id}$re_export$${local}`;
|
|
@@ -803,6 +1081,9 @@ var _default = exports.default = new (_plugin().Transformer)({
|
|
|
803
1081
|
// (and the asset has side effects), or the asset is wrapped.
|
|
804
1082
|
// This allows accessing symbols that don't exist without errors in symbol propagation.
|
|
805
1083
|
if (hoist_result.has_cjs_exports || !hoist_result.is_esm && asset.sideEffects && deps.size === 0 && Object.keys(hoist_result.exported_symbols).length === 0 || hoist_result.should_wrap && !asset.symbols.hasExportSymbol('*')) {
|
|
1084
|
+
if (is_empty_or_empty_export) {
|
|
1085
|
+
asset.meta.emptyFileStarReexport = true;
|
|
1086
|
+
}
|
|
806
1087
|
asset.symbols.set('*', `$${asset.id}$exports`);
|
|
807
1088
|
}
|
|
808
1089
|
asset.meta.hasCJSExports = hoist_result.has_cjs_exports;
|
|
@@ -843,7 +1124,16 @@ var _default = exports.default = new (_plugin().Transformer)({
|
|
|
843
1124
|
let dep = deps.get(source);
|
|
844
1125
|
if (!dep) continue;
|
|
845
1126
|
dep.symbols.ensure();
|
|
846
|
-
|
|
1127
|
+
// When a module has both `import * as ns from 'x'` and
|
|
1128
|
+
// `export * from 'x'`, they share a single dep. Don't overwrite
|
|
1129
|
+
// the namespace import binding — flag the dep instead so symbol
|
|
1130
|
+
// propagation still treats it as a wildcard re-exporter.
|
|
1131
|
+
let existingStar = dep.symbols.get('*');
|
|
1132
|
+
if ((0, _featureFlags().getFeatureFlag)('fixExportStarNamespaceOverwrite') && existingStar && existingStar.local !== '*') {
|
|
1133
|
+
dep.meta.hasExportStar = true;
|
|
1134
|
+
} else {
|
|
1135
|
+
dep.symbols.set('*', '*', convertLoc(loc), true);
|
|
1136
|
+
}
|
|
847
1137
|
}
|
|
848
1138
|
|
|
849
1139
|
// Add * symbol if there are CJS exports, no imports/exports at all, or the asset is wrapped.
|