diff options
author | Kitson Kelly <me@kitsonkelly.com> | 2019-01-17 09:57:15 +1100 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2019-01-16 17:57:15 -0500 |
commit | 00b655add1c83a3924f1e86b51689aa1ed8e5d05 (patch) | |
tree | 4728148fa46fee8671f6074215d859c78cdfefd7 /tools/ts_library_builder | |
parent | eb6f7f901b3b4fd6bfb1596923b50eef8195a131 (diff) |
Add globalThis definition to runtime (#1534)
Diffstat (limited to 'tools/ts_library_builder')
-rw-r--r-- | tools/ts_library_builder/build_library.ts | 4 | ||||
-rw-r--r-- | tools/ts_library_builder/test.ts | 13 |
2 files changed, 11 insertions, 6 deletions
diff --git a/tools/ts_library_builder/build_library.ts b/tools/ts_library_builder/build_library.ts index 00e942540..0717de987 100644 --- a/tools/ts_library_builder/build_library.ts +++ b/tools/ts_library_builder/build_library.ts @@ -156,6 +156,10 @@ export function mergeGlobal({ // Declare the global variable 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 addInterfaceProperty(interfaceDeclaration, globalVarName, interfaceName); diff --git a/tools/ts_library_builder/test.ts b/tools/ts_library_builder/test.ts index b5883433a..ad0d7cfa1 100644 --- a/tools/ts_library_builder/test.ts +++ b/tools/ts_library_builder/test.ts @@ -140,24 +140,25 @@ test(function buildLibraryMerge() { assertEqual(targetSourceFile.getInterfaces().length, 1); const variableDeclarations = targetSourceFile.getVariableDeclarations(); 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( - variableDeclarations[2].getType().getText(), + variableDeclarations[3].getType().getText(), `typeof moduleC.qat` ); assertEqual( - variableDeclarations[3].getType().getText(), + variableDeclarations[4].getType().getText(), `typeof moduleE.process` ); assertEqual( - variableDeclarations[4].getType().getText(), + variableDeclarations[5].getType().getText(), `typeof moduleD.reprocess` ); assertEqual( - variableDeclarations[5].getType().getText(), + variableDeclarations[6].getType().getText(), `typeof moduleC.Bar` ); - assertEqual(variableDeclarations.length, 6); + assertEqual(variableDeclarations.length, 7); const typeAliases = targetSourceFile.getTypeAliases(); assertEqual(typeAliases[0].getName(), "Bar"); assertEqual(typeAliases[0].getType().getText(), "moduleC.Bar"); |