diff --git a/js/assets.ts b/js/assets.ts index 8ea8f960159738e2abce89f36e993ce81c064a79..c97dce6496196688f4e50286fbe1a8710e3407cc 100644 --- a/js/assets.ts +++ b/js/assets.ts @@ -46,7 +46,7 @@ import textEncodingDts from "/third_party/node_modules/@types/text-encoding/inde import typescriptDts from "/third_party/node_modules/typescript/lib/typescript.d.ts!string"; // tslint:enable:max-line-length -// prettier-ignore +// @internal export const assetSourceCode: { [key: string]: string } = { // Generated library "globals.d.ts": globalsDts, @@ -85,5 +85,5 @@ export const assetSourceCode: { [key: string]: string } = { "fetch-types.d.ts": fetchTypesDts, "flatbuffers.d.ts": flatbuffersDts, "text-encoding.d.ts": textEncodingDts, - "typescript.d.ts": typescriptDts, + "typescript.d.ts": typescriptDts }; diff --git a/js/compiler.ts b/js/compiler.ts index fc3dc0b178f0a5468bba7b21efa21bcabe54ba69..eaf64ce879e03241a83ea5c2eb48e1ee8803108c 100644 --- a/js/compiler.ts +++ b/js/compiler.ts @@ -50,6 +50,7 @@ type OutputCode = string; /** * Abstraction of the APIs required from the `os` module so they can be * easily mocked. + * @internal */ export interface Os { codeCache: typeof os.codeCache; @@ -60,6 +61,7 @@ export interface Os { /** * Abstraction of the APIs required from the `typescript` module so they can * be easily mocked. + * @internal */ export interface Ts { createLanguageService: typeof ts.createLanguageService; diff --git a/js/compiler_test.ts b/js/compiler_test.ts index 61eff33d1547b7ea1eb0e8946c7d897f6c6dc8eb..d27818c9cc24111f9dc7bb868b7f4d1af18da1e2 100644 --- a/js/compiler_test.ts +++ b/js/compiler_test.ts @@ -177,7 +177,7 @@ function globalEvalMock(x: string): void { function logMock(...args: any[]): void { logStack.push(args); } -const osMock: compiler.Os = { +const osMock = { codeCache(fileName: string, sourceCode: string, outputCode: string): void { codeCacheStack.push({ fileName, sourceCode, outputCode }); if (fileName in moduleCache) { @@ -205,7 +205,7 @@ const osMock: compiler.Os = { throw new Error(`os.exit(${code})`); } }; -const tsMock: compiler.Ts = { +const tsMock = { createLanguageService(host: ts.LanguageServiceHost): ts.LanguageService { return {} as ts.LanguageService; }, diff --git a/js/errors.ts b/js/errors.ts index 2fca10eaf95d88b2cb22c9d65d52d3696cea84dd..11d4cd509ab667f435d5d9953953f5578804ef43 100644 --- a/js/errors.ts +++ b/js/errors.ts @@ -1,5 +1,6 @@ import { deno as fbs } from "gen/msg_generated"; +// @internal export class DenoError extends Error { constructor(readonly kind: T, msg: string) { super(msg); @@ -7,6 +8,7 @@ export class DenoError extends Error { } } +// @internal export function maybeThrowError(base: fbs.Base): void { const kind = base.errorKind(); if (kind !== fbs.ErrorKind.NoError) { diff --git a/js/fbs_util.ts b/js/fbs_util.ts index fd953ac884294e14c18ca073f230740fe24755cc..bb623d54d1faffcedd96b5a5966a19009234add2 100644 --- a/js/fbs_util.ts +++ b/js/fbs_util.ts @@ -4,6 +4,7 @@ import { flatbuffers } from "flatbuffers"; import { maybeThrowError } from "./errors"; import { deno as fbs } from "gen/msg_generated"; +// @internal export function send( builder: flatbuffers.Builder, msgType: fbs.Any, diff --git a/js/global-eval.ts b/js/global-eval.ts index ee37e6f2497f52a31961fb2c6517dfbd088f20c1..1f77c495252dcb3465a49dc0025ce6eed1446713 100644 --- a/js/global-eval.ts +++ b/js/global-eval.ts @@ -1,6 +1,10 @@ -// 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 -// global functions, and that the code being evaluated doesn't have access to -// local variables within the scope where it's being called. +/** + * 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 + * global functions, and that the code being evaluated doesn't have access to + * local variables within the scope where it's being called. + * + * @internal + */ export const globalEval = eval; diff --git a/js/tsconfig.generated.json b/js/tsconfig.generated.json index 8a8269d5b3c3e22a1a44ef75be22ebb4806ab464..c4aec8ee054e56520f371afeba3e948cc6aca60a 100644 --- a/js/tsconfig.generated.json +++ b/js/tsconfig.generated.json @@ -8,6 +8,7 @@ "declaration": true, "emitDeclarationOnly": true, "module": "amd", + "removeComments": false, "stripInternal": true }, "files": [ diff --git a/js/util.ts b/js/util.ts index 959bc6abdb5e351f2a4a3c422dd40f45a3b2d003..6971ca1b9015df9a9bcaa41feffec12ab13818d4 100644 --- a/js/util.ts +++ b/js/util.ts @@ -3,11 +3,15 @@ import { TypedArray } from "./types"; let logDebug = false; +// @internal export function setLogDebug(debug: boolean): void { logDebug = debug; } -// Debug logging for deno. Enable with the --DEBUG command line flag. +/** + * Debug logging for deno. Enable with the `--DEBUG` command line flag. + * @internal + */ // tslint:disable-next-line:no-any export function log(...args: any[]): void { if (logDebug) { @@ -15,41 +19,51 @@ export function log(...args: any[]): void { } } +// @internal export function assert(cond: boolean, msg = "assert") { if (!cond) { throw Error(msg); } } +// @internal export function typedArrayToArrayBuffer(ta: TypedArray): ArrayBuffer { const ab = ta.buffer.slice(ta.byteOffset, ta.byteOffset + ta.byteLength); return ab as ArrayBuffer; } +// @internal export function arrayToStr(ui8: Uint8Array): string { return String.fromCharCode(...ui8); } -// A `Resolvable` is a Promise with the `reject` and `resolve` functions -// placed as methods on the promise object itself. It allows you to do: -// -// const p = createResolvable(); -// ... -// p.resolve(42); -// -// It'd be prettier to make Resolvable a class that inherits from Promise, -// rather than an interface. This is possible in ES2016, however typescript -// produces broken code when targeting ES5 code. -// See https://github.com/Microsoft/TypeScript/issues/15202 -// At the time of writing, the github issue is closed but the problem remains. +/** + * A `Resolvable` is a Promise with the `reject` and `resolve` functions + * placed as methods on the promise object itself. It allows you to do: + * + * const p = createResolvable(); + * ... + * p.resolve(42); + * + * It'd be prettier to make Resolvable a class that inherits from Promise, + * rather than an interface. This is possible in ES2016, however typescript + * produces broken code when targeting ES5 code. + * See https://github.com/Microsoft/TypeScript/issues/15202 + * At the time of writing, the github issue is closed but the problem remains. + * + * @internal + */ + export interface ResolvableMethods { resolve: (value?: T | PromiseLike) => void; // tslint:disable-next-line:no-any reject: (reason?: any) => void; } +// @internal export type Resolvable = Promise & ResolvableMethods; +// @internal export function createResolvable(): Resolvable { let methods: ResolvableMethods; const promise = new Promise((resolve, reject) => { @@ -60,10 +74,12 @@ export function createResolvable(): Resolvable { return Object.assign(promise, methods!) as Resolvable; } +// @internal export function notImplemented(): never { throw new Error("Not implemented"); } +// @internal export function unreachable(): never { throw new Error("Code not reachable"); } diff --git a/js/v8_source_maps.ts b/js/v8_source_maps.ts index 94c437f6deb44247b9bd597216affc3ac57def9b..1852a89822c2adc81b2fe49d601f07e7649256f5 100644 --- a/js/v8_source_maps.ts +++ b/js/v8_source_maps.ts @@ -26,6 +26,7 @@ type GetGeneratedContentsCallback = (fileName: string) => string | RawSourceMap; let getGeneratedContents: GetGeneratedContentsCallback; +// @internal export function install(options: Options) { getGeneratedContents = options.getGeneratedContents; if (options.installPrepareStackTrace) { @@ -33,6 +34,7 @@ export function install(options: Options) { } } +// @internal export function prepareStackTraceWrapper( error: Error, stack: CallSite[] @@ -48,6 +50,7 @@ export function prepareStackTraceWrapper( } } +// @internal export function prepareStackTrace(error: Error, stack: CallSite[]): string { const frames = stack.map( (frame: CallSite) => `\n at ${wrapCallSite(frame).toString()}` @@ -55,6 +58,7 @@ export function prepareStackTrace(error: Error, stack: CallSite[]): string { return error.toString() + frames.join(""); } +// @internal export function wrapCallSite(frame: CallSite): CallSite { if (frame.isNative()) { return frame; diff --git a/tests/error_003_typescript.ts.out b/tests/error_003_typescript.ts.out index 277d4e9291b2eab95624c0650181b9a2bc610848..1423ae1d42ea4fe234cf3faf0d7c108a1ff5ac0a 100644 --- a/tests/error_003_typescript.ts.out +++ b/tests/error_003_typescript.ts.out @@ -4,7 +4,7 @@   ~~~~~~ $asset$/globals.d.tsILDCARD] - [WILDCARD][0m const console: Console; -    ~~~~~~~ - 'console' is declared here. +[WILDCARD]const console: Console; +[WILDCARD]~~~~~~~ +[WILDCARD]'console' is declared here.