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 8bee64090fc..70aa834e199 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 00a19c01c58..d9b1ab535bb 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 424909a0e10..6d845973deb 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 bdf25926153..5dc4161ad9a 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 a0ad297f73c..17f75471076 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 29dc0c7a776..591ea8c8d32 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 74a329eeb58..026bdc26251 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 d70930f793c..75dd7304dfa 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 3559c1ce1a1..80f52eaeaa3 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 829de93e3df..36a5fb1365f 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 da4f7cdc9af..543f49f139c 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 f13f22dfe7d..629052e8a65 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 3dfc069dda7..c0f09867e6f 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 d442f261db2..9c2311d4b6f 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 c373a655222..d808958c70e 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 614b9695a3c..48f1c28a6f6 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 e6303e2d3ed..05e6c65aa80 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 a0aa056256b..1d16afdfbbb 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 98cd5bbe817..69dbfa38ebb 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 a7a16eee58a..5a99e367a51 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 e077d1648e1..3afa8aee8c6 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) - make this `false` if not `global` + // TODO - remove this in the next major (we have `.kind` now) global?: boolean; /** * Whether the module is `declare`d @@ -51,4 +53,86 @@ 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: 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/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 b77fc06d204..3f74d63a87e 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 c752ccbc4ea..8ce2d9d2915 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 0921c13c37c..54670d060d5 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 d570c43e3ea..620319c6645 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 17df9ce9c9f..28b9f673edc 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 9546b3d34b3..575a9a6bd39 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 85661223163..131440bf5fe 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 1d5ab506238..ba41672f843 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 392a9c23b52..3cdbc8537ae 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 42caff8c0fd..a6aff688ab8 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 543c0266dc8..c4767e22bd0 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 4e3ae341285..0281bcdcbc1 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 c44bb057e42..8177f6c6582 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 33e8853dea7..3256de74436 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 57b0ed0ed58..8ad7040deee 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 f7882ef6207..934dda17d28 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 d2b129beb75..e88155e9351 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 a7f07ea2823..1b64e4bd8e8 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 09f4217111f..7f7359ae7fa 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 c44cfa6ec3e..99c15addea3 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 1f4ef690208..7602cbedcdc 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", @@ -161,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", diff --git a/packages/typescript-estree/src/convert.ts b/packages/typescript-estree/src/convert.ts index 70ee9da4e0c..4f7a89d97c1 100644 --- a/packages/typescript-estree/src/convert.ts +++ b/packages/typescript-estree/src/convert.ts @@ -2791,16 +2791,65 @@ export class Converter { case SyntaxKind.ModuleDeclaration: { const result = this.createNode(node, { type: AST_NODE_TYPES.TSModuleDeclaration, - id: this.convertChild(node.name), + // eslint-disable-next-line @typescript-eslint/explicit-function-return-type -- TODO - add ignore IIFE option + ...(() => { + 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, + body, + global: true, + } satisfies TSESTree.OptionalRangeAndLoc< + 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, + body, + } satisfies TSESTree.OptionalRangeAndLoc< + Omit + >; + } else { + return { + kind: 'module', + id, + ...(body != null ? { 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; - } + // ...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 4e79f84c3dd..2a65e53254b 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 6cbcd85aabe..28b76d987c4 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 b00d347e536..a786486f85d 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 c3849037460..3823ff07f05 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 eca74134194..0fc1dc4ce2b 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 1d6f5b2efda..5a3e8f29ed6 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 08ed9df51fb..08f680075d9 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 70ff82a2ec7..7151fa18dde 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 2284e4afed7..ad77c1edc36 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 37b859d967f..5b90f004775 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,