From 2460689b1a9582ef6ab8c5fa429e281c88bc14d1 Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Mon, 20 Jul 2020 19:49:57 -0400 Subject: Remove deno_typescript (#6813) --- .dprintrc.json | 2 +- .gitmodules | 2 +- Cargo.lock | 10 -- Cargo.toml | 1 - cli/Cargo.toml | 4 +- cli/README.md | 2 +- cli/build.rs | 24 +++-- cli/js2/99_main_compiler.js | 2 - cli/main.rs | 1 + cli/op_fetch_asset.rs | 115 ++++++++++++++++++++++ cli/ops/compiler.rs | 2 +- cli/system_loader.js | 99 +++++++++++++++++++ cli/system_loader_es5.js | 180 +++++++++++++++++++++++++++++++++++ cli/tests/unit/README.md | 3 - cli/typescript | 1 + deno_typescript/Cargo.toml | 24 ----- deno_typescript/README.md | 82 ---------------- deno_typescript/lib.rs | 125 ------------------------ deno_typescript/system_loader.js | 99 ------------------- deno_typescript/system_loader_es5.js | 180 ----------------------------------- deno_typescript/typescript | 1 - 21 files changed, 417 insertions(+), 542 deletions(-) create mode 100644 cli/op_fetch_asset.rs create mode 100644 cli/system_loader.js create mode 100644 cli/system_loader_es5.js create mode 160000 cli/typescript delete mode 100644 deno_typescript/Cargo.toml delete mode 100644 deno_typescript/README.md delete mode 100644 deno_typescript/lib.rs delete mode 100644 deno_typescript/system_loader.js delete mode 100644 deno_typescript/system_loader_es5.js delete mode 160000 deno_typescript/typescript diff --git a/.dprintrc.json b/.dprintrc.json index eb050a17e..c408bb8d4 100644 --- a/.dprintrc.json +++ b/.dprintrc.json @@ -12,7 +12,7 @@ "includes": ["**/*.{ts,tsx,js,jsx,json,md}"], "excludes": [ ".cargo_home", - "deno_typescript/typescript", + "cli/typescript", "gh-pages", "std/**/testdata", "std/**/vendor", diff --git a/.gitmodules b/.gitmodules index c35100865..480dd0206 100644 --- a/.gitmodules +++ b/.gitmodules @@ -2,7 +2,7 @@ path = third_party url = https://github.com/denoland/deno_third_party.git [submodule "typescript"] - path = deno_typescript/typescript + path = cli/typescript url = https://github.com/microsoft/TypeScript.git fetchRecurseSubmodules = false shallow = true diff --git a/Cargo.lock b/Cargo.lock index 1f1aeb62e..f0856e3a2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -386,7 +386,6 @@ dependencies = [ "clap", "deno_core", "deno_lint", - "deno_typescript", "dissimilar", "dlopen", "futures 0.3.5", @@ -459,15 +458,6 @@ dependencies = [ "swc_ecma_visit", ] -[[package]] -name = "deno_typescript" -version = "0.49.0" -dependencies = [ - "deno_core", - "serde", - "serde_json", -] - [[package]] name = "derive_deref" version = "1.1.1" diff --git a/Cargo.toml b/Cargo.toml index 00304f039..ea0e02cf9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,6 @@ members = [ "cli", "core", - "deno_typescript", "test_plugin", "test_util", ] 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( + custom_assets: HashMap, +) -> 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 index 000000000..551f0dd9a --- /dev/null +++ b/cli/typescript @@ -0,0 +1 @@ +Subproject commit 551f0dd9a1b57ecd527a665b0af7fc98cd107af6 diff --git a/deno_typescript/Cargo.toml b/deno_typescript/Cargo.toml deleted file mode 100644 index 10dd8103f..000000000 --- a/deno_typescript/Cargo.toml +++ /dev/null @@ -1,24 +0,0 @@ -[package] -name = "deno_typescript" -version = "0.49.0" -license = "MIT" -description = "To compile TypeScript to a snapshot during build.rs" -repository = "https://github.com/denoland/deno" -authors = ["the Deno authors"] -edition = "2018" - -exclude = [ - "typescript/tests/*", - "typescript/src/*", - "typescript/scripts/*", - "typescript/doc/*", - "typescript/lib/*/*.json", -] - -[lib] -path = "lib.rs" - -[dependencies] -deno_core = { path = "../core", version = "0.49.0" } -serde_json = "1.0.55" -serde = { version = "1.0.112", features = ["derive"] } diff --git a/deno_typescript/README.md b/deno_typescript/README.md deleted file mode 100644 index 7ee4cf1df..000000000 --- a/deno_typescript/README.md +++ /dev/null @@ -1,82 +0,0 @@ -# Deno TypeScript Crate - -[![crates](https://img.shields.io/crates/v/deno_typescript.svg)](https://crates.io/crates/deno_typescript) -[![docs](https://docs.rs/deno_typescript/badge.svg)](https://docs.rs/deno_typescript) - -This crate provides utilities to compile typescript, bundle it up, and create a -V8 snapshot, all during build. Snapshots allow the executable to startup fast. - -## `system_loader.js` - -This is a minimalistic implementation of a -[System](https://github.com/systemjs/systemjs) module loader. It is specifically -designed to load modules that are emitted from TypeScript the module format is -`"system"` and a single `"outfile"` is supplied, which is commonly refereed to -as a bundle. - -Because this loader becomes part of an emitted bundle under `Deno.bundle()` and -`deno bundle`, it has minimal comments and very terse and cryptic syntax, which -isn't very self documenting. Because of this, a guide to this file is provided -here. - -A bundle of System modules expects a `System.register()` function to be in scope -for registering the modules. Modules that are emitted from TypeScript in a -single out file always pass 3 arguments, the module specifier, an array of -strings of modules specifiers that this module depends upon, and finally a -module factory. - -The module factory requires two arguments to be passed, a function for exporting -values and a context object. We have to bind to some information in the -environment to provide these, so `gC` gets the context and `gE` gets the export -function to be passed to a factory. The context contains information like the -module specifier, a reference to the dynamic `import()` and the equivalent of -`import.meta`. The export function takes either two arguments of an named export -and its value, or an object record of keys of the named exports and the values -of the exports. - -Currently, TypeScript does not re-write dynamic imports which resolve to static -strings (see -[microsoft/TypeScript#37429](https://github.com/microsoft/TypeScript/issues/37429)), -which means the import specifier for a dynamic import which has been -incorporated in the bundle does not automatically match a module specifier that -has been registered in the bundle. The `di()` function provides the capability -to try to identify relative import specifiers and resolve them to a specifier -inside the bundle. If it does this, it resolves with the exports of the module, -otherwise it simply passes the module specifier to `import()` and returns the -resulting promise. - -The running of the factories is handled by `rF()`. When the factory is run, it -returns an object with two keys, `execute` and `setters`. `execute` is a -function which finalises that instantiation of the module, and `setters` which -is an array of functions that sets the value of the exports of the dependent -module. - -The `gExp()` and `gExpA()` are the recursive functions which returns the exports -of a given module. It will determine if the module has been fully initialized, -and if not, it will gather the exports of the dependencies, set those exports in -the module via the `setters` and run the modules `execute()`. It will then -always return or resolve with the exports of the module. - -As of TypeScript 3.8, top level await is supported when emitting ES or System -modules. When Deno creates a module bundle, it creates a valid, self-contained -ES module which exports the exports of the "main" module that was used when the -bundle was created. If a module in the bundle requires top-level-await, then the -`execute()` function is emitted as an async function, returning a promise. This -means that in order to export the values of the main module, the instantiation -needs to utilise top-level-await as well. - -At the time of this writing, while V8 and other JavaScript engines have -implemented top-level-await, no browsers have it implemented, meaning that most -browsers could not consume modules that require top-level-await. - -In order to allow more browsers to consume bundles, there is an argument that is -passed to the `__instantiate()` function which determines if the code is -bootstrapped asynchronously or not. When emitting a bundle that contains a -module that requires top-level-await, Deno will detect this and utilise -`await __instantiate(main, true)`. - -The `system_loader_es5.js` is a transpiled version of `system_loader.js` that is -designed to work with ES5 or later, and will be used when the bundle target is < -ES2017. While ES3 is still a potential target which can be passed in a -`tsconfig.json` to Deno, any resulting bundle will not be compatible, as there -is a need to utilise items like `Object.defineProperty()`. diff --git a/deno_typescript/lib.rs b/deno_typescript/lib.rs deleted file mode 100644 index f01993464..000000000 --- a/deno_typescript/lib.rs +++ /dev/null @@ -1,125 +0,0 @@ -// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. -extern crate deno_core; -extern crate serde; -extern crate serde_json; - -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; - -pub static TYPESCRIPT_CODE: &str = include_str!("typescript/lib/typescript.js"); - -pub 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 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( - custom_assets: HashMap, -) -> 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/deno_typescript/system_loader.js b/deno_typescript/system_loader.js deleted file mode 100644 index c96b2c7f6..000000000 --- a/deno_typescript/system_loader.js +++ /dev/null @@ -1,99 +0,0 @@ -// 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/deno_typescript/system_loader_es5.js b/deno_typescript/system_loader_es5.js deleted file mode 100644 index 91bae136a..000000000 --- a/deno_typescript/system_loader_es5.js +++ /dev/null @@ -1,180 +0,0 @@ -// 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/deno_typescript/typescript b/deno_typescript/typescript deleted file mode 160000 index 551f0dd9a..000000000 --- a/deno_typescript/typescript +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 551f0dd9a1b57ecd527a665b0af7fc98cd107af6 -- cgit v1.2.3