fix error on globalThis type extend (#30460)

* Add test for extend globalThis

* Fix compile aborting
This commit is contained in:
Masahiro Wakame
2019-03-19 01:18:27 +09:00
committed by Nathan Shively-Sanders
parent d0646a629a
commit 18b8625ef8
5 changed files with 106 additions and 1 deletions

View File

@@ -27980,8 +27980,8 @@ namespace ts {
// The following checks only apply on a non-ambient instantiated module declaration.
if (symbol.flags & SymbolFlags.ValueModule
&& symbol.declarations.length > 1
&& !inAmbientContext
&& symbol.declarations.length > 1
&& isInstantiatedModule(node, !!compilerOptions.preserveConstEnums || !!compilerOptions.isolatedModules)) {
const firstNonAmbientClassOrFunc = getFirstNonAmbientClassOrFunctionDeclaration(symbol);
if (firstNonAmbientClassOrFunc) {

View File

@@ -0,0 +1,24 @@
//// [tests/cases/compiler/extendGlobalThis.ts] ////
//// [extension.d.ts]
declare global {
namespace globalThis {
var test: string;
}
}
export {}
//// [index.ts]
import "./extention";
globalThis.tests = "a-b";
console.log(globalThis.test.split("-"));
//// [index.js]
"use strict";
exports.__esModule = true;
require("./extention");
globalThis.tests = "a-b";
console.log(globalThis.test.split("-"));

View File

@@ -0,0 +1,30 @@
=== tests/cases/compiler/extension.d.ts ===
declare global {
>global : Symbol(global, Decl(extension.d.ts, 0, 0))
namespace globalThis {
>globalThis : Symbol(globalThis)
var test: string;
>test : Symbol(test, Decl(extension.d.ts, 2, 11))
}
}
export {}
=== tests/cases/compiler/index.ts ===
import "./extention";
globalThis.tests = "a-b";
>globalThis : Symbol(globalThis)
console.log(globalThis.test.split("-"));
>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, --, --))
>globalThis.test.split : Symbol(String.split, Decl(lib.es5.d.ts, --, --))
>globalThis.test : Symbol(test, Decl(extension.d.ts, 2, 11))
>globalThis : Symbol(globalThis)
>test : Symbol(test, Decl(extension.d.ts, 2, 11))
>split : Symbol(String.split, Decl(lib.es5.d.ts, --, --))

View File

@@ -0,0 +1,37 @@
=== tests/cases/compiler/extension.d.ts ===
declare global {
>global : typeof global
namespace globalThis {
>globalThis : typeof globalThis
var test: string;
>test : string
}
}
export {}
=== tests/cases/compiler/index.ts ===
import "./extention";
globalThis.tests = "a-b";
>globalThis.tests = "a-b" : "a-b"
>globalThis.tests : any
>globalThis : typeof globalThis
>tests : any
>"a-b" : "a-b"
console.log(globalThis.test.split("-"));
>console.log(globalThis.test.split("-")) : void
>console.log : (message?: any, ...optionalParams: any[]) => void
>console : Console
>log : (message?: any, ...optionalParams: any[]) => void
>globalThis.test.split("-") : string[]
>globalThis.test.split : (separator: string | RegExp, limit?: number) => string[]
>globalThis.test : string
>globalThis : typeof globalThis
>test : string
>split : (separator: string | RegExp, limit?: number) => string[]
>"-" : "-"

View File

@@ -0,0 +1,14 @@
// @filename: extension.d.ts
declare global {
namespace globalThis {
var test: string;
}
}
export {}
// @filename: index.ts
import "./extention";
globalThis.tests = "a-b";
console.log(globalThis.test.split("-"));