summaryrefslogtreecommitdiff
path: root/cli
diff options
context:
space:
mode:
authorRyan Dahl <ry@tinyclouds.org>2020-07-20 19:49:57 -0400
committerGitHub <noreply@github.com>2020-07-20 19:49:57 -0400
commit2460689b1a9582ef6ab8c5fa429e281c88bc14d1 (patch)
treec6e8f7b8fda45004c0321eb2ac88a5bfb5905483 /cli
parent903d28f872b90a800c64339dea058806cde0be67 (diff)
Remove deno_typescript (#6813)
Diffstat (limited to 'cli')
-rw-r--r--cli/Cargo.toml4
-rw-r--r--cli/README.md2
-rw-r--r--cli/build.rs24
-rw-r--r--cli/js2/99_main_compiler.js2
-rw-r--r--cli/main.rs1
-rw-r--r--cli/op_fetch_asset.rs115
-rw-r--r--cli/ops/compiler.rs2
-rw-r--r--cli/system_loader.js99
-rw-r--r--cli/system_loader_es5.js180
-rw-r--r--cli/tests/unit/README.md3
m---------cli/typescript0
11 files changed, 414 insertions, 18 deletions
diff --git a/cli/Cargo.toml b/cli/Cargo.toml
index 25e0bdc31..29cd04ecd 100644
--- a/cli/Cargo.toml
+++ b/cli/Cargo.toml
@@ -16,7 +16,8 @@ path = "main.rs"
[build-dependencies]
deno_core = { path = "../core", version = "0.49.0" }
-deno_typescript = { path = "../deno_typescript", version = "0.49.0" }
+serde = { version = "1.0.112", features = ["derive"] }
+serde_json = { version = "1.0.55", features = [ "preserve_order" ] }
[target.'cfg(windows)'.build-dependencies]
winres = "0.1"
@@ -25,7 +26,6 @@ winapi = "0.3.8"
[dependencies]
deno_core = { path = "../core", version = "0.49.0" }
deno_lint = "0.1.16"
-deno_typescript = { path = "../deno_typescript", version = "0.49.0" }
atty = "0.2.14"
base64 = "0.12.2"
diff --git a/cli/README.md b/cli/README.md
index 778b279ec..18bee8a41 100644
--- a/cli/README.md
+++ b/cli/README.md
@@ -5,4 +5,4 @@
This provides the actual deno executable and the user-facing APIs.
-The deno crate uses the deno_core and deno_typescript to provide the executable.
+The deno crate uses the deno_core to provide the executable.
diff --git a/cli/build.rs b/cli/build.rs
index 89958325b..31dfc0aba 100644
--- a/cli/build.rs
+++ b/cli/build.rs
@@ -1,4 +1,6 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
+//
+mod op_fetch_asset;
use deno_core::js_check;
use deno_core::CoreIsolate;
@@ -64,16 +66,23 @@ fn create_compiler_snapshot(
);
runtime_isolate.register_op(
"op_fetch_asset",
- deno_typescript::op_fetch_asset(custom_libs),
+ op_fetch_asset::op_fetch_asset(custom_libs),
);
- js_check(
- runtime_isolate.execute("typescript.js", deno_typescript::TYPESCRIPT_CODE),
- );
+ js_check(runtime_isolate.execute(
+ "typescript.js",
+ &std::fs::read_to_string("typescript/lib/typescript.js").unwrap(),
+ ));
create_snapshot(runtime_isolate, snapshot_path, files);
}
+fn ts_version() -> String {
+ let data = include_str!("typescript/package.json");
+ let pkg: serde_json::Value = serde_json::from_str(data).unwrap();
+ pkg["version"].as_str().unwrap().to_string()
+}
+
fn main() {
// Don't build V8 if "cargo doc" is being run. This is to support docs.rs.
if env::var_os("RUSTDOCFLAGS").is_some() {
@@ -81,12 +90,9 @@ fn main() {
}
// To debug snapshot issues uncomment:
- // deno_typescript::trace_serializer();
+ // op_fetch_asset::trace_serializer();
- println!(
- "cargo:rustc-env=TS_VERSION={}",
- deno_typescript::ts_version()
- );
+ println!("cargo:rustc-env=TS_VERSION={}", ts_version());
println!(
"cargo:rustc-env=TARGET={}",
diff --git a/cli/js2/99_main_compiler.js b/cli/js2/99_main_compiler.js
index b9abdde7d..d64896862 100644
--- a/cli/js2/99_main_compiler.js
+++ b/cli/js2/99_main_compiler.js
@@ -1,7 +1,5 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
-// TODO(ry) Combine this implementation with //deno_typescript/compiler_main.js
-
// This module is the entry point for "compiler" isolate, ie. the one
// that is created when Deno needs to compile TS/WASM to JS.
//
diff --git a/cli/main.rs b/cli/main.rs
index cf25ed324..4a87db922 100644
--- a/cli/main.rs
+++ b/cli/main.rs
@@ -49,6 +49,7 @@ mod metrics;
mod module_graph;
pub mod msg;
pub mod op_error;
+mod op_fetch_asset;
pub mod ops;
pub mod permissions;
mod repl;
diff --git a/cli/op_fetch_asset.rs b/cli/op_fetch_asset.rs
new file mode 100644
index 000000000..114aff133
--- /dev/null
+++ b/cli/op_fetch_asset.rs
@@ -0,0 +1,115 @@
+// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
+// Note: this module is used both in build.rs and main.rs.
+
+pub use deno_core::v8_set_flags;
+use deno_core::CoreIsolateState;
+use deno_core::Op;
+use deno_core::OpDispatcher;
+use deno_core::ZeroCopyBuf;
+use std::collections::HashMap;
+use std::path::PathBuf;
+
+fn get_asset(name: &str) -> Option<&'static str> {
+ macro_rules! inc {
+ ($e:expr) => {
+ Some(include_str!(concat!("typescript/lib/", $e)))
+ };
+ }
+ match name {
+ "system_loader.js" => Some(include_str!("system_loader.js")),
+ "system_loader_es5.js" => Some(include_str!("system_loader_es5.js")),
+ "bootstrap.ts" => Some("console.log(\"hello deno\");"),
+ "typescript.d.ts" => inc!("typescript.d.ts"),
+ "lib.dom.d.ts" => inc!("lib.dom.d.ts"),
+ "lib.dom.iterable.d.ts" => inc!("lib.dom.iterable.d.ts"),
+ "lib.es5.d.ts" => inc!("lib.es5.d.ts"),
+ "lib.es6.d.ts" => inc!("lib.es6.d.ts"),
+ "lib.esnext.d.ts" => inc!("lib.esnext.d.ts"),
+ "lib.es2020.d.ts" => inc!("lib.es2020.d.ts"),
+ "lib.es2020.full.d.ts" => inc!("lib.es2020.full.d.ts"),
+ "lib.es2019.d.ts" => inc!("lib.es2019.d.ts"),
+ "lib.es2019.full.d.ts" => inc!("lib.es2019.full.d.ts"),
+ "lib.es2018.d.ts" => inc!("lib.es2018.d.ts"),
+ "lib.es2018.full.d.ts" => inc!("lib.es2018.full.d.ts"),
+ "lib.es2017.d.ts" => inc!("lib.es2017.d.ts"),
+ "lib.es2017.full.d.ts" => inc!("lib.es2017.full.d.ts"),
+ "lib.es2016.d.ts" => inc!("lib.es2016.d.ts"),
+ "lib.es2016.full.d.ts" => inc!("lib.es2016.full.d.ts"),
+ "lib.es2015.d.ts" => inc!("lib.es2015.d.ts"),
+ "lib.es2015.collection.d.ts" => inc!("lib.es2015.collection.d.ts"),
+ "lib.es2015.core.d.ts" => inc!("lib.es2015.core.d.ts"),
+ "lib.es2015.generator.d.ts" => inc!("lib.es2015.generator.d.ts"),
+ "lib.es2015.iterable.d.ts" => inc!("lib.es2015.iterable.d.ts"),
+ "lib.es2015.promise.d.ts" => inc!("lib.es2015.promise.d.ts"),
+ "lib.es2015.proxy.d.ts" => inc!("lib.es2015.proxy.d.ts"),
+ "lib.es2015.reflect.d.ts" => inc!("lib.es2015.reflect.d.ts"),
+ "lib.es2015.symbol.d.ts" => inc!("lib.es2015.symbol.d.ts"),
+ "lib.es2015.symbol.wellknown.d.ts" => {
+ inc!("lib.es2015.symbol.wellknown.d.ts")
+ }
+ "lib.es2016.array.include.d.ts" => inc!("lib.es2016.array.include.d.ts"),
+ "lib.es2017.intl.d.ts" => inc!("lib.es2017.intl.d.ts"),
+ "lib.es2017.object.d.ts" => inc!("lib.es2017.object.d.ts"),
+ "lib.es2017.sharedmemory.d.ts" => inc!("lib.es2017.sharedmemory.d.ts"),
+ "lib.es2017.string.d.ts" => inc!("lib.es2017.string.d.ts"),
+ "lib.es2017.typedarrays.d.ts" => inc!("lib.es2017.typedarrays.d.ts"),
+ "lib.es2018.asyncgenerator.d.ts" => inc!("lib.es2018.asyncgenerator.d.ts"),
+ "lib.es2018.asynciterable.d.ts" => inc!("lib.es2018.asynciterable.d.ts"),
+ "lib.es2018.intl.d.ts" => inc!("lib.es2018.intl.d.ts"),
+ "lib.es2018.promise.d.ts" => inc!("lib.es2018.promise.d.ts"),
+ "lib.es2018.regexp.d.ts" => inc!("lib.es2018.regexp.d.ts"),
+ "lib.es2019.array.d.ts" => inc!("lib.es2019.array.d.ts"),
+ "lib.es2019.object.d.ts" => inc!("lib.es2019.object.d.ts"),
+ "lib.es2019.string.d.ts" => inc!("lib.es2019.string.d.ts"),
+ "lib.es2019.symbol.d.ts" => inc!("lib.es2019.symbol.d.ts"),
+ "lib.es2020.bigint.d.ts" => inc!("lib.es2020.bigint.d.ts"),
+ "lib.es2020.promise.d.ts" => inc!("lib.es2020.promise.d.ts"),
+ "lib.es2020.string.d.ts" => inc!("lib.es2020.string.d.ts"),
+ "lib.es2020.symbol.wellknown.d.ts" => {
+ inc!("lib.es2020.symbol.wellknown.d.ts")
+ }
+ "lib.esnext.array.d.ts" => inc!("lib.esnext.array.d.ts"),
+ "lib.esnext.asynciterable.d.ts" => inc!("lib.esnext.asynciterable.d.ts"),
+ "lib.esnext.bigint.d.ts" => inc!("lib.esnext.bigint.d.ts"),
+ "lib.esnext.intl.d.ts" => inc!("lib.esnext.intl.d.ts"),
+ "lib.esnext.promise.d.ts" => inc!("lib.esnext.promise.d.ts"),
+ "lib.esnext.string.d.ts" => inc!("lib.esnext.string.d.ts"),
+ "lib.esnext.symbol.d.ts" => inc!("lib.esnext.symbol.d.ts"),
+ "lib.scripthost.d.ts" => inc!("lib.scripthost.d.ts"),
+ "lib.webworker.d.ts" => inc!("lib.webworker.d.ts"),
+ "lib.webworker.importscripts.d.ts" => {
+ inc!("lib.webworker.importscripts.d.ts")
+ }
+ _ => None,
+ }
+}
+
+/// Warning: Returns a non-JSON op dispatcher. Must be manually attached to
+/// CoreIsolate.
+pub fn op_fetch_asset<S: ::std::hash::BuildHasher>(
+ custom_assets: HashMap<String, PathBuf, S>,
+) -> impl OpDispatcher {
+ for (_, path) in custom_assets.iter() {
+ println!("cargo:rerun-if-changed={}", path.display());
+ }
+ move |_state: &mut CoreIsolateState,
+ zero_copy_bufs: &mut [ZeroCopyBuf]|
+ -> Op {
+ assert_eq!(zero_copy_bufs.len(), 1, "Invalid number of arguments");
+ let name = std::str::from_utf8(&zero_copy_bufs[0]).unwrap();
+
+ let asset_code = if let Some(source_code) = get_asset(name) {
+ source_code.to_string()
+ } else if let Some(asset_path) = custom_assets.get(name) {
+ let source_code_vec =
+ std::fs::read(&asset_path).expect("Asset not found");
+ let source_code = std::str::from_utf8(&source_code_vec).unwrap();
+ source_code.to_string()
+ } else {
+ panic!("fetch_asset bad asset {}", name)
+ };
+
+ let vec = asset_code.into_bytes();
+ deno_core::Op::Sync(vec.into_boxed_slice())
+ }
+}
diff --git a/cli/ops/compiler.rs b/cli/ops/compiler.rs
index 2e5842c0f..9e56ef436 100644
--- a/cli/ops/compiler.rs
+++ b/cli/ops/compiler.rs
@@ -8,6 +8,6 @@ pub fn init(i: &mut CoreIsolate, _s: &State) {
// TODO(bartlomieju): is this op even required?
i.register_op(
"op_fetch_asset",
- deno_typescript::op_fetch_asset(custom_assets),
+ crate::op_fetch_asset::op_fetch_asset(custom_assets),
);
}
diff --git a/cli/system_loader.js b/cli/system_loader.js
new file mode 100644
index 000000000..c96b2c7f6
--- /dev/null
+++ b/cli/system_loader.js
@@ -0,0 +1,99 @@
+// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
+
+// This is a specialised implementation of a System module loader.
+
+"use strict";
+
+// @ts-nocheck
+/* eslint-disable */
+let System, __instantiate;
+(() => {
+ const r = new Map();
+
+ System = {
+ register(id, d, f) {
+ r.set(id, { d, f, exp: {} });
+ },
+ };
+ async function dI(mid, src) {
+ let id = mid.replace(/\.\w+$/i, "");
+ if (id.includes("./")) {
+ const [o, ...ia] = id.split("/").reverse(),
+ [, ...sa] = src.split("/").reverse(),
+ oa = [o];
+ let s = 0,
+ i;
+ while ((i = ia.shift())) {
+ if (i === "..") s++;
+ else if (i === ".") break;
+ else oa.push(i);
+ }
+ if (s < sa.length) oa.push(...sa.slice(s));
+ id = oa.reverse().join("/");
+ }
+ return r.has(id) ? gExpA(id) : import(mid);
+ }
+
+ function gC(id, main) {
+ return {
+ id,
+ import: (m) => dI(m, id),
+ meta: { url: id, main },
+ };
+ }
+
+ function gE(exp) {
+ return (id, v) => {
+ v = typeof id === "string" ? { [id]: v } : id;
+ for (const [id, value] of Object.entries(v)) {
+ Object.defineProperty(exp, id, {
+ value,
+ writable: true,
+ enumerable: true,
+ });
+ }
+ };
+ }
+
+ function rF(main) {
+ for (const [id, m] of r.entries()) {
+ const { f, exp } = m;
+ const { execute: e, setters: s } = f(gE(exp), gC(id, id === main));
+ delete m.f;
+ m.e = e;
+ m.s = s;
+ }
+ }
+
+ async function gExpA(id) {
+ if (!r.has(id)) return;
+ const m = r.get(id);
+ if (m.s) {
+ const { d, e, s } = m;
+ delete m.s;
+ delete m.e;
+ for (let i = 0; i < s.length; i++) s[i](await gExpA(d[i]));
+ const r = e();
+ if (r) await r;
+ }
+ return m.exp;
+ }
+
+ function gExp(id) {
+ if (!r.has(id)) return;
+ const m = r.get(id);
+ if (m.s) {
+ const { d, e, s } = m;
+ delete m.s;
+ delete m.e;
+ for (let i = 0; i < s.length; i++) s[i](gExp(d[i]));
+ e();
+ }
+ return m.exp;
+ }
+ __instantiate = (m, a) => {
+ System = __instantiate = undefined;
+ rF(m);
+ return a ? gExpA(m) : gExp(m);
+ };
+})();
diff --git a/cli/system_loader_es5.js b/cli/system_loader_es5.js
new file mode 100644
index 000000000..91bae136a
--- /dev/null
+++ b/cli/system_loader_es5.js
@@ -0,0 +1,180 @@
+// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
+
+// This is a specialised implementation of a System module loader.
+
+"use strict";
+
+// @ts-nocheck
+/* eslint-disable */
+var System, __instantiate;
+(function () {
+ // deno-fmt-ignore
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
+ return new (P || (P = Promise))(function (resolve, reject) {
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
+ });
+ };
+ // deno-fmt-ignore
+ var __generator = (this && this.__generator) || function (thisArg, body) {
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
+ function verb(n) { return function (v) { return step([n, v]); }; }
+ function step(op) {
+ if (f) throw new TypeError("Generator is already executing.");
+ while (_) try {
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
+ if (y = 0, t) op = [op[0] & 2, t.value];
+ switch (op[0]) {
+ case 0: case 1: t = op; break;
+ case 4: _.label++; return { value: op[1], done: false };
+ case 5: _.label++; y = op[1]; op = [0]; continue;
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
+ default:
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
+ if (t[2]) _.ops.pop();
+ _.trys.pop(); continue;
+ }
+ op = body.call(thisArg, _);
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
+ }
+ };
+ var r = Object.create(null);
+ System = {
+ register: function (id, d, f) {
+ r[id] = { d: d, f: f, exp: {} };
+ },
+ };
+ function dI(mid, src) {
+ return __awaiter(this, void 0, void 0, function () {
+ var id, _a, o, ia, _b, sa, oa, s, i;
+ return __generator(this, function (_c) {
+ id = mid.replace(/\.\w+$/i, "");
+ if (id.includes("./")) {
+ (_a = id.split("/").reverse()),
+ (o = _a[0]),
+ (ia = _a.slice(1)),
+ (_b = src.split("/").reverse()),
+ (sa = _b.slice(1)),
+ (oa = [o]);
+ (s = 0), (i = void 0);
+ while ((i = ia.shift())) {
+ if (i === "..") s++;
+ else if (i === ".") break;
+ else oa.push(i);
+ }
+ if (s < sa.length) oa.push.apply(oa, sa.slice(s));
+ id = oa.reverse().join("/");
+ }
+ return [
+ 2,
+ id in r ? gExpA(id) : Promise.resolve().then(function () {
+ return require(mid);
+ }),
+ ];
+ });
+ });
+ }
+ function gC(id, main) {
+ return {
+ id: id,
+ import: function (m) {
+ return dI(m, id);
+ },
+ meta: { url: id, main: main },
+ };
+ }
+ function gE(exp) {
+ return function (id, v) {
+ var _a;
+ v = typeof id === "string" ? ((_a = {}), (_a[id] = v), _a) : id;
+ for (var _i = 0, _b = Object.entries(v); _i < _b.length; _i++) {
+ var _c = _b[_i],
+ id_1 = _c[0],
+ value = _c[1];
+ Object.defineProperty(exp, id_1, {
+ value: value,
+ writable: true,
+ enumerable: true,
+ });
+ }
+ };
+ }
+ function rF(main) {
+ var m;
+ for (var id in r) {
+ m = r[id];
+ var f = m.f,
+ exp = m.exp;
+ var _a = f(gE(exp), gC(id, id === main)),
+ e = _a.execute,
+ s = _a.setters;
+ delete m.f;
+ m.e = e;
+ m.s = s;
+ }
+ }
+ function gExpA(id) {
+ return __awaiter(this, void 0, void 0, function () {
+ var m, d, e, s, i, _a, _b, r_1;
+ return __generator(this, function (_c) {
+ switch (_c.label) {
+ case 0:
+ if (!(id in r)) return [2];
+ m = r[id];
+ if (!m.s) return [3, 6];
+ (d = m.d), (e = m.e), (s = m.s);
+ delete m.s;
+ delete m.e;
+ i = 0;
+ _c.label = 1;
+ case 1:
+ if (!(i < s.length)) return [3, 4];
+ _b = (_a = s)[i];
+ return [4, gExpA(d[i])];
+ case 2:
+ _b.apply(_a, [_c.sent()]);
+ _c.label = 3;
+ case 3:
+ i++;
+ return [3, 1];
+ case 4:
+ r_1 = e();
+ if (!r_1) return [3, 6];
+ return [4, r_1];
+ case 5:
+ _c.sent();
+ _c.label = 6;
+ case 6:
+ return [2, m.exp];
+ }
+ });
+ });
+ }
+ function gExp(id) {
+ if (!(id in r)) return;
+ var m = r[id];
+ if (m.s) {
+ var d = m.d,
+ e = m.e,
+ s = m.s;
+ delete m.s;
+ delete m.e;
+ for (var i = 0; i < s.length; i++) s[i](gExp(d[i]));
+ e();
+ }
+ return m.exp;
+ }
+ __instantiate = function (m, a) {
+ System = __instantiate = undefined;
+ rF(m);
+ return a ? gExpA(m) : gExp(m);
+ };
+})();
diff --git a/cli/tests/unit/README.md b/cli/tests/unit/README.md
index 1546038c4..e15ad7080 100644
--- a/cli/tests/unit/README.md
+++ b/cli/tests/unit/README.md
@@ -2,9 +2,6 @@
Files in this directory are unit tests for Deno runtime.
-They are run under compiled Deno binary as opposed to files in `cli/js/` which
-are bundled and snapshotted using `deno_typescript` crate.
-
Testing Deno runtime code requires checking API under different runtime
permissions (ie. running with different `--allow-*` flags). To accomplish this
all tests exercised are created using `unitTest()` function.
diff --git a/cli/typescript b/cli/typescript
new file mode 160000
+Subproject 551f0dd9a1b57ecd527a665b0af7fc98cd107af