diff --git a/Cargo.toml b/Cargo.toml index f96ebf11004..486155d7161 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,7 +11,7 @@ edition = "2018" license = "Apache-2.0/MIT" name = "swc" repository = "https://github.com/swc-project/swc.git" -version = "0.12.2" +version = "0.13.0" [lib] name = "swc" @@ -29,12 +29,12 @@ serde_json = "1" sourcemap = "6" swc_atoms = {version = "0.2", path = "./atoms"} swc_common = {version = "0.10.10", path = "./common", features = ["sourcemap", "concurrent"]} -swc_ecma_ast = {version = "0.41.0", path = "./ecmascript/ast"} -swc_ecma_codegen = {version = "0.49.0", path = "./ecmascript/codegen"} -swc_ecma_ext_transforms = {version = "0.9.0", path = "./ecmascript/ext-transforms"} -swc_ecma_parser = {version = "0.51.0", path = "./ecmascript/parser"} -swc_ecma_preset_env = {version = "0.12.1", path = "./ecmascript/preset_env"} -swc_ecma_transforms = {version = "0.42.1", path = "./ecmascript/transforms", features = [ +swc_ecma_ast = {version = "0.42.0", path = "./ecmascript/ast"} +swc_ecma_codegen = {version = "0.50.0", path = "./ecmascript/codegen"} +swc_ecma_ext_transforms = {version = "0.10.0", path = "./ecmascript/ext-transforms"} +swc_ecma_parser = {version = "0.52.0", path = "./ecmascript/parser"} +swc_ecma_preset_env = {version = "0.13.0", path = "./ecmascript/preset_env"} +swc_ecma_transforms = {version = "0.43.0", path = "./ecmascript/transforms", features = [ "compat", "module", "optimization", @@ -42,8 +42,8 @@ swc_ecma_transforms = {version = "0.42.1", path = "./ecmascript/transforms", fea "react", "typescript", ]} -swc_ecma_utils = {version = "0.32.0", path = "./ecmascript/utils"} -swc_ecma_visit = {version = "0.27.0", path = "./ecmascript/visit"} +swc_ecma_utils = {version = "0.33.0", path = "./ecmascript/utils"} +swc_ecma_visit = {version = "0.28.0", path = "./ecmascript/visit"} swc_visit = {version = "0.2.3", path = "./visit"} [dev-dependencies] diff --git a/bundler/Cargo.toml b/bundler/Cargo.toml index 029a34516b8..0b076ec43f6 100644 --- a/bundler/Cargo.toml +++ b/bundler/Cargo.toml @@ -9,7 +9,7 @@ include = ["Cargo.toml", "build.rs", "src/**/*.rs", "src/**/*.js"] license = "Apache-2.0/MIT" name = "swc_bundler" repository = "https://github.com/swc-project/swc.git" -version = "0.29.2" +version = "0.30.0" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [features] @@ -32,19 +32,19 @@ relative-path = "1.2" retain_mut = "0.1.2" swc_atoms = {version = "0.2.4", path = "../atoms"} swc_common = {version = "0.10.10", path = "../common"} -swc_ecma_ast = {version = "0.41.0", path = "../ecmascript/ast"} -swc_ecma_codegen = {version = "0.49.0", path = "../ecmascript/codegen"} -swc_ecma_parser = {version = "0.51.0", path = "../ecmascript/parser"} -swc_ecma_transforms = {version = "0.42.1", path = "../ecmascript/transforms", features = ["optimization"]} -swc_ecma_utils = {version = "0.32.0", path = "../ecmascript/utils"} -swc_ecma_visit = {version = "0.27.0", path = "../ecmascript/visit"} +swc_ecma_ast = {version = "0.42.0", path = "../ecmascript/ast"} +swc_ecma_codegen = {version = "0.50.0", path = "../ecmascript/codegen"} +swc_ecma_parser = {version = "0.52.0", path = "../ecmascript/parser"} +swc_ecma_transforms = {version = "0.43.0", path = "../ecmascript/transforms", features = ["optimization"]} +swc_ecma_utils = {version = "0.33.0", path = "../ecmascript/utils"} +swc_ecma_visit = {version = "0.28.0", path = "../ecmascript/visit"} [dev-dependencies] hex = "0.4" ntest = "0.7.2" reqwest = {version = "0.10.8", features = ["blocking"]} sha-1 = "0.9" -swc_ecma_transforms = {version = "0.42.1", path = "../ecmascript/transforms", features = ["react", "typescript"]} +swc_ecma_transforms = {version = "0.43.0", path = "../ecmascript/transforms", features = ["react", "typescript"]} tempfile = "3.1.0" testing = {version = "0.10.3", path = "../testing"} url = "2.1.1" diff --git a/ecmascript/Cargo.toml b/ecmascript/Cargo.toml index 93cc7cf58b7..54b5932b60f 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.28.1" +version = "0.29.0" [package.metadata.docs.rs] all-features = true @@ -27,12 +27,12 @@ react = ["swc_ecma_transforms/react"] typescript = ["swc_ecma_transforms/typescript"] [dependencies] -swc_ecma_ast = {version = "0.41.0", path = "./ast"} -swc_ecma_codegen = {version = "0.49.0", path = "./codegen", optional = true} -swc_ecma_dep_graph = {version = "0.19.0", path = "./dep-graph", optional = true} -swc_ecma_parser = {version = "0.51.0", path = "./parser", optional = true} -swc_ecma_transforms = {version = "0.42.1", path = "./transforms", optional = true} -swc_ecma_utils = {version = "0.32.0", path = "./utils", optional = true} -swc_ecma_visit = {version = "0.27.0", path = "./visit", optional = true} +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_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} [dev-dependencies] diff --git a/ecmascript/ast/Cargo.toml b/ecmascript/ast/Cargo.toml index 7de0df1f4d4..249dce20dc2 100644 --- a/ecmascript/ast/Cargo.toml +++ b/ecmascript/ast/Cargo.toml @@ -6,7 +6,7 @@ edition = "2018" license = "Apache-2.0/MIT" name = "swc_ecma_ast" repository = "https://github.com/swc-project/swc.git" -version = "0.41.0" +version = "0.42.0" [features] default = [] diff --git a/ecmascript/ast/src/lib.rs b/ecmascript/ast/src/lib.rs index 01dcf5c7b0a..d6bc0d917f3 100644 --- a/ecmascript/ast/src/lib.rs +++ b/ecmascript/ast/src/lib.rs @@ -52,16 +52,17 @@ pub use self::{ TsConditionalType, TsConstAssertion, TsConstructSignatureDecl, TsConstructorType, TsEntityName, TsEnumDecl, TsEnumMember, TsEnumMemberId, TsExportAssignment, TsExprWithTypeArgs, TsExternalModuleRef, TsFnOrConstructorType, TsFnParam, TsFnType, - TsImportEqualsDecl, TsImportType, TsIndexSignature, TsIndexedAccessType, TsInferType, - TsInterfaceBody, TsInterfaceDecl, TsIntersectionType, TsKeywordType, TsKeywordTypeKind, - TsLit, TsLitType, TsMappedType, TsMethodSignature, TsModuleBlock, TsModuleDecl, - TsModuleName, TsModuleRef, TsNamespaceBody, TsNamespaceDecl, TsNamespaceExportDecl, - TsNonNullExpr, TsOptionalType, TsParamProp, TsParamPropParam, TsParenthesizedType, - TsPropertySignature, TsQualifiedName, TsRestType, TsSignatureDecl, TsThisType, - TsThisTypeOrIdent, TsTplLitType, TsTupleElement, TsTupleType, TsType, TsTypeAliasDecl, - TsTypeAnn, TsTypeAssertion, TsTypeElement, TsTypeLit, TsTypeOperator, TsTypeOperatorOp, - TsTypeParam, TsTypeParamDecl, TsTypeParamInstantiation, TsTypePredicate, TsTypeQuery, - TsTypeQueryExpr, TsTypeRef, TsUnionOrIntersectionType, TsUnionType, + TsGetterSignature, TsImportEqualsDecl, TsImportType, TsIndexSignature, TsIndexedAccessType, + TsInferType, TsInterfaceBody, TsInterfaceDecl, TsIntersectionType, TsKeywordType, + TsKeywordTypeKind, TsLit, TsLitType, TsMappedType, TsMethodSignature, TsModuleBlock, + TsModuleDecl, TsModuleName, TsModuleRef, TsNamespaceBody, TsNamespaceDecl, + TsNamespaceExportDecl, TsNonNullExpr, TsOptionalType, TsParamProp, TsParamPropParam, + TsParenthesizedType, TsPropertySignature, TsQualifiedName, TsRestType, TsSetterSignature, + TsSignatureDecl, TsThisType, TsThisTypeOrIdent, TsTplLitType, TsTupleElement, TsTupleType, + TsType, TsTypeAliasDecl, TsTypeAnn, TsTypeAssertion, TsTypeElement, TsTypeLit, + TsTypeOperator, TsTypeOperatorOp, TsTypeParam, TsTypeParamDecl, TsTypeParamInstantiation, + TsTypePredicate, TsTypeQuery, TsTypeQueryExpr, TsTypeRef, TsUnionOrIntersectionType, + TsUnionType, }, }; use serde::Deserialize; diff --git a/ecmascript/ast/src/typescript.rs b/ecmascript/ast/src/typescript.rs index f8fbc031227..008d6af9135 100644 --- a/ecmascript/ast/src/typescript.rs +++ b/ecmascript/ast/src/typescript.rs @@ -144,6 +144,12 @@ pub enum TsTypeElement { #[tag("TsPropertySignature")] TsPropertySignature(TsPropertySignature), + #[tag("TsGetterSignature")] + TsGetterSignature(TsGetterSignature), + + #[tag("TsSetterSignature")] + TsSetterSignature(TsSetterSignature), + #[tag("TsMethodSignature")] TsMethodSignature(TsMethodSignature), @@ -193,6 +199,31 @@ pub struct TsPropertySignature { pub type_params: Option, } +#[ast_node("TsGetterSignature")] +#[derive(Eq, Hash, EqIgnoreSpan)] +#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] +pub struct TsGetterSignature { + pub span: Span, + pub readonly: bool, + pub key: Box, + pub computed: bool, + pub optional: bool, + #[serde(default, rename = "typeAnnotation")] + pub type_ann: Option, +} + +#[ast_node("TsSetterSignature")] +#[derive(Eq, Hash, EqIgnoreSpan)] +#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] +pub struct TsSetterSignature { + pub span: Span, + pub readonly: bool, + pub key: Box, + pub computed: bool, + pub optional: bool, + pub param: TsFnParam, +} + #[ast_node("TsMethodSignature")] #[derive(Eq, Hash, EqIgnoreSpan)] #[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] diff --git a/ecmascript/codegen/Cargo.toml b/ecmascript/codegen/Cargo.toml index ef8885d3aff..78e73251dfc 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.49.1" +version = "0.50.0" [dependencies] bitflags = "1" @@ -15,9 +15,9 @@ num-bigint = {version = "0.2", features = ["serde"]} sourcemap = "6" swc_atoms = {version = "0.2", path = "../../atoms"} swc_common = {version = "0.10.10", path = "../../common"} -swc_ecma_ast = {version = "0.41.0", path = "../ast"} +swc_ecma_ast = {version = "0.42.0", path = "../ast"} swc_ecma_codegen_macros = {version = "0.5.2", path = "./macros"} -swc_ecma_parser = {version = "0.51.0", path = "../parser"} +swc_ecma_parser = {version = "0.52.0", path = "../parser"} [dev-dependencies] swc_common = {version = "0.10.10", path = "../../common", features = ["sourcemap"]} diff --git a/ecmascript/codegen/src/typescript.rs b/ecmascript/codegen/src/typescript.rs index 0ccc827d882..51ef6ef13d5 100644 --- a/ecmascript/codegen/src/typescript.rs +++ b/ecmascript/codegen/src/typescript.rs @@ -874,10 +874,46 @@ impl<'a> Emitter<'a> { TsTypeElement::TsPropertySignature(n) => emit!(n), TsTypeElement::TsMethodSignature(n) => emit!(n), TsTypeElement::TsIndexSignature(n) => emit!(n), + TsTypeElement::TsGetterSignature(n) => { + emit!(n) + } + TsTypeElement::TsSetterSignature(n) => { + emit!(n) + } } formatting_semi!(); } + #[emitter] + fn emit_ts_getter_signature(&mut self, n: &TsGetterSignature) -> Result { + keyword!("get"); + space!(); + + emit!(n.key); + + punct!("("); + punct!(")"); + + if let Some(ty) = &n.type_ann { + punct!(":"); + formatting_space!(); + + emit!(ty.type_ann); + } + } + + #[emitter] + fn emit_ts_setter_signature(&mut self, n: &TsSetterSignature) -> Result { + keyword!("set"); + space!(); + + emit!(n.key); + + punct!("("); + emit!(n.param); + punct!(")"); + } + #[emitter] fn emit_ts_type_lit(&mut self, n: &TsTypeLit) -> Result { self.emit_leading_comments_of_pos(n.span().lo())?; diff --git a/ecmascript/dep-graph/Cargo.toml b/ecmascript/dep-graph/Cargo.toml index c10c9009300..75f2288a08b 100644 --- a/ecmascript/dep-graph/Cargo.toml +++ b/ecmascript/dep-graph/Cargo.toml @@ -6,14 +6,14 @@ edition = "2018" license = "Apache-2.0/MIT" name = "swc_ecma_dep_graph" repository = "https://github.com/swc-project/swc.git" -version = "0.19.0" +version = "0.20.0" [dependencies] swc_atoms = {version = "0.2", path = "../../atoms"} swc_common = {version = "0.10.10", path = "../../common"} -swc_ecma_ast = {version = "0.41.0", path = "../ast"} -swc_ecma_visit = {version = "0.27.0", path = "../visit"} +swc_ecma_ast = {version = "0.42.0", path = "../ast"} +swc_ecma_visit = {version = "0.28.0", path = "../visit"} [dev-dependencies] -swc_ecma_parser = {version = "0.51.0", path = "../parser"} +swc_ecma_parser = {version = "0.52.0", path = "../parser"} testing = {version = "0.10.3", path = "../../testing"} diff --git a/ecmascript/ext-transforms/Cargo.toml b/ecmascript/ext-transforms/Cargo.toml index a424b53c38d..0a77d4fe534 100644 --- a/ecmascript/ext-transforms/Cargo.toml +++ b/ecmascript/ext-transforms/Cargo.toml @@ -5,7 +5,7 @@ documentation = "https://swc.rs/rustdoc/swc_ecma_ext_transforms/" edition = "2018" license = "Apache-2.0/MIT" name = "swc_ecma_ext_transforms" -version = "0.9.0" +version = "0.10.0" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html @@ -13,7 +13,7 @@ version = "0.9.0" phf = {version = "0.8.0", features = ["macros"]} swc_atoms = {version = "0.2", path = "../../atoms"} swc_common = {version = "0.10.10", path = "../../common"} -swc_ecma_ast = {version = "0.41.0", path = "../ast"} -swc_ecma_parser = {version = "0.51.0", path = "../parser"} -swc_ecma_utils = {version = "0.32.0", path = "../utils"} -swc_ecma_visit = {version = "0.27.0", path = "../visit"} +swc_ecma_ast = {version = "0.42.0", path = "../ast"} +swc_ecma_parser = {version = "0.52.0", path = "../parser"} +swc_ecma_utils = {version = "0.33.0", path = "../utils"} +swc_ecma_visit = {version = "0.28.0", path = "../visit"} diff --git a/ecmascript/jsdoc/Cargo.toml b/ecmascript/jsdoc/Cargo.toml index 2a651e284ee..f266feab311 100644 --- a/ecmascript/jsdoc/Cargo.toml +++ b/ecmascript/jsdoc/Cargo.toml @@ -5,7 +5,7 @@ documentation = "https://swc.rs/rustdoc/jsdoc/" edition = "2018" license = "Apache-2.0/MIT" name = "jsdoc" -version = "0.19.0" +version = "0.20.0" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html @@ -18,7 +18,7 @@ swc_common = {version = "0.10.10", path = "../../common"} [dev-dependencies] anyhow = "1" dashmap = "3" -swc_ecma_ast = {version = "0.41.0", path = "../ast"} -swc_ecma_parser = {version = "0.51.0", path = "../parser"} +swc_ecma_ast = {version = "0.42.0", path = "../ast"} +swc_ecma_parser = {version = "0.52.0", path = "../parser"} testing = {version = "0.10.3", path = "../../testing"} walkdir = "2" diff --git a/ecmascript/loader/Cargo.toml b/ecmascript/loader/Cargo.toml index 3169fc7e71c..f90f198010c 100644 --- a/ecmascript/loader/Cargo.toml +++ b/ecmascript/loader/Cargo.toml @@ -6,15 +6,15 @@ edition = "2018" license = "Apache-2.0/MIT" name = "swc_ecma_loader" repository = "https://github.com/swc-project/swc.git" -version = "0.2.0" +version = "0.3.0" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] swc_atoms = {version = "0.2.3", path = "../../atoms"} swc_common = {version = "0.10.10", path = "../../common"} -swc_ecma_ast = {version = "0.41.0", path = "../ast"} -swc_ecma_visit = {version = "0.27.0", path = "../visit"} +swc_ecma_ast = {version = "0.42.0", path = "../ast"} +swc_ecma_visit = {version = "0.28.0", path = "../visit"} [dev-dependencies] testing = {version = "0.10.3", path = "../../testing"} diff --git a/ecmascript/parser/Cargo.toml b/ecmascript/parser/Cargo.toml index cd529c05272..0a2774c8a2a 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.51.2" +version = "0.52.0" [features] default = [] @@ -22,8 +22,8 @@ serde = {version = "1", features = ["derive"]} smallvec = "1" swc_atoms = {version = "0.2.3", path = "../../atoms"} swc_common = {version = "0.10.10", path = "../../common"} -swc_ecma_ast = {version = "0.41.0", path = "../ast"} -swc_ecma_visit = {version = "0.27.0", path = "../visit"} +swc_ecma_ast = {version = "0.42.0", path = "../ast"} +swc_ecma_visit = {version = "0.28.0", path = "../visit"} unicode-xid = "0.2" [dev-dependencies] diff --git a/ecmascript/parser/src/error.rs b/ecmascript/parser/src/error.rs index 6c59503b04c..1b0b874ce49 100644 --- a/ecmascript/parser/src/error.rs +++ b/ecmascript/parser/src/error.rs @@ -53,6 +53,7 @@ pub enum SyntaxError { ExpectedDigit { radix: u8, }, + SetterParamRequired, RestPatInSetter, UnterminatedBlockComment, @@ -526,6 +527,7 @@ impl SyntaxError { SyntaxError::TSTypeAnnotationAfterAssign => { "Type annotations must come before default assignments".into() } + SyntaxError::SetterParamRequired => "Setter should have exactly one parameter".into(), } } } diff --git a/ecmascript/parser/src/macros.rs b/ecmascript/parser/src/macros.rs index 407ac60d647..5d5dca07c25 100644 --- a/ecmascript/parser/src/macros.rs +++ b/ecmascript/parser/src/macros.rs @@ -362,6 +362,12 @@ macro_rules! tok { ("assert") => { crate::token::Token::Word(crate::token::Word::Ident(swc_atoms::js_word!("assert"))) }; + ("get") => { + crate::token::Token::Word(crate::token::Word::Ident(swc_atoms::js_word!("get"))) + }; + ("set") => { + crate::token::Token::Word(crate::token::Word::Ident(swc_atoms::js_word!("set"))) + }; } macro_rules! token_including_semi { diff --git a/ecmascript/parser/src/parser/pat.rs b/ecmascript/parser/src/parser/pat.rs index 6509a819f10..03921b33d52 100644 --- a/ecmascript/parser/src/parser/pat.rs +++ b/ecmascript/parser/src/parser/pat.rs @@ -1,5 +1,6 @@ //! 13.3.3 Destructuring Binding Patterns use super::{util::ExprExt, *}; +use crate::parser::class_and_fn::is_not_this; use crate::{parser::expr::PatOrExprOrSpread, token::AssignOpToken}; use std::iter; use swc_atoms::js_word; @@ -346,6 +347,27 @@ impl<'a, I: Tokens> Parser { } } + pub(super) fn parse_setter_param(&mut self, key_span: Span) -> PResult { + let params = self.parse_formal_params()?; + let cnt = params.iter().filter(|p| is_not_this(p)).count(); + + if cnt != 1 { + self.emit_err(key_span, SyntaxError::TS1094); + } + + if !params.is_empty() { + if let Pat::Rest(..) = params[0].pat { + self.emit_err(params[0].pat.span(), SyntaxError::RestPatInSetter); + } + } + + if params.is_empty() { + syntax_error!(self, SyntaxError::SetterParamRequired); + } + + Ok(params.into_iter().next().unwrap()) + } + pub(super) fn parse_formal_params(&mut self) -> PResult> { let mut first = true; let mut params = vec![]; diff --git a/ecmascript/parser/src/parser/typescript.rs b/ecmascript/parser/src/parser/typescript.rs index 59a3747bfa0..e88237511e2 100644 --- a/ecmascript/parser/src/parser/typescript.rs +++ b/ecmascript/parser/src/parser/typescript.rs @@ -1223,15 +1223,10 @@ impl Parser { })) } - /// `tsParsePropertyOrMethodSignature` - fn parse_ts_property_or_method_signature( - &mut self, - start: BytePos, - readonly: bool, - ) -> PResult> { - debug_assert!(self.input.syntax().typescript()); - - // ----- inlined self.parsePropertyName(node); + /// `parsePropertyName` in babel. + /// + /// Returns `(computed, key)`. + fn parse_ts_property_name(&mut self) -> PResult<(bool, Box)> { let (computed, key) = if eat!(self, '[') { let key = self.parse_assignment_expr()?; expect!(self, ']'); @@ -1258,7 +1253,19 @@ impl Parser { key.map(|key| (false, key)) })? }; - // ----- + + Ok((computed, key)) + } + + /// `tsParsePropertyOrMethodSignature` + fn parse_ts_property_or_method_signature( + &mut self, + start: BytePos, + readonly: bool, + ) -> PResult> { + debug_assert!(self.input.syntax().typescript()); + + let (computed, key) = self.parse_ts_property_name()?; let optional = eat!(self, '?'); @@ -1334,6 +1341,61 @@ impl Parser { return Ok(idx.into()); } + if let Some(v) = self.try_parse_ts(|p| { + let start = p.input.cur_pos(); + + let reaodnly = p.parse_ts_modifier(&["readonly"])?.is_some(); + + let is_get = if eat!(p, "get") { + true + } else { + expect!(p, "set"); + false + }; + + let (computed, key) = p.parse_ts_property_name()?; + + let key_span = key.span(); + let optional = eat!(p, '?'); + + if is_get { + expect!(p, '('); + expect!(p, ')'); + let type_ann = p.try_parse_ts_type_ann()?; + + p.parse_ts_type_member_semicolon()?; + + Ok(Some(TsTypeElement::TsGetterSignature(TsGetterSignature { + span: span!(p, start), + readonly, + key, + computed, + optional, + type_ann, + }))) + } else { + expect!(p, '('); + let params = p.parse_ts_binding_list_for_signature()?; + if params.is_empty() { + syntax_error!(p, SyntaxError::SetterParamRequired) + } + let param = params.into_iter().next().unwrap(); + + p.parse_ts_type_member_semicolon()?; + + Ok(Some(TsTypeElement::TsSetterSignature(TsSetterSignature { + span: span!(p, start), + readonly, + key, + computed, + optional, + param, + }))) + } + }) { + return Ok(v); + } + self.parse_ts_property_or_method_signature(start, readonly) .map(|e| match e { Either::Left(e) => e.into(), @@ -1707,6 +1769,8 @@ impl Parser { } /// `tsParseBindingListForSignature` + /// + /// Eats ')` at the end but does not eat `(` at start. fn parse_ts_binding_list_for_signature(&mut self) -> PResult> { debug_assert!(self.input.syntax().typescript()); diff --git a/ecmascript/parser/tests/issue-1517/case1/input.ts b/ecmascript/parser/tests/issue-1517/case1/input.ts new file mode 100644 index 00000000000..1fd8438ecb7 --- /dev/null +++ b/ecmascript/parser/tests/issue-1517/case1/input.ts @@ -0,0 +1,4 @@ +interface X { + get foo(): string; +set foo(v: string | number); +} \ No newline at end of file diff --git a/ecmascript/parser/tests/issue-1517/case2/input.ts b/ecmascript/parser/tests/issue-1517/case2/input.ts new file mode 100644 index 00000000000..004ba90b3b8 --- /dev/null +++ b/ecmascript/parser/tests/issue-1517/case2/input.ts @@ -0,0 +1,4 @@ +type Y = { + get bar(): string; +set bar(v: string | number); +} \ No newline at end of file diff --git a/ecmascript/parser/tests/typescript/issue-1454/case1/input.ts b/ecmascript/parser/tests/typescript/issue-1454/case1/input.ts new file mode 100644 index 00000000000..5c7f41db3d5 --- /dev/null +++ b/ecmascript/parser/tests/typescript/issue-1454/case1/input.ts @@ -0,0 +1,2 @@ +export abstract class AbstractProviderDeliveryService { +} \ No newline at end of file diff --git a/ecmascript/parser/tests/typescript/issue-1454/case1/input.ts.json b/ecmascript/parser/tests/typescript/issue-1454/case1/input.ts.json new file mode 100644 index 00000000000..f1ab568ff0c --- /dev/null +++ b/ecmascript/parser/tests/typescript/issue-1454/case1/input.ts.json @@ -0,0 +1,45 @@ +{ + "type": "Module", + "span": { + "start": 0, + "end": 57, + "ctxt": 0 + }, + "body": [ + { + "type": "ExportDeclaration", + "span": { + "start": 0, + "end": 57, + "ctxt": 0 + }, + "declaration": { + "type": "ClassDeclaration", + "identifier": { + "type": "Identifier", + "span": { + "start": 22, + "end": 53, + "ctxt": 0 + }, + "value": "AbstractProviderDeliveryService", + "optional": false + }, + "declare": false, + "span": { + "start": 7, + "end": 57, + "ctxt": 0 + }, + "decorators": [], + "body": [], + "superClass": null, + "isAbstract": true, + "typeParams": null, + "superTypeParams": null, + "implements": [] + } + } + ], + "interpreter": null +} diff --git a/ecmascript/parser/tests/typescript/issue-1517/case1/input.ts b/ecmascript/parser/tests/typescript/issue-1517/case1/input.ts new file mode 100644 index 00000000000..1fd8438ecb7 --- /dev/null +++ b/ecmascript/parser/tests/typescript/issue-1517/case1/input.ts @@ -0,0 +1,4 @@ +interface X { + get foo(): string; +set foo(v: string | number); +} \ No newline at end of file diff --git a/ecmascript/parser/tests/typescript/issue-1517/case1/input.ts.json b/ecmascript/parser/tests/typescript/issue-1517/case1/input.ts.json new file mode 100644 index 00000000000..eae204fdcc4 --- /dev/null +++ b/ecmascript/parser/tests/typescript/issue-1517/case1/input.ts.json @@ -0,0 +1,147 @@ +{ + "type": "Script", + "span": { + "start": 0, + "end": 67, + "ctxt": 0 + }, + "body": [ + { + "type": "TsInterfaceDeclaration", + "span": { + "start": 0, + "end": 67, + "ctxt": 0 + }, + "id": { + "type": "Identifier", + "span": { + "start": 10, + "end": 11, + "ctxt": 0 + }, + "value": "X", + "optional": false + }, + "declare": false, + "typeParams": null, + "extends": [], + "body": { + "type": "TsInterfaceBody", + "span": { + "start": 12, + "end": 67, + "ctxt": 0 + }, + "body": [ + { + "type": "TsGetterSignature", + "span": { + "start": 18, + "end": 36, + "ctxt": 0 + }, + "readonly": false, + "key": { + "type": "Identifier", + "span": { + "start": 22, + "end": 25, + "ctxt": 0 + }, + "value": "foo", + "optional": false + }, + "computed": false, + "optional": false, + "typeAnnotation": { + "type": "TsTypeAnnotation", + "span": { + "start": 27, + "end": 35, + "ctxt": 0 + }, + "typeAnnotation": { + "type": "TsKeywordType", + "span": { + "start": 29, + "end": 35, + "ctxt": 0 + }, + "kind": "string" + } + } + }, + { + "type": "TsSetterSignature", + "span": { + "start": 37, + "end": 65, + "ctxt": 0 + }, + "readonly": false, + "key": { + "type": "Identifier", + "span": { + "start": 41, + "end": 44, + "ctxt": 0 + }, + "value": "foo", + "optional": false + }, + "computed": false, + "optional": false, + "param": { + "type": "Identifier", + "span": { + "start": 45, + "end": 63, + "ctxt": 0 + }, + "value": "v", + "optional": false, + "typeAnnotation": { + "type": "TsTypeAnnotation", + "span": { + "start": 46, + "end": 63, + "ctxt": 0 + }, + "typeAnnotation": { + "type": "TsUnionType", + "span": { + "start": 48, + "end": 63, + "ctxt": 0 + }, + "types": [ + { + "type": "TsKeywordType", + "span": { + "start": 48, + "end": 54, + "ctxt": 0 + }, + "kind": "string" + }, + { + "type": "TsKeywordType", + "span": { + "start": 57, + "end": 63, + "ctxt": 0 + }, + "kind": "number" + } + ] + } + } + } + } + ] + } + } + ], + "interpreter": null +} diff --git a/ecmascript/parser/tests/typescript/issue-1517/case2/input.ts b/ecmascript/parser/tests/typescript/issue-1517/case2/input.ts new file mode 100644 index 00000000000..004ba90b3b8 --- /dev/null +++ b/ecmascript/parser/tests/typescript/issue-1517/case2/input.ts @@ -0,0 +1,4 @@ +type Y = { + get bar(): string; +set bar(v: string | number); +} \ No newline at end of file diff --git a/ecmascript/parser/tests/typescript/issue-1517/case2/input.ts.json b/ecmascript/parser/tests/typescript/issue-1517/case2/input.ts.json new file mode 100644 index 00000000000..b6c543d7035 --- /dev/null +++ b/ecmascript/parser/tests/typescript/issue-1517/case2/input.ts.json @@ -0,0 +1,146 @@ +{ + "type": "Script", + "span": { + "start": 0, + "end": 64, + "ctxt": 0 + }, + "body": [ + { + "type": "TsTypeAliasDeclaration", + "span": { + "start": 0, + "end": 64, + "ctxt": 0 + }, + "declare": false, + "id": { + "type": "Identifier", + "span": { + "start": 5, + "end": 6, + "ctxt": 0 + }, + "value": "Y", + "optional": false + }, + "typeParams": null, + "typeAnnotation": { + "type": "TsTypeLiteral", + "span": { + "start": 9, + "end": 64, + "ctxt": 0 + }, + "members": [ + { + "type": "TsGetterSignature", + "span": { + "start": 15, + "end": 33, + "ctxt": 0 + }, + "readonly": false, + "key": { + "type": "Identifier", + "span": { + "start": 19, + "end": 22, + "ctxt": 0 + }, + "value": "bar", + "optional": false + }, + "computed": false, + "optional": false, + "typeAnnotation": { + "type": "TsTypeAnnotation", + "span": { + "start": 24, + "end": 32, + "ctxt": 0 + }, + "typeAnnotation": { + "type": "TsKeywordType", + "span": { + "start": 26, + "end": 32, + "ctxt": 0 + }, + "kind": "string" + } + } + }, + { + "type": "TsSetterSignature", + "span": { + "start": 34, + "end": 62, + "ctxt": 0 + }, + "readonly": false, + "key": { + "type": "Identifier", + "span": { + "start": 38, + "end": 41, + "ctxt": 0 + }, + "value": "bar", + "optional": false + }, + "computed": false, + "optional": false, + "param": { + "type": "Identifier", + "span": { + "start": 42, + "end": 60, + "ctxt": 0 + }, + "value": "v", + "optional": false, + "typeAnnotation": { + "type": "TsTypeAnnotation", + "span": { + "start": 43, + "end": 60, + "ctxt": 0 + }, + "typeAnnotation": { + "type": "TsUnionType", + "span": { + "start": 45, + "end": 60, + "ctxt": 0 + }, + "types": [ + { + "type": "TsKeywordType", + "span": { + "start": 45, + "end": 51, + "ctxt": 0 + }, + "kind": "string" + }, + { + "type": "TsKeywordType", + "span": { + "start": 54, + "end": 60, + "ctxt": 0 + }, + "kind": "number" + } + ] + } + } + } + } + ] + } + } + ], + "interpreter": null +} diff --git a/ecmascript/preset_env/Cargo.toml b/ecmascript/preset_env/Cargo.toml index 230f86d4870..a2639fba21f 100644 --- a/ecmascript/preset_env/Cargo.toml +++ b/ecmascript/preset_env/Cargo.toml @@ -5,7 +5,7 @@ documentation = "https://swc.rs/rustdoc/swc_ecma_preset_env/" edition = "2018" license = "Apache-2.0/MIT" name = "swc_ecma_preset_env" -version = "0.12.1" +version = "0.13.0" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html @@ -20,14 +20,14 @@ st-map = "0.1.2" string_enum = {version = "0.3.1", path = "../../macros/string_enum"} swc_atoms = {version = "0.2", path = "../../atoms"} swc_common = {version = "0.10.10", path = "../../common"} -swc_ecma_ast = {version = "0.41.0", path = "../ast"} -swc_ecma_transforms = {version = "0.42.1", path = "../transforms", features = ["compat", "proposal"]} -swc_ecma_utils = {version = "0.32.0", path = "../utils"} -swc_ecma_visit = {version = "0.27.0", path = "../visit"} +swc_ecma_ast = {version = "0.42.0", path = "../ast"} +swc_ecma_transforms = {version = "0.43.0", path = "../transforms", features = ["compat", "proposal"]} +swc_ecma_utils = {version = "0.33.0", path = "../utils"} +swc_ecma_visit = {version = "0.28.0", path = "../visit"} walkdir = "2" [dev-dependencies] pretty_assertions = "0.6" -swc_ecma_codegen = {version = "0.49.0", path = "../codegen"} -swc_ecma_parser = {version = "0.51.0", path = "../parser"} +swc_ecma_codegen = {version = "0.50.0", path = "../codegen"} +swc_ecma_parser = {version = "0.52.0", path = "../parser"} testing = {version = "0.10.3", path = "../../testing"} diff --git a/ecmascript/transforms/Cargo.toml b/ecmascript/transforms/Cargo.toml index ba5a12a38b8..9fd6c60362f 100644 --- a/ecmascript/transforms/Cargo.toml +++ b/ecmascript/transforms/Cargo.toml @@ -6,7 +6,7 @@ edition = "2018" license = "Apache-2.0/MIT" name = "swc_ecma_transforms" repository = "https://github.com/swc-project/swc.git" -version = "0.42.1" +version = "0.43.0" [package.metadata.docs.rs] all-features = true @@ -23,24 +23,24 @@ typescript = ["swc_ecma_transforms_typescript"] [dependencies] swc_atoms = {version = "0.2.0", path = "../../atoms"} swc_common = {version = "0.10.10", path = "../../common"} -swc_ecma_ast = {version = "0.41.0", path = "../ast"} -swc_ecma_parser = {version = "0.51.0", path = "../parser"} -swc_ecma_transforms_base = {version = "0.9.0", path = "./base"} -swc_ecma_transforms_compat = {version = "0.10.1", path = "./compat", optional = true} -swc_ecma_transforms_module = {version = "0.10.1", path = "./module", optional = true} -swc_ecma_transforms_optimization = {version = "0.12.1", path = "./optimization", optional = true} -swc_ecma_transforms_proposal = {version = "0.10.1", path = "./proposal", optional = true} -swc_ecma_transforms_react = {version = "0.11.1", path = "./react", optional = true} -swc_ecma_transforms_typescript = {version = "0.11.1", path = "./typescript", optional = true} -swc_ecma_utils = {version = "0.32.0", path = "../utils"} -swc_ecma_visit = {version = "0.27.0", path = "../visit"} +swc_ecma_ast = {version = "0.42.0", path = "../ast"} +swc_ecma_parser = {version = "0.52.0", path = "../parser"} +swc_ecma_transforms_base = {version = "0.10.0", path = "./base"} +swc_ecma_transforms_compat = {version = "0.11.0", path = "./compat", optional = true} +swc_ecma_transforms_module = {version = "0.11.0", path = "./module", optional = true} +swc_ecma_transforms_optimization = {version = "0.13.0", path = "./optimization", optional = true} +swc_ecma_transforms_proposal = {version = "0.11.0", path = "./proposal", optional = true} +swc_ecma_transforms_react = {version = "0.12.0", path = "./react", optional = true} +swc_ecma_transforms_typescript = {version = "0.12.0", path = "./typescript", optional = true} +swc_ecma_utils = {version = "0.33.0", path = "../utils"} +swc_ecma_visit = {version = "0.28.0", path = "../visit"} unicode-xid = "0.2" [dev-dependencies] pretty_assertions = "0.6" sourcemap = "6" -swc_ecma_codegen = {version = "0.49.0", path = "../codegen"} -swc_ecma_transforms_testing = {version = "0.9.0", path = "./testing"} +swc_ecma_codegen = {version = "0.50.0", path = "../codegen"} +swc_ecma_transforms_testing = {version = "0.10.0", path = "./testing"} tempfile = "3" testing = {version = "0.10.3", path = "../../testing"} walkdir = "2" diff --git a/ecmascript/transforms/base/Cargo.toml b/ecmascript/transforms/base/Cargo.toml index 496eb0b11f9..e554d9dbefc 100644 --- a/ecmascript/transforms/base/Cargo.toml +++ b/ecmascript/transforms/base/Cargo.toml @@ -6,7 +6,7 @@ edition = "2018" license = "Apache-2.0/MIT" name = "swc_ecma_transforms_base" repository = "https://github.com/swc-project/swc.git" -version = "0.9.1" +version = "0.10.0" [dependencies] fxhash = "0.2.1" @@ -16,11 +16,11 @@ scoped-tls = "1.0.0" smallvec = "1.6.0" swc_atoms = {version = "0.2", path = "../../../atoms"} swc_common = {version = "0.10.10", path = "../../../common"} -swc_ecma_ast = {version = "0.41.0", path = "../../ast"} -swc_ecma_parser = {version = "0.51.0", path = "../../parser"} -swc_ecma_utils = {version = "0.32.0", path = "../../utils"} -swc_ecma_visit = {version = "0.27.0", path = "../../visit"} +swc_ecma_ast = {version = "0.42.0", path = "../../ast"} +swc_ecma_parser = {version = "0.52.0", path = "../../parser"} +swc_ecma_utils = {version = "0.33.0", path = "../../utils"} +swc_ecma_visit = {version = "0.28.0", path = "../../visit"} [dev-dependencies] -swc_ecma_codegen = {version = "0.49.0", path = "../../codegen"} +swc_ecma_codegen = {version = "0.50.0", path = "../../codegen"} testing = {version = "0.10.3", path = "../../../testing"} diff --git a/ecmascript/transforms/base/src/resolver/mod.rs b/ecmascript/transforms/base/src/resolver/mod.rs index a000979c577..10d8b6cb935 100644 --- a/ecmascript/transforms/base/src/resolver/mod.rs +++ b/ecmascript/transforms/base/src/resolver/mod.rs @@ -709,11 +709,6 @@ impl<'a> VisitMut for Resolver<'a> { f.return_type.visit_mut_with(self); } - // TODO: How should I handle this? - typed!(visit_mut_ts_namespace_export_decl, TsNamespaceExportDecl); - - track_ident_mut!(); - fn visit_mut_ident(&mut self, i: &mut Ident) { let ident_type = self.ident_type; let in_type = self.in_type; @@ -790,6 +785,11 @@ impl<'a> VisitMut for Resolver<'a> { self.ident_type = old; } + // TODO: How should I handle this? + typed!(visit_mut_ts_namespace_export_decl, TsNamespaceExportDecl); + + track_ident_mut!(); + /// Leftmost one of a member expression should be resolved. fn visit_mut_member_expr(&mut self, e: &mut MemberExpr) { e.obj.visit_mut_with(self); @@ -997,6 +997,14 @@ impl<'a> VisitMut for Resolver<'a> { ty.type_ann.visit_mut_with(&mut child); } + fn visit_mut_ts_getter_signature(&mut self, n: &mut TsGetterSignature) { + if n.computed { + n.key.visit_mut_with(self); + } + + n.type_ann.visit_mut_with(self); + } + fn visit_mut_ts_import_equals_decl(&mut self, n: &mut TsImportEqualsDecl) { if !self.handle_types { return; @@ -1132,6 +1140,14 @@ impl<'a> VisitMut for Resolver<'a> { n.left.visit_mut_with(self) } + fn visit_mut_ts_setter_signature(&mut self, n: &mut TsSetterSignature) { + if n.computed { + n.key.visit_mut_with(self); + } + + n.param.visit_mut_with(self); + } + fn visit_mut_ts_tuple_element(&mut self, e: &mut TsTupleElement) { if !self.handle_types { return; diff --git a/ecmascript/transforms/base/src/resolver/tests.rs b/ecmascript/transforms/base/src/resolver/tests.rs index d3e4fd7fd00..1bd61a3468a 100644 --- a/ecmascript/transforms/base/src/resolver/tests.rs +++ b/ecmascript/transforms/base/src/resolver/tests.rs @@ -2345,3 +2345,35 @@ to_ts!( } " ); + +to_ts!( + issue_1517_1, + " + interface X { + get foo(): string; + set foo(v: string | number); + } + ", + " + interface X { + get foo__0(): string; + set foo__0(v: string | number); + } + " +); + +to_ts!( + issue_1517_2, + " + type Y = { + get bar(): string; + set bar(v: string | number); + } + ", + " + type Y = { + get bar__0(): string; + set bar__0(v: string | number); + } + " +); diff --git a/ecmascript/transforms/compat/Cargo.toml b/ecmascript/transforms/compat/Cargo.toml index 03b7895ae88..525970a899f 100644 --- a/ecmascript/transforms/compat/Cargo.toml +++ b/ecmascript/transforms/compat/Cargo.toml @@ -6,7 +6,7 @@ edition = "2018" license = "Apache-2.0/MIT" name = "swc_ecma_transforms_compat" repository = "https://github.com/swc-project/swc.git" -version = "0.10.1" +version = "0.11.0" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] @@ -20,13 +20,13 @@ serde = {version = "1.0.118", features = ["derive"]} smallvec = "1.6.0" swc_atoms = {version = "0.2.5", path = "../../../atoms"} swc_common = {version = "0.10.10", path = "../../../common"} -swc_ecma_ast = {version = "0.41.0", path = "../../ast"} -swc_ecma_transforms_base = {version = "0.9.0", path = "../base"} +swc_ecma_ast = {version = "0.42.0", path = "../../ast"} +swc_ecma_transforms_base = {version = "0.10.0", path = "../base"} swc_ecma_transforms_macros = {version = "0.2.1", path = "../macros"} -swc_ecma_utils = {version = "0.32.0", path = "../../utils"} -swc_ecma_visit = {version = "0.27.0", path = "../../visit"} +swc_ecma_utils = {version = "0.33.0", path = "../../utils"} +swc_ecma_visit = {version = "0.28.0", path = "../../visit"} [dev-dependencies] -swc_ecma_parser = {version = "0.51.0", path = "../../parser"} -swc_ecma_transforms_testing = {version = "0.9.0", path = "../testing"} +swc_ecma_parser = {version = "0.52.0", path = "../../parser"} +swc_ecma_transforms_testing = {version = "0.10.0", path = "../testing"} testing = {version = "0.10.3", path = "../../../testing"} diff --git a/ecmascript/transforms/compat/src/es2015/classes.rs b/ecmascript/transforms/compat/src/es2015/classes/mod.rs similarity index 100% rename from ecmascript/transforms/compat/src/es2015/classes.rs rename to ecmascript/transforms/compat/src/es2015/classes/mod.rs diff --git a/ecmascript/transforms/compat/src/es2015/classes/super_field.rs b/ecmascript/transforms/compat/src/es2015/classes/super_field.rs index ef5ac918efe..1d549d29894 100644 --- a/ecmascript/transforms/compat/src/es2015/classes/super_field.rs +++ b/ecmascript/transforms/compat/src/es2015/classes/super_field.rs @@ -186,7 +186,7 @@ impl<'a> Fold for SuperCalleeFolder<'a> { span, left: left.fold_children_with(self), op, - right: right.fold_children_with(self), + right, }) } _ => n.fold_children_with(self), diff --git a/ecmascript/transforms/compat/src/es2015/template_literal.rs b/ecmascript/transforms/compat/src/es2015/template_literal.rs index 8a11d0e3cb0..9b79480d9d7 100644 --- a/ecmascript/transforms/compat/src/es2015/template_literal.rs +++ b/ecmascript/transforms/compat/src/es2015/template_literal.rs @@ -39,7 +39,26 @@ impl Fold for TemplateLiteral { // TODO: Optimize // This makes result of addition string - let mut obj: Box = Box::new(Lit::Str(quasis[0].raw.clone()).into()); + let mut obj: Box = Box::new( + Lit::Str({ + let mut s = quasis[0] + .cooked + .clone() + .unwrap_or_else(|| quasis[0].raw.clone()); + + // See https://github.com/swc-project/swc/issues/1488 + // + // This is hack to prevent '\\`'. Hack is used to avoid breaking + // change of ast crate. + if s.value.contains("`") { + s.kind = Default::default(); + s.has_escape = false; + } + + s + }) + .into(), + ); let len = quasis.len() + exprs.len(); @@ -59,7 +78,14 @@ impl Fold for TemplateLiteral { match quasis.next() { Some(TplElement { cooked, raw, .. }) => { - let s = cooked.unwrap_or_else(|| raw); + let mut s = cooked.unwrap_or_else(|| raw); + // See https://github.com/swc-project/swc/issues/1488 + // + // This is hack to prevent '\\`'. Hack is used to avoid breaking + // change of ast crate. + if s.value.contains("`") { + s.kind = Default::default(); + } Box::new(Lit::Str(s).into()) } _ => unreachable!(), diff --git a/ecmascript/transforms/compat/tests/es2015_classes.rs b/ecmascript/transforms/compat/tests/es2015_classes.rs index 10f2f492b79..baaecc1d0b9 100644 --- a/ecmascript/transforms/compat/tests/es2015_classes.rs +++ b/ecmascript/transforms/compat/tests/es2015_classes.rs @@ -6062,3 +6062,71 @@ const obj = new OtherClass(); expect(obj.anotherMethod()).toBe(2); "# ); + +test!( + syntax(), + |_| classes(), + issue_1490_1, + " + class ColouredCanvasElement extends CanvasElement { + createFacets(hidden) { + hidden = super.createFacets(hidden); + } + } + ", + " + let ColouredCanvasElement = function (CanvasElement) { + 'use strict'; + _inherits(ColouredCanvasElement, CanvasElement); + function ColouredCanvasElement() { + _classCallCheck(this, ColouredCanvasElement); + return _possibleConstructorReturn(this, \ + _getPrototypeOf(ColouredCanvasElement).apply(this, arguments)); + } + _createClass(ColouredCanvasElement, [ + { + key: 'createFacets', + value: function createFacets(hidden) { + hidden = _get(_getPrototypeOf(ColouredCanvasElement.prototype), \ + 'createFacets', this).call(this, hidden); + } + } + ]); + return ColouredCanvasElement; + }(CanvasElement); + " +); + +test!( + syntax(), + |_| classes(), + issue_1490_2, + " + class ColouredCanvasElement extends CanvasElement { + createFacets(hidden) { + super.createFacets(hidden); + } + } + ", + " + let ColouredCanvasElement = function (CanvasElement) { + 'use strict'; + _inherits(ColouredCanvasElement, CanvasElement); + function ColouredCanvasElement() { + _classCallCheck(this, ColouredCanvasElement); + return _possibleConstructorReturn(this, \ + _getPrototypeOf(ColouredCanvasElement).apply(this, arguments)); + } + _createClass(ColouredCanvasElement, [ + { + key: 'createFacets', + value: function createFacets(hidden) { + _get(_getPrototypeOf(ColouredCanvasElement.prototype), 'createFacets', \ + this).call(this, hidden); + } + } + ]); + return ColouredCanvasElement; + }(CanvasElement); + " +); diff --git a/ecmascript/transforms/compat/tests/es2015_template_literals.rs b/ecmascript/transforms/compat/tests/es2015_template_literals.rs index 1358cd710d5..c261879a3de 100644 --- a/ecmascript/transforms/compat/tests/es2015_template_literals.rs +++ b/ecmascript/transforms/compat/tests/es2015_template_literals.rs @@ -928,3 +928,15 @@ test!( ", ok_if_code_eq ); + +test!( + syntax(), + |_| tr(Default::default()), + issue_1488_1, + " + `\\`` + ", + " + '`' + " +); diff --git a/ecmascript/transforms/module/Cargo.toml b/ecmascript/transforms/module/Cargo.toml index 3c20d8d3733..a7c7c18fcbd 100644 --- a/ecmascript/transforms/module/Cargo.toml +++ b/ecmascript/transforms/module/Cargo.toml @@ -6,7 +6,7 @@ edition = "2018" license = "Apache-2.0/MIT" name = "swc_ecma_transforms_module" repository = "https://github.com/swc-project/swc.git" -version = "0.10.1" +version = "0.11.0" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] @@ -16,13 +16,13 @@ indexmap = "1.6.1" serde = {version = "1.0.118", features = ["derive"]} swc_atoms = {version = "0.2", path = "../../../atoms"} swc_common = {version = "0.10.10", path = "../../../common"} -swc_ecma_ast = {version = "0.41.0", path = "../../ast"} -swc_ecma_parser = {version = "0.51.0", path = "../../parser"} -swc_ecma_transforms_base = {version = "0.9.0", path = "../base"} -swc_ecma_utils = {version = "0.32.0", path = "../../utils"} -swc_ecma_visit = {version = "0.27.0", path = "../../visit"} +swc_ecma_ast = {version = "0.42.0", path = "../../ast"} +swc_ecma_parser = {version = "0.52.0", path = "../../parser"} +swc_ecma_transforms_base = {version = "0.10.0", path = "../base"} +swc_ecma_utils = {version = "0.33.0", path = "../../utils"} +swc_ecma_visit = {version = "0.28.0", path = "../../visit"} [dev-dependencies] -swc_ecma_transforms_compat = {version = "0.10.1", path = "../compat"} -swc_ecma_transforms_testing = {version = "0.9.0", path = "../testing/"} +swc_ecma_transforms_compat = {version = "0.11.0", path = "../compat"} +swc_ecma_transforms_testing = {version = "0.10.0", path = "../testing/"} testing = {version = "0.10.3", path = "../../../testing/"} diff --git a/ecmascript/transforms/module/src/common_js.rs b/ecmascript/transforms/module/src/common_js.rs index 159bb3f2193..95c53a71955 100644 --- a/ecmascript/transforms/module/src/common_js.rs +++ b/ecmascript/transforms/module/src/common_js.rs @@ -694,14 +694,18 @@ impl ModulePass for CommonJs { } fn make_dynamic_import(&mut self, span: Span, args: Vec) -> Expr { - handle_dynamic_import(span, args) + handle_dynamic_import(span, args, !self.config.no_interop) } } /// ```js /// Promise.resolve().then(function () { return require('./foo'); }) /// ``` -pub(super) fn handle_dynamic_import(span: Span, args: Vec) -> Expr { +pub(super) fn handle_dynamic_import( + span: Span, + args: Vec, + es_module_interop: bool, +) -> Expr { let resolve_call = CallExpr { span: DUMMY_SP, callee: member_expr!(DUMMY_SP, Promise.resolve).as_callee(), @@ -730,12 +734,28 @@ pub(super) fn handle_dynamic_import(span: Span, args: Vec) -> Expr span: DUMMY_SP, stmts: vec![Stmt::Return(ReturnStmt { span: DUMMY_SP, - arg: Some(Box::new(Expr::Call(CallExpr { - span: DUMMY_SP, - callee: quote_ident!("require").as_callee(), - args, - type_args: Default::default(), - }))), + arg: Some({ + let mut expr = Box::new(Expr::Call(CallExpr { + span: DUMMY_SP, + callee: quote_ident!("require").as_callee(), + args, + type_args: Default::default(), + })); + + if es_module_interop { + expr = Box::new(Expr::Call(CallExpr { + span: DUMMY_SP, + callee: helper!( + interop_require_wildcard, + "interopRequireWildcard" + ), + args: vec![expr.as_arg()], + type_args: Default::default(), + })); + } + + expr + }), })], }), }, diff --git a/ecmascript/transforms/module/src/umd.rs b/ecmascript/transforms/module/src/umd.rs index 33d95102524..efa547fd453 100644 --- a/ecmascript/transforms/module/src/umd.rs +++ b/ecmascript/transforms/module/src/umd.rs @@ -775,7 +775,11 @@ impl ModulePass for Umd { span, test: Box::new(quote_ident!("exports").make_eq(quote_ident!("undefined"))), cons: Box::new(super::amd::handle_dynamic_import(span, args.clone())), - alt: Box::new(super::common_js::handle_dynamic_import(span, args)), + alt: Box::new(super::common_js::handle_dynamic_import( + span, + args, + !self.config.config.no_interop, + )), }) } } diff --git a/ecmascript/transforms/module/tests/common_js.rs b/ecmascript/transforms/module/tests/common_js.rs index c7cf5579f65..1d884dc7986 100644 --- a/ecmascript/transforms/module/tests/common_js.rs +++ b/ecmascript/transforms/module/tests/common_js.rs @@ -25,6 +25,7 @@ use swc_ecma_visit::Fold; fn syntax() -> Syntax { Syntax::Es(EsConfig { dynamic_import: true, + top_level_await: true, ..Default::default() }) } @@ -4131,7 +4132,7 @@ test!( \"use strict\"; async function foo() { await Promise.resolve().then(function() { - return require(\"foo\"); + return _interopRequireWildcard(require('foo')); }); } " @@ -4558,25 +4559,63 @@ test!( }), issue_1423_1, " - 'use strict'; - import { arrayUtilities } from 'necessary'; + 'use strict'; + import { arrayUtilities } from 'necessary'; - const { second } = arrayUtilities; + const { second } = arrayUtilities; - const elements = [1, 2, 3], - secondElement = second(elements); + const elements = [1, 2, 3], + secondElement = second(elements); - console.log(secondElement) - ", + console.log(secondElement) + ", + " + 'use strict'; + var _necessary = require('necessary'); + const { second } = _necessary.arrayUtilities; + const elements = [ + 1, + 2, + 3 + ], secondElement = second(elements); + console.log(secondElement); + " +); + +test!( + syntax(), + |_| tr(Config { + no_interop: false, + strict: true, + strict_mode: true, + lazy: Lazy::Bool(false) + }), + issue_1480_1, + " + const { default: ora } = await import('ora') + ", " 'use strict'; - var _necessary = require('necessary'); - const { second } = _necessary.arrayUtilities; - const elements = [ - 1, - 2, - 3 - ], secondElement = second(elements); - console.log(secondElement); + const { default: ora } = await Promise.resolve().then(function() { + return _interopRequireWildcard(require('ora')); + }); + " +); + +test!( + syntax(), + |_| tr(Config { + no_interop: false, + strict: true, + strict_mode: true, + lazy: Lazy::Bool(false) + }), + issue_1480_2, + " + import * as ora from 'ora' +", + " + 'use strict'; + var ora = _interopRequireWildcard(require('ora')); " ); diff --git a/ecmascript/transforms/module/tests/umd.rs b/ecmascript/transforms/module/tests/umd.rs index 5d711a69fbd..aa66d763ef5 100644 --- a/ecmascript/transforms/module/tests/umd.rs +++ b/ecmascript/transforms/module/tests/umd.rs @@ -1917,7 +1917,7 @@ test!( reject(err); }); }) : Promise.resolve().then(function() { - return require(\"foo\"); + return _interopRequireWildcard(require(\"foo\")); })); } }); diff --git a/ecmascript/transforms/optimization/Cargo.toml b/ecmascript/transforms/optimization/Cargo.toml index 03bc21cc3c6..e22348fdcd4 100644 --- a/ecmascript/transforms/optimization/Cargo.toml +++ b/ecmascript/transforms/optimization/Cargo.toml @@ -6,7 +6,7 @@ edition = "2018" license = "Apache-2.0/MIT" name = "swc_ecma_transforms_optimization" repository = "https://github.com/swc-project/swc.git" -version = "0.12.1" +version = "0.13.0" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] @@ -19,17 +19,17 @@ retain_mut = "0.1.2" serde_json = "1.0.61" swc_atoms = {version = "0.2", path = "../../../atoms"} swc_common = {version = "0.10.10", path = "../../../common"} -swc_ecma_ast = {version = "0.41.0", path = "../../ast"} -swc_ecma_parser = {version = "0.51.0", path = "../../parser"} -swc_ecma_transforms_base = {version = "0.9.0", path = "../base"} -swc_ecma_utils = {version = "0.32.0", path = "../../utils"} -swc_ecma_visit = {version = "0.27.0", path = "../../visit"} +swc_ecma_ast = {version = "0.42.0", path = "../../ast"} +swc_ecma_parser = {version = "0.52.0", path = "../../parser"} +swc_ecma_transforms_base = {version = "0.10.0", path = "../base"} +swc_ecma_utils = {version = "0.33.0", path = "../../utils"} +swc_ecma_visit = {version = "0.28.0", path = "../../visit"} [dev-dependencies] -swc_ecma_transforms_compat = {version = "0.10.1", path = "../compat"} -swc_ecma_transforms_module = {version = "0.10.1", path = "../module"} -swc_ecma_transforms_proposal = {version = "0.10.1", path = "../proposal"} -swc_ecma_transforms_react = {version = "0.11.1", path = "../react"} -swc_ecma_transforms_testing = {version = "0.9.0", path = "../testing"} -swc_ecma_transforms_typescript = {version = "0.11.1", path = "../typescript"} +swc_ecma_transforms_compat = {version = "0.11.0", path = "../compat"} +swc_ecma_transforms_module = {version = "0.11.0", path = "../module"} +swc_ecma_transforms_proposal = {version = "0.11.0", path = "../proposal"} +swc_ecma_transforms_react = {version = "0.12.0", path = "../react"} +swc_ecma_transforms_testing = {version = "0.10.0", path = "../testing"} +swc_ecma_transforms_typescript = {version = "0.12.0", path = "../typescript"} testing = {version = "0.10.0", path = "../../../testing"} diff --git a/ecmascript/transforms/proposal/Cargo.toml b/ecmascript/transforms/proposal/Cargo.toml index 6f02e1aa117..1afe87c1788 100644 --- a/ecmascript/transforms/proposal/Cargo.toml +++ b/ecmascript/transforms/proposal/Cargo.toml @@ -6,7 +6,7 @@ edition = "2018" license = "Apache-2.0/MIT" name = "swc_ecma_transforms_proposal" repository = "https://github.com/swc-project/swc.git" -version = "0.10.1" +version = "0.11.0" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html @@ -21,14 +21,14 @@ serde = {version = "1.0.118", features = ["derive"]} smallvec = "1.6.0" swc_atoms = {version = "0.2", path = "../../../atoms"} swc_common = {version = "0.10.10", path = "../../../common"} -swc_ecma_ast = {version = "0.41.0", path = "../../ast"} -swc_ecma_loader = {version = "0.2.0", path = "../../loader", optional = true} -swc_ecma_parser = {version = "0.51.0", path = "../../parser"} -swc_ecma_transforms_base = {version = "0.9.0", path = "../base"} -swc_ecma_utils = {version = "0.32.0", path = "../../utils"} -swc_ecma_visit = {version = "0.27.0", path = "../../visit"} +swc_ecma_ast = {version = "0.42.0", path = "../../ast"} +swc_ecma_loader = {version = "0.3.0", path = "../../loader", optional = true} +swc_ecma_parser = {version = "0.52.0", path = "../../parser"} +swc_ecma_transforms_base = {version = "0.10.0", path = "../base"} +swc_ecma_utils = {version = "0.33.0", path = "../../utils"} +swc_ecma_visit = {version = "0.28.0", path = "../../visit"} [dev-dependencies] -swc_ecma_transforms_compat = {version = "0.10.1", path = "../compat"} -swc_ecma_transforms_module = {version = "0.10.1", path = "../module"} -swc_ecma_transforms_testing = {version = "0.9.0", path = "../testing"} +swc_ecma_transforms_compat = {version = "0.11.0", path = "../compat"} +swc_ecma_transforms_module = {version = "0.11.0", path = "../module"} +swc_ecma_transforms_testing = {version = "0.10.0", path = "../testing"} diff --git a/ecmascript/transforms/react/Cargo.toml b/ecmascript/transforms/react/Cargo.toml index 672e0ffaae0..20ba12aecca 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.11.2" +version = "0.12.0" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] @@ -18,14 +18,14 @@ serde = {version = "1.0.118", features = ["derive"]} string_enum = {version = "0.3.1", path = "../../../macros/string_enum"} swc_atoms = {version = "0.2", path = "../../../atoms"} swc_common = {version = "0.10.10", path = "../../../common"} -swc_ecma_ast = {version = "0.41.0", path = "../../ast"} -swc_ecma_parser = {version = "0.51.0", path = "../../parser"} -swc_ecma_transforms_base = {version = "0.9.0", path = "../base"} -swc_ecma_utils = {version = "0.32.0", path = "../../utils"} -swc_ecma_visit = {version = "0.27.0", path = "../../visit"} +swc_ecma_ast = {version = "0.42.0", path = "../../ast"} +swc_ecma_parser = {version = "0.52.0", path = "../../parser"} +swc_ecma_transforms_base = {version = "0.10.0", path = "../base"} +swc_ecma_utils = {version = "0.33.0", path = "../../utils"} +swc_ecma_visit = {version = "0.28.0", path = "../../visit"} [dev-dependencies] -swc_ecma_transforms_compat = {version = "0.10.1", path = "../compat/"} -swc_ecma_transforms_module = {version = "0.10.1", path = "../module"} -swc_ecma_transforms_testing = {version = "0.9.0", path = "../testing/"} +swc_ecma_transforms_compat = {version = "0.11.0", path = "../compat/"} +swc_ecma_transforms_module = {version = "0.11.0", path = "../module"} +swc_ecma_transforms_testing = {version = "0.10.0", path = "../testing/"} testing = {version = "0.10.3", path = "../../../testing"} diff --git a/ecmascript/transforms/testing/Cargo.toml b/ecmascript/transforms/testing/Cargo.toml index cd24a4be98c..0ea213040c2 100644 --- a/ecmascript/transforms/testing/Cargo.toml +++ b/ecmascript/transforms/testing/Cargo.toml @@ -6,7 +6,7 @@ edition = "2018" license = "Apache-2.0/MIT" name = "swc_ecma_transforms_testing" repository = "https://github.com/swc-project/swc.git" -version = "0.9.0" +version = "0.10.0" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html @@ -15,11 +15,11 @@ ansi_term = "0.12.1" serde = "1" serde_json = "1" swc_common = {version = "0.10.10", path = "../../../common"} -swc_ecma_ast = {version = "0.41.0", path = "../../ast"} -swc_ecma_codegen = {version = "0.49.0", path = "../../codegen"} -swc_ecma_parser = {version = "0.51.0", path = "../../parser"} -swc_ecma_transforms_base = {version = "0.9.0", path = "../base"} -swc_ecma_utils = {version = "0.32.0", path = "../../utils"} -swc_ecma_visit = {version = "0.27.0", path = "../../visit"} +swc_ecma_ast = {version = "0.42.0", path = "../../ast"} +swc_ecma_codegen = {version = "0.50.0", path = "../../codegen"} +swc_ecma_parser = {version = "0.52.0", path = "../../parser"} +swc_ecma_transforms_base = {version = "0.10.0", path = "../base"} +swc_ecma_utils = {version = "0.33.0", path = "../../utils"} +swc_ecma_visit = {version = "0.28.0", path = "../../visit"} tempfile = "3.1.0" testing = {version = "0.10.3", path = "../../../testing"} diff --git a/ecmascript/transforms/typescript/Cargo.toml b/ecmascript/transforms/typescript/Cargo.toml index 8095dd534d2..2206492002a 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.11.3" +version = "0.12.0" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] @@ -14,17 +14,17 @@ fxhash = "0.2.1" serde = {version = "1.0.118", features = ["derive"]} swc_atoms = {version = "0.2", path = "../../../atoms"} swc_common = {version = "0.10.10", path = "../../../common"} -swc_ecma_ast = {version = "0.41.0", path = "../../ast"} -swc_ecma_parser = {version = "0.51.0", path = "../../parser"} -swc_ecma_transforms_base = {version = "0.9.0", path = "../base"} -swc_ecma_utils = {version = "0.32.0", path = "../../utils"} -swc_ecma_visit = {version = "0.27.0", path = "../../visit"} +swc_ecma_ast = {version = "0.42.0", path = "../../ast"} +swc_ecma_parser = {version = "0.52.0", path = "../../parser"} +swc_ecma_transforms_base = {version = "0.10.0", path = "../base"} +swc_ecma_utils = {version = "0.33.0", path = "../../utils"} +swc_ecma_visit = {version = "0.28.0", path = "../../visit"} [dev-dependencies] -swc_ecma_codegen = {version = "0.49.0", path = "../../codegen"} -swc_ecma_transforms_compat = {version = "0.10.1", path = "../compat"} -swc_ecma_transforms_module = {version = "0.10.1", path = "../module"} -swc_ecma_transforms_proposal = {version = "0.10.1", path = "../proposal/"} -swc_ecma_transforms_testing = {version = "0.9.0", path = "../testing"} +swc_ecma_codegen = {version = "0.50.0", path = "../../codegen"} +swc_ecma_transforms_compat = {version = "0.11.0", path = "../compat"} +swc_ecma_transforms_module = {version = "0.11.0", path = "../module"} +swc_ecma_transforms_proposal = {version = "0.11.0", path = "../proposal/"} +swc_ecma_transforms_testing = {version = "0.10.0", path = "../testing"} testing = {version = "0.10.3", path = "../../../testing"} walkdir = "2.3.1" diff --git a/ecmascript/transforms/typescript/src/strip.rs b/ecmascript/transforms/typescript/src/strip.rs index d8b1430defa..29122a98ac6 100644 --- a/ecmascript/transforms/typescript/src/strip.rs +++ b/ecmascript/transforms/typescript/src/strip.rs @@ -878,7 +878,7 @@ impl Strip { /// Returns `(var_decl, init)`. fn handle_ts_module(&mut self, module: TsModuleDecl) -> Option<(Option, Stmt)> { - if module.global { + if module.global || module.declare { return None; } let module_span = module.span; diff --git a/ecmascript/transforms/typescript/tests/strip.rs b/ecmascript/transforms/typescript/tests/strip.rs index ac6556108d0..6bdac107c44 100644 --- a/ecmascript/transforms/typescript/tests/strip.rs +++ b/ecmascript/transforms/typescript/tests/strip.rs @@ -3674,3 +3674,35 @@ to!( _class); " ); + +to!( + issue_1508_1, + " + declare namespace twttr { + export const txt: typeof import('twitter-text') + } + ", + "" +); + +to!( + issue_1517_1, + " + interface X { + get foo(): string; + set foo(v: string | number); + } + ", + "" +); + +to!( + issue_1517_2, + " + type Y = { + get bar(): string; + set bar(v: string | number); + } + ", + "" +); diff --git a/ecmascript/utils/Cargo.toml b/ecmascript/utils/Cargo.toml index 4366c5fda8f..a18a66916a9 100644 --- a/ecmascript/utils/Cargo.toml +++ b/ecmascript/utils/Cargo.toml @@ -6,7 +6,7 @@ edition = "2018" license = "Apache-2.0/MIT" name = "swc_ecma_utils" repository = "https://github.com/swc-project/swc.git" -version = "0.32.0" +version = "0.33.0" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html @@ -15,8 +15,8 @@ once_cell = "1" scoped-tls = "1" swc_atoms = {version = "0.2.0", path = "../../atoms"} swc_common = {version = "0.10.10", path = "../../common"} -swc_ecma_ast = {version = "0.41.0", path = "../ast"} -swc_ecma_visit = {version = "0.27.0", path = "../visit"} +swc_ecma_ast = {version = "0.42.0", path = "../ast"} +swc_ecma_visit = {version = "0.28.0", path = "../visit"} unicode-xid = "0.2" [dev-dependencies] diff --git a/ecmascript/visit/Cargo.toml b/ecmascript/visit/Cargo.toml index 0c8f8770c4e..91b062a3e2a 100644 --- a/ecmascript/visit/Cargo.toml +++ b/ecmascript/visit/Cargo.toml @@ -6,11 +6,11 @@ edition = "2018" license = "Apache-2.0/MIT" name = "swc_ecma_visit" repository = "https://github.com/swc-project/swc.git" -version = "0.27.0" +version = "0.28.0" [dependencies] num-bigint = {version = "0.2", features = ["serde"]} swc_atoms = {version = "0.2", path = "../../atoms"} swc_common = {version = "0.10.10", path = "../../common"} -swc_ecma_ast = {version = "0.41.0", path = "../ast"} +swc_ecma_ast = {version = "0.42.0", path = "../ast"} swc_visit = {version = "0.2.3", path = "../../visit"} diff --git a/ecmascript/visit/src/lib.rs b/ecmascript/visit/src/lib.rs index c8df50aa5d8..1f6c5605aab 100644 --- a/ecmascript/visit/src/lib.rs +++ b/ecmascript/visit/src/lib.rs @@ -1309,6 +1309,8 @@ define!({ TsCallSignatureDecl(TsCallSignatureDecl), TsConstructSignatureDecl(TsConstructSignatureDecl), TsPropertySignature(TsPropertySignature), + TsGetterSignature(TsGetterSignature), + TsSetterSignature(TsSetterSignature), TsMethodSignature(TsMethodSignature), TsIndexSignature(TsIndexSignature), } @@ -1335,6 +1337,24 @@ define!({ pub type_ann: Option, pub type_params: Option, } + + pub struct TsGetterSignature { + pub span: Span, + pub readonly: bool, + pub key: Box, + pub computed: bool, + pub optional: bool, + pub type_ann: Option, + } + + pub struct TsSetterSignature { + pub span: Span, + pub readonly: bool, + pub key: Box, + pub computed: bool, + pub optional: bool, + pub param: TsFnParam, + } pub struct TsMethodSignature { pub span: Span, pub readonly: bool, diff --git a/package.json b/package.json index 403cc850edc..62e777f840f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@swc/core", - "version": "1.2.51", + "version": "1.2.52", "description": "Super-fast alternative for babel", "homepage": "https://swc.rs", "main": "./index.js", diff --git a/tests/fixture/issue-1454/case1/input/.swcrc b/tests/fixture/issue-1454/case1/input/.swcrc new file mode 100644 index 00000000000..82a5bce80ce --- /dev/null +++ b/tests/fixture/issue-1454/case1/input/.swcrc @@ -0,0 +1,24 @@ +{ + "test": ".*.ts$", + "jsc": { + "loose": true, + "target": "es2018", + "parser": { + "syntax": "typescript", + "tsx": false, + "decorators": true, + "dynamicImport": true + }, + "transform": { + "legacyDecorator": true, + "decoratorMetadata": true + } + }, + "module": { + "type": "commonjs", + "strict": true, + "strictMode": false, + "lazy": false, + "noInterop": false + } +} diff --git a/tests/fixture/issue-1454/case1/input/index.ts b/tests/fixture/issue-1454/case1/input/index.ts new file mode 100644 index 00000000000..5c7f41db3d5 --- /dev/null +++ b/tests/fixture/issue-1454/case1/input/index.ts @@ -0,0 +1,2 @@ +export abstract class AbstractProviderDeliveryService { +} \ No newline at end of file diff --git a/tests/fixture/issue-1454/case1/output/index.ts b/tests/fixture/issue-1454/case1/output/index.ts new file mode 100644 index 00000000000..11efcb9c617 --- /dev/null +++ b/tests/fixture/issue-1454/case1/output/index.ts @@ -0,0 +1,3 @@ +class AbstractProviderDeliveryService { +} +exports.AbstractProviderDeliveryService = AbstractProviderDeliveryService; diff --git a/tests/fixture/issue-1488/input/index.js b/tests/fixture/issue-1488/input/index.js new file mode 100644 index 00000000000..44d5b04046d --- /dev/null +++ b/tests/fixture/issue-1488/input/index.js @@ -0,0 +1 @@ +`\`` \ No newline at end of file diff --git a/tests/fixture/issue-1488/output/index.js b/tests/fixture/issue-1488/output/index.js new file mode 100644 index 00000000000..c7128984d6d --- /dev/null +++ b/tests/fixture/issue-1488/output/index.js @@ -0,0 +1 @@ +"`"; diff --git a/tests/fixture/issue-1490/case1/input/.swcrc b/tests/fixture/issue-1490/case1/input/.swcrc new file mode 100644 index 00000000000..89600e04898 --- /dev/null +++ b/tests/fixture/issue-1490/case1/input/.swcrc @@ -0,0 +1,11 @@ +{ + "jsc": { + "parser": { + "syntax": "ecmascript", + "jsx": true + } + }, + "module": { + "type": "commonjs" + } +} diff --git a/tests/fixture/issue-1490/case1/input/index.js b/tests/fixture/issue-1490/case1/input/index.js new file mode 100644 index 00000000000..b4e68504e54 --- /dev/null +++ b/tests/fixture/issue-1490/case1/input/index.js @@ -0,0 +1,6 @@ +class ColouredCanvasElement extends CanvasElement { + createFacets(hidden) { + hidden = super.createFacets(hidden); + + } +} diff --git a/tests/fixture/issue-1490/case1/output/index.js b/tests/fixture/issue-1490/case1/output/index.js new file mode 100644 index 00000000000..c79a35ff0ce --- /dev/null +++ b/tests/fixture/issue-1490/case1/output/index.js @@ -0,0 +1,101 @@ +"use strict"; +function _assertThisInitialized(self) { + if (self === void 0) { + throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + } + return self; +} +function _classCallCheck(instance, Constructor) { + if (!(instance instanceof Constructor)) { + throw new TypeError("Cannot call a class as a function"); + } +} +function _defineProperties(target, props) { + for(var i = 0; i < props.length; i++){ + var descriptor = props[i]; + descriptor.enumerable = descriptor.enumerable || false; + descriptor.configurable = true; + if ("value" in descriptor) descriptor.writable = true; + Object.defineProperty(target, descriptor.key, descriptor); + } +} +function _createClass(Constructor, protoProps, staticProps) { + if (protoProps) _defineProperties(Constructor.prototype, protoProps); + if (staticProps) _defineProperties(Constructor, staticProps); + return Constructor; +} +function _get(target, property, receiver) { + if (typeof Reflect !== "undefined" && Reflect.get) { + _get = Reflect.get; + } else { + _get = function _get(target, property, receiver) { + var base = _superPropBase(target, property); + if (!base) return; + var desc = Object.getOwnPropertyDescriptor(base, property); + if (desc.get) { + return desc.get.call(receiver); + } + return desc.value; + }; + } + return _get(target, property, receiver || target); +} +function _getPrototypeOf(o) { + _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { + return o.__proto__ || Object.getPrototypeOf(o); + }; + return _getPrototypeOf(o); +} +function _inherits(subClass, superClass) { + if (typeof superClass !== "function" && superClass !== null) { + throw new TypeError("Super expression must either be null or a function"); + } + subClass.prototype = Object.create(superClass && superClass.prototype, { + constructor: { + value: subClass, + writable: true, + configurable: true + } + }); + if (superClass) _setPrototypeOf(subClass, superClass); +} +function _possibleConstructorReturn(self, call) { + if (call && (_typeof(call) === "object" || typeof call === "function")) { + return call; + } + return _assertThisInitialized(self); +} +function _setPrototypeOf(o, p) { + _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { + o.__proto__ = p; + return o; + }; + return _setPrototypeOf(o, p); +} +function _superPropBase(object, property) { + while(!Object.prototype.hasOwnProperty.call(object, property)){ + object = _getPrototypeOf(object); + if (object === null) break; + } + return object; +} +var _typeof = function(obj) { + return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; +}; +var ColouredCanvasElement = function(CanvasElement) { + "use strict"; + _inherits(ColouredCanvasElement, CanvasElement); + function ColouredCanvasElement() { + _classCallCheck(this, ColouredCanvasElement); + return _possibleConstructorReturn(this, _getPrototypeOf(ColouredCanvasElement).apply(this, arguments)); + } + _createClass(ColouredCanvasElement, [ + { + key: "createFacets", + value: function createFacets(hidden) { + hidden = _get(_getPrototypeOf(ColouredCanvasElement.prototype), "createFacets", this).call(this, hidden); + } + } + ]); + return ColouredCanvasElement; +}(CanvasElement); diff --git a/tests/fixture/issue-1490/full/input/.swcrc b/tests/fixture/issue-1490/full/input/.swcrc new file mode 100644 index 00000000000..89600e04898 --- /dev/null +++ b/tests/fixture/issue-1490/full/input/.swcrc @@ -0,0 +1,11 @@ +{ + "jsc": { + "parser": { + "syntax": "ecmascript", + "jsx": true + } + }, + "module": { + "type": "commonjs" + } +} diff --git a/tests/fixture/issue-1490/full/input/index.js b/tests/fixture/issue-1490/full/input/index.js new file mode 100644 index 00000000000..77d36b0876b --- /dev/null +++ b/tests/fixture/issue-1490/full/input/index.js @@ -0,0 +1,35 @@ +"use strict"; + +class Element { + getChildElements() { + return this.childElements; + } +} + +class CanvasElement extends Element { + createFacets(hidden) { + const childElements = this.getChildElements(); + + /// + } +} + +class ColouredCanvasElement extends CanvasElement { + createFacets(hidden) { + hidden = super.createFacets(hidden); /// + + /// + } +} + +class ColouredSquare extends ColouredCanvasElement { } + +const bugExample = () => { + + const colouredSquare = new ColouredSquare(), + hidden = false; + + colouredSquare.createFacets(hidden); +} + +bugExample() diff --git a/tests/fixture/issue-1490/full/output/index.js b/tests/fixture/issue-1490/full/output/index.js new file mode 100644 index 00000000000..9b5b376e8cd --- /dev/null +++ b/tests/fixture/issue-1490/full/output/index.js @@ -0,0 +1,201 @@ +"use strict"; +function _assertThisInitialized(self) { + if (self === void 0) { + throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + } + return self; +} +function _classCallCheck(instance, Constructor) { + if (!(instance instanceof Constructor)) { + throw new TypeError("Cannot call a class as a function"); + } +} +function isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Date.prototype.toString.call(Reflect.construct(Date, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _construct(Parent, args, Class) { + if (isNativeReflectConstruct()) { + _construct = Reflect.construct; + } else { + _construct = function _construct(Parent, args, Class) { + var a = [ + null + ]; + a.push.apply(a, args); + var Constructor = Function.bind.apply(Parent, a); + var instance = new Constructor(); + if (Class) _setPrototypeOf(instance, Class.prototype); + return instance; + }; + } + return _construct.apply(null, arguments); +} +function _defineProperties(target, props) { + for(var i = 0; i < props.length; i++){ + var descriptor = props[i]; + descriptor.enumerable = descriptor.enumerable || false; + descriptor.configurable = true; + if ("value" in descriptor) descriptor.writable = true; + Object.defineProperty(target, descriptor.key, descriptor); + } +} +function _createClass(Constructor, protoProps, staticProps) { + if (protoProps) _defineProperties(Constructor.prototype, protoProps); + if (staticProps) _defineProperties(Constructor, staticProps); + return Constructor; +} +function _get(target, property, receiver) { + if (typeof Reflect !== "undefined" && Reflect.get) { + _get = Reflect.get; + } else { + _get = function _get(target, property, receiver) { + var base = _superPropBase(target, property); + if (!base) return; + var desc = Object.getOwnPropertyDescriptor(base, property); + if (desc.get) { + return desc.get.call(receiver); + } + return desc.value; + }; + } + return _get(target, property, receiver || target); +} +function _getPrototypeOf(o) { + _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { + return o.__proto__ || Object.getPrototypeOf(o); + }; + return _getPrototypeOf(o); +} +function _inherits(subClass, superClass) { + if (typeof superClass !== "function" && superClass !== null) { + throw new TypeError("Super expression must either be null or a function"); + } + subClass.prototype = Object.create(superClass && superClass.prototype, { + constructor: { + value: subClass, + writable: true, + configurable: true + } + }); + if (superClass) _setPrototypeOf(subClass, superClass); +} +function _isNativeFunction(fn) { + return Function.toString.call(fn).indexOf("[native code]") !== -1; +} +function _possibleConstructorReturn(self, call) { + if (call && (_typeof(call) === "object" || typeof call === "function")) { + return call; + } + return _assertThisInitialized(self); +} +function _setPrototypeOf(o, p) { + _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { + o.__proto__ = p; + return o; + }; + return _setPrototypeOf(o, p); +} +function _superPropBase(object, property) { + while(!Object.prototype.hasOwnProperty.call(object, property)){ + object = _getPrototypeOf(object); + if (object === null) break; + } + return object; +} +var _typeof = function(obj) { + return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; +}; +function _wrapNativeSuper(Class) { + var _cache = typeof Map === "function" ? new Map() : undefined; + _wrapNativeSuper = function _wrapNativeSuper(Class) { + if (Class === null || !_isNativeFunction(Class)) return Class; + if (typeof Class !== "function") { + throw new TypeError("Super expression must either be null or a function"); + } + if (typeof _cache !== "undefined") { + if (_cache.has(Class)) return _cache.get(Class); + _cache.set(Class, Wrapper); + } + function Wrapper() { + return _construct(Class, arguments, _getPrototypeOf(this).constructor); + } + Wrapper.prototype = Object.create(Class.prototype, { + constructor: { + value: Wrapper, + enumerable: false, + writable: true, + configurable: true + } + }); + return _setPrototypeOf(Wrapper, Class); + }; + return _wrapNativeSuper(Class); +} +var Element1 = function() { + function Element1() { + _classCallCheck(this, Element1); + } + _createClass(Element1, [ + { + key: "getChildElements", + value: function getChildElements() { + return this.childElements; + } + } + ]); + return Element1; +}(); +var CanvasElement = function(Element1) { + _inherits(CanvasElement, Element1); + function CanvasElement() { + _classCallCheck(this, CanvasElement); + return _possibleConstructorReturn(this, _getPrototypeOf(CanvasElement).apply(this, arguments)); + } + _createClass(CanvasElement, [ + { + key: "createFacets", + value: function createFacets(hidden) { + var childElements = this.getChildElements(); + } + } + ]); + return CanvasElement; +}(_wrapNativeSuper(Element1)); +var ColouredCanvasElement = function(CanvasElement) { + _inherits(ColouredCanvasElement, CanvasElement); + function ColouredCanvasElement() { + _classCallCheck(this, ColouredCanvasElement); + return _possibleConstructorReturn(this, _getPrototypeOf(ColouredCanvasElement).apply(this, arguments)); + } + _createClass(ColouredCanvasElement, [ + { + key: "createFacets", + value: function createFacets(hidden) { + hidden = _get(_getPrototypeOf(ColouredCanvasElement.prototype), "createFacets", this).call(this, hidden); /// + } + } + ]); + return ColouredCanvasElement; +}(CanvasElement); +var ColouredSquare = function(ColouredCanvasElement) { + _inherits(ColouredSquare, ColouredCanvasElement); + function ColouredSquare() { + _classCallCheck(this, ColouredSquare); + return _possibleConstructorReturn(this, _getPrototypeOf(ColouredSquare).apply(this, arguments)); + } + return ColouredSquare; +}(ColouredCanvasElement); +var bugExample = function() { + var colouredSquare = new ColouredSquare(), hidden = false; + colouredSquare.createFacets(hidden); +}; +bugExample(); diff --git a/tests/fixture/issue-1508/case1/input/.swcrc b/tests/fixture/issue-1508/case1/input/.swcrc new file mode 100644 index 00000000000..37fc02df6a7 --- /dev/null +++ b/tests/fixture/issue-1508/case1/input/.swcrc @@ -0,0 +1,8 @@ +{ + "jsc": { + "parser": { + "syntax": "typescript" + }, + "target": "es2019" + } +} diff --git a/tests/fixture/issue-1508/case1/input/index.ts b/tests/fixture/issue-1508/case1/input/index.ts new file mode 100644 index 00000000000..34cdd6a3e8e --- /dev/null +++ b/tests/fixture/issue-1508/case1/input/index.ts @@ -0,0 +1,3 @@ +declare namespace twttr { + export const txt: typeof import('twitter-text') +} \ No newline at end of file diff --git a/wasm/Cargo.toml b/wasm/Cargo.toml index 136a4ca2730..952cc47322b 100644 --- a/wasm/Cargo.toml +++ b/wasm/Cargo.toml @@ -5,7 +5,7 @@ edition = "2018" license = "Apache-2.0/MIT" name = "wasm" repository = "https://github.com/swc-project/swc.git" -version = "1.2.51" +version = "1.2.52" [lib] crate-type = ["cdylib"]