@parcel/transformer-babel 2.0.0-beta.3.1 → 2.0.0-canary.1521

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/lib/config.js CHANGED
@@ -4,112 +4,74 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.load = load;
7
-
8
- function _path() {
9
- const data = _interopRequireDefault(require("path"));
10
-
11
- _path = function () {
7
+ function _json() {
8
+ const data = _interopRequireDefault(require("json5"));
9
+ _json = function () {
12
10
  return data;
13
11
  };
14
-
15
12
  return data;
16
13
  }
17
-
18
- function internalBabelCore() {
19
- const data = _interopRequireWildcard(require("@babel/core"));
20
-
21
- internalBabelCore = function () {
14
+ function _path() {
15
+ const data = _interopRequireDefault(require("path"));
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
- return data;
36
- }
37
-
38
- function _jsx() {
39
- const data = _interopRequireDefault(require("./jsx"));
40
-
41
- _jsx = function () {
42
- return data;
43
- };
44
-
45
- return data;
46
- }
47
-
48
- function _flow() {
49
- const data = _interopRequireDefault(require("./flow"));
50
-
51
- _flow = function () {
52
- return data;
53
- };
54
-
55
26
  return data;
56
27
  }
57
-
58
- function _utils2() {
59
- const data = require("./utils");
60
-
61
- _utils2 = function () {
28
+ function _diagnostic() {
29
+ const data = require("@parcel/diagnostic");
30
+ _diagnostic = function () {
62
31
  return data;
63
32
  };
64
-
65
33
  return data;
66
34
  }
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; }
71
-
35
+ var _constants = require("./constants");
36
+ var _jsx = _interopRequireDefault(require("./jsx"));
37
+ var _flow = _interopRequireDefault(require("./flow"));
38
+ var _utils2 = require("./utils");
72
39
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
73
-
74
40
  const TYPESCRIPT_EXTNAME_RE = /\.tsx?$/;
75
-
76
- const BABEL_TRANSFORMER_DIR = _path().default.dirname(__dirname);
77
-
78
41
  const JS_EXTNAME_RE = /^\.(js|cjs|mjs)$/;
79
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'];
80
-
81
43
  async function load(config, options, logger) {
82
44
  var _ref, _ref2, _options$env$BABEL_EN;
83
-
84
45
  // Don't transpile inside node_modules
85
46
  if (!config.isSource) {
86
47
  return;
87
- } // Invalidate when any babel config file is added.
88
-
48
+ }
89
49
 
50
+ // Invalidate when any babel config file is added.
90
51
  for (let fileName of BABEL_CONFIG_FILENAMES) {
91
52
  config.invalidateOnFileCreate({
92
53
  fileName,
93
54
  aboveFilePath: config.searchPath
94
55
  });
95
- } // Do nothing if we cannot resolve any babel config filenames. Checking using our own
96
- // config resolution (which is cached) is much faster than relying on babel.
97
-
56
+ }
98
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.
99
60
  if (!(await (0, _utils().resolveConfig)(options.inputFS, config.searchPath, BABEL_CONFIG_FILENAMES, options.projectRoot))) {
100
- await buildDefaultBabelConfig(options, config);
101
- return;
61
+ return buildDefaultBabelConfig(options, config);
102
62
  }
103
-
104
63
  const babelCore = await options.packageManager.require('@babel/core', config.searchPath, {
105
- range: '^7.12.0',
64
+ range: _constants.BABEL_CORE_RANGE,
106
65
  saveDev: true,
107
66
  shouldAutoInstall: options.shouldAutoInstall
108
67
  });
109
68
  config.addDevDependency({
110
- moduleSpecifier: '@babel/core',
111
- resolveFrom: config.searchPath
69
+ specifier: '@babel/core',
70
+ resolveFrom: config.searchPath,
71
+ range: _constants.BABEL_CORE_RANGE
112
72
  });
73
+ config.invalidateOnEnvChange('BABEL_ENV');
74
+ config.invalidateOnEnvChange('NODE_ENV');
113
75
  let babelOptions = {
114
76
  filename: config.searchPath,
115
77
  cwd: options.projectRoot,
@@ -117,7 +79,6 @@ async function load(config, options, logger) {
117
79
  showIgnoredFiles: true
118
80
  };
119
81
  let partialConfig = await babelCore.loadPartialConfigAsync(babelOptions);
120
-
121
82
  let addIncludedFile = file => {
122
83
  if (JS_EXTNAME_RE.test(_path().default.extname(file))) {
123
84
  // We need to invalidate on startup in case the config is non-static,
@@ -125,43 +86,44 @@ async function load(config, options, logger) {
125
86
  logger.warn({
126
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.`
127
88
  });
128
- config.shouldInvalidateOnStartup(); // But also add the config as a dev dependency so we can at least attempt invalidation in watch mode.
89
+ config.invalidateOnStartup();
129
90
 
91
+ // But also add the config as a dev dependency so we can at least attempt invalidation in watch mode.
130
92
  config.addDevDependency({
131
- moduleSpecifier: (0, _utils().relativePath)(options.projectRoot, file),
93
+ specifier: (0, _utils().relativePath)(options.projectRoot, file),
132
94
  resolveFrom: _path().default.join(options.projectRoot, 'index'),
133
- // Also invalidate @parcel/transformer-babel when the config or a dependency updates.
95
+ // Also invalidate @babel/core when the config or a dependency updates.
134
96
  // This ensures that the caches in @babel/core are also invalidated.
135
- invalidateParcelPlugin: true
97
+ additionalInvalidations: [{
98
+ specifier: '@babel/core',
99
+ resolveFrom: config.searchPath,
100
+ range: _constants.BABEL_CORE_RANGE
101
+ }]
136
102
  });
137
103
  } else {
138
- config.addIncludedFile(file);
104
+ config.invalidateOnFileChange(file);
139
105
  }
140
106
  };
141
-
142
107
  let warnOldVersion = () => {
143
108
  logger.warn({
144
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.'
145
110
  });
146
- config.shouldInvalidateOnStartup();
147
- }; // Old versions of @babel/core return null from loadPartialConfig when the file should explicitly not be run through babel (ignore/exclude)
148
-
111
+ config.invalidateOnStartup();
112
+ };
149
113
 
114
+ // Old versions of @babel/core return null from loadPartialConfig when the file should explicitly not be run through babel (ignore/exclude)
150
115
  if (partialConfig == null) {
151
116
  warnOldVersion();
152
117
  return;
153
118
  }
154
-
155
119
  if (partialConfig.files == null) {
156
120
  // If the files property is missing, we're on an old version of @babel/core.
157
121
  // We need to invalidate on startup because we can't properly track dependencies.
158
122
  if (partialConfig.hasFilesystemConfig()) {
159
123
  warnOldVersion();
160
-
161
124
  if (typeof partialConfig.babelrcPath === 'string') {
162
125
  addIncludedFile(partialConfig.babelrcPath);
163
126
  }
164
-
165
127
  if (typeof partialConfig.configPath === 'string') {
166
128
  addIncludedFile(partialConfig.configPath);
167
129
  }
@@ -171,104 +133,182 @@ async function load(config, options, logger) {
171
133
  addIncludedFile(file);
172
134
  }
173
135
  }
174
-
175
136
  if (partialConfig.fileHandling != null && partialConfig.fileHandling !== 'transpile') {} else if (partialConfig.hasFilesystemConfig()) {
176
137
  // Determine what syntax plugins we need to enable
177
138
  let syntaxPlugins = [];
178
-
179
139
  if (TYPESCRIPT_EXTNAME_RE.test(config.searchPath)) {
180
140
  syntaxPlugins.push('typescript');
181
-
182
141
  if (config.searchPath.endsWith('.tsx')) {
183
142
  syntaxPlugins.push('jsx');
184
143
  }
185
- } else if (await (0, _jsx().default)(options, config)) {
144
+ } else if (await (0, _jsx.default)(options, config)) {
186
145
  syntaxPlugins.push('jsx');
187
146
  }
188
147
 
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,
148
+ // If the config has plugins loaded with require(), or inline plugins in the config,
195
149
  // we can't cache the result of the compilation because we don't know where they came from.
196
-
197
150
  if (hasRequire(partialConfig.options)) {
198
151
  logger.warn({
199
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.'
200
153
  });
201
- config.setResultHash(JSON.stringify(Date.now()));
202
- config.shouldInvalidateOnStartup();
154
+ config.setCacheKey(JSON.stringify(Date.now()));
155
+ config.invalidateOnStartup();
203
156
  } else {
204
- definePluginDependencies(config, options);
205
- config.setResultHash((0, _utils().md5FromObject)(partialConfig.options));
157
+ await warnOnRedundantPlugins(options.inputFS, partialConfig, logger);
158
+ definePluginDependencies(config, partialConfig.options, options);
159
+ config.setCacheKey((0, _utils().hashObject)(partialConfig.options));
206
160
  }
161
+ return {
162
+ internal: false,
163
+ config: partialConfig.options,
164
+ targets: (0, _utils2.enginesToBabelTargets)(config.env),
165
+ syntaxPlugins
166
+ };
207
167
  } else {
208
- await buildDefaultBabelConfig(options, config);
168
+ return buildDefaultBabelConfig(options, config);
209
169
  }
210
170
  }
211
-
212
171
  async function buildDefaultBabelConfig(options, config) {
213
172
  // If this is a .ts or .tsx file, we don't need to enable flow.
214
173
  if (TYPESCRIPT_EXTNAME_RE.test(config.searchPath)) {
215
174
  return;
216
- } // Detect flow. If not enabled, babel doesn't need to run at all.
217
-
218
-
219
- let babelOptions = await (0, _flow().default)(config, options);
175
+ }
220
176
 
177
+ // Detect flow. If not enabled, babel doesn't need to run at all.
178
+ let babelOptions = await (0, _flow.default)(config, options);
221
179
  if (babelOptions == null) {
222
180
  return;
223
- } // When flow is enabled, we may also need to enable JSX so it parses properly.
224
-
181
+ }
225
182
 
183
+ // When flow is enabled, we may also need to enable JSX so it parses properly.
226
184
  let syntaxPlugins = [];
227
-
228
- if (await (0, _jsx().default)(options, config)) {
185
+ if (await (0, _jsx.default)(options, config)) {
229
186
  syntaxPlugins.push('jsx');
230
187
  }
231
-
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({
188
+ definePluginDependencies(config, babelOptions, options);
189
+ return {
241
190
  internal: true,
242
191
  config: babelOptions,
243
192
  syntaxPlugins
244
- });
245
- definePluginDependencies(config, options);
193
+ };
246
194
  }
247
-
248
195
  function hasRequire(options) {
249
196
  let configItems = [...options.presets, ...options.plugins];
250
197
  return configItems.some(item => !item.file);
251
198
  }
252
-
253
- function definePluginDependencies(config, options) {
254
- let babelConfig = config.result.config;
255
-
199
+ function definePluginDependencies(config, babelConfig, options) {
256
200
  if (babelConfig == null) {
257
201
  return;
258
202
  }
259
-
260
- let configItems = [...babelConfig.presets, ...babelConfig.plugins];
261
-
203
+ let configItems = [...(babelConfig.presets || []), ...(babelConfig.plugins || [])];
262
204
  for (let configItem of configItems) {
263
205
  // FIXME: this uses a relative path from the project root rather than resolving
264
206
  // from the config location because configItem.file.request can be a shorthand
265
207
  // rather than a full package name.
266
208
  config.addDevDependency({
267
- moduleSpecifier: (0, _utils().relativePath)(options.projectRoot, configItem.file.resolved),
209
+ specifier: (0, _utils().relativePath)(options.projectRoot, configItem.file.resolved),
268
210
  resolveFrom: _path().default.join(options.projectRoot, 'index'),
269
- // Also invalidate @parcel/transformer-babel when the plugin or a dependency updates.
211
+ // Also invalidate @babel/core when the plugin or a dependency updates.
270
212
  // This ensures that the caches in @babel/core are also invalidated.
271
- invalidateParcelPlugin: true
213
+ additionalInvalidations: [{
214
+ specifier: '@babel/core',
215
+ resolveFrom: config.searchPath,
216
+ range: _constants.BABEL_CORE_RANGE
217
+ }]
272
218
  });
273
219
  }
220
+ }
221
+ const redundantPresets = new Set(['@babel/preset-env', '@babel/preset-react', '@babel/preset-typescript', '@parcel/babel-preset-env']);
222
+ async function warnOnRedundantPlugins(fs, babelConfig, logger) {
223
+ var _babelConfig$config;
224
+ if (babelConfig == null) {
225
+ return;
226
+ }
227
+ let configPath = (_babelConfig$config = babelConfig.config) !== null && _babelConfig$config !== void 0 ? _babelConfig$config : babelConfig.babelrc;
228
+ if (!configPath) {
229
+ return;
230
+ }
231
+ let presets = babelConfig.options.presets || [];
232
+ let plugins = babelConfig.options.plugins || [];
233
+ let foundRedundantPresets = new Set();
234
+ let filteredPresets = presets.filter(preset => {
235
+ if (redundantPresets.has(preset.file.request)) {
236
+ foundRedundantPresets.add(preset.file.request);
237
+ return false;
238
+ }
239
+ return true;
240
+ });
241
+ let filePath = _path().default.relative(process.cwd(), configPath);
242
+ let diagnostics = [];
243
+ if (filteredPresets.length === 0 && foundRedundantPresets.size > 0 && plugins.length === 0) {
244
+ diagnostics.push({
245
+ message: (0, _diagnostic().md)`Parcel includes transpilation by default. Babel config __${filePath}__ contains only redundant presets. Deleting it may significantly improve build performance.`,
246
+ codeFrames: [{
247
+ filePath: configPath,
248
+ codeHighlights: await getCodeHighlights(fs, configPath, foundRedundantPresets)
249
+ }],
250
+ hints: [(0, _diagnostic().md)`Delete __${filePath}__`],
251
+ documentationURL: 'https://parceljs.org/languages/javascript/#default-presets'
252
+ });
253
+ } else if (foundRedundantPresets.size > 0) {
254
+ diagnostics.push({
255
+ 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
+ codeFrames: [{
257
+ filePath: configPath,
258
+ codeHighlights: await getCodeHighlights(fs, configPath, foundRedundantPresets)
259
+ }],
260
+ hints: [(0, _diagnostic().md)`Remove the above presets from __${filePath}__`],
261
+ documentationURL: 'https://parceljs.org/languages/javascript/#default-presets'
262
+ });
263
+ }
264
+ if (foundRedundantPresets.has('@babel/preset-env')) {
265
+ var _babelConfig$config2, _babelConfig$config3;
266
+ diagnostics.push({
267
+ message: "@babel/preset-env does not support Parcel's targets, which will likely result in unnecessary transpilation and larger bundle sizes.",
268
+ codeFrames: [{
269
+ filePath: (_babelConfig$config2 = babelConfig.config) !== null && _babelConfig$config2 !== void 0 ? _babelConfig$config2 : babelConfig.babelrc,
270
+ codeHighlights: await getCodeHighlights(fs, (_babelConfig$config3 = babelConfig.config) !== null && _babelConfig$config3 !== void 0 ? _babelConfig$config3 : babelConfig.babelrc, new Set(['@babel/preset-env']))
271
+ }],
272
+ hints: [`Either remove __@babel/preset-env__ to use Parcel's builtin transpilation, or replace with __@parcel/babel-preset-env__`],
273
+ documentationURL: 'https://parceljs.org/languages/javascript/#custom-plugins'
274
+ });
275
+ }
276
+ if (diagnostics.length > 0) {
277
+ logger.warn(diagnostics);
278
+ }
279
+ }
280
+ async function getCodeHighlights(fs, filePath, redundantPresets) {
281
+ let ext = _path().default.extname(filePath);
282
+ if (ext !== '.js' && ext !== '.cjs' && ext !== '.mjs') {
283
+ let contents = await fs.readFile(filePath, 'utf8');
284
+ let json = _json().default.parse(contents);
285
+ let presets = json.presets || [];
286
+ let pointers = [];
287
+ for (let i = 0; i < presets.length; i++) {
288
+ if (Array.isArray(presets[i]) && redundantPresets.has(presets[i][0])) {
289
+ pointers.push({
290
+ type: 'value',
291
+ key: `/presets/${i}/0`
292
+ });
293
+ } else if (redundantPresets.has(presets[i])) {
294
+ pointers.push({
295
+ type: 'value',
296
+ key: `/presets/${i}`
297
+ });
298
+ }
299
+ }
300
+ if (pointers.length > 0) {
301
+ return (0, _diagnostic().generateJSONCodeHighlights)(contents, pointers);
302
+ }
303
+ }
304
+ return [{
305
+ start: {
306
+ line: 1,
307
+ column: 1
308
+ },
309
+ end: {
310
+ line: 1,
311
+ column: 1
312
+ }
313
+ }];
274
314
  }
package/lib/constants.js CHANGED
@@ -3,6 +3,5 @@
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 = exports.BABEL_CORE_RANGE = '^7.12.0';
package/lib/flow.js CHANGED
@@ -4,26 +4,45 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = getFlowOptions;
7
-
7
+ var _constants = require("./constants");
8
+ function _path() {
9
+ const data = _interopRequireDefault(require("path"));
10
+ _path = function () {
11
+ return data;
12
+ };
13
+ return data;
14
+ }
15
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
8
16
  /**
9
17
  * Generates a babel config for stripping away Flow types.
10
18
  */
11
19
  async function getFlowOptions(config, options) {
12
20
  if (!config.isSource) {
13
21
  return null;
14
- } // Only add flow plugin if `flow-bin` is listed as a dependency in the root package.json
15
-
22
+ }
16
23
 
24
+ // Only add flow plugin if `flow-bin` is listed as a dependency in the root package.json
17
25
  let conf = await config.getConfigFrom(options.projectRoot + '/index', ['package.json']);
18
26
  let pkg = conf === null || conf === void 0 ? void 0 : conf.contents;
19
-
20
27
  if (!pkg || !(pkg.dependencies && pkg.dependencies['flow-bin']) && !(pkg.devDependencies && pkg.devDependencies['flow-bin'])) {
21
28
  return null;
22
29
  }
23
-
30
+ const babelCore = await options.packageManager.require('@babel/core', config.searchPath, {
31
+ range: _constants.BABEL_CORE_RANGE,
32
+ saveDev: true,
33
+ shouldAutoInstall: options.shouldAutoInstall
34
+ });
35
+ await options.packageManager.require('@babel/plugin-transform-flow-strip-types', config.searchPath, {
36
+ range: '^7.0.0',
37
+ saveDev: true,
38
+ shouldAutoInstall: options.shouldAutoInstall
39
+ });
24
40
  return {
25
- plugins: [['@babel/plugin-transform-flow-strip-types', {
41
+ plugins: [babelCore.createConfigItem(['@babel/plugin-transform-flow-strip-types', {
26
42
  requireDirective: true
27
- }]]
43
+ }], {
44
+ type: 'plugin',
45
+ dirname: _path().default.dirname(config.searchPath)
46
+ })]
28
47
  };
29
48
  }
package/lib/jsx.js CHANGED
@@ -4,42 +4,34 @@ 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;
41
33
  } else {
42
34
  // Find a dependency that implies JSX syntax.
43
- return JSX_LIBRARIES.some(libName => pkg && (pkg.dependencies && pkg.dependencies[libName] || pkg.devDependencies && pkg.devDependencies[libName]));
35
+ return JSX_LIBRARIES.some(libName => pkg && (pkg.dependencies && pkg.dependencies[libName] || pkg.devDependencies && pkg.devDependencies[libName] || pkg.peerDependencies && pkg.peerDependencies[libName]));
44
36
  }
45
37
  }
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.remapAstLocations = remapAstLocations;
7
+ function remapAstLocations(t, ast, map) {
8
+ // remap ast to original mappings
9
+ // This improves sourcemap accuracy and fixes sourcemaps when scope-hoisting
10
+ traverseAll(t, ast.program, node => {
11
+ if (node.loc) {
12
+ var _node$loc;
13
+ if ((_node$loc = node.loc) !== null && _node$loc !== void 0 && _node$loc.start) {
14
+ let mapping = map.findClosestMapping(node.loc.start.line, node.loc.start.column);
15
+ if (mapping !== null && mapping !== void 0 && mapping.original) {
16
+ // $FlowFixMe
17
+ node.loc.start.line = mapping.original.line;
18
+ // $FlowFixMe
19
+ node.loc.start.column = mapping.original.column;
20
+
21
+ // $FlowFixMe
22
+ let length = node.loc.end.column - node.loc.start.column;
23
+
24
+ // $FlowFixMe
25
+ node.loc.end.line = mapping.original.line;
26
+ // $FlowFixMe
27
+ node.loc.end.column = mapping.original.column + length;
28
+
29
+ // $FlowFixMe
30
+ node.loc.filename = mapping.source;
31
+ } else {
32
+ // Maintain null mappings?
33
+ node.loc = null;
34
+ }
35
+ }
36
+ }
37
+ });
38
+ }
39
+ function traverseAll(t, node, visitor) {
40
+ if (!node) {
41
+ return;
42
+ }
43
+ visitor(node);
44
+ for (let key of t.VISITOR_KEYS[node.type] || []) {
45
+ // $FlowFixMe
46
+ let subNode = node[key];
47
+ if (Array.isArray(subNode)) {
48
+ for (let i = 0; i < subNode.length; i++) {
49
+ traverseAll(t, subNode[i], visitor);
50
+ }
51
+ } else {
52
+ traverseAll(t, subNode, visitor);
53
+ }
54
+ }
55
+ }