Mark APIs at internal and include JSDoc in types

This commit is contained in:
Kitson Kelly 2018-09-04 12:23:38 -07:00 committed by Ryan Dahl
parent 2c0d00840d
commit 10dc71133a
10 changed files with 55 additions and 25 deletions

View file

@ -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"; import typescriptDts from "/third_party/node_modules/typescript/lib/typescript.d.ts!string";
// tslint:enable:max-line-length // tslint:enable:max-line-length
// prettier-ignore // @internal
export const assetSourceCode: { [key: string]: string } = { export const assetSourceCode: { [key: string]: string } = {
// Generated library // Generated library
"globals.d.ts": globalsDts, "globals.d.ts": globalsDts,
@ -85,5 +85,5 @@ export const assetSourceCode: { [key: string]: string } = {
"fetch-types.d.ts": fetchTypesDts, "fetch-types.d.ts": fetchTypesDts,
"flatbuffers.d.ts": flatbuffersDts, "flatbuffers.d.ts": flatbuffersDts,
"text-encoding.d.ts": textEncodingDts, "text-encoding.d.ts": textEncodingDts,
"typescript.d.ts": typescriptDts, "typescript.d.ts": typescriptDts
}; };

View file

@ -50,6 +50,7 @@ type OutputCode = string;
/** /**
* Abstraction of the APIs required from the `os` module so they can be * Abstraction of the APIs required from the `os` module so they can be
* easily mocked. * easily mocked.
* @internal
*/ */
export interface Os { export interface Os {
codeCache: typeof os.codeCache; codeCache: typeof os.codeCache;
@ -60,6 +61,7 @@ export interface Os {
/** /**
* Abstraction of the APIs required from the `typescript` module so they can * Abstraction of the APIs required from the `typescript` module so they can
* be easily mocked. * be easily mocked.
* @internal
*/ */
export interface Ts { export interface Ts {
createLanguageService: typeof ts.createLanguageService; createLanguageService: typeof ts.createLanguageService;

View file

@ -177,7 +177,7 @@ function globalEvalMock(x: string): void {
function logMock(...args: any[]): void { function logMock(...args: any[]): void {
logStack.push(args); logStack.push(args);
} }
const osMock: compiler.Os = { const osMock = {
codeCache(fileName: string, sourceCode: string, outputCode: string): void { codeCache(fileName: string, sourceCode: string, outputCode: string): void {
codeCacheStack.push({ fileName, sourceCode, outputCode }); codeCacheStack.push({ fileName, sourceCode, outputCode });
if (fileName in moduleCache) { if (fileName in moduleCache) {
@ -205,7 +205,7 @@ const osMock: compiler.Os = {
throw new Error(`os.exit(${code})`); throw new Error(`os.exit(${code})`);
} }
}; };
const tsMock: compiler.Ts = { const tsMock = {
createLanguageService(host: ts.LanguageServiceHost): ts.LanguageService { createLanguageService(host: ts.LanguageServiceHost): ts.LanguageService {
return {} as ts.LanguageService; return {} as ts.LanguageService;
}, },

View file

@ -1,5 +1,6 @@
import { deno as fbs } from "gen/msg_generated"; import { deno as fbs } from "gen/msg_generated";
// @internal
export class DenoError<T extends fbs.ErrorKind> extends Error { export class DenoError<T extends fbs.ErrorKind> extends Error {
constructor(readonly kind: T, msg: string) { constructor(readonly kind: T, msg: string) {
super(msg); super(msg);
@ -7,6 +8,7 @@ export class DenoError<T extends fbs.ErrorKind> extends Error {
} }
} }
// @internal
export function maybeThrowError(base: fbs.Base): void { export function maybeThrowError(base: fbs.Base): void {
const kind = base.errorKind(); const kind = base.errorKind();
if (kind !== fbs.ErrorKind.NoError) { if (kind !== fbs.ErrorKind.NoError) {

View file

@ -4,6 +4,7 @@ import { flatbuffers } from "flatbuffers";
import { maybeThrowError } from "./errors"; import { maybeThrowError } from "./errors";
import { deno as fbs } from "gen/msg_generated"; import { deno as fbs } from "gen/msg_generated";
// @internal
export function send( export function send(
builder: flatbuffers.Builder, builder: flatbuffers.Builder,
msgType: fbs.Any, msgType: fbs.Any,

View file

@ -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 * If you use the eval function indirectly, by invoking it via a reference
// the local scope. This means, for instance, that function declarations create * other than eval, as of ECMAScript 5 it works in the global scope rather than
// global functions, and that the code being evaluated doesn't have access to * the local scope. This means, for instance, that function declarations create
// local variables within the scope where it's being called. * 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; export const globalEval = eval;

View file

@ -8,6 +8,7 @@
"declaration": true, "declaration": true,
"emitDeclarationOnly": true, "emitDeclarationOnly": true,
"module": "amd", "module": "amd",
"removeComments": false,
"stripInternal": true "stripInternal": true
}, },
"files": [ "files": [

View file

@ -3,11 +3,15 @@ import { TypedArray } from "./types";
let logDebug = false; let logDebug = false;
// @internal
export function setLogDebug(debug: boolean): void { export function setLogDebug(debug: boolean): void {
logDebug = debug; 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 // tslint:disable-next-line:no-any
export function log(...args: any[]): void { export function log(...args: any[]): void {
if (logDebug) { if (logDebug) {
@ -15,41 +19,51 @@ export function log(...args: any[]): void {
} }
} }
// @internal
export function assert(cond: boolean, msg = "assert") { export function assert(cond: boolean, msg = "assert") {
if (!cond) { if (!cond) {
throw Error(msg); throw Error(msg);
} }
} }
// @internal
export function typedArrayToArrayBuffer(ta: TypedArray): ArrayBuffer { export function typedArrayToArrayBuffer(ta: TypedArray): ArrayBuffer {
const ab = ta.buffer.slice(ta.byteOffset, ta.byteOffset + ta.byteLength); const ab = ta.buffer.slice(ta.byteOffset, ta.byteOffset + ta.byteLength);
return ab as ArrayBuffer; return ab as ArrayBuffer;
} }
// @internal
export function arrayToStr(ui8: Uint8Array): string { export function arrayToStr(ui8: Uint8Array): string {
return String.fromCharCode(...ui8); 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: * 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<number>(); *
// ... * const p = createResolvable<number>();
// p.resolve(42); * ...
// * 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 * It'd be prettier to make Resolvable a class that inherits from Promise,
// produces broken code when targeting ES5 code. * rather than an interface. This is possible in ES2016, however typescript
// See https://github.com/Microsoft/TypeScript/issues/15202 * produces broken code when targeting ES5 code.
// At the time of writing, the github issue is closed but the problem remains. * 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<T> { export interface ResolvableMethods<T> {
resolve: (value?: T | PromiseLike<T>) => void; resolve: (value?: T | PromiseLike<T>) => void;
// tslint:disable-next-line:no-any // tslint:disable-next-line:no-any
reject: (reason?: any) => void; reject: (reason?: any) => void;
} }
// @internal
export type Resolvable<T> = Promise<T> & ResolvableMethods<T>; export type Resolvable<T> = Promise<T> & ResolvableMethods<T>;
// @internal
export function createResolvable<T>(): Resolvable<T> { export function createResolvable<T>(): Resolvable<T> {
let methods: ResolvableMethods<T>; let methods: ResolvableMethods<T>;
const promise = new Promise<T>((resolve, reject) => { const promise = new Promise<T>((resolve, reject) => {
@ -60,10 +74,12 @@ export function createResolvable<T>(): Resolvable<T> {
return Object.assign(promise, methods!) as Resolvable<T>; return Object.assign(promise, methods!) as Resolvable<T>;
} }
// @internal
export function notImplemented(): never { export function notImplemented(): never {
throw new Error("Not implemented"); throw new Error("Not implemented");
} }
// @internal
export function unreachable(): never { export function unreachable(): never {
throw new Error("Code not reachable"); throw new Error("Code not reachable");
} }

View file

@ -26,6 +26,7 @@ type GetGeneratedContentsCallback = (fileName: string) => string | RawSourceMap;
let getGeneratedContents: GetGeneratedContentsCallback; let getGeneratedContents: GetGeneratedContentsCallback;
// @internal
export function install(options: Options) { export function install(options: Options) {
getGeneratedContents = options.getGeneratedContents; getGeneratedContents = options.getGeneratedContents;
if (options.installPrepareStackTrace) { if (options.installPrepareStackTrace) {
@ -33,6 +34,7 @@ export function install(options: Options) {
} }
} }
// @internal
export function prepareStackTraceWrapper( export function prepareStackTraceWrapper(
error: Error, error: Error,
stack: CallSite[] stack: CallSite[]
@ -48,6 +50,7 @@ export function prepareStackTraceWrapper(
} }
} }
// @internal
export function prepareStackTrace(error: Error, stack: CallSite[]): string { export function prepareStackTrace(error: Error, stack: CallSite[]): string {
const frames = stack.map( const frames = stack.map(
(frame: CallSite) => `\n at ${wrapCallSite(frame).toString()}` (frame: CallSite) => `\n at ${wrapCallSite(frame).toString()}`
@ -55,6 +58,7 @@ export function prepareStackTrace(error: Error, stack: CallSite[]): string {
return error.toString() + frames.join(""); return error.toString() + frames.join("");
} }
// @internal
export function wrapCallSite(frame: CallSite): CallSite { export function wrapCallSite(frame: CallSite): CallSite {
if (frame.isNative()) { if (frame.isNative()) {
return frame; return frame;

View file

@ -4,7 +4,7 @@
  ~~~~~~   ~~~~~~
$asset$/globals.d.tsILDCARD] $asset$/globals.d.tsILDCARD]
[WILDCARD][0m const console: Console; [WILDCARD]const console: Console;
   ~~~~~~~ [WILDCARD]~~~~~~~
'console' is declared here. [WILDCARD]'console' is declared here.