Skip to content

Commit 661251c

Browse files
Andaristsnovader
authored andcommitted
Parse reserved identifiers as dotted names of ambient modules (microsoft#55282)
1 parent fb681bf commit 661251c

11 files changed

+238
-1
lines changed

src/compiler/parser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8226,7 +8226,7 @@ namespace Parser {
82268226
// If we are parsing a dotted namespace name, we want to
82278227
// propagate the 'Namespace' flag across the names if set.
82288228
const namespaceFlag = flags & NodeFlags.Namespace;
8229-
const name = parseIdentifier();
8229+
const name = flags & NodeFlags.NestedNamespace ? parseIdentifierName() : parseIdentifier();
82308230
const body = parseOptional(SyntaxKind.DotToken)
82318231
? parseModuleOrNamespaceDeclaration(getNodePos(), /*hasJSDoc*/ false, /*modifiers*/ undefined, NodeFlags.NestedNamespace | namespaceFlag) as NamespaceDeclaration
82328232
: parseModuleBlock();
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
ambientModuleDeclarationWithReservedIdentifierInDottedPath.ts(11,1): error TS2304: Cannot find name 'declare'.
2+
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`.
3+
ambientModuleDeclarationWithReservedIdentifierInDottedPath.ts(11,16): error TS2819: Namespace name cannot be 'debugger'.
4+
ambientModuleDeclarationWithReservedIdentifierInDottedPath.ts(11,25): error TS1005: ';' expected.
5+
6+
7+
==== ambientModuleDeclarationWithReservedIdentifierInDottedPath.ts (4 errors) ====
8+
// https://github.com/microsoft/TypeScript/issues/7840
9+
10+
declare module chrome.debugger {
11+
declare var tabId: number;
12+
}
13+
14+
export const tabId = chrome.debugger.tabId;
15+
16+
declare module test.class {}
17+
18+
declare module debugger {} // still an error
19+
~~~~~~~
20+
!!! error TS2304: Cannot find name 'declare'.
21+
~~~~~~
22+
!!! error TS2580: Cannot find name 'module'. Do you need to install type definitions for node? Try `npm i --save-dev @types/node`.
23+
~~~~~~~~
24+
!!! error TS2819: Namespace name cannot be 'debugger'.
25+
~
26+
!!! error TS1005: ';' expected.
27+
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//// [tests/cases/conformance/ambient/ambientModuleDeclarationWithReservedIdentifierInDottedPath.ts] ////
2+
3+
//// [ambientModuleDeclarationWithReservedIdentifierInDottedPath.ts]
4+
// https://github.com/microsoft/TypeScript/issues/7840
5+
6+
declare module chrome.debugger {
7+
declare var tabId: number;
8+
}
9+
10+
export const tabId = chrome.debugger.tabId;
11+
12+
declare module test.class {}
13+
14+
declare module debugger {} // still an error
15+
16+
17+
//// [ambientModuleDeclarationWithReservedIdentifierInDottedPath.js]
18+
"use strict";
19+
// https://github.com/microsoft/TypeScript/issues/7840
20+
Object.defineProperty(exports, "__esModule", { value: true });
21+
exports.tabId = void 0;
22+
exports.tabId = chrome.debugger.tabId;
23+
declare;
24+
module;
25+
debugger;
26+
{ } // still an error
27+
28+
29+
//// [ambientModuleDeclarationWithReservedIdentifierInDottedPath.d.ts]
30+
export declare const tabId: number;
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//// [tests/cases/conformance/ambient/ambientModuleDeclarationWithReservedIdentifierInDottedPath.ts] ////
2+
3+
=== ambientModuleDeclarationWithReservedIdentifierInDottedPath.ts ===
4+
// https://github.com/microsoft/TypeScript/issues/7840
5+
6+
declare module chrome.debugger {
7+
>chrome : Symbol(chrome, Decl(ambientModuleDeclarationWithReservedIdentifierInDottedPath.ts, 0, 0))
8+
>debugger : Symbol(debugger, Decl(ambientModuleDeclarationWithReservedIdentifierInDottedPath.ts, 2, 22))
9+
10+
declare var tabId: number;
11+
>tabId : Symbol(tabId, Decl(ambientModuleDeclarationWithReservedIdentifierInDottedPath.ts, 3, 15))
12+
}
13+
14+
export const tabId = chrome.debugger.tabId;
15+
>tabId : Symbol(tabId, Decl(ambientModuleDeclarationWithReservedIdentifierInDottedPath.ts, 6, 12))
16+
>chrome.debugger.tabId : Symbol(chrome.debugger.tabId, Decl(ambientModuleDeclarationWithReservedIdentifierInDottedPath.ts, 3, 15))
17+
>chrome.debugger : Symbol(chrome.debugger, Decl(ambientModuleDeclarationWithReservedIdentifierInDottedPath.ts, 2, 22))
18+
>chrome : Symbol(chrome, Decl(ambientModuleDeclarationWithReservedIdentifierInDottedPath.ts, 0, 0))
19+
>debugger : Symbol(chrome.debugger, Decl(ambientModuleDeclarationWithReservedIdentifierInDottedPath.ts, 2, 22))
20+
>tabId : Symbol(chrome.debugger.tabId, Decl(ambientModuleDeclarationWithReservedIdentifierInDottedPath.ts, 3, 15))
21+
22+
declare module test.class {}
23+
>test : Symbol(test, Decl(ambientModuleDeclarationWithReservedIdentifierInDottedPath.ts, 6, 43))
24+
>class : Symbol(class, Decl(ambientModuleDeclarationWithReservedIdentifierInDottedPath.ts, 8, 20))
25+
26+
declare module debugger {} // still an error
27+
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//// [tests/cases/conformance/ambient/ambientModuleDeclarationWithReservedIdentifierInDottedPath.ts] ////
2+
3+
=== ambientModuleDeclarationWithReservedIdentifierInDottedPath.ts ===
4+
// https://github.com/microsoft/TypeScript/issues/7840
5+
6+
declare module chrome.debugger {
7+
>chrome : typeof chrome
8+
>debugger : typeof debugger
9+
10+
declare var tabId: number;
11+
>tabId : number
12+
}
13+
14+
export const tabId = chrome.debugger.tabId;
15+
>tabId : number
16+
>chrome.debugger.tabId : number
17+
>chrome.debugger : typeof chrome.debugger
18+
>chrome : typeof chrome
19+
>debugger : typeof chrome.debugger
20+
>tabId : number
21+
22+
declare module test.class {}
23+
24+
declare module debugger {} // still an error
25+
>declare : any
26+
>module : any
27+
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
ambientModuleDeclarationWithReservedIdentifierInDottedPath2.ts(9,1): error TS2304: Cannot find name 'declare'.
2+
ambientModuleDeclarationWithReservedIdentifierInDottedPath2.ts(9,9): error TS2304: Cannot find name 'namespace'.
3+
ambientModuleDeclarationWithReservedIdentifierInDottedPath2.ts(9,19): error TS2819: Namespace name cannot be 'debugger'.
4+
ambientModuleDeclarationWithReservedIdentifierInDottedPath2.ts(9,28): error TS1005: ';' expected.
5+
6+
7+
==== ambientModuleDeclarationWithReservedIdentifierInDottedPath2.ts (4 errors) ====
8+
declare namespace chrome.debugger {
9+
declare var tabId: number;
10+
}
11+
12+
export const tabId = chrome.debugger.tabId;
13+
14+
declare namespace test.class {}
15+
16+
declare namespace debugger {} // still an error
17+
~~~~~~~
18+
!!! error TS2304: Cannot find name 'declare'.
19+
~~~~~~~~~
20+
!!! error TS2304: Cannot find name 'namespace'.
21+
~~~~~~~~
22+
!!! error TS2819: Namespace name cannot be 'debugger'.
23+
~
24+
!!! error TS1005: ';' expected.
25+
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//// [tests/cases/conformance/ambient/ambientModuleDeclarationWithReservedIdentifierInDottedPath2.ts] ////
2+
3+
//// [ambientModuleDeclarationWithReservedIdentifierInDottedPath2.ts]
4+
declare namespace chrome.debugger {
5+
declare var tabId: number;
6+
}
7+
8+
export const tabId = chrome.debugger.tabId;
9+
10+
declare namespace test.class {}
11+
12+
declare namespace debugger {} // still an error
13+
14+
15+
//// [ambientModuleDeclarationWithReservedIdentifierInDottedPath2.js]
16+
"use strict";
17+
Object.defineProperty(exports, "__esModule", { value: true });
18+
exports.tabId = void 0;
19+
exports.tabId = chrome.debugger.tabId;
20+
declare;
21+
namespace;
22+
debugger;
23+
{ } // still an error
24+
25+
26+
//// [ambientModuleDeclarationWithReservedIdentifierInDottedPath2.d.ts]
27+
export declare const tabId: number;
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//// [tests/cases/conformance/ambient/ambientModuleDeclarationWithReservedIdentifierInDottedPath2.ts] ////
2+
3+
=== ambientModuleDeclarationWithReservedIdentifierInDottedPath2.ts ===
4+
declare namespace chrome.debugger {
5+
>chrome : Symbol(chrome, Decl(ambientModuleDeclarationWithReservedIdentifierInDottedPath2.ts, 0, 0))
6+
>debugger : Symbol(debugger, Decl(ambientModuleDeclarationWithReservedIdentifierInDottedPath2.ts, 0, 25))
7+
8+
declare var tabId: number;
9+
>tabId : Symbol(tabId, Decl(ambientModuleDeclarationWithReservedIdentifierInDottedPath2.ts, 1, 15))
10+
}
11+
12+
export const tabId = chrome.debugger.tabId;
13+
>tabId : Symbol(tabId, Decl(ambientModuleDeclarationWithReservedIdentifierInDottedPath2.ts, 4, 12))
14+
>chrome.debugger.tabId : Symbol(chrome.debugger.tabId, Decl(ambientModuleDeclarationWithReservedIdentifierInDottedPath2.ts, 1, 15))
15+
>chrome.debugger : Symbol(chrome.debugger, Decl(ambientModuleDeclarationWithReservedIdentifierInDottedPath2.ts, 0, 25))
16+
>chrome : Symbol(chrome, Decl(ambientModuleDeclarationWithReservedIdentifierInDottedPath2.ts, 0, 0))
17+
>debugger : Symbol(chrome.debugger, Decl(ambientModuleDeclarationWithReservedIdentifierInDottedPath2.ts, 0, 25))
18+
>tabId : Symbol(chrome.debugger.tabId, Decl(ambientModuleDeclarationWithReservedIdentifierInDottedPath2.ts, 1, 15))
19+
20+
declare namespace test.class {}
21+
>test : Symbol(test, Decl(ambientModuleDeclarationWithReservedIdentifierInDottedPath2.ts, 4, 43))
22+
>class : Symbol(class, Decl(ambientModuleDeclarationWithReservedIdentifierInDottedPath2.ts, 6, 23))
23+
24+
declare namespace debugger {} // still an error
25+
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//// [tests/cases/conformance/ambient/ambientModuleDeclarationWithReservedIdentifierInDottedPath2.ts] ////
2+
3+
=== ambientModuleDeclarationWithReservedIdentifierInDottedPath2.ts ===
4+
declare namespace chrome.debugger {
5+
>chrome : typeof chrome
6+
>debugger : typeof debugger
7+
8+
declare var tabId: number;
9+
>tabId : number
10+
}
11+
12+
export const tabId = chrome.debugger.tabId;
13+
>tabId : number
14+
>chrome.debugger.tabId : number
15+
>chrome.debugger : typeof chrome.debugger
16+
>chrome : typeof chrome
17+
>debugger : typeof chrome.debugger
18+
>tabId : number
19+
20+
declare namespace test.class {}
21+
22+
declare namespace debugger {} // still an error
23+
>declare : any
24+
>namespace : any
25+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// @declaration: true
2+
3+
// https://github.com/microsoft/TypeScript/issues/7840
4+
5+
declare module chrome.debugger {
6+
declare var tabId: number;
7+
}
8+
9+
export const tabId = chrome.debugger.tabId;
10+
11+
declare module test.class {}
12+
13+
declare module debugger {} // still an error
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// @declaration: true
2+
3+
declare namespace chrome.debugger {
4+
declare var tabId: number;
5+
}
6+
7+
export const tabId = chrome.debugger.tabId;
8+
9+
declare namespace test.class {}
10+
11+
declare namespace debugger {} // still an error

0 commit comments

Comments
 (0)