fix(transform): allow import attributes always (#33527)

This commit is contained in:
Max Schmitt 2024-11-11 10:26:13 +01:00 committed by GitHub
parent 503f74da90
commit d5ebe285c1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 2 deletions

View File

@ -27,7 +27,9 @@ import traverseFunction from '@babel/traverse';
export const traverse = traverseFunction;
function babelTransformOptions(isTypeScript: boolean, isModule: boolean, pluginsPrologue: [string, any?][], pluginsEpilogue: [string, any?][]): TransformOptions {
const plugins = [];
const plugins = [
[require('@babel/plugin-syntax-import-attributes'), { deprecatedAssertSyntax: true }],
];
if (isTypeScript) {
plugins.push(
@ -45,7 +47,6 @@ function babelTransformOptions(isTypeScript: boolean, isModule: boolean, plugins
[require('@babel/plugin-syntax-async-generators')],
[require('@babel/plugin-syntax-object-rest-spread')],
[require('@babel/plugin-transform-export-namespace-from')],
[require('@babel/plugin-syntax-import-attributes'), { deprecatedAssertSyntax: true }],
[
// From https://github.com/G-Rath/babel-plugin-replace-ts-export-assignment/blob/8dfdca32c8aa428574b0cae341444fc5822f2dc6/src/index.ts
(

View File

@ -45,9 +45,15 @@ test('should support import attributes', async ({ runInlineTest }) => {
'package.json': JSON.stringify({ type: 'module', foo: 'bar' }),
'a.test.ts': `
import config from './package.json' with { type: 'json' };
import configFooFromUtils from './utils.js'
console.log('imported value (test): ' + config.foo);
import { test, expect } from '@playwright/test';
expect(configFooFromUtils.foo).toBe('bar');
test('pass', async () => {});
`,
'utils.js': `
import config from './package.json' with { type: 'json' };
export default config;
`
});
expect(result.exitCode).toBe(0);