mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-04 21:53:42 -06:00
Parse reserved identifiers as dotted names of ambient modules (#55282)
This commit is contained in:
parent
b5b6048bb3
commit
fe70ec984e
@ -8226,7 +8226,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();
|
||||
|
||||
@ -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.
|
||||
|
||||
@ -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;
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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.
|
||||
|
||||
@ -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;
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
@ -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
|
||||
Loading…
x
Reference in New Issue
Block a user