Skip to content

Commit b347c04

Browse files
authored
feat: add options property to ImportExpression node (typescript-eslint#10255)
1 parent 3f34490 commit b347c04

File tree

5 files changed

+50
-26
lines changed

5 files changed

+50
-26
lines changed

packages/ast-spec/src/expression/ImportExpression/spec.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,22 @@ import type { Expression } from '../../unions/Expression';
44

55
export interface ImportExpression extends BaseNode {
66
type: AST_NODE_TYPES.ImportExpression;
7+
/**
8+
* The attributes declared for the dynamic import.
9+
* @example
10+
* ```ts
11+
* import('mod', \{ assert: \{ type: 'json' \} \});
12+
* ```
13+
* @deprecated Replaced with {@link `options`}.
14+
*/
715
attributes: Expression | null;
16+
/**
17+
* The options bag declared for the dynamic import.
18+
* @example
19+
* ```ts
20+
* import('mod', \{ assert: \{ type: 'json' \} \});
21+
* ```
22+
*/
23+
options: Expression | null;
824
source: Expression;
925
}

packages/ast-spec/src/legacy-fixtures/basics/fixtures/dynamic-import-with-import-assertions/snapshots/1-TSESTree-AST.shot

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/ast-spec/src/legacy-fixtures/basics/fixtures/dynamic-import-with-import-assertions/snapshots/5-AST-Alignment-AST.shot

Lines changed: 17 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/typescript-estree/src/convert.ts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2435,13 +2435,21 @@ export class Converter {
24352435
'Dynamic import requires exactly one or two arguments.',
24362436
);
24372437
}
2438-
return this.createNode<TSESTree.ImportExpression>(node, {
2439-
type: AST_NODE_TYPES.ImportExpression,
2440-
attributes: node.arguments[1]
2441-
? this.convertChild(node.arguments[1])
2442-
: null,
2443-
source: this.convertChild(node.arguments[0]),
2444-
});
2438+
return this.createNode<TSESTree.ImportExpression>(
2439+
node,
2440+
this.#withDeprecatedAliasGetter(
2441+
{
2442+
type: AST_NODE_TYPES.ImportExpression,
2443+
options: node.arguments[1]
2444+
? this.convertChild(node.arguments[1])
2445+
: null,
2446+
source: this.convertChild(node.arguments[0]),
2447+
},
2448+
'attributes',
2449+
'options',
2450+
true,
2451+
),
2452+
);
24452453
}
24462454

24472455
const callee = this.convertChild(node.expression);

packages/visitor-keys/src/visitor-keys.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ const additionalKeys: AdditionalKeys = {
175175
Identifier: ['decorators', 'typeAnnotation'],
176176
ImportAttribute: ['key', 'value'],
177177
ImportDeclaration: ['specifiers', 'source', 'assertions'],
178-
ImportExpression: ['source', 'attributes'],
178+
ImportExpression: ['source', 'options'],
179179
JSXClosingFragment: [],
180180
JSXOpeningElement: ['name', 'typeArguments', 'attributes'],
181181
JSXOpeningFragment: [],

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy