mirror of
https://github.com/denoland/deno.git
synced 2024-11-28 16:20:57 -05:00
Prevent circular imports in ts code (#576)
This commit is contained in:
parent
3bcf7e271f
commit
84c38f34ee
12 changed files with 42 additions and 26 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -6,6 +6,7 @@ Cargo.lock
|
||||||
yarn.lock
|
yarn.lock
|
||||||
# npm deps
|
# npm deps
|
||||||
node_modules
|
node_modules
|
||||||
|
.idea
|
||||||
|
|
||||||
# RLS generated files
|
# RLS generated files
|
||||||
/target/
|
/target/
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
import compilerDts from "gen/js/compiler.d.ts!string";
|
import compilerDts from "gen/js/compiler.d.ts!string";
|
||||||
import consoleDts from "gen/js/console.d.ts!string";
|
import consoleDts from "gen/js/console.d.ts!string";
|
||||||
import denoDts from "gen/js/deno.d.ts!string";
|
import denoDts from "gen/js/deno.d.ts!string";
|
||||||
|
import libdenoDts from "gen/js/libdeno.d.ts!string";
|
||||||
import globalsDts from "gen/js/globals.d.ts!string";
|
import globalsDts from "gen/js/globals.d.ts!string";
|
||||||
import osDts from "gen/js/os.d.ts!string";
|
import osDts from "gen/js/os.d.ts!string";
|
||||||
import fetchDts from "gen/js/fetch.d.ts!string";
|
import fetchDts from "gen/js/fetch.d.ts!string";
|
||||||
|
@ -59,6 +60,7 @@ export const assetSourceCode: { [key: string]: string } = {
|
||||||
"compiler.d.ts": compilerDts,
|
"compiler.d.ts": compilerDts,
|
||||||
"console.d.ts": consoleDts,
|
"console.d.ts": consoleDts,
|
||||||
"deno.d.ts": denoDts,
|
"deno.d.ts": denoDts,
|
||||||
|
"libdeno.d.ts": libdenoDts,
|
||||||
"globals.d.ts": globalsDts,
|
"globals.d.ts": globalsDts,
|
||||||
"os.d.ts": osDts,
|
"os.d.ts": osDts,
|
||||||
"fetch.d.ts": fetchDts,
|
"fetch.d.ts": fetchDts,
|
||||||
|
|
|
@ -2,7 +2,9 @@
|
||||||
import * as ts from "typescript";
|
import * as ts from "typescript";
|
||||||
import { assetSourceCode } from "./assets";
|
import { assetSourceCode } from "./assets";
|
||||||
import * as deno from "./deno";
|
import * as deno from "./deno";
|
||||||
import { libdeno, window, globalEval } from "./globals";
|
import { globalEval } from "./global-eval";
|
||||||
|
import { libdeno } from "./libdeno";
|
||||||
|
import { window } from "./globals";
|
||||||
import * as os from "./os";
|
import * as os from "./os";
|
||||||
import { RawSourceMap } from "./types";
|
import { RawSourceMap } from "./types";
|
||||||
import { assert, log, notImplemented } from "./util";
|
import { assert, log, notImplemented } from "./util";
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
// Copyright 2018 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018 the Deno authors. All rights reserved. MIT license.
|
||||||
// Public deno module.
|
// Public deno module.
|
||||||
export { exit, readFileSync, writeFileSync } from "./os";
|
export { exit, readFileSync, writeFileSync } from "./os";
|
||||||
export { libdeno } from "./globals";
|
export { libdeno } from "./libdeno";
|
||||||
|
|
|
@ -8,7 +8,7 @@ import {
|
||||||
notImplemented
|
notImplemented
|
||||||
} from "./util";
|
} from "./util";
|
||||||
import { flatbuffers } from "flatbuffers";
|
import { flatbuffers } from "flatbuffers";
|
||||||
import { libdeno } from "./globals";
|
import { libdeno } from "./libdeno";
|
||||||
import { deno as fbs } from "gen/msg_generated";
|
import { deno as fbs } from "gen/msg_generated";
|
||||||
import {
|
import {
|
||||||
Headers,
|
Headers,
|
||||||
|
|
6
js/global-eval.ts
Normal file
6
js/global-eval.ts
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
// 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.
|
||||||
|
export const globalEval = eval;
|
|
@ -2,10 +2,11 @@
|
||||||
|
|
||||||
import { Console } from "./console";
|
import { Console } from "./console";
|
||||||
import { exit } from "./os";
|
import { exit } from "./os";
|
||||||
import { RawSourceMap } from "./types";
|
|
||||||
import * as timers from "./timers";
|
import * as timers from "./timers";
|
||||||
import { TextEncoder, TextDecoder } from "./text_encoding";
|
import { TextDecoder, TextEncoder } from "./text_encoding";
|
||||||
import * as fetch_ from "./fetch";
|
import * as fetch_ from "./fetch";
|
||||||
|
import { libdeno } from "./libdeno";
|
||||||
|
import { globalEval } from "./global-eval";
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
interface Window {
|
interface Window {
|
||||||
|
@ -36,27 +37,10 @@ declare global {
|
||||||
// tslint:enable:variable-name
|
// tslint:enable:variable-name
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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.
|
|
||||||
export const globalEval = eval;
|
|
||||||
|
|
||||||
// A reference to the global object.
|
// A reference to the global object.
|
||||||
export const window = globalEval("this");
|
export const window = globalEval("this");
|
||||||
window.window = window;
|
window.window = window;
|
||||||
|
|
||||||
// The libdeno functions are moved so that users can't access them.
|
|
||||||
type MessageCallback = (msg: Uint8Array) => void;
|
|
||||||
interface Libdeno {
|
|
||||||
recv(cb: MessageCallback): void;
|
|
||||||
send(msg: ArrayBufferView): null | Uint8Array;
|
|
||||||
print(x: string): void;
|
|
||||||
mainSource: string;
|
|
||||||
mainSourceMap: RawSourceMap;
|
|
||||||
}
|
|
||||||
export const libdeno = window.libdeno as Libdeno;
|
|
||||||
window.libdeno = null;
|
window.libdeno = null;
|
||||||
|
|
||||||
// import "./url";
|
// import "./url";
|
||||||
|
|
18
js/libdeno.ts
Normal file
18
js/libdeno.ts
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
import { RawSourceMap } from "./types";
|
||||||
|
import { globalEval } from "./global-eval";
|
||||||
|
|
||||||
|
// The libdeno functions are moved so that users can't access them.
|
||||||
|
type MessageCallback = (msg: Uint8Array) => void;
|
||||||
|
interface Libdeno {
|
||||||
|
recv(cb: MessageCallback): void;
|
||||||
|
|
||||||
|
send(msg: ArrayBufferView): null | Uint8Array;
|
||||||
|
|
||||||
|
print(x: string): void;
|
||||||
|
|
||||||
|
mainSource: string;
|
||||||
|
mainSourceMap: RawSourceMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
const window = globalEval("this");
|
||||||
|
export const libdeno = window.libdeno as Libdeno;
|
|
@ -4,7 +4,7 @@ import { deno as fbs } from "gen/msg_generated";
|
||||||
import { assert, assignCmdId, log, setLogDebug } from "./util";
|
import { assert, assignCmdId, log, setLogDebug } from "./util";
|
||||||
import * as os from "./os";
|
import * as os from "./os";
|
||||||
import { DenoCompiler } from "./compiler";
|
import { DenoCompiler } from "./compiler";
|
||||||
import { libdeno } from "./globals";
|
import { libdeno } from "./libdeno";
|
||||||
import * as timers from "./timers";
|
import * as timers from "./timers";
|
||||||
import { onFetchRes } from "./fetch";
|
import { onFetchRes } from "./fetch";
|
||||||
|
|
||||||
|
|
2
js/os.ts
2
js/os.ts
|
@ -5,7 +5,7 @@ import { assert } from "./util";
|
||||||
import * as util from "./util";
|
import * as util from "./util";
|
||||||
import { maybeThrowError } from "./errors";
|
import { maybeThrowError } from "./errors";
|
||||||
import { flatbuffers } from "flatbuffers";
|
import { flatbuffers } from "flatbuffers";
|
||||||
import { libdeno } from "./globals";
|
import { libdeno } from "./libdeno";
|
||||||
|
|
||||||
export function exit(exitCode = 0): never {
|
export function exit(exitCode = 0): never {
|
||||||
const builder = new flatbuffers.Builder();
|
const builder = new flatbuffers.Builder();
|
||||||
|
|
|
@ -3,7 +3,7 @@ import { assert } from "./util";
|
||||||
import * as util from "./util";
|
import * as util from "./util";
|
||||||
import { deno as fbs } from "gen/msg_generated";
|
import { deno as fbs } from "gen/msg_generated";
|
||||||
import { flatbuffers } from "flatbuffers";
|
import { flatbuffers } from "flatbuffers";
|
||||||
import { libdeno } from "./globals";
|
import { libdeno } from "./libdeno";
|
||||||
|
|
||||||
let nextTimerId = 1;
|
let nextTimerId = 1;
|
||||||
|
|
||||||
|
|
|
@ -63,5 +63,8 @@
|
||||||
"allow-leading-underscore",
|
"allow-leading-underscore",
|
||||||
"allow-trailing-underscore"
|
"allow-trailing-underscore"
|
||||||
]
|
]
|
||||||
}
|
},
|
||||||
|
"extends": [
|
||||||
|
"tslint-no-circular-imports"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue