diff --git a/README.md b/README.md index 5fff44a6533..8e339d93cbb 100644 --- a/README.md +++ b/README.md @@ -97,6 +97,17 @@ swc jsc --optimize test.js use(8 + 8, Math.pow(8, 8)); ``` +## Contributing + +See [CONTRIBUTING.md](CONTRIBUTING.md). You may also find the architecture +documentation useful ([ARCHITECTURE.md](ARCHITECTURE.md)). + +## License + +swc is primarily distributed under the terms of both the MIT license +and the Apache License (Version 2.0). + +See LICENSE-APACHE and LICENSE-MIT for details. diff --git a/atoms/build.rs b/atoms/build.rs index 1955fa59ecd..8985cb7dfdf 100644 --- a/atoms/build.rs +++ b/atoms/build.rs @@ -3,85 +3,8 @@ extern crate string_cache_codegen; use std::{env, path::Path}; fn main() { - gen( - "js_word", - "JsWord", - &[ - // keywords - "await", - "break", - "case", - "catch", - "class", - "const", - "continue", - "debugger", - "default", - "delete", - "do", - "else", - "export", - "extends", - "finally", - "for", - "function", - "if", - "import", - "in", - "instanceof", - "new", - "return", - "super", - "switch", - "this", - "throw", - "try", - "typeof", - "var", - "void", - "while", - "with", - "yield", - // reserved word on strict mode. - "let", - "static", - "null", - "true", - "false", - // not keywords, just for pattern matching - "from", - "static", - "of", - "set", - "get", - "target", - "await", - "async", - "as", - // future reserved words? - "enum", - "implements", - "interface", - "package", - "private", - "protected", - "public", - // - "Object", - "length", - "Infinity", - "undefined", - "NaN", - "RegExp", - // helpers - "apply", - "call", - "concat", - "_extends", - "_toConsumableArray", - "constructor", - ], - ); + let strs = include_str!("words.txt").split("\n").collect::>(); + gen("js_word", "JsWord", &strs); } fn gen(mac_name: &str, type_name: &str, atoms: &[&str]) { diff --git a/atoms/scripts/sort.sh b/atoms/scripts/sort.sh new file mode 100755 index 00000000000..4804a1e04c5 --- /dev/null +++ b/atoms/scripts/sort.sh @@ -0,0 +1,5 @@ +#!/bin/bash +set -eu + +cat words.txt | sort > words_sorted.txt +mv words_sorted.txt words.txt \ No newline at end of file diff --git a/atoms/words.txt b/atoms/words.txt new file mode 100644 index 00000000000..ee7a1c398b9 --- /dev/null +++ b/atoms/words.txt @@ -0,0 +1,68 @@ +Infinity +NaN +Object +RegExp +_extends +_toConsumableArray +apply +as +async +await +await +break +call +case +catch +class +concat +const +constructor +continue +debugger +default +delete +do +else +enum +export +extends +false +finally +for +from +function +get +if +implements +import +in +instanceof +interface +key +length +let +new +null +of +package +private +protected +public +return +set +static +static +super +switch +target +this +throw +true +try +typeof +undefined +var +void +while +with +yield diff --git a/common/Cargo.toml b/common/Cargo.toml index 60084293c60..671e7519ca7 100644 --- a/common/Cargo.toml +++ b/common/Cargo.toml @@ -4,10 +4,10 @@ version = "0.1.0" authors = ["강동윤 "] [dependencies] +ast_node = { path = "../macros/ast_node" } string_cache = "0.7" either = "1.5" rustc-ap-rustc_errors = "297" rustc-ap-rustc_data_structures = "297" rustc-ap-syntax = "297" -rustc-ap-syntax_pos = "297" -swc_macros = { path = "../macros" } \ No newline at end of file +rustc-ap-syntax_pos = "297" \ No newline at end of file diff --git a/common/src/ast_node.rs b/common/src/ast_node.rs deleted file mode 100644 index 685c2e1b833..00000000000 --- a/common/src/ast_node.rs +++ /dev/null @@ -1,7 +0,0 @@ -use pos::Spanned; -use std::fmt::Debug; - -/// A marker trait for ast nodes. -pub trait AstNode: Debug + PartialEq + Clone + Spanned {} - -impl AstNode for N {} diff --git a/common/src/fold.rs b/common/src/fold.rs index 01868f0efec..8f1644e90e4 100644 --- a/common/src/fold.rs +++ b/common/src/fold.rs @@ -1,6 +1,5 @@ use either::Either; use string_cache::{Atom, StaticAtomSet}; -pub use swc_macros::Fold; /// Folder based on a type system. /// diff --git a/common/src/lib.rs b/common/src/lib.rs index e21cc84d596..c0d58ab39a5 100644 --- a/common/src/lib.rs +++ b/common/src/lib.rs @@ -3,25 +3,31 @@ #![feature(try_trait)] #![feature(never_type)] #![feature(specialization)] +extern crate ast_node; extern crate either; extern crate rustc_data_structures; extern crate rustc_errors; extern crate string_cache; -extern crate swc_macros; extern crate syntax; extern crate syntax_pos; pub use self::{ - ast_node::AstNode, errors::{SourceMapper, SourceMapperDyn}, fold::{Fold, FoldWith}, pos::*, }; +pub use ast_node::{ast_node, Fold, FromVariant, Spanned}; +use std::fmt::Debug; pub use syntax::source_map::{ FileLines, FileLoader, FileName, FilePathMapping, SourceMap, SpanSnippetError, }; -mod ast_node; + +/// A marker trait for ast nodes. +pub trait AstNode: Debug + PartialEq + Clone + Spanned {} + +impl AstNode for N {} + pub mod errors; mod fold; pub mod macros; -pub mod pos; +mod pos; diff --git a/common/src/pos.rs b/common/src/pos.rs index a7abee3e837..4a0499a61d0 100644 --- a/common/src/pos.rs +++ b/common/src/pos.rs @@ -1,5 +1,4 @@ use fold::FoldWith; -pub use swc_macros::Spanned; pub use syntax_pos::{ hygiene, BytePos, ExpnFormat, ExpnInfo, FileName, Globals, Mark, MultiSpan, SourceFile, Span, SpanData, SyntaxContext, DUMMY_SP, GLOBALS, NO_EXPANSION, diff --git a/ecmascript/ast/Cargo.toml b/ecmascript/ast/Cargo.toml index 8e3660b6944..2f0264f1b52 100644 --- a/ecmascript/ast/Cargo.toml +++ b/ecmascript/ast/Cargo.toml @@ -5,5 +5,6 @@ authors = ["강동윤 "] [dependencies] swc_atoms = { path = "../../atoms" } -swc_macros = { path = "../../macros" } -swc_common = { path = "../../common" } \ No newline at end of file +swc_common = { path = "../../common" } +enum_kind = { path = "../../macros/enum_kind" } +string_enum = { path = "../../macros/string_enum" } diff --git a/ecmascript/ast/src/class.rs b/ecmascript/ast/src/class.rs index b7133a968d7..585286b3816 100644 --- a/ecmascript/ast/src/class.rs +++ b/ecmascript/ast/src/class.rs @@ -1,6 +1,5 @@ use super::{Expr, Function, PropName}; -use swc_common::Span; -use swc_macros::ast_node; +use swc_common::{ast_node, Fold, Span}; #[ast_node] pub struct Class { diff --git a/ecmascript/ast/src/decl.rs b/ecmascript/ast/src/decl.rs index 8ab93872b5c..2fa5a1325c6 100644 --- a/ecmascript/ast/src/decl.rs +++ b/ecmascript/ast/src/decl.rs @@ -1,6 +1,5 @@ use super::{Class, Expr, Function, Ident, Pat}; -use swc_common::Span; -use swc_macros::ast_node; +use swc_common::{ast_node, Fold, Span}; #[ast_node] pub enum Decl { diff --git a/ecmascript/ast/src/expr.rs b/ecmascript/ast/src/expr.rs index 70cac832a48..ad8cc9b5756 100644 --- a/ecmascript/ast/src/expr.rs +++ b/ecmascript/ast/src/expr.rs @@ -1,8 +1,7 @@ use super::{ AssignOp, BinaryOp, BlockStmt, Class, Function, Ident, Lit, Pat, Prop, UnaryOp, UpdateOp, }; -use swc_common::{Span, Spanned}; -use swc_macros::ast_node; +use swc_common::{ast_node, Fold, Span, Spanned}; #[ast_node] pub enum Expr { diff --git a/ecmascript/ast/src/function.rs b/ecmascript/ast/src/function.rs index 95fc7704135..aacd244a377 100644 --- a/ecmascript/ast/src/function.rs +++ b/ecmascript/ast/src/function.rs @@ -1,6 +1,5 @@ use super::{BlockStmt, Pat}; -use swc_common::Span; -use swc_macros::ast_node; +use swc_common::{ast_node, Span}; /// Common parts of function and method. #[ast_node] diff --git a/ecmascript/ast/src/lib.rs b/ecmascript/ast/src/lib.rs index c7f5044b2e2..ceb11886c8e 100644 --- a/ecmascript/ast/src/lib.rs +++ b/ecmascript/ast/src/lib.rs @@ -8,10 +8,12 @@ #![deny(unreachable_pub)] #![deny(variant_size_differences)] +#[macro_use] +extern crate enum_kind; +#[macro_use] +extern crate string_enum; extern crate swc_atoms; extern crate swc_common; -#[macro_use] -extern crate swc_macros; pub use self::{ class::{Class, ClassMethod, ClassMethodKind}, @@ -43,8 +45,7 @@ pub use self::{ }; use std::fmt::{self, Debug, Display, Formatter}; use swc_atoms::JsWord; -use swc_common::Span; -use swc_macros::Fold; +use swc_common::{Fold, Span, Spanned}; mod class; mod decl; diff --git a/ecmascript/ast/src/lit.rs b/ecmascript/ast/src/lit.rs index 3cf145dd546..e9aa9736b3d 100644 --- a/ecmascript/ast/src/lit.rs +++ b/ecmascript/ast/src/lit.rs @@ -1,7 +1,7 @@ use std::fmt::{self, Display, Formatter}; use swc_atoms::JsWord; use swc_common::Span; -use swc_macros::ast_node; +use swc_common::ast_node; #[ast_node] pub enum Lit { diff --git a/ecmascript/ast/src/module.rs b/ecmascript/ast/src/module.rs index 30cd2d07518..69c1902c9d3 100644 --- a/ecmascript/ast/src/module.rs +++ b/ecmascript/ast/src/module.rs @@ -1,6 +1,5 @@ use super::{ModuleDecl, Stmt}; -use swc_common::Span; -use swc_macros::ast_node; +use swc_common::{ast_node, Span}; #[ast_node] pub struct Module { diff --git a/ecmascript/ast/src/module_decl.rs b/ecmascript/ast/src/module_decl.rs index 7d156357da4..476d95ddb3d 100644 --- a/ecmascript/ast/src/module_decl.rs +++ b/ecmascript/ast/src/module_decl.rs @@ -1,6 +1,6 @@ use super::{ClassExpr, Decl, Expr, FnExpr, Ident, Str, VarDecl}; use swc_common::Span; -use swc_macros::ast_node; +use swc_common::ast_node; #[ast_node] pub enum ModuleDecl { diff --git a/ecmascript/ast/src/operators.rs b/ecmascript/ast/src/operators.rs index 95c8543ebc1..51a22e95c8f 100644 --- a/ecmascript/ast/src/operators.rs +++ b/ecmascript/ast/src/operators.rs @@ -1,4 +1,6 @@ -use swc_macros::{Fold, Kind, StringEnum}; +use enum_kind::Kind; +use string_enum::StringEnum; +use swc_common::Fold; #[derive(Kind, Fold, StringEnum, Clone, Copy, Eq, PartialEq, PartialOrd, Ord, Hash)] #[kind(function(precedence = "u8"))] diff --git a/ecmascript/ast/src/pat.rs b/ecmascript/ast/src/pat.rs index 9c231cdcccd..a6702748eac 100644 --- a/ecmascript/ast/src/pat.rs +++ b/ecmascript/ast/src/pat.rs @@ -1,6 +1,5 @@ use super::{Expr, Ident, PropName}; -use swc_common::Span; -use swc_macros::ast_node; +use swc_common::{ast_node, Span}; #[ast_node] pub enum Pat { diff --git a/ecmascript/ast/src/prop.rs b/ecmascript/ast/src/prop.rs index defabbd2e77..abb0c2c2e5e 100644 --- a/ecmascript/ast/src/prop.rs +++ b/ecmascript/ast/src/prop.rs @@ -1,6 +1,5 @@ use super::{BlockStmt, Expr, Function, Ident, Number, Pat, Str}; -use swc_common::Span; -use swc_macros::ast_node; +use swc_common::{ast_node, Span}; #[ast_node] pub enum Prop { diff --git a/ecmascript/ast/src/stmt.rs b/ecmascript/ast/src/stmt.rs index 8c5171f0e5d..83006b15fff 100644 --- a/ecmascript/ast/src/stmt.rs +++ b/ecmascript/ast/src/stmt.rs @@ -1,6 +1,6 @@ use super::{Decl, Expr, Ident, Pat, VarDecl}; use swc_common::Span; -use swc_macros::ast_node; +use swc_common::ast_node; /// Use when only block statements are allowed. #[ast_node] diff --git a/ecmascript/codegen/Cargo.toml b/ecmascript/codegen/Cargo.toml index b5a083724b8..298739435a4 100644 --- a/ecmascript/codegen/Cargo.toml +++ b/ecmascript/codegen/Cargo.toml @@ -8,7 +8,7 @@ bitflags = "1" swc_atoms = { path = "../../atoms" } swc_common = { path = "../../common" } swc_ecma_ast = { path = "../ast" } -ecma_codegen_macros = { path = "./macros" } +swc_ecma_codegen_macros = { path = "./macros" } sourcemap = "2.2" [dev-dependencies] diff --git a/ecmascript/codegen/macros/Cargo.toml b/ecmascript/codegen/macros/Cargo.toml index 43d775fd5a9..2c545d9f3f7 100644 --- a/ecmascript/codegen/macros/Cargo.toml +++ b/ecmascript/codegen/macros/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "ecma_codegen_macros" +name = "swc_ecma_codegen_macros" version = "0.1.0" authors = ["강동윤 "] diff --git a/ecmascript/codegen/src/decl.rs b/ecmascript/codegen/src/decl.rs index a8303304784..2d6421051fc 100644 --- a/ecmascript/codegen/src/decl.rs +++ b/ecmascript/codegen/src/decl.rs @@ -1,7 +1,7 @@ use super::{list::ListFormat, Emitter, Result}; -use ecma_codegen_macros::emitter; use swc_common::Spanned; use swc_ecma_ast::*; +use swc_ecma_codegen_macros::emitter; impl<'a> Emitter<'a> { #[emitter] diff --git a/ecmascript/codegen/src/lib.rs b/ecmascript/codegen/src/lib.rs index 744b9d25760..6528e28c81b 100644 --- a/ecmascript/codegen/src/lib.rs +++ b/ecmascript/codegen/src/lib.rs @@ -8,9 +8,9 @@ #[macro_use] extern crate bitflags; -extern crate ecma_codegen_macros; extern crate sourcemap; extern crate swc_atoms; +extern crate swc_ecma_codegen_macros; #[macro_use] extern crate swc_common; extern crate swc_ecma_ast; @@ -21,11 +21,11 @@ use self::{ text_writer::WriteJs, util::{SourceMapperExt, SpanExt, StartsWithAlphaNum}, }; -use ecma_codegen_macros::emitter; use std::{collections::HashSet, io, rc::Rc}; use swc_atoms::JsWord; -use swc_common::{pos::SyntaxContext, BytePos, SourceMap, Span, Spanned, DUMMY_SP}; +use swc_common::{BytePos, SourceMap, Span, Spanned, SyntaxContext, DUMMY_SP}; use swc_ecma_ast::*; +use swc_ecma_codegen_macros::emitter; #[macro_use] pub mod macros; diff --git a/ecmascript/parser/Cargo.toml b/ecmascript/parser/Cargo.toml index d49f4f4f36a..0504f61cd06 100644 --- a/ecmascript/parser/Cargo.toml +++ b/ecmascript/parser/Cargo.toml @@ -5,10 +5,10 @@ authors = ["강동윤 "] [dependencies] swc_atoms = { path = "../../atoms" } -swc_macros = { path = "../../macros" } swc_common = { path = "../../common" } swc_ecma_ast = { path = "../ast" } -parser_macros = { path = "../parser_macros" } +swc_ecma_parser_macros = { path = "./macros" } +enum_kind = { path = "../../macros/enum_kind" } unicode-xid = "0.1" slog = "2.1" either = { version = "1.4" } diff --git a/ecmascript/parser_macros/Cargo.toml b/ecmascript/parser/macros/Cargo.toml similarity index 72% rename from ecmascript/parser_macros/Cargo.toml rename to ecmascript/parser/macros/Cargo.toml index 7197f5a22e3..d035599f7f1 100644 --- a/ecmascript/parser_macros/Cargo.toml +++ b/ecmascript/parser/macros/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "parser_macros" +name = "swc_ecma_parser_macros" version = "0.1.0" authors = ["강동윤 "] @@ -7,7 +7,7 @@ authors = ["강동윤 "] proc-macro = true [dependencies] -swc_macros_common = { path = "../../macros/common" } +swc_macros_common = { path = "../../../macros/common" } proc-macro2 = "0.4.4" [dependencies.syn] diff --git a/ecmascript/parser_macros/src/expand.rs b/ecmascript/parser/macros/src/expand.rs similarity index 100% rename from ecmascript/parser_macros/src/expand.rs rename to ecmascript/parser/macros/src/expand.rs diff --git a/ecmascript/parser_macros/src/lib.rs b/ecmascript/parser/macros/src/lib.rs similarity index 100% rename from ecmascript/parser_macros/src/lib.rs rename to ecmascript/parser/macros/src/lib.rs diff --git a/ecmascript/parser/src/lexer/state.rs b/ecmascript/parser/src/lexer/state.rs index 5b979dced19..9e5d298a78a 100644 --- a/ecmascript/parser/src/lexer/state.rs +++ b/ecmascript/parser/src/lexer/state.rs @@ -1,4 +1,5 @@ use super::{Input, Lexer}; +use enum_kind::Kind; use slog::Logger; use swc_common::BytePos; use token::*; diff --git a/ecmascript/parser/src/lib.rs b/ecmascript/parser/src/lib.rs index 20380bd868e..a5b5f25b23d 100644 --- a/ecmascript/parser/src/lib.rs +++ b/ecmascript/parser/src/lib.rs @@ -10,15 +10,14 @@ #![deny(unsafe_code)] extern crate either; -extern crate parser_macros; +extern crate swc_ecma_parser_macros as parser_macros; #[macro_use] extern crate slog; #[macro_use(js_word)] extern crate swc_atoms; +extern crate enum_kind; extern crate swc_common; extern crate swc_ecma_ast as ast; -#[macro_use] -extern crate swc_macros; #[cfg(test)] #[macro_use] extern crate testing; diff --git a/ecmascript/parser/src/token/mod.rs b/ecmascript/parser/src/token/mod.rs index 6ca98fcf665..358b51140a2 100644 --- a/ecmascript/parser/src/token/mod.rs +++ b/ecmascript/parser/src/token/mod.rs @@ -4,6 +4,7 @@ pub(crate) use self::{AssignOpToken::*, BinOpToken::*, Keyword::*, Token::*, Word::*}; pub(crate) use ast::AssignOp as AssignOpToken; use ast::{BinaryOp, Str}; +use enum_kind::Kind; use std::fmt::{self, Debug, Display, Formatter}; use swc_atoms::JsWord; use swc_common::{Fold, Span}; diff --git a/ecmascript/transforms/src/compat/es2015/arrow.rs b/ecmascript/transforms/src/compat/es2015/arrow.rs index 94df48499b7..f6cdc131a59 100644 --- a/ecmascript/transforms/src/compat/es2015/arrow.rs +++ b/ecmascript/transforms/src/compat/es2015/arrow.rs @@ -1,5 +1,5 @@ +use ast::*; use swc_common::{Fold, FoldWith}; -use swc_ecma_ast::*; /// Compile ES2015 arrow functions to ES5 /// diff --git a/ecmascript/transforms/src/compat/es2015/classes/mod.rs b/ecmascript/transforms/src/compat/es2015/classes/mod.rs index 36ef003ff40..1b593b10db0 100644 --- a/ecmascript/transforms/src/compat/es2015/classes/mod.rs +++ b/ecmascript/transforms/src/compat/es2015/classes/mod.rs @@ -4,7 +4,7 @@ use std::{ sync::{atomic::Ordering, Arc}, }; use swc_common::{Fold, FoldWith, Span, Spanned, DUMMY_SP}; -use swc_ecma_ast::*; +use ast::*; #[cfg(test)] mod tests; @@ -351,7 +351,7 @@ impl Classes { fn mk_arg_obj_for_create_class(props: Vec) -> ExprOrSpread { if props.is_empty() { - return expr!(DUMMY_SP, null).as_arg(); + return quote_expr!(DUMMY_SP, null).as_arg(); } Expr::Array(ArrayLit { span: DUMMY_SP, diff --git a/ecmascript/transforms/src/compat/es2015/mod.rs b/ecmascript/transforms/src/compat/es2015/mod.rs index 8fcc4c76a99..9386bb1cf6a 100644 --- a/ecmascript/transforms/src/compat/es2015/mod.rs +++ b/ecmascript/transforms/src/compat/es2015/mod.rs @@ -4,9 +4,9 @@ pub use self::{ }; use super::helpers::Helpers; +use ast::Module; use std::sync::Arc; use swc_common::Fold; -use swc_ecma_ast::Module; mod arrow; mod classes; diff --git a/ecmascript/transforms/src/compat/es2015/shorthand_property.rs b/ecmascript/transforms/src/compat/es2015/shorthand_property.rs index 93a9821673f..8bf115e25ca 100644 --- a/ecmascript/transforms/src/compat/es2015/shorthand_property.rs +++ b/ecmascript/transforms/src/compat/es2015/shorthand_property.rs @@ -1,5 +1,5 @@ use swc_common::{Fold, FoldWith}; -use swc_ecma_ast::*; +use ast::*; /// Compile ES2015 shorthand properties to ES5 /// diff --git a/ecmascript/transforms/src/compat/es2015/spread.rs b/ecmascript/transforms/src/compat/es2015/spread.rs index f35cf73553c..e992bc11c37 100644 --- a/ecmascript/transforms/src/compat/es2015/spread.rs +++ b/ecmascript/transforms/src/compat/es2015/spread.rs @@ -4,7 +4,7 @@ use std::{ sync::{atomic::Ordering, Arc}, }; use swc_common::{Fold, FoldWith, Span, DUMMY_SP}; -use swc_ecma_ast::*; +use ast::*; /// es2015 - `SpreadElement` #[derive(Debug, Clone, Default)] @@ -49,7 +49,11 @@ impl Fold for Spread { // // f.apply(undefined, args) // - callee.apply(span, expr!(DUMMY_SP, undefined), vec![args_array.as_arg()]) + callee.apply( + span, + quote_expr!(DUMMY_SP, undefined), + vec![args_array.as_arg()], + ) } Expr::New(NewExpr { callee, @@ -71,7 +75,7 @@ impl Fold for Spread { let args = concat_args( &self.helpers, span, - vec![expr!(span, null).as_arg()] + vec![quote_expr!(span, null).as_arg()] .into_iter() .chain(args) .collect(), diff --git a/ecmascript/transforms/src/compat/es2015/sticky_regex.rs b/ecmascript/transforms/src/compat/es2015/sticky_regex.rs index 23a60481690..acaac64bceb 100644 --- a/ecmascript/transforms/src/compat/es2015/sticky_regex.rs +++ b/ecmascript/transforms/src/compat/es2015/sticky_regex.rs @@ -1,7 +1,7 @@ +use ast::*; use crate::util::ExprFactory; use std::iter; use swc_common::{Fold, FoldWith}; -use swc_ecma_ast::*; /// Compile ES2015 sticky regex to an ES5 RegExp constructor /// diff --git a/ecmascript/transforms/src/compat/es2015/template_literal.rs b/ecmascript/transforms/src/compat/es2015/template_literal.rs index 1c066d64af9..5cfc09c7549 100644 --- a/ecmascript/transforms/src/compat/es2015/template_literal.rs +++ b/ecmascript/transforms/src/compat/es2015/template_literal.rs @@ -1,5 +1,5 @@ +use ast::*; use swc_common::{Fold, FoldWith}; -use swc_ecma_ast::*; #[derive(Debug, Clone, Copy, Default)] pub struct TemplateLiteral; diff --git a/ecmascript/transforms/src/compat/es2016/exponentation.rs b/ecmascript/transforms/src/compat/es2016/exponentation.rs index 2153d9b28ec..3d7d074d7a6 100644 --- a/ecmascript/transforms/src/compat/es2016/exponentation.rs +++ b/ecmascript/transforms/src/compat/es2016/exponentation.rs @@ -1,6 +1,6 @@ use crate::util::ExprFactory; use swc_common::{Fold, FoldWith, Span}; -use swc_ecma_ast::*; +use ast::*; /// `@babel/plugin-transform-exponentiation-operator` /// diff --git a/ecmascript/transforms/src/compat/es2016/mod.rs b/ecmascript/transforms/src/compat/es2016/mod.rs index f31d355e65d..506bd7b471b 100644 --- a/ecmascript/transforms/src/compat/es2016/mod.rs +++ b/ecmascript/transforms/src/compat/es2016/mod.rs @@ -1,6 +1,6 @@ pub use self::exponentation::Exponentation; +use ast::Module; use swc_common::Fold; -use swc_ecma_ast::Module; mod exponentation; diff --git a/ecmascript/transforms/src/compat/es3/member_expr_lits.rs b/ecmascript/transforms/src/compat/es3/member_expr_lits.rs index d12230b8ceb..f758391da8e 100644 --- a/ecmascript/transforms/src/compat/es3/member_expr_lits.rs +++ b/ecmascript/transforms/src/compat/es3/member_expr_lits.rs @@ -1,5 +1,5 @@ +use ast::*; use swc_common::{Fold, FoldWith}; -use swc_ecma_ast::*; /// babel: `transform-member-expression-literals` /// diff --git a/ecmascript/transforms/src/compat/es3/mod.rs b/ecmascript/transforms/src/compat/es3/mod.rs index c73c25f6f3d..42934d49c2f 100644 --- a/ecmascript/transforms/src/compat/es3/mod.rs +++ b/ecmascript/transforms/src/compat/es3/mod.rs @@ -1,5 +1,5 @@ +use ast::Module; use swc_common::Fold; -use swc_ecma_ast::Module; pub use self::{ member_expr_lits::MemberExprLit, prop_lits::PropertyLiteral, reserved_word::ReservedWord, diff --git a/ecmascript/transforms/src/compat/es3/prop_lits.rs b/ecmascript/transforms/src/compat/es3/prop_lits.rs index 058f750364c..25ee85626a3 100644 --- a/ecmascript/transforms/src/compat/es3/prop_lits.rs +++ b/ecmascript/transforms/src/compat/es3/prop_lits.rs @@ -1,5 +1,5 @@ use swc_common::{Fold, FoldWith}; -use swc_ecma_ast::*; +use ast::*; /// babel: `transform-property-literals` /// diff --git a/ecmascript/transforms/src/compat/es3/reserved_word.rs b/ecmascript/transforms/src/compat/es3/reserved_word.rs index 6230d05ea9b..5a7029f8c1f 100644 --- a/ecmascript/transforms/src/compat/es3/reserved_word.rs +++ b/ecmascript/transforms/src/compat/es3/reserved_word.rs @@ -1,5 +1,5 @@ +use ast::*; use swc_common::{Fold, FoldWith}; -use swc_ecma_ast::*; /// babel: `@babel/plugin-transform-reserved-words` /// diff --git a/ecmascript/transforms/src/compat/helpers/mod.rs b/ecmascript/transforms/src/compat/helpers/mod.rs index ba49b47ece8..f5da6a1bb2a 100644 --- a/ecmascript/transforms/src/compat/helpers/mod.rs +++ b/ecmascript/transforms/src/compat/helpers/mod.rs @@ -1,3 +1,4 @@ +use ast::*; use std::{ ops::BitOr, rc::Rc, @@ -10,7 +11,6 @@ use swc_common::{ errors::{ColorConfig, Handler}, FileName, Fold, SourceMap, }; -use swc_ecma_ast::*; use swc_ecma_parser::{Parser, Session, SourceFileInput}; /// Tracks used helper methods. (e.g. __extends) diff --git a/ecmascript/transforms/src/fixer.rs b/ecmascript/transforms/src/fixer.rs index a83bc3d08c1..cff4b82772d 100644 --- a/ecmascript/transforms/src/fixer.rs +++ b/ecmascript/transforms/src/fixer.rs @@ -1,6 +1,6 @@ +use ast::*; use crate::util::ExprFactory; use swc_common::{Fold, FoldWith, Spanned}; -use swc_ecma_ast::*; pub fn fixer() -> impl Fold { Fixer diff --git a/ecmascript/transforms/src/lib.rs b/ecmascript/transforms/src/lib.rs index 247d053866a..95c32bbfffe 100644 --- a/ecmascript/transforms/src/lib.rs +++ b/ecmascript/transforms/src/lib.rs @@ -7,21 +7,21 @@ #[macro_use] extern crate slog; -#[macro_use] +#[macro_use(js_word)] extern crate swc_atoms; extern crate swc_common; -extern crate swc_ecma_ast; +extern crate swc_ecma_ast as ast; #[cfg(test)] extern crate swc_ecma_codegen; extern crate swc_ecma_parser; #[cfg(test)] #[macro_use] extern crate pretty_assertions; -#[macro_use] -#[cfg(test)] -extern crate testing; #[cfg(test)] extern crate sourcemap; +#[cfg(test)] +#[macro_use] +extern crate testing; pub use self::simplify::simplifier; diff --git a/ecmascript/transforms/src/quote.rs b/ecmascript/transforms/src/quote.rs index 072d3d46f16..80e593d5b74 100644 --- a/ecmascript/transforms/src/quote.rs +++ b/ecmascript/transforms/src/quote.rs @@ -4,7 +4,7 @@ macro_rules! quote_ident { quote_ident!(::swc_common::DUMMY_SP, $s) }; ($span:expr, $s:expr) => {{ - ::swc_ecma_ast::Ident::new($s.into(), $span) + ::ast::Ident::new($s.into(), $span) }}; } @@ -14,7 +14,7 @@ macro_rules! quote_str { quote_str!(::swc_common::DUMMY_SP, $s) }; ($span:expr, $s:expr) => {{ - ::swc_ecma_ast::Str { + ::ast::Str { span: $span, value: $s.into(), has_escape: false, @@ -28,26 +28,14 @@ macro_rules! mark { ($span:expr) => {{ let mut span = $span; let parent = span.remove_mark(); - $span.apply_mark(::swc_common::pos::Mark::fresh(parent)) - }}; -} - -#[macro_export] -macro_rules! expr { - ($span:expr, null) => {{ - use swc_ecma_ast::*; - Expr::Lit(Lit::Null(Null { span: $span })) - }}; - - ($span:expr, undefined) => {{ - box Expr::Ident(Ident::new(js_word!("undefined"), $span)) + $span.apply_mark(::swc_common::hygiene::Mark::fresh(parent)) }}; } #[macro_export] macro_rules! quote_expr { ($span:expr, null) => {{ - use swc_ecma_ast::*; + use ast::*; Expr::Lit(Lit::Null(Null { span: $span })) }}; @@ -67,8 +55,8 @@ macro_rules! quote_expr { #[macro_export] macro_rules! member_expr { ($span:expr, $first:ident) => {{ - use swc_ecma_ast::*; - box Expr::Ident(Ident::new(stringify!($first).into(), $span)) + use ast::Expr; + box Expr::Ident(quote_ident!($span, stringify!($first))) }}; ($span:expr, $first:ident . $($rest:tt)+) => {{ @@ -89,7 +77,7 @@ macro_rules! member_expr { }}; (@EXT, $span:expr, $obj:expr, $first:ident) => {{ - use swc_ecma_ast::*; + use ast::*; let prop = member_expr!($span, $first); box Expr::Member(MemberExpr{ @@ -103,8 +91,8 @@ macro_rules! member_expr { #[cfg(test)] mod tests { + use ast::*; use swc_common::DUMMY_SP as span; - use swc_ecma_ast::*; #[test] fn quote_member_expr() { assert_eq_ignore_span!( diff --git a/ecmascript/transforms/src/scope.rs b/ecmascript/transforms/src/scope.rs index 03c857159e9..6fd37502a6b 100644 --- a/ecmascript/transforms/src/scope.rs +++ b/ecmascript/transforms/src/scope.rs @@ -1,5 +1,5 @@ use swc_common::{Fold, FoldWith}; -use swc_ecma_ast::*; +use ast::*; pub trait FoldScope { /// `scope`: Scope which contains `node`. diff --git a/ecmascript/transforms/src/simplify/expr/mod.rs b/ecmascript/transforms/src/simplify/expr/mod.rs index 1f196253202..80710b34973 100644 --- a/ecmascript/transforms/src/simplify/expr/mod.rs +++ b/ecmascript/transforms/src/simplify/expr/mod.rs @@ -2,7 +2,7 @@ use crate::util::*; use std::iter; use swc_atoms::JsWord; use swc_common::{Fold, FoldWith, Span, Spanned}; -use swc_ecma_ast::{Ident, Lit, *}; +use ast::{Ident, Lit, *}; #[cfg(test)] mod tests; diff --git a/ecmascript/transforms/src/simplify/mod.rs b/ecmascript/transforms/src/simplify/mod.rs index f7327ac5ccd..ac9acf202eb 100644 --- a/ecmascript/transforms/src/simplify/mod.rs +++ b/ecmascript/transforms/src/simplify/mod.rs @@ -1,8 +1,8 @@ //! Ported from closure compiler. use self::expr::SimplifyExpr; +use ast::*; use crate::util::*; use swc_common::{Fold, FoldWith, DUMMY_SP}; -use swc_ecma_ast::*; mod expr; #[cfg(test)] diff --git a/ecmascript/transforms/src/tests.rs b/ecmascript/transforms/src/tests.rs index d1710e7922e..eb81027b766 100644 --- a/ecmascript/transforms/src/tests.rs +++ b/ecmascript/transforms/src/tests.rs @@ -6,7 +6,7 @@ use std::{ sync::{Arc, RwLock}, }; use swc_common::{errors::Handler, FileName, Fold, FoldWith, SourceMap}; -use swc_ecma_ast::*; +use ast::*; use swc_ecma_codegen::Emitter; use swc_ecma_parser::{Parser, Session, SourceFileInput}; diff --git a/ecmascript/transforms/src/util/factory.rs b/ecmascript/transforms/src/util/factory.rs index ce273fed9fd..e42b8ea09ac 100644 --- a/ecmascript/transforms/src/util/factory.rs +++ b/ecmascript/transforms/src/util/factory.rs @@ -1,6 +1,6 @@ +use ast::*; use std::iter; use swc_common::{Span, Spanned}; -use swc_ecma_ast::*; /// Extension methods for [Expr]. pub trait ExprFactory: Into { diff --git a/ecmascript/transforms/src/util/mod.rs b/ecmascript/transforms/src/util/mod.rs index 659e04673c2..c8f6fb53e5f 100644 --- a/ecmascript/transforms/src/util/mod.rs +++ b/ecmascript/transforms/src/util/mod.rs @@ -9,6 +9,7 @@ pub use self::{ }, Purity::{MayBeImpure, Pure}, }; +use ast::*; use std::{ borrow::Cow, f64::{INFINITY, NAN}, @@ -16,7 +17,6 @@ use std::{ ops::Add, }; use swc_atoms::JsWord; -use swc_ecma_ast::*; mod factory; mod value; diff --git a/libswc/Cargo.toml b/libswc/Cargo.toml index 927fe496fa9..67274237998 100644 --- a/libswc/Cargo.toml +++ b/libswc/Cargo.toml @@ -8,7 +8,6 @@ edition = "2018" swc_atoms = { path = "../atoms" } swc_common = { path = "../common" } swc_ecmascript = { path = "../ecmascript" } -swc_macros = { path = "../macros" } rayon = "1.0.3" slog = "2" sourcemap = "2.2" \ No newline at end of file diff --git a/libswc/src/lib.rs b/libswc/src/lib.rs index 778c2dbb231..4e84c8f0775 100644 --- a/libswc/src/lib.rs +++ b/libswc/src/lib.rs @@ -7,7 +7,6 @@ pub extern crate sourcemap; pub extern crate swc_atoms as atoms; pub extern crate swc_common as common; pub extern crate swc_ecmascript as ecmascript; -pub extern crate swc_macros as macros; use self::{ common::{errors::Handler, SourceMap}, diff --git a/macros/Cargo.toml b/macros/Cargo.toml deleted file mode 100644 index 5781d6513e3..00000000000 --- a/macros/Cargo.toml +++ /dev/null @@ -1,11 +0,0 @@ -[package] -name = "swc_macros" -version = "0.1.0" -authors = ["강동윤 "] - -[lib] - -[dependencies] -ast_node = { path = "./ast_node" } -enum_kind = { path = "./enum_kind" } -string_enum = { path = "./string_enum" } \ No newline at end of file diff --git a/macros/ast_node/Cargo.toml b/macros/ast_node/Cargo.toml index ad0b98986af..3176c0372bb 100644 --- a/macros/ast_node/Cargo.toml +++ b/macros/ast_node/Cargo.toml @@ -19,5 +19,4 @@ features = ["derive", "fold", "parsing", "printing"] [dev-dependencies] -swc_macros = { path = "../" } swc_common = { path = "../../common" } \ No newline at end of file diff --git a/macros/ast_node/src/lib.rs b/macros/ast_node/src/lib.rs index 1e1557512c4..86353afe35b 100644 --- a/macros/ast_node/src/lib.rs +++ b/macros/ast_node/src/lib.rs @@ -68,11 +68,12 @@ pub fn ast_node( let mut item = Quote::new(Span::call_site()); item = match input.data { Data::Enum(..) => item.quote_with(smart_quote!(Vars { input }, { - #[derive(FromVariant, Spanned, Fold, Clone, Debug, PartialEq)] + #[derive(::swc_common::FromVariant, ::swc_common::Spanned, + ::swc_common::Fold, Clone, Debug, PartialEq)] input })), _ => item.quote_with(smart_quote!(Vars { input }, { - #[derive(Spanned, Fold, Clone, Debug, PartialEq)] + #[derive(::swc_common::Spanned, ::swc_common::Fold, Clone, Debug, PartialEq)] input })), }; diff --git a/macros/ast_node/tests/attr_interop.rs b/macros/ast_node/tests/attr_interop.rs index 6ddde4a483b..0a74eecb55c 100644 --- a/macros/ast_node/tests/attr_interop.rs +++ b/macros/ast_node/tests/attr_interop.rs @@ -1,8 +1,6 @@ //! Test that `#[span]` and `#[fold]` can be used at same time. extern crate swc_common; -extern crate swc_macros; -use swc_common::{Fold, Span, Spanned}; -use swc_macros::ast_node; +use swc_common::{ast_node, Fold, Span, Spanned}; #[ast_node] // See https://github.com/rust-lang/rust/issues/44925 diff --git a/macros/ast_node/tests/fold_bound.rs b/macros/ast_node/tests/fold_bound.rs index 791d7435389..bbb8d876a0e 100644 --- a/macros/ast_node/tests/fold_bound.rs +++ b/macros/ast_node/tests/fold_bound.rs @@ -3,7 +3,6 @@ #![feature(specialization)] extern crate swc_common; -extern crate swc_macros; use std::fmt::Debug; use swc_common::{AstNode, Fold}; diff --git a/macros/ast_node/tests/fold_ignore.rs b/macros/ast_node/tests/fold_ignore.rs index e70214a751d..403a6d6614b 100644 --- a/macros/ast_node/tests/fold_ignore.rs +++ b/macros/ast_node/tests/fold_ignore.rs @@ -1,7 +1,6 @@ #![feature(specialization)] extern crate swc_common; -extern crate swc_macros; use swc_common::{Fold, FoldWith}; struct MyFold; diff --git a/macros/ast_node/tests/fold_simple.rs b/macros/ast_node/tests/fold_simple.rs index 0b03d0861c0..f55e8209ef4 100644 --- a/macros/ast_node/tests/fold_simple.rs +++ b/macros/ast_node/tests/fold_simple.rs @@ -1,7 +1,6 @@ #![feature(specialization)] extern crate swc_common; -extern crate swc_macros; use swc_common::{Fold, FoldWith}; pub trait AssertFold: Fold {} diff --git a/macros/src/lib.rs b/macros/src/lib.rs deleted file mode 100644 index f69c909cea1..00000000000 --- a/macros/src/lib.rs +++ /dev/null @@ -1,13 +0,0 @@ -//! Macros used by swc project. -#![allow(unused_imports)] - -#[macro_use] -extern crate ast_node; -#[macro_use] -extern crate enum_kind; -#[macro_use] -extern crate string_enum; - -pub use ast_node::*; -pub use enum_kind::*; -pub use string_enum::*;