@parcel/transformer-babel 2.8.3 → 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.
- package/lib/BabelTransformer.js +9 -31
- package/lib/babel7.js +56 -21
- package/lib/babelErrorUtils.js +0 -2
- package/lib/config.js +16 -73
- package/lib/flow.js +2 -10
- package/lib/jsx.js +1 -9
- package/lib/remapAstLocations.js +10 -14
- package/lib/utils.js +6 -17
- package/package.json +7 -7
- package/src/BabelTransformer.js +10 -2
- package/src/babel7.js +52 -2
package/lib/BabelTransformer.js
CHANGED
|
@@ -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,17 +44,17 @@ 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,
|
|
74
|
-
|
|
55
|
+
logger,
|
|
56
|
+
options,
|
|
57
|
+
tracer
|
|
75
58
|
}) {
|
|
76
59
|
try {
|
|
77
60
|
if (config !== null && config !== void 0 && config.config) {
|
|
@@ -79,24 +62,26 @@ var _default = new (_plugin().Transformer)({
|
|
|
79
62
|
await (0, _babel.default)({
|
|
80
63
|
asset,
|
|
81
64
|
options,
|
|
65
|
+
logger,
|
|
82
66
|
babelOptions: config,
|
|
83
|
-
additionalPlugins: asset.meta.babelPlugins
|
|
67
|
+
additionalPlugins: asset.meta.babelPlugins,
|
|
68
|
+
tracer
|
|
84
69
|
});
|
|
85
70
|
} else {
|
|
86
71
|
await (0, _babel.default)({
|
|
87
72
|
asset,
|
|
88
73
|
options,
|
|
89
|
-
|
|
74
|
+
logger,
|
|
75
|
+
babelOptions: config,
|
|
76
|
+
tracer
|
|
90
77
|
});
|
|
91
78
|
}
|
|
92
79
|
}
|
|
93
|
-
|
|
94
80
|
return [asset];
|
|
95
81
|
} catch (e) {
|
|
96
82
|
throw await (0, _babelErrorUtils.babelErrorEnhancer)(e, asset);
|
|
97
83
|
}
|
|
98
84
|
},
|
|
99
|
-
|
|
100
85
|
async generate({
|
|
101
86
|
asset,
|
|
102
87
|
ast,
|
|
@@ -121,31 +106,24 @@ var _default = new (_plugin().Transformer)({
|
|
|
121
106
|
comments: true
|
|
122
107
|
});
|
|
123
108
|
let map = new (_sourceMap().default)(options.projectRoot);
|
|
124
|
-
|
|
125
109
|
if (rawMappings) {
|
|
126
110
|
map.addIndexedMappings(rawMappings);
|
|
127
111
|
}
|
|
128
|
-
|
|
129
112
|
if (originalSourceMap) {
|
|
130
113
|
// The babel AST already contains the correct mappings, but not the source contents.
|
|
131
114
|
// We need to copy over the source contents from the original map.
|
|
132
115
|
let sourcesContent = originalSourceMap.getSourcesContentMap();
|
|
133
|
-
|
|
134
116
|
for (let filePath in sourcesContent) {
|
|
135
117
|
let content = sourcesContent[filePath];
|
|
136
|
-
|
|
137
118
|
if (content != null) {
|
|
138
119
|
map.setSourceContent(filePath, content);
|
|
139
120
|
}
|
|
140
121
|
}
|
|
141
122
|
}
|
|
142
|
-
|
|
143
123
|
return {
|
|
144
124
|
content: code,
|
|
145
125
|
map
|
|
146
126
|
};
|
|
147
127
|
}
|
|
148
|
-
|
|
149
128
|
});
|
|
150
|
-
|
|
151
129
|
exports.default = _default;
|
package/lib/babel7.js
CHANGED
|
@@ -4,66 +4,74 @@ 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
|
-
|
|
14
|
+
function _path() {
|
|
15
|
+
const data = _interopRequireDefault(require("path"));
|
|
16
|
+
_path = function () {
|
|
17
|
+
return data;
|
|
18
|
+
};
|
|
19
|
+
return data;
|
|
20
|
+
}
|
|
21
|
+
function _diagnostic() {
|
|
22
|
+
const data = require("@parcel/diagnostic");
|
|
23
|
+
_diagnostic = function () {
|
|
24
|
+
return data;
|
|
25
|
+
};
|
|
26
|
+
return data;
|
|
27
|
+
}
|
|
18
28
|
function _utils() {
|
|
19
29
|
const data = require("@parcel/utils");
|
|
20
|
-
|
|
21
30
|
_utils = function () {
|
|
22
31
|
return data;
|
|
23
32
|
};
|
|
24
|
-
|
|
25
33
|
return data;
|
|
26
34
|
}
|
|
27
|
-
|
|
28
35
|
var _remapAstLocations = require("./remapAstLocations");
|
|
29
|
-
|
|
30
36
|
var _package = _interopRequireDefault(require("../package.json"));
|
|
31
|
-
|
|
32
37
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
33
|
-
|
|
34
38
|
const transformerVersion = _package.default.version;
|
|
35
39
|
(0, _assert().default)(typeof transformerVersion === 'string');
|
|
36
|
-
|
|
37
40
|
async function babel7(opts) {
|
|
38
41
|
var _babelOptions$config$, _babelOptions$config$2, _babelOptions$syntaxP;
|
|
39
|
-
|
|
40
42
|
let {
|
|
41
43
|
asset,
|
|
42
44
|
options,
|
|
43
45
|
babelOptions,
|
|
44
|
-
additionalPlugins = []
|
|
46
|
+
additionalPlugins = [],
|
|
47
|
+
tracer
|
|
45
48
|
} = opts;
|
|
46
49
|
const babelCore = await options.packageManager.require('@babel/core', asset.filePath, {
|
|
47
50
|
range: '^7.12.0',
|
|
48
51
|
saveDev: true,
|
|
49
52
|
shouldAutoInstall: options.shouldAutoInstall
|
|
50
53
|
});
|
|
51
|
-
let config = {
|
|
54
|
+
let config = {
|
|
55
|
+
...babelOptions.config,
|
|
52
56
|
plugins: additionalPlugins.concat(babelOptions.config.plugins),
|
|
53
57
|
code: false,
|
|
54
58
|
ast: true,
|
|
55
59
|
filename: asset.filePath,
|
|
56
60
|
babelrc: false,
|
|
57
61
|
configFile: false,
|
|
58
|
-
parserOpts: {
|
|
62
|
+
parserOpts: {
|
|
63
|
+
...babelOptions.config.parserOpts,
|
|
59
64
|
sourceFilename: (0, _utils().relativeUrl)(options.projectRoot, asset.filePath),
|
|
60
65
|
allowReturnOutsideFunction: true,
|
|
61
66
|
strictMode: false,
|
|
62
67
|
sourceType: 'module',
|
|
63
|
-
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 : []),
|
|
64
|
-
|
|
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'
|
|
65
72
|
]
|
|
66
73
|
},
|
|
74
|
+
|
|
67
75
|
caller: {
|
|
68
76
|
name: 'parcel',
|
|
69
77
|
version: transformerVersion,
|
|
@@ -71,23 +79,50 @@ async function babel7(opts) {
|
|
|
71
79
|
outputFormat: asset.env.outputFormat
|
|
72
80
|
}
|
|
73
81
|
};
|
|
82
|
+
if (tracer.enabled) {
|
|
83
|
+
config.wrapPluginVisitorMethod = (key, nodeType, fn) => {
|
|
84
|
+
return function () {
|
|
85
|
+
let pluginKey = key;
|
|
86
|
+
if (pluginKey.startsWith(options.projectRoot)) {
|
|
87
|
+
pluginKey = _path().default.relative(options.projectRoot, pluginKey);
|
|
88
|
+
}
|
|
89
|
+
const measurement = tracer.createMeasurement(pluginKey, nodeType, _path().default.relative(options.projectRoot, asset.filePath));
|
|
90
|
+
fn.apply(this, arguments);
|
|
91
|
+
measurement && measurement.end();
|
|
92
|
+
};
|
|
93
|
+
};
|
|
94
|
+
}
|
|
74
95
|
let ast = await asset.getAST();
|
|
75
96
|
let res;
|
|
76
|
-
|
|
77
97
|
if (ast) {
|
|
78
98
|
res = await babelCore.transformFromAstAsync(ast.program, asset.isASTDirty() ? undefined : await asset.getCode(), config);
|
|
79
99
|
} else {
|
|
80
100
|
res = await babelCore.transformAsync(await asset.getCode(), config);
|
|
81
|
-
|
|
82
101
|
if (res.ast) {
|
|
83
102
|
let map = await asset.getMap();
|
|
84
|
-
|
|
85
103
|
if (map) {
|
|
86
104
|
(0, _remapAstLocations.remapAstLocations)(babelCore.types, res.ast, map);
|
|
87
105
|
}
|
|
88
106
|
}
|
|
107
|
+
if (res.externalDependencies) {
|
|
108
|
+
for (let f of res.externalDependencies) {
|
|
109
|
+
if (!_path().default.isAbsolute(f)) {
|
|
110
|
+
opts.logger.warn({
|
|
111
|
+
message: (0, _diagnostic().md)`Ignoring non-absolute Babel external dependency: ${f}`,
|
|
112
|
+
hints: ['Please report this to the corresponding Babel plugin and/or to Parcel.']
|
|
113
|
+
});
|
|
114
|
+
} else {
|
|
115
|
+
if (await options.inputFS.exists(f)) {
|
|
116
|
+
asset.invalidateOnFileChange(f);
|
|
117
|
+
} else {
|
|
118
|
+
asset.invalidateOnFileCreate({
|
|
119
|
+
filePath: f
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
89
125
|
}
|
|
90
|
-
|
|
91
126
|
if (res.ast) {
|
|
92
127
|
asset.setAST({
|
|
93
128
|
type: 'babel',
|
package/lib/babelErrorUtils.js
CHANGED
|
@@ -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
|
-
}
|
|
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
|
-
}
|
|
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();
|
|
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
|
-
};
|
|
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
|
-
}
|
|
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
|
-
}
|
|
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
|
-
}
|
|
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
|
-
}
|
|
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;
|
package/lib/remapAstLocations.js
CHANGED
|
@@ -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;
|
|
21
|
-
|
|
22
|
-
node.loc.start.column = mapping.original.column;
|
|
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
|
-
|
|
21
|
+
// $FlowFixMe
|
|
22
|
+
let length = node.loc.end.column - node.loc.start.column;
|
|
27
23
|
|
|
28
|
-
|
|
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
|
-
};
|
|
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];
|
|
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.
|
|
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.
|
|
20
|
+
"parcel": "^2.9.0"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@parcel/diagnostic": "2.
|
|
24
|
-
"@parcel/plugin": "2.
|
|
23
|
+
"@parcel/diagnostic": "2.9.0",
|
|
24
|
+
"@parcel/plugin": "2.9.0",
|
|
25
25
|
"@parcel/source-map": "^2.1.1",
|
|
26
|
-
"@parcel/utils": "2.
|
|
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.
|
|
36
|
+
"@parcel/types": "2.9.0"
|
|
37
37
|
},
|
|
38
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "dd9435be8afed35c5ffc161cf4b586fd6c78fc1f"
|
|
39
39
|
}
|
package/src/BabelTransformer.js
CHANGED
|
@@ -17,7 +17,7 @@ export default (new Transformer({
|
|
|
17
17
|
return ast.type === 'babel' && semver.satisfies(ast.version, '^7.0.0');
|
|
18
18
|
},
|
|
19
19
|
|
|
20
|
-
async transform({asset, config, options}) {
|
|
20
|
+
async transform({asset, config, logger, options, tracer}) {
|
|
21
21
|
try {
|
|
22
22
|
if (config?.config) {
|
|
23
23
|
if (
|
|
@@ -27,11 +27,19 @@ export default (new Transformer({
|
|
|
27
27
|
await babel7({
|
|
28
28
|
asset,
|
|
29
29
|
options,
|
|
30
|
+
logger,
|
|
30
31
|
babelOptions: config,
|
|
31
32
|
additionalPlugins: asset.meta.babelPlugins,
|
|
33
|
+
tracer,
|
|
32
34
|
});
|
|
33
35
|
} else {
|
|
34
|
-
await babel7({
|
|
36
|
+
await babel7({
|
|
37
|
+
asset,
|
|
38
|
+
options,
|
|
39
|
+
logger,
|
|
40
|
+
babelOptions: config,
|
|
41
|
+
tracer,
|
|
42
|
+
});
|
|
35
43
|
}
|
|
36
44
|
}
|
|
37
45
|
|
package/src/babel7.js
CHANGED
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
// @flow
|
|
2
2
|
|
|
3
|
-
import type {
|
|
3
|
+
import type {
|
|
4
|
+
MutableAsset,
|
|
5
|
+
AST,
|
|
6
|
+
PluginOptions,
|
|
7
|
+
PluginTracer,
|
|
8
|
+
PluginLogger,
|
|
9
|
+
} from '@parcel/types';
|
|
4
10
|
import typeof * as BabelCore from '@babel/core';
|
|
5
11
|
|
|
6
12
|
import invariant from 'assert';
|
|
13
|
+
import path from 'path';
|
|
14
|
+
import {md} from '@parcel/diagnostic';
|
|
7
15
|
import {relativeUrl} from '@parcel/utils';
|
|
8
16
|
import {remapAstLocations} from './remapAstLocations';
|
|
9
17
|
|
|
@@ -15,14 +23,16 @@ invariant(typeof transformerVersion === 'string');
|
|
|
15
23
|
type Babel7TransformOptions = {|
|
|
16
24
|
asset: MutableAsset,
|
|
17
25
|
options: PluginOptions,
|
|
26
|
+
logger: PluginLogger,
|
|
18
27
|
babelOptions: any,
|
|
19
28
|
additionalPlugins?: Array<any>,
|
|
29
|
+
tracer: PluginTracer,
|
|
20
30
|
|};
|
|
21
31
|
|
|
22
32
|
export default async function babel7(
|
|
23
33
|
opts: Babel7TransformOptions,
|
|
24
34
|
): Promise<?AST> {
|
|
25
|
-
let {asset, options, babelOptions, additionalPlugins = []} = opts;
|
|
35
|
+
let {asset, options, babelOptions, additionalPlugins = [], tracer} = opts;
|
|
26
36
|
const babelCore: BabelCore = await options.packageManager.require(
|
|
27
37
|
'@babel/core',
|
|
28
38
|
asset.filePath,
|
|
@@ -66,6 +76,28 @@ export default async function babel7(
|
|
|
66
76
|
},
|
|
67
77
|
};
|
|
68
78
|
|
|
79
|
+
if (tracer.enabled) {
|
|
80
|
+
config.wrapPluginVisitorMethod = (
|
|
81
|
+
key: string,
|
|
82
|
+
nodeType: string,
|
|
83
|
+
fn: Function,
|
|
84
|
+
) => {
|
|
85
|
+
return function () {
|
|
86
|
+
let pluginKey = key;
|
|
87
|
+
if (pluginKey.startsWith(options.projectRoot)) {
|
|
88
|
+
pluginKey = path.relative(options.projectRoot, pluginKey);
|
|
89
|
+
}
|
|
90
|
+
const measurement = tracer.createMeasurement(
|
|
91
|
+
pluginKey,
|
|
92
|
+
nodeType,
|
|
93
|
+
path.relative(options.projectRoot, asset.filePath),
|
|
94
|
+
);
|
|
95
|
+
fn.apply(this, arguments);
|
|
96
|
+
measurement && measurement.end();
|
|
97
|
+
};
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
|
|
69
101
|
let ast = await asset.getAST();
|
|
70
102
|
let res;
|
|
71
103
|
if (ast) {
|
|
@@ -82,6 +114,24 @@ export default async function babel7(
|
|
|
82
114
|
remapAstLocations(babelCore.types, res.ast, map);
|
|
83
115
|
}
|
|
84
116
|
}
|
|
117
|
+
if (res.externalDependencies) {
|
|
118
|
+
for (let f of res.externalDependencies) {
|
|
119
|
+
if (!path.isAbsolute(f)) {
|
|
120
|
+
opts.logger.warn({
|
|
121
|
+
message: md`Ignoring non-absolute Babel external dependency: ${f}`,
|
|
122
|
+
hints: [
|
|
123
|
+
'Please report this to the corresponding Babel plugin and/or to Parcel.',
|
|
124
|
+
],
|
|
125
|
+
});
|
|
126
|
+
} else {
|
|
127
|
+
if (await options.inputFS.exists(f)) {
|
|
128
|
+
asset.invalidateOnFileChange(f);
|
|
129
|
+
} else {
|
|
130
|
+
asset.invalidateOnFileCreate({filePath: f});
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
85
135
|
}
|
|
86
136
|
|
|
87
137
|
if (res.ast) {
|