mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-04 21:53:42 -06:00
make globalThis have an empty declarations (#34561)
Fixes #33860 by making it an error. This is an improvement, but sounds like it would be better to make it work later.
This commit is contained in:
parent
d8840f8a18
commit
eb0208c589
@ -319,6 +319,7 @@ namespace ts {
|
||||
|
||||
const globalThisSymbol = createSymbol(SymbolFlags.Module, "globalThis" as __String, CheckFlags.Readonly);
|
||||
globalThisSymbol.exports = globals;
|
||||
globalThisSymbol.declarations = [];
|
||||
globals.set(globalThisSymbol.escapedName, globalThisSymbol);
|
||||
|
||||
const argumentsSymbol = createSymbol(SymbolFlags.Property, "arguments" as __String);
|
||||
|
||||
@ -3,7 +3,7 @@ declare global {
|
||||
>global : Symbol(global, Decl(extension.d.ts, 0, 0))
|
||||
|
||||
namespace globalThis {
|
||||
>globalThis : Symbol(globalThis)
|
||||
>globalThis : Symbol(globalThis, Decl(extension.d.ts, 0, 16))
|
||||
|
||||
var test: string;
|
||||
>test : Symbol(test, Decl(extension.d.ts, 2, 11))
|
||||
@ -16,7 +16,7 @@ export {}
|
||||
import "./extention";
|
||||
|
||||
globalThis.tests = "a-b";
|
||||
>globalThis : Symbol(globalThis)
|
||||
>globalThis : Symbol(globalThis, Decl(extension.d.ts, 0, 16))
|
||||
|
||||
console.log(globalThis.test.split("-"));
|
||||
>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
|
||||
@ -24,7 +24,7 @@ console.log(globalThis.test.split("-"));
|
||||
>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
|
||||
>globalThis.test.split : Symbol(String.split, Decl(lib.es5.d.ts, --, --))
|
||||
>globalThis.test : Symbol(test, Decl(extension.d.ts, 2, 11))
|
||||
>globalThis : Symbol(globalThis)
|
||||
>globalThis : Symbol(globalThis, Decl(extension.d.ts, 0, 16))
|
||||
>test : Symbol(test, Decl(extension.d.ts, 2, 11))
|
||||
>split : Symbol(String.split, Decl(lib.es5.d.ts, --, --))
|
||||
|
||||
|
||||
10
tests/baselines/reference/extendGlobalThis2.errors.txt
Normal file
10
tests/baselines/reference/extendGlobalThis2.errors.txt
Normal file
@ -0,0 +1,10 @@
|
||||
tests/cases/compiler/extendGlobalThis2.ts(1,11): error TS2397: Declaration name conflicts with built-in global identifier 'globalThis'.
|
||||
|
||||
|
||||
==== tests/cases/compiler/extendGlobalThis2.ts (1 errors) ====
|
||||
namespace globalThis {
|
||||
~~~~~~~~~~
|
||||
!!! error TS2397: Declaration name conflicts with built-in global identifier 'globalThis'.
|
||||
export function foo() { console.log("x"); }
|
||||
}
|
||||
|
||||
12
tests/baselines/reference/extendGlobalThis2.js
Normal file
12
tests/baselines/reference/extendGlobalThis2.js
Normal file
@ -0,0 +1,12 @@
|
||||
//// [extendGlobalThis2.ts]
|
||||
namespace globalThis {
|
||||
export function foo() { console.log("x"); }
|
||||
}
|
||||
|
||||
|
||||
//// [extendGlobalThis2.js]
|
||||
var globalThis;
|
||||
(function (globalThis) {
|
||||
function foo() { console.log("x"); }
|
||||
globalThis.foo = foo;
|
||||
})(globalThis || (globalThis = {}));
|
||||
11
tests/baselines/reference/extendGlobalThis2.symbols
Normal file
11
tests/baselines/reference/extendGlobalThis2.symbols
Normal file
@ -0,0 +1,11 @@
|
||||
=== tests/cases/compiler/extendGlobalThis2.ts ===
|
||||
namespace globalThis {
|
||||
>globalThis : Symbol(globalThis, Decl(extendGlobalThis2.ts, 0, 0))
|
||||
|
||||
export function foo() { console.log("x"); }
|
||||
>foo : Symbol(foo, Decl(extendGlobalThis2.ts, 0, 22))
|
||||
>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
|
||||
>console : Symbol(console, Decl(lib.dom.d.ts, --, --))
|
||||
>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
|
||||
}
|
||||
|
||||
13
tests/baselines/reference/extendGlobalThis2.types
Normal file
13
tests/baselines/reference/extendGlobalThis2.types
Normal file
@ -0,0 +1,13 @@
|
||||
=== tests/cases/compiler/extendGlobalThis2.ts ===
|
||||
namespace globalThis {
|
||||
>globalThis : typeof globalThis
|
||||
|
||||
export function foo() { console.log("x"); }
|
||||
>foo : () => void
|
||||
>console.log("x") : void
|
||||
>console.log : (message?: any, ...optionalParams: any[]) => void
|
||||
>console : Console
|
||||
>log : (message?: any, ...optionalParams: any[]) => void
|
||||
>"x" : "x"
|
||||
}
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
=== tests/cases/conformance/es2019/globalThisPropertyAssignment.js ===
|
||||
this.x = 1
|
||||
>this.x : Symbol(x, Decl(globalThisPropertyAssignment.js, 0, 0))
|
||||
>this : Symbol(globalThis)
|
||||
>this : Symbol(globalThis, Decl(globalThisPropertyAssignment.js, 3, 12))
|
||||
>x : Symbol(x, Decl(globalThisPropertyAssignment.js, 0, 0))
|
||||
|
||||
var y = 2
|
||||
@ -14,6 +14,6 @@ window.z = 3
|
||||
// should work in JS (even though it's a secondary declaration)
|
||||
globalThis.alpha = 4
|
||||
>globalThis.alpha : Symbol(alpha, Decl(globalThisPropertyAssignment.js, 3, 12))
|
||||
>globalThis : Symbol(globalThis)
|
||||
>globalThis : Symbol(globalThis, Decl(globalThisPropertyAssignment.js, 3, 12))
|
||||
>alpha : Symbol(alpha, Decl(globalThisPropertyAssignment.js, 3, 12))
|
||||
|
||||
|
||||
3
tests/cases/compiler/extendGlobalThis2.ts
Normal file
3
tests/cases/compiler/extendGlobalThis2.ts
Normal file
@ -0,0 +1,3 @@
|
||||
namespace globalThis {
|
||||
export function foo() { console.log("x"); }
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user