From 66ff86348a4cc1978d71909fcd50a6a1f2c12f6d Mon Sep 17 00:00:00 2001 From: saji-ryu Date: Mon, 14 Aug 2023 15:37:01 +0900 Subject: [PATCH 01/18] feat: update `VariableDeclaration` spec --- packages/ast-spec/src/declaration/VariableDeclaration/spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/ast-spec/src/declaration/VariableDeclaration/spec.ts b/packages/ast-spec/src/declaration/VariableDeclaration/spec.ts index 70ed40f52e62..67af13790264 100644 --- a/packages/ast-spec/src/declaration/VariableDeclaration/spec.ts +++ b/packages/ast-spec/src/declaration/VariableDeclaration/spec.ts @@ -29,5 +29,5 @@ export interface VariableDeclaration extends BaseNode { * var z = 3; * ``` */ - kind: 'const' | 'let' | 'var'; + kind: 'const' | 'let' | 'var' | 'using' | 'await using'; } From f64efd7e7fd65791b9603f8c1e58fcad31192118 Mon Sep 17 00:00:00 2001 From: saji-ryu Date: Mon, 14 Aug 2023 17:28:11 +0900 Subject: [PATCH 02/18] feat: support `using` declaration for `getDeclarationKind` --- packages/typescript-estree/src/node-utils.ts | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/packages/typescript-estree/src/node-utils.ts b/packages/typescript-estree/src/node-utils.ts index 9e75926a617c..9ec38ab74b04 100644 --- a/packages/typescript-estree/src/node-utils.ts +++ b/packages/typescript-estree/src/node-utils.ts @@ -335,14 +335,19 @@ export function isJSXToken(node: ts.Node): boolean { */ export function getDeclarationKind( node: ts.VariableDeclarationList, -): 'const' | 'let' | 'var' { - if (node.flags & ts.NodeFlags.Let) { - return 'let'; - } - if (node.flags & ts.NodeFlags.Const) { - return 'const'; +): 'const' | 'let' | 'var' | 'using' | 'await using' { + switch (node.flags) { + case ts.NodeFlags.Let: + return 'let'; + case ts.NodeFlags.Const: + return 'const'; + case ts.NodeFlags.Using: + return 'using'; + case ts.NodeFlags.AwaitUsing: + return 'await using'; + default: + return 'var'; } - return 'var'; } /** From a4283113d5e6e12162957df6cb76c5ead6e29d57 Mon Sep 17 00:00:00 2001 From: saji-ryu Date: Tue, 15 Aug 2023 00:32:34 +0900 Subject: [PATCH 03/18] feat: add snapshot test --- .prettierignore | 6 + .../fixture.ts | 1 + .../snapshots/1-TSESTree-AST.shot | 95 ++++++++++++++++ .../snapshots/2-TSESTree-Tokens.shot | 106 ++++++++++++++++++ .../snapshots/3-Babel-AST.shot | 88 +++++++++++++++ .../snapshots/4-Babel-Tokens.shot | 106 ++++++++++++++++++ .../snapshots/5-AST-Alignment-AST.shot | 99 ++++++++++++++++ .../snapshots/6-AST-Alignment-Tokens.shot | 6 + .../await-using-with-value/fixture.ts | 1 + .../snapshots/1-TSESTree-AST.shot | 62 ++++++++++ .../snapshots/2-TSESTree-Tokens.shot | 66 +++++++++++ .../snapshots/3-Babel-AST.shot | 58 ++++++++++ .../snapshots/4-Babel-Tokens.shot | 66 +++++++++++ .../snapshots/5-AST-Alignment-AST.shot | 66 +++++++++++ .../snapshots/6-AST-Alignment-Tokens.shot | 6 + .../using-multiple-declarations/fixture.ts | 1 + .../snapshots/1-TSESTree-AST.shot | 95 ++++++++++++++++ .../snapshots/2-TSESTree-Tokens.shot | 96 ++++++++++++++++ .../snapshots/3-Babel-AST.shot | 88 +++++++++++++++ .../snapshots/4-Babel-Tokens.shot | 96 ++++++++++++++++ .../snapshots/5-AST-Alignment-AST.shot | 99 ++++++++++++++++ .../snapshots/6-AST-Alignment-Tokens.shot | 6 + .../fixtures/using-with-value/fixture.ts | 1 + .../snapshots/1-TSESTree-AST.shot | 62 ++++++++++ .../snapshots/2-TSESTree-Tokens.shot | 56 +++++++++ .../snapshots/3-Babel-AST.shot | 58 ++++++++++ .../snapshots/4-Babel-Tokens.shot | 56 +++++++++ .../snapshots/5-AST-Alignment-AST.shot | 66 +++++++++++ .../snapshots/6-AST-Alignment-Tokens.shot | 6 + packages/ast-spec/tests/util/parsers/babel.ts | 1 + 30 files changed, 1619 insertions(+) create mode 100644 packages/ast-spec/src/declaration/VariableDeclaration/fixtures/await-using-multiple-declarations/fixture.ts create mode 100644 packages/ast-spec/src/declaration/VariableDeclaration/fixtures/await-using-multiple-declarations/snapshots/1-TSESTree-AST.shot create mode 100644 packages/ast-spec/src/declaration/VariableDeclaration/fixtures/await-using-multiple-declarations/snapshots/2-TSESTree-Tokens.shot create mode 100644 packages/ast-spec/src/declaration/VariableDeclaration/fixtures/await-using-multiple-declarations/snapshots/3-Babel-AST.shot create mode 100644 packages/ast-spec/src/declaration/VariableDeclaration/fixtures/await-using-multiple-declarations/snapshots/4-Babel-Tokens.shot create mode 100644 packages/ast-spec/src/declaration/VariableDeclaration/fixtures/await-using-multiple-declarations/snapshots/5-AST-Alignment-AST.shot create mode 100644 packages/ast-spec/src/declaration/VariableDeclaration/fixtures/await-using-multiple-declarations/snapshots/6-AST-Alignment-Tokens.shot create mode 100644 packages/ast-spec/src/declaration/VariableDeclaration/fixtures/await-using-with-value/fixture.ts create mode 100644 packages/ast-spec/src/declaration/VariableDeclaration/fixtures/await-using-with-value/snapshots/1-TSESTree-AST.shot create mode 100644 packages/ast-spec/src/declaration/VariableDeclaration/fixtures/await-using-with-value/snapshots/2-TSESTree-Tokens.shot create mode 100644 packages/ast-spec/src/declaration/VariableDeclaration/fixtures/await-using-with-value/snapshots/3-Babel-AST.shot create mode 100644 packages/ast-spec/src/declaration/VariableDeclaration/fixtures/await-using-with-value/snapshots/4-Babel-Tokens.shot create mode 100644 packages/ast-spec/src/declaration/VariableDeclaration/fixtures/await-using-with-value/snapshots/5-AST-Alignment-AST.shot create mode 100644 packages/ast-spec/src/declaration/VariableDeclaration/fixtures/await-using-with-value/snapshots/6-AST-Alignment-Tokens.shot create mode 100644 packages/ast-spec/src/declaration/VariableDeclaration/fixtures/using-multiple-declarations/fixture.ts create mode 100644 packages/ast-spec/src/declaration/VariableDeclaration/fixtures/using-multiple-declarations/snapshots/1-TSESTree-AST.shot create mode 100644 packages/ast-spec/src/declaration/VariableDeclaration/fixtures/using-multiple-declarations/snapshots/2-TSESTree-Tokens.shot create mode 100644 packages/ast-spec/src/declaration/VariableDeclaration/fixtures/using-multiple-declarations/snapshots/3-Babel-AST.shot create mode 100644 packages/ast-spec/src/declaration/VariableDeclaration/fixtures/using-multiple-declarations/snapshots/4-Babel-Tokens.shot create mode 100644 packages/ast-spec/src/declaration/VariableDeclaration/fixtures/using-multiple-declarations/snapshots/5-AST-Alignment-AST.shot create mode 100644 packages/ast-spec/src/declaration/VariableDeclaration/fixtures/using-multiple-declarations/snapshots/6-AST-Alignment-Tokens.shot create mode 100644 packages/ast-spec/src/declaration/VariableDeclaration/fixtures/using-with-value/fixture.ts create mode 100644 packages/ast-spec/src/declaration/VariableDeclaration/fixtures/using-with-value/snapshots/1-TSESTree-AST.shot create mode 100644 packages/ast-spec/src/declaration/VariableDeclaration/fixtures/using-with-value/snapshots/2-TSESTree-Tokens.shot create mode 100644 packages/ast-spec/src/declaration/VariableDeclaration/fixtures/using-with-value/snapshots/3-Babel-AST.shot create mode 100644 packages/ast-spec/src/declaration/VariableDeclaration/fixtures/using-with-value/snapshots/4-Babel-Tokens.shot create mode 100644 packages/ast-spec/src/declaration/VariableDeclaration/fixtures/using-with-value/snapshots/5-AST-Alignment-AST.shot create mode 100644 packages/ast-spec/src/declaration/VariableDeclaration/fixtures/using-with-value/snapshots/6-AST-Alignment-Tokens.shot diff --git a/.prettierignore b/.prettierignore index ac66ab689e23..6232d139482a 100644 --- a/.prettierignore +++ b/.prettierignore @@ -10,6 +10,12 @@ packages/eslint-plugin/tests/fixtures/indent/ # prettier errors on this case because it's semantically valid packages/ast-spec/src/element/AccessorProperty/fixtures/modifier-abstract-with-value/fixture.ts +# prettier doesn't yet support `using` declaration +packages/ast-spec/src/declaration/VariableDeclaration/fixtures/await-using-multiple-declarations/fixture.ts +packages/ast-spec/src/declaration/VariableDeclaration/fixtures/await-using-with-value/fixture.ts +packages/ast-spec/src/declaration/VariableDeclaration/fixtures/using-multiple-declarations/fixture.ts +packages/ast-spec/src/declaration/VariableDeclaration/fixtures/using-with-value/fixture.ts + # prettier doesn't yet support `const` modifiers for type parameters packages/ast-spec/src/special/TSTypeParameter/fixtures diff --git a/packages/ast-spec/src/declaration/VariableDeclaration/fixtures/await-using-multiple-declarations/fixture.ts b/packages/ast-spec/src/declaration/VariableDeclaration/fixtures/await-using-multiple-declarations/fixture.ts new file mode 100644 index 000000000000..9e48b70be733 --- /dev/null +++ b/packages/ast-spec/src/declaration/VariableDeclaration/fixtures/await-using-multiple-declarations/fixture.ts @@ -0,0 +1 @@ +await using x = 1, y = 2; diff --git a/packages/ast-spec/src/declaration/VariableDeclaration/fixtures/await-using-multiple-declarations/snapshots/1-TSESTree-AST.shot b/packages/ast-spec/src/declaration/VariableDeclaration/fixtures/await-using-multiple-declarations/snapshots/1-TSESTree-AST.shot new file mode 100644 index 000000000000..cc177f81242f --- /dev/null +++ b/packages/ast-spec/src/declaration/VariableDeclaration/fixtures/await-using-multiple-declarations/snapshots/1-TSESTree-AST.shot @@ -0,0 +1,95 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`AST Fixtures declaration VariableDeclaration await-using-multiple-declarations TSESTree - AST 1`] = ` +Program { + type: "Program", + body: [ + VariableDeclaration { + type: "VariableDeclaration", + declarations: [ + VariableDeclarator { + type: "VariableDeclarator", + definite: false, + id: Identifier { + type: "Identifier", + decorators: [], + name: "x", + optional: false, + + range: [12, 13], + loc: { + start: { column: 12, line: 1 }, + end: { column: 13, line: 1 }, + }, + }, + init: Literal { + type: "Literal", + raw: "1", + value: 1, + + range: [16, 17], + loc: { + start: { column: 16, line: 1 }, + end: { column: 17, line: 1 }, + }, + }, + + range: [12, 17], + loc: { + start: { column: 12, line: 1 }, + end: { column: 17, line: 1 }, + }, + }, + VariableDeclarator { + type: "VariableDeclarator", + definite: false, + id: Identifier { + type: "Identifier", + decorators: [], + name: "y", + optional: false, + + range: [19, 20], + loc: { + start: { column: 19, line: 1 }, + end: { column: 20, line: 1 }, + }, + }, + init: Literal { + type: "Literal", + raw: "2", + value: 2, + + range: [23, 24], + loc: { + start: { column: 23, line: 1 }, + end: { column: 24, line: 1 }, + }, + }, + + range: [19, 24], + loc: { + start: { column: 19, line: 1 }, + end: { column: 24, line: 1 }, + }, + }, + ], + declare: false, + kind: "await using", + + range: [0, 25], + loc: { + start: { column: 0, line: 1 }, + end: { column: 25, line: 1 }, + }, + }, + ], + sourceType: "script", + + range: [0, 26], + loc: { + start: { column: 0, line: 1 }, + end: { column: 0, line: 2 }, + }, +} +`; diff --git a/packages/ast-spec/src/declaration/VariableDeclaration/fixtures/await-using-multiple-declarations/snapshots/2-TSESTree-Tokens.shot b/packages/ast-spec/src/declaration/VariableDeclaration/fixtures/await-using-multiple-declarations/snapshots/2-TSESTree-Tokens.shot new file mode 100644 index 000000000000..c123deb06892 --- /dev/null +++ b/packages/ast-spec/src/declaration/VariableDeclaration/fixtures/await-using-multiple-declarations/snapshots/2-TSESTree-Tokens.shot @@ -0,0 +1,106 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`AST Fixtures declaration VariableDeclaration await-using-multiple-declarations TSESTree - Tokens 1`] = ` +[ + Identifier { + type: "Identifier", + value: "await", + + range: [0, 5], + loc: { + start: { column: 0, line: 1 }, + end: { column: 5, line: 1 }, + }, + }, + Identifier { + type: "Identifier", + value: "using", + + range: [6, 11], + loc: { + start: { column: 6, line: 1 }, + end: { column: 11, line: 1 }, + }, + }, + Identifier { + type: "Identifier", + value: "x", + + range: [12, 13], + loc: { + start: { column: 12, line: 1 }, + end: { column: 13, line: 1 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "=", + + range: [14, 15], + loc: { + start: { column: 14, line: 1 }, + end: { column: 15, line: 1 }, + }, + }, + Numeric { + type: "Numeric", + value: "1", + + range: [16, 17], + loc: { + start: { column: 16, line: 1 }, + end: { column: 17, line: 1 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ",", + + range: [17, 18], + loc: { + start: { column: 17, line: 1 }, + end: { column: 18, line: 1 }, + }, + }, + Identifier { + type: "Identifier", + value: "y", + + range: [19, 20], + loc: { + start: { column: 19, line: 1 }, + end: { column: 20, line: 1 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "=", + + range: [21, 22], + loc: { + start: { column: 21, line: 1 }, + end: { column: 22, line: 1 }, + }, + }, + Numeric { + type: "Numeric", + value: "2", + + range: [23, 24], + loc: { + start: { column: 23, line: 1 }, + end: { column: 24, line: 1 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ";", + + range: [24, 25], + loc: { + start: { column: 24, line: 1 }, + end: { column: 25, line: 1 }, + }, + }, +] +`; diff --git a/packages/ast-spec/src/declaration/VariableDeclaration/fixtures/await-using-multiple-declarations/snapshots/3-Babel-AST.shot b/packages/ast-spec/src/declaration/VariableDeclaration/fixtures/await-using-multiple-declarations/snapshots/3-Babel-AST.shot new file mode 100644 index 000000000000..56ed5f448201 --- /dev/null +++ b/packages/ast-spec/src/declaration/VariableDeclaration/fixtures/await-using-multiple-declarations/snapshots/3-Babel-AST.shot @@ -0,0 +1,88 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`AST Fixtures declaration VariableDeclaration await-using-multiple-declarations Babel - AST 1`] = ` +Program { + type: "Program", + body: [ + VariableDeclaration { + type: "VariableDeclaration", + declarations: [ + VariableDeclarator { + type: "VariableDeclarator", + id: Identifier { + type: "Identifier", + name: "x", + + range: [12, 13], + loc: { + start: { column: 12, line: 1 }, + end: { column: 13, line: 1 }, + }, + }, + init: Literal { + type: "Literal", + raw: "1", + value: 1, + + range: [16, 17], + loc: { + start: { column: 16, line: 1 }, + end: { column: 17, line: 1 }, + }, + }, + + range: [12, 17], + loc: { + start: { column: 12, line: 1 }, + end: { column: 17, line: 1 }, + }, + }, + VariableDeclarator { + type: "VariableDeclarator", + id: Identifier { + type: "Identifier", + name: "y", + + range: [19, 20], + loc: { + start: { column: 19, line: 1 }, + end: { column: 20, line: 1 }, + }, + }, + init: Literal { + type: "Literal", + raw: "2", + value: 2, + + range: [23, 24], + loc: { + start: { column: 23, line: 1 }, + end: { column: 24, line: 1 }, + }, + }, + + range: [19, 24], + loc: { + start: { column: 19, line: 1 }, + end: { column: 24, line: 1 }, + }, + }, + ], + kind: "await using", + + range: [0, 25], + loc: { + start: { column: 0, line: 1 }, + end: { column: 25, line: 1 }, + }, + }, + ], + sourceType: "script", + + range: [0, 26], + loc: { + start: { column: 0, line: 1 }, + end: { column: 0, line: 2 }, + }, +} +`; diff --git a/packages/ast-spec/src/declaration/VariableDeclaration/fixtures/await-using-multiple-declarations/snapshots/4-Babel-Tokens.shot b/packages/ast-spec/src/declaration/VariableDeclaration/fixtures/await-using-multiple-declarations/snapshots/4-Babel-Tokens.shot new file mode 100644 index 000000000000..a4259e47cb7e --- /dev/null +++ b/packages/ast-spec/src/declaration/VariableDeclaration/fixtures/await-using-multiple-declarations/snapshots/4-Babel-Tokens.shot @@ -0,0 +1,106 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`AST Fixtures declaration VariableDeclaration await-using-multiple-declarations Babel - Tokens 1`] = ` +[ + Identifier { + type: "Identifier", + value: "await", + + range: [0, 5], + loc: { + start: { column: 0, line: 1 }, + end: { column: 5, line: 1 }, + }, + }, + Identifier { + type: "Identifier", + value: "using", + + range: [6, 11], + loc: { + start: { column: 6, line: 1 }, + end: { column: 11, line: 1 }, + }, + }, + Identifier { + type: "Identifier", + value: "x", + + range: [12, 13], + loc: { + start: { column: 12, line: 1 }, + end: { column: 13, line: 1 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "=", + + range: [14, 15], + loc: { + start: { column: 14, line: 1 }, + end: { column: 15, line: 1 }, + }, + }, + Numeric { + type: "Numeric", + value: "1", + + range: [16, 17], + loc: { + start: { column: 16, line: 1 }, + end: { column: 17, line: 1 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ",", + + range: [17, 18], + loc: { + start: { column: 17, line: 1 }, + end: { column: 18, line: 1 }, + }, + }, + Identifier { + type: "Identifier", + value: "y", + + range: [19, 20], + loc: { + start: { column: 19, line: 1 }, + end: { column: 20, line: 1 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "=", + + range: [21, 22], + loc: { + start: { column: 21, line: 1 }, + end: { column: 22, line: 1 }, + }, + }, + Numeric { + type: "Numeric", + value: "2", + + range: [23, 24], + loc: { + start: { column: 23, line: 1 }, + end: { column: 24, line: 1 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ";", + + range: [24, 25], + loc: { + start: { column: 24, line: 1 }, + end: { column: 25, line: 1 }, + }, + }, +] +`; diff --git a/packages/ast-spec/src/declaration/VariableDeclaration/fixtures/await-using-multiple-declarations/snapshots/5-AST-Alignment-AST.shot b/packages/ast-spec/src/declaration/VariableDeclaration/fixtures/await-using-multiple-declarations/snapshots/5-AST-Alignment-AST.shot new file mode 100644 index 000000000000..4495e1e3efaf --- /dev/null +++ b/packages/ast-spec/src/declaration/VariableDeclaration/fixtures/await-using-multiple-declarations/snapshots/5-AST-Alignment-AST.shot @@ -0,0 +1,99 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`AST Fixtures declaration VariableDeclaration await-using-multiple-declarations AST Alignment - AST 1`] = ` +"Snapshot Diff: +- TSESTree ++ Babel + + Program { + type: 'Program', + body: Array [ + VariableDeclaration { + type: 'VariableDeclaration', + declarations: Array [ + VariableDeclarator { + type: 'VariableDeclarator', +- definite: false, + id: Identifier { + type: 'Identifier', +- decorators: Array [], + name: 'x', +- optional: false, + + range: [12, 13], + loc: { + start: { column: 12, line: 1 }, + end: { column: 13, line: 1 }, + }, + }, + init: Literal { + type: 'Literal', + raw: '1', + value: 1, + + range: [16, 17], + loc: { + start: { column: 16, line: 1 }, + end: { column: 17, line: 1 }, + }, + }, + + range: [12, 17], + loc: { + start: { column: 12, line: 1 }, + end: { column: 17, line: 1 }, + }, + }, + VariableDeclarator { + type: 'VariableDeclarator', +- definite: false, + id: Identifier { + type: 'Identifier', +- decorators: Array [], + name: 'y', +- optional: false, + + range: [19, 20], + loc: { + start: { column: 19, line: 1 }, + end: { column: 20, line: 1 }, + }, + }, + init: Literal { + type: 'Literal', + raw: '2', + value: 2, + + range: [23, 24], + loc: { + start: { column: 23, line: 1 }, + end: { column: 24, line: 1 }, + }, + }, + + range: [19, 24], + loc: { + start: { column: 19, line: 1 }, + end: { column: 24, line: 1 }, + }, + }, + ], +- declare: false, + kind: 'await using', + + range: [0, 25], + loc: { + start: { column: 0, line: 1 }, + end: { column: 25, line: 1 }, + }, + }, + ], + sourceType: 'script', + + range: [0, 26], + loc: { + start: { column: 0, line: 1 }, + end: { column: 0, line: 2 }, + }, + }" +`; diff --git a/packages/ast-spec/src/declaration/VariableDeclaration/fixtures/await-using-multiple-declarations/snapshots/6-AST-Alignment-Tokens.shot b/packages/ast-spec/src/declaration/VariableDeclaration/fixtures/await-using-multiple-declarations/snapshots/6-AST-Alignment-Tokens.shot new file mode 100644 index 000000000000..f15bcd7f39b6 --- /dev/null +++ b/packages/ast-spec/src/declaration/VariableDeclaration/fixtures/await-using-multiple-declarations/snapshots/6-AST-Alignment-Tokens.shot @@ -0,0 +1,6 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`AST Fixtures declaration VariableDeclaration await-using-multiple-declarations AST Alignment - Token 1`] = ` +"Snapshot Diff: +Compared values have no visual difference." +`; diff --git a/packages/ast-spec/src/declaration/VariableDeclaration/fixtures/await-using-with-value/fixture.ts b/packages/ast-spec/src/declaration/VariableDeclaration/fixtures/await-using-with-value/fixture.ts new file mode 100644 index 000000000000..d4b1657b2777 --- /dev/null +++ b/packages/ast-spec/src/declaration/VariableDeclaration/fixtures/await-using-with-value/fixture.ts @@ -0,0 +1 @@ +await using a = 1; diff --git a/packages/ast-spec/src/declaration/VariableDeclaration/fixtures/await-using-with-value/snapshots/1-TSESTree-AST.shot b/packages/ast-spec/src/declaration/VariableDeclaration/fixtures/await-using-with-value/snapshots/1-TSESTree-AST.shot new file mode 100644 index 000000000000..7c8b30cf438e --- /dev/null +++ b/packages/ast-spec/src/declaration/VariableDeclaration/fixtures/await-using-with-value/snapshots/1-TSESTree-AST.shot @@ -0,0 +1,62 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`AST Fixtures declaration VariableDeclaration await-using-with-value TSESTree - AST 1`] = ` +Program { + type: "Program", + body: [ + VariableDeclaration { + type: "VariableDeclaration", + declarations: [ + VariableDeclarator { + type: "VariableDeclarator", + definite: false, + id: Identifier { + type: "Identifier", + decorators: [], + name: "a", + optional: false, + + range: [12, 13], + loc: { + start: { column: 12, line: 1 }, + end: { column: 13, line: 1 }, + }, + }, + init: Literal { + type: "Literal", + raw: "1", + value: 1, + + range: [16, 17], + loc: { + start: { column: 16, line: 1 }, + end: { column: 17, line: 1 }, + }, + }, + + range: [12, 17], + loc: { + start: { column: 12, line: 1 }, + end: { column: 17, line: 1 }, + }, + }, + ], + declare: false, + kind: "await using", + + range: [0, 18], + loc: { + start: { column: 0, line: 1 }, + end: { column: 18, line: 1 }, + }, + }, + ], + sourceType: "script", + + range: [0, 19], + loc: { + start: { column: 0, line: 1 }, + end: { column: 0, line: 2 }, + }, +} +`; diff --git a/packages/ast-spec/src/declaration/VariableDeclaration/fixtures/await-using-with-value/snapshots/2-TSESTree-Tokens.shot b/packages/ast-spec/src/declaration/VariableDeclaration/fixtures/await-using-with-value/snapshots/2-TSESTree-Tokens.shot new file mode 100644 index 000000000000..125001aecf1a --- /dev/null +++ b/packages/ast-spec/src/declaration/VariableDeclaration/fixtures/await-using-with-value/snapshots/2-TSESTree-Tokens.shot @@ -0,0 +1,66 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`AST Fixtures declaration VariableDeclaration await-using-with-value TSESTree - Tokens 1`] = ` +[ + Identifier { + type: "Identifier", + value: "await", + + range: [0, 5], + loc: { + start: { column: 0, line: 1 }, + end: { column: 5, line: 1 }, + }, + }, + Identifier { + type: "Identifier", + value: "using", + + range: [6, 11], + loc: { + start: { column: 6, line: 1 }, + end: { column: 11, line: 1 }, + }, + }, + Identifier { + type: "Identifier", + value: "a", + + range: [12, 13], + loc: { + start: { column: 12, line: 1 }, + end: { column: 13, line: 1 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "=", + + range: [14, 15], + loc: { + start: { column: 14, line: 1 }, + end: { column: 15, line: 1 }, + }, + }, + Numeric { + type: "Numeric", + value: "1", + + range: [16, 17], + loc: { + start: { column: 16, line: 1 }, + end: { column: 17, line: 1 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ";", + + range: [17, 18], + loc: { + start: { column: 17, line: 1 }, + end: { column: 18, line: 1 }, + }, + }, +] +`; diff --git a/packages/ast-spec/src/declaration/VariableDeclaration/fixtures/await-using-with-value/snapshots/3-Babel-AST.shot b/packages/ast-spec/src/declaration/VariableDeclaration/fixtures/await-using-with-value/snapshots/3-Babel-AST.shot new file mode 100644 index 000000000000..277714fe4dfc --- /dev/null +++ b/packages/ast-spec/src/declaration/VariableDeclaration/fixtures/await-using-with-value/snapshots/3-Babel-AST.shot @@ -0,0 +1,58 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`AST Fixtures declaration VariableDeclaration await-using-with-value Babel - AST 1`] = ` +Program { + type: "Program", + body: [ + VariableDeclaration { + type: "VariableDeclaration", + declarations: [ + VariableDeclarator { + type: "VariableDeclarator", + id: Identifier { + type: "Identifier", + name: "a", + + range: [12, 13], + loc: { + start: { column: 12, line: 1 }, + end: { column: 13, line: 1 }, + }, + }, + init: Literal { + type: "Literal", + raw: "1", + value: 1, + + range: [16, 17], + loc: { + start: { column: 16, line: 1 }, + end: { column: 17, line: 1 }, + }, + }, + + range: [12, 17], + loc: { + start: { column: 12, line: 1 }, + end: { column: 17, line: 1 }, + }, + }, + ], + kind: "await using", + + range: [0, 18], + loc: { + start: { column: 0, line: 1 }, + end: { column: 18, line: 1 }, + }, + }, + ], + sourceType: "script", + + range: [0, 19], + loc: { + start: { column: 0, line: 1 }, + end: { column: 0, line: 2 }, + }, +} +`; diff --git a/packages/ast-spec/src/declaration/VariableDeclaration/fixtures/await-using-with-value/snapshots/4-Babel-Tokens.shot b/packages/ast-spec/src/declaration/VariableDeclaration/fixtures/await-using-with-value/snapshots/4-Babel-Tokens.shot new file mode 100644 index 000000000000..b425a65d02bf --- /dev/null +++ b/packages/ast-spec/src/declaration/VariableDeclaration/fixtures/await-using-with-value/snapshots/4-Babel-Tokens.shot @@ -0,0 +1,66 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`AST Fixtures declaration VariableDeclaration await-using-with-value Babel - Tokens 1`] = ` +[ + Identifier { + type: "Identifier", + value: "await", + + range: [0, 5], + loc: { + start: { column: 0, line: 1 }, + end: { column: 5, line: 1 }, + }, + }, + Identifier { + type: "Identifier", + value: "using", + + range: [6, 11], + loc: { + start: { column: 6, line: 1 }, + end: { column: 11, line: 1 }, + }, + }, + Identifier { + type: "Identifier", + value: "a", + + range: [12, 13], + loc: { + start: { column: 12, line: 1 }, + end: { column: 13, line: 1 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "=", + + range: [14, 15], + loc: { + start: { column: 14, line: 1 }, + end: { column: 15, line: 1 }, + }, + }, + Numeric { + type: "Numeric", + value: "1", + + range: [16, 17], + loc: { + start: { column: 16, line: 1 }, + end: { column: 17, line: 1 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ";", + + range: [17, 18], + loc: { + start: { column: 17, line: 1 }, + end: { column: 18, line: 1 }, + }, + }, +] +`; diff --git a/packages/ast-spec/src/declaration/VariableDeclaration/fixtures/await-using-with-value/snapshots/5-AST-Alignment-AST.shot b/packages/ast-spec/src/declaration/VariableDeclaration/fixtures/await-using-with-value/snapshots/5-AST-Alignment-AST.shot new file mode 100644 index 000000000000..65bcb52bd166 --- /dev/null +++ b/packages/ast-spec/src/declaration/VariableDeclaration/fixtures/await-using-with-value/snapshots/5-AST-Alignment-AST.shot @@ -0,0 +1,66 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`AST Fixtures declaration VariableDeclaration await-using-with-value AST Alignment - AST 1`] = ` +"Snapshot Diff: +- TSESTree ++ Babel + + Program { + type: 'Program', + body: Array [ + VariableDeclaration { + type: 'VariableDeclaration', + declarations: Array [ + VariableDeclarator { + type: 'VariableDeclarator', +- definite: false, + id: Identifier { + type: 'Identifier', +- decorators: Array [], + name: 'a', +- optional: false, + + range: [12, 13], + loc: { + start: { column: 12, line: 1 }, + end: { column: 13, line: 1 }, + }, + }, + init: Literal { + type: 'Literal', + raw: '1', + value: 1, + + range: [16, 17], + loc: { + start: { column: 16, line: 1 }, + end: { column: 17, line: 1 }, + }, + }, + + range: [12, 17], + loc: { + start: { column: 12, line: 1 }, + end: { column: 17, line: 1 }, + }, + }, + ], +- declare: false, + kind: 'await using', + + range: [0, 18], + loc: { + start: { column: 0, line: 1 }, + end: { column: 18, line: 1 }, + }, + }, + ], + sourceType: 'script', + + range: [0, 19], + loc: { + start: { column: 0, line: 1 }, + end: { column: 0, line: 2 }, + }, + }" +`; diff --git a/packages/ast-spec/src/declaration/VariableDeclaration/fixtures/await-using-with-value/snapshots/6-AST-Alignment-Tokens.shot b/packages/ast-spec/src/declaration/VariableDeclaration/fixtures/await-using-with-value/snapshots/6-AST-Alignment-Tokens.shot new file mode 100644 index 000000000000..44782da70bc6 --- /dev/null +++ b/packages/ast-spec/src/declaration/VariableDeclaration/fixtures/await-using-with-value/snapshots/6-AST-Alignment-Tokens.shot @@ -0,0 +1,6 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`AST Fixtures declaration VariableDeclaration await-using-with-value AST Alignment - Token 1`] = ` +"Snapshot Diff: +Compared values have no visual difference." +`; diff --git a/packages/ast-spec/src/declaration/VariableDeclaration/fixtures/using-multiple-declarations/fixture.ts b/packages/ast-spec/src/declaration/VariableDeclaration/fixtures/using-multiple-declarations/fixture.ts new file mode 100644 index 000000000000..dcce1ee2a42a --- /dev/null +++ b/packages/ast-spec/src/declaration/VariableDeclaration/fixtures/using-multiple-declarations/fixture.ts @@ -0,0 +1 @@ +using x = 1, y = 2; diff --git a/packages/ast-spec/src/declaration/VariableDeclaration/fixtures/using-multiple-declarations/snapshots/1-TSESTree-AST.shot b/packages/ast-spec/src/declaration/VariableDeclaration/fixtures/using-multiple-declarations/snapshots/1-TSESTree-AST.shot new file mode 100644 index 000000000000..0e6057adde39 --- /dev/null +++ b/packages/ast-spec/src/declaration/VariableDeclaration/fixtures/using-multiple-declarations/snapshots/1-TSESTree-AST.shot @@ -0,0 +1,95 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`AST Fixtures declaration VariableDeclaration using-multiple-declarations TSESTree - AST 1`] = ` +Program { + type: "Program", + body: [ + VariableDeclaration { + type: "VariableDeclaration", + declarations: [ + VariableDeclarator { + type: "VariableDeclarator", + definite: false, + id: Identifier { + type: "Identifier", + decorators: [], + name: "x", + optional: false, + + range: [6, 7], + loc: { + start: { column: 6, line: 1 }, + end: { column: 7, line: 1 }, + }, + }, + init: Literal { + type: "Literal", + raw: "1", + value: 1, + + range: [10, 11], + loc: { + start: { column: 10, line: 1 }, + end: { column: 11, line: 1 }, + }, + }, + + range: [6, 11], + loc: { + start: { column: 6, line: 1 }, + end: { column: 11, line: 1 }, + }, + }, + VariableDeclarator { + type: "VariableDeclarator", + definite: false, + id: Identifier { + type: "Identifier", + decorators: [], + name: "y", + optional: false, + + range: [13, 14], + loc: { + start: { column: 13, line: 1 }, + end: { column: 14, line: 1 }, + }, + }, + init: Literal { + type: "Literal", + raw: "2", + value: 2, + + range: [17, 18], + loc: { + start: { column: 17, line: 1 }, + end: { column: 18, line: 1 }, + }, + }, + + range: [13, 18], + loc: { + start: { column: 13, line: 1 }, + end: { column: 18, line: 1 }, + }, + }, + ], + declare: false, + kind: "using", + + range: [0, 19], + loc: { + start: { column: 0, line: 1 }, + end: { column: 19, line: 1 }, + }, + }, + ], + sourceType: "script", + + range: [0, 20], + loc: { + start: { column: 0, line: 1 }, + end: { column: 0, line: 2 }, + }, +} +`; diff --git a/packages/ast-spec/src/declaration/VariableDeclaration/fixtures/using-multiple-declarations/snapshots/2-TSESTree-Tokens.shot b/packages/ast-spec/src/declaration/VariableDeclaration/fixtures/using-multiple-declarations/snapshots/2-TSESTree-Tokens.shot new file mode 100644 index 000000000000..5199e67367c1 --- /dev/null +++ b/packages/ast-spec/src/declaration/VariableDeclaration/fixtures/using-multiple-declarations/snapshots/2-TSESTree-Tokens.shot @@ -0,0 +1,96 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`AST Fixtures declaration VariableDeclaration using-multiple-declarations TSESTree - Tokens 1`] = ` +[ + Identifier { + type: "Identifier", + value: "using", + + range: [0, 5], + loc: { + start: { column: 0, line: 1 }, + end: { column: 5, line: 1 }, + }, + }, + Identifier { + type: "Identifier", + value: "x", + + range: [6, 7], + loc: { + start: { column: 6, line: 1 }, + end: { column: 7, line: 1 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "=", + + range: [8, 9], + loc: { + start: { column: 8, line: 1 }, + end: { column: 9, line: 1 }, + }, + }, + Numeric { + type: "Numeric", + value: "1", + + range: [10, 11], + loc: { + start: { column: 10, line: 1 }, + end: { column: 11, line: 1 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ",", + + range: [11, 12], + loc: { + start: { column: 11, line: 1 }, + end: { column: 12, line: 1 }, + }, + }, + Identifier { + type: "Identifier", + value: "y", + + range: [13, 14], + loc: { + start: { column: 13, line: 1 }, + end: { column: 14, line: 1 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "=", + + range: [15, 16], + loc: { + start: { column: 15, line: 1 }, + end: { column: 16, line: 1 }, + }, + }, + Numeric { + type: "Numeric", + value: "2", + + range: [17, 18], + loc: { + start: { column: 17, line: 1 }, + end: { column: 18, line: 1 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ";", + + range: [18, 19], + loc: { + start: { column: 18, line: 1 }, + end: { column: 19, line: 1 }, + }, + }, +] +`; diff --git a/packages/ast-spec/src/declaration/VariableDeclaration/fixtures/using-multiple-declarations/snapshots/3-Babel-AST.shot b/packages/ast-spec/src/declaration/VariableDeclaration/fixtures/using-multiple-declarations/snapshots/3-Babel-AST.shot new file mode 100644 index 000000000000..291406b764a7 --- /dev/null +++ b/packages/ast-spec/src/declaration/VariableDeclaration/fixtures/using-multiple-declarations/snapshots/3-Babel-AST.shot @@ -0,0 +1,88 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`AST Fixtures declaration VariableDeclaration using-multiple-declarations Babel - AST 1`] = ` +Program { + type: "Program", + body: [ + VariableDeclaration { + type: "VariableDeclaration", + declarations: [ + VariableDeclarator { + type: "VariableDeclarator", + id: Identifier { + type: "Identifier", + name: "x", + + range: [6, 7], + loc: { + start: { column: 6, line: 1 }, + end: { column: 7, line: 1 }, + }, + }, + init: Literal { + type: "Literal", + raw: "1", + value: 1, + + range: [10, 11], + loc: { + start: { column: 10, line: 1 }, + end: { column: 11, line: 1 }, + }, + }, + + range: [6, 11], + loc: { + start: { column: 6, line: 1 }, + end: { column: 11, line: 1 }, + }, + }, + VariableDeclarator { + type: "VariableDeclarator", + id: Identifier { + type: "Identifier", + name: "y", + + range: [13, 14], + loc: { + start: { column: 13, line: 1 }, + end: { column: 14, line: 1 }, + }, + }, + init: Literal { + type: "Literal", + raw: "2", + value: 2, + + range: [17, 18], + loc: { + start: { column: 17, line: 1 }, + end: { column: 18, line: 1 }, + }, + }, + + range: [13, 18], + loc: { + start: { column: 13, line: 1 }, + end: { column: 18, line: 1 }, + }, + }, + ], + kind: "using", + + range: [0, 19], + loc: { + start: { column: 0, line: 1 }, + end: { column: 19, line: 1 }, + }, + }, + ], + sourceType: "script", + + range: [0, 20], + loc: { + start: { column: 0, line: 1 }, + end: { column: 0, line: 2 }, + }, +} +`; diff --git a/packages/ast-spec/src/declaration/VariableDeclaration/fixtures/using-multiple-declarations/snapshots/4-Babel-Tokens.shot b/packages/ast-spec/src/declaration/VariableDeclaration/fixtures/using-multiple-declarations/snapshots/4-Babel-Tokens.shot new file mode 100644 index 000000000000..1adcd3e551cd --- /dev/null +++ b/packages/ast-spec/src/declaration/VariableDeclaration/fixtures/using-multiple-declarations/snapshots/4-Babel-Tokens.shot @@ -0,0 +1,96 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`AST Fixtures declaration VariableDeclaration using-multiple-declarations Babel - Tokens 1`] = ` +[ + Identifier { + type: "Identifier", + value: "using", + + range: [0, 5], + loc: { + start: { column: 0, line: 1 }, + end: { column: 5, line: 1 }, + }, + }, + Identifier { + type: "Identifier", + value: "x", + + range: [6, 7], + loc: { + start: { column: 6, line: 1 }, + end: { column: 7, line: 1 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "=", + + range: [8, 9], + loc: { + start: { column: 8, line: 1 }, + end: { column: 9, line: 1 }, + }, + }, + Numeric { + type: "Numeric", + value: "1", + + range: [10, 11], + loc: { + start: { column: 10, line: 1 }, + end: { column: 11, line: 1 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ",", + + range: [11, 12], + loc: { + start: { column: 11, line: 1 }, + end: { column: 12, line: 1 }, + }, + }, + Identifier { + type: "Identifier", + value: "y", + + range: [13, 14], + loc: { + start: { column: 13, line: 1 }, + end: { column: 14, line: 1 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "=", + + range: [15, 16], + loc: { + start: { column: 15, line: 1 }, + end: { column: 16, line: 1 }, + }, + }, + Numeric { + type: "Numeric", + value: "2", + + range: [17, 18], + loc: { + start: { column: 17, line: 1 }, + end: { column: 18, line: 1 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ";", + + range: [18, 19], + loc: { + start: { column: 18, line: 1 }, + end: { column: 19, line: 1 }, + }, + }, +] +`; diff --git a/packages/ast-spec/src/declaration/VariableDeclaration/fixtures/using-multiple-declarations/snapshots/5-AST-Alignment-AST.shot b/packages/ast-spec/src/declaration/VariableDeclaration/fixtures/using-multiple-declarations/snapshots/5-AST-Alignment-AST.shot new file mode 100644 index 000000000000..5895a5a4d686 --- /dev/null +++ b/packages/ast-spec/src/declaration/VariableDeclaration/fixtures/using-multiple-declarations/snapshots/5-AST-Alignment-AST.shot @@ -0,0 +1,99 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`AST Fixtures declaration VariableDeclaration using-multiple-declarations AST Alignment - AST 1`] = ` +"Snapshot Diff: +- TSESTree ++ Babel + + Program { + type: 'Program', + body: Array [ + VariableDeclaration { + type: 'VariableDeclaration', + declarations: Array [ + VariableDeclarator { + type: 'VariableDeclarator', +- definite: false, + id: Identifier { + type: 'Identifier', +- decorators: Array [], + name: 'x', +- optional: false, + + range: [6, 7], + loc: { + start: { column: 6, line: 1 }, + end: { column: 7, line: 1 }, + }, + }, + init: Literal { + type: 'Literal', + raw: '1', + value: 1, + + range: [10, 11], + loc: { + start: { column: 10, line: 1 }, + end: { column: 11, line: 1 }, + }, + }, + + range: [6, 11], + loc: { + start: { column: 6, line: 1 }, + end: { column: 11, line: 1 }, + }, + }, + VariableDeclarator { + type: 'VariableDeclarator', +- definite: false, + id: Identifier { + type: 'Identifier', +- decorators: Array [], + name: 'y', +- optional: false, + + range: [13, 14], + loc: { + start: { column: 13, line: 1 }, + end: { column: 14, line: 1 }, + }, + }, + init: Literal { + type: 'Literal', + raw: '2', + value: 2, + + range: [17, 18], + loc: { + start: { column: 17, line: 1 }, + end: { column: 18, line: 1 }, + }, + }, + + range: [13, 18], + loc: { + start: { column: 13, line: 1 }, + end: { column: 18, line: 1 }, + }, + }, + ], +- declare: false, + kind: 'using', + + range: [0, 19], + loc: { + start: { column: 0, line: 1 }, + end: { column: 19, line: 1 }, + }, + }, + ], + sourceType: 'script', + + range: [0, 20], + loc: { + start: { column: 0, line: 1 }, + end: { column: 0, line: 2 }, + }, + }" +`; diff --git a/packages/ast-spec/src/declaration/VariableDeclaration/fixtures/using-multiple-declarations/snapshots/6-AST-Alignment-Tokens.shot b/packages/ast-spec/src/declaration/VariableDeclaration/fixtures/using-multiple-declarations/snapshots/6-AST-Alignment-Tokens.shot new file mode 100644 index 000000000000..67189a9cdc57 --- /dev/null +++ b/packages/ast-spec/src/declaration/VariableDeclaration/fixtures/using-multiple-declarations/snapshots/6-AST-Alignment-Tokens.shot @@ -0,0 +1,6 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`AST Fixtures declaration VariableDeclaration using-multiple-declarations AST Alignment - Token 1`] = ` +"Snapshot Diff: +Compared values have no visual difference." +`; diff --git a/packages/ast-spec/src/declaration/VariableDeclaration/fixtures/using-with-value/fixture.ts b/packages/ast-spec/src/declaration/VariableDeclaration/fixtures/using-with-value/fixture.ts new file mode 100644 index 000000000000..0b59975f6289 --- /dev/null +++ b/packages/ast-spec/src/declaration/VariableDeclaration/fixtures/using-with-value/fixture.ts @@ -0,0 +1 @@ +using a = 1; diff --git a/packages/ast-spec/src/declaration/VariableDeclaration/fixtures/using-with-value/snapshots/1-TSESTree-AST.shot b/packages/ast-spec/src/declaration/VariableDeclaration/fixtures/using-with-value/snapshots/1-TSESTree-AST.shot new file mode 100644 index 000000000000..cc85e096e920 --- /dev/null +++ b/packages/ast-spec/src/declaration/VariableDeclaration/fixtures/using-with-value/snapshots/1-TSESTree-AST.shot @@ -0,0 +1,62 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`AST Fixtures declaration VariableDeclaration using-with-value TSESTree - AST 1`] = ` +Program { + type: "Program", + body: [ + VariableDeclaration { + type: "VariableDeclaration", + declarations: [ + VariableDeclarator { + type: "VariableDeclarator", + definite: false, + id: Identifier { + type: "Identifier", + decorators: [], + name: "a", + optional: false, + + range: [6, 7], + loc: { + start: { column: 6, line: 1 }, + end: { column: 7, line: 1 }, + }, + }, + init: Literal { + type: "Literal", + raw: "1", + value: 1, + + range: [10, 11], + loc: { + start: { column: 10, line: 1 }, + end: { column: 11, line: 1 }, + }, + }, + + range: [6, 11], + loc: { + start: { column: 6, line: 1 }, + end: { column: 11, line: 1 }, + }, + }, + ], + declare: false, + kind: "using", + + range: [0, 12], + loc: { + start: { column: 0, line: 1 }, + end: { column: 12, line: 1 }, + }, + }, + ], + sourceType: "script", + + range: [0, 13], + loc: { + start: { column: 0, line: 1 }, + end: { column: 0, line: 2 }, + }, +} +`; diff --git a/packages/ast-spec/src/declaration/VariableDeclaration/fixtures/using-with-value/snapshots/2-TSESTree-Tokens.shot b/packages/ast-spec/src/declaration/VariableDeclaration/fixtures/using-with-value/snapshots/2-TSESTree-Tokens.shot new file mode 100644 index 000000000000..dcdb5109c1c7 --- /dev/null +++ b/packages/ast-spec/src/declaration/VariableDeclaration/fixtures/using-with-value/snapshots/2-TSESTree-Tokens.shot @@ -0,0 +1,56 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`AST Fixtures declaration VariableDeclaration using-with-value TSESTree - Tokens 1`] = ` +[ + Identifier { + type: "Identifier", + value: "using", + + range: [0, 5], + loc: { + start: { column: 0, line: 1 }, + end: { column: 5, line: 1 }, + }, + }, + Identifier { + type: "Identifier", + value: "a", + + range: [6, 7], + loc: { + start: { column: 6, line: 1 }, + end: { column: 7, line: 1 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "=", + + range: [8, 9], + loc: { + start: { column: 8, line: 1 }, + end: { column: 9, line: 1 }, + }, + }, + Numeric { + type: "Numeric", + value: "1", + + range: [10, 11], + loc: { + start: { column: 10, line: 1 }, + end: { column: 11, line: 1 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ";", + + range: [11, 12], + loc: { + start: { column: 11, line: 1 }, + end: { column: 12, line: 1 }, + }, + }, +] +`; diff --git a/packages/ast-spec/src/declaration/VariableDeclaration/fixtures/using-with-value/snapshots/3-Babel-AST.shot b/packages/ast-spec/src/declaration/VariableDeclaration/fixtures/using-with-value/snapshots/3-Babel-AST.shot new file mode 100644 index 000000000000..b220aa39c335 --- /dev/null +++ b/packages/ast-spec/src/declaration/VariableDeclaration/fixtures/using-with-value/snapshots/3-Babel-AST.shot @@ -0,0 +1,58 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`AST Fixtures declaration VariableDeclaration using-with-value Babel - AST 1`] = ` +Program { + type: "Program", + body: [ + VariableDeclaration { + type: "VariableDeclaration", + declarations: [ + VariableDeclarator { + type: "VariableDeclarator", + id: Identifier { + type: "Identifier", + name: "a", + + range: [6, 7], + loc: { + start: { column: 6, line: 1 }, + end: { column: 7, line: 1 }, + }, + }, + init: Literal { + type: "Literal", + raw: "1", + value: 1, + + range: [10, 11], + loc: { + start: { column: 10, line: 1 }, + end: { column: 11, line: 1 }, + }, + }, + + range: [6, 11], + loc: { + start: { column: 6, line: 1 }, + end: { column: 11, line: 1 }, + }, + }, + ], + kind: "using", + + range: [0, 12], + loc: { + start: { column: 0, line: 1 }, + end: { column: 12, line: 1 }, + }, + }, + ], + sourceType: "script", + + range: [0, 13], + loc: { + start: { column: 0, line: 1 }, + end: { column: 0, line: 2 }, + }, +} +`; diff --git a/packages/ast-spec/src/declaration/VariableDeclaration/fixtures/using-with-value/snapshots/4-Babel-Tokens.shot b/packages/ast-spec/src/declaration/VariableDeclaration/fixtures/using-with-value/snapshots/4-Babel-Tokens.shot new file mode 100644 index 000000000000..683b21358f2f --- /dev/null +++ b/packages/ast-spec/src/declaration/VariableDeclaration/fixtures/using-with-value/snapshots/4-Babel-Tokens.shot @@ -0,0 +1,56 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`AST Fixtures declaration VariableDeclaration using-with-value Babel - Tokens 1`] = ` +[ + Identifier { + type: "Identifier", + value: "using", + + range: [0, 5], + loc: { + start: { column: 0, line: 1 }, + end: { column: 5, line: 1 }, + }, + }, + Identifier { + type: "Identifier", + value: "a", + + range: [6, 7], + loc: { + start: { column: 6, line: 1 }, + end: { column: 7, line: 1 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "=", + + range: [8, 9], + loc: { + start: { column: 8, line: 1 }, + end: { column: 9, line: 1 }, + }, + }, + Numeric { + type: "Numeric", + value: "1", + + range: [10, 11], + loc: { + start: { column: 10, line: 1 }, + end: { column: 11, line: 1 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ";", + + range: [11, 12], + loc: { + start: { column: 11, line: 1 }, + end: { column: 12, line: 1 }, + }, + }, +] +`; diff --git a/packages/ast-spec/src/declaration/VariableDeclaration/fixtures/using-with-value/snapshots/5-AST-Alignment-AST.shot b/packages/ast-spec/src/declaration/VariableDeclaration/fixtures/using-with-value/snapshots/5-AST-Alignment-AST.shot new file mode 100644 index 000000000000..ff3bebb4f1d0 --- /dev/null +++ b/packages/ast-spec/src/declaration/VariableDeclaration/fixtures/using-with-value/snapshots/5-AST-Alignment-AST.shot @@ -0,0 +1,66 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`AST Fixtures declaration VariableDeclaration using-with-value AST Alignment - AST 1`] = ` +"Snapshot Diff: +- TSESTree ++ Babel + + Program { + type: 'Program', + body: Array [ + VariableDeclaration { + type: 'VariableDeclaration', + declarations: Array [ + VariableDeclarator { + type: 'VariableDeclarator', +- definite: false, + id: Identifier { + type: 'Identifier', +- decorators: Array [], + name: 'a', +- optional: false, + + range: [6, 7], + loc: { + start: { column: 6, line: 1 }, + end: { column: 7, line: 1 }, + }, + }, + init: Literal { + type: 'Literal', + raw: '1', + value: 1, + + range: [10, 11], + loc: { + start: { column: 10, line: 1 }, + end: { column: 11, line: 1 }, + }, + }, + + range: [6, 11], + loc: { + start: { column: 6, line: 1 }, + end: { column: 11, line: 1 }, + }, + }, + ], +- declare: false, + kind: 'using', + + range: [0, 12], + loc: { + start: { column: 0, line: 1 }, + end: { column: 12, line: 1 }, + }, + }, + ], + sourceType: 'script', + + range: [0, 13], + loc: { + start: { column: 0, line: 1 }, + end: { column: 0, line: 2 }, + }, + }" +`; diff --git a/packages/ast-spec/src/declaration/VariableDeclaration/fixtures/using-with-value/snapshots/6-AST-Alignment-Tokens.shot b/packages/ast-spec/src/declaration/VariableDeclaration/fixtures/using-with-value/snapshots/6-AST-Alignment-Tokens.shot new file mode 100644 index 000000000000..b895e4005836 --- /dev/null +++ b/packages/ast-spec/src/declaration/VariableDeclaration/fixtures/using-with-value/snapshots/6-AST-Alignment-Tokens.shot @@ -0,0 +1,6 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`AST Fixtures declaration VariableDeclaration using-with-value AST Alignment - Token 1`] = ` +"Snapshot Diff: +Compared values have no visual difference." +`; diff --git a/packages/ast-spec/tests/util/parsers/babel.ts b/packages/ast-spec/tests/util/parsers/babel.ts index 37ad64aeb4ac..54ccd07f7e72 100644 --- a/packages/ast-spec/tests/util/parsers/babel.ts +++ b/packages/ast-spec/tests/util/parsers/babel.ts @@ -10,6 +10,7 @@ const PLUGINS: NonNullable = [ // 'classFeatures', 'classProperties', 'decorators-legacy', + 'explicitResourceManagement', 'importAssertions', 'typescript', ]; From 014ca895ccd25e86665021ccf95aa9e85c4bdd2a Mon Sep 17 00:00:00 2001 From: saji-ryu Date: Tue, 15 Aug 2023 01:34:54 +0900 Subject: [PATCH 04/18] fix: getDeclarationKind logic --- packages/ast-spec/tests/fixtures-with-differences-ast.shot | 4 ++++ packages/typescript-estree/src/node-utils.ts | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/packages/ast-spec/tests/fixtures-with-differences-ast.shot b/packages/ast-spec/tests/fixtures-with-differences-ast.shot index a5be38aaf360..903d7f707724 100644 --- a/packages/ast-spec/tests/fixtures-with-differences-ast.shot +++ b/packages/ast-spec/tests/fixtures-with-differences-ast.shot @@ -99,12 +99,16 @@ exports[`AST Fixtures List fixtures with AST differences 1`] = ` "declaration/TSTypeAliasDeclaration/fixtures/type-param-many/fixture.ts", "declaration/TSTypeAliasDeclaration/fixtures/type-param-one/fixture.ts", "declaration/TSTypeAliasDeclaration/fixtures/valid/fixture.ts", + "declaration/VariableDeclaration/fixtures/await-using-multiple-declarations/fixture.ts", + "declaration/VariableDeclaration/fixtures/await-using-with-value/fixture.ts", "declaration/VariableDeclaration/fixtures/const-with-value/fixture.ts", "declaration/VariableDeclaration/fixtures/const-without-value/fixture.ts", "declaration/VariableDeclaration/fixtures/declare/fixture.ts", "declaration/VariableDeclaration/fixtures/let-with-value/fixture.ts", "declaration/VariableDeclaration/fixtures/let-without-value/fixture.ts", "declaration/VariableDeclaration/fixtures/multiple-declarations/fixture.ts", + "declaration/VariableDeclaration/fixtures/using-multiple-declarations/fixture.ts", + "declaration/VariableDeclaration/fixtures/using-with-value/fixture.ts", "declaration/VariableDeclaration/fixtures/var-with-value/fixture.ts", "declaration/VariableDeclaration/fixtures/var-without-value/fixture.ts", "element/AccessorProperty/fixtures/key-computed-complex/fixture.ts", diff --git a/packages/typescript-estree/src/node-utils.ts b/packages/typescript-estree/src/node-utils.ts index 9ec38ab74b04..63b04df48adb 100644 --- a/packages/typescript-estree/src/node-utils.ts +++ b/packages/typescript-estree/src/node-utils.ts @@ -346,6 +346,12 @@ export function getDeclarationKind( case ts.NodeFlags.AwaitUsing: return 'await using'; default: + if (node.flags & ts.NodeFlags.Let) { + return 'let'; + } + if (node.flags & ts.NodeFlags.Const) { + return 'const'; + } return 'var'; } } From 35431263c758265023c4221a7caa950fecf25dc4 Mon Sep 17 00:00:00 2001 From: saji-ryu Date: Wed, 16 Aug 2023 02:53:52 +0900 Subject: [PATCH 05/18] fix: sort `kind` property member. --- packages/ast-spec/src/declaration/VariableDeclaration/spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/ast-spec/src/declaration/VariableDeclaration/spec.ts b/packages/ast-spec/src/declaration/VariableDeclaration/spec.ts index 67af13790264..ddaec3b0051e 100644 --- a/packages/ast-spec/src/declaration/VariableDeclaration/spec.ts +++ b/packages/ast-spec/src/declaration/VariableDeclaration/spec.ts @@ -29,5 +29,5 @@ export interface VariableDeclaration extends BaseNode { * var z = 3; * ``` */ - kind: 'const' | 'let' | 'var' | 'using' | 'await using'; + kind: 'await using' | 'const' | 'let' | 'using' | 'var'; } From 8df31d25050b484a46c7e67e9143956c5d959b63 Mon Sep 17 00:00:00 2001 From: saji-ryu Date: Wed, 16 Aug 2023 03:21:06 +0900 Subject: [PATCH 06/18] fix: reduce switch cases --- packages/typescript-estree/src/node-utils.ts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/packages/typescript-estree/src/node-utils.ts b/packages/typescript-estree/src/node-utils.ts index 63b04df48adb..968ea5df8833 100644 --- a/packages/typescript-estree/src/node-utils.ts +++ b/packages/typescript-estree/src/node-utils.ts @@ -337,10 +337,6 @@ export function getDeclarationKind( node: ts.VariableDeclarationList, ): 'const' | 'let' | 'var' | 'using' | 'await using' { switch (node.flags) { - case ts.NodeFlags.Let: - return 'let'; - case ts.NodeFlags.Const: - return 'const'; case ts.NodeFlags.Using: return 'using'; case ts.NodeFlags.AwaitUsing: From 77ec66d88695ffd6f227bff1caa20ba0de0a3551 Mon Sep 17 00:00:00 2001 From: saji-ryu Date: Wed, 16 Aug 2023 12:30:49 +0900 Subject: [PATCH 07/18] fix: `getDeclarationKind` flag discrimination logic --- packages/typescript-estree/src/node-utils.ts | 25 ++++++++++---------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/packages/typescript-estree/src/node-utils.ts b/packages/typescript-estree/src/node-utils.ts index 968ea5df8833..8da638145c20 100644 --- a/packages/typescript-estree/src/node-utils.ts +++ b/packages/typescript-estree/src/node-utils.ts @@ -336,20 +336,19 @@ export function isJSXToken(node: ts.Node): boolean { export function getDeclarationKind( node: ts.VariableDeclarationList, ): 'const' | 'let' | 'var' | 'using' | 'await using' { - switch (node.flags) { - case ts.NodeFlags.Using: - return 'using'; - case ts.NodeFlags.AwaitUsing: - return 'await using'; - default: - if (node.flags & ts.NodeFlags.Let) { - return 'let'; - } - if (node.flags & ts.NodeFlags.Const) { - return 'const'; - } - return 'var'; + if (node.flags & ts.NodeFlags.Let) { + return 'let'; + } + if ((node.flags & ts.NodeFlags.AwaitUsing) === ts.NodeFlags.AwaitUsing) { + return 'await using'; + } + if (node.flags & ts.NodeFlags.Const) { + return 'const'; + } + if (node.flags & ts.NodeFlags.Using) { + return 'using'; } + return 'var'; } /** From 3631100122491eca9e2c8ca4e7e3506683c97861 Mon Sep 17 00:00:00 2001 From: saji-ryu Date: Wed, 16 Aug 2023 17:11:09 +0900 Subject: [PATCH 08/18] feat: throw errors in binding patterns or not initialized --- packages/typescript-estree/src/convert.ts | 29 +++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/packages/typescript-estree/src/convert.ts b/packages/typescript-estree/src/convert.ts index e6de3e2bf563..83e9406941f3 100644 --- a/packages/typescript-estree/src/convert.ts +++ b/packages/typescript-estree/src/convert.ts @@ -996,6 +996,22 @@ export class Converter { 'A variable declaration list must have at least one variable declarator.', ); } + if (result.kind === 'using' || result.kind === 'await using') { + node.declarationList.declarations.forEach((declaration, i) => { + if (result.declarations[i].init === null) { + this.#throwError( + declaration, + `'${result.kind}' declarations must be initialized.`, + ); + } + if (result.declarations[i].id.type !== AST_NODE_TYPES.Identifier) { + this.#throwError( + declaration.name, + `'${result.kind}' declarations may not have binding patterns.`, + ); + } + }); + } /** * Semantically, decorators are not allowed on variable declarations, @@ -3249,6 +3265,19 @@ export class Converter { ); } + if ( + modifier.kind === SyntaxKind.DeclareKeyword && + ts.isVariableStatement(node) + ) { + const declarationKind = getDeclarationKind(node.declarationList); + if (declarationKind === 'using' || declarationKind === 'await using') { + this.#throwError( + modifier, + `'declare' modifier cannot appear on a '${declarationKind}' declaration.`, + ); + } + } + if ( modifier.kind === SyntaxKind.AbstractKeyword && node.kind !== SyntaxKind.ClassDeclaration && From 50f29340e1a5ec022ce619c60ce482f29d86dafd Mon Sep 17 00:00:00 2001 From: saji-ryu Date: Thu, 17 Aug 2023 12:03:55 +0900 Subject: [PATCH 09/18] feat: add snapshot test error case --- .../fixtures/_error_/declare-with-using/fixture.ts | 1 + .../declare-with-using/snapshots/1-TSESTree-Error.shot | 8 ++++++++ .../declare-with-using/snapshots/2-Babel-Error.shot | 3 +++ .../declare-with-using/snapshots/3-Alignment-Error.shot | 3 +++ .../fixtures/_error_/missing-value-in-using/fixture.ts | 1 + .../snapshots/1-TSESTree-Error.shot | 8 ++++++++ .../missing-value-in-using/snapshots/2-Babel-Error.shot | 3 +++ .../snapshots/3-Alignment-Error.shot | 3 +++ .../_error_/object-binding-patterns-in-using/fixture.ts | 1 + .../snapshots/1-TSESTree-Error.shot | 8 ++++++++ .../snapshots/2-Babel-Error.shot | 3 +++ .../snapshots/3-Alignment-Error.shot | 3 +++ .../ast-spec/tests/fixtures-with-differences-errors.shot | 1 + 13 files changed, 46 insertions(+) create mode 100644 packages/ast-spec/src/declaration/VariableDeclaration/fixtures/_error_/declare-with-using/fixture.ts create mode 100644 packages/ast-spec/src/declaration/VariableDeclaration/fixtures/_error_/declare-with-using/snapshots/1-TSESTree-Error.shot create mode 100644 packages/ast-spec/src/declaration/VariableDeclaration/fixtures/_error_/declare-with-using/snapshots/2-Babel-Error.shot create mode 100644 packages/ast-spec/src/declaration/VariableDeclaration/fixtures/_error_/declare-with-using/snapshots/3-Alignment-Error.shot create mode 100644 packages/ast-spec/src/declaration/VariableDeclaration/fixtures/_error_/missing-value-in-using/fixture.ts create mode 100644 packages/ast-spec/src/declaration/VariableDeclaration/fixtures/_error_/missing-value-in-using/snapshots/1-TSESTree-Error.shot create mode 100644 packages/ast-spec/src/declaration/VariableDeclaration/fixtures/_error_/missing-value-in-using/snapshots/2-Babel-Error.shot create mode 100644 packages/ast-spec/src/declaration/VariableDeclaration/fixtures/_error_/missing-value-in-using/snapshots/3-Alignment-Error.shot create mode 100644 packages/ast-spec/src/declaration/VariableDeclaration/fixtures/_error_/object-binding-patterns-in-using/fixture.ts create mode 100644 packages/ast-spec/src/declaration/VariableDeclaration/fixtures/_error_/object-binding-patterns-in-using/snapshots/1-TSESTree-Error.shot create mode 100644 packages/ast-spec/src/declaration/VariableDeclaration/fixtures/_error_/object-binding-patterns-in-using/snapshots/2-Babel-Error.shot create mode 100644 packages/ast-spec/src/declaration/VariableDeclaration/fixtures/_error_/object-binding-patterns-in-using/snapshots/3-Alignment-Error.shot diff --git a/packages/ast-spec/src/declaration/VariableDeclaration/fixtures/_error_/declare-with-using/fixture.ts b/packages/ast-spec/src/declaration/VariableDeclaration/fixtures/_error_/declare-with-using/fixture.ts new file mode 100644 index 000000000000..e36a9e085f2a --- /dev/null +++ b/packages/ast-spec/src/declaration/VariableDeclaration/fixtures/_error_/declare-with-using/fixture.ts @@ -0,0 +1 @@ +declare using a = 1; diff --git a/packages/ast-spec/src/declaration/VariableDeclaration/fixtures/_error_/declare-with-using/snapshots/1-TSESTree-Error.shot b/packages/ast-spec/src/declaration/VariableDeclaration/fixtures/_error_/declare-with-using/snapshots/1-TSESTree-Error.shot new file mode 100644 index 000000000000..f30f3e6d192e --- /dev/null +++ b/packages/ast-spec/src/declaration/VariableDeclaration/fixtures/_error_/declare-with-using/snapshots/1-TSESTree-Error.shot @@ -0,0 +1,8 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`AST Fixtures declaration VariableDeclaration _error_ declare-with-using TSESTree - Error 1`] = ` +"TSError +> 1 | declare using a = 1; + | ^^^^^^^ 'declare' modifier cannot appear on a 'using' declaration. + 2 |" +`; diff --git a/packages/ast-spec/src/declaration/VariableDeclaration/fixtures/_error_/declare-with-using/snapshots/2-Babel-Error.shot b/packages/ast-spec/src/declaration/VariableDeclaration/fixtures/_error_/declare-with-using/snapshots/2-Babel-Error.shot new file mode 100644 index 000000000000..b9ae47650d49 --- /dev/null +++ b/packages/ast-spec/src/declaration/VariableDeclaration/fixtures/_error_/declare-with-using/snapshots/2-Babel-Error.shot @@ -0,0 +1,3 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`AST Fixtures declaration VariableDeclaration _error_ declare-with-using Babel - Error 1`] = `[SyntaxError: Missing semicolon. (1:7)]`; diff --git a/packages/ast-spec/src/declaration/VariableDeclaration/fixtures/_error_/declare-with-using/snapshots/3-Alignment-Error.shot b/packages/ast-spec/src/declaration/VariableDeclaration/fixtures/_error_/declare-with-using/snapshots/3-Alignment-Error.shot new file mode 100644 index 000000000000..300960cab48d --- /dev/null +++ b/packages/ast-spec/src/declaration/VariableDeclaration/fixtures/_error_/declare-with-using/snapshots/3-Alignment-Error.shot @@ -0,0 +1,3 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`AST Fixtures declaration VariableDeclaration _error_ declare-with-using Error Alignment 1`] = `"Both errored"`; diff --git a/packages/ast-spec/src/declaration/VariableDeclaration/fixtures/_error_/missing-value-in-using/fixture.ts b/packages/ast-spec/src/declaration/VariableDeclaration/fixtures/_error_/missing-value-in-using/fixture.ts new file mode 100644 index 000000000000..2d16eec5ceca --- /dev/null +++ b/packages/ast-spec/src/declaration/VariableDeclaration/fixtures/_error_/missing-value-in-using/fixture.ts @@ -0,0 +1 @@ +using a; diff --git a/packages/ast-spec/src/declaration/VariableDeclaration/fixtures/_error_/missing-value-in-using/snapshots/1-TSESTree-Error.shot b/packages/ast-spec/src/declaration/VariableDeclaration/fixtures/_error_/missing-value-in-using/snapshots/1-TSESTree-Error.shot new file mode 100644 index 000000000000..92cdc2e07735 --- /dev/null +++ b/packages/ast-spec/src/declaration/VariableDeclaration/fixtures/_error_/missing-value-in-using/snapshots/1-TSESTree-Error.shot @@ -0,0 +1,8 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`AST Fixtures declaration VariableDeclaration _error_ missing-value-in-using TSESTree - Error 1`] = ` +"TSError +> 1 | using a; + | ^ 'using' declarations must be initialized. + 2 |" +`; diff --git a/packages/ast-spec/src/declaration/VariableDeclaration/fixtures/_error_/missing-value-in-using/snapshots/2-Babel-Error.shot b/packages/ast-spec/src/declaration/VariableDeclaration/fixtures/_error_/missing-value-in-using/snapshots/2-Babel-Error.shot new file mode 100644 index 000000000000..05e3f2fa460c --- /dev/null +++ b/packages/ast-spec/src/declaration/VariableDeclaration/fixtures/_error_/missing-value-in-using/snapshots/2-Babel-Error.shot @@ -0,0 +1,3 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`AST Fixtures declaration VariableDeclaration _error_ missing-value-in-using Babel - Error 1`] = `"NO ERROR"`; diff --git a/packages/ast-spec/src/declaration/VariableDeclaration/fixtures/_error_/missing-value-in-using/snapshots/3-Alignment-Error.shot b/packages/ast-spec/src/declaration/VariableDeclaration/fixtures/_error_/missing-value-in-using/snapshots/3-Alignment-Error.shot new file mode 100644 index 000000000000..71344766bf98 --- /dev/null +++ b/packages/ast-spec/src/declaration/VariableDeclaration/fixtures/_error_/missing-value-in-using/snapshots/3-Alignment-Error.shot @@ -0,0 +1,3 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`AST Fixtures declaration VariableDeclaration _error_ missing-value-in-using Error Alignment 1`] = `"TSESTree errored but Babel didn't"`; diff --git a/packages/ast-spec/src/declaration/VariableDeclaration/fixtures/_error_/object-binding-patterns-in-using/fixture.ts b/packages/ast-spec/src/declaration/VariableDeclaration/fixtures/_error_/object-binding-patterns-in-using/fixture.ts new file mode 100644 index 000000000000..ecdeec9248e8 --- /dev/null +++ b/packages/ast-spec/src/declaration/VariableDeclaration/fixtures/_error_/object-binding-patterns-in-using/fixture.ts @@ -0,0 +1 @@ +using {a} = {a: 1}; diff --git a/packages/ast-spec/src/declaration/VariableDeclaration/fixtures/_error_/object-binding-patterns-in-using/snapshots/1-TSESTree-Error.shot b/packages/ast-spec/src/declaration/VariableDeclaration/fixtures/_error_/object-binding-patterns-in-using/snapshots/1-TSESTree-Error.shot new file mode 100644 index 000000000000..dc13d7605c23 --- /dev/null +++ b/packages/ast-spec/src/declaration/VariableDeclaration/fixtures/_error_/object-binding-patterns-in-using/snapshots/1-TSESTree-Error.shot @@ -0,0 +1,8 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`AST Fixtures declaration VariableDeclaration _error_ object-binding-patterns-in-using TSESTree - Error 1`] = ` +"TSError +> 1 | using {a} = {a: 1}; + | ^^^ 'using' declarations may not have binding patterns. + 2 |" +`; diff --git a/packages/ast-spec/src/declaration/VariableDeclaration/fixtures/_error_/object-binding-patterns-in-using/snapshots/2-Babel-Error.shot b/packages/ast-spec/src/declaration/VariableDeclaration/fixtures/_error_/object-binding-patterns-in-using/snapshots/2-Babel-Error.shot new file mode 100644 index 000000000000..150938c24f96 --- /dev/null +++ b/packages/ast-spec/src/declaration/VariableDeclaration/fixtures/_error_/object-binding-patterns-in-using/snapshots/2-Babel-Error.shot @@ -0,0 +1,3 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`AST Fixtures declaration VariableDeclaration _error_ object-binding-patterns-in-using Babel - Error 1`] = `[SyntaxError: Missing semicolon. (1:5)]`; diff --git a/packages/ast-spec/src/declaration/VariableDeclaration/fixtures/_error_/object-binding-patterns-in-using/snapshots/3-Alignment-Error.shot b/packages/ast-spec/src/declaration/VariableDeclaration/fixtures/_error_/object-binding-patterns-in-using/snapshots/3-Alignment-Error.shot new file mode 100644 index 000000000000..f8d176652f8f --- /dev/null +++ b/packages/ast-spec/src/declaration/VariableDeclaration/fixtures/_error_/object-binding-patterns-in-using/snapshots/3-Alignment-Error.shot @@ -0,0 +1,3 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`AST Fixtures declaration VariableDeclaration _error_ object-binding-patterns-in-using Error Alignment 1`] = `"Both errored"`; diff --git a/packages/ast-spec/tests/fixtures-with-differences-errors.shot b/packages/ast-spec/tests/fixtures-with-differences-errors.shot index 3baa5a85efca..0fa210c07219 100644 --- a/packages/ast-spec/tests/fixtures-with-differences-errors.shot +++ b/packages/ast-spec/tests/fixtures-with-differences-errors.shot @@ -49,6 +49,7 @@ exports[`AST Fixtures List fixtures with Error differences 1`] = ` "TSESTree errored but Babel didn't": [ "declaration/ExportAllDeclaration/fixtures/_error_/named-non-identifier/fixture.ts", "declaration/ExportNamedDeclaration/fixtures/_error_/aliased-literal/fixture.ts", + "declaration/VariableDeclaration/fixtures/_error_/missing-value-in-using/fixture.ts", "element/AccessorProperty/fixtures/_error_/modifier-abstract-accessor-with-value/fixture.ts", "legacy-fixtures/basics/fixtures/_error_/abstract-class-with-abstract-constructor/fixture.ts", "legacy-fixtures/expressions/fixtures/_error_/instantiation-expression/fixture.ts", From 9080985a75a3ca5f21078c972e6d76acd69b52a1 Mon Sep 17 00:00:00 2001 From: saji-ryu Date: Thu, 17 Aug 2023 19:06:24 +0900 Subject: [PATCH 10/18] fix: lint errors in convert --- packages/typescript-estree/src/convert.ts | 2 +- packages/typescript-estree/src/node-utils.ts | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/typescript-estree/src/convert.ts b/packages/typescript-estree/src/convert.ts index 83e9406941f3..e1cc18d98a98 100644 --- a/packages/typescript-estree/src/convert.ts +++ b/packages/typescript-estree/src/convert.ts @@ -998,7 +998,7 @@ export class Converter { } if (result.kind === 'using' || result.kind === 'await using') { node.declarationList.declarations.forEach((declaration, i) => { - if (result.declarations[i].init === null) { + if (result.declarations[i].init == null) { this.#throwError( declaration, `'${result.kind}' declarations must be initialized.`, diff --git a/packages/typescript-estree/src/node-utils.ts b/packages/typescript-estree/src/node-utils.ts index 8da638145c20..78eda696d67c 100644 --- a/packages/typescript-estree/src/node-utils.ts +++ b/packages/typescript-estree/src/node-utils.ts @@ -339,6 +339,7 @@ export function getDeclarationKind( if (node.flags & ts.NodeFlags.Let) { return 'let'; } + // eslint-disable-next-line @typescript-eslint/no-unsafe-enum-comparison if ((node.flags & ts.NodeFlags.AwaitUsing) === ts.NodeFlags.AwaitUsing) { return 'await using'; } From a718755b6a57471c3afe178de6f7cd298503753a Mon Sep 17 00:00:00 2001 From: saji-ryu Date: Thu, 17 Aug 2023 19:18:34 +0900 Subject: [PATCH 11/18] feat: make `VariableDeclaration` to union type of `let/const/var` case and `using` case --- .../declaration/VariableDeclaration/spec.ts | 40 +++++++++++++++++-- .../src/special/VariableDeclarator/spec.ts | 12 +++++- 2 files changed, 47 insertions(+), 5 deletions(-) diff --git a/packages/ast-spec/src/declaration/VariableDeclaration/spec.ts b/packages/ast-spec/src/declaration/VariableDeclaration/spec.ts index ddaec3b0051e..7b21fe2b23d6 100644 --- a/packages/ast-spec/src/declaration/VariableDeclaration/spec.ts +++ b/packages/ast-spec/src/declaration/VariableDeclaration/spec.ts @@ -1,8 +1,11 @@ import type { AST_NODE_TYPES } from '../../ast-node-types'; import type { BaseNode } from '../../base/BaseNode'; -import type { VariableDeclarator } from '../../special/VariableDeclarator/spec'; +import type { + LetOrConstOrVarDeclarator, + UsingDeclarator, +} from '../../special/VariableDeclarator/spec'; -export interface VariableDeclaration extends BaseNode { +interface LetOrConstOrVarDeclaration extends BaseNode { type: AST_NODE_TYPES.VariableDeclaration; /** * The variables declared by this declaration. @@ -13,7 +16,7 @@ export interface VariableDeclaration extends BaseNode { * ``` */ // TODO(#1852) - this should be guaranteed to have at least 1 element in it. - declarations: VariableDeclarator[]; + declarations: LetOrConstOrVarDeclarator[]; /** * Whether the declaration is `declare`d * ``` @@ -29,5 +32,34 @@ export interface VariableDeclaration extends BaseNode { * var z = 3; * ``` */ - kind: 'await using' | 'const' | 'let' | 'using' | 'var'; + kind: 'const' | 'let' | 'var'; } + +interface UsingDeclaration extends BaseNode { + type: AST_NODE_TYPES.VariableDeclaration; + /** + * The variables declared by this declaration. + * Note that there may be 0 declarations (i.e. `const;`). + * ``` + * using x = 1; + * using y =1, z = 2; + * ``` + */ + // TODO(#1852) - this should be guaranteed to have at least 1 element in it. + declarations: UsingDeclarator[]; + /** + * This value will always be `false` + * because 'declare' modifier cannot appear on a 'using' declaration. + */ + declare: false; + /** + * The keyword used to declare the variable(s) + * ``` + * using x = 1; + * await using y = 2; + * ``` + */ + kind: 'await using' | 'using'; +} + +export type VariableDeclaration = LetOrConstOrVarDeclaration | UsingDeclaration; diff --git a/packages/ast-spec/src/special/VariableDeclarator/spec.ts b/packages/ast-spec/src/special/VariableDeclarator/spec.ts index 50f129faf583..1bebd4e6df3f 100644 --- a/packages/ast-spec/src/special/VariableDeclarator/spec.ts +++ b/packages/ast-spec/src/special/VariableDeclarator/spec.ts @@ -1,11 +1,21 @@ import type { AST_NODE_TYPES } from '../../ast-node-types'; import type { BaseNode } from '../../base/BaseNode'; +import type { Identifier } from '../../expression/Identifier/spec'; import type { BindingName } from '../../unions/BindingName'; import type { Expression } from '../../unions/Expression'; -export interface VariableDeclarator extends BaseNode { +export interface LetOrConstOrVarDeclarator extends BaseNode { type: AST_NODE_TYPES.VariableDeclarator; id: BindingName; init: Expression | null; definite: boolean; } + +export interface UsingDeclarator extends BaseNode { + type: AST_NODE_TYPES.VariableDeclarator; + id: Identifier; + init: Expression | null; + definite: boolean; +} + +export type VariableDeclarator = LetOrConstOrVarDeclarator | UsingDeclarator; From f465d5727d2deac18759fb4ab1c4446eaec8806f Mon Sep 17 00:00:00 2001 From: saji-ryu Date: Thu, 17 Aug 2023 19:46:13 +0900 Subject: [PATCH 12/18] fix: export `LetOrConstOrVarDeclaration` and `UsingDeclaration` type --- packages/ast-spec/src/declaration/VariableDeclaration/spec.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/ast-spec/src/declaration/VariableDeclaration/spec.ts b/packages/ast-spec/src/declaration/VariableDeclaration/spec.ts index 7b21fe2b23d6..f49dd7efe8a3 100644 --- a/packages/ast-spec/src/declaration/VariableDeclaration/spec.ts +++ b/packages/ast-spec/src/declaration/VariableDeclaration/spec.ts @@ -5,7 +5,7 @@ import type { UsingDeclarator, } from '../../special/VariableDeclarator/spec'; -interface LetOrConstOrVarDeclaration extends BaseNode { +export interface LetOrConstOrVarDeclaration extends BaseNode { type: AST_NODE_TYPES.VariableDeclaration; /** * The variables declared by this declaration. @@ -35,7 +35,7 @@ interface LetOrConstOrVarDeclaration extends BaseNode { kind: 'const' | 'let' | 'var'; } -interface UsingDeclaration extends BaseNode { +export interface UsingDeclaration extends BaseNode { type: AST_NODE_TYPES.VariableDeclaration; /** * The variables declared by this declaration. From 468f107960ba6abdf3dbeae8fe8354e6dcce7425 Mon Sep 17 00:00:00 2001 From: saji-ryu Date: Fri, 18 Aug 2023 01:17:45 +0900 Subject: [PATCH 13/18] feat: add `using` declaration in for-of statement test --- .prettierignore | 1 + .../fixtures/using-decralation/fixture.ts | 1 + .../snapshots/1-TSESTree-AST.shot | 84 ++++++++++++++ .../snapshots/2-TSESTree-Tokens.shot | 106 ++++++++++++++++++ .../snapshots/3-Babel-AST.shot | 78 +++++++++++++ .../snapshots/4-Babel-Tokens.shot | 106 ++++++++++++++++++ .../snapshots/5-AST-Alignment-AST.shot | 88 +++++++++++++++ .../snapshots/6-AST-Alignment-Tokens.shot | 6 + .../tests/fixtures-with-differences-ast.shot | 1 + 9 files changed, 471 insertions(+) create mode 100644 packages/ast-spec/src/statement/ForStatement/fixtures/using-decralation/fixture.ts create mode 100644 packages/ast-spec/src/statement/ForStatement/fixtures/using-decralation/snapshots/1-TSESTree-AST.shot create mode 100644 packages/ast-spec/src/statement/ForStatement/fixtures/using-decralation/snapshots/2-TSESTree-Tokens.shot create mode 100644 packages/ast-spec/src/statement/ForStatement/fixtures/using-decralation/snapshots/3-Babel-AST.shot create mode 100644 packages/ast-spec/src/statement/ForStatement/fixtures/using-decralation/snapshots/4-Babel-Tokens.shot create mode 100644 packages/ast-spec/src/statement/ForStatement/fixtures/using-decralation/snapshots/5-AST-Alignment-AST.shot create mode 100644 packages/ast-spec/src/statement/ForStatement/fixtures/using-decralation/snapshots/6-AST-Alignment-Tokens.shot diff --git a/.prettierignore b/.prettierignore index 6232d139482a..f9b30f706e3e 100644 --- a/.prettierignore +++ b/.prettierignore @@ -15,6 +15,7 @@ packages/ast-spec/src/declaration/VariableDeclaration/fixtures/await-using-multi packages/ast-spec/src/declaration/VariableDeclaration/fixtures/await-using-with-value/fixture.ts packages/ast-spec/src/declaration/VariableDeclaration/fixtures/using-multiple-declarations/fixture.ts packages/ast-spec/src/declaration/VariableDeclaration/fixtures/using-with-value/fixture.ts +packages/ast-spec/src/statement/ForStatement/fixtures/using-decralation/fixture.ts # prettier doesn't yet support `const` modifiers for type parameters packages/ast-spec/src/special/TSTypeParameter/fixtures diff --git a/packages/ast-spec/src/statement/ForStatement/fixtures/using-decralation/fixture.ts b/packages/ast-spec/src/statement/ForStatement/fixtures/using-decralation/fixture.ts new file mode 100644 index 000000000000..8ad968c27b69 --- /dev/null +++ b/packages/ast-spec/src/statement/ForStatement/fixtures/using-decralation/fixture.ts @@ -0,0 +1 @@ +for (await using a of b) {} diff --git a/packages/ast-spec/src/statement/ForStatement/fixtures/using-decralation/snapshots/1-TSESTree-AST.shot b/packages/ast-spec/src/statement/ForStatement/fixtures/using-decralation/snapshots/1-TSESTree-AST.shot new file mode 100644 index 000000000000..67e251466f0c --- /dev/null +++ b/packages/ast-spec/src/statement/ForStatement/fixtures/using-decralation/snapshots/1-TSESTree-AST.shot @@ -0,0 +1,84 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`AST Fixtures statement ForStatement using-decralation TSESTree - AST 1`] = ` +Program { + type: "Program", + body: [ + ForOfStatement { + type: "ForOfStatement", + await: false, + body: BlockStatement { + type: "BlockStatement", + body: [], + + range: [25, 27], + loc: { + start: { column: 25, line: 1 }, + end: { column: 27, line: 1 }, + }, + }, + left: VariableDeclaration { + type: "VariableDeclaration", + declarations: [ + VariableDeclarator { + type: "VariableDeclarator", + definite: false, + id: Identifier { + type: "Identifier", + decorators: [], + name: "a", + optional: false, + + range: [17, 18], + loc: { + start: { column: 17, line: 1 }, + end: { column: 18, line: 1 }, + }, + }, + init: null, + + range: [17, 18], + loc: { + start: { column: 17, line: 1 }, + end: { column: 18, line: 1 }, + }, + }, + ], + declare: false, + kind: "await using", + + range: [5, 18], + loc: { + start: { column: 5, line: 1 }, + end: { column: 18, line: 1 }, + }, + }, + right: Identifier { + type: "Identifier", + decorators: [], + name: "b", + optional: false, + + range: [22, 23], + loc: { + start: { column: 22, line: 1 }, + end: { column: 23, line: 1 }, + }, + }, + + range: [0, 27], + loc: { + start: { column: 0, line: 1 }, + end: { column: 27, line: 1 }, + }, + }, + ], + sourceType: "script", + + range: [0, 28], + loc: { + start: { column: 0, line: 1 }, + end: { column: 0, line: 2 }, + }, +} +`; diff --git a/packages/ast-spec/src/statement/ForStatement/fixtures/using-decralation/snapshots/2-TSESTree-Tokens.shot b/packages/ast-spec/src/statement/ForStatement/fixtures/using-decralation/snapshots/2-TSESTree-Tokens.shot new file mode 100644 index 000000000000..3522a0e4723e --- /dev/null +++ b/packages/ast-spec/src/statement/ForStatement/fixtures/using-decralation/snapshots/2-TSESTree-Tokens.shot @@ -0,0 +1,106 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`AST Fixtures statement ForStatement using-decralation TSESTree - Tokens 1`] = ` +[ + Keyword { + type: "Keyword", + value: "for", + + range: [0, 3], + loc: { + start: { column: 0, line: 1 }, + end: { column: 3, line: 1 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "(", + + range: [4, 5], + loc: { + start: { column: 4, line: 1 }, + end: { column: 5, line: 1 }, + }, + }, + Identifier { + type: "Identifier", + value: "await", + + range: [5, 10], + loc: { + start: { column: 5, line: 1 }, + end: { column: 10, line: 1 }, + }, + }, + Identifier { + type: "Identifier", + value: "using", + + range: [11, 16], + loc: { + start: { column: 11, line: 1 }, + end: { column: 16, line: 1 }, + }, + }, + Identifier { + type: "Identifier", + value: "a", + + range: [17, 18], + loc: { + start: { column: 17, line: 1 }, + end: { column: 18, line: 1 }, + }, + }, + Identifier { + type: "Identifier", + value: "of", + + range: [19, 21], + loc: { + start: { column: 19, line: 1 }, + end: { column: 21, line: 1 }, + }, + }, + Identifier { + type: "Identifier", + value: "b", + + range: [22, 23], + loc: { + start: { column: 22, line: 1 }, + end: { column: 23, line: 1 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ")", + + range: [23, 24], + loc: { + start: { column: 23, line: 1 }, + end: { column: 24, line: 1 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "{", + + range: [25, 26], + loc: { + start: { column: 25, line: 1 }, + end: { column: 26, line: 1 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "}", + + range: [26, 27], + loc: { + start: { column: 26, line: 1 }, + end: { column: 27, line: 1 }, + }, + }, +] +`; diff --git a/packages/ast-spec/src/statement/ForStatement/fixtures/using-decralation/snapshots/3-Babel-AST.shot b/packages/ast-spec/src/statement/ForStatement/fixtures/using-decralation/snapshots/3-Babel-AST.shot new file mode 100644 index 000000000000..2d77d6d091c1 --- /dev/null +++ b/packages/ast-spec/src/statement/ForStatement/fixtures/using-decralation/snapshots/3-Babel-AST.shot @@ -0,0 +1,78 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`AST Fixtures statement ForStatement using-decralation Babel - AST 1`] = ` +Program { + type: "Program", + body: [ + ForOfStatement { + type: "ForOfStatement", + await: false, + body: BlockStatement { + type: "BlockStatement", + body: [], + + range: [25, 27], + loc: { + start: { column: 25, line: 1 }, + end: { column: 27, line: 1 }, + }, + }, + left: VariableDeclaration { + type: "VariableDeclaration", + declarations: [ + VariableDeclarator { + type: "VariableDeclarator", + id: Identifier { + type: "Identifier", + name: "a", + + range: [17, 18], + loc: { + start: { column: 17, line: 1 }, + end: { column: 18, line: 1 }, + }, + }, + init: null, + + range: [17, 18], + loc: { + start: { column: 17, line: 1 }, + end: { column: 18, line: 1 }, + }, + }, + ], + kind: "await using", + + range: [5, 18], + loc: { + start: { column: 5, line: 1 }, + end: { column: 18, line: 1 }, + }, + }, + right: Identifier { + type: "Identifier", + name: "b", + + range: [22, 23], + loc: { + start: { column: 22, line: 1 }, + end: { column: 23, line: 1 }, + }, + }, + + range: [0, 27], + loc: { + start: { column: 0, line: 1 }, + end: { column: 27, line: 1 }, + }, + }, + ], + sourceType: "script", + + range: [0, 28], + loc: { + start: { column: 0, line: 1 }, + end: { column: 0, line: 2 }, + }, +} +`; diff --git a/packages/ast-spec/src/statement/ForStatement/fixtures/using-decralation/snapshots/4-Babel-Tokens.shot b/packages/ast-spec/src/statement/ForStatement/fixtures/using-decralation/snapshots/4-Babel-Tokens.shot new file mode 100644 index 000000000000..f7ac0274fdb6 --- /dev/null +++ b/packages/ast-spec/src/statement/ForStatement/fixtures/using-decralation/snapshots/4-Babel-Tokens.shot @@ -0,0 +1,106 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`AST Fixtures statement ForStatement using-decralation Babel - Tokens 1`] = ` +[ + Keyword { + type: "Keyword", + value: "for", + + range: [0, 3], + loc: { + start: { column: 0, line: 1 }, + end: { column: 3, line: 1 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "(", + + range: [4, 5], + loc: { + start: { column: 4, line: 1 }, + end: { column: 5, line: 1 }, + }, + }, + Identifier { + type: "Identifier", + value: "await", + + range: [5, 10], + loc: { + start: { column: 5, line: 1 }, + end: { column: 10, line: 1 }, + }, + }, + Identifier { + type: "Identifier", + value: "using", + + range: [11, 16], + loc: { + start: { column: 11, line: 1 }, + end: { column: 16, line: 1 }, + }, + }, + Identifier { + type: "Identifier", + value: "a", + + range: [17, 18], + loc: { + start: { column: 17, line: 1 }, + end: { column: 18, line: 1 }, + }, + }, + Identifier { + type: "Identifier", + value: "of", + + range: [19, 21], + loc: { + start: { column: 19, line: 1 }, + end: { column: 21, line: 1 }, + }, + }, + Identifier { + type: "Identifier", + value: "b", + + range: [22, 23], + loc: { + start: { column: 22, line: 1 }, + end: { column: 23, line: 1 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ")", + + range: [23, 24], + loc: { + start: { column: 23, line: 1 }, + end: { column: 24, line: 1 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "{", + + range: [25, 26], + loc: { + start: { column: 25, line: 1 }, + end: { column: 26, line: 1 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "}", + + range: [26, 27], + loc: { + start: { column: 26, line: 1 }, + end: { column: 27, line: 1 }, + }, + }, +] +`; diff --git a/packages/ast-spec/src/statement/ForStatement/fixtures/using-decralation/snapshots/5-AST-Alignment-AST.shot b/packages/ast-spec/src/statement/ForStatement/fixtures/using-decralation/snapshots/5-AST-Alignment-AST.shot new file mode 100644 index 000000000000..01da02ed912b --- /dev/null +++ b/packages/ast-spec/src/statement/ForStatement/fixtures/using-decralation/snapshots/5-AST-Alignment-AST.shot @@ -0,0 +1,88 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`AST Fixtures statement ForStatement using-decralation AST Alignment - AST 1`] = ` +"Snapshot Diff: +- TSESTree ++ Babel + + Program { + type: 'Program', + body: Array [ + ForOfStatement { + type: 'ForOfStatement', + await: false, + body: BlockStatement { + type: 'BlockStatement', + body: Array [], + + range: [25, 27], + loc: { + start: { column: 25, line: 1 }, + end: { column: 27, line: 1 }, + }, + }, + left: VariableDeclaration { + type: 'VariableDeclaration', + declarations: Array [ + VariableDeclarator { + type: 'VariableDeclarator', +- definite: false, + id: Identifier { + type: 'Identifier', +- decorators: Array [], + name: 'a', +- optional: false, + + range: [17, 18], + loc: { + start: { column: 17, line: 1 }, + end: { column: 18, line: 1 }, + }, + }, + init: null, + + range: [17, 18], + loc: { + start: { column: 17, line: 1 }, + end: { column: 18, line: 1 }, + }, + }, + ], +- declare: false, + kind: 'await using', + + range: [5, 18], + loc: { + start: { column: 5, line: 1 }, + end: { column: 18, line: 1 }, + }, + }, + right: Identifier { + type: 'Identifier', +- decorators: Array [], + name: 'b', +- optional: false, + + range: [22, 23], + loc: { + start: { column: 22, line: 1 }, + end: { column: 23, line: 1 }, + }, + }, + + range: [0, 27], + loc: { + start: { column: 0, line: 1 }, + end: { column: 27, line: 1 }, + }, + }, + ], + sourceType: 'script', + + range: [0, 28], + loc: { + start: { column: 0, line: 1 }, + end: { column: 0, line: 2 }, + }, + }" +`; diff --git a/packages/ast-spec/src/statement/ForStatement/fixtures/using-decralation/snapshots/6-AST-Alignment-Tokens.shot b/packages/ast-spec/src/statement/ForStatement/fixtures/using-decralation/snapshots/6-AST-Alignment-Tokens.shot new file mode 100644 index 000000000000..26a91ec8c6f3 --- /dev/null +++ b/packages/ast-spec/src/statement/ForStatement/fixtures/using-decralation/snapshots/6-AST-Alignment-Tokens.shot @@ -0,0 +1,6 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`AST Fixtures statement ForStatement using-decralation AST Alignment - Token 1`] = ` +"Snapshot Diff: +Compared values have no visual difference." +`; diff --git a/packages/ast-spec/tests/fixtures-with-differences-ast.shot b/packages/ast-spec/tests/fixtures-with-differences-ast.shot index 903d7f707724..9d8ac8a8f29c 100644 --- a/packages/ast-spec/tests/fixtures-with-differences-ast.shot +++ b/packages/ast-spec/tests/fixtures-with-differences-ast.shot @@ -473,5 +473,6 @@ exports[`AST Fixtures List fixtures with AST differences 1`] = ` "special/TSTypeParameter/fixtures/interface-const-modifier/fixture.ts", "special/TSTypeParameter/fixtures/interface-in-const-modifier-multiple/fixture.ts", "special/TSTypeParameter/fixtures/method-const-modifiers/fixture.ts", + "statement/ForStatement/fixtures/using-decralation/fixture.ts", ] `; From 5073ce1358bbf169ca496eaee76255641434fe4d Mon Sep 17 00:00:00 2001 From: saji-ryu Date: Fri, 18 Aug 2023 13:31:37 +0900 Subject: [PATCH 14/18] fix: move fixtures to `ForOfStatement` --- .prettierignore | 2 +- .../fixtures/using-decralation/fixture.ts | 0 .../fixtures/using-decralation/snapshots/1-TSESTree-AST.shot | 2 +- .../fixtures/using-decralation/snapshots/2-TSESTree-Tokens.shot | 2 +- .../fixtures/using-decralation/snapshots/3-Babel-AST.shot | 2 +- .../fixtures/using-decralation/snapshots/4-Babel-Tokens.shot | 2 +- .../using-decralation/snapshots/5-AST-Alignment-AST.shot | 2 +- .../using-decralation/snapshots/6-AST-Alignment-Tokens.shot | 2 +- packages/ast-spec/tests/fixtures-with-differences-ast.shot | 2 +- 9 files changed, 8 insertions(+), 8 deletions(-) rename packages/ast-spec/src/statement/{ForStatement => ForOfStatement}/fixtures/using-decralation/fixture.ts (100%) rename packages/ast-spec/src/statement/{ForStatement => ForOfStatement}/fixtures/using-decralation/snapshots/1-TSESTree-AST.shot (95%) rename packages/ast-spec/src/statement/{ForStatement => ForOfStatement}/fixtures/using-decralation/snapshots/2-TSESTree-Tokens.shot (95%) rename packages/ast-spec/src/statement/{ForStatement => ForOfStatement}/fixtures/using-decralation/snapshots/3-Babel-AST.shot (95%) rename packages/ast-spec/src/statement/{ForStatement => ForOfStatement}/fixtures/using-decralation/snapshots/4-Babel-Tokens.shot (95%) rename packages/ast-spec/src/statement/{ForStatement => ForOfStatement}/fixtures/using-decralation/snapshots/5-AST-Alignment-AST.shot (95%) rename packages/ast-spec/src/statement/{ForStatement => ForOfStatement}/fixtures/using-decralation/snapshots/6-AST-Alignment-Tokens.shot (52%) diff --git a/.prettierignore b/.prettierignore index f9b30f706e3e..dc8cabea0d18 100644 --- a/.prettierignore +++ b/.prettierignore @@ -15,7 +15,7 @@ packages/ast-spec/src/declaration/VariableDeclaration/fixtures/await-using-multi packages/ast-spec/src/declaration/VariableDeclaration/fixtures/await-using-with-value/fixture.ts packages/ast-spec/src/declaration/VariableDeclaration/fixtures/using-multiple-declarations/fixture.ts packages/ast-spec/src/declaration/VariableDeclaration/fixtures/using-with-value/fixture.ts -packages/ast-spec/src/statement/ForStatement/fixtures/using-decralation/fixture.ts +packages/ast-spec/src/statement/ForOfStatement/fixtures/using-decralation/fixture.ts # prettier doesn't yet support `const` modifiers for type parameters packages/ast-spec/src/special/TSTypeParameter/fixtures diff --git a/packages/ast-spec/src/statement/ForStatement/fixtures/using-decralation/fixture.ts b/packages/ast-spec/src/statement/ForOfStatement/fixtures/using-decralation/fixture.ts similarity index 100% rename from packages/ast-spec/src/statement/ForStatement/fixtures/using-decralation/fixture.ts rename to packages/ast-spec/src/statement/ForOfStatement/fixtures/using-decralation/fixture.ts diff --git a/packages/ast-spec/src/statement/ForStatement/fixtures/using-decralation/snapshots/1-TSESTree-AST.shot b/packages/ast-spec/src/statement/ForOfStatement/fixtures/using-decralation/snapshots/1-TSESTree-AST.shot similarity index 95% rename from packages/ast-spec/src/statement/ForStatement/fixtures/using-decralation/snapshots/1-TSESTree-AST.shot rename to packages/ast-spec/src/statement/ForOfStatement/fixtures/using-decralation/snapshots/1-TSESTree-AST.shot index 67e251466f0c..977879fa9d10 100644 --- a/packages/ast-spec/src/statement/ForStatement/fixtures/using-decralation/snapshots/1-TSESTree-AST.shot +++ b/packages/ast-spec/src/statement/ForOfStatement/fixtures/using-decralation/snapshots/1-TSESTree-AST.shot @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`AST Fixtures statement ForStatement using-decralation TSESTree - AST 1`] = ` +exports[`AST Fixtures statement ForOfStatement using-decralation TSESTree - AST 1`] = ` Program { type: "Program", body: [ diff --git a/packages/ast-spec/src/statement/ForStatement/fixtures/using-decralation/snapshots/2-TSESTree-Tokens.shot b/packages/ast-spec/src/statement/ForOfStatement/fixtures/using-decralation/snapshots/2-TSESTree-Tokens.shot similarity index 95% rename from packages/ast-spec/src/statement/ForStatement/fixtures/using-decralation/snapshots/2-TSESTree-Tokens.shot rename to packages/ast-spec/src/statement/ForOfStatement/fixtures/using-decralation/snapshots/2-TSESTree-Tokens.shot index 3522a0e4723e..bee539e6a68c 100644 --- a/packages/ast-spec/src/statement/ForStatement/fixtures/using-decralation/snapshots/2-TSESTree-Tokens.shot +++ b/packages/ast-spec/src/statement/ForOfStatement/fixtures/using-decralation/snapshots/2-TSESTree-Tokens.shot @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`AST Fixtures statement ForStatement using-decralation TSESTree - Tokens 1`] = ` +exports[`AST Fixtures statement ForOfStatement using-decralation TSESTree - Tokens 1`] = ` [ Keyword { type: "Keyword", diff --git a/packages/ast-spec/src/statement/ForStatement/fixtures/using-decralation/snapshots/3-Babel-AST.shot b/packages/ast-spec/src/statement/ForOfStatement/fixtures/using-decralation/snapshots/3-Babel-AST.shot similarity index 95% rename from packages/ast-spec/src/statement/ForStatement/fixtures/using-decralation/snapshots/3-Babel-AST.shot rename to packages/ast-spec/src/statement/ForOfStatement/fixtures/using-decralation/snapshots/3-Babel-AST.shot index 2d77d6d091c1..59be4b7440ab 100644 --- a/packages/ast-spec/src/statement/ForStatement/fixtures/using-decralation/snapshots/3-Babel-AST.shot +++ b/packages/ast-spec/src/statement/ForOfStatement/fixtures/using-decralation/snapshots/3-Babel-AST.shot @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`AST Fixtures statement ForStatement using-decralation Babel - AST 1`] = ` +exports[`AST Fixtures statement ForOfStatement using-decralation Babel - AST 1`] = ` Program { type: "Program", body: [ diff --git a/packages/ast-spec/src/statement/ForStatement/fixtures/using-decralation/snapshots/4-Babel-Tokens.shot b/packages/ast-spec/src/statement/ForOfStatement/fixtures/using-decralation/snapshots/4-Babel-Tokens.shot similarity index 95% rename from packages/ast-spec/src/statement/ForStatement/fixtures/using-decralation/snapshots/4-Babel-Tokens.shot rename to packages/ast-spec/src/statement/ForOfStatement/fixtures/using-decralation/snapshots/4-Babel-Tokens.shot index f7ac0274fdb6..70b06aff6fb2 100644 --- a/packages/ast-spec/src/statement/ForStatement/fixtures/using-decralation/snapshots/4-Babel-Tokens.shot +++ b/packages/ast-spec/src/statement/ForOfStatement/fixtures/using-decralation/snapshots/4-Babel-Tokens.shot @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`AST Fixtures statement ForStatement using-decralation Babel - Tokens 1`] = ` +exports[`AST Fixtures statement ForOfStatement using-decralation Babel - Tokens 1`] = ` [ Keyword { type: "Keyword", diff --git a/packages/ast-spec/src/statement/ForStatement/fixtures/using-decralation/snapshots/5-AST-Alignment-AST.shot b/packages/ast-spec/src/statement/ForOfStatement/fixtures/using-decralation/snapshots/5-AST-Alignment-AST.shot similarity index 95% rename from packages/ast-spec/src/statement/ForStatement/fixtures/using-decralation/snapshots/5-AST-Alignment-AST.shot rename to packages/ast-spec/src/statement/ForOfStatement/fixtures/using-decralation/snapshots/5-AST-Alignment-AST.shot index 01da02ed912b..7a0a435dcec7 100644 --- a/packages/ast-spec/src/statement/ForStatement/fixtures/using-decralation/snapshots/5-AST-Alignment-AST.shot +++ b/packages/ast-spec/src/statement/ForOfStatement/fixtures/using-decralation/snapshots/5-AST-Alignment-AST.shot @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`AST Fixtures statement ForStatement using-decralation AST Alignment - AST 1`] = ` +exports[`AST Fixtures statement ForOfStatement using-decralation AST Alignment - AST 1`] = ` "Snapshot Diff: - TSESTree + Babel diff --git a/packages/ast-spec/src/statement/ForStatement/fixtures/using-decralation/snapshots/6-AST-Alignment-Tokens.shot b/packages/ast-spec/src/statement/ForOfStatement/fixtures/using-decralation/snapshots/6-AST-Alignment-Tokens.shot similarity index 52% rename from packages/ast-spec/src/statement/ForStatement/fixtures/using-decralation/snapshots/6-AST-Alignment-Tokens.shot rename to packages/ast-spec/src/statement/ForOfStatement/fixtures/using-decralation/snapshots/6-AST-Alignment-Tokens.shot index 26a91ec8c6f3..dade88548450 100644 --- a/packages/ast-spec/src/statement/ForStatement/fixtures/using-decralation/snapshots/6-AST-Alignment-Tokens.shot +++ b/packages/ast-spec/src/statement/ForOfStatement/fixtures/using-decralation/snapshots/6-AST-Alignment-Tokens.shot @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`AST Fixtures statement ForStatement using-decralation AST Alignment - Token 1`] = ` +exports[`AST Fixtures statement ForOfStatement using-decralation AST Alignment - Token 1`] = ` "Snapshot Diff: Compared values have no visual difference." `; diff --git a/packages/ast-spec/tests/fixtures-with-differences-ast.shot b/packages/ast-spec/tests/fixtures-with-differences-ast.shot index 9d8ac8a8f29c..d566a5a5ddc0 100644 --- a/packages/ast-spec/tests/fixtures-with-differences-ast.shot +++ b/packages/ast-spec/tests/fixtures-with-differences-ast.shot @@ -473,6 +473,6 @@ exports[`AST Fixtures List fixtures with AST differences 1`] = ` "special/TSTypeParameter/fixtures/interface-const-modifier/fixture.ts", "special/TSTypeParameter/fixtures/interface-in-const-modifier-multiple/fixture.ts", "special/TSTypeParameter/fixtures/method-const-modifiers/fixture.ts", - "statement/ForStatement/fixtures/using-decralation/fixture.ts", + "statement/ForOfStatement/fixtures/using-decralation/fixture.ts", ] `; From 9456e37e912244a1da64ad0a0a5cab726a23f0a9 Mon Sep 17 00:00:00 2001 From: saji-ryu Date: Fri, 18 Aug 2023 22:12:47 +0900 Subject: [PATCH 15/18] feat: update Declaration type in forOfStatement --- .../declaration/VariableDeclaration/spec.ts | 37 +++++++++++++++++-- .../src/special/VariableDeclarator/spec.ts | 15 +++++++- .../src/statement/ForOfStatement/spec.ts | 6 +-- .../ast-spec/src/unions/ForInitialiser.ts | 4 +- .../ast-spec/src/unions/ForOfInitialiser.ts | 10 +++++ 5 files changed, 62 insertions(+), 10 deletions(-) create mode 100644 packages/ast-spec/src/unions/ForOfInitialiser.ts diff --git a/packages/ast-spec/src/declaration/VariableDeclaration/spec.ts b/packages/ast-spec/src/declaration/VariableDeclaration/spec.ts index f49dd7efe8a3..722ebd1735c4 100644 --- a/packages/ast-spec/src/declaration/VariableDeclaration/spec.ts +++ b/packages/ast-spec/src/declaration/VariableDeclaration/spec.ts @@ -2,7 +2,8 @@ import type { AST_NODE_TYPES } from '../../ast-node-types'; import type { BaseNode } from '../../base/BaseNode'; import type { LetOrConstOrVarDeclarator, - UsingDeclarator, + UsingInNomalConextDeclarator, + UsingInForOfDeclarator, } from '../../special/VariableDeclarator/spec'; export interface LetOrConstOrVarDeclaration extends BaseNode { @@ -35,7 +36,7 @@ export interface LetOrConstOrVarDeclaration extends BaseNode { kind: 'const' | 'let' | 'var'; } -export interface UsingDeclaration extends BaseNode { +export interface UsingInNomalConextDeclaration extends BaseNode { type: AST_NODE_TYPES.VariableDeclaration; /** * The variables declared by this declaration. @@ -46,7 +47,7 @@ export interface UsingDeclaration extends BaseNode { * ``` */ // TODO(#1852) - this should be guaranteed to have at least 1 element in it. - declarations: UsingDeclarator[]; + declarations: UsingInNomalConextDeclarator[]; /** * This value will always be `false` * because 'declare' modifier cannot appear on a 'using' declaration. @@ -62,4 +63,34 @@ export interface UsingDeclaration extends BaseNode { kind: 'await using' | 'using'; } +export interface UsingInForOfDeclaration extends BaseNode { + type: AST_NODE_TYPES.VariableDeclaration; + /** + * The variables declared by this declaration. + * Note that there may be 0 declarations (i.e. `const;`). + * ``` + * for(using x of y){} + * ``` + */ + // TODO - this should be guaranteed to have 1 element in it. + declarations: UsingInForOfDeclarator[]; + /** + * This value will always be `false` + * because 'declare' modifier cannot appear on a 'using' declaration. + */ + declare: false; + /** + * The keyword used to declare the variable(s) + * ``` + * for(using x of y){} + * for(await using x of y){} + * ``` + */ + kind: 'await using' | 'using'; +} + +export type UsingDeclaration = + | UsingInForOfDeclaration + | UsingInNomalConextDeclaration; + export type VariableDeclaration = LetOrConstOrVarDeclaration | UsingDeclaration; diff --git a/packages/ast-spec/src/special/VariableDeclarator/spec.ts b/packages/ast-spec/src/special/VariableDeclarator/spec.ts index 1bebd4e6df3f..54050a4ced41 100644 --- a/packages/ast-spec/src/special/VariableDeclarator/spec.ts +++ b/packages/ast-spec/src/special/VariableDeclarator/spec.ts @@ -11,11 +11,22 @@ export interface LetOrConstOrVarDeclarator extends BaseNode { definite: boolean; } -export interface UsingDeclarator extends BaseNode { +export interface UsingInNomalConextDeclarator extends BaseNode { type: AST_NODE_TYPES.VariableDeclarator; id: Identifier; - init: Expression | null; + init: Expression; definite: boolean; } +export interface UsingInForOfDeclarator extends BaseNode { + type: AST_NODE_TYPES.VariableDeclarator; + id: Identifier; + init: null; + definite: boolean; +} + +export type UsingDeclarator = + | UsingInNomalConextDeclarator + | UsingInForOfDeclarator; + export type VariableDeclarator = LetOrConstOrVarDeclarator | UsingDeclarator; diff --git a/packages/ast-spec/src/statement/ForOfStatement/spec.ts b/packages/ast-spec/src/statement/ForOfStatement/spec.ts index 963261eaaac8..56f17cba471a 100644 --- a/packages/ast-spec/src/statement/ForOfStatement/spec.ts +++ b/packages/ast-spec/src/statement/ForOfStatement/spec.ts @@ -1,12 +1,12 @@ -import type { AST_NODE_TYPES } from '../../ast-node-types'; +import { AST_NODE_TYPES } from '../../ast-node-types'; import type { BaseNode } from '../../base/BaseNode'; import type { Expression } from '../../unions/Expression'; -import type { ForInitialiser } from '../../unions/ForInitialiser'; +import type { ForOfInitialiser } from '../../unions/ForOfInitialiser'; import type { Statement } from '../../unions/Statement'; export interface ForOfStatement extends BaseNode { type: AST_NODE_TYPES.ForOfStatement; - left: ForInitialiser; + left: ForOfInitialiser; right: Expression; body: Statement; await: boolean; diff --git a/packages/ast-spec/src/unions/ForInitialiser.ts b/packages/ast-spec/src/unions/ForInitialiser.ts index 05138cb52fbc..9f93dde30c1d 100644 --- a/packages/ast-spec/src/unions/ForInitialiser.ts +++ b/packages/ast-spec/src/unions/ForInitialiser.ts @@ -1,4 +1,4 @@ -import type { VariableDeclaration } from '../declaration/VariableDeclaration/spec'; +import type { LetOrConstOrVarDeclaration } from '../declaration/VariableDeclaration/spec'; import type { Expression } from './Expression'; -export type ForInitialiser = Expression | VariableDeclaration; +export type ForInitialiser = Expression | LetOrConstOrVarDeclaration; diff --git a/packages/ast-spec/src/unions/ForOfInitialiser.ts b/packages/ast-spec/src/unions/ForOfInitialiser.ts new file mode 100644 index 000000000000..e0cd589e5f0c --- /dev/null +++ b/packages/ast-spec/src/unions/ForOfInitialiser.ts @@ -0,0 +1,10 @@ +import type { + UsingInForOfDeclaration, + LetOrConstOrVarDeclaration, +} from '../declaration/VariableDeclaration/spec'; +import type { Expression } from './Expression'; + +export type ForOfInitialiser = + | Expression + | LetOrConstOrVarDeclaration + | UsingInForOfDeclaration; From a9e716a2d08d199933d8cbdd920aaff11c70af0e Mon Sep 17 00:00:00 2001 From: saji-ryu Date: Sat, 19 Aug 2023 01:11:05 +0900 Subject: [PATCH 16/18] fix: apply lint fix --- packages/ast-spec/src/declaration/VariableDeclaration/spec.ts | 2 +- packages/ast-spec/src/special/VariableDeclarator/spec.ts | 4 ++-- packages/ast-spec/src/statement/ForOfStatement/spec.ts | 2 +- packages/ast-spec/src/unions/ForOfInitialiser.ts | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/ast-spec/src/declaration/VariableDeclaration/spec.ts b/packages/ast-spec/src/declaration/VariableDeclaration/spec.ts index 722ebd1735c4..726af07ea093 100644 --- a/packages/ast-spec/src/declaration/VariableDeclaration/spec.ts +++ b/packages/ast-spec/src/declaration/VariableDeclaration/spec.ts @@ -2,8 +2,8 @@ import type { AST_NODE_TYPES } from '../../ast-node-types'; import type { BaseNode } from '../../base/BaseNode'; import type { LetOrConstOrVarDeclarator, - UsingInNomalConextDeclarator, UsingInForOfDeclarator, + UsingInNomalConextDeclarator, } from '../../special/VariableDeclarator/spec'; export interface LetOrConstOrVarDeclaration extends BaseNode { diff --git a/packages/ast-spec/src/special/VariableDeclarator/spec.ts b/packages/ast-spec/src/special/VariableDeclarator/spec.ts index 54050a4ced41..f8246b6a479a 100644 --- a/packages/ast-spec/src/special/VariableDeclarator/spec.ts +++ b/packages/ast-spec/src/special/VariableDeclarator/spec.ts @@ -26,7 +26,7 @@ export interface UsingInForOfDeclarator extends BaseNode { } export type UsingDeclarator = - | UsingInNomalConextDeclarator - | UsingInForOfDeclarator; + | UsingInForOfDeclarator + | UsingInNomalConextDeclarator; export type VariableDeclarator = LetOrConstOrVarDeclarator | UsingDeclarator; diff --git a/packages/ast-spec/src/statement/ForOfStatement/spec.ts b/packages/ast-spec/src/statement/ForOfStatement/spec.ts index 56f17cba471a..595f9c9e7166 100644 --- a/packages/ast-spec/src/statement/ForOfStatement/spec.ts +++ b/packages/ast-spec/src/statement/ForOfStatement/spec.ts @@ -1,4 +1,4 @@ -import { AST_NODE_TYPES } from '../../ast-node-types'; +import type { AST_NODE_TYPES } from '../../ast-node-types'; import type { BaseNode } from '../../base/BaseNode'; import type { Expression } from '../../unions/Expression'; import type { ForOfInitialiser } from '../../unions/ForOfInitialiser'; diff --git a/packages/ast-spec/src/unions/ForOfInitialiser.ts b/packages/ast-spec/src/unions/ForOfInitialiser.ts index e0cd589e5f0c..91a0738bade5 100644 --- a/packages/ast-spec/src/unions/ForOfInitialiser.ts +++ b/packages/ast-spec/src/unions/ForOfInitialiser.ts @@ -1,6 +1,6 @@ import type { - UsingInForOfDeclaration, LetOrConstOrVarDeclaration, + UsingInForOfDeclaration, } from '../declaration/VariableDeclaration/spec'; import type { Expression } from './Expression'; From d9e3ae34155ada3cd42ab971b0fc5e980905148c Mon Sep 17 00:00:00 2001 From: saji-ryu Date: Sat, 19 Aug 2023 02:25:19 +0900 Subject: [PATCH 17/18] feat: add validation when `using` is used in for-of statement --- packages/typescript-estree/src/convert.ts | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/packages/typescript-estree/src/convert.ts b/packages/typescript-estree/src/convert.ts index e1cc18d98a98..a6e35dd4bcc2 100644 --- a/packages/typescript-estree/src/convert.ts +++ b/packages/typescript-estree/src/convert.ts @@ -1024,14 +1024,33 @@ export class Converter { } // mostly for for-of, for-in - case SyntaxKind.VariableDeclarationList: - return this.createNode(node, { + case SyntaxKind.VariableDeclarationList: { + const result = this.createNode(node, { type: AST_NODE_TYPES.VariableDeclaration, declarations: node.declarations.map(el => this.convertChild(el)), declare: false, kind: getDeclarationKind(node), }); + if (result.kind === 'using' || result.kind === 'await using') { + node.declarations.forEach((declaration, i) => { + if (result.declarations[i].init != null) { + this.#throwError( + declaration, + `'${result.kind}' declarations may not be initialized in for statement.`, + ); + } + if (result.declarations[i].id.type !== AST_NODE_TYPES.Identifier) { + this.#throwError( + declaration.name, + `'${result.kind}' declarations may not have binding patterns.`, + ); + } + }); + } + return result; + } + // Expressions case SyntaxKind.ExpressionStatement: From d7721a7f28f6a174b8cca05a9ca4ec81edb83f5b Mon Sep 17 00:00:00 2001 From: saji-ryu Date: Sat, 19 Aug 2023 02:51:15 +0900 Subject: [PATCH 18/18] feat: define DeclarationKind type --- packages/typescript-estree/src/node-utils.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/typescript-estree/src/node-utils.ts b/packages/typescript-estree/src/node-utils.ts index 78eda696d67c..8c16b24cee41 100644 --- a/packages/typescript-estree/src/node-utils.ts +++ b/packages/typescript-estree/src/node-utils.ts @@ -78,6 +78,8 @@ const BINARY_OPERATORS: ReadonlySet = new Set([ SyntaxKind.ExclamationEqualsToken, ]); +type DeclarationKind = TSESTree.VariableDeclaration['kind']; + /** * Returns true if the given ts.Token is the assignment operator * @param operator the operator token @@ -335,7 +337,7 @@ export function isJSXToken(node: ts.Node): boolean { */ export function getDeclarationKind( node: ts.VariableDeclarationList, -): 'const' | 'let' | 'var' | 'using' | 'await using' { +): DeclarationKind { if (node.flags & ts.NodeFlags.Let) { return 'let'; }