mirror of
https://github.com/swc-project/swc.git
synced 2024-12-24 22:22:34 +03:00
Fix #210.
This commit is contained in:
parent
10e7c9821a
commit
b76c4f26e6
@ -278,7 +278,7 @@ fn is_complex(props: &[PropOrSpread]) -> bool {
|
||||
|
||||
impl<T: StmtLike + VisitWith<ShouldWork>> Fold<Vec<T>> for ComputedProps
|
||||
where
|
||||
Vec<T>: FoldWith<Self>,
|
||||
T: FoldWith<Self> + FoldWith<ObjectLitFolder>,
|
||||
{
|
||||
fn fold(&mut self, stmts: Vec<T>) -> Vec<T> {
|
||||
// Fast path when there's no computed properties.
|
||||
@ -291,26 +291,21 @@ where
|
||||
let mut buf = Vec::with_capacity(stmts.len());
|
||||
|
||||
for stmt in stmts {
|
||||
match stmt.try_into_stmt() {
|
||||
Err(module_item) => buf.push(module_item),
|
||||
Ok(stmt) => {
|
||||
let mut folder = ObjectLitFolder::default();
|
||||
let stmt = stmt.fold_with(&mut folder);
|
||||
let mut folder = ObjectLitFolder::default();
|
||||
let stmt = stmt.fold_with(&mut folder);
|
||||
|
||||
// Add variable declaration
|
||||
// e.g. var ref
|
||||
if !folder.vars.is_empty() {
|
||||
buf.push(T::from_stmt(Stmt::Decl(Decl::Var(VarDecl {
|
||||
span: DUMMY_SP,
|
||||
kind: VarDeclKind::Var,
|
||||
decls: folder.vars,
|
||||
declare: false,
|
||||
}))));
|
||||
}
|
||||
|
||||
buf.push(T::from_stmt(stmt));
|
||||
}
|
||||
// Add variable declaration
|
||||
// e.g. var ref
|
||||
if !folder.vars.is_empty() {
|
||||
buf.push(T::from_stmt(Stmt::Decl(Decl::Var(VarDecl {
|
||||
span: DUMMY_SP,
|
||||
kind: VarDeclKind::Var,
|
||||
decls: folder.vars,
|
||||
declare: false,
|
||||
}))));
|
||||
}
|
||||
|
||||
buf.push(stmt);
|
||||
}
|
||||
|
||||
buf
|
||||
|
@ -1,5 +1,19 @@
|
||||
use super::*;
|
||||
|
||||
test!(
|
||||
::swc_ecma_parser::Syntax::default(),
|
||||
|_| ComputedProps,
|
||||
issue_210,
|
||||
"
|
||||
const b = {[a]: 1}
|
||||
export const c = {[a]: 1}
|
||||
",
|
||||
"const b = _defineProperty({
|
||||
}, a, 1);
|
||||
export const c = _defineProperty({
|
||||
}, a, 1);"
|
||||
);
|
||||
|
||||
test!(
|
||||
::swc_ecma_parser::Syntax::default(),
|
||||
|_| ComputedProps,
|
||||
|
Loading…
Reference in New Issue
Block a user