- rename packages to be consistent
 - `swc_macros` is removed. Now macros are imported with `extern crate macro_name` instead of `extern crate swc_macros`.
 - manage atoms with words.txt file
This commit is contained in:
강동윤 2018-11-17 16:38:23 +09:00 committed by GitHub
parent fb08c18f7e
commit b3a9d1a264
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
66 changed files with 178 additions and 215 deletions

View File

@ -97,6 +97,17 @@ swc jsc --optimize test.js
use(8 + 8, Math.pow(8, 8)); 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.

View File

@ -3,85 +3,8 @@ extern crate string_cache_codegen;
use std::{env, path::Path}; use std::{env, path::Path};
fn main() { fn main() {
gen( let strs = include_str!("words.txt").split("\n").collect::<Vec<_>>();
"js_word", gen("js_word", "JsWord", &strs);
"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",
],
);
} }
fn gen(mac_name: &str, type_name: &str, atoms: &[&str]) { fn gen(mac_name: &str, type_name: &str, atoms: &[&str]) {

5
atoms/scripts/sort.sh Executable file
View File

@ -0,0 +1,5 @@
#!/bin/bash
set -eu
cat words.txt | sort > words_sorted.txt
mv words_sorted.txt words.txt

68
atoms/words.txt Normal file
View File

@ -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

View File

@ -4,10 +4,10 @@ version = "0.1.0"
authors = ["강동윤 <kdy1@outlook.kr>"] authors = ["강동윤 <kdy1@outlook.kr>"]
[dependencies] [dependencies]
ast_node = { path = "../macros/ast_node" }
string_cache = "0.7" string_cache = "0.7"
either = "1.5" either = "1.5"
rustc-ap-rustc_errors = "297" rustc-ap-rustc_errors = "297"
rustc-ap-rustc_data_structures = "297" rustc-ap-rustc_data_structures = "297"
rustc-ap-syntax = "297" rustc-ap-syntax = "297"
rustc-ap-syntax_pos = "297" rustc-ap-syntax_pos = "297"
swc_macros = { path = "../macros" }

View File

@ -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<N: Debug + PartialEq + Clone + Spanned> AstNode for N {}

View File

@ -1,6 +1,5 @@
use either::Either; use either::Either;
use string_cache::{Atom, StaticAtomSet}; use string_cache::{Atom, StaticAtomSet};
pub use swc_macros::Fold;
/// Folder based on a type system. /// Folder based on a type system.
/// ///

View File

@ -3,25 +3,31 @@
#![feature(try_trait)] #![feature(try_trait)]
#![feature(never_type)] #![feature(never_type)]
#![feature(specialization)] #![feature(specialization)]
extern crate ast_node;
extern crate either; extern crate either;
extern crate rustc_data_structures; extern crate rustc_data_structures;
extern crate rustc_errors; extern crate rustc_errors;
extern crate string_cache; extern crate string_cache;
extern crate swc_macros;
extern crate syntax; extern crate syntax;
extern crate syntax_pos; extern crate syntax_pos;
pub use self::{ pub use self::{
ast_node::AstNode,
errors::{SourceMapper, SourceMapperDyn}, errors::{SourceMapper, SourceMapperDyn},
fold::{Fold, FoldWith}, fold::{Fold, FoldWith},
pos::*, pos::*,
}; };
pub use ast_node::{ast_node, Fold, FromVariant, Spanned};
use std::fmt::Debug;
pub use syntax::source_map::{ pub use syntax::source_map::{
FileLines, FileLoader, FileName, FilePathMapping, SourceMap, SpanSnippetError, FileLines, FileLoader, FileName, FilePathMapping, SourceMap, SpanSnippetError,
}; };
mod ast_node;
/// A marker trait for ast nodes.
pub trait AstNode: Debug + PartialEq + Clone + Spanned {}
impl<N: Debug + PartialEq + Clone + Spanned> AstNode for N {}
pub mod errors; pub mod errors;
mod fold; mod fold;
pub mod macros; pub mod macros;
pub mod pos; mod pos;

View File

@ -1,5 +1,4 @@
use fold::FoldWith; use fold::FoldWith;
pub use swc_macros::Spanned;
pub use syntax_pos::{ pub use syntax_pos::{
hygiene, BytePos, ExpnFormat, ExpnInfo, FileName, Globals, Mark, MultiSpan, SourceFile, Span, hygiene, BytePos, ExpnFormat, ExpnInfo, FileName, Globals, Mark, MultiSpan, SourceFile, Span,
SpanData, SyntaxContext, DUMMY_SP, GLOBALS, NO_EXPANSION, SpanData, SyntaxContext, DUMMY_SP, GLOBALS, NO_EXPANSION,

View File

@ -5,5 +5,6 @@ authors = ["강동윤 <kdy1@outlook.kr>"]
[dependencies] [dependencies]
swc_atoms = { path = "../../atoms" } swc_atoms = { path = "../../atoms" }
swc_macros = { path = "../../macros" } swc_common = { path = "../../common" }
swc_common = { path = "../../common" } enum_kind = { path = "../../macros/enum_kind" }
string_enum = { path = "../../macros/string_enum" }

View File

@ -1,6 +1,5 @@
use super::{Expr, Function, PropName}; use super::{Expr, Function, PropName};
use swc_common::Span; use swc_common::{ast_node, Fold, Span};
use swc_macros::ast_node;
#[ast_node] #[ast_node]
pub struct Class { pub struct Class {

View File

@ -1,6 +1,5 @@
use super::{Class, Expr, Function, Ident, Pat}; use super::{Class, Expr, Function, Ident, Pat};
use swc_common::Span; use swc_common::{ast_node, Fold, Span};
use swc_macros::ast_node;
#[ast_node] #[ast_node]
pub enum Decl { pub enum Decl {

View File

@ -1,8 +1,7 @@
use super::{ use super::{
AssignOp, BinaryOp, BlockStmt, Class, Function, Ident, Lit, Pat, Prop, UnaryOp, UpdateOp, AssignOp, BinaryOp, BlockStmt, Class, Function, Ident, Lit, Pat, Prop, UnaryOp, UpdateOp,
}; };
use swc_common::{Span, Spanned}; use swc_common::{ast_node, Fold, Span, Spanned};
use swc_macros::ast_node;
#[ast_node] #[ast_node]
pub enum Expr { pub enum Expr {

View File

@ -1,6 +1,5 @@
use super::{BlockStmt, Pat}; use super::{BlockStmt, Pat};
use swc_common::Span; use swc_common::{ast_node, Span};
use swc_macros::ast_node;
/// Common parts of function and method. /// Common parts of function and method.
#[ast_node] #[ast_node]

View File

@ -8,10 +8,12 @@
#![deny(unreachable_pub)] #![deny(unreachable_pub)]
#![deny(variant_size_differences)] #![deny(variant_size_differences)]
#[macro_use]
extern crate enum_kind;
#[macro_use]
extern crate string_enum;
extern crate swc_atoms; extern crate swc_atoms;
extern crate swc_common; extern crate swc_common;
#[macro_use]
extern crate swc_macros;
pub use self::{ pub use self::{
class::{Class, ClassMethod, ClassMethodKind}, class::{Class, ClassMethod, ClassMethodKind},
@ -43,8 +45,7 @@ pub use self::{
}; };
use std::fmt::{self, Debug, Display, Formatter}; use std::fmt::{self, Debug, Display, Formatter};
use swc_atoms::JsWord; use swc_atoms::JsWord;
use swc_common::Span; use swc_common::{Fold, Span, Spanned};
use swc_macros::Fold;
mod class; mod class;
mod decl; mod decl;

View File

@ -1,7 +1,7 @@
use std::fmt::{self, Display, Formatter}; use std::fmt::{self, Display, Formatter};
use swc_atoms::JsWord; use swc_atoms::JsWord;
use swc_common::Span; use swc_common::Span;
use swc_macros::ast_node; use swc_common::ast_node;
#[ast_node] #[ast_node]
pub enum Lit { pub enum Lit {

View File

@ -1,6 +1,5 @@
use super::{ModuleDecl, Stmt}; use super::{ModuleDecl, Stmt};
use swc_common::Span; use swc_common::{ast_node, Span};
use swc_macros::ast_node;
#[ast_node] #[ast_node]
pub struct Module { pub struct Module {

View File

@ -1,6 +1,6 @@
use super::{ClassExpr, Decl, Expr, FnExpr, Ident, Str, VarDecl}; use super::{ClassExpr, Decl, Expr, FnExpr, Ident, Str, VarDecl};
use swc_common::Span; use swc_common::Span;
use swc_macros::ast_node; use swc_common::ast_node;
#[ast_node] #[ast_node]
pub enum ModuleDecl { pub enum ModuleDecl {

View File

@ -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)] #[derive(Kind, Fold, StringEnum, Clone, Copy, Eq, PartialEq, PartialOrd, Ord, Hash)]
#[kind(function(precedence = "u8"))] #[kind(function(precedence = "u8"))]

View File

@ -1,6 +1,5 @@
use super::{Expr, Ident, PropName}; use super::{Expr, Ident, PropName};
use swc_common::Span; use swc_common::{ast_node, Span};
use swc_macros::ast_node;
#[ast_node] #[ast_node]
pub enum Pat { pub enum Pat {

View File

@ -1,6 +1,5 @@
use super::{BlockStmt, Expr, Function, Ident, Number, Pat, Str}; use super::{BlockStmt, Expr, Function, Ident, Number, Pat, Str};
use swc_common::Span; use swc_common::{ast_node, Span};
use swc_macros::ast_node;
#[ast_node] #[ast_node]
pub enum Prop { pub enum Prop {

View File

@ -1,6 +1,6 @@
use super::{Decl, Expr, Ident, Pat, VarDecl}; use super::{Decl, Expr, Ident, Pat, VarDecl};
use swc_common::Span; use swc_common::Span;
use swc_macros::ast_node; use swc_common::ast_node;
/// Use when only block statements are allowed. /// Use when only block statements are allowed.
#[ast_node] #[ast_node]

View File

@ -8,7 +8,7 @@ bitflags = "1"
swc_atoms = { path = "../../atoms" } swc_atoms = { path = "../../atoms" }
swc_common = { path = "../../common" } swc_common = { path = "../../common" }
swc_ecma_ast = { path = "../ast" } swc_ecma_ast = { path = "../ast" }
ecma_codegen_macros = { path = "./macros" } swc_ecma_codegen_macros = { path = "./macros" }
sourcemap = "2.2" sourcemap = "2.2"
[dev-dependencies] [dev-dependencies]

View File

@ -1,5 +1,5 @@
[package] [package]
name = "ecma_codegen_macros" name = "swc_ecma_codegen_macros"
version = "0.1.0" version = "0.1.0"
authors = ["강동윤 <kdy1@outlook.kr>"] authors = ["강동윤 <kdy1@outlook.kr>"]

View File

@ -1,7 +1,7 @@
use super::{list::ListFormat, Emitter, Result}; use super::{list::ListFormat, Emitter, Result};
use ecma_codegen_macros::emitter;
use swc_common::Spanned; use swc_common::Spanned;
use swc_ecma_ast::*; use swc_ecma_ast::*;
use swc_ecma_codegen_macros::emitter;
impl<'a> Emitter<'a> { impl<'a> Emitter<'a> {
#[emitter] #[emitter]

View File

@ -8,9 +8,9 @@
#[macro_use] #[macro_use]
extern crate bitflags; extern crate bitflags;
extern crate ecma_codegen_macros;
extern crate sourcemap; extern crate sourcemap;
extern crate swc_atoms; extern crate swc_atoms;
extern crate swc_ecma_codegen_macros;
#[macro_use] #[macro_use]
extern crate swc_common; extern crate swc_common;
extern crate swc_ecma_ast; extern crate swc_ecma_ast;
@ -21,11 +21,11 @@ use self::{
text_writer::WriteJs, text_writer::WriteJs,
util::{SourceMapperExt, SpanExt, StartsWithAlphaNum}, util::{SourceMapperExt, SpanExt, StartsWithAlphaNum},
}; };
use ecma_codegen_macros::emitter;
use std::{collections::HashSet, io, rc::Rc}; use std::{collections::HashSet, io, rc::Rc};
use swc_atoms::JsWord; 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_ast::*;
use swc_ecma_codegen_macros::emitter;
#[macro_use] #[macro_use]
pub mod macros; pub mod macros;

View File

@ -5,10 +5,10 @@ authors = ["강동윤 <kdy1@outlook.kr>"]
[dependencies] [dependencies]
swc_atoms = { path = "../../atoms" } swc_atoms = { path = "../../atoms" }
swc_macros = { path = "../../macros" }
swc_common = { path = "../../common" } swc_common = { path = "../../common" }
swc_ecma_ast = { path = "../ast" } 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" unicode-xid = "0.1"
slog = "2.1" slog = "2.1"
either = { version = "1.4" } either = { version = "1.4" }

View File

@ -1,5 +1,5 @@
[package] [package]
name = "parser_macros" name = "swc_ecma_parser_macros"
version = "0.1.0" version = "0.1.0"
authors = ["강동윤 <kdy1@outlook.kr>"] authors = ["강동윤 <kdy1@outlook.kr>"]
@ -7,7 +7,7 @@ authors = ["강동윤 <kdy1@outlook.kr>"]
proc-macro = true proc-macro = true
[dependencies] [dependencies]
swc_macros_common = { path = "../../macros/common" } swc_macros_common = { path = "../../../macros/common" }
proc-macro2 = "0.4.4" proc-macro2 = "0.4.4"
[dependencies.syn] [dependencies.syn]

View File

@ -1,4 +1,5 @@
use super::{Input, Lexer}; use super::{Input, Lexer};
use enum_kind::Kind;
use slog::Logger; use slog::Logger;
use swc_common::BytePos; use swc_common::BytePos;
use token::*; use token::*;

View File

@ -10,15 +10,14 @@
#![deny(unsafe_code)] #![deny(unsafe_code)]
extern crate either; extern crate either;
extern crate parser_macros; extern crate swc_ecma_parser_macros as parser_macros;
#[macro_use] #[macro_use]
extern crate slog; extern crate slog;
#[macro_use(js_word)] #[macro_use(js_word)]
extern crate swc_atoms; extern crate swc_atoms;
extern crate enum_kind;
extern crate swc_common; extern crate swc_common;
extern crate swc_ecma_ast as ast; extern crate swc_ecma_ast as ast;
#[macro_use]
extern crate swc_macros;
#[cfg(test)] #[cfg(test)]
#[macro_use] #[macro_use]
extern crate testing; extern crate testing;

View File

@ -4,6 +4,7 @@
pub(crate) use self::{AssignOpToken::*, BinOpToken::*, Keyword::*, Token::*, Word::*}; pub(crate) use self::{AssignOpToken::*, BinOpToken::*, Keyword::*, Token::*, Word::*};
pub(crate) use ast::AssignOp as AssignOpToken; pub(crate) use ast::AssignOp as AssignOpToken;
use ast::{BinaryOp, Str}; use ast::{BinaryOp, Str};
use enum_kind::Kind;
use std::fmt::{self, Debug, Display, Formatter}; use std::fmt::{self, Debug, Display, Formatter};
use swc_atoms::JsWord; use swc_atoms::JsWord;
use swc_common::{Fold, Span}; use swc_common::{Fold, Span};

View File

@ -1,5 +1,5 @@
use ast::*;
use swc_common::{Fold, FoldWith}; use swc_common::{Fold, FoldWith};
use swc_ecma_ast::*;
/// Compile ES2015 arrow functions to ES5 /// Compile ES2015 arrow functions to ES5
/// ///

View File

@ -4,7 +4,7 @@ use std::{
sync::{atomic::Ordering, Arc}, sync::{atomic::Ordering, Arc},
}; };
use swc_common::{Fold, FoldWith, Span, Spanned, DUMMY_SP}; use swc_common::{Fold, FoldWith, Span, Spanned, DUMMY_SP};
use swc_ecma_ast::*; use ast::*;
#[cfg(test)] #[cfg(test)]
mod tests; mod tests;
@ -351,7 +351,7 @@ impl Classes {
fn mk_arg_obj_for_create_class(props: Vec<Expr>) -> ExprOrSpread { fn mk_arg_obj_for_create_class(props: Vec<Expr>) -> ExprOrSpread {
if props.is_empty() { if props.is_empty() {
return expr!(DUMMY_SP, null).as_arg(); return quote_expr!(DUMMY_SP, null).as_arg();
} }
Expr::Array(ArrayLit { Expr::Array(ArrayLit {
span: DUMMY_SP, span: DUMMY_SP,

View File

@ -4,9 +4,9 @@ pub use self::{
}; };
use super::helpers::Helpers; use super::helpers::Helpers;
use ast::Module;
use std::sync::Arc; use std::sync::Arc;
use swc_common::Fold; use swc_common::Fold;
use swc_ecma_ast::Module;
mod arrow; mod arrow;
mod classes; mod classes;

View File

@ -1,5 +1,5 @@
use swc_common::{Fold, FoldWith}; use swc_common::{Fold, FoldWith};
use swc_ecma_ast::*; use ast::*;
/// Compile ES2015 shorthand properties to ES5 /// Compile ES2015 shorthand properties to ES5
/// ///

View File

@ -4,7 +4,7 @@ use std::{
sync::{atomic::Ordering, Arc}, sync::{atomic::Ordering, Arc},
}; };
use swc_common::{Fold, FoldWith, Span, DUMMY_SP}; use swc_common::{Fold, FoldWith, Span, DUMMY_SP};
use swc_ecma_ast::*; use ast::*;
/// es2015 - `SpreadElement` /// es2015 - `SpreadElement`
#[derive(Debug, Clone, Default)] #[derive(Debug, Clone, Default)]
@ -49,7 +49,11 @@ impl Fold<Expr> for Spread {
// //
// f.apply(undefined, args) // 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 { Expr::New(NewExpr {
callee, callee,
@ -71,7 +75,7 @@ impl Fold<Expr> for Spread {
let args = concat_args( let args = concat_args(
&self.helpers, &self.helpers,
span, span,
vec![expr!(span, null).as_arg()] vec![quote_expr!(span, null).as_arg()]
.into_iter() .into_iter()
.chain(args) .chain(args)
.collect(), .collect(),

View File

@ -1,7 +1,7 @@
use ast::*;
use crate::util::ExprFactory; use crate::util::ExprFactory;
use std::iter; use std::iter;
use swc_common::{Fold, FoldWith}; use swc_common::{Fold, FoldWith};
use swc_ecma_ast::*;
/// Compile ES2015 sticky regex to an ES5 RegExp constructor /// Compile ES2015 sticky regex to an ES5 RegExp constructor
/// ///

View File

@ -1,5 +1,5 @@
use ast::*;
use swc_common::{Fold, FoldWith}; use swc_common::{Fold, FoldWith};
use swc_ecma_ast::*;
#[derive(Debug, Clone, Copy, Default)] #[derive(Debug, Clone, Copy, Default)]
pub struct TemplateLiteral; pub struct TemplateLiteral;

View File

@ -1,6 +1,6 @@
use crate::util::ExprFactory; use crate::util::ExprFactory;
use swc_common::{Fold, FoldWith, Span}; use swc_common::{Fold, FoldWith, Span};
use swc_ecma_ast::*; use ast::*;
/// `@babel/plugin-transform-exponentiation-operator` /// `@babel/plugin-transform-exponentiation-operator`
/// ///

View File

@ -1,6 +1,6 @@
pub use self::exponentation::Exponentation; pub use self::exponentation::Exponentation;
use ast::Module;
use swc_common::Fold; use swc_common::Fold;
use swc_ecma_ast::Module;
mod exponentation; mod exponentation;

View File

@ -1,5 +1,5 @@
use ast::*;
use swc_common::{Fold, FoldWith}; use swc_common::{Fold, FoldWith};
use swc_ecma_ast::*;
/// babel: `transform-member-expression-literals` /// babel: `transform-member-expression-literals`
/// ///

View File

@ -1,5 +1,5 @@
use ast::Module;
use swc_common::Fold; use swc_common::Fold;
use swc_ecma_ast::Module;
pub use self::{ pub use self::{
member_expr_lits::MemberExprLit, prop_lits::PropertyLiteral, reserved_word::ReservedWord, member_expr_lits::MemberExprLit, prop_lits::PropertyLiteral, reserved_word::ReservedWord,

View File

@ -1,5 +1,5 @@
use swc_common::{Fold, FoldWith}; use swc_common::{Fold, FoldWith};
use swc_ecma_ast::*; use ast::*;
/// babel: `transform-property-literals` /// babel: `transform-property-literals`
/// ///

View File

@ -1,5 +1,5 @@
use ast::*;
use swc_common::{Fold, FoldWith}; use swc_common::{Fold, FoldWith};
use swc_ecma_ast::*;
/// babel: `@babel/plugin-transform-reserved-words` /// babel: `@babel/plugin-transform-reserved-words`
/// ///

View File

@ -1,3 +1,4 @@
use ast::*;
use std::{ use std::{
ops::BitOr, ops::BitOr,
rc::Rc, rc::Rc,
@ -10,7 +11,6 @@ use swc_common::{
errors::{ColorConfig, Handler}, errors::{ColorConfig, Handler},
FileName, Fold, SourceMap, FileName, Fold, SourceMap,
}; };
use swc_ecma_ast::*;
use swc_ecma_parser::{Parser, Session, SourceFileInput}; use swc_ecma_parser::{Parser, Session, SourceFileInput};
/// Tracks used helper methods. (e.g. __extends) /// Tracks used helper methods. (e.g. __extends)

View File

@ -1,6 +1,6 @@
use ast::*;
use crate::util::ExprFactory; use crate::util::ExprFactory;
use swc_common::{Fold, FoldWith, Spanned}; use swc_common::{Fold, FoldWith, Spanned};
use swc_ecma_ast::*;
pub fn fixer() -> impl Fold<Module> { pub fn fixer() -> impl Fold<Module> {
Fixer Fixer

View File

@ -7,21 +7,21 @@
#[macro_use] #[macro_use]
extern crate slog; extern crate slog;
#[macro_use] #[macro_use(js_word)]
extern crate swc_atoms; extern crate swc_atoms;
extern crate swc_common; extern crate swc_common;
extern crate swc_ecma_ast; extern crate swc_ecma_ast as ast;
#[cfg(test)] #[cfg(test)]
extern crate swc_ecma_codegen; extern crate swc_ecma_codegen;
extern crate swc_ecma_parser; extern crate swc_ecma_parser;
#[cfg(test)] #[cfg(test)]
#[macro_use] #[macro_use]
extern crate pretty_assertions; extern crate pretty_assertions;
#[macro_use]
#[cfg(test)]
extern crate testing;
#[cfg(test)] #[cfg(test)]
extern crate sourcemap; extern crate sourcemap;
#[cfg(test)]
#[macro_use]
extern crate testing;
pub use self::simplify::simplifier; pub use self::simplify::simplifier;

View File

@ -4,7 +4,7 @@ macro_rules! quote_ident {
quote_ident!(::swc_common::DUMMY_SP, $s) quote_ident!(::swc_common::DUMMY_SP, $s)
}; };
($span:expr, $s:expr) => {{ ($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) quote_str!(::swc_common::DUMMY_SP, $s)
}; };
($span:expr, $s:expr) => {{ ($span:expr, $s:expr) => {{
::swc_ecma_ast::Str { ::ast::Str {
span: $span, span: $span,
value: $s.into(), value: $s.into(),
has_escape: false, has_escape: false,
@ -28,26 +28,14 @@ macro_rules! mark {
($span:expr) => {{ ($span:expr) => {{
let mut span = $span; let mut span = $span;
let parent = span.remove_mark(); let parent = span.remove_mark();
$span.apply_mark(::swc_common::pos::Mark::fresh(parent)) $span.apply_mark(::swc_common::hygiene::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))
}}; }};
} }
#[macro_export] #[macro_export]
macro_rules! quote_expr { macro_rules! quote_expr {
($span:expr, null) => {{ ($span:expr, null) => {{
use swc_ecma_ast::*; use ast::*;
Expr::Lit(Lit::Null(Null { span: $span })) Expr::Lit(Lit::Null(Null { span: $span }))
}}; }};
@ -67,8 +55,8 @@ macro_rules! quote_expr {
#[macro_export] #[macro_export]
macro_rules! member_expr { macro_rules! member_expr {
($span:expr, $first:ident) => {{ ($span:expr, $first:ident) => {{
use swc_ecma_ast::*; use ast::Expr;
box Expr::Ident(Ident::new(stringify!($first).into(), $span)) box Expr::Ident(quote_ident!($span, stringify!($first)))
}}; }};
($span:expr, $first:ident . $($rest:tt)+) => {{ ($span:expr, $first:ident . $($rest:tt)+) => {{
@ -89,7 +77,7 @@ macro_rules! member_expr {
}}; }};
(@EXT, $span:expr, $obj:expr, $first:ident) => {{ (@EXT, $span:expr, $obj:expr, $first:ident) => {{
use swc_ecma_ast::*; use ast::*;
let prop = member_expr!($span, $first); let prop = member_expr!($span, $first);
box Expr::Member(MemberExpr{ box Expr::Member(MemberExpr{
@ -103,8 +91,8 @@ macro_rules! member_expr {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use ast::*;
use swc_common::DUMMY_SP as span; use swc_common::DUMMY_SP as span;
use swc_ecma_ast::*;
#[test] #[test]
fn quote_member_expr() { fn quote_member_expr() {
assert_eq_ignore_span!( assert_eq_ignore_span!(

View File

@ -1,5 +1,5 @@
use swc_common::{Fold, FoldWith}; use swc_common::{Fold, FoldWith};
use swc_ecma_ast::*; use ast::*;
pub trait FoldScope<T> { pub trait FoldScope<T> {
/// `scope`: Scope which contains `node`. /// `scope`: Scope which contains `node`.

View File

@ -2,7 +2,7 @@ use crate::util::*;
use std::iter; use std::iter;
use swc_atoms::JsWord; use swc_atoms::JsWord;
use swc_common::{Fold, FoldWith, Span, Spanned}; use swc_common::{Fold, FoldWith, Span, Spanned};
use swc_ecma_ast::{Ident, Lit, *}; use ast::{Ident, Lit, *};
#[cfg(test)] #[cfg(test)]
mod tests; mod tests;

View File

@ -1,8 +1,8 @@
//! Ported from closure compiler. //! Ported from closure compiler.
use self::expr::SimplifyExpr; use self::expr::SimplifyExpr;
use ast::*;
use crate::util::*; use crate::util::*;
use swc_common::{Fold, FoldWith, DUMMY_SP}; use swc_common::{Fold, FoldWith, DUMMY_SP};
use swc_ecma_ast::*;
mod expr; mod expr;
#[cfg(test)] #[cfg(test)]

View File

@ -6,7 +6,7 @@ use std::{
sync::{Arc, RwLock}, sync::{Arc, RwLock},
}; };
use swc_common::{errors::Handler, FileName, Fold, FoldWith, SourceMap}; use swc_common::{errors::Handler, FileName, Fold, FoldWith, SourceMap};
use swc_ecma_ast::*; use ast::*;
use swc_ecma_codegen::Emitter; use swc_ecma_codegen::Emitter;
use swc_ecma_parser::{Parser, Session, SourceFileInput}; use swc_ecma_parser::{Parser, Session, SourceFileInput};

View File

@ -1,6 +1,6 @@
use ast::*;
use std::iter; use std::iter;
use swc_common::{Span, Spanned}; use swc_common::{Span, Spanned};
use swc_ecma_ast::*;
/// Extension methods for [Expr]. /// Extension methods for [Expr].
pub trait ExprFactory: Into<Expr> { pub trait ExprFactory: Into<Expr> {

View File

@ -9,6 +9,7 @@ pub use self::{
}, },
Purity::{MayBeImpure, Pure}, Purity::{MayBeImpure, Pure},
}; };
use ast::*;
use std::{ use std::{
borrow::Cow, borrow::Cow,
f64::{INFINITY, NAN}, f64::{INFINITY, NAN},
@ -16,7 +17,6 @@ use std::{
ops::Add, ops::Add,
}; };
use swc_atoms::JsWord; use swc_atoms::JsWord;
use swc_ecma_ast::*;
mod factory; mod factory;
mod value; mod value;

View File

@ -8,7 +8,6 @@ edition = "2018"
swc_atoms = { path = "../atoms" } swc_atoms = { path = "../atoms" }
swc_common = { path = "../common" } swc_common = { path = "../common" }
swc_ecmascript = { path = "../ecmascript" } swc_ecmascript = { path = "../ecmascript" }
swc_macros = { path = "../macros" }
rayon = "1.0.3" rayon = "1.0.3"
slog = "2" slog = "2"
sourcemap = "2.2" sourcemap = "2.2"

View File

@ -7,7 +7,6 @@ pub extern crate sourcemap;
pub extern crate swc_atoms as atoms; pub extern crate swc_atoms as atoms;
pub extern crate swc_common as common; pub extern crate swc_common as common;
pub extern crate swc_ecmascript as ecmascript; pub extern crate swc_ecmascript as ecmascript;
pub extern crate swc_macros as macros;
use self::{ use self::{
common::{errors::Handler, SourceMap}, common::{errors::Handler, SourceMap},

View File

@ -1,11 +0,0 @@
[package]
name = "swc_macros"
version = "0.1.0"
authors = ["강동윤 <kdy1@outlook.kr>"]
[lib]
[dependencies]
ast_node = { path = "./ast_node" }
enum_kind = { path = "./enum_kind" }
string_enum = { path = "./string_enum" }

View File

@ -19,5 +19,4 @@ features = ["derive", "fold", "parsing", "printing"]
[dev-dependencies] [dev-dependencies]
swc_macros = { path = "../" }
swc_common = { path = "../../common" } swc_common = { path = "../../common" }

View File

@ -68,11 +68,12 @@ pub fn ast_node(
let mut item = Quote::new(Span::call_site()); let mut item = Quote::new(Span::call_site());
item = match input.data { item = match input.data {
Data::Enum(..) => item.quote_with(smart_quote!(Vars { input }, { 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 input
})), })),
_ => item.quote_with(smart_quote!(Vars { 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 input
})), })),
}; };

View File

@ -1,8 +1,6 @@
//! Test that `#[span]` and `#[fold]` can be used at same time. //! Test that `#[span]` and `#[fold]` can be used at same time.
extern crate swc_common; extern crate swc_common;
extern crate swc_macros; use swc_common::{ast_node, Fold, Span, Spanned};
use swc_common::{Fold, Span, Spanned};
use swc_macros::ast_node;
#[ast_node] #[ast_node]
// See https://github.com/rust-lang/rust/issues/44925 // See https://github.com/rust-lang/rust/issues/44925

View File

@ -3,7 +3,6 @@
#![feature(specialization)] #![feature(specialization)]
extern crate swc_common; extern crate swc_common;
extern crate swc_macros;
use std::fmt::Debug; use std::fmt::Debug;
use swc_common::{AstNode, Fold}; use swc_common::{AstNode, Fold};

View File

@ -1,7 +1,6 @@
#![feature(specialization)] #![feature(specialization)]
extern crate swc_common; extern crate swc_common;
extern crate swc_macros;
use swc_common::{Fold, FoldWith}; use swc_common::{Fold, FoldWith};
struct MyFold; struct MyFold;

View File

@ -1,7 +1,6 @@
#![feature(specialization)] #![feature(specialization)]
extern crate swc_common; extern crate swc_common;
extern crate swc_macros;
use swc_common::{Fold, FoldWith}; use swc_common::{Fold, FoldWith};
pub trait AssertFold<T>: Fold<T> {} pub trait AssertFold<T>: Fold<T> {}

View File

@ -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::*;