mirror of
https://github.com/swc-project/swc.git
synced 2024-12-24 06:05:02 +03:00
Fix regenerator (#851)
swc_ecma_transforms: - Fix regenerator scoping issue.
This commit is contained in:
parent
66d42adf7e
commit
ff440157a0
@ -85,21 +85,27 @@ where
|
||||
return items;
|
||||
}
|
||||
|
||||
let mut items = items.fold_children(self);
|
||||
let mut new = Vec::with_capacity(items.len() + 2);
|
||||
|
||||
if !self.top_level_vars.is_empty() {
|
||||
prepend(
|
||||
&mut items,
|
||||
T::from_stmt(Stmt::Decl(Decl::Var(VarDecl {
|
||||
span: DUMMY_SP,
|
||||
kind: VarDeclKind::Var,
|
||||
declare: false,
|
||||
decls: replace(&mut self.top_level_vars, Default::default()),
|
||||
}))),
|
||||
);
|
||||
for item in items {
|
||||
let item = item.fold_with(self);
|
||||
|
||||
if !self.top_level_vars.is_empty() {
|
||||
prepend(
|
||||
&mut new,
|
||||
T::from_stmt(Stmt::Decl(Decl::Var(VarDecl {
|
||||
span: DUMMY_SP,
|
||||
kind: VarDeclKind::Var,
|
||||
declare: false,
|
||||
decls: replace(&mut self.top_level_vars, Default::default()),
|
||||
}))),
|
||||
);
|
||||
}
|
||||
|
||||
new.push(item);
|
||||
}
|
||||
|
||||
items
|
||||
new
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -6109,3 +6109,26 @@ with (env) {
|
||||
|
||||
"#
|
||||
);
|
||||
|
||||
test_exec!(
|
||||
syntax(),
|
||||
|_| Classes::default(),
|
||||
issue_846,
|
||||
r#"
|
||||
class SomeClass {
|
||||
someMethod() {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
class OtherClass extends SomeClass {
|
||||
anotherMethod() {
|
||||
expect(super.someMethod()).toBe(1);
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
|
||||
const obj = new OtherClass();
|
||||
expect(obj.anotherMethod()).toBe(2);
|
||||
"#
|
||||
);
|
||||
|
@ -1116,3 +1116,14 @@ export function myGenerator() {
|
||||
}
|
||||
"
|
||||
);
|
||||
|
||||
test_exec!(
|
||||
syntax(),
|
||||
|_| es2015::regenerator(Mark::fresh(Mark::root())),
|
||||
issue_849_1,
|
||||
"function* gen() { yield 1 };
|
||||
function genFactory() { return function*() { yield 1 }; }
|
||||
const v = genFactory()();
|
||||
expect(v.next()).toEqual({ value: 1, done: false })
|
||||
expect(v.next()).toEqual({ done: true })"
|
||||
);
|
||||
|
24
node-swc/__tests__/transform/issue846_test.js
Normal file
24
node-swc/__tests__/transform/issue846_test.js
Normal file
@ -0,0 +1,24 @@
|
||||
const swc = require('../../../');
|
||||
|
||||
|
||||
it("should handle es2019", () => {
|
||||
expect(
|
||||
swc.transformSync(`class SomeClass {
|
||||
someMethod() {}
|
||||
}
|
||||
|
||||
class OtherClass extends SomeClass {
|
||||
anotherMethod() {
|
||||
super.someMethod()
|
||||
}
|
||||
}`, {
|
||||
jsc: {
|
||||
parser: {
|
||||
syntax: "ecmascript",
|
||||
},
|
||||
target: "es2019",
|
||||
}
|
||||
})
|
||||
.code.trim()
|
||||
).toContain(`class `);
|
||||
});
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@swc/core",
|
||||
"version": "1.2.4",
|
||||
"version": "1.2.5",
|
||||
"description": "Super-fast alternative for babel",
|
||||
"main": "./index.js",
|
||||
"author": "강동윤 <kdy1997.dev@gmail.com>",
|
||||
|
Loading…
Reference in New Issue
Block a user