fix(es/minifier): Fix evaluator (#3391)

This commit is contained in:
Donny/강동윤 2022-01-28 13:43:29 +09:00 committed by GitHub
parent 3eaebdf479
commit 38c2499358
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 68 additions and 27 deletions

View File

@ -99,6 +99,7 @@ where
);
self.simple_props
.insert((name.to_id(), s.value.clone()), value);
self.mode.store(name.to_id(), n.init.as_deref().unwrap());
}
PropName::Ident(i) => {
tracing::trace!(
@ -107,6 +108,7 @@ where
);
self.simple_props
.insert((name.to_id(), i.sym.clone()), value);
self.mode.store(name.to_id(), n.init.as_deref().unwrap());
}
_ => {}
}

View File

@ -200,6 +200,8 @@ where
i.id.span.ctxt
);
self.mode.store(i.to_id(), &*init);
self.lits.insert(i.to_id(), init.clone());
}
return;

View File

@ -171,8 +171,7 @@ impl VisitMut for PartialInliner {
e.visit_mut_children_with(self);
if let Some(evaluator) = self.eval.as_mut() {
match e {
Expr::TaggedTpl(tt) => {
if let Expr::TaggedTpl(tt) = e {
if tt.tag.is_ident_ref_to("css".into()) {
let res = evaluator.eval_tpl(&tt.tpl);
@ -201,9 +200,6 @@ impl VisitMut for PartialInliner {
}
}
}
_ => {}
}
}
}
@ -466,3 +462,44 @@ fn partial_7() {
",
);
}
#[test]
fn partial_8() {
PartialInliner::expect(
"const darken = c => c
const color = 'red'
const otherColor = 'green'
const mediumScreen = '680px'
const animationDuration = '200ms'
const animationName = 'my-cool-animation'
const obj = { display: 'block' }
export default ({ display }) => (
css`
p.${color} {
color: ${otherColor};
display: ${obj.display};
}
`
)
",
"
const darken = c => c
const color = 'red'
const otherColor = 'green'
const mediumScreen = '680px'
const animationDuration = '200ms'
const animationName = 'my-cool-animation'
const obj = { display: 'block' }
export default ({ display }) => (
css`
p.red {
color: green;
display: block;
}
`
)
",
)
}