diff --git a/ecmascript/Cargo.toml b/ecmascript/Cargo.toml index ae448a918e11..51b6f1c8b2b9 100644 --- a/ecmascript/Cargo.toml +++ b/ecmascript/Cargo.toml @@ -6,7 +6,7 @@ edition = "2018" license = "Apache-2.0/MIT" name = "swc_ecmascript" repository = "https://github.com/swc-project/swc.git" -version = "0.29.0" +version = "0.29.1" [package.metadata.docs.rs] all-features = true @@ -30,7 +30,7 @@ typescript = ["swc_ecma_transforms/typescript"] swc_ecma_ast = {version = "0.42.0", path = "./ast"} swc_ecma_codegen = {version = "0.50.0", path = "./codegen", optional = true} swc_ecma_dep_graph = {version = "0.20.0", path = "./dep-graph", optional = true} -swc_ecma_parser = {version = "0.52.0", path = "./parser", optional = true} +swc_ecma_parser = {version = "0.52.1", path = "./parser", optional = true} swc_ecma_transforms = {version = "0.43.0", path = "./transforms", optional = true} swc_ecma_utils = {version = "0.33.0", path = "./utils", optional = true} swc_ecma_visit = {version = "0.28.0", path = "./visit", optional = true} diff --git a/ecmascript/codegen/Cargo.toml b/ecmascript/codegen/Cargo.toml index 794de0554b50..713284b8358b 100644 --- a/ecmascript/codegen/Cargo.toml +++ b/ecmascript/codegen/Cargo.toml @@ -7,7 +7,7 @@ include = ["Cargo.toml", "src/**/*.rs"] license = "Apache-2.0/MIT" name = "swc_ecma_codegen" repository = "https://github.com/swc-project/swc.git" -version = "0.50.2" +version = "0.50.3" [dependencies] bitflags = "1" diff --git a/ecmascript/codegen/src/comments.rs b/ecmascript/codegen/src/comments.rs index be972c33e747..46a50fb424b4 100644 --- a/ecmascript/codegen/src/comments.rs +++ b/ecmascript/codegen/src/comments.rs @@ -39,6 +39,7 @@ impl<'a> Emitter<'a> { &mut self, pos: BytePos, prefix_space: bool, + _is_hi: bool, ) -> Result { if pos == BytePos(0) { return Ok(()); @@ -54,11 +55,15 @@ impl<'a> Emitter<'a> { write_comments!(self, prefix_space, &cmts) } - pub(super) fn emit_leading_comments_of_pos(&mut self, pos: BytePos) -> Result { + pub(super) fn emit_leading_comments_of_pos(&mut self, mut pos: BytePos, is_hi: bool) -> Result { if pos == BytePos(0) { return Ok(()); } + if is_hi { + pos = pos - BytePos(1) + } + let comments = match self.comments { Some(ref comments) => comments, None => return Ok(()), diff --git a/ecmascript/codegen/src/decl.rs b/ecmascript/codegen/src/decl.rs index c2301693b9d2..e9cbe0a5200f 100644 --- a/ecmascript/codegen/src/decl.rs +++ b/ecmascript/codegen/src/decl.rs @@ -23,7 +23,7 @@ impl<'a> Emitter<'a> { #[emitter] fn emit_class_decl(&mut self, node: &ClassDecl) -> Result { - self.emit_leading_comments_of_pos(node.span().lo())?; + self.emit_leading_comments_of_pos(node.span().lo(), false)?; if node.declare { keyword!("declare"); @@ -44,7 +44,7 @@ impl<'a> Emitter<'a> { #[emitter] fn emit_fn_decl(&mut self, node: &FnDecl) -> Result { - self.emit_leading_comments_of_pos(node.span().lo())?; + self.emit_leading_comments_of_pos(node.span().lo(), false)?; if node.declare { keyword!("declare"); @@ -71,7 +71,7 @@ impl<'a> Emitter<'a> { #[emitter] fn emit_var_decl(&mut self, node: &VarDecl) -> Result { - self.emit_leading_comments_of_pos(node.span.lo())?; + self.emit_leading_comments_of_pos(node.span.lo(), false)?; if node.declare { keyword!("declare"); @@ -90,7 +90,7 @@ impl<'a> Emitter<'a> { #[emitter] fn emit_var_declarator(&mut self, node: &VarDeclarator) -> Result { - self.emit_leading_comments_of_pos(node.span().lo())?; + self.emit_leading_comments_of_pos(node.span().lo(), false)?; emit!(node.name); diff --git a/ecmascript/codegen/src/lib.rs b/ecmascript/codegen/src/lib.rs index 0a25bc737916..b96565c7d6d1 100644 --- a/ecmascript/codegen/src/lib.rs +++ b/ecmascript/codegen/src/lib.rs @@ -99,7 +99,7 @@ impl<'a> Emitter<'a> { #[emitter] fn emit_module_decl(&mut self, node: &ModuleDecl) -> Result { - self.emit_leading_comments_of_pos(node.span().lo())?; + self.emit_leading_comments_of_pos(node.span().lo(), false)?; match *node { ModuleDecl::Import(ref d) => emit!(d), @@ -134,7 +134,7 @@ impl<'a> Emitter<'a> { #[emitter] fn emit_export_default_decl(&mut self, node: &ExportDefaultDecl) -> Result { - self.emit_leading_comments_of_pos(node.span().lo())?; + self.emit_leading_comments_of_pos(node.span().lo(), false)?; keyword!("export"); space!(); @@ -150,7 +150,7 @@ impl<'a> Emitter<'a> { #[emitter] fn emit_import(&mut self, node: &ImportDecl) -> Result { - self.emit_leading_comments_of_pos(node.span().lo())?; + self.emit_leading_comments_of_pos(node.span().lo(), false)?; keyword!("import"); space!(); @@ -238,7 +238,7 @@ impl<'a> Emitter<'a> { #[emitter] fn emit_namespace_export_specifier(&mut self, node: &ExportNamespaceSpecifier) -> Result { - self.emit_leading_comments_of_pos(node.span().lo())?; + self.emit_leading_comments_of_pos(node.span().lo(), false)?; punct!("*"); formatting_space!(); @@ -249,7 +249,7 @@ impl<'a> Emitter<'a> { #[emitter] fn emit_named_export_specifier(&mut self, node: &ExportNamedSpecifier) -> Result { - self.emit_leading_comments_of_pos(node.span().lo())?; + self.emit_leading_comments_of_pos(node.span().lo(), false)?; if let Some(ref exported) = node.exported { emit!(node.orig); @@ -264,7 +264,7 @@ impl<'a> Emitter<'a> { #[emitter] fn emit_named_export(&mut self, node: &NamedExport) -> Result { - self.emit_leading_comments_of_pos(node.span().lo())?; + self.emit_leading_comments_of_pos(node.span().lo(), false)?; struct Specifiers<'a> { has_namespace_spec: bool, @@ -335,7 +335,7 @@ impl<'a> Emitter<'a> { #[emitter] fn emit_export_all(&mut self, node: &ExportAll) -> Result { - self.emit_leading_comments_of_pos(node.span().lo())?; + self.emit_leading_comments_of_pos(node.span().lo(), false)?; keyword!("export"); space!(); @@ -349,7 +349,7 @@ impl<'a> Emitter<'a> { #[emitter] fn emit_lit(&mut self, node: &Lit) -> Result { - self.emit_leading_comments_of_pos(node.span().lo())?; + self.emit_leading_comments_of_pos(node.span().lo(), false)?; match *node { Lit::Bool(Bool { value, span }) => { @@ -381,7 +381,7 @@ impl<'a> Emitter<'a> { #[emitter] fn emit_str_lit(&mut self, node: &Str) -> Result { - self.emit_leading_comments_of_pos(node.span().lo())?; + self.emit_leading_comments_of_pos(node.span().lo(), false)?; let (single_quote, value) = match node.kind { StrKind::Normal { contains_quote } => { @@ -422,7 +422,7 @@ impl<'a> Emitter<'a> { #[emitter] fn emit_num_lit(&mut self, num: &Number) -> Result { - self.emit_leading_comments_of_pos(num.span().lo())?; + self.emit_leading_comments_of_pos(num.span().lo(), false)?; // Handle infinity if num.value.is_infinite() { @@ -441,7 +441,7 @@ impl<'a> Emitter<'a> { #[emitter] fn emit_big_lit(&mut self, v: &BigInt) -> Result { - self.emit_leading_comments_of_pos(v.span.lo())?; + self.emit_leading_comments_of_pos(v.span.lo(), false)?; self.wr.write_lit(v.span, &v.value.to_string())?; self.wr.write_lit(v.span, "n")?; @@ -528,7 +528,7 @@ impl<'a> Emitter<'a> { #[emitter] fn emit_opt_chain(&mut self, n: &OptChainExpr) -> Result { - self.emit_leading_comments_of_pos(n.span().lo())?; + self.emit_leading_comments_of_pos(n.span().lo(), false)?; match *n.expr { Expr::Member(ref e) => { @@ -557,14 +557,14 @@ impl<'a> Emitter<'a> { #[emitter] fn emit_invalid(&mut self, n: &Invalid) -> Result { - self.emit_leading_comments_of_pos(n.span.lo())?; + self.emit_leading_comments_of_pos(n.span.lo(), false)?; self.wr.write_str_lit(n.span, "")?; } #[emitter] fn emit_call_expr(&mut self, node: &CallExpr) -> Result { - self.emit_leading_comments_of_pos(node.span().lo())?; + self.emit_leading_comments_of_pos(node.span().lo(), false)?; emit!(node.callee); @@ -575,7 +575,7 @@ impl<'a> Emitter<'a> { #[emitter] fn emit_new_expr(&mut self, node: &NewExpr) -> Result { - self.emit_leading_comments_of_pos(node.span().lo())?; + self.emit_leading_comments_of_pos(node.span().lo(), false)?; keyword!("new"); space!(); @@ -594,7 +594,7 @@ impl<'a> Emitter<'a> { #[emitter] fn emit_member_expr(&mut self, node: &MemberExpr) -> Result { - self.emit_leading_comments_of_pos(node.span().lo())?; + self.emit_leading_comments_of_pos(node.span().lo(), false)?; emit!(node.obj); @@ -605,12 +605,12 @@ impl<'a> Emitter<'a> { } else { if self.needs_2dots_for_property_access(&node.obj) { if node.prop.span().lo() >= BytePos(2) { - self.emit_leading_comments_of_pos(node.prop.span().lo() - BytePos(2))?; + self.emit_leading_comments_of_pos(node.prop.span().lo() - BytePos(2), false)?; } punct!("."); } if node.prop.span().lo() >= BytePos(1) { - self.emit_leading_comments_of_pos(node.prop.span().lo() - BytePos(1))?; + self.emit_leading_comments_of_pos(node.prop.span().lo() - BytePos(1), false)?; } punct!("."); emit!(node.prop); @@ -646,7 +646,7 @@ impl<'a> Emitter<'a> { #[emitter] fn emit_arrow_expr(&mut self, node: &ArrowExpr) -> Result { - self.emit_leading_comments_of_pos(node.span().lo())?; + self.emit_leading_comments_of_pos(node.span().lo(), false)?; let space = !self.cfg.minify || match node.params.as_slice() { @@ -689,7 +689,7 @@ impl<'a> Emitter<'a> { #[emitter] fn emit_meta_prop_expr(&mut self, node: &MetaPropExpr) -> Result { - self.emit_leading_comments_of_pos(node.span().lo())?; + self.emit_leading_comments_of_pos(node.span().lo(), false)?; emit!(node.meta); punct!("."); @@ -698,7 +698,7 @@ impl<'a> Emitter<'a> { #[emitter] fn emit_seq_expr(&mut self, node: &SeqExpr) -> Result { - self.emit_leading_comments_of_pos(node.span().lo())?; + self.emit_leading_comments_of_pos(node.span().lo(), false)?; let mut first = true; //TODO: Indention @@ -716,7 +716,7 @@ impl<'a> Emitter<'a> { #[emitter] fn emit_assign_expr(&mut self, node: &AssignExpr) -> Result { - self.emit_leading_comments_of_pos(node.span().lo())?; + self.emit_leading_comments_of_pos(node.span().lo(), false)?; emit!(node.left); formatting_space!(); @@ -764,7 +764,7 @@ impl<'a> Emitter<'a> { #[emitter] fn emit_bin_expr(&mut self, node: &BinExpr) -> Result { - self.emit_leading_comments_of_pos(node.span().lo())?; + self.emit_leading_comments_of_pos(node.span().lo(), false)?; { let mut left = Some(node); @@ -798,7 +798,7 @@ impl<'a> Emitter<'a> { #[emitter] fn emit_decorator(&mut self, node: &Decorator) -> Result { - self.emit_leading_comments_of_pos(node.span().lo())?; + self.emit_leading_comments_of_pos(node.span().lo(), false)?; punct!("@"); emit!(node.expr); @@ -807,7 +807,7 @@ impl<'a> Emitter<'a> { #[emitter] fn emit_class_expr(&mut self, node: &ClassExpr) -> Result { - self.emit_leading_comments_of_pos(node.span().lo())?; + self.emit_leading_comments_of_pos(node.span().lo(), false)?; for dec in &node.class.decorators { emit!(dec); @@ -857,7 +857,7 @@ impl<'a> Emitter<'a> { #[emitter] fn emit_private_method(&mut self, n: &PrivateMethod) -> Result { - self.emit_leading_comments_of_pos(n.span().lo())?; + self.emit_leading_comments_of_pos(n.span().lo(), false)?; if n.is_static { keyword!("static"); @@ -894,7 +894,7 @@ impl<'a> Emitter<'a> { #[emitter] fn emit_bool(&mut self, n: &Bool) -> Result { - self.emit_leading_comments_of_pos(n.span().lo())?; + self.emit_leading_comments_of_pos(n.span().lo(), false)?; if n.value { keyword!(n.span, "true") @@ -905,7 +905,7 @@ impl<'a> Emitter<'a> { #[emitter] fn emit_class_method(&mut self, n: &ClassMethod) -> Result { - self.emit_leading_comments_of_pos(n.span().lo())?; + self.emit_leading_comments_of_pos(n.span().lo(), false)?; self.emit_accesibility(n.accessibility)?; @@ -967,7 +967,7 @@ impl<'a> Emitter<'a> { #[emitter] fn emit_private_prop(&mut self, n: &PrivateProp) -> Result { - self.emit_leading_comments_of_pos(n.span().lo())?; + self.emit_leading_comments_of_pos(n.span().lo(), false)?; self.emit_list(n.span, Some(&n.decorators), ListFormat::Decorators)?; @@ -1004,7 +1004,7 @@ impl<'a> Emitter<'a> { #[emitter] fn emit_class_prop(&mut self, n: &ClassProp) -> Result { - self.emit_leading_comments_of_pos(n.span().lo())?; + self.emit_leading_comments_of_pos(n.span().lo(), false)?; if n.accessibility != Some(Accessibility::Public) { self.emit_accesibility(n.accessibility)?; @@ -1066,7 +1066,7 @@ impl<'a> Emitter<'a> { #[emitter] fn emit_class_constructor(&mut self, n: &Constructor) -> Result { - self.emit_leading_comments_of_pos(n.span().lo())?; + self.emit_leading_comments_of_pos(n.span().lo(), false)?; self.emit_accesibility(n.accessibility)?; @@ -1102,7 +1102,7 @@ impl<'a> Emitter<'a> { #[emitter] fn emit_cond_expr(&mut self, node: &CondExpr) -> Result { - self.emit_leading_comments_of_pos(node.span().lo())?; + self.emit_leading_comments_of_pos(node.span().lo(), false)?; emit!(node.test); formatting_space!(); @@ -1117,7 +1117,7 @@ impl<'a> Emitter<'a> { #[emitter] fn emit_fn_expr(&mut self, node: &FnExpr) -> Result { - self.emit_leading_comments_of_pos(node.span().lo())?; + self.emit_leading_comments_of_pos(node.span().lo(), false)?; if node.function.is_async { keyword!("async"); @@ -1178,7 +1178,7 @@ impl<'a> Emitter<'a> { #[emitter] fn emit_this_expr(&mut self, node: &ThisExpr) -> Result { - self.emit_leading_comments_of_pos(node.span().lo())?; + self.emit_leading_comments_of_pos(node.span().lo(), false)?; keyword!("this"); } @@ -1187,7 +1187,7 @@ impl<'a> Emitter<'a> { fn emit_tpl_lit(&mut self, node: &Tpl) -> Result { debug_assert!(node.quasis.len() == node.exprs.len() + 1); - self.emit_leading_comments_of_pos(node.span().lo())?; + self.emit_leading_comments_of_pos(node.span().lo(), false)?; punct!("`"); let i = 0; @@ -1207,7 +1207,7 @@ impl<'a> Emitter<'a> { #[emitter] fn emit_tagged_tpl_lit(&mut self, node: &TaggedTpl) -> Result { - self.emit_leading_comments_of_pos(node.span().lo())?; + self.emit_leading_comments_of_pos(node.span().lo(), false)?; emit!(node.tag); emit!(node.type_params); @@ -1223,7 +1223,7 @@ impl<'a> Emitter<'a> { #[emitter] fn emit_unary_expr(&mut self, node: &UnaryExpr) -> Result { - self.emit_leading_comments_of_pos(node.span().lo())?; + self.emit_leading_comments_of_pos(node.span().lo(), false)?; let need_formatting_space = match node.op { op!("typeof") | op!("void") | op!("delete") => { @@ -1247,7 +1247,7 @@ impl<'a> Emitter<'a> { #[emitter] fn emit_update_expr(&mut self, node: &UpdateExpr) -> Result { - self.emit_leading_comments_of_pos(node.span().lo())?; + self.emit_leading_comments_of_pos(node.span().lo(), false)?; if node.prefix { operator!(node.op.as_str()); @@ -1261,7 +1261,7 @@ impl<'a> Emitter<'a> { #[emitter] fn emit_yield_expr(&mut self, node: &YieldExpr) -> Result { - self.emit_leading_comments_of_pos(node.span().lo())?; + self.emit_leading_comments_of_pos(node.span().lo(), false)?; keyword!("yield"); if node.delegate { @@ -1289,7 +1289,7 @@ impl<'a> Emitter<'a> { #[emitter] fn emit_expr_or_spread(&mut self, node: &ExprOrSpread) -> Result { - self.emit_leading_comments_of_pos(node.span().lo())?; + self.emit_leading_comments_of_pos(node.span().lo(), false)?; if node.spread.is_some() { punct!("..."); @@ -1300,7 +1300,7 @@ impl<'a> Emitter<'a> { #[emitter] fn emit_await_expr(&mut self, node: &AwaitExpr) -> Result { - self.emit_leading_comments_of_pos(node.span().lo())?; + self.emit_leading_comments_of_pos(node.span().lo(), false)?; keyword!("await"); @@ -1311,7 +1311,7 @@ impl<'a> Emitter<'a> { #[emitter] fn emit_array_lit(&mut self, node: &ArrayLit) -> Result { - self.emit_leading_comments_of_pos(node.span().lo())?; + self.emit_leading_comments_of_pos(node.span().lo(), false)?; punct!("["); self.emit_list( @@ -1324,7 +1324,7 @@ impl<'a> Emitter<'a> { #[emitter] fn emit_object_lit(&mut self, node: &ObjectLit) -> Result { - self.emit_leading_comments_of_pos(node.span().lo())?; + self.emit_leading_comments_of_pos(node.span().lo(), false)?; punct!("{"); if !self.cfg.minify { @@ -1355,7 +1355,7 @@ impl<'a> Emitter<'a> { #[emitter] fn emit_kv_prop(&mut self, node: &KeyValueProp) -> Result { - self.emit_leading_comments_of_pos(node.span().lo())?; + self.emit_leading_comments_of_pos(node.span().lo(), false)?; emit!(node.key); punct!(":"); @@ -1365,7 +1365,7 @@ impl<'a> Emitter<'a> { #[emitter] fn emit_assign_prop(&mut self, node: &AssignProp) -> Result { - self.emit_leading_comments_of_pos(node.span().lo())?; + self.emit_leading_comments_of_pos(node.span().lo(), false)?; emit!(node.key); punct!("="); @@ -1374,7 +1374,7 @@ impl<'a> Emitter<'a> { #[emitter] fn emit_getter_prop(&mut self, node: &GetterProp) -> Result { - self.emit_leading_comments_of_pos(node.span().lo())?; + self.emit_leading_comments_of_pos(node.span().lo(), false)?; keyword!("get"); space!(); @@ -1388,7 +1388,7 @@ impl<'a> Emitter<'a> { #[emitter] fn emit_setter_prop(&mut self, node: &SetterProp) -> Result { - self.emit_leading_comments_of_pos(node.span().lo())?; + self.emit_leading_comments_of_pos(node.span().lo(), false)?; keyword!("set"); space!(); @@ -1404,7 +1404,7 @@ impl<'a> Emitter<'a> { #[emitter] fn emit_method_prop(&mut self, node: &MethodProp) -> Result { - self.emit_leading_comments_of_pos(node.span().lo())?; + self.emit_leading_comments_of_pos(node.span().lo(), false)?; if node.function.is_async { keyword!("async"); @@ -1423,7 +1423,7 @@ impl<'a> Emitter<'a> { #[emitter] fn emit_paren_expr(&mut self, node: &ParenExpr) -> Result { - self.emit_leading_comments_of_pos(node.span().lo())?; + self.emit_leading_comments_of_pos(node.span().lo(), false)?; punct!("("); emit!(node.expr); @@ -1432,7 +1432,7 @@ impl<'a> Emitter<'a> { #[emitter] fn emit_private_name(&mut self, n: &PrivateName) -> Result { - self.emit_leading_comments_of_pos(n.span().lo())?; + self.emit_leading_comments_of_pos(n.span().lo(), false)?; punct!("#"); emit!(n.id) @@ -1457,7 +1457,7 @@ impl<'a> Emitter<'a> { #[emitter] fn emit_ident(&mut self, ident: &Ident) -> Result { // TODO: Use write_symbol when ident is a symbol. - self.emit_leading_comments_of_pos(ident.span.lo())?; + self.emit_leading_comments_of_pos(ident.span.lo(), false)?; // TODO: span self.wr.write_symbol(ident.span, &ident.sym)?; @@ -1515,6 +1515,7 @@ impl<'a> Emitter<'a> { parent_node.lo() }, true, + false, )?; } } @@ -1576,7 +1577,7 @@ impl<'a> Emitter<'a> { if format.contains(ListFormat::DelimitersMask) && previous_sibling.span().hi() != parent_node.hi() { - self.emit_leading_comments_of_pos(previous_sibling.span().hi())?; + self.emit_leading_comments_of_pos(previous_sibling.span().hi(), true)?; } self.write_delim(format)?; @@ -1612,7 +1613,7 @@ impl<'a> Emitter<'a> { // Emit this child. if should_emit_intervening_comments { let comment_range = child.comment_range(); - self.emit_trailing_comments_of_pos(comment_range.hi(), false)?; + self.emit_trailing_comments_of_pos(comment_range.hi(), false, true)?; } else { should_emit_intervening_comments = may_emit_intervening_comments; } @@ -1669,7 +1670,7 @@ impl<'a> Emitter<'a> { && previous_sibling.span().hi() != parent_node.hi() && emit_trailing_comments { - self.emit_leading_comments_of_pos(previous_sibling.span().hi())?; + self.emit_leading_comments_of_pos(previous_sibling.span().hi(), true)?; } } } @@ -1696,11 +1697,14 @@ impl<'a> Emitter<'a> { if format.contains(ListFormat::BracketsMask) { if is_empty { - self.emit_leading_comments_of_pos({ - //TODO: children.hi() + self.emit_leading_comments_of_pos( + { + //TODO: children.hi() - parent_node.hi() - })?; // Emit leading comments within empty lists + parent_node.hi() + }, + true, + )?; // Emit leading comments within empty lists } self.wr.write_punct(format.closing_bracket())?; } @@ -1713,7 +1717,7 @@ impl<'a> Emitter<'a> { impl<'a> Emitter<'a> { #[emitter] fn emit_param(&mut self, node: &Param) -> Result { - self.emit_leading_comments_of_pos(node.span().lo())?; + self.emit_leading_comments_of_pos(node.span().lo(), false)?; self.emit_list(node.span, Some(&node.decorators), ListFormat::Decorators)?; @@ -1735,7 +1739,7 @@ impl<'a> Emitter<'a> { #[emitter] fn emit_rest_pat(&mut self, node: &RestPat) -> Result { - self.emit_leading_comments_of_pos(node.span().lo())?; + self.emit_leading_comments_of_pos(node.span().lo(), false)?; punct!("..."); emit!(node.arg); @@ -1757,7 +1761,7 @@ impl<'a> Emitter<'a> { #[emitter] fn emit_spread_element(&mut self, node: &SpreadElement) -> Result { - self.emit_leading_comments_of_pos(node.span().lo())?; + self.emit_leading_comments_of_pos(node.span().lo(), false)?; punct!("..."); emit!(node.expr) @@ -1773,7 +1777,7 @@ impl<'a> Emitter<'a> { #[emitter] fn emit_array_pat(&mut self, node: &ArrayPat) -> Result { - self.emit_leading_comments_of_pos(node.span().lo())?; + self.emit_leading_comments_of_pos(node.span().lo(), false)?; punct!("["); self.emit_list( @@ -1795,7 +1799,7 @@ impl<'a> Emitter<'a> { #[emitter] fn emit_assign_pat(&mut self, node: &AssignPat) -> Result { - self.emit_leading_comments_of_pos(node.span().lo())?; + self.emit_leading_comments_of_pos(node.span().lo(), false)?; emit!(node.left); formatting_space!(); @@ -1806,7 +1810,7 @@ impl<'a> Emitter<'a> { #[emitter] fn emit_object_pat(&mut self, node: &ObjectPat) -> Result { - self.emit_leading_comments_of_pos(node.span().lo())?; + self.emit_leading_comments_of_pos(node.span().lo(), false)?; punct!("{"); self.emit_list( @@ -1837,7 +1841,7 @@ impl<'a> Emitter<'a> { #[emitter] fn emit_object_kv_pat(&mut self, node: &KeyValuePatProp) -> Result { - self.emit_leading_comments_of_pos(node.span().lo())?; + self.emit_leading_comments_of_pos(node.span().lo(), false)?; emit!(node.key); punct!(":"); @@ -1848,7 +1852,7 @@ impl<'a> Emitter<'a> { #[emitter] fn emit_object_assign_pat(&mut self, node: &AssignPatProp) -> Result { - self.emit_leading_comments_of_pos(node.span().lo())?; + self.emit_leading_comments_of_pos(node.span().lo(), false)?; emit!(node.key); formatting_space!(); @@ -1896,7 +1900,7 @@ impl<'a> Emitter<'a> { Stmt::ForOf(ref e) => emit!(e), Stmt::Decl(ref e) => emit!(e), } - self.emit_trailing_comments_of_pos(node.span().hi(), true)?; + self.emit_trailing_comments_of_pos(node.span().hi(), true, true)?; if !self.cfg.minify { self.wr.write_line()?; @@ -1911,7 +1915,7 @@ impl<'a> Emitter<'a> { #[emitter] fn emit_block_stmt(&mut self, node: &BlockStmt) -> Result { - self.emit_leading_comments_of_pos(node.span().lo())?; + self.emit_leading_comments_of_pos(node.span().lo(), false)?; punct!("{"); self.emit_list( @@ -1920,21 +1924,21 @@ impl<'a> Emitter<'a> { ListFormat::MultiLineBlockStatements, )?; - self.emit_leading_comments_of_pos(node.span().hi())?; + self.emit_leading_comments_of_pos(node.span().hi(), true)?; punct!("}"); } #[emitter] fn emit_empty_stmt(&mut self, node: &EmptyStmt) -> Result { - self.emit_leading_comments_of_pos(node.span().lo())?; + self.emit_leading_comments_of_pos(node.span().lo(), false)?; semi!(); } #[emitter] fn emit_debugger_stmt(&mut self, node: &DebuggerStmt) -> Result { - self.emit_leading_comments_of_pos(node.span().lo())?; + self.emit_leading_comments_of_pos(node.span().lo(), false)?; keyword!("debugger"); formatting_semi!(); @@ -1954,7 +1958,7 @@ impl<'a> Emitter<'a> { #[emitter] fn emit_return_stmt(&mut self, node: &ReturnStmt) -> Result { - self.emit_leading_comments_of_pos(node.span.lo())?; + self.emit_leading_comments_of_pos(node.span.lo(), false)?; keyword!("return"); if let Some(ref arg) = node.arg { @@ -2011,7 +2015,7 @@ impl<'a> Emitter<'a> { #[emitter] fn emit_if_stmt(&mut self, node: &IfStmt) -> Result { - self.emit_leading_comments_of_pos(node.span().lo())?; + self.emit_leading_comments_of_pos(node.span().lo(), false)?; keyword!("if"); @@ -2044,7 +2048,7 @@ impl<'a> Emitter<'a> { #[emitter] fn emit_switch_stmt(&mut self, node: &SwitchStmt) -> Result { - self.emit_leading_comments_of_pos(node.span().lo())?; + self.emit_leading_comments_of_pos(node.span().lo(), false)?; keyword!("switch"); @@ -2059,7 +2063,7 @@ impl<'a> Emitter<'a> { #[emitter] fn emit_catch_clause(&mut self, node: &CatchClause) -> Result { - self.emit_leading_comments_of_pos(node.span().lo())?; + self.emit_leading_comments_of_pos(node.span().lo(), false)?; keyword!("catch"); formatting_space!(); @@ -2077,7 +2081,7 @@ impl<'a> Emitter<'a> { #[emitter] fn emit_switch_case(&mut self, node: &SwitchCase) -> Result { - self.emit_leading_comments_of_pos(node.span().lo())?; + self.emit_leading_comments_of_pos(node.span().lo(), false)?; if let Some(ref test) = node.test { keyword!("case"); @@ -2109,7 +2113,7 @@ impl<'a> Emitter<'a> { #[emitter] fn emit_throw_stmt(&mut self, node: &ThrowStmt) -> Result { - self.emit_leading_comments_of_pos(node.span().lo())?; + self.emit_leading_comments_of_pos(node.span().lo(), false)?; keyword!("throw"); space!(); @@ -2119,7 +2123,7 @@ impl<'a> Emitter<'a> { #[emitter] fn emit_try_stmt(&mut self, node: &TryStmt) -> Result { - self.emit_leading_comments_of_pos(node.span().lo())?; + self.emit_leading_comments_of_pos(node.span().lo(), false)?; keyword!("try"); formatting_space!(); @@ -2140,7 +2144,7 @@ impl<'a> Emitter<'a> { #[emitter] fn emit_while_stmt(&mut self, node: &WhileStmt) -> Result { - self.emit_leading_comments_of_pos(node.span().lo())?; + self.emit_leading_comments_of_pos(node.span().lo(), false)?; keyword!("while"); @@ -2153,7 +2157,7 @@ impl<'a> Emitter<'a> { #[emitter] fn emit_do_while_stmt(&mut self, node: &DoWhileStmt) -> Result { - self.emit_leading_comments_of_pos(node.span().lo())?; + self.emit_leading_comments_of_pos(node.span().lo(), false)?; keyword!("do"); if node.body.starts_with_alpha_num() { @@ -2174,7 +2178,7 @@ impl<'a> Emitter<'a> { #[emitter] fn emit_for_stmt(&mut self, node: &ForStmt) -> Result { - self.emit_leading_comments_of_pos(node.span().lo())?; + self.emit_leading_comments_of_pos(node.span().lo(), false)?; keyword!("for"); punct!("("); @@ -2190,7 +2194,7 @@ impl<'a> Emitter<'a> { #[emitter] fn emit_for_in_stmt(&mut self, node: &ForInStmt) -> Result { - self.emit_leading_comments_of_pos(node.span().lo())?; + self.emit_leading_comments_of_pos(node.span().lo(), false)?; keyword!("for"); punct!("("); @@ -2206,7 +2210,7 @@ impl<'a> Emitter<'a> { #[emitter] fn emit_for_of_stmt(&mut self, node: &ForOfStmt) -> Result { - self.emit_leading_comments_of_pos(node.span().lo())?; + self.emit_leading_comments_of_pos(node.span().lo(), false)?; keyword!("for"); if node.await_token.is_some() { diff --git a/ecmascript/codegen/src/typescript.rs b/ecmascript/codegen/src/typescript.rs index ce8cd6ac2da0..c536bae7b4b9 100644 --- a/ecmascript/codegen/src/typescript.rs +++ b/ecmascript/codegen/src/typescript.rs @@ -15,7 +15,7 @@ impl<'a> Emitter<'a> { #[emitter] fn emit_ts_array_type(&mut self, n: &TsArrayType) -> Result { - self.emit_leading_comments_of_pos(n.span().lo())?; + self.emit_leading_comments_of_pos(n.span().lo(), false)?; emit!(n.elem_type); punct!("["); @@ -24,7 +24,7 @@ impl<'a> Emitter<'a> { #[emitter] fn emit_ts_as_expr(&mut self, n: &TsAsExpr) -> Result { - self.emit_leading_comments_of_pos(n.span().lo())?; + self.emit_leading_comments_of_pos(n.span().lo(), false)?; emit!(n.expr); @@ -37,7 +37,7 @@ impl<'a> Emitter<'a> { #[emitter] fn emit_ts_call_signature_decl(&mut self, n: &TsCallSignatureDecl) -> Result { - self.emit_leading_comments_of_pos(n.span().lo())?; + self.emit_leading_comments_of_pos(n.span().lo(), false)?; emit!(n.type_params); @@ -56,7 +56,7 @@ impl<'a> Emitter<'a> { #[emitter] fn emit_ts_cond_type(&mut self, n: &TsConditionalType) -> Result { - self.emit_leading_comments_of_pos(n.span().lo())?; + self.emit_leading_comments_of_pos(n.span().lo(), false)?; emit!(n.check_type); space!(); @@ -80,7 +80,7 @@ impl<'a> Emitter<'a> { #[emitter] fn emit_ts_constructor_signature_decl(&mut self, n: &TsConstructSignatureDecl) -> Result { - self.emit_leading_comments_of_pos(n.span().lo())?; + self.emit_leading_comments_of_pos(n.span().lo(), false)?; keyword!("constructor"); @@ -91,7 +91,7 @@ impl<'a> Emitter<'a> { #[emitter] fn emit_ts_constructor_type(&mut self, n: &TsConstructorType) -> Result { - self.emit_leading_comments_of_pos(n.span().lo())?; + self.emit_leading_comments_of_pos(n.span().lo(), false)?; if n.is_abstract { keyword!("abstract"); @@ -117,7 +117,7 @@ impl<'a> Emitter<'a> { #[emitter] fn emit_ts_entity_name(&mut self, n: &TsEntityName) -> Result { - self.emit_leading_comments_of_pos(n.span().lo())?; + self.emit_leading_comments_of_pos(n.span().lo(), false)?; match n { TsEntityName::TsQualifiedName(n) => { @@ -129,7 +129,7 @@ impl<'a> Emitter<'a> { #[emitter] fn emit_ts_enum_decl(&mut self, n: &TsEnumDecl) -> Result { - self.emit_leading_comments_of_pos(n.span().lo())?; + self.emit_leading_comments_of_pos(n.span().lo(), false)?; if n.declare { keyword!("declare"); @@ -156,7 +156,7 @@ impl<'a> Emitter<'a> { #[emitter] fn emit_ts_enum_member(&mut self, n: &TsEnumMember) -> Result { - self.emit_leading_comments_of_pos(n.span().lo())?; + self.emit_leading_comments_of_pos(n.span().lo(), false)?; emit!(n.id); @@ -178,7 +178,7 @@ impl<'a> Emitter<'a> { #[emitter] fn emit_ts_export_assignment(&mut self, n: &TsExportAssignment) -> Result { - self.emit_leading_comments_of_pos(n.span().lo())?; + self.emit_leading_comments_of_pos(n.span().lo(), false)?; keyword!("export"); formatting_space!(); @@ -189,7 +189,7 @@ impl<'a> Emitter<'a> { #[emitter] fn emit_ts_expr_with_type_args(&mut self, n: &TsExprWithTypeArgs) -> Result { - self.emit_leading_comments_of_pos(n.span().lo())?; + self.emit_leading_comments_of_pos(n.span().lo(), false)?; emit!(n.expr); @@ -198,14 +198,14 @@ impl<'a> Emitter<'a> { #[emitter] fn emit_ts_external_module_ref(&mut self, n: &TsExternalModuleRef) -> Result { - self.emit_leading_comments_of_pos(n.span().lo())?; + self.emit_leading_comments_of_pos(n.span().lo(), false)?; unimplemented!("emit_ts_external_module_ref") } #[emitter] fn emit_ts_fn_or_constructor_type(&mut self, n: &TsFnOrConstructorType) -> Result { - self.emit_leading_comments_of_pos(n.span().lo())?; + self.emit_leading_comments_of_pos(n.span().lo(), false)?; match n { TsFnOrConstructorType::TsFnType(n) => emit!(n), @@ -225,7 +225,7 @@ impl<'a> Emitter<'a> { #[emitter] fn emit_ts_fn_type(&mut self, n: &TsFnType) -> Result { - self.emit_leading_comments_of_pos(n.span().lo())?; + self.emit_leading_comments_of_pos(n.span().lo(), false)?; emit!(n.type_params); @@ -242,7 +242,7 @@ impl<'a> Emitter<'a> { #[emitter] fn emit_ts_import_equals_decl(&mut self, n: &TsImportEqualsDecl) -> Result { - self.emit_leading_comments_of_pos(n.span().lo())?; + self.emit_leading_comments_of_pos(n.span().lo(), false)?; if n.is_export { keyword!("export"); @@ -259,7 +259,7 @@ impl<'a> Emitter<'a> { #[emitter] fn emit_ts_index_signature(&mut self, n: &TsIndexSignature) -> Result { - self.emit_leading_comments_of_pos(n.span().lo())?; + self.emit_leading_comments_of_pos(n.span().lo(), false)?; punct!("["); self.emit_list(n.span, Some(&n.params), ListFormat::Parameters)?; @@ -274,7 +274,7 @@ impl<'a> Emitter<'a> { #[emitter] fn emit_ts_index_accessed_type(&mut self, n: &TsIndexedAccessType) -> Result { - self.emit_leading_comments_of_pos(n.span().lo())?; + self.emit_leading_comments_of_pos(n.span().lo(), false)?; emit!(n.obj_type); @@ -285,7 +285,7 @@ impl<'a> Emitter<'a> { #[emitter] fn emit_ts_infer_type(&mut self, n: &TsInferType) -> Result { - self.emit_leading_comments_of_pos(n.span().lo())?; + self.emit_leading_comments_of_pos(n.span().lo(), false)?; keyword!("infer"); space!(); @@ -294,7 +294,7 @@ impl<'a> Emitter<'a> { #[emitter] fn emit_ts_interface_body(&mut self, n: &TsInterfaceBody) -> Result { - self.emit_leading_comments_of_pos(n.span().lo())?; + self.emit_leading_comments_of_pos(n.span().lo(), false)?; punct!("{"); @@ -305,7 +305,7 @@ impl<'a> Emitter<'a> { #[emitter] fn emit_ts_interface_decl(&mut self, n: &TsInterfaceDecl) -> Result { - self.emit_leading_comments_of_pos(n.span().lo())?; + self.emit_leading_comments_of_pos(n.span().lo(), false)?; if n.declare { keyword!("declare"); @@ -338,7 +338,7 @@ impl<'a> Emitter<'a> { #[emitter] fn emit_ts_intersection_type(&mut self, n: &TsIntersectionType) -> Result { - self.emit_leading_comments_of_pos(n.span().lo())?; + self.emit_leading_comments_of_pos(n.span().lo(), false)?; self.emit_list( n.span, @@ -349,7 +349,7 @@ impl<'a> Emitter<'a> { #[emitter] fn emit_ts_keyword_type(&mut self, n: &TsKeywordType) -> Result { - self.emit_leading_comments_of_pos(n.span().lo())?; + self.emit_leading_comments_of_pos(n.span().lo(), false)?; match n.kind { TsKeywordTypeKind::TsAnyKeyword => keyword!(n.span, "any"), @@ -383,7 +383,7 @@ impl<'a> Emitter<'a> { fn emit_ts_tpl_lit(&mut self, node: &TsTplLitType) -> Result { debug_assert!(node.quasis.len() == node.types.len() + 1); - self.emit_leading_comments_of_pos(node.span().lo())?; + self.emit_leading_comments_of_pos(node.span().lo(), false)?; punct!("`"); let i = 0; @@ -403,14 +403,14 @@ impl<'a> Emitter<'a> { #[emitter] fn emit_ts_lit_type(&mut self, n: &TsLitType) -> Result { - self.emit_leading_comments_of_pos(n.span().lo())?; + self.emit_leading_comments_of_pos(n.span().lo(), false)?; emit!(n.lit); } #[emitter] fn emit_ts_mapped_type(&mut self, n: &TsMappedType) -> Result { - self.emit_leading_comments_of_pos(n.span().lo())?; + self.emit_leading_comments_of_pos(n.span().lo(), false)?; punct!("{"); self.wr.write_line()?; @@ -485,7 +485,7 @@ impl<'a> Emitter<'a> { #[emitter] fn emit_ts_method_signature(&mut self, n: &TsMethodSignature) -> Result { - self.emit_leading_comments_of_pos(n.span().lo())?; + self.emit_leading_comments_of_pos(n.span().lo(), false)?; if n.readonly { keyword!("readonly"); @@ -521,12 +521,12 @@ impl<'a> Emitter<'a> { #[emitter] fn emit_ts_module_block(&mut self, n: &TsModuleBlock) -> Result { self.emit_list(n.span, Some(&n.body), ListFormat::SourceFileStatements)?; - self.emit_leading_comments_of_pos(n.span().lo())?; + self.emit_leading_comments_of_pos(n.span().lo(), false)?; } #[emitter] fn emit_ts_module_decl(&mut self, n: &TsModuleDecl) -> Result { - self.emit_leading_comments_of_pos(n.span().lo())?; + self.emit_leading_comments_of_pos(n.span().lo(), false)?; if n.declare { keyword!("declare"); @@ -553,14 +553,14 @@ impl<'a> Emitter<'a> { #[emitter] fn emit_ts_module_ref(&mut self, n: &TsModuleRef) -> Result { - self.emit_leading_comments_of_pos(n.span().lo())?; + self.emit_leading_comments_of_pos(n.span().lo(), false)?; unimplemented!("emit_ts_module_ref") } #[emitter] fn emit_ts_ns_body(&mut self, n: &TsNamespaceBody) -> Result { - self.emit_leading_comments_of_pos(n.span().lo())?; + self.emit_leading_comments_of_pos(n.span().lo(), false)?; punct!("{"); self.wr.increase_indent()?; @@ -574,14 +574,14 @@ impl<'a> Emitter<'a> { #[emitter] fn emit_ts_ns_decl(&mut self, n: &TsNamespaceDecl) -> Result { - self.emit_leading_comments_of_pos(n.span().lo())?; + self.emit_leading_comments_of_pos(n.span().lo(), false)?; unimplemented!("emit_ts_ns_decl") } #[emitter] fn emit_ts_ns_export_decl(&mut self, n: &TsNamespaceExportDecl) -> Result { - self.emit_leading_comments_of_pos(n.span().lo())?; + self.emit_leading_comments_of_pos(n.span().lo(), false)?; keyword!("export"); space!(); @@ -592,7 +592,7 @@ impl<'a> Emitter<'a> { #[emitter] fn emit_ts_non_null_expr(&mut self, n: &TsNonNullExpr) -> Result { - self.emit_leading_comments_of_pos(n.span().lo())?; + self.emit_leading_comments_of_pos(n.span().lo(), false)?; emit!(n.expr); punct!("!") @@ -600,7 +600,7 @@ impl<'a> Emitter<'a> { #[emitter] fn emit_ts_optional_type(&mut self, n: &TsOptionalType) -> Result { - self.emit_leading_comments_of_pos(n.span().lo())?; + self.emit_leading_comments_of_pos(n.span().lo(), false)?; emit!(n.type_ann); punct!("?"); @@ -608,7 +608,7 @@ impl<'a> Emitter<'a> { #[emitter] fn emit_ts_param_prop(&mut self, n: &TsParamProp) -> Result { - self.emit_leading_comments_of_pos(n.span().lo())?; + self.emit_leading_comments_of_pos(n.span().lo(), false)?; self.emit_accesibility(n.accessibility)?; @@ -622,7 +622,7 @@ impl<'a> Emitter<'a> { #[emitter] fn emit_ts_param_prop_param(&mut self, n: &TsParamPropParam) -> Result { - self.emit_leading_comments_of_pos(n.span().lo())?; + self.emit_leading_comments_of_pos(n.span().lo(), false)?; match n { TsParamPropParam::Ident(n) => emit!(n), @@ -632,7 +632,7 @@ impl<'a> Emitter<'a> { #[emitter] fn emit_ts_paren_type(&mut self, n: &TsParenthesizedType) -> Result { - self.emit_leading_comments_of_pos(n.span().lo())?; + self.emit_leading_comments_of_pos(n.span().lo(), false)?; punct!("("); emit!(n.type_ann); @@ -641,7 +641,7 @@ impl<'a> Emitter<'a> { #[emitter] fn emit_ts_property_signature(&mut self, n: &TsPropertySignature) -> Result { - self.emit_leading_comments_of_pos(n.span().lo())?; + self.emit_leading_comments_of_pos(n.span().lo(), false)?; if n.readonly { keyword!("readonly"); @@ -682,7 +682,7 @@ impl<'a> Emitter<'a> { #[emitter] fn emit_ts_qualified_name(&mut self, n: &TsQualifiedName) -> Result { - self.emit_leading_comments_of_pos(n.span().lo())?; + self.emit_leading_comments_of_pos(n.span().lo(), false)?; emit!(n.left); punct!("."); @@ -691,7 +691,7 @@ impl<'a> Emitter<'a> { #[emitter] fn emit_ts_rest_type(&mut self, n: &TsRestType) -> Result { - self.emit_leading_comments_of_pos(n.span().lo())?; + self.emit_leading_comments_of_pos(n.span().lo(), false)?; punct!("..."); emit!(n.type_ann); @@ -699,7 +699,7 @@ impl<'a> Emitter<'a> { #[emitter] fn emit_ts_signature_decl(&mut self, n: &TsSignatureDecl) -> Result { - self.emit_leading_comments_of_pos(n.span().lo())?; + self.emit_leading_comments_of_pos(n.span().lo(), false)?; match n { TsSignatureDecl::TsCallSignatureDecl(n) => { @@ -722,14 +722,14 @@ impl<'a> Emitter<'a> { #[emitter] fn emit_ts_this_type(&mut self, n: &TsThisType) -> Result { - self.emit_leading_comments_of_pos(n.span().lo())?; + self.emit_leading_comments_of_pos(n.span().lo(), false)?; keyword!(n.span, "this"); } #[emitter] fn emit_ts_this_type_or_ident(&mut self, n: &TsThisTypeOrIdent) -> Result { - self.emit_leading_comments_of_pos(n.span().lo())?; + self.emit_leading_comments_of_pos(n.span().lo(), false)?; match n { TsThisTypeOrIdent::TsThisType(n) => emit!(n), @@ -739,7 +739,7 @@ impl<'a> Emitter<'a> { #[emitter] fn emit_ts_tuple_type(&mut self, n: &TsTupleType) -> Result { - self.emit_leading_comments_of_pos(n.span().lo())?; + self.emit_leading_comments_of_pos(n.span().lo(), false)?; punct!("["); self.emit_list(n.span, Some(&n.elem_types), ListFormat::TupleTypeElements)?; @@ -748,7 +748,7 @@ impl<'a> Emitter<'a> { #[emitter] fn emit_ts_tuple_element(&mut self, n: &TsTupleElement) -> Result { - self.emit_leading_comments_of_pos(n.span().lo())?; + self.emit_leading_comments_of_pos(n.span().lo(), false)?; if let Some(label) = &n.label { emit!(label); @@ -787,7 +787,7 @@ impl<'a> Emitter<'a> { #[emitter] fn emit_ts_import_type(&mut self, n: &TsImportType) -> Result { - self.emit_leading_comments_of_pos(n.span().lo())?; + self.emit_leading_comments_of_pos(n.span().lo(), false)?; keyword!("import"); punct!("("); @@ -808,7 +808,7 @@ impl<'a> Emitter<'a> { #[emitter] fn emit_ts_type_alias_decl(&mut self, n: &TsTypeAliasDecl) -> Result { - self.emit_leading_comments_of_pos(n.span().lo())?; + self.emit_leading_comments_of_pos(n.span().lo(), false)?; if n.declare { keyword!("declare"); @@ -836,14 +836,14 @@ impl<'a> Emitter<'a> { #[emitter] fn emit_ts_type_ann(&mut self, n: &TsTypeAnn) -> Result { - self.emit_leading_comments_of_pos(n.span().lo())?; + self.emit_leading_comments_of_pos(n.span().lo(), false)?; emit!(n.type_ann) } #[emitter] fn emit_ts_type_assertion(&mut self, n: &TsTypeAssertion) -> Result { - self.emit_leading_comments_of_pos(n.span().lo())?; + self.emit_leading_comments_of_pos(n.span().lo(), false)?; punct!("<"); emit!(n.type_ann); @@ -853,7 +853,7 @@ impl<'a> Emitter<'a> { #[emitter] fn emit_ts_const_assertion(&mut self, n: &TsConstAssertion) -> Result { - self.emit_leading_comments_of_pos(n.span().lo())?; + self.emit_leading_comments_of_pos(n.span().lo(), false)?; emit!(n.expr); @@ -913,7 +913,7 @@ impl<'a> Emitter<'a> { #[emitter] fn emit_ts_type_lit(&mut self, n: &TsTypeLit) -> Result { - self.emit_leading_comments_of_pos(n.span().lo())?; + self.emit_leading_comments_of_pos(n.span().lo(), false)?; punct!("{"); self.emit_list( @@ -926,7 +926,7 @@ impl<'a> Emitter<'a> { #[emitter] fn emit_ts_type_operator(&mut self, n: &TsTypeOperator) -> Result { - self.emit_leading_comments_of_pos(n.span().lo())?; + self.emit_leading_comments_of_pos(n.span().lo(), false)?; match n.op { TsTypeOperatorOp::KeyOf => keyword!("keyof"), @@ -939,7 +939,7 @@ impl<'a> Emitter<'a> { #[emitter] fn emit_ts_type_param(&mut self, n: &TsTypeParam) -> Result { - self.emit_leading_comments_of_pos(n.span().lo())?; + self.emit_leading_comments_of_pos(n.span().lo(), false)?; emit!(n.name); @@ -960,7 +960,7 @@ impl<'a> Emitter<'a> { #[emitter] fn emit_ts_type_param_decl(&mut self, n: &TsTypeParamDecl) -> Result { - self.emit_leading_comments_of_pos(n.span().lo())?; + self.emit_leading_comments_of_pos(n.span().lo(), false)?; punct!("<"); @@ -971,7 +971,7 @@ impl<'a> Emitter<'a> { #[emitter] fn emit_ts_type_param_instantiation(&mut self, n: &TsTypeParamInstantiation) -> Result { - self.emit_leading_comments_of_pos(n.span().lo())?; + self.emit_leading_comments_of_pos(n.span().lo(), false)?; punct!("<"); self.emit_list(n.span, Some(&n.params), ListFormat::TypeParameters)?; @@ -981,7 +981,7 @@ impl<'a> Emitter<'a> { #[emitter] fn emit_ts_type_predicate(&mut self, n: &TsTypePredicate) -> Result { - self.emit_leading_comments_of_pos(n.span().lo())?; + self.emit_leading_comments_of_pos(n.span().lo(), false)?; if n.asserts { keyword!("asserts"); @@ -1000,7 +1000,7 @@ impl<'a> Emitter<'a> { #[emitter] fn emit_ts_type_query(&mut self, n: &TsTypeQuery) -> Result { - self.emit_leading_comments_of_pos(n.span().lo())?; + self.emit_leading_comments_of_pos(n.span().lo(), false)?; keyword!("typeof"); space!(); @@ -1017,7 +1017,7 @@ impl<'a> Emitter<'a> { #[emitter] fn emit_ts_type_ref(&mut self, n: &TsTypeRef) -> Result { - self.emit_leading_comments_of_pos(n.span().lo())?; + self.emit_leading_comments_of_pos(n.span().lo(), false)?; emit!(n.type_name); @@ -1038,7 +1038,7 @@ impl<'a> Emitter<'a> { #[emitter] fn emit_ts_union_type(&mut self, n: &TsUnionType) -> Result { - self.emit_leading_comments_of_pos(n.span().lo())?; + self.emit_leading_comments_of_pos(n.span().lo(), false)?; self.emit_list(n.span, Some(&n.types), ListFormat::UnionTypeConstituents)?; } diff --git a/ecmascript/parser/Cargo.toml b/ecmascript/parser/Cargo.toml index 735011122aad..a0afd453d305 100644 --- a/ecmascript/parser/Cargo.toml +++ b/ecmascript/parser/Cargo.toml @@ -7,7 +7,7 @@ include = ["Cargo.toml", "src/**/*.rs", "examples/**/*.rs"] license = "Apache-2.0/MIT" name = "swc_ecma_parser" repository = "https://github.com/swc-project/swc.git" -version = "0.52.1" +version = "0.52.2" [features] default = [] diff --git a/ecmascript/parser/src/lexer/state.rs b/ecmascript/parser/src/lexer/state.rs index 34ff99a78f6b..1fd92187b957 100644 --- a/ecmascript/parser/src/lexer/state.rs +++ b/ecmascript/parser/src/lexer/state.rs @@ -278,13 +278,8 @@ impl<'a, I: Input> Iterator for Lexer<'a, I> { .borrow() .is_empty() { - let comment_pos = match token { - tok!('}') | tok!('`') => start + BytePos(1), - _ => start, - }; - self.comments.as_ref().unwrap().add_leading_comments( - comment_pos, + start, mem::replace( &mut *self .leading_comments_buffer diff --git a/ecmascript/parser/tests/comments.rs b/ecmascript/parser/tests/comments.rs new file mode 100644 index 000000000000..41a731a9ed32 --- /dev/null +++ b/ecmascript/parser/tests/comments.rs @@ -0,0 +1,160 @@ +use std::path::PathBuf; +use swc_common::comments::SingleThreadedComments; +use swc_common::errors::DiagnosticBuilder; +use swc_common::errors::Handler; +use swc_common::input::SourceFileInput; +use swc_common::BytePos; +use swc_common::Span; +use swc_common::DUMMY_SP; +use swc_ecma_ast::*; +use swc_ecma_parser::lexer::Lexer; +use swc_ecma_parser::EsConfig; +use swc_ecma_parser::Parser; +use swc_ecma_parser::Syntax; +use swc_ecma_parser::TsConfig; +use swc_ecma_visit::Node; +use swc_ecma_visit::Visit; +use swc_ecma_visit::VisitWith; +use testing::fixture; +use testing::Tester; + +#[fixture("comments/**/input.js")] +#[fixture("comments/**/input.ts")] +#[fixture("comments/**/input.tsx")] +fn test(input: PathBuf) { + let ext = input.extension().unwrap(); + let ext = ext.to_string_lossy(); + + let output_file = PathBuf::from(format!("{}.stderr", input.display())); + + let output = Tester::new() + .print_errors(|cm, handler| -> Result<(), _> { + // + let fm = cm.load_file(&input).unwrap(); + let syntax = match &*ext { + "js" => Syntax::Es(EsConfig { + jsx: false, + num_sep: true, + class_private_props: true, + class_private_methods: true, + class_props: true, + fn_bind: false, + decorators: true, + decorators_before_export: false, + export_default_from: true, + export_namespace_from: true, + dynamic_import: true, + nullish_coalescing: true, + optional_chaining: true, + import_meta: true, + top_level_await: true, + import_assertions: true, + }), + "ts" | "tsx" => Syntax::Typescript(TsConfig { + tsx: ext == "tsx", + decorators: true, + dynamic_import: true, + no_early_errors: true, + import_assertions: true, + ..Default::default() + }), + _ => { + unreachable!() + } + }; + + let comments = SingleThreadedComments::default(); + + let lexer = Lexer::new( + syntax, + EsVersion::latest(), + SourceFileInput::from(&*fm), + Some(&comments), + ); + let mut parser = Parser::new_from(lexer); + + let module = parser.parse_module(); + let module = match module { + Ok(v) => v, + Err(err) => { + panic!("{:?}", err) + } + }; + + module.visit_with( + &Invalid { span: DUMMY_SP }, + &mut CommentPrinter { + handler: &handler, + comments, + }, + ); + + Err(()) + }) + .unwrap_err(); + if output.trim().is_empty() { + panic!("Comments have incorrect position") + } + + output.compare_to_file(&output_file).unwrap(); +} + +struct CommentPrinter<'a> { + handler: &'a Handler, + comments: SingleThreadedComments, +} + +impl Visit for CommentPrinter<'_> { + fn visit_span(&mut self, n: &Span, _: &dyn Node) { + self.comments.with_leading(n.lo, |comments| { + for c in comments { + DiagnosticBuilder::new( + &self.handler, + swc_common::errors::Level::Note, + "Leading (lo)", + ) + .span_note(Span::new(n.lo, n.lo, Default::default()), &c.text) + .emit(); + } + }); + + self.comments.with_trailing(n.lo, |comments| { + for c in comments { + DiagnosticBuilder::new( + &self.handler, + swc_common::errors::Level::Note, + "Trailing (lo)", + ) + .span_note(Span::new(n.lo, n.lo, Default::default()), &c.text) + .emit(); + } + }); + + self.comments.with_leading(n.hi - BytePos(1), |comments| { + for c in comments { + DiagnosticBuilder::new( + &self.handler, + swc_common::errors::Level::Note, + "Leading (hi)", + ) + .span_note( + Span::new(n.hi - BytePos(1), n.hi - BytePos(1), Default::default()), + &c.text, + ) + .emit(); + } + }); + + self.comments.with_trailing(n.hi, |comments| { + for c in comments { + DiagnosticBuilder::new( + &self.handler, + swc_common::errors::Level::Note, + "Trailing (hi)", + ) + .span_note(Span::new(n.hi, n.hi, Default::default()), &c.text) + .emit(); + } + }); + } +} diff --git a/ecmascript/parser/tests/comments/exprs/array/blockStmt/input.js b/ecmascript/parser/tests/comments/exprs/array/blockStmt/input.js new file mode 100644 index 000000000000..cb7f7240033c --- /dev/null +++ b/ecmascript/parser/tests/comments/exprs/array/blockStmt/input.js @@ -0,0 +1,3 @@ +React.useEffect(() => { + // @refresh reset +}); \ No newline at end of file diff --git a/ecmascript/parser/tests/comments/exprs/array/blockStmt/input.js.stderr b/ecmascript/parser/tests/comments/exprs/array/blockStmt/input.js.stderr new file mode 100644 index 000000000000..63d66befd04f --- /dev/null +++ b/ecmascript/parser/tests/comments/exprs/array/blockStmt/input.js.stderr @@ -0,0 +1,8 @@ +note: Leading (hi) + | +note: @refresh reset + --> $DIR/tests/comments/exprs/array/blockStmt/input.js:3:1 + | +3 | }); + | ^ + diff --git a/ecmascript/parser/tests/comments/exprs/call/simple/input.js b/ecmascript/parser/tests/comments/exprs/call/simple/input.js new file mode 100644 index 000000000000..155fbc792194 --- /dev/null +++ b/ecmascript/parser/tests/comments/exprs/call/simple/input.js @@ -0,0 +1 @@ +test(123/*post: 9*/, 456/*post: 10*/); diff --git a/ecmascript/parser/tests/comments/exprs/call/simple/input.js.stderr b/ecmascript/parser/tests/comments/exprs/call/simple/input.js.stderr new file mode 100644 index 000000000000..753305986b7d --- /dev/null +++ b/ecmascript/parser/tests/comments/exprs/call/simple/input.js.stderr @@ -0,0 +1,16 @@ +note: Trailing (hi) + | +note: post: 9 + --> $DIR/tests/comments/exprs/call/simple/input.js:1:9 + | +1 | test(123/*post: 9*/, 456/*post: 10*/); + | ^ + +note: Trailing (hi) + | +note: post: 10 + --> $DIR/tests/comments/exprs/call/simple/input.js:1:25 + | +1 | test(123/*post: 9*/, 456/*post: 10*/); + | ^ + diff --git a/ecmascript/parser/tests/comments/stmts/block/input.js b/ecmascript/parser/tests/comments/stmts/block/input.js new file mode 100644 index 000000000000..3f4890200f3e --- /dev/null +++ b/ecmascript/parser/tests/comments/stmts/block/input.js @@ -0,0 +1,3 @@ +while (1) { + /* test */ +} \ No newline at end of file diff --git a/ecmascript/parser/tests/comments/stmts/block/input.js.stderr b/ecmascript/parser/tests/comments/stmts/block/input.js.stderr new file mode 100644 index 000000000000..f6c28b5b2cd1 --- /dev/null +++ b/ecmascript/parser/tests/comments/stmts/block/input.js.stderr @@ -0,0 +1,8 @@ +note: Leading (hi) + | +note: test + --> $DIR/tests/comments/stmts/block/input.js:3:1 + | +3 | } + | ^ + diff --git a/ecmascript/parser/tests/comments/stmts/switch/input.js b/ecmascript/parser/tests/comments/stmts/switch/input.js new file mode 100644 index 000000000000..d580a2e0d675 --- /dev/null +++ b/ecmascript/parser/tests/comments/stmts/switch/input.js @@ -0,0 +1,5 @@ +switch (1) { + case 2: + 3; + // 4 +} \ No newline at end of file diff --git a/ecmascript/parser/tests/comments/stmts/switch/input.js.stderr b/ecmascript/parser/tests/comments/stmts/switch/input.js.stderr new file mode 100644 index 000000000000..ecd2eb169f4a --- /dev/null +++ b/ecmascript/parser/tests/comments/stmts/switch/input.js.stderr @@ -0,0 +1,8 @@ +note: Leading (hi) + | +note: 4 + --> $DIR/tests/comments/stmts/switch/input.js:5:1 + | +5 | } + | ^ + diff --git a/ecmascript/parser/tests/span/js/expr/arrow-2.js b/ecmascript/parser/tests/span/js/expr/arrow-2.js new file mode 100644 index 000000000000..cb7f7240033c --- /dev/null +++ b/ecmascript/parser/tests/span/js/expr/arrow-2.js @@ -0,0 +1,3 @@ +React.useEffect(() => { + // @refresh reset +}); \ No newline at end of file diff --git a/ecmascript/parser/tests/span/js/expr/arrow-2.js.spans b/ecmascript/parser/tests/span/js/expr/arrow-2.js.spans new file mode 100644 index 000000000000..29f3d66149a2 --- /dev/null +++ b/ecmascript/parser/tests/span/js/expr/arrow-2.js.spans @@ -0,0 +1,141 @@ +warning: Module + --> $DIR/tests/span/js/expr/arrow-2.js:1:1 + | +1 | / React.useEffect(() => { +2 | | // @refresh reset +3 | | }); + | |___^ + +warning: ModuleItem + --> $DIR/tests/span/js/expr/arrow-2.js:1:1 + | +1 | / React.useEffect(() => { +2 | | // @refresh reset +3 | | }); + | |___^ + +warning: Stmt + --> $DIR/tests/span/js/expr/arrow-2.js:1:1 + | +1 | / React.useEffect(() => { +2 | | // @refresh reset +3 | | }); + | |___^ + +warning: ExprStmt + --> $DIR/tests/span/js/expr/arrow-2.js:1:1 + | +1 | / React.useEffect(() => { +2 | | // @refresh reset +3 | | }); + | |___^ + +warning: Expr + --> $DIR/tests/span/js/expr/arrow-2.js:1:1 + | +1 | / React.useEffect(() => { +2 | | // @refresh reset +3 | | }); + | |__^ + +warning: CallExpr + --> $DIR/tests/span/js/expr/arrow-2.js:1:1 + | +1 | / React.useEffect(() => { +2 | | // @refresh reset +3 | | }); + | |__^ + +warning: ExprOrSuper + --> $DIR/tests/span/js/expr/arrow-2.js:1:1 + | +1 | React.useEffect(() => { + | ^^^^^^^^^^^^^^^ + +warning: Expr + --> $DIR/tests/span/js/expr/arrow-2.js:1:1 + | +1 | React.useEffect(() => { + | ^^^^^^^^^^^^^^^ + +warning: MemberExpr + --> $DIR/tests/span/js/expr/arrow-2.js:1:1 + | +1 | React.useEffect(() => { + | ^^^^^^^^^^^^^^^ + +warning: ExprOrSuper + --> $DIR/tests/span/js/expr/arrow-2.js:1:1 + | +1 | React.useEffect(() => { + | ^^^^^ + +warning: Expr + --> $DIR/tests/span/js/expr/arrow-2.js:1:1 + | +1 | React.useEffect(() => { + | ^^^^^ + +warning: Ident + --> $DIR/tests/span/js/expr/arrow-2.js:1:1 + | +1 | React.useEffect(() => { + | ^^^^^ + +warning: Expr + --> $DIR/tests/span/js/expr/arrow-2.js:1:7 + | +1 | React.useEffect(() => { + | ^^^^^^^^^ + +warning: Ident + --> $DIR/tests/span/js/expr/arrow-2.js:1:7 + | +1 | React.useEffect(() => { + | ^^^^^^^^^ + +warning: ExprOrSpread + --> $DIR/tests/span/js/expr/arrow-2.js:1:17 + | +1 | React.useEffect(() => { + | _________________^ +2 | | // @refresh reset +3 | | }); + | |_^ + +warning: Expr + --> $DIR/tests/span/js/expr/arrow-2.js:1:17 + | +1 | React.useEffect(() => { + | _________________^ +2 | | // @refresh reset +3 | | }); + | |_^ + +warning: ArrowExpr + --> $DIR/tests/span/js/expr/arrow-2.js:1:17 + | +1 | React.useEffect(() => { + | _________________^ +2 | | // @refresh reset +3 | | }); + | |_^ + +warning: BlockStmtOrExpr + --> $DIR/tests/span/js/expr/arrow-2.js:1:23 + | +1 | React.useEffect(() => { + | _______________________^ +2 | | // @refresh reset +3 | | }); + | |_^ + +warning: BlockStmt + --> $DIR/tests/span/js/expr/arrow-2.js:1:23 + | +1 | React.useEffect(() => { + | _______________________^ +2 | | // @refresh reset +3 | | }); + | |_^ + diff --git a/ecmascript/transforms/compat/src/es2015/destructuring.rs b/ecmascript/transforms/compat/src/es2015/destructuring.rs index 831f9d02378f..8b47b9ce4803 100644 --- a/ecmascript/transforms/compat/src/es2015/destructuring.rs +++ b/ecmascript/transforms/compat/src/es2015/destructuring.rs @@ -807,7 +807,30 @@ impl Fold for AssignFolder { exprs, }) } - Pat::Assign(pat) => unimplemented!("assignment pattern {:?}", pat), + Pat::Assign(pat) => { + let ref_ident = make_ref_ident(self.c, &mut self.vars, None); + + let mut exprs = vec![]; + + exprs.push(Box::new(Expr::Assign(AssignExpr { + span, + left: PatOrExpr::Pat(Box::new(Pat::Ident(ref_ident.clone().into()))), + op: op!("="), + right: pat.right, + }))); + + exprs.push(Box::new(Expr::Assign(AssignExpr { + span, + left: PatOrExpr::Pat(pat.left), + op: op!("="), + right: Box::new(Expr::Ident(ref_ident)), + }))); + + Expr::Seq(SeqExpr { + span: DUMMY_SP, + exprs, + }) + } Pat::Rest(pat) => unimplemented!("rest pattern {:?}", pat), Pat::Invalid(..) => unreachable!(), diff --git a/ecmascript/transforms/compat/src/es2017/async_to_generator.rs b/ecmascript/transforms/compat/src/es2017/async_to_generator.rs index df71ed0bf1cf..0d8f4038c1ed 100644 --- a/ecmascript/transforms/compat/src/es2017/async_to_generator.rs +++ b/ecmascript/transforms/compat/src/es2017/async_to_generator.rs @@ -42,6 +42,7 @@ pub fn async_to_generator() -> impl Fold { struct AsyncToGenerator; struct Actual { + in_object_prop: bool, extra_stmts: Vec, } @@ -70,6 +71,7 @@ impl AsyncToGenerator { for stmt in stmts { let mut actual = Actual { + in_object_prop: false, extra_stmts: vec![], }; let stmt = stmt.fold_with(&mut actual); @@ -98,10 +100,13 @@ impl Fold for Actual { let mut folder = MethodFolder { vars: vec![] }; m.function.params.clear(); let function = m.function.fold_children_with(&mut folder); - let expr = make_fn_ref(FnExpr { - ident: None, - function, - }); + let expr = make_fn_ref( + FnExpr { + ident: None, + function, + }, + self.in_object_prop, + ); let hoisted_super = if folder.vars.is_empty() { None @@ -259,12 +264,12 @@ impl Fold for Actual { }; if !used_this { - return make_fn_ref(fn_expr); + return make_fn_ref(fn_expr, false); } return Expr::Call(CallExpr { span, - callee: make_fn_ref(fn_expr) + callee: make_fn_ref(fn_expr, false) .make_member(quote_ident!("bind")) .as_callee(), args: vec![ThisExpr { span: DUMMY_SP }.as_arg()], @@ -324,6 +329,18 @@ impl Fold for Actual { declare: false, } } + + fn fold_prop(&mut self, n: Prop) -> Prop { + let old = self.in_object_prop; + self.in_object_prop = true; + + let n = n.fold_children_with(self); + + self.in_object_prop = old; + + n + } + fn fold_method_prop(&mut self, prop: MethodProp) -> MethodProp { let prop = prop.fold_children_with(self); @@ -332,13 +349,16 @@ impl Fold for Actual { } let params = prop.function.params; - let fn_ref = make_fn_ref(FnExpr { - ident: None, - function: Function { - params: vec![], - ..prop.function + let fn_ref = make_fn_ref( + FnExpr { + ident: None, + function: Function { + params: vec![], + ..prop.function + }, }, - }); + true, + ); let fn_ref = Expr::Call(CallExpr { span: DUMMY_SP, callee: fn_ref.as_callee(), @@ -660,7 +680,7 @@ impl Actual { .fold_children_with(self); } - return make_fn_ref(callee); + return make_fn_ref(callee, self.in_object_prop); } fn fold_fn(&mut self, raw_ident: Option, f: Function, is_decl: bool) -> Function { if f.body.is_none() { @@ -693,10 +713,13 @@ impl Actual { let ident = raw_ident.clone().unwrap_or_else(|| quote_ident!("ref")); let real_fn_ident = private_ident!(ident.span, format!("_{}", ident.sym)); - let right = make_fn_ref(FnExpr { - ident: None, - function: f, - }); + let right = make_fn_ref( + FnExpr { + ident: None, + function: f, + }, + self.in_object_prop, + ); if is_decl { let real_fn = FnDecl { @@ -817,7 +840,7 @@ impl Actual { /// Creates /// /// `_asyncToGenerator(function*() {})` from `async function() {}`; -fn make_fn_ref(mut expr: FnExpr) -> Expr { +fn make_fn_ref(mut expr: FnExpr, should_not_bind_this: bool) -> Expr { struct AwaitToYield; macro_rules! noop { @@ -859,8 +882,8 @@ fn make_fn_ref(mut expr: FnExpr) -> Expr { let span = expr.span(); - let contains_this = contains_this_expr(&expr.function.body); - let expr = if contains_this { + let should_bind_this = !should_not_bind_this && contains_this_expr(&expr.function.body); + let expr = if should_bind_this { Expr::Call(CallExpr { span: DUMMY_SP, callee: expr.make_member(quote_ident!("bind")).as_callee(), diff --git a/ecmascript/transforms/compat/tests/es2015_destructuring.rs b/ecmascript/transforms/compat/tests/es2015_destructuring.rs index eedca6fbf510..3f4e5e084293 100644 --- a/ecmascript/transforms/compat/tests/es2015_destructuring.rs +++ b/ecmascript/transforms/compat/tests/es2015_destructuring.rs @@ -1488,3 +1488,56 @@ test!( "var ref; foo((ref = [1, 2], a = ref[0], b = ref[1], ref));" ); + +test!( + syntax(), + |_| tr(), + issue_1477_1, + " + const [ { a: a_ = 1 } ] = b + ", + " + const ref = b[0], tmp = ref.a, a_ = tmp === void 0 ? 1 : tmp; + " +); + +test!( + syntax(), + |_| tr(), + issue_1477_2, + " + async function f(a, b) { + const [ { a: a_ = 1 } ] = JSON.parse(b) + } + ", + " + async function f(a, b) { + const ref = JSON.parse(b), ref1 = ref[0], tmp = ref1.a, a_ = tmp === void 0 ? 1 : tmp; + } + " +); + +test!( + syntax(), + |_| tr(), + issue_1477_3, + " + const [ a = 1 ] = b + ", + " + const tmp = b[0], a = tmp === void 0 ? 1 : tmp; + " +); + +test!( + syntax(), + |_| tr(), + issue_1477_4, + " + [ a = 1 ] = b + ", + " + var ref, ref1; + ref = b, ref1 = ref[0], a = ref1 === void 0 ? 1 : ref1, ref; + " +); diff --git a/ecmascript/transforms/compat/tests/es2017_async_to_generator.rs b/ecmascript/transforms/compat/tests/es2017_async_to_generator.rs index d3a5f105929c..58bbb038c216 100644 --- a/ecmascript/transforms/compat/tests/es2017_async_to_generator.rs +++ b/ecmascript/transforms/compat/tests/es2017_async_to_generator.rs @@ -2334,3 +2334,46 @@ test_exec!( expect(a.foo()).resolves.toEqual('a1') " ); + +test!( + Syntax::default(), + |_| async_to_generator(), + issue_1455_1, + " + const obj = { + find({ platform }) { + return { platform } + }, + byPlatform: async function (platform) { + const result = await this.find({ platform: { $eq: platform } }); + return result; + }, + }; + + obj.byPlatform('foo').then(v => console.log(v)) + ", + " + const obj = { + find ({ platform }) { + return { + platform + }; + }, + byPlatform: function(platform) { + var _ref = _asyncToGenerator(function*(platform) { + const result = yield this.find({ + platform: { + $eq: platform + } + }); + return result; + }); + return function() { + return _ref.apply(this, arguments); + }; + }() + }; + obj.byPlatform('foo').then((v)=>console.log(v) + ); + " +); diff --git a/ecmascript/transforms/react/Cargo.toml b/ecmascript/transforms/react/Cargo.toml index 6893d67cc55c..083f44a5de0a 100644 --- a/ecmascript/transforms/react/Cargo.toml +++ b/ecmascript/transforms/react/Cargo.toml @@ -7,7 +7,7 @@ include = ["Cargo.toml", "src/**/*.rs"] license = "Apache-2.0/MIT" name = "swc_ecma_transforms_react" repository = "https://github.com/swc-project/swc.git" -version = "0.12.0" +version = "0.12.1" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] diff --git a/ecmascript/transforms/react/src/refresh/mod.rs b/ecmascript/transforms/react/src/refresh/mod.rs index ec66d1986221..8402d6cdf51a 100644 --- a/ecmascript/transforms/react/src/refresh/mod.rs +++ b/ecmascript/transforms/react/src/refresh/mod.rs @@ -6,6 +6,7 @@ use once_cell::sync::Lazy; use regex::Regex; use swc_atoms::JsWord; +use swc_common::BytePos; use swc_common::{ comments::Comments, comments::CommentsExt, sync::Lrc, SourceMap, Span, Spanned, DUMMY_SP, }; @@ -486,11 +487,13 @@ where let mut should_refresh = self.should_refresh; if let Some(comments) = &self.comments { - comments.with_leading(n.hi, |comments| { - if comments.iter().any(|c| c.text.contains("@refresh reset")) { - should_refresh = true - } - }); + if n.hi != BytePos(0) { + comments.with_leading(n.hi - BytePos(1), |comments| { + if comments.iter().any(|c| c.text.contains("@refresh reset")) { + should_refresh = true + } + }); + } comments.with_trailing(n.lo, |comments| { if comments.iter().any(|c| c.text.contains("@refresh reset")) { @@ -673,7 +676,7 @@ impl Fold for Refresh { Expr::Arrow(func) } } - Expr::Call(mut call) => Expr::Call(call), + Expr::Call(call) => Expr::Call(call), _ => n, } } diff --git a/ecmascript/transforms/typescript/Cargo.toml b/ecmascript/transforms/typescript/Cargo.toml index e30b6e812780..1bf95ff9009b 100644 --- a/ecmascript/transforms/typescript/Cargo.toml +++ b/ecmascript/transforms/typescript/Cargo.toml @@ -6,7 +6,7 @@ edition = "2018" license = "Apache-2.0/MIT" name = "swc_ecma_transforms_typescript" repository = "https://github.com/swc-project/swc.git" -version = "0.12.0" +version = "0.12.1" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] diff --git a/ecmascript/transforms/typescript/src/strip.rs b/ecmascript/transforms/typescript/src/strip.rs index 73cc2d1f5e8b..c67488628109 100644 --- a/ecmascript/transforms/typescript/src/strip.rs +++ b/ecmascript/transforms/typescript/src/strip.rs @@ -7,6 +7,7 @@ use swc_common::{util::move_map::MoveMap, Span, Spanned, SyntaxContext, DUMMY_SP use swc_ecma_ast::*; use swc_ecma_transforms_base::ext::MapWithMut; use swc_ecma_utils::private_ident; +use swc_ecma_utils::quote_ident; use swc_ecma_utils::var::VarCollector; use swc_ecma_utils::ExprFactory; use swc_ecma_utils::{constructor::inject_after_super, default_constructor}; @@ -1660,6 +1661,33 @@ impl VisitMut for Strip { continue } + ModuleItem::ModuleDecl(ModuleDecl::TsImportEquals(TsImportEqualsDecl { + span, + declare: false, + is_export: false, + id, + module_ref: + TsModuleRef::TsExternalModuleRef(TsExternalModuleRef { span: _, expr }), + })) => { + let default = VarDeclarator { + span: DUMMY_SP, + name: Pat::Ident(id.into()), + init: Some(Box::new(Expr::Call(CallExpr { + span: DUMMY_SP, + callee: quote_ident!("require").as_callee(), + args: vec![expr.as_arg()], + type_args: None, + }))), + definite: false, + }; + stmts.push(ModuleItem::Stmt(Stmt::Decl(Decl::Var(VarDecl { + span, + kind: VarDeclKind::Const, + declare: false, + decls: vec![default], + })))) + } + // Always strip type only import / exports ModuleItem::Stmt(Stmt::Empty(..)) | ModuleItem::ModuleDecl(ModuleDecl::Import(ImportDecl { diff --git a/ecmascript/transforms/typescript/tests/strip.rs b/ecmascript/transforms/typescript/tests/strip.rs index 7befdc3944ce..8705f57eb016 100644 --- a/ecmascript/transforms/typescript/tests/strip.rs +++ b/ecmascript/transforms/typescript/tests/strip.rs @@ -3880,3 +3880,15 @@ to!( import { Test } from 'test'; " ); + +to!( + issue_1448_1, + " + import F = require('yaml') + console.log(F) + ", + " + const F = require('yaml'); + console.log(F) + " +); diff --git a/tests/fixture/codegen/escape/case-1/output/index.js b/tests/fixture/codegen/escape/case-1/output/index.js index ca06baba5421..fef6ecaf3659 100644 --- a/tests/fixture/codegen/escape/case-1/output/index.js +++ b/tests/fixture/codegen/escape/case-1/output/index.js @@ -3,5 +3,5 @@ Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; -var _default = /* glsl */ "\nvoid main() {\n\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}\n"; +var _default = "\nvoid main() {\n\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}\n"; exports.default = _default; diff --git a/tests/fixture/codegen/escape/case-2/output/index.js b/tests/fixture/codegen/escape/case-2/output/index.js index d25d5cd76d8b..8eea8c77f35c 100644 --- a/tests/fixture/codegen/escape/case-2/output/index.js +++ b/tests/fixture/codegen/escape/case-2/output/index.js @@ -3,5 +3,5 @@ Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; -var _default = /* glsl */ "\n// Analytical approximation of the DFG LUT, one half of the\n// split-sum approximation used in indirect specular lighting.\n// via 'environmentBRDF' from \"Physically Based Shading on Mobile\"\n// https://www.unrealengine.com/blog/physically-based-shading-on-mobile - environmentBRDF for GGX on mobile\nvec2 integrateSpecularBRDF( const in float dotNV, const in float roughness ) {\n\tconst vec4 c0 = vec4( - 1, - 0.0275, - 0.572, 0.022 );\n\tconst vec4 c1 = vec4( 1, 0.0425, 1.04, - 0.04 );\n\tvec4 r = roughness * c0 + c1;\n\tfloat a004 = min( r.x * r.x, exp2( - 9.28 * dotNV ) ) * r.x + r.y;\n\treturn vec2( -1.04, 1.04 ) * a004 + r.zw;\n}\nfloat punctualLightIntensityToIrradianceFactor( const in float lightDistance, const in float cutoffDistance, const in float decayExponent ) {\n#if defined ( PHYSICALLY_CORRECT_LIGHTS )\n\t// based upon Frostbite 3 Moving to Physically-based Rendering\n\t// page 32, equation 26: E[window1]\n\t// https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf\n\t// this is intended to be used on spot and point lights who are represented as luminous intensity\n\t// but who must be converted to luminous irradiance for surface lighting calculation\n\tfloat distanceFalloff = 1.0 / max( pow( lightDistance, decayExponent ), 0.01 );\n\tif( cutoffDistance > 0.0 ) {\n\t\tdistanceFalloff *= pow2( saturate( 1.0 - pow4( lightDistance / cutoffDistance ) ) );\n\t}\n\treturn distanceFalloff;\n#else\n\tif( cutoffDistance > 0.0 && decayExponent > 0.0 ) {\n\t\treturn pow( saturate( -lightDistance / cutoffDistance + 1.0 ), decayExponent );\n\t}\n\treturn 1.0;\n#endif\n}\nvec3 BRDF_Diffuse_Lambert( const in vec3 diffuseColor ) {\n\treturn RECIPROCAL_PI * diffuseColor;\n} // validated\nvec3 F_Schlick( const in vec3 specularColor, const in float dotLH ) {\n\t// Original approximation by Christophe Schlick '94\n\t// float fresnel = pow( 1.0 - dotLH, 5.0 );\n\t// Optimized variant (presented by Epic at SIGGRAPH '13)\n\t// https://cdn2.unrealengine.com/Resources/files/2013SiggraphPresentationsNotes-26915738.pdf\n\tfloat fresnel = exp2( ( -5.55473 * dotLH - 6.98316 ) * dotLH );\n\treturn ( 1.0 - specularColor ) * fresnel + specularColor;\n} // validated\nvec3 F_Schlick_RoughnessDependent( const in vec3 F0, const in float dotNV, const in float roughness ) {\n\t// See F_Schlick\n\tfloat fresnel = exp2( ( -5.55473 * dotNV - 6.98316 ) * dotNV );\n\tvec3 Fr = max( vec3( 1.0 - roughness ), F0 ) - F0;\n\treturn Fr * fresnel + F0;\n}\n// Microfacet Models for Refraction through Rough Surfaces - equation (34)\n// http://graphicrants.blogspot.com/2013/08/specular-brdf-reference.html\n// alpha is \"roughness squared\" in Disney\u2019s reparameterization\nfloat G_GGX_Smith( const in float alpha, const in float dotNL, const in float dotNV ) {\n\t// geometry term (normalized) = G(l)\u22c5G(v) / 4(n\u22c5l)(n\u22c5v)\n\t// also see #12151\n\tfloat a2 = pow2( alpha );\n\tfloat gl = dotNL + sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNL ) );\n\tfloat gv = dotNV + sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNV ) );\n\treturn 1.0 / ( gl * gv );\n} // validated\n// Moving Frostbite to Physically Based Rendering 3.0 - page 12, listing 2\n// https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf\nfloat G_GGX_SmithCorrelated( const in float alpha, const in float dotNL, const in float dotNV ) {\n\tfloat a2 = pow2( alpha );\n\t// dotNL and dotNV are explicitly swapped. This is not a mistake.\n\tfloat gv = dotNL * sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNV ) );\n\tfloat gl = dotNV * sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNL ) );\n\treturn 0.5 / max( gv + gl, EPSILON );\n}\n// Microfacet Models for Refraction through Rough Surfaces - equation (33)\n// http://graphicrants.blogspot.com/2013/08/specular-brdf-reference.html\n// alpha is \"roughness squared\" in Disney\u2019s reparameterization\nfloat D_GGX( const in float alpha, const in float dotNH ) {\n\tfloat a2 = pow2( alpha );\n\tfloat denom = pow2( dotNH ) * ( a2 - 1.0 ) + 1.0; // avoid alpha = 0 with dotNH = 1\n\treturn RECIPROCAL_PI * a2 / pow2( denom );\n}\n// GGX Distribution, Schlick Fresnel, GGX-Smith Visibility\nvec3 BRDF_Specular_GGX( const in IncidentLight incidentLight, const in vec3 viewDir, const in vec3 normal, const in vec3 specularColor, const in float roughness ) {\n\tfloat alpha = pow2( roughness ); // UE4's roughness\n\tvec3 halfDir = normalize( incidentLight.direction + viewDir );\n\tfloat dotNL = saturate( dot( normal, incidentLight.direction ) );\n\tfloat dotNV = saturate( dot( normal, viewDir ) );\n\tfloat dotNH = saturate( dot( normal, halfDir ) );\n\tfloat dotLH = saturate( dot( incidentLight.direction, halfDir ) );\n\tvec3 F = F_Schlick( specularColor, dotLH );\n\tfloat G = G_GGX_SmithCorrelated( alpha, dotNL, dotNV );\n\tfloat D = D_GGX( alpha, dotNH );\n\treturn F * ( G * D );\n} // validated\n// Rect Area Light\n// Real-Time Polygonal-Light Shading with Linearly Transformed Cosines\n// by Eric Heitz, Jonathan Dupuy, Stephen Hill and David Neubelt\n// code: https://github.com/selfshadow/ltc_code/\nvec2 LTC_Uv( const in vec3 N, const in vec3 V, const in float roughness ) {\n\tconst float LUT_SIZE = 64.0;\n\tconst float LUT_SCALE = ( LUT_SIZE - 1.0 ) / LUT_SIZE;\n\tconst float LUT_BIAS = 0.5 / LUT_SIZE;\n\tfloat dotNV = saturate( dot( N, V ) );\n\t// texture parameterized by sqrt( GGX alpha ) and sqrt( 1 - cos( theta ) )\n\tvec2 uv = vec2( roughness, sqrt( 1.0 - dotNV ) );\n\tuv = uv * LUT_SCALE + LUT_BIAS;\n\treturn uv;\n}\nfloat LTC_ClippedSphereFormFactor( const in vec3 f ) {\n\t// Real-Time Area Lighting: a Journey from Research to Production (p.102)\n\t// An approximation of the form factor of a horizon-clipped rectangle.\n\tfloat l = length( f );\n\treturn max( ( l * l + f.z ) / ( l + 1.0 ), 0.0 );\n}\nvec3 LTC_EdgeVectorFormFactor( const in vec3 v1, const in vec3 v2 ) {\n\tfloat x = dot( v1, v2 );\n\tfloat y = abs( x );\n\t// rational polynomial approximation to theta / sin( theta ) / 2PI\n\tfloat a = 0.8543985 + ( 0.4965155 + 0.0145206 * y ) * y;\n\tfloat b = 3.4175940 + ( 4.1616724 + y ) * y;\n\tfloat v = a / b;\n\tfloat theta_sintheta = ( x > 0.0 ) ? v : 0.5 * inversesqrt( max( 1.0 - x * x, 1e-7 ) ) - v;\n\treturn cross( v1, v2 ) * theta_sintheta;\n}\nvec3 LTC_Evaluate( const in vec3 N, const in vec3 V, const in vec3 P, const in mat3 mInv, const in vec3 rectCoords[ 4 ] ) {\n\t// bail if point is on back side of plane of light\n\t// assumes ccw winding order of light vertices\n\tvec3 v1 = rectCoords[ 1 ] - rectCoords[ 0 ];\n\tvec3 v2 = rectCoords[ 3 ] - rectCoords[ 0 ];\n\tvec3 lightNormal = cross( v1, v2 );\n\tif( dot( lightNormal, P - rectCoords[ 0 ] ) < 0.0 ) return vec3( 0.0 );\n\t// construct orthonormal basis around N\n\tvec3 T1, T2;\n\tT1 = normalize( V - N * dot( V, N ) );\n\tT2 = - cross( N, T1 ); // negated from paper; possibly due to a different handedness of world coordinate system\n\t// compute transform\n\tmat3 mat = mInv * transposeMat3( mat3( T1, T2, N ) );\n\t// transform rect\n\tvec3 coords[ 4 ];\n\tcoords[ 0 ] = mat * ( rectCoords[ 0 ] - P );\n\tcoords[ 1 ] = mat * ( rectCoords[ 1 ] - P );\n\tcoords[ 2 ] = mat * ( rectCoords[ 2 ] - P );\n\tcoords[ 3 ] = mat * ( rectCoords[ 3 ] - P );\n\t// project rect onto sphere\n\tcoords[ 0 ] = normalize( coords[ 0 ] );\n\tcoords[ 1 ] = normalize( coords[ 1 ] );\n\tcoords[ 2 ] = normalize( coords[ 2 ] );\n\tcoords[ 3 ] = normalize( coords[ 3 ] );\n\t// calculate vector form factor\n\tvec3 vectorFormFactor = vec3( 0.0 );\n\tvectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 0 ], coords[ 1 ] );\n\tvectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 1 ], coords[ 2 ] );\n\tvectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 2 ], coords[ 3 ] );\n\tvectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 3 ], coords[ 0 ] );\n\t// adjust for horizon clipping\n\tfloat result = LTC_ClippedSphereFormFactor( vectorFormFactor );\n/*\n\t// alternate method of adjusting for horizon clipping (see referece)\n\t// refactoring required\n\tfloat len = length( vectorFormFactor );\n\tfloat z = vectorFormFactor.z / len;\n\tconst float LUT_SIZE = 64.0;\n\tconst float LUT_SCALE = ( LUT_SIZE - 1.0 ) / LUT_SIZE;\n\tconst float LUT_BIAS = 0.5 / LUT_SIZE;\n\t// tabulated horizon-clipped sphere, apparently...\n\tvec2 uv = vec2( z * 0.5 + 0.5, len );\n\tuv = uv * LUT_SCALE + LUT_BIAS;\n\tfloat scale = texture2D( ltc_2, uv ).w;\n\tfloat result = len * scale;\n*/\n\treturn vec3( result );\n}\n// End Rect Area Light\n// ref: https://www.unrealengine.com/blog/physically-based-shading-on-mobile - environmentBRDF for GGX on mobile\nvec3 BRDF_Specular_GGX_Environment( const in vec3 viewDir, const in vec3 normal, const in vec3 specularColor, const in float roughness ) {\n\tfloat dotNV = saturate( dot( normal, viewDir ) );\n\tvec2 brdf = integrateSpecularBRDF( dotNV, roughness );\n\treturn specularColor * brdf.x + brdf.y;\n} // validated\n// Fdez-Ag\xfcera's \"Multiple-Scattering Microfacet Model for Real-Time Image Based Lighting\"\n// Approximates multiscattering in order to preserve energy.\n// http://www.jcgt.org/published/0008/01/03/\nvoid BRDF_Specular_Multiscattering_Environment( const in GeometricContext geometry, const in vec3 specularColor, const in float roughness, inout vec3 singleScatter, inout vec3 multiScatter ) {\n\tfloat dotNV = saturate( dot( geometry.normal, geometry.viewDir ) );\n\tvec3 F = F_Schlick_RoughnessDependent( specularColor, dotNV, roughness );\n\tvec2 brdf = integrateSpecularBRDF( dotNV, roughness );\n\tvec3 FssEss = F * brdf.x + brdf.y;\n\tfloat Ess = brdf.x + brdf.y;\n\tfloat Ems = 1.0 - Ess;\n\tvec3 Favg = specularColor + ( 1.0 - specularColor ) * 0.047619; // 1/21\n\tvec3 Fms = FssEss * Favg / ( 1.0 - Ems * Favg );\n\tsingleScatter += FssEss;\n\tmultiScatter += Fms * Ems;\n}\nfloat G_BlinnPhong_Implicit( /* const in float dotNL, const in float dotNV */ ) {\n\t// geometry term is (n dot l)(n dot v) / 4(n dot l)(n dot v)\n\treturn 0.25;\n}\nfloat D_BlinnPhong( const in float shininess, const in float dotNH ) {\n\treturn RECIPROCAL_PI * ( shininess * 0.5 + 1.0 ) * pow( dotNH, shininess );\n}\nvec3 BRDF_Specular_BlinnPhong( const in IncidentLight incidentLight, const in GeometricContext geometry, const in vec3 specularColor, const in float shininess ) {\n\tvec3 halfDir = normalize( incidentLight.direction + geometry.viewDir );\n\t//float dotNL = saturate( dot( geometry.normal, incidentLight.direction ) );\n\t//float dotNV = saturate( dot( geometry.normal, geometry.viewDir ) );\n\tfloat dotNH = saturate( dot( geometry.normal, halfDir ) );\n\tfloat dotLH = saturate( dot( incidentLight.direction, halfDir ) );\n\tvec3 F = F_Schlick( specularColor, dotLH );\n\tfloat G = G_BlinnPhong_Implicit( /* dotNL, dotNV */ );\n\tfloat D = D_BlinnPhong( shininess, dotNH );\n\treturn F * ( G * D );\n} // validated\n// source: http://simonstechblog.blogspot.ca/2011/12/microfacet-brdf.html\nfloat GGXRoughnessToBlinnExponent( const in float ggxRoughness ) {\n\treturn ( 2.0 / pow2( ggxRoughness + 0.0001 ) - 2.0 );\n}\nfloat BlinnExponentToGGXRoughness( const in float blinnExponent ) {\n\treturn sqrt( 2.0 / ( blinnExponent + 2.0 ) );\n}\n#if defined( USE_SHEEN )\n// https://github.com/google/filament/blob/master/shaders/src/brdf.fs#L94\nfloat D_Charlie(float roughness, float NoH) {\n\t// Estevez and Kulla 2017, \"Production Friendly Microfacet Sheen BRDF\"\n\tfloat invAlpha = 1.0 / roughness;\n\tfloat cos2h = NoH * NoH;\n\tfloat sin2h = max(1.0 - cos2h, 0.0078125); // 2^(-14/2), so sin2h^2 > 0 in fp16\n\treturn (2.0 + invAlpha) * pow(sin2h, invAlpha * 0.5) / (2.0 * PI);\n}\n// https://github.com/google/filament/blob/master/shaders/src/brdf.fs#L136\nfloat V_Neubelt(float NoV, float NoL) {\n\t// Neubelt and Pettineo 2013, \"Crafting a Next-gen Material Pipeline for The Order: 1886\"\n\treturn saturate(1.0 / (4.0 * (NoL + NoV - NoL * NoV)));\n}\nvec3 BRDF_Specular_Sheen( const in float roughness, const in vec3 L, const in GeometricContext geometry, vec3 specularColor ) {\n\tvec3 N = geometry.normal;\n\tvec3 V = geometry.viewDir;\n\tvec3 H = normalize( V + L );\n\tfloat dotNH = saturate( dot( N, H ) );\n\treturn specularColor * D_Charlie( roughness, dotNH ) * V_Neubelt( dot(N, V), dot(N, L) );\n}\n#endif\n"; +var _default = "\n// Analytical approximation of the DFG LUT, one half of the\n// split-sum approximation used in indirect specular lighting.\n// via 'environmentBRDF' from \"Physically Based Shading on Mobile\"\n// https://www.unrealengine.com/blog/physically-based-shading-on-mobile - environmentBRDF for GGX on mobile\nvec2 integrateSpecularBRDF( const in float dotNV, const in float roughness ) {\n\tconst vec4 c0 = vec4( - 1, - 0.0275, - 0.572, 0.022 );\n\tconst vec4 c1 = vec4( 1, 0.0425, 1.04, - 0.04 );\n\tvec4 r = roughness * c0 + c1;\n\tfloat a004 = min( r.x * r.x, exp2( - 9.28 * dotNV ) ) * r.x + r.y;\n\treturn vec2( -1.04, 1.04 ) * a004 + r.zw;\n}\nfloat punctualLightIntensityToIrradianceFactor( const in float lightDistance, const in float cutoffDistance, const in float decayExponent ) {\n#if defined ( PHYSICALLY_CORRECT_LIGHTS )\n\t// based upon Frostbite 3 Moving to Physically-based Rendering\n\t// page 32, equation 26: E[window1]\n\t// https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf\n\t// this is intended to be used on spot and point lights who are represented as luminous intensity\n\t// but who must be converted to luminous irradiance for surface lighting calculation\n\tfloat distanceFalloff = 1.0 / max( pow( lightDistance, decayExponent ), 0.01 );\n\tif( cutoffDistance > 0.0 ) {\n\t\tdistanceFalloff *= pow2( saturate( 1.0 - pow4( lightDistance / cutoffDistance ) ) );\n\t}\n\treturn distanceFalloff;\n#else\n\tif( cutoffDistance > 0.0 && decayExponent > 0.0 ) {\n\t\treturn pow( saturate( -lightDistance / cutoffDistance + 1.0 ), decayExponent );\n\t}\n\treturn 1.0;\n#endif\n}\nvec3 BRDF_Diffuse_Lambert( const in vec3 diffuseColor ) {\n\treturn RECIPROCAL_PI * diffuseColor;\n} // validated\nvec3 F_Schlick( const in vec3 specularColor, const in float dotLH ) {\n\t// Original approximation by Christophe Schlick '94\n\t// float fresnel = pow( 1.0 - dotLH, 5.0 );\n\t// Optimized variant (presented by Epic at SIGGRAPH '13)\n\t// https://cdn2.unrealengine.com/Resources/files/2013SiggraphPresentationsNotes-26915738.pdf\n\tfloat fresnel = exp2( ( -5.55473 * dotLH - 6.98316 ) * dotLH );\n\treturn ( 1.0 - specularColor ) * fresnel + specularColor;\n} // validated\nvec3 F_Schlick_RoughnessDependent( const in vec3 F0, const in float dotNV, const in float roughness ) {\n\t// See F_Schlick\n\tfloat fresnel = exp2( ( -5.55473 * dotNV - 6.98316 ) * dotNV );\n\tvec3 Fr = max( vec3( 1.0 - roughness ), F0 ) - F0;\n\treturn Fr * fresnel + F0;\n}\n// Microfacet Models for Refraction through Rough Surfaces - equation (34)\n// http://graphicrants.blogspot.com/2013/08/specular-brdf-reference.html\n// alpha is \"roughness squared\" in Disney\u2019s reparameterization\nfloat G_GGX_Smith( const in float alpha, const in float dotNL, const in float dotNV ) {\n\t// geometry term (normalized) = G(l)\u22c5G(v) / 4(n\u22c5l)(n\u22c5v)\n\t// also see #12151\n\tfloat a2 = pow2( alpha );\n\tfloat gl = dotNL + sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNL ) );\n\tfloat gv = dotNV + sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNV ) );\n\treturn 1.0 / ( gl * gv );\n} // validated\n// Moving Frostbite to Physically Based Rendering 3.0 - page 12, listing 2\n// https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf\nfloat G_GGX_SmithCorrelated( const in float alpha, const in float dotNL, const in float dotNV ) {\n\tfloat a2 = pow2( alpha );\n\t// dotNL and dotNV are explicitly swapped. This is not a mistake.\n\tfloat gv = dotNL * sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNV ) );\n\tfloat gl = dotNV * sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNL ) );\n\treturn 0.5 / max( gv + gl, EPSILON );\n}\n// Microfacet Models for Refraction through Rough Surfaces - equation (33)\n// http://graphicrants.blogspot.com/2013/08/specular-brdf-reference.html\n// alpha is \"roughness squared\" in Disney\u2019s reparameterization\nfloat D_GGX( const in float alpha, const in float dotNH ) {\n\tfloat a2 = pow2( alpha );\n\tfloat denom = pow2( dotNH ) * ( a2 - 1.0 ) + 1.0; // avoid alpha = 0 with dotNH = 1\n\treturn RECIPROCAL_PI * a2 / pow2( denom );\n}\n// GGX Distribution, Schlick Fresnel, GGX-Smith Visibility\nvec3 BRDF_Specular_GGX( const in IncidentLight incidentLight, const in vec3 viewDir, const in vec3 normal, const in vec3 specularColor, const in float roughness ) {\n\tfloat alpha = pow2( roughness ); // UE4's roughness\n\tvec3 halfDir = normalize( incidentLight.direction + viewDir );\n\tfloat dotNL = saturate( dot( normal, incidentLight.direction ) );\n\tfloat dotNV = saturate( dot( normal, viewDir ) );\n\tfloat dotNH = saturate( dot( normal, halfDir ) );\n\tfloat dotLH = saturate( dot( incidentLight.direction, halfDir ) );\n\tvec3 F = F_Schlick( specularColor, dotLH );\n\tfloat G = G_GGX_SmithCorrelated( alpha, dotNL, dotNV );\n\tfloat D = D_GGX( alpha, dotNH );\n\treturn F * ( G * D );\n} // validated\n// Rect Area Light\n// Real-Time Polygonal-Light Shading with Linearly Transformed Cosines\n// by Eric Heitz, Jonathan Dupuy, Stephen Hill and David Neubelt\n// code: https://github.com/selfshadow/ltc_code/\nvec2 LTC_Uv( const in vec3 N, const in vec3 V, const in float roughness ) {\n\tconst float LUT_SIZE = 64.0;\n\tconst float LUT_SCALE = ( LUT_SIZE - 1.0 ) / LUT_SIZE;\n\tconst float LUT_BIAS = 0.5 / LUT_SIZE;\n\tfloat dotNV = saturate( dot( N, V ) );\n\t// texture parameterized by sqrt( GGX alpha ) and sqrt( 1 - cos( theta ) )\n\tvec2 uv = vec2( roughness, sqrt( 1.0 - dotNV ) );\n\tuv = uv * LUT_SCALE + LUT_BIAS;\n\treturn uv;\n}\nfloat LTC_ClippedSphereFormFactor( const in vec3 f ) {\n\t// Real-Time Area Lighting: a Journey from Research to Production (p.102)\n\t// An approximation of the form factor of a horizon-clipped rectangle.\n\tfloat l = length( f );\n\treturn max( ( l * l + f.z ) / ( l + 1.0 ), 0.0 );\n}\nvec3 LTC_EdgeVectorFormFactor( const in vec3 v1, const in vec3 v2 ) {\n\tfloat x = dot( v1, v2 );\n\tfloat y = abs( x );\n\t// rational polynomial approximation to theta / sin( theta ) / 2PI\n\tfloat a = 0.8543985 + ( 0.4965155 + 0.0145206 * y ) * y;\n\tfloat b = 3.4175940 + ( 4.1616724 + y ) * y;\n\tfloat v = a / b;\n\tfloat theta_sintheta = ( x > 0.0 ) ? v : 0.5 * inversesqrt( max( 1.0 - x * x, 1e-7 ) ) - v;\n\treturn cross( v1, v2 ) * theta_sintheta;\n}\nvec3 LTC_Evaluate( const in vec3 N, const in vec3 V, const in vec3 P, const in mat3 mInv, const in vec3 rectCoords[ 4 ] ) {\n\t// bail if point is on back side of plane of light\n\t// assumes ccw winding order of light vertices\n\tvec3 v1 = rectCoords[ 1 ] - rectCoords[ 0 ];\n\tvec3 v2 = rectCoords[ 3 ] - rectCoords[ 0 ];\n\tvec3 lightNormal = cross( v1, v2 );\n\tif( dot( lightNormal, P - rectCoords[ 0 ] ) < 0.0 ) return vec3( 0.0 );\n\t// construct orthonormal basis around N\n\tvec3 T1, T2;\n\tT1 = normalize( V - N * dot( V, N ) );\n\tT2 = - cross( N, T1 ); // negated from paper; possibly due to a different handedness of world coordinate system\n\t// compute transform\n\tmat3 mat = mInv * transposeMat3( mat3( T1, T2, N ) );\n\t// transform rect\n\tvec3 coords[ 4 ];\n\tcoords[ 0 ] = mat * ( rectCoords[ 0 ] - P );\n\tcoords[ 1 ] = mat * ( rectCoords[ 1 ] - P );\n\tcoords[ 2 ] = mat * ( rectCoords[ 2 ] - P );\n\tcoords[ 3 ] = mat * ( rectCoords[ 3 ] - P );\n\t// project rect onto sphere\n\tcoords[ 0 ] = normalize( coords[ 0 ] );\n\tcoords[ 1 ] = normalize( coords[ 1 ] );\n\tcoords[ 2 ] = normalize( coords[ 2 ] );\n\tcoords[ 3 ] = normalize( coords[ 3 ] );\n\t// calculate vector form factor\n\tvec3 vectorFormFactor = vec3( 0.0 );\n\tvectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 0 ], coords[ 1 ] );\n\tvectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 1 ], coords[ 2 ] );\n\tvectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 2 ], coords[ 3 ] );\n\tvectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 3 ], coords[ 0 ] );\n\t// adjust for horizon clipping\n\tfloat result = LTC_ClippedSphereFormFactor( vectorFormFactor );\n/*\n\t// alternate method of adjusting for horizon clipping (see referece)\n\t// refactoring required\n\tfloat len = length( vectorFormFactor );\n\tfloat z = vectorFormFactor.z / len;\n\tconst float LUT_SIZE = 64.0;\n\tconst float LUT_SCALE = ( LUT_SIZE - 1.0 ) / LUT_SIZE;\n\tconst float LUT_BIAS = 0.5 / LUT_SIZE;\n\t// tabulated horizon-clipped sphere, apparently...\n\tvec2 uv = vec2( z * 0.5 + 0.5, len );\n\tuv = uv * LUT_SCALE + LUT_BIAS;\n\tfloat scale = texture2D( ltc_2, uv ).w;\n\tfloat result = len * scale;\n*/\n\treturn vec3( result );\n}\n// End Rect Area Light\n// ref: https://www.unrealengine.com/blog/physically-based-shading-on-mobile - environmentBRDF for GGX on mobile\nvec3 BRDF_Specular_GGX_Environment( const in vec3 viewDir, const in vec3 normal, const in vec3 specularColor, const in float roughness ) {\n\tfloat dotNV = saturate( dot( normal, viewDir ) );\n\tvec2 brdf = integrateSpecularBRDF( dotNV, roughness );\n\treturn specularColor * brdf.x + brdf.y;\n} // validated\n// Fdez-Ag\xfcera's \"Multiple-Scattering Microfacet Model for Real-Time Image Based Lighting\"\n// Approximates multiscattering in order to preserve energy.\n// http://www.jcgt.org/published/0008/01/03/\nvoid BRDF_Specular_Multiscattering_Environment( const in GeometricContext geometry, const in vec3 specularColor, const in float roughness, inout vec3 singleScatter, inout vec3 multiScatter ) {\n\tfloat dotNV = saturate( dot( geometry.normal, geometry.viewDir ) );\n\tvec3 F = F_Schlick_RoughnessDependent( specularColor, dotNV, roughness );\n\tvec2 brdf = integrateSpecularBRDF( dotNV, roughness );\n\tvec3 FssEss = F * brdf.x + brdf.y;\n\tfloat Ess = brdf.x + brdf.y;\n\tfloat Ems = 1.0 - Ess;\n\tvec3 Favg = specularColor + ( 1.0 - specularColor ) * 0.047619; // 1/21\n\tvec3 Fms = FssEss * Favg / ( 1.0 - Ems * Favg );\n\tsingleScatter += FssEss;\n\tmultiScatter += Fms * Ems;\n}\nfloat G_BlinnPhong_Implicit( /* const in float dotNL, const in float dotNV */ ) {\n\t// geometry term is (n dot l)(n dot v) / 4(n dot l)(n dot v)\n\treturn 0.25;\n}\nfloat D_BlinnPhong( const in float shininess, const in float dotNH ) {\n\treturn RECIPROCAL_PI * ( shininess * 0.5 + 1.0 ) * pow( dotNH, shininess );\n}\nvec3 BRDF_Specular_BlinnPhong( const in IncidentLight incidentLight, const in GeometricContext geometry, const in vec3 specularColor, const in float shininess ) {\n\tvec3 halfDir = normalize( incidentLight.direction + geometry.viewDir );\n\t//float dotNL = saturate( dot( geometry.normal, incidentLight.direction ) );\n\t//float dotNV = saturate( dot( geometry.normal, geometry.viewDir ) );\n\tfloat dotNH = saturate( dot( geometry.normal, halfDir ) );\n\tfloat dotLH = saturate( dot( incidentLight.direction, halfDir ) );\n\tvec3 F = F_Schlick( specularColor, dotLH );\n\tfloat G = G_BlinnPhong_Implicit( /* dotNL, dotNV */ );\n\tfloat D = D_BlinnPhong( shininess, dotNH );\n\treturn F * ( G * D );\n} // validated\n// source: http://simonstechblog.blogspot.ca/2011/12/microfacet-brdf.html\nfloat GGXRoughnessToBlinnExponent( const in float ggxRoughness ) {\n\treturn ( 2.0 / pow2( ggxRoughness + 0.0001 ) - 2.0 );\n}\nfloat BlinnExponentToGGXRoughness( const in float blinnExponent ) {\n\treturn sqrt( 2.0 / ( blinnExponent + 2.0 ) );\n}\n#if defined( USE_SHEEN )\n// https://github.com/google/filament/blob/master/shaders/src/brdf.fs#L94\nfloat D_Charlie(float roughness, float NoH) {\n\t// Estevez and Kulla 2017, \"Production Friendly Microfacet Sheen BRDF\"\n\tfloat invAlpha = 1.0 / roughness;\n\tfloat cos2h = NoH * NoH;\n\tfloat sin2h = max(1.0 - cos2h, 0.0078125); // 2^(-14/2), so sin2h^2 > 0 in fp16\n\treturn (2.0 + invAlpha) * pow(sin2h, invAlpha * 0.5) / (2.0 * PI);\n}\n// https://github.com/google/filament/blob/master/shaders/src/brdf.fs#L136\nfloat V_Neubelt(float NoV, float NoL) {\n\t// Neubelt and Pettineo 2013, \"Crafting a Next-gen Material Pipeline for The Order: 1886\"\n\treturn saturate(1.0 / (4.0 * (NoL + NoV - NoL * NoV)));\n}\nvec3 BRDF_Specular_Sheen( const in float roughness, const in vec3 L, const in GeometricContext geometry, vec3 specularColor ) {\n\tvec3 N = geometry.normal;\n\tvec3 V = geometry.viewDir;\n\tvec3 H = normalize( V + L );\n\tfloat dotNH = saturate( dot( N, H ) );\n\treturn specularColor * D_Charlie( roughness, dotNH ) * V_Neubelt( dot(N, V), dot(N, L) );\n}\n#endif\n"; exports.default = _default; diff --git a/tests/fixture/issue-1449/case1/input/index.js b/tests/fixture/issue-1449/case1/input/index.js new file mode 100644 index 000000000000..fd37a6c96fe2 --- /dev/null +++ b/tests/fixture/issue-1449/case1/input/index.js @@ -0,0 +1,5 @@ +async function foo() { + const { + bar: { } = {} + } = baz; +} \ No newline at end of file diff --git a/tests/fixture/issue-1449/case1/output/index.js b/tests/fixture/issue-1449/case1/output/index.js new file mode 100644 index 000000000000..fe3124ee7cac --- /dev/null +++ b/tests/fixture/issue-1449/case1/output/index.js @@ -0,0 +1,52 @@ +function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { + try { + var info = gen[key](arg); + var value = info.value; + } catch (error) { + reject(error); + return; + } + if (info.done) { + resolve(value); + } else { + Promise.resolve(value).then(_next, _throw); + } +} +function _asyncToGenerator(fn) { + return function() { + var self = this, args = arguments; + return new Promise(function(resolve, reject) { + var gen = fn.apply(self, args); + function _next(value) { + asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); + } + function _throw(err) { + asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); + } + _next(undefined); + }); + }; +} +var regeneratorRuntime = require("regenerator-runtime"); +var _marked = regeneratorRuntime.mark(_foo); +function _foo() { + _foo = _asyncToGenerator(regeneratorRuntime.mark(function _callee() { + return regeneratorRuntime.wrap(function _callee$(_ctx) { + var ref; + while(1)switch(_ctx.prev = _ctx.next){ + case 0: + var ref1; + var ref2; + ref1 = baz, ref = { + }, ref2 = ref, ref1; + case 1: + case "end": + return _ctx.stop(); + } + }, _callee); + })); + return _foo.apply(this, arguments); +} +function foo() { + return _foo.apply(this, arguments); +} diff --git a/tests/fixture/issue-1455/case1/input/.swcrc b/tests/fixture/issue-1455/case1/input/.swcrc new file mode 100644 index 000000000000..45a6553f67ac --- /dev/null +++ b/tests/fixture/issue-1455/case1/input/.swcrc @@ -0,0 +1,15 @@ +{ + "exclude": [".*.js$", ".*.map$", ".*.test.ts$"], + "jsc": { + "target": "es2016", + "parser": { + "syntax": "typescript", + "tsx": false, + "decorators": true + } + }, + "minify": false, + "module": { + "type": "commonjs" + } +} diff --git a/tests/fixture/issue-1455/case1/input/index.ts b/tests/fixture/issue-1455/case1/input/index.ts new file mode 100644 index 000000000000..545f76e635b1 --- /dev/null +++ b/tests/fixture/issue-1455/case1/input/index.ts @@ -0,0 +1,10 @@ +const SampleData = typedModel("SampleVideo", VideosSchema, undefined, undefined, { + byPlatform: async function (platform: string) { + const result = await this.find({ platform: { $eq: platform } }); + return result; + }, +}); + +SampleData.byPlatform("youtube").then((res) => { + console.info(res); +}); \ No newline at end of file diff --git a/tests/fixture/issue-1455/case1/output/index.ts b/tests/fixture/issue-1455/case1/output/index.ts new file mode 100644 index 000000000000..d0b9ef67dd96 --- /dev/null +++ b/tests/fixture/issue-1455/case1/output/index.ts @@ -0,0 +1,48 @@ +"use strict"; +function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { + try { + var info = gen[key](arg); + var value = info.value; + } catch (error) { + reject(error); + return; + } + if (info.done) { + resolve(value); + } else { + Promise.resolve(value).then(_next, _throw); + } +} +function _asyncToGenerator(fn) { + return function() { + var self = this, args = arguments; + return new Promise(function(resolve, reject) { + var gen = fn.apply(self, args); + function _next(value) { + asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); + } + function _throw(err) { + asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); + } + _next(undefined); + }); + }; +} +const SampleData = typedModel("SampleVideo", VideosSchema, undefined, undefined, { + byPlatform: function(platform) { + var _ref = _asyncToGenerator(function*(platform) { + const result = yield this.find({ + platform: { + $eq: platform + } + }); + return result; + }); + return function() { + return _ref.apply(this, arguments); + }; + }() +}); +SampleData.byPlatform("youtube").then((res)=>{ + console.info(res); +}); diff --git a/tests/fixture/issue-1455/case2/input/index.ts b/tests/fixture/issue-1455/case2/input/index.ts new file mode 100644 index 000000000000..e3808e6d5d8b --- /dev/null +++ b/tests/fixture/issue-1455/case2/input/index.ts @@ -0,0 +1,11 @@ +const obj = { + find({ platform }) { + return { platform } + }, + byPlatform: async function (platform) { + const result = await this.find({ platform: { $eq: platform } }); + return result; + }, +}; + +obj.byPlatform('foo').then(v => console.log(v)) diff --git a/tests/fixture/issue-1455/case2/output/index.ts b/tests/fixture/issue-1455/case2/output/index.ts new file mode 100644 index 000000000000..c3bbf5944db6 --- /dev/null +++ b/tests/fixture/issue-1455/case2/output/index.ts @@ -0,0 +1,66 @@ +function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { + try { + var info = gen[key](arg); + var value = info.value; + } catch (error) { + reject(error); + return; + } + if (info.done) { + resolve(value); + } else { + Promise.resolve(value).then(_next, _throw); + } +} +function _asyncToGenerator(fn) { + return function() { + var self = this, args = arguments; + return new Promise(function(resolve, reject) { + var gen = fn.apply(self, args); + function _next(value) { + asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); + } + function _throw(err) { + asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); + } + _next(undefined); + }); + }; +} +var regeneratorRuntime = require("regenerator-runtime"); +var obj = { + find: function(param) { + var platform = param.platform; + return { + platform: platform + }; + }, + byPlatform: function(platform) { + var _ref = _asyncToGenerator(regeneratorRuntime.mark(function _callee(platform) { + var result; + return regeneratorRuntime.wrap(function _callee$(_ctx) { + while(1)switch(_ctx.prev = _ctx.next){ + case 0: + _ctx.next = 2; + return this.find({ + platform: { + $eq: platform + } + }); + case 2: + result = _ctx.sent; + return _ctx.abrupt("return", result); + case 4: + case "end": + return _ctx.stop(); + } + }, _callee, this); + })); + return function() { + return _ref.apply(this, arguments); + }; + }() +}; +obj.byPlatform('foo').then(function(v) { + return console.log(v); +}); diff --git a/tests/fixture/issue-1477/case1/input/index.js b/tests/fixture/issue-1477/case1/input/index.js new file mode 100644 index 000000000000..3c5341897011 --- /dev/null +++ b/tests/fixture/issue-1477/case1/input/index.js @@ -0,0 +1,3 @@ +async function f(a, b) { + const [{ a: a_ = 1 }] = JSON.parse(b) +} \ No newline at end of file diff --git a/tests/fixture/issue-1477/case1/output/index.js b/tests/fixture/issue-1477/case1/output/index.js new file mode 100644 index 000000000000..6b4b297437ba --- /dev/null +++ b/tests/fixture/issue-1477/case1/output/index.js @@ -0,0 +1,51 @@ +function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { + try { + var info = gen[key](arg); + var value = info.value; + } catch (error) { + reject(error); + return; + } + if (info.done) { + resolve(value); + } else { + Promise.resolve(value).then(_next, _throw); + } +} +function _asyncToGenerator(fn) { + return function() { + var self = this, args = arguments; + return new Promise(function(resolve, reject) { + var gen = fn.apply(self, args); + function _next(value) { + asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); + } + function _throw(err) { + asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); + } + _next(undefined); + }); + }; +} +var regeneratorRuntime = require("regenerator-runtime"); +var _marked = regeneratorRuntime.mark(_f); +function _f() { + _f = _asyncToGenerator(regeneratorRuntime.mark(function _callee(a, b) { + var a_; + return regeneratorRuntime.wrap(function _callee$(_ctx) { + var ref; + while(1)switch(_ctx.prev = _ctx.next){ + case 0: + var ref1, ref2; + ref1 = JSON.parse(b), ref2 = ref1[0], ref = 1, a_ = ref, ref1; + case 1: + case "end": + return _ctx.stop(); + } + }, _callee); + })); + return _f.apply(this, arguments); +} +function f(a, b) { + return _f.apply(this, arguments); +} diff --git a/tests/projects/issue-532-block/input.js b/tests/fixture/issue-532/block/input/index.js similarity index 100% rename from tests/projects/issue-532-block/input.js rename to tests/fixture/issue-532/block/input/index.js diff --git a/tests/fixture/issue-532/block/output/index.js b/tests/fixture/issue-532/block/output/index.js new file mode 100644 index 000000000000..3484b2370387 --- /dev/null +++ b/tests/fixture/issue-532/block/output/index.js @@ -0,0 +1,6 @@ +/*pre: 1*/ test(); +test(123/*post: 3*/ ); +test(/*pre: 4*/ 123); +test(/*pre: 5*/ 123/*post: 6*/ ); +test(/*pre: 7*/ 123, /*pre: 8*/ 456); +test(123/*post: 9*/ , 456/*post: 10*/ ); diff --git a/tests/issue-1448/case1/input/.swcrc b/tests/issue-1448/case1/input/.swcrc new file mode 100644 index 000000000000..13bc04c6fd16 --- /dev/null +++ b/tests/issue-1448/case1/input/.swcrc @@ -0,0 +1,12 @@ +{ + "env": { + "coreJs": 3 + }, + "jsc": { + "parser": { + "syntax": "typescript", + "tsx": true + }, + "loose": true + } +} diff --git a/tests/issue-1448/case1/input/index.ts b/tests/issue-1448/case1/input/index.ts new file mode 100644 index 000000000000..e325eccfc42d --- /dev/null +++ b/tests/issue-1448/case1/input/index.ts @@ -0,0 +1,2 @@ +import F = require("yaml") +console.log(F) \ No newline at end of file diff --git a/tests/projects.rs b/tests/projects.rs index c4f4e9b51701..3392c419db97 100644 --- a/tests/projects.rs +++ b/tests/projects.rs @@ -337,27 +337,6 @@ fn project_env() { project("tests/projects/env/"); } -#[test] -fn issue_532() { - let f = file("tests/projects/issue-532-block/input.js") - .unwrap() - .replace(" ", ""); - let f = f.trim(); - - println!("{}", f); - - assert_eq!( - f, - "\ -/*pre:1*/test(); -test(123/*post:3*/); -test(/*pre:4*/123); -test(/*pre:5*/123/*post:6*/); -test(/*pre:7*/123,/*pre:8*/456); -test(123/*post:9*/,456/*post:10*/);" - ) -} - #[test] fn issue_602() { let f = file("tests/projects/issue-602/input.js").unwrap();