Skip to content

Commit

Permalink
fix(es/compat): Use correct span.lo in class transforms (#8439)
Browse files Browse the repository at this point in the history
**Related issue:**

 - Closes #8435
  • Loading branch information
Austaras committed Dec 21, 2023
1 parent dc26f0f commit a06d5b2
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 3 deletions.
2 changes: 1 addition & 1 deletion crates/swc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ concurrent = [
"swc_ecma_minifier/concurrent",
]

debug = ["swc_ecma_visit/debug"]
debug = ["swc_ecma_visit/debug", "swc_ecma_minifier/debug"]
default = ["es3"]
es3 = []
node = ["napi", "napi-derive", "swc_compiler_base/node"]
Expand Down
2 changes: 1 addition & 1 deletion crates/swc/tests/fixture/issues-5xxx/5272/1/output/a.map
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"mappings": ";;;+BACaA;;;eAAAA;;;;;;;oBADQ;AACd,IAAA,AAAMA,oBAAN;;gBAAMA;iCAAAA;aAAAA;kCAAAA;;;oBAAAA;;YACTC,KAAAA;mBAAAA,SAAAA;gBACI,OAAO,IAAI,IAAI,CAACC,GAAG;YACvB;;;WAHSF;EAAYG,UAAI",
"mappings": ";;;+BACaA;;;eAAAA;;;;;;;oBADQ;AACd,IAAA,AAAMA,oBAAD,AAAL;;gBAAMA;iCAAAA;aAAAA;kCAAAA;;;oBAAAA;;YACTC,KAAAA;mBAAAA,SAAAA;gBACI,OAAO,IAAI,IAAI,CAACC,GAAG;YACvB;;;WAHSF;EAAYG,UAAI",
"names": [
"Foo",
"bar",
Expand Down
20 changes: 20 additions & 0 deletions crates/swc/tests/fixture/issues-8xxx/8435/input/.swcrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"jsc": {
"parser": {
"syntax": "typescript",
"dynamicImport": true,
"tsx": true,
"jsx": true
},
"minify": {
"compress": true,
"mangle": false
},
"loose": false
},
"env": {
"targets": "> 0.25%, not dead, Safari >=8",
"mode": "entry",
"coreJs": "3.27"
}
}
12 changes: 12 additions & 0 deletions crates/swc/tests/fixture/issues-8xxx/8435/input/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const init = () => {
var e = window.parcelRequire;
e.register('module1', function () {
class Hello {
world() {}
}
}), e.register('module2', function () {
console.log('test')
});
};

init();
6 changes: 6 additions & 0 deletions crates/swc/tests/fixture/issues-8xxx/8435/output/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
var e;
import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check";
import { _ as _create_class } from "@swc/helpers/_/_create_class";
(e = window.parcelRequire).register("module1", function() {}), e.register("module2", function() {
console.log("test");
});
2 changes: 1 addition & 1 deletion crates/swc_ecma_compat_es2015/src/classes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ where
if let Expr::Call(call) = &mut rhs {
let mut span = Span {
// after class
lo: span.hi + BytePos(5),
lo: span.lo + BytePos(5),
..span
};
self.add_pure_comments(&mut span.lo);
Expand Down

0 comments on commit a06d5b2

Please sign in to comment.