From a21a5ad2fa4dcbad58fe63c298c69f8607705bf4 Mon Sep 17 00:00:00 2001 From: Kitson Kelly Date: Wed, 13 Feb 2019 02:08:56 +1100 Subject: Add Deno global namespace (#1748) Resolves #1705 This PR adds the Deno APIs as a global namespace named `Deno`. For backwards compatibility, the ability to `import * from "deno"` is preserved. I have tried to convert every test and internal code the references the module to use the namespace instead, but because I didn't break compatibility I am not sure. On the REPL, `deno` no longer exists, replaced only with `Deno` to align with the regular runtime. The runtime type library includes both the namespace and module. This means it duplicates the whole type information. When we remove the functionality from the runtime, it will be a one line change to the library generator to remove the module definition from the type library. I marked a `TODO` in a couple places where to remove the `"deno"` module, but there are additional places I know I didn't mark. --- tools/ts_library_builder/test.ts | 40 ++++++++++++++++++++++++++++++++++------ 1 file changed, 34 insertions(+), 6 deletions(-) (limited to 'tools/ts_library_builder/test.ts') diff --git a/tools/ts_library_builder/test.ts b/tools/ts_library_builder/test.ts index acc2c43db..d8cbec62b 100644 --- a/tools/ts_library_builder/test.ts +++ b/tools/ts_library_builder/test.ts @@ -79,14 +79,16 @@ test(function buildLibraryFlatten() { debug, declarationProject, filePath: `${buildPath}/api.d.ts`, - namespaceName: `"api"`, + moduleName: `"api"`, + namespaceName: "Api", targetSourceFile }); assert(targetSourceFile.getNamespace(`"api"`) != null); - assertEqual(targetSourceFile.getNamespaces().length, 1); - const namespaceApi = targetSourceFile.getNamespaceOrThrow(`"api"`); - const functions = namespaceApi.getFunctions(); + assert(targetSourceFile.getNamespace("Api") != null); + assertEqual(targetSourceFile.getNamespaces().length, 2); + const moduleApi = targetSourceFile.getNamespaceOrThrow(`"api"`); + const functions = moduleApi.getFunctions(); assertEqual(functions[0].getName(), "foo"); assertEqual( functions[0] @@ -104,12 +106,38 @@ test(function buildLibraryFlatten() { "" ); assertEqual(functions.length, 2); - const classes = namespaceApi.getClasses(); + const classes = moduleApi.getClasses(); assertEqual(classes[0].getName(), "Foo"); assertEqual(classes.length, 1); - const variableDeclarations = namespaceApi.getVariableDeclarations(); + const variableDeclarations = moduleApi.getVariableDeclarations(); assertEqual(variableDeclarations[0].getName(), "arr"); assertEqual(variableDeclarations.length, 1); + + const namespaceApi = targetSourceFile.getNamespaceOrThrow(`"api"`); + const functionsNs = namespaceApi.getFunctions(); + assertEqual(functionsNs[0].getName(), "foo"); + assertEqual( + functionsNs[0] + .getJsDocs() + .map(jsdoc => jsdoc.getInnerText()) + .join("\n"), + "jsdoc for foo" + ); + assertEqual(functionsNs[1].getName(), "bar"); + assertEqual( + functionsNs[1] + .getJsDocs() + .map(jsdoc => jsdoc.getInnerText()) + .join("\n"), + "" + ); + assertEqual(functionsNs.length, 2); + const classesNs = namespaceApi.getClasses(); + assertEqual(classesNs[0].getName(), "Foo"); + assertEqual(classesNs.length, 1); + const variableDeclarationsNs = namespaceApi.getVariableDeclarations(); + assertEqual(variableDeclarationsNs[0].getName(), "arr"); + assertEqual(variableDeclarationsNs.length, 1); }); test(function buildLibraryMerge() { -- cgit v1.2.3