mirror of
https://github.com/denoland/deno.git
synced 2024-11-29 16:30:56 -05:00
Add globalThis definition to runtime (#1534)
This commit is contained in:
parent
eb6f7f901b
commit
00b655add1
4 changed files with 29 additions and 6 deletions
17
js/globals_test.ts
Normal file
17
js/globals_test.ts
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
import { test, assert } from "./test_util.ts";
|
||||||
|
|
||||||
|
test(function globalThisExists() {
|
||||||
|
assert(globalThis != null);
|
||||||
|
});
|
||||||
|
|
||||||
|
test(function windowExists() {
|
||||||
|
assert(window != null);
|
||||||
|
});
|
||||||
|
|
||||||
|
test(function windowWindowExists() {
|
||||||
|
assert(window.window === window);
|
||||||
|
});
|
||||||
|
|
||||||
|
test(function globalThisEqualsWindow() {
|
||||||
|
assert(globalThis === window);
|
||||||
|
});
|
|
@ -18,6 +18,7 @@ import "./fetch_test.ts";
|
||||||
// import "./file_test.ts";
|
// import "./file_test.ts";
|
||||||
import "./files_test.ts";
|
import "./files_test.ts";
|
||||||
import "./form_data_test.ts";
|
import "./form_data_test.ts";
|
||||||
|
import "./globals_test.ts";
|
||||||
import "./headers_test.ts";
|
import "./headers_test.ts";
|
||||||
import "./make_temp_dir_test.ts";
|
import "./make_temp_dir_test.ts";
|
||||||
import "./metrics_test.ts";
|
import "./metrics_test.ts";
|
||||||
|
|
|
@ -156,6 +156,10 @@ export function mergeGlobal({
|
||||||
// Declare the global variable
|
// Declare the global variable
|
||||||
addVariableDeclaration(targetSourceFile, globalVarName, interfaceName, true);
|
addVariableDeclaration(targetSourceFile, globalVarName, interfaceName, true);
|
||||||
|
|
||||||
|
// `globalThis` accesses the global scope and is defined here:
|
||||||
|
// https://github.com/tc39/proposal-global
|
||||||
|
addVariableDeclaration(targetSourceFile, "globalThis", interfaceName, true);
|
||||||
|
|
||||||
// Add self reference to the global variable
|
// Add self reference to the global variable
|
||||||
addInterfaceProperty(interfaceDeclaration, globalVarName, interfaceName);
|
addInterfaceProperty(interfaceDeclaration, globalVarName, interfaceName);
|
||||||
|
|
||||||
|
|
|
@ -140,24 +140,25 @@ test(function buildLibraryMerge() {
|
||||||
assertEqual(targetSourceFile.getInterfaces().length, 1);
|
assertEqual(targetSourceFile.getInterfaces().length, 1);
|
||||||
const variableDeclarations = targetSourceFile.getVariableDeclarations();
|
const variableDeclarations = targetSourceFile.getVariableDeclarations();
|
||||||
assertEqual(variableDeclarations[0].getType().getText(), `FooBar`);
|
assertEqual(variableDeclarations[0].getType().getText(), `FooBar`);
|
||||||
assertEqual(variableDeclarations[1].getType().getText(), `moduleC.Bar`);
|
assertEqual(variableDeclarations[1].getType().getText(), `FooBar`);
|
||||||
|
assertEqual(variableDeclarations[2].getType().getText(), `moduleC.Bar`);
|
||||||
assertEqual(
|
assertEqual(
|
||||||
variableDeclarations[2].getType().getText(),
|
variableDeclarations[3].getType().getText(),
|
||||||
`typeof moduleC.qat`
|
`typeof moduleC.qat`
|
||||||
);
|
);
|
||||||
assertEqual(
|
assertEqual(
|
||||||
variableDeclarations[3].getType().getText(),
|
variableDeclarations[4].getType().getText(),
|
||||||
`typeof moduleE.process`
|
`typeof moduleE.process`
|
||||||
);
|
);
|
||||||
assertEqual(
|
assertEqual(
|
||||||
variableDeclarations[4].getType().getText(),
|
variableDeclarations[5].getType().getText(),
|
||||||
`typeof moduleD.reprocess`
|
`typeof moduleD.reprocess`
|
||||||
);
|
);
|
||||||
assertEqual(
|
assertEqual(
|
||||||
variableDeclarations[5].getType().getText(),
|
variableDeclarations[6].getType().getText(),
|
||||||
`typeof moduleC.Bar`
|
`typeof moduleC.Bar`
|
||||||
);
|
);
|
||||||
assertEqual(variableDeclarations.length, 6);
|
assertEqual(variableDeclarations.length, 7);
|
||||||
const typeAliases = targetSourceFile.getTypeAliases();
|
const typeAliases = targetSourceFile.getTypeAliases();
|
||||||
assertEqual(typeAliases[0].getName(), "Bar");
|
assertEqual(typeAliases[0].getName(), "Bar");
|
||||||
assertEqual(typeAliases[0].getType().getText(), "moduleC.Bar");
|
assertEqual(typeAliases[0].getType().getText(), "moduleC.Bar");
|
||||||
|
|
Loading…
Reference in a new issue