Skip to content

Commit

Permalink
fix(es/codegen, es/transforms/typescript): Fix bugs (#2383)
Browse files Browse the repository at this point in the history
swc_ecma_codegen:
 - Emit sourcemap for `import` tokens.

swc_ecma_transforms_typescript:
 - Strip `react` correctly.
  • Loading branch information
kdy1 authored Oct 9, 2021
1 parent d19df13 commit 2c058cb
Show file tree
Hide file tree
Showing 15 changed files with 59 additions and 50 deletions.
20 changes: 10 additions & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ edition = "2018"
license = "Apache-2.0/MIT"
name = "swc"
repository = "https://github.com/swc-project/swc.git"
version = "0.66.0"
version = "0.66.1"

[lib]
name = "swc"
Expand Down Expand Up @@ -52,16 +52,16 @@ serde = {version = "1", features = ["derive"]}
serde_json = "1"
sourcemap = "6"
swc_atoms = {version = "0.2", path = "./atoms"}
swc_bundler = {version = "0.67.0", path = "./bundler"}
swc_bundler = {version = "0.67.1", path = "./bundler"}
swc_common = {version = "0.13.0", path = "./common", features = ["sourcemap", "concurrent"]}
swc_ecma_ast = {version = "0.54.0", path = "./ecmascript/ast"}
swc_ecma_codegen = {version = "0.74.0", path = "./ecmascript/codegen"}
swc_ecma_ext_transforms = {version = "0.31.0", path = "./ecmascript/ext-transforms"}
swc_ecma_loader = {version = "0.20.0", path = "./ecmascript/loader", features = ["lru", "node", "tsc"]}
swc_ecma_minifier = {version = "0.36.0", path = "./ecmascript/minifier"}
swc_ecma_minifier = {version = "0.36.1", path = "./ecmascript/minifier"}
swc_ecma_parser = {version = "0.73.0", path = "./ecmascript/parser"}
swc_ecma_preset_env = {version = "0.51.0", path = "./ecmascript/preset-env"}
swc_ecma_transforms = {version = "0.80.0", path = "./ecmascript/transforms", features = [
swc_ecma_preset_env = {version = "0.51.1", path = "./ecmascript/preset-env"}
swc_ecma_transforms = {version = "0.80.1", path = "./ecmascript/transforms", features = [
"compat",
"module",
"optimization",
Expand All @@ -72,7 +72,7 @@ swc_ecma_transforms = {version = "0.80.0", path = "./ecmascript/transforms", fea
swc_ecma_transforms_base = {version = "0.35.0", path = "./ecmascript/transforms/base"}
swc_ecma_utils = {version = "0.46.0", path = "./ecmascript/utils"}
swc_ecma_visit = {version = "0.40.0", path = "./ecmascript/visit"}
swc_ecmascript = {version = "0.72.0", path = "./ecmascript"}
swc_ecmascript = {version = "0.72.1", path = "./ecmascript"}
swc_visit = {version = "0.2.3", path = "./visit"}
tracing = "0.1.28"

Expand Down
6 changes: 3 additions & 3 deletions bundler/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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.67.0"
version = "0.67.1"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[features]
Expand All @@ -36,7 +36,7 @@ swc_ecma_ast = {version = "0.54.0", path = "../ecmascript/ast"}
swc_ecma_codegen = {version = "0.74.0", path = "../ecmascript/codegen"}
swc_ecma_loader = {version = "0.20.0", path = "../ecmascript/loader"}
swc_ecma_parser = {version = "0.73.0", path = "../ecmascript/parser"}
swc_ecma_transforms = {version = "0.80.0", path = "../ecmascript/transforms", features = ["optimization"]}
swc_ecma_transforms = {version = "0.80.1", path = "../ecmascript/transforms", features = ["optimization"]}
swc_ecma_utils = {version = "0.46.0", path = "../ecmascript/utils"}
swc_ecma_visit = {version = "0.40.0", path = "../ecmascript/visit"}
tracing = "0.1.28"
Expand All @@ -47,7 +47,7 @@ ntest = "0.7.2"
path-clean = "=0.1.0"
reqwest = {version = "0.11.4", features = ["blocking"]}
sha-1 = "0.9"
swc_ecma_transforms = {version = "0.80.0", path = "../ecmascript/transforms", features = ["react", "typescript"]}
swc_ecma_transforms = {version = "0.80.1", path = "../ecmascript/transforms", features = ["react", "typescript"]}
swc_node_base = {version = "0.4.0", path = "../node/base"}
tempfile = "3.1.0"
testing = {version = "0.14.0", path = "../testing"}
Expand Down
8 changes: 4 additions & 4 deletions ecmascript/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ edition = "2018"
license = "Apache-2.0/MIT"
name = "swc_ecmascript"
repository = "https://github.com/swc-project/swc.git"
version = "0.72.0"
version = "0.72.1"

[package.metadata.docs.rs]
all-features = true
Expand Down Expand Up @@ -35,10 +35,10 @@ typescript = ["typescript-parser", "swc_ecma_transforms/typescript"]
swc_ecma_ast = {version = "0.54.0", path = "./ast"}
swc_ecma_codegen = {version = "0.74.0", path = "./codegen", optional = true}
swc_ecma_dep_graph = {version = "0.42.0", path = "./dep-graph", optional = true}
swc_ecma_minifier = {version = "0.36.0", path = "./minifier", optional = true}
swc_ecma_minifier = {version = "0.36.1", path = "./minifier", optional = true}
swc_ecma_parser = {version = "0.73.0", path = "./parser", optional = true, default-features = false}
swc_ecma_preset_env = {version = "0.51.0", path = "./preset-env", optional = true}
swc_ecma_transforms = {version = "0.80.0", path = "./transforms", optional = true}
swc_ecma_preset_env = {version = "0.51.1", path = "./preset-env", optional = true}
swc_ecma_transforms = {version = "0.80.1", path = "./transforms", optional = true}
swc_ecma_utils = {version = "0.46.0", path = "./utils", optional = true}
swc_ecma_visit = {version = "0.40.0", path = "./visit", optional = true}

Expand Down
2 changes: 1 addition & 1 deletion ecmascript/codegen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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.74.1"
version = "0.74.2"

[dependencies]
bitflags = "1"
Expand Down
25 changes: 16 additions & 9 deletions ecmascript/codegen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,12 +178,19 @@ where
}

#[emitter]
fn emit_import(&mut self, node: &ImportDecl) -> Result {
self.emit_leading_comments_of_span(node.span(), false)?;
fn emit_import(&mut self, n: &ImportDecl) -> Result {
self.emit_leading_comments_of_span(n.span(), false)?;

keyword!("import");
let starts_with_ident = !node.specifiers.is_empty()
&& match &node.specifiers[0] {
{
let span = if n.span.is_dummy() {
DUMMY_SP
} else {
Span::new(n.span.lo, n.span.lo + BytePos(6), Default::default())
};
keyword!(span, "import");
}
let starts_with_ident = !n.specifiers.is_empty()
&& match &n.specifiers[0] {
ImportSpecifier::Default(_) => true,
_ => false,
};
Expand All @@ -196,7 +203,7 @@ where
let mut specifiers = vec![];
let mut emitted_default = false;
let mut emitted_ns = false;
for specifier in &node.specifiers {
for specifier in &n.specifiers {
match specifier {
ImportSpecifier::Named(ref s) => {
specifiers.push(s);
Expand All @@ -213,7 +220,7 @@ where

emitted_ns = true;

assert!(node.specifiers.len() <= 2);
assert!(n.specifiers.len() <= 2);
punct!("*");
formatting_space!();
keyword!("as");
Expand All @@ -237,7 +244,7 @@ where

punct!("{");
self.emit_list(
node.span(),
n.span(),
Some(&specifiers),
ListFormat::NamedImportsOrExportsElements,
)?;
Expand All @@ -248,7 +255,7 @@ where
formatting_space!();
}

emit!(node.src);
emit!(n.src);
formatting_semi!();
}

Expand Down
4 changes: 2 additions & 2 deletions ecmascript/minifier/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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.36.0"
version = "0.36.1"

[features]
debug = ["backtrace"]
Expand All @@ -29,7 +29,7 @@ swc_common = {version = "0.13.0", path = "../../common"}
swc_ecma_ast = {version = "0.54.0", path = "../ast"}
swc_ecma_codegen = {version = "0.74.0", path = "../codegen"}
swc_ecma_parser = {version = "0.73.0", path = "../parser"}
swc_ecma_transforms = {version = "0.80.0", path = "../transforms/", features = ["optimization"]}
swc_ecma_transforms = {version = "0.80.1", path = "../transforms/", features = ["optimization"]}
swc_ecma_transforms_base = {version = "0.35.0", path = "../transforms/base"}
swc_ecma_utils = {version = "0.46.0", path = "../utils"}
swc_ecma_visit = {version = "0.40.0", path = "../visit"}
Expand Down
4 changes: 2 additions & 2 deletions ecmascript/preset-env/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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.51.0"
version = "0.51.1"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand All @@ -22,7 +22,7 @@ string_enum = {version = "0.3.1", path = "../../macros/string_enum"}
swc_atoms = {version = "0.2", path = "../../atoms"}
swc_common = {version = "0.13.0", path = "../../common"}
swc_ecma_ast = {version = "0.54.0", path = "../ast"}
swc_ecma_transforms = {version = "0.80.0", path = "../transforms", features = ["compat", "proposal"]}
swc_ecma_transforms = {version = "0.80.1", path = "../transforms", features = ["compat", "proposal"]}
swc_ecma_utils = {version = "0.46.0", path = "../utils"}
swc_ecma_visit = {version = "0.40.0", path = "../visit"}
walkdir = "2"
Expand Down
6 changes: 3 additions & 3 deletions ecmascript/transforms/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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.80.0"
version = "0.80.1"

[package.metadata.docs.rs]
all-features = true
Expand All @@ -28,10 +28,10 @@ swc_ecma_parser = {version = "0.73.0", path = "../parser"}
swc_ecma_transforms_base = {version = "0.35.0", path = "./base"}
swc_ecma_transforms_compat = {version = "0.40.0", path = "./compat", optional = true}
swc_ecma_transforms_module = {version = "0.44.0", path = "./module", optional = true}
swc_ecma_transforms_optimization = {version = "0.50.0", path = "./optimization", optional = true}
swc_ecma_transforms_optimization = {version = "0.50.1", path = "./optimization", optional = true}
swc_ecma_transforms_proposal = {version = "0.44.0", path = "./proposal", optional = true}
swc_ecma_transforms_react = {version = "0.46.0", path = "./react", optional = true}
swc_ecma_transforms_typescript = {version = "0.46.1", path = "./typescript", optional = true}
swc_ecma_transforms_typescript = {version = "0.46.2", path = "./typescript", optional = true}
swc_ecma_utils = {version = "0.46.0", path = "../utils"}
swc_ecma_visit = {version = "0.40.0", path = "../visit"}
unicode-xid = "0.2"
Expand Down
4 changes: 2 additions & 2 deletions ecmascript/transforms/optimization/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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.50.0"
version = "0.50.1"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
Expand All @@ -32,5 +32,5 @@ swc_ecma_transforms_module = {version = "0.44.0", path = "../module"}
swc_ecma_transforms_proposal = {version = "0.44.0", path = "../proposal"}
swc_ecma_transforms_react = {version = "0.46.0", path = "../react"}
swc_ecma_transforms_testing = {version = "0.36.0", path = "../testing"}
swc_ecma_transforms_typescript = {version = "0.46.1", path = "../typescript"}
swc_ecma_transforms_typescript = {version = "0.46.2", path = "../typescript"}
testing = {version = "0.14.0", path = "../../../testing"}
2 changes: 1 addition & 1 deletion ecmascript/transforms/typescript/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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.46.1"
version = "0.46.2"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
Expand Down
10 changes: 6 additions & 4 deletions ecmascript/transforms/typescript/src/strip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1444,16 +1444,18 @@ impl VisitMut for Strip {
}

fn visit_mut_import_decl(&mut self, import: &mut ImportDecl) {
if &*import.src.value == "react" {
return;
}

self.is_side_effect_import = import.specifiers.is_empty();

let src = &import.src;
import.specifiers.retain(|s| match *s {
ImportSpecifier::Named(ImportNamedSpecifier {
ref is_type_only, ..
}) if *is_type_only => false,

ImportSpecifier::Default(..) if &*src.value == "react" => {
return true;
}

ImportSpecifier::Default(ImportDefaultSpecifier { ref local, .. })
| ImportSpecifier::Named(ImportNamedSpecifier { ref local, .. })
| ImportSpecifier::Namespace(ImportStarAsSpecifier { ref local, .. }) => {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@swc/core",
"version": "1.2.94",
"version": "1.2.95",
"description": "Super-fast alternative for babel",
"homepage": "https://swc.rs",
"main": "./index.js",
Expand Down
2 changes: 1 addition & 1 deletion tests/fixture/deno-10014/case1/output/index.map
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"mappings": "OAAO,CAAa;SAEX,CAAC,GAAG,CAAC;IACV,CAAC;AACL,CAAC;SAEQ,CAAC,CAAC,KAAS,EAAE,CAAC;QAAZ,CAAC,GAAD,KAAS,cAAL,KAAK,GAAT,KAAS;IAChB,EAAE,EAAE,CAAC,EAAE,CAAC;QACJ,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,CAAO;IAC3B,CAAC;IACD,CAAC,EAAE,CAAC;AACR,CAAC;AAED,CAAC",
"mappings": "AAAA,MAAM,CAAC,CAAa;SAEX,CAAC,GAAG,CAAC;IACV,CAAC;AACL,CAAC;SAEQ,CAAC,CAAC,KAAS,EAAE,CAAC;QAAZ,CAAC,GAAD,KAAS,cAAL,KAAK,GAAT,KAAS;IAChB,EAAE,EAAE,CAAC,EAAE,CAAC;QACJ,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,CAAO;IAC3B,CAAC;IACD,CAAC,EAAE,CAAC;AACR,CAAC;AAED,CAAC",
"names": [
"a",
"t",
Expand Down
2 changes: 1 addition & 1 deletion wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ license = "Apache-2.0 AND MIT"
name = "wasm"
publish = false
repository = "https://github.com/swc-project/swc.git"
version = "1.2.94"
version = "1.2.95"

[lib]
crate-type = ["cdylib"]
Expand Down

0 comments on commit 2c058cb

Please sign in to comment.