diff --git a/packages/ast-spec/src/declaration/ExportNamedDeclaration/fixtures/namespace/snapshots/1-Babel-AST.shot b/packages/ast-spec/src/declaration/ExportNamedDeclaration/fixtures/namespace/snapshots/1-Babel-AST.shot new file mode 100644 index 00000000000..494c5144247 --- /dev/null +++ b/packages/ast-spec/src/declaration/ExportNamedDeclaration/fixtures/namespace/snapshots/1-Babel-AST.shot @@ -0,0 +1,58 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`AST Fixtures declaration ExportNamedDeclaration namespace Babel - AST 1`] = ` +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 }, + }, + }, + + 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/ExportNamedDeclaration/fixtures/namespace/snapshots/2-Babel-Tokens.shot b/packages/ast-spec/src/declaration/ExportNamedDeclaration/fixtures/namespace/snapshots/2-Babel-Tokens.shot new file mode 100644 index 00000000000..0a3d1ca1dee --- /dev/null +++ b/packages/ast-spec/src/declaration/ExportNamedDeclaration/fixtures/namespace/snapshots/2-Babel-Tokens.shot @@ -0,0 +1,56 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`AST Fixtures declaration ExportNamedDeclaration namespace Babel - Tokens 1`] = ` +Array [ + Keyword { + type: "Keyword", + value: "export", + + range: [0, 6], + loc: { + start: { column: 0, line: 1 }, + end: { column: 6, line: 1 }, + }, + }, + Identifier { + type: "Identifier", + value: "namespace", + + range: [7, 16], + loc: { + start: { column: 7, line: 1 }, + end: { column: 16, line: 1 }, + }, + }, + Identifier { + type: "Identifier", + value: "Foo", + + range: [17, 20], + loc: { + start: { column: 17, line: 1 }, + end: { column: 20, line: 1 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "{", + + range: [21, 22], + loc: { + start: { column: 21, line: 1 }, + end: { column: 22, line: 1 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "}", + + range: [22, 23], + loc: { + start: { column: 22, line: 1 }, + end: { column: 23, line: 1 }, + }, + }, +] +`; diff --git a/packages/ast-spec/src/declaration/TSModuleDeclaration/fixtures/namespace-declare/snapshots/1-Babel-AST.shot b/packages/ast-spec/src/declaration/TSModuleDeclaration/fixtures/namespace-declare/snapshots/1-Babel-AST.shot new file mode 100644 index 00000000000..26936650860 --- /dev/null +++ b/packages/ast-spec/src/declaration/TSModuleDeclaration/fixtures/namespace-declare/snapshots/1-Babel-AST.shot @@ -0,0 +1,46 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`AST Fixtures declaration TSModuleDeclaration namespace-declare Babel - AST 1`] = ` +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 }, + }, + }, + + 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-declare/snapshots/2-Babel-Tokens.shot b/packages/ast-spec/src/declaration/TSModuleDeclaration/fixtures/namespace-declare/snapshots/2-Babel-Tokens.shot new file mode 100644 index 00000000000..374070330ed --- /dev/null +++ b/packages/ast-spec/src/declaration/TSModuleDeclaration/fixtures/namespace-declare/snapshots/2-Babel-Tokens.shot @@ -0,0 +1,56 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`AST Fixtures declaration TSModuleDeclaration namespace-declare Babel - Tokens 1`] = ` +Array [ + Identifier { + type: "Identifier", + value: "declare", + + range: [0, 7], + loc: { + start: { column: 0, line: 1 }, + end: { column: 7, line: 1 }, + }, + }, + Identifier { + type: "Identifier", + value: "namespace", + + range: [8, 17], + loc: { + start: { column: 8, line: 1 }, + end: { column: 17, line: 1 }, + }, + }, + Identifier { + type: "Identifier", + value: "F", + + range: [18, 19], + loc: { + start: { column: 18, line: 1 }, + end: { column: 19, line: 1 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "{", + + range: [20, 21], + loc: { + start: { column: 20, line: 1 }, + end: { column: 21, line: 1 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "}", + + range: [21, 22], + loc: { + start: { column: 21, line: 1 }, + end: { column: 22, line: 1 }, + }, + }, +] +`; diff --git a/packages/ast-spec/src/declaration/TSModuleDeclaration/fixtures/namespace-id-identifier/snapshots/1-Babel-AST.shot b/packages/ast-spec/src/declaration/TSModuleDeclaration/fixtures/namespace-id-identifier/snapshots/1-Babel-AST.shot new file mode 100644 index 00000000000..2e47480e044 --- /dev/null +++ b/packages/ast-spec/src/declaration/TSModuleDeclaration/fixtures/namespace-id-identifier/snapshots/1-Babel-AST.shot @@ -0,0 +1,45 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`AST Fixtures declaration TSModuleDeclaration namespace-id-identifier Babel - AST 1`] = ` +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 }, + }, + }, + + 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-identifier/snapshots/2-Babel-Tokens.shot b/packages/ast-spec/src/declaration/TSModuleDeclaration/fixtures/namespace-id-identifier/snapshots/2-Babel-Tokens.shot new file mode 100644 index 00000000000..1fb07e00228 --- /dev/null +++ b/packages/ast-spec/src/declaration/TSModuleDeclaration/fixtures/namespace-id-identifier/snapshots/2-Babel-Tokens.shot @@ -0,0 +1,46 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`AST Fixtures declaration TSModuleDeclaration namespace-id-identifier Babel - Tokens 1`] = ` +Array [ + Identifier { + type: "Identifier", + value: "namespace", + + range: [0, 9], + loc: { + start: { column: 0, line: 1 }, + end: { column: 9, line: 1 }, + }, + }, + Identifier { + type: "Identifier", + value: "F", + + range: [10, 11], + loc: { + start: { column: 10, line: 1 }, + end: { column: 11, line: 1 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "{", + + range: [12, 13], + loc: { + start: { column: 12, line: 1 }, + end: { column: 13, line: 1 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "}", + + range: [13, 14], + loc: { + start: { column: 13, line: 1 }, + end: { column: 14, line: 1 }, + }, + }, +] +`; 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 69dbfa38ebb..895c60ac574 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 @@ -6,64 +6,62 @@ Program { body: Array [ TSModuleDeclaration { type: "TSModuleDeclaration", - body: TSModuleDeclaration { - type: "TSModuleDeclaration", - body: TSModuleDeclaration { - type: "TSModuleDeclaration", - body: TSModuleBlock { - type: "TSModuleBlock", - body: Array [], + body: TSModuleBlock { + type: "TSModuleBlock", + body: Array [], - range: [16, 18], + range: [16, 18], + loc: { + start: { column: 16, line: 1 }, + end: { column: 18, line: 1 }, + }, + }, + id: TSQualifiedName { + type: "TSQualifiedName", + left: TSQualifiedName { + type: "TSQualifiedName", + left: Identifier { + type: "Identifier", + name: "A", + + range: [10, 11], loc: { - start: { column: 16, line: 1 }, - end: { column: 18, line: 1 }, + start: { column: 10, line: 1 }, + end: { column: 11, line: 1 }, }, }, - id: Identifier { + right: Identifier { type: "Identifier", - name: "C", + name: "B", - range: [14, 15], + range: [12, 13], loc: { - start: { column: 14, line: 1 }, - end: { column: 15, line: 1 }, + start: { column: 12, line: 1 }, + end: { column: 13, line: 1 }, }, }, - kind: "namespace", - range: [14, 18], + range: [10, 13], loc: { - start: { column: 14, line: 1 }, - end: { column: 18, line: 1 }, + start: { column: 10, line: 1 }, + end: { column: 13, line: 1 }, }, }, - id: Identifier { + right: Identifier { type: "Identifier", - name: "B", + name: "C", - range: [12, 13], + range: [14, 15], loc: { - start: { column: 12, line: 1 }, - end: { column: 13, line: 1 }, + start: { column: 14, line: 1 }, + end: { column: 15, 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], + range: [10, 15], loc: { start: { column: 10, line: 1 }, - end: { column: 11, line: 1 }, + end: { column: 15, line: 1 }, }, }, kind: "namespace", 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 5a99e367a51..21215095129 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 @@ -10,64 +10,97 @@ exports[`AST Fixtures declaration TSModuleDeclaration namespace-id-qualified-nam body: Array [ TSModuleDeclaration { type: 'TSModuleDeclaration', - body: TSModuleDeclaration { - type: 'TSModuleDeclaration', - body: TSModuleDeclaration { - type: 'TSModuleDeclaration', - body: TSModuleBlock { - type: 'TSModuleBlock', - body: Array [], +- body: TSModuleBlock { +- type: 'TSModuleBlock', +- body: Array [], +- +- range: [16, 18], +- loc: { +- start: { column: 16, line: 1 }, +- end: { column: 18, line: 1 }, +- }, +- }, +- id: TSQualifiedName { +- type: 'TSQualifiedName', +- left: TSQualifiedName { +- type: 'TSQualifiedName', +- left: Identifier { +- type: 'Identifier', +- name: 'A', ++ body: TSModuleDeclaration { ++ type: 'TSModuleDeclaration', ++ body: TSModuleDeclaration { ++ type: 'TSModuleDeclaration', ++ body: TSModuleBlock { ++ type: 'TSModuleBlock', ++ body: Array [], - range: [16, 18], +- range: [10, 11], ++ range: [16, 18], loc: { - start: { column: 16, line: 1 }, - end: { column: 18, line: 1 }, +- start: { column: 10, line: 1 }, +- end: { column: 11, line: 1 }, ++ start: { column: 16, line: 1 }, ++ end: { column: 18, line: 1 }, }, }, - id: Identifier { +- right: Identifier { ++ id: Identifier { type: 'Identifier', - name: 'C', +- name: 'B', ++ name: 'C', - range: [14, 15], +- range: [12, 13], ++ range: [14, 15], loc: { - start: { column: 14, line: 1 }, - end: { column: 15, line: 1 }, +- start: { column: 12, line: 1 }, +- end: { column: 13, line: 1 }, ++ start: { column: 14, line: 1 }, ++ end: { column: 15, line: 1 }, }, }, -- kind: 'namespace', - range: [14, 18], +- range: [10, 13], ++ range: [14, 18], loc: { - start: { column: 14, line: 1 }, - end: { column: 18, line: 1 }, +- start: { column: 10, line: 1 }, +- end: { column: 13, line: 1 }, ++ start: { column: 14, line: 1 }, ++ end: { column: 18, line: 1 }, }, }, - id: Identifier { +- right: Identifier { ++ id: Identifier { type: 'Identifier', - name: 'B', +- name: 'C', ++ name: 'B', - range: [12, 13], +- range: [14, 15], ++ range: [12, 13], loc: { - start: { column: 12, line: 1 }, - end: { column: 13, line: 1 }, +- start: { column: 14, line: 1 }, +- end: { column: 15, line: 1 }, ++ 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], +- range: [10, 15], ++ 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 }, +- end: { column: 15, line: 1 }, ++ end: { column: 11, line: 1 }, }, }, - kind: 'namespace', diff --git a/packages/ast-spec/src/declaration/TSModuleDeclaration/fixtures/namespace-nested-once/fixture.ts b/packages/ast-spec/src/declaration/TSModuleDeclaration/fixtures/namespace-nested-once/fixture.ts new file mode 100644 index 00000000000..e4db463ec8f --- /dev/null +++ b/packages/ast-spec/src/declaration/TSModuleDeclaration/fixtures/namespace-nested-once/fixture.ts @@ -0,0 +1 @@ +namespace abd.def {} diff --git a/packages/ast-spec/src/declaration/TSModuleDeclaration/fixtures/namespace-nested-once/snapshots/1-TSESTree-AST.shot b/packages/ast-spec/src/declaration/TSModuleDeclaration/fixtures/namespace-nested-once/snapshots/1-TSESTree-AST.shot new file mode 100644 index 00000000000..34e1101435b --- /dev/null +++ b/packages/ast-spec/src/declaration/TSModuleDeclaration/fixtures/namespace-nested-once/snapshots/1-TSESTree-AST.shot @@ -0,0 +1,65 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`AST Fixtures declaration TSModuleDeclaration namespace-nested-once TSESTree - AST 1`] = ` +Program { + type: "Program", + body: Array [ + TSModuleDeclaration { + type: "TSModuleDeclaration", + body: TSModuleBlock { + type: "TSModuleBlock", + body: Array [], + + range: [18, 20], + loc: { + start: { column: 18, line: 1 }, + end: { column: 20, line: 1 }, + }, + }, + id: TSQualifiedName { + type: "TSQualifiedName", + left: Identifier { + type: "Identifier", + name: "abd", + + range: [10, 13], + loc: { + start: { column: 10, line: 1 }, + end: { column: 13, line: 1 }, + }, + }, + right: Identifier { + type: "Identifier", + name: "def", + + range: [14, 17], + loc: { + start: { column: 14, line: 1 }, + end: { column: 17, line: 1 }, + }, + }, + + range: [10, 17], + loc: { + start: { column: 10, line: 1 }, + end: { column: 17, line: 1 }, + }, + }, + kind: "namespace", + + range: [0, 20], + loc: { + start: { column: 0, line: 1 }, + end: { column: 20, line: 1 }, + }, + }, + ], + sourceType: "script", + + range: [0, 21], + loc: { + start: { column: 0, line: 1 }, + end: { column: 0, line: 2 }, + }, +} +`; diff --git a/packages/ast-spec/src/declaration/TSModuleDeclaration/fixtures/namespace-nested-once/snapshots/2-TSESTree-Tokens.shot b/packages/ast-spec/src/declaration/TSModuleDeclaration/fixtures/namespace-nested-once/snapshots/2-TSESTree-Tokens.shot new file mode 100644 index 00000000000..23c1cc3f1ac --- /dev/null +++ b/packages/ast-spec/src/declaration/TSModuleDeclaration/fixtures/namespace-nested-once/snapshots/2-TSESTree-Tokens.shot @@ -0,0 +1,66 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`AST Fixtures declaration TSModuleDeclaration namespace-nested-once TSESTree - Tokens 1`] = ` +Array [ + Identifier { + type: "Identifier", + value: "namespace", + + range: [0, 9], + loc: { + start: { column: 0, line: 1 }, + end: { column: 9, line: 1 }, + }, + }, + Identifier { + type: "Identifier", + value: "abd", + + range: [10, 13], + loc: { + start: { column: 10, line: 1 }, + end: { column: 13, line: 1 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ".", + + range: [13, 14], + loc: { + start: { column: 13, line: 1 }, + end: { column: 14, line: 1 }, + }, + }, + Identifier { + type: "Identifier", + value: "def", + + range: [14, 17], + loc: { + start: { column: 14, line: 1 }, + end: { column: 17, line: 1 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "{", + + range: [18, 19], + loc: { + start: { column: 18, line: 1 }, + end: { column: 19, line: 1 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "}", + + range: [19, 20], + loc: { + start: { column: 19, line: 1 }, + end: { column: 20, line: 1 }, + }, + }, +] +`; diff --git a/packages/ast-spec/src/declaration/TSModuleDeclaration/fixtures/namespace-nested-once/snapshots/3-Babel-AST.shot b/packages/ast-spec/src/declaration/TSModuleDeclaration/fixtures/namespace-nested-once/snapshots/3-Babel-AST.shot new file mode 100644 index 00000000000..cd7fc6acd60 --- /dev/null +++ b/packages/ast-spec/src/declaration/TSModuleDeclaration/fixtures/namespace-nested-once/snapshots/3-Babel-AST.shot @@ -0,0 +1,64 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`AST Fixtures declaration TSModuleDeclaration namespace-nested-once Babel - AST 1`] = ` +Program { + type: "Program", + body: Array [ + TSModuleDeclaration { + type: "TSModuleDeclaration", + body: TSModuleDeclaration { + type: "TSModuleDeclaration", + body: TSModuleBlock { + type: "TSModuleBlock", + body: Array [], + + range: [18, 20], + loc: { + start: { column: 18, line: 1 }, + end: { column: 20, line: 1 }, + }, + }, + id: Identifier { + type: "Identifier", + name: "def", + + range: [14, 17], + loc: { + start: { column: 14, line: 1 }, + end: { column: 17, line: 1 }, + }, + }, + + range: [14, 20], + loc: { + start: { column: 14, line: 1 }, + end: { column: 20, line: 1 }, + }, + }, + id: Identifier { + type: "Identifier", + name: "abd", + + range: [10, 13], + loc: { + start: { column: 10, line: 1 }, + end: { column: 13, line: 1 }, + }, + }, + + range: [0, 20], + loc: { + start: { column: 0, line: 1 }, + end: { column: 20, line: 1 }, + }, + }, + ], + sourceType: "script", + + range: [0, 21], + loc: { + start: { column: 0, line: 1 }, + end: { column: 0, line: 2 }, + }, +} +`; diff --git a/packages/ast-spec/src/declaration/TSModuleDeclaration/fixtures/namespace-nested-once/snapshots/4-Babel-Tokens.shot b/packages/ast-spec/src/declaration/TSModuleDeclaration/fixtures/namespace-nested-once/snapshots/4-Babel-Tokens.shot new file mode 100644 index 00000000000..1779dbfd42f --- /dev/null +++ b/packages/ast-spec/src/declaration/TSModuleDeclaration/fixtures/namespace-nested-once/snapshots/4-Babel-Tokens.shot @@ -0,0 +1,66 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`AST Fixtures declaration TSModuleDeclaration namespace-nested-once Babel - Tokens 1`] = ` +Array [ + Identifier { + type: "Identifier", + value: "namespace", + + range: [0, 9], + loc: { + start: { column: 0, line: 1 }, + end: { column: 9, line: 1 }, + }, + }, + Identifier { + type: "Identifier", + value: "abd", + + range: [10, 13], + loc: { + start: { column: 10, line: 1 }, + end: { column: 13, line: 1 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ".", + + range: [13, 14], + loc: { + start: { column: 13, line: 1 }, + end: { column: 14, line: 1 }, + }, + }, + Identifier { + type: "Identifier", + value: "def", + + range: [14, 17], + loc: { + start: { column: 14, line: 1 }, + end: { column: 17, line: 1 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "{", + + range: [18, 19], + loc: { + start: { column: 18, line: 1 }, + end: { column: 19, line: 1 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "}", + + range: [19, 20], + loc: { + start: { column: 19, line: 1 }, + end: { column: 20, line: 1 }, + }, + }, +] +`; diff --git a/packages/ast-spec/src/declaration/TSModuleDeclaration/fixtures/namespace-nested-once/snapshots/5-AST-Alignment-AST.shot b/packages/ast-spec/src/declaration/TSModuleDeclaration/fixtures/namespace-nested-once/snapshots/5-AST-Alignment-AST.shot new file mode 100644 index 00000000000..5efa8c2f8b5 --- /dev/null +++ b/packages/ast-spec/src/declaration/TSModuleDeclaration/fixtures/namespace-nested-once/snapshots/5-AST-Alignment-AST.shot @@ -0,0 +1,90 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`AST Fixtures declaration TSModuleDeclaration namespace-nested-once AST Alignment - AST 1`] = ` +"Snapshot Diff: +- TSESTree ++ Babel + + Program { + type: 'Program', + body: Array [ + TSModuleDeclaration { + type: 'TSModuleDeclaration', +- body: TSModuleBlock { +- type: 'TSModuleBlock', +- body: Array [], +- +- range: [18, 20], +- loc: { +- start: { column: 18, line: 1 }, +- end: { column: 20, line: 1 }, +- }, +- }, +- id: TSQualifiedName { +- type: 'TSQualifiedName', +- left: Identifier { +- type: 'Identifier', +- name: 'abd', ++ body: TSModuleDeclaration { ++ type: 'TSModuleDeclaration', ++ body: TSModuleBlock { ++ type: 'TSModuleBlock', ++ body: Array [], + +- range: [10, 13], ++ range: [18, 20], + loc: { +- start: { column: 10, line: 1 }, +- end: { column: 13, line: 1 }, ++ start: { column: 18, line: 1 }, ++ end: { column: 20, line: 1 }, + }, + }, +- right: Identifier { ++ id: Identifier { + type: 'Identifier', + name: 'def', + + range: [14, 17], + loc: { + start: { column: 14, line: 1 }, + end: { column: 17, line: 1 }, + }, + }, + +- range: [10, 17], ++ range: [14, 20], ++ loc: { ++ start: { column: 14, line: 1 }, ++ end: { column: 20, line: 1 }, ++ }, ++ }, ++ id: Identifier { ++ type: 'Identifier', ++ name: 'abd', ++ ++ range: [10, 13], + loc: { + start: { column: 10, line: 1 }, +- end: { column: 17, line: 1 }, ++ end: { column: 13, line: 1 }, + }, + }, +- kind: 'namespace', + + range: [0, 20], + loc: { + start: { column: 0, line: 1 }, + end: { column: 20, line: 1 }, + }, + }, + ], + sourceType: 'script', + + range: [0, 21], + loc: { + start: { column: 0, line: 1 }, + end: { column: 0, line: 2 }, + }, + }" +`; diff --git a/packages/ast-spec/src/declaration/TSModuleDeclaration/fixtures/namespace-nested-once/snapshots/6-AST-Alignment-Tokens.shot b/packages/ast-spec/src/declaration/TSModuleDeclaration/fixtures/namespace-nested-once/snapshots/6-AST-Alignment-Tokens.shot new file mode 100644 index 00000000000..657e47e2dc1 --- /dev/null +++ b/packages/ast-spec/src/declaration/TSModuleDeclaration/fixtures/namespace-nested-once/snapshots/6-AST-Alignment-Tokens.shot @@ -0,0 +1,6 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`AST Fixtures declaration TSModuleDeclaration namespace-nested-once AST Alignment - Token 1`] = ` +"Snapshot Diff: +Compared values have no visual difference." +`; diff --git a/packages/ast-spec/src/declaration/TSModuleDeclaration/fixtures/namespace-nested-twice/fixture.ts b/packages/ast-spec/src/declaration/TSModuleDeclaration/fixtures/namespace-nested-twice/fixture.ts new file mode 100644 index 00000000000..aa16edb5ae5 --- /dev/null +++ b/packages/ast-spec/src/declaration/TSModuleDeclaration/fixtures/namespace-nested-twice/fixture.ts @@ -0,0 +1 @@ +namespace abc.def.ghi {} diff --git a/packages/ast-spec/src/declaration/TSModuleDeclaration/fixtures/namespace-nested-twice/snapshots/1-TSESTree-AST.shot b/packages/ast-spec/src/declaration/TSModuleDeclaration/fixtures/namespace-nested-twice/snapshots/1-TSESTree-AST.shot new file mode 100644 index 00000000000..a36e6371322 --- /dev/null +++ b/packages/ast-spec/src/declaration/TSModuleDeclaration/fixtures/namespace-nested-twice/snapshots/1-TSESTree-AST.shot @@ -0,0 +1,84 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`AST Fixtures declaration TSModuleDeclaration namespace-nested-twice TSESTree - AST 1`] = ` +Program { + type: "Program", + body: Array [ + TSModuleDeclaration { + type: "TSModuleDeclaration", + body: TSModuleBlock { + type: "TSModuleBlock", + body: Array [], + + range: [22, 24], + loc: { + start: { column: 22, line: 1 }, + end: { column: 24, line: 1 }, + }, + }, + id: TSQualifiedName { + type: "TSQualifiedName", + left: TSQualifiedName { + type: "TSQualifiedName", + left: Identifier { + type: "Identifier", + name: "abc", + + range: [10, 13], + loc: { + start: { column: 10, line: 1 }, + end: { column: 13, line: 1 }, + }, + }, + right: Identifier { + type: "Identifier", + name: "def", + + range: [14, 17], + loc: { + start: { column: 14, line: 1 }, + end: { column: 17, line: 1 }, + }, + }, + + range: [10, 17], + loc: { + start: { column: 10, line: 1 }, + end: { column: 17, line: 1 }, + }, + }, + right: Identifier { + type: "Identifier", + name: "ghi", + + range: [18, 21], + loc: { + start: { column: 18, line: 1 }, + end: { column: 21, line: 1 }, + }, + }, + + range: [10, 21], + loc: { + start: { column: 10, line: 1 }, + end: { column: 21, line: 1 }, + }, + }, + kind: "namespace", + + range: [0, 24], + loc: { + start: { column: 0, line: 1 }, + end: { column: 24, line: 1 }, + }, + }, + ], + sourceType: "script", + + range: [0, 25], + loc: { + start: { column: 0, line: 1 }, + end: { column: 0, line: 2 }, + }, +} +`; diff --git a/packages/ast-spec/src/declaration/TSModuleDeclaration/fixtures/namespace-nested-twice/snapshots/2-TSESTree-Tokens.shot b/packages/ast-spec/src/declaration/TSModuleDeclaration/fixtures/namespace-nested-twice/snapshots/2-TSESTree-Tokens.shot new file mode 100644 index 00000000000..4f2b06d094f --- /dev/null +++ b/packages/ast-spec/src/declaration/TSModuleDeclaration/fixtures/namespace-nested-twice/snapshots/2-TSESTree-Tokens.shot @@ -0,0 +1,86 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`AST Fixtures declaration TSModuleDeclaration namespace-nested-twice TSESTree - Tokens 1`] = ` +Array [ + Identifier { + type: "Identifier", + value: "namespace", + + range: [0, 9], + loc: { + start: { column: 0, line: 1 }, + end: { column: 9, line: 1 }, + }, + }, + Identifier { + type: "Identifier", + value: "abc", + + range: [10, 13], + loc: { + start: { column: 10, line: 1 }, + end: { column: 13, line: 1 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ".", + + range: [13, 14], + loc: { + start: { column: 13, line: 1 }, + end: { column: 14, line: 1 }, + }, + }, + Identifier { + type: "Identifier", + value: "def", + + range: [14, 17], + loc: { + start: { column: 14, line: 1 }, + end: { column: 17, line: 1 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ".", + + range: [17, 18], + loc: { + start: { column: 17, line: 1 }, + end: { column: 18, line: 1 }, + }, + }, + Identifier { + type: "Identifier", + value: "ghi", + + range: [18, 21], + loc: { + start: { column: 18, line: 1 }, + end: { column: 21, line: 1 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "{", + + range: [22, 23], + loc: { + start: { column: 22, line: 1 }, + end: { column: 23, line: 1 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "}", + + range: [23, 24], + loc: { + start: { column: 23, line: 1 }, + end: { column: 24, line: 1 }, + }, + }, +] +`; diff --git a/packages/ast-spec/src/declaration/TSModuleDeclaration/fixtures/namespace-nested-twice/snapshots/3-Babel-AST.shot b/packages/ast-spec/src/declaration/TSModuleDeclaration/fixtures/namespace-nested-twice/snapshots/3-Babel-AST.shot new file mode 100644 index 00000000000..d694d20934a --- /dev/null +++ b/packages/ast-spec/src/declaration/TSModuleDeclaration/fixtures/namespace-nested-twice/snapshots/3-Babel-AST.shot @@ -0,0 +1,83 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`AST Fixtures declaration TSModuleDeclaration namespace-nested-twice Babel - AST 1`] = ` +Program { + type: "Program", + body: Array [ + TSModuleDeclaration { + type: "TSModuleDeclaration", + body: TSModuleDeclaration { + type: "TSModuleDeclaration", + body: TSModuleDeclaration { + type: "TSModuleDeclaration", + body: TSModuleBlock { + type: "TSModuleBlock", + body: Array [], + + range: [22, 24], + loc: { + start: { column: 22, line: 1 }, + end: { column: 24, line: 1 }, + }, + }, + id: Identifier { + type: "Identifier", + name: "ghi", + + range: [18, 21], + loc: { + start: { column: 18, line: 1 }, + end: { column: 21, line: 1 }, + }, + }, + + range: [18, 24], + loc: { + start: { column: 18, line: 1 }, + end: { column: 24, line: 1 }, + }, + }, + id: Identifier { + type: "Identifier", + name: "def", + + range: [14, 17], + loc: { + start: { column: 14, line: 1 }, + end: { column: 17, line: 1 }, + }, + }, + + range: [14, 24], + loc: { + start: { column: 14, line: 1 }, + end: { column: 24, line: 1 }, + }, + }, + id: Identifier { + type: "Identifier", + name: "abc", + + range: [10, 13], + loc: { + start: { column: 10, line: 1 }, + end: { column: 13, line: 1 }, + }, + }, + + range: [0, 24], + loc: { + start: { column: 0, line: 1 }, + end: { column: 24, line: 1 }, + }, + }, + ], + sourceType: "script", + + range: [0, 25], + loc: { + start: { column: 0, line: 1 }, + end: { column: 0, line: 2 }, + }, +} +`; diff --git a/packages/ast-spec/src/declaration/TSModuleDeclaration/fixtures/namespace-nested-twice/snapshots/4-Babel-Tokens.shot b/packages/ast-spec/src/declaration/TSModuleDeclaration/fixtures/namespace-nested-twice/snapshots/4-Babel-Tokens.shot new file mode 100644 index 00000000000..8cf1c7e6e3b --- /dev/null +++ b/packages/ast-spec/src/declaration/TSModuleDeclaration/fixtures/namespace-nested-twice/snapshots/4-Babel-Tokens.shot @@ -0,0 +1,86 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`AST Fixtures declaration TSModuleDeclaration namespace-nested-twice Babel - Tokens 1`] = ` +Array [ + Identifier { + type: "Identifier", + value: "namespace", + + range: [0, 9], + loc: { + start: { column: 0, line: 1 }, + end: { column: 9, line: 1 }, + }, + }, + Identifier { + type: "Identifier", + value: "abc", + + range: [10, 13], + loc: { + start: { column: 10, line: 1 }, + end: { column: 13, line: 1 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ".", + + range: [13, 14], + loc: { + start: { column: 13, line: 1 }, + end: { column: 14, line: 1 }, + }, + }, + Identifier { + type: "Identifier", + value: "def", + + range: [14, 17], + loc: { + start: { column: 14, line: 1 }, + end: { column: 17, line: 1 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ".", + + range: [17, 18], + loc: { + start: { column: 17, line: 1 }, + end: { column: 18, line: 1 }, + }, + }, + Identifier { + type: "Identifier", + value: "ghi", + + range: [18, 21], + loc: { + start: { column: 18, line: 1 }, + end: { column: 21, line: 1 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "{", + + range: [22, 23], + loc: { + start: { column: 22, line: 1 }, + end: { column: 23, line: 1 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "}", + + range: [23, 24], + loc: { + start: { column: 23, line: 1 }, + end: { column: 24, line: 1 }, + }, + }, +] +`; diff --git a/packages/ast-spec/src/declaration/TSModuleDeclaration/fixtures/namespace-nested-twice/snapshots/5-AST-Alignment-AST.shot b/packages/ast-spec/src/declaration/TSModuleDeclaration/fixtures/namespace-nested-twice/snapshots/5-AST-Alignment-AST.shot new file mode 100644 index 00000000000..c7d69187d81 --- /dev/null +++ b/packages/ast-spec/src/declaration/TSModuleDeclaration/fixtures/namespace-nested-twice/snapshots/5-AST-Alignment-AST.shot @@ -0,0 +1,123 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`AST Fixtures declaration TSModuleDeclaration namespace-nested-twice AST Alignment - AST 1`] = ` +"Snapshot Diff: +- TSESTree ++ Babel + + Program { + type: 'Program', + body: Array [ + TSModuleDeclaration { + type: 'TSModuleDeclaration', +- body: TSModuleBlock { +- type: 'TSModuleBlock', +- body: Array [], +- +- range: [22, 24], +- loc: { +- start: { column: 22, line: 1 }, +- end: { column: 24, line: 1 }, +- }, +- }, +- id: TSQualifiedName { +- type: 'TSQualifiedName', +- left: TSQualifiedName { +- type: 'TSQualifiedName', +- left: Identifier { +- type: 'Identifier', +- name: 'abc', ++ body: TSModuleDeclaration { ++ type: 'TSModuleDeclaration', ++ body: TSModuleDeclaration { ++ type: 'TSModuleDeclaration', ++ body: TSModuleBlock { ++ type: 'TSModuleBlock', ++ body: Array [], + +- range: [10, 13], ++ range: [22, 24], + loc: { +- start: { column: 10, line: 1 }, +- end: { column: 13, line: 1 }, ++ start: { column: 22, line: 1 }, ++ end: { column: 24, line: 1 }, + }, + }, +- right: Identifier { ++ id: Identifier { + type: 'Identifier', +- name: 'def', ++ name: 'ghi', + +- range: [14, 17], ++ range: [18, 21], + loc: { +- start: { column: 14, line: 1 }, +- end: { column: 17, line: 1 }, ++ start: { column: 18, line: 1 }, ++ end: { column: 21, line: 1 }, + }, + }, + +- range: [10, 17], ++ range: [18, 24], + loc: { +- start: { column: 10, line: 1 }, +- end: { column: 17, line: 1 }, ++ start: { column: 18, line: 1 }, ++ end: { column: 24, line: 1 }, + }, + }, +- right: Identifier { ++ id: Identifier { + type: 'Identifier', +- name: 'ghi', ++ name: 'def', + +- range: [18, 21], ++ range: [14, 17], + loc: { +- start: { column: 18, line: 1 }, +- end: { column: 21, line: 1 }, ++ start: { column: 14, line: 1 }, ++ end: { column: 17, line: 1 }, + }, + }, + +- range: [10, 21], ++ range: [14, 24], ++ loc: { ++ start: { column: 14, line: 1 }, ++ end: { column: 24, line: 1 }, ++ }, ++ }, ++ id: Identifier { ++ type: 'Identifier', ++ name: 'abc', ++ ++ range: [10, 13], + loc: { + start: { column: 10, line: 1 }, +- end: { column: 21, line: 1 }, ++ end: { column: 13, line: 1 }, + }, + }, +- kind: 'namespace', + + range: [0, 24], + loc: { + start: { column: 0, line: 1 }, + end: { column: 24, line: 1 }, + }, + }, + ], + sourceType: 'script', + + range: [0, 25], + loc: { + start: { column: 0, line: 1 }, + end: { column: 0, line: 2 }, + }, + }" +`; diff --git a/packages/ast-spec/src/declaration/TSModuleDeclaration/fixtures/namespace-nested-twice/snapshots/6-AST-Alignment-Tokens.shot b/packages/ast-spec/src/declaration/TSModuleDeclaration/fixtures/namespace-nested-twice/snapshots/6-AST-Alignment-Tokens.shot new file mode 100644 index 00000000000..f0ac1cd2c04 --- /dev/null +++ b/packages/ast-spec/src/declaration/TSModuleDeclaration/fixtures/namespace-nested-twice/snapshots/6-AST-Alignment-Tokens.shot @@ -0,0 +1,6 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`AST Fixtures declaration TSModuleDeclaration namespace-nested-twice AST Alignment - Token 1`] = ` +"Snapshot Diff: +Compared values have no visual difference." +`; diff --git a/packages/ast-spec/src/declaration/TSModuleDeclaration/spec.ts b/packages/ast-spec/src/declaration/TSModuleDeclaration/spec.ts index 3184702206e..84fb5668100 100644 --- a/packages/ast-spec/src/declaration/TSModuleDeclaration/spec.ts +++ b/packages/ast-spec/src/declaration/TSModuleDeclaration/spec.ts @@ -3,20 +3,11 @@ 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 { TSQualifiedName } from '../../type/spec'; +import type { Literal } from '../../unions/Literal'; 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; /** @@ -27,13 +18,13 @@ interface TSModuleDeclarationBase extends BaseNode { * module 'a' {} * ``` */ - id: Identifier | StringLiteral; + id: Identifier | Literal | TSQualifiedName; /** * 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?: ModuleBody_TODOFixThis; + body?: TSModuleBlock; /** * Whether this is a global declaration * ``` @@ -70,9 +61,9 @@ interface TSModuleDeclarationBase extends BaseNode { export interface TSModuleDeclarationNamespace extends TSModuleDeclarationBase { kind: 'namespace'; // namespaces cannot have literal IDs - id: Identifier; + id: Identifier | TSQualifiedName; // namespaces must always have a body - body: ModuleBody_TODOFixThis; + body: TSModuleBlock; // TODO - remove this in the next major (we have `.kind` now) global?: undefined; @@ -126,7 +117,7 @@ export interface TSModuleDeclarationModuleWithIdentifierId kind: 'module'; id: Identifier; // modules with an Identifier must always have a body - body: ModuleBody_TODOFixThis; + body: TSModuleBlock; } export type TSModuleDeclaration = diff --git a/packages/ast-spec/src/legacy-fixtures/basics/fixtures/directive-in-namespace/snapshots/1-Babel-AST.shot b/packages/ast-spec/src/legacy-fixtures/basics/fixtures/directive-in-namespace/snapshots/1-Babel-AST.shot new file mode 100644 index 00000000000..79bfb11b065 --- /dev/null +++ b/packages/ast-spec/src/legacy-fixtures/basics/fixtures/directive-in-namespace/snapshots/1-Babel-AST.shot @@ -0,0 +1,128 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`AST Fixtures legacy-fixtures basics directive-in-namespace Babel - AST 1`] = ` +Program { + type: "Program", + body: Array [ + TSModuleDeclaration { + type: "TSModuleDeclaration", + body: TSModuleBlock { + type: "TSModuleBlock", + body: Array [ + ExpressionStatement { + type: "ExpressionStatement", + expression: Literal { + type: "Literal", + raw: "'use strict'", + value: "use strict", + + range: [91, 103], + loc: { + start: { column: 2, line: 4 }, + end: { column: 14, line: 4 }, + }, + }, + + range: [91, 104], + loc: { + start: { column: 2, line: 4 }, + end: { column: 15, line: 4 }, + }, + }, + VariableDeclaration { + type: "VariableDeclaration", + declarations: Array [ + VariableDeclarator { + type: "VariableDeclarator", + id: Identifier { + type: "Identifier", + name: "a", + + range: [111, 112], + loc: { + start: { column: 6, line: 5 }, + end: { column: 7, line: 5 }, + }, + }, + init: Literal { + type: "Literal", + raw: "1", + value: 1, + + range: [115, 116], + loc: { + start: { column: 10, line: 5 }, + end: { column: 11, line: 5 }, + }, + }, + + range: [111, 116], + loc: { + start: { column: 6, line: 5 }, + end: { column: 11, line: 5 }, + }, + }, + ], + kind: "var", + + range: [107, 117], + loc: { + start: { column: 2, line: 5 }, + end: { column: 12, line: 5 }, + }, + }, + ExpressionStatement { + type: "ExpressionStatement", + expression: Literal { + type: "Literal", + raw: "'use strict'", + value: "use strict", + + range: [120, 132], + loc: { + start: { column: 2, line: 6 }, + end: { column: 14, line: 6 }, + }, + }, + + range: [120, 133], + loc: { + start: { column: 2, line: 6 }, + end: { column: 15, line: 6 }, + }, + }, + ], + + range: [87, 135], + loc: { + start: { column: 14, line: 3 }, + end: { column: 1, line: 7 }, + }, + }, + id: Identifier { + type: "Identifier", + name: "foo", + + range: [83, 86], + loc: { + start: { column: 10, line: 3 }, + end: { column: 13, line: 3 }, + }, + }, + + range: [73, 135], + loc: { + start: { column: 0, line: 3 }, + end: { column: 1, line: 7 }, + }, + }, + ], + sourceType: "script", + + range: [73, 136], + loc: { + start: { column: 0, line: 3 }, + end: { column: 0, line: 8 }, + }, +} +`; diff --git a/packages/ast-spec/src/legacy-fixtures/basics/fixtures/directive-in-namespace/snapshots/2-Babel-Tokens.shot b/packages/ast-spec/src/legacy-fixtures/basics/fixtures/directive-in-namespace/snapshots/2-Babel-Tokens.shot new file mode 100644 index 00000000000..d3ffef96096 --- /dev/null +++ b/packages/ast-spec/src/legacy-fixtures/basics/fixtures/directive-in-namespace/snapshots/2-Babel-Tokens.shot @@ -0,0 +1,136 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`AST Fixtures legacy-fixtures basics directive-in-namespace Babel - Tokens 1`] = ` +Array [ + Identifier { + type: "Identifier", + value: "namespace", + + range: [73, 82], + loc: { + start: { column: 0, line: 3 }, + end: { column: 9, line: 3 }, + }, + }, + Identifier { + type: "Identifier", + value: "foo", + + range: [83, 86], + loc: { + start: { column: 10, line: 3 }, + end: { column: 13, line: 3 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "{", + + range: [87, 88], + loc: { + start: { column: 14, line: 3 }, + end: { column: 15, line: 3 }, + }, + }, + String { + type: "String", + value: "'use strict'", + + range: [91, 103], + loc: { + start: { column: 2, line: 4 }, + end: { column: 14, line: 4 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ";", + + range: [103, 104], + loc: { + start: { column: 14, line: 4 }, + end: { column: 15, line: 4 }, + }, + }, + Keyword { + type: "Keyword", + value: "var", + + range: [107, 110], + loc: { + start: { column: 2, line: 5 }, + end: { column: 5, line: 5 }, + }, + }, + Identifier { + type: "Identifier", + value: "a", + + range: [111, 112], + loc: { + start: { column: 6, line: 5 }, + end: { column: 7, line: 5 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "=", + + range: [113, 114], + loc: { + start: { column: 8, line: 5 }, + end: { column: 9, line: 5 }, + }, + }, + Numeric { + type: "Numeric", + value: "1", + + range: [115, 116], + loc: { + start: { column: 10, line: 5 }, + end: { column: 11, line: 5 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ";", + + range: [116, 117], + loc: { + start: { column: 11, line: 5 }, + end: { column: 12, line: 5 }, + }, + }, + String { + type: "String", + value: "'use strict'", + + range: [120, 132], + loc: { + start: { column: 2, line: 6 }, + end: { column: 14, line: 6 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ";", + + range: [132, 133], + loc: { + start: { column: 14, line: 6 }, + end: { column: 15, line: 6 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "}", + + range: [134, 135], + loc: { + start: { column: 0, line: 7 }, + end: { column: 1, line: 7 }, + }, + }, +] +`; diff --git a/packages/ast-spec/src/legacy-fixtures/declare/fixtures/namespace/snapshots/1-Babel-AST.shot b/packages/ast-spec/src/legacy-fixtures/declare/fixtures/namespace/snapshots/1-Babel-AST.shot new file mode 100644 index 00000000000..34abdd0420b --- /dev/null +++ b/packages/ast-spec/src/legacy-fixtures/declare/fixtures/namespace/snapshots/1-Babel-AST.shot @@ -0,0 +1,46 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`AST Fixtures legacy-fixtures declare namespace Babel - AST 1`] = ` +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 }, + }, + }, + + 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/declare/fixtures/namespace/snapshots/2-Babel-Tokens.shot b/packages/ast-spec/src/legacy-fixtures/declare/fixtures/namespace/snapshots/2-Babel-Tokens.shot new file mode 100644 index 00000000000..014f4d3e257 --- /dev/null +++ b/packages/ast-spec/src/legacy-fixtures/declare/fixtures/namespace/snapshots/2-Babel-Tokens.shot @@ -0,0 +1,56 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`AST Fixtures legacy-fixtures declare namespace Babel - Tokens 1`] = ` +Array [ + Identifier { + type: "Identifier", + value: "declare", + + range: [73, 80], + loc: { + start: { column: 0, line: 3 }, + end: { column: 7, line: 3 }, + }, + }, + Identifier { + type: "Identifier", + value: "namespace", + + range: [81, 90], + loc: { + start: { column: 8, line: 3 }, + end: { column: 17, line: 3 }, + }, + }, + Identifier { + type: "Identifier", + value: "Foo", + + range: [91, 94], + loc: { + start: { column: 18, line: 3 }, + end: { column: 21, line: 3 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "{", + + range: [95, 96], + loc: { + start: { column: 22, line: 3 }, + end: { column: 23, line: 3 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "}", + + range: [96, 97], + loc: { + start: { column: 23, line: 3 }, + end: { column: 24, line: 3 }, + }, + }, +] +`; diff --git a/packages/ast-spec/src/legacy-fixtures/namespaces-and-modules/fixtures/declare-namespace-with-exported-function/snapshots/1-Babel-AST.shot b/packages/ast-spec/src/legacy-fixtures/namespaces-and-modules/fixtures/declare-namespace-with-exported-function/snapshots/1-Babel-AST.shot new file mode 100644 index 00000000000..d153d51196f --- /dev/null +++ b/packages/ast-spec/src/legacy-fixtures/namespaces-and-modules/fixtures/declare-namespace-with-exported-function/snapshots/1-Babel-AST.shot @@ -0,0 +1,160 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`AST Fixtures legacy-fixtures namespaces-and-modules declare-namespace-with-exported-function Babel - AST 1`] = ` +Program { + type: "Program", + body: Array [ + TSModuleDeclaration { + type: "TSModuleDeclaration", + body: TSModuleBlock { + type: "TSModuleBlock", + body: Array [ + ExportNamedDeclaration { + type: "ExportNamedDeclaration", + assertions: Array [], + declaration: TSDeclareFunction { + type: "TSDeclareFunction", + async: false, + expression: false, + generator: false, + id: Identifier { + type: "Identifier", + name: "select", + + range: [114, 120], + loc: { + start: { column: 18, line: 4 }, + end: { column: 24, line: 4 }, + }, + }, + params: Array [ + Identifier { + type: "Identifier", + name: "selector", + typeAnnotation: TSTypeAnnotation { + type: "TSTypeAnnotation", + typeAnnotation: TSStringKeyword { + type: "TSStringKeyword", + + range: [131, 137], + loc: { + start: { column: 35, line: 4 }, + end: { column: 41, line: 4 }, + }, + }, + + range: [129, 137], + loc: { + start: { column: 33, line: 4 }, + end: { column: 41, line: 4 }, + }, + }, + + range: [121, 137], + loc: { + start: { column: 25, line: 4 }, + end: { column: 41, line: 4 }, + }, + }, + ], + returnType: TSTypeAnnotation { + type: "TSTypeAnnotation", + typeAnnotation: TSTypeReference { + type: "TSTypeReference", + typeName: Identifier { + type: "Identifier", + name: "Selection", + + range: [140, 149], + loc: { + start: { column: 44, line: 4 }, + end: { column: 53, line: 4 }, + }, + }, + typeParameters: TSTypeParameterInstantiation { + type: "TSTypeParameterInstantiation", + params: Array [ + TSAnyKeyword { + type: "TSAnyKeyword", + + range: [150, 153], + loc: { + start: { column: 54, line: 4 }, + end: { column: 57, line: 4 }, + }, + }, + ], + + range: [149, 154], + loc: { + start: { column: 53, line: 4 }, + end: { column: 58, line: 4 }, + }, + }, + + range: [140, 154], + loc: { + start: { column: 44, line: 4 }, + end: { column: 58, line: 4 }, + }, + }, + + range: [138, 154], + loc: { + start: { column: 42, line: 4 }, + end: { column: 58, line: 4 }, + }, + }, + + range: [105, 155], + loc: { + start: { column: 9, line: 4 }, + end: { column: 59, line: 4 }, + }, + }, + exportKind: "value", + source: null, + specifiers: Array [], + + range: [98, 155], + loc: { + start: { column: 2, line: 4 }, + end: { column: 59, line: 4 }, + }, + }, + ], + + range: [94, 157], + loc: { + start: { column: 21, line: 3 }, + end: { column: 1, line: 5 }, + }, + }, + declare: true, + id: Identifier { + type: "Identifier", + name: "d3", + + range: [91, 93], + loc: { + start: { column: 18, line: 3 }, + end: { column: 20, line: 3 }, + }, + }, + + range: [73, 157], + loc: { + start: { column: 0, line: 3 }, + end: { column: 1, line: 5 }, + }, + }, + ], + sourceType: "module", + + range: [73, 158], + loc: { + start: { column: 0, line: 3 }, + end: { column: 0, line: 6 }, + }, +} +`; diff --git a/packages/ast-spec/src/legacy-fixtures/namespaces-and-modules/fixtures/declare-namespace-with-exported-function/snapshots/2-Babel-Tokens.shot b/packages/ast-spec/src/legacy-fixtures/namespaces-and-modules/fixtures/declare-namespace-with-exported-function/snapshots/2-Babel-Tokens.shot new file mode 100644 index 00000000000..3461c38ebce --- /dev/null +++ b/packages/ast-spec/src/legacy-fixtures/namespaces-and-modules/fixtures/declare-namespace-with-exported-function/snapshots/2-Babel-Tokens.shot @@ -0,0 +1,196 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`AST Fixtures legacy-fixtures namespaces-and-modules declare-namespace-with-exported-function Babel - Tokens 1`] = ` +Array [ + Identifier { + type: "Identifier", + value: "declare", + + range: [73, 80], + loc: { + start: { column: 0, line: 3 }, + end: { column: 7, line: 3 }, + }, + }, + Identifier { + type: "Identifier", + value: "namespace", + + range: [81, 90], + loc: { + start: { column: 8, line: 3 }, + end: { column: 17, line: 3 }, + }, + }, + Identifier { + type: "Identifier", + value: "d3", + + range: [91, 93], + loc: { + start: { column: 18, line: 3 }, + end: { column: 20, line: 3 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "{", + + range: [94, 95], + loc: { + start: { column: 21, line: 3 }, + end: { column: 22, line: 3 }, + }, + }, + Keyword { + type: "Keyword", + value: "export", + + range: [98, 104], + loc: { + start: { column: 2, line: 4 }, + end: { column: 8, line: 4 }, + }, + }, + Keyword { + type: "Keyword", + value: "function", + + range: [105, 113], + loc: { + start: { column: 9, line: 4 }, + end: { column: 17, line: 4 }, + }, + }, + Identifier { + type: "Identifier", + value: "select", + + range: [114, 120], + loc: { + start: { column: 18, line: 4 }, + end: { column: 24, line: 4 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "(", + + range: [120, 121], + loc: { + start: { column: 24, line: 4 }, + end: { column: 25, line: 4 }, + }, + }, + Identifier { + type: "Identifier", + value: "selector", + + range: [121, 129], + loc: { + start: { column: 25, line: 4 }, + end: { column: 33, line: 4 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ":", + + range: [129, 130], + loc: { + start: { column: 33, line: 4 }, + end: { column: 34, line: 4 }, + }, + }, + Identifier { + type: "Identifier", + value: "string", + + range: [131, 137], + loc: { + start: { column: 35, line: 4 }, + end: { column: 41, line: 4 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ")", + + range: [137, 138], + loc: { + start: { column: 41, line: 4 }, + end: { column: 42, line: 4 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ":", + + range: [138, 139], + loc: { + start: { column: 42, line: 4 }, + end: { column: 43, line: 4 }, + }, + }, + Identifier { + type: "Identifier", + value: "Selection", + + range: [140, 149], + loc: { + start: { column: 44, line: 4 }, + end: { column: 53, line: 4 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "<", + + range: [149, 150], + loc: { + start: { column: 53, line: 4 }, + end: { column: 54, line: 4 }, + }, + }, + Identifier { + type: "Identifier", + value: "any", + + range: [150, 153], + loc: { + start: { column: 54, line: 4 }, + end: { column: 57, line: 4 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ">", + + range: [153, 154], + loc: { + start: { column: 57, line: 4 }, + end: { column: 58, line: 4 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ";", + + range: [154, 155], + loc: { + start: { column: 58, line: 4 }, + end: { column: 59, line: 4 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "}", + + range: [156, 157], + loc: { + start: { column: 0, line: 5 }, + end: { column: 1, line: 5 }, + }, + }, +] +`; diff --git a/packages/ast-spec/src/legacy-fixtures/namespaces-and-modules/fixtures/global-module-declaration/snapshots/1-Babel-AST.shot b/packages/ast-spec/src/legacy-fixtures/namespaces-and-modules/fixtures/global-module-declaration/snapshots/1-Babel-AST.shot new file mode 100644 index 00000000000..138b3944413 --- /dev/null +++ b/packages/ast-spec/src/legacy-fixtures/namespaces-and-modules/fixtures/global-module-declaration/snapshots/1-Babel-AST.shot @@ -0,0 +1,108 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`AST Fixtures legacy-fixtures namespaces-and-modules global-module-declaration Babel - AST 1`] = ` +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 }, + }, + }, + + 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 }, + }, + }, + + 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 }, + }, + }, + + 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/global-module-declaration/snapshots/2-Babel-Tokens.shot b/packages/ast-spec/src/legacy-fixtures/namespaces-and-modules/fixtures/global-module-declaration/snapshots/2-Babel-Tokens.shot new file mode 100644 index 00000000000..dcc869e00d2 --- /dev/null +++ b/packages/ast-spec/src/legacy-fixtures/namespaces-and-modules/fixtures/global-module-declaration/snapshots/2-Babel-Tokens.shot @@ -0,0 +1,146 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`AST Fixtures legacy-fixtures namespaces-and-modules global-module-declaration Babel - Tokens 1`] = ` +Array [ + Identifier { + type: "Identifier", + value: "declare", + + range: [73, 80], + loc: { + start: { column: 0, line: 3 }, + end: { column: 7, line: 3 }, + }, + }, + Identifier { + type: "Identifier", + value: "global", + + range: [81, 87], + loc: { + start: { column: 8, line: 3 }, + end: { column: 14, line: 3 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "{", + + range: [88, 89], + loc: { + start: { column: 15, line: 3 }, + end: { column: 16, line: 3 }, + }, + }, + Identifier { + type: "Identifier", + value: "declare", + + range: [92, 99], + loc: { + start: { column: 2, line: 4 }, + end: { column: 9, line: 4 }, + }, + }, + Identifier { + type: "Identifier", + value: "module", + + range: [100, 106], + loc: { + start: { column: 10, line: 4 }, + end: { column: 16, line: 4 }, + }, + }, + Identifier { + type: "Identifier", + value: "global", + + range: [107, 113], + loc: { + start: { column: 17, line: 4 }, + end: { column: 23, line: 4 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "{", + + range: [114, 115], + loc: { + start: { column: 24, line: 4 }, + end: { column: 25, line: 4 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "}", + + range: [115, 116], + loc: { + start: { column: 25, line: 4 }, + end: { column: 26, line: 4 }, + }, + }, + Identifier { + type: "Identifier", + value: "declare", + + range: [119, 126], + loc: { + start: { column: 2, line: 5 }, + end: { column: 9, line: 5 }, + }, + }, + Identifier { + type: "Identifier", + value: "namespace", + + range: [127, 136], + loc: { + start: { column: 10, line: 5 }, + end: { column: 19, line: 5 }, + }, + }, + Identifier { + type: "Identifier", + value: "global", + + range: [137, 143], + loc: { + start: { column: 20, line: 5 }, + end: { column: 26, line: 5 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "{", + + range: [144, 145], + loc: { + start: { column: 27, line: 5 }, + end: { column: 28, line: 5 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "}", + + range: [145, 146], + loc: { + start: { column: 28, line: 5 }, + end: { column: 29, line: 5 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "}", + + range: [147, 148], + loc: { + start: { column: 0, line: 6 }, + end: { column: 1, line: 6 }, + }, + }, +] +`; diff --git a/packages/ast-spec/tests/fixtures-with-differences-ast.shot b/packages/ast-spec/tests/fixtures-with-differences-ast.shot index 85be5819680..cef525143bf 100644 --- a/packages/ast-spec/tests/fixtures-with-differences-ast.shot +++ b/packages/ast-spec/tests/fixtures-with-differences-ast.shot @@ -34,6 +34,8 @@ Set { "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/TSModuleDeclaration/fixtures/namespace-nested-once/fixture.ts", + "declaration/TSModuleDeclaration/fixtures/namespace-nested-twice/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/eslint-plugin/src/rules/no-namespace.ts b/packages/eslint-plugin/src/rules/no-namespace.ts index 28706e2e0b6..145ddc3ad16 100644 --- a/packages/eslint-plugin/src/rules/no-namespace.ts +++ b/packages/eslint-plugin/src/rules/no-namespace.ts @@ -63,7 +63,7 @@ export default util.createRule({ } return { - "TSModuleDeclaration[global!=true][id.type='Identifier']"( + "TSModuleDeclaration[global!=true][id.type!='Literal']"( node: TSESTree.TSModuleDeclaration, ): void { if ( diff --git a/packages/typescript-estree/src/convert.ts b/packages/typescript-estree/src/convert.ts index 7d14d25cc9a..ec1b335e6e7 100644 --- a/packages/typescript-estree/src/convert.ts +++ b/packages/typescript-estree/src/convert.ts @@ -240,12 +240,8 @@ export class Converter { data: Omit, 'parent'>, ): T { const result = data; - if (!result.range) { - result.range = getRange(node, this.ast); - } - if (!result.loc) { - result.loc = getLocFor(result.range[0], result.range[1], this.ast); - } + result.range ??= getRange(node, this.ast); + result.loc ??= getLocFor(result.range[0], result.range[1], this.ast); if (result && this.options.shouldPreserveNodeMaps) { this.esTreeNodeToTSNodeMap.set(result, node); @@ -2778,19 +2774,20 @@ export class Converter { case SyntaxKind.ModuleDeclaration: { const result = this.createNode(node, { type: AST_NODE_TYPES.TSModuleDeclaration, - // 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); - + ...((): TSESTree.OptionalRangeAndLoc< + Omit + > => { // 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) { + const id: TSESTree.Identifier | TSESTree.StringLiteral = + this.convertChild(node.name); + const body: + | TSESTree.TSModuleBlock + | TSESTree.TSModuleDeclaration + | null = this.convertChild(node.body); + if ( body == null || body.type === AST_NODE_TYPES.TSModuleDeclaration @@ -2804,46 +2801,79 @@ export class Converter { } 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 { + }; + } + + if (!(node.flags & ts.NodeFlags.Namespace)) { + const body: TSESTree.TSModuleBlock | null = this.convertChild( + node.body, + ); return { kind: 'module', - id, ...(body != null ? { body } : {}), - } satisfies TSESTree.OptionalRangeAndLoc< - Omit - >; + id: this.convertChild(node.name), + }; + } + + // Nested module declarations are stored in TypeScript as nested tree nodes. + // We "unravel" them here by making our own nested TSQualifiedName, + // with the innermost node's body as the actual node body. + + if (node.body == null) { + throw new Error('Expected a module body'); + } + if (node.name.kind !== ts.SyntaxKind.Identifier) { + throw new Error('`namespace`s must have an Identifier id'); } + + let name: TSESTree.Identifier | TSESTree.TSQualifiedName = + this.createNode(node.name, { + name: node.name.text, + range: [node.name.getStart(this.ast), node.name.getEnd()], + type: AST_NODE_TYPES.Identifier, + }); + + while ( + node.body && + ts.isModuleDeclaration(node.body) && + node.body.name + ) { + node = node.body; + + const nextName = node.name as ts.Identifier; + + const right = this.createNode(nextName, { + name: nextName.text, + range: [nextName.getStart(this.ast), nextName.getEnd()], + type: AST_NODE_TYPES.Identifier, + }); + + name = this.createNode(nextName, { + left: name, + right: right, + range: [name.range[0], right.range[1]], + type: AST_NODE_TYPES.TSQualifiedName, + }); + } + + return { + kind: 'namespace', + body: this.convertChild(node.body), + id: name, + }; })(), }); if (hasModifier(SyntaxKind.DeclareKeyword, node)) { result.declare = true; } + if (node.flags & ts.NodeFlags.GlobalAugmentation) { result.global = true; } - // ...then check for exports return this.fixExports(node, result); } diff --git a/packages/typescript-estree/src/ts-estree/estree-to-ts-node-types.ts b/packages/typescript-estree/src/ts-estree/estree-to-ts-node-types.ts index 7d758d66d87..c5c7eebef18 100644 --- a/packages/typescript-estree/src/ts-estree/estree-to-ts-node-types.ts +++ b/packages/typescript-estree/src/ts-estree/estree-to-ts-node-types.ts @@ -203,7 +203,7 @@ export interface EstreeToTsNodeTypes { [AST_NODE_TYPES.TSOptionalType]: ts.OptionalTypeNode; [AST_NODE_TYPES.TSParameterProperty]: ts.ParameterDeclaration; [AST_NODE_TYPES.TSPropertySignature]: ts.PropertySignature; - [AST_NODE_TYPES.TSQualifiedName]: ts.QualifiedName; + [AST_NODE_TYPES.TSQualifiedName]: ts.Identifier | ts.QualifiedName; [AST_NODE_TYPES.TSRestType]: | ts.RestTypeNode // for consistency and following babel's choices, a named tuple member with a rest gets converted to a TSRestType diff --git a/packages/typescript-estree/tests/lib/__snapshots__/semantic-diagnostics-enabled.test.ts.snap b/packages/typescript-estree/tests/lib/__snapshots__/semantic-diagnostics-enabled.test.ts.snap index ea7a8d73903..3b22a3797d3 100644 --- a/packages/typescript-estree/tests/lib/__snapshots__/semantic-diagnostics-enabled.test.ts.snap +++ b/packages/typescript-estree/tests/lib/__snapshots__/semantic-diagnostics-enabled.test.ts.snap @@ -296,6 +296,10 @@ exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" e exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/declaration/TSModuleDeclaration/fixtures/namespace-id-qualified-name/fixture 1`] = `[Error: Cannot calculate TypeScript semantic issues without a valid project.]`; +exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/declaration/TSModuleDeclaration/fixtures/namespace-nested-once/fixture 1`] = `[Error: Cannot calculate TypeScript semantic issues without a valid project.]`; + +exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/declaration/TSModuleDeclaration/fixtures/namespace-nested-twice/fixture 1`] = `[Error: Cannot calculate TypeScript semantic issues without a valid project.]`; + exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/declaration/TSNamespaceExportDeclaration/fixtures/_error_/missing-id/fixture 1`] = `[Error: Cannot calculate TypeScript semantic issues without a valid project.]`; exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/declaration/TSNamespaceExportDeclaration/fixtures/_error_/non-identifier-name/fixture 1`] = `[Error: Cannot calculate TypeScript semantic issues without a valid project.]`;