@atlaspack/transformer-js 3.4.0 → 3.4.1-typescript-5ad950d33.0

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/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright (c) 2024 Atlassian US., Inc.
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,3 @@
1
+ import { Transformer } from '@atlaspack/plugin';
2
+ declare const _default: Transformer<unknown>;
3
+ export default _default;
@@ -188,18 +188,25 @@ var _default = exports.default = new (_plugin().Transformer)({
188
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;
189
189
 
190
190
  // Use explicitly defined JSX options in tsconfig.json over inferred values from dependencies.
191
- pragma = (compilerOptions === null || compilerOptions === void 0 ? void 0 : compilerOptions.jsxFactory) || (reactLib ? JSX_PRAGMA[reactLib].pragma : undefined);
192
- 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);
193
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) {
194
198
  jsxImportSource = compilerOptions === null || compilerOptions === void 0 ? void 0 : compilerOptions.jsxImportSource;
195
199
  automaticJSXRuntime = true;
196
200
  } else if (reactLib) {
197
201
  var _JSX_PRAGMA$effective, _packageJson$dependen3, _packageJson$devDepen3, _packageJson$peerDepe3, _semver$minVersion;
198
202
  let effectiveReactLib = packageJson !== null && packageJson !== void 0 && packageJson.alias && packageJson.alias['react'] === 'preact/compat' ? 'preact' : reactLib;
203
+ // @ts-expect-error TS7053
199
204
  let automaticVersion = (_JSX_PRAGMA$effective = JSX_PRAGMA[effectiveReactLib]) === null || _JSX_PRAGMA$effective === void 0 ? void 0 : _JSX_PRAGMA$effective.automatic;
200
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
201
207
  reactLibVersion = reactLibVersion ? _semver().default.validRange(reactLibVersion) : null;
202
- 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;
203
210
  automaticJSXRuntime = automaticVersion && !(compilerOptions !== null && compilerOptions !== void 0 && compilerOptions.jsxFactory) && minReactLibVersion != null && _semver().default.satisfies(minReactLibVersion, automaticVersion, {
204
211
  includePrerelease: true
205
212
  });
@@ -242,10 +249,16 @@ var _default = exports.default = new (_plugin().Transformer)({
242
249
  },
243
250
  // FIXME
244
251
  '@atlaspack/transformer-js', 'Invalid config for @atlaspack/transformer-js');
252
+
253
+ // @ts-expect-error TS2339
245
254
  magicComments = ((_conf$contents = conf.contents) === null || _conf$contents === void 0 ? void 0 : _conf$contents.magicComments) ?? magicComments;
255
+ // @ts-expect-error TS2339
246
256
  inlineEnvironment = ((_conf$contents2 = conf.contents) === null || _conf$contents2 === void 0 ? void 0 : _conf$contents2.inlineEnvironment) ?? inlineEnvironment;
257
+ // @ts-expect-error TS2339
247
258
  inlineFS = ((_conf$contents3 = conf.contents) === null || _conf$contents3 === void 0 ? void 0 : _conf$contents3.inlineFS) ?? inlineFS;
248
- 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;
249
262
  }
250
263
  return {
251
264
  isJSX,
@@ -288,17 +301,22 @@ var _default = exports.default = new (_plugin().Transformer)({
288
301
  for (let browser of browsers) {
289
302
  let [name, version] = browser.split(' ');
290
303
  if (BROWSER_MAPPING.hasOwnProperty(name)) {
304
+ // @ts-expect-error TS7053
291
305
  name = BROWSER_MAPPING[name];
292
306
  if (!name) {
293
307
  continue;
294
308
  }
295
309
  }
296
310
  let [major, minor = '0', patch = '0'] = version.split('-')[0].split('.');
311
+ // @ts-expect-error TS2345
297
312
  if (isNaN(major) || isNaN(minor) || isNaN(patch)) {
298
313
  continue;
299
314
  }
300
315
  let semverVersion = `${major}.${minor}.${patch}`;
316
+
317
+ // @ts-expect-error TS2345
301
318
  if (targets[name] == null || _semver().default.gt(targets[name], semverVersion)) {
319
+ // @ts-expect-error TS7053
302
320
  targets[name] = semverVersion;
303
321
  }
304
322
  }
@@ -309,8 +327,6 @@ var _default = exports.default = new (_plugin().Transformer)({
309
327
  };
310
328
  }
311
329
  let env = {};
312
-
313
- // $FlowFixMe
314
330
  if (!(config !== null && config !== void 0 && config.inlineEnvironment)) {
315
331
  if (options.env.NODE_ENV != null) {
316
332
  env.NODE_ENV = options.env.NODE_ENV;
@@ -319,9 +335,7 @@ var _default = exports.default = new (_plugin().Transformer)({
319
335
  env.ATLASPACK_BUILD_ENV = 'test';
320
336
  }
321
337
  } else if (Array.isArray(config === null || config === void 0 ? void 0 : config.inlineEnvironment)) {
322
- for (let match of (0, _utils().globMatch)(Object.keys(options.env),
323
- // $FlowFixMe
324
- config.inlineEnvironment)) {
338
+ for (let match of (0, _utils().globMatch)(Object.keys(options.env), config.inlineEnvironment)) {
325
339
  env[match] = String(options.env[match]);
326
340
  }
327
341
  } else {
@@ -332,30 +346,44 @@ var _default = exports.default = new (_plugin().Transformer)({
332
346
  }
333
347
  }
334
348
  let supportsModuleWorkers = asset.env.shouldScopeHoist && asset.env.supports('worker-module', true);
335
- // $FlowFixMe
336
349
  let isJSX = Boolean(config === null || config === void 0 ? void 0 : config.isJSX);
337
350
  if (asset.isSource) {
338
351
  if (asset.type === 'ts') {
339
352
  isJSX = false;
340
353
  } else if (!isJSX) {
354
+ // @ts-expect-error TS7053
341
355
  isJSX = Boolean(JSX_EXTENSIONS[asset.type]);
342
356
  }
343
357
  }
344
358
  let macroAssets = [];
345
359
  let {
360
+ // @ts-expect-error TS2339
346
361
  dependencies,
362
+ // @ts-expect-error TS2339
347
363
  code: compiledCode,
364
+ // @ts-expect-error TS2339
348
365
  map,
366
+ // @ts-expect-error TS2339
349
367
  shebang,
368
+ // @ts-expect-error TS2339
350
369
  hoist_result,
370
+ // @ts-expect-error TS2339
351
371
  symbol_result,
372
+ // @ts-expect-error TS2339
352
373
  is_empty_or_empty_export,
374
+ // @ts-expect-error TS2339
353
375
  needs_esm_helpers,
376
+ // @ts-expect-error TS2339
354
377
  diagnostics,
378
+ // @ts-expect-error TS2339
355
379
  used_env,
380
+ // @ts-expect-error TS2339
356
381
  has_node_replacements,
382
+ // @ts-expect-error TS2339
357
383
  is_constant_module,
384
+ // @ts-expect-error TS2339
358
385
  conditions,
386
+ // @ts-expect-error TS2339
359
387
  magic_comments
360
388
  } = await (_rust().transformAsync || _rust().transform)({
361
389
  filename: asset.filePath,
@@ -363,7 +391,6 @@ var _default = exports.default = new (_plugin().Transformer)({
363
391
  module_id: asset.id,
364
392
  project_root: options.projectRoot,
365
393
  replace_env: !asset.env.isNode(),
366
- // $FlowFixMe
367
394
  inline_fs: Boolean(config === null || config === void 0 ? void 0 : config.inlineFS) && !asset.env.isNode(),
368
395
  insert_node_globals: !asset.env.isNode() && asset.env.sourceType !== 'script',
369
396
  node_replacer: asset.env.isNode(),
@@ -372,21 +399,13 @@ var _default = exports.default = new (_plugin().Transformer)({
372
399
  env,
373
400
  is_type_script: asset.type === 'ts' || asset.type === 'tsx',
374
401
  is_jsx: isJSX,
375
- // $FlowFixMe
376
402
  jsx_pragma: config === null || config === void 0 ? void 0 : config.pragma,
377
- // $FlowFixMe
378
403
  jsx_pragma_frag: config === null || config === void 0 ? void 0 : config.pragmaFrag,
379
- // $FlowFixMe
380
404
  automatic_jsx_runtime: Boolean(config === null || config === void 0 ? void 0 : config.automaticJSXRuntime),
381
- // $FlowFixMe
382
405
  jsx_import_source: config === null || config === void 0 ? void 0 : config.jsxImportSource,
383
406
  is_development: options.mode === 'development',
384
- react_refresh: asset.env.isBrowser() && !asset.env.isLibrary && !asset.env.isWorker() && !asset.env.isWorklet() &&
385
- // $FlowFixMe
386
- Boolean(config === null || config === void 0 ? void 0 : config.reactRefresh),
387
- // $FlowFixMe
407
+ react_refresh: asset.env.isBrowser() && !asset.env.isLibrary && !asset.env.isWorker() && !asset.env.isWorklet() && Boolean(config === null || config === void 0 ? void 0 : config.reactRefresh),
388
408
  decorators: Boolean(config === null || config === void 0 ? void 0 : config.decorators),
389
- // $FlowFixMe
390
409
  use_define_for_class_fields: Boolean(config === null || config === void 0 ? void 0 : config.useDefineForClassFields),
391
410
  targets,
392
411
  source_maps: !!asset.env.sourceMap,
@@ -398,23 +417,18 @@ var _default = exports.default = new (_plugin().Transformer)({
398
417
  trace_bailouts: options.logLevel === 'verbose',
399
418
  is_swc_helpers: /@swc[/\\]helpers/.test(asset.filePath),
400
419
  standalone: asset.query.has('standalone'),
401
- // $FlowFixMe
402
420
  inline_constants: config.inlineConstants,
403
421
  conditional_bundling: options.featureFlags.conditionalBundlingApi,
404
422
  hmr_improvements: options.featureFlags.hmrImprovements,
405
423
  computed_properties_fix: options.featureFlags.unusedComputedPropertyFix,
406
- magic_comments:
407
- // $FlowFixMe
408
- Boolean(config === null || config === void 0 ? void 0 : config.magicComments) || (0, _featureFlags().getFeatureFlag)('supportWebpackChunkName'),
424
+ magic_comments: Boolean(config === null || config === void 0 ? void 0 : config.magicComments) || (0, _featureFlags().getFeatureFlag)('supportWebpackChunkName'),
409
425
  callMacro: asset.isSource ? async (err, src, exportName, args, loc) => {
410
426
  let mod;
411
427
  try {
412
428
  mod = await options.packageManager.require(src, asset.filePath);
413
429
 
414
430
  // Default interop for CommonJS modules.
415
- if (exportName === 'default' && !mod.__esModule &&
416
- // $FlowFixMe
417
- Object.prototype.toString.call(config) !== '[object Module]') {
431
+ if (exportName === 'default' && !mod.__esModule && Object.prototype.toString.call(config) !== '[object Module]') {
418
432
  mod = {
419
433
  default: mod
420
434
  };
@@ -438,6 +452,7 @@ var _default = exports.default = new (_plugin().Transformer)({
438
452
  if (asset.env.sourceMap) {
439
453
  // Generate a source map that maps each line of the asset to the original macro call.
440
454
  map = new (_sourceMap().default)(options.projectRoot);
455
+ // @ts-expect-error TS2304
441
456
  let mappings = [];
442
457
  let line = 1;
443
458
  for (let i = 0; i <= a.content.length; i++) {
@@ -458,6 +473,7 @@ var _default = exports.default = new (_plugin().Transformer)({
458
473
  }
459
474
  map.addIndexedMappings(mappings);
460
475
  if (originalMap) {
476
+ // @ts-expect-error TS2345
461
477
  map.extends(originalMap);
462
478
  } else {
463
479
  map.setSourceContent(asset.filePath, code.toString());
@@ -512,7 +528,9 @@ var _default = exports.default = new (_plugin().Transformer)({
512
528
  } : null
513
529
  });
514
530
  if ((0, _featureFlags().getFeatureFlag)('conditionalBundlingApi')) {
515
- asset.meta.conditions = conditions.map(c => ({
531
+ asset.meta.conditions = conditions.map(
532
+ // @ts-expect-error TS7006
533
+ c => ({
516
534
  key: c.key,
517
535
  ifTruePlaceholder: c.if_true_placeholder,
518
536
  ifFalsePlaceholder: c.if_false_placeholder
@@ -541,12 +559,17 @@ var _default = exports.default = new (_plugin().Transformer)({
541
559
  return location;
542
560
  };
543
561
  if (diagnostics) {
544
- let errors = diagnostics.filter(d => d.severity === 'Error' || d.severity === 'SourceError' && asset.isSource);
545
- 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);
546
568
  let convertDiagnostic = diagnostic => {
547
569
  var _diagnostic$code_high;
548
570
  let message = diagnostic.message;
549
571
  if (message === 'SCRIPT_ERROR') {
572
+ // @ts-expect-error TS7053
550
573
  let err = SCRIPT_ERRORS[asset.env.context];
551
574
  message = (err === null || err === void 0 ? void 0 : err.message) || SCRIPT_ERRORS.browser.message;
552
575
  }
@@ -569,6 +592,8 @@ var _default = exports.default = new (_plugin().Transformer)({
569
592
  codeHighlights: [(0, _diagnostic().convertSourceLocationToHighlight)(asset.env.loc, 'The environment was originally created here')]
570
593
  });
571
594
  }
595
+
596
+ // @ts-expect-error TS7053
572
597
  let err = SCRIPT_ERRORS[asset.env.context];
573
598
  if (err) {
574
599
  if (!res.hints) {
@@ -613,6 +638,7 @@ var _default = exports.default = new (_plugin().Transformer)({
613
638
  env: {
614
639
  context: 'web-worker',
615
640
  sourceType: dep.source_type === 'Module' ? 'module' : 'script',
641
+ // @ts-expect-error TS2322
616
642
  outputFormat,
617
643
  loc
618
644
  },
@@ -741,6 +767,7 @@ var _default = exports.default = new (_plugin().Transformer)({
741
767
  idx = dep.specifier.indexOf('/', idx + 1);
742
768
  }
743
769
  let module = idx >= 0 ? dep.specifier.slice(0, idx) : dep.specifier;
770
+ // @ts-expect-error TS7053
744
771
  range = _package.default.dependencies[module];
745
772
  }
746
773
  asset.addDependency({
@@ -752,6 +779,7 @@ var _default = exports.default = new (_plugin().Transformer)({
752
779
  meta,
753
780
  resolveFrom: isHelper ? __filename : undefined,
754
781
  range,
782
+ // @ts-expect-error TS2322
755
783
  env
756
784
  });
757
785
  }
@@ -798,11 +826,14 @@ var _default = exports.default = new (_plugin().Transformer)({
798
826
  let dep = deps.get(source);
799
827
  if (!dep) continue;
800
828
  if (local === '*' && imported === '*') {
829
+ // @ts-expect-error TS2345
801
830
  dep.symbols.set('*', '*', convertLoc(loc), true);
802
831
  } else {
803
832
  var _dep$symbols$get;
804
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
805
835
  asset.symbols.set(local, reExportName);
836
+ // @ts-expect-error TS2345
806
837
  dep.symbols.set(imported, reExportName, convertLoc(loc), true);
807
838
  }
808
839
  }
@@ -820,7 +851,9 @@ var _default = exports.default = new (_plugin().Transformer)({
820
851
  let symbols = new Map();
821
852
  for (let name of hoist_result.self_references) {
822
853
  // Do not create a self-reference for the `default` symbol unless we have seen an __esModule flag.
823
- if (name === 'default' && !asset.symbols.hasExportSymbol('__esModule')) {
854
+ if (name === 'default' &&
855
+ // @ts-expect-error TS2345
856
+ !asset.symbols.hasExportSymbol('__esModule')) {
824
857
  continue;
825
858
  }
826
859
  let local = (0, _nullthrows().default)(asset.symbols.get(name)).local;
@@ -847,10 +880,13 @@ var _default = exports.default = new (_plugin().Transformer)({
847
880
  // Add * symbol if there are CJS exports, no imports/exports at all
848
881
  // (and the asset has side effects), or the asset is wrapped.
849
882
  // This allows accessing symbols that don't exist without errors in symbol propagation.
850
- 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('*')) {
851
886
  if (is_empty_or_empty_export) {
852
887
  asset.meta.emptyFileStarReexport = true;
853
888
  }
889
+ // @ts-expect-error TS2345
854
890
  asset.symbols.set('*', `$${asset.id}$exports`);
855
891
  }
856
892
  asset.meta.hasCJSExports = hoist_result.has_cjs_exports;
@@ -867,10 +903,14 @@ var _default = exports.default = new (_plugin().Transformer)({
867
903
  source
868
904
  } of symbol_result.exports) {
869
905
  let dep = source ? deps.get(source) : undefined;
870
- 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));
871
909
  if (dep != null) {
872
910
  dep.symbols.ensure();
873
- 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);
874
914
  }
875
915
  }
876
916
  for (let {
@@ -891,18 +931,23 @@ var _default = exports.default = new (_plugin().Transformer)({
891
931
  let dep = deps.get(source);
892
932
  if (!dep) continue;
893
933
  dep.symbols.ensure();
934
+ // @ts-expect-error TS2345
894
935
  dep.symbols.set('*', '*', convertLoc(loc), true);
895
936
  }
896
937
 
897
938
  // Add * symbol if there are CJS exports, no imports/exports at all, or the asset is wrapped.
898
939
  // This allows accessing symbols that don't exist without errors in symbol propagation.
899
- 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('*')) {
900
943
  asset.symbols.ensure();
944
+ // @ts-expect-error TS2345
901
945
  asset.symbols.set('*', `$${asset.id}$exports`);
902
946
  }
903
947
  } else {
904
948
  // If the asset is wrapped, add * as a fallback
905
949
  asset.symbols.ensure();
950
+ // @ts-expect-error TS2345
906
951
  asset.symbols.set('*', `$${asset.id}$exports`);
907
952
  }
908
953
 
@@ -911,6 +956,7 @@ var _default = exports.default = new (_plugin().Transformer)({
911
956
  for (let dep of asset.getDependencies()) {
912
957
  if (dep.symbols.isCleared) {
913
958
  dep.symbols.ensure();
959
+ // @ts-expect-error TS2345
914
960
  dep.symbols.set('*', `${dep.id}$`);
915
961
  }
916
962
  }
@@ -933,6 +979,7 @@ var _default = exports.default = new (_plugin().Transformer)({
933
979
  let sourceMap = new (_sourceMap().default)(options.projectRoot);
934
980
  sourceMap.addVLQMap(JSON.parse(map));
935
981
  if (originalMap) {
982
+ // @ts-expect-error TS2345
936
983
  sourceMap.extends(originalMap);
937
984
  }
938
985
  asset.setMap(sourceMap);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaspack/transformer-js",
3
- "version": "3.4.0",
3
+ "version": "3.4.1-typescript-5ad950d33.0",
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,13 +24,13 @@
22
24
  "src"
23
25
  ],
24
26
  "dependencies": {
25
- "@atlaspack/diagnostic": "2.14.1",
26
- "@atlaspack/feature-flags": "2.20.0",
27
- "@atlaspack/plugin": "2.14.21",
28
- "@atlaspack/rust": "3.4.1",
27
+ "@atlaspack/diagnostic": "2.14.2-typescript-5ad950d33.0",
28
+ "@atlaspack/feature-flags": "2.20.1-typescript-5ad950d33.0",
29
+ "@atlaspack/plugin": "2.14.22-typescript-5ad950d33.0",
30
+ "@atlaspack/rust": "3.4.2-typescript-5ad950d33.0",
31
+ "@atlaspack/utils": "2.17.4-typescript-5ad950d33.0",
32
+ "@atlaspack/workers": "2.14.22-typescript-5ad950d33.0",
29
33
  "@parcel/source-map": "^2.1.1",
30
- "@atlaspack/utils": "2.17.3",
31
- "@atlaspack/workers": "2.14.21",
32
34
  "@swc/helpers": "^0.5.15",
33
35
  "browserslist": "^4.6.6",
34
36
  "nullthrows": "^1.1.1",
@@ -38,5 +40,6 @@
38
40
  "peerDependencies": {
39
41
  "@atlaspack/core": "^2.13.1"
40
42
  },
41
- "type": "commonjs"
42
- }
43
+ "type": "commonjs",
44
+ "gitHead": "5ad950d33a5f2255ebeb10c04a2e84c346e2de85"
45
+ }
@@ -1,4 +1,3 @@
1
- // @flow
2
1
  import type {
3
2
  JSONObject,
4
3
  EnvMap,
@@ -27,7 +26,7 @@ import {getFeatureFlag} from '@atlaspack/feature-flags';
27
26
  const JSX_EXTENSIONS = {
28
27
  jsx: true,
29
28
  tsx: true,
30
- };
29
+ } as const;
31
30
 
32
31
  const JSX_PRAGMA = {
33
32
  react: {
@@ -50,7 +49,7 @@ const JSX_PRAGMA = {
50
49
  pragmaFrag: undefined,
51
50
  automatic: undefined,
52
51
  },
53
- };
52
+ } as const;
54
53
 
55
54
  const BROWSER_MAPPING = {
56
55
  and_chr: 'chrome',
@@ -64,7 +63,7 @@ const BROWSER_MAPPING = {
64
63
  bb: null,
65
64
  kaios: null,
66
65
  op_mini: null,
67
- };
66
+ } as const;
68
67
 
69
68
  // List of browsers to exclude when the esmodule target is specified.
70
69
  // Based on https://caniuse.com/#feat=es6-module
@@ -134,45 +133,43 @@ const SCRIPT_ERRORS = {
134
133
  'Service workers cannot have imports or exports without the `type: "module"` option.',
135
134
  hint: "Add {type: 'module'} as a second argument to the navigator.serviceWorker.register() call.",
136
135
  },
137
- };
136
+ } as const;
138
137
 
139
138
  type TSConfig = {
140
139
  compilerOptions?: {
141
140
  // https://www.typescriptlang.org/tsconfig#jsx
142
- jsx?: 'react' | 'react-jsx' | 'react-jsxdev' | 'preserve' | 'react-native',
141
+ jsx?: 'react' | 'react-jsx' | 'react-jsxdev' | 'preserve' | 'react-native';
143
142
  // https://www.typescriptlang.org/tsconfig#jsxFactory
144
- jsxFactory?: string,
143
+ jsxFactory?: string;
145
144
  // https://www.typescriptlang.org/tsconfig#jsxFragmentFactory
146
- jsxFragmentFactory?: string,
145
+ jsxFragmentFactory?: string;
147
146
  // https://www.typescriptlang.org/tsconfig#jsxImportSource
148
- jsxImportSource?: string,
147
+ jsxImportSource?: string;
149
148
  // https://www.typescriptlang.org/tsconfig#experimentalDecorators
150
- experimentalDecorators?: boolean,
149
+ experimentalDecorators?: boolean;
151
150
  // https://www.typescriptlang.org/tsconfig#useDefineForClassFields
152
- useDefineForClassFields?: boolean,
151
+ useDefineForClassFields?: boolean;
153
152
  // https://www.typescriptlang.org/tsconfig#target
154
- target?: string, // 'es3' | 'es5' | 'es6' | 'es2015' | ... |'es2022' | ... | 'esnext'
155
- ...
156
- },
157
- ...
153
+ target?: string; // 'es3' | 'es5' | 'es6' | 'es2015' | ... |'es2022' | ... | 'esnext';
154
+ };
158
155
  };
159
156
 
160
- type MacroAsset = {|
161
- type: string,
162
- content: string,
163
- |};
157
+ type MacroAsset = {
158
+ type: string;
159
+ content: string;
160
+ };
164
161
 
165
162
  // NOTE: Make sure this is in sync with the TypeScript definition in the @atlaspack/macros package.
166
- type MacroContext = {|
167
- addAsset(asset: MacroAsset): void,
168
- invalidateOnFileChange(FilePath): void,
169
- invalidateOnFileCreate(FileCreateInvalidation): void,
170
- invalidateOnEnvChange(string): void,
171
- invalidateOnStartup(): void,
172
- invalidateOnBuild(): void,
173
- |};
174
-
175
- 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({
176
173
  async loadConfig({config, options}) {
177
174
  let packageJson = await config.getPackage();
178
175
  let isJSX,
@@ -220,9 +217,11 @@ export default (new Transformer({
220
217
  // Use explicitly defined JSX options in tsconfig.json over inferred values from dependencies.
221
218
  pragma =
222
219
  compilerOptions?.jsxFactory ||
220
+ // @ts-expect-error TS7053
223
221
  (reactLib ? JSX_PRAGMA[reactLib].pragma : undefined);
224
222
  pragmaFrag =
225
223
  compilerOptions?.jsxFragmentFactory ||
224
+ // @ts-expect-error TS7053
226
225
  (reactLib ? JSX_PRAGMA[reactLib].pragmaFrag : undefined);
227
226
 
228
227
  if (
@@ -237,17 +236,20 @@ export default (new Transformer({
237
236
  packageJson?.alias && packageJson.alias['react'] === 'preact/compat'
238
237
  ? 'preact'
239
238
  : reactLib;
239
+ // @ts-expect-error TS7053
240
240
  let automaticVersion = JSX_PRAGMA[effectiveReactLib]?.automatic;
241
241
  let reactLibVersion =
242
242
  packageJson?.dependencies?.[effectiveReactLib] ||
243
243
  packageJson?.devDependencies?.[effectiveReactLib] ||
244
244
  packageJson?.peerDependencies?.[effectiveReactLib];
245
+ // @ts-expect-error TS2322
245
246
  reactLibVersion = reactLibVersion
246
247
  ? semver.validRange(reactLibVersion)
247
248
  : null;
248
249
  let minReactLibVersion =
249
250
  reactLibVersion !== null && reactLibVersion !== '*'
250
- ? semver.minVersion(reactLibVersion)?.toString()
251
+ ? // @ts-expect-error TS2345
252
+ semver.minVersion(reactLibVersion)?.toString()
251
253
  : null;
252
254
 
253
255
  automaticJSXRuntime =
@@ -312,10 +314,14 @@ export default (new Transformer({
312
314
  'Invalid config for @atlaspack/transformer-js',
313
315
  );
314
316
 
317
+ // @ts-expect-error TS2339
315
318
  magicComments = conf.contents?.magicComments ?? magicComments;
319
+ // @ts-expect-error TS2339
316
320
  inlineEnvironment = conf.contents?.inlineEnvironment ?? inlineEnvironment;
321
+ // @ts-expect-error TS2339
317
322
  inlineFS = conf.contents?.inlineFS ?? inlineFS;
318
323
  inlineConstants =
324
+ // @ts-expect-error TS2339
319
325
  conf.contents?.unstable_inlineConstants ?? inlineConstants;
320
326
  }
321
327
 
@@ -362,6 +368,7 @@ export default (new Transformer({
362
368
  for (let browser of browsers) {
363
369
  let [name, version] = browser.split(' ');
364
370
  if (BROWSER_MAPPING.hasOwnProperty(name)) {
371
+ // @ts-expect-error TS7053
365
372
  name = BROWSER_MAPPING[name];
366
373
  if (!name) {
367
374
  continue;
@@ -371,12 +378,15 @@ export default (new Transformer({
371
378
  let [major, minor = '0', patch = '0'] = version
372
379
  .split('-')[0]
373
380
  .split('.');
381
+ // @ts-expect-error TS2345
374
382
  if (isNaN(major) || isNaN(minor) || isNaN(patch)) {
375
383
  continue;
376
384
  }
377
385
  let semverVersion = `${major}.${minor}.${patch}`;
378
386
 
387
+ // @ts-expect-error TS2345
379
388
  if (targets[name] == null || semver.gt(targets[name], semverVersion)) {
389
+ // @ts-expect-error TS7053
380
390
  targets[name] = semverVersion;
381
391
  }
382
392
  }
@@ -386,7 +396,6 @@ export default (new Transformer({
386
396
 
387
397
  let env: EnvMap = {};
388
398
 
389
- // $FlowFixMe
390
399
  if (!config?.inlineEnvironment) {
391
400
  if (options.env.NODE_ENV != null) {
392
401
  env.NODE_ENV = options.env.NODE_ENV;
@@ -398,7 +407,6 @@ export default (new Transformer({
398
407
  } else if (Array.isArray(config?.inlineEnvironment)) {
399
408
  for (let match of globMatch(
400
409
  Object.keys(options.env),
401
- // $FlowFixMe
402
410
  config.inlineEnvironment,
403
411
  )) {
404
412
  env[match] = String(options.env[match]);
@@ -413,31 +421,51 @@ export default (new Transformer({
413
421
 
414
422
  let supportsModuleWorkers =
415
423
  asset.env.shouldScopeHoist && asset.env.supports('worker-module', true);
416
- // $FlowFixMe
417
424
  let isJSX = Boolean(config?.isJSX);
418
425
  if (asset.isSource) {
419
426
  if (asset.type === 'ts') {
420
427
  isJSX = false;
421
428
  } else if (!isJSX) {
429
+ // @ts-expect-error TS7053
422
430
  isJSX = Boolean(JSX_EXTENSIONS[asset.type]);
423
431
  }
424
432
  }
425
433
 
426
- 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
+ }> = [];
427
441
  let {
442
+ // @ts-expect-error TS2339
428
443
  dependencies,
444
+ // @ts-expect-error TS2339
429
445
  code: compiledCode,
446
+ // @ts-expect-error TS2339
430
447
  map,
448
+ // @ts-expect-error TS2339
431
449
  shebang,
450
+ // @ts-expect-error TS2339
432
451
  hoist_result,
452
+ // @ts-expect-error TS2339
433
453
  symbol_result,
454
+ // @ts-expect-error TS2339
434
455
  is_empty_or_empty_export,
456
+ // @ts-expect-error TS2339
435
457
  needs_esm_helpers,
458
+ // @ts-expect-error TS2339
436
459
  diagnostics,
460
+ // @ts-expect-error TS2339
437
461
  used_env,
462
+ // @ts-expect-error TS2339
438
463
  has_node_replacements,
464
+ // @ts-expect-error TS2339
439
465
  is_constant_module,
466
+ // @ts-expect-error TS2339
440
467
  conditions,
468
+ // @ts-expect-error TS2339
441
469
  magic_comments,
442
470
  } = await (transformAsync || transform)({
443
471
  filename: asset.filePath,
@@ -445,7 +473,6 @@ export default (new Transformer({
445
473
  module_id: asset.id,
446
474
  project_root: options.projectRoot,
447
475
  replace_env: !asset.env.isNode(),
448
- // $FlowFixMe
449
476
  inline_fs: Boolean(config?.inlineFS) && !asset.env.isNode(),
450
477
  insert_node_globals:
451
478
  !asset.env.isNode() && asset.env.sourceType !== 'script',
@@ -455,13 +482,9 @@ export default (new Transformer({
455
482
  env,
456
483
  is_type_script: asset.type === 'ts' || asset.type === 'tsx',
457
484
  is_jsx: isJSX,
458
- // $FlowFixMe
459
485
  jsx_pragma: config?.pragma,
460
- // $FlowFixMe
461
486
  jsx_pragma_frag: config?.pragmaFrag,
462
- // $FlowFixMe
463
487
  automatic_jsx_runtime: Boolean(config?.automaticJSXRuntime),
464
- // $FlowFixMe
465
488
  jsx_import_source: config?.jsxImportSource,
466
489
  is_development: options.mode === 'development',
467
490
  react_refresh:
@@ -469,11 +492,8 @@ export default (new Transformer({
469
492
  !asset.env.isLibrary &&
470
493
  !asset.env.isWorker() &&
471
494
  !asset.env.isWorklet() &&
472
- // $FlowFixMe
473
495
  Boolean(config?.reactRefresh),
474
- // $FlowFixMe
475
496
  decorators: Boolean(config?.decorators),
476
- // $FlowFixMe
477
497
  use_define_for_class_fields: Boolean(config?.useDefineForClassFields),
478
498
  targets,
479
499
  source_maps: !!asset.env.sourceMap,
@@ -486,17 +506,15 @@ export default (new Transformer({
486
506
  trace_bailouts: options.logLevel === 'verbose',
487
507
  is_swc_helpers: /@swc[/\\]helpers/.test(asset.filePath),
488
508
  standalone: asset.query.has('standalone'),
489
- // $FlowFixMe
490
509
  inline_constants: config.inlineConstants,
491
510
  conditional_bundling: options.featureFlags.conditionalBundlingApi,
492
511
  hmr_improvements: options.featureFlags.hmrImprovements,
493
512
  computed_properties_fix: options.featureFlags.unusedComputedPropertyFix,
494
513
  magic_comments:
495
- // $FlowFixMe
496
514
  Boolean(config?.magicComments) ||
497
515
  getFeatureFlag('supportWebpackChunkName'),
498
516
  callMacro: asset.isSource
499
- ? async (err, src, exportName, args, loc) => {
517
+ ? async (err: any, src: any, exportName: any, args: any, loc: any) => {
500
518
  let mod;
501
519
  try {
502
520
  mod = await options.packageManager.require(src, asset.filePath);
@@ -505,7 +523,6 @@ export default (new Transformer({
505
523
  if (
506
524
  exportName === 'default' &&
507
525
  !mod.__esModule &&
508
- // $FlowFixMe
509
526
  Object.prototype.toString.call(config) !== '[object Module]'
510
527
  ) {
511
528
  mod = {default: mod};
@@ -514,7 +531,7 @@ export default (new Transformer({
514
531
  if (!Object.hasOwnProperty.call(mod, exportName)) {
515
532
  throw new Error(`"${src}" does not export "${exportName}".`);
516
533
  }
517
- } catch (err) {
534
+ } catch (err: any) {
518
535
  throw {
519
536
  kind: 1,
520
537
  message: err.message,
@@ -531,7 +548,8 @@ export default (new Transformer({
531
548
  if (asset.env.sourceMap) {
532
549
  // Generate a source map that maps each line of the asset to the original macro call.
533
550
  map = new SourceMap(options.projectRoot);
534
- let mappings = [];
551
+ // @ts-expect-error TS2304
552
+ let mappings: Array<IndexedMapping<string>> = [];
535
553
  let line = 1;
536
554
  for (let i = 0; i <= a.content.length; i++) {
537
555
  if (i === a.content.length || a.content[i] === '\n') {
@@ -552,6 +570,7 @@ export default (new Transformer({
552
570
 
553
571
  map.addIndexedMappings(mappings);
554
572
  if (originalMap) {
573
+ // @ts-expect-error TS2345
555
574
  map.extends(originalMap);
556
575
  } else {
557
576
  map.setSourceContent(asset.filePath, code.toString());
@@ -570,13 +589,13 @@ export default (new Transformer({
570
589
  specifierType: 'esm',
571
590
  });
572
591
  },
573
- invalidateOnFileChange(filePath) {
592
+ invalidateOnFileChange(filePath: FilePath) {
574
593
  asset.invalidateOnFileChange(filePath);
575
594
  },
576
- invalidateOnFileCreate(invalidation) {
595
+ invalidateOnFileCreate(invalidation: FileCreateInvalidation) {
577
596
  asset.invalidateOnFileCreate(invalidation);
578
597
  },
579
- invalidateOnEnvChange(env) {
598
+ invalidateOnEnvChange(env: string) {
580
599
  asset.invalidateOnEnvChange(env);
581
600
  },
582
601
  invalidateOnStartup() {
@@ -593,7 +612,7 @@ export default (new Transformer({
593
612
  `"${exportName}" in "${src}" is not a function.`,
594
613
  );
595
614
  }
596
- } catch (err) {
615
+ } catch (err: any) {
597
616
  // Remove atlaspack core from stack and build string so Rust can process errors more easily.
598
617
  let stack = (err.stack || '').split('\n').slice(1);
599
618
  let message = err.message;
@@ -613,18 +632,21 @@ export default (new Transformer({
613
632
  });
614
633
 
615
634
  if (getFeatureFlag('conditionalBundlingApi')) {
616
- asset.meta.conditions = conditions.map((c): ConditionMeta => ({
617
- key: c.key,
618
- ifTruePlaceholder: c.if_true_placeholder,
619
- ifFalsePlaceholder: c.if_false_placeholder,
620
- }));
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
+ );
621
643
  }
622
644
 
623
645
  if (is_constant_module) {
624
646
  asset.meta.isConstantModule = true;
625
647
  }
626
648
 
627
- let convertLoc = (loc): SourceLocation => {
649
+ let convertLoc = (loc: any): SourceLocation => {
628
650
  let location = {
629
651
  filePath: asset.filePath,
630
652
  start: {
@@ -647,19 +669,22 @@ export default (new Transformer({
647
669
 
648
670
  if (diagnostics) {
649
671
  let errors = diagnostics.filter(
672
+ // @ts-expect-error TS7006
650
673
  (d) =>
651
674
  d.severity === 'Error' ||
652
675
  (d.severity === 'SourceError' && asset.isSource),
653
676
  );
654
677
  let warnings = diagnostics.filter(
678
+ // @ts-expect-error TS7006
655
679
  (d) =>
656
680
  d.severity === 'Warning' ||
657
681
  (d.severity === 'SourceError' && !asset.isSource),
658
682
  );
659
- let convertDiagnostic = (diagnostic) => {
683
+ let convertDiagnostic = (diagnostic: any) => {
660
684
  let message = diagnostic.message;
661
685
  if (message === 'SCRIPT_ERROR') {
662
- let err = SCRIPT_ERRORS[(asset.env.context: string)];
686
+ // @ts-expect-error TS7053
687
+ let err = SCRIPT_ERRORS[asset.env.context as string];
663
688
  message = err?.message || SCRIPT_ERRORS.browser.message;
664
689
  }
665
690
 
@@ -668,11 +693,12 @@ export default (new Transformer({
668
693
  codeFrames: [
669
694
  {
670
695
  filePath: asset.filePath,
671
- codeHighlights: diagnostic.code_highlights?.map((highlight) =>
672
- convertSourceLocationToHighlight(
673
- convertLoc(highlight.loc),
674
- highlight.message ?? undefined,
675
- ),
696
+ codeHighlights: diagnostic.code_highlights?.map(
697
+ (highlight: any) =>
698
+ convertSourceLocationToHighlight(
699
+ convertLoc(highlight.loc),
700
+ highlight.message ?? undefined,
701
+ ),
676
702
  ),
677
703
  },
678
704
  ],
@@ -696,7 +722,8 @@ export default (new Transformer({
696
722
  });
697
723
  }
698
724
 
699
- let err = SCRIPT_ERRORS[(asset.env.context: string)];
725
+ // @ts-expect-error TS7053
726
+ let err = SCRIPT_ERRORS[asset.env.context as string];
700
727
  if (err) {
701
728
  if (!res.hints) {
702
729
  res.hints = [err.hint];
@@ -753,6 +780,7 @@ export default (new Transformer({
753
780
  env: {
754
781
  context: 'web-worker',
755
782
  sourceType: dep.source_type === 'Module' ? 'module' : 'script',
783
+ // @ts-expect-error TS2322
756
784
  outputFormat,
757
785
  loc,
758
786
  },
@@ -901,6 +929,7 @@ export default (new Transformer({
901
929
  idx = dep.specifier.indexOf('/', idx + 1);
902
930
  }
903
931
  let module = idx >= 0 ? dep.specifier.slice(0, idx) : dep.specifier;
932
+ // @ts-expect-error TS7053
904
933
  range = pkg.dependencies[module];
905
934
  }
906
935
 
@@ -912,12 +941,13 @@ export default (new Transformer({
912
941
  dep.kind === 'DynamicImport'
913
942
  ? 'lazy'
914
943
  : dep.kind === 'ConditionalImport'
915
- ? 'conditional'
916
- : 'sync',
944
+ ? 'conditional'
945
+ : 'sync',
917
946
  isOptional: dep.is_optional,
918
947
  meta,
919
948
  resolveFrom: isHelper ? __filename : undefined,
920
949
  range,
950
+ // @ts-expect-error TS2322
921
951
  env,
922
952
  });
923
953
  }
@@ -964,12 +994,15 @@ export default (new Transformer({
964
994
  let dep = deps.get(source);
965
995
  if (!dep) continue;
966
996
  if (local === '*' && imported === '*') {
997
+ // @ts-expect-error TS2345
967
998
  dep.symbols.set('*', '*', convertLoc(loc), true);
968
999
  } else {
969
1000
  let reExportName =
970
1001
  dep.symbols.get(imported)?.local ??
971
1002
  `$${asset.id}$re_export$${local}`;
1003
+ // @ts-expect-error TS2345
972
1004
  asset.symbols.set(local, reExportName);
1005
+ // @ts-expect-error TS2345
973
1006
  dep.symbols.set(imported, reExportName, convertLoc(loc), true);
974
1007
  }
975
1008
  }
@@ -992,6 +1025,7 @@ export default (new Transformer({
992
1025
  // Do not create a self-reference for the `default` symbol unless we have seen an __esModule flag.
993
1026
  if (
994
1027
  name === 'default' &&
1028
+ // @ts-expect-error TS2345
995
1029
  !asset.symbols.hasExportSymbol('__esModule')
996
1030
  ) {
997
1031
  continue;
@@ -1027,11 +1061,13 @@ export default (new Transformer({
1027
1061
  asset.sideEffects &&
1028
1062
  deps.size === 0 &&
1029
1063
  Object.keys(hoist_result.exported_symbols).length === 0) ||
1064
+ // @ts-expect-error TS2345
1030
1065
  (hoist_result.should_wrap && !asset.symbols.hasExportSymbol('*'))
1031
1066
  ) {
1032
1067
  if (is_empty_or_empty_export) {
1033
1068
  asset.meta.emptyFileStarReexport = true;
1034
1069
  }
1070
+ // @ts-expect-error TS2345
1035
1071
  asset.symbols.set('*', `$${asset.id}$exports`);
1036
1072
  }
1037
1073
 
@@ -1051,6 +1087,7 @@ export default (new Transformer({
1051
1087
  let dep = source ? deps.get(source) : undefined;
1052
1088
  asset.symbols.set(
1053
1089
  exported,
1090
+ // @ts-expect-error TS2345
1054
1091
  `${dep?.id ?? ''}$${local}`,
1055
1092
  convertLoc(loc),
1056
1093
  );
@@ -1058,6 +1095,7 @@ export default (new Transformer({
1058
1095
  dep.symbols.ensure();
1059
1096
  dep.symbols.set(
1060
1097
  local,
1098
+ // @ts-expect-error TS2345
1061
1099
  `${dep?.id ?? ''}$${local}`,
1062
1100
  convertLoc(loc),
1063
1101
  true,
@@ -1076,6 +1114,7 @@ export default (new Transformer({
1076
1114
  let dep = deps.get(source);
1077
1115
  if (!dep) continue;
1078
1116
  dep.symbols.ensure();
1117
+ // @ts-expect-error TS2345
1079
1118
  dep.symbols.set('*', '*', convertLoc(loc), true);
1080
1119
  }
1081
1120
 
@@ -1086,14 +1125,17 @@ export default (new Transformer({
1086
1125
  (!symbol_result.is_esm &&
1087
1126
  deps.size === 0 &&
1088
1127
  symbol_result.exports.length === 0) ||
1128
+ // @ts-expect-error TS2345
1089
1129
  (symbol_result.should_wrap && !asset.symbols.hasExportSymbol('*'))
1090
1130
  ) {
1091
1131
  asset.symbols.ensure();
1132
+ // @ts-expect-error TS2345
1092
1133
  asset.symbols.set('*', `$${asset.id}$exports`);
1093
1134
  }
1094
1135
  } else {
1095
1136
  // If the asset is wrapped, add * as a fallback
1096
1137
  asset.symbols.ensure();
1138
+ // @ts-expect-error TS2345
1097
1139
  asset.symbols.set('*', `$${asset.id}$exports`);
1098
1140
  }
1099
1141
 
@@ -1102,6 +1144,7 @@ export default (new Transformer({
1102
1144
  for (let dep of asset.getDependencies()) {
1103
1145
  if (dep.symbols.isCleared) {
1104
1146
  dep.symbols.ensure();
1147
+ // @ts-expect-error TS2345
1105
1148
  dep.symbols.set('*', `${dep.id}$`);
1106
1149
  }
1107
1150
  }
@@ -1127,6 +1170,7 @@ export default (new Transformer({
1127
1170
  let sourceMap = new SourceMap(options.projectRoot);
1128
1171
  sourceMap.addVLQMap(JSON.parse(map));
1129
1172
  if (originalMap) {
1173
+ // @ts-expect-error TS2345
1130
1174
  sourceMap.extends(originalMap);
1131
1175
  }
1132
1176
  asset.setMap(sourceMap);
@@ -1134,4 +1178,4 @@ export default (new Transformer({
1134
1178
 
1135
1179
  return [asset, ...macroAssets];
1136
1180
  },
1137
- }): Transformer<mixed>);
1181
+ }) as Transformer<unknown>;