@rollup/plugin-babel 6.0.0 → 6.0.1
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/dist/cjs/index.js +19 -61
- package/dist/es/index.js +19 -61
- package/package.json +5 -5
package/dist/cjs/index.js
CHANGED
|
@@ -28,9 +28,10 @@ var babel__namespace = /*#__PURE__*/_interopNamespaceDefault(babel);
|
|
|
28
28
|
const BUNDLED = 'bundled';
|
|
29
29
|
const INLINE = 'inline';
|
|
30
30
|
const RUNTIME = 'runtime';
|
|
31
|
-
const EXTERNAL = 'external';
|
|
32
|
-
// e.g. https://github.com/rollup/rollup-plugin-node-resolve/blob/313a3e32f432f9eb18cc4c231cc7aac6df317a51/src/index.js#L74
|
|
31
|
+
const EXTERNAL = 'external';
|
|
33
32
|
|
|
33
|
+
// NOTE: DO NOT REMOVE the null character `\0` as it may be used by other plugins
|
|
34
|
+
// e.g. https://github.com/rollup/rollup-plugin-node-resolve/blob/313a3e32f432f9eb18cc4c231cc7aac6df317a51/src/index.js#L74
|
|
34
35
|
const HELPERS = '\0rollupPluginBabelHelpers.js';
|
|
35
36
|
|
|
36
37
|
function importHelperPlugin({
|
|
@@ -43,20 +44,18 @@ function importHelperPlugin({
|
|
|
43
44
|
if (!file.availableHelper(name)) {
|
|
44
45
|
return null;
|
|
45
46
|
}
|
|
46
|
-
|
|
47
47
|
if (cachedHelpers[name]) {
|
|
48
48
|
return t.cloneNode(cachedHelpers[name]);
|
|
49
49
|
}
|
|
50
|
-
|
|
51
50
|
return cachedHelpers[name] = helperModuleImports.addNamed(file.path, name, HELPERS);
|
|
52
51
|
});
|
|
53
52
|
}
|
|
54
|
-
|
|
55
53
|
};
|
|
56
54
|
}
|
|
57
55
|
|
|
58
56
|
const addBabelPlugin = (options, plugin) => {
|
|
59
|
-
return {
|
|
57
|
+
return {
|
|
58
|
+
...options,
|
|
60
59
|
plugins: options.plugins.concat(plugin)
|
|
61
60
|
};
|
|
62
61
|
};
|
|
@@ -83,7 +82,6 @@ const MODULE_ERROR = 'Rollup requires that your Babel configuration keeps ES6 mo
|
|
|
83
82
|
const UNEXPECTED_ERROR = 'An unexpected situation arose. Please raise an issue at ' + 'https://github.com/rollup/plugins/issues. Thanks!';
|
|
84
83
|
const PREFLIGHT_TEST_STRING = '__ROLLUP__PREFLIGHT_CHECK_DO_NOT_TOUCH__';
|
|
85
84
|
const PREFLIGHT_INPUT = `export default "${PREFLIGHT_TEST_STRING}";`;
|
|
86
|
-
|
|
87
85
|
function helpersTestTransform() {
|
|
88
86
|
return {
|
|
89
87
|
visitor: {
|
|
@@ -92,72 +90,62 @@ function helpersTestTransform() {
|
|
|
92
90
|
path.replaceWith(state.file.addHelper('inherits'));
|
|
93
91
|
}
|
|
94
92
|
}
|
|
95
|
-
|
|
96
93
|
}
|
|
97
94
|
};
|
|
98
95
|
}
|
|
96
|
+
const mismatchError = (actual, expected, filename) => `You have declared using "${expected}" babelHelpers, but transforming ${filename} resulted in "${actual}". Please check your configuration.`;
|
|
99
97
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
98
|
+
// Revert to /\/helpers\/(esm\/)?inherits/ when Babel 8 gets released, this was fixed in https://github.com/babel/babel/issues/14185
|
|
103
99
|
const inheritsHelperRe = /[\\/]+helpers[\\/]+(esm[\\/]+)?inherits/;
|
|
104
100
|
async function preflightCheck(ctx, babelHelpers, transformOptions) {
|
|
105
101
|
const finalOptions = addBabelPlugin(transformOptions, helpersTestTransform);
|
|
106
|
-
const check = (await babel__namespace.transformAsync(PREFLIGHT_INPUT, finalOptions)).code;
|
|
102
|
+
const check = (await babel__namespace.transformAsync(PREFLIGHT_INPUT, finalOptions)).code;
|
|
107
103
|
|
|
104
|
+
// Babel sometimes splits ExportDefaultDeclaration into 2 statements, so we also check for ExportNamedDeclaration
|
|
108
105
|
if (!/export (d|{)/.test(check)) {
|
|
109
106
|
ctx.error(MODULE_ERROR);
|
|
110
107
|
}
|
|
111
|
-
|
|
112
108
|
if (inheritsHelperRe.test(check)) {
|
|
113
109
|
if (babelHelpers === RUNTIME) {
|
|
114
110
|
return;
|
|
115
111
|
}
|
|
116
|
-
|
|
117
112
|
ctx.error(mismatchError(RUNTIME, babelHelpers, transformOptions.filename));
|
|
118
113
|
}
|
|
119
|
-
|
|
120
114
|
if (check.includes('babelHelpers.inherits')) {
|
|
121
115
|
if (babelHelpers === EXTERNAL) {
|
|
122
116
|
return;
|
|
123
117
|
}
|
|
124
|
-
|
|
125
118
|
ctx.error(mismatchError(EXTERNAL, babelHelpers, transformOptions.filename));
|
|
126
|
-
}
|
|
127
|
-
|
|
119
|
+
}
|
|
128
120
|
|
|
121
|
+
// test unminifiable string content
|
|
129
122
|
if (check.includes('Super expression must either be null or a function')) {
|
|
130
123
|
if (babelHelpers === INLINE || babelHelpers === BUNDLED) {
|
|
131
124
|
return;
|
|
132
125
|
}
|
|
133
|
-
|
|
134
126
|
if (babelHelpers === RUNTIME && !transformOptions.plugins.length) {
|
|
135
127
|
ctx.error(`You must use the \`@babel/plugin-transform-runtime\` plugin when \`babelHelpers\` is "${RUNTIME}".\n`);
|
|
136
128
|
}
|
|
137
|
-
|
|
138
129
|
ctx.error(mismatchError(INLINE, babelHelpers, transformOptions.filename));
|
|
139
130
|
}
|
|
140
|
-
|
|
141
131
|
ctx.error(UNEXPECTED_ERROR);
|
|
142
132
|
}
|
|
143
133
|
|
|
144
134
|
async function transformCode(inputCode, babelOptions, overrides, customOptions, ctx, finalizeOptions) {
|
|
145
135
|
// loadPartialConfigAsync has become available in @babel/core@7.8.0
|
|
146
|
-
const config = await (babel__namespace.loadPartialConfigAsync || babel__namespace.loadPartialConfig)(babelOptions);
|
|
136
|
+
const config = await (babel__namespace.loadPartialConfigAsync || babel__namespace.loadPartialConfig)(babelOptions);
|
|
147
137
|
|
|
138
|
+
// file is ignored by babel
|
|
148
139
|
if (!config) {
|
|
149
140
|
return null;
|
|
150
141
|
}
|
|
151
|
-
|
|
152
142
|
let transformOptions = !overrides.config ? config.options : await overrides.config.call(ctx, config, {
|
|
153
143
|
code: inputCode,
|
|
154
144
|
customOptions
|
|
155
145
|
});
|
|
156
|
-
|
|
157
146
|
if (finalizeOptions) {
|
|
158
147
|
transformOptions = await finalizeOptions(transformOptions);
|
|
159
148
|
}
|
|
160
|
-
|
|
161
149
|
if (!overrides.result) {
|
|
162
150
|
const {
|
|
163
151
|
code,
|
|
@@ -168,7 +156,6 @@ async function transformCode(inputCode, babelOptions, overrides, customOptions,
|
|
|
168
156
|
map
|
|
169
157
|
};
|
|
170
158
|
}
|
|
171
|
-
|
|
172
159
|
const result = await babel__namespace.transformAsync(inputCode, transformOptions);
|
|
173
160
|
const {
|
|
174
161
|
code,
|
|
@@ -206,7 +193,6 @@ const unpackOptions = ({
|
|
|
206
193
|
}
|
|
207
194
|
};
|
|
208
195
|
};
|
|
209
|
-
|
|
210
196
|
const warnAboutDeprecatedHelpersOption = ({
|
|
211
197
|
deprecatedOption,
|
|
212
198
|
suggestion
|
|
@@ -214,7 +200,6 @@ const warnAboutDeprecatedHelpersOption = ({
|
|
|
214
200
|
// eslint-disable-next-line no-console
|
|
215
201
|
console.warn(`\`${deprecatedOption}\` has been removed in favor a \`babelHelpers\` option. Try changing your configuration to \`${suggestion}\`. ` + `Refer to the documentation to learn more: https://github.com/rollup/plugins/tree/master/packages/babel#babelhelpers`);
|
|
216
202
|
};
|
|
217
|
-
|
|
218
203
|
const unpackInputPluginOptions = ({
|
|
219
204
|
skipPreflightCheck = false,
|
|
220
205
|
...rest
|
|
@@ -233,8 +218,8 @@ const unpackInputPluginOptions = ({
|
|
|
233
218
|
// eslint-disable-next-line no-console
|
|
234
219
|
console.warn("babelHelpers: 'bundled' option was used by default. It is recommended to configure this option explicitly, read more here: " + 'https://github.com/rollup/plugins/tree/master/packages/babel#babelhelpers');
|
|
235
220
|
}
|
|
236
|
-
|
|
237
|
-
|
|
221
|
+
return unpackOptions({
|
|
222
|
+
...rest,
|
|
238
223
|
skipPreflightCheck,
|
|
239
224
|
babelHelpers: rest.babelHelpers || BUNDLED,
|
|
240
225
|
caller: {
|
|
@@ -247,7 +232,6 @@ const unpackInputPluginOptions = ({
|
|
|
247
232
|
}
|
|
248
233
|
});
|
|
249
234
|
};
|
|
250
|
-
|
|
251
235
|
const unpackOutputPluginOptions = (options, {
|
|
252
236
|
format
|
|
253
237
|
}) => unpackOptions({
|
|
@@ -259,28 +243,23 @@ const unpackOutputPluginOptions = (options, {
|
|
|
259
243
|
...options.caller
|
|
260
244
|
}
|
|
261
245
|
});
|
|
262
|
-
|
|
263
246
|
function getOptionsWithOverrides(pluginOptions = {}, overrides = {}) {
|
|
264
247
|
if (!overrides.options) return {
|
|
265
248
|
customOptions: null,
|
|
266
249
|
pluginOptionsWithOverrides: pluginOptions
|
|
267
250
|
};
|
|
268
251
|
const overridden = overrides.options(pluginOptions);
|
|
269
|
-
|
|
270
252
|
if (typeof overridden.then === 'function') {
|
|
271
253
|
throw new Error(".options hook can't be asynchronous. It should return `{ customOptions, pluginsOptions }` synchronously.");
|
|
272
254
|
}
|
|
273
|
-
|
|
274
255
|
return {
|
|
275
256
|
customOptions: overridden.customOptions || null,
|
|
276
257
|
pluginOptionsWithOverrides: overridden.pluginOptions || pluginOptions
|
|
277
258
|
};
|
|
278
259
|
}
|
|
279
|
-
|
|
280
260
|
const returnObject = () => {
|
|
281
261
|
return {};
|
|
282
262
|
};
|
|
283
|
-
|
|
284
263
|
function createBabelInputPluginFactory(customCallback = returnObject) {
|
|
285
264
|
const overrides = customCallback(babel__namespace);
|
|
286
265
|
return pluginOptions => {
|
|
@@ -294,7 +273,6 @@ function createBabelInputPluginFactory(customCallback = returnObject) {
|
|
|
294
273
|
let skipPreflightCheck;
|
|
295
274
|
return {
|
|
296
275
|
name: 'babel',
|
|
297
|
-
|
|
298
276
|
options() {
|
|
299
277
|
// todo: remove options hook and hoist declarations when version checks are removed
|
|
300
278
|
let exclude;
|
|
@@ -311,69 +289,54 @@ function createBabelInputPluginFactory(customCallback = returnObject) {
|
|
|
311
289
|
...babelOptions
|
|
312
290
|
} = unpackInputPluginOptions(pluginOptionsWithOverrides, this.meta.rollupVersion));
|
|
313
291
|
const extensionRegExp = new RegExp(`(${extensions.map(escapeRegExpCharacters).join('|')})$`);
|
|
314
|
-
|
|
315
292
|
if (customFilter && (include || exclude)) {
|
|
316
293
|
throw new Error('Could not handle include or exclude with custom filter together');
|
|
317
294
|
}
|
|
318
|
-
|
|
319
295
|
const userDefinedFilter = typeof customFilter === 'function' ? customFilter : pluginutils.createFilter(include, exclude);
|
|
320
|
-
|
|
321
296
|
filter = id => extensionRegExp.test(stripQuery(id).bareId) && userDefinedFilter(id);
|
|
322
|
-
|
|
323
297
|
return null;
|
|
324
298
|
},
|
|
325
|
-
|
|
326
299
|
resolveId(id) {
|
|
327
300
|
if (id !== HELPERS) {
|
|
328
301
|
return null;
|
|
329
302
|
}
|
|
330
|
-
|
|
331
303
|
return id;
|
|
332
304
|
},
|
|
333
|
-
|
|
334
305
|
load(id) {
|
|
335
306
|
if (id !== HELPERS) {
|
|
336
307
|
return null;
|
|
337
308
|
}
|
|
338
|
-
|
|
339
309
|
return babel__namespace.buildExternalHelpers(null, 'module');
|
|
340
310
|
},
|
|
341
|
-
|
|
342
311
|
transform(code, filename) {
|
|
343
312
|
if (!filter(filename)) return null;
|
|
344
313
|
if (filename === HELPERS) return null;
|
|
345
|
-
return transformCode(code, {
|
|
314
|
+
return transformCode(code, {
|
|
315
|
+
...babelOptions,
|
|
346
316
|
filename
|
|
347
317
|
}, overrides, customOptions, this, async transformOptions => {
|
|
348
318
|
if (!skipPreflightCheck) {
|
|
349
319
|
await preflightCheck(this, babelHelpers, transformOptions);
|
|
350
320
|
}
|
|
351
|
-
|
|
352
321
|
return babelHelpers === BUNDLED ? addBabelPlugin(transformOptions, importHelperPlugin) : transformOptions;
|
|
353
322
|
});
|
|
354
323
|
}
|
|
355
|
-
|
|
356
324
|
};
|
|
357
325
|
};
|
|
358
326
|
}
|
|
359
|
-
|
|
360
327
|
function getRecommendedFormat(rollupFormat) {
|
|
361
328
|
switch (rollupFormat) {
|
|
362
329
|
case 'amd':
|
|
363
330
|
return 'amd';
|
|
364
|
-
|
|
365
331
|
case 'iife':
|
|
366
332
|
case 'umd':
|
|
367
333
|
return 'umd';
|
|
368
|
-
|
|
369
334
|
case 'system':
|
|
370
335
|
return 'systemjs';
|
|
371
|
-
|
|
372
336
|
default:
|
|
373
337
|
return '<module format>';
|
|
374
338
|
}
|
|
375
339
|
}
|
|
376
|
-
|
|
377
340
|
function createBabelOutputPluginFactory(customCallback = returnObject) {
|
|
378
341
|
const overrides = customCallback(babel__namespace);
|
|
379
342
|
return pluginOptions => {
|
|
@@ -383,7 +346,6 @@ function createBabelOutputPluginFactory(customCallback = returnObject) {
|
|
|
383
346
|
} = getOptionsWithOverrides(pluginOptions, overrides);
|
|
384
347
|
return {
|
|
385
348
|
name: 'babel',
|
|
386
|
-
|
|
387
349
|
renderStart(outputOptions) {
|
|
388
350
|
const {
|
|
389
351
|
extensions,
|
|
@@ -391,16 +353,13 @@ function createBabelOutputPluginFactory(customCallback = returnObject) {
|
|
|
391
353
|
exclude,
|
|
392
354
|
allowAllFormats
|
|
393
355
|
} = pluginOptionsWithOverrides;
|
|
394
|
-
|
|
395
356
|
if (extensions || include || exclude) {
|
|
396
357
|
warnOnce(this, 'The "include", "exclude" and "extensions" options are ignored when transforming the output.');
|
|
397
358
|
}
|
|
398
|
-
|
|
399
359
|
if (!allowAllFormats && outputOptions.format !== 'es' && outputOptions.format !== 'cjs') {
|
|
400
360
|
this.error(`Using Babel on the generated chunks is strongly discouraged for formats other than "esm" or "cjs" as it can easily break wrapper code and lead to accidentally created global variables. Instead, you should set "output.format" to "esm" and use Babel to transform to another format, e.g. by adding "presets: [['@babel/env', { modules: '${getRecommendedFormat(outputOptions.format)}' }]]" to your Babel options. If you still want to proceed, add "allowAllFormats: true" to your plugin options.`);
|
|
401
361
|
}
|
|
402
362
|
},
|
|
403
|
-
|
|
404
363
|
renderChunk(code, chunk, outputOptions) {
|
|
405
364
|
/* eslint-disable no-unused-vars */
|
|
406
365
|
const {
|
|
@@ -417,12 +376,11 @@ function createBabelOutputPluginFactory(customCallback = returnObject) {
|
|
|
417
376
|
|
|
418
377
|
return transformCode(code, babelOptions, overrides, customOptions, this);
|
|
419
378
|
}
|
|
420
|
-
|
|
421
379
|
};
|
|
422
380
|
};
|
|
423
|
-
}
|
|
424
|
-
|
|
381
|
+
}
|
|
425
382
|
|
|
383
|
+
// export this for symmetry with output-related exports
|
|
426
384
|
const getBabelInputPlugin = createBabelInputPluginFactory();
|
|
427
385
|
const getBabelOutputPlugin = createBabelOutputPluginFactory();
|
|
428
386
|
|
package/dist/es/index.js
CHANGED
|
@@ -5,9 +5,10 @@ import { addNamed } from '@babel/helper-module-imports';
|
|
|
5
5
|
const BUNDLED = 'bundled';
|
|
6
6
|
const INLINE = 'inline';
|
|
7
7
|
const RUNTIME = 'runtime';
|
|
8
|
-
const EXTERNAL = 'external';
|
|
9
|
-
// e.g. https://github.com/rollup/rollup-plugin-node-resolve/blob/313a3e32f432f9eb18cc4c231cc7aac6df317a51/src/index.js#L74
|
|
8
|
+
const EXTERNAL = 'external';
|
|
10
9
|
|
|
10
|
+
// NOTE: DO NOT REMOVE the null character `\0` as it may be used by other plugins
|
|
11
|
+
// e.g. https://github.com/rollup/rollup-plugin-node-resolve/blob/313a3e32f432f9eb18cc4c231cc7aac6df317a51/src/index.js#L74
|
|
11
12
|
const HELPERS = '\0rollupPluginBabelHelpers.js';
|
|
12
13
|
|
|
13
14
|
function importHelperPlugin({
|
|
@@ -20,20 +21,18 @@ function importHelperPlugin({
|
|
|
20
21
|
if (!file.availableHelper(name)) {
|
|
21
22
|
return null;
|
|
22
23
|
}
|
|
23
|
-
|
|
24
24
|
if (cachedHelpers[name]) {
|
|
25
25
|
return t.cloneNode(cachedHelpers[name]);
|
|
26
26
|
}
|
|
27
|
-
|
|
28
27
|
return cachedHelpers[name] = addNamed(file.path, name, HELPERS);
|
|
29
28
|
});
|
|
30
29
|
}
|
|
31
|
-
|
|
32
30
|
};
|
|
33
31
|
}
|
|
34
32
|
|
|
35
33
|
const addBabelPlugin = (options, plugin) => {
|
|
36
|
-
return {
|
|
34
|
+
return {
|
|
35
|
+
...options,
|
|
37
36
|
plugins: options.plugins.concat(plugin)
|
|
38
37
|
};
|
|
39
38
|
};
|
|
@@ -60,7 +59,6 @@ const MODULE_ERROR = 'Rollup requires that your Babel configuration keeps ES6 mo
|
|
|
60
59
|
const UNEXPECTED_ERROR = 'An unexpected situation arose. Please raise an issue at ' + 'https://github.com/rollup/plugins/issues. Thanks!';
|
|
61
60
|
const PREFLIGHT_TEST_STRING = '__ROLLUP__PREFLIGHT_CHECK_DO_NOT_TOUCH__';
|
|
62
61
|
const PREFLIGHT_INPUT = `export default "${PREFLIGHT_TEST_STRING}";`;
|
|
63
|
-
|
|
64
62
|
function helpersTestTransform() {
|
|
65
63
|
return {
|
|
66
64
|
visitor: {
|
|
@@ -69,72 +67,62 @@ function helpersTestTransform() {
|
|
|
69
67
|
path.replaceWith(state.file.addHelper('inherits'));
|
|
70
68
|
}
|
|
71
69
|
}
|
|
72
|
-
|
|
73
70
|
}
|
|
74
71
|
};
|
|
75
72
|
}
|
|
73
|
+
const mismatchError = (actual, expected, filename) => `You have declared using "${expected}" babelHelpers, but transforming ${filename} resulted in "${actual}". Please check your configuration.`;
|
|
76
74
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
75
|
+
// Revert to /\/helpers\/(esm\/)?inherits/ when Babel 8 gets released, this was fixed in https://github.com/babel/babel/issues/14185
|
|
80
76
|
const inheritsHelperRe = /[\\/]+helpers[\\/]+(esm[\\/]+)?inherits/;
|
|
81
77
|
async function preflightCheck(ctx, babelHelpers, transformOptions) {
|
|
82
78
|
const finalOptions = addBabelPlugin(transformOptions, helpersTestTransform);
|
|
83
|
-
const check = (await babel.transformAsync(PREFLIGHT_INPUT, finalOptions)).code;
|
|
79
|
+
const check = (await babel.transformAsync(PREFLIGHT_INPUT, finalOptions)).code;
|
|
84
80
|
|
|
81
|
+
// Babel sometimes splits ExportDefaultDeclaration into 2 statements, so we also check for ExportNamedDeclaration
|
|
85
82
|
if (!/export (d|{)/.test(check)) {
|
|
86
83
|
ctx.error(MODULE_ERROR);
|
|
87
84
|
}
|
|
88
|
-
|
|
89
85
|
if (inheritsHelperRe.test(check)) {
|
|
90
86
|
if (babelHelpers === RUNTIME) {
|
|
91
87
|
return;
|
|
92
88
|
}
|
|
93
|
-
|
|
94
89
|
ctx.error(mismatchError(RUNTIME, babelHelpers, transformOptions.filename));
|
|
95
90
|
}
|
|
96
|
-
|
|
97
91
|
if (check.includes('babelHelpers.inherits')) {
|
|
98
92
|
if (babelHelpers === EXTERNAL) {
|
|
99
93
|
return;
|
|
100
94
|
}
|
|
101
|
-
|
|
102
95
|
ctx.error(mismatchError(EXTERNAL, babelHelpers, transformOptions.filename));
|
|
103
|
-
}
|
|
104
|
-
|
|
96
|
+
}
|
|
105
97
|
|
|
98
|
+
// test unminifiable string content
|
|
106
99
|
if (check.includes('Super expression must either be null or a function')) {
|
|
107
100
|
if (babelHelpers === INLINE || babelHelpers === BUNDLED) {
|
|
108
101
|
return;
|
|
109
102
|
}
|
|
110
|
-
|
|
111
103
|
if (babelHelpers === RUNTIME && !transformOptions.plugins.length) {
|
|
112
104
|
ctx.error(`You must use the \`@babel/plugin-transform-runtime\` plugin when \`babelHelpers\` is "${RUNTIME}".\n`);
|
|
113
105
|
}
|
|
114
|
-
|
|
115
106
|
ctx.error(mismatchError(INLINE, babelHelpers, transformOptions.filename));
|
|
116
107
|
}
|
|
117
|
-
|
|
118
108
|
ctx.error(UNEXPECTED_ERROR);
|
|
119
109
|
}
|
|
120
110
|
|
|
121
111
|
async function transformCode(inputCode, babelOptions, overrides, customOptions, ctx, finalizeOptions) {
|
|
122
112
|
// loadPartialConfigAsync has become available in @babel/core@7.8.0
|
|
123
|
-
const config = await (babel.loadPartialConfigAsync || babel.loadPartialConfig)(babelOptions);
|
|
113
|
+
const config = await (babel.loadPartialConfigAsync || babel.loadPartialConfig)(babelOptions);
|
|
124
114
|
|
|
115
|
+
// file is ignored by babel
|
|
125
116
|
if (!config) {
|
|
126
117
|
return null;
|
|
127
118
|
}
|
|
128
|
-
|
|
129
119
|
let transformOptions = !overrides.config ? config.options : await overrides.config.call(ctx, config, {
|
|
130
120
|
code: inputCode,
|
|
131
121
|
customOptions
|
|
132
122
|
});
|
|
133
|
-
|
|
134
123
|
if (finalizeOptions) {
|
|
135
124
|
transformOptions = await finalizeOptions(transformOptions);
|
|
136
125
|
}
|
|
137
|
-
|
|
138
126
|
if (!overrides.result) {
|
|
139
127
|
const {
|
|
140
128
|
code,
|
|
@@ -145,7 +133,6 @@ async function transformCode(inputCode, babelOptions, overrides, customOptions,
|
|
|
145
133
|
map
|
|
146
134
|
};
|
|
147
135
|
}
|
|
148
|
-
|
|
149
136
|
const result = await babel.transformAsync(inputCode, transformOptions);
|
|
150
137
|
const {
|
|
151
138
|
code,
|
|
@@ -183,7 +170,6 @@ const unpackOptions = ({
|
|
|
183
170
|
}
|
|
184
171
|
};
|
|
185
172
|
};
|
|
186
|
-
|
|
187
173
|
const warnAboutDeprecatedHelpersOption = ({
|
|
188
174
|
deprecatedOption,
|
|
189
175
|
suggestion
|
|
@@ -191,7 +177,6 @@ const warnAboutDeprecatedHelpersOption = ({
|
|
|
191
177
|
// eslint-disable-next-line no-console
|
|
192
178
|
console.warn(`\`${deprecatedOption}\` has been removed in favor a \`babelHelpers\` option. Try changing your configuration to \`${suggestion}\`. ` + `Refer to the documentation to learn more: https://github.com/rollup/plugins/tree/master/packages/babel#babelhelpers`);
|
|
193
179
|
};
|
|
194
|
-
|
|
195
180
|
const unpackInputPluginOptions = ({
|
|
196
181
|
skipPreflightCheck = false,
|
|
197
182
|
...rest
|
|
@@ -210,8 +195,8 @@ const unpackInputPluginOptions = ({
|
|
|
210
195
|
// eslint-disable-next-line no-console
|
|
211
196
|
console.warn("babelHelpers: 'bundled' option was used by default. It is recommended to configure this option explicitly, read more here: " + 'https://github.com/rollup/plugins/tree/master/packages/babel#babelhelpers');
|
|
212
197
|
}
|
|
213
|
-
|
|
214
|
-
|
|
198
|
+
return unpackOptions({
|
|
199
|
+
...rest,
|
|
215
200
|
skipPreflightCheck,
|
|
216
201
|
babelHelpers: rest.babelHelpers || BUNDLED,
|
|
217
202
|
caller: {
|
|
@@ -224,7 +209,6 @@ const unpackInputPluginOptions = ({
|
|
|
224
209
|
}
|
|
225
210
|
});
|
|
226
211
|
};
|
|
227
|
-
|
|
228
212
|
const unpackOutputPluginOptions = (options, {
|
|
229
213
|
format
|
|
230
214
|
}) => unpackOptions({
|
|
@@ -236,28 +220,23 @@ const unpackOutputPluginOptions = (options, {
|
|
|
236
220
|
...options.caller
|
|
237
221
|
}
|
|
238
222
|
});
|
|
239
|
-
|
|
240
223
|
function getOptionsWithOverrides(pluginOptions = {}, overrides = {}) {
|
|
241
224
|
if (!overrides.options) return {
|
|
242
225
|
customOptions: null,
|
|
243
226
|
pluginOptionsWithOverrides: pluginOptions
|
|
244
227
|
};
|
|
245
228
|
const overridden = overrides.options(pluginOptions);
|
|
246
|
-
|
|
247
229
|
if (typeof overridden.then === 'function') {
|
|
248
230
|
throw new Error(".options hook can't be asynchronous. It should return `{ customOptions, pluginsOptions }` synchronously.");
|
|
249
231
|
}
|
|
250
|
-
|
|
251
232
|
return {
|
|
252
233
|
customOptions: overridden.customOptions || null,
|
|
253
234
|
pluginOptionsWithOverrides: overridden.pluginOptions || pluginOptions
|
|
254
235
|
};
|
|
255
236
|
}
|
|
256
|
-
|
|
257
237
|
const returnObject = () => {
|
|
258
238
|
return {};
|
|
259
239
|
};
|
|
260
|
-
|
|
261
240
|
function createBabelInputPluginFactory(customCallback = returnObject) {
|
|
262
241
|
const overrides = customCallback(babel);
|
|
263
242
|
return pluginOptions => {
|
|
@@ -271,7 +250,6 @@ function createBabelInputPluginFactory(customCallback = returnObject) {
|
|
|
271
250
|
let skipPreflightCheck;
|
|
272
251
|
return {
|
|
273
252
|
name: 'babel',
|
|
274
|
-
|
|
275
253
|
options() {
|
|
276
254
|
// todo: remove options hook and hoist declarations when version checks are removed
|
|
277
255
|
let exclude;
|
|
@@ -288,69 +266,54 @@ function createBabelInputPluginFactory(customCallback = returnObject) {
|
|
|
288
266
|
...babelOptions
|
|
289
267
|
} = unpackInputPluginOptions(pluginOptionsWithOverrides, this.meta.rollupVersion));
|
|
290
268
|
const extensionRegExp = new RegExp(`(${extensions.map(escapeRegExpCharacters).join('|')})$`);
|
|
291
|
-
|
|
292
269
|
if (customFilter && (include || exclude)) {
|
|
293
270
|
throw new Error('Could not handle include or exclude with custom filter together');
|
|
294
271
|
}
|
|
295
|
-
|
|
296
272
|
const userDefinedFilter = typeof customFilter === 'function' ? customFilter : createFilter(include, exclude);
|
|
297
|
-
|
|
298
273
|
filter = id => extensionRegExp.test(stripQuery(id).bareId) && userDefinedFilter(id);
|
|
299
|
-
|
|
300
274
|
return null;
|
|
301
275
|
},
|
|
302
|
-
|
|
303
276
|
resolveId(id) {
|
|
304
277
|
if (id !== HELPERS) {
|
|
305
278
|
return null;
|
|
306
279
|
}
|
|
307
|
-
|
|
308
280
|
return id;
|
|
309
281
|
},
|
|
310
|
-
|
|
311
282
|
load(id) {
|
|
312
283
|
if (id !== HELPERS) {
|
|
313
284
|
return null;
|
|
314
285
|
}
|
|
315
|
-
|
|
316
286
|
return babel.buildExternalHelpers(null, 'module');
|
|
317
287
|
},
|
|
318
|
-
|
|
319
288
|
transform(code, filename) {
|
|
320
289
|
if (!filter(filename)) return null;
|
|
321
290
|
if (filename === HELPERS) return null;
|
|
322
|
-
return transformCode(code, {
|
|
291
|
+
return transformCode(code, {
|
|
292
|
+
...babelOptions,
|
|
323
293
|
filename
|
|
324
294
|
}, overrides, customOptions, this, async transformOptions => {
|
|
325
295
|
if (!skipPreflightCheck) {
|
|
326
296
|
await preflightCheck(this, babelHelpers, transformOptions);
|
|
327
297
|
}
|
|
328
|
-
|
|
329
298
|
return babelHelpers === BUNDLED ? addBabelPlugin(transformOptions, importHelperPlugin) : transformOptions;
|
|
330
299
|
});
|
|
331
300
|
}
|
|
332
|
-
|
|
333
301
|
};
|
|
334
302
|
};
|
|
335
303
|
}
|
|
336
|
-
|
|
337
304
|
function getRecommendedFormat(rollupFormat) {
|
|
338
305
|
switch (rollupFormat) {
|
|
339
306
|
case 'amd':
|
|
340
307
|
return 'amd';
|
|
341
|
-
|
|
342
308
|
case 'iife':
|
|
343
309
|
case 'umd':
|
|
344
310
|
return 'umd';
|
|
345
|
-
|
|
346
311
|
case 'system':
|
|
347
312
|
return 'systemjs';
|
|
348
|
-
|
|
349
313
|
default:
|
|
350
314
|
return '<module format>';
|
|
351
315
|
}
|
|
352
316
|
}
|
|
353
|
-
|
|
354
317
|
function createBabelOutputPluginFactory(customCallback = returnObject) {
|
|
355
318
|
const overrides = customCallback(babel);
|
|
356
319
|
return pluginOptions => {
|
|
@@ -360,7 +323,6 @@ function createBabelOutputPluginFactory(customCallback = returnObject) {
|
|
|
360
323
|
} = getOptionsWithOverrides(pluginOptions, overrides);
|
|
361
324
|
return {
|
|
362
325
|
name: 'babel',
|
|
363
|
-
|
|
364
326
|
renderStart(outputOptions) {
|
|
365
327
|
const {
|
|
366
328
|
extensions,
|
|
@@ -368,16 +330,13 @@ function createBabelOutputPluginFactory(customCallback = returnObject) {
|
|
|
368
330
|
exclude,
|
|
369
331
|
allowAllFormats
|
|
370
332
|
} = pluginOptionsWithOverrides;
|
|
371
|
-
|
|
372
333
|
if (extensions || include || exclude) {
|
|
373
334
|
warnOnce(this, 'The "include", "exclude" and "extensions" options are ignored when transforming the output.');
|
|
374
335
|
}
|
|
375
|
-
|
|
376
336
|
if (!allowAllFormats && outputOptions.format !== 'es' && outputOptions.format !== 'cjs') {
|
|
377
337
|
this.error(`Using Babel on the generated chunks is strongly discouraged for formats other than "esm" or "cjs" as it can easily break wrapper code and lead to accidentally created global variables. Instead, you should set "output.format" to "esm" and use Babel to transform to another format, e.g. by adding "presets: [['@babel/env', { modules: '${getRecommendedFormat(outputOptions.format)}' }]]" to your Babel options. If you still want to proceed, add "allowAllFormats: true" to your plugin options.`);
|
|
378
338
|
}
|
|
379
339
|
},
|
|
380
|
-
|
|
381
340
|
renderChunk(code, chunk, outputOptions) {
|
|
382
341
|
/* eslint-disable no-unused-vars */
|
|
383
342
|
const {
|
|
@@ -394,12 +353,11 @@ function createBabelOutputPluginFactory(customCallback = returnObject) {
|
|
|
394
353
|
|
|
395
354
|
return transformCode(code, babelOptions, overrides, customOptions, this);
|
|
396
355
|
}
|
|
397
|
-
|
|
398
356
|
};
|
|
399
357
|
};
|
|
400
|
-
}
|
|
401
|
-
|
|
358
|
+
}
|
|
402
359
|
|
|
360
|
+
// export this for symmetry with output-related exports
|
|
403
361
|
const getBabelInputPlugin = createBabelInputPluginFactory();
|
|
404
362
|
const getBabelOutputPlugin = createBabelOutputPluginFactory();
|
|
405
363
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rollup/plugin-babel",
|
|
3
|
-
"version": "6.0.
|
|
3
|
+
"version": "6.0.1",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -66,7 +66,7 @@
|
|
|
66
66
|
},
|
|
67
67
|
"dependencies": {
|
|
68
68
|
"@babel/helper-module-imports": "^7.18.6",
|
|
69
|
-
"@rollup/pluginutils": "^
|
|
69
|
+
"@rollup/pluginutils": "^5.0.1"
|
|
70
70
|
},
|
|
71
71
|
"devDependencies": {
|
|
72
72
|
"@babel/core": "^7.19.1",
|
|
@@ -75,10 +75,10 @@
|
|
|
75
75
|
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
|
|
76
76
|
"@babel/plugin-transform-runtime": "^7.19.1",
|
|
77
77
|
"@babel/preset-env": "^7.19.1",
|
|
78
|
-
"@rollup/plugin-json": "^
|
|
79
|
-
"@rollup/plugin-node-resolve": "^
|
|
78
|
+
"@rollup/plugin-json": "^5.0.0",
|
|
79
|
+
"@rollup/plugin-node-resolve": "^15.0.0",
|
|
80
80
|
"@types/babel__core": "^7.1.9",
|
|
81
|
-
"rollup": "^3.
|
|
81
|
+
"rollup": "^3.2.3",
|
|
82
82
|
"source-map": "^0.7.4"
|
|
83
83
|
},
|
|
84
84
|
"types": "./types/index.d.ts",
|