@parcel/transformer-babel 2.8.2 → 2.8.4-nightly.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 -3
- package/lib/babel7.js +58 -1
- package/package.json +7 -7
- package/src/BabelTransformer.js +10 -2
- package/src/babel7.js +52 -2
package/lib/BabelTransformer.js
CHANGED
|
@@ -71,7 +71,9 @@ var _default = new (_plugin().Transformer)({
|
|
|
71
71
|
async transform({
|
|
72
72
|
asset,
|
|
73
73
|
config,
|
|
74
|
-
|
|
74
|
+
logger,
|
|
75
|
+
options,
|
|
76
|
+
tracer
|
|
75
77
|
}) {
|
|
76
78
|
try {
|
|
77
79
|
if (config !== null && config !== void 0 && config.config) {
|
|
@@ -79,14 +81,18 @@ var _default = new (_plugin().Transformer)({
|
|
|
79
81
|
await (0, _babel.default)({
|
|
80
82
|
asset,
|
|
81
83
|
options,
|
|
84
|
+
logger,
|
|
82
85
|
babelOptions: config,
|
|
83
|
-
additionalPlugins: asset.meta.babelPlugins
|
|
86
|
+
additionalPlugins: asset.meta.babelPlugins,
|
|
87
|
+
tracer
|
|
84
88
|
});
|
|
85
89
|
} else {
|
|
86
90
|
await (0, _babel.default)({
|
|
87
91
|
asset,
|
|
88
92
|
options,
|
|
89
|
-
|
|
93
|
+
logger,
|
|
94
|
+
babelOptions: config,
|
|
95
|
+
tracer
|
|
90
96
|
});
|
|
91
97
|
}
|
|
92
98
|
}
|
package/lib/babel7.js
CHANGED
|
@@ -15,6 +15,26 @@ function _assert() {
|
|
|
15
15
|
return data;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
+
function _path() {
|
|
19
|
+
const data = _interopRequireDefault(require("path"));
|
|
20
|
+
|
|
21
|
+
_path = function () {
|
|
22
|
+
return data;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
return data;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function _diagnostic() {
|
|
29
|
+
const data = require("@parcel/diagnostic");
|
|
30
|
+
|
|
31
|
+
_diagnostic = function () {
|
|
32
|
+
return data;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
return data;
|
|
36
|
+
}
|
|
37
|
+
|
|
18
38
|
function _utils() {
|
|
19
39
|
const data = require("@parcel/utils");
|
|
20
40
|
|
|
@@ -41,7 +61,8 @@ async function babel7(opts) {
|
|
|
41
61
|
asset,
|
|
42
62
|
options,
|
|
43
63
|
babelOptions,
|
|
44
|
-
additionalPlugins = []
|
|
64
|
+
additionalPlugins = [],
|
|
65
|
+
tracer
|
|
45
66
|
} = opts;
|
|
46
67
|
const babelCore = await options.packageManager.require('@babel/core', asset.filePath, {
|
|
47
68
|
range: '^7.12.0',
|
|
@@ -71,6 +92,23 @@ async function babel7(opts) {
|
|
|
71
92
|
outputFormat: asset.env.outputFormat
|
|
72
93
|
}
|
|
73
94
|
};
|
|
95
|
+
|
|
96
|
+
if (tracer.enabled) {
|
|
97
|
+
config.wrapPluginVisitorMethod = (key, nodeType, fn) => {
|
|
98
|
+
return function () {
|
|
99
|
+
let pluginKey = key;
|
|
100
|
+
|
|
101
|
+
if (pluginKey.startsWith(options.projectRoot)) {
|
|
102
|
+
pluginKey = _path().default.relative(options.projectRoot, pluginKey);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const measurement = tracer.createMeasurement(pluginKey, nodeType, _path().default.relative(options.projectRoot, asset.filePath));
|
|
106
|
+
fn.apply(this, arguments);
|
|
107
|
+
measurement && measurement.end();
|
|
108
|
+
};
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
|
|
74
112
|
let ast = await asset.getAST();
|
|
75
113
|
let res;
|
|
76
114
|
|
|
@@ -86,6 +124,25 @@ async function babel7(opts) {
|
|
|
86
124
|
(0, _remapAstLocations.remapAstLocations)(babelCore.types, res.ast, map);
|
|
87
125
|
}
|
|
88
126
|
}
|
|
127
|
+
|
|
128
|
+
if (res.externalDependencies) {
|
|
129
|
+
for (let f of res.externalDependencies) {
|
|
130
|
+
if (!_path().default.isAbsolute(f)) {
|
|
131
|
+
opts.logger.warn({
|
|
132
|
+
message: (0, _diagnostic().md)`Ignoring non-absolute Babel external dependency: ${f}`,
|
|
133
|
+
hints: ['Please report this to the corresponding Babel plugin and/or to Parcel.']
|
|
134
|
+
});
|
|
135
|
+
} else {
|
|
136
|
+
if (await options.inputFS.exists(f)) {
|
|
137
|
+
asset.invalidateOnFileChange(f);
|
|
138
|
+
} else {
|
|
139
|
+
asset.invalidateOnFileCreate({
|
|
140
|
+
filePath: f
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
89
146
|
}
|
|
90
147
|
|
|
91
148
|
if (res.ast) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@parcel/transformer-babel",
|
|
3
|
-
"version": "2.8.
|
|
3
|
+
"version": "2.8.4-nightly.0+7b79c6d",
|
|
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": "
|
|
20
|
+
"parcel": "2.8.4-nightly.0+7b79c6d"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@parcel/diagnostic": "2.8.
|
|
24
|
-
"@parcel/plugin": "2.8.
|
|
23
|
+
"@parcel/diagnostic": "2.8.4-nightly.0+7b79c6d",
|
|
24
|
+
"@parcel/plugin": "2.8.4-nightly.0+7b79c6d",
|
|
25
25
|
"@parcel/source-map": "^2.1.1",
|
|
26
|
-
"@parcel/utils": "2.8.
|
|
26
|
+
"@parcel/utils": "2.8.4-nightly.0+7b79c6d",
|
|
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.8.
|
|
36
|
+
"@parcel/types": "2.8.4-nightly.0+7b79c6d"
|
|
37
37
|
},
|
|
38
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "7b79c6d69ffabef89810a8db61e9abdeb70d6990"
|
|
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) {
|