0
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-02-08 07:16:56 -05:00

Hide compiler module (#909)

Fixes #876
This commit is contained in:
Kitson Kelly 2018-10-06 00:13:22 +10:00 committed by Ryan Dahl
parent 6a649012bc
commit 6c42ded097
4 changed files with 23 additions and 20 deletions

View file

@ -1,7 +1,7 @@
// Copyright 2018 the Deno authors. All rights reserved. MIT license. // Copyright 2018 the Deno authors. All rights reserved. MIT license.
/// <amd-module name="compiler"/>
import * as ts from "typescript"; import * as ts from "typescript";
import { assetSourceCode } from "./assets"; import { assetSourceCode } from "./assets";
// tslint:disable-next-line:no-circular-imports
import * as deno from "./deno"; import * as deno from "./deno";
import { globalEval } from "./global_eval"; import { globalEval } from "./global_eval";
import { libdeno } from "./libdeno"; import { libdeno } from "./libdeno";
@ -648,7 +648,7 @@ export class DenoCompiler
this._log("resolveModuleNames()", { moduleNames, containingFile }); this._log("resolveModuleNames()", { moduleNames, containingFile });
return moduleNames.map(name => { return moduleNames.map(name => {
let resolvedFileName; let resolvedFileName;
if (name === "deno" || name === "compiler") { if (name === "deno") {
// builtin modules are part of `globals.d.ts` // builtin modules are part of `globals.d.ts`
resolvedFileName = this._resolveModuleName("globals.d.ts", ASSETS); resolvedFileName = this._resolveModuleName("globals.d.ts", ASSETS);
} else if (name === "typescript") { } else if (name === "typescript") {
@ -683,8 +683,7 @@ export class DenoCompiler
// tslint:disable-next-line:no-any // tslint:disable-next-line:no-any
private static _builtins: { [mid: string]: any } = { private static _builtins: { [mid: string]: any } = {
typescript: ts, typescript: ts,
deno, deno
compiler: { DenoCompiler, ModuleMetaData }
}; };
private static _instance: DenoCompiler | undefined; private static _instance: DenoCompiler | undefined;

View file

@ -1,12 +1,12 @@
// Copyright 2018 the Deno authors. All rights reserved. MIT license. // Copyright 2018 the Deno authors. All rights reserved. MIT license.
import { test, assert, assertEqual } from "./test_util.ts"; import { test, assert, assertEqual } from "./test_util.ts";
import * as compiler from "compiler"; import * as deno from "deno";
import * as ts from "typescript"; import * as ts from "typescript";
// We use a silly amount of `any` in these tests... // We use a silly amount of `any` in these tests...
// tslint:disable:no-any // tslint:disable:no-any
const { DenoCompiler } = compiler; const { DenoCompiler } = (deno as any)._compiler;
interface ModuleInfo { interface ModuleInfo {
moduleName: string | null; moduleName: string | null;
@ -42,8 +42,8 @@ function mockModuleInfo(
} }
// Some fixtures we will us in testing // Some fixtures we will us in testing
const fooBarTsSource = `import * as compiler from "compiler"; const fooBarTsSource = `import * as deno from "deno";
console.log(compiler); console.log(deno);
export const foo = "bar"; export const foo = "bar";
`; `;
@ -81,13 +81,13 @@ const modBModuleInfo = mockModuleInfo(
// TODO(#23) Remove source map strings from fooBarTsOutput. // TODO(#23) Remove source map strings from fooBarTsOutput.
// tslint:disable:max-line-length // tslint:disable:max-line-length
const fooBarTsOutput = `define(["require", "exports", "compiler"], function (require, exports, compiler) { const fooBarTsOutput = `define(["require", "exports", "deno"], function (require, exports, deno) {
"use strict"; "use strict";
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
console.log(compiler); console.log(deno);
exports.foo = "bar"; exports.foo = "bar";
}); });
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYmFyLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiZmlsZTovLy9yb290L3Byb2plY3QvZm9vL2Jhci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7SUFDQSxPQUFPLENBQUMsR0FBRyxDQUFDLFFBQVEsQ0FBQyxDQUFDO0lBQ1QsUUFBQSxHQUFHLEdBQUcsS0FBSyxDQUFDIiwic291cmNlc0NvbnRlbnQiOlsiaW1wb3J0ICogYXMgY29tcGlsZXIgZnJvbSBcImNvbXBpbGVyXCI7XG5jb25zb2xlLmxvZyhjb21waWxlcik7XG5leHBvcnQgY29uc3QgZm9vID0gXCJiYXJcIjtcbiJdfQ== //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYmFyLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiZmlsZTovLy9yb290L3Byb2plY3QvZm9vL2Jhci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7SUFDQSxPQUFPLENBQUMsR0FBRyxDQUFDLElBQUksQ0FBQyxDQUFDO0lBQ0wsUUFBQSxHQUFHLEdBQUcsS0FBSyxDQUFDIiwic291cmNlc0NvbnRlbnQiOlsiaW1wb3J0ICogYXMgZGVubyBmcm9tIFwiZGVub1wiO1xuY29uc29sZS5sb2coZGVubyk7XG5leHBvcnQgY29uc3QgZm9vID0gXCJiYXJcIjtcbiJdfQ==
//# sourceURL=/root/project/foo/bar.ts`; //# sourceURL=/root/project/foo/bar.ts`;
// TODO(#23) Remove source map strings from fooBazTsOutput. // TODO(#23) Remove source map strings from fooBazTsOutput.
@ -159,7 +159,7 @@ let codeFetchStack: Array<{
}> = []; }> = [];
let mockDepsStack: string[][] = []; let mockDepsStack: string[][] = [];
let mockFactoryStack: compiler.AmdFactory[] = []; let mockFactoryStack: any[] = [];
function globalEvalMock(x: string): void { function globalEvalMock(x: string): void {
globalEvalStack.push(x); globalEvalStack.push(x);
@ -247,7 +247,7 @@ const serviceMock = {
); );
} }
}; };
const windowMock: { define?: compiler.AmdDefine } = {}; const windowMock: { define?: any } = {};
const mocks = { const mocks = {
_globalEval: globalEvalMock, _globalEval: globalEvalMock,
_log: logMock, _log: logMock,
@ -300,12 +300,12 @@ test(function compilerRun() {
// equal to `deno foo/bar.ts` // equal to `deno foo/bar.ts`
setup(); setup();
let factoryRun = false; let factoryRun = false;
mockDepsStack.push(["require", "exports", "compiler"]); mockDepsStack.push(["require", "exports", "deno"]);
mockFactoryStack.push((_require, _exports, _compiler) => { mockFactoryStack.push((_require, _exports, _deno) => {
factoryRun = true; factoryRun = true;
assertEqual(typeof _require, "function"); assertEqual(typeof _require, "function");
assertEqual(typeof _exports, "object"); assertEqual(typeof _exports, "object");
assert(_compiler === compiler); assert(_deno === deno);
_exports.foo = "bar"; _exports.foo = "bar";
}); });
const moduleMetaData = compilerInstance.run("foo/bar.ts", "/root/project"); const moduleMetaData = compilerInstance.run("foo/bar.ts", "/root/project");
@ -337,8 +337,8 @@ test(function compilerRunMultiModule() {
factoryStack.push("baz"); factoryStack.push("baz");
assertEqual(_bar.foo, "bar"); assertEqual(_bar.foo, "bar");
}; };
const barDeps = ["require", "exports", "compiler"]; const barDeps = ["require", "exports", "deno"];
const barFactory = (_require, _exports, _compiler) => { const barFactory = (_require, _exports, _deno) => {
factoryStack.push("bar"); factoryStack.push("bar");
_exports.foo = "bar"; _exports.foo = "bar";
}; };
@ -411,7 +411,7 @@ test(function compilerGetModuleDependencies() {
const bazFactory = () => { const bazFactory = () => {
throw new Error("Unexpected factory call"); throw new Error("Unexpected factory call");
}; };
const barDeps = ["require", "exports", "compiler"]; const barDeps = ["require", "exports", "deno"];
const barFactory = () => { const barFactory = () => {
throw new Error("Unexpected factory call"); throw new Error("Unexpected factory call");
}; };

View file

@ -23,3 +23,8 @@ export { truncateSync, truncate } from "./truncate";
export { FileInfo } from "./file_info"; export { FileInfo } from "./file_info";
export { connect, dial, listen, Listener, Conn } from "./net"; export { connect, dial, listen, Listener, Conn } from "./net";
export const args: string[] = []; export const args: string[] = [];
// Provide the compiler API in an obfuscated way
import * as compiler from "./compiler";
// @internal
export const _compiler = compiler;

View file

@ -13,7 +13,6 @@
}, },
"files": [ "files": [
"../node_modules/typescript/lib/lib.esnext.d.ts", "../node_modules/typescript/lib/lib.esnext.d.ts",
"./compiler.ts",
"./deno.ts", "./deno.ts",
"./globals.ts" "./globals.ts"
] ]