@parcel/transformer-babel 2.16.4 → 3.0.0-alpha.2
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/BabelTransformer.js +64 -124
- package/package.json +12 -18
- package/LICENSE +0 -21
- package/lib/babel7.js +0 -132
- package/lib/babelErrorUtils.js +0 -15
- package/lib/config.js +0 -311
- package/lib/constants.js +0 -7
- package/lib/flow.js +0 -52
- package/lib/jsx.js +0 -37
- package/lib/remapAstLocations.js +0 -55
- package/lib/types.js +0 -1
- package/lib/utils.js +0 -75
- package/src/BabelTransformer.js +0 -103
- package/src/babel7.js +0 -144
- package/src/babelErrorUtils.js +0 -30
- package/src/config.js +0 -413
- package/src/constants.js +0 -3
- package/src/flow.js +0 -74
- package/src/jsx.js +0 -40
- package/src/remapAstLocations.js +0 -70
- package/src/types.js +0 -6
- package/src/utils.js +0 -86
package/src/remapAstLocations.js
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
// @flow strict-local
|
|
2
|
-
|
|
3
|
-
import type {File as BabelNodeFile} from '@babel/types';
|
|
4
|
-
import type SourceMap from '@parcel/source-map';
|
|
5
|
-
import type {Node} from '@babel/types';
|
|
6
|
-
import typeof * as BabelTypes from '@babel/types';
|
|
7
|
-
|
|
8
|
-
export function remapAstLocations(
|
|
9
|
-
t: BabelTypes,
|
|
10
|
-
ast: BabelNodeFile,
|
|
11
|
-
map: SourceMap,
|
|
12
|
-
) {
|
|
13
|
-
// remap ast to original mappings
|
|
14
|
-
// This improves sourcemap accuracy and fixes sourcemaps when scope-hoisting
|
|
15
|
-
traverseAll(t, ast.program, node => {
|
|
16
|
-
if (node.loc) {
|
|
17
|
-
if (node.loc?.start) {
|
|
18
|
-
let mapping = map.findClosestMapping(
|
|
19
|
-
node.loc.start.line,
|
|
20
|
-
node.loc.start.column,
|
|
21
|
-
);
|
|
22
|
-
|
|
23
|
-
if (mapping?.original) {
|
|
24
|
-
// $FlowFixMe
|
|
25
|
-
node.loc.start.line = mapping.original.line;
|
|
26
|
-
// $FlowFixMe
|
|
27
|
-
node.loc.start.column = mapping.original.column;
|
|
28
|
-
|
|
29
|
-
// $FlowFixMe
|
|
30
|
-
let length = node.loc.end.column - node.loc.start.column;
|
|
31
|
-
|
|
32
|
-
// $FlowFixMe
|
|
33
|
-
node.loc.end.line = mapping.original.line;
|
|
34
|
-
// $FlowFixMe
|
|
35
|
-
node.loc.end.column = mapping.original.column + length;
|
|
36
|
-
|
|
37
|
-
// $FlowFixMe
|
|
38
|
-
node.loc.filename = mapping.source;
|
|
39
|
-
} else {
|
|
40
|
-
// Maintain null mappings?
|
|
41
|
-
node.loc = null;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
function traverseAll(
|
|
49
|
-
t: BabelTypes,
|
|
50
|
-
node: Node,
|
|
51
|
-
visitor: (node: Node) => void,
|
|
52
|
-
): void {
|
|
53
|
-
if (!node) {
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
visitor(node);
|
|
58
|
-
|
|
59
|
-
for (let key of t.VISITOR_KEYS[node.type] || []) {
|
|
60
|
-
// $FlowFixMe
|
|
61
|
-
let subNode: Node | Array<Node> = node[key];
|
|
62
|
-
if (Array.isArray(subNode)) {
|
|
63
|
-
for (let i = 0; i < subNode.length; i++) {
|
|
64
|
-
traverseAll(t, subNode[i], visitor);
|
|
65
|
-
}
|
|
66
|
-
} else {
|
|
67
|
-
traverseAll(t, subNode, visitor);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
}
|
package/src/types.js
DELETED
package/src/utils.js
DELETED
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
// @flow
|
|
2
|
-
|
|
3
|
-
import type {Environment} from '@parcel/types';
|
|
4
|
-
import type {Targets as BabelTargets} from '@babel/preset-env';
|
|
5
|
-
|
|
6
|
-
import invariant from 'assert';
|
|
7
|
-
import semver from 'semver';
|
|
8
|
-
|
|
9
|
-
// Copied from @babel/helper-compilation-targets/lib/options.js
|
|
10
|
-
const TargetNames = {
|
|
11
|
-
node: 'node',
|
|
12
|
-
chrome: 'chrome',
|
|
13
|
-
opera: 'opera',
|
|
14
|
-
edge: 'edge',
|
|
15
|
-
firefox: 'firefox',
|
|
16
|
-
safari: 'safari',
|
|
17
|
-
ie: 'ie',
|
|
18
|
-
ios: 'ios',
|
|
19
|
-
android: 'android',
|
|
20
|
-
electron: 'electron',
|
|
21
|
-
samsung: 'samsung',
|
|
22
|
-
rhino: 'rhino',
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
// List of browsers to exclude when the esmodule target is specified.
|
|
26
|
-
// Based on https://caniuse.com/#feat=es6-module
|
|
27
|
-
const ESMODULE_BROWSERS = [
|
|
28
|
-
'not ie <= 11',
|
|
29
|
-
'not edge < 16',
|
|
30
|
-
'not firefox < 60',
|
|
31
|
-
'not chrome < 61',
|
|
32
|
-
'not safari < 11',
|
|
33
|
-
'not opera < 48',
|
|
34
|
-
'not ios_saf < 11',
|
|
35
|
-
'not op_mini all',
|
|
36
|
-
'not android < 76',
|
|
37
|
-
'not blackberry > 0',
|
|
38
|
-
'not op_mob > 0',
|
|
39
|
-
'not and_chr < 76',
|
|
40
|
-
'not and_ff < 68',
|
|
41
|
-
'not ie_mob > 0',
|
|
42
|
-
'not and_uc > 0',
|
|
43
|
-
'not samsung < 8.2',
|
|
44
|
-
'not and_qq > 0',
|
|
45
|
-
'not baidu > 0',
|
|
46
|
-
'not kaios > 0',
|
|
47
|
-
];
|
|
48
|
-
|
|
49
|
-
export function enginesToBabelTargets(env: Environment): BabelTargets {
|
|
50
|
-
// "Targets" is the name @babel/preset-env uses for what Parcel calls engines.
|
|
51
|
-
// This should not be confused with Parcel's own targets.
|
|
52
|
-
// Unlike Parcel's engines, @babel/preset-env expects to work with minimum
|
|
53
|
-
// versions, not semver ranges, of its targets.
|
|
54
|
-
let targets = {};
|
|
55
|
-
for (let engineName of Object.keys(env.engines)) {
|
|
56
|
-
let engineValue = env.engines[engineName];
|
|
57
|
-
|
|
58
|
-
// if the engineValue is a string, it might be a semver range. Use the minimum
|
|
59
|
-
// possible version instead.
|
|
60
|
-
if (engineName === 'browsers') {
|
|
61
|
-
targets[engineName] = engineValue;
|
|
62
|
-
} else {
|
|
63
|
-
invariant(typeof engineValue === 'string');
|
|
64
|
-
if (!TargetNames.hasOwnProperty(engineName)) continue;
|
|
65
|
-
let minVersion = semver.minVersion(engineValue)?.toString();
|
|
66
|
-
targets[engineName] = minVersion ?? engineValue;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
if (env.outputFormat === 'esmodule' && env.isBrowser()) {
|
|
71
|
-
// If there is already a browsers target, add a blacklist to exclude
|
|
72
|
-
// instead of using babel's esmodules target. This allows specifying
|
|
73
|
-
// a newer set of browsers than the baseline esmodule support list.
|
|
74
|
-
// See https://github.com/babel/babel/issues/8809.
|
|
75
|
-
if (targets.browsers) {
|
|
76
|
-
let browsers = Array.isArray(targets.browsers)
|
|
77
|
-
? targets.browsers
|
|
78
|
-
: [targets.browsers];
|
|
79
|
-
targets.browsers = [...browsers, ...ESMODULE_BROWSERS];
|
|
80
|
-
} else {
|
|
81
|
-
targets.esmodules = true;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
return targets;
|
|
86
|
-
}
|