summaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
Diffstat (limited to 'js')
-rw-r--r--js/assets.ts47
-rw-r--r--js/deno.d.ts10
-rw-r--r--js/deno.ts2
-rw-r--r--js/globals.ts21
-rw-r--r--js/lib.globals.d.ts24
-rw-r--r--js/main.ts1
-rw-r--r--js/runtime.ts15
-rw-r--r--js/tsconfig.generated.json16
-rw-r--r--js/types.d.ts134
-rw-r--r--js/types.ts9
-rw-r--r--js/v8_source_maps.ts11
11 files changed, 206 insertions, 84 deletions
diff --git a/js/assets.ts b/js/assets.ts
index 52c33b26b..0c1b85e5d 100644
--- a/js/assets.ts
+++ b/js/assets.ts
@@ -5,11 +5,15 @@
// There is a rollup plugin that will inline any module ending with `!string`
// tslint:disable:max-line-length
-import denoDts from "/js/deno.d.ts!string";
-// import libDts from "/third_party/node_modules/typescript/lib/lib.d.ts!string";
-import globalsDts from "/js/lib.globals.d.ts!string";
-// import libDomD qts from "/third_party/node_modules/typescript/lib/lib.dom.d.ts!string";
-// import libDomIterableDts from "/third_party/node_modules/typescript/lib/lib.dom.iterable.d.ts!string";
+
+// Generated definitions
+import consoleDts from "gen/js/console.d.ts!string";
+import denoDts from "gen/js/deno.d.ts!string";
+import globalsDts from "gen/js/globals.d.ts!string";
+import osDts from "gen/js/os.d.ts!string";
+import utilDts from "gen/js/util.d.ts!string";
+
+// Static libraries
import libEs2015Dts from "/third_party/node_modules/typescript/lib/lib.es2015.d.ts!string";
import libEs2015CollectionDts from "/third_party/node_modules/typescript/lib/lib.es2015.collection.d.ts!string";
import libEs2015CoreDts from "/third_party/node_modules/typescript/lib/lib.es2015.core.d.ts!string";
@@ -38,17 +42,23 @@ import libEsnextAsynciterablesDts from "/third_party/node_modules/typescript/lib
import libEsnextDts from "/third_party/node_modules/typescript/lib/lib.esnext.d.ts!string";
import libEsnextIntlDts from "/third_party/node_modules/typescript/lib/lib.esnext.intl.d.ts!string";
import libEsnextSymbolDts from "/third_party/node_modules/typescript/lib/lib.esnext.symbol.d.ts!string";
-// import libScripthost from "/third_party/node_modules/typescript/lib/lib.scripthost.d.ts!string";
-// import libWebworkerImportscripts from "/third_party/node_modules/typescript/lib/lib.webworker.importscripts.d.ts!string";
+import libGlobalsDts from "/js/lib.globals.d.ts!string";
+
+// Static definitions
import typescriptDts from "/third_party/node_modules/typescript/lib/typescript.d.ts!string";
+import typesDts from "/js/types.d.ts!string";
+// tslint:enable:max-line-length
// prettier-ignore
export const assetSourceCode: { [key: string]: string } = {
+ // Generated definitions
+ "console.d.ts": consoleDts,
"deno.d.ts": denoDts,
- // "lib.d.ts": libDts,
- "lib.globals.d.ts": globalsDts,
- // "lib.dom.d.ts": libDomDts,
- // "lib.dom.iterable.d.ts": libDomIterableDts,
+ "globals.d.ts": globalsDts,
+ "os.d.ts": osDts,
+ "util.d.ts": utilDts,
+
+ // Static libraries
"lib.es2015.collection.d.ts": libEs2015CollectionDts,
"lib.es2015.core.d.ts": libEs2015CoreDts,
"lib.es2015.d.ts": libEs2015Dts,
@@ -61,32 +71,25 @@ export const assetSourceCode: { [key: string]: string } = {
"lib.es2015.symbol.wellknown.d.ts": libEs2015SymbolWellknownDts,
"lib.es2016.array.include.d.ts": libEs2016ArrayIncludeDts,
"lib.es2016.d.ts": libEs2016Dts,
- //"lib.es2016.full.d.ts": readFileSync(__dirname + "/../third_party/node_modules/typescript/lib/lib.es2016.full.d.ts", "utf8"),
"lib.es2017.d.ts": libEs2017Dts,
- //"lib.es2017.full.d.ts": readFileSync(__dirname + "/../third_party/node_modules/typescript/lib/lib.es2017.full.d.ts", "utf8"),
"lib.es2017.intl.d.ts": libEs2017IntlDts,
"lib.es2017.object.d.ts": libEs2017ObjectDts,
"lib.es2017.sharedmemory.d.ts": libEs2017SharedmemoryDts,
"lib.es2017.string.d.ts": libEs2017StringDts,
"lib.es2017.typedarrays.d.ts": libEs2017TypedarraysDts,
"lib.es2018.d.ts": libEs2018Dts,
- //"lib.es2018.full.d.ts": readFileSync(__dirname + "/../third_party/node_modules/typescript/lib/lib.es2018.full.d.ts", "utf8"),
"lib.es2018.intl.d.ts": libEs2018IntlDts,
"lib.es2018.promise.d.ts": libEs2018PromiseDts,
"lib.es2018.regexp.d.ts": libEs2018RegexpDts,
"lib.es5.d.ts": libEs5Dts,
- //"lib.es6.d.ts": readFileSync(__dirname + "/../third_party/node_modules/typescript/lib/lib.es6.d.ts", "utf8"),
"lib.esnext.d.ts": libEsnextDts,
"lib.esnext.array.d.ts": libEsnextArrayDts,
"lib.esnext.asynciterable.d.ts": libEsnextAsynciterablesDts,
"lib.esnext.intl.d.ts": libEsnextIntlDts,
"lib.esnext.symbol.d.ts": libEsnextSymbolDts,
- //"lib.esnext.full.d.ts": readFileSync(__dirname + "/../third_party/node_modules/typescript/lib/lib.esnext.full.d.ts", "utf8"),
- // "lib.scripthost.d.ts": libScripthost,
- // "lib.webworker.d.ts": libWebworker,
- // "lib.webworker.importscripts.d.ts": libWebworkerImportscripts,
- //"protocol.d.ts": readFileSync(__dirname + "/../third_party/node_modules/typescript/lib/protocol.d.ts", "utf8"),
- //"tsserverlibrary.d.ts": readFileSync(__dirname + "/../third_party/node_modules/typescript/lib/tsserverlibrary.d.ts", "utf8"),
+ "lib.globals.d.ts": libGlobalsDts,
+
+ // Static definitions
"typescript.d.ts": typescriptDts,
- //"typescriptServices.d.ts": readFileSync(__dirname + "/../third_party/node_modules/typescript/lib/typescriptServices.d.ts", "utf8"),
+ "types.d.ts": typesDts,
};
diff --git a/js/deno.d.ts b/js/deno.d.ts
deleted file mode 100644
index f2b726d8e..000000000
--- a/js/deno.d.ts
+++ /dev/null
@@ -1,10 +0,0 @@
-// Copyright 2018 the Deno authors. All rights reserved. MIT license.
-type MessageCallback = (msg: Uint8Array) => void;
-
-interface Deno {
- recv(cb: MessageCallback): void;
- send(msg: ArrayBufferView): null | Uint8Array;
- print(x: string): void;
-}
-
-declare let deno: Deno;
diff --git a/js/deno.ts b/js/deno.ts
index df1148453..9ef533a9e 100644
--- a/js/deno.ts
+++ b/js/deno.ts
@@ -1,5 +1,5 @@
// Copyright 2018 the Deno authors. All rights reserved. MIT license.
// Public deno module.
// TODO get rid of deno.d.ts
-export { pub, sub } from "./dispatch";
+// export { pub, sub } from "./dispatch";
export { readFileSync, writeFileSync } from "./os";
diff --git a/js/globals.ts b/js/globals.ts
index c36eaff60..82c9a24c0 100644
--- a/js/globals.ts
+++ b/js/globals.ts
@@ -1,5 +1,25 @@
// Copyright 2018 the Deno authors. All rights reserved. MIT license.
+import { Console } from "./console";
+
+declare global {
+ type MessageCallback = (msg: Uint8Array) => void;
+
+ interface Deno {
+ print(text: string): void;
+ recv(cb: MessageCallback): void;
+ send(msg: ArrayBufferView): Uint8Array | null;
+ }
+
+ interface Window {
+ console: Console;
+ }
+
+ const console: Console;
+ const deno: Readonly<Deno>;
+ const window: Window;
+}
+
// If you use the eval function indirectly, by invoking it via a reference
// other than eval, as of ECMAScript 5 it works in the global scope rather than
// the local scope. This means, for instance, that function declarations create
@@ -20,7 +40,6 @@ window["window"] = window; // Create a window object.
// window["clearTimeout"] = timer.clearTimer;
// window["clearInterval"] = timer.clearTimer;
-import { Console } from "./console";
window["console"] = new Console();
// import { fetch } from "./fetch";
diff --git a/js/lib.globals.d.ts b/js/lib.globals.d.ts
index b11a08edf..d11bbe97d 100644
--- a/js/lib.globals.d.ts
+++ b/js/lib.globals.d.ts
@@ -6,36 +6,14 @@
/// <reference lib="esnext" />
-// TODO generate `console.d.ts` and inline it in `assets.ts` and remove
-// declaration of `Console`
-// import { Console } from 'gen/console';
-
-declare class Console {
- // tslint:disable-next-line:no-any
- log(...args: any[]): void;
- // tslint:disable-next-line:no-any
- debug(...args: any[]): void;
- // tslint:disable-next-line:no-any
- info(...args: any[]): void;
- // tslint:disable-next-line:no-any
- warn(...args: any[]): void;
- // tslint:disable-next-line:no-any
- error(...args: any[]): void;
- // tslint:disable-next-line:no-any
- assert(condition: boolean, ...args: any[]): void;
-}
+import "gen/js/globals";
interface Window {
- console: Console;
// TODO(ry) These shouldn't be global.
mainSource: string;
setMainSourceMap(sm: string): void;
}
-// Globals in the runtime environment
-declare let console: Console;
-declare const window: Window;
-
// TODO(ry) These shouldn't be global.
declare let mainSource: string;
declare function setMainSourceMap(sm: string): void;
diff --git a/js/main.ts b/js/main.ts
index 81dabab33..29c4ab412 100644
--- a/js/main.ts
+++ b/js/main.ts
@@ -1,6 +1,5 @@
// Copyright 2018 the Deno authors. All rights reserved. MIT license.
// tslint:disable-next-line:no-reference
-/// <reference path="deno.d.ts" />
import { flatbuffers } from "flatbuffers";
import { deno as fbs } from "gen/msg_generated";
import { assert, log, assignCmdId } from "./util";
diff --git a/js/runtime.ts b/js/runtime.ts
index 8b7863b9f..9a3302d64 100644
--- a/js/runtime.ts
+++ b/js/runtime.ts
@@ -166,12 +166,11 @@ export function resolveModule(
util.log("resolveModule", { moduleSpecifier, containingFile });
util.assert(moduleSpecifier != null && moduleSpecifier.length > 0);
let filename: string, sourceCode: string, outputCode: string;
- if (
- moduleSpecifier.startsWith(ASSETS) ||
- containingFile.startsWith(ASSETS)
- ) {
+ if (moduleSpecifier.startsWith(ASSETS) || containingFile.startsWith(ASSETS)) {
// Assets are compiled into the runtime javascript bundle.
- const assetName = moduleSpecifier.split("/").pop();
+ const moduleId = moduleSpecifier.split("/").pop();
+ const assetName = moduleId.includes(".") ? moduleId : `${moduleId}.d.ts`;
+ util.assert(assetName in assetSourceCode);
sourceCode = assetSourceCode[assetName];
filename = ASSETS + assetName;
} else {
@@ -330,7 +329,7 @@ class TypeScriptHost implements ts.LanguageServiceHost {
}
getDefaultLibFileName(options: ts.CompilerOptions): string {
- const fn = "lib.deno.d.ts"; // ts.getDefaultLibFileName(options);
+ const fn = "lib.globals.d.ts"; // ts.getDefaultLibFileName(options);
util.log("getDefaultLibFileName", fn);
const m = resolveModule(fn, ASSETS);
return m.fileName;
@@ -354,7 +353,9 @@ class TypeScriptHost implements ts.LanguageServiceHost {
return undefined;
}
}
- const isExternalLibraryImport = false;
+ // This flags to the compiler to not go looking to transpile functional
+ // code, anything that is in `/$asset$/` is just library code
+ const isExternalLibraryImport = resolvedFileName.startsWith(ASSETS);
return { resolvedFileName, isExternalLibraryImport };
});
}
diff --git a/js/tsconfig.generated.json b/js/tsconfig.generated.json
new file mode 100644
index 000000000..4fa3be1a1
--- /dev/null
+++ b/js/tsconfig.generated.json
@@ -0,0 +1,16 @@
+{
+ // This configuration file provides the tsc configuration for generating
+ // definitions for the runtime, which are then inlined via the `js/assets.ts`
+ // module into the bundle to be available for type checking at runtime
+ // See also gen_declarations in //BUILD.gn
+ "extends": "../tsconfig.json",
+ "compilerOptions": {
+ "declaration": true,
+ "declarationMap": true,
+ },
+ "files": [
+ "../node_modules/typescript/lib/lib.esnext.d.ts",
+ "./deno.ts",
+ "./globals.ts"
+ ]
+}
diff --git a/js/types.d.ts b/js/types.d.ts
new file mode 100644
index 000000000..a9e013193
--- /dev/null
+++ b/js/types.d.ts
@@ -0,0 +1,134 @@
+// Copyright 2018 the Deno authors. All rights reserved. MIT license.
+export type TypedArray = Uint8Array | Float32Array | Int32Array;
+
+export interface ModuleInfo {
+ moduleName?: string;
+ filename?: string;
+ sourceCode?: string;
+ outputCode?: string;
+}
+
+// Following definitions adapted from:
+// https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/node/index.d.ts
+// Type definitions for Node.js 10.3.x
+// Definitions by: Microsoft TypeScript <http://typescriptlang.org>
+// DefinitelyTyped <https://github.com/DefinitelyTyped/DefinitelyTyped>
+// Parambir Singh <https://github.com/parambirs>
+// Christian Vaagland Tellnes <https://github.com/tellnes>
+// Wilco Bakker <https://github.com/WilcoBakker>
+// Nicolas Voigt <https://github.com/octo-sniffle>
+// Chigozirim C. <https://github.com/smac89>
+// Flarna <https://github.com/Flarna>
+// Mariusz Wiktorczyk <https://github.com/mwiktorczyk>
+// wwwy3y3 <https://github.com/wwwy3y3>
+// Deividas Bakanas <https://github.com/DeividasBakanas>
+// Kelvin Jin <https://github.com/kjin>
+// Alvis HT Tang <https://github.com/alvis>
+// Sebastian Silbermann <https://github.com/eps1lon>
+// Hannes Magnusson <https://github.com/Hannes-Magnusson-CK>
+// Alberto Schiabel <https://github.com/jkomyno>
+// Klaus Meinhardt <https://github.com/ajafff>
+// Huw <https://github.com/hoo29>
+// Nicolas Even <https://github.com/n-e>
+// Bruno Scheufler <https://github.com/brunoscheufler>
+// Mohsen Azimi <https://github.com/mohsen1>
+// Hoàng Văn Khải <https://github.com/KSXGitHub>
+// Alexander T. <https://github.com/a-tarasyuk>
+// Lishude <https://github.com/islishude>
+// Andrew Makarov <https://github.com/r3nya>
+
+export interface CallSite {
+ /**
+ * Value of "this"
+ */
+ getThis(): any;
+
+ /**
+ * Type of "this" as a string.
+ * This is the name of the function stored in the constructor field of
+ * "this", if available. Otherwise the object's [[Class]] internal
+ * property.
+ */
+ getTypeName(): string | null;
+
+ /**
+ * Current function
+ */
+ getFunction(): Function | undefined;
+
+ /**
+ * Name of the current function, typically its name property.
+ * If a name property is not available an attempt will be made to try
+ * to infer a name from the function's context.
+ */
+ getFunctionName(): string | null;
+
+ /**
+ * Name of the property [of "this" or one of its prototypes] that holds
+ * the current function
+ */
+ getMethodName(): string | null;
+
+ /**
+ * Name of the script [if this function was defined in a script]
+ */
+ getFileName(): string | null;
+
+ /**
+ * Get the script name or source URL for the source map
+ */
+ getScriptNameOrSourceURL(): string;
+
+ /**
+ * Current line number [if this function was defined in a script]
+ */
+ getLineNumber(): number | null;
+
+ /**
+ * Current column number [if this function was defined in a script]
+ */
+ getColumnNumber(): number | null;
+
+ /**
+ * A call site object representing the location where eval was called
+ * [if this function was created using a call to eval]
+ */
+ getEvalOrigin(): string | undefined;
+
+ /**
+ * Is this a toplevel invocation, that is, is "this" the global object?
+ */
+ isToplevel(): boolean;
+
+ /**
+ * Does this call take place in code defined by a call to eval?
+ */
+ isEval(): boolean;
+
+ /**
+ * Is this call in native V8 code?
+ */
+ isNative(): boolean;
+
+ /**
+ * Is this a constructor call?
+ */
+ isConstructor(): boolean;
+}
+
+declare global {
+ // Declare "static" methods in Error
+ interface ErrorConstructor {
+ /** Create .stack property on a target object */
+ captureStackTrace(targetObject: Object, constructorOpt?: Function): void;
+
+ /**
+ * Optional override for formatting stack traces
+ *
+ * @see https://github.com/v8/v8/wiki/Stack%20Trace%20API#customizing-stack-traces
+ */
+ prepareStackTrace?: (err: Error, stackTraces: CallSite[]) => any;
+
+ stackTraceLimit: number;
+ }
+}
diff --git a/js/types.ts b/js/types.ts
deleted file mode 100644
index ae8ee1e81..000000000
--- a/js/types.ts
+++ /dev/null
@@ -1,9 +0,0 @@
-// Copyright 2018 the Deno authors. All rights reserved. MIT license.
-export type TypedArray = Uint8Array | Float32Array | Int32Array;
-
-export interface ModuleInfo {
- moduleName?: string;
- filename?: string;
- sourceCode?: string;
- outputCode?: string;
-}
diff --git a/js/v8_source_maps.ts b/js/v8_source_maps.ts
index d5feeb1c0..29091486c 100644
--- a/js/v8_source_maps.ts
+++ b/js/v8_source_maps.ts
@@ -2,16 +2,11 @@
// Copyright 2018 the Deno authors. All rights reserved. MIT license.
// Originated from source-map-support but has been heavily modified for deno.
-// Because NodeJS.CallSite and Error.prepareStackTrace are used we add a
-// dependency on the Node types.
-// TODO(ry) Ideally this triple slash directive should be removed as we only
-// need CallSite and Error.prepareStackTrace but nothing else.
-/// <reference types="node" />
-
import { SourceMapConsumer, MappedPosition } from "source-map";
import { RawSourceMap } from "source-map";
import * as base64 from "base64-js";
import { arrayToStr } from "./util";
+import { CallSite } from "./types";
const consumers = new Map<string, SourceMapConsumer>();
@@ -22,10 +17,6 @@ interface Options {
installPrepareStackTrace: boolean;
}
-interface CallSite extends NodeJS.CallSite {
- getScriptNameOrSourceURL(): string;
-}
-
interface Position {
source: string; // Filename
column: number;