@parcel/transformer-babel 2.0.0-beta.3.1 → 2.0.0-nightly.1002

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.
@@ -5,15 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = void 0;
7
7
 
8
- function _babelAstUtils() {
9
- const data = require("@parcel/babel-ast-utils");
10
-
11
- _babelAstUtils = function () {
12
- return data;
13
- };
14
-
15
- return data;
16
- }
8
+ var _babelErrorUtils = require("./babelErrorUtils");
17
9
 
18
10
  function _plugin() {
19
11
  const data = require("@parcel/plugin");
@@ -55,45 +47,19 @@ function _semver() {
55
47
  return data;
56
48
  }
57
49
 
58
- function _generator() {
59
- const data = _interopRequireDefault(require("@babel/generator"));
60
-
61
- _generator = function () {
62
- return data;
63
- };
50
+ var _babel = _interopRequireDefault(require("./babel7"));
64
51
 
65
- return data;
66
- }
67
-
68
- function _babel() {
69
- const data = _interopRequireDefault(require("./babel7"));
70
-
71
- _babel = function () {
72
- return data;
73
- };
74
-
75
- return data;
76
- }
77
-
78
- function _config() {
79
- const data = require("./config");
80
-
81
- _config = function () {
82
- return data;
83
- };
84
-
85
- return data;
86
- }
52
+ var _config = require("./config");
87
53
 
88
54
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
89
55
 
90
56
  var _default = new (_plugin().Transformer)({
91
- async loadConfig({
57
+ loadConfig({
92
58
  config,
93
59
  options,
94
60
  logger
95
61
  }) {
96
- await (0, _config().load)(config, options, logger);
62
+ return (0, _config.load)(config, options, logger);
97
63
  },
98
64
 
99
65
  canReuseAST({
@@ -107,21 +73,17 @@ var _default = new (_plugin().Transformer)({
107
73
  config,
108
74
  options
109
75
  }) {
110
- // TODO: Provide invalidateOnEnvChange on config?
111
- asset.invalidateOnEnvChange('BABEL_ENV');
112
- asset.invalidateOnEnvChange('NODE_ENV'); // TODO: come up with a better name
113
-
114
76
  try {
115
77
  if (config !== null && config !== void 0 && config.config) {
116
78
  if (asset.meta.babelPlugins != null && Array.isArray(asset.meta.babelPlugins)) {
117
- await (0, _babel().default)({
79
+ await (0, _babel.default)({
118
80
  asset,
119
81
  options,
120
82
  babelOptions: config,
121
83
  additionalPlugins: asset.meta.babelPlugins
122
84
  });
123
85
  } else {
124
- await (0, _babel().default)({
86
+ await (0, _babel.default)({
125
87
  asset,
126
88
  options,
127
89
  babelOptions: config
@@ -131,7 +93,7 @@ var _default = new (_plugin().Transformer)({
131
93
 
132
94
  return [asset];
133
95
  } catch (e) {
134
- throw await (0, _babelAstUtils().babelErrorEnhancer)(e, asset);
96
+ throw await (0, _babelErrorUtils.babelErrorEnhancer)(e, asset);
135
97
  }
136
98
  },
137
99
 
@@ -142,10 +104,18 @@ var _default = new (_plugin().Transformer)({
142
104
  }) {
143
105
  let originalSourceMap = await asset.getMap();
144
106
  let sourceFileName = (0, _utils().relativeUrl)(options.projectRoot, asset.filePath);
107
+ const babelCorePath = await options.packageManager.resolve('@babel/core', asset.filePath, {
108
+ range: '^7.12.0',
109
+ saveDev: true,
110
+ shouldAutoInstall: options.shouldAutoInstall
111
+ });
112
+ const {
113
+ default: generate
114
+ } = await options.packageManager.require('@babel/generator', babelCorePath.resolved);
145
115
  let {
146
116
  code,
147
117
  rawMappings
148
- } = (0, _generator().default)(ast.program, {
118
+ } = generate(ast.program, {
149
119
  sourceFileName,
150
120
  sourceMaps: !!asset.env.sourceMap,
151
121
  comments: true
package/lib/babel7.js CHANGED
@@ -15,16 +15,6 @@ function _assert() {
15
15
  return data;
16
16
  }
17
17
 
18
- function internalBabelCore() {
19
- const data = _interopRequireWildcard(require("@babel/core"));
20
-
21
- internalBabelCore = function () {
22
- return data;
23
- };
24
-
25
- return data;
26
- }
27
-
28
18
  function _utils() {
29
19
  const data = require("@parcel/utils");
30
20
 
@@ -35,34 +25,13 @@ function _utils() {
35
25
  return data;
36
26
  }
37
27
 
38
- function _babelAstUtils() {
39
- const data = require("@parcel/babel-ast-utils");
40
-
41
- _babelAstUtils = function () {
42
- return data;
43
- };
44
-
45
- return data;
46
- }
47
-
48
- function _package() {
49
- const data = _interopRequireDefault(require("../package.json"));
28
+ var _remapAstLocations = require("./remapAstLocations");
50
29
 
51
- _package = function () {
52
- return data;
53
- };
54
-
55
- return data;
56
- }
57
-
58
- function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
59
-
60
- function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
30
+ var _package = _interopRequireDefault(require("../package.json"));
61
31
 
62
32
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
63
33
 
64
- const transformerVersion = _package().default.version;
65
-
34
+ const transformerVersion = _package.default.version;
66
35
  (0, _assert().default)(typeof transformerVersion === 'string');
67
36
 
68
37
  async function babel7(opts) {
@@ -74,7 +43,7 @@ async function babel7(opts) {
74
43
  babelOptions,
75
44
  additionalPlugins = []
76
45
  } = opts;
77
- const babelCore = babelOptions.internal ? internalBabelCore() : await options.packageManager.require('@babel/core', asset.filePath, {
46
+ const babelCore = await options.packageManager.require('@babel/core', asset.filePath, {
78
47
  range: '^7.12.0',
79
48
  saveDev: true,
80
49
  shouldAutoInstall: options.shouldAutoInstall
@@ -114,7 +83,7 @@ async function babel7(opts) {
114
83
  let map = await asset.getMap();
115
84
 
116
85
  if (map) {
117
- (0, _babelAstUtils().remapAstLocations)(res.ast, map);
86
+ (0, _remapAstLocations.remapAstLocations)(babelCore.types, res.ast, map);
118
87
  }
119
88
  }
120
89
  }
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.babelErrorEnhancer = babelErrorEnhancer;
7
+
8
+ async function babelErrorEnhancer(error, asset) {
9
+ if (error.loc) {
10
+ let start = error.message.startsWith(asset.filePath) ? asset.filePath.length + 1 : 0;
11
+ error.message = error.message.slice(start).split('\n')[0].trim();
12
+ }
13
+
14
+ error.source = await asset.getCode();
15
+ error.filePath = asset.filePath;
16
+ return error;
17
+ }
package/lib/config.js CHANGED
@@ -5,20 +5,20 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.load = load;
7
7
 
8
- function _path() {
9
- const data = _interopRequireDefault(require("path"));
8
+ function _json() {
9
+ const data = _interopRequireDefault(require("json5"));
10
10
 
11
- _path = function () {
11
+ _json = function () {
12
12
  return data;
13
13
  };
14
14
 
15
15
  return data;
16
16
  }
17
17
 
18
- function internalBabelCore() {
19
- const data = _interopRequireWildcard(require("@babel/core"));
18
+ function _path() {
19
+ const data = _interopRequireDefault(require("path"));
20
20
 
21
- internalBabelCore = function () {
21
+ _path = function () {
22
22
  return data;
23
23
  };
24
24
 
@@ -35,46 +35,27 @@ function _utils() {
35
35
  return data;
36
36
  }
37
37
 
38
- function _jsx() {
39
- const data = _interopRequireDefault(require("./jsx"));
38
+ function _diagnostic() {
39
+ const data = require("@parcel/diagnostic");
40
40
 
41
- _jsx = function () {
41
+ _diagnostic = function () {
42
42
  return data;
43
43
  };
44
44
 
45
45
  return data;
46
46
  }
47
47
 
48
- function _flow() {
49
- const data = _interopRequireDefault(require("./flow"));
48
+ var _constants = require("./constants");
50
49
 
51
- _flow = function () {
52
- return data;
53
- };
50
+ var _jsx = _interopRequireDefault(require("./jsx"));
54
51
 
55
- return data;
56
- }
52
+ var _flow = _interopRequireDefault(require("./flow"));
57
53
 
58
- function _utils2() {
59
- const data = require("./utils");
60
-
61
- _utils2 = function () {
62
- return data;
63
- };
64
-
65
- return data;
66
- }
67
-
68
- function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
69
-
70
- function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
54
+ var _utils2 = require("./utils");
71
55
 
72
56
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
73
57
 
74
58
  const TYPESCRIPT_EXTNAME_RE = /\.tsx?$/;
75
-
76
- const BABEL_TRANSFORMER_DIR = _path().default.dirname(__dirname);
77
-
78
59
  const JS_EXTNAME_RE = /^\.(js|cjs|mjs)$/;
79
60
  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'];
80
61
 
@@ -97,19 +78,21 @@ async function load(config, options, logger) {
97
78
 
98
79
 
99
80
  if (!(await (0, _utils().resolveConfig)(options.inputFS, config.searchPath, BABEL_CONFIG_FILENAMES, options.projectRoot))) {
100
- await buildDefaultBabelConfig(options, config);
101
- return;
81
+ return buildDefaultBabelConfig(options, config);
102
82
  }
103
83
 
104
84
  const babelCore = await options.packageManager.require('@babel/core', config.searchPath, {
105
- range: '^7.12.0',
85
+ range: _constants.BABEL_CORE_RANGE,
106
86
  saveDev: true,
107
87
  shouldAutoInstall: options.shouldAutoInstall
108
88
  });
109
89
  config.addDevDependency({
110
- moduleSpecifier: '@babel/core',
111
- resolveFrom: config.searchPath
90
+ specifier: '@babel/core',
91
+ resolveFrom: config.searchPath,
92
+ range: _constants.BABEL_CORE_RANGE
112
93
  });
94
+ config.invalidateOnEnvChange('BABEL_ENV');
95
+ config.invalidateOnEnvChange('NODE_ENV');
113
96
  let babelOptions = {
114
97
  filename: config.searchPath,
115
98
  cwd: options.projectRoot,
@@ -125,17 +108,21 @@ async function load(config, options, logger) {
125
108
  logger.warn({
126
109
  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.`
127
110
  });
128
- config.shouldInvalidateOnStartup(); // But also add the config as a dev dependency so we can at least attempt invalidation in watch mode.
111
+ config.invalidateOnStartup(); // But also add the config as a dev dependency so we can at least attempt invalidation in watch mode.
129
112
 
130
113
  config.addDevDependency({
131
- moduleSpecifier: (0, _utils().relativePath)(options.projectRoot, file),
114
+ specifier: (0, _utils().relativePath)(options.projectRoot, file),
132
115
  resolveFrom: _path().default.join(options.projectRoot, 'index'),
133
- // Also invalidate @parcel/transformer-babel when the config or a dependency updates.
116
+ // Also invalidate @babel/core when the config or a dependency updates.
134
117
  // This ensures that the caches in @babel/core are also invalidated.
135
- invalidateParcelPlugin: true
118
+ additionalInvalidations: [{
119
+ specifier: '@babel/core',
120
+ resolveFrom: config.searchPath,
121
+ range: _constants.BABEL_CORE_RANGE
122
+ }]
136
123
  });
137
124
  } else {
138
- config.addIncludedFile(file);
125
+ config.invalidateOnFileChange(file);
139
126
  }
140
127
  };
141
128
 
@@ -143,7 +130,7 @@ async function load(config, options, logger) {
143
130
  logger.warn({
144
131
  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.'
145
132
  });
146
- config.shouldInvalidateOnStartup();
133
+ config.invalidateOnStartup();
147
134
  }; // Old versions of @babel/core return null from loadPartialConfig when the file should explicitly not be run through babel (ignore/exclude)
148
135
 
149
136
 
@@ -182,30 +169,32 @@ async function load(config, options, logger) {
182
169
  if (config.searchPath.endsWith('.tsx')) {
183
170
  syntaxPlugins.push('jsx');
184
171
  }
185
- } else if (await (0, _jsx().default)(options, config)) {
172
+ } else if (await (0, _jsx.default)(options, config)) {
186
173
  syntaxPlugins.push('jsx');
187
- }
188
-
189
- config.setResult({
190
- internal: false,
191
- config: partialConfig.options,
192
- targets: (0, _utils2().enginesToBabelTargets)(config.env),
193
- syntaxPlugins
194
- }); // If the config has plugins loaded with require(), or inline plugins in the config,
174
+ } // If the config has plugins loaded with require(), or inline plugins in the config,
195
175
  // we can't cache the result of the compilation because we don't know where they came from.
196
176
 
177
+
197
178
  if (hasRequire(partialConfig.options)) {
198
179
  logger.warn({
199
180
  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.'
200
181
  });
201
- config.setResultHash(JSON.stringify(Date.now()));
202
- config.shouldInvalidateOnStartup();
182
+ config.setCacheKey(JSON.stringify(Date.now()));
183
+ config.invalidateOnStartup();
203
184
  } else {
204
- definePluginDependencies(config, options);
205
- config.setResultHash((0, _utils().md5FromObject)(partialConfig.options));
185
+ await warnOnRedundantPlugins(options.inputFS, partialConfig, logger);
186
+ definePluginDependencies(config, partialConfig.options, options);
187
+ config.setCacheKey((0, _utils().hashObject)(partialConfig.options));
206
188
  }
189
+
190
+ return {
191
+ internal: false,
192
+ config: partialConfig.options,
193
+ targets: (0, _utils2.enginesToBabelTargets)(config.env),
194
+ syntaxPlugins
195
+ };
207
196
  } else {
208
- await buildDefaultBabelConfig(options, config);
197
+ return buildDefaultBabelConfig(options, config);
209
198
  }
210
199
  }
211
200
 
@@ -216,7 +205,7 @@ async function buildDefaultBabelConfig(options, config) {
216
205
  } // Detect flow. If not enabled, babel doesn't need to run at all.
217
206
 
218
207
 
219
- let babelOptions = await (0, _flow().default)(config, options);
208
+ let babelOptions = await (0, _flow.default)(config, options);
220
209
 
221
210
  if (babelOptions == null) {
222
211
  return;
@@ -225,24 +214,16 @@ async function buildDefaultBabelConfig(options, config) {
225
214
 
226
215
  let syntaxPlugins = [];
227
216
 
228
- if (await (0, _jsx().default)(options, config)) {
217
+ if (await (0, _jsx.default)(options, config)) {
229
218
  syntaxPlugins.push('jsx');
230
219
  }
231
220
 
232
- babelOptions.presets = (babelOptions.presets || []).map(preset => internalBabelCore().createConfigItem(preset, {
233
- type: 'preset',
234
- dirname: BABEL_TRANSFORMER_DIR
235
- }));
236
- babelOptions.plugins = (babelOptions.plugins || []).map(plugin => internalBabelCore().createConfigItem(plugin, {
237
- type: 'plugin',
238
- dirname: BABEL_TRANSFORMER_DIR
239
- }));
240
- config.setResult({
221
+ definePluginDependencies(config, babelOptions, options);
222
+ return {
241
223
  internal: true,
242
224
  config: babelOptions,
243
225
  syntaxPlugins
244
- });
245
- definePluginDependencies(config, options);
226
+ };
246
227
  }
247
228
 
248
229
  function hasRequire(options) {
@@ -250,25 +231,145 @@ function hasRequire(options) {
250
231
  return configItems.some(item => !item.file);
251
232
  }
252
233
 
253
- function definePluginDependencies(config, options) {
254
- let babelConfig = config.result.config;
255
-
234
+ function definePluginDependencies(config, babelConfig, options) {
256
235
  if (babelConfig == null) {
257
236
  return;
258
237
  }
259
238
 
260
- let configItems = [...babelConfig.presets, ...babelConfig.plugins];
239
+ let configItems = [...(babelConfig.presets || []), ...(babelConfig.plugins || [])];
261
240
 
262
241
  for (let configItem of configItems) {
263
242
  // FIXME: this uses a relative path from the project root rather than resolving
264
243
  // from the config location because configItem.file.request can be a shorthand
265
244
  // rather than a full package name.
266
245
  config.addDevDependency({
267
- moduleSpecifier: (0, _utils().relativePath)(options.projectRoot, configItem.file.resolved),
246
+ specifier: (0, _utils().relativePath)(options.projectRoot, configItem.file.resolved),
268
247
  resolveFrom: _path().default.join(options.projectRoot, 'index'),
269
- // Also invalidate @parcel/transformer-babel when the plugin or a dependency updates.
248
+ // Also invalidate @babel/core when the plugin or a dependency updates.
270
249
  // This ensures that the caches in @babel/core are also invalidated.
271
- invalidateParcelPlugin: true
250
+ additionalInvalidations: [{
251
+ specifier: '@babel/core',
252
+ resolveFrom: config.searchPath,
253
+ range: _constants.BABEL_CORE_RANGE
254
+ }]
255
+ });
256
+ }
257
+ }
258
+
259
+ const redundantPresets = new Set(['@babel/preset-env', '@babel/preset-react', '@babel/preset-typescript', '@parcel/babel-preset-env']);
260
+
261
+ async function warnOnRedundantPlugins(fs, babelConfig, logger) {
262
+ var _babelConfig$config;
263
+
264
+ if (babelConfig == null) {
265
+ return;
266
+ }
267
+
268
+ let configPath = (_babelConfig$config = babelConfig.config) !== null && _babelConfig$config !== void 0 ? _babelConfig$config : babelConfig.babelrc;
269
+
270
+ if (!configPath) {
271
+ return;
272
+ }
273
+
274
+ let presets = babelConfig.options.presets || [];
275
+ let plugins = babelConfig.options.plugins || [];
276
+ let foundRedundantPresets = new Set();
277
+ let filteredPresets = presets.filter(preset => {
278
+ if (redundantPresets.has(preset.file.request)) {
279
+ foundRedundantPresets.add(preset.file.request);
280
+ return false;
281
+ }
282
+
283
+ return true;
284
+ });
285
+
286
+ let filePath = _path().default.relative(process.cwd(), configPath);
287
+
288
+ let diagnostics = [];
289
+
290
+ if (filteredPresets.length === 0 && foundRedundantPresets.size > 0 && plugins.length === 0) {
291
+ diagnostics.push({
292
+ message: (0, _diagnostic().md)`Parcel includes transpilation by default. Babel config __${filePath}__ contains only redundant presets. Deleting it may significantly improve build performance.`,
293
+ codeFrames: [{
294
+ filePath: configPath,
295
+ codeHighlights: await getCodeHighlights(fs, configPath, foundRedundantPresets)
296
+ }],
297
+ hints: [(0, _diagnostic().md)`Delete __${filePath}__`],
298
+ documentationURL: 'https://parceljs.org/languages/javascript/#default-presets'
299
+ });
300
+ } else if (foundRedundantPresets.size > 0) {
301
+ diagnostics.push({
302
+ 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.`,
303
+ codeFrames: [{
304
+ filePath: configPath,
305
+ codeHighlights: await getCodeHighlights(fs, configPath, foundRedundantPresets)
306
+ }],
307
+ hints: [(0, _diagnostic().md)`Remove the above presets from __${filePath}__`],
308
+ documentationURL: 'https://parceljs.org/languages/javascript/#default-presets'
272
309
  });
273
310
  }
311
+
312
+ if (foundRedundantPresets.has('@babel/preset-env')) {
313
+ var _babelConfig$config2, _babelConfig$config3;
314
+
315
+ diagnostics.push({
316
+ message: "@babel/preset-env does not support Parcel's targets, which will likely result in unnecessary transpilation and larger bundle sizes.",
317
+ codeFrames: [{
318
+ filePath: (_babelConfig$config2 = babelConfig.config) !== null && _babelConfig$config2 !== void 0 ? _babelConfig$config2 : babelConfig.babelrc,
319
+ codeHighlights: await getCodeHighlights(fs, (_babelConfig$config3 = babelConfig.config) !== null && _babelConfig$config3 !== void 0 ? _babelConfig$config3 : babelConfig.babelrc, new Set(['@babel/preset-env']))
320
+ }],
321
+ hints: [`Either remove __@babel/preset-env__ to use Parcel's builtin transpilation, or replace with __@parcel/babel-preset-env__`],
322
+ documentationURL: 'https://parceljs.org/languages/javascript/#custom-plugins'
323
+ });
324
+ }
325
+
326
+ if (diagnostics.length > 0) {
327
+ logger.warn(diagnostics);
328
+ }
329
+ }
330
+
331
+ async function getCodeHighlights(fs, filePath, redundantPresets) {
332
+ let ext = _path().default.extname(filePath);
333
+
334
+ if (ext !== '.js' && ext !== '.cjs' && ext !== '.mjs') {
335
+ let contents = await fs.readFile(filePath, 'utf8');
336
+
337
+ let json = _json().default.parse(contents);
338
+
339
+ let presets = json.presets || [];
340
+ let pointers = [];
341
+
342
+ for (let i = 0; i < presets.length; i++) {
343
+ if (Array.isArray(presets[i]) && redundantPresets.has(presets[i][0])) {
344
+ pointers.push({
345
+ type: 'value',
346
+ key: `/presets/${i}/0`
347
+ });
348
+ } else if (redundantPresets.has(presets[i])) {
349
+ pointers.push({
350
+ type: 'value',
351
+ key: `/presets/${i}`
352
+ });
353
+ }
354
+ }
355
+
356
+ if (pointers.length > 0) {
357
+ try {
358
+ return (0, _diagnostic().generateJSONCodeHighlights)(contents, pointers);
359
+ } catch {// TODO: support code highlights for json5 sources.
360
+ // Babel supports json5 syntax, but json-source-map does not.
361
+ }
362
+ }
363
+ }
364
+
365
+ return [{
366
+ start: {
367
+ line: 1,
368
+ column: 1
369
+ },
370
+ end: {
371
+ line: 1,
372
+ column: 1
373
+ }
374
+ }];
274
375
  }
package/lib/constants.js CHANGED
@@ -3,6 +3,6 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.BABEL_RANGE = void 0;
7
- const BABEL_RANGE = '^7.0.0';
8
- exports.BABEL_RANGE = BABEL_RANGE;
6
+ exports.BABEL_CORE_RANGE = void 0;
7
+ const BABEL_CORE_RANGE = '^7.12.0';
8
+ exports.BABEL_CORE_RANGE = BABEL_CORE_RANGE;
package/lib/flow.js CHANGED
@@ -5,6 +5,20 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = getFlowOptions;
7
7
 
8
+ var _constants = require("./constants");
9
+
10
+ function _path() {
11
+ const data = _interopRequireDefault(require("path"));
12
+
13
+ _path = function () {
14
+ return data;
15
+ };
16
+
17
+ return data;
18
+ }
19
+
20
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
21
+
8
22
  /**
9
23
  * Generates a babel config for stripping away Flow types.
10
24
  */
@@ -21,9 +35,22 @@ async function getFlowOptions(config, options) {
21
35
  return null;
22
36
  }
23
37
 
38
+ const babelCore = await options.packageManager.require('@babel/core', config.searchPath, {
39
+ range: _constants.BABEL_CORE_RANGE,
40
+ saveDev: true,
41
+ shouldAutoInstall: options.shouldAutoInstall
42
+ });
43
+ await options.packageManager.require('@babel/plugin-transform-flow-strip-types', config.searchPath, {
44
+ range: '^7.0.0',
45
+ saveDev: true,
46
+ shouldAutoInstall: options.shouldAutoInstall
47
+ });
24
48
  return {
25
- plugins: [['@babel/plugin-transform-flow-strip-types', {
49
+ plugins: [babelCore.createConfigItem(['@babel/plugin-transform-flow-strip-types', {
26
50
  requireDirective: true
27
- }]]
51
+ }], {
52
+ type: 'plugin',
53
+ dirname: _path().default.dirname(config.searchPath)
54
+ })]
28
55
  };
29
56
  }
package/lib/jsx.js CHANGED
@@ -40,6 +40,6 @@ async function isJSX(options, config) {
40
40
  return true;
41
41
  } else {
42
42
  // Find a dependency that implies JSX syntax.
43
- return JSX_LIBRARIES.some(libName => pkg && (pkg.dependencies && pkg.dependencies[libName] || pkg.devDependencies && pkg.devDependencies[libName]));
43
+ return JSX_LIBRARIES.some(libName => pkg && (pkg.dependencies && pkg.dependencies[libName] || pkg.devDependencies && pkg.devDependencies[libName] || pkg.peerDependencies && pkg.peerDependencies[libName]));
44
44
  }
45
45
  }