Skip to content

Commit

Permalink
fix(typescript-estree): fix error handling on ImportExpression (#6587)
Browse files Browse the repository at this point in the history
  • Loading branch information
fisker committed Mar 13, 2023
1 parent 1d78576 commit e8cdd5c
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 1 deletion.
@@ -0,0 +1,5 @@
import(
"./source.json",
{assert: {type: "json"}},
extraArgument
);
@@ -0,0 +1,11 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`AST Fixtures expression ImportExpression _error_ extra-arguments TSESTree - Error 1`] = `
"TSError
2 | \\"./source.json\\",
3 | {assert: {type: \\"json\\"}},
> 4 | extraArgument
| ^^^^^^^^^^^^^ Dynamic import requires exactly one or two arguments.
5 | );
6 |"
`;
@@ -0,0 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`AST Fixtures expression ImportExpression _error_ extra-arguments Babel - Error 1`] = `[SyntaxError: \`import()\` requires exactly one or two arguments. (1:0)]`;
@@ -0,0 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`AST Fixtures expression ImportExpression _error_ extra-arguments Error Alignment 1`] = `"Both errored"`;
@@ -0,0 +1 @@
import();
@@ -0,0 +1,8 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`AST Fixtures expression ImportExpression _error_ no-arguments TSESTree - Error 1`] = `
"TSError
> 1 | import();
| ^^^^^^^^ Dynamic import requires exactly one or two arguments.
2 |"
`;
@@ -0,0 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`AST Fixtures expression ImportExpression _error_ no-arguments Babel - Error 1`] = `[SyntaxError: \`import()\` requires exactly one or two arguments. (1:0)]`;
@@ -0,0 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`AST Fixtures expression ImportExpression _error_ no-arguments Error Alignment 1`] = `"Both errored"`;
2 changes: 1 addition & 1 deletion packages/typescript-estree/src/convert.ts
Expand Up @@ -2059,7 +2059,7 @@ export class Converter {
if (node.expression.kind === SyntaxKind.ImportKeyword) {
if (node.arguments.length !== 1 && node.arguments.length !== 2) {
this.#throwUnlessAllowInvalidAST(
node.arguments[0],
node.arguments[2] ?? node,
'Dynamic import requires exactly one or two arguments.',
);
}
Expand Down

0 comments on commit e8cdd5c

Please sign in to comment.