Add tests for import with new (#20024)

This commit is contained in:
fisker Cheung authored and GitHub committed 2026-09-11 06:47:21 +08:00
1 parent f6ddf6e437
commit 2caef979dd
2 files changed
+360

No files matched your search

@@ -236,6 +236,360 @@ exports[`snippet: #3 format[yuku-ts] 1`] = `
| ^^^^^^"
`;
exports[`snippet: #4 format[babel] 1`] = `
"Cannot use new with import(). (1:5)
> 1 | new import("foo").bar;
| ^
Cause: Cannot use new with import(). (1:4)"
`;
exports[`snippet: #4 format[babel-ts] 1`] = `
"Cannot use new with import(). (1:5)
> 1 | new import("foo").bar;
| ^
Cause: Cannot use new with import(). (1:4)"
`;
exports[`snippet: #4 format[flow] 1`] = `
"Unexpected token \`import\` (1:5)
> 1 | new import("foo").bar;
| ^
Cause: Unexpected token \`import\` (1:4)"
`;
exports[`snippet: #4 format[meriyah] 1`] = `
"Cannot use new with import(...) (1:11)
> 1 | new import("foo").bar;
| ^
Cause: [1:10-1:11]: Cannot use new with import(...)"
`;
exports[`snippet: #4 format[oxc] 1`] = `
"Cannot use new with dynamic import (1:5)
> 1 | new import("foo").bar;
| ^^^^^^^^^^^^^^^^^"
`;
exports[`snippet: #4 format[oxc-ts] 1`] = `
"Cannot use new with dynamic import (1:5)
> 1 | new import("foo").bar;
| ^^^^^^^^^^^^^^^^^"
`;
exports[`snippet: #4 format[typescript] 1`] = `
"Expression expected. (1:5)
> 1 | new import("foo").bar;
| ^
Cause: Expression expected."
`;
exports[`snippet: #4 format[yuku] 1`] = `
"'import' is reserved and cannot be used as an identifier (1:5)
> 1 | new import("foo").bar;
| ^^^^^^"
`;
exports[`snippet: #4 format[yuku-ts] 1`] = `
"'import' is reserved and cannot be used as an identifier (1:5)
> 1 | new import("foo").bar;
| ^^^^^^"
`;
exports[`snippet: #5 format[babel] 1`] = `
"Cannot use new with import(). (1:5)
> 1 | new import("foo")[bar];
| ^
Cause: Cannot use new with import(). (1:4)"
`;
exports[`snippet: #5 format[babel-ts] 1`] = `
"Cannot use new with import(). (1:5)
> 1 | new import("foo")[bar];
| ^
Cause: Cannot use new with import(). (1:4)"
`;
exports[`snippet: #5 format[flow] 1`] = `
"Unexpected token \`import\` (1:5)
> 1 | new import("foo")[bar];
| ^
Cause: Unexpected token \`import\` (1:4)"
`;
exports[`snippet: #5 format[meriyah] 1`] = `
"Cannot use new with import(...) (1:11)
> 1 | new import("foo")[bar];
| ^
Cause: [1:10-1:11]: Cannot use new with import(...)"
`;
exports[`snippet: #5 format[oxc] 1`] = `
"Cannot use new with dynamic import (1:5)
> 1 | new import("foo")[bar];
| ^^^^^^^^^^^^^^^^^^"
`;
exports[`snippet: #5 format[oxc-ts] 1`] = `
"Cannot use new with dynamic import (1:5)
> 1 | new import("foo")[bar];
| ^^^^^^^^^^^^^^^^^^"
`;
exports[`snippet: #5 format[typescript] 1`] = `
"Expression expected. (1:5)
> 1 | new import("foo")[bar];
| ^
Cause: Expression expected."
`;
exports[`snippet: #5 format[yuku] 1`] = `
"'import' is reserved and cannot be used as an identifier (1:5)
> 1 | new import("foo")[bar];
| ^^^^^^"
`;
exports[`snippet: #5 format[yuku-ts] 1`] = `
"'import' is reserved and cannot be used as an identifier (1:5)
> 1 | new import("foo")[bar];
| ^^^^^^"
`;
exports[`snippet: #6 format[babel] 1`] = `
"Cannot use new with import(). (1:5)
> 1 | new import("foo")\`bar\`;
| ^
Cause: Cannot use new with import(). (1:4)"
`;
exports[`snippet: #6 format[babel-ts] 1`] = `
"Cannot use new with import(). (1:5)
> 1 | new import("foo")\`bar\`;
| ^
Cause: Cannot use new with import(). (1:4)"
`;
exports[`snippet: #6 format[flow] 1`] = `
"Unexpected token \`import\` (1:5)
> 1 | new import("foo")\`bar\`;
| ^
Cause: Unexpected token \`import\` (1:4)"
`;
exports[`snippet: #6 format[meriyah] 1`] = `
"Cannot use new with import(...) (1:11)
> 1 | new import("foo")\`bar\`;
| ^
Cause: [1:10-1:11]: Cannot use new with import(...)"
`;
exports[`snippet: #6 format[oxc] 1`] = `
"Cannot use new with dynamic import (1:5)
> 1 | new import("foo")\`bar\`;
| ^^^^^^^^^^^^^^^^^^"
`;
exports[`snippet: #6 format[oxc-ts] 1`] = `
"Cannot use new with dynamic import (1:5)
> 1 | new import("foo")\`bar\`;
| ^^^^^^^^^^^^^^^^^^"
`;
exports[`snippet: #6 format[typescript] 1`] = `
"Expression expected. (1:5)
> 1 | new import("foo")\`bar\`;
| ^
Cause: Expression expected."
`;
exports[`snippet: #6 format[yuku] 1`] = `
"'import' is reserved and cannot be used as an identifier (1:5)
> 1 | new import("foo")\`bar\`;
| ^^^^^^"
`;
exports[`snippet: #6 format[yuku-ts] 1`] = `
"'import' is reserved and cannot be used as an identifier (1:5)
> 1 | new import("foo")\`bar\`;
| ^^^^^^"
`;
exports[`snippet: #7 format[babel] 1`] = `
"Cannot use new with import(). (1:5)
> 1 | new import("foo").bar(qux);
| ^
Cause: Cannot use new with import(). (1:4)"
`;
exports[`snippet: #7 format[babel-ts] 1`] = `
"Cannot use new with import(). (1:5)
> 1 | new import("foo").bar(qux);
| ^
Cause: Cannot use new with import(). (1:4)"
`;
exports[`snippet: #7 format[flow] 1`] = `
"Unexpected token \`import\` (1:5)
> 1 | new import("foo").bar(qux);
| ^
Cause: Unexpected token \`import\` (1:4)"
`;
exports[`snippet: #7 format[meriyah] 1`] = `
"Cannot use new with import(...) (1:11)
> 1 | new import("foo").bar(qux);
| ^
Cause: [1:10-1:11]: Cannot use new with import(...)"
`;
exports[`snippet: #7 format[oxc] 1`] = `
"Cannot use new with dynamic import (1:5)
> 1 | new import("foo").bar(qux);
| ^^^^^^^^^^^^^^^^^^^^^^"
`;
exports[`snippet: #7 format[oxc-ts] 1`] = `
"Cannot use new with dynamic import (1:5)
> 1 | new import("foo").bar(qux);
| ^^^^^^^^^^^^^^^^^^^^^^"
`;
exports[`snippet: #7 format[typescript] 1`] = `
"Expression expected. (1:5)
> 1 | new import("foo").bar(qux);
| ^
Cause: Expression expected."
`;
exports[`snippet: #7 format[yuku] 1`] = `
"'import' is reserved and cannot be used as an identifier (1:5)
> 1 | new import("foo").bar(qux);
| ^^^^^^"
`;
exports[`snippet: #7 format[yuku-ts] 1`] = `
"'import' is reserved and cannot be used as an identifier (1:5)
> 1 | new import("foo").bar(qux);
| ^^^^^^"
`;
exports[`snippet: #8 format[babel] 1`] = `
"Cannot use new with import(). (1:5)
> 1 | new import("foo")[bar](qux);
| ^
Cause: Cannot use new with import(). (1:4)"
`;
exports[`snippet: #8 format[babel-ts] 1`] = `
"Cannot use new with import(). (1:5)
> 1 | new import("foo")[bar](qux);
| ^
Cause: Cannot use new with import(). (1:4)"
`;
exports[`snippet: #8 format[flow] 1`] = `
"Unexpected token \`import\` (1:5)
> 1 | new import("foo")[bar](qux);
| ^
Cause: Unexpected token \`import\` (1:4)"
`;
exports[`snippet: #8 format[meriyah] 1`] = `
"Cannot use new with import(...) (1:11)
> 1 | new import("foo")[bar](qux);
| ^
Cause: [1:10-1:11]: Cannot use new with import(...)"
`;
exports[`snippet: #8 format[oxc] 1`] = `
"Cannot use new with dynamic import (1:5)
> 1 | new import("foo")[bar](qux);
| ^^^^^^^^^^^^^^^^^^^^^^^"
`;
exports[`snippet: #8 format[oxc-ts] 1`] = `
"Cannot use new with dynamic import (1:5)
> 1 | new import("foo")[bar](qux);
| ^^^^^^^^^^^^^^^^^^^^^^^"
`;
exports[`snippet: #8 format[typescript] 1`] = `
"Expression expected. (1:5)
> 1 | new import("foo")[bar](qux);
| ^
Cause: Expression expected."
`;
exports[`snippet: #8 format[yuku] 1`] = `
"'import' is reserved and cannot be used as an identifier (1:5)
> 1 | new import("foo")[bar](qux);
| ^^^^^^"
`;
exports[`snippet: #8 format[yuku-ts] 1`] = `
"'import' is reserved and cannot be used as an identifier (1:5)
> 1 | new import("foo")[bar](qux);
| ^^^^^^"
`;
exports[`snippet: #9 format[babel] 1`] = `
"Cannot use new with import(). (1:5)
> 1 | new import("foo")\`bar\`(qux);
| ^
Cause: Cannot use new with import(). (1:4)"
`;
exports[`snippet: #9 format[babel-ts] 1`] = `
"Cannot use new with import(). (1:5)
> 1 | new import("foo")\`bar\`(qux);
| ^
Cause: Cannot use new with import(). (1:4)"
`;
exports[`snippet: #9 format[flow] 1`] = `
"Unexpected token \`import\` (1:5)
> 1 | new import("foo")\`bar\`(qux);
| ^
Cause: Unexpected token \`import\` (1:4)"
`;
exports[`snippet: #9 format[meriyah] 1`] = `
"Cannot use new with import(...) (1:11)
> 1 | new import("foo")\`bar\`(qux);
| ^
Cause: [1:10-1:11]: Cannot use new with import(...)"
`;
exports[`snippet: #9 format[oxc] 1`] = `
"Cannot use new with dynamic import (1:5)
> 1 | new import("foo")\`bar\`(qux);
| ^^^^^^^^^^^^^^^^^^^^^^^"
`;
exports[`snippet: #9 format[oxc-ts] 1`] = `
"Cannot use new with dynamic import (1:5)
> 1 | new import("foo")\`bar\`(qux);
| ^^^^^^^^^^^^^^^^^^^^^^^"
`;
exports[`snippet: #9 format[typescript] 1`] = `
"Expression expected. (1:5)
> 1 | new import("foo")\`bar\`(qux);
| ^
Cause: Expression expected."
`;
exports[`snippet: #9 format[yuku] 1`] = `
"'import' is reserved and cannot be used as an identifier (1:5)
> 1 | new import("foo")\`bar\`(qux);
| ^^^^^^"
`;
exports[`snippet: #9 format[yuku-ts] 1`] = `
"'import' is reserved and cannot be used as an identifier (1:5)
> 1 | new import("foo")\`bar\`(qux);
| ^^^^^^"
`;
exports[`static-import-source-should-not-has-extra-token.js format[babel] 1`] = `
"Unexpected token (4:16)
2 | // be parenthesized, that accidentally break #8016
@@ -6,6 +6,12 @@ runFormatTest(
"import(/* comment */);",
"new import('./a.mjs');",
"new import();",
'new import("foo").bar;',
'new import("foo")[bar];',
'new import("foo")`bar`;',
'new import("foo").bar(qux);',
'new import("foo")[bar](qux);',
'new import("foo")`bar`(qux);',
],
},
[