BREAKING: Remove Deno.symbols namespace (#4936)

This commit is contained in:
Nayeem Rahman 2020-04-28 00:06:03 +01:00 committed by GitHub
parent 2f0641885c
commit 4041a7b857
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
19 changed files with 31 additions and 58 deletions

View file

@ -12,7 +12,7 @@ export { build, OperatingSystem, Arch } from "./build.ts";
export { chmodSync, chmod } from "./ops/fs/chmod.ts"; export { chmodSync, chmod } from "./ops/fs/chmod.ts";
export { chownSync, chown } from "./ops/fs/chown.ts"; export { chownSync, chown } from "./ops/fs/chown.ts";
export { transpileOnly, compile, bundle } from "./compiler/api.ts"; export { transpileOnly, compile, bundle } from "./compiler/api.ts";
export { inspect } from "./web/console.ts"; export { customInspect, inspect } from "./web/console.ts";
export { copyFileSync, copyFile } from "./ops/fs/copy_file.ts"; export { copyFileSync, copyFile } from "./ops/fs/copy_file.ts";
export { export {
Diagnostic, Diagnostic,
@ -38,6 +38,7 @@ export {
} from "./files.ts"; } from "./files.ts";
export { read, readSync, write, writeSync } from "./ops/io.ts"; export { read, readSync, write, writeSync } from "./ops/io.ts";
export { FsEvent, watchFs } from "./ops/fs_events.ts"; export { FsEvent, watchFs } from "./ops/fs_events.ts";
export { internalSymbol as internal } from "./internals.ts";
export { export {
EOF, EOF,
copy, copy,
@ -123,5 +124,3 @@ export { core } from "./core.ts";
export let pid: number; export let pid: number;
export let noColor: boolean; export let noColor: boolean;
export { symbols } from "./symbols.ts";

View file

@ -1,12 +1,12 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
export const internalSymbol = Symbol("Deno.symbols.internal"); export const internalSymbol = Symbol("Deno.internal");
// The object where all the internal fields for testing will be living. // The object where all the internal fields for testing will be living.
// eslint-disable-next-line @typescript-eslint/no-explicit-any // eslint-disable-next-line @typescript-eslint/no-explicit-any
export const internalObject: { [key: string]: any } = {}; export const internalObject: { [key: string]: any } = {};
// Register a field to internalObject for test access, // Register a field to internalObject for test access,
// through Deno[Deno.symbols.internal][name]. // through Deno[Deno.internal][name].
// eslint-disable-next-line @typescript-eslint/no-explicit-any // eslint-disable-next-line @typescript-eslint/no-explicit-any
export function exposeForTest(name: string, value: any): void { export function exposeForTest(name: string, value: any): void {
Object.defineProperty(internalObject, name, { Object.defineProperty(internalObject, name, {

View file

@ -379,7 +379,7 @@ declare namespace Deno {
*/ */
export function umask(mask?: number): number; export function umask(mask?: number): number;
/** **UNSTABLE**: might move to `Deno.symbols`. */ /** **UNSTABLE**: might be removed in favor of `null` (#3932). */
export const EOF: unique symbol; export const EOF: unique symbol;
export type EOF = typeof EOF; export type EOF = typeof EOF;
@ -2338,7 +2338,7 @@ declare namespace Deno {
* class A { * class A {
* x = 10; * x = 10;
* y = "hello"; * y = "hello";
* [Deno.symbols.customInspect](): string { * [Deno.customInspect](): string {
* return "x=" + this.x + ", y=" + this.y; * return "x=" + this.x + ", y=" + this.y;
* } * }
* } * }
@ -2860,16 +2860,8 @@ declare namespace Deno {
windowChange: () => SignalStream; windowChange: () => SignalStream;
}; };
/** **UNSTABLE**: new API. Maybe move `Deno.EOF` here. /** A symbol which can be used as a key for a custom method which will be
* * called when `Deno.inspect()` is called, or when the object is logged to
* Special Deno related symbols. */ * the console. */
export const symbols: { export const customInspect: unique symbol;
/** Symbol to access exposed internal Deno API */
readonly internal: unique symbol;
/** A symbol which can be used as a key for a custom method which will be
* called when `Deno.inspect()` is called, or when the object is logged to
* the console. */
readonly customInspect: unique symbol;
// TODO(ry) move EOF here?
};
} }

View file

@ -19,20 +19,19 @@ import {
eventTargetProperties, eventTargetProperties,
setEventTargetData, setEventTargetData,
} from "./globals.ts"; } from "./globals.ts";
import { internalObject } from "./internals.ts"; import { internalObject, internalSymbol } from "./internals.ts";
import { setSignals } from "./signals.ts"; import { setSignals } from "./signals.ts";
import { replLoop } from "./repl.ts"; import { replLoop } from "./repl.ts";
import { LocationImpl } from "./web/location.ts"; import { LocationImpl } from "./web/location.ts";
import { setTimeout } from "./web/timers.ts"; import { setTimeout } from "./web/timers.ts";
import * as runtime from "./runtime.ts"; import * as runtime from "./runtime.ts";
import { symbols } from "./symbols.ts";
import { log, immutableDefine } from "./util.ts"; import { log, immutableDefine } from "./util.ts";
// TODO: factor out `Deno` global assignment to separate function // TODO: factor out `Deno` global assignment to separate function
// Add internal object to Deno object. // Add internal object to Deno object.
// This is not exposed as part of the Deno types. // This is not exposed as part of the Deno types.
// @ts-ignore // @ts-ignore
Deno[symbols.internal] = internalObject; Deno[internalSymbol] = internalObject;
let windowIsClosing = false; let windowIsClosing = false;

View file

@ -24,8 +24,7 @@ import { log, assert, immutableDefine } from "./util.ts";
import { MessageEvent, ErrorEvent } from "./web/workers.ts"; import { MessageEvent, ErrorEvent } from "./web/workers.ts";
import { TextEncoder } from "./web/text_encoding.ts"; import { TextEncoder } from "./web/text_encoding.ts";
import * as runtime from "./runtime.ts"; import * as runtime from "./runtime.ts";
import { internalObject } from "./internals.ts"; import { internalObject, internalSymbol } from "./internals.ts";
import { symbols } from "./symbols.ts";
import { setSignals } from "./signals.ts"; import { setSignals } from "./signals.ts";
// FIXME(bartlomieju): duplicated in `runtime_main.ts` // FIXME(bartlomieju): duplicated in `runtime_main.ts`
@ -33,7 +32,7 @@ import { setSignals } from "./signals.ts";
// Add internal object to Deno object. // Add internal object to Deno object.
// This is not exposed as part of the Deno types. // This is not exposed as part of the Deno types.
// @ts-ignore // @ts-ignore
Deno[symbols.internal] = internalObject; Deno[internalSymbol] = internalObject;
const encoder = new TextEncoder(); const encoder = new TextEncoder();

View file

@ -1,8 +0,0 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { internalSymbol } from "./internals.ts";
import { customInspect } from "./web/console.ts";
export const symbols = {
internal: internalSymbol,
customInspect,
};

View file

@ -8,12 +8,12 @@ const {
// eslint-disable-next-line @typescript-eslint/no-explicit-any // eslint-disable-next-line @typescript-eslint/no-explicit-any
} = Deno as any; } = Deno as any;
const customInspect = Deno.symbols.customInspect; const customInspect = Deno.customInspect;
const { const {
Console, Console,
stringifyArgs, stringifyArgs,
// @ts-ignore TypeScript (as of 3.7) does not support indexing namespaces by symbol // @ts-ignore TypeScript (as of 3.7) does not support indexing namespaces by symbol
} = Deno[Deno.symbols.internal]; } = Deno[Deno.internal];
function stringify(...args: unknown[]): string { function stringify(...args: unknown[]): string {
return stringifyArgs(args).replace(/\n$/, ""); return stringifyArgs(args).replace(/\n$/, "");

View file

@ -21,7 +21,7 @@ function setup() {
// This is using an internal API we don't want published as types, so having // This is using an internal API we don't want published as types, so having
// to cast to any to "trick" TypeScript // to cast to any to "trick" TypeScript
// @ts-ignore TypeScript (as of 3.7) does not support indexing namespaces by symbol // @ts-ignore TypeScript (as of 3.7) does not support indexing namespaces by symbol
DomIterable: Deno[Deno.symbols.internal].DomIterableMixin(Base, dataSymbol), DomIterable: Deno[Deno.internal].DomIterableMixin(Base, dataSymbol),
}; };
} }

View file

@ -2,7 +2,7 @@
import { unitTest, assert } from "./test_util.ts"; import { unitTest, assert } from "./test_util.ts";
// @ts-ignore TypeScript (as of 3.7) does not support indexing namespaces by symbol // @ts-ignore TypeScript (as of 3.7) does not support indexing namespaces by symbol
const { setPrepareStackTrace } = Deno[Deno.symbols.internal]; const { setPrepareStackTrace } = Deno[Deno.internal];
interface CallSite { interface CallSite {
getThis(): unknown; getThis(): unknown;

View file

@ -8,7 +8,7 @@ import {
const { const {
stringifyArgs, stringifyArgs,
// @ts-ignore TypeScript (as of 3.7) does not support indexing namespaces by symbol // @ts-ignore TypeScript (as of 3.7) does not support indexing namespaces by symbol
} = Deno[Deno.symbols.internal]; } = Deno[Deno.internal];
// Logic heavily copied from web-platform-tests, make // Logic heavily copied from web-platform-tests, make
// sure pass mostly header basic test // sure pass mostly header basic test

View file

@ -5,6 +5,6 @@ unitTest(function internalsExists(): void {
const { const {
stringifyArgs, stringifyArgs,
// @ts-ignore TypeScript (as of 3.7) does not support indexing namespaces by symbol // @ts-ignore TypeScript (as of 3.7) does not support indexing namespaces by symbol
} = Deno[Deno.symbols.internal]; } = Deno[Deno.internal];
assert(!!stringifyArgs); assert(!!stringifyArgs);
}); });

View file

@ -1,7 +0,0 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { unitTest, assert } from "./test_util.ts";
unitTest(function symbolsExists(): void {
assert("internal" in Deno.symbols);
assert("customInspect" in Deno.symbols);
});

View file

@ -11,8 +11,8 @@ import {
reportToConn, reportToConn,
} from "./test_util.ts"; } from "./test_util.ts";
// eslint-disable-next-line @typescript-eslint/no-explicit-any // @ts-ignore
const internalObj = (Deno as any)[Deno.symbols.internal]; const internalObj = Deno[Deno.internal];
// eslint-disable-next-line @typescript-eslint/no-explicit-any // eslint-disable-next-line @typescript-eslint/no-explicit-any
const reportToConsole = internalObj.reportToConsole as (message: any) => void; const reportToConsole = internalObj.reportToConsole as (message: any) => void;
// eslint-disable-next-line @typescript-eslint/no-explicit-any // eslint-disable-next-line @typescript-eslint/no-explicit-any

View file

@ -52,7 +52,6 @@ import "./request_test.ts";
import "./resources_test.ts"; import "./resources_test.ts";
import "./signal_test.ts"; import "./signal_test.ts";
import "./stat_test.ts"; import "./stat_test.ts";
import "./symbols_test.ts";
import "./symlink_test.ts"; import "./symlink_test.ts";
import "./text_encoding_test.ts"; import "./text_encoding_test.ts";
import "./testing_test.ts"; import "./testing_test.ts";

View file

@ -22,7 +22,7 @@ import {
import { ReadableStreamImpl } from "./readable_stream.ts"; import { ReadableStreamImpl } from "./readable_stream.ts";
import * as sym from "./symbols.ts"; import * as sym from "./symbols.ts";
import { assert } from "../../util.ts"; import { assert } from "../../util.ts";
import { symbols } from "../../symbols.ts"; import { customInspect } from "../../web/console.ts";
export class ReadableByteStreamControllerImpl export class ReadableByteStreamControllerImpl
implements ReadableByteStreamController { implements ReadableByteStreamController {
@ -135,7 +135,7 @@ export class ReadableByteStreamControllerImpl
return promise; return promise;
} }
[symbols.customInspect](): string { [customInspect](): string {
return `ReadableByteStreamController { byobRequest: ${String( return `ReadableByteStreamController { byobRequest: ${String(
this.byobRequest this.byobRequest
)}, desiredSize: ${String(this.desiredSize)} }`; )}, desiredSize: ${String(this.desiredSize)} }`;

View file

@ -18,8 +18,8 @@ import { ReadableByteStreamControllerImpl } from "./readable_byte_stream_control
import { ReadableStreamAsyncIteratorPrototype } from "./readable_stream_async_iterator.ts"; import { ReadableStreamAsyncIteratorPrototype } from "./readable_stream_async_iterator.ts";
import { ReadableStreamDefaultControllerImpl } from "./readable_stream_default_controller.ts"; import { ReadableStreamDefaultControllerImpl } from "./readable_stream_default_controller.ts";
import * as sym from "./symbols.ts"; import * as sym from "./symbols.ts";
import { symbols } from "../../symbols.ts";
import { notImplemented } from "../../util.ts"; import { notImplemented } from "../../util.ts";
import { customInspect } from "../../web/console.ts";
// eslint-disable-next-line @typescript-eslint/no-explicit-any // eslint-disable-next-line @typescript-eslint/no-explicit-any
export class ReadableStreamImpl<R = any> implements ReadableStream<R> { export class ReadableStreamImpl<R = any> implements ReadableStream<R> {
@ -202,7 +202,7 @@ export class ReadableStreamImpl<R = any> implements ReadableStream<R> {
return readableStreamTee(this, false); return readableStreamTee(this, false);
} }
[symbols.customInspect](): string { [customInspect](): string {
return `ReadableStream { locked: ${String(this.locked)} }`; return `ReadableStream { locked: ${String(this.locked)} }`;
} }

View file

@ -21,7 +21,7 @@ import {
} from "./internals.ts"; } from "./internals.ts";
import { ReadableStreamImpl } from "./readable_stream.ts"; import { ReadableStreamImpl } from "./readable_stream.ts";
import * as sym from "./symbols.ts"; import * as sym from "./symbols.ts";
import { symbols } from "../../symbols.ts"; import { customInspect } from "../../web/console.ts";
// eslint-disable-next-line @typescript-eslint/no-explicit-any // eslint-disable-next-line @typescript-eslint/no-explicit-any
export class ReadableStreamDefaultControllerImpl<R = any> export class ReadableStreamDefaultControllerImpl<R = any>
@ -112,7 +112,7 @@ export class ReadableStreamDefaultControllerImpl<R = any>
return pendingPromise; return pendingPromise;
} }
[symbols.customInspect](): string { [customInspect](): string {
return `ReadableStreamDefaultController { desiredSize: ${String( return `ReadableStreamDefaultController { desiredSize: ${String(
this.desiredSize this.desiredSize
)} }`; )} }`;

View file

@ -12,7 +12,7 @@ import {
} from "./internals.ts"; } from "./internals.ts";
import { ReadableStreamImpl } from "./readable_stream.ts"; import { ReadableStreamImpl } from "./readable_stream.ts";
import * as sym from "./symbols.ts"; import * as sym from "./symbols.ts";
import { symbols } from "../../symbols.ts"; import { customInspect } from "../../web/console.ts";
// eslint-disable-next-line @typescript-eslint/no-explicit-any // eslint-disable-next-line @typescript-eslint/no-explicit-any
export class ReadableStreamDefaultReaderImpl<R = any> export class ReadableStreamDefaultReaderImpl<R = any>
@ -83,7 +83,7 @@ export class ReadableStreamDefaultReaderImpl<R = any>
readableStreamReaderGenericRelease(this); readableStreamReaderGenericRelease(this);
} }
[symbols.customInspect](): string { [customInspect](): string {
return `ReadableStreamDefaultReader { closed: Promise }`; return `ReadableStreamDefaultReader { closed: Promise }`;
} }
} }

View file

@ -79,7 +79,7 @@ pub fn render_test_file(
}; };
let run_tests_cmd = format!( let run_tests_cmd = format!(
"(Deno as any)[Deno.symbols.internal].runTests({});\n", "// @ts-ignore\nDeno[Deno.internal].runTests({});\n",
options options
); );
test_file.push_str(&run_tests_cmd); test_file.push_str(&run_tests_cmd);