@parcel/transformer-babel 2.8.4-nightly.0 → 2.9.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.
@@ -4,55 +4,38 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
-
8
7
  var _babelErrorUtils = require("./babelErrorUtils");
9
-
10
8
  function _plugin() {
11
9
  const data = require("@parcel/plugin");
12
-
13
10
  _plugin = function () {
14
11
  return data;
15
12
  };
16
-
17
13
  return data;
18
14
  }
19
-
20
15
  function _utils() {
21
16
  const data = require("@parcel/utils");
22
-
23
17
  _utils = function () {
24
18
  return data;
25
19
  };
26
-
27
20
  return data;
28
21
  }
29
-
30
22
  function _sourceMap() {
31
23
  const data = _interopRequireDefault(require("@parcel/source-map"));
32
-
33
24
  _sourceMap = function () {
34
25
  return data;
35
26
  };
36
-
37
27
  return data;
38
28
  }
39
-
40
29
  function _semver() {
41
30
  const data = _interopRequireDefault(require("semver"));
42
-
43
31
  _semver = function () {
44
32
  return data;
45
33
  };
46
-
47
34
  return data;
48
35
  }
49
-
50
36
  var _babel = _interopRequireDefault(require("./babel7"));
51
-
52
37
  var _config = require("./config");
53
-
54
38
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
55
-
56
39
  var _default = new (_plugin().Transformer)({
57
40
  loadConfig({
58
41
  config,
@@ -61,13 +44,11 @@ var _default = new (_plugin().Transformer)({
61
44
  }) {
62
45
  return (0, _config.load)(config, options, logger);
63
46
  },
64
-
65
47
  canReuseAST({
66
48
  ast
67
49
  }) {
68
50
  return ast.type === 'babel' && _semver().default.satisfies(ast.version, '^7.0.0');
69
51
  },
70
-
71
52
  async transform({
72
53
  asset,
73
54
  config,
@@ -96,13 +77,11 @@ var _default = new (_plugin().Transformer)({
96
77
  });
97
78
  }
98
79
  }
99
-
100
80
  return [asset];
101
81
  } catch (e) {
102
82
  throw await (0, _babelErrorUtils.babelErrorEnhancer)(e, asset);
103
83
  }
104
84
  },
105
-
106
85
  async generate({
107
86
  asset,
108
87
  ast,
@@ -127,31 +106,24 @@ var _default = new (_plugin().Transformer)({
127
106
  comments: true
128
107
  });
129
108
  let map = new (_sourceMap().default)(options.projectRoot);
130
-
131
109
  if (rawMappings) {
132
110
  map.addIndexedMappings(rawMappings);
133
111
  }
134
-
135
112
  if (originalSourceMap) {
136
113
  // The babel AST already contains the correct mappings, but not the source contents.
137
114
  // We need to copy over the source contents from the original map.
138
115
  let sourcesContent = originalSourceMap.getSourcesContentMap();
139
-
140
116
  for (let filePath in sourcesContent) {
141
117
  let content = sourcesContent[filePath];
142
-
143
118
  if (content != null) {
144
119
  map.setSourceContent(filePath, content);
145
120
  }
146
121
  }
147
122
  }
148
-
149
123
  return {
150
124
  content: code,
151
125
  map
152
126
  };
153
127
  }
154
-
155
128
  });
156
-
157
129
  exports.default = _default;
package/lib/babel7.js CHANGED
@@ -4,59 +4,41 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = babel7;
7
-
8
7
  function _assert() {
9
8
  const data = _interopRequireDefault(require("assert"));
10
-
11
9
  _assert = function () {
12
10
  return data;
13
11
  };
14
-
15
12
  return data;
16
13
  }
17
-
18
14
  function _path() {
19
15
  const data = _interopRequireDefault(require("path"));
20
-
21
16
  _path = function () {
22
17
  return data;
23
18
  };
24
-
25
19
  return data;
26
20
  }
27
-
28
21
  function _diagnostic() {
29
22
  const data = require("@parcel/diagnostic");
30
-
31
23
  _diagnostic = function () {
32
24
  return data;
33
25
  };
34
-
35
26
  return data;
36
27
  }
37
-
38
28
  function _utils() {
39
29
  const data = require("@parcel/utils");
40
-
41
30
  _utils = function () {
42
31
  return data;
43
32
  };
44
-
45
33
  return data;
46
34
  }
47
-
48
35
  var _remapAstLocations = require("./remapAstLocations");
49
-
50
36
  var _package = _interopRequireDefault(require("../package.json"));
51
-
52
37
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
53
-
54
38
  const transformerVersion = _package.default.version;
55
39
  (0, _assert().default)(typeof transformerVersion === 'string');
56
-
57
40
  async function babel7(opts) {
58
41
  var _babelOptions$config$, _babelOptions$config$2, _babelOptions$syntaxP;
59
-
60
42
  let {
61
43
  asset,
62
44
  options,
@@ -69,22 +51,27 @@ async function babel7(opts) {
69
51
  saveDev: true,
70
52
  shouldAutoInstall: options.shouldAutoInstall
71
53
  });
72
- let config = { ...babelOptions.config,
54
+ let config = {
55
+ ...babelOptions.config,
73
56
  plugins: additionalPlugins.concat(babelOptions.config.plugins),
74
57
  code: false,
75
58
  ast: true,
76
59
  filename: asset.filePath,
77
60
  babelrc: false,
78
61
  configFile: false,
79
- parserOpts: { ...babelOptions.config.parserOpts,
62
+ parserOpts: {
63
+ ...babelOptions.config.parserOpts,
80
64
  sourceFilename: (0, _utils().relativeUrl)(options.projectRoot, asset.filePath),
81
65
  allowReturnOutsideFunction: true,
82
66
  strictMode: false,
83
67
  sourceType: 'module',
84
- plugins: [...((_babelOptions$config$ = (_babelOptions$config$2 = babelOptions.config.parserOpts) === null || _babelOptions$config$2 === void 0 ? void 0 : _babelOptions$config$2.plugins) !== null && _babelOptions$config$ !== void 0 ? _babelOptions$config$ : []), ...((_babelOptions$syntaxP = babelOptions.syntaxPlugins) !== null && _babelOptions$syntaxP !== void 0 ? _babelOptions$syntaxP : []), // Applied by preset-env
85
- 'classProperties', 'classPrivateProperties', 'classPrivateMethods', 'exportDefaultFrom' // 'topLevelAwait'
68
+ plugins: [...((_babelOptions$config$ = (_babelOptions$config$2 = babelOptions.config.parserOpts) === null || _babelOptions$config$2 === void 0 ? void 0 : _babelOptions$config$2.plugins) !== null && _babelOptions$config$ !== void 0 ? _babelOptions$config$ : []), ...((_babelOptions$syntaxP = babelOptions.syntaxPlugins) !== null && _babelOptions$syntaxP !== void 0 ? _babelOptions$syntaxP : []),
69
+ // Applied by preset-env
70
+ 'classProperties', 'classPrivateProperties', 'classPrivateMethods', 'exportDefaultFrom'
71
+ // 'topLevelAwait'
86
72
  ]
87
73
  },
74
+
88
75
  caller: {
89
76
  name: 'parcel',
90
77
  version: transformerVersion,
@@ -92,39 +79,31 @@ async function babel7(opts) {
92
79
  outputFormat: asset.env.outputFormat
93
80
  }
94
81
  };
95
-
96
82
  if (tracer.enabled) {
97
83
  config.wrapPluginVisitorMethod = (key, nodeType, fn) => {
98
84
  return function () {
99
85
  let pluginKey = key;
100
-
101
86
  if (pluginKey.startsWith(options.projectRoot)) {
102
87
  pluginKey = _path().default.relative(options.projectRoot, pluginKey);
103
88
  }
104
-
105
89
  const measurement = tracer.createMeasurement(pluginKey, nodeType, _path().default.relative(options.projectRoot, asset.filePath));
106
90
  fn.apply(this, arguments);
107
91
  measurement && measurement.end();
108
92
  };
109
93
  };
110
94
  }
111
-
112
95
  let ast = await asset.getAST();
113
96
  let res;
114
-
115
97
  if (ast) {
116
98
  res = await babelCore.transformFromAstAsync(ast.program, asset.isASTDirty() ? undefined : await asset.getCode(), config);
117
99
  } else {
118
100
  res = await babelCore.transformAsync(await asset.getCode(), config);
119
-
120
101
  if (res.ast) {
121
102
  let map = await asset.getMap();
122
-
123
103
  if (map) {
124
104
  (0, _remapAstLocations.remapAstLocations)(babelCore.types, res.ast, map);
125
105
  }
126
106
  }
127
-
128
107
  if (res.externalDependencies) {
129
108
  for (let f of res.externalDependencies) {
130
109
  if (!_path().default.isAbsolute(f)) {
@@ -144,7 +123,6 @@ async function babel7(opts) {
144
123
  }
145
124
  }
146
125
  }
147
-
148
126
  if (res.ast) {
149
127
  asset.setAST({
150
128
  type: 'babel',
@@ -4,13 +4,11 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.babelErrorEnhancer = babelErrorEnhancer;
7
-
8
7
  async function babelErrorEnhancer(error, asset) {
9
8
  if (error.loc) {
10
9
  let start = error.message.startsWith(asset.filePath) ? asset.filePath.length + 1 : 0;
11
10
  error.message = error.message.slice(start).split('\n')[0].trim();
12
11
  }
13
-
14
12
  error.source = await asset.getCode();
15
13
  error.filePath = asset.filePath;
16
14
  return error;
package/lib/config.js CHANGED
@@ -4,83 +4,62 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.load = load;
7
-
8
7
  function _json() {
9
8
  const data = _interopRequireDefault(require("json5"));
10
-
11
9
  _json = function () {
12
10
  return data;
13
11
  };
14
-
15
12
  return data;
16
13
  }
17
-
18
14
  function _path() {
19
15
  const data = _interopRequireDefault(require("path"));
20
-
21
16
  _path = function () {
22
17
  return data;
23
18
  };
24
-
25
19
  return data;
26
20
  }
27
-
28
21
  function _utils() {
29
22
  const data = require("@parcel/utils");
30
-
31
23
  _utils = function () {
32
24
  return data;
33
25
  };
34
-
35
26
  return data;
36
27
  }
37
-
38
28
  function _diagnostic() {
39
29
  const data = require("@parcel/diagnostic");
40
-
41
30
  _diagnostic = function () {
42
31
  return data;
43
32
  };
44
-
45
33
  return data;
46
34
  }
47
-
48
35
  var _constants = require("./constants");
49
-
50
36
  var _jsx = _interopRequireDefault(require("./jsx"));
51
-
52
37
  var _flow = _interopRequireDefault(require("./flow"));
53
-
54
38
  var _utils2 = require("./utils");
55
-
56
39
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
57
-
58
40
  const TYPESCRIPT_EXTNAME_RE = /\.tsx?$/;
59
41
  const JS_EXTNAME_RE = /^\.(js|cjs|mjs)$/;
60
42
  const BABEL_CONFIG_FILENAMES = ['.babelrc', '.babelrc.js', '.babelrc.json', '.babelrc.cjs', '.babelrc.mjs', '.babelignore', 'babel.config.js', 'babel.config.json', 'babel.config.mjs', 'babel.config.cjs'];
61
-
62
43
  async function load(config, options, logger) {
63
44
  var _ref, _ref2, _options$env$BABEL_EN;
64
-
65
45
  // Don't transpile inside node_modules
66
46
  if (!config.isSource) {
67
47
  return;
68
- } // Invalidate when any babel config file is added.
69
-
48
+ }
70
49
 
50
+ // Invalidate when any babel config file is added.
71
51
  for (let fileName of BABEL_CONFIG_FILENAMES) {
72
52
  config.invalidateOnFileCreate({
73
53
  fileName,
74
54
  aboveFilePath: config.searchPath
75
55
  });
76
- } // Do nothing if we cannot resolve any babel config filenames. Checking using our own
77
- // config resolution (which is cached) is much faster than relying on babel.
78
-
56
+ }
79
57
 
58
+ // Do nothing if we cannot resolve any babel config filenames. Checking using our own
59
+ // config resolution (which is cached) is much faster than relying on babel.
80
60
  if (!(await (0, _utils().resolveConfig)(options.inputFS, config.searchPath, BABEL_CONFIG_FILENAMES, options.projectRoot))) {
81
61
  return buildDefaultBabelConfig(options, config);
82
62
  }
83
-
84
63
  const babelCore = await options.packageManager.require('@babel/core', config.searchPath, {
85
64
  range: _constants.BABEL_CORE_RANGE,
86
65
  saveDev: true,
@@ -100,7 +79,6 @@ async function load(config, options, logger) {
100
79
  showIgnoredFiles: true
101
80
  };
102
81
  let partialConfig = await babelCore.loadPartialConfigAsync(babelOptions);
103
-
104
82
  let addIncludedFile = file => {
105
83
  if (JS_EXTNAME_RE.test(_path().default.extname(file))) {
106
84
  // We need to invalidate on startup in case the config is non-static,
@@ -108,8 +86,9 @@ async function load(config, options, logger) {
108
86
  logger.warn({
109
87
  message: `It looks like you're using a JavaScript Babel config file. This means the config cannot be watched for changes, and Babel transformations cannot be cached. You'll need to restart Parcel for changes to this config to take effect. Try using a ${_path().default.basename(file, _path().default.extname(file)) + '.json'} file instead.`
110
88
  });
111
- config.invalidateOnStartup(); // But also add the config as a dev dependency so we can at least attempt invalidation in watch mode.
89
+ config.invalidateOnStartup();
112
90
 
91
+ // But also add the config as a dev dependency so we can at least attempt invalidation in watch mode.
113
92
  config.addDevDependency({
114
93
  specifier: (0, _utils().relativePath)(options.projectRoot, file),
115
94
  resolveFrom: _path().default.join(options.projectRoot, 'index'),
@@ -125,30 +104,26 @@ async function load(config, options, logger) {
125
104
  config.invalidateOnFileChange(file);
126
105
  }
127
106
  };
128
-
129
107
  let warnOldVersion = () => {
130
108
  logger.warn({
131
109
  message: 'You are using an old version of @babel/core which does not support the necessary features for Parcel to cache and watch babel config files safely. You may need to restart Parcel for config changes to take effect. Please upgrade to @babel/core 7.12.0 or later to resolve this issue.'
132
110
  });
133
111
  config.invalidateOnStartup();
134
- }; // Old versions of @babel/core return null from loadPartialConfig when the file should explicitly not be run through babel (ignore/exclude)
135
-
112
+ };
136
113
 
114
+ // Old versions of @babel/core return null from loadPartialConfig when the file should explicitly not be run through babel (ignore/exclude)
137
115
  if (partialConfig == null) {
138
116
  warnOldVersion();
139
117
  return;
140
118
  }
141
-
142
119
  if (partialConfig.files == null) {
143
120
  // If the files property is missing, we're on an old version of @babel/core.
144
121
  // We need to invalidate on startup because we can't properly track dependencies.
145
122
  if (partialConfig.hasFilesystemConfig()) {
146
123
  warnOldVersion();
147
-
148
124
  if (typeof partialConfig.babelrcPath === 'string') {
149
125
  addIncludedFile(partialConfig.babelrcPath);
150
126
  }
151
-
152
127
  if (typeof partialConfig.configPath === 'string') {
153
128
  addIncludedFile(partialConfig.configPath);
154
129
  }
@@ -158,23 +133,20 @@ async function load(config, options, logger) {
158
133
  addIncludedFile(file);
159
134
  }
160
135
  }
161
-
162
136
  if (partialConfig.fileHandling != null && partialConfig.fileHandling !== 'transpile') {} else if (partialConfig.hasFilesystemConfig()) {
163
137
  // Determine what syntax plugins we need to enable
164
138
  let syntaxPlugins = [];
165
-
166
139
  if (TYPESCRIPT_EXTNAME_RE.test(config.searchPath)) {
167
140
  syntaxPlugins.push('typescript');
168
-
169
141
  if (config.searchPath.endsWith('.tsx')) {
170
142
  syntaxPlugins.push('jsx');
171
143
  }
172
144
  } else if (await (0, _jsx.default)(options, config)) {
173
145
  syntaxPlugins.push('jsx');
174
- } // If the config has plugins loaded with require(), or inline plugins in the config,
175
- // we can't cache the result of the compilation because we don't know where they came from.
176
-
146
+ }
177
147
 
148
+ // If the config has plugins loaded with require(), or inline plugins in the config,
149
+ // we can't cache the result of the compilation because we don't know where they came from.
178
150
  if (hasRequire(partialConfig.options)) {
179
151
  logger.warn({
180
152
  message: 'It looks like you are using `require` to configure Babel plugins or presets. This means Babel transformations cannot be cached and will run on each build. Please use strings to configure Babel instead.'
@@ -186,7 +158,6 @@ async function load(config, options, logger) {
186
158
  definePluginDependencies(config, partialConfig.options, options);
187
159
  config.setCacheKey((0, _utils().hashObject)(partialConfig.options));
188
160
  }
189
-
190
161
  return {
191
162
  internal: false,
192
163
  config: partialConfig.options,
@@ -197,27 +168,23 @@ async function load(config, options, logger) {
197
168
  return buildDefaultBabelConfig(options, config);
198
169
  }
199
170
  }
200
-
201
171
  async function buildDefaultBabelConfig(options, config) {
202
172
  // If this is a .ts or .tsx file, we don't need to enable flow.
203
173
  if (TYPESCRIPT_EXTNAME_RE.test(config.searchPath)) {
204
174
  return;
205
- } // Detect flow. If not enabled, babel doesn't need to run at all.
206
-
175
+ }
207
176
 
177
+ // Detect flow. If not enabled, babel doesn't need to run at all.
208
178
  let babelOptions = await (0, _flow.default)(config, options);
209
-
210
179
  if (babelOptions == null) {
211
180
  return;
212
- } // When flow is enabled, we may also need to enable JSX so it parses properly.
213
-
181
+ }
214
182
 
183
+ // When flow is enabled, we may also need to enable JSX so it parses properly.
215
184
  let syntaxPlugins = [];
216
-
217
185
  if (await (0, _jsx.default)(options, config)) {
218
186
  syntaxPlugins.push('jsx');
219
187
  }
220
-
221
188
  definePluginDependencies(config, babelOptions, options);
222
189
  return {
223
190
  internal: true,
@@ -225,19 +192,15 @@ async function buildDefaultBabelConfig(options, config) {
225
192
  syntaxPlugins
226
193
  };
227
194
  }
228
-
229
195
  function hasRequire(options) {
230
196
  let configItems = [...options.presets, ...options.plugins];
231
197
  return configItems.some(item => !item.file);
232
198
  }
233
-
234
199
  function definePluginDependencies(config, babelConfig, options) {
235
200
  if (babelConfig == null) {
236
201
  return;
237
202
  }
238
-
239
203
  let configItems = [...(babelConfig.presets || []), ...(babelConfig.plugins || [])];
240
-
241
204
  for (let configItem of configItems) {
242
205
  // FIXME: this uses a relative path from the project root rather than resolving
243
206
  // from the config location because configItem.file.request can be a shorthand
@@ -255,22 +218,16 @@ function definePluginDependencies(config, babelConfig, options) {
255
218
  });
256
219
  }
257
220
  }
258
-
259
221
  const redundantPresets = new Set(['@babel/preset-env', '@babel/preset-react', '@babel/preset-typescript', '@parcel/babel-preset-env']);
260
-
261
222
  async function warnOnRedundantPlugins(fs, babelConfig, logger) {
262
223
  var _babelConfig$config;
263
-
264
224
  if (babelConfig == null) {
265
225
  return;
266
226
  }
267
-
268
227
  let configPath = (_babelConfig$config = babelConfig.config) !== null && _babelConfig$config !== void 0 ? _babelConfig$config : babelConfig.babelrc;
269
-
270
228
  if (!configPath) {
271
229
  return;
272
230
  }
273
-
274
231
  let presets = babelConfig.options.presets || [];
275
232
  let plugins = babelConfig.options.plugins || [];
276
233
  let foundRedundantPresets = new Set();
@@ -279,14 +236,10 @@ async function warnOnRedundantPlugins(fs, babelConfig, logger) {
279
236
  foundRedundantPresets.add(preset.file.request);
280
237
  return false;
281
238
  }
282
-
283
239
  return true;
284
240
  });
285
-
286
241
  let filePath = _path().default.relative(process.cwd(), configPath);
287
-
288
242
  let diagnostics = [];
289
-
290
243
  if (filteredPresets.length === 0 && foundRedundantPresets.size > 0 && plugins.length === 0) {
291
244
  diagnostics.push({
292
245
  message: (0, _diagnostic().md)`Parcel includes transpilation by default. Babel config __${filePath}__ contains only redundant presets. Deleting it may significantly improve build performance.`,
@@ -308,10 +261,8 @@ async function warnOnRedundantPlugins(fs, babelConfig, logger) {
308
261
  documentationURL: 'https://parceljs.org/languages/javascript/#default-presets'
309
262
  });
310
263
  }
311
-
312
264
  if (foundRedundantPresets.has('@babel/preset-env')) {
313
265
  var _babelConfig$config2, _babelConfig$config3;
314
-
315
266
  diagnostics.push({
316
267
  message: "@babel/preset-env does not support Parcel's targets, which will likely result in unnecessary transpilation and larger bundle sizes.",
317
268
  codeFrames: [{
@@ -322,23 +273,17 @@ async function warnOnRedundantPlugins(fs, babelConfig, logger) {
322
273
  documentationURL: 'https://parceljs.org/languages/javascript/#custom-plugins'
323
274
  });
324
275
  }
325
-
326
276
  if (diagnostics.length > 0) {
327
277
  logger.warn(diagnostics);
328
278
  }
329
279
  }
330
-
331
280
  async function getCodeHighlights(fs, filePath, redundantPresets) {
332
281
  let ext = _path().default.extname(filePath);
333
-
334
282
  if (ext !== '.js' && ext !== '.cjs' && ext !== '.mjs') {
335
283
  let contents = await fs.readFile(filePath, 'utf8');
336
-
337
284
  let json = _json().default.parse(contents);
338
-
339
285
  let presets = json.presets || [];
340
286
  let pointers = [];
341
-
342
287
  for (let i = 0; i < presets.length; i++) {
343
288
  if (Array.isArray(presets[i]) && redundantPresets.has(presets[i][0])) {
344
289
  pointers.push({
@@ -352,12 +297,10 @@ async function getCodeHighlights(fs, filePath, redundantPresets) {
352
297
  });
353
298
  }
354
299
  }
355
-
356
300
  if (pointers.length > 0) {
357
301
  return (0, _diagnostic().generateJSONCodeHighlights)(contents, pointers);
358
302
  }
359
303
  }
360
-
361
304
  return [{
362
305
  start: {
363
306
  line: 1,
package/lib/flow.js CHANGED
@@ -4,37 +4,29 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = getFlowOptions;
7
-
8
7
  var _constants = require("./constants");
9
-
10
8
  function _path() {
11
9
  const data = _interopRequireDefault(require("path"));
12
-
13
10
  _path = function () {
14
11
  return data;
15
12
  };
16
-
17
13
  return data;
18
14
  }
19
-
20
15
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
21
-
22
16
  /**
23
17
  * Generates a babel config for stripping away Flow types.
24
18
  */
25
19
  async function getFlowOptions(config, options) {
26
20
  if (!config.isSource) {
27
21
  return null;
28
- } // Only add flow plugin if `flow-bin` is listed as a dependency in the root package.json
29
-
22
+ }
30
23
 
24
+ // Only add flow plugin if `flow-bin` is listed as a dependency in the root package.json
31
25
  let conf = await config.getConfigFrom(options.projectRoot + '/index', ['package.json']);
32
26
  let pkg = conf === null || conf === void 0 ? void 0 : conf.contents;
33
-
34
27
  if (!pkg || !(pkg.dependencies && pkg.dependencies['flow-bin']) && !(pkg.devDependencies && pkg.devDependencies['flow-bin'])) {
35
28
  return null;
36
29
  }
37
-
38
30
  const babelCore = await options.packageManager.require('@babel/core', config.searchPath, {
39
31
  range: _constants.BABEL_CORE_RANGE,
40
32
  saveDev: true,
package/lib/jsx.js CHANGED
@@ -4,37 +4,29 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = isJSX;
7
-
8
7
  function _path() {
9
8
  const data = _interopRequireDefault(require("path"));
10
-
11
9
  _path = function () {
12
10
  return data;
13
11
  };
14
-
15
12
  return data;
16
13
  }
17
-
18
14
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
-
20
15
  const JSX_EXTENSIONS = new Set(['.jsx', '.tsx']);
21
16
  const JSX_LIBRARIES = ['react', 'preact', 'nervejs', 'hyperapp'];
17
+
22
18
  /**
23
19
  * Returns whether an asset is likely JSX. Attempts to detect react or react-like libraries
24
20
  * along with
25
21
  */
26
-
27
22
  async function isJSX(options, config) {
28
23
  if (!config.isSource) {
29
24
  return false;
30
25
  }
31
-
32
26
  if (JSX_EXTENSIONS.has(_path().default.extname(config.searchPath))) {
33
27
  return true;
34
28
  }
35
-
36
29
  let pkg = await config.getPackage();
37
-
38
30
  if (pkg !== null && pkg !== void 0 && pkg.alias && pkg.alias['react']) {
39
31
  // e.g.: `{ alias: { "react": "preact/compat" } }`
40
32
  return true;
@@ -4,29 +4,29 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.remapAstLocations = remapAstLocations;
7
-
8
7
  function remapAstLocations(t, ast, map) {
9
8
  // remap ast to original mappings
10
9
  // This improves sourcemap accuracy and fixes sourcemaps when scope-hoisting
11
10
  traverseAll(t, ast.program, node => {
12
11
  if (node.loc) {
13
12
  var _node$loc;
14
-
15
13
  if ((_node$loc = node.loc) !== null && _node$loc !== void 0 && _node$loc.start) {
16
14
  let mapping = map.findClosestMapping(node.loc.start.line, node.loc.start.column);
17
-
18
15
  if (mapping !== null && mapping !== void 0 && mapping.original) {
19
16
  // $FlowFixMe
20
- node.loc.start.line = mapping.original.line; // $FlowFixMe
21
-
22
- node.loc.start.column = mapping.original.column; // $FlowFixMe
23
-
24
- let length = node.loc.end.column - node.loc.start.column; // $FlowFixMe
17
+ node.loc.start.line = mapping.original.line;
18
+ // $FlowFixMe
19
+ node.loc.start.column = mapping.original.column;
25
20
 
26
- node.loc.end.line = mapping.original.line; // $FlowFixMe
21
+ // $FlowFixMe
22
+ let length = node.loc.end.column - node.loc.start.column;
27
23
 
28
- node.loc.end.column = mapping.original.column + length; // $FlowFixMe
24
+ // $FlowFixMe
25
+ node.loc.end.line = mapping.original.line;
26
+ // $FlowFixMe
27
+ node.loc.end.column = mapping.original.column + length;
29
28
 
29
+ // $FlowFixMe
30
30
  node.loc.filename = mapping.source;
31
31
  } else {
32
32
  // Maintain null mappings?
@@ -36,18 +36,14 @@ function remapAstLocations(t, ast, map) {
36
36
  }
37
37
  });
38
38
  }
39
-
40
39
  function traverseAll(t, node, visitor) {
41
40
  if (!node) {
42
41
  return;
43
42
  }
44
-
45
43
  visitor(node);
46
-
47
44
  for (let key of t.VISITOR_KEYS[node.type] || []) {
48
45
  // $FlowFixMe
49
46
  let subNode = node[key];
50
-
51
47
  if (Array.isArray(subNode)) {
52
48
  for (let i = 0; i < subNode.length; i++) {
53
49
  traverseAll(t, subNode[i], visitor);
package/lib/utils.js CHANGED
@@ -4,29 +4,21 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.enginesToBabelTargets = enginesToBabelTargets;
7
-
8
7
  function _assert() {
9
8
  const data = _interopRequireDefault(require("assert"));
10
-
11
9
  _assert = function () {
12
10
  return data;
13
11
  };
14
-
15
12
  return data;
16
13
  }
17
-
18
14
  function _semver() {
19
15
  const data = _interopRequireDefault(require("semver"));
20
-
21
16
  _semver = function () {
22
17
  return data;
23
18
  };
24
-
25
19
  return data;
26
20
  }
27
-
28
21
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
29
-
30
22
  // Copied from @babel/helper-compilation-targets/lib/options.js
31
23
  const TargetNames = {
32
24
  node: 'node',
@@ -41,34 +33,32 @@ const TargetNames = {
41
33
  electron: 'electron',
42
34
  samsung: 'samsung',
43
35
  rhino: 'rhino'
44
- }; // List of browsers to exclude when the esmodule target is specified.
45
- // Based on https://caniuse.com/#feat=es6-module
36
+ };
46
37
 
38
+ // List of browsers to exclude when the esmodule target is specified.
39
+ // Based on https://caniuse.com/#feat=es6-module
47
40
  const ESMODULE_BROWSERS = ['not ie <= 11', 'not edge < 16', 'not firefox < 60', 'not chrome < 61', 'not safari < 11', 'not opera < 48', 'not ios_saf < 11', 'not op_mini all', 'not android < 76', 'not blackberry > 0', 'not op_mob > 0', 'not and_chr < 76', 'not and_ff < 68', 'not ie_mob > 0', 'not and_uc > 0', 'not samsung < 8.2', 'not and_qq > 0', 'not baidu > 0', 'not kaios > 0'];
48
-
49
41
  function enginesToBabelTargets(env) {
50
42
  // "Targets" is the name @babel/preset-env uses for what Parcel calls engines.
51
43
  // This should not be confused with Parcel's own targets.
52
44
  // Unlike Parcel's engines, @babel/preset-env expects to work with minimum
53
45
  // versions, not semver ranges, of its targets.
54
46
  let targets = {};
55
-
56
47
  for (let engineName of Object.keys(env.engines)) {
57
- let engineValue = env.engines[engineName]; // if the engineValue is a string, it might be a semver range. Use the minimum
58
- // possible version instead.
48
+ let engineValue = env.engines[engineName];
59
49
 
50
+ // if the engineValue is a string, it might be a semver range. Use the minimum
51
+ // possible version instead.
60
52
  if (engineName === 'browsers') {
61
53
  targets[engineName] = engineValue;
62
54
  } else {
63
55
  var _semver$minVersion;
64
-
65
56
  (0, _assert().default)(typeof engineValue === 'string');
66
57
  if (!TargetNames.hasOwnProperty(engineName)) continue;
67
58
  let minVersion = (_semver$minVersion = _semver().default.minVersion(engineValue)) === null || _semver$minVersion === void 0 ? void 0 : _semver$minVersion.toString();
68
59
  targets[engineName] = minVersion !== null && minVersion !== void 0 ? minVersion : engineValue;
69
60
  }
70
61
  }
71
-
72
62
  if (env.outputFormat === 'esmodule' && env.isBrowser()) {
73
63
  // If there is already a browsers target, add a blacklist to exclude
74
64
  // instead of using babel's esmodules target. This allows specifying
@@ -81,6 +71,5 @@ function enginesToBabelTargets(env) {
81
71
  targets.esmodules = true;
82
72
  }
83
73
  }
84
-
85
74
  return targets;
86
75
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@parcel/transformer-babel",
3
- "version": "2.8.4-nightly.0+7b79c6d",
3
+ "version": "2.9.0",
4
4
  "license": "MIT",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -17,13 +17,13 @@
17
17
  "source": "src/BabelTransformer.js",
18
18
  "engines": {
19
19
  "node": ">= 12.0.0",
20
- "parcel": "2.8.4-nightly.0+7b79c6d"
20
+ "parcel": "^2.9.0"
21
21
  },
22
22
  "dependencies": {
23
- "@parcel/diagnostic": "2.8.4-nightly.0+7b79c6d",
24
- "@parcel/plugin": "2.8.4-nightly.0+7b79c6d",
23
+ "@parcel/diagnostic": "2.9.0",
24
+ "@parcel/plugin": "2.9.0",
25
25
  "@parcel/source-map": "^2.1.1",
26
- "@parcel/utils": "2.8.4-nightly.0+7b79c6d",
26
+ "@parcel/utils": "2.9.0",
27
27
  "browserslist": "^4.6.6",
28
28
  "json5": "^2.2.0",
29
29
  "nullthrows": "^1.1.1",
@@ -33,7 +33,7 @@
33
33
  "@babel/core": "^7.12.0",
34
34
  "@babel/preset-env": "^7.0.0",
35
35
  "@babel/types": "^7.12.0",
36
- "@parcel/types": "2.8.4-nightly.0+7b79c6d"
36
+ "@parcel/types": "2.9.0"
37
37
  },
38
- "gitHead": "7b79c6d69ffabef89810a8db61e9abdeb70d6990"
38
+ "gitHead": "dd9435be8afed35c5ffc161cf4b586fd6c78fc1f"
39
39
  }