diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 0e0b9a53b5d9c..6b42589471f1e 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -8229,7 +8229,7 @@ namespace Parser { // If we are parsing a dotted namespace name, we want to // propagate the 'Namespace' flag across the names if set. const namespaceFlag = flags & NodeFlags.Namespace; - const name = parseIdentifier(); + const name = flags & NodeFlags.NestedNamespace ? parseIdentifierName() : parseIdentifier(); const body = parseOptional(SyntaxKind.DotToken) ? parseModuleOrNamespaceDeclaration(getNodePos(), /*hasJSDoc*/ false, /*modifiers*/ undefined, NodeFlags.NestedNamespace | namespaceFlag) as NamespaceDeclaration : parseModuleBlock(); diff --git a/tests/baselines/reference/ambientModuleDeclarationWithReservedIdentifierInDottedPath.errors.txt b/tests/baselines/reference/ambientModuleDeclarationWithReservedIdentifierInDottedPath.errors.txt new file mode 100644 index 0000000000000..32d0fa85f966d --- /dev/null +++ b/tests/baselines/reference/ambientModuleDeclarationWithReservedIdentifierInDottedPath.errors.txt @@ -0,0 +1,27 @@ +ambientModuleDeclarationWithReservedIdentifierInDottedPath.ts(11,1): error TS2304: Cannot find name 'declare'. +ambientModuleDeclarationWithReservedIdentifierInDottedPath.ts(11,9): error TS2580: Cannot find name 'module'. Do you need to install type definitions for node? Try `npm i --save-dev @types/node`. +ambientModuleDeclarationWithReservedIdentifierInDottedPath.ts(11,16): error TS2819: Namespace name cannot be 'debugger'. +ambientModuleDeclarationWithReservedIdentifierInDottedPath.ts(11,25): error TS1005: ';' expected. + + +==== ambientModuleDeclarationWithReservedIdentifierInDottedPath.ts (4 errors) ==== + // https://github.com/microsoft/TypeScript/issues/7840 + + declare module chrome.debugger { + declare var tabId: number; + } + + export const tabId = chrome.debugger.tabId; + + declare module test.class {} + + declare module debugger {} // still an error + ~~~~~~~ +!!! error TS2304: Cannot find name 'declare'. + ~~~~~~ +!!! error TS2580: Cannot find name 'module'. Do you need to install type definitions for node? Try `npm i --save-dev @types/node`. + ~~~~~~~~ +!!! error TS2819: Namespace name cannot be 'debugger'. + ~ +!!! error TS1005: ';' expected. + \ No newline at end of file diff --git a/tests/baselines/reference/ambientModuleDeclarationWithReservedIdentifierInDottedPath.js b/tests/baselines/reference/ambientModuleDeclarationWithReservedIdentifierInDottedPath.js new file mode 100644 index 0000000000000..8066fd7de6b57 --- /dev/null +++ b/tests/baselines/reference/ambientModuleDeclarationWithReservedIdentifierInDottedPath.js @@ -0,0 +1,30 @@ +//// [tests/cases/conformance/ambient/ambientModuleDeclarationWithReservedIdentifierInDottedPath.ts] //// + +//// [ambientModuleDeclarationWithReservedIdentifierInDottedPath.ts] +// https://github.com/microsoft/TypeScript/issues/7840 + +declare module chrome.debugger { + declare var tabId: number; +} + +export const tabId = chrome.debugger.tabId; + +declare module test.class {} + +declare module debugger {} // still an error + + +//// [ambientModuleDeclarationWithReservedIdentifierInDottedPath.js] +"use strict"; +// https://github.com/microsoft/TypeScript/issues/7840 +Object.defineProperty(exports, "__esModule", { value: true }); +exports.tabId = void 0; +exports.tabId = chrome.debugger.tabId; +declare; +module; +debugger; +{ } // still an error + + +//// [ambientModuleDeclarationWithReservedIdentifierInDottedPath.d.ts] +export declare const tabId: number; diff --git a/tests/baselines/reference/ambientModuleDeclarationWithReservedIdentifierInDottedPath.symbols b/tests/baselines/reference/ambientModuleDeclarationWithReservedIdentifierInDottedPath.symbols new file mode 100644 index 0000000000000..353e1d3c7e1e7 --- /dev/null +++ b/tests/baselines/reference/ambientModuleDeclarationWithReservedIdentifierInDottedPath.symbols @@ -0,0 +1,27 @@ +//// [tests/cases/conformance/ambient/ambientModuleDeclarationWithReservedIdentifierInDottedPath.ts] //// + +=== ambientModuleDeclarationWithReservedIdentifierInDottedPath.ts === +// https://github.com/microsoft/TypeScript/issues/7840 + +declare module chrome.debugger { +>chrome : Symbol(chrome, Decl(ambientModuleDeclarationWithReservedIdentifierInDottedPath.ts, 0, 0)) +>debugger : Symbol(debugger, Decl(ambientModuleDeclarationWithReservedIdentifierInDottedPath.ts, 2, 22)) + + declare var tabId: number; +>tabId : Symbol(tabId, Decl(ambientModuleDeclarationWithReservedIdentifierInDottedPath.ts, 3, 15)) +} + +export const tabId = chrome.debugger.tabId; +>tabId : Symbol(tabId, Decl(ambientModuleDeclarationWithReservedIdentifierInDottedPath.ts, 6, 12)) +>chrome.debugger.tabId : Symbol(chrome.debugger.tabId, Decl(ambientModuleDeclarationWithReservedIdentifierInDottedPath.ts, 3, 15)) +>chrome.debugger : Symbol(chrome.debugger, Decl(ambientModuleDeclarationWithReservedIdentifierInDottedPath.ts, 2, 22)) +>chrome : Symbol(chrome, Decl(ambientModuleDeclarationWithReservedIdentifierInDottedPath.ts, 0, 0)) +>debugger : Symbol(chrome.debugger, Decl(ambientModuleDeclarationWithReservedIdentifierInDottedPath.ts, 2, 22)) +>tabId : Symbol(chrome.debugger.tabId, Decl(ambientModuleDeclarationWithReservedIdentifierInDottedPath.ts, 3, 15)) + +declare module test.class {} +>test : Symbol(test, Decl(ambientModuleDeclarationWithReservedIdentifierInDottedPath.ts, 6, 43)) +>class : Symbol(class, Decl(ambientModuleDeclarationWithReservedIdentifierInDottedPath.ts, 8, 20)) + +declare module debugger {} // still an error + diff --git a/tests/baselines/reference/ambientModuleDeclarationWithReservedIdentifierInDottedPath.types b/tests/baselines/reference/ambientModuleDeclarationWithReservedIdentifierInDottedPath.types new file mode 100644 index 0000000000000..d3d2470edc09d --- /dev/null +++ b/tests/baselines/reference/ambientModuleDeclarationWithReservedIdentifierInDottedPath.types @@ -0,0 +1,27 @@ +//// [tests/cases/conformance/ambient/ambientModuleDeclarationWithReservedIdentifierInDottedPath.ts] //// + +=== ambientModuleDeclarationWithReservedIdentifierInDottedPath.ts === +// https://github.com/microsoft/TypeScript/issues/7840 + +declare module chrome.debugger { +>chrome : typeof chrome +>debugger : typeof debugger + + declare var tabId: number; +>tabId : number +} + +export const tabId = chrome.debugger.tabId; +>tabId : number +>chrome.debugger.tabId : number +>chrome.debugger : typeof chrome.debugger +>chrome : typeof chrome +>debugger : typeof chrome.debugger +>tabId : number + +declare module test.class {} + +declare module debugger {} // still an error +>declare : any +>module : any + diff --git a/tests/baselines/reference/ambientModuleDeclarationWithReservedIdentifierInDottedPath2.errors.txt b/tests/baselines/reference/ambientModuleDeclarationWithReservedIdentifierInDottedPath2.errors.txt new file mode 100644 index 0000000000000..3cce670b6fc12 --- /dev/null +++ b/tests/baselines/reference/ambientModuleDeclarationWithReservedIdentifierInDottedPath2.errors.txt @@ -0,0 +1,25 @@ +ambientModuleDeclarationWithReservedIdentifierInDottedPath2.ts(9,1): error TS2304: Cannot find name 'declare'. +ambientModuleDeclarationWithReservedIdentifierInDottedPath2.ts(9,9): error TS2304: Cannot find name 'namespace'. +ambientModuleDeclarationWithReservedIdentifierInDottedPath2.ts(9,19): error TS2819: Namespace name cannot be 'debugger'. +ambientModuleDeclarationWithReservedIdentifierInDottedPath2.ts(9,28): error TS1005: ';' expected. + + +==== ambientModuleDeclarationWithReservedIdentifierInDottedPath2.ts (4 errors) ==== + declare namespace chrome.debugger { + declare var tabId: number; + } + + export const tabId = chrome.debugger.tabId; + + declare namespace test.class {} + + declare namespace debugger {} // still an error + ~~~~~~~ +!!! error TS2304: Cannot find name 'declare'. + ~~~~~~~~~ +!!! error TS2304: Cannot find name 'namespace'. + ~~~~~~~~ +!!! error TS2819: Namespace name cannot be 'debugger'. + ~ +!!! error TS1005: ';' expected. + \ No newline at end of file diff --git a/tests/baselines/reference/ambientModuleDeclarationWithReservedIdentifierInDottedPath2.js b/tests/baselines/reference/ambientModuleDeclarationWithReservedIdentifierInDottedPath2.js new file mode 100644 index 0000000000000..1751a8d5c967e --- /dev/null +++ b/tests/baselines/reference/ambientModuleDeclarationWithReservedIdentifierInDottedPath2.js @@ -0,0 +1,27 @@ +//// [tests/cases/conformance/ambient/ambientModuleDeclarationWithReservedIdentifierInDottedPath2.ts] //// + +//// [ambientModuleDeclarationWithReservedIdentifierInDottedPath2.ts] +declare namespace chrome.debugger { + declare var tabId: number; +} + +export const tabId = chrome.debugger.tabId; + +declare namespace test.class {} + +declare namespace debugger {} // still an error + + +//// [ambientModuleDeclarationWithReservedIdentifierInDottedPath2.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.tabId = void 0; +exports.tabId = chrome.debugger.tabId; +declare; +namespace; +debugger; +{ } // still an error + + +//// [ambientModuleDeclarationWithReservedIdentifierInDottedPath2.d.ts] +export declare const tabId: number; diff --git a/tests/baselines/reference/ambientModuleDeclarationWithReservedIdentifierInDottedPath2.symbols b/tests/baselines/reference/ambientModuleDeclarationWithReservedIdentifierInDottedPath2.symbols new file mode 100644 index 0000000000000..2b61ab650343f --- /dev/null +++ b/tests/baselines/reference/ambientModuleDeclarationWithReservedIdentifierInDottedPath2.symbols @@ -0,0 +1,25 @@ +//// [tests/cases/conformance/ambient/ambientModuleDeclarationWithReservedIdentifierInDottedPath2.ts] //// + +=== ambientModuleDeclarationWithReservedIdentifierInDottedPath2.ts === +declare namespace chrome.debugger { +>chrome : Symbol(chrome, Decl(ambientModuleDeclarationWithReservedIdentifierInDottedPath2.ts, 0, 0)) +>debugger : Symbol(debugger, Decl(ambientModuleDeclarationWithReservedIdentifierInDottedPath2.ts, 0, 25)) + + declare var tabId: number; +>tabId : Symbol(tabId, Decl(ambientModuleDeclarationWithReservedIdentifierInDottedPath2.ts, 1, 15)) +} + +export const tabId = chrome.debugger.tabId; +>tabId : Symbol(tabId, Decl(ambientModuleDeclarationWithReservedIdentifierInDottedPath2.ts, 4, 12)) +>chrome.debugger.tabId : Symbol(chrome.debugger.tabId, Decl(ambientModuleDeclarationWithReservedIdentifierInDottedPath2.ts, 1, 15)) +>chrome.debugger : Symbol(chrome.debugger, Decl(ambientModuleDeclarationWithReservedIdentifierInDottedPath2.ts, 0, 25)) +>chrome : Symbol(chrome, Decl(ambientModuleDeclarationWithReservedIdentifierInDottedPath2.ts, 0, 0)) +>debugger : Symbol(chrome.debugger, Decl(ambientModuleDeclarationWithReservedIdentifierInDottedPath2.ts, 0, 25)) +>tabId : Symbol(chrome.debugger.tabId, Decl(ambientModuleDeclarationWithReservedIdentifierInDottedPath2.ts, 1, 15)) + +declare namespace test.class {} +>test : Symbol(test, Decl(ambientModuleDeclarationWithReservedIdentifierInDottedPath2.ts, 4, 43)) +>class : Symbol(class, Decl(ambientModuleDeclarationWithReservedIdentifierInDottedPath2.ts, 6, 23)) + +declare namespace debugger {} // still an error + diff --git a/tests/baselines/reference/ambientModuleDeclarationWithReservedIdentifierInDottedPath2.types b/tests/baselines/reference/ambientModuleDeclarationWithReservedIdentifierInDottedPath2.types new file mode 100644 index 0000000000000..57367d2f26bcd --- /dev/null +++ b/tests/baselines/reference/ambientModuleDeclarationWithReservedIdentifierInDottedPath2.types @@ -0,0 +1,25 @@ +//// [tests/cases/conformance/ambient/ambientModuleDeclarationWithReservedIdentifierInDottedPath2.ts] //// + +=== ambientModuleDeclarationWithReservedIdentifierInDottedPath2.ts === +declare namespace chrome.debugger { +>chrome : typeof chrome +>debugger : typeof debugger + + declare var tabId: number; +>tabId : number +} + +export const tabId = chrome.debugger.tabId; +>tabId : number +>chrome.debugger.tabId : number +>chrome.debugger : typeof chrome.debugger +>chrome : typeof chrome +>debugger : typeof chrome.debugger +>tabId : number + +declare namespace test.class {} + +declare namespace debugger {} // still an error +>declare : any +>namespace : any + diff --git a/tests/cases/conformance/ambient/ambientModuleDeclarationWithReservedIdentifierInDottedPath.ts b/tests/cases/conformance/ambient/ambientModuleDeclarationWithReservedIdentifierInDottedPath.ts new file mode 100644 index 0000000000000..5871010878546 --- /dev/null +++ b/tests/cases/conformance/ambient/ambientModuleDeclarationWithReservedIdentifierInDottedPath.ts @@ -0,0 +1,13 @@ +// @declaration: true + +// https://github.com/microsoft/TypeScript/issues/7840 + +declare module chrome.debugger { + declare var tabId: number; +} + +export const tabId = chrome.debugger.tabId; + +declare module test.class {} + +declare module debugger {} // still an error diff --git a/tests/cases/conformance/ambient/ambientModuleDeclarationWithReservedIdentifierInDottedPath2.ts b/tests/cases/conformance/ambient/ambientModuleDeclarationWithReservedIdentifierInDottedPath2.ts new file mode 100644 index 0000000000000..7b41511cb2cb9 --- /dev/null +++ b/tests/cases/conformance/ambient/ambientModuleDeclarationWithReservedIdentifierInDottedPath2.ts @@ -0,0 +1,11 @@ +// @declaration: true + +declare namespace chrome.debugger { + declare var tabId: number; +} + +export const tabId = chrome.debugger.tabId; + +declare namespace test.class {} + +declare namespace debugger {} // still an error