2020-10-02 05:07:40 +03:00
|
|
|
//! In-tree testing for deno integration.
|
|
|
|
//!
|
|
|
|
//! This module exists because this is way easier than using copying requires
|
|
|
|
//! files.
|
2020-12-02 16:48:35 +03:00
|
|
|
|
2022-02-09 09:33:32 +03:00
|
|
|
use std::{collections::HashMap, fs::write, path::PathBuf, process::Command};
|
|
|
|
|
2020-12-02 16:48:35 +03:00
|
|
|
use anyhow::Error;
|
2020-12-27 13:02:41 +03:00
|
|
|
use ntest::timeout;
|
2020-11-02 09:22:21 +03:00
|
|
|
use swc_atoms::js_word;
|
2020-12-02 16:48:35 +03:00
|
|
|
use swc_bundler::{Bundler, Load, ModuleRecord};
|
2021-10-21 14:56:48 +03:00
|
|
|
use swc_common::{collections::AHashSet, FileName, Mark, Span, GLOBALS};
|
2020-11-19 14:42:56 +03:00
|
|
|
use swc_ecma_ast::*;
|
2021-10-21 14:56:48 +03:00
|
|
|
use swc_ecma_codegen::{
|
|
|
|
text_writer::{omit_trailing_semi, JsWriter, WriteJs},
|
|
|
|
Emitter,
|
|
|
|
};
|
2021-10-24 13:52:09 +03:00
|
|
|
use swc_ecma_minifier::option::MangleOptions;
|
2021-10-21 14:56:48 +03:00
|
|
|
use swc_ecma_transforms_base::{fixer::fixer, resolver::resolver_with_mark};
|
2020-11-19 14:42:56 +03:00
|
|
|
use swc_ecma_utils::{find_ids, Id};
|
2021-12-07 08:34:16 +03:00
|
|
|
use swc_ecma_visit::{Visit, VisitMutWith, VisitWith};
|
2020-11-19 14:42:56 +03:00
|
|
|
use testing::assert_eq;
|
2020-12-02 16:48:35 +03:00
|
|
|
|
2022-02-09 09:33:32 +03:00
|
|
|
use self::common::*;
|
|
|
|
|
2020-12-02 16:48:35 +03:00
|
|
|
#[path = "common/mod.rs"]
|
|
|
|
mod common;
|
2020-10-02 05:07:40 +03:00
|
|
|
|
|
|
|
#[test]
|
2020-12-27 13:02:41 +03:00
|
|
|
#[timeout(60000)]
|
2020-10-14 17:28:38 +03:00
|
|
|
fn oak_6_3_1_application() {
|
2020-11-19 14:42:56 +03:00
|
|
|
run(
|
|
|
|
"https://deno.land/x/oak@v6.3.1/application.ts",
|
|
|
|
&[
|
|
|
|
"ApplicationErrorEvent",
|
|
|
|
"ApplicationListenEvent",
|
|
|
|
"Application",
|
|
|
|
],
|
|
|
|
);
|
2020-10-14 17:28:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2020-12-27 13:02:41 +03:00
|
|
|
#[timeout(60000)]
|
2020-10-14 17:28:38 +03:00
|
|
|
fn oak_6_3_1_mod() {
|
2020-11-19 14:42:56 +03:00
|
|
|
run(
|
|
|
|
"https://deno.land/x/oak@v6.3.1/mod.ts",
|
|
|
|
&[
|
|
|
|
"Application",
|
|
|
|
"Context",
|
|
|
|
"helpers",
|
|
|
|
"Cookies",
|
|
|
|
"HttpError",
|
|
|
|
"httpErrors",
|
|
|
|
"isHttpError",
|
|
|
|
"composeMiddleware",
|
|
|
|
"FormDataReader",
|
|
|
|
"Request",
|
|
|
|
"REDIRECT_BACK",
|
|
|
|
"Response",
|
|
|
|
"Router",
|
|
|
|
"send",
|
|
|
|
"ServerSentEvent",
|
|
|
|
"ServerSentEventTarget",
|
|
|
|
"isErrorStatus",
|
|
|
|
"isRedirectStatus",
|
|
|
|
"Status",
|
|
|
|
"STATUS_TEXT",
|
|
|
|
],
|
|
|
|
);
|
2020-10-14 17:28:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2020-12-27 13:02:41 +03:00
|
|
|
#[timeout(60000)]
|
2020-11-19 14:42:56 +03:00
|
|
|
fn std_0_74_0_http_server() {
|
|
|
|
run(
|
|
|
|
"https://deno.land/std@0.74.0/http/server.ts",
|
|
|
|
&[
|
|
|
|
"ServerRequest",
|
|
|
|
"Server",
|
|
|
|
"_parseAddrFromStr",
|
|
|
|
"serve",
|
|
|
|
"listenAndServe",
|
|
|
|
"serveTLS",
|
|
|
|
"listenAndServeTLS",
|
|
|
|
],
|
|
|
|
);
|
2020-10-14 17:28:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2020-12-27 13:02:41 +03:00
|
|
|
#[timeout(60000)]
|
2020-11-02 08:55:28 +03:00
|
|
|
#[ignore = "Does not finish by default"]
|
2020-10-16 16:26:18 +03:00
|
|
|
fn oak_6_3_1_example_server() {
|
2020-11-19 14:42:56 +03:00
|
|
|
run("https://deno.land/x/oak@v6.3.1/examples/server.ts", &[]);
|
2020-10-14 17:28:38 +03:00
|
|
|
}
|
|
|
|
|
2020-10-16 16:26:18 +03:00
|
|
|
#[test]
|
2020-12-27 13:02:41 +03:00
|
|
|
#[timeout(60000)]
|
2020-11-02 08:55:28 +03:00
|
|
|
#[ignore = "Does not finish by default"]
|
2020-10-16 16:26:18 +03:00
|
|
|
fn oak_6_3_1_example_sse_server() {
|
2020-11-19 14:42:56 +03:00
|
|
|
run("https://deno.land/x/oak@v6.3.1/examples/sseServer.ts", &[]);
|
2020-10-16 16:26:18 +03:00
|
|
|
}
|
|
|
|
|
2020-10-30 08:49:02 +03:00
|
|
|
#[test]
|
2020-12-21 22:27:18 +03:00
|
|
|
#[ignore = "Will be fixed by #1264"]
|
2020-12-27 13:02:41 +03:00
|
|
|
#[timeout(60000)]
|
2020-11-19 14:42:56 +03:00
|
|
|
fn deno_8188_full() {
|
|
|
|
run(
|
|
|
|
"https://raw.githubusercontent.com/nats-io/nats.ws/master/src/mod.ts",
|
|
|
|
&[
|
|
|
|
"connect",
|
|
|
|
"NatsConnectionImpl",
|
|
|
|
"Nuid",
|
|
|
|
"nuid",
|
|
|
|
"ErrorCode",
|
|
|
|
"NatsError",
|
|
|
|
"DebugEvents",
|
|
|
|
"Empty",
|
|
|
|
"Events",
|
|
|
|
"MsgImpl",
|
|
|
|
"SubscriptionImpl",
|
|
|
|
"Subscriptions",
|
|
|
|
"setTransportFactory",
|
|
|
|
"setUrlParseFn",
|
|
|
|
"Connect",
|
|
|
|
"createInbox",
|
|
|
|
"INFO",
|
|
|
|
"ProtocolHandler",
|
|
|
|
"deferred",
|
|
|
|
"delay",
|
|
|
|
"extractProtocolMessage",
|
|
|
|
"render",
|
|
|
|
"timeout",
|
|
|
|
"headers",
|
|
|
|
"MsgHdrsImpl",
|
|
|
|
"Heartbeat",
|
|
|
|
"MuxSubscription",
|
|
|
|
"DataBuffer",
|
|
|
|
"checkOptions",
|
|
|
|
"Request",
|
|
|
|
"credsAuthenticator",
|
|
|
|
"jwtAuthenticator",
|
|
|
|
"nkeyAuthenticator",
|
|
|
|
"JSONCodec",
|
|
|
|
"StringCodec",
|
|
|
|
"QueuedIterator",
|
|
|
|
"Kind",
|
|
|
|
"Parser",
|
|
|
|
"State",
|
|
|
|
"DenoBuffer",
|
|
|
|
"MAX_SIZE",
|
|
|
|
"readAll",
|
|
|
|
"writeAll",
|
|
|
|
"Bench",
|
|
|
|
"Metric",
|
|
|
|
"TD",
|
|
|
|
"TE",
|
|
|
|
"isIP",
|
|
|
|
"parseIP",
|
|
|
|
"nkeys",
|
|
|
|
],
|
|
|
|
);
|
2020-10-30 08:49:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2020-12-27 13:02:41 +03:00
|
|
|
#[timeout(60000)]
|
2020-11-19 14:42:56 +03:00
|
|
|
fn deno_8188_01() {
|
2020-10-30 08:49:02 +03:00
|
|
|
run(
|
2020-11-19 14:42:56 +03:00
|
|
|
"https://raw.githubusercontent.com/nats-io/nats.deno/v1.0.0-12/nats-base-client/nkeys.ts",
|
|
|
|
&["nkeys"],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2020-12-27 13:02:41 +03:00
|
|
|
#[timeout(60000)]
|
2020-11-19 14:42:56 +03:00
|
|
|
fn deno_8188_02() {
|
|
|
|
run(
|
|
|
|
"https://raw.githubusercontent.com/nats-io/nkeys.js/v1.0.0-7/modules/esm/mod.ts",
|
|
|
|
&[
|
|
|
|
"NKeysError",
|
|
|
|
"NKeysErrorCode",
|
|
|
|
"createAccount",
|
|
|
|
"createOperator",
|
|
|
|
"createPair",
|
|
|
|
"createUser",
|
|
|
|
"decode",
|
|
|
|
"encode",
|
|
|
|
"fromPublic",
|
|
|
|
"fromSeed",
|
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2020-12-27 13:02:41 +03:00
|
|
|
#[timeout(60000)]
|
2020-11-19 14:42:56 +03:00
|
|
|
fn deno_8188_03() {
|
|
|
|
run(
|
|
|
|
"https://raw.githubusercontent.com/nats-io/nkeys.js/v1.0.0-7/modules/esm/deps.ts",
|
|
|
|
&["denoHelper"],
|
2020-10-30 08:49:02 +03:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2020-12-27 13:02:41 +03:00
|
|
|
#[timeout(60000)]
|
2020-10-30 08:49:02 +03:00
|
|
|
fn deno_8189() {
|
2020-11-19 14:42:56 +03:00
|
|
|
run(
|
|
|
|
"https://deno.land/x/lz4/mod.ts",
|
|
|
|
&["compress", "decompress"],
|
|
|
|
);
|
2020-10-30 08:49:02 +03:00
|
|
|
}
|
|
|
|
|
2020-11-02 08:55:28 +03:00
|
|
|
#[test]
|
2020-12-27 13:02:41 +03:00
|
|
|
#[timeout(60000)]
|
|
|
|
fn deno_8211_1() {
|
2020-11-19 14:42:56 +03:00
|
|
|
run(
|
|
|
|
"https://unpkg.com/luxon@1.25.0/src/luxon.js",
|
|
|
|
&[
|
|
|
|
"DateTime",
|
|
|
|
"Duration",
|
|
|
|
"Interval",
|
|
|
|
"Info",
|
|
|
|
"Zone",
|
|
|
|
"FixedOffsetZone",
|
|
|
|
"IANAZone",
|
|
|
|
"InvalidZone",
|
|
|
|
"LocalZone",
|
|
|
|
"Settings",
|
|
|
|
],
|
|
|
|
);
|
2020-11-02 08:55:28 +03:00
|
|
|
}
|
|
|
|
|
2020-11-06 12:42:04 +03:00
|
|
|
#[test]
|
2020-12-27 13:02:41 +03:00
|
|
|
#[timeout(60000)]
|
2020-11-06 12:42:04 +03:00
|
|
|
fn deno_8246() {
|
2020-11-19 14:42:56 +03:00
|
|
|
run("https://raw.githubusercontent.com/nats-io/nats.deno/v1.0.0-11/nats-base-client/internal_mod.ts",&[
|
|
|
|
"NatsConnectionImpl",
|
|
|
|
"Nuid",
|
|
|
|
"nuid",
|
|
|
|
"ErrorCode",
|
|
|
|
"NatsError",
|
|
|
|
"DebugEvents",
|
|
|
|
"Empty",
|
|
|
|
"Events",
|
|
|
|
"MsgImpl",
|
|
|
|
"SubscriptionImpl",
|
|
|
|
"Subscriptions",
|
|
|
|
"setTransportFactory",
|
|
|
|
"setUrlParseFn",
|
|
|
|
"Connect",
|
|
|
|
"createInbox",
|
|
|
|
"INFO",
|
|
|
|
"ProtocolHandler",
|
|
|
|
"deferred",
|
|
|
|
"delay",
|
|
|
|
"extractProtocolMessage",
|
|
|
|
"render",
|
|
|
|
"timeout",
|
|
|
|
"headers",
|
|
|
|
"MsgHdrsImpl",
|
|
|
|
"Heartbeat",
|
|
|
|
"MuxSubscription",
|
|
|
|
"DataBuffer",
|
|
|
|
"checkOptions",
|
|
|
|
"Request",
|
|
|
|
"credsAuthenticator",
|
|
|
|
"jwtAuthenticator",
|
|
|
|
"nkeyAuthenticator",
|
|
|
|
"JSONCodec",
|
|
|
|
"StringCodec",
|
|
|
|
"QueuedIterator",
|
|
|
|
"Kind",
|
|
|
|
"Parser",
|
|
|
|
"State",
|
|
|
|
"DenoBuffer",
|
|
|
|
"MAX_SIZE",
|
|
|
|
"readAll",
|
|
|
|
"writeAll",
|
|
|
|
"Bench",
|
|
|
|
"Metric",
|
|
|
|
"TD",
|
|
|
|
"TE",
|
|
|
|
"isIP",
|
|
|
|
"parseIP",
|
|
|
|
"nkeys",
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2020-12-27 13:02:41 +03:00
|
|
|
#[timeout(60000)]
|
2020-11-19 14:42:56 +03:00
|
|
|
#[ignore = "document is not defined when I use deno run"]
|
|
|
|
fn deno_6802() {
|
|
|
|
run("tests/deno/issue-6802/input.tsx", &[]);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2020-12-27 13:02:41 +03:00
|
|
|
#[timeout(60000)]
|
2020-11-19 14:42:56 +03:00
|
|
|
fn deno_8314_1() {
|
|
|
|
run("tests/deno/issue-8314/input.ts", &[]);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2020-12-27 13:02:41 +03:00
|
|
|
#[timeout(60000)]
|
2020-11-19 14:42:56 +03:00
|
|
|
fn deno_8314_2() {
|
|
|
|
run("https://dev.jspm.io/ngraph.graph", &["default"]);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2020-12-27 13:02:41 +03:00
|
|
|
#[timeout(60000)]
|
2020-11-19 14:42:56 +03:00
|
|
|
fn deno_8302() {
|
|
|
|
run("tests/deno/issue-8302/input.ts", &["DB", "Empty", "Status"]);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2020-12-27 13:02:41 +03:00
|
|
|
#[timeout(60000)]
|
2020-11-19 14:42:56 +03:00
|
|
|
fn deno_8399_1() {
|
|
|
|
run("tests/deno/issue-8399-1/input.ts", &[]);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2020-12-27 13:02:41 +03:00
|
|
|
#[timeout(60000)]
|
2020-11-19 14:42:56 +03:00
|
|
|
fn deno_8399_2() {
|
|
|
|
run("tests/deno/issue-8399-2/input.ts", &[]);
|
|
|
|
}
|
|
|
|
|
2020-11-27 13:37:22 +03:00
|
|
|
#[test]
|
2020-12-27 13:02:41 +03:00
|
|
|
#[timeout(60000)]
|
2020-11-27 13:37:22 +03:00
|
|
|
fn deno_8486_1() {
|
|
|
|
run("tests/deno/issue-8486-1/input.ts", &["myCLI"]);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2020-12-27 13:02:41 +03:00
|
|
|
#[timeout(60000)]
|
2020-11-27 13:37:22 +03:00
|
|
|
fn deno_7288_1() {
|
|
|
|
run("tests/deno/deno-7288-1/input.ts", &[]);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2020-12-21 22:27:18 +03:00
|
|
|
#[ignore = "Will be fixed by #1264"]
|
2020-12-27 13:02:41 +03:00
|
|
|
#[timeout(60000)]
|
2020-11-27 13:37:22 +03:00
|
|
|
fn deno_8481_1() {
|
|
|
|
run(
|
|
|
|
"https://raw.githubusercontent.com/nats-io/nats.ws/master/src/mod.ts",
|
|
|
|
&[
|
|
|
|
"Bench",
|
|
|
|
"Connect",
|
|
|
|
"DataBuffer",
|
|
|
|
"DebugEvents",
|
|
|
|
"DenoBuffer",
|
|
|
|
"Empty",
|
|
|
|
"ErrorCode",
|
|
|
|
"Events",
|
|
|
|
"Heartbeat",
|
|
|
|
"INFO",
|
|
|
|
"JSONCodec",
|
|
|
|
"Kind",
|
|
|
|
"MAX_SIZE",
|
|
|
|
"Metric",
|
|
|
|
"MsgHdrsImpl",
|
|
|
|
"MsgImpl",
|
|
|
|
"MuxSubscription",
|
|
|
|
"NatsConnectionImpl",
|
|
|
|
"NatsError",
|
|
|
|
"Nuid",
|
|
|
|
"Parser",
|
|
|
|
"ProtocolHandler",
|
|
|
|
"QueuedIterator",
|
|
|
|
"Request",
|
|
|
|
"State",
|
|
|
|
"StringCodec",
|
|
|
|
"SubscriptionImpl",
|
|
|
|
"Subscriptions",
|
|
|
|
"TD",
|
|
|
|
"TE",
|
|
|
|
"checkOptions",
|
|
|
|
"connect",
|
|
|
|
"createInbox",
|
|
|
|
"credsAuthenticator",
|
|
|
|
"deferred",
|
|
|
|
"delay",
|
|
|
|
"extractProtocolMessage",
|
|
|
|
"headers",
|
|
|
|
"isIP",
|
|
|
|
"jwtAuthenticator",
|
|
|
|
"nkeyAuthenticator",
|
|
|
|
"nkeys",
|
|
|
|
"nuid",
|
|
|
|
"parseIP",
|
|
|
|
"readAll",
|
|
|
|
"render",
|
|
|
|
"setTransportFactory",
|
|
|
|
"setUrlParseFn",
|
|
|
|
"timeout",
|
|
|
|
"writeAll",
|
|
|
|
],
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2020-11-30 12:21:34 +03:00
|
|
|
#[test]
|
2020-12-21 22:27:18 +03:00
|
|
|
#[ignore = "Will be fixed by #1264"]
|
2020-12-27 13:02:41 +03:00
|
|
|
#[timeout(60000)]
|
2020-11-30 12:21:34 +03:00
|
|
|
fn deno_8530() {
|
|
|
|
run("tests/deno/deno-8530/input/entry.ts", &[])
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2020-12-27 13:02:41 +03:00
|
|
|
#[timeout(60000)]
|
2020-12-02 16:48:35 +03:00
|
|
|
fn deno_8573() {
|
|
|
|
run("tests/deno/deno-8573/entry.ts", &[])
|
|
|
|
}
|
2020-12-27 13:02:41 +03:00
|
|
|
|
2020-12-09 08:23:44 +03:00
|
|
|
#[test]
|
2021-02-22 11:27:40 +03:00
|
|
|
#[timeout(120000)]
|
|
|
|
#[ignore = "The generated bundled aceesses `location`"]
|
2020-12-09 08:23:44 +03:00
|
|
|
fn deno_8597() {
|
|
|
|
run(
|
2020-12-20 15:31:00 +03:00
|
|
|
"https://cdn.skypack.dev/@tensorflow/tfjs@2.6.0",
|
2020-12-09 08:23:44 +03:00
|
|
|
&[
|
|
|
|
"Abs",
|
|
|
|
"Acos",
|
|
|
|
"Acosh",
|
|
|
|
"AdadeltaOptimizer",
|
|
|
|
"AdagradOptimizer",
|
|
|
|
"AdamOptimizer",
|
|
|
|
"AdamaxOptimizer",
|
|
|
|
"Add",
|
|
|
|
"AddN",
|
|
|
|
"All",
|
|
|
|
"Any",
|
|
|
|
"ArgMax",
|
|
|
|
"ArgMin",
|
|
|
|
"Asin",
|
|
|
|
"Asinh",
|
|
|
|
"Atan",
|
|
|
|
"Atan2",
|
|
|
|
"Atanh",
|
|
|
|
"AvgPool",
|
|
|
|
"AvgPool3D",
|
|
|
|
"AvgPool3DBackprop",
|
|
|
|
"AvgPoolBackprop",
|
|
|
|
"BatchMatMul",
|
|
|
|
"BatchToSpaceND",
|
|
|
|
"BroadcastTo",
|
|
|
|
"Callback",
|
|
|
|
"CallbackList",
|
|
|
|
"Cast",
|
|
|
|
"Ceil",
|
|
|
|
"ClipByValue",
|
|
|
|
"Complex",
|
|
|
|
"Concat",
|
|
|
|
"Conv2D",
|
|
|
|
"Conv2DBackpropFilter",
|
|
|
|
"Conv2DBackpropInput",
|
|
|
|
"Conv3D",
|
|
|
|
"Conv3DBackpropFilterV2",
|
|
|
|
"Conv3DBackpropInputV2",
|
|
|
|
"Cos",
|
|
|
|
"Cosh",
|
|
|
|
"CropAndResize",
|
|
|
|
"Cumsum",
|
|
|
|
"CustomCallback",
|
|
|
|
"DataStorage",
|
|
|
|
"DepthToSpace",
|
|
|
|
"DepthwiseConv2dNative",
|
|
|
|
"DepthwiseConv2dNativeBackpropFilter",
|
|
|
|
"DepthwiseConv2dNativeBackpropInput",
|
|
|
|
"Diag",
|
|
|
|
"Dilation2D",
|
|
|
|
"Dilation2DBackpropFilter",
|
|
|
|
"Dilation2DBackpropInput",
|
|
|
|
"Div",
|
|
|
|
"ENV",
|
|
|
|
"EarlyStopping",
|
|
|
|
"Elu",
|
|
|
|
"EluGrad",
|
|
|
|
"Environment",
|
|
|
|
"Equal",
|
|
|
|
"Erf",
|
|
|
|
"Exp",
|
|
|
|
"Expm1",
|
|
|
|
"FFT",
|
|
|
|
"Fill",
|
|
|
|
"FlipLeftRight",
|
|
|
|
"Floor",
|
|
|
|
"FloorDiv",
|
|
|
|
"FromPixels",
|
|
|
|
"FusedBatchNorm",
|
|
|
|
"FusedConv2D",
|
|
|
|
"FusedDepthwiseConv2D",
|
|
|
|
"GatherNd",
|
|
|
|
"GatherV2",
|
|
|
|
"GraphModel",
|
|
|
|
"Greater",
|
|
|
|
"GreaterEqual",
|
|
|
|
"History",
|
|
|
|
"IFFT",
|
|
|
|
"Identity",
|
|
|
|
"Imag",
|
|
|
|
"InputSpec",
|
|
|
|
"IsFinite",
|
|
|
|
"IsInf",
|
|
|
|
"IsNan",
|
|
|
|
"KernelBackend",
|
|
|
|
"LRN",
|
|
|
|
"LRNBackprop",
|
|
|
|
"LayerVariable",
|
|
|
|
"LayersModel",
|
|
|
|
"Less",
|
|
|
|
"LessEqual",
|
|
|
|
"LinSpace",
|
|
|
|
"Log",
|
|
|
|
"Log1p",
|
|
|
|
"LogSoftmax",
|
|
|
|
"LogicalAnd",
|
|
|
|
"LogicalNot",
|
|
|
|
"LogicalOr",
|
|
|
|
"Max",
|
|
|
|
"MaxPool",
|
|
|
|
"MaxPool3D",
|
|
|
|
"MaxPool3DBackprop",
|
|
|
|
"MaxPoolBackprop",
|
|
|
|
"MaxPoolWithArgmax",
|
|
|
|
"Maximum",
|
|
|
|
"Mean",
|
|
|
|
"Min",
|
|
|
|
"Minimum",
|
|
|
|
"Mod",
|
|
|
|
"MomentumOptimizer",
|
|
|
|
"Multiply",
|
|
|
|
"Negate",
|
|
|
|
"NonMaxSuppressionV3",
|
|
|
|
"NonMaxSuppressionV4",
|
|
|
|
"NonMaxSuppressionV5",
|
|
|
|
"NotEqual",
|
|
|
|
"OP_SCOPE_SUFFIX",
|
|
|
|
"OneHot",
|
|
|
|
"OnesLike",
|
|
|
|
"Optimizer",
|
|
|
|
"PadV2",
|
|
|
|
"Pool",
|
|
|
|
"Pow",
|
|
|
|
"Prelu",
|
|
|
|
"Prod",
|
|
|
|
"RMSPropOptimizer",
|
|
|
|
"RNN",
|
|
|
|
"Range",
|
|
|
|
"Rank",
|
|
|
|
"Real",
|
|
|
|
"Reciprocal",
|
|
|
|
"Reduction",
|
|
|
|
"Relu",
|
|
|
|
"Relu6",
|
|
|
|
"Reshape",
|
|
|
|
"ResizeBilinear",
|
|
|
|
"ResizeBilinearGrad",
|
|
|
|
"ResizeNearestNeighbor",
|
|
|
|
"ResizeNearestNeighborGrad",
|
|
|
|
"Reverse",
|
|
|
|
"RotateWithOffset",
|
|
|
|
"Round",
|
|
|
|
"Rsqrt",
|
|
|
|
"SGDOptimizer",
|
|
|
|
"ScatterNd",
|
|
|
|
"SelectV2",
|
|
|
|
"Selu",
|
|
|
|
"Sequential",
|
|
|
|
"Sigmoid",
|
|
|
|
"Sign",
|
|
|
|
"Sin",
|
|
|
|
"Sinh",
|
|
|
|
"Slice",
|
|
|
|
"Softmax",
|
|
|
|
"Softplus",
|
|
|
|
"SpaceToBatchND",
|
|
|
|
"SparseToDense",
|
|
|
|
"SplitV",
|
|
|
|
"Sqrt",
|
|
|
|
"Square",
|
|
|
|
"SquaredDifference",
|
|
|
|
"Step",
|
|
|
|
"StridedSlice",
|
|
|
|
"Sub",
|
|
|
|
"Sum",
|
|
|
|
"SymbolicTensor",
|
|
|
|
"Tan",
|
|
|
|
"Tanh",
|
|
|
|
"Tensor",
|
|
|
|
"TensorBuffer",
|
|
|
|
"Tile",
|
|
|
|
"TopK",
|
|
|
|
"Transpose",
|
|
|
|
"Unique",
|
|
|
|
"Unpack",
|
|
|
|
"UnsortedSegmentSum",
|
|
|
|
"Variable",
|
|
|
|
"ZerosLike",
|
|
|
|
"_FusedMatMul",
|
|
|
|
"abs",
|
|
|
|
"acos",
|
|
|
|
"acosh",
|
|
|
|
"add",
|
|
|
|
"addN",
|
|
|
|
"addStrict",
|
|
|
|
"all",
|
|
|
|
"any",
|
|
|
|
"argMax",
|
|
|
|
"argMin",
|
|
|
|
"asin",
|
|
|
|
"asinh",
|
|
|
|
"atan",
|
|
|
|
"atan2",
|
|
|
|
"atanh",
|
|
|
|
"avgPool",
|
|
|
|
"avgPool3d",
|
|
|
|
"backend",
|
|
|
|
"backend_util",
|
|
|
|
"basicLSTMCell",
|
|
|
|
"batchNorm",
|
|
|
|
"batchNorm2d",
|
|
|
|
"batchNorm3d",
|
|
|
|
"batchNorm4d",
|
|
|
|
"batchToSpaceND",
|
|
|
|
"booleanMaskAsync",
|
|
|
|
"broadcastTo",
|
|
|
|
"browser",
|
|
|
|
"buffer",
|
|
|
|
"callbacks",
|
|
|
|
"cast",
|
|
|
|
"ceil",
|
|
|
|
"clipByValue",
|
|
|
|
"clone",
|
|
|
|
"complex",
|
|
|
|
"concat",
|
|
|
|
"concat1d",
|
|
|
|
"concat2d",
|
|
|
|
"concat3d",
|
|
|
|
"concat4d",
|
|
|
|
"constraints",
|
|
|
|
"conv1d",
|
|
|
|
"conv2d",
|
|
|
|
"conv2dTranspose",
|
|
|
|
"conv3d",
|
|
|
|
"conv3dTranspose",
|
|
|
|
"copyRegisteredKernels",
|
|
|
|
"cos",
|
|
|
|
"cosh",
|
|
|
|
"cosineWindow",
|
|
|
|
"cumsum",
|
|
|
|
"customGrad",
|
|
|
|
"data",
|
|
|
|
"default",
|
|
|
|
"deprecationWarn",
|
|
|
|
"depthToSpace",
|
|
|
|
"depthwiseConv2d",
|
|
|
|
"deregisterOp",
|
|
|
|
"device_util",
|
|
|
|
"diag",
|
|
|
|
"dilation2d",
|
|
|
|
"disableDeprecationWarnings",
|
|
|
|
"dispose",
|
|
|
|
"disposeVariables",
|
|
|
|
"div",
|
|
|
|
"divNoNan",
|
|
|
|
"divStrict",
|
|
|
|
"dot",
|
|
|
|
"dropout",
|
|
|
|
"elu",
|
|
|
|
"enableDebugMode",
|
|
|
|
"enableProdMode",
|
|
|
|
"enclosingPowerOfTwo",
|
|
|
|
"engine",
|
|
|
|
"env",
|
|
|
|
"equal",
|
|
|
|
"equalStrict",
|
|
|
|
"erf",
|
|
|
|
"exp",
|
|
|
|
"expandDims",
|
|
|
|
"expm1",
|
|
|
|
"eye",
|
|
|
|
"fft",
|
|
|
|
"fill",
|
|
|
|
"findBackend",
|
|
|
|
"findBackendFactory",
|
|
|
|
"floor",
|
|
|
|
"floorDiv",
|
|
|
|
"fused",
|
|
|
|
"gather",
|
|
|
|
"gatherND",
|
|
|
|
"gather_util",
|
|
|
|
"getBackend",
|
|
|
|
"getGradient",
|
|
|
|
"getKernel",
|
|
|
|
"getKernelsForBackend",
|
|
|
|
"grad",
|
|
|
|
"grads",
|
|
|
|
"greater",
|
|
|
|
"greaterEqual",
|
|
|
|
"greaterEqualStrict",
|
|
|
|
"greaterStrict",
|
|
|
|
"ifft",
|
|
|
|
"imag",
|
|
|
|
"image",
|
|
|
|
"inTopKAsync",
|
|
|
|
"initializers",
|
|
|
|
"input",
|
|
|
|
"io",
|
|
|
|
"irfft",
|
|
|
|
"isFinite",
|
|
|
|
"isInf",
|
|
|
|
"isNaN",
|
|
|
|
"keep",
|
|
|
|
"kernel_impls",
|
|
|
|
"layers",
|
|
|
|
"leakyRelu",
|
|
|
|
"less",
|
|
|
|
"lessEqual",
|
|
|
|
"lessEqualStrict",
|
|
|
|
"lessStrict",
|
|
|
|
"linalg",
|
|
|
|
"linspace",
|
|
|
|
"loadGraphModel",
|
|
|
|
"loadLayersModel",
|
|
|
|
"localResponseNormalization",
|
|
|
|
"log",
|
|
|
|
"log1p",
|
|
|
|
"logSigmoid",
|
|
|
|
"logSoftmax",
|
|
|
|
"logSumExp",
|
|
|
|
"logicalAnd",
|
|
|
|
"logicalNot",
|
|
|
|
"logicalOr",
|
|
|
|
"logicalXor",
|
|
|
|
"losses",
|
|
|
|
"matMul",
|
|
|
|
"math",
|
|
|
|
"max",
|
|
|
|
"maxPool",
|
|
|
|
"maxPool3d",
|
|
|
|
"maxPoolWithArgmax",
|
|
|
|
"maximum",
|
|
|
|
"maximumStrict",
|
|
|
|
"mean",
|
|
|
|
"memory",
|
|
|
|
"metrics",
|
|
|
|
"min",
|
|
|
|
"minimum",
|
|
|
|
"minimumStrict",
|
|
|
|
"mod",
|
|
|
|
"modStrict",
|
|
|
|
"model",
|
|
|
|
"models",
|
|
|
|
"moments",
|
|
|
|
"movingAverage",
|
|
|
|
"mul",
|
|
|
|
"mulStrict",
|
|
|
|
"multiRNNCell",
|
|
|
|
"multinomial",
|
|
|
|
"neg",
|
|
|
|
"nextFrame",
|
|
|
|
"norm",
|
|
|
|
"notEqual",
|
|
|
|
"notEqualStrict",
|
|
|
|
"oneHot",
|
|
|
|
"ones",
|
|
|
|
"onesLike",
|
|
|
|
"op",
|
|
|
|
"outerProduct",
|
|
|
|
"pad",
|
|
|
|
"pad1d",
|
|
|
|
"pad2d",
|
|
|
|
"pad3d",
|
|
|
|
"pad4d",
|
|
|
|
"pool",
|
|
|
|
"pow",
|
|
|
|
"powStrict",
|
|
|
|
"prelu",
|
|
|
|
"print",
|
|
|
|
"prod",
|
|
|
|
"profile",
|
|
|
|
"rand",
|
|
|
|
"randomGamma",
|
|
|
|
"randomNormal",
|
|
|
|
"randomUniform",
|
|
|
|
"range",
|
|
|
|
"ready",
|
|
|
|
"real",
|
|
|
|
"reciprocal",
|
|
|
|
"registerBackend",
|
|
|
|
"registerCallbackConstructor",
|
|
|
|
"registerGradient",
|
|
|
|
"registerKernel",
|
|
|
|
"registerOp",
|
|
|
|
"regularizers",
|
|
|
|
"relu",
|
|
|
|
"relu6",
|
|
|
|
"removeBackend",
|
|
|
|
"reshape",
|
|
|
|
"reverse",
|
|
|
|
"reverse1d",
|
|
|
|
"reverse2d",
|
|
|
|
"reverse3d",
|
|
|
|
"reverse4d",
|
|
|
|
"rfft",
|
|
|
|
"round",
|
|
|
|
"rsqrt",
|
|
|
|
"scalar",
|
|
|
|
"scatterND",
|
|
|
|
"scatter_util",
|
|
|
|
"selu",
|
|
|
|
"separableConv2d",
|
|
|
|
"sequential",
|
|
|
|
"serialization",
|
|
|
|
"setBackend",
|
|
|
|
"setPlatform",
|
|
|
|
"setdiff1dAsync",
|
|
|
|
"sigmoid",
|
|
|
|
"sign",
|
|
|
|
"signal",
|
|
|
|
"sin",
|
|
|
|
"sinh",
|
|
|
|
"slice",
|
|
|
|
"slice1d",
|
|
|
|
"slice2d",
|
|
|
|
"slice3d",
|
|
|
|
"slice4d",
|
|
|
|
"slice_util",
|
|
|
|
"softmax",
|
|
|
|
"softplus",
|
|
|
|
"spaceToBatchND",
|
|
|
|
"sparseToDense",
|
|
|
|
"spectral",
|
|
|
|
"split",
|
|
|
|
"sqrt",
|
|
|
|
"square",
|
|
|
|
"squaredDifference",
|
|
|
|
"squaredDifferenceStrict",
|
|
|
|
"squeeze",
|
|
|
|
"stack",
|
|
|
|
"step",
|
|
|
|
"stridedSlice",
|
|
|
|
"sub",
|
|
|
|
"subStrict",
|
|
|
|
"sum",
|
|
|
|
"sumOutType",
|
|
|
|
"tan",
|
|
|
|
"tanh",
|
|
|
|
"tensor",
|
|
|
|
"tensor1d",
|
|
|
|
"tensor2d",
|
|
|
|
"tensor3d",
|
|
|
|
"tensor4d",
|
|
|
|
"tensor5d",
|
|
|
|
"tensor6d",
|
|
|
|
"tensor_util",
|
|
|
|
"test_util",
|
|
|
|
"tidy",
|
|
|
|
"tile",
|
|
|
|
"time",
|
|
|
|
"topk",
|
|
|
|
"train",
|
|
|
|
"transpose",
|
|
|
|
"truncatedNormal",
|
|
|
|
"unique",
|
|
|
|
"unregisterGradient",
|
|
|
|
"unregisterKernel",
|
|
|
|
"unsortedSegmentSum",
|
|
|
|
"unstack",
|
|
|
|
"upcastType",
|
|
|
|
"util",
|
|
|
|
"valueAndGrad",
|
|
|
|
"valueAndGrads",
|
|
|
|
"variable",
|
|
|
|
"variableGrads",
|
|
|
|
"version",
|
|
|
|
"version_converter",
|
|
|
|
"version_core",
|
|
|
|
"version_layers",
|
|
|
|
"where",
|
|
|
|
"whereAsync",
|
|
|
|
"zeros",
|
|
|
|
"zerosLike",
|
|
|
|
],
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2020-12-21 22:27:18 +03:00
|
|
|
#[ignore = "Will be fixed by #1264"]
|
2020-12-27 13:02:41 +03:00
|
|
|
#[timeout(60000)]
|
2020-12-09 08:23:44 +03:00
|
|
|
fn deno_8620() {
|
|
|
|
run("tests/deno/deno-8620/entry.ts", &[])
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2020-12-27 13:02:41 +03:00
|
|
|
#[timeout(60000)]
|
2020-12-09 08:23:44 +03:00
|
|
|
#[ignore = "Requires newer version of deno"]
|
|
|
|
fn deno_8627() {
|
|
|
|
run("tests/deno/deno-8627/input.ts", &[])
|
|
|
|
}
|
2020-12-02 16:48:35 +03:00
|
|
|
|
2020-11-19 14:42:56 +03:00
|
|
|
#[test]
|
2020-12-27 13:02:41 +03:00
|
|
|
#[timeout(60000)]
|
2020-11-19 14:42:56 +03:00
|
|
|
fn merging_order_01() {
|
|
|
|
run(
|
|
|
|
"https://deno.land/x/oak@v6.3.1/multipart.ts",
|
|
|
|
&["FormDataReader"],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2020-12-27 13:02:41 +03:00
|
|
|
#[timeout(60000)]
|
2020-11-19 14:42:56 +03:00
|
|
|
fn reexport_01() {
|
|
|
|
run(
|
|
|
|
"https://raw.githubusercontent.com/aricart/tweetnacl-deno/import-type-fixes/src/nacl.ts",
|
|
|
|
&[
|
|
|
|
"AuthLength",
|
2021-04-24 07:28:38 +03:00
|
|
|
"BoxLength",
|
2020-11-19 14:42:56 +03:00
|
|
|
"ByteArray",
|
|
|
|
"HalfArray",
|
|
|
|
"HashLength",
|
|
|
|
"IntArray",
|
|
|
|
"NumArray",
|
2021-04-24 07:28:38 +03:00
|
|
|
"ScalarLength",
|
2020-11-19 14:42:56 +03:00
|
|
|
"SealedBoxLength",
|
2021-04-24 07:28:38 +03:00
|
|
|
"SecretBoxLength",
|
2020-11-19 14:42:56 +03:00
|
|
|
"SignLength",
|
|
|
|
"WordArray",
|
|
|
|
"_hash",
|
2021-04-24 07:28:38 +03:00
|
|
|
"_onetimeauth",
|
|
|
|
"_scalarMult",
|
|
|
|
"_scalarMult_base",
|
2020-11-19 14:42:56 +03:00
|
|
|
"_verify_16",
|
|
|
|
"_verify_32",
|
|
|
|
"auth",
|
|
|
|
"auth_full",
|
|
|
|
"blake2b",
|
|
|
|
"blake2b_final",
|
|
|
|
"blake2b_init",
|
|
|
|
"blake2b_update",
|
|
|
|
"blake2s",
|
|
|
|
"blake2s_final",
|
|
|
|
"blake2s_init",
|
|
|
|
"blake2s_update",
|
2021-04-24 07:28:38 +03:00
|
|
|
"box",
|
|
|
|
"box_after",
|
|
|
|
"box_before",
|
|
|
|
"box_keyPair",
|
|
|
|
"box_keyPair_fromSecretKey",
|
|
|
|
"box_open",
|
|
|
|
"box_open_after",
|
2020-11-19 14:42:56 +03:00
|
|
|
"decodeBase64",
|
|
|
|
"decodeHex",
|
|
|
|
"decodeUTF8",
|
|
|
|
"encodeBase64",
|
|
|
|
"encodeHex",
|
|
|
|
"encodeUTF8",
|
|
|
|
"hash",
|
|
|
|
"randomBytes",
|
2021-04-24 07:28:38 +03:00
|
|
|
"scalarMult",
|
|
|
|
"scalarMult_base",
|
2020-11-19 14:42:56 +03:00
|
|
|
"scalarbase",
|
|
|
|
"scalarmult",
|
|
|
|
"sealedbox",
|
|
|
|
"sealedbox_open",
|
2021-04-24 07:28:38 +03:00
|
|
|
"secretbox",
|
|
|
|
"secretbox_open",
|
2020-11-19 14:42:56 +03:00
|
|
|
"sign",
|
|
|
|
"sign_detached",
|
|
|
|
"sign_detached_verify",
|
|
|
|
"sign_keyPair",
|
|
|
|
"sign_keyPair_fromSecretKey",
|
|
|
|
"sign_keyPair_fromSeed",
|
|
|
|
"sign_open",
|
|
|
|
"validateBase64",
|
|
|
|
"validateHex",
|
|
|
|
"verify",
|
|
|
|
],
|
|
|
|
);
|
2020-11-06 12:42:04 +03:00
|
|
|
}
|
|
|
|
|
2020-11-19 14:42:56 +03:00
|
|
|
fn run(url: &str, exports: &[&str]) {
|
2020-10-14 17:28:38 +03:00
|
|
|
let dir = tempfile::tempdir().expect("failed to crate temp file");
|
|
|
|
let path = dir.path().join("main.js");
|
2021-04-14 17:00:33 +03:00
|
|
|
// println!("{}", path.display());
|
2020-10-14 17:28:38 +03:00
|
|
|
|
2021-10-21 14:56:48 +03:00
|
|
|
let src = bundle(url, false);
|
2020-10-14 17:28:38 +03:00
|
|
|
write(&path, &src).unwrap();
|
2020-11-19 14:42:56 +03:00
|
|
|
|
|
|
|
::testing::run_test2(false, |cm, _| {
|
|
|
|
let fm = cm.load_file(&path).unwrap();
|
2022-01-13 17:06:11 +03:00
|
|
|
let loader = Loader { cm };
|
2020-11-19 14:42:56 +03:00
|
|
|
let module = loader.load(&fm.name).unwrap().module;
|
|
|
|
|
|
|
|
let mut actual_exports = collect_exports(&module).into_iter().collect::<Vec<_>>();
|
|
|
|
actual_exports.sort();
|
2022-01-13 17:06:11 +03:00
|
|
|
let mut expected_exports = exports.iter().map(|s| s.to_string()).collect::<Vec<_>>();
|
2020-11-19 14:42:56 +03:00
|
|
|
expected_exports.sort();
|
|
|
|
|
|
|
|
assert_eq!(expected_exports, actual_exports);
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
})
|
|
|
|
.unwrap();
|
2020-10-14 17:28:38 +03:00
|
|
|
|
2021-04-14 17:00:33 +03:00
|
|
|
println!("{}", src);
|
2020-11-02 08:55:28 +03:00
|
|
|
|
2020-10-14 17:28:38 +03:00
|
|
|
let output = Command::new("deno")
|
|
|
|
.arg("run")
|
|
|
|
.arg("--no-check")
|
|
|
|
.arg(&path)
|
2021-12-29 13:19:44 +03:00
|
|
|
.output()
|
|
|
|
.expect("failed to get output from deno");
|
2020-10-14 17:28:38 +03:00
|
|
|
|
2021-12-29 13:19:44 +03:00
|
|
|
if !output.status.success() {
|
|
|
|
std::mem::forget(dir);
|
2020-10-14 17:28:38 +03:00
|
|
|
|
2021-12-29 13:19:44 +03:00
|
|
|
panic!(
|
|
|
|
"failed to execute:\n{}\n{}",
|
|
|
|
String::from_utf8_lossy(&output.stdout),
|
|
|
|
String::from_utf8_lossy(&output.stderr)
|
|
|
|
)
|
|
|
|
}
|
2020-10-02 05:07:40 +03:00
|
|
|
}
|
|
|
|
|
2021-10-21 14:56:48 +03:00
|
|
|
fn bundle(url: &str, minify: bool) -> String {
|
2022-01-13 17:06:11 +03:00
|
|
|
testing::run_test2(false, |cm, _handler| {
|
2020-10-02 05:07:40 +03:00
|
|
|
GLOBALS.with(|globals| {
|
2021-10-15 06:49:37 +03:00
|
|
|
let mut bundler = Bundler::new(
|
2020-10-02 05:07:40 +03:00
|
|
|
globals,
|
|
|
|
cm.clone(),
|
|
|
|
Loader { cm: cm.clone() },
|
2020-12-02 16:48:35 +03:00
|
|
|
NodeResolver,
|
2020-10-02 05:07:40 +03:00
|
|
|
swc_bundler::Config {
|
|
|
|
require: false,
|
2020-10-14 17:28:38 +03:00
|
|
|
disable_inliner: false,
|
2020-10-02 05:07:40 +03:00
|
|
|
..Default::default()
|
|
|
|
},
|
|
|
|
Box::new(Hook),
|
|
|
|
);
|
|
|
|
let mut entries = HashMap::new();
|
2020-11-19 14:42:56 +03:00
|
|
|
entries.insert(
|
|
|
|
"main".to_string(),
|
|
|
|
if url.starts_with("http") {
|
|
|
|
FileName::Custom(url.to_string())
|
|
|
|
} else {
|
|
|
|
FileName::Real(url.to_string().into())
|
|
|
|
},
|
|
|
|
);
|
2020-10-02 05:07:40 +03:00
|
|
|
let output = bundler.bundle(entries).unwrap();
|
2021-10-21 14:56:48 +03:00
|
|
|
let mut module = output.into_iter().next().unwrap().module;
|
|
|
|
|
|
|
|
if minify {
|
|
|
|
let top_level_mark = Mark::fresh(Mark::root());
|
|
|
|
|
|
|
|
module.visit_mut_with(&mut resolver_with_mark(top_level_mark));
|
|
|
|
|
|
|
|
module = swc_ecma_minifier::optimize(
|
|
|
|
module,
|
|
|
|
cm.clone(),
|
|
|
|
None,
|
|
|
|
None,
|
|
|
|
&swc_ecma_minifier::option::MinifyOptions {
|
|
|
|
compress: Some(Default::default()),
|
2021-10-24 13:52:09 +03:00
|
|
|
mangle: Some(MangleOptions {
|
|
|
|
top_level: true,
|
|
|
|
..Default::default()
|
|
|
|
}),
|
2021-10-21 14:56:48 +03:00
|
|
|
..Default::default()
|
|
|
|
},
|
|
|
|
&swc_ecma_minifier::option::ExtraOptions { top_level_mark },
|
|
|
|
);
|
|
|
|
module.visit_mut_with(&mut fixer(None));
|
|
|
|
}
|
2020-10-14 17:28:38 +03:00
|
|
|
|
|
|
|
let mut buf = vec![];
|
|
|
|
{
|
2021-10-21 14:56:48 +03:00
|
|
|
let mut wr: Box<dyn WriteJs> =
|
|
|
|
Box::new(JsWriter::new(cm.clone(), "\n", &mut buf, None));
|
|
|
|
|
|
|
|
if minify {
|
|
|
|
wr = Box::new(omit_trailing_semi(wr));
|
|
|
|
}
|
|
|
|
|
2020-10-14 17:28:38 +03:00
|
|
|
Emitter {
|
2021-10-21 14:56:48 +03:00
|
|
|
cfg: swc_ecma_codegen::Config { minify },
|
2020-10-14 17:28:38 +03:00
|
|
|
cm: cm.clone(),
|
|
|
|
comments: None,
|
2021-10-21 14:56:48 +03:00
|
|
|
wr,
|
2020-10-14 17:28:38 +03:00
|
|
|
}
|
|
|
|
.emit_module(&module)
|
|
|
|
.unwrap();
|
|
|
|
}
|
2020-10-02 05:07:40 +03:00
|
|
|
|
2020-10-14 17:28:38 +03:00
|
|
|
Ok(String::from_utf8_lossy(&buf).to_string())
|
2020-10-02 05:07:40 +03:00
|
|
|
})
|
|
|
|
})
|
2022-01-13 17:06:11 +03:00
|
|
|
.unwrap()
|
2020-10-02 05:07:40 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
struct Hook;
|
|
|
|
|
|
|
|
impl swc_bundler::Hook for Hook {
|
2020-11-02 09:22:21 +03:00
|
|
|
fn get_import_meta_props(
|
|
|
|
&self,
|
|
|
|
span: Span,
|
|
|
|
module_record: &ModuleRecord,
|
|
|
|
) -> Result<Vec<KeyValueProp>, Error> {
|
2022-03-22 10:54:08 +03:00
|
|
|
let file_name = module_record.file_name.to_string();
|
|
|
|
|
2020-11-02 09:22:21 +03:00
|
|
|
Ok(vec![
|
|
|
|
KeyValueProp {
|
|
|
|
key: PropName::Ident(Ident::new(js_word!("url"), span)),
|
|
|
|
value: Box::new(Expr::Lit(Lit::Str(Str {
|
|
|
|
span,
|
2022-03-22 10:54:08 +03:00
|
|
|
raw: None,
|
|
|
|
value: file_name.into(),
|
2020-11-02 09:22:21 +03:00
|
|
|
}))),
|
|
|
|
},
|
|
|
|
KeyValueProp {
|
|
|
|
key: PropName::Ident(Ident::new(js_word!("main"), span)),
|
|
|
|
value: Box::new(if module_record.is_entry {
|
|
|
|
Expr::Member(MemberExpr {
|
|
|
|
span,
|
2022-01-10 16:54:42 +03:00
|
|
|
obj: Box::new(Expr::MetaProp(MetaPropExpr {
|
|
|
|
span,
|
|
|
|
kind: MetaPropKind::ImportMeta,
|
|
|
|
})),
|
|
|
|
prop: MemberProp::Ident(Ident::new(js_word!("main"), span)),
|
2020-11-02 09:22:21 +03:00
|
|
|
})
|
|
|
|
} else {
|
|
|
|
Expr::Lit(Lit::Bool(Bool { span, value: false }))
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
])
|
2020-10-02 05:07:40 +03:00
|
|
|
}
|
|
|
|
}
|
2020-11-19 14:42:56 +03:00
|
|
|
|
2021-08-14 13:33:16 +03:00
|
|
|
fn collect_exports(module: &Module) -> AHashSet<String> {
|
2020-11-19 14:42:56 +03:00
|
|
|
let mut v = ExportCollector::default();
|
2021-12-07 08:34:16 +03:00
|
|
|
module.visit_with(&mut v);
|
2020-11-19 14:42:56 +03:00
|
|
|
|
|
|
|
v.exports
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Default)]
|
|
|
|
struct ExportCollector {
|
2021-08-14 13:33:16 +03:00
|
|
|
exports: AHashSet<String>,
|
2020-11-19 14:42:56 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Visit for ExportCollector {
|
2021-12-07 08:34:16 +03:00
|
|
|
fn visit_export_specifier(&mut self, s: &ExportSpecifier) {
|
2020-11-19 14:42:56 +03:00
|
|
|
match s {
|
|
|
|
ExportSpecifier::Namespace(ns) => {
|
2022-01-06 14:19:11 +03:00
|
|
|
match &ns.name {
|
|
|
|
ModuleExportName::Ident(name) => {
|
|
|
|
self.exports.insert(name.sym.to_string());
|
|
|
|
}
|
|
|
|
ModuleExportName::Str(..) => {
|
|
|
|
unimplemented!("module string names unimplemented")
|
|
|
|
}
|
|
|
|
};
|
2020-11-19 14:42:56 +03:00
|
|
|
}
|
|
|
|
ExportSpecifier::Default(_) => {
|
|
|
|
self.exports.insert("default".into());
|
|
|
|
}
|
|
|
|
ExportSpecifier::Named(named) => {
|
2022-01-03 11:44:11 +03:00
|
|
|
let exported_ident = match &named.exported {
|
|
|
|
Some(ModuleExportName::Ident(ident)) => Some(ident),
|
|
|
|
Some(ModuleExportName::Str(..)) => {
|
|
|
|
unimplemented!("module string names unimplemented")
|
|
|
|
}
|
|
|
|
_ => None,
|
|
|
|
};
|
2020-11-19 14:42:56 +03:00
|
|
|
self.exports.insert(
|
2022-01-03 11:44:11 +03:00
|
|
|
exported_ident
|
|
|
|
.unwrap_or(match &named.orig {
|
|
|
|
ModuleExportName::Ident(ident) => ident,
|
|
|
|
ModuleExportName::Str(..) => {
|
|
|
|
unimplemented!("module string names unimplemented")
|
|
|
|
}
|
|
|
|
})
|
2020-11-19 14:42:56 +03:00
|
|
|
.sym
|
|
|
|
.to_string(),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-07 08:34:16 +03:00
|
|
|
fn visit_export_default_decl(&mut self, _: &ExportDefaultDecl) {
|
2020-11-19 14:42:56 +03:00
|
|
|
self.exports.insert("default".into());
|
|
|
|
}
|
|
|
|
|
2021-12-07 08:34:16 +03:00
|
|
|
fn visit_export_default_expr(&mut self, _: &ExportDefaultExpr) {
|
2020-11-19 14:42:56 +03:00
|
|
|
self.exports.insert("default".into());
|
|
|
|
}
|
|
|
|
|
2021-12-07 08:34:16 +03:00
|
|
|
fn visit_export_decl(&mut self, export: &ExportDecl) {
|
2020-11-19 14:42:56 +03:00
|
|
|
match &export.decl {
|
|
|
|
swc_ecma_ast::Decl::Class(ClassDecl { ident, .. })
|
|
|
|
| swc_ecma_ast::Decl::Fn(FnDecl { ident, .. }) => {
|
|
|
|
self.exports.insert(ident.sym.to_string());
|
|
|
|
}
|
|
|
|
swc_ecma_ast::Decl::Var(var) => {
|
|
|
|
let ids: Vec<Id> = find_ids(var);
|
|
|
|
self.exports
|
|
|
|
.extend(ids.into_iter().map(|v| v.0.to_string()));
|
|
|
|
}
|
|
|
|
_ => {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-12-27 13:02:41 +03:00
|
|
|
|
2021-07-29 08:18:21 +03:00
|
|
|
#[testing::fixture("tests/deno-exec/**/entry.ts")]
|
2020-12-27 13:02:41 +03:00
|
|
|
fn exec(input: PathBuf) {
|
|
|
|
let dir = tempfile::tempdir().expect("failed to crate temp file");
|
|
|
|
let path = dir.path().join("main.js");
|
|
|
|
println!("{}", path.display());
|
|
|
|
|
2021-10-21 14:56:48 +03:00
|
|
|
let src = bundle(&input.to_string_lossy(), false);
|
|
|
|
write(&path, &src).unwrap();
|
|
|
|
|
|
|
|
// println!("{}", src);
|
|
|
|
|
|
|
|
let output = Command::new("deno")
|
|
|
|
.arg("run")
|
|
|
|
.arg("--no-check")
|
|
|
|
.arg("--allow-net")
|
|
|
|
.arg(&path)
|
2021-12-29 13:19:44 +03:00
|
|
|
.output()
|
2021-10-21 14:56:48 +03:00
|
|
|
.unwrap();
|
|
|
|
|
2021-12-29 13:19:44 +03:00
|
|
|
if !output.status.success() {
|
|
|
|
std::mem::forget(dir);
|
2021-10-21 14:56:48 +03:00
|
|
|
|
2021-12-29 13:19:44 +03:00
|
|
|
panic!(
|
|
|
|
"failed to execute:\n{}\n{}",
|
|
|
|
String::from_utf8_lossy(&output.stdout),
|
|
|
|
String::from_utf8_lossy(&output.stderr)
|
|
|
|
)
|
|
|
|
}
|
2021-10-21 14:56:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#[testing::fixture("tests/deno-exec/**/entry.ts")]
|
|
|
|
fn exec_minified(input: PathBuf) {
|
|
|
|
// TODO: Fix the bug.
|
|
|
|
if input.to_string_lossy().contains("deno-9464") {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-10-24 13:52:09 +03:00
|
|
|
{
|
|
|
|
let dir = tempfile::tempdir().expect("failed to crate temp file");
|
|
|
|
let path = dir.path().join("main.js");
|
|
|
|
println!("Unminified: {}", path.display());
|
|
|
|
|
|
|
|
let src = bundle(&input.to_string_lossy(), false);
|
|
|
|
write(&path, &src).unwrap();
|
|
|
|
|
|
|
|
std::mem::forget(dir);
|
|
|
|
}
|
|
|
|
|
2021-10-21 14:56:48 +03:00
|
|
|
let dir = tempfile::tempdir().expect("failed to crate temp file");
|
|
|
|
let path = dir.path().join("main.js");
|
|
|
|
println!("{}", path.display());
|
|
|
|
|
|
|
|
let src = bundle(&input.to_string_lossy(), true);
|
2020-12-27 13:02:41 +03:00
|
|
|
write(&path, &src).unwrap();
|
2021-04-14 17:00:33 +03:00
|
|
|
// println!("{}", src);
|
2020-12-27 13:02:41 +03:00
|
|
|
|
|
|
|
let output = Command::new("deno")
|
|
|
|
.arg("run")
|
|
|
|
.arg("--no-check")
|
2021-04-14 17:00:33 +03:00
|
|
|
.arg("--allow-net")
|
2020-12-27 13:02:41 +03:00
|
|
|
.arg(&path)
|
2021-12-29 13:19:44 +03:00
|
|
|
.output()
|
2020-12-27 13:02:41 +03:00
|
|
|
.unwrap();
|
|
|
|
|
2021-12-29 13:19:44 +03:00
|
|
|
if !output.status.success() {
|
|
|
|
std::mem::forget(dir);
|
2020-12-27 13:02:41 +03:00
|
|
|
|
2021-12-29 13:19:44 +03:00
|
|
|
panic!(
|
|
|
|
"failed to execute:\n{}\n{}",
|
|
|
|
String::from_utf8_lossy(&output.stdout),
|
|
|
|
String::from_utf8_lossy(&output.stderr)
|
|
|
|
)
|
|
|
|
}
|
2020-12-27 13:02:41 +03:00
|
|
|
}
|