mirror of
https://github.com/swc-project/swc.git
synced 2024-12-24 22:22:34 +03:00
parent
04699ea3a4
commit
654f55b658
@ -13,8 +13,8 @@ pub use self::{
|
||||
diagnostic_builder::DiagnosticBuilder,
|
||||
emitter::ColorConfig,
|
||||
};
|
||||
pub use self::emitter::{Emitter,EmitterWriter};
|
||||
use self::{
|
||||
emitter::{Emitter, EmitterWriter},
|
||||
Level::*,
|
||||
};
|
||||
use crate::{
|
||||
|
@ -387,7 +387,6 @@ impl Classes {
|
||||
}
|
||||
|
||||
// inject _classCallCheck(this, Bar);
|
||||
helper!(class_call_check);
|
||||
inject_class_call_check(&mut constructor, class_name.clone());
|
||||
let mut body = constructor.body.unwrap().stmts;
|
||||
// should we insert `var _this`?
|
||||
@ -628,6 +627,7 @@ impl Classes {
|
||||
methods: ExprOrSpread,
|
||||
static_methods: Option<ExprOrSpread>,
|
||||
) -> Stmt {
|
||||
helper!(create_class);
|
||||
Stmt::Expr(box Expr::Call(CallExpr {
|
||||
span: DUMMY_SP,
|
||||
callee: quote_ident!("_createClass").as_callee(),
|
||||
@ -729,7 +729,6 @@ impl Classes {
|
||||
if props.is_empty() && static_props.is_empty() {
|
||||
return vec![];
|
||||
}
|
||||
helper!(create_class);
|
||||
vec![mk_create_class_call(
|
||||
class_name,
|
||||
mk_arg_obj_for_create_class(props),
|
||||
@ -759,6 +758,7 @@ fn get_prototype_of(obj: &Expr) -> Expr {
|
||||
}
|
||||
|
||||
fn inject_class_call_check(c: &mut Constructor, name: Ident) {
|
||||
helper!(class_call_check);
|
||||
let class_call_check = Stmt::Expr(box Expr::Call(CallExpr {
|
||||
span: DUMMY_SP,
|
||||
callee: Expr::Ident(quote_ident!("_classCallCheck")).as_callee(),
|
||||
|
@ -174,6 +174,7 @@ impl<'a> Fold<Expr> for SuperCalleeFolder<'a> {
|
||||
impl<'a> SuperCalleeFolder<'a> {
|
||||
fn super_to_get_call(&mut self, super_token: Span, prop: Box<Expr>, computed: bool) -> Expr {
|
||||
self.inject_get = true;
|
||||
helper!(get);
|
||||
|
||||
let proto_arg = get_prototype_of(&if self.is_static {
|
||||
// Foo
|
||||
@ -231,6 +232,7 @@ impl<'a> SuperCalleeFolder<'a> {
|
||||
rhs: Box<Expr>,
|
||||
) -> Expr {
|
||||
self.inject_set = true;
|
||||
helper!(set);
|
||||
|
||||
let mut ref_ident = alias_ident_for(&rhs, "_ref");
|
||||
ref_ident.span = ref_ident.span.apply_mark(Mark::fresh(Mark::root()));
|
||||
@ -416,8 +418,6 @@ impl<'a> Fold<Expr> for SuperFieldAccessFolder<'a> {
|
||||
}
|
||||
|
||||
if callee_folder.inject_get {
|
||||
helper!(get);
|
||||
|
||||
if should_invoke_call {
|
||||
match n {
|
||||
Expr::Call(CallExpr {
|
||||
@ -470,10 +470,6 @@ impl<'a> Fold<Expr> for SuperFieldAccessFolder<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
if callee_folder.inject_set {
|
||||
helper!(set);
|
||||
}
|
||||
|
||||
n.fold_children(self)
|
||||
}
|
||||
}
|
||||
|
@ -193,6 +193,7 @@ impl Fold<Expr> for ObjectLitFolder {
|
||||
};
|
||||
|
||||
if props_cnt == 1 {
|
||||
helper!(define_property);
|
||||
return Expr::Call(CallExpr {
|
||||
span,
|
||||
callee: quote_ident!("_defineProperty").as_callee(),
|
||||
@ -208,6 +209,7 @@ impl Fold<Expr> for ObjectLitFolder {
|
||||
type_args: Default::default(),
|
||||
});
|
||||
}
|
||||
helper!(define_property);
|
||||
exprs.push(box Expr::Call(CallExpr {
|
||||
span,
|
||||
callee: quote_ident!("_defineProperty").as_callee(),
|
||||
@ -232,6 +234,7 @@ impl Fold<Expr> for ObjectLitFolder {
|
||||
})),
|
||||
definite: false,
|
||||
});
|
||||
helper!(define_enumerable_properties);
|
||||
exprs.push(box Expr::Call(CallExpr {
|
||||
span,
|
||||
callee: quote_ident!("_defineEnumerableProperties").as_callee(),
|
||||
|
@ -611,7 +611,6 @@ fn make_fn_ref(mut expr: FnExpr) -> Expr {
|
||||
expr.function.is_generator = true;
|
||||
|
||||
let span = expr.span();
|
||||
helper!(async_to_generator);
|
||||
|
||||
let contains_this = contains_this_expr(&expr.function.body);
|
||||
let expr = if contains_this {
|
||||
@ -625,6 +624,7 @@ fn make_fn_ref(mut expr: FnExpr) -> Expr {
|
||||
Expr::Fn(expr)
|
||||
};
|
||||
|
||||
helper!(async_to_generator);
|
||||
Expr::Call(CallExpr {
|
||||
span,
|
||||
callee: quote_ident!("_asyncToGenerator").as_callee(),
|
||||
|
@ -30,7 +30,7 @@ impl Fold<MemberExpr> for MemberExprLit {
|
||||
value: sym, span, ..
|
||||
}))
|
||||
| Expr::Ident(Ident { sym, span, .. }) => {
|
||||
if sym.is_reserved_for_es3() {
|
||||
if sym.is_reserved_for_es3() || sym.contains("-") || sym.contains(".") {
|
||||
return MemberExpr {
|
||||
computed: true,
|
||||
prop: box Expr::Lit(Lit::Str(Str {
|
||||
|
@ -39,7 +39,7 @@ impl Fold<PropName> for PropertyLiteral {
|
||||
PropName::Str(Str {
|
||||
value: sym, span, ..
|
||||
}) => {
|
||||
if sym.is_reserved_for_es3() || sym.contains('-') {
|
||||
if sym.is_reserved_for_es3() || sym.contains('-') || sym.contains('.') {
|
||||
return PropName::Str(Str {
|
||||
span,
|
||||
value: sym,
|
||||
@ -51,7 +51,7 @@ impl Fold<PropName> for PropertyLiteral {
|
||||
}
|
||||
PropName::Ident(i) => {
|
||||
let Ident { sym, span, .. } = i;
|
||||
if sym.is_reserved_for_es3() || sym.contains('-') {
|
||||
if sym.is_reserved_for_es3() || sym.contains('-') || sym.contains('.') {
|
||||
return PropName::Str(Str {
|
||||
span,
|
||||
value: sym,
|
||||
@ -95,4 +95,19 @@ mod tests {
|
||||
ok_if_code_eq
|
||||
);
|
||||
|
||||
test!(
|
||||
::swc_ecma_parser::Syntax::default(),
|
||||
|_| PropertyLiteral,
|
||||
str_lit,
|
||||
r#"'use strict';
|
||||
var x = {
|
||||
'foo.bar': true
|
||||
};"#,
|
||||
r#"'use strict';
|
||||
var x = {
|
||||
'foo.bar': true
|
||||
};"#,
|
||||
ok_if_code_eq
|
||||
);
|
||||
|
||||
}
|
||||
|
@ -440,4 +440,6 @@ const _ref = {}, { c =( _tmp = {}, d = _extends({}, _tmp), _tmp) } = _ref;"
|
||||
identical!(regression_10, "({x} = { x: 1 }), exports.x = x;");
|
||||
|
||||
identical!(regression_11, "(void 0).foo();");
|
||||
|
||||
identical!(regression_12, "(function{})()");
|
||||
}
|
||||
|
@ -13,6 +13,7 @@ use swc_ecma_parser::{Parser, Session, SourceFileInput, Syntax};
|
||||
#[derive(Default, Clone, Serialize, Deserialize)]
|
||||
#[serde(deny_unknown_fields, rename_all = "camelCase")]
|
||||
pub struct Config {
|
||||
#[serde(default)]
|
||||
pub globals: FxHashMap<String, String>,
|
||||
}
|
||||
|
||||
|
@ -440,16 +440,13 @@ impl Fold<Module> for Umd {
|
||||
|
||||
match ty {
|
||||
Some(&wildcard) => {
|
||||
if wildcard {
|
||||
helper!(interop_require_wildcard);
|
||||
} else {
|
||||
helper!(interop_require_default);
|
||||
}
|
||||
let right = box Expr::Call(CallExpr {
|
||||
span: DUMMY_SP,
|
||||
callee: if wildcard {
|
||||
helper!(interop_require_wildcard);
|
||||
quote_ident!("_interopRequireWildcard").as_callee()
|
||||
} else {
|
||||
helper!(interop_require_default);
|
||||
quote_ident!("_interopRequireDefault").as_callee()
|
||||
},
|
||||
args: vec![ident.clone().as_arg()],
|
||||
@ -619,6 +616,7 @@ impl Fold<Module> for Umd {
|
||||
ident: None,
|
||||
function: helper_fn,
|
||||
}
|
||||
.wrap_with_paren()
|
||||
.as_callee(),
|
||||
args: vec![ThisExpr { span: DUMMY_SP }.as_arg(), factory_arg],
|
||||
type_args: Default::default(),
|
||||
|
@ -462,7 +462,6 @@ impl Decorators {
|
||||
.map(Some)
|
||||
.collect();
|
||||
|
||||
helper!(decorate);
|
||||
let decorate_call = Expr::Call(make_decorate_call(
|
||||
class.decorators,
|
||||
iter::once({
|
||||
@ -539,6 +538,8 @@ fn make_decorate_call(
|
||||
decorators: Vec<Decorator>,
|
||||
args: impl Iterator<Item = ExprOrSpread>,
|
||||
) -> CallExpr {
|
||||
helper!(decorate);
|
||||
|
||||
CallExpr {
|
||||
span: DUMMY_SP,
|
||||
callee: quote_ident!("_decorate").as_callee(),
|
||||
|
Loading…
Reference in New Issue
Block a user