Skip to content

Commit

Permalink
fix(es): Fix bugs (#2004)
Browse files Browse the repository at this point in the history
swc_ecma_codegen:
 - Fix codegen of regexp where `minify` = `true`. (#2000)

swc_ecma_transforms_react:
 - Respect `@jsxImportSource` in `classic` mode. (#1933)

swc:
 - Upgrade `base64`.
  • Loading branch information
kdy1 authored Aug 4, 2021
1 parent 064416c commit 81abfe5
Show file tree
Hide file tree
Showing 21 changed files with 59 additions and 32 deletions.
14 changes: 4 additions & 10 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ name = "swc"
[dependencies]
ahash = "0.7.2"
anyhow = "1"
base64 = "0.12.0"
base64 = "0.13.0"
dashmap = "4.0.2"
either = "1"
log = {version = "0.4", features = ["release_max_level_info"]}
Expand Down
2 changes: 1 addition & 1 deletion ecmascript/ast/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_ast"
repository = "https://github.com/swc-project/swc.git"
version = "0.49.0"
version = "0.49.1"

[features]
default = []
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.65.0"
version = "0.65.1"

[dependencies]
bitflags = "1"
Expand Down
2 changes: 1 addition & 1 deletion ecmascript/codegen/src/text_writer/semicolon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ impl<W: WriteJs> WriteJs for OmitTrailingSemi<W> {
self.commit_pending_semi()?;
}

"{" | "(" => {
"/" | "{" | "(" => {
self.commit_pending_semi()?;
}

Expand Down
5 changes: 5 additions & 0 deletions ecmascript/codegen/tests/fixture/issues/2000/input.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
function testme() {
for (var a = arguments.length, b = new Array(a), c = 0; c < a; c++)
b[c] = arguments[c];
/^toto.+/.test(b.join("")) && global.other(!0)
}
4 changes: 4 additions & 0 deletions ecmascript/codegen/tests/fixture/issues/2000/output.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
function testme() {
for(var a = arguments.length, b = new Array(a), c = 0; c < a; c++)b[c] = arguments[c];
/^toto.+/.test(b.join("")) && global.other(!0);
}
1 change: 1 addition & 0 deletions ecmascript/codegen/tests/fixture/issues/2000/output.min.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
function testme(){for(var a=arguments.length,b=new Array(a),c=0;c<a;c++)b[c]=arguments[c];/^toto.+/.test(b.join(""))&&global.other(!0)}
2 changes: 1 addition & 1 deletion ecmascript/transforms/react/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_transforms_react"
repository = "https://github.com/swc-project/swc.git"
version = "0.30.0"
version = "0.30.1"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
Expand Down
21 changes: 10 additions & 11 deletions ecmascript/transforms/react/src/jsx/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -752,6 +752,7 @@ where

if line.starts_with("@jsxImportSource") {
let src = line.replace("@jsxImportSource", "").trim().to_string();
self.runtime = Runtime::Automatic;
self.import_source = src.into();
}

Expand All @@ -775,17 +776,15 @@ where
};
} else if line.starts_with("@jsx ") {
if self.runtime == Runtime::Automatic {
if self.runtime == Runtime::Automatic {
HANDLER.with(|handler| {
handler
.struct_span_err(
module.span,
"pragma and pragmaFrag cannot be set when runtime \
is automatic",
)
.emit()
});
}
HANDLER.with(|handler| {
handler
.struct_span_err(
module.span,
"pragma and pragmaFrag cannot be set when runtime is \
automatic",
)
.emit()
});
}

let src = line.replace("@jsx", "").trim().to_string();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/* @jsxImportSource react */
const p = () => (
<div>Hello World</div>
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"runtime": "classic"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { jsx as _jsx } from "react/jsx-runtime";

/* @jsxImportSource react */
const p = () => /*#__PURE__*/_jsx("div", {
children: "Hello World"
});
1 change: 0 additions & 1 deletion tests/fixture/.issue-1726/case1/input/index.tsx

This file was deleted.

3 changes: 0 additions & 3 deletions tests/fixture/.issue-1726/case1/output/index.tsx

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"sourceMaps": "inline",
"jsc": {
"target": "es5",
"parser": {
Expand All @@ -8,4 +7,4 @@
},
"loose": true
}
}
}
1 change: 1 addition & 0 deletions tests/fixture/issue-1726/case1/input/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
const foo = /* 1 */ <h1>{/* 2 */ bar /* 3 */}</h1>; /* 4 */
1 change: 1 addition & 0 deletions tests/fixture/issue-1726/case1/output/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
var foo = /* 1 */ /*#__PURE__*/ React.createElement("h1", null, bar /* 3 */ ); /* 4 */
10 changes: 10 additions & 0 deletions tests/fixture/issue-2000/input/.swcrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"jsc": {
"loose": true,
"minify": {
"compress": true,
"mangle": true
}
},
"minify": true
}
3 changes: 3 additions & 0 deletions tests/fixture/issue-2000/input/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
function testme(...list) {
if (/^toto.+/.test(list.join(''))) global.other(true);
}
1 change: 1 addition & 0 deletions tests/fixture/issue-2000/output/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
function testme(){for(var a=arguments.length,b=new Array(a),c=0;c<a;c++)b[c]=arguments[c];/^toto.+/.test(b.join(""))&&global.other(!0)}

0 comments on commit 81abfe5

Please sign in to comment.