diff --git a/Cargo.toml b/Cargo.toml index f3874d201f84..62a42d1adb3a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,7 +11,7 @@ edition = "2018" license = "Apache-2.0/MIT" name = "swc" repository = "https://github.com/swc-project/swc.git" -version = "0.15.0" +version = "0.15.1" [lib] name = "swc" @@ -28,13 +28,13 @@ serde = {version = "1", features = ["derive"]} serde_json = "1" sourcemap = "6" swc_atoms = {version = "0.2", path = "./atoms"} -swc_common = {version = "0.10.10", path = "./common", features = ["sourcemap", "concurrent"]} -swc_ecma_ast = {version = "0.43.0", path = "./ecmascript/ast"} -swc_ecma_codegen = {version = "0.52.0", path = "./ecmascript/codegen"} -swc_ecma_ext_transforms = {version = "0.12.0", path = "./ecmascript/ext-transforms"} -swc_ecma_parser = {version = "0.54.0", path = "./ecmascript/parser"} -swc_ecma_preset_env = {version = "0.15.0", path = "./ecmascript/preset_env"} -swc_ecma_transforms = {version = "0.45.0", path = "./ecmascript/transforms", features = [ +swc_common = {version = "0.10.16", path = "./common", features = ["sourcemap", "concurrent"]} +swc_ecma_ast = {version = "0.43.1", path = "./ecmascript/ast"} +swc_ecma_codegen = {version = "0.52.1", path = "./ecmascript/codegen"} +swc_ecma_ext_transforms = {version = "0.12.1", path = "./ecmascript/ext-transforms"} +swc_ecma_parser = {version = "0.54.2", path = "./ecmascript/parser"} +swc_ecma_preset_env = {version = "0.15.1", path = "./ecmascript/preset_env"} +swc_ecma_transforms = {version = "0.45.1", path = "./ecmascript/transforms", features = [ "compat", "module", "optimization", @@ -42,13 +42,13 @@ swc_ecma_transforms = {version = "0.45.0", path = "./ecmascript/transforms", fea "react", "typescript", ]} -swc_ecma_utils = {version = "0.34.0", path = "./ecmascript/utils"} -swc_ecma_visit = {version = "0.29.0", path = "./ecmascript/visit"} +swc_ecma_utils = {version = "0.34.1", path = "./ecmascript/utils"} +swc_ecma_visit = {version = "0.29.1", path = "./ecmascript/visit"} swc_visit = {version = "0.2.3", path = "./visit"} [dev-dependencies] rayon = "1" -testing = {version = "0.10.3", path = "./testing"} +testing = {version = "0.10.5", path = "./testing"} walkdir = "2" [[example]] diff --git a/bundler/Cargo.toml b/bundler/Cargo.toml index 6c30f2e74630..f16c450e8731 100644 --- a/bundler/Cargo.toml +++ b/bundler/Cargo.toml @@ -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.32.0" +version = "0.32.1" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [features] @@ -31,21 +31,21 @@ rayon = {version = "1", optional = true} relative-path = "1.2" retain_mut = "0.1.2" swc_atoms = {version = "0.2.4", path = "../atoms"} -swc_common = {version = "0.10.10", path = "../common"} -swc_ecma_ast = {version = "0.43.0", path = "../ecmascript/ast"} -swc_ecma_codegen = {version = "0.52.0", path = "../ecmascript/codegen"} -swc_ecma_parser = {version = "0.54.0", path = "../ecmascript/parser"} -swc_ecma_transforms = {version = "0.45.0", path = "../ecmascript/transforms", features = ["optimization"]} -swc_ecma_utils = {version = "0.34.0", path = "../ecmascript/utils"} -swc_ecma_visit = {version = "0.29.0", path = "../ecmascript/visit"} +swc_common = {version = "0.10.16", path = "../common"} +swc_ecma_ast = {version = "0.43.1", path = "../ecmascript/ast"} +swc_ecma_codegen = {version = "0.52.1", path = "../ecmascript/codegen"} +swc_ecma_parser = {version = "0.54.2", path = "../ecmascript/parser"} +swc_ecma_transforms = {version = "0.45.1", path = "../ecmascript/transforms", features = ["optimization"]} +swc_ecma_utils = {version = "0.34.1", path = "../ecmascript/utils"} +swc_ecma_visit = {version = "0.29.1", path = "../ecmascript/visit"} [dev-dependencies] hex = "0.4" ntest = "0.7.2" reqwest = {version = "0.10.8", features = ["blocking"]} sha-1 = "0.9" -swc_ecma_transforms = {version = "0.45.0", path = "../ecmascript/transforms", features = ["react", "typescript"]} +swc_ecma_transforms = {version = "0.45.1", path = "../ecmascript/transforms", features = ["react", "typescript"]} tempfile = "3.1.0" -testing = {version = "0.10.3", path = "../testing"} +testing = {version = "0.10.5", path = "../testing"} url = "2.1.1" walkdir = "2" diff --git a/common/Cargo.toml b/common/Cargo.toml index 12addbbd03af..593db861bfe2 100644 --- a/common/Cargo.toml +++ b/common/Cargo.toml @@ -6,7 +6,7 @@ edition = "2018" license = "Apache-2.0/MIT" name = "swc_common" repository = "https://github.com/swc-project/swc.git" -version = "0.10.15" +version = "0.10.16" [features] concurrent = ["parking_lot"] diff --git a/common/src/comments.rs b/common/src/comments.rs index 51ae7d677135..f252e149d2ce 100644 --- a/common/src/comments.rs +++ b/common/src/comments.rs @@ -1,6 +1,6 @@ use crate::{ pos::Spanned, - syntax_pos::{BytePos, Span}, + syntax_pos::{BytePos, Span, DUMMY_SP}, }; use fxhash::FxHashMap; use std::{ @@ -37,6 +37,29 @@ pub trait Comments { fn has_trailing(&self, pos: BytePos) -> bool; fn move_trailing(&self, from: BytePos, to: BytePos); fn take_trailing(&self, pos: BytePos) -> Option>; + + fn add_pure_comment(&self, pos: BytePos) { + let mut leading = self.take_leading(pos); + let pure_comment = Comment { + kind: CommentKind::Block, + span: DUMMY_SP, + text: "#__PURE__".into(), + }; + + match &mut leading { + Some(comments) => { + if !comments.iter().any(|c| c.text == pure_comment.text) { + comments.push(pure_comment); + } + } + None => { + leading = Some(vec![pure_comment]); + } + } + if let Some(leading) = leading { + self.add_leading_comments(pos, leading); + } + } } macro_rules! delegate { @@ -80,6 +103,10 @@ macro_rules! delegate { fn take_trailing(&self, pos: BytePos) -> Option> { (**self).take_trailing(pos) } + + fn add_pure_comment(&self, pos: BytePos) { + (**self).add_pure_comment(pos) + } }; } diff --git a/ecmascript/Cargo.toml b/ecmascript/Cargo.toml index 01b04303fb68..e10ed14bfb58 100644 --- a/ecmascript/Cargo.toml +++ b/ecmascript/Cargo.toml @@ -6,7 +6,7 @@ edition = "2018" license = "Apache-2.0/MIT" name = "swc_ecmascript" repository = "https://github.com/swc-project/swc.git" -version = "0.31.0" +version = "0.31.1" [package.metadata.docs.rs] all-features = true @@ -27,12 +27,12 @@ react = ["swc_ecma_transforms/react"] typescript = ["swc_ecma_transforms/typescript"] [dependencies] -swc_ecma_ast = {version = "0.43.0", path = "./ast"} -swc_ecma_codegen = {version = "0.52.0", path = "./codegen", optional = true} -swc_ecma_dep_graph = {version = "0.22.0", path = "./dep-graph", optional = true} -swc_ecma_parser = {version = "0.54.0", path = "./parser", optional = true} -swc_ecma_transforms = {version = "0.45.0", path = "./transforms", optional = true} -swc_ecma_utils = {version = "0.34.0", path = "./utils", optional = true} -swc_ecma_visit = {version = "0.29.0", path = "./visit", optional = true} +swc_ecma_ast = {version = "0.43.1", path = "./ast"} +swc_ecma_codegen = {version = "0.52.1", path = "./codegen", optional = true} +swc_ecma_dep_graph = {version = "0.22.1", path = "./dep-graph", optional = true} +swc_ecma_parser = {version = "0.54.2", path = "./parser", optional = true} +swc_ecma_transforms = {version = "0.45.1", path = "./transforms", optional = true} +swc_ecma_utils = {version = "0.34.1", path = "./utils", optional = true} +swc_ecma_visit = {version = "0.29.1", path = "./visit", optional = true} [dev-dependencies] diff --git a/ecmascript/ast/Cargo.toml b/ecmascript/ast/Cargo.toml index d5fcbd718cde..26acfbea7cb9 100644 --- a/ecmascript/ast/Cargo.toml +++ b/ecmascript/ast/Cargo.toml @@ -6,7 +6,7 @@ edition = "2018" license = "Apache-2.0/MIT" name = "swc_ecma_ast" repository = "https://github.com/swc-project/swc.git" -version = "0.43.0" +version = "0.43.1" [features] default = [] @@ -19,7 +19,7 @@ num-bigint = {version = "0.2", features = ["serde"]} serde = {version = "1.0.88", features = ["derive"]} string_enum = {version = "0.3.1", path = "../../macros/string_enum"} swc_atoms = {version = "0.2", path = "../../atoms"} -swc_common = {version = "0.10.10", path = "../../common"} +swc_common = {version = "0.10.16", path = "../../common"} [dev-dependencies] serde_json = "1" diff --git a/ecmascript/codegen/Cargo.toml b/ecmascript/codegen/Cargo.toml index c2a43535654f..9b47bfb4b057 100644 --- a/ecmascript/codegen/Cargo.toml +++ b/ecmascript/codegen/Cargo.toml @@ -7,18 +7,18 @@ include = ["Cargo.toml", "src/**/*.rs"] license = "Apache-2.0/MIT" name = "swc_ecma_codegen" repository = "https://github.com/swc-project/swc.git" -version = "0.52.0" +version = "0.52.1" [dependencies] bitflags = "1" num-bigint = {version = "0.2", features = ["serde"]} sourcemap = "6" swc_atoms = {version = "0.2", path = "../../atoms"} -swc_common = {version = "0.10.10", path = "../../common"} -swc_ecma_ast = {version = "0.43.0", path = "../ast"} +swc_common = {version = "0.10.16", path = "../../common"} +swc_ecma_ast = {version = "0.43.1", path = "../ast"} swc_ecma_codegen_macros = {version = "0.5.2", path = "./macros"} -swc_ecma_parser = {version = "0.54.0", path = "../parser"} +swc_ecma_parser = {version = "0.54.2", path = "../parser"} [dev-dependencies] -swc_common = {version = "0.10.10", path = "../../common", features = ["sourcemap"]} -testing = {version = "0.10.3", path = "../../testing"} +swc_common = {version = "0.10.16", path = "../../common", features = ["sourcemap"]} +testing = {version = "0.10.5", path = "../../testing"} diff --git a/ecmascript/dep-graph/Cargo.toml b/ecmascript/dep-graph/Cargo.toml index 2b4d00e568d1..563ad6fc1688 100644 --- a/ecmascript/dep-graph/Cargo.toml +++ b/ecmascript/dep-graph/Cargo.toml @@ -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.22.0" +version = "0.22.1" [dependencies] swc_atoms = {version = "0.2", path = "../../atoms"} -swc_common = {version = "0.10.10", path = "../../common"} -swc_ecma_ast = {version = "0.43.0", path = "../ast"} -swc_ecma_visit = {version = "0.29.0", path = "../visit"} +swc_common = {version = "0.10.16", path = "../../common"} +swc_ecma_ast = {version = "0.43.1", path = "../ast"} +swc_ecma_visit = {version = "0.29.1", path = "../visit"} [dev-dependencies] -swc_ecma_parser = {version = "0.54.0", path = "../parser"} -testing = {version = "0.10.3", path = "../../testing"} +swc_ecma_parser = {version = "0.54.2", path = "../parser"} +testing = {version = "0.10.5", path = "../../testing"} diff --git a/ecmascript/ext-transforms/Cargo.toml b/ecmascript/ext-transforms/Cargo.toml index 2defc7446897..b123c760cb73 100644 --- a/ecmascript/ext-transforms/Cargo.toml +++ b/ecmascript/ext-transforms/Cargo.toml @@ -5,15 +5,15 @@ documentation = "https://rustdoc.swc.rs/swc_ecma_ext_transforms/" edition = "2018" license = "Apache-2.0/MIT" name = "swc_ecma_ext_transforms" -version = "0.12.0" +version = "0.12.1" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] phf = {version = "0.8.0", features = ["macros"]} swc_atoms = {version = "0.2", path = "../../atoms"} -swc_common = {version = "0.10.10", path = "../../common"} -swc_ecma_ast = {version = "0.43.0", path = "../ast"} -swc_ecma_parser = {version = "0.54.0", path = "../parser"} -swc_ecma_utils = {version = "0.34.0", path = "../utils"} -swc_ecma_visit = {version = "0.29.0", path = "../visit"} +swc_common = {version = "0.10.16", path = "../../common"} +swc_ecma_ast = {version = "0.43.1", path = "../ast"} +swc_ecma_parser = {version = "0.54.2", path = "../parser"} +swc_ecma_utils = {version = "0.34.1", path = "../utils"} +swc_ecma_visit = {version = "0.29.1", path = "../visit"} diff --git a/ecmascript/jsdoc/Cargo.toml b/ecmascript/jsdoc/Cargo.toml index ac62f397d051..7a83650fc9bb 100644 --- a/ecmascript/jsdoc/Cargo.toml +++ b/ecmascript/jsdoc/Cargo.toml @@ -5,7 +5,7 @@ documentation = "https://rustdoc.swc.rs/jsdoc/" edition = "2018" license = "Apache-2.0/MIT" name = "jsdoc" -version = "0.22.0" +version = "0.22.1" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html @@ -13,12 +13,12 @@ version = "0.22.0" nom = "5.1.2" serde = {version = "1", features = ["derive"]} swc_atoms = {version = "0.2", path = "../../atoms"} -swc_common = {version = "0.10.10", path = "../../common"} +swc_common = {version = "0.10.16", path = "../../common"} [dev-dependencies] anyhow = "1" dashmap = "3" -swc_ecma_ast = {version = "0.43.0", path = "../ast"} -swc_ecma_parser = {version = "0.54.0", path = "../parser"} -testing = {version = "0.10.3", path = "../../testing"} +swc_ecma_ast = {version = "0.43.1", path = "../ast"} +swc_ecma_parser = {version = "0.54.2", path = "../parser"} +testing = {version = "0.10.5", path = "../../testing"} walkdir = "2" diff --git a/ecmascript/loader/Cargo.toml b/ecmascript/loader/Cargo.toml index 57bc0e44e310..a13069bd6ffd 100644 --- a/ecmascript/loader/Cargo.toml +++ b/ecmascript/loader/Cargo.toml @@ -6,15 +6,15 @@ edition = "2018" license = "Apache-2.0/MIT" name = "swc_ecma_loader" 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] swc_atoms = {version = "0.2.3", path = "../../atoms"} -swc_common = {version = "0.10.10", path = "../../common"} -swc_ecma_ast = {version = "0.43.0", path = "../ast"} -swc_ecma_visit = {version = "0.29.0", path = "../visit"} +swc_common = {version = "0.10.16", path = "../../common"} +swc_ecma_ast = {version = "0.43.1", path = "../ast"} +swc_ecma_visit = {version = "0.29.1", path = "../visit"} [dev-dependencies] -testing = {version = "0.10.3", path = "../../testing"} +testing = {version = "0.10.5", path = "../../testing"} diff --git a/ecmascript/parser/Cargo.toml b/ecmascript/parser/Cargo.toml index 22c910ddfb8c..69d976fc9359 100644 --- a/ecmascript/parser/Cargo.toml +++ b/ecmascript/parser/Cargo.toml @@ -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.54.1" +version = "0.54.2" [features] default = [] @@ -21,16 +21,16 @@ num-bigint = "0.2" serde = {version = "1", features = ["derive"]} smallvec = "1" swc_atoms = {version = "0.2.3", path = "../../atoms"} -swc_common = {version = "0.10.10", path = "../../common"} -swc_ecma_ast = {version = "0.43.0", path = "../ast"} -swc_ecma_visit = {version = "0.29.0", path = "../visit"} +swc_common = {version = "0.10.16", path = "../../common"} +swc_ecma_ast = {version = "0.43.1", path = "../ast"} +swc_ecma_visit = {version = "0.29.1", path = "../visit"} unicode-xid = "0.2" [dev-dependencies] env_logger = "0.7" pretty_assertions = "0.6" serde_json = "1" -testing = {version = "0.10.3", path = "../../testing"} +testing = {version = "0.10.5", path = "../../testing"} walkdir = "2" [[example]] diff --git a/ecmascript/preset_env/Cargo.toml b/ecmascript/preset_env/Cargo.toml index 5f7761183b48..b4012bdada40 100644 --- a/ecmascript/preset_env/Cargo.toml +++ b/ecmascript/preset_env/Cargo.toml @@ -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.15.0" +version = "0.15.1" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html @@ -19,15 +19,15 @@ serde_json = "1" st-map = "0.1.2" string_enum = {version = "0.3.1", path = "../../macros/string_enum"} swc_atoms = {version = "0.2", path = "../../atoms"} -swc_common = {version = "0.10.10", path = "../../common"} -swc_ecma_ast = {version = "0.43.0", path = "../ast"} -swc_ecma_transforms = {version = "0.45.0", path = "../transforms", features = ["compat", "proposal"]} -swc_ecma_utils = {version = "0.34.0", path = "../utils"} -swc_ecma_visit = {version = "0.29.0", path = "../visit"} +swc_common = {version = "0.10.16", path = "../../common"} +swc_ecma_ast = {version = "0.43.1", path = "../ast"} +swc_ecma_transforms = {version = "0.45.1", path = "../transforms", features = ["compat", "proposal"]} +swc_ecma_utils = {version = "0.34.1", path = "../utils"} +swc_ecma_visit = {version = "0.29.1", path = "../visit"} walkdir = "2" [dev-dependencies] pretty_assertions = "0.6" -swc_ecma_codegen = {version = "0.52.0", path = "../codegen"} -swc_ecma_parser = {version = "0.54.0", path = "../parser"} -testing = {version = "0.10.3", path = "../../testing"} +swc_ecma_codegen = {version = "0.52.1", path = "../codegen"} +swc_ecma_parser = {version = "0.54.2", path = "../parser"} +testing = {version = "0.10.5", path = "../../testing"} diff --git a/ecmascript/transforms/Cargo.toml b/ecmascript/transforms/Cargo.toml index e94e00daca32..b47ea4a873ad 100644 --- a/ecmascript/transforms/Cargo.toml +++ b/ecmascript/transforms/Cargo.toml @@ -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.45.0" +version = "0.45.1" [package.metadata.docs.rs] all-features = true @@ -22,25 +22,25 @@ typescript = ["swc_ecma_transforms_typescript"] [dependencies] swc_atoms = {version = "0.2.0", path = "../../atoms"} -swc_common = {version = "0.10.10", path = "../../common"} -swc_ecma_ast = {version = "0.43.0", path = "../ast"} -swc_ecma_parser = {version = "0.54.0", path = "../parser"} -swc_ecma_transforms_base = {version = "0.12.0", path = "./base"} -swc_ecma_transforms_compat = {version = "0.13.0", path = "./compat", optional = true} -swc_ecma_transforms_module = {version = "0.13.0", path = "./module", optional = true} -swc_ecma_transforms_optimization = {version = "0.15.0", path = "./optimization", optional = true} -swc_ecma_transforms_proposal = {version = "0.13.0", path = "./proposal", optional = true} -swc_ecma_transforms_react = {version = "0.14.0", path = "./react", optional = true} -swc_ecma_transforms_typescript = {version = "0.14.0", path = "./typescript", optional = true} -swc_ecma_utils = {version = "0.34.0", path = "../utils"} -swc_ecma_visit = {version = "0.29.0", path = "../visit"} +swc_common = {version = "0.10.16", path = "../../common"} +swc_ecma_ast = {version = "0.43.1", path = "../ast"} +swc_ecma_parser = {version = "0.54.2", path = "../parser"} +swc_ecma_transforms_base = {version = "0.12.2", path = "./base"} +swc_ecma_transforms_compat = {version = "0.13.1", path = "./compat", optional = true} +swc_ecma_transforms_module = {version = "0.13.1", path = "./module", optional = true} +swc_ecma_transforms_optimization = {version = "0.15.2", path = "./optimization", optional = true} +swc_ecma_transforms_proposal = {version = "0.13.1", path = "./proposal", optional = true} +swc_ecma_transforms_react = {version = "0.14.1", path = "./react", optional = true} +swc_ecma_transforms_typescript = {version = "0.14.1", path = "./typescript", optional = true} +swc_ecma_utils = {version = "0.34.1", path = "../utils"} +swc_ecma_visit = {version = "0.29.1", path = "../visit"} unicode-xid = "0.2" [dev-dependencies] pretty_assertions = "0.6" sourcemap = "6" -swc_ecma_codegen = {version = "0.52.0", path = "../codegen"} -swc_ecma_transforms_testing = {version = "0.12.0", path = "./testing"} +swc_ecma_codegen = {version = "0.52.1", path = "../codegen"} +swc_ecma_transforms_testing = {version = "0.12.1", path = "./testing"} tempfile = "3" -testing = {version = "0.10.3", path = "../../testing"} +testing = {version = "0.10.5", path = "../../testing"} walkdir = "2" diff --git a/ecmascript/transforms/base/Cargo.toml b/ecmascript/transforms/base/Cargo.toml index 4d277b3ed59e..b2e7abf6a3fc 100644 --- a/ecmascript/transforms/base/Cargo.toml +++ b/ecmascript/transforms/base/Cargo.toml @@ -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.12.1" +version = "0.12.2" [dependencies] fxhash = "0.2.1" @@ -15,12 +15,12 @@ phf = {version = "0.8.0", features = ["macros"]} scoped-tls = "1.0.0" smallvec = "1.6.0" swc_atoms = {version = "0.2", path = "../../../atoms"} -swc_common = {version = "0.10.10", path = "../../../common"} -swc_ecma_ast = {version = "0.43.0", path = "../../ast"} -swc_ecma_parser = {version = "0.54.0", path = "../../parser"} -swc_ecma_utils = {version = "0.34.0", path = "../../utils"} -swc_ecma_visit = {version = "0.29.0", path = "../../visit"} +swc_common = {version = "0.10.16", path = "../../../common"} +swc_ecma_ast = {version = "0.43.1", path = "../../ast"} +swc_ecma_parser = {version = "0.54.2", path = "../../parser"} +swc_ecma_utils = {version = "0.34.1", path = "../../utils"} +swc_ecma_visit = {version = "0.29.1", path = "../../visit"} [dev-dependencies] -swc_ecma_codegen = {version = "0.52.0", path = "../../codegen"} -testing = {version = "0.10.3", path = "../../../testing"} +swc_ecma_codegen = {version = "0.52.1", path = "../../codegen"} +testing = {version = "0.10.5", path = "../../../testing"} diff --git a/ecmascript/transforms/compat/Cargo.toml b/ecmascript/transforms/compat/Cargo.toml index 6038d416370a..9a380720e0e4 100644 --- a/ecmascript/transforms/compat/Cargo.toml +++ b/ecmascript/transforms/compat/Cargo.toml @@ -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.13.0" +version = "0.13.1" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] @@ -19,14 +19,14 @@ ordered-float = "2.0.1" serde = {version = "1.0.118", features = ["derive"]} smallvec = "1.6.0" swc_atoms = {version = "0.2.5", path = "../../../atoms"} -swc_common = {version = "0.10.10", path = "../../../common"} -swc_ecma_ast = {version = "0.43.0", path = "../../ast"} -swc_ecma_transforms_base = {version = "0.12.0", path = "../base"} +swc_common = {version = "0.10.16", path = "../../../common"} +swc_ecma_ast = {version = "0.43.1", path = "../../ast"} +swc_ecma_transforms_base = {version = "0.12.2", path = "../base"} swc_ecma_transforms_macros = {version = "0.2.1", path = "../macros"} -swc_ecma_utils = {version = "0.34.0", path = "../../utils"} -swc_ecma_visit = {version = "0.29.0", path = "../../visit"} +swc_ecma_utils = {version = "0.34.1", path = "../../utils"} +swc_ecma_visit = {version = "0.29.1", path = "../../visit"} [dev-dependencies] -swc_ecma_parser = {version = "0.54.0", path = "../../parser"} -swc_ecma_transforms_testing = {version = "0.12.0", path = "../testing"} -testing = {version = "0.10.3", path = "../../../testing"} +swc_ecma_parser = {version = "0.54.2", path = "../../parser"} +swc_ecma_transforms_testing = {version = "0.12.1", path = "../testing"} +testing = {version = "0.10.5", path = "../../../testing"} diff --git a/ecmascript/transforms/module/Cargo.toml b/ecmascript/transforms/module/Cargo.toml index 4f54beb5375c..d822bfbdaf27 100644 --- a/ecmascript/transforms/module/Cargo.toml +++ b/ecmascript/transforms/module/Cargo.toml @@ -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.13.0" +version = "0.13.1" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] @@ -15,14 +15,14 @@ fxhash = "0.2.1" indexmap = "1.6.1" serde = {version = "1.0.118", features = ["derive"]} swc_atoms = {version = "0.2", path = "../../../atoms"} -swc_common = {version = "0.10.10", path = "../../../common"} -swc_ecma_ast = {version = "0.43.0", path = "../../ast"} -swc_ecma_parser = {version = "0.54.0", path = "../../parser"} -swc_ecma_transforms_base = {version = "0.12.0", path = "../base"} -swc_ecma_utils = {version = "0.34.0", path = "../../utils"} -swc_ecma_visit = {version = "0.29.0", path = "../../visit"} +swc_common = {version = "0.10.16", path = "../../../common"} +swc_ecma_ast = {version = "0.43.1", path = "../../ast"} +swc_ecma_parser = {version = "0.54.2", path = "../../parser"} +swc_ecma_transforms_base = {version = "0.12.2", path = "../base"} +swc_ecma_utils = {version = "0.34.1", path = "../../utils"} +swc_ecma_visit = {version = "0.29.1", path = "../../visit"} [dev-dependencies] -swc_ecma_transforms_compat = {version = "0.13.0", path = "../compat"} -swc_ecma_transforms_testing = {version = "0.12.0", path = "../testing/"} -testing = {version = "0.10.3", path = "../../../testing/"} +swc_ecma_transforms_compat = {version = "0.13.1", path = "../compat"} +swc_ecma_transforms_testing = {version = "0.12.1", path = "../testing/"} +testing = {version = "0.10.5", path = "../../../testing/"} diff --git a/ecmascript/transforms/optimization/Cargo.toml b/ecmascript/transforms/optimization/Cargo.toml index 84a59c8e077e..fd9981c90a94 100644 --- a/ecmascript/transforms/optimization/Cargo.toml +++ b/ecmascript/transforms/optimization/Cargo.toml @@ -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.15.1" +version = "0.15.2" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] @@ -18,18 +18,18 @@ once_cell = "1.5.2" retain_mut = "0.1.2" serde_json = "1.0.61" swc_atoms = {version = "0.2", path = "../../../atoms"} -swc_common = {version = "0.10.10", path = "../../../common"} -swc_ecma_ast = {version = "0.43.0", path = "../../ast"} -swc_ecma_parser = {version = "0.54.0", path = "../../parser"} -swc_ecma_transforms_base = {version = "0.12.0", path = "../base"} -swc_ecma_utils = {version = "0.34.0", path = "../../utils"} -swc_ecma_visit = {version = "0.29.0", path = "../../visit"} +swc_common = {version = "0.10.16", path = "../../../common"} +swc_ecma_ast = {version = "0.43.1", path = "../../ast"} +swc_ecma_parser = {version = "0.54.2", path = "../../parser"} +swc_ecma_transforms_base = {version = "0.12.2", path = "../base"} +swc_ecma_utils = {version = "0.34.1", path = "../../utils"} +swc_ecma_visit = {version = "0.29.1", path = "../../visit"} [dev-dependencies] -swc_ecma_transforms_compat = {version = "0.13.0", path = "../compat"} -swc_ecma_transforms_module = {version = "0.13.0", path = "../module"} -swc_ecma_transforms_proposal = {version = "0.13.0", path = "../proposal"} -swc_ecma_transforms_react = {version = "0.14.0", path = "../react"} -swc_ecma_transforms_testing = {version = "0.12.0", path = "../testing"} -swc_ecma_transforms_typescript = {version = "0.14.0", path = "../typescript"} -testing = {version = "0.10.0", path = "../../../testing"} +swc_ecma_transforms_compat = {version = "0.13.1", path = "../compat"} +swc_ecma_transforms_module = {version = "0.13.1", path = "../module"} +swc_ecma_transforms_proposal = {version = "0.13.1", path = "../proposal"} +swc_ecma_transforms_react = {version = "0.14.1", path = "../react"} +swc_ecma_transforms_testing = {version = "0.12.1", path = "../testing"} +swc_ecma_transforms_typescript = {version = "0.14.1", path = "../typescript"} +testing = {version = "0.10.5", path = "../../../testing"} diff --git a/ecmascript/transforms/proposal/Cargo.toml b/ecmascript/transforms/proposal/Cargo.toml index 5468942a2abf..0df623a44d0b 100644 --- a/ecmascript/transforms/proposal/Cargo.toml +++ b/ecmascript/transforms/proposal/Cargo.toml @@ -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.13.0" +version = "0.13.1" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html @@ -20,15 +20,15 @@ fxhash = "0.2.1" serde = {version = "1.0.118", features = ["derive"]} smallvec = "1.6.0" swc_atoms = {version = "0.2", path = "../../../atoms"} -swc_common = {version = "0.10.10", path = "../../../common"} -swc_ecma_ast = {version = "0.43.0", path = "../../ast"} -swc_ecma_loader = {version = "0.4.0", path = "../../loader", optional = true} -swc_ecma_parser = {version = "0.54.0", path = "../../parser"} -swc_ecma_transforms_base = {version = "0.12.0", path = "../base"} -swc_ecma_utils = {version = "0.34.0", path = "../../utils"} -swc_ecma_visit = {version = "0.29.0", path = "../../visit"} +swc_common = {version = "0.10.16", path = "../../../common"} +swc_ecma_ast = {version = "0.43.1", path = "../../ast"} +swc_ecma_loader = {version = "0.4.1", path = "../../loader", optional = true} +swc_ecma_parser = {version = "0.54.2", path = "../../parser"} +swc_ecma_transforms_base = {version = "0.12.2", path = "../base"} +swc_ecma_utils = {version = "0.34.1", path = "../../utils"} +swc_ecma_visit = {version = "0.29.1", path = "../../visit"} [dev-dependencies] -swc_ecma_transforms_compat = {version = "0.13.0", path = "../compat"} -swc_ecma_transforms_module = {version = "0.13.0", path = "../module"} -swc_ecma_transforms_testing = {version = "0.12.0", path = "../testing"} +swc_ecma_transforms_compat = {version = "0.13.1", path = "../compat"} +swc_ecma_transforms_module = {version = "0.13.1", path = "../module"} +swc_ecma_transforms_testing = {version = "0.12.1", path = "../testing"} diff --git a/ecmascript/transforms/react/Cargo.toml b/ecmascript/transforms/react/Cargo.toml index 211ef2a2dca8..983d65a441e9 100644 --- a/ecmascript/transforms/react/Cargo.toml +++ b/ecmascript/transforms/react/Cargo.toml @@ -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.14.0" +version = "0.14.1" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] @@ -20,15 +20,16 @@ serde = {version = "1.0.118", features = ["derive"]} sha-1 = "0.9.4" string_enum = {version = "0.3.1", path = "../../../macros/string_enum"} swc_atoms = {version = "0.2", path = "../../../atoms"} -swc_common = {version = "0.10.10", path = "../../../common"} -swc_ecma_ast = {version = "0.43.0", path = "../../ast"} -swc_ecma_parser = {version = "0.54.0", path = "../../parser"} -swc_ecma_transforms_base = {version = "0.12.0", path = "../base"} -swc_ecma_utils = {version = "0.34.0", path = "../../utils"} -swc_ecma_visit = {version = "0.29.0", path = "../../visit"} +swc_common = {version = "0.10.16", path = "../../../common"} +swc_ecma_ast = {version = "0.43.1", path = "../../ast"} +swc_ecma_parser = {version = "0.54.2", path = "../../parser"} +swc_ecma_transforms_base = {version = "0.12.2", path = "../base"} +swc_ecma_utils = {version = "0.34.1", path = "../../utils"} +swc_ecma_visit = {version = "0.29.1", path = "../../visit"} [dev-dependencies] -swc_ecma_transforms_compat = {version = "0.13.0", path = "../compat/"} -swc_ecma_transforms_module = {version = "0.13.0", path = "../module"} -swc_ecma_transforms_testing = {version = "0.12.0", path = "../testing/"} -testing = {version = "0.10.3", path = "../../../testing"} +swc_ecma_transforms_compat = {version = "0.13.1", path = "../compat/"} +swc_ecma_transforms_module = {version = "0.13.1", path = "../module"} +swc_ecma_transforms_testing = {version = "0.12.1", path = "../testing/"} +swc_ecma_codegen = {version = "0.52.1", path = "../../codegen/"} +testing = {version = "0.10.5", path = "../../../testing"} diff --git a/ecmascript/transforms/react/src/jsx/mod.rs b/ecmascript/transforms/react/src/jsx/mod.rs index a18b4698db70..818aa10b646c 100644 --- a/ecmascript/transforms/react/src/jsx/mod.rs +++ b/ecmascript/transforms/react/src/jsx/mod.rs @@ -220,6 +220,10 @@ where let use_jsxs = count_children(&el.children) > 1; + if let Some(comments) = &self.comments { + comments.add_pure_comment(span.lo); + } + match self.runtime { Runtime::Automatic => { let jsx = if use_jsxs { @@ -325,6 +329,10 @@ where let name = self.jsx_name(el.opening.name); + if let Some(comments) = &self.comments { + comments.add_pure_comment(span.lo); + } + match self.runtime { Runtime::Automatic => { // function jsx(tagName: string, props: { children: Node[], ... }, key: string) diff --git a/ecmascript/transforms/react/src/lib.rs b/ecmascript/transforms/react/src/lib.rs index 38e387499ba1..993166d1e240 100644 --- a/ecmascript/transforms/react/src/lib.rs +++ b/ecmascript/transforms/react/src/lib.rs @@ -5,6 +5,7 @@ pub use self::{ jsx::{jsx, Options}, jsx_self::jsx_self, jsx_src::jsx_src, + pure_annotations::pure_annotations, refresh::refresh, }; use swc_common::{chain, comments::Comments, sync::Lrc, SourceMap}; @@ -14,6 +15,7 @@ mod display_name; mod jsx; mod jsx_self; mod jsx_src; +mod pure_annotations; mod refresh; /// `@babel/preset-react` @@ -32,6 +34,7 @@ where display_name(), jsx_src(development, cm.clone()), jsx_self(development), + pure_annotations(comments.clone()), refresh(development, refresh_options, cm.clone(), comments) ) } diff --git a/ecmascript/transforms/react/src/pure_annotations/mod.rs b/ecmascript/transforms/react/src/pure_annotations/mod.rs new file mode 100644 index 000000000000..ac60a4e37fb5 --- /dev/null +++ b/ecmascript/transforms/react/src/pure_annotations/mod.rs @@ -0,0 +1,134 @@ +use std::collections::HashMap; +use swc_atoms::{js_word, JsWord}; +use swc_common::comments::Comments; +use swc_ecma_ast::*; +use swc_ecma_utils::{id, Id}; +use swc_ecma_visit::{Fold, FoldWith}; + +#[cfg(test)] +mod tests; + +/// This pass adds a /*#__PURE__#/ annotation to calls to known pure top-level +/// React methods, so that terser and other minifiers can safely remove them +/// during dead code elimination. +/// See https://reactjs.org/docs/react-api.html +pub fn pure_annotations(comments: Option) -> impl Fold +where + C: Comments, +{ + PureAnnotations { + imports: HashMap::new(), + comments, + } +} + +struct PureAnnotations +where + C: Comments, +{ + imports: HashMap, + comments: Option, +} + +impl Fold for PureAnnotations +where + C: Comments, +{ + fn fold_module(&mut self, module: Module) -> Module { + // Pass 1: collect imports + for item in &module.body { + match item { + ModuleItem::ModuleDecl(ModuleDecl::Import(import)) => { + let src_str = import.src.value.to_string(); + if src_str != "react" && src_str != "react-dom" { + continue; + } + + for specifier in &import.specifiers { + let src = import.src.value.clone(); + match specifier { + ImportSpecifier::Named(named) => { + let imported = match &named.imported { + Some(imported) => imported.sym.clone(), + None => named.local.sym.clone(), + }; + self.imports.insert(id(&named.local), (src, imported)); + } + ImportSpecifier::Default(default) => { + self.imports + .insert(id(&default.local), (src, js_word!("default"))); + } + ImportSpecifier::Namespace(ns) => { + self.imports.insert(id(&ns.local), (src, "*".into())); + } + } + } + } + _ => {} + } + } + + // Pass 2: add pure annotations. + module.fold_children_with(self) + } + + fn fold_call_expr(&mut self, call: CallExpr) -> CallExpr { + let is_react_call = match &call.callee { + ExprOrSuper::Expr(expr) => match &**expr { + Expr::Ident(ident) => { + if let Some((src, specifier)) = self.imports.get(&id(&ident)) { + is_pure(src, specifier) + } else { + false + } + } + Expr::Member(member) => match &member.obj { + ExprOrSuper::Expr(expr) => match &**expr { + Expr::Ident(ident) => { + if let Some((src, specifier)) = self.imports.get(&id(&ident)) { + let specifier_str = specifier.to_string(); + if specifier_str == "default" || specifier_str == "*" { + match &*member.prop { + Expr::Ident(ident) => is_pure(src, &ident.sym), + _ => false, + } + } else { + false + } + } else { + false + } + } + _ => false, + }, + _ => false, + }, + _ => false, + }, + _ => false, + }; + + if is_react_call { + if let Some(comments) = &self.comments { + comments.add_pure_comment(call.span.lo); + } + } + + call.fold_children_with(self) + } +} + +fn is_pure(src: &JsWord, specifier: &JsWord) -> bool { + match src.to_string().as_str() { + "react" => match specifier.to_string().as_str() { + "cloneElement" | "createContext" | "createElement" | "createFactory" | "createRef" + | "forwardRef" | "isValidElement" | "memo" | "lazy" => true, + _ => false, + }, + "react-dom" => match specifier.to_string().as_str() { + "createPortal" => true, + _ => false, + }, + _ => false, + } +} diff --git a/ecmascript/transforms/react/src/pure_annotations/tests.rs b/ecmascript/transforms/react/src/pure_annotations/tests.rs new file mode 100644 index 000000000000..19e56a2064ad --- /dev/null +++ b/ecmascript/transforms/react/src/pure_annotations/tests.rs @@ -0,0 +1,309 @@ +use super::*; +use swc_common::comments::SingleThreadedComments; +use swc_common::{sync::Lrc, FileName, SourceMap}; +use swc_ecma_codegen::{text_writer::JsWriter, Emitter}; +use swc_ecma_parser::{Parser, StringInput}; +use swc_ecma_transforms_base::resolver; +use swc_ecma_transforms_testing::Tester; + +fn parse( + tester: &mut Tester, + src: &str, +) -> Result<(Module, Lrc, Lrc), ()> { + let syntax = ::swc_ecma_parser::Syntax::Es(::swc_ecma_parser::EsConfig { + jsx: true, + dynamic_import: true, + ..Default::default() + }); + let source_map = Lrc::new(SourceMap::default()); + let source_file = source_map.new_source_file(FileName::Anon, src.into()); + + let comments = Lrc::new(SingleThreadedComments::default()); + let module = { + let mut p = Parser::new(syntax, StringInput::from(&*source_file), Some(&comments)); + let res = p + .parse_module() + .map_err(|e| e.into_diagnostic(&tester.handler).emit()); + + for e in p.take_errors() { + e.into_diagnostic(&tester.handler).emit() + } + + res? + }; + + Ok((module, source_map, comments)) +} + +fn emit( + source_map: Lrc, + comments: Lrc, + program: &Module, +) -> String { + let mut src_map_buf = vec![]; + let mut buf = vec![]; + { + let writer = Box::new(JsWriter::new( + source_map.clone(), + "\n", + &mut buf, + Some(&mut src_map_buf), + )); + let mut emitter = Emitter { + cfg: Default::default(), + comments: Some(&comments), + cm: source_map.clone(), + wr: writer, + }; + emitter.emit_module(&program).unwrap(); + } + + return String::from_utf8(buf).unwrap(); +} + +fn run_test(input: &str, expected: &str) { + Tester::run(|tester| { + let (actual, actual_sm, actual_comments) = parse(tester, input)?; + let actual = actual + .fold_with(&mut resolver::resolver()) + .fold_with(&mut crate::react( + actual_sm.clone(), + Some(&actual_comments), + Default::default(), + )); + + let actual_src = emit(actual_sm, actual_comments, &actual); + + let (expected, expected_sm, expected_comments) = parse(tester, expected)?; + let expected_src = emit(expected_sm, expected_comments, &expected); + + if actual_src != expected_src { + println!(">>>>> Orig <<<<<\n{}", input); + println!(">>>>> Code <<<<<\n{}", actual_src); + panic!( + r#"assertion failed: `(left == right)` + {}"#, + ::testing::diff(&actual_src, &expected_src), + ); + } + + Ok(()) + }); +} + +macro_rules! test { + ($test_name:ident, $input:expr, $expected:expr) => { + #[test] + fn $test_name() { + run_test($input, $expected) + } + }; +} + +test!( + forward_ref, + r#" + import {forwardRef} from 'react'; + const Comp = forwardRef((props, ref) => null); + "#, + r#" + import {forwardRef} from 'react'; + const Comp = /*#__PURE__*/ forwardRef((props, ref) => null); + "# +); + +test!( + create_element, + r#" + import React from 'react'; + React.createElement('div'); + "#, + r#" + import React from 'react'; + /*#__PURE__*/ React.createElement('div'); + "# +); + +test!( + create_element_jsx, + r#" + import React from 'react'; + const x =
; + "#, + r#" + import React from 'react'; + const x = /*#__PURE__*/ React.createElement("div", null); + "# +); + +test!( + create_element_fragment_jsx, + r#" + import React from 'react'; + const x = <>
; + "#, + r#" + import React from 'react'; + const x = /*#__PURE__*/ React.createElement(React.Fragment, null, /*#__PURE__*/ React.createElement("div", null)); + "# +); + +test!( + clone_element, + r#" + import React from 'react'; + React.cloneElement(React.createElement('div')); + "#, + r#" + import React from 'react'; + /*#__PURE__*/ React.cloneElement(/*#__PURE__*/ React.createElement('div')); + "# +); + +test!( + create_context, + r#" + import { createContext } from 'react'; + const context = createContext({}); + "#, + r#" + import { createContext } from 'react'; + const context = /*#__PURE__*/createContext({}); + "# +); + +test!( + create_factory, + r#" + import {createFactory} from 'react'; + const div = createFactory('div'); + "#, + r#" + import { createFactory } from 'react'; + const div = /*#__PURE__*/createFactory('div'); + "# +); + +test!( + create_ref, + r#" + import React from 'react'; + React.createRef(); + "#, + r#" + import React from 'react'; + /*#__PURE__*/ React.createRef(); + "# +); + +test!( + is_valid_element, + r#" + import React from 'react'; + const isElement = React.isValidElement(React.createElement('div')); + "#, + r#" + import React from 'react'; + const isElement = /*#__PURE__*/React.isValidElement( /*#__PURE__*/React.createElement('div')); + "# +); + +test!( + lazy, + r#" + import React from 'react'; + const SomeComponent = React.lazy(() => import('./SomeComponent')); + "#, + r#" + import React from 'react'; + const SomeComponent = /*#__PURE__*/React.lazy(() => import('./SomeComponent')); + "# +); + +test!( + memo, + r#" + import React from 'react'; + const Comp = React.memo((props) => null); + "#, + r#" + import React from 'react'; + const Comp = /*#__PURE__*/React.memo(props => null); + "# +); + +test!( + create_portal, + r#" + import * as React from 'react'; + import ReactDOM from 'react-dom'; + const Portal = ReactDOM.createPortal(React.createElement('div'), document.getElementById('test')); + "#, + r#" + import * as React from 'react'; + import ReactDOM from 'react-dom'; + const Portal = /*#__PURE__*/ReactDOM.createPortal( /*#__PURE__*/React.createElement('div'), document.getElementById('test')); + "# +); + +test!( + non_pure_react, + r#" + import {useState} from 'react'; + useState(2); + "#, + r#" + import {useState} from 'react'; + useState(2); + "# +); + +test!( + non_pure_react_dom, + r#" + import React from 'react'; + import ReactDOM from 'react-dom'; + ReactDOM.render(React.createElement('div')); + "#, + r#" + import React from 'react'; + import ReactDOM from 'react-dom'; + ReactDOM.render(/*#__PURE__*/React.createElement('div')); + "# +); + +test!( + non_react_named, + r#" + import {createElement} from 'foo'; + createElement('hi'); + "#, + r#" + import {createElement} from 'foo'; + createElement('hi'); + "# +); + +test!( + non_react_namespace, + r#" + import * as foo from 'foo'; + foo.createElement('hi'); + "#, + r#" + import * as foo from 'foo'; + foo.createElement('hi'); + "# +); + +test!( + non_react_default, + r#" + import foo from 'foo'; + foo.createElement('hi'); + "#, + r#" + import foo from 'foo'; + foo.createElement('hi'); + "# +); diff --git a/ecmascript/transforms/testing/Cargo.toml b/ecmascript/transforms/testing/Cargo.toml index 44ffdb9b3f88..d6fbedba26b2 100644 --- a/ecmascript/transforms/testing/Cargo.toml +++ b/ecmascript/transforms/testing/Cargo.toml @@ -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.12.0" +version = "0.12.1" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html @@ -14,12 +14,12 @@ version = "0.12.0" ansi_term = "0.12.1" serde = "1" serde_json = "1" -swc_common = {version = "0.10.10", path = "../../../common"} -swc_ecma_ast = {version = "0.43.0", path = "../../ast"} -swc_ecma_codegen = {version = "0.52.0", path = "../../codegen"} -swc_ecma_parser = {version = "0.54.0", path = "../../parser"} -swc_ecma_transforms_base = {version = "0.12.0", path = "../base"} -swc_ecma_utils = {version = "0.34.0", path = "../../utils"} -swc_ecma_visit = {version = "0.29.0", path = "../../visit"} +swc_common = {version = "0.10.16", path = "../../../common"} +swc_ecma_ast = {version = "0.43.1", path = "../../ast"} +swc_ecma_codegen = {version = "0.52.1", path = "../../codegen"} +swc_ecma_parser = {version = "0.54.2", path = "../../parser"} +swc_ecma_transforms_base = {version = "0.12.2", path = "../base"} +swc_ecma_utils = {version = "0.34.1", path = "../../utils"} +swc_ecma_visit = {version = "0.29.1", path = "../../visit"} tempfile = "3.1.0" -testing = {version = "0.10.3", path = "../../../testing"} +testing = {version = "0.10.5", path = "../../../testing"} diff --git a/ecmascript/transforms/typescript/Cargo.toml b/ecmascript/transforms/typescript/Cargo.toml index e51dc02f2b3f..f4a3746d062a 100644 --- a/ecmascript/transforms/typescript/Cargo.toml +++ b/ecmascript/transforms/typescript/Cargo.toml @@ -6,25 +6,25 @@ edition = "2018" license = "Apache-2.0/MIT" name = "swc_ecma_transforms_typescript" repository = "https://github.com/swc-project/swc.git" -version = "0.14.0" +version = "0.14.1" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] fxhash = "0.2.1" serde = {version = "1.0.118", features = ["derive"]} swc_atoms = {version = "0.2", path = "../../../atoms"} -swc_common = {version = "0.10.10", path = "../../../common"} -swc_ecma_ast = {version = "0.43.0", path = "../../ast"} -swc_ecma_parser = {version = "0.54.0", path = "../../parser"} -swc_ecma_transforms_base = {version = "0.12.0", path = "../base"} -swc_ecma_utils = {version = "0.34.0", path = "../../utils"} -swc_ecma_visit = {version = "0.29.0", path = "../../visit"} +swc_common = {version = "0.10.16", path = "../../../common"} +swc_ecma_ast = {version = "0.43.1", path = "../../ast"} +swc_ecma_parser = {version = "0.54.2", path = "../../parser"} +swc_ecma_transforms_base = {version = "0.12.2", path = "../base"} +swc_ecma_utils = {version = "0.34.1", path = "../../utils"} +swc_ecma_visit = {version = "0.29.1", path = "../../visit"} [dev-dependencies] -swc_ecma_codegen = {version = "0.52.0", path = "../../codegen"} -swc_ecma_transforms_compat = {version = "0.13.0", path = "../compat"} -swc_ecma_transforms_module = {version = "0.13.0", path = "../module"} -swc_ecma_transforms_proposal = {version = "0.13.0", path = "../proposal/"} -swc_ecma_transforms_testing = {version = "0.12.0", path = "../testing"} -testing = {version = "0.10.3", path = "../../../testing"} +swc_ecma_codegen = {version = "0.52.1", path = "../../codegen"} +swc_ecma_transforms_compat = {version = "0.13.1", path = "../compat"} +swc_ecma_transforms_module = {version = "0.13.1", path = "../module"} +swc_ecma_transforms_proposal = {version = "0.13.1", path = "../proposal/"} +swc_ecma_transforms_testing = {version = "0.12.1", path = "../testing"} +testing = {version = "0.10.5", path = "../../../testing"} walkdir = "2.3.1" diff --git a/ecmascript/utils/Cargo.toml b/ecmascript/utils/Cargo.toml index 5e21e461dab5..dc3182faf45a 100644 --- a/ecmascript/utils/Cargo.toml +++ b/ecmascript/utils/Cargo.toml @@ -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.34.0" +version = "0.34.1" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html @@ -14,10 +14,10 @@ version = "0.34.0" once_cell = "1" scoped-tls = "1" swc_atoms = {version = "0.2.0", path = "../../atoms"} -swc_common = {version = "0.10.10", path = "../../common"} -swc_ecma_ast = {version = "0.43.0", path = "../ast"} -swc_ecma_visit = {version = "0.29.0", path = "../visit"} +swc_common = {version = "0.10.16", path = "../../common"} +swc_ecma_ast = {version = "0.43.1", path = "../ast"} +swc_ecma_visit = {version = "0.29.1", path = "../visit"} unicode-xid = "0.2" [dev-dependencies] -testing = {version = "0.10.3", path = "../../testing"} +testing = {version = "0.10.5", path = "../../testing"} diff --git a/ecmascript/visit/Cargo.toml b/ecmascript/visit/Cargo.toml index be740fa0b3d1..0b968140719f 100644 --- a/ecmascript/visit/Cargo.toml +++ b/ecmascript/visit/Cargo.toml @@ -6,11 +6,11 @@ edition = "2018" license = "Apache-2.0/MIT" name = "swc_ecma_visit" repository = "https://github.com/swc-project/swc.git" -version = "0.29.0" +version = "0.29.1" [dependencies] num-bigint = {version = "0.2", features = ["serde"]} swc_atoms = {version = "0.2", path = "../../atoms"} -swc_common = {version = "0.10.10", path = "../../common"} -swc_ecma_ast = {version = "0.43.0", path = "../ast"} +swc_common = {version = "0.10.16", path = "../../common"} +swc_ecma_ast = {version = "0.43.1", path = "../ast"} swc_visit = {version = "0.2.3", path = "../../visit"} diff --git a/spack/tests/pass/swcrc/jsx/issue-884/output/entry.js b/spack/tests/pass/swcrc/jsx/issue-884/output/entry.js index 0a36ac2c8c09..4e9cea206d8c 100644 --- a/spack/tests/pass/swcrc/jsx/issue-884/output/entry.js +++ b/spack/tests/pass/swcrc/jsx/issue-884/output/entry.js @@ -1,4 +1,4 @@ -var Divider1 = React.createElement("div", null); +var Divider1 = /*#__PURE__*/ React.createElement("div", null); /** * Don't ask why it is named as divider. */ export { Divider1 as Divider }; diff --git a/testing/Cargo.toml b/testing/Cargo.toml index ce8d8247bebe..677a1ebf9a2f 100644 --- a/testing/Cargo.toml +++ b/testing/Cargo.toml @@ -6,7 +6,7 @@ edition = "2018" license = "Apache-2.0/MIT" name = "testing" repository = "https://github.com/swc-project/swc.git" -version = "0.10.4" +version = "0.10.5" [dependencies] ansi_term = "0.12.1" @@ -16,5 +16,5 @@ log = "0.4" once_cell = "1" pretty_assertions = "0.6.1" regex = "1" -swc_common = {version = "0.10.10", path = "../common", features = ["tty-emitter"]} +swc_common = {version = "0.10.16", path = "../common", features = ["tty-emitter"]} testing_macros = {version = "0.1", path = "./macros"} diff --git a/tests/fixture/issue-1233/case-1/output/index.js b/tests/fixture/issue-1233/case-1/output/index.js index 1cda37671e6c..70b3fefa92bb 100644 --- a/tests/fixture/issue-1233/case-1/output/index.js +++ b/tests/fixture/issue-1233/case-1/output/index.js @@ -1,5 +1,5 @@ function Component() { - return React.createElement("div", { + return( /*#__PURE__*/ React.createElement("div", { name: "A\n\n B" - }); + })); } diff --git a/tests/fixture/issue-1446/case1/output/input.tsx b/tests/fixture/issue-1446/case1/output/input.tsx index d4dd2262eb62..b532f5722673 100644 --- a/tests/fixture/issue-1446/case1/output/input.tsx +++ b/tests/fixture/issue-1446/case1/output/input.tsx @@ -1 +1 @@ -const Span = React.createElement("span", null, "with\xa0"); +const Span = /*#__PURE__*/ React.createElement("span", null, "with\xa0"); diff --git a/tests/fixture/issue-1446/case2/output/input.tsx b/tests/fixture/issue-1446/case2/output/input.tsx index f62c36c498f1..a3f74e24fc53 100644 --- a/tests/fixture/issue-1446/case2/output/input.tsx +++ b/tests/fixture/issue-1446/case2/output/input.tsx @@ -1 +1 @@ -const Span = React.createElement("span", null, "with "); +const Span = /*#__PURE__*/ React.createElement("span", null, "with "); diff --git a/tests/fixture/issue-1479/case-es2020/output/index.tsx b/tests/fixture/issue-1479/case-es2020/output/index.tsx index f8002be37ff2..3b696ffd393c 100644 --- a/tests/fixture/issue-1479/case-es2020/output/index.tsx +++ b/tests/fixture/issue-1479/case-es2020/output/index.tsx @@ -1,3 +1,3 @@ -const a = React.createElement("div", { +const a = /*#__PURE__*/ React.createElement("div", { id: "abc>" }); diff --git a/tests/fixture/issue-1479/case-es5/output/index.tsx b/tests/fixture/issue-1479/case-es5/output/index.tsx index 6b0c2e63042a..94537d9320aa 100644 --- a/tests/fixture/issue-1479/case-es5/output/index.tsx +++ b/tests/fixture/issue-1479/case-es5/output/index.tsx @@ -1,3 +1,3 @@ -var a = React.createElement("div", { +var a = /*#__PURE__*/ React.createElement("div", { id: "abc>" }); diff --git a/tests/fixture/options/react/output/index.tsx b/tests/fixture/options/react/output/index.tsx index bc177005575b..61420d36d223 100644 --- a/tests/fixture/options/react/output/index.tsx +++ b/tests/fixture/options/react/output/index.tsx @@ -1,3 +1,3 @@ export var App = function() { - return testPragma("div", null, testPragma(Foo, null)); + return( /*#__PURE__*/ testPragma("div", null, /*#__PURE__*/ testPragma(Foo, null))); }; diff --git a/tests/fixture/pr-1524/comment-1/output/index.tsx b/tests/fixture/pr-1524/comment-1/output/index.tsx index fc94d26846a7..6a6730e3cff7 100644 --- a/tests/fixture/pr-1524/comment-1/output/index.tsx +++ b/tests/fixture/pr-1524/comment-1/output/index.tsx @@ -34,5 +34,5 @@ function Bar() { // @refresh reset React.useEffect(function() { }); - return React.createElement("h1", null, foo, " "); + return( /*#__PURE__*/ React.createElement("h1", null, foo, " ")); } diff --git a/tests/fixture/pr-1524/comment-2/output/index.tsx b/tests/fixture/pr-1524/comment-2/output/index.tsx index bc94cbe60a76..83ef48a934e2 100644 --- a/tests/fixture/pr-1524/comment-2/output/index.tsx +++ b/tests/fixture/pr-1524/comment-2/output/index.tsx @@ -3,5 +3,5 @@ function Bar() { React.useEffect(()=>{ // @refresh reset }); - return React.createElement("h1", null, foo, " "); + return( /*#__PURE__*/ React.createElement("h1", null, foo, " ")); }