@atlaspack/transformer-js 3.2.3-canary.34 → 3.2.3-canary.340

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.
@@ -4,8 +4,15 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
+ function _buildCache() {
8
+ const data = require("@atlaspack/build-cache");
9
+ _buildCache = function () {
10
+ return data;
11
+ };
12
+ return data;
13
+ }
7
14
  function _sourceMap() {
8
- const data = _interopRequireDefault(require("@parcel/source-map"));
15
+ const data = _interopRequireDefault(require("@atlaspack/source-map"));
9
16
  _sourceMap = function () {
10
17
  return data;
11
18
  };
@@ -25,6 +32,13 @@ function _rust() {
25
32
  };
26
33
  return data;
27
34
  }
35
+ function _assert() {
36
+ const data = _interopRequireDefault(require("assert"));
37
+ _assert = function () {
38
+ return data;
39
+ };
40
+ return data;
41
+ }
28
42
  function _browserslist() {
29
43
  const data = _interopRequireDefault(require("browserslist"));
30
44
  _browserslist = function () {
@@ -130,15 +144,25 @@ const CONFIG_SCHEMA = {
130
144
  }
131
145
  }]
132
146
  },
147
+ addReactDisplayName: {
148
+ type: 'boolean'
149
+ },
133
150
  magicComments: {
134
151
  type: 'boolean'
135
152
  },
136
153
  unstable_inlineConstants: {
137
154
  type: 'boolean'
155
+ },
156
+ jsx: {
157
+ type: 'object'
138
158
  }
139
159
  },
140
160
  additionalProperties: false
141
161
  };
162
+
163
+ // Mirrors the CONFIG_SCHEMA
164
+
165
+ const configCache = (0, _buildCache().createBuildCache)();
142
166
  const SCRIPT_ERRORS = {
143
167
  browser: {
144
168
  message: 'Browser scripts cannot have imports or exports.',
@@ -155,51 +179,100 @@ const SCRIPT_ERRORS = {
155
179
  };
156
180
 
157
181
  // NOTE: Make sure this is in sync with the TypeScript definition in the @atlaspack/macros package.
182
+
183
+ async function legacyDetemineJsxConfig(config, options) {
184
+ let packageJson = await config.getPackage();
185
+ let isJSX, jsxPragma, jsxPragmaFrag, jsxImportSource, automaticJSXRuntime, reactRefresh;
186
+ if (config.isSource) {
187
+ var _packageJson$dependen2, _packageJson$devDepen2, _packageJson$peerDepe2, _await$config$getConf;
188
+ let reactLib;
189
+ if (packageJson !== null && packageJson !== void 0 && packageJson.alias && packageJson.alias['react']) {
190
+ // e.g.: `{ alias: { "react": "preact/compat" } }`
191
+ reactLib = 'react';
192
+ } else {
193
+ // Find a dependency that we can map to a JSX pragma
194
+ reactLib = Object.keys(JSX_PRAGMA).find(libName => {
195
+ var _packageJson$dependen, _packageJson$devDepen, _packageJson$peerDepe;
196
+ 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]);
197
+ });
198
+ }
199
+ 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));
200
+ const compilerOptions = (_await$config$getConf = await config.getConfigFrom(options.projectRoot + '/index', ['tsconfig.json', 'jsconfig.json'], {
201
+ readTracking: true
202
+ })) === 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;
203
+
204
+ // Use explicitly defined JSX options in tsconfig.json over inferred values from dependencies.
205
+ jsxPragma = (compilerOptions === null || compilerOptions === void 0 ? void 0 : compilerOptions.jsxFactory) || (
206
+ // @ts-expect-error TS7053
207
+ reactLib ? JSX_PRAGMA[reactLib].pragma : undefined);
208
+ jsxPragmaFrag = (compilerOptions === null || compilerOptions === void 0 ? void 0 : compilerOptions.jsxFragmentFactory) || (
209
+ // @ts-expect-error TS7053
210
+ reactLib ? JSX_PRAGMA[reactLib].pragmaFrag : undefined);
211
+ 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) {
212
+ jsxImportSource = compilerOptions === null || compilerOptions === void 0 ? void 0 : compilerOptions.jsxImportSource;
213
+ automaticJSXRuntime = true;
214
+ } else if (reactLib) {
215
+ var _JSX_PRAGMA$effective, _packageJson$dependen3, _packageJson$devDepen3, _packageJson$peerDepe3, _semver$minVersion;
216
+ let effectiveReactLib = packageJson !== null && packageJson !== void 0 && packageJson.alias && packageJson.alias['react'] === 'preact/compat' ? 'preact' : reactLib;
217
+ // @ts-expect-error TS7053
218
+ let automaticVersion = (_JSX_PRAGMA$effective = JSX_PRAGMA[effectiveReactLib]) === null || _JSX_PRAGMA$effective === void 0 ? void 0 : _JSX_PRAGMA$effective.automatic;
219
+ 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]);
220
+ // @ts-expect-error TS2322
221
+ reactLibVersion = reactLibVersion ? _semver().default.validRange(reactLibVersion) : null;
222
+ let minReactLibVersion = reactLibVersion !== null && reactLibVersion !== '*' ? // @ts-expect-error TS2345
223
+ (_semver$minVersion = _semver().default.minVersion(reactLibVersion)) === null || _semver$minVersion === void 0 ? void 0 : _semver$minVersion.toString() : null;
224
+ automaticJSXRuntime = automaticVersion && !(compilerOptions !== null && compilerOptions !== void 0 && compilerOptions.jsxFactory) && minReactLibVersion != null && _semver().default.satisfies(minReactLibVersion, automaticVersion, {
225
+ includePrerelease: true
226
+ });
227
+ if (automaticJSXRuntime) {
228
+ jsxImportSource = reactLib;
229
+ }
230
+ }
231
+ isJSX = Boolean((compilerOptions === null || compilerOptions === void 0 ? void 0 : compilerOptions.jsx) || jsxPragma);
232
+ }
233
+ return {
234
+ isJSX,
235
+ jsxPragma,
236
+ jsxPragmaFrag,
237
+ jsxImportSource,
238
+ automaticJSXRuntime,
239
+ reactRefresh
240
+ };
241
+ }
158
242
  var _default = exports.default = new (_plugin().Transformer)({
159
243
  async loadConfig({
160
244
  config,
161
245
  options
162
246
  }) {
163
- let pkg = await config.getPackage();
164
- let isJSX, pragma, pragmaFrag, jsxImportSource, automaticJSXRuntime, reactRefresh, decorators, useDefineForClassFields;
247
+ var _conf$contents;
248
+ let conf = await config.getConfigFrom(options.projectRoot + '/index', [], {
249
+ packageKey: '@atlaspack/transformer-js'
250
+ });
251
+ if (conf && conf.contents) {
252
+ _utils().validateSchema.diagnostic(CONFIG_SCHEMA, {
253
+ data: conf.contents,
254
+ source: () => options.inputFS.readFileSync(conf.filePath, 'utf8'),
255
+ filePath: conf.filePath,
256
+ prependKey: `/${(0, _diagnostic().encodeJSONKeyComponent)('@atlaspack/transformer-js')}`
257
+ },
258
+ // FIXME
259
+ '@atlaspack/transformer-js', 'Invalid config for @atlaspack/transformer-js');
260
+ }
261
+ let packageJson = await config.getPackage();
262
+ let decorators, useDefineForClassFields;
263
+ let {
264
+ isJSX,
265
+ jsxPragma,
266
+ jsxPragmaFrag,
267
+ jsxImportSource,
268
+ automaticJSXRuntime,
269
+ reactRefresh
270
+ } = 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
271
  if (config.isSource) {
166
- var _pkg$dependencies2, _pkg$devDependencies2, _pkg$peerDependencies2, _tsconfig$contents;
167
- let reactLib;
168
- if (pkg !== null && pkg !== void 0 && pkg.alias && pkg.alias['react']) {
169
- // e.g.: `{ alias: { "react": "preact/compat" } }`
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
- let tsconfig = await config.getConfigFrom(options.projectRoot + '/index', ['tsconfig.json', 'jsconfig.json']);
180
- let compilerOptions = tsconfig === null || tsconfig === void 0 || (_tsconfig$contents = tsconfig.contents) === null || _tsconfig$contents === void 0 ? void 0 : _tsconfig$contents.compilerOptions;
181
-
182
- // Use explicitly defined JSX options in tsconfig.json over inferred values from dependencies.
183
- pragma = (compilerOptions === null || compilerOptions === void 0 ? void 0 : compilerOptions.jsxFactory) || (reactLib ? JSX_PRAGMA[reactLib].pragma : undefined);
184
- pragmaFrag = (compilerOptions === null || compilerOptions === void 0 ? void 0 : compilerOptions.jsxFragmentFactory) || (reactLib ? JSX_PRAGMA[reactLib].pragmaFrag : undefined);
185
- 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) {
186
- jsxImportSource = compilerOptions === null || compilerOptions === void 0 ? void 0 : compilerOptions.jsxImportSource;
187
- automaticJSXRuntime = true;
188
- } else if (reactLib) {
189
- var _JSX_PRAGMA$effective, _pkg$dependencies3, _pkg$devDependencies3, _pkg$peerDependencies3, _semver$minVersion;
190
- let effectiveReactLib = pkg !== null && pkg !== void 0 && pkg.alias && pkg.alias['react'] === 'preact/compat' ? 'preact' : reactLib;
191
- let automaticVersion = (_JSX_PRAGMA$effective = JSX_PRAGMA[effectiveReactLib]) === null || _JSX_PRAGMA$effective === void 0 ? void 0 : _JSX_PRAGMA$effective.automatic;
192
- 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]);
193
- reactLibVersion = reactLibVersion ? _semver().default.validRange(reactLibVersion) : null;
194
- let minReactLibVersion = reactLibVersion !== null && reactLibVersion !== '*' ? (_semver$minVersion = _semver().default.minVersion(reactLibVersion)) === null || _semver$minVersion === void 0 ? void 0 : _semver$minVersion.toString() : null;
195
- automaticJSXRuntime = automaticVersion && !(compilerOptions !== null && compilerOptions !== void 0 && compilerOptions.jsxFactory) && minReactLibVersion != null && _semver().default.satisfies(minReactLibVersion, automaticVersion, {
196
- includePrerelease: true
197
- });
198
- if (automaticJSXRuntime) {
199
- jsxImportSource = reactLib;
200
- }
201
- }
202
- isJSX = Boolean((compilerOptions === null || compilerOptions === void 0 ? void 0 : compilerOptions.jsx) || pragma);
272
+ var _await$config$getConf2;
273
+ const compilerOptions = (_await$config$getConf2 = await config.getConfigFrom(options.projectRoot + '/index', ['tsconfig.json', 'jsconfig.json'], {
274
+ readTracking: true
275
+ })) === 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;
203
276
  decorators = compilerOptions === null || compilerOptions === void 0 ? void 0 : compilerOptions.experimentalDecorators;
204
277
  useDefineForClassFields = compilerOptions === null || compilerOptions === void 0 ? void 0 : compilerOptions.useDefineForClassFields;
205
278
  if (useDefineForClassFields === undefined && (compilerOptions === null || compilerOptions === void 0 ? void 0 : compilerOptions.target) != null) {
@@ -215,43 +288,82 @@ var _default = exports.default = new (_plugin().Transformer)({
215
288
 
216
289
  // Check if we should ignore fs calls
217
290
  // See https://github.com/defunctzombie/node-browser-resolve#skip
218
- let ignoreFS = pkg && pkg.browser && typeof pkg.browser === 'object' && pkg.browser.fs === false;
219
- let conf = await config.getConfigFrom(options.projectRoot + '/index', [], {
220
- packageKey: '@atlaspack/transformer-js'
221
- });
291
+ let ignoreFS = packageJson && packageJson.browser && typeof packageJson.browser === 'object' && packageJson.browser.fs === false;
222
292
  let inlineEnvironment = config.isSource;
223
293
  let inlineFS = !ignoreFS;
224
294
  let inlineConstants = false;
225
295
  let magicComments = false;
296
+ let addReactDisplayName = false;
297
+ let enableSsrTypeofReplacement = options.env.NATIVE_SSR_TYPEOF_REPLACEMENT === 'true';
298
+ let globalAliasingConfig = options.env.NATIVE_GLOBAL_ALIASING && JSON.parse(options.env.NATIVE_GLOBAL_ALIASING);
299
+ let enableLazyLoading = options.env.NATIVE_LAZY_LOADING === 'true';
300
+ let enableReactHooksRemoval = options.env.NATIVE_REACT_HOOKS_REMOVAL === 'true';
301
+ let enableReactAsyncImportLift = options.env.NATIVE_REACT_ASYNC_IMPORT_LIFT === 'true';
302
+ let reactAsyncLiftByDefault = options.env.REACT_ASYNC_IMPORT_LIFTING_BY_DEFAULT === 'true';
303
+ let reactAsyncLiftReportLevel = options.env.REACT_ASYNC_LIFT_REPORT_LEVEL || 'none';
304
+ let enableStaticPrevaluation = options.env.NATIVE_PREVALUATION === 'true';
305
+ let enableDeadReturnsRemoval = options.env.NATIVE_DEAD_RETURNS_REMOVAL === 'true';
306
+ let enableUnusedBindingsRemoval = options.env.NATIVE_UNUSED_BINDINGS_REMOVAL === 'true';
307
+ let syncDynamicImportConfig;
308
+ if (config.env.isTesseract() && options.env.SYNC_DYNAMIC_IMPORT_CONFIG) {
309
+ try {
310
+ let config = configCache.get('SYNC_DYNAMIC_IMPORT_CONFIG');
311
+ if (!config) {
312
+ var _config;
313
+ config = JSON.parse(options.env.SYNC_DYNAMIC_IMPORT_CONFIG);
314
+ (0, _assert().default)(typeof ((_config = config) === null || _config === void 0 ? void 0 : _config.entrypoint_filepath_suffix) === 'string');
315
+ (0, _assert().default)(Array.isArray(config.actual_require_paths));
316
+ configCache.set('SYNC_DYNAMIC_IMPORT_CONFIG', config);
317
+ }
318
+ syncDynamicImportConfig = config;
319
+ } catch {
320
+ // eslint-disable-next-line no-console
321
+ console.warn('Failed to parse SYNC_DYNAMIC_IMPORT_CONFIG to JSON or config shape did not match. Config will not be applied.');
322
+ const fallback = {
323
+ entrypoint_filepath_suffix: '__NO_MATCH__',
324
+ actual_require_paths: []
325
+ };
326
+
327
+ // Set cache to fallback so we don't keep trying to parse.
328
+ configCache.set('SYNC_DYNAMIC_IMPORT_CONFIG', fallback);
329
+ syncDynamicImportConfig = fallback;
330
+ }
331
+ }
332
+ config.invalidateOnEnvChange('SYNC_DYNAMIC_IMPORT_CONFIG');
226
333
  if (conf && conf.contents) {
227
- var _conf$contents, _conf$contents2, _conf$contents3, _conf$contents4;
228
- _utils().validateSchema.diagnostic(CONFIG_SCHEMA, {
229
- data: conf.contents,
230
- // FIXME
231
- source: await options.inputFS.readFile(conf.filePath, 'utf8'),
232
- filePath: conf.filePath,
233
- prependKey: `/${(0, _diagnostic().encodeJSONKeyComponent)('@atlaspack/transformer-js')}`
234
- },
235
- // FIXME
236
- '@atlaspack/transformer-js', 'Invalid config for @atlaspack/transformer-js');
237
- magicComments = ((_conf$contents = conf.contents) === null || _conf$contents === void 0 ? void 0 : _conf$contents.magicComments) ?? magicComments;
238
- inlineEnvironment = ((_conf$contents2 = conf.contents) === null || _conf$contents2 === void 0 ? void 0 : _conf$contents2.inlineEnvironment) ?? inlineEnvironment;
239
- inlineFS = ((_conf$contents3 = conf.contents) === null || _conf$contents3 === void 0 ? void 0 : _conf$contents3.inlineFS) ?? inlineFS;
240
- inlineConstants = ((_conf$contents4 = conf.contents) === null || _conf$contents4 === void 0 ? void 0 : _conf$contents4.unstable_inlineConstants) ?? inlineConstants;
334
+ var _conf$contents2, _conf$contents3, _conf$contents4, _conf$contents5, _conf$contents6;
335
+ addReactDisplayName = ((_conf$contents2 = conf.contents) === null || _conf$contents2 === void 0 ? void 0 : _conf$contents2.addReactDisplayName) ?? addReactDisplayName;
336
+ magicComments = ((_conf$contents3 = conf.contents) === null || _conf$contents3 === void 0 ? void 0 : _conf$contents3.magicComments) ?? magicComments;
337
+ // @ts-expect-error TS2322
338
+ inlineEnvironment = ((_conf$contents4 = conf.contents) === null || _conf$contents4 === void 0 ? void 0 : _conf$contents4.inlineEnvironment) ?? inlineEnvironment;
339
+ inlineFS = ((_conf$contents5 = conf.contents) === null || _conf$contents5 === void 0 ? void 0 : _conf$contents5.inlineFS) ?? inlineFS;
340
+ inlineConstants = ((_conf$contents6 = conf.contents) === null || _conf$contents6 === void 0 ? void 0 : _conf$contents6.unstable_inlineConstants) ?? inlineConstants;
241
341
  }
242
342
  return {
243
343
  isJSX,
244
344
  automaticJSXRuntime,
245
345
  jsxImportSource,
246
- pragma,
247
- pragmaFrag,
346
+ pragma: jsxPragma,
347
+ pragmaFrag: jsxPragmaFrag,
248
348
  inlineEnvironment,
249
349
  inlineFS,
250
350
  inlineConstants,
351
+ addReactDisplayName,
251
352
  reactRefresh,
252
353
  decorators,
253
354
  useDefineForClassFields,
254
- magicComments
355
+ magicComments,
356
+ globalAliasingConfig,
357
+ enableSsrTypeofReplacement,
358
+ enableLazyLoading,
359
+ enableDeadReturnsRemoval,
360
+ enableUnusedBindingsRemoval,
361
+ enableStaticPrevaluation,
362
+ enableReactHooksRemoval,
363
+ syncDynamicImportConfig,
364
+ enableReactAsyncImportLift,
365
+ reactAsyncLiftByDefault,
366
+ reactAsyncLiftReportLevel
255
367
  };
256
368
  },
257
369
  async transform({
@@ -280,17 +392,22 @@ var _default = exports.default = new (_plugin().Transformer)({
280
392
  for (let browser of browsers) {
281
393
  let [name, version] = browser.split(' ');
282
394
  if (BROWSER_MAPPING.hasOwnProperty(name)) {
395
+ // @ts-expect-error TS7053
283
396
  name = BROWSER_MAPPING[name];
284
397
  if (!name) {
285
398
  continue;
286
399
  }
287
400
  }
288
401
  let [major, minor = '0', patch = '0'] = version.split('-')[0].split('.');
402
+ // @ts-expect-error TS2345
289
403
  if (isNaN(major) || isNaN(minor) || isNaN(patch)) {
290
404
  continue;
291
405
  }
292
406
  let semverVersion = `${major}.${minor}.${patch}`;
407
+
408
+ // @ts-expect-error TS2345
293
409
  if (targets[name] == null || _semver().default.gt(targets[name], semverVersion)) {
410
+ // @ts-expect-error TS7053
294
411
  targets[name] = semverVersion;
295
412
  }
296
413
  }
@@ -305,6 +422,9 @@ var _default = exports.default = new (_plugin().Transformer)({
305
422
  if (options.env.NODE_ENV != null) {
306
423
  env.NODE_ENV = options.env.NODE_ENV;
307
424
  }
425
+ if (process.env.ATLASPACK_BUILD_ENV === 'test') {
426
+ env.ATLASPACK_BUILD_ENV = 'test';
427
+ }
308
428
  } else if (Array.isArray(config === null || config === void 0 ? void 0 : config.inlineEnvironment)) {
309
429
  for (let match of (0, _utils().globMatch)(Object.keys(options.env), config.inlineEnvironment)) {
310
430
  env[match] = String(options.env[match]);
@@ -322,23 +442,40 @@ var _default = exports.default = new (_plugin().Transformer)({
322
442
  if (asset.type === 'ts') {
323
443
  isJSX = false;
324
444
  } else if (!isJSX) {
445
+ // @ts-expect-error TS7053
325
446
  isJSX = Boolean(JSX_EXTENSIONS[asset.type]);
326
447
  }
327
448
  }
328
449
  let macroAssets = [];
329
450
  let {
451
+ // @ts-expect-error TS2339
330
452
  dependencies,
453
+ // @ts-expect-error TS2339
331
454
  code: compiledCode,
455
+ // @ts-expect-error TS2339
332
456
  map,
457
+ // @ts-expect-error TS2339
333
458
  shebang,
459
+ // @ts-expect-error TS2339
334
460
  hoist_result,
461
+ // @ts-expect-error TS2339
335
462
  symbol_result,
463
+ // @ts-expect-error TS2339
464
+ is_empty_or_empty_export,
465
+ // @ts-expect-error TS2339
336
466
  needs_esm_helpers,
467
+ // @ts-expect-error TS2339
337
468
  diagnostics,
469
+ // @ts-expect-error TS2339
338
470
  used_env,
471
+ // @ts-expect-error TS2339
339
472
  has_node_replacements,
473
+ // @ts-expect-error TS2339
340
474
  is_constant_module,
341
- conditions
475
+ // @ts-expect-error TS2339
476
+ conditions,
477
+ // @ts-expect-error TS2339
478
+ magic_comments
342
479
  } = await (_rust().transformAsync || _rust().transform)({
343
480
  filename: asset.filePath,
344
481
  code,
@@ -349,7 +486,7 @@ var _default = exports.default = new (_plugin().Transformer)({
349
486
  insert_node_globals: !asset.env.isNode() && asset.env.sourceType !== 'script',
350
487
  node_replacer: asset.env.isNode(),
351
488
  is_browser: asset.env.isBrowser(),
352
- is_worker: asset.env.isWorker(),
489
+ is_worker: asset.env.isWorker() || asset.env.isTesseract(),
353
490
  env,
354
491
  is_type_script: asset.type === 'ts' || asset.type === 'tsx',
355
492
  is_jsx: isJSX,
@@ -358,7 +495,7 @@ var _default = exports.default = new (_plugin().Transformer)({
358
495
  automatic_jsx_runtime: Boolean(config === null || config === void 0 ? void 0 : config.automaticJSXRuntime),
359
496
  jsx_import_source: config === null || config === void 0 ? void 0 : config.jsxImportSource,
360
497
  is_development: options.mode === 'development',
361
- react_refresh: asset.env.isBrowser() && !asset.env.isLibrary && !asset.env.isWorker() && !asset.env.isWorklet() && Boolean(config === null || config === void 0 ? void 0 : config.reactRefresh),
498
+ 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'),
362
499
  decorators: Boolean(config === null || config === void 0 ? void 0 : config.decorators),
363
500
  use_define_for_class_fields: Boolean(config === null || config === void 0 ? void 0 : config.useDefineForClassFields),
364
501
  targets,
@@ -373,16 +510,30 @@ var _default = exports.default = new (_plugin().Transformer)({
373
510
  standalone: asset.query.has('standalone'),
374
511
  inline_constants: config.inlineConstants,
375
512
  conditional_bundling: options.featureFlags.conditionalBundlingApi,
376
- magic_comments: Boolean(config === null || config === void 0 ? void 0 : config.magicComments),
513
+ hmr_improvements: options.featureFlags.hmrImprovements,
514
+ add_display_name: Boolean(config.addReactDisplayName),
515
+ exports_rebinding_optimisation: options.featureFlags.exportsRebindingOptimisation,
516
+ magic_comments: Boolean(config === null || config === void 0 ? void 0 : config.magicComments) || (0, _featureFlags().getFeatureFlag)('supportWebpackChunkName'),
517
+ is_source: asset.isSource,
518
+ nested_promise_import_fix: options.featureFlags.nestedPromiseImportFix,
519
+ global_aliasing_config: config.globalAliasingConfig,
520
+ enable_ssr_typeof_replacement: Boolean(config.enableSsrTypeofReplacement),
521
+ enable_lazy_loading: Boolean(config.enableLazyLoading),
522
+ enable_dead_returns_removal: Boolean(config.enableDeadReturnsRemoval),
523
+ enable_unused_bindings_removal: Boolean(config.enableUnusedBindingsRemoval),
524
+ enable_static_prevaluation: Boolean(config.enableStaticPrevaluation),
525
+ enable_react_hooks_removal: Boolean(config.enableReactHooksRemoval),
526
+ enable_react_async_import_lift: Boolean(config.enableReactAsyncImportLift),
527
+ react_async_lift_by_default: Boolean(config.reactAsyncLiftByDefault),
528
+ react_async_lift_report_level: String(config.reactAsyncLiftReportLevel),
529
+ sync_dynamic_import_config: config.syncDynamicImportConfig,
377
530
  callMacro: asset.isSource ? async (err, src, exportName, args, loc) => {
378
531
  let mod;
379
532
  try {
380
533
  mod = await options.packageManager.require(src, asset.filePath);
381
534
 
382
535
  // Default interop for CommonJS modules.
383
- if (exportName === 'default' && !mod.__esModule &&
384
- // $FlowFixMe
385
- Object.prototype.toString.call(config) !== '[object Module]') {
536
+ if (exportName === 'default' && !mod.__esModule && Object.prototype.toString.call(config) !== '[object Module]') {
386
537
  mod = {
387
538
  default: mod
388
539
  };
@@ -398,7 +549,7 @@ var _default = exports.default = new (_plugin().Transformer)({
398
549
  }
399
550
  try {
400
551
  if (typeof mod[exportName] === 'function') {
401
- return mod[exportName].apply({
552
+ let ctx = {
402
553
  // Allows macros to emit additional assets to add as dependencies (e.g. css).
403
554
  addAsset(a) {
404
555
  let k = String(macroAssets.length);
@@ -406,6 +557,7 @@ var _default = exports.default = new (_plugin().Transformer)({
406
557
  if (asset.env.sourceMap) {
407
558
  // Generate a source map that maps each line of the asset to the original macro call.
408
559
  map = new (_sourceMap().default)(options.projectRoot);
560
+ // @ts-expect-error TS2304
409
561
  let mappings = [];
410
562
  let line = 1;
411
563
  for (let i = 0; i <= a.content.length; i++) {
@@ -428,7 +580,9 @@ var _default = exports.default = new (_plugin().Transformer)({
428
580
  if (originalMap) {
429
581
  map.extends(originalMap);
430
582
  } else {
431
- map.setSourceContent(asset.filePath, code.toString());
583
+ if (!(0, _featureFlags().getFeatureFlag)('omitSourcesContentInMemory')) {
584
+ map.setSourceContent(asset.filePath, code.toString());
585
+ }
432
586
  }
433
587
  }
434
588
  macroAssets.push({
@@ -457,7 +611,8 @@ var _default = exports.default = new (_plugin().Transformer)({
457
611
  invalidateOnBuild() {
458
612
  asset.invalidateOnBuild();
459
613
  }
460
- }, args);
614
+ };
615
+ return mod[exportName].apply(ctx, args);
461
616
  } else {
462
617
  throw new Error(`"${exportName}" in "${src}" is not a function.`);
463
618
  }
@@ -479,11 +634,7 @@ var _default = exports.default = new (_plugin().Transformer)({
479
634
  } : null
480
635
  });
481
636
  if ((0, _featureFlags().getFeatureFlag)('conditionalBundlingApi')) {
482
- asset.meta.conditions = conditions.map(c => ({
483
- key: c.key,
484
- ifTruePlaceholder: c.if_true_placeholder,
485
- ifFalsePlaceholder: c.if_false_placeholder
486
- }));
637
+ asset.meta.conditions = conditions;
487
638
  }
488
639
  if (is_constant_module) {
489
640
  asset.meta.isConstantModule = true;
@@ -503,17 +654,22 @@ var _default = exports.default = new (_plugin().Transformer)({
503
654
 
504
655
  // If there is an original source map, use it to remap to the original source location.
505
656
  if (originalMap) {
506
- location = (0, _utils().remapSourceLocation)(location, originalMap);
657
+ location = (0, _utils().remapSourceLocation)(location, originalMap, options.projectRoot);
507
658
  }
508
659
  return location;
509
660
  };
510
661
  if (diagnostics) {
511
- let errors = diagnostics.filter(d => d.severity === 'Error' || d.severity === 'SourceError' && asset.isSource);
512
- let warnings = diagnostics.filter(d => d.severity === 'Warning' || d.severity === 'SourceError' && !asset.isSource);
662
+ let errors = diagnostics.filter(
663
+ // @ts-expect-error TS7006
664
+ d => d.severity === 'Error' || d.severity === 'SourceError' && asset.isSource);
665
+ let warnings = diagnostics.filter(
666
+ // @ts-expect-error TS7006
667
+ d => d.severity === 'Warning' || d.severity === 'SourceError' && !asset.isSource);
513
668
  let convertDiagnostic = diagnostic => {
514
669
  var _diagnostic$code_high;
515
670
  let message = diagnostic.message;
516
671
  if (message === 'SCRIPT_ERROR') {
672
+ // @ts-expect-error TS7053
517
673
  let err = SCRIPT_ERRORS[asset.env.context];
518
674
  message = (err === null || err === void 0 ? void 0 : err.message) || SCRIPT_ERRORS.browser.message;
519
675
  }
@@ -536,6 +692,8 @@ var _default = exports.default = new (_plugin().Transformer)({
536
692
  codeHighlights: [(0, _diagnostic().convertSourceLocationToHighlight)(asset.env.loc, 'The environment was originally created here')]
537
693
  });
538
694
  }
695
+
696
+ // @ts-expect-error TS7053
539
697
  let err = SCRIPT_ERRORS[asset.env.context];
540
698
  if (err) {
541
699
  if (!res.hints) {
@@ -580,6 +738,7 @@ var _default = exports.default = new (_plugin().Transformer)({
580
738
  env: {
581
739
  context: 'web-worker',
582
740
  sourceType: dep.source_type === 'Module' ? 'module' : 'script',
741
+ // @ts-expect-error TS2322
583
742
  outputFormat,
584
743
  loc
585
744
  },
@@ -629,6 +788,13 @@ var _default = exports.default = new (_plugin().Transformer)({
629
788
  });
630
789
  } else if (dep.kind === 'File') {
631
790
  asset.invalidateOnFileChange(dep.specifier);
791
+ } else if (dep.kind === 'Id') {
792
+ // Record parcelRequire calls so that the dev packager can add them as dependencies.
793
+ // This allows the HMR runtime to collect parents across async boundaries (through runtimes).
794
+ // TODO: ideally this would result as an actual dep in the graph rather than asset.meta.
795
+ asset.meta.hmrDeps ??= [];
796
+ (0, _assert().default)(Array.isArray(asset.meta.hmrDeps));
797
+ asset.meta.hmrDeps.push(dep.specifier);
632
798
  } else {
633
799
  let meta = {
634
800
  kind: dep.kind
@@ -676,6 +842,12 @@ var _default = exports.default = new (_plugin().Transformer)({
676
842
  outputFormat,
677
843
  loc: convertLoc(dep.loc)
678
844
  };
845
+ if ((0, _featureFlags().getFeatureFlag)('supportWebpackChunkName')) {
846
+ let chunkName = magic_comments[dep.specifier];
847
+ if (chunkName) {
848
+ meta.chunkName = chunkName;
849
+ }
850
+ }
679
851
  }
680
852
 
681
853
  // Always bundle helpers, even with includeNodeModules: false, except if this is a library.
@@ -695,6 +867,7 @@ var _default = exports.default = new (_plugin().Transformer)({
695
867
  idx = dep.specifier.indexOf('/', idx + 1);
696
868
  }
697
869
  let module = idx >= 0 ? dep.specifier.slice(0, idx) : dep.specifier;
870
+ // @ts-expect-error TS7053
698
871
  range = _package.default.dependencies[module];
699
872
  }
700
873
  asset.addDependency({
@@ -706,6 +879,7 @@ var _default = exports.default = new (_plugin().Transformer)({
706
879
  meta,
707
880
  resolveFrom: isHelper ? __filename : undefined,
708
881
  range,
882
+ // @ts-expect-error TS2322
709
883
  env
710
884
  });
711
885
  }
@@ -717,10 +891,12 @@ var _default = exports.default = new (_plugin().Transformer)({
717
891
  exported,
718
892
  local,
719
893
  loc,
720
- is_esm
894
+ is_esm,
895
+ is_static_binding_safe
721
896
  } of hoist_result.exported_symbols) {
722
897
  asset.symbols.set(exported, local, convertLoc(loc), {
723
- isEsm: is_esm
898
+ isEsm: is_esm,
899
+ isStaticBindingSafe: is_static_binding_safe
724
900
  });
725
901
  }
726
902
 
@@ -802,6 +978,9 @@ var _default = exports.default = new (_plugin().Transformer)({
802
978
  // (and the asset has side effects), or the asset is wrapped.
803
979
  // This allows accessing symbols that don't exist without errors in symbol propagation.
804
980
  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('*')) {
981
+ if (is_empty_or_empty_export) {
982
+ asset.meta.emptyFileStarReexport = true;
983
+ }
805
984
  asset.symbols.set('*', `$${asset.id}$exports`);
806
985
  }
807
986
  asset.meta.hasCJSExports = hoist_result.has_cjs_exports;
@@ -0,0 +1,3 @@
1
+ import { Transformer } from '@atlaspack/plugin';
2
+ declare const _default: Transformer<unknown>;
3
+ export default _default;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaspack/transformer-js",
3
- "version": "3.2.3-canary.34+47310a406",
3
+ "version": "3.2.3-canary.340+4fc968d9e",
4
4
  "license": "(MIT OR Apache-2.0)",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -9,10 +9,12 @@
9
9
  "type": "git",
10
10
  "url": "https://github.com/atlassian-labs/atlaspack.git"
11
11
  },
12
- "main": "lib/JSTransformer.js",
13
- "source": "src/JSTransformer.js",
12
+ "main": "./lib/JSTransformer.js",
13
+ "source": "./src/JSTransformer.ts",
14
+ "types": "./lib/types/JSTransformer.d.ts",
14
15
  "scripts": {
15
- "test": "mocha"
16
+ "test": "mocha",
17
+ "build:lib": "gulp build --gulpfile ../../../gulpfile.js --cwd ."
16
18
  },
17
19
  "engines": {
18
20
  "node": ">= 16.0.0"
@@ -22,13 +24,14 @@
22
24
  "src"
23
25
  ],
24
26
  "dependencies": {
25
- "@atlaspack/diagnostic": "2.14.1-canary.102+47310a406",
26
- "@atlaspack/feature-flags": "2.14.1-canary.102+47310a406",
27
- "@atlaspack/plugin": "2.14.5-canary.34+47310a406",
28
- "@atlaspack/rust": "3.2.1-canary.34+47310a406",
29
- "@atlaspack/utils": "2.14.5-canary.34+47310a406",
30
- "@atlaspack/workers": "2.14.5-canary.34+47310a406",
31
- "@parcel/source-map": "^2.1.1",
27
+ "@atlaspack/build-cache": "2.13.3-canary.408+4fc968d9e",
28
+ "@atlaspack/diagnostic": "2.14.1-canary.408+4fc968d9e",
29
+ "@atlaspack/feature-flags": "2.14.1-canary.408+4fc968d9e",
30
+ "@atlaspack/plugin": "2.14.5-canary.340+4fc968d9e",
31
+ "@atlaspack/rust": "3.2.1-canary.340+4fc968d9e",
32
+ "@atlaspack/source-map": "3.2.3-canary.4119+4fc968d9e",
33
+ "@atlaspack/utils": "2.14.5-canary.340+4fc968d9e",
34
+ "@atlaspack/workers": "2.14.5-canary.340+4fc968d9e",
32
35
  "@swc/helpers": "^0.5.15",
33
36
  "browserslist": "^4.6.6",
34
37
  "nullthrows": "^1.1.1",
@@ -36,8 +39,8 @@
36
39
  "semver": "^7.5.2"
37
40
  },
38
41
  "peerDependencies": {
39
- "@atlaspack/core": "^2.13.1"
42
+ "@atlaspack/core": "2.31.1"
40
43
  },
41
44
  "type": "commonjs",
42
- "gitHead": "47310a406469632d857a2fc9f10d04c456ae4dfa"
43
- }
45
+ "gitHead": "4fc968d9e06ad96d371fa7bc9ea071fa99f0b7c6"
46
+ }