diff --git a/common/src/errors/mod.rs b/common/src/errors/mod.rs index 0317660b450..1d72ec66632 100644 --- a/common/src/errors/mod.rs +++ b/common/src/errors/mod.rs @@ -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::{ diff --git a/ecmascript/transforms/src/compat/es2015/classes/mod.rs b/ecmascript/transforms/src/compat/es2015/classes/mod.rs index 0c9b6e348f1..ca6607e6918 100644 --- a/ecmascript/transforms/src/compat/es2015/classes/mod.rs +++ b/ecmascript/transforms/src/compat/es2015/classes/mod.rs @@ -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, ) -> 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(), diff --git a/ecmascript/transforms/src/compat/es2015/classes/super_field.rs b/ecmascript/transforms/src/compat/es2015/classes/super_field.rs index da49ce85708..d17b4ad9eb0 100644 --- a/ecmascript/transforms/src/compat/es2015/classes/super_field.rs +++ b/ecmascript/transforms/src/compat/es2015/classes/super_field.rs @@ -174,6 +174,7 @@ impl<'a> Fold for SuperCalleeFolder<'a> { impl<'a> SuperCalleeFolder<'a> { fn super_to_get_call(&mut self, super_token: Span, prop: Box, 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 { 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 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 for SuperFieldAccessFolder<'a> { } } - if callee_folder.inject_set { - helper!(set); - } - n.fold_children(self) } } diff --git a/ecmascript/transforms/src/compat/es2015/computed_props/mod.rs b/ecmascript/transforms/src/compat/es2015/computed_props/mod.rs index 04db9fa5db5..5ff94efa250 100644 --- a/ecmascript/transforms/src/compat/es2015/computed_props/mod.rs +++ b/ecmascript/transforms/src/compat/es2015/computed_props/mod.rs @@ -193,6 +193,7 @@ impl Fold 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 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 for ObjectLitFolder { })), definite: false, }); + helper!(define_enumerable_properties); exprs.push(box Expr::Call(CallExpr { span, callee: quote_ident!("_defineEnumerableProperties").as_callee(), diff --git a/ecmascript/transforms/src/compat/es2017/async_to_generator/mod.rs b/ecmascript/transforms/src/compat/es2017/async_to_generator/mod.rs index 77da678e47e..beda98e4434 100644 --- a/ecmascript/transforms/src/compat/es2017/async_to_generator/mod.rs +++ b/ecmascript/transforms/src/compat/es2017/async_to_generator/mod.rs @@ -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(), diff --git a/ecmascript/transforms/src/compat/es3/member_expr_lits.rs b/ecmascript/transforms/src/compat/es3/member_expr_lits.rs index 6582310e6e6..a0339dc3d75 100644 --- a/ecmascript/transforms/src/compat/es3/member_expr_lits.rs +++ b/ecmascript/transforms/src/compat/es3/member_expr_lits.rs @@ -30,7 +30,7 @@ impl Fold 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 { diff --git a/ecmascript/transforms/src/compat/es3/prop_lits.rs b/ecmascript/transforms/src/compat/es3/prop_lits.rs index 71b571d14ed..88bcaa19aae 100644 --- a/ecmascript/transforms/src/compat/es3/prop_lits.rs +++ b/ecmascript/transforms/src/compat/es3/prop_lits.rs @@ -39,7 +39,7 @@ impl Fold 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 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 + ); + } diff --git a/ecmascript/transforms/src/fixer.rs b/ecmascript/transforms/src/fixer.rs index 06915944058..da0622412e5 100644 --- a/ecmascript/transforms/src/fixer.rs +++ b/ecmascript/transforms/src/fixer.rs @@ -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{})()"); } diff --git a/ecmascript/transforms/src/modules/umd/config.rs b/ecmascript/transforms/src/modules/umd/config.rs index b55633cca37..b216ce4fff4 100644 --- a/ecmascript/transforms/src/modules/umd/config.rs +++ b/ecmascript/transforms/src/modules/umd/config.rs @@ -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, } diff --git a/ecmascript/transforms/src/modules/umd/mod.rs b/ecmascript/transforms/src/modules/umd/mod.rs index 46ce587b013..797910f39bb 100644 --- a/ecmascript/transforms/src/modules/umd/mod.rs +++ b/ecmascript/transforms/src/modules/umd/mod.rs @@ -440,16 +440,13 @@ impl Fold 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 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(), diff --git a/ecmascript/transforms/src/proposals/decorators/mod.rs b/ecmascript/transforms/src/proposals/decorators/mod.rs index 557746f4a6a..f36d30d06a7 100644 --- a/ecmascript/transforms/src/proposals/decorators/mod.rs +++ b/ecmascript/transforms/src/proposals/decorators/mod.rs @@ -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, args: impl Iterator, ) -> CallExpr { + helper!(decorate); + CallExpr { span: DUMMY_SP, callee: quote_ident!("_decorate").as_callee(),