diff --git a/.prettierignore b/.prettierignore index ac66ab689e23..dc8cabea0d18 100644 --- a/.prettierignore +++ b/.prettierignore @@ -10,6 +10,13 @@ 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 +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/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/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/src/declaration/VariableDeclaration/spec.ts b/packages/ast-spec/src/declaration/VariableDeclaration/spec.ts index 70ed40f52e62..726af07ea093 100644 --- a/packages/ast-spec/src/declaration/VariableDeclaration/spec.ts +++ b/packages/ast-spec/src/declaration/VariableDeclaration/spec.ts @@ -1,8 +1,12 @@ 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, + UsingInForOfDeclarator, + UsingInNomalConextDeclarator, +} from '../../special/VariableDeclarator/spec'; -export interface VariableDeclaration extends BaseNode { +export interface LetOrConstOrVarDeclaration extends BaseNode { type: AST_NODE_TYPES.VariableDeclaration; /** * The variables declared by this declaration. @@ -13,7 +17,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 * ``` @@ -31,3 +35,62 @@ export interface VariableDeclaration extends BaseNode { */ kind: 'const' | 'let' | 'var'; } + +export interface UsingInNomalConextDeclaration 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: UsingInNomalConextDeclarator[]; + /** + * 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 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 50f129faf583..f8246b6a479a 100644 --- a/packages/ast-spec/src/special/VariableDeclarator/spec.ts +++ b/packages/ast-spec/src/special/VariableDeclarator/spec.ts @@ -1,11 +1,32 @@ 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 UsingInNomalConextDeclarator extends BaseNode { + type: AST_NODE_TYPES.VariableDeclarator; + id: Identifier; + init: Expression; + definite: boolean; +} + +export interface UsingInForOfDeclarator extends BaseNode { + type: AST_NODE_TYPES.VariableDeclarator; + id: Identifier; + init: null; + definite: boolean; +} + +export type UsingDeclarator = + | UsingInForOfDeclarator + | UsingInNomalConextDeclarator; + +export type VariableDeclarator = LetOrConstOrVarDeclarator | UsingDeclarator; diff --git a/packages/ast-spec/src/statement/ForOfStatement/fixtures/using-decralation/fixture.ts b/packages/ast-spec/src/statement/ForOfStatement/fixtures/using-decralation/fixture.ts new file mode 100644 index 000000000000..8ad968c27b69 --- /dev/null +++ b/packages/ast-spec/src/statement/ForOfStatement/fixtures/using-decralation/fixture.ts @@ -0,0 +1 @@ +for (await using a of b) {} diff --git a/packages/ast-spec/src/statement/ForOfStatement/fixtures/using-decralation/snapshots/1-TSESTree-AST.shot b/packages/ast-spec/src/statement/ForOfStatement/fixtures/using-decralation/snapshots/1-TSESTree-AST.shot new file mode 100644 index 000000000000..977879fa9d10 --- /dev/null +++ b/packages/ast-spec/src/statement/ForOfStatement/fixtures/using-decralation/snapshots/1-TSESTree-AST.shot @@ -0,0 +1,84 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`AST Fixtures statement ForOfStatement 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/ForOfStatement/fixtures/using-decralation/snapshots/2-TSESTree-Tokens.shot b/packages/ast-spec/src/statement/ForOfStatement/fixtures/using-decralation/snapshots/2-TSESTree-Tokens.shot new file mode 100644 index 000000000000..bee539e6a68c --- /dev/null +++ b/packages/ast-spec/src/statement/ForOfStatement/fixtures/using-decralation/snapshots/2-TSESTree-Tokens.shot @@ -0,0 +1,106 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`AST Fixtures statement ForOfStatement 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/ForOfStatement/fixtures/using-decralation/snapshots/3-Babel-AST.shot b/packages/ast-spec/src/statement/ForOfStatement/fixtures/using-decralation/snapshots/3-Babel-AST.shot new file mode 100644 index 000000000000..59be4b7440ab --- /dev/null +++ b/packages/ast-spec/src/statement/ForOfStatement/fixtures/using-decralation/snapshots/3-Babel-AST.shot @@ -0,0 +1,78 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`AST Fixtures statement ForOfStatement 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/ForOfStatement/fixtures/using-decralation/snapshots/4-Babel-Tokens.shot b/packages/ast-spec/src/statement/ForOfStatement/fixtures/using-decralation/snapshots/4-Babel-Tokens.shot new file mode 100644 index 000000000000..70b06aff6fb2 --- /dev/null +++ b/packages/ast-spec/src/statement/ForOfStatement/fixtures/using-decralation/snapshots/4-Babel-Tokens.shot @@ -0,0 +1,106 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`AST Fixtures statement ForOfStatement 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/ForOfStatement/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 new file mode 100644 index 000000000000..7a0a435dcec7 --- /dev/null +++ b/packages/ast-spec/src/statement/ForOfStatement/fixtures/using-decralation/snapshots/5-AST-Alignment-AST.shot @@ -0,0 +1,88 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`AST Fixtures statement ForOfStatement 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/ForOfStatement/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 new file mode 100644 index 000000000000..dade88548450 --- /dev/null +++ b/packages/ast-spec/src/statement/ForOfStatement/fixtures/using-decralation/snapshots/6-AST-Alignment-Tokens.shot @@ -0,0 +1,6 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +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/src/statement/ForOfStatement/spec.ts b/packages/ast-spec/src/statement/ForOfStatement/spec.ts index 963261eaaac8..595f9c9e7166 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 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..91a0738bade5 --- /dev/null +++ b/packages/ast-spec/src/unions/ForOfInitialiser.ts @@ -0,0 +1,10 @@ +import type { + LetOrConstOrVarDeclaration, + UsingInForOfDeclaration, +} from '../declaration/VariableDeclaration/spec'; +import type { Expression } from './Expression'; + +export type ForOfInitialiser = + | Expression + | LetOrConstOrVarDeclaration + | UsingInForOfDeclaration; diff --git a/packages/ast-spec/tests/fixtures-with-differences-ast.shot b/packages/ast-spec/tests/fixtures-with-differences-ast.shot index a5be38aaf360..d566a5a5ddc0 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", @@ -469,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/ForOfStatement/fixtures/using-decralation/fixture.ts", ] `; 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", 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', ]; diff --git a/packages/typescript-estree/src/convert.ts b/packages/typescript-estree/src/convert.ts index e6de3e2bf563..a6e35dd4bcc2 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, @@ -1008,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: @@ -3249,6 +3284,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 && diff --git a/packages/typescript-estree/src/node-utils.ts b/packages/typescript-estree/src/node-utils.ts index 9e75926a617c..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,13 +337,20 @@ export function isJSXToken(node: ts.Node): boolean { */ export function getDeclarationKind( node: ts.VariableDeclarationList, -): 'const' | 'let' | 'var' { +): DeclarationKind { 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'; + } if (node.flags & ts.NodeFlags.Const) { return 'const'; } + if (node.flags & ts.NodeFlags.Using) { + return 'using'; + } return 'var'; }