mirror of
https://github.com/swc-project/swc.git
synced 2024-10-05 04:39:06 +03:00
fix(es): Fix bugs (#2222)
swc_ecma_parser: - Don't panic on `typeof import(T)`. (#2198) - Fix parsing of ternary. (#2196) swc_ecma_transforms_base: - `fixer`: Handle unary in lhs of an exponentation expression. (#2191) swc_ecma_transforms_compat: - Use variable for `this` in arrow expressions. (#2212) swc_ecma_visit: - Add a trait `InjectVars`. node_swc: - Increease recursion limit while deserializing. (#2223)
This commit is contained in:
parent
a9573b9a5f
commit
2c477780f0
52
Cargo.lock
generated
52
Cargo.lock
generated
@ -939,7 +939,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "jsdoc"
|
||||
version = "0.38.0"
|
||||
version = "0.38.1"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"dashmap",
|
||||
@ -2287,7 +2287,7 @@ checksum = "6446ced80d6c486436db5c078dde11a9f73d42b57fb273121e160b84f63d894c"
|
||||
|
||||
[[package]]
|
||||
name = "swc"
|
||||
version = "0.51.0"
|
||||
version = "0.51.1"
|
||||
dependencies = [
|
||||
"ahash",
|
||||
"anyhow",
|
||||
@ -2392,7 +2392,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "swc_bundler"
|
||||
version = "0.58.0"
|
||||
version = "0.58.1"
|
||||
dependencies = [
|
||||
"ahash",
|
||||
"anyhow",
|
||||
@ -2557,7 +2557,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "swc_ecma_codegen"
|
||||
version = "0.70.1"
|
||||
version = "0.70.2"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"num-bigint",
|
||||
@ -2583,7 +2583,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "swc_ecma_dep_graph"
|
||||
version = "0.39.0"
|
||||
version = "0.39.1"
|
||||
dependencies = [
|
||||
"swc_atoms 0.2.7",
|
||||
"swc_common",
|
||||
@ -2595,7 +2595,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "swc_ecma_ext_transforms"
|
||||
version = "0.28.0"
|
||||
version = "0.28.1"
|
||||
dependencies = [
|
||||
"phf",
|
||||
"swc_atoms 0.2.7",
|
||||
@ -2608,7 +2608,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "swc_ecma_loader"
|
||||
version = "0.18.0"
|
||||
version = "0.18.1"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"dashmap",
|
||||
@ -2629,7 +2629,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "swc_ecma_minifier"
|
||||
version = "0.27.1"
|
||||
version = "0.27.2"
|
||||
dependencies = [
|
||||
"ansi_term 0.12.1",
|
||||
"anyhow",
|
||||
@ -2661,7 +2661,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "swc_ecma_parser"
|
||||
version = "0.70.1"
|
||||
version = "0.70.2"
|
||||
dependencies = [
|
||||
"either",
|
||||
"enum_kind",
|
||||
@ -2685,7 +2685,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "swc_ecma_preset_env"
|
||||
version = "0.42.0"
|
||||
version = "0.42.1"
|
||||
dependencies = [
|
||||
"dashmap",
|
||||
"fxhash",
|
||||
@ -2711,7 +2711,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "swc_ecma_transforms"
|
||||
version = "0.71.0"
|
||||
version = "0.71.1"
|
||||
dependencies = [
|
||||
"pretty_assertions 0.6.1",
|
||||
"sourcemap",
|
||||
@ -2738,7 +2738,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "swc_ecma_transforms_base"
|
||||
version = "0.31.0"
|
||||
version = "0.31.1"
|
||||
dependencies = [
|
||||
"fxhash",
|
||||
"once_cell",
|
||||
@ -2757,7 +2757,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "swc_ecma_transforms_classes"
|
||||
version = "0.17.0"
|
||||
version = "0.17.1"
|
||||
dependencies = [
|
||||
"swc_atoms 0.2.7",
|
||||
"swc_common",
|
||||
@ -2769,7 +2769,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "swc_ecma_transforms_compat"
|
||||
version = "0.34.0"
|
||||
version = "0.34.1"
|
||||
dependencies = [
|
||||
"arrayvec",
|
||||
"fxhash",
|
||||
@ -2805,7 +2805,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "swc_ecma_transforms_module"
|
||||
version = "0.38.0"
|
||||
version = "0.38.1"
|
||||
dependencies = [
|
||||
"Inflector",
|
||||
"anyhow",
|
||||
@ -2828,7 +2828,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "swc_ecma_transforms_optimization"
|
||||
version = "0.41.0"
|
||||
version = "0.41.1"
|
||||
dependencies = [
|
||||
"dashmap",
|
||||
"fxhash",
|
||||
@ -2855,7 +2855,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "swc_ecma_transforms_proposal"
|
||||
version = "0.38.0"
|
||||
version = "0.38.1"
|
||||
dependencies = [
|
||||
"either",
|
||||
"fxhash",
|
||||
@ -2877,7 +2877,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "swc_ecma_transforms_react"
|
||||
version = "0.39.0"
|
||||
version = "0.39.1"
|
||||
dependencies = [
|
||||
"base64 0.13.0",
|
||||
"dashmap",
|
||||
@ -2903,7 +2903,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "swc_ecma_transforms_testing"
|
||||
version = "0.32.0"
|
||||
version = "0.32.1"
|
||||
dependencies = [
|
||||
"ansi_term 0.12.1",
|
||||
"anyhow",
|
||||
@ -2922,7 +2922,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "swc_ecma_transforms_typescript"
|
||||
version = "0.40.1"
|
||||
version = "0.40.2"
|
||||
dependencies = [
|
||||
"fxhash",
|
||||
"serde",
|
||||
@ -2944,7 +2944,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "swc_ecma_utils"
|
||||
version = "0.44.1"
|
||||
version = "0.44.2"
|
||||
dependencies = [
|
||||
"once_cell",
|
||||
"scoped-tls",
|
||||
@ -2958,7 +2958,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "swc_ecma_visit"
|
||||
version = "0.38.0"
|
||||
version = "0.38.1"
|
||||
dependencies = [
|
||||
"num-bigint",
|
||||
"swc_atoms 0.2.7",
|
||||
@ -2969,7 +2969,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "swc_ecmascript"
|
||||
version = "0.63.0"
|
||||
version = "0.63.1"
|
||||
dependencies = [
|
||||
"swc_ecma_ast",
|
||||
"swc_ecma_codegen",
|
||||
@ -3046,7 +3046,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "swc_plugin"
|
||||
version = "0.4.0"
|
||||
version = "0.4.1"
|
||||
dependencies = [
|
||||
"abi_stable",
|
||||
"anyhow",
|
||||
@ -3061,7 +3061,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "swc_plugin_runner"
|
||||
version = "0.4.0"
|
||||
version = "0.4.1"
|
||||
dependencies = [
|
||||
"abi_stable",
|
||||
"anyhow",
|
||||
@ -3079,7 +3079,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "swc_plugin_testing"
|
||||
version = "0.4.0"
|
||||
version = "0.4.1"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"swc_atoms 0.2.7",
|
||||
|
26
Cargo.toml
26
Cargo.toml
@ -20,7 +20,7 @@ edition = "2018"
|
||||
license = "Apache-2.0/MIT"
|
||||
name = "swc"
|
||||
repository = "https://github.com/swc-project/swc.git"
|
||||
version = "0.51.0"
|
||||
version = "0.51.1"
|
||||
|
||||
[lib]
|
||||
name = "swc"
|
||||
@ -46,16 +46,16 @@ serde = {version = "1", features = ["derive"]}
|
||||
serde_json = "1"
|
||||
sourcemap = "6"
|
||||
swc_atoms = {version = "0.2", path = "./atoms"}
|
||||
swc_bundler = {version = "0.58.0", path = "./bundler"}
|
||||
swc_bundler = {version = "0.58.1", path = "./bundler"}
|
||||
swc_common = {version = "0.12.0", path = "./common", features = ["sourcemap", "concurrent"]}
|
||||
swc_ecma_ast = {version = "0.52.0", path = "./ecmascript/ast"}
|
||||
swc_ecma_codegen = {version = "0.70.0", path = "./ecmascript/codegen"}
|
||||
swc_ecma_ext_transforms = {version = "0.28.0", path = "./ecmascript/ext-transforms"}
|
||||
swc_ecma_loader = {version = "0.18.0", path = "./ecmascript/loader", features = ["lru", "node", "tsc"]}
|
||||
swc_ecma_minifier = {version = "0.27.0", path = "./ecmascript/minifier"}
|
||||
swc_ecma_parser = {version = "0.70.0", path = "./ecmascript/parser"}
|
||||
swc_ecma_preset_env = {version = "0.42.0", path = "./ecmascript/preset-env"}
|
||||
swc_ecma_transforms = {version = "0.71.0", path = "./ecmascript/transforms", features = [
|
||||
swc_ecma_codegen = {version = "0.70.2", path = "./ecmascript/codegen"}
|
||||
swc_ecma_ext_transforms = {version = "0.28.1", path = "./ecmascript/ext-transforms"}
|
||||
swc_ecma_loader = {version = "0.18.1", path = "./ecmascript/loader", features = ["lru", "node", "tsc"]}
|
||||
swc_ecma_minifier = {version = "0.27.2", path = "./ecmascript/minifier"}
|
||||
swc_ecma_parser = {version = "0.70.2", path = "./ecmascript/parser"}
|
||||
swc_ecma_preset_env = {version = "0.42.1", path = "./ecmascript/preset-env"}
|
||||
swc_ecma_transforms = {version = "0.71.1", path = "./ecmascript/transforms", features = [
|
||||
"compat",
|
||||
"module",
|
||||
"optimization",
|
||||
@ -63,10 +63,10 @@ swc_ecma_transforms = {version = "0.71.0", path = "./ecmascript/transforms", fea
|
||||
"react",
|
||||
"typescript",
|
||||
]}
|
||||
swc_ecma_transforms_base = {version = "0.31.0", path = "./ecmascript/transforms/base"}
|
||||
swc_ecma_utils = {version = "0.44.0", path = "./ecmascript/utils"}
|
||||
swc_ecma_visit = {version = "0.38.0", path = "./ecmascript/visit"}
|
||||
swc_ecmascript = {version = "0.63.0", path = "./ecmascript"}
|
||||
swc_ecma_transforms_base = {version = "0.31.1", path = "./ecmascript/transforms/base"}
|
||||
swc_ecma_utils = {version = "0.44.2", path = "./ecmascript/utils"}
|
||||
swc_ecma_visit = {version = "0.38.1", path = "./ecmascript/visit"}
|
||||
swc_ecmascript = {version = "0.63.1", path = "./ecmascript"}
|
||||
swc_node_base = {version = "0.3.0", path = "./node/base"}
|
||||
swc_visit = {version = "0.2.3", path = "./visit"}
|
||||
|
||||
|
@ -9,7 +9,7 @@ include = ["Cargo.toml", "build.rs", "src/**/*.rs", "src/**/*.js"]
|
||||
license = "Apache-2.0/MIT"
|
||||
name = "swc_bundler"
|
||||
repository = "https://github.com/swc-project/swc.git"
|
||||
version = "0.58.0"
|
||||
version = "0.58.1"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
[features]
|
||||
@ -34,19 +34,19 @@ retain_mut = "0.1.2"
|
||||
swc_atoms = {version = "0.2.4", path = "../atoms"}
|
||||
swc_common = {version = "0.12.0", path = "../common"}
|
||||
swc_ecma_ast = {version = "0.52.0", path = "../ecmascript/ast"}
|
||||
swc_ecma_codegen = {version = "0.70.0", path = "../ecmascript/codegen"}
|
||||
swc_ecma_loader = {version = "0.18.0", path = "../ecmascript/loader"}
|
||||
swc_ecma_parser = {version = "0.70.0", path = "../ecmascript/parser"}
|
||||
swc_ecma_transforms = {version = "0.71.0", path = "../ecmascript/transforms", features = ["optimization"]}
|
||||
swc_ecma_utils = {version = "0.44.0", path = "../ecmascript/utils"}
|
||||
swc_ecma_visit = {version = "0.38.0", path = "../ecmascript/visit"}
|
||||
swc_ecma_codegen = {version = "0.70.2", path = "../ecmascript/codegen"}
|
||||
swc_ecma_loader = {version = "0.18.1", path = "../ecmascript/loader"}
|
||||
swc_ecma_parser = {version = "0.70.2", path = "../ecmascript/parser"}
|
||||
swc_ecma_transforms = {version = "0.71.1", path = "../ecmascript/transforms", features = ["optimization"]}
|
||||
swc_ecma_utils = {version = "0.44.2", path = "../ecmascript/utils"}
|
||||
swc_ecma_visit = {version = "0.38.1", path = "../ecmascript/visit"}
|
||||
|
||||
[dev-dependencies]
|
||||
hex = "0.4"
|
||||
ntest = "0.7.2"
|
||||
reqwest = {version = "0.11.4", features = ["blocking"]}
|
||||
sha-1 = "0.9"
|
||||
swc_ecma_transforms = {version = "0.71.0", path = "../ecmascript/transforms", features = ["react", "typescript"]}
|
||||
swc_ecma_transforms = {version = "0.71.1", path = "../ecmascript/transforms", features = ["react", "typescript"]}
|
||||
tempfile = "3.1.0"
|
||||
testing = {version = "0.13.0", path = "../testing"}
|
||||
url = "2.1.1"
|
||||
|
@ -6,7 +6,7 @@ edition = "2018"
|
||||
license = "Apache-2.0/MIT"
|
||||
name = "swc_ecmascript"
|
||||
repository = "https://github.com/swc-project/swc.git"
|
||||
version = "0.63.0"
|
||||
version = "0.63.1"
|
||||
|
||||
[package.metadata.docs.rs]
|
||||
all-features = true
|
||||
@ -33,13 +33,13 @@ typescript = ["typescript-parser", "swc_ecma_transforms/typescript"]
|
||||
|
||||
[dependencies]
|
||||
swc_ecma_ast = {version = "0.52.0", path = "./ast"}
|
||||
swc_ecma_codegen = {version = "0.70.0", path = "./codegen", optional = true}
|
||||
swc_ecma_dep_graph = {version = "0.39.0", path = "./dep-graph", optional = true}
|
||||
swc_ecma_minifier = {version = "0.27.0", path = "./minifier", optional = true}
|
||||
swc_ecma_parser = {version = "0.70.0", path = "./parser", optional = true, default-features = false}
|
||||
swc_ecma_preset_env = {version = "0.42.0", path = "./preset-env", optional = true}
|
||||
swc_ecma_transforms = {version = "0.71.0", path = "./transforms", optional = true}
|
||||
swc_ecma_utils = {version = "0.44.0", path = "./utils", optional = true}
|
||||
swc_ecma_visit = {version = "0.38.0", path = "./visit", optional = true}
|
||||
swc_ecma_codegen = {version = "0.70.2", path = "./codegen", optional = true}
|
||||
swc_ecma_dep_graph = {version = "0.39.1", path = "./dep-graph", optional = true}
|
||||
swc_ecma_minifier = {version = "0.27.2", path = "./minifier", optional = true}
|
||||
swc_ecma_parser = {version = "0.70.2", path = "./parser", optional = true, default-features = false}
|
||||
swc_ecma_preset_env = {version = "0.42.1", path = "./preset-env", optional = true}
|
||||
swc_ecma_transforms = {version = "0.71.1", path = "./transforms", optional = true}
|
||||
swc_ecma_utils = {version = "0.44.2", path = "./utils", optional = true}
|
||||
swc_ecma_visit = {version = "0.38.1", path = "./visit", optional = true}
|
||||
|
||||
[dev-dependencies]
|
||||
|
@ -7,7 +7,7 @@ include = ["Cargo.toml", "src/**/*.rs"]
|
||||
license = "Apache-2.0/MIT"
|
||||
name = "swc_ecma_codegen"
|
||||
repository = "https://github.com/swc-project/swc.git"
|
||||
version = "0.70.1"
|
||||
version = "0.70.2"
|
||||
|
||||
[dependencies]
|
||||
bitflags = "1"
|
||||
@ -17,7 +17,7 @@ swc_atoms = {version = "0.2", path = "../../atoms"}
|
||||
swc_common = {version = "0.12.0", path = "../../common"}
|
||||
swc_ecma_ast = {version = "0.52.0", path = "../ast"}
|
||||
swc_ecma_codegen_macros = {version = "0.5.2", path = "./macros"}
|
||||
swc_ecma_parser = {version = "0.70.0", path = "../parser"}
|
||||
swc_ecma_parser = {version = "0.70.2", path = "../parser"}
|
||||
|
||||
[dev-dependencies]
|
||||
swc_common = {version = "0.12.0", path = "../../common", features = ["sourcemap"]}
|
||||
|
@ -6,14 +6,14 @@ edition = "2018"
|
||||
license = "Apache-2.0/MIT"
|
||||
name = "swc_ecma_dep_graph"
|
||||
repository = "https://github.com/swc-project/swc.git"
|
||||
version = "0.39.0"
|
||||
version = "0.39.1"
|
||||
|
||||
[dependencies]
|
||||
swc_atoms = {version = "0.2", path = "../../atoms"}
|
||||
swc_common = {version = "0.12.0", path = "../../common"}
|
||||
swc_ecma_ast = {version = "0.52.0", path = "../ast"}
|
||||
swc_ecma_visit = {version = "0.38.0", path = "../visit"}
|
||||
swc_ecma_visit = {version = "0.38.1", path = "../visit"}
|
||||
|
||||
[dev-dependencies]
|
||||
swc_ecma_parser = {version = "0.70.0", path = "../parser"}
|
||||
swc_ecma_parser = {version = "0.70.2", path = "../parser"}
|
||||
testing = {version = "0.13.0", path = "../../testing"}
|
||||
|
@ -5,7 +5,7 @@ documentation = "https://rustdoc.swc.rs/swc_ecma_ext_transforms/"
|
||||
edition = "2018"
|
||||
license = "Apache-2.0/MIT"
|
||||
name = "swc_ecma_ext_transforms"
|
||||
version = "0.28.0"
|
||||
version = "0.28.1"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
@ -14,6 +14,6 @@ phf = {version = "0.8.0", features = ["macros"]}
|
||||
swc_atoms = {version = "0.2", path = "../../atoms"}
|
||||
swc_common = {version = "0.12.0", path = "../../common"}
|
||||
swc_ecma_ast = {version = "0.52.0", path = "../ast"}
|
||||
swc_ecma_parser = {version = "0.70.0", path = "../parser"}
|
||||
swc_ecma_utils = {version = "0.44.0", path = "../utils"}
|
||||
swc_ecma_visit = {version = "0.38.0", path = "../visit"}
|
||||
swc_ecma_parser = {version = "0.70.2", path = "../parser"}
|
||||
swc_ecma_utils = {version = "0.44.2", path = "../utils"}
|
||||
swc_ecma_visit = {version = "0.38.1", path = "../visit"}
|
||||
|
@ -5,7 +5,7 @@ documentation = "https://rustdoc.swc.rs/jsdoc/"
|
||||
edition = "2018"
|
||||
license = "Apache-2.0/MIT"
|
||||
name = "jsdoc"
|
||||
version = "0.38.0"
|
||||
version = "0.38.1"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
@ -19,6 +19,6 @@ swc_common = {version = "0.12.0", path = "../../common"}
|
||||
anyhow = "1"
|
||||
dashmap = "4.0.2"
|
||||
swc_ecma_ast = {version = "0.52.0", path = "../ast"}
|
||||
swc_ecma_parser = {version = "0.70.0", path = "../parser"}
|
||||
swc_ecma_parser = {version = "0.70.2", path = "../parser"}
|
||||
testing = {version = "0.13.0", path = "../../testing"}
|
||||
walkdir = "2"
|
||||
|
@ -6,7 +6,7 @@ edition = "2018"
|
||||
license = "Apache-2.0/MIT"
|
||||
name = "swc_ecma_loader"
|
||||
repository = "https://github.com/swc-project/swc.git"
|
||||
version = "0.18.0"
|
||||
version = "0.18.1"
|
||||
|
||||
[package.metadata.docs.rs]
|
||||
all-features = true
|
||||
@ -32,7 +32,7 @@ serde_json = {version = "1.0.64", optional = true}
|
||||
swc_atoms = {version = "0.2.3", path = "../../atoms"}
|
||||
swc_common = {version = "0.12.0", path = "../../common"}
|
||||
swc_ecma_ast = {version = "0.52.0", path = "../ast"}
|
||||
swc_ecma_visit = {version = "0.38.0", path = "../visit"}
|
||||
swc_ecma_visit = {version = "0.38.1", path = "../visit"}
|
||||
|
||||
[dev-dependencies]
|
||||
testing = {version = "0.13.0", path = "../../testing"}
|
||||
|
@ -7,7 +7,7 @@ include = ["Cargo.toml", "src/**/*.rs", "src/lists/*.json"]
|
||||
license = "Apache-2.0/MIT"
|
||||
name = "swc_ecma_minifier"
|
||||
repository = "https://github.com/swc-project/swc.git"
|
||||
version = "0.27.1"
|
||||
version = "0.27.2"
|
||||
|
||||
[features]
|
||||
debug = []
|
||||
@ -27,12 +27,12 @@ serde_regex = "1.1.0"
|
||||
swc_atoms = {version = "0.2", path = "../../atoms"}
|
||||
swc_common = {version = "0.12.0", path = "../../common"}
|
||||
swc_ecma_ast = {version = "0.52.0", path = "../ast"}
|
||||
swc_ecma_codegen = {version = "0.70.0", path = "../codegen"}
|
||||
swc_ecma_parser = {version = "0.70.0", path = "../parser"}
|
||||
swc_ecma_transforms = {version = "0.71.0", path = "../transforms/", features = ["optimization"]}
|
||||
swc_ecma_transforms_base = {version = "0.31.0", path = "../transforms/base"}
|
||||
swc_ecma_utils = {version = "0.44.0", path = "../utils"}
|
||||
swc_ecma_visit = {version = "0.38.0", path = "../visit"}
|
||||
swc_ecma_codegen = {version = "0.70.2", path = "../codegen"}
|
||||
swc_ecma_parser = {version = "0.70.2", path = "../parser"}
|
||||
swc_ecma_transforms = {version = "0.71.1", path = "../transforms/", features = ["optimization"]}
|
||||
swc_ecma_transforms_base = {version = "0.31.1", path = "../transforms/base"}
|
||||
swc_ecma_utils = {version = "0.44.2", path = "../utils"}
|
||||
swc_ecma_visit = {version = "0.38.1", path = "../visit"}
|
||||
unicode-xid = "0.2.2"
|
||||
|
||||
[dev-dependencies]
|
||||
|
@ -443,17 +443,16 @@ fn fixture(input: PathBuf) {
|
||||
}
|
||||
}
|
||||
|
||||
let output_str = print(cm.clone(), &[drop_span(output_module.clone())], false);
|
||||
|
||||
if env::var("UPDATE").map(|s| s == "1").unwrap_or(false) {
|
||||
let output = output.clone();
|
||||
let _ = catch_unwind(|| {
|
||||
NormalizedOutput::from(output)
|
||||
NormalizedOutput::from(output_str.clone())
|
||||
.compare_to_file(dir.join("output.js"))
|
||||
.unwrap();
|
||||
});
|
||||
}
|
||||
|
||||
let output_str = print(cm.clone(), &[drop_span(output_module.clone())], false);
|
||||
|
||||
assert_eq!(DebugUsingDisplay(&output_str), DebugUsingDisplay(&expected));
|
||||
|
||||
Ok(())
|
||||
|
@ -7,7 +7,7 @@ include = ["Cargo.toml", "src/**/*.rs", "examples/**/*.rs"]
|
||||
license = "Apache-2.0/MIT"
|
||||
name = "swc_ecma_parser"
|
||||
repository = "https://github.com/swc-project/swc.git"
|
||||
version = "0.70.1"
|
||||
version = "0.70.2"
|
||||
|
||||
[package.metadata.docs.rs]
|
||||
all-features = true
|
||||
@ -28,7 +28,7 @@ smallvec = "1"
|
||||
swc_atoms = {version = "0.2.3", path = "../../atoms"}
|
||||
swc_common = {version = "0.12.0", path = "../../common"}
|
||||
swc_ecma_ast = {version = "0.52.0", path = "../ast"}
|
||||
swc_ecma_visit = {version = "0.38.0", path = "../visit"}
|
||||
swc_ecma_visit = {version = "0.38.1", path = "../visit"}
|
||||
unicode-xid = "0.2"
|
||||
|
||||
[dev-dependencies]
|
||||
|
@ -420,7 +420,7 @@ pub struct Context {
|
||||
in_forced_jsx_context: bool,
|
||||
|
||||
/// If true, `:` should not be treated as a type annotation.
|
||||
in_case_cond: bool,
|
||||
dont_parse_colon_as_type_ann: bool,
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
@ -291,7 +291,12 @@ impl<'a, I: Tokens> Parser<I> {
|
||||
}
|
||||
|
||||
tok!('[') => {
|
||||
return self.parse_array_lit();
|
||||
let ctx = Context {
|
||||
is_direct_child_of_cond: false,
|
||||
dont_parse_colon_as_type_ann: false,
|
||||
..self.ctx()
|
||||
};
|
||||
return self.with_ctx(ctx).parse_array_lit();
|
||||
}
|
||||
|
||||
tok!('{') => {
|
||||
@ -679,10 +684,10 @@ impl<'a, I: Tokens> Parser<I> {
|
||||
}
|
||||
}
|
||||
|
||||
let return_type = if !self.ctx().in_cond_expr
|
||||
let return_type = if !(self.ctx().in_cond_expr && self.ctx().is_direct_child_of_cond)
|
||||
&& self.input.syntax().typescript()
|
||||
&& is!(self, ':')
|
||||
&& !self.ctx().in_case_cond
|
||||
&& !self.ctx().dont_parse_colon_as_type_ann
|
||||
{
|
||||
Some(self.parse_ts_type_or_type_predicate_ann(&tok!(':'))?)
|
||||
} else {
|
||||
@ -1578,7 +1583,7 @@ impl<'a, I: Tokens> Parser<I> {
|
||||
pub(super) fn parse_lit(&mut self) -> PResult<Lit> {
|
||||
let start = cur_pos!(self);
|
||||
|
||||
let v = match *cur!(self, true)? {
|
||||
let v = match cur!(self, true)? {
|
||||
Word(Word::Null) => {
|
||||
bump!(self);
|
||||
let span = span!(self, start);
|
||||
@ -1616,7 +1621,7 @@ impl<'a, I: Tokens> Parser<I> {
|
||||
}),
|
||||
_ => unreachable!(),
|
||||
},
|
||||
_ => unreachable!("parse_lit should not be called"),
|
||||
token => unreachable!("parse_lit should not be called for {:?}", token),
|
||||
};
|
||||
Ok(v)
|
||||
}
|
||||
|
@ -11,30 +11,37 @@ impl<'a, I: Tokens> Parser<I> {
|
||||
where
|
||||
Self: ParseObject<T>,
|
||||
{
|
||||
trace_cur!(self, parse_object);
|
||||
let ctx = Context {
|
||||
is_direct_child_of_cond: false,
|
||||
dont_parse_colon_as_type_ann: false,
|
||||
..self.ctx()
|
||||
};
|
||||
self.with_ctx(ctx).parse_with(|p| {
|
||||
trace_cur!(p, parse_object);
|
||||
|
||||
let start = cur_pos!(self);
|
||||
assert_and_bump!(self, '{');
|
||||
let start = cur_pos!(p);
|
||||
assert_and_bump!(p, '{');
|
||||
|
||||
let mut props = vec![];
|
||||
let mut props = vec![];
|
||||
|
||||
let mut first = true;
|
||||
while !eat!(self, '}') {
|
||||
// Handle comma
|
||||
if first {
|
||||
first = false;
|
||||
} else {
|
||||
expect!(self, ',');
|
||||
if eat!(self, '}') {
|
||||
break;
|
||||
let mut first = true;
|
||||
while !eat!(p, '}') {
|
||||
// Handle comma
|
||||
if first {
|
||||
first = false;
|
||||
} else {
|
||||
expect!(p, ',');
|
||||
if eat!(p, '}') {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
let prop = p.parse_object_prop()?;
|
||||
props.push(prop);
|
||||
}
|
||||
|
||||
let prop = self.parse_object_prop()?;
|
||||
props.push(prop);
|
||||
}
|
||||
|
||||
self.make_object(span!(self, start), props)
|
||||
p.make_object(span!(p, start), props)
|
||||
})
|
||||
}
|
||||
|
||||
/// spec: 'PropertyName'
|
||||
|
@ -481,7 +481,7 @@ impl<'a, I: Tokens> Parser<I> {
|
||||
let case_start = cur_pos!(p);
|
||||
bump!(p);
|
||||
let ctx = Context {
|
||||
in_case_cond: true,
|
||||
dont_parse_colon_as_type_ann: true,
|
||||
..p.ctx()
|
||||
};
|
||||
let test = if is_case {
|
||||
|
@ -304,13 +304,27 @@ impl<I: Tokens> Parser<I> {
|
||||
|
||||
expect!(self, '(');
|
||||
|
||||
let lit = self.parse_lit()?;
|
||||
let arg = match lit {
|
||||
Lit::Str(arg) => arg,
|
||||
let _ = cur!(self, false);
|
||||
|
||||
let arg_span = self.input.cur_span();
|
||||
|
||||
let arg = match cur!(self, true)? {
|
||||
Token::Str { .. } => match bump!(self) {
|
||||
Token::Str { value, has_escape } => Str {
|
||||
span: arg_span,
|
||||
value,
|
||||
has_escape,
|
||||
kind: StrKind::Normal {
|
||||
contains_quote: true,
|
||||
},
|
||||
},
|
||||
_ => unreachable!(),
|
||||
},
|
||||
_ => {
|
||||
self.emit_err(lit.span(), SyntaxError::TS1141);
|
||||
bump!(self);
|
||||
self.emit_err(arg_span, SyntaxError::TS1141);
|
||||
Str {
|
||||
span: lit.span(),
|
||||
span: arg_span,
|
||||
value: "".into(),
|
||||
has_escape: false,
|
||||
kind: Default::default(),
|
||||
|
@ -0,0 +1,5 @@
|
||||
function imp<T extends string>(x: T): typeof import(T) {
|
||||
return x;
|
||||
}
|
||||
|
||||
console.log("123");
|
@ -0,0 +1,6 @@
|
||||
error: literal in an import type should be string literal
|
||||
--> $DIR/tests/typescript-errors/issue-2198/ts/input.ts:1:53
|
||||
|
|
||||
1 | function imp<T extends string>(x: T): typeof import(T) {
|
||||
| ^
|
||||
|
@ -0,0 +1,5 @@
|
||||
function imp<T extends string>(x: T): typeof import(T) {
|
||||
return x;
|
||||
}
|
||||
|
||||
console.log("123");
|
@ -0,0 +1,6 @@
|
||||
error: literal in an import type should be string literal
|
||||
--> $DIR/tests/typescript-errors/issue-2198/tsx/input.tsx:1:53
|
||||
|
|
||||
1 | function imp<T extends string>(x: T): typeof import(T) {
|
||||
| ^
|
||||
|
@ -94,7 +94,7 @@ fn spec(file: PathBuf) {
|
||||
);
|
||||
}
|
||||
|
||||
with_parser(is_backtrace_enabled(), &file, true, |p| {
|
||||
with_parser(false, &file, true, |p| {
|
||||
let program = p.parse_program()?.fold_with(&mut Normalizer {
|
||||
drop_span: false,
|
||||
is_test262: false,
|
||||
@ -220,10 +220,3 @@ fn errors(file: PathBuf) {
|
||||
panic!()
|
||||
}
|
||||
}
|
||||
|
||||
fn is_backtrace_enabled() -> bool {
|
||||
match ::std::env::var("RUST_BACKTRACE") {
|
||||
Ok(val) => val == "1" || val == "full",
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,3 @@
|
||||
export const reproValue = true ? {} : {
|
||||
reproFunc: (_: any): any => { },
|
||||
};
|
166
ecmascript/parser/tests/typescript/issue-2196/ts/input.ts.json
Normal file
166
ecmascript/parser/tests/typescript/issue-2196/ts/input.ts.json
Normal file
@ -0,0 +1,166 @@
|
||||
{
|
||||
"type": "Module",
|
||||
"span": {
|
||||
"start": 0,
|
||||
"end": 79,
|
||||
"ctxt": 0
|
||||
},
|
||||
"body": [
|
||||
{
|
||||
"type": "ExportDeclaration",
|
||||
"span": {
|
||||
"start": 0,
|
||||
"end": 79,
|
||||
"ctxt": 0
|
||||
},
|
||||
"declaration": {
|
||||
"type": "VariableDeclaration",
|
||||
"span": {
|
||||
"start": 7,
|
||||
"end": 79,
|
||||
"ctxt": 0
|
||||
},
|
||||
"kind": "const",
|
||||
"declare": false,
|
||||
"declarations": [
|
||||
{
|
||||
"type": "VariableDeclarator",
|
||||
"span": {
|
||||
"start": 13,
|
||||
"end": 78,
|
||||
"ctxt": 0
|
||||
},
|
||||
"id": {
|
||||
"type": "Identifier",
|
||||
"span": {
|
||||
"start": 13,
|
||||
"end": 23,
|
||||
"ctxt": 0
|
||||
},
|
||||
"value": "reproValue",
|
||||
"optional": false,
|
||||
"typeAnnotation": null
|
||||
},
|
||||
"init": {
|
||||
"type": "ConditionalExpression",
|
||||
"span": {
|
||||
"start": 26,
|
||||
"end": 78,
|
||||
"ctxt": 0
|
||||
},
|
||||
"test": {
|
||||
"type": "BooleanLiteral",
|
||||
"span": {
|
||||
"start": 26,
|
||||
"end": 30,
|
||||
"ctxt": 0
|
||||
},
|
||||
"value": true
|
||||
},
|
||||
"consequent": {
|
||||
"type": "ObjectExpression",
|
||||
"span": {
|
||||
"start": 33,
|
||||
"end": 35,
|
||||
"ctxt": 0
|
||||
},
|
||||
"properties": []
|
||||
},
|
||||
"alternate": {
|
||||
"type": "ObjectExpression",
|
||||
"span": {
|
||||
"start": 38,
|
||||
"end": 78,
|
||||
"ctxt": 0
|
||||
},
|
||||
"properties": [
|
||||
{
|
||||
"type": "KeyValueProperty",
|
||||
"key": {
|
||||
"type": "Identifier",
|
||||
"span": {
|
||||
"start": 44,
|
||||
"end": 53,
|
||||
"ctxt": 0
|
||||
},
|
||||
"value": "reproFunc",
|
||||
"optional": false
|
||||
},
|
||||
"value": {
|
||||
"type": "ArrowFunctionExpression",
|
||||
"span": {
|
||||
"start": 55,
|
||||
"end": 75,
|
||||
"ctxt": 0
|
||||
},
|
||||
"params": [
|
||||
{
|
||||
"type": "Identifier",
|
||||
"span": {
|
||||
"start": 56,
|
||||
"end": 62,
|
||||
"ctxt": 0
|
||||
},
|
||||
"value": "_",
|
||||
"optional": false,
|
||||
"typeAnnotation": {
|
||||
"type": "TsTypeAnnotation",
|
||||
"span": {
|
||||
"start": 57,
|
||||
"end": 62,
|
||||
"ctxt": 0
|
||||
},
|
||||
"typeAnnotation": {
|
||||
"type": "TsKeywordType",
|
||||
"span": {
|
||||
"start": 59,
|
||||
"end": 62,
|
||||
"ctxt": 0
|
||||
},
|
||||
"kind": "any"
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"body": {
|
||||
"type": "BlockStatement",
|
||||
"span": {
|
||||
"start": 72,
|
||||
"end": 75,
|
||||
"ctxt": 0
|
||||
},
|
||||
"stmts": []
|
||||
},
|
||||
"async": false,
|
||||
"generator": false,
|
||||
"typeParameters": null,
|
||||
"returnType": {
|
||||
"type": "TsTypeAnnotation",
|
||||
"span": {
|
||||
"start": 63,
|
||||
"end": 68,
|
||||
"ctxt": 0
|
||||
},
|
||||
"typeAnnotation": {
|
||||
"type": "TsKeywordType",
|
||||
"span": {
|
||||
"start": 65,
|
||||
"end": 68,
|
||||
"ctxt": 0
|
||||
},
|
||||
"kind": "any"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"definite": false
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
],
|
||||
"interpreter": null
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
export const reproValue = true ? {} : {
|
||||
reproFunc: (_: any): any => { },
|
||||
};
|
166
ecmascript/parser/tests/typescript/issue-2196/tsx/input.ts.json
Normal file
166
ecmascript/parser/tests/typescript/issue-2196/tsx/input.ts.json
Normal file
@ -0,0 +1,166 @@
|
||||
{
|
||||
"type": "Module",
|
||||
"span": {
|
||||
"start": 0,
|
||||
"end": 79,
|
||||
"ctxt": 0
|
||||
},
|
||||
"body": [
|
||||
{
|
||||
"type": "ExportDeclaration",
|
||||
"span": {
|
||||
"start": 0,
|
||||
"end": 79,
|
||||
"ctxt": 0
|
||||
},
|
||||
"declaration": {
|
||||
"type": "VariableDeclaration",
|
||||
"span": {
|
||||
"start": 7,
|
||||
"end": 79,
|
||||
"ctxt": 0
|
||||
},
|
||||
"kind": "const",
|
||||
"declare": false,
|
||||
"declarations": [
|
||||
{
|
||||
"type": "VariableDeclarator",
|
||||
"span": {
|
||||
"start": 13,
|
||||
"end": 78,
|
||||
"ctxt": 0
|
||||
},
|
||||
"id": {
|
||||
"type": "Identifier",
|
||||
"span": {
|
||||
"start": 13,
|
||||
"end": 23,
|
||||
"ctxt": 0
|
||||
},
|
||||
"value": "reproValue",
|
||||
"optional": false,
|
||||
"typeAnnotation": null
|
||||
},
|
||||
"init": {
|
||||
"type": "ConditionalExpression",
|
||||
"span": {
|
||||
"start": 26,
|
||||
"end": 78,
|
||||
"ctxt": 0
|
||||
},
|
||||
"test": {
|
||||
"type": "BooleanLiteral",
|
||||
"span": {
|
||||
"start": 26,
|
||||
"end": 30,
|
||||
"ctxt": 0
|
||||
},
|
||||
"value": true
|
||||
},
|
||||
"consequent": {
|
||||
"type": "ObjectExpression",
|
||||
"span": {
|
||||
"start": 33,
|
||||
"end": 35,
|
||||
"ctxt": 0
|
||||
},
|
||||
"properties": []
|
||||
},
|
||||
"alternate": {
|
||||
"type": "ObjectExpression",
|
||||
"span": {
|
||||
"start": 38,
|
||||
"end": 78,
|
||||
"ctxt": 0
|
||||
},
|
||||
"properties": [
|
||||
{
|
||||
"type": "KeyValueProperty",
|
||||
"key": {
|
||||
"type": "Identifier",
|
||||
"span": {
|
||||
"start": 44,
|
||||
"end": 53,
|
||||
"ctxt": 0
|
||||
},
|
||||
"value": "reproFunc",
|
||||
"optional": false
|
||||
},
|
||||
"value": {
|
||||
"type": "ArrowFunctionExpression",
|
||||
"span": {
|
||||
"start": 55,
|
||||
"end": 75,
|
||||
"ctxt": 0
|
||||
},
|
||||
"params": [
|
||||
{
|
||||
"type": "Identifier",
|
||||
"span": {
|
||||
"start": 56,
|
||||
"end": 62,
|
||||
"ctxt": 0
|
||||
},
|
||||
"value": "_",
|
||||
"optional": false,
|
||||
"typeAnnotation": {
|
||||
"type": "TsTypeAnnotation",
|
||||
"span": {
|
||||
"start": 57,
|
||||
"end": 62,
|
||||
"ctxt": 0
|
||||
},
|
||||
"typeAnnotation": {
|
||||
"type": "TsKeywordType",
|
||||
"span": {
|
||||
"start": 59,
|
||||
"end": 62,
|
||||
"ctxt": 0
|
||||
},
|
||||
"kind": "any"
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"body": {
|
||||
"type": "BlockStatement",
|
||||
"span": {
|
||||
"start": 72,
|
||||
"end": 75,
|
||||
"ctxt": 0
|
||||
},
|
||||
"stmts": []
|
||||
},
|
||||
"async": false,
|
||||
"generator": false,
|
||||
"typeParameters": null,
|
||||
"returnType": {
|
||||
"type": "TsTypeAnnotation",
|
||||
"span": {
|
||||
"start": 63,
|
||||
"end": 68,
|
||||
"ctxt": 0
|
||||
},
|
||||
"typeAnnotation": {
|
||||
"type": "TsKeywordType",
|
||||
"span": {
|
||||
"start": 65,
|
||||
"end": 68,
|
||||
"ctxt": 0
|
||||
},
|
||||
"kind": "any"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"definite": false
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
],
|
||||
"interpreter": null
|
||||
}
|
@ -5,7 +5,7 @@ documentation = "https://rustdoc.swc.rs/swc_ecma_preset_env/"
|
||||
edition = "2018"
|
||||
license = "Apache-2.0/MIT"
|
||||
name = "swc_ecma_preset_env"
|
||||
version = "0.42.0"
|
||||
version = "0.42.1"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
@ -22,13 +22,13 @@ string_enum = {version = "0.3.1", path = "../../macros/string_enum"}
|
||||
swc_atoms = {version = "0.2", path = "../../atoms"}
|
||||
swc_common = {version = "0.12.0", path = "../../common"}
|
||||
swc_ecma_ast = {version = "0.52.0", path = "../ast"}
|
||||
swc_ecma_transforms = {version = "0.71.0", path = "../transforms", features = ["compat", "proposal"]}
|
||||
swc_ecma_utils = {version = "0.44.0", path = "../utils"}
|
||||
swc_ecma_visit = {version = "0.38.0", path = "../visit"}
|
||||
swc_ecma_transforms = {version = "0.71.1", path = "../transforms", features = ["compat", "proposal"]}
|
||||
swc_ecma_utils = {version = "0.44.2", path = "../utils"}
|
||||
swc_ecma_visit = {version = "0.38.1", path = "../visit"}
|
||||
walkdir = "2"
|
||||
|
||||
[dev-dependencies]
|
||||
pretty_assertions = "0.6"
|
||||
swc_ecma_codegen = {version = "0.70.0", path = "../codegen"}
|
||||
swc_ecma_parser = {version = "0.70.0", path = "../parser"}
|
||||
swc_ecma_codegen = {version = "0.70.2", path = "../codegen"}
|
||||
swc_ecma_parser = {version = "0.70.2", path = "../parser"}
|
||||
testing = {version = "0.13.0", path = "../../testing"}
|
||||
|
@ -6,7 +6,7 @@ edition = "2018"
|
||||
license = "Apache-2.0/MIT"
|
||||
name = "swc_ecma_transforms"
|
||||
repository = "https://github.com/swc-project/swc.git"
|
||||
version = "0.71.0"
|
||||
version = "0.71.1"
|
||||
|
||||
[package.metadata.docs.rs]
|
||||
all-features = true
|
||||
@ -24,23 +24,23 @@ typescript = ["swc_ecma_transforms_typescript"]
|
||||
swc_atoms = {version = "0.2.0", path = "../../atoms"}
|
||||
swc_common = {version = "0.12.0", path = "../../common"}
|
||||
swc_ecma_ast = {version = "0.52.0", path = "../ast"}
|
||||
swc_ecma_parser = {version = "0.70.0", path = "../parser"}
|
||||
swc_ecma_transforms_base = {version = "0.31.0", path = "./base"}
|
||||
swc_ecma_transforms_compat = {version = "0.34.0", path = "./compat", optional = true}
|
||||
swc_ecma_transforms_module = {version = "0.38.0", path = "./module", optional = true}
|
||||
swc_ecma_transforms_optimization = {version = "0.41.0", path = "./optimization", optional = true}
|
||||
swc_ecma_transforms_proposal = {version = "0.38.0", path = "./proposal", optional = true}
|
||||
swc_ecma_transforms_react = {version = "0.39.0", path = "./react", optional = true}
|
||||
swc_ecma_transforms_typescript = {version = "0.40.0", path = "./typescript", optional = true}
|
||||
swc_ecma_utils = {version = "0.44.0", path = "../utils"}
|
||||
swc_ecma_visit = {version = "0.38.0", path = "../visit"}
|
||||
swc_ecma_parser = {version = "0.70.2", path = "../parser"}
|
||||
swc_ecma_transforms_base = {version = "0.31.1", path = "./base"}
|
||||
swc_ecma_transforms_compat = {version = "0.34.1", path = "./compat", optional = true}
|
||||
swc_ecma_transforms_module = {version = "0.38.1", path = "./module", optional = true}
|
||||
swc_ecma_transforms_optimization = {version = "0.41.1", path = "./optimization", optional = true}
|
||||
swc_ecma_transforms_proposal = {version = "0.38.1", path = "./proposal", optional = true}
|
||||
swc_ecma_transforms_react = {version = "0.39.1", path = "./react", optional = true}
|
||||
swc_ecma_transforms_typescript = {version = "0.40.2", path = "./typescript", optional = true}
|
||||
swc_ecma_utils = {version = "0.44.2", path = "../utils"}
|
||||
swc_ecma_visit = {version = "0.38.1", path = "../visit"}
|
||||
unicode-xid = "0.2"
|
||||
|
||||
[dev-dependencies]
|
||||
pretty_assertions = "0.6"
|
||||
sourcemap = "6"
|
||||
swc_ecma_codegen = {version = "0.70.0", path = "../codegen"}
|
||||
swc_ecma_transforms_testing = {version = "0.32.0", path = "./testing"}
|
||||
swc_ecma_codegen = {version = "0.70.2", path = "../codegen"}
|
||||
swc_ecma_transforms_testing = {version = "0.32.1", path = "./testing"}
|
||||
tempfile = "3"
|
||||
testing = {version = "0.13.0", path = "../../testing"}
|
||||
walkdir = "2"
|
||||
|
@ -6,7 +6,7 @@ edition = "2018"
|
||||
license = "Apache-2.0/MIT"
|
||||
name = "swc_ecma_transforms_base"
|
||||
repository = "https://github.com/swc-project/swc.git"
|
||||
version = "0.31.0"
|
||||
version = "0.31.1"
|
||||
|
||||
[dependencies]
|
||||
fxhash = "0.2.1"
|
||||
@ -17,10 +17,10 @@ smallvec = "1.6.0"
|
||||
swc_atoms = {version = "0.2", path = "../../../atoms"}
|
||||
swc_common = {version = "0.12.0", path = "../../../common"}
|
||||
swc_ecma_ast = {version = "0.52.0", path = "../../ast"}
|
||||
swc_ecma_parser = {version = "0.70.0", path = "../../parser"}
|
||||
swc_ecma_utils = {version = "0.44.0", path = "../../utils"}
|
||||
swc_ecma_visit = {version = "0.38.0", path = "../../visit"}
|
||||
swc_ecma_parser = {version = "0.70.2", path = "../../parser"}
|
||||
swc_ecma_utils = {version = "0.44.2", path = "../../utils"}
|
||||
swc_ecma_visit = {version = "0.38.1", path = "../../visit"}
|
||||
|
||||
[dev-dependencies]
|
||||
swc_ecma_codegen = {version = "0.70.0", path = "../../codegen"}
|
||||
swc_ecma_codegen = {version = "0.70.2", path = "../../codegen"}
|
||||
testing = {version = "0.13.0", path = "../../../testing"}
|
||||
|
@ -165,6 +165,16 @@ impl VisitMut for Fixer<'_> {
|
||||
_ => {}
|
||||
},
|
||||
|
||||
op!("**") => match &*expr.left {
|
||||
Expr::Unary(..) => {
|
||||
self.wrap(&mut expr.left);
|
||||
}
|
||||
Expr::Lit(Lit::Num(v)) if v.value.is_sign_negative() => {
|
||||
self.wrap(&mut expr.left);
|
||||
}
|
||||
_ => {}
|
||||
},
|
||||
|
||||
_ => {}
|
||||
}
|
||||
|
||||
@ -1414,4 +1424,6 @@ var store = global[SHARED] || (global[SHARED] = {});
|
||||
identical!(issue_2163_1, "() => ({foo} = bar());");
|
||||
|
||||
identical!(issue_2163_2, "() => ([foo] = bar());");
|
||||
|
||||
identical!(issue_2191, "(-1) ** h");
|
||||
}
|
||||
|
@ -6,12 +6,12 @@ edition = "2018"
|
||||
license = "Apache-2.0/MIT"
|
||||
name = "swc_ecma_transforms_classes"
|
||||
repository = "https://github.com/swc-project/swc.git"
|
||||
version = "0.17.0"
|
||||
version = "0.17.1"
|
||||
|
||||
[dependencies]
|
||||
swc_atoms = {version = "0.2.6", path = "../../../atoms"}
|
||||
swc_common = {version = "0.12.0", path = "../../../common"}
|
||||
swc_ecma_ast = {version = "0.52.0", path = "../../ast"}
|
||||
swc_ecma_transforms_base = {version = "0.31.0", path = "../base"}
|
||||
swc_ecma_utils = {version = "0.44.0", path = "../../utils"}
|
||||
swc_ecma_visit = {version = "0.38.0", path = "../../visit"}
|
||||
swc_ecma_transforms_base = {version = "0.31.1", path = "../base"}
|
||||
swc_ecma_utils = {version = "0.44.2", path = "../../utils"}
|
||||
swc_ecma_visit = {version = "0.38.1", path = "../../visit"}
|
||||
|
@ -6,7 +6,7 @@ edition = "2018"
|
||||
license = "Apache-2.0/MIT"
|
||||
name = "swc_ecma_transforms_compat"
|
||||
repository = "https://github.com/swc-project/swc.git"
|
||||
version = "0.34.0"
|
||||
version = "0.34.1"
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
@ -21,13 +21,13 @@ smallvec = "1.6.0"
|
||||
swc_atoms = {version = "0.2.5", path = "../../../atoms"}
|
||||
swc_common = {version = "0.12.0", path = "../../../common"}
|
||||
swc_ecma_ast = {version = "0.52.0", path = "../../ast"}
|
||||
swc_ecma_transforms_base = {version = "0.31.0", path = "../base"}
|
||||
swc_ecma_transforms_classes = {version = "0.17.0", path = "../classes"}
|
||||
swc_ecma_transforms_base = {version = "0.31.1", path = "../base"}
|
||||
swc_ecma_transforms_classes = {version = "0.17.1", path = "../classes"}
|
||||
swc_ecma_transforms_macros = {version = "0.2.1", path = "../macros"}
|
||||
swc_ecma_utils = {version = "0.44.0", path = "../../utils"}
|
||||
swc_ecma_visit = {version = "0.38.0", path = "../../visit"}
|
||||
swc_ecma_utils = {version = "0.44.2", path = "../../utils"}
|
||||
swc_ecma_visit = {version = "0.38.1", path = "../../visit"}
|
||||
|
||||
[dev-dependencies]
|
||||
swc_ecma_parser = {version = "0.70.0", path = "../../parser"}
|
||||
swc_ecma_transforms_testing = {version = "0.32.0", path = "../testing"}
|
||||
swc_ecma_parser = {version = "0.70.2", path = "../../parser"}
|
||||
swc_ecma_transforms_testing = {version = "0.32.1", path = "../testing"}
|
||||
testing = {version = "0.13.0", path = "../../../testing"}
|
||||
|
@ -1,6 +1,8 @@
|
||||
use crate::es2015::arrow;
|
||||
use swc_common::{util::take::Take, DUMMY_SP};
|
||||
use swc_ecma_ast::*;
|
||||
use swc_ecma_visit::{noop_fold_type, Fold, FoldWith};
|
||||
use swc_ecma_utils::prepend;
|
||||
use swc_ecma_visit::{noop_fold_type, Fold, FoldWith, InjectVars};
|
||||
|
||||
/// Safari 10.3 had an issue where async arrow function expressions within any
|
||||
/// class method would throw. After an initial fix, any references to the
|
||||
@ -10,22 +12,23 @@ use swc_ecma_visit::{noop_fold_type, Fold, FoldWith};
|
||||
pub fn async_arrows_in_class() -> impl Fold {
|
||||
AsyncArrowsInClass::default()
|
||||
}
|
||||
#[derive(Default, Clone, Copy)]
|
||||
#[derive(Default, Clone)]
|
||||
struct AsyncArrowsInClass {
|
||||
in_class_method: bool,
|
||||
vars: Vec<VarDeclarator>,
|
||||
}
|
||||
|
||||
impl Fold for AsyncArrowsInClass {
|
||||
noop_fold_type!();
|
||||
|
||||
fn fold_constructor(&mut self, n: Constructor) -> Constructor {
|
||||
fn fold_class_method(&mut self, n: ClassMethod) -> ClassMethod {
|
||||
self.in_class_method = true;
|
||||
let res = n.fold_children_with(self);
|
||||
self.in_class_method = false;
|
||||
res
|
||||
}
|
||||
|
||||
fn fold_class_method(&mut self, n: ClassMethod) -> ClassMethod {
|
||||
fn fold_constructor(&mut self, n: Constructor) -> Constructor {
|
||||
self.in_class_method = true;
|
||||
let res = n.fold_children_with(self);
|
||||
self.in_class_method = false;
|
||||
@ -41,7 +44,10 @@ impl Fold for AsyncArrowsInClass {
|
||||
match n {
|
||||
Expr::Arrow(ref a) => {
|
||||
if a.is_async {
|
||||
n.fold_with(&mut arrow())
|
||||
let mut v = arrow();
|
||||
let n = n.fold_with(&mut v);
|
||||
self.vars.extend(v.take_vars());
|
||||
n
|
||||
} else {
|
||||
n
|
||||
}
|
||||
@ -49,6 +55,40 @@ impl Fold for AsyncArrowsInClass {
|
||||
_ => n,
|
||||
}
|
||||
}
|
||||
|
||||
fn fold_module_items(&mut self, stmts: Vec<ModuleItem>) -> Vec<ModuleItem> {
|
||||
let mut stmts = stmts.fold_children_with(self);
|
||||
if !self.vars.is_empty() {
|
||||
prepend(
|
||||
&mut stmts,
|
||||
ModuleItem::Stmt(Stmt::Decl(Decl::Var(VarDecl {
|
||||
span: DUMMY_SP,
|
||||
kind: VarDeclKind::Var,
|
||||
declare: false,
|
||||
decls: self.vars.take(),
|
||||
}))),
|
||||
);
|
||||
}
|
||||
|
||||
stmts
|
||||
}
|
||||
|
||||
fn fold_stmts(&mut self, stmts: Vec<Stmt>) -> Vec<Stmt> {
|
||||
let mut stmts = stmts.fold_children_with(self);
|
||||
if !self.vars.is_empty() {
|
||||
prepend(
|
||||
&mut stmts,
|
||||
Stmt::Decl(Decl::Var(VarDecl {
|
||||
span: DUMMY_SP,
|
||||
kind: VarDeclKind::Var,
|
||||
declare: false,
|
||||
decls: self.vars.take(),
|
||||
})),
|
||||
);
|
||||
}
|
||||
|
||||
stmts
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
@ -115,10 +155,11 @@ mod tests {
|
||||
}"#,
|
||||
r#"
|
||||
class Foo {
|
||||
constructor() {
|
||||
this.x = () => (async function () {
|
||||
return await this;
|
||||
}).bind(this);
|
||||
constructor() {
|
||||
var _this = this;
|
||||
this.x = () => async function () {
|
||||
return await _this;
|
||||
};
|
||||
}
|
||||
}"#
|
||||
);
|
||||
|
@ -1,10 +1,13 @@
|
||||
use swc_atoms::js_word;
|
||||
use swc_common::{Spanned, DUMMY_SP};
|
||||
use swc_common::{util::take::Take, Spanned, DUMMY_SP};
|
||||
use swc_ecma_ast::*;
|
||||
use swc_ecma_transforms_base::perf::Check;
|
||||
use swc_ecma_transforms_macros::fast_path;
|
||||
use swc_ecma_utils::{contains_this_expr, private_ident, quote_ident, ExprFactory};
|
||||
use swc_ecma_visit::{noop_fold_type, noop_visit_type, Fold, FoldWith, Node, Visit};
|
||||
use swc_ecma_utils::{contains_this_expr, prepend, private_ident};
|
||||
use swc_ecma_visit::{
|
||||
noop_fold_type, noop_visit_mut_type, noop_visit_type, Fold, FoldWith, InjectVars, Node, Visit,
|
||||
VisitMut, VisitMutWith,
|
||||
};
|
||||
|
||||
/// Compile ES2015 arrow functions to ES5
|
||||
///
|
||||
@ -54,19 +57,28 @@ use swc_ecma_visit::{noop_fold_type, noop_visit_type, Fold, FoldWith, Node, Visi
|
||||
/// };
|
||||
/// console.log(bob.printFriends());
|
||||
/// ```
|
||||
pub fn arrow() -> impl Fold {
|
||||
pub fn arrow() -> impl Fold + InjectVars {
|
||||
Arrow::default()
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
struct Arrow {
|
||||
in_arrow: bool,
|
||||
vars: Vec<VarDeclarator>,
|
||||
}
|
||||
|
||||
#[fast_path(ArrowVisitor)]
|
||||
impl Fold for Arrow {
|
||||
noop_fold_type!();
|
||||
|
||||
fn fold_constructor(&mut self, c: Constructor) -> Constructor {
|
||||
let in_arrow = self.in_arrow;
|
||||
self.in_arrow = false;
|
||||
let res = c.fold_children_with(self);
|
||||
self.in_arrow = in_arrow;
|
||||
res
|
||||
}
|
||||
|
||||
fn fold_expr(&mut self, e: Expr) -> Expr {
|
||||
match e {
|
||||
Expr::Arrow(ArrowExpr {
|
||||
@ -78,9 +90,7 @@ impl Fold for Arrow {
|
||||
type_params,
|
||||
return_type,
|
||||
}) => {
|
||||
let used_this = contains_this_expr(&body);
|
||||
|
||||
let mut params: Vec<Param> = params
|
||||
let params: Vec<Param> = params
|
||||
.fold_with(self)
|
||||
.into_iter()
|
||||
.map(|pat| Param {
|
||||
@ -90,10 +100,14 @@ impl Fold for Arrow {
|
||||
})
|
||||
.collect();
|
||||
|
||||
// If we aren't already in an arrow expression, check if there is
|
||||
// any arguments references within this function. If so, we need to
|
||||
// replace them so that they refer to the parent function environment.
|
||||
let (body, used_arguments) = if !self.in_arrow {
|
||||
let mut arguments_var = None;
|
||||
|
||||
let in_arrow = self.in_arrow;
|
||||
self.in_arrow = true;
|
||||
let body = body.fold_with(self);
|
||||
self.in_arrow = in_arrow;
|
||||
|
||||
let mut body = {
|
||||
let mut arguments_replacer = ArgumentsReplacer {
|
||||
arguments: private_ident!("_arguments"),
|
||||
found: false,
|
||||
@ -101,26 +115,41 @@ impl Fold for Arrow {
|
||||
let body = body.fold_with(&mut arguments_replacer);
|
||||
|
||||
if arguments_replacer.found {
|
||||
params.insert(
|
||||
0,
|
||||
Param {
|
||||
span: DUMMY_SP,
|
||||
decorators: Default::default(),
|
||||
pat: Pat::Ident(BindingIdent::from(
|
||||
arguments_replacer.arguments.clone(),
|
||||
)),
|
||||
},
|
||||
);
|
||||
arguments_var = Some(arguments_replacer.arguments.clone());
|
||||
}
|
||||
(body, arguments_replacer.found)
|
||||
} else {
|
||||
(body, false)
|
||||
body
|
||||
};
|
||||
|
||||
let in_arrow = self.in_arrow;
|
||||
self.in_arrow = true;
|
||||
let body = body.fold_with(self);
|
||||
self.in_arrow = in_arrow;
|
||||
let used_this = contains_this_expr(&body);
|
||||
|
||||
let this_id = if used_this {
|
||||
Some(private_ident!("_this"))
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
if let Some(this_id) = this_id.clone() {
|
||||
self.vars.push(VarDeclarator {
|
||||
span: DUMMY_SP,
|
||||
name: Pat::Ident(this_id.clone().into()),
|
||||
init: Some(Box::new(Expr::This(ThisExpr { span: DUMMY_SP }))),
|
||||
definite: false,
|
||||
});
|
||||
|
||||
body.visit_mut_with(&mut ThisReplacer { to: &this_id })
|
||||
}
|
||||
|
||||
if let Some(id) = arguments_var.clone() {
|
||||
self.vars.push(VarDeclarator {
|
||||
span: DUMMY_SP,
|
||||
name: Pat::Ident(id.into()),
|
||||
init: Some(Box::new(Expr::Ident(Ident::new(
|
||||
js_word!("arguments"),
|
||||
DUMMY_SP,
|
||||
)))),
|
||||
definite: false,
|
||||
});
|
||||
}
|
||||
|
||||
let fn_expr = Expr::Fn(FnExpr {
|
||||
ident: None,
|
||||
@ -145,34 +174,12 @@ impl Fold for Arrow {
|
||||
},
|
||||
});
|
||||
|
||||
if !used_this && !used_arguments {
|
||||
return fn_expr;
|
||||
}
|
||||
|
||||
let mut args = vec![ThisExpr { span: DUMMY_SP }.as_arg()];
|
||||
if used_arguments {
|
||||
args.push(quote_ident!("arguments").as_arg());
|
||||
}
|
||||
|
||||
Expr::Call(CallExpr {
|
||||
span,
|
||||
callee: fn_expr.make_member(quote_ident!("bind")).as_callee(),
|
||||
args,
|
||||
type_args: Default::default(),
|
||||
})
|
||||
return fn_expr;
|
||||
}
|
||||
_ => e.fold_children_with(self),
|
||||
}
|
||||
}
|
||||
|
||||
fn fold_constructor(&mut self, c: Constructor) -> Constructor {
|
||||
let in_arrow = self.in_arrow;
|
||||
self.in_arrow = false;
|
||||
let res = c.fold_children_with(self);
|
||||
self.in_arrow = in_arrow;
|
||||
res
|
||||
}
|
||||
|
||||
fn fold_function(&mut self, f: Function) -> Function {
|
||||
let in_arrow = self.in_arrow;
|
||||
self.in_arrow = false;
|
||||
@ -180,6 +187,50 @@ impl Fold for Arrow {
|
||||
self.in_arrow = in_arrow;
|
||||
res
|
||||
}
|
||||
|
||||
fn fold_module_items(&mut self, stmts: Vec<ModuleItem>) -> Vec<ModuleItem> {
|
||||
let mut stmts = stmts.fold_children_with(self);
|
||||
if !self.vars.is_empty() {
|
||||
prepend(
|
||||
&mut stmts,
|
||||
ModuleItem::Stmt(Stmt::Decl(Decl::Var(VarDecl {
|
||||
span: DUMMY_SP,
|
||||
kind: VarDeclKind::Var,
|
||||
declare: false,
|
||||
decls: self.vars.take(),
|
||||
}))),
|
||||
);
|
||||
}
|
||||
|
||||
stmts
|
||||
}
|
||||
|
||||
fn fold_stmts(&mut self, stmts: Vec<Stmt>) -> Vec<Stmt> {
|
||||
let old_vars = self.vars.take();
|
||||
|
||||
let mut stmts = stmts.fold_children_with(self);
|
||||
if !self.vars.is_empty() {
|
||||
prepend(
|
||||
&mut stmts,
|
||||
Stmt::Decl(Decl::Var(VarDecl {
|
||||
span: DUMMY_SP,
|
||||
kind: VarDeclKind::Var,
|
||||
declare: false,
|
||||
decls: self.vars.take(),
|
||||
})),
|
||||
);
|
||||
}
|
||||
|
||||
self.vars = old_vars;
|
||||
|
||||
stmts
|
||||
}
|
||||
}
|
||||
|
||||
impl InjectVars for Arrow {
|
||||
fn take_vars(&mut self) -> Vec<VarDeclarator> {
|
||||
self.vars.take()
|
||||
}
|
||||
}
|
||||
|
||||
struct ArgumentsReplacer {
|
||||
@ -226,6 +277,32 @@ impl Fold for ArgumentsReplacer {
|
||||
}
|
||||
}
|
||||
|
||||
struct ThisReplacer<'a> {
|
||||
to: &'a Ident,
|
||||
}
|
||||
|
||||
impl VisitMut for ThisReplacer<'_> {
|
||||
noop_visit_mut_type!();
|
||||
|
||||
fn visit_mut_arrow_expr(&mut self, _: &mut ArrowExpr) {}
|
||||
|
||||
fn visit_mut_constructor(&mut self, _: &mut Constructor) {}
|
||||
|
||||
fn visit_mut_expr(&mut self, e: &mut Expr) {
|
||||
e.visit_mut_children_with(self);
|
||||
|
||||
match e {
|
||||
Expr::This(..) => {
|
||||
*e = Expr::Ident(self.to.clone());
|
||||
}
|
||||
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
fn visit_mut_function(&mut self, _: &mut Function) {}
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
struct ArrowVisitor {
|
||||
found: bool,
|
||||
|
@ -1,5 +1,5 @@
|
||||
use swc_ecma_transforms_compat::es2015::arrow;
|
||||
use swc_ecma_transforms_testing::test;
|
||||
use swc_ecma_transforms_testing::{compare_stdout, test};
|
||||
|
||||
test!(
|
||||
::swc_ecma_parser::Syntax::default(),
|
||||
@ -169,68 +169,51 @@ function test() {
|
||||
}"#,
|
||||
r#"
|
||||
function test() {
|
||||
return (function(_arguments) {
|
||||
var _arguments = arguments;
|
||||
return function() {
|
||||
return _arguments[0];
|
||||
}).bind(this, arguments)
|
||||
}
|
||||
}"#
|
||||
);
|
||||
|
||||
test!(
|
||||
compare_stdout!(
|
||||
::swc_ecma_parser::Syntax::default(),
|
||||
|_| arrow(),
|
||||
arguments_nested_arrow,
|
||||
r#"
|
||||
function test() {
|
||||
console.log(arguments[0]);
|
||||
return () => {
|
||||
"
|
||||
function test() {
|
||||
console.log(arguments[0]);
|
||||
return () => {
|
||||
console.log(arguments[0])
|
||||
};
|
||||
}
|
||||
}"#,
|
||||
r#"
|
||||
function test() {
|
||||
console.log(arguments[0]);
|
||||
return (function(_arguments) {
|
||||
console.log(_arguments[0]);
|
||||
return function() {
|
||||
console.log(_arguments[0]);
|
||||
};
|
||||
}).bind(this, arguments);
|
||||
}"#
|
||||
);
|
||||
|
||||
test!(
|
||||
::swc_ecma_parser::Syntax::default(),
|
||||
|_| arrow(),
|
||||
arguments_nested_fn,
|
||||
r#"
|
||||
function test() {
|
||||
console.log(arguments[0]);
|
||||
return () => {
|
||||
console.log(arguments[0]);
|
||||
return function() {
|
||||
console.log(arguments[0]);
|
||||
return () => {
|
||||
console.log(arguments[0])
|
||||
};
|
||||
};
|
||||
}
|
||||
}
|
||||
}"#,
|
||||
r#"
|
||||
function test() {
|
||||
console.log(arguments[0]);
|
||||
return (function(_arguments) {
|
||||
console.log(_arguments[0]);
|
||||
|
||||
test()(1)(2);
|
||||
"
|
||||
);
|
||||
|
||||
compare_stdout!(
|
||||
::swc_ecma_parser::Syntax::default(),
|
||||
|_| arrow(),
|
||||
arguments_nested_fn,
|
||||
"
|
||||
function test() {
|
||||
console.log(arguments[0]);
|
||||
return () => {
|
||||
console.log(arguments[0]);
|
||||
return function() {
|
||||
console.log(arguments[0]);
|
||||
return (function(_arguments) {
|
||||
console.log(_arguments[0]);
|
||||
}).bind(this, arguments);
|
||||
console.log(arguments[0]);
|
||||
return () => {
|
||||
console.log(arguments[0])
|
||||
};
|
||||
};
|
||||
}).bind(this, arguments);
|
||||
}"#
|
||||
}
|
||||
}
|
||||
test()(1)(2)(3);
|
||||
"
|
||||
);
|
||||
|
||||
test!(
|
||||
@ -268,3 +251,39 @@ test!(
|
||||
};
|
||||
}"#
|
||||
);
|
||||
|
||||
test!(
|
||||
::swc_ecma_parser::Syntax::default(),
|
||||
|_| arrow(),
|
||||
issue_2212_1,
|
||||
"const foo = () => this",
|
||||
"
|
||||
var _this = this;
|
||||
const foo = function() {
|
||||
return _this;
|
||||
};
|
||||
"
|
||||
);
|
||||
|
||||
test!(
|
||||
::swc_ecma_parser::Syntax::default(),
|
||||
|_| arrow(),
|
||||
issue_2212_2,
|
||||
"
|
||||
const foo = function (){
|
||||
() => () => () => this
|
||||
}
|
||||
",
|
||||
"
|
||||
const foo = function() {
|
||||
var _this = this;
|
||||
(function() {
|
||||
return function() {
|
||||
return function() {
|
||||
return _this;
|
||||
};
|
||||
};
|
||||
});
|
||||
};
|
||||
"
|
||||
);
|
||||
|
@ -5,7 +5,7 @@ use swc_ecma_transforms_compat::{
|
||||
es2015::{block_scoping, for_of::for_of},
|
||||
es2017::async_to_generator,
|
||||
};
|
||||
use swc_ecma_transforms_testing::{test, test_exec, Tester};
|
||||
use swc_ecma_transforms_testing::{compare_stdout, test, test_exec, Tester};
|
||||
|
||||
test!(
|
||||
::swc_ecma_parser::Syntax::default(),
|
||||
@ -778,7 +778,7 @@ test!(
|
||||
"
|
||||
);
|
||||
|
||||
test!(
|
||||
compare_stdout!(
|
||||
::swc_ecma_parser::Syntax::default(),
|
||||
|Tester { comments, .. }| {
|
||||
let mark = Mark::fresh(Mark::root());
|
||||
@ -792,22 +792,14 @@ test!(
|
||||
},
|
||||
arguments_arrow,
|
||||
"
|
||||
function test() {
|
||||
for (var i = 0; i < arguments.length; i++) {
|
||||
console.log((() => arguments[i])());
|
||||
}
|
||||
function test() {
|
||||
for (var i = 0; i < arguments.length; i++) {
|
||||
console.log((() => arguments[i])());
|
||||
}
|
||||
",
|
||||
}
|
||||
|
||||
test(1, 2, 3);
|
||||
"
|
||||
function test() {
|
||||
var _this = this, _arguments = arguments, _loop = function(i) {
|
||||
console.log((function(_arguments) {
|
||||
return _arguments[i];
|
||||
}).bind(_this, _arguments)());
|
||||
};
|
||||
for(var i = 0; i < arguments.length; i++)_loop(i);
|
||||
}
|
||||
"
|
||||
);
|
||||
|
||||
test!(
|
||||
|
@ -89,15 +89,16 @@ let TestClass = {
|
||||
let TestClass = {
|
||||
name: 'John Doe',
|
||||
testMethodFailure () {
|
||||
return new Promise((function(resolve) {
|
||||
var _ref = _asyncToGenerator((function*(resolve) {
|
||||
console.log(this);
|
||||
var _this = this;
|
||||
return new Promise(function(resolve) {
|
||||
var _ref = _asyncToGenerator(function*(resolve) {
|
||||
console.log(_this);
|
||||
setTimeout(resolve, 1000);
|
||||
}).bind(this));
|
||||
});
|
||||
return function() {
|
||||
return _ref.apply(this, arguments);
|
||||
};
|
||||
})().bind(this));
|
||||
}());
|
||||
}
|
||||
};
|
||||
"#
|
||||
@ -219,42 +220,46 @@ async function s(x, ...args) {
|
||||
}
|
||||
"#,
|
||||
r#"
|
||||
function _s() {
|
||||
_s = _asyncToGenerator((function*(x) {
|
||||
for(let _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++){
|
||||
args[_key - 1] = arguments[_key];
|
||||
}
|
||||
let t = (function(_arguments, y, a) {
|
||||
var _ref = _asyncToGenerator((function*(_arguments, y, a) {
|
||||
let r = (function(z, b) {
|
||||
var _ref = _asyncToGenerator((function*(z, b) {
|
||||
for(let _len = arguments.length, innerArgs = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++){
|
||||
innerArgs[_key - 2] = arguments[_key];
|
||||
}
|
||||
yield z;
|
||||
console.log(this, innerArgs, _arguments);
|
||||
return this.x;
|
||||
}).bind(this));
|
||||
return function() {
|
||||
return _ref.apply(this, arguments);
|
||||
};
|
||||
})().bind(this);
|
||||
yield r();
|
||||
console.log(this, args, _arguments);
|
||||
return this.g(r);
|
||||
}).bind(this));
|
||||
return function () {
|
||||
return _ref.apply(this, arguments);
|
||||
};
|
||||
})().bind(this, arguments);
|
||||
yield t();
|
||||
return this.h(t);
|
||||
}).bind(this));
|
||||
return _s.apply(this, arguments);
|
||||
}
|
||||
function s(x) {
|
||||
return _s.apply(this, arguments);
|
||||
}
|
||||
function _s() {
|
||||
_s = _asyncToGenerator((function*(x) {
|
||||
for(let _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++){
|
||||
args[_key - 1] = arguments[_key];
|
||||
}
|
||||
var _this = this, _arguments = arguments;
|
||||
let t = function(y, a) {
|
||||
var _t = _asyncToGenerator(function*(y, a) {
|
||||
var _this1 = _this, _arguments1 = _arguments;
|
||||
let r = function(z, b) {
|
||||
var _r = _asyncToGenerator(function*(z, b) {
|
||||
for(let _len = arguments.length, innerArgs = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++){
|
||||
innerArgs[_key - 2] = arguments[_key];
|
||||
}
|
||||
yield z;
|
||||
console.log(_this1, innerArgs, _arguments1);
|
||||
return _this1.x;
|
||||
});
|
||||
function r() {
|
||||
return _r.apply(this, arguments);
|
||||
}
|
||||
return r;
|
||||
}();
|
||||
yield r();
|
||||
console.log(_this, args, _arguments);
|
||||
return _this.g(r);
|
||||
});
|
||||
function t() {
|
||||
return _t.apply(this, arguments);
|
||||
}
|
||||
return t;
|
||||
}();
|
||||
yield t();
|
||||
return this.h(t);
|
||||
}).bind(this));
|
||||
return _s.apply(this, arguments);
|
||||
}
|
||||
function s(x) {
|
||||
return _s.apply(this, arguments);
|
||||
}
|
||||
"#
|
||||
);
|
||||
|
||||
@ -371,52 +376,54 @@ class Class {
|
||||
}
|
||||
"#,
|
||||
r#"
|
||||
class Class{
|
||||
method() {
|
||||
return _asyncToGenerator((function*() {
|
||||
this;
|
||||
(function() {
|
||||
return this;
|
||||
}).bind(this);
|
||||
(function() {
|
||||
this;
|
||||
(function() {
|
||||
return this;
|
||||
}).bind(this);
|
||||
function x() {
|
||||
this;
|
||||
(function() {
|
||||
this;
|
||||
}).bind(this);
|
||||
(function() {
|
||||
var _ref = _asyncToGenerator((function*() {
|
||||
this;
|
||||
}).bind(this));
|
||||
return function() {
|
||||
return _ref.apply(this, arguments);
|
||||
};
|
||||
})().bind(this);
|
||||
}
|
||||
}).bind(this);
|
||||
function x() {
|
||||
this;
|
||||
(function() {
|
||||
this;
|
||||
}).bind(this);
|
||||
(function() {
|
||||
var _ref = _asyncToGenerator((function*() {
|
||||
this;
|
||||
}).bind(this));
|
||||
return function() {
|
||||
return _ref.apply(this, arguments);
|
||||
};
|
||||
})().bind(this);
|
||||
}
|
||||
}).bind(this))();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class Class {
|
||||
method() {
|
||||
return _asyncToGenerator((function*() {
|
||||
var _this = this, _this1 = this;
|
||||
this;
|
||||
(function() {
|
||||
return _this;
|
||||
});
|
||||
(function() {
|
||||
var _this = _this1;
|
||||
_this1;
|
||||
(function() {
|
||||
return _this;
|
||||
});
|
||||
function x() {
|
||||
var _this = this, _this2 = this;
|
||||
this;
|
||||
(function() {
|
||||
_this;
|
||||
});
|
||||
(function() {
|
||||
var _ref = _asyncToGenerator(function*() {
|
||||
_this2;
|
||||
});
|
||||
return function() {
|
||||
return _ref.apply(this, arguments);
|
||||
};
|
||||
})();
|
||||
}
|
||||
});
|
||||
function x() {
|
||||
var _this = this, _this2 = this;
|
||||
this;
|
||||
(function() {
|
||||
_this;
|
||||
});
|
||||
(function() {
|
||||
var _ref = _asyncToGenerator(function*() {
|
||||
_this2;
|
||||
});
|
||||
return function() {
|
||||
return _ref.apply(this, arguments);
|
||||
};
|
||||
})();
|
||||
}
|
||||
}).bind(this))();
|
||||
}
|
||||
}
|
||||
"#
|
||||
);
|
||||
|
||||
|
@ -3749,9 +3749,10 @@ var qux = function() {
|
||||
(function () {
|
||||
class Foo {
|
||||
constructor() {
|
||||
_defineProperty(this, 'fn', (function() {
|
||||
return console.log(this);
|
||||
}).bind(this));
|
||||
var _this = this;
|
||||
_defineProperty(this, 'fn', function() {
|
||||
return console.log(_this);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@ -3764,9 +3765,10 @@ var qux = function() {
|
||||
(function () {
|
||||
class Bar {
|
||||
constructor() {
|
||||
_defineProperty(this, 'fn', (function() {
|
||||
return console.log(this);
|
||||
}).bind(this));
|
||||
var _this = this;
|
||||
_defineProperty(this, 'fn', function() {
|
||||
return console.log(_this);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@ -3779,9 +3781,10 @@ var qux = function() {
|
||||
(function () {
|
||||
class Baz {
|
||||
constructor(force){
|
||||
_defineProperty(this, 'fn', (function() {
|
||||
return console.log(this);
|
||||
}).bind(this));
|
||||
var _this = this;
|
||||
_defineProperty(this, 'fn', function() {
|
||||
return console.log(_this);
|
||||
});
|
||||
_defineProperty(this, "force", force);
|
||||
}
|
||||
|
||||
@ -3795,9 +3798,10 @@ var qux = function() {
|
||||
var qux = (function () {
|
||||
class Qux {
|
||||
constructor() {
|
||||
_defineProperty(this, 'fn', (function() {
|
||||
return console.log(this);
|
||||
}).bind(this));
|
||||
var _this = this;
|
||||
_defineProperty(this, 'fn', function() {
|
||||
return console.log(_this);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ edition = "2018"
|
||||
license = "Apache-2.0/MIT"
|
||||
name = "swc_ecma_transforms_module"
|
||||
repository = "https://github.com/swc-project/swc.git"
|
||||
version = "0.38.0"
|
||||
version = "0.38.1"
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
@ -19,13 +19,13 @@ serde = {version = "1.0.118", features = ["derive"]}
|
||||
swc_atoms = {version = "0.2", path = "../../../atoms"}
|
||||
swc_common = {version = "0.12.0", path = "../../../common"}
|
||||
swc_ecma_ast = {version = "0.52.0", path = "../../ast"}
|
||||
swc_ecma_loader = {version = "0.18.0", path = "../../loader", features = ["node"]}
|
||||
swc_ecma_parser = {version = "0.70.0", path = "../../parser"}
|
||||
swc_ecma_transforms_base = {version = "0.31.0", path = "../base"}
|
||||
swc_ecma_utils = {version = "0.44.0", path = "../../utils"}
|
||||
swc_ecma_visit = {version = "0.38.0", path = "../../visit"}
|
||||
swc_ecma_loader = {version = "0.18.1", path = "../../loader", features = ["node"]}
|
||||
swc_ecma_parser = {version = "0.70.2", path = "../../parser"}
|
||||
swc_ecma_transforms_base = {version = "0.31.1", path = "../base"}
|
||||
swc_ecma_utils = {version = "0.44.2", path = "../../utils"}
|
||||
swc_ecma_visit = {version = "0.38.1", path = "../../visit"}
|
||||
|
||||
[dev-dependencies]
|
||||
swc_ecma_transforms_compat = {version = "0.34.0", path = "../compat"}
|
||||
swc_ecma_transforms_testing = {version = "0.32.0", path = "../testing/"}
|
||||
swc_ecma_transforms_compat = {version = "0.34.1", path = "../compat"}
|
||||
swc_ecma_transforms_testing = {version = "0.32.1", path = "../testing/"}
|
||||
testing = {version = "0.13.0", path = "../../../testing/"}
|
||||
|
@ -6,7 +6,7 @@ edition = "2018"
|
||||
license = "Apache-2.0/MIT"
|
||||
name = "swc_ecma_transforms_optimization"
|
||||
repository = "https://github.com/swc-project/swc.git"
|
||||
version = "0.41.0"
|
||||
version = "0.41.1"
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
@ -20,16 +20,16 @@ serde_json = "1.0.61"
|
||||
swc_atoms = {version = "0.2", path = "../../../atoms"}
|
||||
swc_common = {version = "0.12.0", path = "../../../common"}
|
||||
swc_ecma_ast = {version = "0.52.0", path = "../../ast"}
|
||||
swc_ecma_parser = {version = "0.70.0", path = "../../parser"}
|
||||
swc_ecma_transforms_base = {version = "0.31.0", path = "../base"}
|
||||
swc_ecma_utils = {version = "0.44.0", path = "../../utils"}
|
||||
swc_ecma_visit = {version = "0.38.0", path = "../../visit"}
|
||||
swc_ecma_parser = {version = "0.70.2", path = "../../parser"}
|
||||
swc_ecma_transforms_base = {version = "0.31.1", path = "../base"}
|
||||
swc_ecma_utils = {version = "0.44.2", path = "../../utils"}
|
||||
swc_ecma_visit = {version = "0.38.1", path = "../../visit"}
|
||||
|
||||
[dev-dependencies]
|
||||
swc_ecma_transforms_compat = {version = "0.34.0", path = "../compat"}
|
||||
swc_ecma_transforms_module = {version = "0.38.0", path = "../module"}
|
||||
swc_ecma_transforms_proposal = {version = "0.38.0", path = "../proposal"}
|
||||
swc_ecma_transforms_react = {version = "0.39.0", path = "../react"}
|
||||
swc_ecma_transforms_testing = {version = "0.32.0", path = "../testing"}
|
||||
swc_ecma_transforms_typescript = {version = "0.40.0", path = "../typescript"}
|
||||
swc_ecma_transforms_compat = {version = "0.34.1", path = "../compat"}
|
||||
swc_ecma_transforms_module = {version = "0.38.1", path = "../module"}
|
||||
swc_ecma_transforms_proposal = {version = "0.38.1", path = "../proposal"}
|
||||
swc_ecma_transforms_react = {version = "0.39.1", path = "../react"}
|
||||
swc_ecma_transforms_testing = {version = "0.32.1", path = "../testing"}
|
||||
swc_ecma_transforms_typescript = {version = "0.40.2", path = "../typescript"}
|
||||
testing = {version = "0.13.0", path = "../../../testing"}
|
||||
|
@ -6,7 +6,7 @@ edition = "2018"
|
||||
license = "Apache-2.0/MIT"
|
||||
name = "swc_ecma_transforms_proposal"
|
||||
repository = "https://github.com/swc-project/swc.git"
|
||||
version = "0.38.0"
|
||||
version = "0.38.1"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
@ -22,14 +22,14 @@ smallvec = "1.6.0"
|
||||
swc_atoms = {version = "0.2", path = "../../../atoms"}
|
||||
swc_common = {version = "0.12.0", path = "../../../common"}
|
||||
swc_ecma_ast = {version = "0.52.0", path = "../../ast"}
|
||||
swc_ecma_loader = {version = "0.18.0", path = "../../loader", optional = true}
|
||||
swc_ecma_parser = {version = "0.70.0", path = "../../parser"}
|
||||
swc_ecma_transforms_base = {version = "0.31.0", path = "../base"}
|
||||
swc_ecma_transforms_classes = {version = "0.17.0", path = "../classes"}
|
||||
swc_ecma_utils = {version = "0.44.0", path = "../../utils"}
|
||||
swc_ecma_visit = {version = "0.38.0", path = "../../visit"}
|
||||
swc_ecma_loader = {version = "0.18.1", path = "../../loader", optional = true}
|
||||
swc_ecma_parser = {version = "0.70.2", path = "../../parser"}
|
||||
swc_ecma_transforms_base = {version = "0.31.1", path = "../base"}
|
||||
swc_ecma_transforms_classes = {version = "0.17.1", path = "../classes"}
|
||||
swc_ecma_utils = {version = "0.44.2", path = "../../utils"}
|
||||
swc_ecma_visit = {version = "0.38.1", path = "../../visit"}
|
||||
|
||||
[dev-dependencies]
|
||||
swc_ecma_transforms_compat = {version = "0.34.0", path = "../compat"}
|
||||
swc_ecma_transforms_module = {version = "0.38.0", path = "../module"}
|
||||
swc_ecma_transforms_testing = {version = "0.32.0", path = "../testing"}
|
||||
swc_ecma_transforms_compat = {version = "0.34.1", path = "../compat"}
|
||||
swc_ecma_transforms_module = {version = "0.38.1", path = "../module"}
|
||||
swc_ecma_transforms_testing = {version = "0.32.1", path = "../testing"}
|
||||
|
@ -7,7 +7,7 @@ include = ["Cargo.toml", "src/**/*.rs"]
|
||||
license = "Apache-2.0/MIT"
|
||||
name = "swc_ecma_transforms_react"
|
||||
repository = "https://github.com/swc-project/swc.git"
|
||||
version = "0.39.0"
|
||||
version = "0.39.1"
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
@ -22,14 +22,14 @@ string_enum = {version = "0.3.1", path = "../../../macros/string_enum"}
|
||||
swc_atoms = {version = "0.2", path = "../../../atoms"}
|
||||
swc_common = {version = "0.12.0", path = "../../../common"}
|
||||
swc_ecma_ast = {version = "0.52.0", path = "../../ast"}
|
||||
swc_ecma_parser = {version = "0.70.0", path = "../../parser"}
|
||||
swc_ecma_transforms_base = {version = "0.31.0", path = "../base"}
|
||||
swc_ecma_utils = {version = "0.44.0", path = "../../utils"}
|
||||
swc_ecma_visit = {version = "0.38.0", path = "../../visit"}
|
||||
swc_ecma_parser = {version = "0.70.2", path = "../../parser"}
|
||||
swc_ecma_transforms_base = {version = "0.31.1", path = "../base"}
|
||||
swc_ecma_utils = {version = "0.44.2", path = "../../utils"}
|
||||
swc_ecma_visit = {version = "0.38.1", path = "../../visit"}
|
||||
|
||||
[dev-dependencies]
|
||||
swc_ecma_codegen = {version = "0.70.0", path = "../../codegen/"}
|
||||
swc_ecma_transforms_compat = {version = "0.34.0", path = "../compat/"}
|
||||
swc_ecma_transforms_module = {version = "0.38.0", path = "../module"}
|
||||
swc_ecma_transforms_testing = {version = "0.32.0", path = "../testing/"}
|
||||
swc_ecma_codegen = {version = "0.70.2", path = "../../codegen/"}
|
||||
swc_ecma_transforms_compat = {version = "0.34.1", path = "../compat/"}
|
||||
swc_ecma_transforms_module = {version = "0.38.1", path = "../module"}
|
||||
swc_ecma_transforms_testing = {version = "0.32.1", path = "../testing/"}
|
||||
testing = {version = "0.13.0", path = "../../../testing"}
|
||||
|
@ -92,14 +92,16 @@ var bar = function () {
|
||||
"#,
|
||||
r#"
|
||||
var foo = function() {
|
||||
return (function() {
|
||||
return React.createElement(this, null);
|
||||
}).bind(this);
|
||||
var _this = this;
|
||||
return function() {
|
||||
return React.createElement(_this, null);
|
||||
};
|
||||
};
|
||||
var bar = function() {
|
||||
return (function() {
|
||||
return React.createElement(this.foo, null);
|
||||
}).bind(this);
|
||||
var _this = this;
|
||||
return function() {
|
||||
return React.createElement(_this.foo, null);
|
||||
};
|
||||
};
|
||||
"#
|
||||
);
|
||||
|
@ -6,7 +6,7 @@ edition = "2018"
|
||||
license = "Apache-2.0/MIT"
|
||||
name = "swc_ecma_transforms_testing"
|
||||
repository = "https://github.com/swc-project/swc.git"
|
||||
version = "0.32.0"
|
||||
version = "0.32.1"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
@ -17,10 +17,10 @@ serde = "1"
|
||||
serde_json = "1"
|
||||
swc_common = {version = "0.12.0", path = "../../../common"}
|
||||
swc_ecma_ast = {version = "0.52.0", path = "../../ast"}
|
||||
swc_ecma_codegen = {version = "0.70.0", path = "../../codegen"}
|
||||
swc_ecma_parser = {version = "0.70.0", path = "../../parser"}
|
||||
swc_ecma_transforms_base = {version = "0.31.0", path = "../base"}
|
||||
swc_ecma_utils = {version = "0.44.0", path = "../../utils"}
|
||||
swc_ecma_visit = {version = "0.38.0", path = "../../visit"}
|
||||
swc_ecma_codegen = {version = "0.70.2", path = "../../codegen"}
|
||||
swc_ecma_parser = {version = "0.70.2", path = "../../parser"}
|
||||
swc_ecma_transforms_base = {version = "0.31.1", path = "../base"}
|
||||
swc_ecma_utils = {version = "0.44.2", path = "../../utils"}
|
||||
swc_ecma_visit = {version = "0.38.1", path = "../../visit"}
|
||||
tempfile = "3.1.0"
|
||||
testing = {version = "0.13.0", path = "../../../testing"}
|
||||
|
@ -377,6 +377,9 @@ where
|
||||
);
|
||||
|
||||
let expected = stdout_of(&input).unwrap();
|
||||
|
||||
println!("\t>>>>> Expected stdout <<<<<\n{}", expected);
|
||||
|
||||
let actual = stdout_of(&transfomred_src).unwrap();
|
||||
|
||||
assert_eq!(expected, actual);
|
||||
@ -518,6 +521,18 @@ macro_rules! test_exec {
|
||||
};
|
||||
}
|
||||
|
||||
/// Test transformation by invoking it using `node`. The code must print
|
||||
/// something to stdout.
|
||||
#[macro_export]
|
||||
macro_rules! compare_stdout {
|
||||
($syntax:expr, $tr:expr, $test_name:ident, $input:expr) => {
|
||||
#[test]
|
||||
fn $test_name() {
|
||||
$crate::compare_stdout($syntax, $tr, $input)
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
struct Buf(Arc<RwLock<Vec<u8>>>);
|
||||
impl Write for Buf {
|
||||
|
@ -6,7 +6,7 @@ edition = "2018"
|
||||
license = "Apache-2.0/MIT"
|
||||
name = "swc_ecma_transforms_typescript"
|
||||
repository = "https://github.com/swc-project/swc.git"
|
||||
version = "0.40.1"
|
||||
version = "0.40.2"
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
@ -15,16 +15,16 @@ serde = {version = "1.0.118", features = ["derive"]}
|
||||
swc_atoms = {version = "0.2", path = "../../../atoms"}
|
||||
swc_common = {version = "0.12.0", path = "../../../common"}
|
||||
swc_ecma_ast = {version = "0.52.0", path = "../../ast"}
|
||||
swc_ecma_parser = {version = "0.70.0", path = "../../parser"}
|
||||
swc_ecma_transforms_base = {version = "0.31.0", path = "../base"}
|
||||
swc_ecma_utils = {version = "0.44.0", path = "../../utils"}
|
||||
swc_ecma_visit = {version = "0.38.0", path = "../../visit"}
|
||||
swc_ecma_parser = {version = "0.70.2", path = "../../parser"}
|
||||
swc_ecma_transforms_base = {version = "0.31.1", path = "../base"}
|
||||
swc_ecma_utils = {version = "0.44.2", path = "../../utils"}
|
||||
swc_ecma_visit = {version = "0.38.1", path = "../../visit"}
|
||||
|
||||
[dev-dependencies]
|
||||
swc_ecma_codegen = {version = "0.70.0", path = "../../codegen"}
|
||||
swc_ecma_transforms_compat = {version = "0.34.0", path = "../compat"}
|
||||
swc_ecma_transforms_module = {version = "0.38.0", path = "../module"}
|
||||
swc_ecma_transforms_proposal = {version = "0.38.0", path = "../proposal/"}
|
||||
swc_ecma_transforms_testing = {version = "0.32.0", path = "../testing"}
|
||||
swc_ecma_codegen = {version = "0.70.2", path = "../../codegen"}
|
||||
swc_ecma_transforms_compat = {version = "0.34.1", path = "../compat"}
|
||||
swc_ecma_transforms_module = {version = "0.38.1", path = "../module"}
|
||||
swc_ecma_transforms_proposal = {version = "0.38.1", path = "../proposal/"}
|
||||
swc_ecma_transforms_testing = {version = "0.32.1", path = "../testing"}
|
||||
testing = {version = "0.13.0", path = "../../../testing"}
|
||||
walkdir = "2.3.1"
|
||||
|
@ -6,7 +6,7 @@ edition = "2018"
|
||||
license = "Apache-2.0/MIT"
|
||||
name = "swc_ecma_utils"
|
||||
repository = "https://github.com/swc-project/swc.git"
|
||||
version = "0.44.1"
|
||||
version = "0.44.2"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
@ -16,7 +16,7 @@ scoped-tls = "1"
|
||||
swc_atoms = {version = "0.2.0", path = "../../atoms"}
|
||||
swc_common = {version = "0.12.0", path = "../../common"}
|
||||
swc_ecma_ast = {version = "0.52.0", path = "../ast"}
|
||||
swc_ecma_visit = {version = "0.38.0", path = "../visit"}
|
||||
swc_ecma_visit = {version = "0.38.1", path = "../visit"}
|
||||
unicode-xid = "0.2"
|
||||
|
||||
[dev-dependencies]
|
||||
|
@ -6,7 +6,7 @@ edition = "2018"
|
||||
license = "Apache-2.0/MIT"
|
||||
name = "swc_ecma_visit"
|
||||
repository = "https://github.com/swc-project/swc.git"
|
||||
version = "0.38.0"
|
||||
version = "0.38.1"
|
||||
|
||||
[dependencies]
|
||||
num-bigint = {version = "0.2", features = ["serde"]}
|
||||
|
@ -130,6 +130,23 @@ macro_rules! assert_eq_ignore_span {
|
||||
}};
|
||||
}
|
||||
|
||||
/// Implemeented for passes which inject varaibles.
|
||||
///
|
||||
/// If a pass depends on other pass which injects variables, this trait can be
|
||||
/// used to keep the varaibles.
|
||||
pub trait InjectVars {
|
||||
fn take_vars(&mut self) -> Vec<VarDeclarator>;
|
||||
}
|
||||
|
||||
impl<V> InjectVars for Folder<V>
|
||||
where
|
||||
V: VisitMut + InjectVars,
|
||||
{
|
||||
fn take_vars(&mut self) -> Vec<VarDeclarator> {
|
||||
self.0.take_vars()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn as_folder<V>(v: V) -> Folder<V>
|
||||
where
|
||||
V: VisitMut,
|
||||
|
@ -23,7 +23,7 @@ napi = {version = "1", features = ["serde-json"]}
|
||||
napi-derive = {version = "1"}
|
||||
path-clean = "0.1"
|
||||
serde = {version = "1", features = ["derive"]}
|
||||
serde_json = "1"
|
||||
serde_json = {version = "1", features = ["unbounded_depth"]}
|
||||
swc = {path = "../../"}
|
||||
swc_atoms = {version = "0.2.4", path = "../../atoms"}
|
||||
swc_bundler = {path = "../../bundler"}
|
||||
|
@ -1,6 +1,6 @@
|
||||
use crate::{
|
||||
complete_output, get_compiler,
|
||||
util::{CtxtExt, MapErr},
|
||||
util::{deserialize_json, CtxtExt, MapErr},
|
||||
};
|
||||
use napi::{CallContext, Env, Error, JsObject, JsString, Status, Task};
|
||||
use std::sync::Arc;
|
||||
@ -51,7 +51,7 @@ impl Task for PrintTask {
|
||||
pub fn print(cx: CallContext) -> napi::Result<JsObject> {
|
||||
let c = get_compiler(&cx);
|
||||
let program = cx.get::<JsString>(0)?.into_utf8()?;
|
||||
let program: Program = serde_json::from_str(program.as_str()?).map_err(|e| {
|
||||
let program: Program = deserialize_json(program.as_str()?).map_err(|e| {
|
||||
Error::new(
|
||||
Status::InvalidArg,
|
||||
format!("failed to deserialize Program {}", e),
|
||||
@ -75,7 +75,7 @@ pub fn print_sync(cx: CallContext) -> napi::Result<JsObject> {
|
||||
|
||||
let program = cx.get::<JsString>(0)?.into_utf8()?;
|
||||
let program: Program =
|
||||
serde_json::from_str(&program.as_str()?).expect("failed to deserialize Program");
|
||||
deserialize_json(&program.as_str()?).expect("failed to deserialize Program");
|
||||
|
||||
let options: Options = cx.get_deserialized(1)?;
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
use crate::{
|
||||
complete_output, get_compiler,
|
||||
util::{CtxtExt, MapErr},
|
||||
util::{deserialize_json, CtxtExt, MapErr},
|
||||
};
|
||||
use anyhow::{Context as _, Error};
|
||||
use napi::{CallContext, Env, JsBoolean, JsObject, JsString, Task};
|
||||
@ -39,7 +39,7 @@ impl Task for TransformTask {
|
||||
self.c.run(|| match self.input {
|
||||
Input::Program(ref s) => {
|
||||
let program: Program =
|
||||
serde_json::from_str(&s).expect("failed to deserialize Program");
|
||||
deserialize_json(&s).expect("failed to deserialize Program");
|
||||
// TODO: Source map
|
||||
self.c.process_js(&handler, program, &self.options)
|
||||
}
|
||||
@ -90,7 +90,7 @@ where
|
||||
c.run(|| {
|
||||
if is_module.get_value()? {
|
||||
let program: Program =
|
||||
serde_json::from_str(s.as_str()?).context("failed to deserialize Program")?;
|
||||
deserialize_json(s.as_str()?).context("failed to deserialize Program")?;
|
||||
c.process_js(&handler, program, &options)
|
||||
} else {
|
||||
let fm =
|
||||
|
@ -1,4 +1,4 @@
|
||||
use anyhow::Context;
|
||||
use anyhow::{Context, Error};
|
||||
use napi::{CallContext, JsBuffer, Status};
|
||||
use serde::de::DeserializeOwned;
|
||||
use std::any::type_name;
|
||||
@ -25,7 +25,10 @@ impl CtxtExt for CallContext<'_> {
|
||||
T: DeserializeOwned,
|
||||
{
|
||||
let buffer = self.get::<JsBuffer>(index)?.into_value()?;
|
||||
let v = serde_json::from_slice(&buffer)
|
||||
let mut deserializer = serde_json::Deserializer::from_slice(&buffer);
|
||||
deserializer.disable_recursion_limit();
|
||||
|
||||
let v = T::deserialize(&mut deserializer)
|
||||
.with_context(|| {
|
||||
format!(
|
||||
"Failed to deserialize argument at `{}` as {}\nJSON: {}",
|
||||
@ -39,3 +42,21 @@ impl CtxtExt for CallContext<'_> {
|
||||
Ok(v)
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn deserialize_json<T>(json: &str) -> Result<T, Error>
|
||||
where
|
||||
T: DeserializeOwned,
|
||||
{
|
||||
let mut deserializer = serde_json::Deserializer::from_str(&json);
|
||||
deserializer.disable_recursion_limit();
|
||||
|
||||
let val = T::deserialize(&mut deserializer);
|
||||
|
||||
val.with_context(|| {
|
||||
format!(
|
||||
"Failed to deserialize {} from json string (`{}`)",
|
||||
type_name::<T>(),
|
||||
json
|
||||
)
|
||||
})
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ edition = "2018"
|
||||
license = "Apache-2.0/MIT"
|
||||
name = "swc_plugin"
|
||||
repository = "https://github.com/swc-project/swc.git"
|
||||
version = "0.4.0"
|
||||
version = "0.4.1"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
@ -18,5 +18,5 @@ serde_json = "1.0.64"
|
||||
swc_atoms = {version = "0.2.7", path = "../atoms"}
|
||||
swc_common = {version = "0.12.0", path = "../common"}
|
||||
swc_ecma_ast = {version = "0.52.0", path = "../ecmascript/ast"}
|
||||
swc_ecma_utils = {version = "0.44.0", path = "../ecmascript/utils"}
|
||||
swc_ecma_visit = {version = "0.38.0", path = "../ecmascript/visit"}
|
||||
swc_ecma_utils = {version = "0.44.2", path = "../ecmascript/utils"}
|
||||
swc_ecma_visit = {version = "0.38.1", path = "../ecmascript/visit"}
|
||||
|
@ -6,7 +6,7 @@ edition = "2018"
|
||||
license = "Apache-2.0/MIT"
|
||||
name = "swc_plugin_runner"
|
||||
repository = "https://github.com/swc-project/swc.git"
|
||||
version = "0.4.0"
|
||||
version = "0.4.1"
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
@ -18,9 +18,9 @@ serde_json = "1.0.64"
|
||||
swc_atoms = "0.2.7"
|
||||
swc_common = {version = "0.12.0", path = "../../common"}
|
||||
swc_ecma_ast = {version = "0.52.0", path = "../../ecmascript/ast"}
|
||||
swc_ecma_parser = {version = "0.70.0", path = "../../ecmascript/parser"}
|
||||
swc_plugin = {version = "0.4.0", path = "../"}
|
||||
swc_ecma_parser = {version = "0.70.2", path = "../../ecmascript/parser"}
|
||||
swc_plugin = {version = "0.4.1", path = "../"}
|
||||
|
||||
[dev-dependencies]
|
||||
swc_ecma_codegen = {version = "0.70.0", path = "../../ecmascript/codegen"}
|
||||
swc_ecma_codegen = {version = "0.70.2", path = "../../ecmascript/codegen"}
|
||||
testing = {version = "0.13.0", path = "../../testing"}
|
||||
|
@ -6,7 +6,7 @@ edition = "2018"
|
||||
license = "Apache-2.0/MIT"
|
||||
name = "swc_plugin_testing"
|
||||
repository = "https://github.com/swc-project/swc.git"
|
||||
version = "0.4.0"
|
||||
version = "0.4.1"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
@ -15,7 +15,7 @@ anyhow = "1.0.41"
|
||||
swc_atoms = {version = "0.2.7", path = "../../atoms"}
|
||||
swc_common = {version = "0.12.0", path = "../../common"}
|
||||
swc_ecma_ast = {version = "0.52.0", path = "../../ecmascript/ast"}
|
||||
swc_ecma_codegen = {version = "0.70.0", path = "../../ecmascript/codegen"}
|
||||
swc_ecma_utils = {version = "0.44.0", path = "../../ecmascript/utils"}
|
||||
swc_ecma_visit = {version = "0.38.0", path = "../../ecmascript/visit"}
|
||||
swc_plugin = {version = "0.4.0", path = "../"}
|
||||
swc_ecma_codegen = {version = "0.70.2", path = "../../ecmascript/codegen"}
|
||||
swc_ecma_utils = {version = "0.44.2", path = "../../ecmascript/utils"}
|
||||
swc_ecma_visit = {version = "0.38.1", path = "../../ecmascript/visit"}
|
||||
swc_plugin = {version = "0.4.1", path = "../"}
|
||||
|
Loading…
Reference in New Issue
Block a user