From 1cb54397717b03294e146f546b7564bf56bf6176 Mon Sep 17 00:00:00 2001 From: yosuke ota Date: Fri, 1 Nov 2024 08:50:41 +0900 Subject: [PATCH 1/2] feat(ast-spec): add `options` property to `ImportExpression` node --- .../src/expression/ImportExpression/spec.ts | 16 +++++++++ .../snapshots/1-TSESTree-AST.shot | 2 +- .../snapshots/5-AST-Alignment-AST.shot | 34 +++++++++---------- packages/typescript-estree/src/convert.ts | 22 ++++++++---- packages/visitor-keys/src/visitor-keys.ts | 2 +- 5 files changed, 50 insertions(+), 26 deletions(-) diff --git a/packages/ast-spec/src/expression/ImportExpression/spec.ts b/packages/ast-spec/src/expression/ImportExpression/spec.ts index 9365bdae6265..960b2763262d 100644 --- a/packages/ast-spec/src/expression/ImportExpression/spec.ts +++ b/packages/ast-spec/src/expression/ImportExpression/spec.ts @@ -4,6 +4,22 @@ import type { Expression } from '../../unions/Expression'; export interface ImportExpression extends BaseNode { type: AST_NODE_TYPES.ImportExpression; + /** + * The attributes declared for the dynamic import. + * @example + * ```ts + * import('mod', \{ assert: { type: 'json' } \}); + * ``` + * @deprecated Replaced with {@link `options`}. + */ attributes: Expression | null; + /** + * The options bag declared for the dynamic import. + * @example + * ```ts + * import('mod', \{ assert: { type: 'json' } \}); + * ``` + */ + options: Expression | null; source: Expression; } diff --git a/packages/ast-spec/src/legacy-fixtures/basics/fixtures/dynamic-import-with-import-assertions/snapshots/1-TSESTree-AST.shot b/packages/ast-spec/src/legacy-fixtures/basics/fixtures/dynamic-import-with-import-assertions/snapshots/1-TSESTree-AST.shot index 75537c0edbdd..cf35251a3a58 100644 --- a/packages/ast-spec/src/legacy-fixtures/basics/fixtures/dynamic-import-with-import-assertions/snapshots/1-TSESTree-AST.shot +++ b/packages/ast-spec/src/legacy-fixtures/basics/fixtures/dynamic-import-with-import-assertions/snapshots/1-TSESTree-AST.shot @@ -8,7 +8,7 @@ Program { type: "ExpressionStatement", expression: ImportExpression { type: "ImportExpression", - attributes: ObjectExpression { + options: ObjectExpression { type: "ObjectExpression", properties: [ Property { diff --git a/packages/ast-spec/src/legacy-fixtures/basics/fixtures/dynamic-import-with-import-assertions/snapshots/5-AST-Alignment-AST.shot b/packages/ast-spec/src/legacy-fixtures/basics/fixtures/dynamic-import-with-import-assertions/snapshots/5-AST-Alignment-AST.shot index 716706840f94..368720ed8e62 100644 --- a/packages/ast-spec/src/legacy-fixtures/basics/fixtures/dynamic-import-with-import-assertions/snapshots/5-AST-Alignment-AST.shot +++ b/packages/ast-spec/src/legacy-fixtures/basics/fixtures/dynamic-import-with-import-assertions/snapshots/5-AST-Alignment-AST.shot @@ -12,15 +12,14 @@ exports[`AST Fixtures legacy-fixtures basics dynamic-import-with-import-assertio type: 'ExpressionStatement', expression: ImportExpression { type: 'ImportExpression', - attributes: ObjectExpression { - type: 'ObjectExpression', - properties: Array [ - Property { - type: 'Property', - computed: false, - key: Identifier { - type: 'Identifier', -- decorators: Array [], ++ attributes: ObjectExpression { ++ type: 'ObjectExpression', ++ properties: Array [ ++ Property { ++ type: 'Property', ++ computed: false, ++ key: Identifier { ++ type: 'Identifier', + name: 'assert', + + range: [89, 95], @@ -92,14 +91,15 @@ exports[`AST Fixtures legacy-fixtures basics dynamic-import-with-import-assertio + end: { column: 42, line: 3 }, + }, + }, -+ options: ObjectExpression { -+ type: 'ObjectExpression', -+ properties: Array [ -+ Property { -+ type: 'Property', -+ computed: false, -+ key: Identifier { -+ type: 'Identifier', + options: ObjectExpression { + type: 'ObjectExpression', + properties: Array [ + Property { + type: 'Property', + computed: false, + key: Identifier { + type: 'Identifier', +- decorators: Array [], name: 'assert', - optional: false, diff --git a/packages/typescript-estree/src/convert.ts b/packages/typescript-estree/src/convert.ts index b014d885bf31..d32d4d54e926 100644 --- a/packages/typescript-estree/src/convert.ts +++ b/packages/typescript-estree/src/convert.ts @@ -2435,13 +2435,21 @@ export class Converter { 'Dynamic import requires exactly one or two arguments.', ); } - return this.createNode(node, { - type: AST_NODE_TYPES.ImportExpression, - attributes: node.arguments[1] - ? this.convertChild(node.arguments[1]) - : null, - source: this.convertChild(node.arguments[0]), - }); + return this.createNode( + node, + this.#withDeprecatedAliasGetter( + { + type: AST_NODE_TYPES.ImportExpression, + options: node.arguments[1] + ? this.convertChild(node.arguments[1]) + : null, + source: this.convertChild(node.arguments[0]), + }, + 'attributes', + 'options', + true, + ), + ); } const callee = this.convertChild(node.expression); diff --git a/packages/visitor-keys/src/visitor-keys.ts b/packages/visitor-keys/src/visitor-keys.ts index 935171d8c25b..0aa7a24450fe 100644 --- a/packages/visitor-keys/src/visitor-keys.ts +++ b/packages/visitor-keys/src/visitor-keys.ts @@ -175,7 +175,7 @@ const additionalKeys: AdditionalKeys = { Identifier: ['decorators', 'typeAnnotation'], ImportAttribute: ['key', 'value'], ImportDeclaration: ['specifiers', 'source', 'assertions'], - ImportExpression: ['source', 'attributes'], + ImportExpression: ['source', 'options'], JSXClosingFragment: [], JSXOpeningElement: ['name', 'typeArguments', 'attributes'], JSXOpeningFragment: [], From 676e283cba2be31910a855c6ace72e03170ebf25 Mon Sep 17 00:00:00 2001 From: yosuke ota Date: Sat, 2 Nov 2024 07:38:42 +0900 Subject: [PATCH 2/2] fix: jsdoc escape --- packages/ast-spec/src/expression/ImportExpression/spec.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/ast-spec/src/expression/ImportExpression/spec.ts b/packages/ast-spec/src/expression/ImportExpression/spec.ts index 960b2763262d..3d52e111a8af 100644 --- a/packages/ast-spec/src/expression/ImportExpression/spec.ts +++ b/packages/ast-spec/src/expression/ImportExpression/spec.ts @@ -8,7 +8,7 @@ export interface ImportExpression extends BaseNode { * The attributes declared for the dynamic import. * @example * ```ts - * import('mod', \{ assert: { type: 'json' } \}); + * import('mod', \{ assert: \{ type: 'json' \} \}); * ``` * @deprecated Replaced with {@link `options`}. */ @@ -17,7 +17,7 @@ export interface ImportExpression extends BaseNode { * The options bag declared for the dynamic import. * @example * ```ts - * import('mod', \{ assert: { type: 'json' } \}); + * import('mod', \{ assert: \{ type: 'json' \} \}); * ``` */ options: Expression | null; 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