Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
kdy1 committed Dec 21, 2020
1 parent acd57c2 commit 8cdb055
Showing 1 changed file with 25 additions and 10 deletions.
35 changes: 25 additions & 10 deletions ecmascript/transforms/src/compat/es2015/template_literal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ impl Fold for TemplateLiteral {
noop_fold_type!();

fn fold_expr(&mut self, e: Expr) -> Expr {
let str_ctxt = self.str_ctxt;

let e = validate!(e);

let e = e.fold_children_with(self);
Expand All @@ -42,12 +44,14 @@ impl Fold for TemplateLiteral {

// This makes result of addition string
let mut obj: Box<Expr> = Box::new(
Lit::Str(
quasis[0]
Lit::Str({
let mut v = quasis[0]
.cooked
.clone()
.unwrap_or_else(|| quasis[0].raw.clone()),
)
.unwrap_or_else(|| quasis[0].raw.clone());
v.span.ctxt = str_ctxt;
v
})
.into(),
);

Expand All @@ -70,7 +74,7 @@ impl Fold for TemplateLiteral {
match quasis.next() {
Some(TplElement { cooked, raw, .. }) => {
let mut s = cooked.unwrap_or_else(|| raw);
s.span.ctxt = self.str_ctxt;
s.span.ctxt = str_ctxt;
Box::new(Lit::Str(s).into())
}
_ => unreachable!(),
Expand Down Expand Up @@ -114,15 +118,15 @@ impl Fold for TemplateLiteral {
})) = *expr
{
obj = Box::new(Expr::Lit(Lit::Str(Str {
span: span.with_hi(r_span.hi()),
span: span.with_hi(r_span.hi()).with_ctxt(str_ctxt),
value: format!("{}{}", value, r_value).into(),
has_escape: has_escape || r_has_escape,
})));

continue;
} else {
obj = Box::new(Expr::Lit(Lit::Str(Str {
span,
span: span.with_ctxt(str_ctxt),
value,
has_escape,
})))
Expand Down Expand Up @@ -234,7 +238,13 @@ impl Fold for TemplateLiteral {
elems: quasis
.iter()
.cloned()
.map(|elem| Lit::Str(elem.raw).as_arg())
.map(|mut elem| {
Lit::Str({
elem.raw.span = str_ctxt;
elem.raw
})
.as_arg()
})
.map(Some)
.collect(),
}
Expand All @@ -250,8 +260,13 @@ impl Fold for TemplateLiteral {
elems: quasis
.into_iter()
.map(|elem| {
Lit::Str(elem.cooked.unwrap_or(elem.raw))
.as_arg()
Lit::Str({
let mut v =
elem.cooked.unwrap_or(elem.raw);
v.span.ctxt = str_ctxt;
v
})
.as_arg()
})
.map(Some)
.collect(),
Expand Down

0 comments on commit 8cdb055

Please sign in to comment.