From 6dc6d8a8474f17a1064a9da2d7744bf518f72660 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Tue, 13 Jul 2021 11:59:13 -0400 Subject: [PATCH] refactor(es/dep-graph): Remove SourceMap dependency (#1908) --- Cargo.toml | 28 +-- bundler/Cargo.toml | 22 +-- common/Cargo.toml | 2 +- common/src/comments.rs | 55 +++--- ecmascript/Cargo.toml | 18 +- ecmascript/ast/Cargo.toml | 4 +- ecmascript/codegen/Cargo.toml | 12 +- ecmascript/dep-graph/Cargo.toml | 12 +- ecmascript/dep-graph/src/lib.rs | 169 ++++++------------ ecmascript/ext-transforms/Cargo.toml | 12 +- ecmascript/jsdoc/Cargo.toml | 10 +- ecmascript/jsdoc/tests/fixture.rs | 23 ++- ecmascript/loader/Cargo.toml | 10 +- ecmascript/minifier/Cargo.toml | 20 +-- .../minifier/src/compress/optimize/util.rs | 4 +- ecmascript/parser/Cargo.toml | 10 +- ecmascript/preset-env/Cargo.toml | 18 +- ecmascript/transforms/Cargo.toml | 32 ++-- ecmascript/transforms/base/Cargo.toml | 16 +- ecmascript/transforms/classes/Cargo.toml | 12 +- ecmascript/transforms/compat/Cargo.toml | 20 +-- ecmascript/transforms/module/Cargo.toml | 22 +-- ecmascript/transforms/optimization/Cargo.toml | 28 +-- ecmascript/transforms/proposal/Cargo.toml | 24 +-- ecmascript/transforms/react/Cargo.toml | 24 +-- ecmascript/transforms/testing/Cargo.toml | 18 +- ecmascript/transforms/typescript/Cargo.toml | 26 +-- ecmascript/utils/Cargo.toml | 10 +- ecmascript/visit/Cargo.toml | 6 +- node/base/Cargo.toml | 4 +- src/lib.rs | 25 ++- testing/Cargo.toml | 4 +- 32 files changed, 347 insertions(+), 353 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index b1d555d59d91..4b5f4bdbf766 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.28.1" +version = "0.29.0" [lib] name = "swc" @@ -31,15 +31,15 @@ serde = {version = "1", features = ["derive"]} serde_json = "1" sourcemap = "6" swc_atoms = {version = "0.2", path = "./atoms"} -swc_bundler = {version = "0.45.0", path = "./bundler"} -swc_common = {version = "0.10.16", path = "./common", features = ["sourcemap", "concurrent"]} -swc_ecma_ast = {version = "0.48.0", path = "./ecmascript/ast"} -swc_ecma_codegen = {version = "0.61.0", path = "./ecmascript/codegen"} -swc_ecma_ext_transforms = {version = "0.20.0", path = "./ecmascript/ext-transforms"} -swc_ecma_loader = {version = "0.10.0", path = "./ecmascript/loader", features = ["lru", "node", "tsc"]} -swc_ecma_parser = {version = "0.62.0", path = "./ecmascript/parser"} -swc_ecma_preset_env = {version = "0.28.0", path = "./ecmascript/preset-env"} -swc_ecma_transforms = {version = "0.58.0", path = "./ecmascript/transforms", features = [ +swc_bundler = {version = "0.46.0", path = "./bundler"} +swc_common = {version = "0.11.0", path = "./common", features = ["sourcemap", "concurrent"]} +swc_ecma_ast = {version = "0.49.0", path = "./ecmascript/ast"} +swc_ecma_codegen = {version = "0.62.0", path = "./ecmascript/codegen"} +swc_ecma_ext_transforms = {version = "0.21.0", path = "./ecmascript/ext-transforms"} +swc_ecma_loader = {version = "0.11.0", path = "./ecmascript/loader", features = ["lru", "node", "tsc"]} +swc_ecma_parser = {version = "0.63.0", path = "./ecmascript/parser"} +swc_ecma_preset_env = {version = "0.29.0", path = "./ecmascript/preset-env"} +swc_ecma_transforms = {version = "0.59.0", path = "./ecmascript/transforms", features = [ "compat", "module", "optimization", @@ -47,14 +47,14 @@ swc_ecma_transforms = {version = "0.58.0", path = "./ecmascript/transforms", fea "react", "typescript", ]} -swc_ecma_utils = {version = "0.39.0", path = "./ecmascript/utils"} -swc_ecma_visit = {version = "0.34.0", path = "./ecmascript/visit"} -swc_node_base = {version = "0.1.0", path = "./node/base"} +swc_ecma_utils = {version = "0.40.0", path = "./ecmascript/utils"} +swc_ecma_visit = {version = "0.35.0", path = "./ecmascript/visit"} +swc_node_base = {version = "0.2.0", path = "./node/base"} swc_visit = {version = "0.2.3", path = "./visit"} [dev-dependencies] rayon = "1" -testing = {version = "0.10.5", path = "./testing"} +testing = {version = "0.11.0", path = "./testing"} walkdir = "2" [[example]] diff --git a/bundler/Cargo.toml b/bundler/Cargo.toml index 82c7e73911b9..6eb8e9b91a03 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.45.0" +version = "0.46.0" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [features] @@ -32,22 +32,22 @@ rayon = {version = "1", optional = true} relative-path = "1.2" retain_mut = "0.1.2" swc_atoms = {version = "0.2.4", path = "../atoms"} -swc_common = {version = "0.10.16", path = "../common"} -swc_ecma_ast = {version = "0.48.0", path = "../ecmascript/ast"} -swc_ecma_codegen = {version = "0.61.0", path = "../ecmascript/codegen"} -swc_ecma_loader = {version = "0.10.0", path = "../ecmascript/loader"} -swc_ecma_parser = {version = "0.62.0", path = "../ecmascript/parser"} -swc_ecma_transforms = {version = "0.58.0", path = "../ecmascript/transforms", features = ["optimization"]} -swc_ecma_utils = {version = "0.39.0", path = "../ecmascript/utils"} -swc_ecma_visit = {version = "0.34.0", path = "../ecmascript/visit"} +swc_common = {version = "0.11.0", path = "../common"} +swc_ecma_ast = {version = "0.49.0", path = "../ecmascript/ast"} +swc_ecma_codegen = {version = "0.62.0", path = "../ecmascript/codegen"} +swc_ecma_loader = {version = "0.11.0", path = "../ecmascript/loader"} +swc_ecma_parser = {version = "0.63.0", path = "../ecmascript/parser"} +swc_ecma_transforms = {version = "0.59.0", path = "../ecmascript/transforms", features = ["optimization"]} +swc_ecma_utils = {version = "0.40.0", path = "../ecmascript/utils"} +swc_ecma_visit = {version = "0.35.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.58.0", path = "../ecmascript/transforms", features = ["react", "typescript"]} +swc_ecma_transforms = {version = "0.59.0", path = "../ecmascript/transforms", features = ["react", "typescript"]} tempfile = "3.1.0" -testing = {version = "0.10.5", path = "../testing"} +testing = {version = "0.11.0", path = "../testing"} url = "2.1.1" walkdir = "2" diff --git a/common/Cargo.toml b/common/Cargo.toml index d6744f557856..745531170ff8 100644 --- a/common/Cargo.toml +++ b/common/Cargo.toml @@ -6,7 +6,7 @@ edition = "2018" license = "Apache-2.0/MIT" name = "swc_common" repository = "https://github.com/swc-project/swc.git" -version = "0.10.23" +version = "0.11.0" [features] concurrent = ["parking_lot"] diff --git a/common/src/comments.rs b/common/src/comments.rs index 9f6c1acf4c8b..ccf65ecbc50b 100644 --- a/common/src/comments.rs +++ b/common/src/comments.rs @@ -31,35 +31,16 @@ pub trait Comments { fn has_leading(&self, pos: BytePos) -> bool; fn move_leading(&self, from: BytePos, to: BytePos); fn take_leading(&self, pos: BytePos) -> Option>; + fn get_leading(&self, pos: BytePos) -> Option>; fn add_trailing(&self, pos: BytePos, cmt: Comment); fn add_trailing_comments(&self, pos: BytePos, comments: Vec); fn has_trailing(&self, pos: BytePos) -> bool; fn move_trailing(&self, from: BytePos, to: BytePos); fn take_trailing(&self, pos: BytePos) -> Option>; + fn get_trailing(&self, pos: BytePos) -> Option>; - fn add_pure_comment(&self, pos: BytePos) { - let mut leading = self.take_leading(pos); - let pure_comment = Comment { - kind: CommentKind::Block, - span: DUMMY_SP, - text: "#__PURE__".into(), - }; - - match &mut leading { - Some(comments) => { - if !comments.iter().any(|c| c.text == pure_comment.text) { - comments.push(pure_comment); - } - } - None => { - leading = Some(vec![pure_comment]); - } - } - if let Some(leading) = leading { - self.add_leading_comments(pos, leading); - } - } + fn add_pure_comment(&self, pos: BytePos); } macro_rules! delegate { @@ -84,6 +65,10 @@ macro_rules! delegate { (**self).take_leading(pos) } + fn get_leading(&self, pos: BytePos) -> Option> { + (**self).get_leading(pos) + } + fn add_trailing(&self, pos: BytePos, cmt: Comment) { (**self).add_trailing(pos, cmt) } @@ -104,6 +89,10 @@ macro_rules! delegate { (**self).take_trailing(pos) } + fn get_trailing(&self, pos: BytePos) -> Option> { + (**self).get_trailing(pos) + } + fn add_pure_comment(&self, pos: BytePos) { (**self).add_pure_comment(pos) } @@ -181,6 +170,10 @@ impl Comments for SingleThreadedComments { self.leading.borrow_mut().remove(&pos) } + fn get_leading(&self, pos: BytePos) -> Option> { + self.leading.borrow().get(&pos).map(|c| c.to_owned()) + } + fn add_trailing(&self, pos: BytePos, cmt: Comment) { self.trailing.borrow_mut().entry(pos).or_default().push(cmt); } @@ -216,6 +209,24 @@ impl Comments for SingleThreadedComments { fn take_trailing(&self, pos: BytePos) -> Option> { self.trailing.borrow_mut().remove(&pos) } + + fn get_trailing(&self, pos: BytePos) -> Option> { + self.trailing.borrow().get(&pos).map(|c| c.to_owned()) + } + + fn add_pure_comment(&self, pos: BytePos) { + let mut leading_map = self.leading.borrow_mut(); + let leading = leading_map.entry(pos).or_default(); + let pure_comment = Comment { + kind: CommentKind::Block, + span: DUMMY_SP, + text: "#__PURE__".into(), + }; + + if !leading.iter().any(|c| c.text == pure_comment.text) { + leading.push(pure_comment); + } + } } impl SingleThreadedComments { diff --git a/ecmascript/Cargo.toml b/ecmascript/Cargo.toml index a755fcd23cb6..c1ceb5c3ca2c 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.45.0" +version = "0.46.0" [package.metadata.docs.rs] all-features = true @@ -28,13 +28,13 @@ react = ["swc_ecma_transforms/react"] typescript = ["swc_ecma_transforms/typescript"] [dependencies] -swc_ecma_ast = {version = "0.48.0", path = "./ast"} -swc_ecma_codegen = {version = "0.61.0", path = "./codegen", optional = true} -swc_ecma_dep_graph = {version = "0.30.0", path = "./dep-graph", optional = true} -swc_ecma_minifier = {version = "0.11.0", path = "./minifier", optional = true} -swc_ecma_parser = {version = "0.62.0", path = "./parser", optional = true} -swc_ecma_transforms = {version = "0.58.0", path = "./transforms", optional = true} -swc_ecma_utils = {version = "0.39.0", path = "./utils", optional = true} -swc_ecma_visit = {version = "0.34.0", path = "./visit", optional = true} +swc_ecma_ast = {version = "0.49.0", path = "./ast"} +swc_ecma_codegen = {version = "0.62.0", path = "./codegen", optional = true} +swc_ecma_dep_graph = {version = "0.31.0", path = "./dep-graph", optional = true} +swc_ecma_minifier = {version = "0.12.0", path = "./minifier", optional = true} +swc_ecma_parser = {version = "0.63.0", path = "./parser", optional = true} +swc_ecma_transforms = {version = "0.59.0", path = "./transforms", optional = true} +swc_ecma_utils = {version = "0.40.0", path = "./utils", optional = true} +swc_ecma_visit = {version = "0.35.0", path = "./visit", optional = true} [dev-dependencies] diff --git a/ecmascript/ast/Cargo.toml b/ecmascript/ast/Cargo.toml index 77e44381b67e..a1a6c06bbbb1 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.48.1" +version = "0.49.0" [features] default = [] @@ -19,7 +19,7 @@ num-bigint = {version = "0.2", features = ["serde"]} serde = {version = "1.0.88", features = ["derive"]} string_enum = {version = "0.3.1", path = "../../macros/string_enum"} swc_atoms = {version = "0.2", path = "../../atoms"} -swc_common = {version = "0.10.16", path = "../../common"} +swc_common = {version = "0.11.0", path = "../../common"} [dev-dependencies] serde_json = "1" diff --git a/ecmascript/codegen/Cargo.toml b/ecmascript/codegen/Cargo.toml index a6c5ef160e3b..adc221c16a3a 100644 --- a/ecmascript/codegen/Cargo.toml +++ b/ecmascript/codegen/Cargo.toml @@ -7,18 +7,18 @@ include = ["Cargo.toml", "src/**/*.rs"] license = "Apache-2.0/MIT" name = "swc_ecma_codegen" repository = "https://github.com/swc-project/swc.git" -version = "0.61.1" +version = "0.62.0" [dependencies] bitflags = "1" num-bigint = {version = "0.2", features = ["serde"]} sourcemap = "6" swc_atoms = {version = "0.2", path = "../../atoms"} -swc_common = {version = "0.10.21", path = "../../common"} -swc_ecma_ast = {version = "0.48.0", path = "../ast"} +swc_common = {version = "0.11.0", path = "../../common"} +swc_ecma_ast = {version = "0.49.0", path = "../ast"} swc_ecma_codegen_macros = {version = "0.5.2", path = "./macros"} -swc_ecma_parser = {version = "0.62.0", path = "../parser"} +swc_ecma_parser = {version = "0.63.0", path = "../parser"} [dev-dependencies] -swc_common = {version = "0.10.16", path = "../../common", features = ["sourcemap"]} -testing = {version = "0.10.5", path = "../../testing"} +swc_common = {version = "0.11.0", path = "../../common", features = ["sourcemap"]} +testing = {version = "0.11.0", path = "../../testing"} diff --git a/ecmascript/dep-graph/Cargo.toml b/ecmascript/dep-graph/Cargo.toml index 49f29345db6b..feddb3d0e685 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.30.0" +version = "0.31.0" [dependencies] swc_atoms = {version = "0.2", path = "../../atoms"} -swc_common = {version = "0.10.16", path = "../../common"} -swc_ecma_ast = {version = "0.48.0", path = "../ast"} -swc_ecma_visit = {version = "0.34.0", path = "../visit"} +swc_common = {version = "0.11.0", path = "../../common"} +swc_ecma_ast = {version = "0.49.0", path = "../ast"} +swc_ecma_visit = {version = "0.35.0", path = "../visit"} [dev-dependencies] -swc_ecma_parser = {version = "0.62.0", path = "../parser"} -testing = {version = "0.10.5", path = "../../testing"} +swc_ecma_parser = {version = "0.63.0", path = "../parser"} +testing = {version = "0.11.0", path = "../../testing"} diff --git a/ecmascript/dep-graph/src/lib.rs b/ecmascript/dep-graph/src/lib.rs index 422f9c630035..32ff56291a83 100644 --- a/ecmascript/dep-graph/src/lib.rs +++ b/ecmascript/dep-graph/src/lib.rs @@ -1,20 +1,18 @@ use std::collections::HashMap; use swc_atoms::JsWord; use swc_common::{ - comments::{Comment, SingleThreadedComments}, - Loc, SourceMap, Span, DUMMY_SP, + comments::{Comment, Comments}, + Span, DUMMY_SP, }; use swc_ecma_ast as ast; use swc_ecma_visit::{self, Node, Visit, VisitWith}; pub fn analyze_dependencies( module: &ast::Module, - source_map: &SourceMap, - comments: &SingleThreadedComments, + comments: &impl Comments, ) -> Vec { let mut v = DependencyCollector { comments, - source_map, items: vec![], is_top_level: true, }; @@ -39,46 +37,35 @@ pub struct DependencyDescriptor { /// Any leading comments associated with the dependency. This is used for /// further processing of supported pragma that impact the dependency. pub leading_comments: Vec, - /// The location of the import/export statement. - pub line: usize, - pub col: usize, + /// The span of the import/export statement. + pub span: Span, /// The text specifier associated with the import/export statement. pub specifier: JsWord, - /// The location of the specifier. - pub specifier_line: usize, - pub specifier_col: usize, + /// The span of the specifier. + pub specifier_span: Span, /// Import assertions for this dependency. /// NOTE: it's filled only for static imports and exports. pub import_assertions: HashMap, } -struct DependencyCollector<'a> { - comments: &'a SingleThreadedComments, +struct DependencyCollector<'a, TComments: Comments> { + comments: &'a TComments, pub items: Vec, - source_map: &'a SourceMap, // This field is used to determine if currently visited "require" // is top level and "static", or inside module body and "dynamic". is_top_level: bool, } -impl<'a> DependencyCollector<'a> { - fn get_location(&self, span: Span) -> Loc { - self.source_map.lookup_char_pos(span.lo) - } - +impl<'a, TComments: Comments> DependencyCollector<'a, TComments> { fn get_leading_comments(&self, span: Span) -> Vec { - self.comments - .with_leading(span.lo, |comments| comments.to_vec()) + self.comments.get_leading(span.lo).unwrap_or_else(Vec::new) } } -impl<'a> Visit for DependencyCollector<'a> { +impl<'a, TComments: Comments> Visit for DependencyCollector<'a, TComments> { fn visit_import_decl(&mut self, node: &ast::ImportDecl, _parent: &dyn Node) { let specifier = node.src.value.clone(); - let span = node.span; - let location = self.get_location(span); - let leading_comments = self.get_leading_comments(span); - let specifier_location = self.get_location(node.src.span); + let leading_comments = self.get_leading_comments(node.span); let kind = if node.type_only { DependencyKind::ImportType } else { @@ -89,11 +76,9 @@ impl<'a> Visit for DependencyCollector<'a> { kind, is_dynamic: false, leading_comments, - col: location.col_display, - line: location.line, + span: node.span, specifier, - specifier_col: specifier_location.col_display, - specifier_line: specifier_location.line, + specifier_span: node.src.span, import_assertions, }); } @@ -101,10 +86,7 @@ impl<'a> Visit for DependencyCollector<'a> { fn visit_named_export(&mut self, node: &ast::NamedExport, _parent: &dyn Node) { if let Some(src) = &node.src { let specifier = src.value.clone(); - let span = node.span; - let location = self.get_location(span); - let leading_comments = self.get_leading_comments(span); - let specifier_location = self.get_location(src.span); + let leading_comments = self.get_leading_comments(node.span); let kind = if node.type_only { DependencyKind::ExportType } else { @@ -115,11 +97,9 @@ impl<'a> Visit for DependencyCollector<'a> { kind, is_dynamic: false, leading_comments, - col: location.col_display, - line: location.line, + span: node.span, specifier, - specifier_col: specifier_location.col_display, - specifier_line: specifier_location.line, + specifier_span: src.span, import_assertions, }); } @@ -127,20 +107,15 @@ impl<'a> Visit for DependencyCollector<'a> { fn visit_export_all(&mut self, node: &ast::ExportAll, _parent: &dyn Node) { let specifier = node.src.value.clone(); - let span = node.span; - let location = self.get_location(span); - let leading_comments = self.get_leading_comments(span); - let specifier_location = self.get_location(node.src.span); + let leading_comments = self.get_leading_comments(node.span); let import_assertions = parse_import_assertions(node.asserts.as_ref()); self.items.push(DependencyDescriptor { kind: DependencyKind::Export, is_dynamic: false, leading_comments, - col: location.col_display, - line: location.line, + span: node.span, specifier, - specifier_col: specifier_location.col_display, - specifier_line: specifier_location.line, + specifier_span: node.src.span, import_assertions, }); } @@ -148,18 +123,14 @@ impl<'a> Visit for DependencyCollector<'a> { fn visit_ts_import_type(&mut self, node: &ast::TsImportType, _parent: &dyn Node) { let specifier = node.arg.value.clone(); let span = node.span; - let location = self.get_location(span); let leading_comments = self.get_leading_comments(span); - let specifier_location = self.get_location(node.arg.span); self.items.push(DependencyDescriptor { kind: DependencyKind::ImportType, is_dynamic: false, leading_comments, - col: location.col_display, - line: location.line, + span: node.span, specifier, - specifier_col: specifier_location.col_display, - specifier_line: specifier_location.line, + specifier_span: node.arg.span, import_assertions: HashMap::default(), }); } @@ -199,19 +170,14 @@ impl<'a> Visit for DependencyCollector<'a> { if let Lit(lit) = &*arg.expr { if let ast::Lit::Str(str_) = lit { let specifier = str_.value.clone(); - let span = node.span; - let location = self.get_location(span); - let leading_comments = self.get_leading_comments(span); - let specifier_location = self.get_location(str_.span); + let leading_comments = self.get_leading_comments(node.span); self.items.push(DependencyDescriptor { kind, is_dynamic, leading_comments, - col: location.col_display, - line: location.line, + span: node.span, specifier, - specifier_col: specifier_location.col_display, - specifier_line: specifier_location.line, + specifier_span: str_.span, import_assertions: HashMap::default(), }); } @@ -243,8 +209,7 @@ fn parse_import_assertions(asserts: Option<&ast::ObjectLit>) -> HashMap Result<(ast::Module, Lrc, SingleThreadedComments), testing::StdErr> { + ) -> Result<(ast::Module, SingleThreadedComments), testing::StdErr> { let output = ::testing::run_test(false, |cm, handler| { let fm = cm.new_source_file(FileName::Custom(file_name.to_string()), source.to_string()); @@ -287,7 +252,7 @@ mod tests { return Err(()); } - Ok((res.unwrap(), cm, comments)) + Ok((res.unwrap(), comments)) }); output @@ -307,7 +272,7 @@ export * as Buzz from "./buzz.ts"; export type { Fizz } from "./fizz.d.ts"; const { join } = require("path"); -// dynamic +// dynamic await import("./foo1.ts"); try { @@ -322,8 +287,8 @@ try { // pass } "#; - let (module, source_map, comments) = helper("test.ts", &source).unwrap(); - let dependencies = analyze_dependencies(&module, &source_map, &comments); + let (module, comments) = helper("test.ts", &source).unwrap(); + let dependencies = analyze_dependencies(&module, &comments); assert_eq!(dependencies.len(), 8); assert_eq!( dependencies, @@ -332,11 +297,9 @@ try { kind: DependencyKind::Import, is_dynamic: false, leading_comments: Vec::new(), - col: 0, - line: 1, + span: Span::new(BytePos(0), BytePos(33), Default::default()), specifier: JsWord::from("./test.ts"), - specifier_col: 21, - specifier_line: 1, + specifier_span: Span::new(BytePos(21), BytePos(32), Default::default()), import_assertions: HashMap::default(), }, DependencyDescriptor { @@ -347,11 +310,9 @@ try { text: r#"* JSDoc "#.to_string(), span: Span::new(BytePos(34), BytePos(46), SyntaxContext::empty()), }], - col: 0, - line: 3, + span: Span::new(BytePos(47), BytePos(85), Default::default()), specifier: JsWord::from("./foo.d.ts"), - specifier_col: 25, - specifier_line: 3, + specifier_span: Span::new(BytePos(72), BytePos(84), Default::default()), import_assertions: HashMap::default(), }, DependencyDescriptor { @@ -362,11 +323,9 @@ try { text: r#"/ "#.to_string(), span: Span::new(BytePos(86), BytePos(113), SyntaxContext::empty()), }], - col: 0, - line: 5, + span: Span::new(BytePos(114), BytePos(147), Default::default()), specifier: JsWord::from("./buzz.ts"), - specifier_col: 22, - specifier_line: 5, + specifier_span: Span::new(BytePos(136), BytePos(147), Default::default()), import_assertions: HashMap::default(), }, DependencyDescriptor { @@ -384,55 +343,45 @@ try { span: Span::new(BytePos(165), BytePos(179), SyntaxContext::empty()), } ], - col: 0, - line: 10, + span: Span::new(BytePos(180), BytePos(220), Default::default()), specifier: JsWord::from("./fizz.d.ts"), - specifier_col: 26, - specifier_line: 10, + specifier_span: Span::new(BytePos(206), BytePos(219), Default::default()), import_assertions: HashMap::default(), }, DependencyDescriptor { kind: DependencyKind::Require, is_dynamic: false, leading_comments: Vec::new(), - col: 17, - line: 11, + span: Span::new(BytePos(238), BytePos(253), Default::default()), specifier: JsWord::from("path"), - specifier_col: 25, - specifier_line: 11, + specifier_span: Span::new(BytePos(246), BytePos(252), Default::default()), import_assertions: HashMap::default(), }, DependencyDescriptor { kind: DependencyKind::Import, is_dynamic: true, leading_comments: Vec::new(), - col: 6, - line: 14, + span: Span::new(BytePos(273), BytePos(292), Default::default()), specifier: JsWord::from("./foo1.ts"), - specifier_col: 13, - specifier_line: 14, + specifier_span: Span::new(BytePos(280), BytePos(291), Default::default()), import_assertions: HashMap::default(), }, DependencyDescriptor { kind: DependencyKind::Import, is_dynamic: true, leading_comments: Vec::new(), - col: 22, - line: 17, + span: Span::new(BytePos(323), BytePos(341), Default::default()), specifier: JsWord::from("./foo.ts"), - specifier_col: 29, - specifier_line: 17, + specifier_span: Span::new(BytePos(330), BytePos(340), Default::default()), import_assertions: HashMap::default(), }, DependencyDescriptor { kind: DependencyKind::Require, is_dynamic: true, leading_comments: Vec::new(), - col: 16, - line: 23, + span: Span::new(BytePos(394), BytePos(417), Default::default()), specifier: JsWord::from("some_package"), - specifier_col: 24, - specifier_line: 23, + specifier_span: Span::new(BytePos(402), BytePos(416), Default::default()), import_assertions: HashMap::default(), } ] @@ -445,12 +394,12 @@ try { export * from "./test.ts" assert { "type": "typescript" }; export { bar } from "./test.json" assert { "type": "json" }; "#; - let (module, source_map, comments) = helper("test.ts", &source).unwrap(); + let (module, comments) = helper("test.ts", &source).unwrap(); let mut expected_assertions1 = HashMap::new(); expected_assertions1.insert("type".to_string(), "typescript".to_string()); let mut expected_assertions2 = HashMap::new(); expected_assertions2.insert("type".to_string(), "json".to_string()); - let dependencies = analyze_dependencies(&module, &source_map, &comments); + let dependencies = analyze_dependencies(&module, &comments); assert_eq!(dependencies.len(), 3); assert_eq!( dependencies, @@ -459,33 +408,27 @@ export { bar } from "./test.json" assert { "type": "json" }; kind: DependencyKind::Import, is_dynamic: false, leading_comments: Vec::new(), - col: 0, - line: 1, + span: Span::new(BytePos(0), BytePos(65), Default::default()), specifier: JsWord::from("./test.ts"), - specifier_col: 21, - specifier_line: 1, + specifier_span: Span::new(BytePos(21), BytePos(32), Default::default()), import_assertions: expected_assertions1.clone(), }, DependencyDescriptor { kind: DependencyKind::Export, is_dynamic: false, leading_comments: Vec::new(), - col: 0, - line: 2, + span: Span::new(BytePos(66), BytePos(124), Default::default()), specifier: JsWord::from("./test.ts"), - specifier_col: 14, - specifier_line: 2, + specifier_span: Span::new(BytePos(80), BytePos(91), Default::default()), import_assertions: expected_assertions1, }, DependencyDescriptor { kind: DependencyKind::Export, is_dynamic: false, leading_comments: Vec::new(), - col: 0, - line: 3, + span: Span::new(BytePos(125), BytePos(185), Default::default()), specifier: JsWord::from("./test.json"), - specifier_col: 20, - specifier_line: 3, + specifier_span: Span::new(BytePos(145), BytePos(158), Default::default()), import_assertions: expected_assertions2, }, ] diff --git a/ecmascript/ext-transforms/Cargo.toml b/ecmascript/ext-transforms/Cargo.toml index 6481a607130f..06ee243a19d2 100644 --- a/ecmascript/ext-transforms/Cargo.toml +++ b/ecmascript/ext-transforms/Cargo.toml @@ -5,15 +5,15 @@ documentation = "https://rustdoc.swc.rs/swc_ecma_ext_transforms/" edition = "2018" license = "Apache-2.0/MIT" name = "swc_ecma_ext_transforms" -version = "0.20.0" +version = "0.21.0" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] phf = {version = "0.8.0", features = ["macros"]} swc_atoms = {version = "0.2", path = "../../atoms"} -swc_common = {version = "0.10.16", path = "../../common"} -swc_ecma_ast = {version = "0.48.0", path = "../ast"} -swc_ecma_parser = {version = "0.62.0", path = "../parser"} -swc_ecma_utils = {version = "0.39.0", path = "../utils"} -swc_ecma_visit = {version = "0.34.0", path = "../visit"} +swc_common = {version = "0.11.0", path = "../../common"} +swc_ecma_ast = {version = "0.49.0", path = "../ast"} +swc_ecma_parser = {version = "0.63.0", path = "../parser"} +swc_ecma_utils = {version = "0.40.0", path = "../utils"} +swc_ecma_visit = {version = "0.35.0", path = "../visit"} diff --git a/ecmascript/jsdoc/Cargo.toml b/ecmascript/jsdoc/Cargo.toml index 475d34b0b380..e1690d9ba517 100644 --- a/ecmascript/jsdoc/Cargo.toml +++ b/ecmascript/jsdoc/Cargo.toml @@ -5,7 +5,7 @@ documentation = "https://rustdoc.swc.rs/jsdoc/" edition = "2018" license = "Apache-2.0/MIT" name = "jsdoc" -version = "0.30.0" +version = "0.31.0" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html @@ -13,12 +13,12 @@ version = "0.30.0" nom = "5.1.2" serde = {version = "1", features = ["derive"]} swc_atoms = {version = "0.2", path = "../../atoms"} -swc_common = {version = "0.10.16", path = "../../common"} +swc_common = {version = "0.11.0", path = "../../common"} [dev-dependencies] anyhow = "1" dashmap = "4.0.2" -swc_ecma_ast = {version = "0.48.0", path = "../ast"} -swc_ecma_parser = {version = "0.62.0", path = "../parser"} -testing = {version = "0.10.5", path = "../../testing"} +swc_ecma_ast = {version = "0.49.0", path = "../ast"} +swc_ecma_parser = {version = "0.63.0", path = "../parser"} +testing = {version = "0.11.0", path = "../../testing"} walkdir = "2" diff --git a/ecmascript/jsdoc/tests/fixture.rs b/ecmascript/jsdoc/tests/fixture.rs index 5b63ea856978..47ce73a053cb 100644 --- a/ecmascript/jsdoc/tests/fixture.rs +++ b/ecmascript/jsdoc/tests/fixture.rs @@ -7,7 +7,7 @@ use dashmap::DashMap; use std::{env, path::PathBuf}; use swc_common::{ comments::{Comment, CommentKind, Comments}, - BytePos, + BytePos, DUMMY_SP, }; use swc_ecma_parser::{lexer::Lexer, EsConfig, Parser, StringInput, Syntax}; use test::{test_main, DynTestFn, ShouldPanic::No, TestDesc, TestDescAndFn, TestName, TestType}; @@ -159,6 +159,10 @@ impl Comments for SwcComments { self.leading.remove(&pos).map(|v| v.1) } + fn get_leading(&self, pos: BytePos) -> Option> { + self.leading.get(&pos).map(|v| v.to_owned()) + } + fn add_trailing(&self, pos: BytePos, cmt: Comment) { self.trailing.entry(pos).or_default().push(cmt) } @@ -182,4 +186,21 @@ impl Comments for SwcComments { fn take_trailing(&self, pos: BytePos) -> Option> { self.trailing.remove(&pos).map(|v| v.1) } + + fn get_trailing(&self, pos: BytePos) -> Option> { + self.trailing.get(&pos).map(|v| v.to_owned()) + } + + fn add_pure_comment(&self, pos: BytePos) { + let mut leading = self.leading.entry(pos).or_default(); + let pure_comment = Comment { + kind: CommentKind::Block, + span: DUMMY_SP, + text: "#__PURE__".into(), + }; + + if !leading.iter().any(|c| c.text == pure_comment.text) { + leading.push(pure_comment); + } + } } diff --git a/ecmascript/loader/Cargo.toml b/ecmascript/loader/Cargo.toml index a13bea7c3f25..7880af418976 100644 --- a/ecmascript/loader/Cargo.toml +++ b/ecmascript/loader/Cargo.toml @@ -6,7 +6,7 @@ edition = "2018" license = "Apache-2.0/MIT" name = "swc_ecma_loader" repository = "https://github.com/swc-project/swc.git" -version = "0.10.0" +version = "0.11.0" [package.metadata.docs.rs] all-features = true @@ -28,12 +28,12 @@ regex = {version = "1", optional = true} serde = {version = "1.0.126", optional = true} serde_json = {version = "1.0.64", optional = true} swc_atoms = {version = "0.2.3", path = "../../atoms"} -swc_common = {version = "0.10.16", path = "../../common"} -swc_ecma_ast = {version = "0.48.0", path = "../ast"} -swc_ecma_visit = {version = "0.34.0", path = "../visit"} +swc_common = {version = "0.11.0", path = "../../common"} +swc_ecma_ast = {version = "0.49.0", path = "../ast"} +swc_ecma_visit = {version = "0.35.0", path = "../visit"} [dev-dependencies] -testing = {version = "0.10.5", path = "../../testing"} +testing = {version = "0.11.0", path = "../../testing"} [target.'cfg(windows)'.dependencies] normpath = {version = "0.2", optional = true} diff --git a/ecmascript/minifier/Cargo.toml b/ecmascript/minifier/Cargo.toml index 79d899a26acc..f9ecd17db842 100644 --- a/ecmascript/minifier/Cargo.toml +++ b/ecmascript/minifier/Cargo.toml @@ -7,7 +7,7 @@ include = ["Cargo.toml", "src/**/*.rs", "src/lists/*.json"] license = "Apache-2.0/MIT" name = "swc_ecma_minifier" repository = "https://github.com/swc-project/swc.git" -version = "0.11.0" +version = "0.12.0" [features] debug = [] @@ -23,18 +23,18 @@ serde = {version = "1.0.118", features = ["derive"]} serde_json = "1.0.61" serde_regex = "1.1.0" swc_atoms = {version = "0.2", path = "../../atoms"} -swc_common = {version = "0.10.8", path = "../../common"} -swc_ecma_ast = {version = "0.48.0", path = "../ast"} -swc_ecma_codegen = {version = "0.61.0", path = "../codegen"} -swc_ecma_parser = {version = "0.62.0", path = "../parser"} -swc_ecma_transforms = {version = "0.58.0", path = "../transforms/", features = ["optimization"]} -swc_ecma_transforms_base = {version = "0.21.0", path = "../transforms/base"} -swc_ecma_utils = {version = "0.39.0", path = "../utils"} -swc_ecma_visit = {version = "0.34.0", path = "../visit"} +swc_common = {version = "0.11.0", path = "../../common"} +swc_ecma_ast = {version = "0.49.0", path = "../ast"} +swc_ecma_codegen = {version = "0.62.0", path = "../codegen"} +swc_ecma_parser = {version = "0.63.0", path = "../parser"} +swc_ecma_transforms = {version = "0.59.0", path = "../transforms/", features = ["optimization"]} +swc_ecma_transforms_base = {version = "0.22.0", path = "../transforms/base"} +swc_ecma_utils = {version = "0.40.0", path = "../utils"} +swc_ecma_visit = {version = "0.35.0", path = "../visit"} [dev-dependencies] ansi_term = "0.12.1" anyhow = "1" pretty_assertions = "0.6.1" -testing = {version = "0.10.2", path = "../../testing"} +testing = {version = "0.11.0", path = "../../testing"} walkdir = "2.3.1" diff --git a/ecmascript/minifier/src/compress/optimize/util.rs b/ecmascript/minifier/src/compress/optimize/util.rs index f6bdd15f072b..b914a747cefb 100644 --- a/ecmascript/minifier/src/compress/optimize/util.rs +++ b/ecmascript/minifier/src/compress/optimize/util.rs @@ -94,7 +94,7 @@ impl<'b> Optimizer<'b> { { let mut found = false; if let Some(comments) = self.comments { - let cs = comments.take_leading(span.lo); + let cs = comments.get_leading(span.lo); if let Some(cs) = cs { for c in &cs { found |= op(&c); @@ -102,8 +102,6 @@ impl<'b> Optimizer<'b> { break; } } - - comments.add_leading_comments(span.lo, cs); } } diff --git a/ecmascript/parser/Cargo.toml b/ecmascript/parser/Cargo.toml index 54e1c43d4067..b2394f0c13a5 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.62.1" +version = "0.63.0" [features] default = [] @@ -22,16 +22,16 @@ num-bigint = "0.2" serde = {version = "1", features = ["derive"]} smallvec = "1" swc_atoms = {version = "0.2.3", path = "../../atoms"} -swc_common = {version = "0.10.16", path = "../../common"} -swc_ecma_ast = {version = "0.48.0", path = "../ast"} -swc_ecma_visit = {version = "0.34.0", path = "../visit"} +swc_common = {version = "0.11.0", path = "../../common"} +swc_ecma_ast = {version = "0.49.0", path = "../ast"} +swc_ecma_visit = {version = "0.35.0", path = "../visit"} unicode-xid = "0.2" [dev-dependencies] env_logger = "0.7" pretty_assertions = "0.6" serde_json = "1" -testing = {version = "0.10.5", path = "../../testing"} +testing = {version = "0.11.0", path = "../../testing"} walkdir = "2" [[example]] diff --git a/ecmascript/preset-env/Cargo.toml b/ecmascript/preset-env/Cargo.toml index 7a868db0f34b..20b497c2ec96 100644 --- a/ecmascript/preset-env/Cargo.toml +++ b/ecmascript/preset-env/Cargo.toml @@ -5,7 +5,7 @@ documentation = "https://rustdoc.swc.rs/swc_ecma_preset_env/" edition = "2018" license = "Apache-2.0/MIT" name = "swc_ecma_preset_env" -version = "0.28.0" +version = "0.29.0" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html @@ -20,15 +20,15 @@ serde_json = "1" 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.16", path = "../../common"} -swc_ecma_ast = {version = "0.48.0", path = "../ast"} -swc_ecma_transforms = {version = "0.58.0", path = "../transforms", features = ["compat", "proposal"]} -swc_ecma_utils = {version = "0.39.0", path = "../utils"} -swc_ecma_visit = {version = "0.34.0", path = "../visit"} +swc_common = {version = "0.11.0", path = "../../common"} +swc_ecma_ast = {version = "0.49.0", path = "../ast"} +swc_ecma_transforms = {version = "0.59.0", path = "../transforms", features = ["compat", "proposal"]} +swc_ecma_utils = {version = "0.40.0", path = "../utils"} +swc_ecma_visit = {version = "0.35.0", path = "../visit"} walkdir = "2" [dev-dependencies] pretty_assertions = "0.6" -swc_ecma_codegen = {version = "0.61.0", path = "../codegen"} -swc_ecma_parser = {version = "0.62.0", path = "../parser"} -testing = {version = "0.10.5", path = "../../testing"} +swc_ecma_codegen = {version = "0.62.0", path = "../codegen"} +swc_ecma_parser = {version = "0.63.0", path = "../parser"} +testing = {version = "0.11.0", path = "../../testing"} diff --git a/ecmascript/transforms/Cargo.toml b/ecmascript/transforms/Cargo.toml index 2e408c04e18a..f21ce36d159e 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.58.1" +version = "0.59.0" [package.metadata.docs.rs] all-features = true @@ -22,25 +22,25 @@ typescript = ["swc_ecma_transforms_typescript"] [dependencies] swc_atoms = {version = "0.2.0", path = "../../atoms"} -swc_common = {version = "0.10.16", path = "../../common"} -swc_ecma_ast = {version = "0.48.0", path = "../ast"} -swc_ecma_parser = {version = "0.62.0", path = "../parser"} -swc_ecma_transforms_base = {version = "0.21.0", path = "./base"} -swc_ecma_transforms_compat = {version = "0.24.0", path = "./compat", optional = true} -swc_ecma_transforms_module = {version = "0.25.0", path = "./module", optional = true} -swc_ecma_transforms_optimization = {version = "0.28.0", path = "./optimization", optional = true} -swc_ecma_transforms_proposal = {version = "0.25.0", path = "./proposal", optional = true} -swc_ecma_transforms_react = {version = "0.26.0", path = "./react", optional = true} -swc_ecma_transforms_typescript = {version = "0.27.0", path = "./typescript", optional = true} -swc_ecma_utils = {version = "0.39.0", path = "../utils"} -swc_ecma_visit = {version = "0.34.0", path = "../visit"} +swc_common = {version = "0.11.0", path = "../../common"} +swc_ecma_ast = {version = "0.49.0", path = "../ast"} +swc_ecma_parser = {version = "0.63.0", path = "../parser"} +swc_ecma_transforms_base = {version = "0.22.0", path = "./base"} +swc_ecma_transforms_compat = {version = "0.25.0", path = "./compat", optional = true} +swc_ecma_transforms_module = {version = "0.26.0", path = "./module", optional = true} +swc_ecma_transforms_optimization = {version = "0.29.0", path = "./optimization", optional = true} +swc_ecma_transforms_proposal = {version = "0.26.0", path = "./proposal", optional = true} +swc_ecma_transforms_react = {version = "0.27.0", path = "./react", optional = true} +swc_ecma_transforms_typescript = {version = "0.28.0", path = "./typescript", optional = true} +swc_ecma_utils = {version = "0.40.0", path = "../utils"} +swc_ecma_visit = {version = "0.35.0", path = "../visit"} unicode-xid = "0.2" [dev-dependencies] pretty_assertions = "0.6" sourcemap = "6" -swc_ecma_codegen = {version = "0.61.0", path = "../codegen"} -swc_ecma_transforms_testing = {version = "0.21.0", path = "./testing"} +swc_ecma_codegen = {version = "0.62.0", path = "../codegen"} +swc_ecma_transforms_testing = {version = "0.22.0", path = "./testing"} tempfile = "3" -testing = {version = "0.10.5", path = "../../testing"} +testing = {version = "0.11.0", path = "../../testing"} walkdir = "2" diff --git a/ecmascript/transforms/base/Cargo.toml b/ecmascript/transforms/base/Cargo.toml index 75c644bde26c..8b7d35b86d5e 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.21.1" +version = "0.22.0" [dependencies] fxhash = "0.2.1" @@ -15,12 +15,12 @@ phf = {version = "0.8.0", features = ["macros"]} scoped-tls = "1.0.0" smallvec = "1.6.0" swc_atoms = {version = "0.2", path = "../../../atoms"} -swc_common = {version = "0.10.16", path = "../../../common"} -swc_ecma_ast = {version = "0.48.0", path = "../../ast"} -swc_ecma_parser = {version = "0.62.0", path = "../../parser"} -swc_ecma_utils = {version = "0.39.0", path = "../../utils"} -swc_ecma_visit = {version = "0.34.0", path = "../../visit"} +swc_common = {version = "0.11.0", path = "../../../common"} +swc_ecma_ast = {version = "0.49.0", path = "../../ast"} +swc_ecma_parser = {version = "0.63.0", path = "../../parser"} +swc_ecma_utils = {version = "0.40.0", path = "../../utils"} +swc_ecma_visit = {version = "0.35.0", path = "../../visit"} [dev-dependencies] -swc_ecma_codegen = {version = "0.61.0", path = "../../codegen"} -testing = {version = "0.10.5", path = "../../../testing"} +swc_ecma_codegen = {version = "0.62.0", path = "../../codegen"} +testing = {version = "0.11.0", path = "../../../testing"} diff --git a/ecmascript/transforms/classes/Cargo.toml b/ecmascript/transforms/classes/Cargo.toml index 0aef268d9ebc..52ee2b6a7852 100644 --- a/ecmascript/transforms/classes/Cargo.toml +++ b/ecmascript/transforms/classes/Cargo.toml @@ -6,12 +6,12 @@ edition = "2018" license = "Apache-2.0/MIT" name = "swc_ecma_transforms_classes" repository = "https://github.com/swc-project/swc.git" -version = "0.7.0" +version = "0.8.0" [dependencies] swc_atoms = {version = "0.2.6", path = "../../../atoms"} -swc_common = {version = "0.10.20", path = "../../../common"} -swc_ecma_ast = {version = "0.48.0", path = "../../ast"} -swc_ecma_transforms_base = {version = "0.21.0", path = "../base"} -swc_ecma_utils = {version = "0.39.0", path = "../../utils"} -swc_ecma_visit = {version = "0.34.0", path = "../../visit"} +swc_common = {version = "0.11.0", path = "../../../common"} +swc_ecma_ast = {version = "0.49.0", path = "../../ast"} +swc_ecma_transforms_base = {version = "0.22.0", path = "../base"} +swc_ecma_utils = {version = "0.40.0", path = "../../utils"} +swc_ecma_visit = {version = "0.35.0", path = "../../visit"} diff --git a/ecmascript/transforms/compat/Cargo.toml b/ecmascript/transforms/compat/Cargo.toml index 822a85c45e47..1010a452a8a0 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.24.4" +version = "0.25.0" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] @@ -19,15 +19,15 @@ ordered-float = "2.0.1" serde = {version = "1.0.118", features = ["derive"]} smallvec = "1.6.0" swc_atoms = {version = "0.2.5", path = "../../../atoms"} -swc_common = {version = "0.10.16", path = "../../../common"} -swc_ecma_ast = {version = "0.48.0", path = "../../ast"} -swc_ecma_transforms_base = {version = "0.21.0", path = "../base"} -swc_ecma_transforms_classes = {version = "0.7.0", path = "../classes"} +swc_common = {version = "0.11.0", path = "../../../common"} +swc_ecma_ast = {version = "0.49.0", path = "../../ast"} +swc_ecma_transforms_base = {version = "0.22.0", path = "../base"} +swc_ecma_transforms_classes = {version = "0.8.0", path = "../classes"} swc_ecma_transforms_macros = {version = "0.2.1", path = "../macros"} -swc_ecma_utils = {version = "0.39.0", path = "../../utils"} -swc_ecma_visit = {version = "0.34.0", path = "../../visit"} +swc_ecma_utils = {version = "0.40.0", path = "../../utils"} +swc_ecma_visit = {version = "0.35.0", path = "../../visit"} [dev-dependencies] -swc_ecma_parser = {version = "0.62.0", path = "../../parser"} -swc_ecma_transforms_testing = {version = "0.21.0", path = "../testing"} -testing = {version = "0.10.5", path = "../../../testing"} +swc_ecma_parser = {version = "0.63.0", path = "../../parser"} +swc_ecma_transforms_testing = {version = "0.22.0", path = "../testing"} +testing = {version = "0.11.0", path = "../../../testing"} diff --git a/ecmascript/transforms/module/Cargo.toml b/ecmascript/transforms/module/Cargo.toml index b668ff5842ef..186068994b5d 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.25.2" +version = "0.26.0" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] @@ -17,15 +17,15 @@ indexmap = "1.6.1" pathdiff = "0.2.0" serde = {version = "1.0.118", features = ["derive"]} swc_atoms = {version = "0.2", path = "../../../atoms"} -swc_common = {version = "0.10.16", path = "../../../common"} -swc_ecma_ast = {version = "0.48.0", path = "../../ast"} -swc_ecma_loader = {version = "0.10.0", path = "../../loader", features = ["node"]} -swc_ecma_parser = {version = "0.62.0", path = "../../parser"} -swc_ecma_transforms_base = {version = "0.21.0", path = "../base"} -swc_ecma_utils = {version = "0.39.0", path = "../../utils"} -swc_ecma_visit = {version = "0.34.0", path = "../../visit"} +swc_common = {version = "0.11.0", path = "../../../common"} +swc_ecma_ast = {version = "0.49.0", path = "../../ast"} +swc_ecma_loader = {version = "0.11.0", path = "../../loader", features = ["node"]} +swc_ecma_parser = {version = "0.63.0", path = "../../parser"} +swc_ecma_transforms_base = {version = "0.22.0", path = "../base"} +swc_ecma_utils = {version = "0.40.0", path = "../../utils"} +swc_ecma_visit = {version = "0.35.0", path = "../../visit"} [dev-dependencies] -swc_ecma_transforms_compat = {version = "0.24.0", path = "../compat"} -swc_ecma_transforms_testing = {version = "0.21.0", path = "../testing/"} -testing = {version = "0.10.5", path = "../../../testing/"} +swc_ecma_transforms_compat = {version = "0.25.0", path = "../compat"} +swc_ecma_transforms_testing = {version = "0.22.0", path = "../testing/"} +testing = {version = "0.11.0", path = "../../../testing/"} diff --git a/ecmascript/transforms/optimization/Cargo.toml b/ecmascript/transforms/optimization/Cargo.toml index 6e61b160513f..45d87b9675e1 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.28.0" +version = "0.29.0" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] @@ -18,18 +18,18 @@ once_cell = "1.5.2" retain_mut = "0.1.2" serde_json = "1.0.61" swc_atoms = {version = "0.2", path = "../../../atoms"} -swc_common = {version = "0.10.16", path = "../../../common"} -swc_ecma_ast = {version = "0.48.0", path = "../../ast"} -swc_ecma_parser = {version = "0.62.0", path = "../../parser"} -swc_ecma_transforms_base = {version = "0.21.0", path = "../base"} -swc_ecma_utils = {version = "0.39.0", path = "../../utils"} -swc_ecma_visit = {version = "0.34.0", path = "../../visit"} +swc_common = {version = "0.11.0", path = "../../../common"} +swc_ecma_ast = {version = "0.49.0", path = "../../ast"} +swc_ecma_parser = {version = "0.63.0", path = "../../parser"} +swc_ecma_transforms_base = {version = "0.22.0", path = "../base"} +swc_ecma_utils = {version = "0.40.0", path = "../../utils"} +swc_ecma_visit = {version = "0.35.0", path = "../../visit"} [dev-dependencies] -swc_ecma_transforms_compat = {version = "0.24.0", path = "../compat"} -swc_ecma_transforms_module = {version = "0.25.0", path = "../module"} -swc_ecma_transforms_proposal = {version = "0.25.0", path = "../proposal"} -swc_ecma_transforms_react = {version = "0.26.0", path = "../react"} -swc_ecma_transforms_testing = {version = "0.21.0", path = "../testing"} -swc_ecma_transforms_typescript = {version = "0.27.0", path = "../typescript"} -testing = {version = "0.10.5", path = "../../../testing"} +swc_ecma_transforms_compat = {version = "0.25.0", path = "../compat"} +swc_ecma_transforms_module = {version = "0.26.0", path = "../module"} +swc_ecma_transforms_proposal = {version = "0.26.0", path = "../proposal"} +swc_ecma_transforms_react = {version = "0.27.0", path = "../react"} +swc_ecma_transforms_testing = {version = "0.22.0", path = "../testing"} +swc_ecma_transforms_typescript = {version = "0.28.0", path = "../typescript"} +testing = {version = "0.11.0", path = "../../../testing"} diff --git a/ecmascript/transforms/proposal/Cargo.toml b/ecmascript/transforms/proposal/Cargo.toml index 78e0934ffdfd..163146658366 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.25.1" +version = "0.26.0" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html @@ -20,16 +20,16 @@ fxhash = "0.2.1" serde = {version = "1.0.118", features = ["derive"]} smallvec = "1.6.0" swc_atoms = {version = "0.2", path = "../../../atoms"} -swc_common = {version = "0.10.16", path = "../../../common"} -swc_ecma_ast = {version = "0.48.0", path = "../../ast"} -swc_ecma_loader = {version = "0.10.0", path = "../../loader", optional = true} -swc_ecma_parser = {version = "0.62.0", path = "../../parser"} -swc_ecma_transforms_base = {version = "0.21.0", path = "../base"} -swc_ecma_transforms_classes = {version = "0.7.0", path = "../classes"} -swc_ecma_utils = {version = "0.39.0", path = "../../utils"} -swc_ecma_visit = {version = "0.34.0", path = "../../visit"} +swc_common = {version = "0.11.0", path = "../../../common"} +swc_ecma_ast = {version = "0.49.0", path = "../../ast"} +swc_ecma_loader = {version = "0.11.0", path = "../../loader", optional = true} +swc_ecma_parser = {version = "0.63.0", path = "../../parser"} +swc_ecma_transforms_base = {version = "0.22.0", path = "../base"} +swc_ecma_transforms_classes = {version = "0.8.0", path = "../classes"} +swc_ecma_utils = {version = "0.40.0", path = "../../utils"} +swc_ecma_visit = {version = "0.35.0", path = "../../visit"} [dev-dependencies] -swc_ecma_transforms_compat = {version = "0.24.0", path = "../compat"} -swc_ecma_transforms_module = {version = "0.25.0", path = "../module"} -swc_ecma_transforms_testing = {version = "0.21.0", path = "../testing"} +swc_ecma_transforms_compat = {version = "0.25.0", path = "../compat"} +swc_ecma_transforms_module = {version = "0.26.0", path = "../module"} +swc_ecma_transforms_testing = {version = "0.22.0", path = "../testing"} diff --git a/ecmascript/transforms/react/Cargo.toml b/ecmascript/transforms/react/Cargo.toml index 2b1df4386ed6..f24b756c4a8f 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.26.0" +version = "0.27.0" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] @@ -20,16 +20,16 @@ serde = {version = "1.0.118", features = ["derive"]} sha-1 = "0.9.4" string_enum = {version = "0.3.1", path = "../../../macros/string_enum"} swc_atoms = {version = "0.2", path = "../../../atoms"} -swc_common = {version = "0.10.16", path = "../../../common"} -swc_ecma_ast = {version = "0.48.0", path = "../../ast"} -swc_ecma_parser = {version = "0.62.0", path = "../../parser"} -swc_ecma_transforms_base = {version = "0.21.0", path = "../base"} -swc_ecma_utils = {version = "0.39.0", path = "../../utils"} -swc_ecma_visit = {version = "0.34.0", path = "../../visit"} +swc_common = {version = "0.11.0", path = "../../../common"} +swc_ecma_ast = {version = "0.49.0", path = "../../ast"} +swc_ecma_parser = {version = "0.63.0", path = "../../parser"} +swc_ecma_transforms_base = {version = "0.22.0", path = "../base"} +swc_ecma_utils = {version = "0.40.0", path = "../../utils"} +swc_ecma_visit = {version = "0.35.0", path = "../../visit"} [dev-dependencies] -swc_ecma_codegen = {version = "0.61.0", path = "../../codegen/"} -swc_ecma_transforms_compat = {version = "0.24.0", path = "../compat/"} -swc_ecma_transforms_module = {version = "0.25.0", path = "../module"} -swc_ecma_transforms_testing = {version = "0.21.0", path = "../testing/"} -testing = {version = "0.10.5", path = "../../../testing"} +swc_ecma_codegen = {version = "0.62.0", path = "../../codegen/"} +swc_ecma_transforms_compat = {version = "0.25.0", path = "../compat/"} +swc_ecma_transforms_module = {version = "0.26.0", path = "../module"} +swc_ecma_transforms_testing = {version = "0.22.0", path = "../testing/"} +testing = {version = "0.11.0", path = "../../../testing"} diff --git a/ecmascript/transforms/testing/Cargo.toml b/ecmascript/transforms/testing/Cargo.toml index cf8c4a315146..ed62a4ccd748 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.21.1" +version = "0.22.0" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html @@ -14,12 +14,12 @@ version = "0.21.1" ansi_term = "0.12.1" serde = "1" serde_json = "1" -swc_common = {version = "0.10.16", path = "../../../common"} -swc_ecma_ast = {version = "0.48.0", path = "../../ast"} -swc_ecma_codegen = {version = "0.61.0", path = "../../codegen"} -swc_ecma_parser = {version = "0.62.0", path = "../../parser"} -swc_ecma_transforms_base = {version = "0.21.0", path = "../base"} -swc_ecma_utils = {version = "0.39.0", path = "../../utils"} -swc_ecma_visit = {version = "0.34.0", path = "../../visit"} +swc_common = {version = "0.11.0", path = "../../../common"} +swc_ecma_ast = {version = "0.49.0", path = "../../ast"} +swc_ecma_codegen = {version = "0.62.0", path = "../../codegen"} +swc_ecma_parser = {version = "0.63.0", path = "../../parser"} +swc_ecma_transforms_base = {version = "0.22.0", path = "../base"} +swc_ecma_utils = {version = "0.40.0", path = "../../utils"} +swc_ecma_visit = {version = "0.35.0", path = "../../visit"} tempfile = "3.1.0" -testing = {version = "0.10.5", path = "../../../testing"} +testing = {version = "0.11.0", path = "../../../testing"} diff --git a/ecmascript/transforms/typescript/Cargo.toml b/ecmascript/transforms/typescript/Cargo.toml index 8c6ac6fb502a..264fbf23e2fc 100644 --- a/ecmascript/transforms/typescript/Cargo.toml +++ b/ecmascript/transforms/typescript/Cargo.toml @@ -6,25 +6,25 @@ edition = "2018" license = "Apache-2.0/MIT" name = "swc_ecma_transforms_typescript" repository = "https://github.com/swc-project/swc.git" -version = "0.27.0" +version = "0.28.0" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] fxhash = "0.2.1" serde = {version = "1.0.118", features = ["derive"]} swc_atoms = {version = "0.2", path = "../../../atoms"} -swc_common = {version = "0.10.16", path = "../../../common"} -swc_ecma_ast = {version = "0.48.0", path = "../../ast"} -swc_ecma_parser = {version = "0.62.0", path = "../../parser"} -swc_ecma_transforms_base = {version = "0.21.0", path = "../base"} -swc_ecma_utils = {version = "0.39.0", path = "../../utils"} -swc_ecma_visit = {version = "0.34.0", path = "../../visit"} +swc_common = {version = "0.11.0", path = "../../../common"} +swc_ecma_ast = {version = "0.49.0", path = "../../ast"} +swc_ecma_parser = {version = "0.63.0", path = "../../parser"} +swc_ecma_transforms_base = {version = "0.22.0", path = "../base"} +swc_ecma_utils = {version = "0.40.0", path = "../../utils"} +swc_ecma_visit = {version = "0.35.0", path = "../../visit"} [dev-dependencies] -swc_ecma_codegen = {version = "0.61.0", path = "../../codegen"} -swc_ecma_transforms_compat = {version = "0.24.0", path = "../compat"} -swc_ecma_transforms_module = {version = "0.25.0", path = "../module"} -swc_ecma_transforms_proposal = {version = "0.25.0", path = "../proposal/"} -swc_ecma_transforms_testing = {version = "0.21.0", path = "../testing"} -testing = {version = "0.10.5", path = "../../../testing"} +swc_ecma_codegen = {version = "0.62.0", path = "../../codegen"} +swc_ecma_transforms_compat = {version = "0.25.0", path = "../compat"} +swc_ecma_transforms_module = {version = "0.26.0", path = "../module"} +swc_ecma_transforms_proposal = {version = "0.26.0", path = "../proposal/"} +swc_ecma_transforms_testing = {version = "0.22.0", path = "../testing"} +testing = {version = "0.11.0", path = "../../../testing"} walkdir = "2.3.1" diff --git a/ecmascript/utils/Cargo.toml b/ecmascript/utils/Cargo.toml index ba2c06a008cf..30b8ff015adf 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.39.0" +version = "0.40.0" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html @@ -14,10 +14,10 @@ version = "0.39.0" once_cell = "1" scoped-tls = "1" swc_atoms = {version = "0.2.0", path = "../../atoms"} -swc_common = {version = "0.10.16", path = "../../common"} -swc_ecma_ast = {version = "0.48.0", path = "../ast"} -swc_ecma_visit = {version = "0.34.0", path = "../visit"} +swc_common = {version = "0.11.0", path = "../../common"} +swc_ecma_ast = {version = "0.49.0", path = "../ast"} +swc_ecma_visit = {version = "0.35.0", path = "../visit"} unicode-xid = "0.2" [dev-dependencies] -testing = {version = "0.10.5", path = "../../testing"} +testing = {version = "0.11.0", path = "../../testing"} diff --git a/ecmascript/visit/Cargo.toml b/ecmascript/visit/Cargo.toml index 3c3a2c7952c2..c1ef3fbb15aa 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.34.0" +version = "0.35.0" [dependencies] num-bigint = {version = "0.2", features = ["serde"]} swc_atoms = {version = "0.2", path = "../../atoms"} -swc_common = {version = "0.10.16", path = "../../common"} -swc_ecma_ast = {version = "0.48.0", path = "../ast"} +swc_common = {version = "0.11.0", path = "../../common"} +swc_ecma_ast = {version = "0.49.0", path = "../ast"} swc_visit = {version = "0.2.3", path = "../../visit"} diff --git a/node/base/Cargo.toml b/node/base/Cargo.toml index 60d6fb38801a..932df7d10c4e 100644 --- a/node/base/Cargo.toml +++ b/node/base/Cargo.toml @@ -6,13 +6,13 @@ edition = "2018" license = "Apache-2.0/MIT" name = "swc_node_base" repository = "https://github.com/swc-project/swc.git" -version = "0.1.0" +version = "0.2.0" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] dashmap = "4.0.2" -swc_common = {version = "0.10", path = "../../common"} +swc_common = {version = "0.11.0", path = "../../common"} [target.'cfg(all(unix, not(target_env = "musl"), not(target_os = "freebsd"), not(target_arch = "arm"), not(target_arch = "aarch64")))'.dependencies] jemallocator = {version = "0.3", features = ["disable_initial_exec_tls"]} diff --git a/src/lib.rs b/src/lib.rs index d2702bde4917..5ef6e3d80662 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -17,11 +17,11 @@ use std::{ }; use swc_common::{ chain, - comments::{Comment, Comments}, + comments::{Comment, CommentKind, Comments}, errors::Handler, input::StringInput, source_map::SourceMapGenConfig, - BytePos, FileName, Globals, SourceFile, SourceMap, Spanned, GLOBALS, + BytePos, FileName, Globals, SourceFile, SourceMap, Spanned, DUMMY_SP, GLOBALS, }; use swc_ecma_ast::Program; use swc_ecma_codegen::{self, Emitter, Node}; @@ -680,6 +680,10 @@ impl Comments for SwcComments { self.leading.remove(&pos).map(|v| v.1) } + fn get_leading(&self, pos: BytePos) -> Option> { + self.leading.get(&pos).map(|v| v.to_owned()) + } + fn add_trailing(&self, pos: BytePos, cmt: Comment) { self.trailing.entry(pos).or_default().push(cmt) } @@ -707,4 +711,21 @@ impl Comments for SwcComments { fn take_trailing(&self, pos: BytePos) -> Option> { self.trailing.remove(&pos).map(|v| v.1) } + + fn get_trailing(&self, pos: BytePos) -> Option> { + self.trailing.get(&pos).map(|v| v.to_owned()) + } + + fn add_pure_comment(&self, pos: BytePos) { + let mut leading = self.leading.entry(pos).or_default(); + let pure_comment = Comment { + kind: CommentKind::Block, + span: DUMMY_SP, + text: "#__PURE__".into(), + }; + + if !leading.iter().any(|c| c.text == pure_comment.text) { + leading.push(pure_comment); + } + } } diff --git a/testing/Cargo.toml b/testing/Cargo.toml index e2d4a04f9dd6..e2877c3635c8 100644 --- a/testing/Cargo.toml +++ b/testing/Cargo.toml @@ -6,7 +6,7 @@ edition = "2018" license = "Apache-2.0/MIT" name = "testing" repository = "https://github.com/swc-project/swc.git" -version = "0.10.6" +version = "0.11.0" [dependencies] ansi_term = "0.12.1" @@ -16,5 +16,5 @@ log = "0.4" once_cell = "1" pretty_assertions = "0.6.1" regex = "1" -swc_common = {version = "0.10.16", path = "../common", features = ["tty-emitter"]} +swc_common = {version = "0.11.0", path = "../common", features = ["tty-emitter"]} testing_macros = {version = "0.1", path = "./macros"}