@atlaspack/transformer-js 3.2.3-canary.14 → 3.2.3-canary.141

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.
@@ -0,0 +1,3 @@
1
+ import { Transformer } from '@atlaspack/plugin';
2
+ declare const _default: Transformer<unknown>;
3
+ export default _default;
@@ -25,6 +25,13 @@ function _rust() {
25
25
  };
26
26
  return data;
27
27
  }
28
+ function _assert() {
29
+ const data = _interopRequireDefault(require("assert"));
30
+ _assert = function () {
31
+ return data;
32
+ };
33
+ return data;
34
+ }
28
35
  function _browserslist() {
29
36
  const data = _interopRequireDefault(require("browserslist"));
30
37
  _browserslist = function () {
@@ -160,38 +167,46 @@ var _default = exports.default = new (_plugin().Transformer)({
160
167
  config,
161
168
  options
162
169
  }) {
163
- let pkg = await config.getPackage();
170
+ let packageJson = await config.getPackage();
164
171
  let isJSX, pragma, pragmaFrag, jsxImportSource, automaticJSXRuntime, reactRefresh, decorators, useDefineForClassFields;
165
172
  if (config.isSource) {
166
- var _pkg$dependencies2, _pkg$devDependencies2, _pkg$peerDependencies2, _tsconfig$contents;
173
+ var _packageJson$dependen2, _packageJson$devDepen2, _packageJson$peerDepe2, _await$config$getConf;
167
174
  let reactLib;
168
- if (pkg !== null && pkg !== void 0 && pkg.alias && pkg.alias['react']) {
175
+ if (packageJson !== null && packageJson !== void 0 && packageJson.alias && packageJson.alias['react']) {
169
176
  // e.g.: `{ alias: { "react": "preact/compat" } }`
170
177
  reactLib = 'react';
171
178
  } else {
172
179
  // Find a dependency that we can map to a JSX pragma
173
180
  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]);
181
+ var _packageJson$dependen, _packageJson$devDepen, _packageJson$peerDepe;
182
+ 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]);
176
183
  });
177
184
  }
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;
185
+ reactRefresh = options.hmrOptions && options.mode === 'development' && 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));
186
+ const compilerOptions = (_await$config$getConf = await config.getConfigFrom(options.projectRoot + '/index', ['tsconfig.json', 'jsconfig.json'], {
187
+ readTracking: true
188
+ })) === 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;
181
189
 
182
190
  // 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);
191
+ pragma = (compilerOptions === null || compilerOptions === void 0 ? void 0 : compilerOptions.jsxFactory) || (
192
+ // @ts-expect-error TS7053
193
+ reactLib ? JSX_PRAGMA[reactLib].pragma : undefined);
194
+ pragmaFrag = (compilerOptions === null || compilerOptions === void 0 ? void 0 : compilerOptions.jsxFragmentFactory) || (
195
+ // @ts-expect-error TS7053
196
+ reactLib ? JSX_PRAGMA[reactLib].pragmaFrag : undefined);
185
197
  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
198
  jsxImportSource = compilerOptions === null || compilerOptions === void 0 ? void 0 : compilerOptions.jsxImportSource;
187
199
  automaticJSXRuntime = true;
188
200
  } 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;
201
+ var _JSX_PRAGMA$effective, _packageJson$dependen3, _packageJson$devDepen3, _packageJson$peerDepe3, _semver$minVersion;
202
+ let effectiveReactLib = packageJson !== null && packageJson !== void 0 && packageJson.alias && packageJson.alias['react'] === 'preact/compat' ? 'preact' : reactLib;
203
+ // @ts-expect-error TS7053
191
204
  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]);
205
+ 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]);
206
+ // @ts-expect-error TS2322
193
207
  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;
208
+ let minReactLibVersion = reactLibVersion !== null && reactLibVersion !== '*' ? // @ts-expect-error TS2345
209
+ (_semver$minVersion = _semver().default.minVersion(reactLibVersion)) === null || _semver$minVersion === void 0 ? void 0 : _semver$minVersion.toString() : null;
195
210
  automaticJSXRuntime = automaticVersion && !(compilerOptions !== null && compilerOptions !== void 0 && compilerOptions.jsxFactory) && minReactLibVersion != null && _semver().default.satisfies(minReactLibVersion, automaticVersion, {
196
211
  includePrerelease: true
197
212
  });
@@ -215,7 +230,7 @@ var _default = exports.default = new (_plugin().Transformer)({
215
230
 
216
231
  // Check if we should ignore fs calls
217
232
  // See https://github.com/defunctzombie/node-browser-resolve#skip
218
- let ignoreFS = pkg && pkg.browser && typeof pkg.browser === 'object' && pkg.browser.fs === false;
233
+ let ignoreFS = packageJson && packageJson.browser && typeof packageJson.browser === 'object' && packageJson.browser.fs === false;
219
234
  let conf = await config.getConfigFrom(options.projectRoot + '/index', [], {
220
235
  packageKey: '@atlaspack/transformer-js'
221
236
  });
@@ -234,10 +249,16 @@ var _default = exports.default = new (_plugin().Transformer)({
234
249
  },
235
250
  // FIXME
236
251
  '@atlaspack/transformer-js', 'Invalid config for @atlaspack/transformer-js');
252
+
253
+ // @ts-expect-error TS2339
237
254
  magicComments = ((_conf$contents = conf.contents) === null || _conf$contents === void 0 ? void 0 : _conf$contents.magicComments) ?? magicComments;
255
+ // @ts-expect-error TS2339
238
256
  inlineEnvironment = ((_conf$contents2 = conf.contents) === null || _conf$contents2 === void 0 ? void 0 : _conf$contents2.inlineEnvironment) ?? inlineEnvironment;
257
+ // @ts-expect-error TS2339
239
258
  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;
259
+ inlineConstants =
260
+ // @ts-expect-error TS2339
261
+ ((_conf$contents4 = conf.contents) === null || _conf$contents4 === void 0 ? void 0 : _conf$contents4.unstable_inlineConstants) ?? inlineConstants;
241
262
  }
242
263
  return {
243
264
  isJSX,
@@ -280,17 +301,22 @@ var _default = exports.default = new (_plugin().Transformer)({
280
301
  for (let browser of browsers) {
281
302
  let [name, version] = browser.split(' ');
282
303
  if (BROWSER_MAPPING.hasOwnProperty(name)) {
304
+ // @ts-expect-error TS7053
283
305
  name = BROWSER_MAPPING[name];
284
306
  if (!name) {
285
307
  continue;
286
308
  }
287
309
  }
288
310
  let [major, minor = '0', patch = '0'] = version.split('-')[0].split('.');
311
+ // @ts-expect-error TS2345
289
312
  if (isNaN(major) || isNaN(minor) || isNaN(patch)) {
290
313
  continue;
291
314
  }
292
315
  let semverVersion = `${major}.${minor}.${patch}`;
316
+
317
+ // @ts-expect-error TS2345
293
318
  if (targets[name] == null || _semver().default.gt(targets[name], semverVersion)) {
319
+ // @ts-expect-error TS7053
294
320
  targets[name] = semverVersion;
295
321
  }
296
322
  }
@@ -305,6 +331,9 @@ var _default = exports.default = new (_plugin().Transformer)({
305
331
  if (options.env.NODE_ENV != null) {
306
332
  env.NODE_ENV = options.env.NODE_ENV;
307
333
  }
334
+ if (process.env.ATLASPACK_BUILD_ENV === 'test') {
335
+ env.ATLASPACK_BUILD_ENV = 'test';
336
+ }
308
337
  } else if (Array.isArray(config === null || config === void 0 ? void 0 : config.inlineEnvironment)) {
309
338
  for (let match of (0, _utils().globMatch)(Object.keys(options.env), config.inlineEnvironment)) {
310
339
  env[match] = String(options.env[match]);
@@ -322,23 +351,40 @@ var _default = exports.default = new (_plugin().Transformer)({
322
351
  if (asset.type === 'ts') {
323
352
  isJSX = false;
324
353
  } else if (!isJSX) {
354
+ // @ts-expect-error TS7053
325
355
  isJSX = Boolean(JSX_EXTENSIONS[asset.type]);
326
356
  }
327
357
  }
328
358
  let macroAssets = [];
329
359
  let {
360
+ // @ts-expect-error TS2339
330
361
  dependencies,
362
+ // @ts-expect-error TS2339
331
363
  code: compiledCode,
364
+ // @ts-expect-error TS2339
332
365
  map,
366
+ // @ts-expect-error TS2339
333
367
  shebang,
368
+ // @ts-expect-error TS2339
334
369
  hoist_result,
370
+ // @ts-expect-error TS2339
335
371
  symbol_result,
372
+ // @ts-expect-error TS2339
373
+ is_empty_or_empty_export,
374
+ // @ts-expect-error TS2339
336
375
  needs_esm_helpers,
376
+ // @ts-expect-error TS2339
337
377
  diagnostics,
378
+ // @ts-expect-error TS2339
338
379
  used_env,
380
+ // @ts-expect-error TS2339
339
381
  has_node_replacements,
382
+ // @ts-expect-error TS2339
340
383
  is_constant_module,
341
- conditions
384
+ // @ts-expect-error TS2339
385
+ conditions,
386
+ // @ts-expect-error TS2339
387
+ magic_comments
342
388
  } = await (_rust().transformAsync || _rust().transform)({
343
389
  filename: asset.filePath,
344
390
  code,
@@ -373,16 +419,16 @@ var _default = exports.default = new (_plugin().Transformer)({
373
419
  standalone: asset.query.has('standalone'),
374
420
  inline_constants: config.inlineConstants,
375
421
  conditional_bundling: options.featureFlags.conditionalBundlingApi,
376
- magic_comments: Boolean(config === null || config === void 0 ? void 0 : config.magicComments),
422
+ hmr_improvements: options.featureFlags.hmrImprovements,
423
+ computed_properties_fix: options.featureFlags.unusedComputedPropertyFix,
424
+ magic_comments: Boolean(config === null || config === void 0 ? void 0 : config.magicComments) || (0, _featureFlags().getFeatureFlag)('supportWebpackChunkName'),
377
425
  callMacro: asset.isSource ? async (err, src, exportName, args, loc) => {
378
426
  let mod;
379
427
  try {
380
428
  mod = await options.packageManager.require(src, asset.filePath);
381
429
 
382
430
  // Default interop for CommonJS modules.
383
- if (exportName === 'default' && !mod.__esModule &&
384
- // $FlowFixMe
385
- Object.prototype.toString.call(config) !== '[object Module]') {
431
+ if (exportName === 'default' && !mod.__esModule && Object.prototype.toString.call(config) !== '[object Module]') {
386
432
  mod = {
387
433
  default: mod
388
434
  };
@@ -398,7 +444,7 @@ var _default = exports.default = new (_plugin().Transformer)({
398
444
  }
399
445
  try {
400
446
  if (typeof mod[exportName] === 'function') {
401
- return mod[exportName].apply({
447
+ let ctx = {
402
448
  // Allows macros to emit additional assets to add as dependencies (e.g. css).
403
449
  addAsset(a) {
404
450
  let k = String(macroAssets.length);
@@ -406,6 +452,7 @@ var _default = exports.default = new (_plugin().Transformer)({
406
452
  if (asset.env.sourceMap) {
407
453
  // Generate a source map that maps each line of the asset to the original macro call.
408
454
  map = new (_sourceMap().default)(options.projectRoot);
455
+ // @ts-expect-error TS2304
409
456
  let mappings = [];
410
457
  let line = 1;
411
458
  for (let i = 0; i <= a.content.length; i++) {
@@ -426,6 +473,7 @@ var _default = exports.default = new (_plugin().Transformer)({
426
473
  }
427
474
  map.addIndexedMappings(mappings);
428
475
  if (originalMap) {
476
+ // @ts-expect-error TS2345
429
477
  map.extends(originalMap);
430
478
  } else {
431
479
  map.setSourceContent(asset.filePath, code.toString());
@@ -457,7 +505,8 @@ var _default = exports.default = new (_plugin().Transformer)({
457
505
  invalidateOnBuild() {
458
506
  asset.invalidateOnBuild();
459
507
  }
460
- }, args);
508
+ };
509
+ return mod[exportName].apply(ctx, args);
461
510
  } else {
462
511
  throw new Error(`"${exportName}" in "${src}" is not a function.`);
463
512
  }
@@ -479,7 +528,9 @@ var _default = exports.default = new (_plugin().Transformer)({
479
528
  } : null
480
529
  });
481
530
  if ((0, _featureFlags().getFeatureFlag)('conditionalBundlingApi')) {
482
- asset.meta.conditions = conditions.map(c => ({
531
+ asset.meta.conditions = conditions.map(
532
+ // @ts-expect-error TS7006
533
+ c => ({
483
534
  key: c.key,
484
535
  ifTruePlaceholder: c.if_true_placeholder,
485
536
  ifFalsePlaceholder: c.if_false_placeholder
@@ -508,12 +559,17 @@ var _default = exports.default = new (_plugin().Transformer)({
508
559
  return location;
509
560
  };
510
561
  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);
562
+ let errors = diagnostics.filter(
563
+ // @ts-expect-error TS7006
564
+ d => d.severity === 'Error' || d.severity === 'SourceError' && asset.isSource);
565
+ let warnings = diagnostics.filter(
566
+ // @ts-expect-error TS7006
567
+ d => d.severity === 'Warning' || d.severity === 'SourceError' && !asset.isSource);
513
568
  let convertDiagnostic = diagnostic => {
514
569
  var _diagnostic$code_high;
515
570
  let message = diagnostic.message;
516
571
  if (message === 'SCRIPT_ERROR') {
572
+ // @ts-expect-error TS7053
517
573
  let err = SCRIPT_ERRORS[asset.env.context];
518
574
  message = (err === null || err === void 0 ? void 0 : err.message) || SCRIPT_ERRORS.browser.message;
519
575
  }
@@ -536,6 +592,8 @@ var _default = exports.default = new (_plugin().Transformer)({
536
592
  codeHighlights: [(0, _diagnostic().convertSourceLocationToHighlight)(asset.env.loc, 'The environment was originally created here')]
537
593
  });
538
594
  }
595
+
596
+ // @ts-expect-error TS7053
539
597
  let err = SCRIPT_ERRORS[asset.env.context];
540
598
  if (err) {
541
599
  if (!res.hints) {
@@ -580,6 +638,7 @@ var _default = exports.default = new (_plugin().Transformer)({
580
638
  env: {
581
639
  context: 'web-worker',
582
640
  sourceType: dep.source_type === 'Module' ? 'module' : 'script',
641
+ // @ts-expect-error TS2322
583
642
  outputFormat,
584
643
  loc
585
644
  },
@@ -629,6 +688,13 @@ var _default = exports.default = new (_plugin().Transformer)({
629
688
  });
630
689
  } else if (dep.kind === 'File') {
631
690
  asset.invalidateOnFileChange(dep.specifier);
691
+ } else if (dep.kind === 'Id') {
692
+ // Record parcelRequire calls so that the dev packager can add them as dependencies.
693
+ // This allows the HMR runtime to collect parents across async boundaries (through runtimes).
694
+ // TODO: ideally this would result as an actual dep in the graph rather than asset.meta.
695
+ asset.meta.hmrDeps ??= [];
696
+ (0, _assert().default)(Array.isArray(asset.meta.hmrDeps));
697
+ asset.meta.hmrDeps.push(dep.specifier);
632
698
  } else {
633
699
  let meta = {
634
700
  kind: dep.kind
@@ -676,6 +742,12 @@ var _default = exports.default = new (_plugin().Transformer)({
676
742
  outputFormat,
677
743
  loc: convertLoc(dep.loc)
678
744
  };
745
+ if ((0, _featureFlags().getFeatureFlag)('supportWebpackChunkName')) {
746
+ let chunkName = magic_comments[dep.specifier];
747
+ if (chunkName) {
748
+ meta.chunkName = chunkName;
749
+ }
750
+ }
679
751
  }
680
752
 
681
753
  // Always bundle helpers, even with includeNodeModules: false, except if this is a library.
@@ -695,6 +767,7 @@ var _default = exports.default = new (_plugin().Transformer)({
695
767
  idx = dep.specifier.indexOf('/', idx + 1);
696
768
  }
697
769
  let module = idx >= 0 ? dep.specifier.slice(0, idx) : dep.specifier;
770
+ // @ts-expect-error TS7053
698
771
  range = _package.default.dependencies[module];
699
772
  }
700
773
  asset.addDependency({
@@ -706,6 +779,7 @@ var _default = exports.default = new (_plugin().Transformer)({
706
779
  meta,
707
780
  resolveFrom: isHelper ? __filename : undefined,
708
781
  range,
782
+ // @ts-expect-error TS2322
709
783
  env
710
784
  });
711
785
  }
@@ -752,11 +826,14 @@ var _default = exports.default = new (_plugin().Transformer)({
752
826
  let dep = deps.get(source);
753
827
  if (!dep) continue;
754
828
  if (local === '*' && imported === '*') {
829
+ // @ts-expect-error TS2345
755
830
  dep.symbols.set('*', '*', convertLoc(loc), true);
756
831
  } else {
757
832
  var _dep$symbols$get;
758
833
  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}`;
834
+ // @ts-expect-error TS2345
759
835
  asset.symbols.set(local, reExportName);
836
+ // @ts-expect-error TS2345
760
837
  dep.symbols.set(imported, reExportName, convertLoc(loc), true);
761
838
  }
762
839
  }
@@ -774,7 +851,9 @@ var _default = exports.default = new (_plugin().Transformer)({
774
851
  let symbols = new Map();
775
852
  for (let name of hoist_result.self_references) {
776
853
  // Do not create a self-reference for the `default` symbol unless we have seen an __esModule flag.
777
- if (name === 'default' && !asset.symbols.hasExportSymbol('__esModule')) {
854
+ if (name === 'default' &&
855
+ // @ts-expect-error TS2345
856
+ !asset.symbols.hasExportSymbol('__esModule')) {
778
857
  continue;
779
858
  }
780
859
  let local = (0, _nullthrows().default)(asset.symbols.get(name)).local;
@@ -801,7 +880,13 @@ var _default = exports.default = new (_plugin().Transformer)({
801
880
  // Add * symbol if there are CJS exports, no imports/exports at all
802
881
  // (and the asset has side effects), or the asset is wrapped.
803
882
  // This allows accessing symbols that don't exist without errors in symbol propagation.
804
- 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('*')) {
883
+ if (hoist_result.has_cjs_exports || !hoist_result.is_esm && asset.sideEffects && deps.size === 0 && Object.keys(hoist_result.exported_symbols).length === 0 ||
884
+ // @ts-expect-error TS2345
885
+ hoist_result.should_wrap && !asset.symbols.hasExportSymbol('*')) {
886
+ if (is_empty_or_empty_export) {
887
+ asset.meta.emptyFileStarReexport = true;
888
+ }
889
+ // @ts-expect-error TS2345
805
890
  asset.symbols.set('*', `$${asset.id}$exports`);
806
891
  }
807
892
  asset.meta.hasCJSExports = hoist_result.has_cjs_exports;
@@ -818,10 +903,14 @@ var _default = exports.default = new (_plugin().Transformer)({
818
903
  source
819
904
  } of symbol_result.exports) {
820
905
  let dep = source ? deps.get(source) : undefined;
821
- asset.symbols.set(exported, `${(dep === null || dep === void 0 ? void 0 : dep.id) ?? ''}$${local}`, convertLoc(loc));
906
+ asset.symbols.set(exported,
907
+ // @ts-expect-error TS2345
908
+ `${(dep === null || dep === void 0 ? void 0 : dep.id) ?? ''}$${local}`, convertLoc(loc));
822
909
  if (dep != null) {
823
910
  dep.symbols.ensure();
824
- dep.symbols.set(local, `${(dep === null || dep === void 0 ? void 0 : dep.id) ?? ''}$${local}`, convertLoc(loc), true);
911
+ dep.symbols.set(local,
912
+ // @ts-expect-error TS2345
913
+ `${(dep === null || dep === void 0 ? void 0 : dep.id) ?? ''}$${local}`, convertLoc(loc), true);
825
914
  }
826
915
  }
827
916
  for (let {
@@ -842,18 +931,23 @@ var _default = exports.default = new (_plugin().Transformer)({
842
931
  let dep = deps.get(source);
843
932
  if (!dep) continue;
844
933
  dep.symbols.ensure();
934
+ // @ts-expect-error TS2345
845
935
  dep.symbols.set('*', '*', convertLoc(loc), true);
846
936
  }
847
937
 
848
938
  // Add * symbol if there are CJS exports, no imports/exports at all, or the asset is wrapped.
849
939
  // This allows accessing symbols that don't exist without errors in symbol propagation.
850
- if (symbol_result.has_cjs_exports || !symbol_result.is_esm && deps.size === 0 && symbol_result.exports.length === 0 || symbol_result.should_wrap && !asset.symbols.hasExportSymbol('*')) {
940
+ if (symbol_result.has_cjs_exports || !symbol_result.is_esm && deps.size === 0 && symbol_result.exports.length === 0 ||
941
+ // @ts-expect-error TS2345
942
+ symbol_result.should_wrap && !asset.symbols.hasExportSymbol('*')) {
851
943
  asset.symbols.ensure();
944
+ // @ts-expect-error TS2345
852
945
  asset.symbols.set('*', `$${asset.id}$exports`);
853
946
  }
854
947
  } else {
855
948
  // If the asset is wrapped, add * as a fallback
856
949
  asset.symbols.ensure();
950
+ // @ts-expect-error TS2345
857
951
  asset.symbols.set('*', `$${asset.id}$exports`);
858
952
  }
859
953
 
@@ -862,6 +956,7 @@ var _default = exports.default = new (_plugin().Transformer)({
862
956
  for (let dep of asset.getDependencies()) {
863
957
  if (dep.symbols.isCleared) {
864
958
  dep.symbols.ensure();
959
+ // @ts-expect-error TS2345
865
960
  dep.symbols.set('*', `${dep.id}$`);
866
961
  }
867
962
  }
@@ -884,6 +979,7 @@ var _default = exports.default = new (_plugin().Transformer)({
884
979
  let sourceMap = new (_sourceMap().default)(options.projectRoot);
885
980
  sourceMap.addVLQMap(JSON.parse(map));
886
981
  if (originalMap) {
982
+ // @ts-expect-error TS2345
887
983
  sourceMap.extends(originalMap);
888
984
  }
889
985
  asset.setMap(sourceMap);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaspack/transformer-js",
3
- "version": "3.2.3-canary.14+267b0d591",
3
+ "version": "3.2.3-canary.141+2f29297bd",
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/JSTransformer.d.ts",
14
15
  "scripts": {
15
- "test": "mocha"
16
+ "test": "mocha",
17
+ "check-ts": "tsc --emitDeclarationOnly --rootDir src"
16
18
  },
17
19
  "engines": {
18
20
  "node": ">= 16.0.0"
@@ -22,12 +24,12 @@
22
24
  "src"
23
25
  ],
24
26
  "dependencies": {
25
- "@atlaspack/diagnostic": "2.14.1-canary.82+267b0d591",
26
- "@atlaspack/feature-flags": "2.14.1-canary.82+267b0d591",
27
- "@atlaspack/plugin": "2.14.5-canary.14+267b0d591",
28
- "@atlaspack/rust": "3.2.1-canary.14+267b0d591",
29
- "@atlaspack/utils": "2.14.5-canary.14+267b0d591",
30
- "@atlaspack/workers": "2.14.5-canary.14+267b0d591",
27
+ "@atlaspack/diagnostic": "2.14.1-canary.209+2f29297bd",
28
+ "@atlaspack/feature-flags": "2.14.1-canary.209+2f29297bd",
29
+ "@atlaspack/plugin": "2.14.5-canary.141+2f29297bd",
30
+ "@atlaspack/rust": "3.2.1-canary.141+2f29297bd",
31
+ "@atlaspack/utils": "2.14.5-canary.141+2f29297bd",
32
+ "@atlaspack/workers": "2.14.5-canary.141+2f29297bd",
31
33
  "@parcel/source-map": "^2.1.1",
32
34
  "@swc/helpers": "^0.5.15",
33
35
  "browserslist": "^4.6.6",
@@ -39,5 +41,5 @@
39
41
  "@atlaspack/core": "^2.13.1"
40
42
  },
41
43
  "type": "commonjs",
42
- "gitHead": "267b0d59131c00e4cd1526bbf87aa84b9c8fd411"
43
- }
44
+ "gitHead": "2f29297bd550840c9840871559349ef773bcbf6d"
45
+ }
@@ -1,4 +1,3 @@
1
- // @flow
2
1
  import type {
3
2
  JSONObject,
4
3
  EnvMap,
@@ -12,6 +11,7 @@ import type {Diagnostic} from '@atlaspack/diagnostic';
12
11
  import SourceMap from '@parcel/source-map';
13
12
  import {Transformer} from '@atlaspack/plugin';
14
13
  import {transform, transformAsync} from '@atlaspack/rust';
14
+ import invariant from 'assert';
15
15
  import browserslist from 'browserslist';
16
16
  import semver from 'semver';
17
17
  import nullthrows from 'nullthrows';
@@ -26,7 +26,7 @@ import {getFeatureFlag} from '@atlaspack/feature-flags';
26
26
  const JSX_EXTENSIONS = {
27
27
  jsx: true,
28
28
  tsx: true,
29
- };
29
+ } as const;
30
30
 
31
31
  const JSX_PRAGMA = {
32
32
  react: {
@@ -49,7 +49,7 @@ const JSX_PRAGMA = {
49
49
  pragmaFrag: undefined,
50
50
  automatic: undefined,
51
51
  },
52
- };
52
+ } as const;
53
53
 
54
54
  const BROWSER_MAPPING = {
55
55
  and_chr: 'chrome',
@@ -63,7 +63,7 @@ const BROWSER_MAPPING = {
63
63
  bb: null,
64
64
  kaios: null,
65
65
  op_mini: null,
66
- };
66
+ } as const;
67
67
 
68
68
  // List of browsers to exclude when the esmodule target is specified.
69
69
  // Based on https://caniuse.com/#feat=es6-module
@@ -133,47 +133,45 @@ const SCRIPT_ERRORS = {
133
133
  'Service workers cannot have imports or exports without the `type: "module"` option.',
134
134
  hint: "Add {type: 'module'} as a second argument to the navigator.serviceWorker.register() call.",
135
135
  },
136
- };
136
+ } as const;
137
137
 
138
138
  type TSConfig = {
139
139
  compilerOptions?: {
140
140
  // https://www.typescriptlang.org/tsconfig#jsx
141
- jsx?: 'react' | 'react-jsx' | 'react-jsxdev' | 'preserve' | 'react-native',
141
+ jsx?: 'react' | 'react-jsx' | 'react-jsxdev' | 'preserve' | 'react-native';
142
142
  // https://www.typescriptlang.org/tsconfig#jsxFactory
143
- jsxFactory?: string,
143
+ jsxFactory?: string;
144
144
  // https://www.typescriptlang.org/tsconfig#jsxFragmentFactory
145
- jsxFragmentFactory?: string,
145
+ jsxFragmentFactory?: string;
146
146
  // https://www.typescriptlang.org/tsconfig#jsxImportSource
147
- jsxImportSource?: string,
147
+ jsxImportSource?: string;
148
148
  // https://www.typescriptlang.org/tsconfig#experimentalDecorators
149
- experimentalDecorators?: boolean,
149
+ experimentalDecorators?: boolean;
150
150
  // https://www.typescriptlang.org/tsconfig#useDefineForClassFields
151
- useDefineForClassFields?: boolean,
151
+ useDefineForClassFields?: boolean;
152
152
  // https://www.typescriptlang.org/tsconfig#target
153
- target?: string, // 'es3' | 'es5' | 'es6' | 'es2015' | ... |'es2022' | ... | 'esnext'
154
- ...
155
- },
156
- ...
153
+ target?: string; // 'es3' | 'es5' | 'es6' | 'es2015' | ... |'es2022' | ... | 'esnext';
154
+ };
157
155
  };
158
156
 
159
- type MacroAsset = {|
160
- type: string,
161
- content: string,
162
- |};
157
+ type MacroAsset = {
158
+ type: string;
159
+ content: string;
160
+ };
163
161
 
164
162
  // NOTE: Make sure this is in sync with the TypeScript definition in the @atlaspack/macros package.
165
- type MacroContext = {|
166
- addAsset(asset: MacroAsset): void,
167
- invalidateOnFileChange(FilePath): void,
168
- invalidateOnFileCreate(FileCreateInvalidation): void,
169
- invalidateOnEnvChange(string): void,
170
- invalidateOnStartup(): void,
171
- invalidateOnBuild(): void,
172
- |};
173
-
174
- export default (new Transformer({
163
+ type MacroContext = {
164
+ addAsset(asset: MacroAsset): void;
165
+ invalidateOnFileChange(arg1: FilePath): void;
166
+ invalidateOnFileCreate(arg1: FileCreateInvalidation): void;
167
+ invalidateOnEnvChange(arg1: string): void;
168
+ invalidateOnStartup(): void;
169
+ invalidateOnBuild(): void;
170
+ };
171
+
172
+ export default new Transformer({
175
173
  async loadConfig({config, options}) {
176
- let pkg = await config.getPackage();
174
+ let packageJson = await config.getPackage();
177
175
  let isJSX,
178
176
  pragma,
179
177
  pragmaFrag,
@@ -184,16 +182,16 @@ export default (new Transformer({
184
182
  useDefineForClassFields;
185
183
  if (config.isSource) {
186
184
  let reactLib;
187
- if (pkg?.alias && pkg.alias['react']) {
185
+ if (packageJson?.alias && packageJson.alias['react']) {
188
186
  // e.g.: `{ alias: { "react": "preact/compat" } }`
189
187
  reactLib = 'react';
190
188
  } else {
191
189
  // Find a dependency that we can map to a JSX pragma
192
190
  reactLib = Object.keys(JSX_PRAGMA).find(
193
191
  (libName) =>
194
- pkg?.dependencies?.[libName] ||
195
- pkg?.devDependencies?.[libName] ||
196
- pkg?.peerDependencies?.[libName],
192
+ packageJson?.dependencies?.[libName] ||
193
+ packageJson?.devDependencies?.[libName] ||
194
+ packageJson?.peerDependencies?.[libName],
197
195
  );
198
196
  }
199
197
 
@@ -201,23 +199,29 @@ export default (new Transformer({
201
199
  options.hmrOptions &&
202
200
  options.mode === 'development' &&
203
201
  Boolean(
204
- pkg?.dependencies?.react ||
205
- pkg?.devDependencies?.react ||
206
- pkg?.peerDependencies?.react,
202
+ packageJson?.dependencies?.react ||
203
+ packageJson?.devDependencies?.react ||
204
+ packageJson?.peerDependencies?.react,
207
205
  );
208
206
 
209
- let tsconfig = await config.getConfigFrom<TSConfig>(
210
- options.projectRoot + '/index',
211
- ['tsconfig.json', 'jsconfig.json'],
212
- );
213
- let compilerOptions = tsconfig?.contents?.compilerOptions;
207
+ const compilerOptions: TSConfig['compilerOptions'] = (
208
+ await config.getConfigFrom<TSConfig>(
209
+ options.projectRoot + '/index',
210
+ ['tsconfig.json', 'jsconfig.json'],
211
+ {
212
+ readTracking: true,
213
+ },
214
+ )
215
+ )?.contents?.compilerOptions;
214
216
 
215
217
  // Use explicitly defined JSX options in tsconfig.json over inferred values from dependencies.
216
218
  pragma =
217
219
  compilerOptions?.jsxFactory ||
220
+ // @ts-expect-error TS7053
218
221
  (reactLib ? JSX_PRAGMA[reactLib].pragma : undefined);
219
222
  pragmaFrag =
220
223
  compilerOptions?.jsxFragmentFactory ||
224
+ // @ts-expect-error TS7053
221
225
  (reactLib ? JSX_PRAGMA[reactLib].pragmaFrag : undefined);
222
226
 
223
227
  if (
@@ -229,20 +233,23 @@ export default (new Transformer({
229
233
  automaticJSXRuntime = true;
230
234
  } else if (reactLib) {
231
235
  let effectiveReactLib =
232
- pkg?.alias && pkg.alias['react'] === 'preact/compat'
236
+ packageJson?.alias && packageJson.alias['react'] === 'preact/compat'
233
237
  ? 'preact'
234
238
  : reactLib;
239
+ // @ts-expect-error TS7053
235
240
  let automaticVersion = JSX_PRAGMA[effectiveReactLib]?.automatic;
236
241
  let reactLibVersion =
237
- pkg?.dependencies?.[effectiveReactLib] ||
238
- pkg?.devDependencies?.[effectiveReactLib] ||
239
- pkg?.peerDependencies?.[effectiveReactLib];
242
+ packageJson?.dependencies?.[effectiveReactLib] ||
243
+ packageJson?.devDependencies?.[effectiveReactLib] ||
244
+ packageJson?.peerDependencies?.[effectiveReactLib];
245
+ // @ts-expect-error TS2322
240
246
  reactLibVersion = reactLibVersion
241
247
  ? semver.validRange(reactLibVersion)
242
248
  : null;
243
249
  let minReactLibVersion =
244
250
  reactLibVersion !== null && reactLibVersion !== '*'
245
- ? semver.minVersion(reactLibVersion)?.toString()
251
+ ? // @ts-expect-error TS2345
252
+ semver.minVersion(reactLibVersion)?.toString()
246
253
  : null;
247
254
 
248
255
  automaticJSXRuntime =
@@ -278,10 +285,10 @@ export default (new Transformer({
278
285
  // Check if we should ignore fs calls
279
286
  // See https://github.com/defunctzombie/node-browser-resolve#skip
280
287
  let ignoreFS =
281
- pkg &&
282
- pkg.browser &&
283
- typeof pkg.browser === 'object' &&
284
- pkg.browser.fs === false;
288
+ packageJson &&
289
+ packageJson.browser &&
290
+ typeof packageJson.browser === 'object' &&
291
+ packageJson.browser.fs === false;
285
292
 
286
293
  let conf = await config.getConfigFrom(options.projectRoot + '/index', [], {
287
294
  packageKey: '@atlaspack/transformer-js',
@@ -307,10 +314,14 @@ export default (new Transformer({
307
314
  'Invalid config for @atlaspack/transformer-js',
308
315
  );
309
316
 
317
+ // @ts-expect-error TS2339
310
318
  magicComments = conf.contents?.magicComments ?? magicComments;
319
+ // @ts-expect-error TS2339
311
320
  inlineEnvironment = conf.contents?.inlineEnvironment ?? inlineEnvironment;
321
+ // @ts-expect-error TS2339
312
322
  inlineFS = conf.contents?.inlineFS ?? inlineFS;
313
323
  inlineConstants =
324
+ // @ts-expect-error TS2339
314
325
  conf.contents?.unstable_inlineConstants ?? inlineConstants;
315
326
  }
316
327
 
@@ -357,6 +368,7 @@ export default (new Transformer({
357
368
  for (let browser of browsers) {
358
369
  let [name, version] = browser.split(' ');
359
370
  if (BROWSER_MAPPING.hasOwnProperty(name)) {
371
+ // @ts-expect-error TS7053
360
372
  name = BROWSER_MAPPING[name];
361
373
  if (!name) {
362
374
  continue;
@@ -366,12 +378,15 @@ export default (new Transformer({
366
378
  let [major, minor = '0', patch = '0'] = version
367
379
  .split('-')[0]
368
380
  .split('.');
381
+ // @ts-expect-error TS2345
369
382
  if (isNaN(major) || isNaN(minor) || isNaN(patch)) {
370
383
  continue;
371
384
  }
372
385
  let semverVersion = `${major}.${minor}.${patch}`;
373
386
 
387
+ // @ts-expect-error TS2345
374
388
  if (targets[name] == null || semver.gt(targets[name], semverVersion)) {
389
+ // @ts-expect-error TS7053
375
390
  targets[name] = semverVersion;
376
391
  }
377
392
  }
@@ -411,24 +426,47 @@ export default (new Transformer({
411
426
  if (asset.type === 'ts') {
412
427
  isJSX = false;
413
428
  } else if (!isJSX) {
429
+ // @ts-expect-error TS7053
414
430
  isJSX = Boolean(JSX_EXTENSIONS[asset.type]);
415
431
  }
416
432
  }
417
433
 
418
- let macroAssets = [];
434
+ let macroAssets: Array<{
435
+ content: string;
436
+ // @ts-expect-error TS2552
437
+ map: undefined | NodeSourceMap;
438
+ type: string;
439
+ uniqueKey: string;
440
+ }> = [];
419
441
  let {
442
+ // @ts-expect-error TS2339
420
443
  dependencies,
444
+ // @ts-expect-error TS2339
421
445
  code: compiledCode,
446
+ // @ts-expect-error TS2339
422
447
  map,
448
+ // @ts-expect-error TS2339
423
449
  shebang,
450
+ // @ts-expect-error TS2339
424
451
  hoist_result,
452
+ // @ts-expect-error TS2339
425
453
  symbol_result,
454
+ // @ts-expect-error TS2339
455
+ is_empty_or_empty_export,
456
+ // @ts-expect-error TS2339
426
457
  needs_esm_helpers,
458
+ // @ts-expect-error TS2339
427
459
  diagnostics,
460
+ // @ts-expect-error TS2339
428
461
  used_env,
462
+ // @ts-expect-error TS2339
429
463
  has_node_replacements,
464
+ // @ts-expect-error TS2339
430
465
  is_constant_module,
466
+ // @ts-expect-error TS2339
431
467
  conditions,
468
+ // @ts-expect-error TS2339
469
+ magic_comments,
432
470
  } = await (transformAsync || transform)({
433
471
  filename: asset.filePath,
434
472
  code,
@@ -470,9 +508,13 @@ export default (new Transformer({
470
508
  standalone: asset.query.has('standalone'),
471
509
  inline_constants: config.inlineConstants,
472
510
  conditional_bundling: options.featureFlags.conditionalBundlingApi,
473
- magic_comments: Boolean(config?.magicComments),
511
+ hmr_improvements: options.featureFlags.hmrImprovements,
512
+ computed_properties_fix: options.featureFlags.unusedComputedPropertyFix,
513
+ magic_comments:
514
+ Boolean(config?.magicComments) ||
515
+ getFeatureFlag('supportWebpackChunkName'),
474
516
  callMacro: asset.isSource
475
- ? async (err, src, exportName, args, loc) => {
517
+ ? async (err: any, src: any, exportName: any, args: any, loc: any) => {
476
518
  let mod;
477
519
  try {
478
520
  mod = await options.packageManager.require(src, asset.filePath);
@@ -481,7 +523,6 @@ export default (new Transformer({
481
523
  if (
482
524
  exportName === 'default' &&
483
525
  !mod.__esModule &&
484
- // $FlowFixMe
485
526
  Object.prototype.toString.call(config) !== '[object Module]'
486
527
  ) {
487
528
  mod = {default: mod};
@@ -490,7 +531,7 @@ export default (new Transformer({
490
531
  if (!Object.hasOwnProperty.call(mod, exportName)) {
491
532
  throw new Error(`"${src}" does not export "${exportName}".`);
492
533
  }
493
- } catch (err) {
534
+ } catch (err: any) {
494
535
  throw {
495
536
  kind: 1,
496
537
  message: err.message,
@@ -507,7 +548,8 @@ export default (new Transformer({
507
548
  if (asset.env.sourceMap) {
508
549
  // Generate a source map that maps each line of the asset to the original macro call.
509
550
  map = new SourceMap(options.projectRoot);
510
- let mappings = [];
551
+ // @ts-expect-error TS2304
552
+ let mappings: Array<IndexedMapping<string>> = [];
511
553
  let line = 1;
512
554
  for (let i = 0; i <= a.content.length; i++) {
513
555
  if (i === a.content.length || a.content[i] === '\n') {
@@ -528,6 +570,7 @@ export default (new Transformer({
528
570
 
529
571
  map.addIndexedMappings(mappings);
530
572
  if (originalMap) {
573
+ // @ts-expect-error TS2345
531
574
  map.extends(originalMap);
532
575
  } else {
533
576
  map.setSourceContent(asset.filePath, code.toString());
@@ -546,13 +589,13 @@ export default (new Transformer({
546
589
  specifierType: 'esm',
547
590
  });
548
591
  },
549
- invalidateOnFileChange(filePath) {
592
+ invalidateOnFileChange(filePath: FilePath) {
550
593
  asset.invalidateOnFileChange(filePath);
551
594
  },
552
- invalidateOnFileCreate(invalidation) {
595
+ invalidateOnFileCreate(invalidation: FileCreateInvalidation) {
553
596
  asset.invalidateOnFileCreate(invalidation);
554
597
  },
555
- invalidateOnEnvChange(env) {
598
+ invalidateOnEnvChange(env: string) {
556
599
  asset.invalidateOnEnvChange(env);
557
600
  },
558
601
  invalidateOnStartup() {
@@ -569,7 +612,7 @@ export default (new Transformer({
569
612
  `"${exportName}" in "${src}" is not a function.`,
570
613
  );
571
614
  }
572
- } catch (err) {
615
+ } catch (err: any) {
573
616
  // Remove atlaspack core from stack and build string so Rust can process errors more easily.
574
617
  let stack = (err.stack || '').split('\n').slice(1);
575
618
  let message = err.message;
@@ -589,18 +632,21 @@ export default (new Transformer({
589
632
  });
590
633
 
591
634
  if (getFeatureFlag('conditionalBundlingApi')) {
592
- asset.meta.conditions = conditions.map((c): ConditionMeta => ({
593
- key: c.key,
594
- ifTruePlaceholder: c.if_true_placeholder,
595
- ifFalsePlaceholder: c.if_false_placeholder,
596
- }));
635
+ asset.meta.conditions = conditions.map(
636
+ // @ts-expect-error TS7006
637
+ (c): ConditionMeta => ({
638
+ key: c.key,
639
+ ifTruePlaceholder: c.if_true_placeholder,
640
+ ifFalsePlaceholder: c.if_false_placeholder,
641
+ }),
642
+ );
597
643
  }
598
644
 
599
645
  if (is_constant_module) {
600
646
  asset.meta.isConstantModule = true;
601
647
  }
602
648
 
603
- let convertLoc = (loc): SourceLocation => {
649
+ let convertLoc = (loc: any): SourceLocation => {
604
650
  let location = {
605
651
  filePath: asset.filePath,
606
652
  start: {
@@ -623,19 +669,22 @@ export default (new Transformer({
623
669
 
624
670
  if (diagnostics) {
625
671
  let errors = diagnostics.filter(
672
+ // @ts-expect-error TS7006
626
673
  (d) =>
627
674
  d.severity === 'Error' ||
628
675
  (d.severity === 'SourceError' && asset.isSource),
629
676
  );
630
677
  let warnings = diagnostics.filter(
678
+ // @ts-expect-error TS7006
631
679
  (d) =>
632
680
  d.severity === 'Warning' ||
633
681
  (d.severity === 'SourceError' && !asset.isSource),
634
682
  );
635
- let convertDiagnostic = (diagnostic) => {
683
+ let convertDiagnostic = (diagnostic: any) => {
636
684
  let message = diagnostic.message;
637
685
  if (message === 'SCRIPT_ERROR') {
638
- let err = SCRIPT_ERRORS[(asset.env.context: string)];
686
+ // @ts-expect-error TS7053
687
+ let err = SCRIPT_ERRORS[asset.env.context as string];
639
688
  message = err?.message || SCRIPT_ERRORS.browser.message;
640
689
  }
641
690
 
@@ -644,11 +693,12 @@ export default (new Transformer({
644
693
  codeFrames: [
645
694
  {
646
695
  filePath: asset.filePath,
647
- codeHighlights: diagnostic.code_highlights?.map((highlight) =>
648
- convertSourceLocationToHighlight(
649
- convertLoc(highlight.loc),
650
- highlight.message ?? undefined,
651
- ),
696
+ codeHighlights: diagnostic.code_highlights?.map(
697
+ (highlight: any) =>
698
+ convertSourceLocationToHighlight(
699
+ convertLoc(highlight.loc),
700
+ highlight.message ?? undefined,
701
+ ),
652
702
  ),
653
703
  },
654
704
  ],
@@ -672,7 +722,8 @@ export default (new Transformer({
672
722
  });
673
723
  }
674
724
 
675
- let err = SCRIPT_ERRORS[(asset.env.context: string)];
725
+ // @ts-expect-error TS7053
726
+ let err = SCRIPT_ERRORS[asset.env.context as string];
676
727
  if (err) {
677
728
  if (!res.hints) {
678
729
  res.hints = [err.hint];
@@ -729,6 +780,7 @@ export default (new Transformer({
729
780
  env: {
730
781
  context: 'web-worker',
731
782
  sourceType: dep.source_type === 'Module' ? 'module' : 'script',
783
+ // @ts-expect-error TS2322
732
784
  outputFormat,
733
785
  loc,
734
786
  },
@@ -776,6 +828,13 @@ export default (new Transformer({
776
828
  });
777
829
  } else if (dep.kind === 'File') {
778
830
  asset.invalidateOnFileChange(dep.specifier);
831
+ } else if (dep.kind === 'Id') {
832
+ // Record parcelRequire calls so that the dev packager can add them as dependencies.
833
+ // This allows the HMR runtime to collect parents across async boundaries (through runtimes).
834
+ // TODO: ideally this would result as an actual dep in the graph rather than asset.meta.
835
+ asset.meta.hmrDeps ??= [];
836
+ invariant(Array.isArray(asset.meta.hmrDeps));
837
+ asset.meta.hmrDeps.push(dep.specifier);
779
838
  } else {
780
839
  let meta: JSONObject = {kind: dep.kind};
781
840
  if (dep.attributes) {
@@ -839,6 +898,13 @@ export default (new Transformer({
839
898
  outputFormat,
840
899
  loc: convertLoc(dep.loc),
841
900
  };
901
+
902
+ if (getFeatureFlag('supportWebpackChunkName')) {
903
+ let chunkName = magic_comments[dep.specifier];
904
+ if (chunkName) {
905
+ meta.chunkName = chunkName;
906
+ }
907
+ }
842
908
  }
843
909
 
844
910
  // Always bundle helpers, even with includeNodeModules: false, except if this is a library.
@@ -863,6 +929,7 @@ export default (new Transformer({
863
929
  idx = dep.specifier.indexOf('/', idx + 1);
864
930
  }
865
931
  let module = idx >= 0 ? dep.specifier.slice(0, idx) : dep.specifier;
932
+ // @ts-expect-error TS7053
866
933
  range = pkg.dependencies[module];
867
934
  }
868
935
 
@@ -874,12 +941,13 @@ export default (new Transformer({
874
941
  dep.kind === 'DynamicImport'
875
942
  ? 'lazy'
876
943
  : dep.kind === 'ConditionalImport'
877
- ? 'conditional'
878
- : 'sync',
944
+ ? 'conditional'
945
+ : 'sync',
879
946
  isOptional: dep.is_optional,
880
947
  meta,
881
948
  resolveFrom: isHelper ? __filename : undefined,
882
949
  range,
950
+ // @ts-expect-error TS2322
883
951
  env,
884
952
  });
885
953
  }
@@ -926,12 +994,15 @@ export default (new Transformer({
926
994
  let dep = deps.get(source);
927
995
  if (!dep) continue;
928
996
  if (local === '*' && imported === '*') {
997
+ // @ts-expect-error TS2345
929
998
  dep.symbols.set('*', '*', convertLoc(loc), true);
930
999
  } else {
931
1000
  let reExportName =
932
1001
  dep.symbols.get(imported)?.local ??
933
1002
  `$${asset.id}$re_export$${local}`;
1003
+ // @ts-expect-error TS2345
934
1004
  asset.symbols.set(local, reExportName);
1005
+ // @ts-expect-error TS2345
935
1006
  dep.symbols.set(imported, reExportName, convertLoc(loc), true);
936
1007
  }
937
1008
  }
@@ -954,6 +1025,7 @@ export default (new Transformer({
954
1025
  // Do not create a self-reference for the `default` symbol unless we have seen an __esModule flag.
955
1026
  if (
956
1027
  name === 'default' &&
1028
+ // @ts-expect-error TS2345
957
1029
  !asset.symbols.hasExportSymbol('__esModule')
958
1030
  ) {
959
1031
  continue;
@@ -989,8 +1061,13 @@ export default (new Transformer({
989
1061
  asset.sideEffects &&
990
1062
  deps.size === 0 &&
991
1063
  Object.keys(hoist_result.exported_symbols).length === 0) ||
1064
+ // @ts-expect-error TS2345
992
1065
  (hoist_result.should_wrap && !asset.symbols.hasExportSymbol('*'))
993
1066
  ) {
1067
+ if (is_empty_or_empty_export) {
1068
+ asset.meta.emptyFileStarReexport = true;
1069
+ }
1070
+ // @ts-expect-error TS2345
994
1071
  asset.symbols.set('*', `$${asset.id}$exports`);
995
1072
  }
996
1073
 
@@ -1010,6 +1087,7 @@ export default (new Transformer({
1010
1087
  let dep = source ? deps.get(source) : undefined;
1011
1088
  asset.symbols.set(
1012
1089
  exported,
1090
+ // @ts-expect-error TS2345
1013
1091
  `${dep?.id ?? ''}$${local}`,
1014
1092
  convertLoc(loc),
1015
1093
  );
@@ -1017,6 +1095,7 @@ export default (new Transformer({
1017
1095
  dep.symbols.ensure();
1018
1096
  dep.symbols.set(
1019
1097
  local,
1098
+ // @ts-expect-error TS2345
1020
1099
  `${dep?.id ?? ''}$${local}`,
1021
1100
  convertLoc(loc),
1022
1101
  true,
@@ -1035,6 +1114,7 @@ export default (new Transformer({
1035
1114
  let dep = deps.get(source);
1036
1115
  if (!dep) continue;
1037
1116
  dep.symbols.ensure();
1117
+ // @ts-expect-error TS2345
1038
1118
  dep.symbols.set('*', '*', convertLoc(loc), true);
1039
1119
  }
1040
1120
 
@@ -1045,14 +1125,17 @@ export default (new Transformer({
1045
1125
  (!symbol_result.is_esm &&
1046
1126
  deps.size === 0 &&
1047
1127
  symbol_result.exports.length === 0) ||
1128
+ // @ts-expect-error TS2345
1048
1129
  (symbol_result.should_wrap && !asset.symbols.hasExportSymbol('*'))
1049
1130
  ) {
1050
1131
  asset.symbols.ensure();
1132
+ // @ts-expect-error TS2345
1051
1133
  asset.symbols.set('*', `$${asset.id}$exports`);
1052
1134
  }
1053
1135
  } else {
1054
1136
  // If the asset is wrapped, add * as a fallback
1055
1137
  asset.symbols.ensure();
1138
+ // @ts-expect-error TS2345
1056
1139
  asset.symbols.set('*', `$${asset.id}$exports`);
1057
1140
  }
1058
1141
 
@@ -1061,6 +1144,7 @@ export default (new Transformer({
1061
1144
  for (let dep of asset.getDependencies()) {
1062
1145
  if (dep.symbols.isCleared) {
1063
1146
  dep.symbols.ensure();
1147
+ // @ts-expect-error TS2345
1064
1148
  dep.symbols.set('*', `${dep.id}$`);
1065
1149
  }
1066
1150
  }
@@ -1086,6 +1170,7 @@ export default (new Transformer({
1086
1170
  let sourceMap = new SourceMap(options.projectRoot);
1087
1171
  sourceMap.addVLQMap(JSON.parse(map));
1088
1172
  if (originalMap) {
1173
+ // @ts-expect-error TS2345
1089
1174
  sourceMap.extends(originalMap);
1090
1175
  }
1091
1176
  asset.setMap(sourceMap);
@@ -1093,4 +1178,4 @@ export default (new Transformer({
1093
1178
 
1094
1179
  return [asset, ...macroAssets];
1095
1180
  },
1096
- }): Transformer);
1181
+ }) as Transformer<unknown>;