This commit is contained in:
강동윤 2019-02-14 17:46:22 +09:00
parent 10e7c9821a
commit b76c4f26e6
2 changed files with 28 additions and 19 deletions

View File

@ -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,9 +291,6 @@ 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);
@ -308,9 +305,7 @@ where
}))));
}
buf.push(T::from_stmt(stmt));
}
}
buf.push(stmt);
}
buf

View File

@ -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,