diff --git a/packages/ast-spec/src/legacy-fixtures/types/fixtures/mapped-named-type/snapshots/1-TSESTree-AST.shot b/packages/ast-spec/src/legacy-fixtures/types/fixtures/mapped-named-type/snapshots/1-TSESTree-AST.shot index bd1c860246c7..1b6a8258fa1b 100644 --- a/packages/ast-spec/src/legacy-fixtures/types/fixtures/mapped-named-type/snapshots/1-TSESTree-AST.shot +++ b/packages/ast-spec/src/legacy-fixtures/types/fixtures/mapped-named-type/snapshots/1-TSESTree-AST.shot @@ -81,6 +81,7 @@ Program { end: { column: 22, line: 4 }, }, }, + optional: false, typeAnnotation: TSIndexedAccessType { type: "TSIndexedAccessType", indexType: TSTypeReference { diff --git a/packages/ast-spec/src/legacy-fixtures/types/fixtures/mapped-named-type/snapshots/5-AST-Alignment-AST.shot b/packages/ast-spec/src/legacy-fixtures/types/fixtures/mapped-named-type/snapshots/5-AST-Alignment-AST.shot index c35480a4e34a..9880c4e448e3 100644 --- a/packages/ast-spec/src/legacy-fixtures/types/fixtures/mapped-named-type/snapshots/5-AST-Alignment-AST.shot +++ b/packages/ast-spec/src/legacy-fixtures/types/fixtures/mapped-named-type/snapshots/5-AST-Alignment-AST.shot @@ -88,6 +88,7 @@ Snapshot Diff: end: { column: 22, line: 4 }, }, }, +- optional: false, typeAnnotation: TSIndexedAccessType { type: 'TSIndexedAccessType', indexType: TSTypeReference { @@ -137,8 +138,8 @@ Snapshot Diff: loc: { start: { column: 25, line: 4 }, end: { column: 29, line: 4 }, - }, - }, ++ }, ++ }, + typeParameter: TSTypeParameter { + type: 'TSTypeParameter', + constraint: TSTypeOperator { @@ -176,8 +177,8 @@ Snapshot Diff: + loc: { + start: { column: 3, line: 4 }, + end: { column: 15, line: 4 }, -+ }, -+ }, + }, + }, range: [88, 122], loc: { diff --git a/packages/ast-spec/src/legacy-fixtures/types/fixtures/mapped-untypped/snapshots/1-TSESTree-AST.shot b/packages/ast-spec/src/legacy-fixtures/types/fixtures/mapped-untypped/snapshots/1-TSESTree-AST.shot index f4b40bb33c3e..4000cf45965c 100644 --- a/packages/ast-spec/src/legacy-fixtures/types/fixtures/mapped-untypped/snapshots/1-TSESTree-AST.shot +++ b/packages/ast-spec/src/legacy-fixtures/types/fixtures/mapped-untypped/snapshots/1-TSESTree-AST.shot @@ -38,6 +38,7 @@ Program { }, }, nameType: null, + optional: false, range: [82, 99], loc: { diff --git a/packages/ast-spec/src/legacy-fixtures/types/fixtures/mapped-untypped/snapshots/5-AST-Alignment-AST.shot b/packages/ast-spec/src/legacy-fixtures/types/fixtures/mapped-untypped/snapshots/5-AST-Alignment-AST.shot index d3eae2e1b02f..69cf164569b8 100644 --- a/packages/ast-spec/src/legacy-fixtures/types/fixtures/mapped-untypped/snapshots/5-AST-Alignment-AST.shot +++ b/packages/ast-spec/src/legacy-fixtures/types/fixtures/mapped-untypped/snapshots/5-AST-Alignment-AST.shot @@ -57,6 +57,7 @@ Snapshot Diff: }, }, - nameType: null, +- optional: false, range: [82, 99], loc: { diff --git a/packages/ast-spec/src/legacy-fixtures/types/fixtures/mapped/snapshots/1-TSESTree-AST.shot b/packages/ast-spec/src/legacy-fixtures/types/fixtures/mapped/snapshots/1-TSESTree-AST.shot index d32a917d685f..6b1b9f2820d2 100644 --- a/packages/ast-spec/src/legacy-fixtures/types/fixtures/mapped/snapshots/1-TSESTree-AST.shot +++ b/packages/ast-spec/src/legacy-fixtures/types/fixtures/mapped/snapshots/1-TSESTree-AST.shot @@ -38,6 +38,7 @@ Program { }, }, nameType: null, + optional: false, typeAnnotation: TSNumberKeyword { type: "TSNumberKeyword", diff --git a/packages/ast-spec/src/legacy-fixtures/types/fixtures/mapped/snapshots/5-AST-Alignment-AST.shot b/packages/ast-spec/src/legacy-fixtures/types/fixtures/mapped/snapshots/5-AST-Alignment-AST.shot index c90c3cfd4ba4..fd7eca35a7f5 100644 --- a/packages/ast-spec/src/legacy-fixtures/types/fixtures/mapped/snapshots/5-AST-Alignment-AST.shot +++ b/packages/ast-spec/src/legacy-fixtures/types/fixtures/mapped/snapshots/5-AST-Alignment-AST.shot @@ -25,22 +25,36 @@ Snapshot Diff: type: 'TSMappedType', - constraint: TSStringKeyword { - type: 'TSStringKeyword', -+ nameType: null, -+ typeAnnotation: TSNumberKeyword { -+ type: 'TSNumberKeyword', - +- - range: [90, 96], -+ range: [99, 105], - loc: { +- loc: { - start: { column: 17, line: 3 }, - end: { column: 23, line: 3 }, -+ start: { column: 26, line: 3 }, -+ end: { column: 32, line: 3 }, - }, - }, +- }, +- }, - key: Identifier { - type: 'Identifier', - decorators: Array [], +- name: 'P', +- optional: false, +- +- range: [85, 86], +- loc: { +- start: { column: 12, line: 3 }, +- end: { column: 13, line: 3 }, +- }, +- }, + nameType: null, +- optional: false, + typeAnnotation: TSNumberKeyword { + type: 'TSNumberKeyword', + + range: [99, 105], + loc: { + start: { column: 26, line: 3 }, + end: { column: 32, line: 3 }, ++ }, ++ }, + typeParameter: TSTypeParameter { + type: 'TSTypeParameter', + constraint: TSStringKeyword { @@ -52,24 +66,11 @@ Snapshot Diff: + end: { column: 23, line: 3 }, + }, + }, - name: 'P', -- optional: false, - -- range: [85, 86], ++ name: 'P', ++ + range: [85, 96], - loc: { - start: { column: 12, line: 3 }, -- end: { column: 13, line: 3 }, -- }, -- }, -- nameType: null, -- typeAnnotation: TSNumberKeyword { -- type: 'TSNumberKeyword', -- -- range: [99, 105], -- loc: { -- start: { column: 26, line: 3 }, -- end: { column: 32, line: 3 }, ++ loc: { ++ start: { column: 12, line: 3 }, + end: { column: 23, line: 3 }, }, }, diff --git a/packages/ast-spec/src/type/TSMappedType/fixtures/_error_/looks-like-mapped-type-but-with-members/snapshots/3-Alignment-Error.shot b/packages/ast-spec/src/type/TSMappedType/fixtures/_error_/looks-like-mapped-type-but-with-members/snapshots/3-Alignment-Error.shot deleted file mode 100644 index f437a6d2c415..000000000000 --- a/packages/ast-spec/src/type/TSMappedType/fixtures/_error_/looks-like-mapped-type-but-with-members/snapshots/3-Alignment-Error.shot +++ /dev/null @@ -1,4 +0,0 @@ -// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html - -exports[`AST Fixtures > type > TSMappedType > _error_ > looks-like-mapped-type-but-with-members > Error Alignment`] -Both errored diff --git a/packages/ast-spec/src/type/TSMappedType/fixtures/_error_/with-member/fixture.ts b/packages/ast-spec/src/type/TSMappedType/fixtures/_error_/with-member-after/fixture.ts similarity index 100% rename from packages/ast-spec/src/type/TSMappedType/fixtures/_error_/with-member/fixture.ts rename to packages/ast-spec/src/type/TSMappedType/fixtures/_error_/with-member-after/fixture.ts diff --git a/packages/ast-spec/src/type/TSMappedType/fixtures/_error_/with-member/snapshots/1-Babel-Error.shot b/packages/ast-spec/src/type/TSMappedType/fixtures/_error_/with-member-after/snapshots/1-Babel-Error.shot similarity index 100% rename from packages/ast-spec/src/type/TSMappedType/fixtures/_error_/with-member/snapshots/1-Babel-Error.shot rename to packages/ast-spec/src/type/TSMappedType/fixtures/_error_/with-member-after/snapshots/1-Babel-Error.shot diff --git a/packages/ast-spec/src/type/TSMappedType/fixtures/_error_/with-member/snapshots/1-TSESTree-Error.shot b/packages/ast-spec/src/type/TSMappedType/fixtures/_error_/with-member-after/snapshots/1-TSESTree-Error.shot similarity index 90% rename from packages/ast-spec/src/type/TSMappedType/fixtures/_error_/with-member/snapshots/1-TSESTree-Error.shot rename to packages/ast-spec/src/type/TSMappedType/fixtures/_error_/with-member-after/snapshots/1-TSESTree-Error.shot index 744e922376a2..de0bae168fda 100644 --- a/packages/ast-spec/src/type/TSMappedType/fixtures/_error_/with-member/snapshots/1-TSESTree-Error.shot +++ b/packages/ast-spec/src/type/TSMappedType/fixtures/_error_/with-member-after/snapshots/1-TSESTree-Error.shot @@ -1,6 +1,6 @@ // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html -exports[`AST Fixtures > type > TSMappedType > _error_ > with-member > TSESTree - Error`] +exports[`AST Fixtures > type > TSMappedType > _error_ > with-member-after > TSESTree - Error`] TSError 1 | type Mapped = { 2 | [key in keyof O]: number; diff --git a/packages/ast-spec/src/type/TSMappedType/fixtures/_error_/with-member/snapshots/2-Alignment-Error.shot b/packages/ast-spec/src/type/TSMappedType/fixtures/_error_/with-member-after/snapshots/2-Alignment-Error.shot similarity index 100% rename from packages/ast-spec/src/type/TSMappedType/fixtures/_error_/with-member/snapshots/2-Alignment-Error.shot rename to packages/ast-spec/src/type/TSMappedType/fixtures/_error_/with-member-after/snapshots/2-Alignment-Error.shot diff --git a/packages/ast-spec/src/type/TSMappedType/fixtures/_error_/with-member/snapshots/2-Babel-Error.shot b/packages/ast-spec/src/type/TSMappedType/fixtures/_error_/with-member-after/snapshots/2-Babel-Error.shot similarity index 86% rename from packages/ast-spec/src/type/TSMappedType/fixtures/_error_/with-member/snapshots/2-Babel-Error.shot rename to packages/ast-spec/src/type/TSMappedType/fixtures/_error_/with-member-after/snapshots/2-Babel-Error.shot index 02ac78f26e15..9f5f417fcabd 100644 --- a/packages/ast-spec/src/type/TSMappedType/fixtures/_error_/with-member/snapshots/2-Babel-Error.shot +++ b/packages/ast-spec/src/type/TSMappedType/fixtures/_error_/with-member-after/snapshots/2-Babel-Error.shot @@ -1,4 +1,4 @@ // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html -exports[`AST Fixtures > type > TSMappedType > _error_ > with-member > Babel - Error`] +exports[`AST Fixtures > type > TSMappedType > _error_ > with-member-after > Babel - Error`] SyntaxError: Unexpected token, expected "}" (3:2) diff --git a/packages/ast-spec/src/type/TSMappedType/fixtures/_error_/with-member/snapshots/3-Alignment-Error.shot b/packages/ast-spec/src/type/TSMappedType/fixtures/_error_/with-member-after/snapshots/3-Alignment-Error.shot similarity index 82% rename from packages/ast-spec/src/type/TSMappedType/fixtures/_error_/with-member/snapshots/3-Alignment-Error.shot rename to packages/ast-spec/src/type/TSMappedType/fixtures/_error_/with-member-after/snapshots/3-Alignment-Error.shot index 356781d94e3d..bdbc90c17cb0 100644 --- a/packages/ast-spec/src/type/TSMappedType/fixtures/_error_/with-member/snapshots/3-Alignment-Error.shot +++ b/packages/ast-spec/src/type/TSMappedType/fixtures/_error_/with-member-after/snapshots/3-Alignment-Error.shot @@ -1,4 +1,4 @@ // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html -exports[`AST Fixtures > type > TSMappedType > _error_ > with-member > Error Alignment`] +exports[`AST Fixtures > type > TSMappedType > _error_ > with-member-after > Error Alignment`] Both errored diff --git a/packages/ast-spec/src/type/TSMappedType/fixtures/_error_/looks-like-mapped-type-but-with-members/fixture.ts b/packages/ast-spec/src/type/TSMappedType/fixtures/_error_/with-member-before/fixture.ts similarity index 100% rename from packages/ast-spec/src/type/TSMappedType/fixtures/_error_/looks-like-mapped-type-but-with-members/fixture.ts rename to packages/ast-spec/src/type/TSMappedType/fixtures/_error_/with-member-before/fixture.ts diff --git a/packages/ast-spec/src/type/TSMappedType/fixtures/_error_/looks-like-mapped-type-but-with-members/snapshots/1-Babel-Error.shot b/packages/ast-spec/src/type/TSMappedType/fixtures/_error_/with-member-before/snapshots/1-Babel-Error.shot similarity index 100% rename from packages/ast-spec/src/type/TSMappedType/fixtures/_error_/looks-like-mapped-type-but-with-members/snapshots/1-Babel-Error.shot rename to packages/ast-spec/src/type/TSMappedType/fixtures/_error_/with-member-before/snapshots/1-Babel-Error.shot diff --git a/packages/ast-spec/src/type/TSMappedType/fixtures/_error_/looks-like-mapped-type-but-with-members/snapshots/1-TSESTree-Error.shot b/packages/ast-spec/src/type/TSMappedType/fixtures/_error_/with-member-before/snapshots/1-TSESTree-Error.shot similarity index 63% rename from packages/ast-spec/src/type/TSMappedType/fixtures/_error_/looks-like-mapped-type-but-with-members/snapshots/1-TSESTree-Error.shot rename to packages/ast-spec/src/type/TSMappedType/fixtures/_error_/with-member-before/snapshots/1-TSESTree-Error.shot index 2c4ca093ca0a..34483c684ca8 100644 --- a/packages/ast-spec/src/type/TSMappedType/fixtures/_error_/looks-like-mapped-type-but-with-members/snapshots/1-TSESTree-Error.shot +++ b/packages/ast-spec/src/type/TSMappedType/fixtures/_error_/with-member-before/snapshots/1-TSESTree-Error.shot @@ -1,6 +1,6 @@ // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html -exports[`AST Fixtures > type > TSMappedType > _error_ > looks-like-mapped-type-but-with-members > TSESTree - Error`] +exports[`AST Fixtures > type > TSMappedType > _error_ > with-member-before > TSESTree - Error`] TSError 1 | type Mapped = { 2 | member: member; diff --git a/packages/ast-spec/src/type/TSMappedType/fixtures/_error_/looks-like-mapped-type-but-with-members/snapshots/2-Alignment-Error.shot b/packages/ast-spec/src/type/TSMappedType/fixtures/_error_/with-member-before/snapshots/2-Alignment-Error.shot similarity index 100% rename from packages/ast-spec/src/type/TSMappedType/fixtures/_error_/looks-like-mapped-type-but-with-members/snapshots/2-Alignment-Error.shot rename to packages/ast-spec/src/type/TSMappedType/fixtures/_error_/with-member-before/snapshots/2-Alignment-Error.shot diff --git a/packages/ast-spec/src/type/TSMappedType/fixtures/_error_/looks-like-mapped-type-but-with-members/snapshots/2-Babel-Error.shot b/packages/ast-spec/src/type/TSMappedType/fixtures/_error_/with-member-before/snapshots/2-Babel-Error.shot similarity index 50% rename from packages/ast-spec/src/type/TSMappedType/fixtures/_error_/looks-like-mapped-type-but-with-members/snapshots/2-Babel-Error.shot rename to packages/ast-spec/src/type/TSMappedType/fixtures/_error_/with-member-before/snapshots/2-Babel-Error.shot index bba41049c6c1..c1f120be3d57 100644 --- a/packages/ast-spec/src/type/TSMappedType/fixtures/_error_/looks-like-mapped-type-but-with-members/snapshots/2-Babel-Error.shot +++ b/packages/ast-spec/src/type/TSMappedType/fixtures/_error_/with-member-before/snapshots/2-Babel-Error.shot @@ -1,4 +1,4 @@ // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html -exports[`AST Fixtures > type > TSMappedType > _error_ > looks-like-mapped-type-but-with-members > Babel - Error`] +exports[`AST Fixtures > type > TSMappedType > _error_ > with-member-before > Babel - Error`] SyntaxError: Unexpected token, expected "]" (3:16) diff --git a/packages/ast-spec/src/type/TSMappedType/fixtures/_error_/with-member-before/snapshots/3-Alignment-Error.shot b/packages/ast-spec/src/type/TSMappedType/fixtures/_error_/with-member-before/snapshots/3-Alignment-Error.shot new file mode 100644 index 000000000000..117552d9c320 --- /dev/null +++ b/packages/ast-spec/src/type/TSMappedType/fixtures/_error_/with-member-before/snapshots/3-Alignment-Error.shot @@ -0,0 +1,4 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`AST Fixtures > type > TSMappedType > _error_ > with-member-before > Error Alignment`] +Both errored diff --git a/packages/ast-spec/src/type/TSMappedType/fixtures/no-modifiers/fixture.ts b/packages/ast-spec/src/type/TSMappedType/fixtures/no-modifiers/fixture.ts new file mode 100644 index 000000000000..f40ba5446116 --- /dev/null +++ b/packages/ast-spec/src/type/TSMappedType/fixtures/no-modifiers/fixture.ts @@ -0,0 +1,3 @@ +type T = { + [K in any]: any; +}; diff --git a/packages/ast-spec/src/type/TSMappedType/fixtures/no-modifiers/snapshots/1-TSESTree-AST.shot b/packages/ast-spec/src/type/TSMappedType/fixtures/no-modifiers/snapshots/1-TSESTree-AST.shot new file mode 100644 index 000000000000..d696e642a0fd --- /dev/null +++ b/packages/ast-spec/src/type/TSMappedType/fixtures/no-modifiers/snapshots/1-TSESTree-AST.shot @@ -0,0 +1,75 @@ +Program { + type: "Program", + body: [ + TSTypeAliasDeclaration { + type: "TSTypeAliasDeclaration", + declare: false, + id: Identifier { + type: "Identifier", + decorators: [], + name: "T", + optional: false, + + range: [5, 6], + loc: { + start: { column: 5, line: 1 }, + end: { column: 6, line: 1 }, + }, + }, + typeAnnotation: TSMappedType { + type: "TSMappedType", + constraint: TSAnyKeyword { + type: "TSAnyKeyword", + + range: [19, 22], + loc: { + start: { column: 8, line: 2 }, + end: { column: 11, line: 2 }, + }, + }, + key: Identifier { + type: "Identifier", + decorators: [], + name: "K", + optional: false, + + range: [14, 15], + loc: { + start: { column: 3, line: 2 }, + end: { column: 4, line: 2 }, + }, + }, + nameType: null, + optional: false, + typeAnnotation: TSAnyKeyword { + type: "TSAnyKeyword", + + range: [25, 28], + loc: { + start: { column: 14, line: 2 }, + end: { column: 17, line: 2 }, + }, + }, + + range: [9, 31], + loc: { + start: { column: 9, line: 1 }, + end: { column: 1, line: 3 }, + }, + }, + + range: [0, 32], + loc: { + start: { column: 0, line: 1 }, + end: { column: 2, line: 3 }, + }, + }, + ], + sourceType: "script", + + range: [0, 33], + loc: { + start: { column: 0, line: 1 }, + end: { column: 0, line: 4 }, + }, +} \ No newline at end of file diff --git a/packages/ast-spec/src/type/TSMappedType/fixtures/no-modifiers/snapshots/2-TSESTree-Tokens.shot b/packages/ast-spec/src/type/TSMappedType/fixtures/no-modifiers/snapshots/2-TSESTree-Tokens.shot new file mode 100644 index 000000000000..96a010ab783d --- /dev/null +++ b/packages/ast-spec/src/type/TSMappedType/fixtures/no-modifiers/snapshots/2-TSESTree-Tokens.shot @@ -0,0 +1,142 @@ +[ + Identifier { + type: "Identifier", + value: "type", + + range: [0, 4], + loc: { + start: { column: 0, line: 1 }, + end: { column: 4, line: 1 }, + }, + }, + Identifier { + type: "Identifier", + value: "T", + + range: [5, 6], + loc: { + start: { column: 5, line: 1 }, + end: { column: 6, line: 1 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "=", + + range: [7, 8], + loc: { + start: { column: 7, line: 1 }, + end: { column: 8, line: 1 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "{", + + range: [9, 10], + loc: { + start: { column: 9, line: 1 }, + end: { column: 10, line: 1 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "[", + + range: [13, 14], + loc: { + start: { column: 2, line: 2 }, + end: { column: 3, line: 2 }, + }, + }, + Identifier { + type: "Identifier", + value: "K", + + range: [14, 15], + loc: { + start: { column: 3, line: 2 }, + end: { column: 4, line: 2 }, + }, + }, + Keyword { + type: "Keyword", + value: "in", + + range: [16, 18], + loc: { + start: { column: 5, line: 2 }, + end: { column: 7, line: 2 }, + }, + }, + Identifier { + type: "Identifier", + value: "any", + + range: [19, 22], + loc: { + start: { column: 8, line: 2 }, + end: { column: 11, line: 2 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "]", + + range: [22, 23], + loc: { + start: { column: 11, line: 2 }, + end: { column: 12, line: 2 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ":", + + range: [23, 24], + loc: { + start: { column: 12, line: 2 }, + end: { column: 13, line: 2 }, + }, + }, + Identifier { + type: "Identifier", + value: "any", + + range: [25, 28], + loc: { + start: { column: 14, line: 2 }, + end: { column: 17, line: 2 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ";", + + range: [28, 29], + loc: { + start: { column: 17, line: 2 }, + end: { column: 18, line: 2 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "}", + + range: [30, 31], + loc: { + start: { column: 0, line: 3 }, + end: { column: 1, line: 3 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ";", + + range: [31, 32], + loc: { + start: { column: 1, line: 3 }, + end: { column: 2, line: 3 }, + }, + }, +] \ No newline at end of file diff --git a/packages/ast-spec/src/type/TSMappedType/fixtures/no-modifiers/snapshots/3-Babel-AST.shot b/packages/ast-spec/src/type/TSMappedType/fixtures/no-modifiers/snapshots/3-Babel-AST.shot new file mode 100644 index 000000000000..493867ad4561 --- /dev/null +++ b/packages/ast-spec/src/type/TSMappedType/fixtures/no-modifiers/snapshots/3-Babel-AST.shot @@ -0,0 +1,69 @@ +Program { + type: "Program", + body: [ + TSTypeAliasDeclaration { + type: "TSTypeAliasDeclaration", + id: Identifier { + type: "Identifier", + name: "T", + + range: [5, 6], + loc: { + start: { column: 5, line: 1 }, + end: { column: 6, line: 1 }, + }, + }, + typeAnnotation: TSMappedType { + type: "TSMappedType", + nameType: null, + typeAnnotation: TSAnyKeyword { + type: "TSAnyKeyword", + + range: [25, 28], + loc: { + start: { column: 14, line: 2 }, + end: { column: 17, line: 2 }, + }, + }, + typeParameter: TSTypeParameter { + type: "TSTypeParameter", + constraint: TSAnyKeyword { + type: "TSAnyKeyword", + + range: [19, 22], + loc: { + start: { column: 8, line: 2 }, + end: { column: 11, line: 2 }, + }, + }, + name: "K", + + range: [14, 22], + loc: { + start: { column: 3, line: 2 }, + end: { column: 11, line: 2 }, + }, + }, + + range: [9, 31], + loc: { + start: { column: 9, line: 1 }, + end: { column: 1, line: 3 }, + }, + }, + + range: [0, 32], + loc: { + start: { column: 0, line: 1 }, + end: { column: 2, line: 3 }, + }, + }, + ], + sourceType: "script", + + range: [0, 33], + loc: { + start: { column: 0, line: 1 }, + end: { column: 0, line: 4 }, + }, +} \ No newline at end of file diff --git a/packages/ast-spec/src/type/TSMappedType/fixtures/no-modifiers/snapshots/4-Babel-Tokens.shot b/packages/ast-spec/src/type/TSMappedType/fixtures/no-modifiers/snapshots/4-Babel-Tokens.shot new file mode 100644 index 000000000000..96a010ab783d --- /dev/null +++ b/packages/ast-spec/src/type/TSMappedType/fixtures/no-modifiers/snapshots/4-Babel-Tokens.shot @@ -0,0 +1,142 @@ +[ + Identifier { + type: "Identifier", + value: "type", + + range: [0, 4], + loc: { + start: { column: 0, line: 1 }, + end: { column: 4, line: 1 }, + }, + }, + Identifier { + type: "Identifier", + value: "T", + + range: [5, 6], + loc: { + start: { column: 5, line: 1 }, + end: { column: 6, line: 1 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "=", + + range: [7, 8], + loc: { + start: { column: 7, line: 1 }, + end: { column: 8, line: 1 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "{", + + range: [9, 10], + loc: { + start: { column: 9, line: 1 }, + end: { column: 10, line: 1 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "[", + + range: [13, 14], + loc: { + start: { column: 2, line: 2 }, + end: { column: 3, line: 2 }, + }, + }, + Identifier { + type: "Identifier", + value: "K", + + range: [14, 15], + loc: { + start: { column: 3, line: 2 }, + end: { column: 4, line: 2 }, + }, + }, + Keyword { + type: "Keyword", + value: "in", + + range: [16, 18], + loc: { + start: { column: 5, line: 2 }, + end: { column: 7, line: 2 }, + }, + }, + Identifier { + type: "Identifier", + value: "any", + + range: [19, 22], + loc: { + start: { column: 8, line: 2 }, + end: { column: 11, line: 2 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "]", + + range: [22, 23], + loc: { + start: { column: 11, line: 2 }, + end: { column: 12, line: 2 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ":", + + range: [23, 24], + loc: { + start: { column: 12, line: 2 }, + end: { column: 13, line: 2 }, + }, + }, + Identifier { + type: "Identifier", + value: "any", + + range: [25, 28], + loc: { + start: { column: 14, line: 2 }, + end: { column: 17, line: 2 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ";", + + range: [28, 29], + loc: { + start: { column: 17, line: 2 }, + end: { column: 18, line: 2 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "}", + + range: [30, 31], + loc: { + start: { column: 0, line: 3 }, + end: { column: 1, line: 3 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ";", + + range: [31, 32], + loc: { + start: { column: 1, line: 3 }, + end: { column: 2, line: 3 }, + }, + }, +] \ No newline at end of file diff --git a/packages/ast-spec/src/type/TSMappedType/fixtures/no-modifiers/snapshots/5-AST-Alignment-AST.shot b/packages/ast-spec/src/type/TSMappedType/fixtures/no-modifiers/snapshots/5-AST-Alignment-AST.shot new file mode 100644 index 000000000000..7690d33999d5 --- /dev/null +++ b/packages/ast-spec/src/type/TSMappedType/fixtures/no-modifiers/snapshots/5-AST-Alignment-AST.shot @@ -0,0 +1,100 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`AST Fixtures > type > TSMappedType > no-modifiers > AST Alignment - AST`] +Snapshot Diff: +- TSESTree ++ Babel + + Program { + type: 'Program', + body: Array [ + TSTypeAliasDeclaration { + type: 'TSTypeAliasDeclaration', +- declare: false, + id: Identifier { + type: 'Identifier', +- decorators: Array [], + name: 'T', +- optional: false, + + range: [5, 6], + loc: { + start: { column: 5, line: 1 }, + end: { column: 6, line: 1 }, + }, + }, + typeAnnotation: TSMappedType { + type: 'TSMappedType', +- constraint: TSAnyKeyword { ++ nameType: null, ++ typeAnnotation: TSAnyKeyword { + type: 'TSAnyKeyword', + +- range: [19, 22], ++ range: [25, 28], + loc: { +- start: { column: 8, line: 2 }, +- end: { column: 11, line: 2 }, ++ start: { column: 14, line: 2 }, ++ end: { column: 17, line: 2 }, + }, + }, +- key: Identifier { +- type: 'Identifier', +- decorators: Array [], ++ typeParameter: TSTypeParameter { ++ type: 'TSTypeParameter', ++ constraint: TSAnyKeyword { ++ type: 'TSAnyKeyword', ++ ++ range: [19, 22], ++ loc: { ++ start: { column: 8, line: 2 }, ++ end: { column: 11, line: 2 }, ++ }, ++ }, + name: 'K', +- optional: false, + +- range: [14, 15], ++ range: [14, 22], + loc: { + start: { column: 3, line: 2 }, +- end: { column: 4, line: 2 }, +- }, +- }, +- nameType: null, +- optional: false, +- typeAnnotation: TSAnyKeyword { +- type: 'TSAnyKeyword', +- +- range: [25, 28], +- loc: { +- start: { column: 14, line: 2 }, +- end: { column: 17, line: 2 }, ++ end: { column: 11, line: 2 }, + }, + }, + + range: [9, 31], + loc: { + start: { column: 9, line: 1 }, + end: { column: 1, line: 3 }, + }, + }, + + range: [0, 32], + loc: { + start: { column: 0, line: 1 }, + end: { column: 2, line: 3 }, + }, + }, + ], + sourceType: 'script', + + range: [0, 33], + loc: { + start: { column: 0, line: 1 }, + end: { column: 0, line: 4 }, + }, + } diff --git a/packages/ast-spec/src/type/TSMappedType/fixtures/no-modifiers/snapshots/6-AST-Alignment-Tokens.shot b/packages/ast-spec/src/type/TSMappedType/fixtures/no-modifiers/snapshots/6-AST-Alignment-Tokens.shot new file mode 100644 index 000000000000..abfcfdb9ba8d --- /dev/null +++ b/packages/ast-spec/src/type/TSMappedType/fixtures/no-modifiers/snapshots/6-AST-Alignment-Tokens.shot @@ -0,0 +1,5 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`AST Fixtures > type > TSMappedType > no-modifiers > AST Alignment - Token`] +Snapshot Diff: +Compared values have no visual difference. diff --git a/packages/ast-spec/src/type/TSMappedType/fixtures/optional-minus/fixture.ts b/packages/ast-spec/src/type/TSMappedType/fixtures/optional-minus/fixture.ts new file mode 100644 index 000000000000..f759cd13200d --- /dev/null +++ b/packages/ast-spec/src/type/TSMappedType/fixtures/optional-minus/fixture.ts @@ -0,0 +1,3 @@ +type T = { + [K in any]-?: any; +}; diff --git a/packages/ast-spec/src/type/TSMappedType/fixtures/optional-minus/snapshots/1-TSESTree-AST.shot b/packages/ast-spec/src/type/TSMappedType/fixtures/optional-minus/snapshots/1-TSESTree-AST.shot new file mode 100644 index 000000000000..ed550983f9fd --- /dev/null +++ b/packages/ast-spec/src/type/TSMappedType/fixtures/optional-minus/snapshots/1-TSESTree-AST.shot @@ -0,0 +1,75 @@ +Program { + type: "Program", + body: [ + TSTypeAliasDeclaration { + type: "TSTypeAliasDeclaration", + declare: false, + id: Identifier { + type: "Identifier", + decorators: [], + name: "T", + optional: false, + + range: [5, 6], + loc: { + start: { column: 5, line: 1 }, + end: { column: 6, line: 1 }, + }, + }, + typeAnnotation: TSMappedType { + type: "TSMappedType", + constraint: TSAnyKeyword { + type: "TSAnyKeyword", + + range: [19, 22], + loc: { + start: { column: 8, line: 2 }, + end: { column: 11, line: 2 }, + }, + }, + key: Identifier { + type: "Identifier", + decorators: [], + name: "K", + optional: false, + + range: [14, 15], + loc: { + start: { column: 3, line: 2 }, + end: { column: 4, line: 2 }, + }, + }, + nameType: null, + optional: "-", + typeAnnotation: TSAnyKeyword { + type: "TSAnyKeyword", + + range: [27, 30], + loc: { + start: { column: 16, line: 2 }, + end: { column: 19, line: 2 }, + }, + }, + + range: [9, 33], + loc: { + start: { column: 9, line: 1 }, + end: { column: 1, line: 3 }, + }, + }, + + range: [0, 34], + loc: { + start: { column: 0, line: 1 }, + end: { column: 2, line: 3 }, + }, + }, + ], + sourceType: "script", + + range: [0, 35], + loc: { + start: { column: 0, line: 1 }, + end: { column: 0, line: 4 }, + }, +} \ No newline at end of file diff --git a/packages/ast-spec/src/type/TSMappedType/fixtures/optional-minus/snapshots/2-TSESTree-Tokens.shot b/packages/ast-spec/src/type/TSMappedType/fixtures/optional-minus/snapshots/2-TSESTree-Tokens.shot new file mode 100644 index 000000000000..2d2ad113c249 --- /dev/null +++ b/packages/ast-spec/src/type/TSMappedType/fixtures/optional-minus/snapshots/2-TSESTree-Tokens.shot @@ -0,0 +1,162 @@ +[ + Identifier { + type: "Identifier", + value: "type", + + range: [0, 4], + loc: { + start: { column: 0, line: 1 }, + end: { column: 4, line: 1 }, + }, + }, + Identifier { + type: "Identifier", + value: "T", + + range: [5, 6], + loc: { + start: { column: 5, line: 1 }, + end: { column: 6, line: 1 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "=", + + range: [7, 8], + loc: { + start: { column: 7, line: 1 }, + end: { column: 8, line: 1 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "{", + + range: [9, 10], + loc: { + start: { column: 9, line: 1 }, + end: { column: 10, line: 1 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "[", + + range: [13, 14], + loc: { + start: { column: 2, line: 2 }, + end: { column: 3, line: 2 }, + }, + }, + Identifier { + type: "Identifier", + value: "K", + + range: [14, 15], + loc: { + start: { column: 3, line: 2 }, + end: { column: 4, line: 2 }, + }, + }, + Keyword { + type: "Keyword", + value: "in", + + range: [16, 18], + loc: { + start: { column: 5, line: 2 }, + end: { column: 7, line: 2 }, + }, + }, + Identifier { + type: "Identifier", + value: "any", + + range: [19, 22], + loc: { + start: { column: 8, line: 2 }, + end: { column: 11, line: 2 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "]", + + range: [22, 23], + loc: { + start: { column: 11, line: 2 }, + end: { column: 12, line: 2 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "-", + + range: [23, 24], + loc: { + start: { column: 12, line: 2 }, + end: { column: 13, line: 2 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "?", + + range: [24, 25], + loc: { + start: { column: 13, line: 2 }, + end: { column: 14, line: 2 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ":", + + range: [25, 26], + loc: { + start: { column: 14, line: 2 }, + end: { column: 15, line: 2 }, + }, + }, + Identifier { + type: "Identifier", + value: "any", + + range: [27, 30], + loc: { + start: { column: 16, line: 2 }, + end: { column: 19, line: 2 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ";", + + range: [30, 31], + loc: { + start: { column: 19, line: 2 }, + end: { column: 20, line: 2 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "}", + + range: [32, 33], + loc: { + start: { column: 0, line: 3 }, + end: { column: 1, line: 3 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ";", + + range: [33, 34], + loc: { + start: { column: 1, line: 3 }, + end: { column: 2, line: 3 }, + }, + }, +] \ No newline at end of file diff --git a/packages/ast-spec/src/type/TSMappedType/fixtures/optional-minus/snapshots/3-Babel-AST.shot b/packages/ast-spec/src/type/TSMappedType/fixtures/optional-minus/snapshots/3-Babel-AST.shot new file mode 100644 index 000000000000..089aec05bc1a --- /dev/null +++ b/packages/ast-spec/src/type/TSMappedType/fixtures/optional-minus/snapshots/3-Babel-AST.shot @@ -0,0 +1,70 @@ +Program { + type: "Program", + body: [ + TSTypeAliasDeclaration { + type: "TSTypeAliasDeclaration", + id: Identifier { + type: "Identifier", + name: "T", + + range: [5, 6], + loc: { + start: { column: 5, line: 1 }, + end: { column: 6, line: 1 }, + }, + }, + typeAnnotation: TSMappedType { + type: "TSMappedType", + nameType: null, + optional: "-", + typeAnnotation: TSAnyKeyword { + type: "TSAnyKeyword", + + range: [27, 30], + loc: { + start: { column: 16, line: 2 }, + end: { column: 19, line: 2 }, + }, + }, + typeParameter: TSTypeParameter { + type: "TSTypeParameter", + constraint: TSAnyKeyword { + type: "TSAnyKeyword", + + range: [19, 22], + loc: { + start: { column: 8, line: 2 }, + end: { column: 11, line: 2 }, + }, + }, + name: "K", + + range: [14, 22], + loc: { + start: { column: 3, line: 2 }, + end: { column: 11, line: 2 }, + }, + }, + + range: [9, 33], + loc: { + start: { column: 9, line: 1 }, + end: { column: 1, line: 3 }, + }, + }, + + range: [0, 34], + loc: { + start: { column: 0, line: 1 }, + end: { column: 2, line: 3 }, + }, + }, + ], + sourceType: "script", + + range: [0, 35], + loc: { + start: { column: 0, line: 1 }, + end: { column: 0, line: 4 }, + }, +} \ No newline at end of file diff --git a/packages/ast-spec/src/type/TSMappedType/fixtures/optional-minus/snapshots/4-Babel-Tokens.shot b/packages/ast-spec/src/type/TSMappedType/fixtures/optional-minus/snapshots/4-Babel-Tokens.shot new file mode 100644 index 000000000000..2d2ad113c249 --- /dev/null +++ b/packages/ast-spec/src/type/TSMappedType/fixtures/optional-minus/snapshots/4-Babel-Tokens.shot @@ -0,0 +1,162 @@ +[ + Identifier { + type: "Identifier", + value: "type", + + range: [0, 4], + loc: { + start: { column: 0, line: 1 }, + end: { column: 4, line: 1 }, + }, + }, + Identifier { + type: "Identifier", + value: "T", + + range: [5, 6], + loc: { + start: { column: 5, line: 1 }, + end: { column: 6, line: 1 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "=", + + range: [7, 8], + loc: { + start: { column: 7, line: 1 }, + end: { column: 8, line: 1 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "{", + + range: [9, 10], + loc: { + start: { column: 9, line: 1 }, + end: { column: 10, line: 1 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "[", + + range: [13, 14], + loc: { + start: { column: 2, line: 2 }, + end: { column: 3, line: 2 }, + }, + }, + Identifier { + type: "Identifier", + value: "K", + + range: [14, 15], + loc: { + start: { column: 3, line: 2 }, + end: { column: 4, line: 2 }, + }, + }, + Keyword { + type: "Keyword", + value: "in", + + range: [16, 18], + loc: { + start: { column: 5, line: 2 }, + end: { column: 7, line: 2 }, + }, + }, + Identifier { + type: "Identifier", + value: "any", + + range: [19, 22], + loc: { + start: { column: 8, line: 2 }, + end: { column: 11, line: 2 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "]", + + range: [22, 23], + loc: { + start: { column: 11, line: 2 }, + end: { column: 12, line: 2 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "-", + + range: [23, 24], + loc: { + start: { column: 12, line: 2 }, + end: { column: 13, line: 2 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "?", + + range: [24, 25], + loc: { + start: { column: 13, line: 2 }, + end: { column: 14, line: 2 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ":", + + range: [25, 26], + loc: { + start: { column: 14, line: 2 }, + end: { column: 15, line: 2 }, + }, + }, + Identifier { + type: "Identifier", + value: "any", + + range: [27, 30], + loc: { + start: { column: 16, line: 2 }, + end: { column: 19, line: 2 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ";", + + range: [30, 31], + loc: { + start: { column: 19, line: 2 }, + end: { column: 20, line: 2 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "}", + + range: [32, 33], + loc: { + start: { column: 0, line: 3 }, + end: { column: 1, line: 3 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ";", + + range: [33, 34], + loc: { + start: { column: 1, line: 3 }, + end: { column: 2, line: 3 }, + }, + }, +] \ No newline at end of file diff --git a/packages/ast-spec/src/type/TSMappedType/fixtures/optional-minus/snapshots/5-AST-Alignment-AST.shot b/packages/ast-spec/src/type/TSMappedType/fixtures/optional-minus/snapshots/5-AST-Alignment-AST.shot new file mode 100644 index 000000000000..866a68796a21 --- /dev/null +++ b/packages/ast-spec/src/type/TSMappedType/fixtures/optional-minus/snapshots/5-AST-Alignment-AST.shot @@ -0,0 +1,101 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`AST Fixtures > type > TSMappedType > optional-minus > AST Alignment - AST`] +Snapshot Diff: +- TSESTree ++ Babel + + Program { + type: 'Program', + body: Array [ + TSTypeAliasDeclaration { + type: 'TSTypeAliasDeclaration', +- declare: false, + id: Identifier { + type: 'Identifier', +- decorators: Array [], + name: 'T', +- optional: false, + + range: [5, 6], + loc: { + start: { column: 5, line: 1 }, + end: { column: 6, line: 1 }, + }, + }, + typeAnnotation: TSMappedType { + type: 'TSMappedType', +- constraint: TSAnyKeyword { +- type: 'TSAnyKeyword', +- +- range: [19, 22], +- loc: { +- start: { column: 8, line: 2 }, +- end: { column: 11, line: 2 }, +- }, +- }, +- key: Identifier { +- type: 'Identifier', +- decorators: Array [], +- name: 'K', +- optional: false, +- +- range: [14, 15], +- loc: { +- start: { column: 3, line: 2 }, +- end: { column: 4, line: 2 }, +- }, +- }, + nameType: null, + optional: '-', + typeAnnotation: TSAnyKeyword { + type: 'TSAnyKeyword', + + range: [27, 30], + loc: { + start: { column: 16, line: 2 }, + end: { column: 19, line: 2 }, ++ }, ++ }, ++ typeParameter: TSTypeParameter { ++ type: 'TSTypeParameter', ++ constraint: TSAnyKeyword { ++ type: 'TSAnyKeyword', ++ ++ range: [19, 22], ++ loc: { ++ start: { column: 8, line: 2 }, ++ end: { column: 11, line: 2 }, ++ }, ++ }, ++ name: 'K', ++ ++ range: [14, 22], ++ loc: { ++ start: { column: 3, line: 2 }, ++ end: { column: 11, line: 2 }, + }, + }, + + range: [9, 33], + loc: { + start: { column: 9, line: 1 }, + end: { column: 1, line: 3 }, + }, + }, + + range: [0, 34], + loc: { + start: { column: 0, line: 1 }, + end: { column: 2, line: 3 }, + }, + }, + ], + sourceType: 'script', + + range: [0, 35], + loc: { + start: { column: 0, line: 1 }, + end: { column: 0, line: 4 }, + }, + } diff --git a/packages/ast-spec/src/type/TSMappedType/fixtures/optional-minus/snapshots/6-AST-Alignment-Tokens.shot b/packages/ast-spec/src/type/TSMappedType/fixtures/optional-minus/snapshots/6-AST-Alignment-Tokens.shot new file mode 100644 index 000000000000..e1adf4d8ccec --- /dev/null +++ b/packages/ast-spec/src/type/TSMappedType/fixtures/optional-minus/snapshots/6-AST-Alignment-Tokens.shot @@ -0,0 +1,5 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`AST Fixtures > type > TSMappedType > optional-minus > AST Alignment - Token`] +Snapshot Diff: +Compared values have no visual difference. diff --git a/packages/ast-spec/src/type/TSMappedType/fixtures/optional-plus/fixture.ts b/packages/ast-spec/src/type/TSMappedType/fixtures/optional-plus/fixture.ts new file mode 100644 index 000000000000..3ba522247e25 --- /dev/null +++ b/packages/ast-spec/src/type/TSMappedType/fixtures/optional-plus/fixture.ts @@ -0,0 +1,3 @@ +type T = { + [K in any]+?: any; +}; diff --git a/packages/ast-spec/src/type/TSMappedType/fixtures/optional-plus/snapshots/1-TSESTree-AST.shot b/packages/ast-spec/src/type/TSMappedType/fixtures/optional-plus/snapshots/1-TSESTree-AST.shot new file mode 100644 index 000000000000..7ab20722ff01 --- /dev/null +++ b/packages/ast-spec/src/type/TSMappedType/fixtures/optional-plus/snapshots/1-TSESTree-AST.shot @@ -0,0 +1,75 @@ +Program { + type: "Program", + body: [ + TSTypeAliasDeclaration { + type: "TSTypeAliasDeclaration", + declare: false, + id: Identifier { + type: "Identifier", + decorators: [], + name: "T", + optional: false, + + range: [5, 6], + loc: { + start: { column: 5, line: 1 }, + end: { column: 6, line: 1 }, + }, + }, + typeAnnotation: TSMappedType { + type: "TSMappedType", + constraint: TSAnyKeyword { + type: "TSAnyKeyword", + + range: [19, 22], + loc: { + start: { column: 8, line: 2 }, + end: { column: 11, line: 2 }, + }, + }, + key: Identifier { + type: "Identifier", + decorators: [], + name: "K", + optional: false, + + range: [14, 15], + loc: { + start: { column: 3, line: 2 }, + end: { column: 4, line: 2 }, + }, + }, + nameType: null, + optional: "+", + typeAnnotation: TSAnyKeyword { + type: "TSAnyKeyword", + + range: [27, 30], + loc: { + start: { column: 16, line: 2 }, + end: { column: 19, line: 2 }, + }, + }, + + range: [9, 33], + loc: { + start: { column: 9, line: 1 }, + end: { column: 1, line: 3 }, + }, + }, + + range: [0, 34], + loc: { + start: { column: 0, line: 1 }, + end: { column: 2, line: 3 }, + }, + }, + ], + sourceType: "script", + + range: [0, 35], + loc: { + start: { column: 0, line: 1 }, + end: { column: 0, line: 4 }, + }, +} \ No newline at end of file diff --git a/packages/ast-spec/src/type/TSMappedType/fixtures/optional-plus/snapshots/2-TSESTree-Tokens.shot b/packages/ast-spec/src/type/TSMappedType/fixtures/optional-plus/snapshots/2-TSESTree-Tokens.shot new file mode 100644 index 000000000000..4e4960266005 --- /dev/null +++ b/packages/ast-spec/src/type/TSMappedType/fixtures/optional-plus/snapshots/2-TSESTree-Tokens.shot @@ -0,0 +1,162 @@ +[ + Identifier { + type: "Identifier", + value: "type", + + range: [0, 4], + loc: { + start: { column: 0, line: 1 }, + end: { column: 4, line: 1 }, + }, + }, + Identifier { + type: "Identifier", + value: "T", + + range: [5, 6], + loc: { + start: { column: 5, line: 1 }, + end: { column: 6, line: 1 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "=", + + range: [7, 8], + loc: { + start: { column: 7, line: 1 }, + end: { column: 8, line: 1 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "{", + + range: [9, 10], + loc: { + start: { column: 9, line: 1 }, + end: { column: 10, line: 1 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "[", + + range: [13, 14], + loc: { + start: { column: 2, line: 2 }, + end: { column: 3, line: 2 }, + }, + }, + Identifier { + type: "Identifier", + value: "K", + + range: [14, 15], + loc: { + start: { column: 3, line: 2 }, + end: { column: 4, line: 2 }, + }, + }, + Keyword { + type: "Keyword", + value: "in", + + range: [16, 18], + loc: { + start: { column: 5, line: 2 }, + end: { column: 7, line: 2 }, + }, + }, + Identifier { + type: "Identifier", + value: "any", + + range: [19, 22], + loc: { + start: { column: 8, line: 2 }, + end: { column: 11, line: 2 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "]", + + range: [22, 23], + loc: { + start: { column: 11, line: 2 }, + end: { column: 12, line: 2 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "+", + + range: [23, 24], + loc: { + start: { column: 12, line: 2 }, + end: { column: 13, line: 2 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "?", + + range: [24, 25], + loc: { + start: { column: 13, line: 2 }, + end: { column: 14, line: 2 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ":", + + range: [25, 26], + loc: { + start: { column: 14, line: 2 }, + end: { column: 15, line: 2 }, + }, + }, + Identifier { + type: "Identifier", + value: "any", + + range: [27, 30], + loc: { + start: { column: 16, line: 2 }, + end: { column: 19, line: 2 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ";", + + range: [30, 31], + loc: { + start: { column: 19, line: 2 }, + end: { column: 20, line: 2 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "}", + + range: [32, 33], + loc: { + start: { column: 0, line: 3 }, + end: { column: 1, line: 3 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ";", + + range: [33, 34], + loc: { + start: { column: 1, line: 3 }, + end: { column: 2, line: 3 }, + }, + }, +] \ No newline at end of file diff --git a/packages/ast-spec/src/type/TSMappedType/fixtures/optional-plus/snapshots/3-Babel-AST.shot b/packages/ast-spec/src/type/TSMappedType/fixtures/optional-plus/snapshots/3-Babel-AST.shot new file mode 100644 index 000000000000..a53f741d7671 --- /dev/null +++ b/packages/ast-spec/src/type/TSMappedType/fixtures/optional-plus/snapshots/3-Babel-AST.shot @@ -0,0 +1,70 @@ +Program { + type: "Program", + body: [ + TSTypeAliasDeclaration { + type: "TSTypeAliasDeclaration", + id: Identifier { + type: "Identifier", + name: "T", + + range: [5, 6], + loc: { + start: { column: 5, line: 1 }, + end: { column: 6, line: 1 }, + }, + }, + typeAnnotation: TSMappedType { + type: "TSMappedType", + nameType: null, + optional: "+", + typeAnnotation: TSAnyKeyword { + type: "TSAnyKeyword", + + range: [27, 30], + loc: { + start: { column: 16, line: 2 }, + end: { column: 19, line: 2 }, + }, + }, + typeParameter: TSTypeParameter { + type: "TSTypeParameter", + constraint: TSAnyKeyword { + type: "TSAnyKeyword", + + range: [19, 22], + loc: { + start: { column: 8, line: 2 }, + end: { column: 11, line: 2 }, + }, + }, + name: "K", + + range: [14, 22], + loc: { + start: { column: 3, line: 2 }, + end: { column: 11, line: 2 }, + }, + }, + + range: [9, 33], + loc: { + start: { column: 9, line: 1 }, + end: { column: 1, line: 3 }, + }, + }, + + range: [0, 34], + loc: { + start: { column: 0, line: 1 }, + end: { column: 2, line: 3 }, + }, + }, + ], + sourceType: "script", + + range: [0, 35], + loc: { + start: { column: 0, line: 1 }, + end: { column: 0, line: 4 }, + }, +} \ No newline at end of file diff --git a/packages/ast-spec/src/type/TSMappedType/fixtures/optional-plus/snapshots/4-Babel-Tokens.shot b/packages/ast-spec/src/type/TSMappedType/fixtures/optional-plus/snapshots/4-Babel-Tokens.shot new file mode 100644 index 000000000000..4e4960266005 --- /dev/null +++ b/packages/ast-spec/src/type/TSMappedType/fixtures/optional-plus/snapshots/4-Babel-Tokens.shot @@ -0,0 +1,162 @@ +[ + Identifier { + type: "Identifier", + value: "type", + + range: [0, 4], + loc: { + start: { column: 0, line: 1 }, + end: { column: 4, line: 1 }, + }, + }, + Identifier { + type: "Identifier", + value: "T", + + range: [5, 6], + loc: { + start: { column: 5, line: 1 }, + end: { column: 6, line: 1 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "=", + + range: [7, 8], + loc: { + start: { column: 7, line: 1 }, + end: { column: 8, line: 1 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "{", + + range: [9, 10], + loc: { + start: { column: 9, line: 1 }, + end: { column: 10, line: 1 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "[", + + range: [13, 14], + loc: { + start: { column: 2, line: 2 }, + end: { column: 3, line: 2 }, + }, + }, + Identifier { + type: "Identifier", + value: "K", + + range: [14, 15], + loc: { + start: { column: 3, line: 2 }, + end: { column: 4, line: 2 }, + }, + }, + Keyword { + type: "Keyword", + value: "in", + + range: [16, 18], + loc: { + start: { column: 5, line: 2 }, + end: { column: 7, line: 2 }, + }, + }, + Identifier { + type: "Identifier", + value: "any", + + range: [19, 22], + loc: { + start: { column: 8, line: 2 }, + end: { column: 11, line: 2 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "]", + + range: [22, 23], + loc: { + start: { column: 11, line: 2 }, + end: { column: 12, line: 2 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "+", + + range: [23, 24], + loc: { + start: { column: 12, line: 2 }, + end: { column: 13, line: 2 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "?", + + range: [24, 25], + loc: { + start: { column: 13, line: 2 }, + end: { column: 14, line: 2 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ":", + + range: [25, 26], + loc: { + start: { column: 14, line: 2 }, + end: { column: 15, line: 2 }, + }, + }, + Identifier { + type: "Identifier", + value: "any", + + range: [27, 30], + loc: { + start: { column: 16, line: 2 }, + end: { column: 19, line: 2 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ";", + + range: [30, 31], + loc: { + start: { column: 19, line: 2 }, + end: { column: 20, line: 2 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "}", + + range: [32, 33], + loc: { + start: { column: 0, line: 3 }, + end: { column: 1, line: 3 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ";", + + range: [33, 34], + loc: { + start: { column: 1, line: 3 }, + end: { column: 2, line: 3 }, + }, + }, +] \ No newline at end of file diff --git a/packages/ast-spec/src/type/TSMappedType/fixtures/optional-plus/snapshots/5-AST-Alignment-AST.shot b/packages/ast-spec/src/type/TSMappedType/fixtures/optional-plus/snapshots/5-AST-Alignment-AST.shot new file mode 100644 index 000000000000..0af20518c5ac --- /dev/null +++ b/packages/ast-spec/src/type/TSMappedType/fixtures/optional-plus/snapshots/5-AST-Alignment-AST.shot @@ -0,0 +1,101 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`AST Fixtures > type > TSMappedType > optional-plus > AST Alignment - AST`] +Snapshot Diff: +- TSESTree ++ Babel + + Program { + type: 'Program', + body: Array [ + TSTypeAliasDeclaration { + type: 'TSTypeAliasDeclaration', +- declare: false, + id: Identifier { + type: 'Identifier', +- decorators: Array [], + name: 'T', +- optional: false, + + range: [5, 6], + loc: { + start: { column: 5, line: 1 }, + end: { column: 6, line: 1 }, + }, + }, + typeAnnotation: TSMappedType { + type: 'TSMappedType', +- constraint: TSAnyKeyword { +- type: 'TSAnyKeyword', +- +- range: [19, 22], +- loc: { +- start: { column: 8, line: 2 }, +- end: { column: 11, line: 2 }, +- }, +- }, +- key: Identifier { +- type: 'Identifier', +- decorators: Array [], +- name: 'K', +- optional: false, +- +- range: [14, 15], +- loc: { +- start: { column: 3, line: 2 }, +- end: { column: 4, line: 2 }, +- }, +- }, + nameType: null, + optional: '+', + typeAnnotation: TSAnyKeyword { + type: 'TSAnyKeyword', + + range: [27, 30], + loc: { + start: { column: 16, line: 2 }, + end: { column: 19, line: 2 }, ++ }, ++ }, ++ typeParameter: TSTypeParameter { ++ type: 'TSTypeParameter', ++ constraint: TSAnyKeyword { ++ type: 'TSAnyKeyword', ++ ++ range: [19, 22], ++ loc: { ++ start: { column: 8, line: 2 }, ++ end: { column: 11, line: 2 }, ++ }, ++ }, ++ name: 'K', ++ ++ range: [14, 22], ++ loc: { ++ start: { column: 3, line: 2 }, ++ end: { column: 11, line: 2 }, + }, + }, + + range: [9, 33], + loc: { + start: { column: 9, line: 1 }, + end: { column: 1, line: 3 }, + }, + }, + + range: [0, 34], + loc: { + start: { column: 0, line: 1 }, + end: { column: 2, line: 3 }, + }, + }, + ], + sourceType: 'script', + + range: [0, 35], + loc: { + start: { column: 0, line: 1 }, + end: { column: 0, line: 4 }, + }, + } diff --git a/packages/ast-spec/src/type/TSMappedType/fixtures/optional-plus/snapshots/6-AST-Alignment-Tokens.shot b/packages/ast-spec/src/type/TSMappedType/fixtures/optional-plus/snapshots/6-AST-Alignment-Tokens.shot new file mode 100644 index 000000000000..cf0536defdec --- /dev/null +++ b/packages/ast-spec/src/type/TSMappedType/fixtures/optional-plus/snapshots/6-AST-Alignment-Tokens.shot @@ -0,0 +1,5 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`AST Fixtures > type > TSMappedType > optional-plus > AST Alignment - Token`] +Snapshot Diff: +Compared values have no visual difference. diff --git a/packages/ast-spec/src/type/TSMappedType/fixtures/optional/fixture.ts b/packages/ast-spec/src/type/TSMappedType/fixtures/optional/fixture.ts new file mode 100644 index 000000000000..4296694ae99a --- /dev/null +++ b/packages/ast-spec/src/type/TSMappedType/fixtures/optional/fixture.ts @@ -0,0 +1,3 @@ +type T = { + [K in any]?: any; +}; diff --git a/packages/ast-spec/src/type/TSMappedType/fixtures/optional/snapshots/1-TSESTree-AST.shot b/packages/ast-spec/src/type/TSMappedType/fixtures/optional/snapshots/1-TSESTree-AST.shot new file mode 100644 index 000000000000..ec3bc8ac20f9 --- /dev/null +++ b/packages/ast-spec/src/type/TSMappedType/fixtures/optional/snapshots/1-TSESTree-AST.shot @@ -0,0 +1,75 @@ +Program { + type: "Program", + body: [ + TSTypeAliasDeclaration { + type: "TSTypeAliasDeclaration", + declare: false, + id: Identifier { + type: "Identifier", + decorators: [], + name: "T", + optional: false, + + range: [5, 6], + loc: { + start: { column: 5, line: 1 }, + end: { column: 6, line: 1 }, + }, + }, + typeAnnotation: TSMappedType { + type: "TSMappedType", + constraint: TSAnyKeyword { + type: "TSAnyKeyword", + + range: [19, 22], + loc: { + start: { column: 8, line: 2 }, + end: { column: 11, line: 2 }, + }, + }, + key: Identifier { + type: "Identifier", + decorators: [], + name: "K", + optional: false, + + range: [14, 15], + loc: { + start: { column: 3, line: 2 }, + end: { column: 4, line: 2 }, + }, + }, + nameType: null, + optional: true, + typeAnnotation: TSAnyKeyword { + type: "TSAnyKeyword", + + range: [26, 29], + loc: { + start: { column: 15, line: 2 }, + end: { column: 18, line: 2 }, + }, + }, + + range: [9, 32], + loc: { + start: { column: 9, line: 1 }, + end: { column: 1, line: 3 }, + }, + }, + + range: [0, 33], + loc: { + start: { column: 0, line: 1 }, + end: { column: 2, line: 3 }, + }, + }, + ], + sourceType: "script", + + range: [0, 34], + loc: { + start: { column: 0, line: 1 }, + end: { column: 0, line: 4 }, + }, +} \ No newline at end of file diff --git a/packages/ast-spec/src/type/TSMappedType/fixtures/optional/snapshots/2-TSESTree-Tokens.shot b/packages/ast-spec/src/type/TSMappedType/fixtures/optional/snapshots/2-TSESTree-Tokens.shot new file mode 100644 index 000000000000..1ca17e133643 --- /dev/null +++ b/packages/ast-spec/src/type/TSMappedType/fixtures/optional/snapshots/2-TSESTree-Tokens.shot @@ -0,0 +1,152 @@ +[ + Identifier { + type: "Identifier", + value: "type", + + range: [0, 4], + loc: { + start: { column: 0, line: 1 }, + end: { column: 4, line: 1 }, + }, + }, + Identifier { + type: "Identifier", + value: "T", + + range: [5, 6], + loc: { + start: { column: 5, line: 1 }, + end: { column: 6, line: 1 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "=", + + range: [7, 8], + loc: { + start: { column: 7, line: 1 }, + end: { column: 8, line: 1 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "{", + + range: [9, 10], + loc: { + start: { column: 9, line: 1 }, + end: { column: 10, line: 1 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "[", + + range: [13, 14], + loc: { + start: { column: 2, line: 2 }, + end: { column: 3, line: 2 }, + }, + }, + Identifier { + type: "Identifier", + value: "K", + + range: [14, 15], + loc: { + start: { column: 3, line: 2 }, + end: { column: 4, line: 2 }, + }, + }, + Keyword { + type: "Keyword", + value: "in", + + range: [16, 18], + loc: { + start: { column: 5, line: 2 }, + end: { column: 7, line: 2 }, + }, + }, + Identifier { + type: "Identifier", + value: "any", + + range: [19, 22], + loc: { + start: { column: 8, line: 2 }, + end: { column: 11, line: 2 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "]", + + range: [22, 23], + loc: { + start: { column: 11, line: 2 }, + end: { column: 12, line: 2 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "?", + + range: [23, 24], + loc: { + start: { column: 12, line: 2 }, + end: { column: 13, line: 2 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ":", + + range: [24, 25], + loc: { + start: { column: 13, line: 2 }, + end: { column: 14, line: 2 }, + }, + }, + Identifier { + type: "Identifier", + value: "any", + + range: [26, 29], + loc: { + start: { column: 15, line: 2 }, + end: { column: 18, line: 2 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ";", + + range: [29, 30], + loc: { + start: { column: 18, line: 2 }, + end: { column: 19, line: 2 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "}", + + range: [31, 32], + loc: { + start: { column: 0, line: 3 }, + end: { column: 1, line: 3 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ";", + + range: [32, 33], + loc: { + start: { column: 1, line: 3 }, + end: { column: 2, line: 3 }, + }, + }, +] \ No newline at end of file diff --git a/packages/ast-spec/src/type/TSMappedType/fixtures/optional/snapshots/3-Babel-AST.shot b/packages/ast-spec/src/type/TSMappedType/fixtures/optional/snapshots/3-Babel-AST.shot new file mode 100644 index 000000000000..951124f0703f --- /dev/null +++ b/packages/ast-spec/src/type/TSMappedType/fixtures/optional/snapshots/3-Babel-AST.shot @@ -0,0 +1,70 @@ +Program { + type: "Program", + body: [ + TSTypeAliasDeclaration { + type: "TSTypeAliasDeclaration", + id: Identifier { + type: "Identifier", + name: "T", + + range: [5, 6], + loc: { + start: { column: 5, line: 1 }, + end: { column: 6, line: 1 }, + }, + }, + typeAnnotation: TSMappedType { + type: "TSMappedType", + nameType: null, + optional: true, + typeAnnotation: TSAnyKeyword { + type: "TSAnyKeyword", + + range: [26, 29], + loc: { + start: { column: 15, line: 2 }, + end: { column: 18, line: 2 }, + }, + }, + typeParameter: TSTypeParameter { + type: "TSTypeParameter", + constraint: TSAnyKeyword { + type: "TSAnyKeyword", + + range: [19, 22], + loc: { + start: { column: 8, line: 2 }, + end: { column: 11, line: 2 }, + }, + }, + name: "K", + + range: [14, 22], + loc: { + start: { column: 3, line: 2 }, + end: { column: 11, line: 2 }, + }, + }, + + range: [9, 32], + loc: { + start: { column: 9, line: 1 }, + end: { column: 1, line: 3 }, + }, + }, + + range: [0, 33], + loc: { + start: { column: 0, line: 1 }, + end: { column: 2, line: 3 }, + }, + }, + ], + sourceType: "script", + + range: [0, 34], + loc: { + start: { column: 0, line: 1 }, + end: { column: 0, line: 4 }, + }, +} \ No newline at end of file diff --git a/packages/ast-spec/src/type/TSMappedType/fixtures/optional/snapshots/4-Babel-Tokens.shot b/packages/ast-spec/src/type/TSMappedType/fixtures/optional/snapshots/4-Babel-Tokens.shot new file mode 100644 index 000000000000..1ca17e133643 --- /dev/null +++ b/packages/ast-spec/src/type/TSMappedType/fixtures/optional/snapshots/4-Babel-Tokens.shot @@ -0,0 +1,152 @@ +[ + Identifier { + type: "Identifier", + value: "type", + + range: [0, 4], + loc: { + start: { column: 0, line: 1 }, + end: { column: 4, line: 1 }, + }, + }, + Identifier { + type: "Identifier", + value: "T", + + range: [5, 6], + loc: { + start: { column: 5, line: 1 }, + end: { column: 6, line: 1 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "=", + + range: [7, 8], + loc: { + start: { column: 7, line: 1 }, + end: { column: 8, line: 1 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "{", + + range: [9, 10], + loc: { + start: { column: 9, line: 1 }, + end: { column: 10, line: 1 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "[", + + range: [13, 14], + loc: { + start: { column: 2, line: 2 }, + end: { column: 3, line: 2 }, + }, + }, + Identifier { + type: "Identifier", + value: "K", + + range: [14, 15], + loc: { + start: { column: 3, line: 2 }, + end: { column: 4, line: 2 }, + }, + }, + Keyword { + type: "Keyword", + value: "in", + + range: [16, 18], + loc: { + start: { column: 5, line: 2 }, + end: { column: 7, line: 2 }, + }, + }, + Identifier { + type: "Identifier", + value: "any", + + range: [19, 22], + loc: { + start: { column: 8, line: 2 }, + end: { column: 11, line: 2 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "]", + + range: [22, 23], + loc: { + start: { column: 11, line: 2 }, + end: { column: 12, line: 2 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "?", + + range: [23, 24], + loc: { + start: { column: 12, line: 2 }, + end: { column: 13, line: 2 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ":", + + range: [24, 25], + loc: { + start: { column: 13, line: 2 }, + end: { column: 14, line: 2 }, + }, + }, + Identifier { + type: "Identifier", + value: "any", + + range: [26, 29], + loc: { + start: { column: 15, line: 2 }, + end: { column: 18, line: 2 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ";", + + range: [29, 30], + loc: { + start: { column: 18, line: 2 }, + end: { column: 19, line: 2 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "}", + + range: [31, 32], + loc: { + start: { column: 0, line: 3 }, + end: { column: 1, line: 3 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ";", + + range: [32, 33], + loc: { + start: { column: 1, line: 3 }, + end: { column: 2, line: 3 }, + }, + }, +] \ No newline at end of file diff --git a/packages/ast-spec/src/type/TSMappedType/fixtures/optional/snapshots/5-AST-Alignment-AST.shot b/packages/ast-spec/src/type/TSMappedType/fixtures/optional/snapshots/5-AST-Alignment-AST.shot new file mode 100644 index 000000000000..4ce829da2429 --- /dev/null +++ b/packages/ast-spec/src/type/TSMappedType/fixtures/optional/snapshots/5-AST-Alignment-AST.shot @@ -0,0 +1,101 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`AST Fixtures > type > TSMappedType > optional > AST Alignment - AST`] +Snapshot Diff: +- TSESTree ++ Babel + + Program { + type: 'Program', + body: Array [ + TSTypeAliasDeclaration { + type: 'TSTypeAliasDeclaration', +- declare: false, + id: Identifier { + type: 'Identifier', +- decorators: Array [], + name: 'T', +- optional: false, + + range: [5, 6], + loc: { + start: { column: 5, line: 1 }, + end: { column: 6, line: 1 }, + }, + }, + typeAnnotation: TSMappedType { + type: 'TSMappedType', +- constraint: TSAnyKeyword { +- type: 'TSAnyKeyword', +- +- range: [19, 22], +- loc: { +- start: { column: 8, line: 2 }, +- end: { column: 11, line: 2 }, +- }, +- }, +- key: Identifier { +- type: 'Identifier', +- decorators: Array [], +- name: 'K', +- optional: false, +- +- range: [14, 15], +- loc: { +- start: { column: 3, line: 2 }, +- end: { column: 4, line: 2 }, +- }, +- }, + nameType: null, + optional: true, + typeAnnotation: TSAnyKeyword { + type: 'TSAnyKeyword', + + range: [26, 29], + loc: { + start: { column: 15, line: 2 }, + end: { column: 18, line: 2 }, ++ }, ++ }, ++ typeParameter: TSTypeParameter { ++ type: 'TSTypeParameter', ++ constraint: TSAnyKeyword { ++ type: 'TSAnyKeyword', ++ ++ range: [19, 22], ++ loc: { ++ start: { column: 8, line: 2 }, ++ end: { column: 11, line: 2 }, ++ }, ++ }, ++ name: 'K', ++ ++ range: [14, 22], ++ loc: { ++ start: { column: 3, line: 2 }, ++ end: { column: 11, line: 2 }, + }, + }, + + range: [9, 32], + loc: { + start: { column: 9, line: 1 }, + end: { column: 1, line: 3 }, + }, + }, + + range: [0, 33], + loc: { + start: { column: 0, line: 1 }, + end: { column: 2, line: 3 }, + }, + }, + ], + sourceType: 'script', + + range: [0, 34], + loc: { + start: { column: 0, line: 1 }, + end: { column: 0, line: 4 }, + }, + } diff --git a/packages/ast-spec/src/type/TSMappedType/fixtures/optional/snapshots/6-AST-Alignment-Tokens.shot b/packages/ast-spec/src/type/TSMappedType/fixtures/optional/snapshots/6-AST-Alignment-Tokens.shot new file mode 100644 index 000000000000..91ebb5abdd6d --- /dev/null +++ b/packages/ast-spec/src/type/TSMappedType/fixtures/optional/snapshots/6-AST-Alignment-Tokens.shot @@ -0,0 +1,5 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`AST Fixtures > type > TSMappedType > optional > AST Alignment - Token`] +Snapshot Diff: +Compared values have no visual difference. diff --git a/packages/ast-spec/src/type/TSMappedType/fixtures/readonly-minus/fixture.ts b/packages/ast-spec/src/type/TSMappedType/fixtures/readonly-minus/fixture.ts new file mode 100644 index 000000000000..5303452d1094 --- /dev/null +++ b/packages/ast-spec/src/type/TSMappedType/fixtures/readonly-minus/fixture.ts @@ -0,0 +1,3 @@ +type ReadonlyOptional = { + -readonly [P in string]?: number; +}; diff --git a/packages/ast-spec/src/type/TSMappedType/fixtures/readonly-minus/snapshots/1-TSESTree-AST.shot b/packages/ast-spec/src/type/TSMappedType/fixtures/readonly-minus/snapshots/1-TSESTree-AST.shot new file mode 100644 index 000000000000..76b04f7c6f1c --- /dev/null +++ b/packages/ast-spec/src/type/TSMappedType/fixtures/readonly-minus/snapshots/1-TSESTree-AST.shot @@ -0,0 +1,76 @@ +Program { + type: "Program", + body: [ + TSTypeAliasDeclaration { + type: "TSTypeAliasDeclaration", + declare: false, + id: Identifier { + type: "Identifier", + decorators: [], + name: "ReadonlyOptional", + optional: false, + + range: [5, 21], + loc: { + start: { column: 5, line: 1 }, + end: { column: 21, line: 1 }, + }, + }, + typeAnnotation: TSMappedType { + type: "TSMappedType", + constraint: TSStringKeyword { + type: "TSStringKeyword", + + range: [44, 50], + loc: { + start: { column: 18, line: 2 }, + end: { column: 24, line: 2 }, + }, + }, + key: Identifier { + type: "Identifier", + decorators: [], + name: "P", + optional: false, + + range: [39, 40], + loc: { + start: { column: 13, line: 2 }, + end: { column: 14, line: 2 }, + }, + }, + nameType: null, + optional: true, + readonly: "-", + typeAnnotation: TSNumberKeyword { + type: "TSNumberKeyword", + + range: [54, 60], + loc: { + start: { column: 28, line: 2 }, + end: { column: 34, line: 2 }, + }, + }, + + range: [24, 63], + loc: { + start: { column: 24, line: 1 }, + end: { column: 1, line: 3 }, + }, + }, + + range: [0, 64], + loc: { + start: { column: 0, line: 1 }, + end: { column: 2, line: 3 }, + }, + }, + ], + sourceType: "script", + + range: [0, 65], + loc: { + start: { column: 0, line: 1 }, + end: { column: 0, line: 4 }, + }, +} \ No newline at end of file diff --git a/packages/ast-spec/src/type/TSMappedType/fixtures/readonly-minus/snapshots/2-TSESTree-Tokens.shot b/packages/ast-spec/src/type/TSMappedType/fixtures/readonly-minus/snapshots/2-TSESTree-Tokens.shot new file mode 100644 index 000000000000..1d219ddc3a3b --- /dev/null +++ b/packages/ast-spec/src/type/TSMappedType/fixtures/readonly-minus/snapshots/2-TSESTree-Tokens.shot @@ -0,0 +1,172 @@ +[ + Identifier { + type: "Identifier", + value: "type", + + range: [0, 4], + loc: { + start: { column: 0, line: 1 }, + end: { column: 4, line: 1 }, + }, + }, + Identifier { + type: "Identifier", + value: "ReadonlyOptional", + + range: [5, 21], + loc: { + start: { column: 5, line: 1 }, + end: { column: 21, line: 1 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "=", + + range: [22, 23], + loc: { + start: { column: 22, line: 1 }, + end: { column: 23, line: 1 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "{", + + range: [24, 25], + loc: { + start: { column: 24, line: 1 }, + end: { column: 25, line: 1 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "-", + + range: [28, 29], + loc: { + start: { column: 2, line: 2 }, + end: { column: 3, line: 2 }, + }, + }, + Identifier { + type: "Identifier", + value: "readonly", + + range: [29, 37], + loc: { + start: { column: 3, line: 2 }, + end: { column: 11, line: 2 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "[", + + range: [38, 39], + loc: { + start: { column: 12, line: 2 }, + end: { column: 13, line: 2 }, + }, + }, + Identifier { + type: "Identifier", + value: "P", + + range: [39, 40], + loc: { + start: { column: 13, line: 2 }, + end: { column: 14, line: 2 }, + }, + }, + Keyword { + type: "Keyword", + value: "in", + + range: [41, 43], + loc: { + start: { column: 15, line: 2 }, + end: { column: 17, line: 2 }, + }, + }, + Identifier { + type: "Identifier", + value: "string", + + range: [44, 50], + loc: { + start: { column: 18, line: 2 }, + end: { column: 24, line: 2 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "]", + + range: [50, 51], + loc: { + start: { column: 24, line: 2 }, + end: { column: 25, line: 2 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "?", + + range: [51, 52], + loc: { + start: { column: 25, line: 2 }, + end: { column: 26, line: 2 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ":", + + range: [52, 53], + loc: { + start: { column: 26, line: 2 }, + end: { column: 27, line: 2 }, + }, + }, + Identifier { + type: "Identifier", + value: "number", + + range: [54, 60], + loc: { + start: { column: 28, line: 2 }, + end: { column: 34, line: 2 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ";", + + range: [60, 61], + loc: { + start: { column: 34, line: 2 }, + end: { column: 35, line: 2 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "}", + + range: [62, 63], + loc: { + start: { column: 0, line: 3 }, + end: { column: 1, line: 3 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ";", + + range: [63, 64], + loc: { + start: { column: 1, line: 3 }, + end: { column: 2, line: 3 }, + }, + }, +] \ No newline at end of file diff --git a/packages/ast-spec/src/type/TSMappedType/fixtures/readonly-minus/snapshots/3-Babel-AST.shot b/packages/ast-spec/src/type/TSMappedType/fixtures/readonly-minus/snapshots/3-Babel-AST.shot new file mode 100644 index 000000000000..4520f235a393 --- /dev/null +++ b/packages/ast-spec/src/type/TSMappedType/fixtures/readonly-minus/snapshots/3-Babel-AST.shot @@ -0,0 +1,71 @@ +Program { + type: "Program", + body: [ + TSTypeAliasDeclaration { + type: "TSTypeAliasDeclaration", + id: Identifier { + type: "Identifier", + name: "ReadonlyOptional", + + range: [5, 21], + loc: { + start: { column: 5, line: 1 }, + end: { column: 21, line: 1 }, + }, + }, + typeAnnotation: TSMappedType { + type: "TSMappedType", + nameType: null, + optional: true, + readonly: "-", + typeAnnotation: TSNumberKeyword { + type: "TSNumberKeyword", + + range: [54, 60], + loc: { + start: { column: 28, line: 2 }, + end: { column: 34, line: 2 }, + }, + }, + typeParameter: TSTypeParameter { + type: "TSTypeParameter", + constraint: TSStringKeyword { + type: "TSStringKeyword", + + range: [44, 50], + loc: { + start: { column: 18, line: 2 }, + end: { column: 24, line: 2 }, + }, + }, + name: "P", + + range: [39, 50], + loc: { + start: { column: 13, line: 2 }, + end: { column: 24, line: 2 }, + }, + }, + + range: [24, 63], + loc: { + start: { column: 24, line: 1 }, + end: { column: 1, line: 3 }, + }, + }, + + range: [0, 64], + loc: { + start: { column: 0, line: 1 }, + end: { column: 2, line: 3 }, + }, + }, + ], + sourceType: "script", + + range: [0, 65], + loc: { + start: { column: 0, line: 1 }, + end: { column: 0, line: 4 }, + }, +} \ No newline at end of file diff --git a/packages/ast-spec/src/type/TSMappedType/fixtures/readonly-minus/snapshots/4-Babel-Tokens.shot b/packages/ast-spec/src/type/TSMappedType/fixtures/readonly-minus/snapshots/4-Babel-Tokens.shot new file mode 100644 index 000000000000..1d219ddc3a3b --- /dev/null +++ b/packages/ast-spec/src/type/TSMappedType/fixtures/readonly-minus/snapshots/4-Babel-Tokens.shot @@ -0,0 +1,172 @@ +[ + Identifier { + type: "Identifier", + value: "type", + + range: [0, 4], + loc: { + start: { column: 0, line: 1 }, + end: { column: 4, line: 1 }, + }, + }, + Identifier { + type: "Identifier", + value: "ReadonlyOptional", + + range: [5, 21], + loc: { + start: { column: 5, line: 1 }, + end: { column: 21, line: 1 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "=", + + range: [22, 23], + loc: { + start: { column: 22, line: 1 }, + end: { column: 23, line: 1 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "{", + + range: [24, 25], + loc: { + start: { column: 24, line: 1 }, + end: { column: 25, line: 1 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "-", + + range: [28, 29], + loc: { + start: { column: 2, line: 2 }, + end: { column: 3, line: 2 }, + }, + }, + Identifier { + type: "Identifier", + value: "readonly", + + range: [29, 37], + loc: { + start: { column: 3, line: 2 }, + end: { column: 11, line: 2 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "[", + + range: [38, 39], + loc: { + start: { column: 12, line: 2 }, + end: { column: 13, line: 2 }, + }, + }, + Identifier { + type: "Identifier", + value: "P", + + range: [39, 40], + loc: { + start: { column: 13, line: 2 }, + end: { column: 14, line: 2 }, + }, + }, + Keyword { + type: "Keyword", + value: "in", + + range: [41, 43], + loc: { + start: { column: 15, line: 2 }, + end: { column: 17, line: 2 }, + }, + }, + Identifier { + type: "Identifier", + value: "string", + + range: [44, 50], + loc: { + start: { column: 18, line: 2 }, + end: { column: 24, line: 2 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "]", + + range: [50, 51], + loc: { + start: { column: 24, line: 2 }, + end: { column: 25, line: 2 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "?", + + range: [51, 52], + loc: { + start: { column: 25, line: 2 }, + end: { column: 26, line: 2 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ":", + + range: [52, 53], + loc: { + start: { column: 26, line: 2 }, + end: { column: 27, line: 2 }, + }, + }, + Identifier { + type: "Identifier", + value: "number", + + range: [54, 60], + loc: { + start: { column: 28, line: 2 }, + end: { column: 34, line: 2 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ";", + + range: [60, 61], + loc: { + start: { column: 34, line: 2 }, + end: { column: 35, line: 2 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "}", + + range: [62, 63], + loc: { + start: { column: 0, line: 3 }, + end: { column: 1, line: 3 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ";", + + range: [63, 64], + loc: { + start: { column: 1, line: 3 }, + end: { column: 2, line: 3 }, + }, + }, +] \ No newline at end of file diff --git a/packages/ast-spec/src/type/TSMappedType/fixtures/readonly-minus/snapshots/5-AST-Alignment-AST.shot b/packages/ast-spec/src/type/TSMappedType/fixtures/readonly-minus/snapshots/5-AST-Alignment-AST.shot new file mode 100644 index 000000000000..00517798d7d1 --- /dev/null +++ b/packages/ast-spec/src/type/TSMappedType/fixtures/readonly-minus/snapshots/5-AST-Alignment-AST.shot @@ -0,0 +1,102 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`AST Fixtures > type > TSMappedType > readonly-minus > AST Alignment - AST`] +Snapshot Diff: +- TSESTree ++ Babel + + Program { + type: 'Program', + body: Array [ + TSTypeAliasDeclaration { + type: 'TSTypeAliasDeclaration', +- declare: false, + id: Identifier { + type: 'Identifier', +- decorators: Array [], + name: 'ReadonlyOptional', +- optional: false, + + range: [5, 21], + loc: { + start: { column: 5, line: 1 }, + end: { column: 21, line: 1 }, + }, + }, + typeAnnotation: TSMappedType { + type: 'TSMappedType', +- constraint: TSStringKeyword { +- type: 'TSStringKeyword', +- +- range: [44, 50], +- loc: { +- start: { column: 18, line: 2 }, +- end: { column: 24, line: 2 }, +- }, +- }, +- key: Identifier { +- type: 'Identifier', +- decorators: Array [], +- name: 'P', +- optional: false, +- +- range: [39, 40], +- loc: { +- start: { column: 13, line: 2 }, +- end: { column: 14, line: 2 }, +- }, +- }, + nameType: null, + optional: true, + readonly: '-', + typeAnnotation: TSNumberKeyword { + type: 'TSNumberKeyword', + + range: [54, 60], + loc: { + start: { column: 28, line: 2 }, + end: { column: 34, line: 2 }, ++ }, ++ }, ++ typeParameter: TSTypeParameter { ++ type: 'TSTypeParameter', ++ constraint: TSStringKeyword { ++ type: 'TSStringKeyword', ++ ++ range: [44, 50], ++ loc: { ++ start: { column: 18, line: 2 }, ++ end: { column: 24, line: 2 }, ++ }, ++ }, ++ name: 'P', ++ ++ range: [39, 50], ++ loc: { ++ start: { column: 13, line: 2 }, ++ end: { column: 24, line: 2 }, + }, + }, + + range: [24, 63], + loc: { + start: { column: 24, line: 1 }, + end: { column: 1, line: 3 }, + }, + }, + + range: [0, 64], + loc: { + start: { column: 0, line: 1 }, + end: { column: 2, line: 3 }, + }, + }, + ], + sourceType: 'script', + + range: [0, 65], + loc: { + start: { column: 0, line: 1 }, + end: { column: 0, line: 4 }, + }, + } diff --git a/packages/ast-spec/src/type/TSMappedType/fixtures/readonly-minus/snapshots/6-AST-Alignment-Tokens.shot b/packages/ast-spec/src/type/TSMappedType/fixtures/readonly-minus/snapshots/6-AST-Alignment-Tokens.shot new file mode 100644 index 000000000000..baa98a4a57bc --- /dev/null +++ b/packages/ast-spec/src/type/TSMappedType/fixtures/readonly-minus/snapshots/6-AST-Alignment-Tokens.shot @@ -0,0 +1,5 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`AST Fixtures > type > TSMappedType > readonly-minus > AST Alignment - Token`] +Snapshot Diff: +Compared values have no visual difference. diff --git a/packages/ast-spec/src/type/TSMappedType/fixtures/readonly-optional/fixture.ts b/packages/ast-spec/src/type/TSMappedType/fixtures/readonly-optional/fixture.ts new file mode 100644 index 000000000000..3d965c3064c2 --- /dev/null +++ b/packages/ast-spec/src/type/TSMappedType/fixtures/readonly-optional/fixture.ts @@ -0,0 +1,3 @@ +type ReadonlyOptional = { + readonly [P in string]: number; +}; diff --git a/packages/ast-spec/src/type/TSMappedType/fixtures/readonly-optional/snapshots/1-TSESTree-AST.shot b/packages/ast-spec/src/type/TSMappedType/fixtures/readonly-optional/snapshots/1-TSESTree-AST.shot new file mode 100644 index 000000000000..139d4e56d96f --- /dev/null +++ b/packages/ast-spec/src/type/TSMappedType/fixtures/readonly-optional/snapshots/1-TSESTree-AST.shot @@ -0,0 +1,76 @@ +Program { + type: "Program", + body: [ + TSTypeAliasDeclaration { + type: "TSTypeAliasDeclaration", + declare: false, + id: Identifier { + type: "Identifier", + decorators: [], + name: "ReadonlyOptional", + optional: false, + + range: [5, 21], + loc: { + start: { column: 5, line: 1 }, + end: { column: 21, line: 1 }, + }, + }, + typeAnnotation: TSMappedType { + type: "TSMappedType", + constraint: TSStringKeyword { + type: "TSStringKeyword", + + range: [43, 49], + loc: { + start: { column: 17, line: 2 }, + end: { column: 23, line: 2 }, + }, + }, + key: Identifier { + type: "Identifier", + decorators: [], + name: "P", + optional: false, + + range: [38, 39], + loc: { + start: { column: 12, line: 2 }, + end: { column: 13, line: 2 }, + }, + }, + nameType: null, + optional: false, + readonly: true, + typeAnnotation: TSNumberKeyword { + type: "TSNumberKeyword", + + range: [52, 58], + loc: { + start: { column: 26, line: 2 }, + end: { column: 32, line: 2 }, + }, + }, + + range: [24, 61], + loc: { + start: { column: 24, line: 1 }, + end: { column: 1, line: 3 }, + }, + }, + + range: [0, 62], + loc: { + start: { column: 0, line: 1 }, + end: { column: 2, line: 3 }, + }, + }, + ], + sourceType: "script", + + range: [0, 63], + loc: { + start: { column: 0, line: 1 }, + end: { column: 0, line: 4 }, + }, +} \ No newline at end of file diff --git a/packages/ast-spec/src/type/TSMappedType/fixtures/readonly-optional/snapshots/2-TSESTree-Tokens.shot b/packages/ast-spec/src/type/TSMappedType/fixtures/readonly-optional/snapshots/2-TSESTree-Tokens.shot new file mode 100644 index 000000000000..93d054f69131 --- /dev/null +++ b/packages/ast-spec/src/type/TSMappedType/fixtures/readonly-optional/snapshots/2-TSESTree-Tokens.shot @@ -0,0 +1,152 @@ +[ + Identifier { + type: "Identifier", + value: "type", + + range: [0, 4], + loc: { + start: { column: 0, line: 1 }, + end: { column: 4, line: 1 }, + }, + }, + Identifier { + type: "Identifier", + value: "ReadonlyOptional", + + range: [5, 21], + loc: { + start: { column: 5, line: 1 }, + end: { column: 21, line: 1 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "=", + + range: [22, 23], + loc: { + start: { column: 22, line: 1 }, + end: { column: 23, line: 1 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "{", + + range: [24, 25], + loc: { + start: { column: 24, line: 1 }, + end: { column: 25, line: 1 }, + }, + }, + Identifier { + type: "Identifier", + value: "readonly", + + range: [28, 36], + loc: { + start: { column: 2, line: 2 }, + end: { column: 10, line: 2 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "[", + + range: [37, 38], + loc: { + start: { column: 11, line: 2 }, + end: { column: 12, line: 2 }, + }, + }, + Identifier { + type: "Identifier", + value: "P", + + range: [38, 39], + loc: { + start: { column: 12, line: 2 }, + end: { column: 13, line: 2 }, + }, + }, + Keyword { + type: "Keyword", + value: "in", + + range: [40, 42], + loc: { + start: { column: 14, line: 2 }, + end: { column: 16, line: 2 }, + }, + }, + Identifier { + type: "Identifier", + value: "string", + + range: [43, 49], + loc: { + start: { column: 17, line: 2 }, + end: { column: 23, line: 2 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "]", + + range: [49, 50], + loc: { + start: { column: 23, line: 2 }, + end: { column: 24, line: 2 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ":", + + range: [50, 51], + loc: { + start: { column: 24, line: 2 }, + end: { column: 25, line: 2 }, + }, + }, + Identifier { + type: "Identifier", + value: "number", + + range: [52, 58], + loc: { + start: { column: 26, line: 2 }, + end: { column: 32, line: 2 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ";", + + range: [58, 59], + loc: { + start: { column: 32, line: 2 }, + end: { column: 33, line: 2 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "}", + + range: [60, 61], + loc: { + start: { column: 0, line: 3 }, + end: { column: 1, line: 3 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ";", + + range: [61, 62], + loc: { + start: { column: 1, line: 3 }, + end: { column: 2, line: 3 }, + }, + }, +] \ No newline at end of file diff --git a/packages/ast-spec/src/type/TSMappedType/fixtures/readonly-optional/snapshots/3-Babel-AST.shot b/packages/ast-spec/src/type/TSMappedType/fixtures/readonly-optional/snapshots/3-Babel-AST.shot new file mode 100644 index 000000000000..11605a809d58 --- /dev/null +++ b/packages/ast-spec/src/type/TSMappedType/fixtures/readonly-optional/snapshots/3-Babel-AST.shot @@ -0,0 +1,70 @@ +Program { + type: "Program", + body: [ + TSTypeAliasDeclaration { + type: "TSTypeAliasDeclaration", + id: Identifier { + type: "Identifier", + name: "ReadonlyOptional", + + range: [5, 21], + loc: { + start: { column: 5, line: 1 }, + end: { column: 21, line: 1 }, + }, + }, + typeAnnotation: TSMappedType { + type: "TSMappedType", + nameType: null, + readonly: true, + typeAnnotation: TSNumberKeyword { + type: "TSNumberKeyword", + + range: [52, 58], + loc: { + start: { column: 26, line: 2 }, + end: { column: 32, line: 2 }, + }, + }, + typeParameter: TSTypeParameter { + type: "TSTypeParameter", + constraint: TSStringKeyword { + type: "TSStringKeyword", + + range: [43, 49], + loc: { + start: { column: 17, line: 2 }, + end: { column: 23, line: 2 }, + }, + }, + name: "P", + + range: [38, 49], + loc: { + start: { column: 12, line: 2 }, + end: { column: 23, line: 2 }, + }, + }, + + range: [24, 61], + loc: { + start: { column: 24, line: 1 }, + end: { column: 1, line: 3 }, + }, + }, + + range: [0, 62], + loc: { + start: { column: 0, line: 1 }, + end: { column: 2, line: 3 }, + }, + }, + ], + sourceType: "script", + + range: [0, 63], + loc: { + start: { column: 0, line: 1 }, + end: { column: 0, line: 4 }, + }, +} \ No newline at end of file diff --git a/packages/ast-spec/src/type/TSMappedType/fixtures/readonly-optional/snapshots/4-Babel-Tokens.shot b/packages/ast-spec/src/type/TSMappedType/fixtures/readonly-optional/snapshots/4-Babel-Tokens.shot new file mode 100644 index 000000000000..93d054f69131 --- /dev/null +++ b/packages/ast-spec/src/type/TSMappedType/fixtures/readonly-optional/snapshots/4-Babel-Tokens.shot @@ -0,0 +1,152 @@ +[ + Identifier { + type: "Identifier", + value: "type", + + range: [0, 4], + loc: { + start: { column: 0, line: 1 }, + end: { column: 4, line: 1 }, + }, + }, + Identifier { + type: "Identifier", + value: "ReadonlyOptional", + + range: [5, 21], + loc: { + start: { column: 5, line: 1 }, + end: { column: 21, line: 1 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "=", + + range: [22, 23], + loc: { + start: { column: 22, line: 1 }, + end: { column: 23, line: 1 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "{", + + range: [24, 25], + loc: { + start: { column: 24, line: 1 }, + end: { column: 25, line: 1 }, + }, + }, + Identifier { + type: "Identifier", + value: "readonly", + + range: [28, 36], + loc: { + start: { column: 2, line: 2 }, + end: { column: 10, line: 2 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "[", + + range: [37, 38], + loc: { + start: { column: 11, line: 2 }, + end: { column: 12, line: 2 }, + }, + }, + Identifier { + type: "Identifier", + value: "P", + + range: [38, 39], + loc: { + start: { column: 12, line: 2 }, + end: { column: 13, line: 2 }, + }, + }, + Keyword { + type: "Keyword", + value: "in", + + range: [40, 42], + loc: { + start: { column: 14, line: 2 }, + end: { column: 16, line: 2 }, + }, + }, + Identifier { + type: "Identifier", + value: "string", + + range: [43, 49], + loc: { + start: { column: 17, line: 2 }, + end: { column: 23, line: 2 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "]", + + range: [49, 50], + loc: { + start: { column: 23, line: 2 }, + end: { column: 24, line: 2 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ":", + + range: [50, 51], + loc: { + start: { column: 24, line: 2 }, + end: { column: 25, line: 2 }, + }, + }, + Identifier { + type: "Identifier", + value: "number", + + range: [52, 58], + loc: { + start: { column: 26, line: 2 }, + end: { column: 32, line: 2 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ";", + + range: [58, 59], + loc: { + start: { column: 32, line: 2 }, + end: { column: 33, line: 2 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "}", + + range: [60, 61], + loc: { + start: { column: 0, line: 3 }, + end: { column: 1, line: 3 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ";", + + range: [61, 62], + loc: { + start: { column: 1, line: 3 }, + end: { column: 2, line: 3 }, + }, + }, +] \ No newline at end of file diff --git a/packages/ast-spec/src/type/TSMappedType/fixtures/readonly-optional/snapshots/5-AST-Alignment-AST.shot b/packages/ast-spec/src/type/TSMappedType/fixtures/readonly-optional/snapshots/5-AST-Alignment-AST.shot new file mode 100644 index 000000000000..4a9202d4d905 --- /dev/null +++ b/packages/ast-spec/src/type/TSMappedType/fixtures/readonly-optional/snapshots/5-AST-Alignment-AST.shot @@ -0,0 +1,102 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`AST Fixtures > type > TSMappedType > readonly-optional > AST Alignment - AST`] +Snapshot Diff: +- TSESTree ++ Babel + + Program { + type: 'Program', + body: Array [ + TSTypeAliasDeclaration { + type: 'TSTypeAliasDeclaration', +- declare: false, + id: Identifier { + type: 'Identifier', +- decorators: Array [], + name: 'ReadonlyOptional', +- optional: false, + + range: [5, 21], + loc: { + start: { column: 5, line: 1 }, + end: { column: 21, line: 1 }, + }, + }, + typeAnnotation: TSMappedType { + type: 'TSMappedType', +- constraint: TSStringKeyword { +- type: 'TSStringKeyword', +- +- range: [43, 49], +- loc: { +- start: { column: 17, line: 2 }, +- end: { column: 23, line: 2 }, +- }, +- }, +- key: Identifier { +- type: 'Identifier', +- decorators: Array [], +- name: 'P', +- optional: false, +- +- range: [38, 39], +- loc: { +- start: { column: 12, line: 2 }, +- end: { column: 13, line: 2 }, +- }, +- }, + nameType: null, +- optional: false, + readonly: true, + typeAnnotation: TSNumberKeyword { + type: 'TSNumberKeyword', + + range: [52, 58], + loc: { + start: { column: 26, line: 2 }, + end: { column: 32, line: 2 }, ++ }, ++ }, ++ typeParameter: TSTypeParameter { ++ type: 'TSTypeParameter', ++ constraint: TSStringKeyword { ++ type: 'TSStringKeyword', ++ ++ range: [43, 49], ++ loc: { ++ start: { column: 17, line: 2 }, ++ end: { column: 23, line: 2 }, ++ }, ++ }, ++ name: 'P', ++ ++ range: [38, 49], ++ loc: { ++ start: { column: 12, line: 2 }, ++ end: { column: 23, line: 2 }, + }, + }, + + range: [24, 61], + loc: { + start: { column: 24, line: 1 }, + end: { column: 1, line: 3 }, + }, + }, + + range: [0, 62], + loc: { + start: { column: 0, line: 1 }, + end: { column: 2, line: 3 }, + }, + }, + ], + sourceType: 'script', + + range: [0, 63], + loc: { + start: { column: 0, line: 1 }, + end: { column: 0, line: 4 }, + }, + } diff --git a/packages/ast-spec/src/type/TSMappedType/fixtures/readonly-optional/snapshots/6-AST-Alignment-Tokens.shot b/packages/ast-spec/src/type/TSMappedType/fixtures/readonly-optional/snapshots/6-AST-Alignment-Tokens.shot new file mode 100644 index 000000000000..06340f1bf562 --- /dev/null +++ b/packages/ast-spec/src/type/TSMappedType/fixtures/readonly-optional/snapshots/6-AST-Alignment-Tokens.shot @@ -0,0 +1,5 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`AST Fixtures > type > TSMappedType > readonly-optional > AST Alignment - Token`] +Snapshot Diff: +Compared values have no visual difference. diff --git a/packages/ast-spec/src/type/TSMappedType/fixtures/readonly-plus/fixture.ts b/packages/ast-spec/src/type/TSMappedType/fixtures/readonly-plus/fixture.ts new file mode 100644 index 000000000000..cac84c242209 --- /dev/null +++ b/packages/ast-spec/src/type/TSMappedType/fixtures/readonly-plus/fixture.ts @@ -0,0 +1,3 @@ +type PlusReadonly = { + +readonly [P in string]: number; +}; diff --git a/packages/ast-spec/src/type/TSMappedType/fixtures/readonly-plus/snapshots/1-TSESTree-AST.shot b/packages/ast-spec/src/type/TSMappedType/fixtures/readonly-plus/snapshots/1-TSESTree-AST.shot new file mode 100644 index 000000000000..cd70d426838d --- /dev/null +++ b/packages/ast-spec/src/type/TSMappedType/fixtures/readonly-plus/snapshots/1-TSESTree-AST.shot @@ -0,0 +1,76 @@ +Program { + type: "Program", + body: [ + TSTypeAliasDeclaration { + type: "TSTypeAliasDeclaration", + declare: false, + id: Identifier { + type: "Identifier", + decorators: [], + name: "PlusReadonly", + optional: false, + + range: [5, 17], + loc: { + start: { column: 5, line: 1 }, + end: { column: 17, line: 1 }, + }, + }, + typeAnnotation: TSMappedType { + type: "TSMappedType", + constraint: TSStringKeyword { + type: "TSStringKeyword", + + range: [40, 46], + loc: { + start: { column: 18, line: 2 }, + end: { column: 24, line: 2 }, + }, + }, + key: Identifier { + type: "Identifier", + decorators: [], + name: "P", + optional: false, + + range: [35, 36], + loc: { + start: { column: 13, line: 2 }, + end: { column: 14, line: 2 }, + }, + }, + nameType: null, + optional: false, + readonly: "+", + typeAnnotation: TSNumberKeyword { + type: "TSNumberKeyword", + + range: [49, 55], + loc: { + start: { column: 27, line: 2 }, + end: { column: 33, line: 2 }, + }, + }, + + range: [20, 58], + loc: { + start: { column: 20, line: 1 }, + end: { column: 1, line: 3 }, + }, + }, + + range: [0, 59], + loc: { + start: { column: 0, line: 1 }, + end: { column: 2, line: 3 }, + }, + }, + ], + sourceType: "script", + + range: [0, 60], + loc: { + start: { column: 0, line: 1 }, + end: { column: 0, line: 4 }, + }, +} \ No newline at end of file diff --git a/packages/ast-spec/src/type/TSMappedType/fixtures/readonly-plus/snapshots/2-TSESTree-Tokens.shot b/packages/ast-spec/src/type/TSMappedType/fixtures/readonly-plus/snapshots/2-TSESTree-Tokens.shot new file mode 100644 index 000000000000..6705b1f3585f --- /dev/null +++ b/packages/ast-spec/src/type/TSMappedType/fixtures/readonly-plus/snapshots/2-TSESTree-Tokens.shot @@ -0,0 +1,162 @@ +[ + Identifier { + type: "Identifier", + value: "type", + + range: [0, 4], + loc: { + start: { column: 0, line: 1 }, + end: { column: 4, line: 1 }, + }, + }, + Identifier { + type: "Identifier", + value: "PlusReadonly", + + range: [5, 17], + loc: { + start: { column: 5, line: 1 }, + end: { column: 17, line: 1 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "=", + + range: [18, 19], + loc: { + start: { column: 18, line: 1 }, + end: { column: 19, line: 1 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "{", + + range: [20, 21], + loc: { + start: { column: 20, line: 1 }, + end: { column: 21, line: 1 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "+", + + range: [24, 25], + loc: { + start: { column: 2, line: 2 }, + end: { column: 3, line: 2 }, + }, + }, + Identifier { + type: "Identifier", + value: "readonly", + + range: [25, 33], + loc: { + start: { column: 3, line: 2 }, + end: { column: 11, line: 2 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "[", + + range: [34, 35], + loc: { + start: { column: 12, line: 2 }, + end: { column: 13, line: 2 }, + }, + }, + Identifier { + type: "Identifier", + value: "P", + + range: [35, 36], + loc: { + start: { column: 13, line: 2 }, + end: { column: 14, line: 2 }, + }, + }, + Keyword { + type: "Keyword", + value: "in", + + range: [37, 39], + loc: { + start: { column: 15, line: 2 }, + end: { column: 17, line: 2 }, + }, + }, + Identifier { + type: "Identifier", + value: "string", + + range: [40, 46], + loc: { + start: { column: 18, line: 2 }, + end: { column: 24, line: 2 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "]", + + range: [46, 47], + loc: { + start: { column: 24, line: 2 }, + end: { column: 25, line: 2 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ":", + + range: [47, 48], + loc: { + start: { column: 25, line: 2 }, + end: { column: 26, line: 2 }, + }, + }, + Identifier { + type: "Identifier", + value: "number", + + range: [49, 55], + loc: { + start: { column: 27, line: 2 }, + end: { column: 33, line: 2 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ";", + + range: [55, 56], + loc: { + start: { column: 33, line: 2 }, + end: { column: 34, line: 2 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "}", + + range: [57, 58], + loc: { + start: { column: 0, line: 3 }, + end: { column: 1, line: 3 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ";", + + range: [58, 59], + loc: { + start: { column: 1, line: 3 }, + end: { column: 2, line: 3 }, + }, + }, +] \ No newline at end of file diff --git a/packages/ast-spec/src/type/TSMappedType/fixtures/readonly-plus/snapshots/3-Babel-AST.shot b/packages/ast-spec/src/type/TSMappedType/fixtures/readonly-plus/snapshots/3-Babel-AST.shot new file mode 100644 index 000000000000..cf6c86c51b3b --- /dev/null +++ b/packages/ast-spec/src/type/TSMappedType/fixtures/readonly-plus/snapshots/3-Babel-AST.shot @@ -0,0 +1,70 @@ +Program { + type: "Program", + body: [ + TSTypeAliasDeclaration { + type: "TSTypeAliasDeclaration", + id: Identifier { + type: "Identifier", + name: "PlusReadonly", + + range: [5, 17], + loc: { + start: { column: 5, line: 1 }, + end: { column: 17, line: 1 }, + }, + }, + typeAnnotation: TSMappedType { + type: "TSMappedType", + nameType: null, + readonly: "+", + typeAnnotation: TSNumberKeyword { + type: "TSNumberKeyword", + + range: [49, 55], + loc: { + start: { column: 27, line: 2 }, + end: { column: 33, line: 2 }, + }, + }, + typeParameter: TSTypeParameter { + type: "TSTypeParameter", + constraint: TSStringKeyword { + type: "TSStringKeyword", + + range: [40, 46], + loc: { + start: { column: 18, line: 2 }, + end: { column: 24, line: 2 }, + }, + }, + name: "P", + + range: [35, 46], + loc: { + start: { column: 13, line: 2 }, + end: { column: 24, line: 2 }, + }, + }, + + range: [20, 58], + loc: { + start: { column: 20, line: 1 }, + end: { column: 1, line: 3 }, + }, + }, + + range: [0, 59], + loc: { + start: { column: 0, line: 1 }, + end: { column: 2, line: 3 }, + }, + }, + ], + sourceType: "script", + + range: [0, 60], + loc: { + start: { column: 0, line: 1 }, + end: { column: 0, line: 4 }, + }, +} \ No newline at end of file diff --git a/packages/ast-spec/src/type/TSMappedType/fixtures/readonly-plus/snapshots/4-Babel-Tokens.shot b/packages/ast-spec/src/type/TSMappedType/fixtures/readonly-plus/snapshots/4-Babel-Tokens.shot new file mode 100644 index 000000000000..6705b1f3585f --- /dev/null +++ b/packages/ast-spec/src/type/TSMappedType/fixtures/readonly-plus/snapshots/4-Babel-Tokens.shot @@ -0,0 +1,162 @@ +[ + Identifier { + type: "Identifier", + value: "type", + + range: [0, 4], + loc: { + start: { column: 0, line: 1 }, + end: { column: 4, line: 1 }, + }, + }, + Identifier { + type: "Identifier", + value: "PlusReadonly", + + range: [5, 17], + loc: { + start: { column: 5, line: 1 }, + end: { column: 17, line: 1 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "=", + + range: [18, 19], + loc: { + start: { column: 18, line: 1 }, + end: { column: 19, line: 1 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "{", + + range: [20, 21], + loc: { + start: { column: 20, line: 1 }, + end: { column: 21, line: 1 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "+", + + range: [24, 25], + loc: { + start: { column: 2, line: 2 }, + end: { column: 3, line: 2 }, + }, + }, + Identifier { + type: "Identifier", + value: "readonly", + + range: [25, 33], + loc: { + start: { column: 3, line: 2 }, + end: { column: 11, line: 2 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "[", + + range: [34, 35], + loc: { + start: { column: 12, line: 2 }, + end: { column: 13, line: 2 }, + }, + }, + Identifier { + type: "Identifier", + value: "P", + + range: [35, 36], + loc: { + start: { column: 13, line: 2 }, + end: { column: 14, line: 2 }, + }, + }, + Keyword { + type: "Keyword", + value: "in", + + range: [37, 39], + loc: { + start: { column: 15, line: 2 }, + end: { column: 17, line: 2 }, + }, + }, + Identifier { + type: "Identifier", + value: "string", + + range: [40, 46], + loc: { + start: { column: 18, line: 2 }, + end: { column: 24, line: 2 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "]", + + range: [46, 47], + loc: { + start: { column: 24, line: 2 }, + end: { column: 25, line: 2 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ":", + + range: [47, 48], + loc: { + start: { column: 25, line: 2 }, + end: { column: 26, line: 2 }, + }, + }, + Identifier { + type: "Identifier", + value: "number", + + range: [49, 55], + loc: { + start: { column: 27, line: 2 }, + end: { column: 33, line: 2 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ";", + + range: [55, 56], + loc: { + start: { column: 33, line: 2 }, + end: { column: 34, line: 2 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "}", + + range: [57, 58], + loc: { + start: { column: 0, line: 3 }, + end: { column: 1, line: 3 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ";", + + range: [58, 59], + loc: { + start: { column: 1, line: 3 }, + end: { column: 2, line: 3 }, + }, + }, +] \ No newline at end of file diff --git a/packages/ast-spec/src/type/TSMappedType/fixtures/readonly-plus/snapshots/5-AST-Alignment-AST.shot b/packages/ast-spec/src/type/TSMappedType/fixtures/readonly-plus/snapshots/5-AST-Alignment-AST.shot new file mode 100644 index 000000000000..4d6ea7914636 --- /dev/null +++ b/packages/ast-spec/src/type/TSMappedType/fixtures/readonly-plus/snapshots/5-AST-Alignment-AST.shot @@ -0,0 +1,102 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`AST Fixtures > type > TSMappedType > readonly-plus > AST Alignment - AST`] +Snapshot Diff: +- TSESTree ++ Babel + + Program { + type: 'Program', + body: Array [ + TSTypeAliasDeclaration { + type: 'TSTypeAliasDeclaration', +- declare: false, + id: Identifier { + type: 'Identifier', +- decorators: Array [], + name: 'PlusReadonly', +- optional: false, + + range: [5, 17], + loc: { + start: { column: 5, line: 1 }, + end: { column: 17, line: 1 }, + }, + }, + typeAnnotation: TSMappedType { + type: 'TSMappedType', +- constraint: TSStringKeyword { +- type: 'TSStringKeyword', +- +- range: [40, 46], +- loc: { +- start: { column: 18, line: 2 }, +- end: { column: 24, line: 2 }, +- }, +- }, +- key: Identifier { +- type: 'Identifier', +- decorators: Array [], +- name: 'P', +- optional: false, +- +- range: [35, 36], +- loc: { +- start: { column: 13, line: 2 }, +- end: { column: 14, line: 2 }, +- }, +- }, + nameType: null, +- optional: false, + readonly: '+', + typeAnnotation: TSNumberKeyword { + type: 'TSNumberKeyword', + + range: [49, 55], + loc: { + start: { column: 27, line: 2 }, + end: { column: 33, line: 2 }, ++ }, ++ }, ++ typeParameter: TSTypeParameter { ++ type: 'TSTypeParameter', ++ constraint: TSStringKeyword { ++ type: 'TSStringKeyword', ++ ++ range: [40, 46], ++ loc: { ++ start: { column: 18, line: 2 }, ++ end: { column: 24, line: 2 }, ++ }, ++ }, ++ name: 'P', ++ ++ range: [35, 46], ++ loc: { ++ start: { column: 13, line: 2 }, ++ end: { column: 24, line: 2 }, + }, + }, + + range: [20, 58], + loc: { + start: { column: 20, line: 1 }, + end: { column: 1, line: 3 }, + }, + }, + + range: [0, 59], + loc: { + start: { column: 0, line: 1 }, + end: { column: 2, line: 3 }, + }, + }, + ], + sourceType: 'script', + + range: [0, 60], + loc: { + start: { column: 0, line: 1 }, + end: { column: 0, line: 4 }, + }, + } diff --git a/packages/ast-spec/src/type/TSMappedType/fixtures/readonly-plus/snapshots/6-AST-Alignment-Tokens.shot b/packages/ast-spec/src/type/TSMappedType/fixtures/readonly-plus/snapshots/6-AST-Alignment-Tokens.shot new file mode 100644 index 000000000000..ffe93c7e8277 --- /dev/null +++ b/packages/ast-spec/src/type/TSMappedType/fixtures/readonly-plus/snapshots/6-AST-Alignment-Tokens.shot @@ -0,0 +1,5 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`AST Fixtures > type > TSMappedType > readonly-plus > AST Alignment - Token`] +Snapshot Diff: +Compared values have no visual difference. diff --git a/packages/ast-spec/src/type/TSMappedType/fixtures/readonly/fixture.ts b/packages/ast-spec/src/type/TSMappedType/fixtures/readonly/fixture.ts new file mode 100644 index 000000000000..f6774b5d317e --- /dev/null +++ b/packages/ast-spec/src/type/TSMappedType/fixtures/readonly/fixture.ts @@ -0,0 +1,3 @@ +type ReadonlyOptional = { + readonly [P in string]?: number; +}; diff --git a/packages/ast-spec/src/type/TSMappedType/fixtures/readonly/snapshots/1-TSESTree-AST.shot b/packages/ast-spec/src/type/TSMappedType/fixtures/readonly/snapshots/1-TSESTree-AST.shot new file mode 100644 index 000000000000..ce3b5b1785e9 --- /dev/null +++ b/packages/ast-spec/src/type/TSMappedType/fixtures/readonly/snapshots/1-TSESTree-AST.shot @@ -0,0 +1,76 @@ +Program { + type: "Program", + body: [ + TSTypeAliasDeclaration { + type: "TSTypeAliasDeclaration", + declare: false, + id: Identifier { + type: "Identifier", + decorators: [], + name: "ReadonlyOptional", + optional: false, + + range: [5, 21], + loc: { + start: { column: 5, line: 1 }, + end: { column: 21, line: 1 }, + }, + }, + typeAnnotation: TSMappedType { + type: "TSMappedType", + constraint: TSStringKeyword { + type: "TSStringKeyword", + + range: [43, 49], + loc: { + start: { column: 17, line: 2 }, + end: { column: 23, line: 2 }, + }, + }, + key: Identifier { + type: "Identifier", + decorators: [], + name: "P", + optional: false, + + range: [38, 39], + loc: { + start: { column: 12, line: 2 }, + end: { column: 13, line: 2 }, + }, + }, + nameType: null, + optional: true, + readonly: true, + typeAnnotation: TSNumberKeyword { + type: "TSNumberKeyword", + + range: [53, 59], + loc: { + start: { column: 27, line: 2 }, + end: { column: 33, line: 2 }, + }, + }, + + range: [24, 62], + loc: { + start: { column: 24, line: 1 }, + end: { column: 1, line: 3 }, + }, + }, + + range: [0, 63], + loc: { + start: { column: 0, line: 1 }, + end: { column: 2, line: 3 }, + }, + }, + ], + sourceType: "script", + + range: [0, 64], + loc: { + start: { column: 0, line: 1 }, + end: { column: 0, line: 4 }, + }, +} \ No newline at end of file diff --git a/packages/ast-spec/src/type/TSMappedType/fixtures/readonly/snapshots/2-TSESTree-Tokens.shot b/packages/ast-spec/src/type/TSMappedType/fixtures/readonly/snapshots/2-TSESTree-Tokens.shot new file mode 100644 index 000000000000..1dc2635c20ca --- /dev/null +++ b/packages/ast-spec/src/type/TSMappedType/fixtures/readonly/snapshots/2-TSESTree-Tokens.shot @@ -0,0 +1,162 @@ +[ + Identifier { + type: "Identifier", + value: "type", + + range: [0, 4], + loc: { + start: { column: 0, line: 1 }, + end: { column: 4, line: 1 }, + }, + }, + Identifier { + type: "Identifier", + value: "ReadonlyOptional", + + range: [5, 21], + loc: { + start: { column: 5, line: 1 }, + end: { column: 21, line: 1 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "=", + + range: [22, 23], + loc: { + start: { column: 22, line: 1 }, + end: { column: 23, line: 1 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "{", + + range: [24, 25], + loc: { + start: { column: 24, line: 1 }, + end: { column: 25, line: 1 }, + }, + }, + Identifier { + type: "Identifier", + value: "readonly", + + range: [28, 36], + loc: { + start: { column: 2, line: 2 }, + end: { column: 10, line: 2 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "[", + + range: [37, 38], + loc: { + start: { column: 11, line: 2 }, + end: { column: 12, line: 2 }, + }, + }, + Identifier { + type: "Identifier", + value: "P", + + range: [38, 39], + loc: { + start: { column: 12, line: 2 }, + end: { column: 13, line: 2 }, + }, + }, + Keyword { + type: "Keyword", + value: "in", + + range: [40, 42], + loc: { + start: { column: 14, line: 2 }, + end: { column: 16, line: 2 }, + }, + }, + Identifier { + type: "Identifier", + value: "string", + + range: [43, 49], + loc: { + start: { column: 17, line: 2 }, + end: { column: 23, line: 2 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "]", + + range: [49, 50], + loc: { + start: { column: 23, line: 2 }, + end: { column: 24, line: 2 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "?", + + range: [50, 51], + loc: { + start: { column: 24, line: 2 }, + end: { column: 25, line: 2 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ":", + + range: [51, 52], + loc: { + start: { column: 25, line: 2 }, + end: { column: 26, line: 2 }, + }, + }, + Identifier { + type: "Identifier", + value: "number", + + range: [53, 59], + loc: { + start: { column: 27, line: 2 }, + end: { column: 33, line: 2 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ";", + + range: [59, 60], + loc: { + start: { column: 33, line: 2 }, + end: { column: 34, line: 2 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "}", + + range: [61, 62], + loc: { + start: { column: 0, line: 3 }, + end: { column: 1, line: 3 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ";", + + range: [62, 63], + loc: { + start: { column: 1, line: 3 }, + end: { column: 2, line: 3 }, + }, + }, +] \ No newline at end of file diff --git a/packages/ast-spec/src/type/TSMappedType/fixtures/readonly/snapshots/3-Babel-AST.shot b/packages/ast-spec/src/type/TSMappedType/fixtures/readonly/snapshots/3-Babel-AST.shot new file mode 100644 index 000000000000..dcba1b68e86f --- /dev/null +++ b/packages/ast-spec/src/type/TSMappedType/fixtures/readonly/snapshots/3-Babel-AST.shot @@ -0,0 +1,71 @@ +Program { + type: "Program", + body: [ + TSTypeAliasDeclaration { + type: "TSTypeAliasDeclaration", + id: Identifier { + type: "Identifier", + name: "ReadonlyOptional", + + range: [5, 21], + loc: { + start: { column: 5, line: 1 }, + end: { column: 21, line: 1 }, + }, + }, + typeAnnotation: TSMappedType { + type: "TSMappedType", + nameType: null, + optional: true, + readonly: true, + typeAnnotation: TSNumberKeyword { + type: "TSNumberKeyword", + + range: [53, 59], + loc: { + start: { column: 27, line: 2 }, + end: { column: 33, line: 2 }, + }, + }, + typeParameter: TSTypeParameter { + type: "TSTypeParameter", + constraint: TSStringKeyword { + type: "TSStringKeyword", + + range: [43, 49], + loc: { + start: { column: 17, line: 2 }, + end: { column: 23, line: 2 }, + }, + }, + name: "P", + + range: [38, 49], + loc: { + start: { column: 12, line: 2 }, + end: { column: 23, line: 2 }, + }, + }, + + range: [24, 62], + loc: { + start: { column: 24, line: 1 }, + end: { column: 1, line: 3 }, + }, + }, + + range: [0, 63], + loc: { + start: { column: 0, line: 1 }, + end: { column: 2, line: 3 }, + }, + }, + ], + sourceType: "script", + + range: [0, 64], + loc: { + start: { column: 0, line: 1 }, + end: { column: 0, line: 4 }, + }, +} \ No newline at end of file diff --git a/packages/ast-spec/src/type/TSMappedType/fixtures/readonly/snapshots/4-Babel-Tokens.shot b/packages/ast-spec/src/type/TSMappedType/fixtures/readonly/snapshots/4-Babel-Tokens.shot new file mode 100644 index 000000000000..1dc2635c20ca --- /dev/null +++ b/packages/ast-spec/src/type/TSMappedType/fixtures/readonly/snapshots/4-Babel-Tokens.shot @@ -0,0 +1,162 @@ +[ + Identifier { + type: "Identifier", + value: "type", + + range: [0, 4], + loc: { + start: { column: 0, line: 1 }, + end: { column: 4, line: 1 }, + }, + }, + Identifier { + type: "Identifier", + value: "ReadonlyOptional", + + range: [5, 21], + loc: { + start: { column: 5, line: 1 }, + end: { column: 21, line: 1 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "=", + + range: [22, 23], + loc: { + start: { column: 22, line: 1 }, + end: { column: 23, line: 1 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "{", + + range: [24, 25], + loc: { + start: { column: 24, line: 1 }, + end: { column: 25, line: 1 }, + }, + }, + Identifier { + type: "Identifier", + value: "readonly", + + range: [28, 36], + loc: { + start: { column: 2, line: 2 }, + end: { column: 10, line: 2 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "[", + + range: [37, 38], + loc: { + start: { column: 11, line: 2 }, + end: { column: 12, line: 2 }, + }, + }, + Identifier { + type: "Identifier", + value: "P", + + range: [38, 39], + loc: { + start: { column: 12, line: 2 }, + end: { column: 13, line: 2 }, + }, + }, + Keyword { + type: "Keyword", + value: "in", + + range: [40, 42], + loc: { + start: { column: 14, line: 2 }, + end: { column: 16, line: 2 }, + }, + }, + Identifier { + type: "Identifier", + value: "string", + + range: [43, 49], + loc: { + start: { column: 17, line: 2 }, + end: { column: 23, line: 2 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "]", + + range: [49, 50], + loc: { + start: { column: 23, line: 2 }, + end: { column: 24, line: 2 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "?", + + range: [50, 51], + loc: { + start: { column: 24, line: 2 }, + end: { column: 25, line: 2 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ":", + + range: [51, 52], + loc: { + start: { column: 25, line: 2 }, + end: { column: 26, line: 2 }, + }, + }, + Identifier { + type: "Identifier", + value: "number", + + range: [53, 59], + loc: { + start: { column: 27, line: 2 }, + end: { column: 33, line: 2 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ";", + + range: [59, 60], + loc: { + start: { column: 33, line: 2 }, + end: { column: 34, line: 2 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "}", + + range: [61, 62], + loc: { + start: { column: 0, line: 3 }, + end: { column: 1, line: 3 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ";", + + range: [62, 63], + loc: { + start: { column: 1, line: 3 }, + end: { column: 2, line: 3 }, + }, + }, +] \ No newline at end of file diff --git a/packages/ast-spec/src/type/TSMappedType/fixtures/readonly/snapshots/5-AST-Alignment-AST.shot b/packages/ast-spec/src/type/TSMappedType/fixtures/readonly/snapshots/5-AST-Alignment-AST.shot new file mode 100644 index 000000000000..a3cd43ce9c5f --- /dev/null +++ b/packages/ast-spec/src/type/TSMappedType/fixtures/readonly/snapshots/5-AST-Alignment-AST.shot @@ -0,0 +1,102 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`AST Fixtures > type > TSMappedType > readonly > AST Alignment - AST`] +Snapshot Diff: +- TSESTree ++ Babel + + Program { + type: 'Program', + body: Array [ + TSTypeAliasDeclaration { + type: 'TSTypeAliasDeclaration', +- declare: false, + id: Identifier { + type: 'Identifier', +- decorators: Array [], + name: 'ReadonlyOptional', +- optional: false, + + range: [5, 21], + loc: { + start: { column: 5, line: 1 }, + end: { column: 21, line: 1 }, + }, + }, + typeAnnotation: TSMappedType { + type: 'TSMappedType', +- constraint: TSStringKeyword { +- type: 'TSStringKeyword', +- +- range: [43, 49], +- loc: { +- start: { column: 17, line: 2 }, +- end: { column: 23, line: 2 }, +- }, +- }, +- key: Identifier { +- type: 'Identifier', +- decorators: Array [], +- name: 'P', +- optional: false, +- +- range: [38, 39], +- loc: { +- start: { column: 12, line: 2 }, +- end: { column: 13, line: 2 }, +- }, +- }, + nameType: null, + optional: true, + readonly: true, + typeAnnotation: TSNumberKeyword { + type: 'TSNumberKeyword', + + range: [53, 59], + loc: { + start: { column: 27, line: 2 }, + end: { column: 33, line: 2 }, ++ }, ++ }, ++ typeParameter: TSTypeParameter { ++ type: 'TSTypeParameter', ++ constraint: TSStringKeyword { ++ type: 'TSStringKeyword', ++ ++ range: [43, 49], ++ loc: { ++ start: { column: 17, line: 2 }, ++ end: { column: 23, line: 2 }, ++ }, ++ }, ++ name: 'P', ++ ++ range: [38, 49], ++ loc: { ++ start: { column: 12, line: 2 }, ++ end: { column: 23, line: 2 }, + }, + }, + + range: [24, 62], + loc: { + start: { column: 24, line: 1 }, + end: { column: 1, line: 3 }, + }, + }, + + range: [0, 63], + loc: { + start: { column: 0, line: 1 }, + end: { column: 2, line: 3 }, + }, + }, + ], + sourceType: 'script', + + range: [0, 64], + loc: { + start: { column: 0, line: 1 }, + end: { column: 0, line: 4 }, + }, + } diff --git a/packages/ast-spec/src/type/TSMappedType/fixtures/readonly/snapshots/6-AST-Alignment-Tokens.shot b/packages/ast-spec/src/type/TSMappedType/fixtures/readonly/snapshots/6-AST-Alignment-Tokens.shot new file mode 100644 index 000000000000..e2181a65c27f --- /dev/null +++ b/packages/ast-spec/src/type/TSMappedType/fixtures/readonly/snapshots/6-AST-Alignment-Tokens.shot @@ -0,0 +1,5 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`AST Fixtures > type > TSMappedType > readonly > AST Alignment - Token`] +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 77762c062843..35ac2ec6cf36 100644 --- a/packages/ast-spec/tests/fixtures-with-differences-ast.shot +++ b/packages/ast-spec/tests/fixtures-with-differences-ast.shot @@ -524,5 +524,13 @@ exports[`AST Fixtures > List fixtures with AST differences`] "statement/ForInStatement/fixtures/expr-init/fixture.ts", "statement/ForOfStatement/fixtures/expr-init/fixture.ts", "statement/ForOfStatement/fixtures/using-declaration/fixture.ts", - "type/TSImportType/fixtures/type-import-type-with-import-attributes/fixture.ts" + "type/TSImportType/fixtures/type-import-type-with-import-attributes/fixture.ts", + "type/TSMappedType/fixtures/no-modifiers/fixture.ts", + "type/TSMappedType/fixtures/optional-minus/fixture.ts", + "type/TSMappedType/fixtures/optional-plus/fixture.ts", + "type/TSMappedType/fixtures/optional/fixture.ts", + "type/TSMappedType/fixtures/readonly-minus/fixture.ts", + "type/TSMappedType/fixtures/readonly-optional/fixture.ts", + "type/TSMappedType/fixtures/readonly-plus/fixture.ts", + "type/TSMappedType/fixtures/readonly/fixture.ts" ] diff --git a/packages/typescript-estree/src/convert.ts b/packages/typescript-estree/src/convert.ts index 7faa5353b12c..83aa176ef074 100644 --- a/packages/typescript-estree/src/convert.ts +++ b/packages/typescript-estree/src/convert.ts @@ -2870,14 +2870,14 @@ export class Converter { constraint: this.convertChild(node.typeParameter.constraint), key: this.convertChild(node.typeParameter.name), nameType: this.convertChild(node.nameType) ?? null, - optional: - node.questionToken && - (node.questionToken.kind === SyntaxKind.QuestionToken || - getTextForTokenKind(node.questionToken.kind)), - readonly: - node.readonlyToken && - (node.readonlyToken.kind === SyntaxKind.ReadonlyKeyword || - getTextForTokenKind(node.readonlyToken.kind)), + optional: node.questionToken + ? node.questionToken.kind === SyntaxKind.QuestionToken || + getTextForTokenKind(node.questionToken.kind) + : false, + readonly: node.readonlyToken + ? node.readonlyToken.kind === SyntaxKind.ReadonlyKeyword || + getTextForTokenKind(node.readonlyToken.kind) + : undefined, typeAnnotation: node.type && this.convertChild(node.type), }, 'typeParameter',