diff --git a/ecmascript/ast/Cargo.toml b/ecmascript/ast/Cargo.toml index 311fe7d43f4..50c4662e31f 100644 --- a/ecmascript/ast/Cargo.toml +++ b/ecmascript/ast/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "swc_ecma_ast" -version = "0.16.0" +version = "0.17.0" authors = ["강동윤 "] license = "Apache-2.0/MIT" repository = "https://github.com/swc-project/swc.git" diff --git a/ecmascript/codegen/Cargo.toml b/ecmascript/codegen/Cargo.toml index 1365bf34d31..3c64c75333a 100644 --- a/ecmascript/codegen/Cargo.toml +++ b/ecmascript/codegen/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "swc_ecma_codegen" -version = "0.15.0" +version = "0.16.0" authors = ["강동윤 "] license = "Apache-2.0/MIT" repository = "https://github.com/swc-project/swc.git" @@ -13,11 +13,11 @@ bitflags = "1" hashbrown = "0.6" swc_atoms = { version = "0.2", path ="../../atoms" } swc_common = { version = "0.5", path ="../../common" } -swc_ecma_ast = { version = "0.16.0", path ="../ast" } +swc_ecma_ast = { version = "0.17.0", path ="../ast" } swc_ecma_codegen_macros = { version = "0.4", path ="./macros" } sourcemap = "4.1.1" num-bigint = { version = "0.2", features = ["serde"] } [dev-dependencies] testing = { version = "0.5", path ="../../testing" } -swc_ecma_parser = { version = "0.18", path ="../parser" } \ No newline at end of file +swc_ecma_parser = { version = "0.19", path ="../parser" } \ No newline at end of file diff --git a/ecmascript/parser/Cargo.toml b/ecmascript/parser/Cargo.toml index ebfe6939cef..abb583e9283 100644 --- a/ecmascript/parser/Cargo.toml +++ b/ecmascript/parser/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "swc_ecma_parser" -version = "0.18.1" +version = "0.19.0" authors = ["강동윤 "] license = "Apache-2.0/MIT" repository = "https://github.com/swc-project/swc.git" @@ -18,7 +18,7 @@ verify = ["fold"] [dependencies] swc_atoms = { version = "0.2", path ="../../atoms" } swc_common = { version = "0.5.0", path ="../../common" } -swc_ecma_ast = { version = "0.16.0", path ="../ast" } +swc_ecma_ast = { version = "0.17.0", path ="../ast" } swc_ecma_parser_macros = { version = "0.4", path ="./macros" } enum_kind = { version = "0.2", path ="../../macros/enum_kind" } unicode-xid = "0.2" diff --git a/ecmascript/parser/src/lib.rs b/ecmascript/parser/src/lib.rs index 6f7eb93605f..5d71aaf6866 100644 --- a/ecmascript/parser/src/lib.rs +++ b/ecmascript/parser/src/lib.rs @@ -330,7 +330,7 @@ pub enum JscTarget { impl Default for JscTarget { fn default() -> Self { - JscTarget::Es3 + JscTarget::Es5 } } diff --git a/ecmascript/transforms/Cargo.toml b/ecmascript/transforms/Cargo.toml index 3219bd95bec..091b58ff7fb 100644 --- a/ecmascript/transforms/Cargo.toml +++ b/ecmascript/transforms/Cargo.toml @@ -11,9 +11,9 @@ edition = "2018" [dependencies] swc_atoms = { version = "0.2.0", path ="../../atoms" } swc_common = { version = "0.5.0", path ="../../common" } -swc_ecma_ast = { version = "0.16.0", path ="../ast" } +swc_ecma_ast = { version = "0.17.0", path ="../ast" } swc_ecma_utils = { version = "0.3.0", path ="../utils" } -swc_ecma_parser = { version = "0.18", path ="../parser", features = ["verify"] } +swc_ecma_parser = { version = "0.19", path ="../parser", features = ["verify"] } dashmap = "=3.4.0" either = "1.5" fxhash = "0.2" @@ -33,7 +33,7 @@ is-macro = "0.1" [dev-dependencies] testing = { version = "0.5", path ="../../testing" } -swc_ecma_codegen = { version = "0.15.0", path ="../codegen" } +swc_ecma_codegen = { version = "0.16.0", path ="../codegen" } tempfile = "3" pretty_assertions = "0.6" sourcemap = "4.1.1" diff --git a/ecmascript/transforms/src/typescript.rs b/ecmascript/transforms/src/typescript.rs index 2d16a8cdca6..cc9268db52e 100644 --- a/ecmascript/transforms/src/typescript.rs +++ b/ecmascript/transforms/src/typescript.rs @@ -623,6 +623,7 @@ impl Fold for Strip { Expr::TsAs(TsAsExpr { expr, .. }) => validate!(*expr), Expr::TsNonNull(TsNonNullExpr { expr, .. }) => validate!(*expr), Expr::TsTypeAssertion(TsTypeAssertion { expr, .. }) => validate!(*expr), + Expr::TsConstAssertion(TsConstAssertion { expr, .. }) => validate!(*expr), Expr::TsTypeCast(TsTypeCastExpr { expr, .. }) => validate!(*expr), _ => validate!(expr), } diff --git a/ecmascript/transforms/tests/typescript_strip.rs b/ecmascript/transforms/tests/typescript_strip.rs index 51e14f110f2..e7d86c22fab 100644 --- a/ecmascript/transforms/tests/typescript_strip.rs +++ b/ecmascript/transforms/tests/typescript_strip.rs @@ -321,3 +321,12 @@ export const handler: Handler = async (event, context) => {};", "export const handler = async (event, context) => {};", ok_if_code_eq ); + +test!( + ::swc_ecma_parser::Syntax::Typescript(Default::default()), + |_| strip(), + issue_656, + "export const x = { text: 'hello' } as const;", + "export const x = { text: 'hello' };", + ok_if_code_eq +); diff --git a/ecmascript/utils/Cargo.toml b/ecmascript/utils/Cargo.toml index 2aba3c01e04..f0c9b5438c6 100644 --- a/ecmascript/utils/Cargo.toml +++ b/ecmascript/utils/Cargo.toml @@ -11,10 +11,10 @@ edition = "2018" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -swc_ecma_ast = { version = "0.16.0", path ="../ast" } +swc_ecma_ast = { version = "0.17.0", path ="../ast" } swc_atoms = { version = "0.2.0", path ="../../atoms" } swc_common = { version = "0.5.0", path ="../../common" } -swc_ecma_parser = { version = "0.18", path ="../parser", features = ["verify"] } +swc_ecma_parser = { version = "0.19", path ="../parser", features = ["verify"] } once_cell = "1" scoped-tls = "1" unicode-xid = "0.2" diff --git a/src/config.rs b/src/config.rs index 037e86d5fbc..020379dbd83 100644 --- a/src/config.rs +++ b/src/config.rs @@ -16,7 +16,7 @@ use swc_common::{errors::Handler, FileName, SourceMap}; pub use swc_ecmascript::parser::JscTarget; use swc_ecmascript::{ ast::{Expr, ExprStmt, ModuleItem, Stmt}, - parser::{lexer::Lexer, Parser, Session as ParseSess, SourceFileInput, Syntax}, + parser::{lexer::Lexer, Parser, Session as ParseSess, SourceFileInput, Syntax, TsConfig}, preset_env, transforms::{ const_modules, modules, @@ -278,16 +278,71 @@ fn default_cwd() -> PathBuf { } /// `.swcrc` file -#[derive(Clone, Deserialize)] -#[serde(untagged)] +#[derive(Debug, Clone, Deserialize)] +#[serde(untagged, rename = "swcrc")] pub enum Rc { Single(Config), Multi(Vec), } +impl Default for Rc { + fn default() -> Self { + Rc::Multi(vec![ + Config { + env: None, + test: None, + exclude: Some(FileMatcher::Regex("\\.tsx?$".into())), + jsc: JscConfig { + syntax: Some(Default::default()), + transform: None, + external_helpers: false, + target: Default::default(), + loose: false, + }, + module: None, + minify: None, + }, + Config { + env: None, + test: Some(FileMatcher::Regex("\\.tsx$".into())), + exclude: None, + jsc: JscConfig { + syntax: Some(Syntax::Typescript(TsConfig { + tsx: true, + ..Default::default() + })), + transform: None, + external_helpers: false, + target: Default::default(), + loose: false, + }, + module: None, + minify: None, + }, + Config { + env: None, + test: Some(FileMatcher::Regex("\\.ts$".into())), + exclude: None, + jsc: JscConfig { + syntax: Some(Syntax::Typescript(TsConfig { + tsx: false, + ..Default::default() + })), + transform: None, + external_helpers: false, + target: Default::default(), + loose: false, + }, + module: None, + minify: None, + }, + ]) + } +} + impl Rc { pub fn into_config(self, filename: Option<&Path>) -> Result { - let cs = match self { + let mut cs = match self { Rc::Single(c) => match filename { Some(filename) => { if c.matches(filename)? { @@ -311,20 +366,7 @@ impl Rc { } } // TODO - None => { - let mut first = None; - for c in cs { - if c.test.is_none() { - return Ok(c); - } - - if first.is_none() { - first = Some(c); - } - } - - return Ok(first.unwrap_or_default()); - } + None => return Ok(cs.remove(0)), } Err(Error::Unmatched) diff --git a/src/lib.rs b/src/lib.rs index 33f14942677..4cda9f8f9d9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -258,15 +258,14 @@ impl Compiler { } } - if let Some(config_file) = config_file { - let built = opts.build( - &self.cm, - &self.handler, - *is_module, - Some(config_file.into_config(Some(path))?), - ); - return Ok(built); - } + let config_file = config_file.unwrap_or_else(|| Rc::default()); + let built = opts.build( + &self.cm, + &self.handler, + *is_module, + Some(config_file.into_config(Some(path))?), + ); + return Ok(built); } _ => {} } @@ -277,7 +276,7 @@ impl Compiler { *is_module, match config_file { Some(config_file) => Some(config_file.into_config(None)?), - None => None, + None => Some(Rc::default().into_config(None)?), }, ); Ok(built) diff --git a/tests/projects.rs b/tests/projects.rs index 628e15c06ca..ca6de288f8b 100644 --- a/tests/projects.rs +++ b/tests/projects.rs @@ -370,3 +370,13 @@ fn await_expr_2() { assert!(f.contains("await")); assert!(f.contains("test")); } + +#[test] +fn default_config() { + project("tests/projects/issue-655") +} + +#[test] +fn issue_658() { + project("tests/projects/issue-658") +} diff --git a/tests/projects/issue-655/index.js b/tests/projects/issue-655/index.js new file mode 100644 index 00000000000..576000ea446 --- /dev/null +++ b/tests/projects/issue-655/index.js @@ -0,0 +1,3 @@ +class Foo { + +} \ No newline at end of file diff --git a/tests/projects/issue-655/ts.ts b/tests/projects/issue-655/ts.ts new file mode 100644 index 00000000000..20e7d424e9a --- /dev/null +++ b/tests/projects/issue-655/ts.ts @@ -0,0 +1,3 @@ +function foo(): string { + return 'Hello, world!'; +} \ No newline at end of file diff --git a/tests/projects/issue-655/tsx.tsx b/tests/projects/issue-655/tsx.tsx new file mode 100644 index 00000000000..672f92b3c39 --- /dev/null +++ b/tests/projects/issue-655/tsx.tsx @@ -0,0 +1,3 @@ +function foo(): string { + return
{'Hello, world!'}
; +} \ No newline at end of file diff --git a/tests/projects/issue-658/.swcrc b/tests/projects/issue-658/.swcrc new file mode 100644 index 00000000000..62b07815766 --- /dev/null +++ b/tests/projects/issue-658/.swcrc @@ -0,0 +1,11 @@ +{ + "test": ".*.tsx$", + "exclude": ".*.spec.tsx$", + "jsc": { + "target": "es2018", + "parser": { + "syntax": "typescript", + "tsx": true + } + } +} \ No newline at end of file diff --git a/tests/projects/issue-658/invalid.spec.tsx b/tests/projects/issue-658/invalid.spec.tsx new file mode 100644 index 00000000000..1b87b3b356f --- /dev/null +++ b/tests/projects/issue-658/invalid.spec.tsx @@ -0,0 +1,3 @@ +function foo(): string { + return 'Hello, world!'; +} \ No newline at end of file diff --git a/tests/projects/issue-658/valid.tsx b/tests/projects/issue-658/valid.tsx new file mode 100644 index 00000000000..672f92b3c39 --- /dev/null +++ b/tests/projects/issue-658/valid.tsx @@ -0,0 +1,3 @@ +function foo(): string { + return
{'Hello, world!'}
; +} \ No newline at end of file