@atlaspack/transformer-babel 2.14.21 → 2.14.22-typescript-17c3d1dec.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;
@@ -57,7 +57,6 @@ var _default = exports.default = new (_plugin().Transformer)({
57
57
  tracer
58
58
  }) {
59
59
  try {
60
- // $FlowFixMe
61
60
  if (config !== null && config !== void 0 && config.config) {
62
61
  if (asset.meta.babelPlugins != null && Array.isArray(asset.meta.babelPlugins)) {
63
62
  await (0, _babel.default)({
@@ -113,6 +112,7 @@ var _default = exports.default = new (_plugin().Transformer)({
113
112
  if (originalSourceMap) {
114
113
  // The babel AST already contains the correct mappings, but not the source contents.
115
114
  // We need to copy over the source contents from the original map.
115
+ // @ts-expect-error TS2551
116
116
  let sourcesContent = originalSourceMap.getSourcesContentMap();
117
117
  for (let filePath in sourcesContent) {
118
118
  let content = sourcesContent[filePath];
@@ -0,0 +1,11 @@
1
+ import type { MutableAsset, AST, PluginOptions, PluginTracer, PluginLogger } from '@atlaspack/types';
2
+ type Babel7TransformOptions = {
3
+ asset: MutableAsset;
4
+ options: PluginOptions;
5
+ logger: PluginLogger;
6
+ babelOptions: any;
7
+ additionalPlugins?: Array<any>;
8
+ tracer: PluginTracer;
9
+ };
10
+ export default function babel7(opts: Babel7TransformOptions): Promise<AST | null | undefined>;
11
+ export {};
package/lib/babel7.js CHANGED
@@ -37,7 +37,9 @@ var _package = _interopRequireDefault(require("../package.json"));
37
37
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
38
38
  const transformerVersion = _package.default.version;
39
39
  (0, _assert().default)(typeof transformerVersion === 'string');
40
- async function babel7(opts) {
40
+ async function babel7(opts
41
+ // @ts-expect-error TS2355
42
+ ) {
41
43
  var _babelOptions$config$;
42
44
  let {
43
45
  asset,
@@ -46,6 +48,7 @@ async function babel7(opts) {
46
48
  additionalPlugins = [],
47
49
  tracer
48
50
  } = opts;
51
+ // @ts-expect-error TS2709
49
52
  const babelCore = await options.packageManager.require('@babel/core', asset.filePath, {
50
53
  range: '^7.12.0',
51
54
  saveDev: true,
@@ -87,6 +90,7 @@ async function babel7(opts) {
87
90
  pluginKey = _path().default.relative(options.projectRoot, pluginKey);
88
91
  }
89
92
  const measurement = tracer.createMeasurement(pluginKey, nodeType, _path().default.relative(options.projectRoot, asset.filePath));
93
+ // @ts-expect-error TS2683
90
94
  fn.apply(this, arguments);
91
95
  measurement && measurement.end();
92
96
  };
@@ -108,6 +112,7 @@ async function babel7(opts) {
108
112
  for (let f of res.externalDependencies) {
109
113
  if (!_path().default.isAbsolute(f)) {
110
114
  opts.logger.warn({
115
+ // @ts-expect-error TS2345
111
116
  message: (0, _diagnostic().md)`Ignoring non-absolute Babel external dependency: ${f}`,
112
117
  hints: ['Please report this to the corresponding Babel plugin and/or to Parcel.']
113
118
  });
@@ -0,0 +1,10 @@
1
+ import type { BaseAsset } from '@atlaspack/types';
2
+ export type BabelError = Error & {
3
+ loc?: {
4
+ line: number;
5
+ column: number;
6
+ };
7
+ source?: string;
8
+ filePath?: string;
9
+ };
10
+ export declare function babelErrorEnhancer(error: BabelError, asset: BaseAsset): Promise<BabelError>;
@@ -0,0 +1,10 @@
1
+ import type { Config, PluginOptions, PluginLogger } from '@atlaspack/types';
2
+ import type { BabelConfig } from './types';
3
+ type BabelConfigResult = {
4
+ internal: boolean;
5
+ config: BabelConfig;
6
+ targets?: unknown;
7
+ syntaxPlugins?: unknown;
8
+ };
9
+ export declare function load(config: Config, options: PluginOptions, logger: PluginLogger): Promise<BabelConfigResult | null | undefined>;
10
+ export {};
package/lib/config.js CHANGED
@@ -59,6 +59,8 @@ async function load(config, options, logger) {
59
59
  if (!(await (0, _utils().resolveConfig)(options.inputFS, config.searchPath, BABEL_CONFIG_FILENAMES, options.projectRoot))) {
60
60
  return buildDefaultBabelConfig(options, config);
61
61
  }
62
+
63
+ // @ts-expect-error TS2709
62
64
  const babelCore = await options.packageManager.require('@babel/core', config.searchPath, {
63
65
  range: _constants.BABEL_CORE_RANGE,
64
66
  saveDev: true,
@@ -220,7 +222,9 @@ function definePluginDependencies(config, babelConfig, options) {
220
222
  }
221
223
  }
222
224
  const redundantPresets = new Set(['@babel/preset-env', '@babel/preset-react', '@babel/preset-typescript', '@atlaspack/babel-preset-env']);
223
- async function warnOnRedundantPlugins(fs, babelConfig, logger) {
225
+ async function warnOnRedundantPlugins(
226
+ // @ts-expect-error TS2345
227
+ fs, babelConfig, logger) {
224
228
  if (babelConfig == null) {
225
229
  return;
226
230
  }
@@ -231,6 +235,8 @@ async function warnOnRedundantPlugins(fs, babelConfig, logger) {
231
235
  let presets = babelConfig.options.presets || [];
232
236
  let plugins = babelConfig.options.plugins || [];
233
237
  let foundRedundantPresets = new Set();
238
+
239
+ // @ts-expect-error TS7006
234
240
  let filteredPresets = presets.filter(preset => {
235
241
  if (redundantPresets.has(preset.file.request)) {
236
242
  foundRedundantPresets.add(preset.file.request);
@@ -242,21 +248,25 @@ async function warnOnRedundantPlugins(fs, babelConfig, logger) {
242
248
  let diagnostics = [];
243
249
  if (filteredPresets.length === 0 && foundRedundantPresets.size > 0 && plugins.length === 0) {
244
250
  diagnostics.push({
251
+ // @ts-expect-error TS2345
245
252
  message: (0, _diagnostic().md)`Parcel includes transpilation by default. Babel config __${filePath}__ contains only redundant presets. Deleting it may significantly improve build performance.`,
246
253
  codeFrames: [{
247
254
  filePath: configPath,
248
255
  codeHighlights: await getCodeHighlights(fs, configPath, foundRedundantPresets)
249
256
  }],
257
+ // @ts-expect-error TS2345
250
258
  hints: [(0, _diagnostic().md)`Delete __${filePath}__`],
251
259
  documentationURL: 'https://parceljs.org/languages/javascript/#default-presets'
252
260
  });
253
261
  } else if (foundRedundantPresets.size > 0) {
254
262
  diagnostics.push({
263
+ // @ts-expect-error TS2345
255
264
  message: (0, _diagnostic().md)`Parcel includes transpilation by default. Babel config __${filePath}__ includes the following redundant presets: ${[...foundRedundantPresets].map(p => _diagnostic().md.underline(p))}. Removing these may improve build performance.`,
256
265
  codeFrames: [{
257
266
  filePath: configPath,
258
267
  codeHighlights: await getCodeHighlights(fs, configPath, foundRedundantPresets)
259
268
  }],
269
+ // @ts-expect-error TS2345
260
270
  hints: [(0, _diagnostic().md)`Remove the above presets from __${filePath}__`],
261
271
  documentationURL: 'https://parceljs.org/languages/javascript/#default-presets'
262
272
  });
@@ -276,7 +286,9 @@ async function warnOnRedundantPlugins(fs, babelConfig, logger) {
276
286
  logger.warn(diagnostics);
277
287
  }
278
288
  }
279
- async function getCodeHighlights(fs, filePath, redundantPresets) {
289
+ async function getCodeHighlights(
290
+ // @ts-expect-error TS2339
291
+ fs, filePath, redundantPresets) {
280
292
  let ext = _path().default.extname(filePath);
281
293
  if (ext !== '.js' && ext !== '.cjs' && ext !== '.mjs') {
282
294
  let contents = await fs.readFile(filePath, 'utf8');
@@ -0,0 +1 @@
1
+ export declare const BABEL_CORE_RANGE = "^7.12.0";
package/lib/flow.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ import type { Config, PluginOptions } from '@atlaspack/types';
2
+ import type { BabelConfig } from './types';
3
+ /**
4
+ * Generates a babel config for stripping away Flow types.
5
+ */
6
+ export default function getFlowOptions(config: Config, options: PluginOptions): Promise<BabelConfig | null | undefined>;
package/lib/flow.js CHANGED
@@ -27,6 +27,8 @@ async function getFlowOptions(config, options) {
27
27
  if (!pkg || !(pkg.dependencies && pkg.dependencies['flow-bin']) && !(pkg.devDependencies && pkg.devDependencies['flow-bin'])) {
28
28
  return null;
29
29
  }
30
+
31
+ // @ts-expect-error TS2709
30
32
  const babelCore = await options.packageManager.require('@babel/core', config.searchPath, {
31
33
  range: _constants.BABEL_CORE_RANGE,
32
34
  saveDev: true,
package/lib/jsx.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ import type { Config, PluginOptions } from '@atlaspack/types';
2
+ /**
3
+ * Returns whether an asset is likely JSX. Attempts to detect react or react-like libraries
4
+ * along with
5
+ */
6
+ export default function isJSX(options: PluginOptions, config: Config): Promise<boolean>;
@@ -0,0 +1,3 @@
1
+ import type { File as BabelNodeFile } from '@babel/types';
2
+ import type SourceMap from '@parcel/source-map';
3
+ export declare function remapAstLocations(t: BabelTypes, ast: BabelNodeFile, map: SourceMap): void;
@@ -4,7 +4,9 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.remapAstLocations = remapAstLocations;
7
- function remapAstLocations(t, ast, map) {
7
+ function remapAstLocations(
8
+ // @ts-expect-error TS2709
9
+ t, ast, map) {
8
10
  // remap ast to original mappings
9
11
  // This improves sourcemap accuracy and fixes sourcemaps when scope-hoisting
10
12
  traverseAll(t, ast.program, node => {
@@ -13,20 +15,13 @@ function remapAstLocations(t, ast, map) {
13
15
  if ((_node$loc = node.loc) !== null && _node$loc !== void 0 && _node$loc.start) {
14
16
  let mapping = map.findClosestMapping(node.loc.start.line, node.loc.start.column);
15
17
  if (mapping !== null && mapping !== void 0 && mapping.original) {
16
- // $FlowFixMe
17
18
  node.loc.start.line = mapping.original.line;
18
- // $FlowFixMe
19
19
  node.loc.start.column = mapping.original.column;
20
-
21
- // $FlowFixMe
22
20
  let length = node.loc.end.column - node.loc.start.column;
23
-
24
- // $FlowFixMe
25
21
  node.loc.end.line = mapping.original.line;
26
- // $FlowFixMe
27
22
  node.loc.end.column = mapping.original.column + length;
28
23
 
29
- // $FlowFixMe
24
+ // @ts-expect-error TS2322
30
25
  node.loc.filename = mapping.source;
31
26
  } else {
32
27
  // Maintain null mappings?
@@ -36,13 +31,15 @@ function remapAstLocations(t, ast, map) {
36
31
  }
37
32
  });
38
33
  }
39
- function traverseAll(t, node, visitor) {
34
+ function traverseAll(
35
+ // @ts-expect-error TS2709
36
+ t, node, visitor) {
40
37
  if (!node) {
41
38
  return;
42
39
  }
43
40
  visitor(node);
44
41
  for (let key of t.VISITOR_KEYS[node.type] || []) {
45
- // $FlowFixMe
42
+ // @ts-expect-error TS7053
46
43
  let subNode = node[key];
47
44
  if (Array.isArray(subNode)) {
48
45
  for (let i = 0; i < subNode.length; i++) {
package/lib/types.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ export type BabelConfig = {
2
+ plugins?: Array<any>;
3
+ presets?: Array<any>;
4
+ };
package/lib/utils.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ import type { Environment } from '@atlaspack/types';
2
+ import type { Targets as BabelTargets } from '@babel/preset-env';
3
+ export declare function enginesToBabelTargets(env: Environment): BabelTargets;
package/lib/utils.js CHANGED
@@ -19,6 +19,8 @@ function _semver() {
19
19
  return data;
20
20
  }
21
21
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
22
+ // @ts-expect-error TS7016
23
+
22
24
  // Copied from @babel/helper-compilation-targets/lib/options.js
23
25
  const TargetNames = {
24
26
  node: 'node',
@@ -45,6 +47,7 @@ function enginesToBabelTargets(env) {
45
47
  // versions, not semver ranges, of its targets.
46
48
  let targets = {};
47
49
  for (let engineName of Object.keys(env.engines)) {
50
+ // @ts-expect-error TS7053
48
51
  let engineValue = env.engines[engineName];
49
52
 
50
53
  // if the engineValue is a string, it might be a semver range. Use the minimum
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaspack/transformer-babel",
3
- "version": "2.14.21",
3
+ "version": "2.14.22-typescript-17c3d1dec.0",
4
4
  "license": "(MIT OR Apache-2.0)",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -9,26 +9,31 @@
9
9
  "type": "git",
10
10
  "url": "https://github.com/atlassian-labs/atlaspack.git"
11
11
  },
12
- "main": "lib/BabelTransformer.js",
13
- "source": "src/BabelTransformer.js",
12
+ "main": "./lib/BabelTransformer.js",
13
+ "source": "./src/BabelTransformer.ts",
14
+ "types": "./lib/BabelTransformer.d.ts",
14
15
  "engines": {
15
16
  "node": ">= 16.0.0"
16
17
  },
17
18
  "dependencies": {
18
- "@atlaspack/diagnostic": "2.14.1",
19
- "@atlaspack/plugin": "2.14.21",
19
+ "@atlaspack/diagnostic": "2.14.2-typescript-17c3d1dec.0",
20
+ "@atlaspack/plugin": "2.14.22-typescript-17c3d1dec.0",
21
+ "@atlaspack/utils": "2.17.4-typescript-17c3d1dec.0",
20
22
  "@parcel/source-map": "^2.1.1",
21
- "@atlaspack/utils": "2.17.3",
22
23
  "browserslist": "^4.6.6",
23
24
  "json5": "^2.2.0",
24
25
  "nullthrows": "^1.1.1",
25
26
  "semver": "^7.5.2"
26
27
  },
27
28
  "devDependencies": {
29
+ "@atlaspack/types": "2.15.12-typescript-17c3d1dec.0",
28
30
  "@babel/core": "^7.22.11",
29
31
  "@babel/preset-env": "^7.22.14",
30
- "@babel/types": "^7.22.11",
31
- "@atlaspack/types": "2.15.11"
32
+ "@babel/types": "^7.22.11"
32
33
  },
33
- "type": "commonjs"
34
- }
34
+ "type": "commonjs",
35
+ "scripts": {
36
+ "check-ts": "tsc --emitDeclarationOnly --rootDir src"
37
+ },
38
+ "gitHead": "17c3d1decf641e688fcfe3ca985e80e9897b7573"
39
+ }
@@ -1,5 +1,3 @@
1
- // @flow strict-local
2
-
3
1
  import {babelErrorEnhancer} from './babelErrorUtils';
4
2
  import {Transformer} from '@atlaspack/plugin';
5
3
  import {relativeUrl} from '@atlaspack/utils';
@@ -8,7 +6,7 @@ import semver from 'semver';
8
6
  import babel7 from './babel7';
9
7
  import {load} from './config';
10
8
 
11
- export default (new Transformer({
9
+ export default new Transformer({
12
10
  loadConfig({config, options, logger}) {
13
11
  return load(config, options, logger);
14
12
  },
@@ -19,7 +17,6 @@ export default (new Transformer({
19
17
 
20
18
  async transform({asset, config, logger, options, tracer}) {
21
19
  try {
22
- // $FlowFixMe
23
20
  if (config?.config) {
24
21
  if (
25
22
  asset.meta.babelPlugins != null &&
@@ -45,7 +42,7 @@ export default (new Transformer({
45
42
  }
46
43
 
47
44
  return [asset];
48
- } catch (e) {
45
+ } catch (e: any) {
49
46
  throw await babelErrorEnhancer(e, asset);
50
47
  }
51
48
  },
@@ -86,6 +83,7 @@ export default (new Transformer({
86
83
  if (originalSourceMap) {
87
84
  // The babel AST already contains the correct mappings, but not the source contents.
88
85
  // We need to copy over the source contents from the original map.
86
+ // @ts-expect-error TS2551
89
87
  let sourcesContent = originalSourceMap.getSourcesContentMap();
90
88
  for (let filePath in sourcesContent) {
91
89
  let content = sourcesContent[filePath];
@@ -100,4 +98,4 @@ export default (new Transformer({
100
98
  map,
101
99
  };
102
100
  },
103
- }): Transformer<mixed>);
101
+ }) as Transformer<unknown>;
@@ -1,5 +1,3 @@
1
- // @flow
2
-
3
1
  import type {
4
2
  MutableAsset,
5
3
  AST,
@@ -7,7 +5,7 @@ import type {
7
5
  PluginTracer,
8
6
  PluginLogger,
9
7
  } from '@atlaspack/types';
10
- import typeof * as BabelCore from '@babel/core';
8
+ import * as BabelCore from '@babel/core';
11
9
 
12
10
  import invariant from 'assert';
13
11
  import path from 'path';
@@ -17,22 +15,24 @@ import {remapAstLocations} from './remapAstLocations';
17
15
 
18
16
  import packageJson from '../package.json';
19
17
 
20
- const transformerVersion: mixed = packageJson.version;
18
+ const transformerVersion: unknown = packageJson.version;
21
19
  invariant(typeof transformerVersion === 'string');
22
20
 
23
- type Babel7TransformOptions = {|
24
- asset: MutableAsset,
25
- options: PluginOptions,
26
- logger: PluginLogger,
27
- babelOptions: any,
28
- additionalPlugins?: Array<any>,
29
- tracer: PluginTracer,
30
- |};
21
+ type Babel7TransformOptions = {
22
+ asset: MutableAsset;
23
+ options: PluginOptions;
24
+ logger: PluginLogger;
25
+ babelOptions: any;
26
+ additionalPlugins?: Array<any>;
27
+ tracer: PluginTracer;
28
+ };
31
29
 
32
30
  export default async function babel7(
33
31
  opts: Babel7TransformOptions,
34
- ): Promise<?AST> {
32
+ // @ts-expect-error TS2355
33
+ ): Promise<AST | null | undefined> {
35
34
  let {asset, options, babelOptions, additionalPlugins = [], tracer} = opts;
35
+ // @ts-expect-error TS2709
36
36
  const babelCore: BabelCore = await options.packageManager.require(
37
37
  '@babel/core',
38
38
  asset.filePath,
@@ -80,7 +80,7 @@ export default async function babel7(
80
80
  config.wrapPluginVisitorMethod = (
81
81
  key: string,
82
82
  nodeType: string,
83
- fn: Function,
83
+ fn: any,
84
84
  ) => {
85
85
  return function () {
86
86
  let pluginKey = key;
@@ -92,6 +92,7 @@ export default async function babel7(
92
92
  nodeType,
93
93
  path.relative(options.projectRoot, asset.filePath),
94
94
  );
95
+ // @ts-expect-error TS2683
95
96
  fn.apply(this, arguments);
96
97
  measurement && measurement.end();
97
98
  };
@@ -118,6 +119,7 @@ export default async function babel7(
118
119
  for (let f of res.externalDependencies) {
119
120
  if (!path.isAbsolute(f)) {
120
121
  opts.logger.warn({
122
+ // @ts-expect-error TS2345
121
123
  message: md`Ignoring non-absolute Babel external dependency: ${f}`,
122
124
  hints: [
123
125
  'Please report this to the corresponding Babel plugin and/or to Parcel.',
@@ -1,15 +1,12 @@
1
- // @flow
2
1
  import type {BaseAsset} from '@atlaspack/types';
3
2
 
4
3
  export type BabelError = Error & {
5
4
  loc?: {
6
- line: number,
7
- column: number,
8
- ...
9
- },
10
- source?: string,
11
- filePath?: string,
12
- ...
5
+ line: number;
6
+ column: number;
7
+ };
8
+ source?: string;
9
+ filePath?: string;
13
10
  };
14
11
 
15
12
  export async function babelErrorEnhancer(
@@ -1,7 +1,5 @@
1
- // @flow
2
-
3
1
  import type {Config, PluginOptions, PluginLogger} from '@atlaspack/types';
4
- import typeof * as BabelCore from '@babel/core';
2
+ import * as BabelCore from '@babel/core';
5
3
  import type {Diagnostic} from '@atlaspack/diagnostic';
6
4
  import type {BabelConfig} from './types';
7
5
 
@@ -30,18 +28,18 @@ const BABEL_CONFIG_FILENAMES = [
30
28
  'babel.config.cjs',
31
29
  ];
32
30
 
33
- type BabelConfigResult = {|
34
- internal: boolean,
35
- config: BabelConfig,
36
- targets?: mixed,
37
- syntaxPlugins?: mixed,
38
- |};
31
+ type BabelConfigResult = {
32
+ internal: boolean;
33
+ config: BabelConfig;
34
+ targets?: unknown;
35
+ syntaxPlugins?: unknown;
36
+ };
39
37
 
40
38
  export async function load(
41
39
  config: Config,
42
40
  options: PluginOptions,
43
41
  logger: PluginLogger,
44
- ): Promise<?BabelConfigResult> {
42
+ ): Promise<BabelConfigResult | null | undefined> {
45
43
  // Don't transpile inside node_modules
46
44
  if (!config.isSource) {
47
45
  return;
@@ -68,6 +66,7 @@ export async function load(
68
66
  return buildDefaultBabelConfig(options, config);
69
67
  }
70
68
 
69
+ // @ts-expect-error TS2709
71
70
  const babelCore: BabelCore = await options.packageManager.require(
72
71
  '@babel/core',
73
72
  config.searchPath,
@@ -98,11 +97,14 @@ export async function load(
98
97
  showIgnoredFiles: true,
99
98
  };
100
99
 
101
- let partialConfig: ?{|
102
- [string]: any,
103
- |} = await babelCore.loadPartialConfigAsync(babelOptions);
100
+ let partialConfig:
101
+ | {
102
+ [key: string]: any;
103
+ }
104
+ | null
105
+ | undefined = await babelCore.loadPartialConfigAsync(babelOptions);
104
106
 
105
- let addIncludedFile = (file) => {
107
+ let addIncludedFile = (file: string) => {
106
108
  if (JS_EXTNAME_RE.test(path.extname(file))) {
107
109
  // We need to invalidate on startup in case the config is non-static,
108
110
  // e.g. uses unknown environment variables, reads from the filesystem, etc.
@@ -173,7 +175,7 @@ export async function load(
173
175
  return;
174
176
  } else if (partialConfig.hasFilesystemConfig()) {
175
177
  // Determine what syntax plugins we need to enable
176
- let syntaxPlugins = [];
178
+ let syntaxPlugins: Array<string> = [];
177
179
  if (TYPESCRIPT_EXTNAME_RE.test(config.searchPath)) {
178
180
  syntaxPlugins.push('typescript');
179
181
  if (config.searchPath.endsWith('.tsx')) {
@@ -213,7 +215,7 @@ export async function load(
213
215
  async function buildDefaultBabelConfig(
214
216
  options: PluginOptions,
215
217
  config: Config,
216
- ): Promise<?BabelConfigResult> {
218
+ ): Promise<BabelConfigResult | null | undefined> {
217
219
  // If this is a .ts or .tsx file, we don't need to enable flow.
218
220
  if (TYPESCRIPT_EXTNAME_RE.test(config.searchPath)) {
219
221
  return;
@@ -226,7 +228,7 @@ async function buildDefaultBabelConfig(
226
228
  }
227
229
 
228
230
  // When flow is enabled, we may also need to enable JSX so it parses properly.
229
- let syntaxPlugins = [];
231
+ let syntaxPlugins: Array<string> = [];
230
232
  if (await isJSX(options, config)) {
231
233
  syntaxPlugins.push('jsx');
232
234
  }
@@ -239,12 +241,16 @@ async function buildDefaultBabelConfig(
239
241
  };
240
242
  }
241
243
 
242
- function hasRequire(options) {
244
+ function hasRequire(options: any) {
243
245
  let configItems = [...options.presets, ...options.plugins];
244
246
  return configItems.some((item) => !item.file);
245
247
  }
246
248
 
247
- function definePluginDependencies(config, babelConfig: ?BabelConfig, options) {
249
+ function definePluginDependencies(
250
+ config: Config,
251
+ babelConfig: BabelConfig | null | undefined,
252
+ options: PluginOptions,
253
+ ) {
248
254
  if (babelConfig == null) {
249
255
  return;
250
256
  }
@@ -280,7 +286,14 @@ const redundantPresets = new Set([
280
286
  '@atlaspack/babel-preset-env',
281
287
  ]);
282
288
 
283
- async function warnOnRedundantPlugins(fs, babelConfig, logger) {
289
+ async function warnOnRedundantPlugins(
290
+ // @ts-expect-error TS2345
291
+ fs: FileSystem,
292
+ babelConfig: {
293
+ [key: string]: any;
294
+ },
295
+ logger: PluginLogger,
296
+ ) {
284
297
  if (babelConfig == null) {
285
298
  return;
286
299
  }
@@ -294,6 +307,7 @@ async function warnOnRedundantPlugins(fs, babelConfig, logger) {
294
307
  let plugins = babelConfig.options.plugins || [];
295
308
  let foundRedundantPresets = new Set();
296
309
 
310
+ // @ts-expect-error TS7006
297
311
  let filteredPresets = presets.filter((preset) => {
298
312
  if (redundantPresets.has(preset.file.request)) {
299
313
  foundRedundantPresets.add(preset.file.request);
@@ -312,6 +326,7 @@ async function warnOnRedundantPlugins(fs, babelConfig, logger) {
312
326
  plugins.length === 0
313
327
  ) {
314
328
  diagnostics.push({
329
+ // @ts-expect-error TS2345
315
330
  message: md`Parcel includes transpilation by default. Babel config __${filePath}__ contains only redundant presets. Deleting it may significantly improve build performance.`,
316
331
  codeFrames: [
317
332
  {
@@ -323,12 +338,14 @@ async function warnOnRedundantPlugins(fs, babelConfig, logger) {
323
338
  ),
324
339
  },
325
340
  ],
341
+ // @ts-expect-error TS2345
326
342
  hints: [md`Delete __${filePath}__`],
327
343
  documentationURL:
328
344
  'https://parceljs.org/languages/javascript/#default-presets',
329
345
  });
330
346
  } else if (foundRedundantPresets.size > 0) {
331
347
  diagnostics.push({
348
+ // @ts-expect-error TS2345
332
349
  message: md`Parcel includes transpilation by default. Babel config __${filePath}__ includes the following redundant presets: ${[
333
350
  ...foundRedundantPresets,
334
351
  ].map((p) =>
@@ -344,6 +361,7 @@ async function warnOnRedundantPlugins(fs, babelConfig, logger) {
344
361
  ),
345
362
  },
346
363
  ],
364
+ // @ts-expect-error TS2345
347
365
  hints: [md`Remove the above presets from __${filePath}__`],
348
366
  documentationURL:
349
367
  'https://parceljs.org/languages/javascript/#default-presets',
@@ -377,14 +395,23 @@ async function warnOnRedundantPlugins(fs, babelConfig, logger) {
377
395
  }
378
396
  }
379
397
 
380
- async function getCodeHighlights(fs, filePath, redundantPresets) {
398
+ async function getCodeHighlights(
399
+ // @ts-expect-error TS2339
400
+ fs: FileSystem,
401
+ filePath: any,
402
+ redundantPresets: Set<any | string>,
403
+ ) {
381
404
  let ext = path.extname(filePath);
382
405
  if (ext !== '.js' && ext !== '.cjs' && ext !== '.mjs') {
383
406
  let contents = await fs.readFile(filePath, 'utf8');
384
407
  let json = json5.parse(contents);
385
408
 
386
409
  let presets = json.presets || [];
387
- let pointers = [];
410
+ let pointers: Array<{
411
+ key: string;
412
+ message?: string;
413
+ type?: 'key' | 'value' | null | undefined;
414
+ }> = [];
388
415
  for (let i = 0; i < presets.length; i++) {
389
416
  if (Array.isArray(presets[i]) && redundantPresets.has(presets[i][0])) {
390
417
  pointers.push({type: 'value', key: `/presets/${i}/0`});
@@ -1,3 +1 @@
1
- // @flow strict-local
2
-
3
1
  export const BABEL_CORE_RANGE = '^7.12.0';
@@ -1,8 +1,6 @@
1
- // @flow
2
-
3
1
  import type {Config, PluginOptions, PackageJSON} from '@atlaspack/types';
4
2
  import type {BabelConfig} from './types';
5
- import typeof * as BabelCore from '@babel/core';
3
+ import * as BabelCore from '@babel/core';
6
4
 
7
5
  import {BABEL_CORE_RANGE} from './constants';
8
6
  import path from 'path';
@@ -13,7 +11,7 @@ import path from 'path';
13
11
  export default async function getFlowOptions(
14
12
  config: Config,
15
13
  options: PluginOptions,
16
- ): Promise<?BabelConfig> {
14
+ ): Promise<BabelConfig | null | undefined> {
17
15
  if (!config.isSource) {
18
16
  return null;
19
17
  }
@@ -32,6 +30,7 @@ export default async function getFlowOptions(
32
30
  return null;
33
31
  }
34
32
 
33
+ // @ts-expect-error TS2709
35
34
  const babelCore: BabelCore = await options.packageManager.require(
36
35
  '@babel/core',
37
36
  config.searchPath,
@@ -1,5 +1,3 @@
1
- // @flow strict-local
2
-
3
1
  import type {Config, PluginOptions} from '@atlaspack/types';
4
2
 
5
3
  import path from 'path';
@@ -1,11 +1,10 @@
1
- // @flow strict-local
2
-
3
1
  import type {File as BabelNodeFile} from '@babel/types';
4
2
  import type SourceMap from '@parcel/source-map';
5
3
  import type {Node} from '@babel/types';
6
- import typeof * as BabelTypes from '@babel/types';
4
+ import * as BabelTypes from '@babel/types';
7
5
 
8
6
  export function remapAstLocations(
7
+ // @ts-expect-error TS2709
9
8
  t: BabelTypes,
10
9
  ast: BabelNodeFile,
11
10
  map: SourceMap,
@@ -21,20 +20,15 @@ export function remapAstLocations(
21
20
  );
22
21
 
23
22
  if (mapping?.original) {
24
- // $FlowFixMe
25
23
  node.loc.start.line = mapping.original.line;
26
- // $FlowFixMe
27
24
  node.loc.start.column = mapping.original.column;
28
25
 
29
- // $FlowFixMe
30
26
  let length = node.loc.end.column - node.loc.start.column;
31
27
 
32
- // $FlowFixMe
33
28
  node.loc.end.line = mapping.original.line;
34
- // $FlowFixMe
35
29
  node.loc.end.column = mapping.original.column + length;
36
30
 
37
- // $FlowFixMe
31
+ // @ts-expect-error TS2322
38
32
  node.loc.filename = mapping.source;
39
33
  } else {
40
34
  // Maintain null mappings?
@@ -46,6 +40,7 @@ export function remapAstLocations(
46
40
  }
47
41
 
48
42
  function traverseAll(
43
+ // @ts-expect-error TS2709
49
44
  t: BabelTypes,
50
45
  node: Node,
51
46
  visitor: (node: Node) => void,
@@ -57,7 +52,7 @@ function traverseAll(
57
52
  visitor(node);
58
53
 
59
54
  for (let key of t.VISITOR_KEYS[node.type] || []) {
60
- // $FlowFixMe
55
+ // @ts-expect-error TS7053
61
56
  let subNode: Node | Array<Node> = node[key];
62
57
  if (Array.isArray(subNode)) {
63
58
  for (let i = 0; i < subNode.length; i++) {
package/src/types.ts ADDED
@@ -0,0 +1,4 @@
1
+ export type BabelConfig = {
2
+ plugins?: Array<any>;
3
+ presets?: Array<any>;
4
+ };
@@ -1,6 +1,5 @@
1
- // @flow
2
-
3
1
  import type {Environment} from '@atlaspack/types';
2
+ // @ts-expect-error TS7016
4
3
  import type {Targets as BabelTargets} from '@babel/preset-env';
5
4
 
6
5
  import invariant from 'assert';
@@ -20,7 +19,7 @@ const TargetNames = {
20
19
  electron: 'electron',
21
20
  samsung: 'samsung',
22
21
  rhino: 'rhino',
23
- };
22
+ } as const;
24
23
 
25
24
  // List of browsers to exclude when the esmodule target is specified.
26
25
  // Based on https://caniuse.com/#feat=es6-module
@@ -51,8 +50,9 @@ export function enginesToBabelTargets(env: Environment): BabelTargets {
51
50
  // This should not be confused with Parcel's own targets.
52
51
  // Unlike Parcel's engines, @babel/preset-env expects to work with minimum
53
52
  // versions, not semver ranges, of its targets.
54
- let targets = {};
53
+ let targets: Record<string, any> = {};
55
54
  for (let engineName of Object.keys(env.engines)) {
55
+ // @ts-expect-error TS7053
56
56
  let engineValue = env.engines[engineName];
57
57
 
58
58
  // if the engineValue is a string, it might be a semver range. Use the minimum
package/tsconfig.json ADDED
@@ -0,0 +1,4 @@
1
+ {
2
+ "extends": "../../../tsconfig.json",
3
+ "include": ["src"]
4
+ }
package/src/types.js DELETED
@@ -1,6 +0,0 @@
1
- // @flow
2
-
3
- export type BabelConfig = {|
4
- plugins?: Array<any>,
5
- presets?: Array<any>,
6
- |};