mirror of
https://github.com/swc-project/swc.git
synced 2024-12-24 06:05:02 +03:00
parent
5a47c7a15c
commit
bf70946546
@ -59,28 +59,31 @@ impl Fold<Expr> for InlineGlobals {
|
||||
})),
|
||||
prop,
|
||||
computed,
|
||||
}) => match *prop {
|
||||
Expr::Ident(Ident { ref sym, .. }) => {
|
||||
if let Some(env) = self.envs.get(sym) {
|
||||
return env.clone();
|
||||
}) => {
|
||||
match *prop {
|
||||
Expr::Lit(Lit::Str(Str { value: ref sym, .. }))
|
||||
| Expr::Ident(Ident { ref sym, .. }) => {
|
||||
if let Some(env) = self.envs.get(sym) {
|
||||
return env.clone();
|
||||
}
|
||||
}
|
||||
return Expr::Member(MemberExpr {
|
||||
span,
|
||||
obj: ExprOrSuper::Expr(box Expr::Member(MemberExpr {
|
||||
obj: ExprOrSuper::Expr(box Expr::Ident(Ident::new(
|
||||
js_word!("process"),
|
||||
process_span,
|
||||
))),
|
||||
prop: box Expr::Ident(Ident::new(js_word!("env"), env_span)),
|
||||
span: obj_span,
|
||||
computed: obj_computed,
|
||||
})),
|
||||
prop,
|
||||
computed,
|
||||
});
|
||||
_ => {}
|
||||
}
|
||||
_ => unimplemented!("node.env.NONE-IDENT"),
|
||||
},
|
||||
return Expr::Member(MemberExpr {
|
||||
span,
|
||||
obj: ExprOrSuper::Expr(box Expr::Member(MemberExpr {
|
||||
obj: ExprOrSuper::Expr(box Expr::Ident(Ident::new(
|
||||
js_word!("process"),
|
||||
process_span,
|
||||
))),
|
||||
prop: box Expr::Ident(Ident::new(js_word!("env"), env_span)),
|
||||
span: obj_span,
|
||||
computed: obj_computed,
|
||||
})),
|
||||
prop,
|
||||
computed,
|
||||
});
|
||||
}
|
||||
_ => expr,
|
||||
}
|
||||
}
|
||||
@ -178,4 +181,26 @@ mod tests {
|
||||
r#"if (foo.debug) {}"#,
|
||||
r#"if (foo.debug) {}"#
|
||||
);
|
||||
|
||||
test!(
|
||||
Default::default(),
|
||||
|tester| InlineGlobals {
|
||||
envs: envs(tester, &[]),
|
||||
globals: globals(tester, &[]),
|
||||
},
|
||||
issue_417_1,
|
||||
"const test = process.env['x']",
|
||||
"const test = process.env['x']"
|
||||
);
|
||||
|
||||
test!(
|
||||
Default::default(),
|
||||
|tester| InlineGlobals {
|
||||
envs: envs(tester, &[("x", "FOO")]),
|
||||
globals: globals(tester, &[]),
|
||||
},
|
||||
issue_417_2,
|
||||
"const test = process.env['x']",
|
||||
"const test = 'FOO'"
|
||||
);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user