mirror of
https://github.com/swc-project/swc.git
synced 2024-11-27 04:47:03 +03:00
Cleanup (#64)
- 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:
parent
fb08c18f7e
commit
b3a9d1a264
11
README.md
11
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.
|
||||
|
||||
|
||||
|
||||
|
@ -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::<Vec<_>>();
|
||||
gen("js_word", "JsWord", &strs);
|
||||
}
|
||||
|
||||
fn gen(mac_name: &str, type_name: &str, atoms: &[&str]) {
|
||||
|
5
atoms/scripts/sort.sh
Executable file
5
atoms/scripts/sort.sh
Executable 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
68
atoms/words.txt
Normal 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
|
@ -4,10 +4,10 @@ version = "0.1.0"
|
||||
authors = ["강동윤 <kdy1@outlook.kr>"]
|
||||
|
||||
[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" }
|
@ -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 {}
|
@ -1,6 +1,5 @@
|
||||
use either::Either;
|
||||
use string_cache::{Atom, StaticAtomSet};
|
||||
pub use swc_macros::Fold;
|
||||
|
||||
/// Folder based on a type system.
|
||||
///
|
||||
|
@ -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<N: Debug + PartialEq + Clone + Spanned> AstNode for N {}
|
||||
|
||||
pub mod errors;
|
||||
mod fold;
|
||||
pub mod macros;
|
||||
pub mod pos;
|
||||
mod pos;
|
||||
|
@ -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,
|
||||
|
@ -5,5 +5,6 @@ authors = ["강동윤 <kdy1@outlook.kr>"]
|
||||
|
||||
[dependencies]
|
||||
swc_atoms = { path = "../../atoms" }
|
||||
swc_macros = { path = "../../macros" }
|
||||
swc_common = { path = "../../common" }
|
||||
enum_kind = { path = "../../macros/enum_kind" }
|
||||
string_enum = { path = "../../macros/string_enum" }
|
||||
|
@ -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 {
|
||||
|
@ -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 {
|
||||
|
@ -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 {
|
||||
|
@ -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]
|
||||
|
@ -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;
|
||||
|
@ -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 {
|
||||
|
@ -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 {
|
||||
|
@ -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 {
|
||||
|
@ -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"))]
|
||||
|
@ -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 {
|
||||
|
@ -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 {
|
||||
|
@ -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]
|
||||
|
@ -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]
|
||||
|
@ -1,5 +1,5 @@
|
||||
[package]
|
||||
name = "ecma_codegen_macros"
|
||||
name = "swc_ecma_codegen_macros"
|
||||
version = "0.1.0"
|
||||
authors = ["강동윤 <kdy1@outlook.kr>"]
|
||||
|
||||
|
@ -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]
|
||||
|
@ -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;
|
||||
|
@ -5,10 +5,10 @@ authors = ["강동윤 <kdy1@outlook.kr>"]
|
||||
|
||||
[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" }
|
||||
|
@ -1,5 +1,5 @@
|
||||
[package]
|
||||
name = "parser_macros"
|
||||
name = "swc_ecma_parser_macros"
|
||||
version = "0.1.0"
|
||||
authors = ["강동윤 <kdy1@outlook.kr>"]
|
||||
|
||||
@ -7,7 +7,7 @@ authors = ["강동윤 <kdy1@outlook.kr>"]
|
||||
proc-macro = true
|
||||
|
||||
[dependencies]
|
||||
swc_macros_common = { path = "../../macros/common" }
|
||||
swc_macros_common = { path = "../../../macros/common" }
|
||||
proc-macro2 = "0.4.4"
|
||||
|
||||
[dependencies.syn]
|
@ -1,4 +1,5 @@
|
||||
use super::{Input, Lexer};
|
||||
use enum_kind::Kind;
|
||||
use slog::Logger;
|
||||
use swc_common::BytePos;
|
||||
use token::*;
|
||||
|
@ -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;
|
||||
|
@ -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};
|
||||
|
@ -1,5 +1,5 @@
|
||||
use ast::*;
|
||||
use swc_common::{Fold, FoldWith};
|
||||
use swc_ecma_ast::*;
|
||||
|
||||
/// Compile ES2015 arrow functions to ES5
|
||||
///
|
||||
|
@ -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<Expr>) -> 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,
|
||||
|
@ -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;
|
||||
|
@ -1,5 +1,5 @@
|
||||
use swc_common::{Fold, FoldWith};
|
||||
use swc_ecma_ast::*;
|
||||
use ast::*;
|
||||
|
||||
/// Compile ES2015 shorthand properties to ES5
|
||||
///
|
||||
|
@ -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<Expr> 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<Expr> 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(),
|
||||
|
@ -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
|
||||
///
|
||||
|
@ -1,5 +1,5 @@
|
||||
use ast::*;
|
||||
use swc_common::{Fold, FoldWith};
|
||||
use swc_ecma_ast::*;
|
||||
|
||||
#[derive(Debug, Clone, Copy, Default)]
|
||||
pub struct TemplateLiteral;
|
||||
|
@ -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`
|
||||
///
|
||||
|
@ -1,6 +1,6 @@
|
||||
pub use self::exponentation::Exponentation;
|
||||
use ast::Module;
|
||||
use swc_common::Fold;
|
||||
use swc_ecma_ast::Module;
|
||||
|
||||
mod exponentation;
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
use ast::*;
|
||||
use swc_common::{Fold, FoldWith};
|
||||
use swc_ecma_ast::*;
|
||||
|
||||
/// babel: `transform-member-expression-literals`
|
||||
///
|
||||
|
@ -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,
|
||||
|
@ -1,5 +1,5 @@
|
||||
use swc_common::{Fold, FoldWith};
|
||||
use swc_ecma_ast::*;
|
||||
use ast::*;
|
||||
|
||||
/// babel: `transform-property-literals`
|
||||
///
|
||||
|
@ -1,5 +1,5 @@
|
||||
use ast::*;
|
||||
use swc_common::{Fold, FoldWith};
|
||||
use swc_ecma_ast::*;
|
||||
|
||||
/// babel: `@babel/plugin-transform-reserved-words`
|
||||
///
|
||||
|
@ -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)
|
||||
|
@ -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<Module> {
|
||||
Fixer
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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!(
|
||||
|
@ -1,5 +1,5 @@
|
||||
use swc_common::{Fold, FoldWith};
|
||||
use swc_ecma_ast::*;
|
||||
use ast::*;
|
||||
|
||||
pub trait FoldScope<T> {
|
||||
/// `scope`: Scope which contains `node`.
|
||||
|
@ -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;
|
||||
|
@ -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)]
|
||||
|
@ -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};
|
||||
|
||||
|
@ -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<Expr> {
|
||||
|
@ -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;
|
||||
|
@ -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"
|
@ -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},
|
||||
|
@ -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" }
|
@ -19,5 +19,4 @@ features = ["derive", "fold", "parsing", "printing"]
|
||||
|
||||
|
||||
[dev-dependencies]
|
||||
swc_macros = { path = "../" }
|
||||
swc_common = { path = "../../common" }
|
@ -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
|
||||
})),
|
||||
};
|
||||
|
@ -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
|
||||
|
@ -3,7 +3,6 @@
|
||||
#![feature(specialization)]
|
||||
|
||||
extern crate swc_common;
|
||||
extern crate swc_macros;
|
||||
use std::fmt::Debug;
|
||||
use swc_common::{AstNode, Fold};
|
||||
|
||||
|
@ -1,7 +1,6 @@
|
||||
#![feature(specialization)]
|
||||
|
||||
extern crate swc_common;
|
||||
extern crate swc_macros;
|
||||
use swc_common::{Fold, FoldWith};
|
||||
struct MyFold;
|
||||
|
||||
|
@ -1,7 +1,6 @@
|
||||
#![feature(specialization)]
|
||||
|
||||
extern crate swc_common;
|
||||
extern crate swc_macros;
|
||||
use swc_common::{Fold, FoldWith};
|
||||
|
||||
pub trait AssertFold<T>: Fold<T> {}
|
||||
|
@ -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::*;
|
Loading…
Reference in New Issue
Block a user