summaryrefslogtreecommitdiff
path: root/deno_typescript
diff options
context:
space:
mode:
Diffstat (limited to 'deno_typescript')
-rw-r--r--deno_typescript/Cargo.toml24
-rw-r--r--deno_typescript/README.md82
-rw-r--r--deno_typescript/lib.rs125
-rw-r--r--deno_typescript/system_loader.js99
-rw-r--r--deno_typescript/system_loader_es5.js180
m---------deno_typescript/typescript0
6 files changed, 0 insertions, 510 deletions
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<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/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
-Subproject 551f0dd9a1b57ecd527a665b0af7fc98cd107af