@parcel/transformer-babel 2.0.0-beta.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.
package/src/config.js CHANGED
@@ -1,304 +1,418 @@
1
1
  // @flow
2
2
 
3
- import type {Config, PluginOptions} from '@parcel/types';
3
+ import type {Config, PluginOptions, PluginLogger} from '@parcel/types';
4
+ import typeof * as BabelCore from '@babel/core';
5
+ import type {Diagnostic} from '@parcel/diagnostic';
4
6
  import type {BabelConfig} from './types';
5
- import type {PluginLogger} from '@parcel/logger';
6
7
 
7
- import nullthrows from 'nullthrows';
8
+ import json5 from 'json5';
8
9
  import path from 'path';
9
- import * as bundledBabelCore from '@babel/core';
10
- import {md5FromObject, resolveConfig} from '@parcel/utils';
10
+ import {hashObject, relativePath, resolveConfig} from '@parcel/utils';
11
+ import {md, generateJSONCodeHighlights} from '@parcel/diagnostic';
12
+ import {BABEL_CORE_RANGE} from './constants';
11
13
 
12
- import getEnvOptions from './env';
13
- import getJSXOptions from './jsx';
14
+ import isJSX from './jsx';
14
15
  import getFlowOptions from './flow';
15
- import getTypescriptOptions from './typescript';
16
16
  import {enginesToBabelTargets} from './utils';
17
- import {BABEL_RANGE} from './constants';
18
17
 
19
- const TYPESCRIPT_EXTNAME_RE = /^\.tsx?/;
20
- const BABEL_TRANSFORMER_DIR = path.dirname(__dirname);
18
+ const TYPESCRIPT_EXTNAME_RE = /\.tsx?$/;
19
+ const JS_EXTNAME_RE = /^\.(js|cjs|mjs)$/;
20
+ const BABEL_CONFIG_FILENAMES = [
21
+ '.babelrc',
22
+ '.babelrc.js',
23
+ '.babelrc.json',
24
+ '.babelrc.cjs',
25
+ '.babelrc.mjs',
26
+ '.babelignore',
27
+ 'babel.config.js',
28
+ 'babel.config.json',
29
+ 'babel.config.mjs',
30
+ 'babel.config.cjs',
31
+ ];
32
+
33
+ type BabelConfigResult = {|
34
+ internal: boolean,
35
+ config: BabelConfig,
36
+ targets?: mixed,
37
+ syntaxPlugins?: mixed,
38
+ |};
21
39
 
22
40
  export async function load(
23
41
  config: Config,
24
42
  options: PluginOptions,
25
43
  logger: PluginLogger,
26
- ) {
27
- // Don't look for a custom babel config if inside node_modules
44
+ ): Promise<?BabelConfigResult> {
45
+ // Don't transpile inside node_modules
28
46
  if (!config.isSource) {
29
- return buildDefaultBabelConfig(options, config);
47
+ return;
30
48
  }
31
49
 
32
- // If we are in a monorepo, also find .babelrc configs in the sub packages.
33
- let babelrcRoots = [options.projectRoot];
34
- let packageJSONPath = await resolveConfig(
35
- options.inputFS,
36
- config.searchPath,
37
- ['package.json'],
38
- );
39
- if (packageJSONPath) {
40
- let packageRoot = path.dirname(packageJSONPath);
41
- if (packageRoot && packageRoot !== options.projectRoot) {
42
- babelrcRoots.push(packageRoot);
43
- }
50
+ // Invalidate when any babel config file is added.
51
+ for (let fileName of BABEL_CONFIG_FILENAMES) {
52
+ config.invalidateOnFileCreate({
53
+ fileName,
54
+ aboveFilePath: config.searchPath,
55
+ });
44
56
  }
45
57
 
46
- let babelCore = await options.packageManager.require(
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.
60
+ if (
61
+ !(await resolveConfig(
62
+ options.inputFS,
63
+ config.searchPath,
64
+ BABEL_CONFIG_FILENAMES,
65
+ options.projectRoot,
66
+ ))
67
+ ) {
68
+ return buildDefaultBabelConfig(options, config);
69
+ }
70
+
71
+ const babelCore: BabelCore = await options.packageManager.require(
47
72
  '@babel/core',
48
73
  config.searchPath,
49
- {range: BABEL_RANGE, autoinstall: options.autoinstall},
74
+ {
75
+ range: BABEL_CORE_RANGE,
76
+ saveDev: true,
77
+ shouldAutoInstall: options.shouldAutoInstall,
78
+ },
50
79
  );
51
- let partialConfig = babelCore.loadPartialConfig({
80
+ config.addDevDependency({
81
+ specifier: '@babel/core',
82
+ resolveFrom: config.searchPath,
83
+ range: BABEL_CORE_RANGE,
84
+ });
85
+
86
+ config.invalidateOnEnvChange('BABEL_ENV');
87
+ config.invalidateOnEnvChange('NODE_ENV');
88
+ let babelOptions = {
52
89
  filename: config.searchPath,
53
- cwd: path.dirname(config.searchPath),
54
- root: options.projectRoot,
55
- babelrcRoots,
90
+ cwd: options.projectRoot,
56
91
  envName:
57
92
  options.env.BABEL_ENV ??
58
- process.env.BABEL_ENV ??
59
93
  options.env.NODE_ENV ??
60
- process.env.NODE_ENV ??
61
94
  (options.mode === 'production' || options.mode === 'development'
62
95
  ? options.mode
63
96
  : null) ??
64
97
  'development',
65
- });
98
+ showIgnoredFiles: true,
99
+ };
100
+
101
+ let partialConfig: ?{|
102
+ [string]: any,
103
+ |} = await babelCore.loadPartialConfigAsync(babelOptions);
104
+
105
+ let addIncludedFile = file => {
106
+ if (JS_EXTNAME_RE.test(path.extname(file))) {
107
+ // We need to invalidate on startup in case the config is non-static,
108
+ // e.g. uses unknown environment variables, reads from the filesystem, etc.
109
+ logger.warn({
110
+ 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 ${
111
+ path.basename(file, path.extname(file)) + '.json'
112
+ } file instead.`,
113
+ });
114
+ config.invalidateOnStartup();
115
+
116
+ // But also add the config as a dev dependency so we can at least attempt invalidation in watch mode.
117
+ config.addDevDependency({
118
+ specifier: relativePath(options.projectRoot, file),
119
+ resolveFrom: path.join(options.projectRoot, 'index'),
120
+ // Also invalidate @babel/core when the config or a dependency updates.
121
+ // This ensures that the caches in @babel/core are also invalidated.
122
+ additionalInvalidations: [
123
+ {
124
+ specifier: '@babel/core',
125
+ resolveFrom: config.searchPath,
126
+ range: BABEL_CORE_RANGE,
127
+ },
128
+ ],
129
+ });
130
+ } else {
131
+ config.invalidateOnFileChange(file);
132
+ }
133
+ };
134
+
135
+ let warnOldVersion = () => {
136
+ logger.warn({
137
+ message:
138
+ '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.',
139
+ });
140
+ config.invalidateOnStartup();
141
+ };
66
142
 
67
- // loadPartialConfig returns null when the file should explicitly not be run through babel (ignore/exclude)
143
+ // Old versions of @babel/core return null from loadPartialConfig when the file should explicitly not be run through babel (ignore/exclude)
68
144
  if (partialConfig == null) {
145
+ warnOldVersion();
69
146
  return;
70
- } else if (partialConfig.hasFilesystemConfig()) {
71
- config.setResult({
72
- internal: false,
73
- config: partialConfig.options,
74
- targets: enginesToBabelTargets(config.env),
75
- });
147
+ }
76
148
 
77
- let {babelrc: babelrcPath, config: configPath} = partialConfig;
78
- let {canBeRehydrated, dependsOnRelative, dependsOnLocal} = getStats(
79
- partialConfig.options,
80
- );
149
+ if (partialConfig.files == null) {
150
+ // If the files property is missing, we're on an old version of @babel/core.
151
+ // We need to invalidate on startup because we can't properly track dependencies.
152
+ if (partialConfig.hasFilesystemConfig()) {
153
+ warnOldVersion();
81
154
 
82
- let configIsJS =
83
- (typeof babelrcPath === 'string' &&
84
- path.extname(babelrcPath) === '.js') ||
85
- (typeof configPath === 'string' && path.extname(configPath) === '.js');
155
+ if (typeof partialConfig.babelrcPath === 'string') {
156
+ addIncludedFile(partialConfig.babelrcPath);
157
+ }
86
158
 
87
- if (configIsJS) {
88
- logger.verbose({
89
- message:
90
- 'WARNING: Using a JavaScript Babel config file means losing out on some caching features of Parcel. Try using a .babelrc file instead.',
91
- });
92
- config.shouldInvalidateOnStartup();
93
- // babel.config.js files get required by @babel/core so there's no use in setting resolved path for watch mode invalidation
94
- } else {
95
- config.addIncludedFile(
96
- typeof babelrcPath === 'string' ? babelrcPath : configPath,
97
- );
159
+ if (typeof partialConfig.configPath === 'string') {
160
+ addIncludedFile(partialConfig.configPath);
161
+ }
98
162
  }
163
+ } else {
164
+ for (let file of partialConfig.files) {
165
+ addIncludedFile(file);
166
+ }
167
+ }
99
168
 
100
- if (babelrcPath && (await isExtended(/* babelrcPath */))) {
101
- logger.verbose({
102
- message:
103
- 'WARNING: You are using `extends` in your Babel config, which means you are losing out on some of the caching features of Parcel. Maybe try using a reusable preset instead.',
104
- });
105
- config.shouldInvalidateOnStartup();
169
+ if (
170
+ partialConfig.fileHandling != null &&
171
+ partialConfig.fileHandling !== 'transpile'
172
+ ) {
173
+ return;
174
+ } else if (partialConfig.hasFilesystemConfig()) {
175
+ // Determine what syntax plugins we need to enable
176
+ let syntaxPlugins = [];
177
+ if (TYPESCRIPT_EXTNAME_RE.test(config.searchPath)) {
178
+ syntaxPlugins.push('typescript');
179
+ if (config.searchPath.endsWith('.tsx')) {
180
+ syntaxPlugins.push('jsx');
181
+ }
182
+ } else if (await isJSX(options, config)) {
183
+ syntaxPlugins.push('jsx');
106
184
  }
107
185
 
108
- if (dependsOnRelative || dependsOnLocal) {
109
- logger.verbose({
186
+ // If the config has plugins loaded with require(), or inline plugins in the config,
187
+ // we can't cache the result of the compilation because we don't know where they came from.
188
+ if (hasRequire(partialConfig.options)) {
189
+ logger.warn({
110
190
  message:
111
- 'WARNING: It looks like you are using local Babel plugins or presets. You will need to run with the `--no-cache` option in order to pick up changes to these until their containing package versions are bumped.',
191
+ '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.',
112
192
  });
113
- }
114
193
 
115
- if (canBeRehydrated) {
116
- await definePluginDependencies(config);
117
- config.setResultHash(md5FromObject(partialConfig.options));
194
+ config.setCacheKey(JSON.stringify(Date.now()));
195
+ config.invalidateOnStartup();
118
196
  } else {
119
- logger.verbose({
120
- message:
121
- 'WARNING: 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.',
122
- });
123
- config.setResultHash(JSON.stringify(Date.now()));
124
- config.shouldInvalidateOnStartup();
197
+ await warnOnRedundantPlugins(options.inputFS, partialConfig, logger);
198
+ definePluginDependencies(config, partialConfig.options, options);
199
+ config.setCacheKey(hashObject(partialConfig.options));
125
200
  }
201
+
202
+ return {
203
+ internal: false,
204
+ config: partialConfig.options,
205
+ targets: enginesToBabelTargets(config.env),
206
+ syntaxPlugins,
207
+ };
126
208
  } else {
127
- await buildDefaultBabelConfig(options, config);
209
+ return buildDefaultBabelConfig(options, config);
128
210
  }
129
211
  }
130
212
 
131
- async function buildDefaultBabelConfig(options: PluginOptions, config: Config) {
132
- let babelOptions;
133
- if (path.extname(config.searchPath).match(TYPESCRIPT_EXTNAME_RE)) {
134
- babelOptions = getTypescriptOptions(config);
135
- } else {
136
- babelOptions = getFlowOptions(config);
213
+ async function buildDefaultBabelConfig(
214
+ options: PluginOptions,
215
+ config: Config,
216
+ ): Promise<?BabelConfigResult> {
217
+ // If this is a .ts or .tsx file, we don't need to enable flow.
218
+ if (TYPESCRIPT_EXTNAME_RE.test(config.searchPath)) {
219
+ return;
137
220
  }
138
221
 
139
- let babelTargets;
140
- let envOptions = await getEnvOptions(config);
141
- if (envOptions != null) {
142
- babelTargets = envOptions.targets;
143
- babelOptions = mergeOptions(babelOptions, {presets: envOptions.presets});
222
+ // Detect flow. If not enabled, babel doesn't need to run at all.
223
+ let babelOptions = await getFlowOptions(config, options);
224
+ if (babelOptions == null) {
225
+ return;
144
226
  }
145
- babelOptions = mergeOptions(
146
- babelOptions,
147
- await getJSXOptions(options, config),
148
- );
149
227
 
150
- if (babelOptions != null) {
151
- babelOptions.presets = (babelOptions.presets || []).map(preset =>
152
- bundledBabelCore.createConfigItem(preset, {
153
- type: 'preset',
154
- dirname: BABEL_TRANSFORMER_DIR,
155
- }),
156
- );
157
- babelOptions.plugins = (babelOptions.plugins || []).map(plugin =>
158
- bundledBabelCore.createConfigItem(plugin, {
159
- type: 'plugin',
160
- dirname: BABEL_TRANSFORMER_DIR,
161
- }),
162
- );
228
+ // When flow is enabled, we may also need to enable JSX so it parses properly.
229
+ let syntaxPlugins = [];
230
+ if (await isJSX(options, config)) {
231
+ syntaxPlugins.push('jsx');
163
232
  }
164
233
 
165
- config.setResult({
234
+ definePluginDependencies(config, babelOptions, options);
235
+ return {
166
236
  internal: true,
167
237
  config: babelOptions,
168
- targets: babelTargets,
169
- });
170
- await definePluginDependencies(config);
238
+ syntaxPlugins,
239
+ };
171
240
  }
172
241
 
173
- function mergeOptions(result, config?: null | BabelConfig) {
174
- if (
175
- !config ||
176
- ((!config.presets || config.presets.length === 0) &&
177
- (!config.plugins || config.plugins.length === 0))
178
- ) {
179
- return result;
180
- }
242
+ function hasRequire(options) {
243
+ let configItems = [...options.presets, ...options.plugins];
244
+ return configItems.some(item => !item.file);
245
+ }
181
246
 
182
- let merged = result;
183
- if (merged) {
184
- merged.presets = (merged.presets || []).concat(config.presets || []);
185
- merged.plugins = (merged.plugins || []).concat(config.plugins || []);
186
- } else {
187
- result = config;
247
+ function definePluginDependencies(config, babelConfig: ?BabelConfig, options) {
248
+ if (babelConfig == null) {
249
+ return;
188
250
  }
189
251
 
190
- return result;
252
+ let configItems = [
253
+ ...(babelConfig.presets || []),
254
+ ...(babelConfig.plugins || []),
255
+ ];
256
+ for (let configItem of configItems) {
257
+ // FIXME: this uses a relative path from the project root rather than resolving
258
+ // from the config location because configItem.file.request can be a shorthand
259
+ // rather than a full package name.
260
+ config.addDevDependency({
261
+ specifier: relativePath(options.projectRoot, configItem.file.resolved),
262
+ resolveFrom: path.join(options.projectRoot, 'index'),
263
+ // Also invalidate @babel/core when the plugin or a dependency updates.
264
+ // This ensures that the caches in @babel/core are also invalidated.
265
+ additionalInvalidations: [
266
+ {
267
+ specifier: '@babel/core',
268
+ resolveFrom: config.searchPath,
269
+ range: BABEL_CORE_RANGE,
270
+ },
271
+ ],
272
+ });
273
+ }
191
274
  }
192
275
 
193
- function getStats(options) {
194
- let canBeRehydrated = true;
195
- let dependsOnRelative = false;
196
- let dependsOnLocal = false;
276
+ const redundantPresets = new Set([
277
+ '@babel/preset-env',
278
+ '@babel/preset-react',
279
+ '@babel/preset-typescript',
280
+ '@parcel/babel-preset-env',
281
+ ]);
197
282
 
198
- let configItems = [...options.presets, ...options.plugins];
283
+ async function warnOnRedundantPlugins(fs, babelConfig, logger) {
284
+ if (babelConfig == null) {
285
+ return;
286
+ }
199
287
 
200
- for (let configItem of configItems) {
201
- if (!configItem.file) {
202
- canBeRehydrated = false;
203
- } else if (configItem.file.request.startsWith('.')) {
204
- dependsOnRelative = true;
205
- } else if (isLocal(/*configItem.file.resolved*/)) {
206
- dependsOnLocal = true;
207
- }
288
+ let configPath = babelConfig.config ?? babelConfig.babelrc;
289
+ if (!configPath) {
290
+ return;
208
291
  }
209
292
 
210
- return {canBeRehydrated, dependsOnRelative, dependsOnLocal};
211
- }
293
+ let presets = babelConfig.options.presets || [];
294
+ let plugins = babelConfig.options.plugins || [];
295
+ let foundRedundantPresets = new Set();
212
296
 
213
- function isExtended(/* babelrcPath */) {
214
- // TODO: read and parse babelrc and check to see if extends property exists
215
- // need access to fs in case of memory filesystem
216
- return false;
217
- }
297
+ let filteredPresets = presets.filter(preset => {
298
+ if (redundantPresets.has(preset.file.request)) {
299
+ foundRedundantPresets.add(preset.file.request);
300
+ return false;
301
+ }
218
302
 
219
- function isLocal(/* configItemPath */) {
220
- // TODO: check if realpath is different, need access to fs in case of memory filesystem
221
- return false;
222
- }
303
+ return true;
304
+ });
223
305
 
224
- export function preSerialize(config: Config) {
225
- let babelConfig = config.result.config;
226
- if (babelConfig == null) {
227
- return;
228
- }
306
+ let filePath = path.relative(process.cwd(), configPath);
307
+ let diagnostics: Array<Diagnostic> = [];
229
308
 
230
- // ConfigItem.value is a function which the v8 serializer chokes on
231
- // It is being ommited here and will be rehydrated later using the path provided by ConfigItem.file
232
- babelConfig.presets = (babelConfig.presets || []).map(
233
- ({options, dirname, name, file}) => ({
234
- options,
235
- dirname,
236
- name,
237
- file,
238
- }),
239
- );
240
- babelConfig.plugins = (babelConfig.plugins || []).map(
241
- ({options, dirname, name, file}) => ({
242
- options,
243
- dirname,
244
- name,
245
- file,
246
- }),
247
- );
248
- }
309
+ if (
310
+ filteredPresets.length === 0 &&
311
+ foundRedundantPresets.size > 0 &&
312
+ plugins.length === 0
313
+ ) {
314
+ diagnostics.push({
315
+ message: md`Parcel includes transpilation by default. Babel config __${filePath}__ contains only redundant presets. Deleting it may significantly improve build performance.`,
316
+ codeFrames: [
317
+ {
318
+ filePath: configPath,
319
+ codeHighlights: await getCodeHighlights(
320
+ fs,
321
+ configPath,
322
+ foundRedundantPresets,
323
+ ),
324
+ },
325
+ ],
326
+ hints: [md`Delete __${filePath}__`],
327
+ documentationURL:
328
+ 'https://parceljs.org/languages/javascript/#default-presets',
329
+ });
330
+ } else if (foundRedundantPresets.size > 0) {
331
+ diagnostics.push({
332
+ message: md`Parcel includes transpilation by default. Babel config __${filePath}__ includes the following redundant presets: ${[
333
+ ...foundRedundantPresets,
334
+ ].map(p =>
335
+ md.underline(p),
336
+ )}. Removing these may improve build performance.`,
337
+ codeFrames: [
338
+ {
339
+ filePath: configPath,
340
+ codeHighlights: await getCodeHighlights(
341
+ fs,
342
+ configPath,
343
+ foundRedundantPresets,
344
+ ),
345
+ },
346
+ ],
347
+ hints: [md`Remove the above presets from __${filePath}__`],
348
+ documentationURL:
349
+ 'https://parceljs.org/languages/javascript/#default-presets',
350
+ });
351
+ }
249
352
 
250
- async function definePluginDependencies(config) {
251
- let babelConfig = config.result.config;
252
- if (babelConfig == null) {
253
- return;
353
+ if (foundRedundantPresets.has('@babel/preset-env')) {
354
+ diagnostics.push({
355
+ message:
356
+ "@babel/preset-env does not support Parcel's targets, which will likely result in unnecessary transpilation and larger bundle sizes.",
357
+ codeFrames: [
358
+ {
359
+ filePath: babelConfig.config ?? babelConfig.babelrc,
360
+ codeHighlights: await getCodeHighlights(
361
+ fs,
362
+ babelConfig.config ?? babelConfig.babelrc,
363
+ new Set(['@babel/preset-env']),
364
+ ),
365
+ },
366
+ ],
367
+ hints: [
368
+ `Either remove __@babel/preset-env__ to use Parcel's builtin transpilation, or replace with __@parcel/babel-preset-env__`,
369
+ ],
370
+ documentationURL:
371
+ 'https://parceljs.org/languages/javascript/#custom-plugins',
372
+ });
254
373
  }
255
374
 
256
- let configItems = [...babelConfig.presets, ...babelConfig.plugins];
257
- await Promise.all(
258
- configItems.map(async configItem => {
259
- let pkg = nullthrows(
260
- await config.getConfigFrom(configItem.file.resolved, ['package.json'], {
261
- parse: true,
262
- }),
263
- ).contents;
264
- config.addDevDependency(pkg.name, pkg.version);
265
- }),
266
- );
375
+ if (diagnostics.length > 0) {
376
+ logger.warn(diagnostics);
377
+ }
267
378
  }
268
379
 
269
- export async function postDeserialize(config: Config, options: PluginOptions) {
270
- let babelCore = config.result.internal
271
- ? bundledBabelCore
272
- : await options.packageManager.require('@babel/core', config.searchPath, {
273
- autoinstall: options.autoinstall,
274
- });
380
+ async function getCodeHighlights(fs, filePath, redundantPresets) {
381
+ let ext = path.extname(filePath);
382
+ if (ext !== '.js' && ext !== '.cjs' && ext !== '.mjs') {
383
+ let contents = await fs.readFile(filePath, 'utf8');
384
+ let json = json5.parse(contents);
385
+
386
+ let presets = json.presets || [];
387
+ let pointers = [];
388
+ for (let i = 0; i < presets.length; i++) {
389
+ if (Array.isArray(presets[i]) && redundantPresets.has(presets[i][0])) {
390
+ pointers.push({type: 'value', key: `/presets/${i}/0`});
391
+ } else if (redundantPresets.has(presets[i])) {
392
+ pointers.push({type: 'value', key: `/presets/${i}`});
393
+ }
394
+ }
275
395
 
276
- config.result.config.presets = await Promise.all(
277
- config.result.config.presets.map(async configItem => {
278
- let value = await options.packageManager.require(
279
- configItem.file.resolved,
280
- config.searchPath,
281
- {autoinstall: options.autoinstall},
282
- );
283
- value = value.default ? value.default : value;
284
- return babelCore.createConfigItem([value, configItem.options], {
285
- type: 'preset',
286
- dirname: configItem.dirname,
287
- });
288
- }),
289
- );
290
- config.result.config.plugins = await Promise.all(
291
- config.result.config.plugins.map(async configItem => {
292
- let value = await options.packageManager.require(
293
- configItem.file.resolved,
294
- config.searchPath,
295
- {autoinstall: options.autoinstall},
296
- );
297
- value = value.default ? value.default : value;
298
- return babelCore.createConfigItem([value, configItem.options], {
299
- type: 'plugin',
300
- dirname: configItem.dirname,
301
- });
302
- }),
303
- );
396
+ if (pointers.length > 0) {
397
+ try {
398
+ return generateJSONCodeHighlights(contents, pointers);
399
+ } catch {
400
+ // TODO: support code highlights for json5 sources.
401
+ // Babel supports json5 syntax, but json-source-map does not.
402
+ }
403
+ }
404
+ }
405
+
406
+ return [
407
+ {
408
+ start: {
409
+ line: 1,
410
+ column: 1,
411
+ },
412
+ end: {
413
+ line: 1,
414
+ column: 1,
415
+ },
416
+ },
417
+ ];
304
418
  }
package/src/constants.js CHANGED
@@ -1,3 +1,3 @@
1
1
  // @flow strict-local
2
2
 
3
- export const BABEL_RANGE = '^7.0.0';
3
+ export const BABEL_CORE_RANGE = '^7.12.0';