From 6b01edc335c29b4ae2d339e5c9cb9001faad5098 Mon Sep 17 00:00:00 2001 From: Brad Zacher Date: Thu, 9 Feb 2023 17:08:44 +1030 Subject: [PATCH 1/5] feat: add `.kind` to `TSModuleDeclaration` --- .../namespace/snapshots/1-TSESTree-AST.shot | 1 + .../snapshots/5-AST-Alignment-AST.shot | 59 ++++++++++++- .../global/snapshots/1-TSESTree-AST.shot | 1 + .../global/snapshots/5-AST-Alignment-AST.shot | 48 ++++++++++- .../snapshots/1-TSESTree-AST.shot | 1 + .../snapshots/5-AST-Alignment-AST.shot | 38 +++++++- .../snapshots/1-TSESTree-AST.shot | 1 + .../snapshots/5-AST-Alignment-AST.shot | 47 +++++++++- .../snapshots/1-TSESTree-AST.shot | 1 + .../snapshots/5-AST-Alignment-AST.shot | 46 +++++++++- .../snapshots/1-TSESTree-AST.shot | 1 + .../snapshots/5-AST-Alignment-AST.shot | 47 +++++++++- .../snapshots/1-TSESTree-AST.shot | 3 + .../snapshots/5-AST-Alignment-AST.shot | 86 ++++++++++++++++++- .../snapshots/1-TSESTree-AST.shot | 1 + .../snapshots/5-AST-Alignment-AST.shot | 47 +++++++++- .../snapshots/1-TSESTree-AST.shot | 1 + .../snapshots/5-AST-Alignment-AST.shot | 46 +++++++++- .../snapshots/1-TSESTree-AST.shot | 3 + .../snapshots/5-AST-Alignment-AST.shot | 86 ++++++++++++++++++- .../declaration/TSModuleDeclaration/spec.ts | 17 +++- .../tests/fixtures-with-differences-ast.shot | 10 +++ packages/typescript-estree/src/convert.ts | 6 ++ .../basics/directive-in-module.src.ts.shot | 1 + .../basics/directive-in-namespace.src.ts.shot | 1 + .../typescript/declare/module.src.ts.shot | 1 + .../typescript/declare/namespace.src.ts.shot | 1 + ...module-declaration-with-import.src.ts.shot | 1 + ...mespace-with-exported-function.src.ts.shot | 1 + .../global-module-declaration.src.ts.shot | 3 + .../module-with-default-exports.src.ts.shot | 1 + .../nested-internal-module.src.ts.shot | 2 + ...and-ambient-module-declaration.src.ts.shot | 1 + 33 files changed, 599 insertions(+), 11 deletions(-) diff --git a/packages/ast-spec/src/declaration/ExportNamedDeclaration/fixtures/namespace/snapshots/1-TSESTree-AST.shot b/packages/ast-spec/src/declaration/ExportNamedDeclaration/fixtures/namespace/snapshots/1-TSESTree-AST.shot index 8bee64090fc2..70aa834e1993 100644 --- a/packages/ast-spec/src/declaration/ExportNamedDeclaration/fixtures/namespace/snapshots/1-TSESTree-AST.shot +++ b/packages/ast-spec/src/declaration/ExportNamedDeclaration/fixtures/namespace/snapshots/1-TSESTree-AST.shot @@ -29,6 +29,7 @@ Program { end: { column: 20, line: 1 }, }, }, + kind: "namespace", range: [7, 23], loc: { diff --git a/packages/ast-spec/src/declaration/ExportNamedDeclaration/fixtures/namespace/snapshots/5-AST-Alignment-AST.shot b/packages/ast-spec/src/declaration/ExportNamedDeclaration/fixtures/namespace/snapshots/5-AST-Alignment-AST.shot index 00a19c01c581..d9b1ab535bb8 100644 --- a/packages/ast-spec/src/declaration/ExportNamedDeclaration/fixtures/namespace/snapshots/5-AST-Alignment-AST.shot +++ b/packages/ast-spec/src/declaration/ExportNamedDeclaration/fixtures/namespace/snapshots/5-AST-Alignment-AST.shot @@ -2,5 +2,62 @@ exports[`AST Fixtures declaration ExportNamedDeclaration namespace AST Alignment - AST 1`] = ` "Snapshot Diff: -Compared values have no visual difference." +- TSESTree ++ Babel + + Program { + type: 'Program', + body: Array [ + ExportNamedDeclaration { + type: 'ExportNamedDeclaration', + assertions: Array [], + declaration: TSModuleDeclaration { + type: 'TSModuleDeclaration', + body: TSModuleBlock { + type: 'TSModuleBlock', + body: Array [], + + range: [21, 23], + loc: { + start: { column: 21, line: 1 }, + end: { column: 23, line: 1 }, + }, + }, + id: Identifier { + type: 'Identifier', + name: 'Foo', + + range: [17, 20], + loc: { + start: { column: 17, line: 1 }, + end: { column: 20, line: 1 }, + }, + }, +- kind: 'namespace', + + range: [7, 23], + loc: { + start: { column: 7, line: 1 }, + end: { column: 23, line: 1 }, + }, + }, + exportKind: 'value', + source: null, + specifiers: Array [], + + range: [0, 23], + loc: { + start: { column: 0, line: 1 }, + end: { column: 23, line: 1 }, + }, + }, + ], + sourceType: 'module', + + range: [0, 24], + loc: { + start: { column: 0, line: 1 }, + end: { column: 0, line: 2 }, + }, + }" `; diff --git a/packages/ast-spec/src/declaration/TSModuleDeclaration/fixtures/global/snapshots/1-TSESTree-AST.shot b/packages/ast-spec/src/declaration/TSModuleDeclaration/fixtures/global/snapshots/1-TSESTree-AST.shot index 424909a0e10c..6d845973debe 100644 --- a/packages/ast-spec/src/declaration/TSModuleDeclaration/fixtures/global/snapshots/1-TSESTree-AST.shot +++ b/packages/ast-spec/src/declaration/TSModuleDeclaration/fixtures/global/snapshots/1-TSESTree-AST.shot @@ -28,6 +28,7 @@ Program { end: { column: 14, line: 1 }, }, }, + kind: "global", range: [0, 17], loc: { diff --git a/packages/ast-spec/src/declaration/TSModuleDeclaration/fixtures/global/snapshots/5-AST-Alignment-AST.shot b/packages/ast-spec/src/declaration/TSModuleDeclaration/fixtures/global/snapshots/5-AST-Alignment-AST.shot index bdf259261537..5dc4161ad9a4 100644 --- a/packages/ast-spec/src/declaration/TSModuleDeclaration/fixtures/global/snapshots/5-AST-Alignment-AST.shot +++ b/packages/ast-spec/src/declaration/TSModuleDeclaration/fixtures/global/snapshots/5-AST-Alignment-AST.shot @@ -2,5 +2,51 @@ exports[`AST Fixtures declaration TSModuleDeclaration global AST Alignment - AST 1`] = ` "Snapshot Diff: -Compared values have no visual difference." +- TSESTree ++ Babel + + Program { + type: 'Program', + body: Array [ + TSModuleDeclaration { + type: 'TSModuleDeclaration', + body: TSModuleBlock { + type: 'TSModuleBlock', + body: Array [], + + range: [15, 17], + loc: { + start: { column: 15, line: 1 }, + end: { column: 17, line: 1 }, + }, + }, + declare: true, + global: true, + id: Identifier { + type: 'Identifier', + name: 'global', + + range: [8, 14], + loc: { + start: { column: 8, line: 1 }, + end: { column: 14, line: 1 }, + }, + }, +- kind: 'global', + + range: [0, 17], + loc: { + start: { column: 0, line: 1 }, + end: { column: 17, line: 1 }, + }, + }, + ], + sourceType: 'script', + + range: [0, 18], + loc: { + start: { column: 0, line: 1 }, + end: { column: 0, line: 2 }, + }, + }" `; diff --git a/packages/ast-spec/src/declaration/TSModuleDeclaration/fixtures/module-declare-no-body/snapshots/1-TSESTree-AST.shot b/packages/ast-spec/src/declaration/TSModuleDeclaration/fixtures/module-declare-no-body/snapshots/1-TSESTree-AST.shot index a0ad297f73cd..17f754710762 100644 --- a/packages/ast-spec/src/declaration/TSModuleDeclaration/fixtures/module-declare-no-body/snapshots/1-TSESTree-AST.shot +++ b/packages/ast-spec/src/declaration/TSModuleDeclaration/fixtures/module-declare-no-body/snapshots/1-TSESTree-AST.shot @@ -18,6 +18,7 @@ Program { end: { column: 18, line: 1 }, }, }, + kind: "module", range: [0, 19], loc: { diff --git a/packages/ast-spec/src/declaration/TSModuleDeclaration/fixtures/module-declare-no-body/snapshots/5-AST-Alignment-AST.shot b/packages/ast-spec/src/declaration/TSModuleDeclaration/fixtures/module-declare-no-body/snapshots/5-AST-Alignment-AST.shot index 29dc0c7a7765..591ea8c8d32e 100644 --- a/packages/ast-spec/src/declaration/TSModuleDeclaration/fixtures/module-declare-no-body/snapshots/5-AST-Alignment-AST.shot +++ b/packages/ast-spec/src/declaration/TSModuleDeclaration/fixtures/module-declare-no-body/snapshots/5-AST-Alignment-AST.shot @@ -2,5 +2,41 @@ exports[`AST Fixtures declaration TSModuleDeclaration module-declare-no-body AST Alignment - AST 1`] = ` "Snapshot Diff: -Compared values have no visual difference." +- TSESTree ++ Babel + + Program { + type: 'Program', + body: Array [ + TSModuleDeclaration { + type: 'TSModuleDeclaration', + declare: true, + id: Literal { + type: 'Literal', + raw: '\\\\'a\\\\'', + value: 'a', + + range: [15, 18], + loc: { + start: { column: 15, line: 1 }, + end: { column: 18, line: 1 }, + }, + }, +- kind: 'module', + + range: [0, 19], + loc: { + start: { column: 0, line: 1 }, + end: { column: 19, line: 1 }, + }, + }, + ], + sourceType: 'script', + + range: [0, 20], + loc: { + start: { column: 0, line: 1 }, + end: { column: 0, line: 2 }, + }, + }" `; diff --git a/packages/ast-spec/src/declaration/TSModuleDeclaration/fixtures/module-declare/snapshots/1-TSESTree-AST.shot b/packages/ast-spec/src/declaration/TSModuleDeclaration/fixtures/module-declare/snapshots/1-TSESTree-AST.shot index 74a329eeb585..026bdc26251d 100644 --- a/packages/ast-spec/src/declaration/TSModuleDeclaration/fixtures/module-declare/snapshots/1-TSESTree-AST.shot +++ b/packages/ast-spec/src/declaration/TSModuleDeclaration/fixtures/module-declare/snapshots/1-TSESTree-AST.shot @@ -27,6 +27,7 @@ Program { end: { column: 16, line: 1 }, }, }, + kind: "module", range: [0, 19], loc: { diff --git a/packages/ast-spec/src/declaration/TSModuleDeclaration/fixtures/module-declare/snapshots/5-AST-Alignment-AST.shot b/packages/ast-spec/src/declaration/TSModuleDeclaration/fixtures/module-declare/snapshots/5-AST-Alignment-AST.shot index d70930f793c0..75dd7304dfaa 100644 --- a/packages/ast-spec/src/declaration/TSModuleDeclaration/fixtures/module-declare/snapshots/5-AST-Alignment-AST.shot +++ b/packages/ast-spec/src/declaration/TSModuleDeclaration/fixtures/module-declare/snapshots/5-AST-Alignment-AST.shot @@ -2,5 +2,50 @@ exports[`AST Fixtures declaration TSModuleDeclaration module-declare AST Alignment - AST 1`] = ` "Snapshot Diff: -Compared values have no visual difference." +- TSESTree ++ Babel + + Program { + type: 'Program', + body: Array [ + TSModuleDeclaration { + type: 'TSModuleDeclaration', + body: TSModuleBlock { + type: 'TSModuleBlock', + body: Array [], + + range: [17, 19], + loc: { + start: { column: 17, line: 1 }, + end: { column: 19, line: 1 }, + }, + }, + declare: true, + id: Identifier { + type: 'Identifier', + name: 'F', + + range: [15, 16], + loc: { + start: { column: 15, line: 1 }, + end: { column: 16, line: 1 }, + }, + }, +- kind: 'module', + + range: [0, 19], + loc: { + start: { column: 0, line: 1 }, + end: { column: 19, line: 1 }, + }, + }, + ], + sourceType: 'script', + + range: [0, 20], + loc: { + start: { column: 0, line: 1 }, + end: { column: 0, line: 2 }, + }, + }" `; diff --git a/packages/ast-spec/src/declaration/TSModuleDeclaration/fixtures/module-id-identifier/snapshots/1-TSESTree-AST.shot b/packages/ast-spec/src/declaration/TSModuleDeclaration/fixtures/module-id-identifier/snapshots/1-TSESTree-AST.shot index 3559c1ce1a19..80f52eaeaa38 100644 --- a/packages/ast-spec/src/declaration/TSModuleDeclaration/fixtures/module-id-identifier/snapshots/1-TSESTree-AST.shot +++ b/packages/ast-spec/src/declaration/TSModuleDeclaration/fixtures/module-id-identifier/snapshots/1-TSESTree-AST.shot @@ -26,6 +26,7 @@ Program { end: { column: 8, line: 1 }, }, }, + kind: "module", range: [0, 11], loc: { diff --git a/packages/ast-spec/src/declaration/TSModuleDeclaration/fixtures/module-id-identifier/snapshots/5-AST-Alignment-AST.shot b/packages/ast-spec/src/declaration/TSModuleDeclaration/fixtures/module-id-identifier/snapshots/5-AST-Alignment-AST.shot index 829de93e3df2..36a5fb1365f5 100644 --- a/packages/ast-spec/src/declaration/TSModuleDeclaration/fixtures/module-id-identifier/snapshots/5-AST-Alignment-AST.shot +++ b/packages/ast-spec/src/declaration/TSModuleDeclaration/fixtures/module-id-identifier/snapshots/5-AST-Alignment-AST.shot @@ -2,5 +2,49 @@ exports[`AST Fixtures declaration TSModuleDeclaration module-id-identifier AST Alignment - AST 1`] = ` "Snapshot Diff: -Compared values have no visual difference." +- TSESTree ++ Babel + + Program { + type: 'Program', + body: Array [ + TSModuleDeclaration { + type: 'TSModuleDeclaration', + body: TSModuleBlock { + type: 'TSModuleBlock', + body: Array [], + + range: [9, 11], + loc: { + start: { column: 9, line: 1 }, + end: { column: 11, line: 1 }, + }, + }, + id: Identifier { + type: 'Identifier', + name: 'F', + + range: [7, 8], + loc: { + start: { column: 7, line: 1 }, + end: { column: 8, line: 1 }, + }, + }, +- kind: 'module', + + range: [0, 11], + loc: { + start: { column: 0, line: 1 }, + end: { column: 11, line: 1 }, + }, + }, + ], + sourceType: 'script', + + range: [0, 12], + loc: { + start: { column: 0, line: 1 }, + end: { column: 0, line: 2 }, + }, + }" `; diff --git a/packages/ast-spec/src/declaration/TSModuleDeclaration/fixtures/module-id-literal/snapshots/1-TSESTree-AST.shot b/packages/ast-spec/src/declaration/TSModuleDeclaration/fixtures/module-id-literal/snapshots/1-TSESTree-AST.shot index da4f7cdc9afb..543f49f139cc 100644 --- a/packages/ast-spec/src/declaration/TSModuleDeclaration/fixtures/module-id-literal/snapshots/1-TSESTree-AST.shot +++ b/packages/ast-spec/src/declaration/TSModuleDeclaration/fixtures/module-id-literal/snapshots/1-TSESTree-AST.shot @@ -27,6 +27,7 @@ Program { end: { column: 10, line: 1 }, }, }, + kind: "module", range: [0, 13], loc: { diff --git a/packages/ast-spec/src/declaration/TSModuleDeclaration/fixtures/module-id-literal/snapshots/5-AST-Alignment-AST.shot b/packages/ast-spec/src/declaration/TSModuleDeclaration/fixtures/module-id-literal/snapshots/5-AST-Alignment-AST.shot index f13f22dfe7df..629052e8a659 100644 --- a/packages/ast-spec/src/declaration/TSModuleDeclaration/fixtures/module-id-literal/snapshots/5-AST-Alignment-AST.shot +++ b/packages/ast-spec/src/declaration/TSModuleDeclaration/fixtures/module-id-literal/snapshots/5-AST-Alignment-AST.shot @@ -2,5 +2,50 @@ exports[`AST Fixtures declaration TSModuleDeclaration module-id-literal AST Alignment - AST 1`] = ` "Snapshot Diff: -Compared values have no visual difference." +- TSESTree ++ Babel + + Program { + type: 'Program', + body: Array [ + TSModuleDeclaration { + type: 'TSModuleDeclaration', + body: TSModuleBlock { + type: 'TSModuleBlock', + body: Array [], + + range: [11, 13], + loc: { + start: { column: 11, line: 1 }, + end: { column: 13, line: 1 }, + }, + }, + id: Literal { + type: 'Literal', + raw: '\\\\'a\\\\'', + value: 'a', + + range: [7, 10], + loc: { + start: { column: 7, line: 1 }, + end: { column: 10, line: 1 }, + }, + }, +- kind: 'module', + + range: [0, 13], + loc: { + start: { column: 0, line: 1 }, + end: { column: 13, line: 1 }, + }, + }, + ], + sourceType: 'script', + + range: [0, 14], + loc: { + start: { column: 0, line: 1 }, + end: { column: 0, line: 2 }, + }, + }" `; diff --git a/packages/ast-spec/src/declaration/TSModuleDeclaration/fixtures/module-id-qualified-name/snapshots/1-TSESTree-AST.shot b/packages/ast-spec/src/declaration/TSModuleDeclaration/fixtures/module-id-qualified-name/snapshots/1-TSESTree-AST.shot index 3dfc069dda7e..c0f09867e6f5 100644 --- a/packages/ast-spec/src/declaration/TSModuleDeclaration/fixtures/module-id-qualified-name/snapshots/1-TSESTree-AST.shot +++ b/packages/ast-spec/src/declaration/TSModuleDeclaration/fixtures/module-id-qualified-name/snapshots/1-TSESTree-AST.shot @@ -30,6 +30,7 @@ Program { end: { column: 12, line: 1 }, }, }, + kind: "module", range: [11, 15], loc: { @@ -47,6 +48,7 @@ Program { end: { column: 10, line: 1 }, }, }, + kind: "module", range: [9, 15], loc: { @@ -64,6 +66,7 @@ Program { end: { column: 8, line: 1 }, }, }, + kind: "module", range: [0, 15], loc: { diff --git a/packages/ast-spec/src/declaration/TSModuleDeclaration/fixtures/module-id-qualified-name/snapshots/5-AST-Alignment-AST.shot b/packages/ast-spec/src/declaration/TSModuleDeclaration/fixtures/module-id-qualified-name/snapshots/5-AST-Alignment-AST.shot index d442f261db29..9c2311d4b6f6 100644 --- a/packages/ast-spec/src/declaration/TSModuleDeclaration/fixtures/module-id-qualified-name/snapshots/5-AST-Alignment-AST.shot +++ b/packages/ast-spec/src/declaration/TSModuleDeclaration/fixtures/module-id-qualified-name/snapshots/5-AST-Alignment-AST.shot @@ -2,5 +2,89 @@ exports[`AST Fixtures declaration TSModuleDeclaration module-id-qualified-name AST Alignment - AST 1`] = ` "Snapshot Diff: -Compared values have no visual difference." +- TSESTree ++ Babel + + Program { + type: 'Program', + body: Array [ + TSModuleDeclaration { + type: 'TSModuleDeclaration', + body: TSModuleDeclaration { + type: 'TSModuleDeclaration', + body: TSModuleDeclaration { + type: 'TSModuleDeclaration', + body: TSModuleBlock { + type: 'TSModuleBlock', + body: Array [], + + range: [13, 15], + loc: { + start: { column: 13, line: 1 }, + end: { column: 15, line: 1 }, + }, + }, + id: Identifier { + type: 'Identifier', + name: 'C', + + range: [11, 12], + loc: { + start: { column: 11, line: 1 }, + end: { column: 12, line: 1 }, + }, + }, +- kind: 'module', + + range: [11, 15], + loc: { + start: { column: 11, line: 1 }, + end: { column: 15, line: 1 }, + }, + }, + id: Identifier { + type: 'Identifier', + name: 'B', + + range: [9, 10], + loc: { + start: { column: 9, line: 1 }, + end: { column: 10, line: 1 }, + }, + }, +- kind: 'module', + + range: [9, 15], + loc: { + start: { column: 9, line: 1 }, + end: { column: 15, line: 1 }, + }, + }, + id: Identifier { + type: 'Identifier', + name: 'A', + + range: [7, 8], + loc: { + start: { column: 7, line: 1 }, + end: { column: 8, line: 1 }, + }, + }, +- kind: 'module', + + range: [0, 15], + loc: { + start: { column: 0, line: 1 }, + end: { column: 15, line: 1 }, + }, + }, + ], + sourceType: 'script', + + range: [0, 16], + loc: { + start: { column: 0, line: 1 }, + end: { column: 0, line: 2 }, + }, + }" `; diff --git a/packages/ast-spec/src/declaration/TSModuleDeclaration/fixtures/namespace-declare/snapshots/1-TSESTree-AST.shot b/packages/ast-spec/src/declaration/TSModuleDeclaration/fixtures/namespace-declare/snapshots/1-TSESTree-AST.shot index c373a655222a..d808958c70e3 100644 --- a/packages/ast-spec/src/declaration/TSModuleDeclaration/fixtures/namespace-declare/snapshots/1-TSESTree-AST.shot +++ b/packages/ast-spec/src/declaration/TSModuleDeclaration/fixtures/namespace-declare/snapshots/1-TSESTree-AST.shot @@ -27,6 +27,7 @@ Program { end: { column: 19, line: 1 }, }, }, + kind: "namespace", range: [0, 22], loc: { diff --git a/packages/ast-spec/src/declaration/TSModuleDeclaration/fixtures/namespace-declare/snapshots/5-AST-Alignment-AST.shot b/packages/ast-spec/src/declaration/TSModuleDeclaration/fixtures/namespace-declare/snapshots/5-AST-Alignment-AST.shot index 614b9695a3cf..48f1c28a6f60 100644 --- a/packages/ast-spec/src/declaration/TSModuleDeclaration/fixtures/namespace-declare/snapshots/5-AST-Alignment-AST.shot +++ b/packages/ast-spec/src/declaration/TSModuleDeclaration/fixtures/namespace-declare/snapshots/5-AST-Alignment-AST.shot @@ -2,5 +2,50 @@ exports[`AST Fixtures declaration TSModuleDeclaration namespace-declare AST Alignment - AST 1`] = ` "Snapshot Diff: -Compared values have no visual difference." +- TSESTree ++ Babel + + Program { + type: 'Program', + body: Array [ + TSModuleDeclaration { + type: 'TSModuleDeclaration', + body: TSModuleBlock { + type: 'TSModuleBlock', + body: Array [], + + range: [20, 22], + loc: { + start: { column: 20, line: 1 }, + end: { column: 22, line: 1 }, + }, + }, + declare: true, + id: Identifier { + type: 'Identifier', + name: 'F', + + range: [18, 19], + loc: { + start: { column: 18, line: 1 }, + end: { column: 19, line: 1 }, + }, + }, +- kind: 'namespace', + + range: [0, 22], + loc: { + start: { column: 0, line: 1 }, + end: { column: 22, line: 1 }, + }, + }, + ], + sourceType: 'script', + + range: [0, 23], + loc: { + start: { column: 0, line: 1 }, + end: { column: 0, line: 2 }, + }, + }" `; diff --git a/packages/ast-spec/src/declaration/TSModuleDeclaration/fixtures/namespace-id-identifier/snapshots/1-TSESTree-AST.shot b/packages/ast-spec/src/declaration/TSModuleDeclaration/fixtures/namespace-id-identifier/snapshots/1-TSESTree-AST.shot index e6303e2d3edc..05e6c65aa804 100644 --- a/packages/ast-spec/src/declaration/TSModuleDeclaration/fixtures/namespace-id-identifier/snapshots/1-TSESTree-AST.shot +++ b/packages/ast-spec/src/declaration/TSModuleDeclaration/fixtures/namespace-id-identifier/snapshots/1-TSESTree-AST.shot @@ -26,6 +26,7 @@ Program { end: { column: 11, line: 1 }, }, }, + kind: "namespace", range: [0, 14], loc: { diff --git a/packages/ast-spec/src/declaration/TSModuleDeclaration/fixtures/namespace-id-identifier/snapshots/5-AST-Alignment-AST.shot b/packages/ast-spec/src/declaration/TSModuleDeclaration/fixtures/namespace-id-identifier/snapshots/5-AST-Alignment-AST.shot index a0aa056256bc..1d16afdfbbb7 100644 --- a/packages/ast-spec/src/declaration/TSModuleDeclaration/fixtures/namespace-id-identifier/snapshots/5-AST-Alignment-AST.shot +++ b/packages/ast-spec/src/declaration/TSModuleDeclaration/fixtures/namespace-id-identifier/snapshots/5-AST-Alignment-AST.shot @@ -2,5 +2,49 @@ exports[`AST Fixtures declaration TSModuleDeclaration namespace-id-identifier AST Alignment - AST 1`] = ` "Snapshot Diff: -Compared values have no visual difference." +- TSESTree ++ Babel + + Program { + type: 'Program', + body: Array [ + TSModuleDeclaration { + type: 'TSModuleDeclaration', + body: TSModuleBlock { + type: 'TSModuleBlock', + body: Array [], + + range: [12, 14], + loc: { + start: { column: 12, line: 1 }, + end: { column: 14, line: 1 }, + }, + }, + id: Identifier { + type: 'Identifier', + name: 'F', + + range: [10, 11], + loc: { + start: { column: 10, line: 1 }, + end: { column: 11, line: 1 }, + }, + }, +- kind: 'namespace', + + range: [0, 14], + loc: { + start: { column: 0, line: 1 }, + end: { column: 14, line: 1 }, + }, + }, + ], + sourceType: 'script', + + range: [0, 15], + loc: { + start: { column: 0, line: 1 }, + end: { column: 0, line: 2 }, + }, + }" `; diff --git a/packages/ast-spec/src/declaration/TSModuleDeclaration/fixtures/namespace-id-qualified-name/snapshots/1-TSESTree-AST.shot b/packages/ast-spec/src/declaration/TSModuleDeclaration/fixtures/namespace-id-qualified-name/snapshots/1-TSESTree-AST.shot index 98cd5bbe8176..69dbfa38ebbd 100644 --- a/packages/ast-spec/src/declaration/TSModuleDeclaration/fixtures/namespace-id-qualified-name/snapshots/1-TSESTree-AST.shot +++ b/packages/ast-spec/src/declaration/TSModuleDeclaration/fixtures/namespace-id-qualified-name/snapshots/1-TSESTree-AST.shot @@ -30,6 +30,7 @@ Program { end: { column: 15, line: 1 }, }, }, + kind: "namespace", range: [14, 18], loc: { @@ -47,6 +48,7 @@ Program { end: { column: 13, line: 1 }, }, }, + kind: "namespace", range: [12, 18], loc: { @@ -64,6 +66,7 @@ Program { end: { column: 11, line: 1 }, }, }, + kind: "namespace", range: [0, 18], loc: { diff --git a/packages/ast-spec/src/declaration/TSModuleDeclaration/fixtures/namespace-id-qualified-name/snapshots/5-AST-Alignment-AST.shot b/packages/ast-spec/src/declaration/TSModuleDeclaration/fixtures/namespace-id-qualified-name/snapshots/5-AST-Alignment-AST.shot index a7a16eee58a5..5a99e367a51d 100644 --- a/packages/ast-spec/src/declaration/TSModuleDeclaration/fixtures/namespace-id-qualified-name/snapshots/5-AST-Alignment-AST.shot +++ b/packages/ast-spec/src/declaration/TSModuleDeclaration/fixtures/namespace-id-qualified-name/snapshots/5-AST-Alignment-AST.shot @@ -2,5 +2,89 @@ exports[`AST Fixtures declaration TSModuleDeclaration namespace-id-qualified-name AST Alignment - AST 1`] = ` "Snapshot Diff: -Compared values have no visual difference." +- TSESTree ++ Babel + + Program { + type: 'Program', + body: Array [ + TSModuleDeclaration { + type: 'TSModuleDeclaration', + body: TSModuleDeclaration { + type: 'TSModuleDeclaration', + body: TSModuleDeclaration { + type: 'TSModuleDeclaration', + body: TSModuleBlock { + type: 'TSModuleBlock', + body: Array [], + + range: [16, 18], + loc: { + start: { column: 16, line: 1 }, + end: { column: 18, line: 1 }, + }, + }, + id: Identifier { + type: 'Identifier', + name: 'C', + + range: [14, 15], + loc: { + start: { column: 14, line: 1 }, + end: { column: 15, line: 1 }, + }, + }, +- kind: 'namespace', + + range: [14, 18], + loc: { + start: { column: 14, line: 1 }, + end: { column: 18, line: 1 }, + }, + }, + id: Identifier { + type: 'Identifier', + name: 'B', + + range: [12, 13], + loc: { + start: { column: 12, line: 1 }, + end: { column: 13, line: 1 }, + }, + }, +- kind: 'namespace', + + range: [12, 18], + loc: { + start: { column: 12, line: 1 }, + end: { column: 18, line: 1 }, + }, + }, + id: Identifier { + type: 'Identifier', + name: 'A', + + range: [10, 11], + loc: { + start: { column: 10, line: 1 }, + end: { column: 11, line: 1 }, + }, + }, +- kind: 'namespace', + + range: [0, 18], + loc: { + start: { column: 0, line: 1 }, + end: { column: 18, line: 1 }, + }, + }, + ], + sourceType: 'script', + + range: [0, 19], + loc: { + start: { column: 0, line: 1 }, + end: { column: 0, line: 2 }, + }, + }" `; diff --git a/packages/ast-spec/src/declaration/TSModuleDeclaration/spec.ts b/packages/ast-spec/src/declaration/TSModuleDeclaration/spec.ts index e077d1648e1f..31150f53dc2c 100644 --- a/packages/ast-spec/src/declaration/TSModuleDeclaration/spec.ts +++ b/packages/ast-spec/src/declaration/TSModuleDeclaration/spec.ts @@ -39,7 +39,7 @@ export interface TSModuleDeclaration extends BaseNode { * declare global {} * ``` */ - // TODO(#5020) - make this `false` if not `global` + // TODO(#5020) - remove this in the next major (we have `.kind` now) global?: boolean; /** * Whether the module is `declare`d @@ -51,4 +51,19 @@ export interface TSModuleDeclaration extends BaseNode { declare?: boolean; // TODO(#4759) - breaking change remove this modifiers?: Modifier[]; + + /** + * THe keyword used to define this module declaration + * ``` + * namespace Foo {} + * ^^^^^^^^^ + * + * module 'foo' {} + * ^^^^^^ + * + * declare global {} + * ^^^^^^ + * ``` + */ + kind: 'global' | 'module' | 'namespace'; } diff --git a/packages/ast-spec/tests/fixtures-with-differences-ast.shot b/packages/ast-spec/tests/fixtures-with-differences-ast.shot index 233fc7f4f95e..80f631573c0a 100644 --- a/packages/ast-spec/tests/fixtures-with-differences-ast.shot +++ b/packages/ast-spec/tests/fixtures-with-differences-ast.shot @@ -12,6 +12,7 @@ Set { "declaration/ExportNamedDeclaration/fixtures/identifier-braced/fixture.ts", "declaration/ExportNamedDeclaration/fixtures/identifier-many/fixture.ts", "declaration/ExportNamedDeclaration/fixtures/interface/fixture.ts", + "declaration/ExportNamedDeclaration/fixtures/namespace/fixture.ts", "declaration/ExportNamedDeclaration/fixtures/type-alias/fixture.ts", "declaration/FunctionDeclaration/fixtures/type-param-many/fixture.ts", "declaration/FunctionDeclaration/fixtures/type-param-one/fixture.ts", @@ -22,6 +23,15 @@ Set { "declaration/TSInterfaceDeclaration/fixtures/extends-one/fixture.ts", "declaration/TSInterfaceDeclaration/fixtures/type-param-many/fixture.ts", "declaration/TSInterfaceDeclaration/fixtures/type-param-one/fixture.ts", + "declaration/TSModuleDeclaration/fixtures/global/fixture.ts", + "declaration/TSModuleDeclaration/fixtures/module-declare-no-body/fixture.ts", + "declaration/TSModuleDeclaration/fixtures/module-declare/fixture.ts", + "declaration/TSModuleDeclaration/fixtures/module-id-identifier/fixture.ts", + "declaration/TSModuleDeclaration/fixtures/module-id-literal/fixture.ts", + "declaration/TSModuleDeclaration/fixtures/module-id-qualified-name/fixture.ts", + "declaration/TSModuleDeclaration/fixtures/namespace-declare/fixture.ts", + "declaration/TSModuleDeclaration/fixtures/namespace-id-identifier/fixture.ts", + "declaration/TSModuleDeclaration/fixtures/namespace-id-qualified-name/fixture.ts", "declaration/TSTypeAliasDeclaration/fixtures/type-param-many/fixture.ts", "declaration/TSTypeAliasDeclaration/fixtures/type-param-one/fixture.ts", "element/AccessorProperty/fixtures/key-computed-complex/fixture.ts", diff --git a/packages/typescript-estree/src/convert.ts b/packages/typescript-estree/src/convert.ts index 70ee9da4e0ce..f0a92d0e06b5 100644 --- a/packages/typescript-estree/src/convert.ts +++ b/packages/typescript-estree/src/convert.ts @@ -2792,6 +2792,7 @@ export class Converter { const result = this.createNode(node, { type: AST_NODE_TYPES.TSModuleDeclaration, id: this.convertChild(node.name), + kind: 'module', }); if (node.body) { result.body = this.convertChild(node.body); @@ -2800,6 +2801,11 @@ export class Converter { this.applyModifiersToResult(result, getModifiers(node)); if (node.flags & ts.NodeFlags.GlobalAugmentation) { result.global = true; + result.kind = 'global'; + } else if (node.flags & ts.NodeFlags.Namespace) { + result.kind = 'namespace'; + } else { + result.kind = 'module'; } // ...then check for exports return this.fixExports(node, result); diff --git a/packages/typescript-estree/tests/snapshots/typescript/basics/directive-in-module.src.ts.shot b/packages/typescript-estree/tests/snapshots/typescript/basics/directive-in-module.src.ts.shot index 4e79f84c3dd1..2a65e53254b6 100644 --- a/packages/typescript-estree/tests/snapshots/typescript/basics/directive-in-module.src.ts.shot +++ b/packages/typescript-estree/tests/snapshots/typescript/basics/directive-in-module.src.ts.shot @@ -188,6 +188,7 @@ Object { ], "type": "Identifier", }, + "kind": "module", "loc": Object { "end": Object { "column": 1, diff --git a/packages/typescript-estree/tests/snapshots/typescript/basics/directive-in-namespace.src.ts.shot b/packages/typescript-estree/tests/snapshots/typescript/basics/directive-in-namespace.src.ts.shot index 6cbcd85aabe6..28b76d987c48 100644 --- a/packages/typescript-estree/tests/snapshots/typescript/basics/directive-in-namespace.src.ts.shot +++ b/packages/typescript-estree/tests/snapshots/typescript/basics/directive-in-namespace.src.ts.shot @@ -188,6 +188,7 @@ Object { ], "type": "Identifier", }, + "kind": "namespace", "loc": Object { "end": Object { "column": 1, diff --git a/packages/typescript-estree/tests/snapshots/typescript/declare/module.src.ts.shot b/packages/typescript-estree/tests/snapshots/typescript/declare/module.src.ts.shot index b00d347e536b..a786486f85d1 100644 --- a/packages/typescript-estree/tests/snapshots/typescript/declare/module.src.ts.shot +++ b/packages/typescript-estree/tests/snapshots/typescript/declare/module.src.ts.shot @@ -41,6 +41,7 @@ Object { ], "type": "Identifier", }, + "kind": "module", "loc": Object { "end": Object { "column": 1, diff --git a/packages/typescript-estree/tests/snapshots/typescript/declare/namespace.src.ts.shot b/packages/typescript-estree/tests/snapshots/typescript/declare/namespace.src.ts.shot index c38490374609..3823ff07f05a 100644 --- a/packages/typescript-estree/tests/snapshots/typescript/declare/namespace.src.ts.shot +++ b/packages/typescript-estree/tests/snapshots/typescript/declare/namespace.src.ts.shot @@ -41,6 +41,7 @@ Object { ], "type": "Identifier", }, + "kind": "namespace", "loc": Object { "end": Object { "column": 1, diff --git a/packages/typescript-estree/tests/snapshots/typescript/namespaces-and-modules/ambient-module-declaration-with-import.src.ts.shot b/packages/typescript-estree/tests/snapshots/typescript/namespaces-and-modules/ambient-module-declaration-with-import.src.ts.shot index eca74134194e..0fc1dc4ce2b1 100644 --- a/packages/typescript-estree/tests/snapshots/typescript/namespaces-and-modules/ambient-module-declaration-with-import.src.ts.shot +++ b/packages/typescript-estree/tests/snapshots/typescript/namespaces-and-modules/ambient-module-declaration-with-import.src.ts.shot @@ -118,6 +118,7 @@ Object { "type": "Literal", "value": "i-use-things", }, + "kind": "module", "loc": Object { "end": Object { "column": 1, diff --git a/packages/typescript-estree/tests/snapshots/typescript/namespaces-and-modules/declare-namespace-with-exported-function.src.ts.shot b/packages/typescript-estree/tests/snapshots/typescript/namespaces-and-modules/declare-namespace-with-exported-function.src.ts.shot index 1d6f5b2efdac..5a3e8f29ed62 100644 --- a/packages/typescript-estree/tests/snapshots/typescript/namespaces-and-modules/declare-namespace-with-exported-function.src.ts.shot +++ b/packages/typescript-estree/tests/snapshots/typescript/namespaces-and-modules/declare-namespace-with-exported-function.src.ts.shot @@ -244,6 +244,7 @@ Object { ], "type": "Identifier", }, + "kind": "namespace", "loc": Object { "end": Object { "column": 1, diff --git a/packages/typescript-estree/tests/snapshots/typescript/namespaces-and-modules/global-module-declaration.src.ts.shot b/packages/typescript-estree/tests/snapshots/typescript/namespaces-and-modules/global-module-declaration.src.ts.shot index 08ed9df51fba..08f680075d90 100644 --- a/packages/typescript-estree/tests/snapshots/typescript/namespaces-and-modules/global-module-declaration.src.ts.shot +++ b/packages/typescript-estree/tests/snapshots/typescript/namespaces-and-modules/global-module-declaration.src.ts.shot @@ -44,6 +44,7 @@ Object { ], "type": "Identifier", }, + "kind": "module", "loc": Object { "end": Object { "column": 5, @@ -98,6 +99,7 @@ Object { ], "type": "Identifier", }, + "kind": "namespace", "loc": Object { "end": Object { "column": 5, @@ -151,6 +153,7 @@ Object { ], "type": "Identifier", }, + "kind": "global", "loc": Object { "end": Object { "column": 1, diff --git a/packages/typescript-estree/tests/snapshots/typescript/namespaces-and-modules/module-with-default-exports.src.ts.shot b/packages/typescript-estree/tests/snapshots/typescript/namespaces-and-modules/module-with-default-exports.src.ts.shot index 70ff82a2ec71..7151fa18ddec 100644 --- a/packages/typescript-estree/tests/snapshots/typescript/namespaces-and-modules/module-with-default-exports.src.ts.shot +++ b/packages/typescript-estree/tests/snapshots/typescript/namespaces-and-modules/module-with-default-exports.src.ts.shot @@ -322,6 +322,7 @@ Object { "type": "Literal", "value": "foo", }, + "kind": "module", "loc": Object { "end": Object { "column": 1, diff --git a/packages/typescript-estree/tests/snapshots/typescript/namespaces-and-modules/nested-internal-module.src.ts.shot b/packages/typescript-estree/tests/snapshots/typescript/namespaces-and-modules/nested-internal-module.src.ts.shot index 2284e4afed7d..ad77c1edc36d 100644 --- a/packages/typescript-estree/tests/snapshots/typescript/namespaces-and-modules/nested-internal-module.src.ts.shot +++ b/packages/typescript-estree/tests/snapshots/typescript/namespaces-and-modules/nested-internal-module.src.ts.shot @@ -595,6 +595,7 @@ Object { ], "type": "Identifier", }, + "kind": "module", "loc": Object { "end": Object { "column": 5, @@ -665,6 +666,7 @@ Object { ], "type": "Identifier", }, + "kind": "module", "loc": Object { "end": Object { "column": 1, diff --git a/packages/typescript-estree/tests/snapshots/typescript/namespaces-and-modules/shorthand-ambient-module-declaration.src.ts.shot b/packages/typescript-estree/tests/snapshots/typescript/namespaces-and-modules/shorthand-ambient-module-declaration.src.ts.shot index 37b859d967fb..5b90f004775a 100644 --- a/packages/typescript-estree/tests/snapshots/typescript/namespaces-and-modules/shorthand-ambient-module-declaration.src.ts.shot +++ b/packages/typescript-estree/tests/snapshots/typescript/namespaces-and-modules/shorthand-ambient-module-declaration.src.ts.shot @@ -24,6 +24,7 @@ Object { "type": "Literal", "value": "hot-new-module", }, + "kind": "module", "loc": Object { "end": Object { "column": 32, From 6f884b46b17d372eec6e4e784c2c88a941b77e12 Mon Sep 17 00:00:00 2001 From: Brad Zacher Date: Thu, 9 Feb 2023 18:11:10 +1030 Subject: [PATCH 2/5] tighten up types --- .../declaration/TSModuleDeclaration/spec.ts | 103 +++++++++++++++--- packages/typescript-estree/src/convert.ts | 47 +++++--- 2 files changed, 119 insertions(+), 31 deletions(-) diff --git a/packages/ast-spec/src/declaration/TSModuleDeclaration/spec.ts b/packages/ast-spec/src/declaration/TSModuleDeclaration/spec.ts index 31150f53dc2c..4d58ac28db56 100644 --- a/packages/ast-spec/src/declaration/TSModuleDeclaration/spec.ts +++ b/packages/ast-spec/src/declaration/TSModuleDeclaration/spec.ts @@ -1,11 +1,24 @@ import type { AST_NODE_TYPES } from '../../ast-node-types'; import type { BaseNode } from '../../base/BaseNode'; import type { Identifier } from '../../expression/Identifier/spec'; +import type { StringLiteral } from '../../expression/literal/StringLiteral/spec'; import type { TSModuleBlock } from '../../special/TSModuleBlock/spec'; -import type { Literal } from '../../unions/Literal'; import type { Modifier } from '../../unions/Modifier'; -export interface TSModuleDeclaration extends BaseNode { +export type TSModuleDeclarationKind = 'global' | 'module' | 'namespace'; + +/* +TODO(#4966) - we currently emit this due to bad parser handling of nested modules +namespace Foo.Bar {} +^^^^^^^^^^^^^^^^^^^^ TSModuleDeclaration + ^^^^^^ TSModuleDeclaration + ^^ TSModuleBlock + +This should instead emit a TSQualifiedName for the `id` and not emit an inner TSModuleDeclaration +*/ +type ModuleBody_TODOFixThis = TSModuleBlock | TSModuleDeclaration; + +interface TSModuleDeclarationBase extends BaseNode { type: AST_NODE_TYPES.TSModuleDeclaration; /** * The name of the module @@ -15,31 +28,20 @@ export interface TSModuleDeclaration extends BaseNode { * module 'a' {} * ``` */ - id: Identifier | Literal; + id: Identifier | StringLiteral; /** * The body of the module. * This can only be `undefined` for the code `declare module 'mod';` * This will be a `TSModuleDeclaration` if the name is "nested" (`Foo.Bar`). */ - body?: - | TSModuleBlock - /* - TODO(#4966) - we currently emit this due to bad parser handling of nested modules - namespace Foo.Bar {} - ^^^^^^^^^^^^^^^^^^^^ TSModuleDeclaration - ^^^^^^ TSModuleDeclaration - ^^ TSModuleBlock - - This should instead emit a TSQualifiedName for the `id` and not emit an inner TSModuleDeclaration - */ - | TSModuleDeclaration; + body?: ModuleBody_TODOFixThis; /** * Whether this is a global declaration * ``` * declare global {} * ``` */ - // TODO(#5020) - remove this in the next major (we have `.kind` now) + // TODO - remove this in the next major (we have `.kind` now) global?: boolean; /** * Whether the module is `declare`d @@ -65,5 +67,72 @@ export interface TSModuleDeclaration extends BaseNode { * ^^^^^^ * ``` */ - kind: 'global' | 'module' | 'namespace'; + kind: TSModuleDeclarationKind; +} + +export interface TSModuleDeclarationNamespace extends TSModuleDeclarationBase { + kind: 'namespace'; + // namespaces cannot have literal IDs + id: Identifier; + // namespaces must always have a body + body: ModuleBody_TODOFixThis; + + // TODO - remove this in the next major (we have `.kind` now) + global?: undefined; } + +export interface TSModuleDeclarationGlobal extends TSModuleDeclarationBase { + kind: 'global'; + // cannot have a nested namespace for global module augmentation + // cannot have `declare global;` + body: TSModuleBlock; + // this will always be an Identifier with name `global` + id: Identifier; + + // note - it's not syntactically required to have `declare`, but it semantically required + + // TODO - remove this in the next major (we have `.kind` now) + global: true; +} + +interface TSModuleDeclarationModuleBase extends TSModuleDeclarationBase { + kind: 'module'; + + // TODO - remove this in the next major (we have `.kind` now) + global?: undefined; +} + +export type TSModuleDeclarationModule = + | TSModuleDeclarationModuleWithIdentifierId + | TSModuleDeclarationModuleWithStringId; +export type TSModuleDeclarationModuleWithStringId = + | TSModuleDeclarationModuleWithStringIdDeclared + | TSModuleDeclarationModuleWithStringIdNotDeclared; +export interface TSModuleDeclarationModuleWithStringIdNotDeclared + extends TSModuleDeclarationModuleBase { + kind: 'module'; + id: StringLiteral; + declare: false; + // cannot have nested namespaces with a string ID, must have a body + body: TSModuleBlock; +} +export interface TSModuleDeclarationModuleWithStringIdDeclared + extends TSModuleDeclarationModuleBase { + kind: 'module'; + id: StringLiteral; + declare: true; + // cannot have nested namespaces with a string ID, might not have a body + body?: TSModuleBlock; +} +export interface TSModuleDeclarationModuleWithIdentifierId + extends TSModuleDeclarationModuleBase { + kind: 'module'; + id: Identifier; + // modules with an Identifier must always have a body + body: ModuleBody_TODOFixThis; +} + +export type TSModuleDeclaration = + | TSModuleDeclarationGlobal + | TSModuleDeclarationModule + | TSModuleDeclarationNamespace; diff --git a/packages/typescript-estree/src/convert.ts b/packages/typescript-estree/src/convert.ts index f0a92d0e06b5..ceacdb20ea52 100644 --- a/packages/typescript-estree/src/convert.ts +++ b/packages/typescript-estree/src/convert.ts @@ -2791,22 +2791,41 @@ export class Converter { case SyntaxKind.ModuleDeclaration: { const result = this.createNode(node, { type: AST_NODE_TYPES.TSModuleDeclaration, - id: this.convertChild(node.name), - kind: 'module', + // eslint-disable-next-line @typescript-eslint/explicit-function-return-type -- TODO - add ignore IIFE option + ...(() => { + const id = this.convertChild(node.name); + const body = this.convertChild(node.body); + + if (node.flags & ts.NodeFlags.GlobalAugmentation) { + return { + kind: 'global', + id, + body, + global: true, + } satisfies TSESTree.OptionalRangeAndLoc< + Omit + >; + } else if (node.flags & ts.NodeFlags.Namespace) { + return { + kind: 'namespace', + id, + body, + } satisfies TSESTree.OptionalRangeAndLoc< + Omit + >; + } else { + return { + kind: 'module', + id, + body, + } satisfies TSESTree.OptionalRangeAndLoc< + Omit + >; + } + })(), }); - if (node.body) { - result.body = this.convertChild(node.body); - } - // apply modifiers first... this.applyModifiersToResult(result, getModifiers(node)); - if (node.flags & ts.NodeFlags.GlobalAugmentation) { - result.global = true; - result.kind = 'global'; - } else if (node.flags & ts.NodeFlags.Namespace) { - result.kind = 'namespace'; - } else { - result.kind = 'module'; - } + // ...then check for exports return this.fixExports(node, result); } From b4bf4c2a1294c91b9421f3b3258026c133d7f677 Mon Sep 17 00:00:00 2001 From: Brad Zacher Date: Thu, 9 Feb 2023 21:05:00 +1030 Subject: [PATCH 3/5] fix accidental introduction of null --- packages/typescript-estree/src/convert.ts | 30 ++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/packages/typescript-estree/src/convert.ts b/packages/typescript-estree/src/convert.ts index ceacdb20ea52..4f7a89d97c14 100644 --- a/packages/typescript-estree/src/convert.ts +++ b/packages/typescript-estree/src/convert.ts @@ -2793,10 +2793,28 @@ export class Converter { type: AST_NODE_TYPES.TSModuleDeclaration, // eslint-disable-next-line @typescript-eslint/explicit-function-return-type -- TODO - add ignore IIFE option ...(() => { - const id = this.convertChild(node.name); - const body = this.convertChild(node.body); + const id: TSESTree.Identifier | TSESTree.StringLiteral = + this.convertChild(node.name); + const body: + | TSESTree.TSModuleBlock + | TSESTree.TSModuleDeclaration + | null = this.convertChild(node.body); + + // the constraints checked by this function are syntactically enforced by TS + // the checks mostly exist for type's sake if (node.flags & ts.NodeFlags.GlobalAugmentation) { + if ( + body == null || + body.type === AST_NODE_TYPES.TSModuleDeclaration + ) { + throw new Error('Expected a valid module body'); + } + if (id.type !== AST_NODE_TYPES.Identifier) { + throw new Error( + 'global module augmentation must have an Identifier id', + ); + } return { kind: 'global', id, @@ -2806,6 +2824,12 @@ export class Converter { Omit >; } else if (node.flags & ts.NodeFlags.Namespace) { + if (body == null) { + throw new Error('Expected a module body'); + } + if (id.type !== AST_NODE_TYPES.Identifier) { + throw new Error('`namespace`s must have an Identifier id'); + } return { kind: 'namespace', id, @@ -2817,7 +2841,7 @@ export class Converter { return { kind: 'module', id, - body, + ...(body != null ? { body } : {}), } satisfies TSESTree.OptionalRangeAndLoc< Omit >; From b85070b96ce7b8612f630b3387a2638e912eaa50 Mon Sep 17 00:00:00 2001 From: Brad Zacher Date: Fri, 10 Feb 2023 13:18:39 +1030 Subject: [PATCH 4/5] update for new old snapshots --- .../snapshots/1-TSESTree-AST.shot | 1 + .../snapshots/5-AST-Alignment-AST.shot | 1 + .../snapshots/1-TSESTree-AST.shot | 1 + .../snapshots/5-AST-Alignment-AST.shot | 1 + .../module/snapshots/1-TSESTree-AST.shot | 1 + .../module/snapshots/5-AST-Alignment-AST.shot | 47 +++++++- .../namespace/snapshots/1-TSESTree-AST.shot | 1 + .../snapshots/5-AST-Alignment-AST.shot | 47 +++++++- .../snapshots/1-TSESTree-AST.shot | 1 + .../snapshots/5-AST-Alignment-AST.shot | 1 + .../snapshots/1-TSESTree-AST.shot | 1 + .../snapshots/5-AST-Alignment-AST.shot | 1 + .../snapshots/1-TSESTree-AST.shot | 3 + .../snapshots/5-AST-Alignment-AST.shot | 111 +++++++++++++++++- .../snapshots/1-TSESTree-AST.shot | 1 + .../snapshots/5-AST-Alignment-AST.shot | 1 + .../snapshots/1-TSESTree-AST.shot | 2 + .../snapshots/5-AST-Alignment-AST.shot | 2 + .../snapshots/1-TSESTree-AST.shot | 1 + .../snapshots/5-AST-Alignment-AST.shot | 38 +++++- .../tests/fixtures-with-differences-ast.shot | 4 + 21 files changed, 263 insertions(+), 4 deletions(-) diff --git a/packages/ast-spec/src/legacy-fixtures/basics/fixtures/directive-in-module/snapshots/1-TSESTree-AST.shot b/packages/ast-spec/src/legacy-fixtures/basics/fixtures/directive-in-module/snapshots/1-TSESTree-AST.shot index b77fc06d204f..3f74d63a87e9 100644 --- a/packages/ast-spec/src/legacy-fixtures/basics/fixtures/directive-in-module/snapshots/1-TSESTree-AST.shot +++ b/packages/ast-spec/src/legacy-fixtures/basics/fixtures/directive-in-module/snapshots/1-TSESTree-AST.shot @@ -110,6 +110,7 @@ Program { end: { column: 10, line: 3 }, }, }, + kind: "module", range: [73, 132], loc: { diff --git a/packages/ast-spec/src/legacy-fixtures/basics/fixtures/directive-in-module/snapshots/5-AST-Alignment-AST.shot b/packages/ast-spec/src/legacy-fixtures/basics/fixtures/directive-in-module/snapshots/5-AST-Alignment-AST.shot index c752ccbc4ea3..8ce2d9d2915d 100644 --- a/packages/ast-spec/src/legacy-fixtures/basics/fixtures/directive-in-module/snapshots/5-AST-Alignment-AST.shot +++ b/packages/ast-spec/src/legacy-fixtures/basics/fixtures/directive-in-module/snapshots/5-AST-Alignment-AST.shot @@ -114,6 +114,7 @@ exports[`AST Fixtures legacy-fixtures basics directive-in-module AST Alignment - end: { column: 10, line: 3 }, }, }, +- kind: 'module', range: [73, 132], loc: { diff --git a/packages/ast-spec/src/legacy-fixtures/basics/fixtures/directive-in-namespace/snapshots/1-TSESTree-AST.shot b/packages/ast-spec/src/legacy-fixtures/basics/fixtures/directive-in-namespace/snapshots/1-TSESTree-AST.shot index 0921c13c37c8..54670d060d5f 100644 --- a/packages/ast-spec/src/legacy-fixtures/basics/fixtures/directive-in-namespace/snapshots/1-TSESTree-AST.shot +++ b/packages/ast-spec/src/legacy-fixtures/basics/fixtures/directive-in-namespace/snapshots/1-TSESTree-AST.shot @@ -110,6 +110,7 @@ Program { end: { column: 13, line: 3 }, }, }, + kind: "namespace", range: [73, 135], loc: { diff --git a/packages/ast-spec/src/legacy-fixtures/basics/fixtures/directive-in-namespace/snapshots/5-AST-Alignment-AST.shot b/packages/ast-spec/src/legacy-fixtures/basics/fixtures/directive-in-namespace/snapshots/5-AST-Alignment-AST.shot index d570c43e3eaf..620319c66453 100644 --- a/packages/ast-spec/src/legacy-fixtures/basics/fixtures/directive-in-namespace/snapshots/5-AST-Alignment-AST.shot +++ b/packages/ast-spec/src/legacy-fixtures/basics/fixtures/directive-in-namespace/snapshots/5-AST-Alignment-AST.shot @@ -114,6 +114,7 @@ exports[`AST Fixtures legacy-fixtures basics directive-in-namespace AST Alignmen end: { column: 13, line: 3 }, }, }, +- kind: 'namespace', range: [73, 135], loc: { diff --git a/packages/ast-spec/src/legacy-fixtures/declare/fixtures/module/snapshots/1-TSESTree-AST.shot b/packages/ast-spec/src/legacy-fixtures/declare/fixtures/module/snapshots/1-TSESTree-AST.shot index 17df9ce9c9ff..28b9f673edcf 100644 --- a/packages/ast-spec/src/legacy-fixtures/declare/fixtures/module/snapshots/1-TSESTree-AST.shot +++ b/packages/ast-spec/src/legacy-fixtures/declare/fixtures/module/snapshots/1-TSESTree-AST.shot @@ -27,6 +27,7 @@ Program { end: { column: 18, line: 3 }, }, }, + kind: "module", range: [73, 94], loc: { diff --git a/packages/ast-spec/src/legacy-fixtures/declare/fixtures/module/snapshots/5-AST-Alignment-AST.shot b/packages/ast-spec/src/legacy-fixtures/declare/fixtures/module/snapshots/5-AST-Alignment-AST.shot index 9546b3d34b31..575a9a6bd393 100644 --- a/packages/ast-spec/src/legacy-fixtures/declare/fixtures/module/snapshots/5-AST-Alignment-AST.shot +++ b/packages/ast-spec/src/legacy-fixtures/declare/fixtures/module/snapshots/5-AST-Alignment-AST.shot @@ -2,5 +2,50 @@ exports[`AST Fixtures legacy-fixtures declare module AST Alignment - AST 1`] = ` "Snapshot Diff: -Compared values have no visual difference." +- TSESTree ++ Babel + + Program { + type: 'Program', + body: Array [ + TSModuleDeclaration { + type: 'TSModuleDeclaration', + body: TSModuleBlock { + type: 'TSModuleBlock', + body: Array [], + + range: [92, 94], + loc: { + start: { column: 19, line: 3 }, + end: { column: 21, line: 3 }, + }, + }, + declare: true, + id: Identifier { + type: 'Identifier', + name: 'Foo', + + range: [88, 91], + loc: { + start: { column: 15, line: 3 }, + end: { column: 18, line: 3 }, + }, + }, +- kind: 'module', + + range: [73, 94], + loc: { + start: { column: 0, line: 3 }, + end: { column: 21, line: 3 }, + }, + }, + ], + sourceType: 'script', + + range: [73, 95], + loc: { + start: { column: 0, line: 3 }, + end: { column: 0, line: 4 }, + }, + }" `; diff --git a/packages/ast-spec/src/legacy-fixtures/declare/fixtures/namespace/snapshots/1-TSESTree-AST.shot b/packages/ast-spec/src/legacy-fixtures/declare/fixtures/namespace/snapshots/1-TSESTree-AST.shot index 85661223163a..131440bf5fe7 100644 --- a/packages/ast-spec/src/legacy-fixtures/declare/fixtures/namespace/snapshots/1-TSESTree-AST.shot +++ b/packages/ast-spec/src/legacy-fixtures/declare/fixtures/namespace/snapshots/1-TSESTree-AST.shot @@ -27,6 +27,7 @@ Program { end: { column: 21, line: 3 }, }, }, + kind: "namespace", range: [73, 97], loc: { diff --git a/packages/ast-spec/src/legacy-fixtures/declare/fixtures/namespace/snapshots/5-AST-Alignment-AST.shot b/packages/ast-spec/src/legacy-fixtures/declare/fixtures/namespace/snapshots/5-AST-Alignment-AST.shot index 1d5ab5062386..ba41672f8430 100644 --- a/packages/ast-spec/src/legacy-fixtures/declare/fixtures/namespace/snapshots/5-AST-Alignment-AST.shot +++ b/packages/ast-spec/src/legacy-fixtures/declare/fixtures/namespace/snapshots/5-AST-Alignment-AST.shot @@ -2,5 +2,50 @@ exports[`AST Fixtures legacy-fixtures declare namespace AST Alignment - AST 1`] = ` "Snapshot Diff: -Compared values have no visual difference." +- TSESTree ++ Babel + + Program { + type: 'Program', + body: Array [ + TSModuleDeclaration { + type: 'TSModuleDeclaration', + body: TSModuleBlock { + type: 'TSModuleBlock', + body: Array [], + + range: [95, 97], + loc: { + start: { column: 22, line: 3 }, + end: { column: 24, line: 3 }, + }, + }, + declare: true, + id: Identifier { + type: 'Identifier', + name: 'Foo', + + range: [91, 94], + loc: { + start: { column: 18, line: 3 }, + end: { column: 21, line: 3 }, + }, + }, +- kind: 'namespace', + + range: [73, 97], + loc: { + start: { column: 0, line: 3 }, + end: { column: 24, line: 3 }, + }, + }, + ], + sourceType: 'script', + + range: [73, 98], + loc: { + start: { column: 0, line: 3 }, + end: { column: 0, line: 4 }, + }, + }" `; diff --git a/packages/ast-spec/src/legacy-fixtures/namespaces-and-modules/fixtures/ambient-module-declaration-with-import/snapshots/1-TSESTree-AST.shot b/packages/ast-spec/src/legacy-fixtures/namespaces-and-modules/fixtures/ambient-module-declaration-with-import/snapshots/1-TSESTree-AST.shot index 392a9c23b52d..3cdbc8537ae7 100644 --- a/packages/ast-spec/src/legacy-fixtures/namespaces-and-modules/fixtures/ambient-module-declaration-with-import/snapshots/1-TSESTree-AST.shot +++ b/packages/ast-spec/src/legacy-fixtures/namespaces-and-modules/fixtures/ambient-module-declaration-with-import/snapshots/1-TSESTree-AST.shot @@ -72,6 +72,7 @@ Program { end: { column: 29, line: 3 }, }, }, + kind: "module", range: [73, 129], loc: { diff --git a/packages/ast-spec/src/legacy-fixtures/namespaces-and-modules/fixtures/ambient-module-declaration-with-import/snapshots/5-AST-Alignment-AST.shot b/packages/ast-spec/src/legacy-fixtures/namespaces-and-modules/fixtures/ambient-module-declaration-with-import/snapshots/5-AST-Alignment-AST.shot index 42caff8c0fd1..a6aff688ab87 100644 --- a/packages/ast-spec/src/legacy-fixtures/namespaces-and-modules/fixtures/ambient-module-declaration-with-import/snapshots/5-AST-Alignment-AST.shot +++ b/packages/ast-spec/src/legacy-fixtures/namespaces-and-modules/fixtures/ambient-module-declaration-with-import/snapshots/5-AST-Alignment-AST.shot @@ -76,6 +76,7 @@ exports[`AST Fixtures legacy-fixtures namespaces-and-modules ambient-module-decl end: { column: 29, line: 3 }, }, }, +- kind: 'module', range: [73, 129], loc: { diff --git a/packages/ast-spec/src/legacy-fixtures/namespaces-and-modules/fixtures/declare-namespace-with-exported-function/snapshots/1-TSESTree-AST.shot b/packages/ast-spec/src/legacy-fixtures/namespaces-and-modules/fixtures/declare-namespace-with-exported-function/snapshots/1-TSESTree-AST.shot index 543c0266dc83..c4767e22bd00 100644 --- a/packages/ast-spec/src/legacy-fixtures/namespaces-and-modules/fixtures/declare-namespace-with-exported-function/snapshots/1-TSESTree-AST.shot +++ b/packages/ast-spec/src/legacy-fixtures/namespaces-and-modules/fixtures/declare-namespace-with-exported-function/snapshots/1-TSESTree-AST.shot @@ -141,6 +141,7 @@ Program { end: { column: 20, line: 3 }, }, }, + kind: "namespace", range: [73, 157], loc: { diff --git a/packages/ast-spec/src/legacy-fixtures/namespaces-and-modules/fixtures/declare-namespace-with-exported-function/snapshots/5-AST-Alignment-AST.shot b/packages/ast-spec/src/legacy-fixtures/namespaces-and-modules/fixtures/declare-namespace-with-exported-function/snapshots/5-AST-Alignment-AST.shot index 4e3ae3412850..0281bcdcbc15 100644 --- a/packages/ast-spec/src/legacy-fixtures/namespaces-and-modules/fixtures/declare-namespace-with-exported-function/snapshots/5-AST-Alignment-AST.shot +++ b/packages/ast-spec/src/legacy-fixtures/namespaces-and-modules/fixtures/declare-namespace-with-exported-function/snapshots/5-AST-Alignment-AST.shot @@ -145,6 +145,7 @@ exports[`AST Fixtures legacy-fixtures namespaces-and-modules declare-namespace-w end: { column: 20, line: 3 }, }, }, +- kind: 'namespace', range: [73, 157], loc: { diff --git a/packages/ast-spec/src/legacy-fixtures/namespaces-and-modules/fixtures/global-module-declaration/snapshots/1-TSESTree-AST.shot b/packages/ast-spec/src/legacy-fixtures/namespaces-and-modules/fixtures/global-module-declaration/snapshots/1-TSESTree-AST.shot index c44bb057e429..8177f6c6582a 100644 --- a/packages/ast-spec/src/legacy-fixtures/namespaces-and-modules/fixtures/global-module-declaration/snapshots/1-TSESTree-AST.shot +++ b/packages/ast-spec/src/legacy-fixtures/namespaces-and-modules/fixtures/global-module-declaration/snapshots/1-TSESTree-AST.shot @@ -32,6 +32,7 @@ Program { end: { column: 23, line: 4 }, }, }, + kind: "module", range: [92, 116], loc: { @@ -62,6 +63,7 @@ Program { end: { column: 26, line: 5 }, }, }, + kind: "namespace", range: [119, 146], loc: { @@ -89,6 +91,7 @@ Program { end: { column: 14, line: 3 }, }, }, + kind: "global", range: [73, 148], loc: { diff --git a/packages/ast-spec/src/legacy-fixtures/namespaces-and-modules/fixtures/global-module-declaration/snapshots/5-AST-Alignment-AST.shot b/packages/ast-spec/src/legacy-fixtures/namespaces-and-modules/fixtures/global-module-declaration/snapshots/5-AST-Alignment-AST.shot index 33e8853dea71..3256de744361 100644 --- a/packages/ast-spec/src/legacy-fixtures/namespaces-and-modules/fixtures/global-module-declaration/snapshots/5-AST-Alignment-AST.shot +++ b/packages/ast-spec/src/legacy-fixtures/namespaces-and-modules/fixtures/global-module-declaration/snapshots/5-AST-Alignment-AST.shot @@ -2,5 +2,114 @@ exports[`AST Fixtures legacy-fixtures namespaces-and-modules global-module-declaration AST Alignment - AST 1`] = ` "Snapshot Diff: -Compared values have no visual difference." +- TSESTree ++ Babel + + Program { + type: 'Program', + body: Array [ + TSModuleDeclaration { + type: 'TSModuleDeclaration', + body: TSModuleBlock { + type: 'TSModuleBlock', + body: Array [ + TSModuleDeclaration { + type: 'TSModuleDeclaration', + body: TSModuleBlock { + type: 'TSModuleBlock', + body: Array [], + + range: [114, 116], + loc: { + start: { column: 24, line: 4 }, + end: { column: 26, line: 4 }, + }, + }, + declare: true, + id: Identifier { + type: 'Identifier', + name: 'global', + + range: [107, 113], + loc: { + start: { column: 17, line: 4 }, + end: { column: 23, line: 4 }, + }, + }, +- kind: 'module', + + range: [92, 116], + loc: { + start: { column: 2, line: 4 }, + end: { column: 26, line: 4 }, + }, + }, + TSModuleDeclaration { + type: 'TSModuleDeclaration', + body: TSModuleBlock { + type: 'TSModuleBlock', + body: Array [], + + range: [144, 146], + loc: { + start: { column: 27, line: 5 }, + end: { column: 29, line: 5 }, + }, + }, + declare: true, + id: Identifier { + type: 'Identifier', + name: 'global', + + range: [137, 143], + loc: { + start: { column: 20, line: 5 }, + end: { column: 26, line: 5 }, + }, + }, +- kind: 'namespace', + + range: [119, 146], + loc: { + start: { column: 2, line: 5 }, + end: { column: 29, line: 5 }, + }, + }, + ], + + range: [88, 148], + loc: { + start: { column: 15, line: 3 }, + end: { column: 1, line: 6 }, + }, + }, + declare: true, + global: true, + id: Identifier { + type: 'Identifier', + name: 'global', + + range: [81, 87], + loc: { + start: { column: 8, line: 3 }, + end: { column: 14, line: 3 }, + }, + }, +- kind: 'global', + + range: [73, 148], + loc: { + start: { column: 0, line: 3 }, + end: { column: 1, line: 6 }, + }, + }, + ], + sourceType: 'script', + + range: [73, 149], + loc: { + start: { column: 0, line: 3 }, + end: { column: 0, line: 7 }, + }, + }" `; diff --git a/packages/ast-spec/src/legacy-fixtures/namespaces-and-modules/fixtures/module-with-default-exports/snapshots/1-TSESTree-AST.shot b/packages/ast-spec/src/legacy-fixtures/namespaces-and-modules/fixtures/module-with-default-exports/snapshots/1-TSESTree-AST.shot index 57b0ed0ed584..8ad7040deeec 100644 --- a/packages/ast-spec/src/legacy-fixtures/namespaces-and-modules/fixtures/module-with-default-exports/snapshots/1-TSESTree-AST.shot +++ b/packages/ast-spec/src/legacy-fixtures/namespaces-and-modules/fixtures/module-with-default-exports/snapshots/1-TSESTree-AST.shot @@ -187,6 +187,7 @@ Program { end: { column: 12, line: 3 }, }, }, + kind: "module", range: [73, 174], loc: { diff --git a/packages/ast-spec/src/legacy-fixtures/namespaces-and-modules/fixtures/module-with-default-exports/snapshots/5-AST-Alignment-AST.shot b/packages/ast-spec/src/legacy-fixtures/namespaces-and-modules/fixtures/module-with-default-exports/snapshots/5-AST-Alignment-AST.shot index f7882ef62079..934dda17d284 100644 --- a/packages/ast-spec/src/legacy-fixtures/namespaces-and-modules/fixtures/module-with-default-exports/snapshots/5-AST-Alignment-AST.shot +++ b/packages/ast-spec/src/legacy-fixtures/namespaces-and-modules/fixtures/module-with-default-exports/snapshots/5-AST-Alignment-AST.shot @@ -191,6 +191,7 @@ exports[`AST Fixtures legacy-fixtures namespaces-and-modules module-with-default end: { column: 12, line: 3 }, }, }, +- kind: 'module', range: [73, 174], loc: { diff --git a/packages/ast-spec/src/legacy-fixtures/namespaces-and-modules/fixtures/nested-internal-module/snapshots/1-TSESTree-AST.shot b/packages/ast-spec/src/legacy-fixtures/namespaces-and-modules/fixtures/nested-internal-module/snapshots/1-TSESTree-AST.shot index d2b129beb751..e88155e93516 100644 --- a/packages/ast-spec/src/legacy-fixtures/namespaces-and-modules/fixtures/nested-internal-module/snapshots/1-TSESTree-AST.shot +++ b/packages/ast-spec/src/legacy-fixtures/namespaces-and-modules/fixtures/nested-internal-module/snapshots/1-TSESTree-AST.shot @@ -339,6 +339,7 @@ Program { end: { column: 17, line: 8 }, }, }, + kind: "module", range: [207, 273], loc: { @@ -374,6 +375,7 @@ Program { end: { column: 8, line: 3 }, }, }, + kind: "module", range: [73, 275], loc: { diff --git a/packages/ast-spec/src/legacy-fixtures/namespaces-and-modules/fixtures/nested-internal-module/snapshots/5-AST-Alignment-AST.shot b/packages/ast-spec/src/legacy-fixtures/namespaces-and-modules/fixtures/nested-internal-module/snapshots/5-AST-Alignment-AST.shot index a7f07ea2823e..1b64e4bd8e89 100644 --- a/packages/ast-spec/src/legacy-fixtures/namespaces-and-modules/fixtures/nested-internal-module/snapshots/5-AST-Alignment-AST.shot +++ b/packages/ast-spec/src/legacy-fixtures/namespaces-and-modules/fixtures/nested-internal-module/snapshots/5-AST-Alignment-AST.shot @@ -343,6 +343,7 @@ exports[`AST Fixtures legacy-fixtures namespaces-and-modules nested-internal-mod end: { column: 17, line: 8 }, }, }, +- kind: 'module', range: [207, 273], loc: { @@ -378,6 +379,7 @@ exports[`AST Fixtures legacy-fixtures namespaces-and-modules nested-internal-mod end: { column: 8, line: 3 }, }, }, +- kind: 'module', range: [73, 275], loc: { diff --git a/packages/ast-spec/src/legacy-fixtures/namespaces-and-modules/fixtures/shorthand-ambient-module-declaration/snapshots/1-TSESTree-AST.shot b/packages/ast-spec/src/legacy-fixtures/namespaces-and-modules/fixtures/shorthand-ambient-module-declaration/snapshots/1-TSESTree-AST.shot index 09f4217111fb..7f7359ae7fa6 100644 --- a/packages/ast-spec/src/legacy-fixtures/namespaces-and-modules/fixtures/shorthand-ambient-module-declaration/snapshots/1-TSESTree-AST.shot +++ b/packages/ast-spec/src/legacy-fixtures/namespaces-and-modules/fixtures/shorthand-ambient-module-declaration/snapshots/1-TSESTree-AST.shot @@ -18,6 +18,7 @@ Program { end: { column: 31, line: 3 }, }, }, + kind: "module", range: [73, 105], loc: { diff --git a/packages/ast-spec/src/legacy-fixtures/namespaces-and-modules/fixtures/shorthand-ambient-module-declaration/snapshots/5-AST-Alignment-AST.shot b/packages/ast-spec/src/legacy-fixtures/namespaces-and-modules/fixtures/shorthand-ambient-module-declaration/snapshots/5-AST-Alignment-AST.shot index c44cfa6ec3e8..99c15addea30 100644 --- a/packages/ast-spec/src/legacy-fixtures/namespaces-and-modules/fixtures/shorthand-ambient-module-declaration/snapshots/5-AST-Alignment-AST.shot +++ b/packages/ast-spec/src/legacy-fixtures/namespaces-and-modules/fixtures/shorthand-ambient-module-declaration/snapshots/5-AST-Alignment-AST.shot @@ -2,5 +2,41 @@ exports[`AST Fixtures legacy-fixtures namespaces-and-modules shorthand-ambient-module-declaration AST Alignment - AST 1`] = ` "Snapshot Diff: -Compared values have no visual difference." +- TSESTree ++ Babel + + Program { + type: 'Program', + body: Array [ + TSModuleDeclaration { + type: 'TSModuleDeclaration', + declare: true, + id: Literal { + type: 'Literal', + raw: '\\\\'hot-new-module\\\\'', + value: 'hot-new-module', + + range: [88, 104], + loc: { + start: { column: 15, line: 3 }, + end: { column: 31, line: 3 }, + }, + }, +- kind: 'module', + + range: [73, 105], + loc: { + start: { column: 0, line: 3 }, + end: { column: 32, line: 3 }, + }, + }, + ], + sourceType: 'script', + + range: [73, 106], + loc: { + start: { column: 0, line: 3 }, + end: { column: 0, line: 4 }, + }, + }" `; diff --git a/packages/ast-spec/tests/fixtures-with-differences-ast.shot b/packages/ast-spec/tests/fixtures-with-differences-ast.shot index 597fbbeb4628..7602cbedcdc1 100644 --- a/packages/ast-spec/tests/fixtures-with-differences-ast.shot +++ b/packages/ast-spec/tests/fixtures-with-differences-ast.shot @@ -171,14 +171,18 @@ Set { "legacy-fixtures/class-decorators/fixtures/class-parameter-property/fixture.ts", "legacy-fixtures/class-decorators/fixtures/export-default-class-decorator/fixture.ts", "legacy-fixtures/class-decorators/fixtures/export-named-class-decorator/fixture.ts", + "legacy-fixtures/declare/fixtures/module/fixture.ts", + "legacy-fixtures/declare/fixtures/namespace/fixture.ts", "legacy-fixtures/method-decorators/fixtures/method-decorator-factory-instance-member/fixture.ts", "legacy-fixtures/method-decorators/fixtures/method-decorator-factory-static-member/fixture.ts", "legacy-fixtures/method-decorators/fixtures/method-decorator-instance-member/fixture.ts", "legacy-fixtures/method-decorators/fixtures/method-decorator-static-member/fixture.ts", "legacy-fixtures/namespaces-and-modules/fixtures/ambient-module-declaration-with-import/fixture.ts", "legacy-fixtures/namespaces-and-modules/fixtures/declare-namespace-with-exported-function/fixture.ts", + "legacy-fixtures/namespaces-and-modules/fixtures/global-module-declaration/fixture.ts", "legacy-fixtures/namespaces-and-modules/fixtures/module-with-default-exports/fixture.ts", "legacy-fixtures/namespaces-and-modules/fixtures/nested-internal-module/fixture.ts", + "legacy-fixtures/namespaces-and-modules/fixtures/shorthand-ambient-module-declaration/fixture.ts", "legacy-fixtures/parameter-decorators/fixtures/parameter-decorator-constructor/fixture.ts", "legacy-fixtures/parameter-decorators/fixtures/parameter-decorator-decorator-instance-member/fixture.ts", "legacy-fixtures/parameter-decorators/fixtures/parameter-decorator-decorator-static-member/fixture.ts", From e0209170f5cfc166c90f3efb096d350c09eea3d4 Mon Sep 17 00:00:00 2001 From: Brad Zacher Date: Fri, 10 Feb 2023 13:23:58 +1030 Subject: [PATCH 5/5] merge --- packages/ast-spec/src/declaration/TSModuleDeclaration/spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/ast-spec/src/declaration/TSModuleDeclaration/spec.ts b/packages/ast-spec/src/declaration/TSModuleDeclaration/spec.ts index 4d58ac28db56..3afa8aee8c62 100644 --- a/packages/ast-spec/src/declaration/TSModuleDeclaration/spec.ts +++ b/packages/ast-spec/src/declaration/TSModuleDeclaration/spec.ts @@ -55,7 +55,7 @@ interface TSModuleDeclarationBase extends BaseNode { modifiers?: Modifier[]; /** - * THe keyword used to define this module declaration + * The keyword used to define this module declaration * ``` * namespace Foo {} * ^^^^^^^^^ pFad - Phonifier reborn

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

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


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy