Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/babel/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"peerDependencies": {
"@babel/core": "^7.0.0",
"@types/babel__core": "^7.1.9",
"rollup": "^2.0.0||^3.0.0||^4.0.0"
"rollup": "^2.78.0||^3.0.0||^4.0.0||^5.0.0"
},
"peerDependenciesMeta": {
"rollup": {
Expand All @@ -80,7 +80,7 @@
"@rollup/plugin-json": "^5.0.0",
"@rollup/plugin-node-resolve": "^15.0.0",
"@types/babel__core": "^7.1.9",
"rollup": "^4.0.0-24",
"rollup": "catalog:rollup-next",
"source-map": "^0.7.4"
},
"types": "./types/index.d.ts",
Expand Down
31 changes: 25 additions & 6 deletions packages/babel/test/as-input-plugin.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as fs from 'node:fs';
import { fileURLToPath } from 'url';

import { test, expect } from 'vitest';
import { rollup } from 'rollup';
import { rollup, VERSION } from 'rollup';
import jsonPlugin from '@rollup/plugin-json';
import nodeResolvePlugin from '@rollup/plugin-node-resolve';
import { createFilter } from '@rollup/pluginutils';
Expand All @@ -13,8 +13,13 @@ import babelPlugin, { getBabelOutputPlugin, createBabelInputPluginFactory } from

import { getCode } from '../../../util/test.js';

const [rollupMajor] = VERSION.split('.').map(Number);
const DIRNAME = fileURLToPath(new URL('.', import.meta.url));
const FIXTURES = `${DIRNAME}/fixtures/`;
const getUnresolvedImportWarning = (source, importer) =>
rollupMajor < 3
? `'${source}' is imported by ${importer}, but could not be resolved – treating it as an external dependency`
: `"${source}" is imported by "${importer}", but could not be resolved – treating it as an external dependency.`;
function getLocation(source, charIndex) {
const lines = source.split('\n');
const len = lines.length;
Expand Down Expand Up @@ -250,16 +255,24 @@ test('allows transform-runtime to be used instead of bundled helpers', async ()
{
babelHelpers: 'runtime'
},
{},
{
interop: 'default'
},
{
onwarn(warning) {
warnings.push(warning.message);
}
}
);
expect(warnings).toEqual([
`"@babel/runtime/helpers/createClass" is imported by "test/fixtures/runtime-helpers/main.js", but could not be resolved – treating it as an external dependency.`,
`"@babel/runtime/helpers/classCallCheck" is imported by "test/fixtures/runtime-helpers/main.js", but could not be resolved – treating it as an external dependency.`
getUnresolvedImportWarning(
'@babel/runtime/helpers/createClass',
'test/fixtures/runtime-helpers/main.js'
),
getUnresolvedImportWarning(
'@babel/runtime/helpers/classCallCheck',
'test/fixtures/runtime-helpers/main.js'
)
]);
expect(code).toBe(`'use strict';

Expand Down Expand Up @@ -290,8 +303,14 @@ test('allows transform-runtime to inject esm version of helpers', async () => {
}
);
expect(warnings).toEqual([
`"@babel/runtime/helpers/esm/createClass" is imported by "test/fixtures/runtime-helpers-esm/main.js", but could not be resolved – treating it as an external dependency.`,
`"@babel/runtime/helpers/esm/classCallCheck" is imported by "test/fixtures/runtime-helpers-esm/main.js", but could not be resolved – treating it as an external dependency.`
getUnresolvedImportWarning(
'@babel/runtime/helpers/esm/createClass',
'test/fixtures/runtime-helpers-esm/main.js'
),
getUnresolvedImportWarning(
'@babel/runtime/helpers/esm/classCallCheck',
'test/fixtures/runtime-helpers-esm/main.js'
)
]);
expect(code).toBe(`import _createClass from '@babel/runtime/helpers/esm/createClass';
import _classCallCheck from '@babel/runtime/helpers/esm/classCallCheck';
Expand Down
18 changes: 15 additions & 3 deletions packages/babel/test/as-output-plugin.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ import * as nodePath from 'path';
import { fileURLToPath } from 'url';

import { test, expect } from 'vitest';
import { rollup } from 'rollup';
import { rollup, VERSION } from 'rollup';

import { getBabelOutputPlugin, createBabelOutputPluginFactory } from 'current-package';

import { getCode } from '../../../util/test.js';

const [rollupMajor, rollupMinor] = VERSION.split('.').map(Number);
// rollup 4.13.0 augments plugin warnings and errors with a "[plugin <name>]" message prefix
const hasAugmentedPluginLogs = rollupMajor > 4 || (rollupMajor === 4 && rollupMinor >= 13);
const DIRNAME = fileURLToPath(new URL('.', import.meta.url));
const FIXTURES = `${DIRNAME}/fixtures/`;
function getLocation(source, charIndex) {
Expand Down Expand Up @@ -192,7 +195,9 @@ test('warns when using the "include" option', async () => {
}
);
expect(warnings).toEqual([
'The "include", "exclude" and "extensions" options are ignored when transforming the output.'
`${
hasAugmentedPluginLogs ? '[plugin babel] ' : ''
}The "include", "exclude" and "extensions" options are ignored when transforming the output.`
]);
});
test('transforms all chunks in a code-splitting setup', async () => {
Expand All @@ -212,8 +217,15 @@ test('transforms all chunks in a code-splitting setup', async () => {
},
true
);
// the content hash algorithm changed in rollup 4.10.0
const depFileName =
rollupMajor < 3
? 'dep-805038a5.js'
: rollupMajor > 4 || (rollupMajor === 4 && rollupMinor >= 10)
? 'dep-D_rFPbwT.js'
: 'dep--s88I99N.js';
expect(output.map(({ code }) => code)).toEqual([
`import('./dep--s88I99N.js').then(function (result) {
`import('./${depFileName}').then(function (result) {
return console.log(result);
});
`,
Expand Down
Loading
Loading