Skip to content

Commit

Permalink
Merge #30
Browse files Browse the repository at this point in the history
30: Make rls work r=kdy1 a=kdy1

rust-analysis chokes with `Option<Box<Expr>>` style fields.
Rls only shows a warning on the crate with that fields, but ICEs on
dependent crates.
This can be workarounded by using `Option<(Box<Expr>)>`.

Also, using multiple glob imports is bad for rls.
So this commit deglobs them.
bors[bot] committed Feb 3, 2018
2 parents f4bbd69 + fa40c8d commit ca663aa
Showing 13 changed files with 113 additions and 69 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -4,4 +4,8 @@ target/
**/*.bk
core
*.log
Cargo.lock
Cargo.lock

/.vscode
/.idea
*.iml
1 change: 0 additions & 1 deletion common/src/errors/handler.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use super::Diagnostic;
use Span;
use rustc_errors::{CodeMapper, ColorConfig, Diagnostic as RustcDiagnostic,
Handler as RustcHandler, HandlerFlags, Level};
use std::rc::Rc;
12 changes: 3 additions & 9 deletions ecmascript/ast/src/class.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use super::{Expr, Function, PropName};
use swc_common::{FoldWith, Span};
use swc_common::Span;
use swc_macros::ast_node;

#[ast_node]
pub struct Class {
pub span: Span,

pub super_class: Option<Box<Expr>>,
pub body: Vec<ClassMethod>,
pub super_class: Option<(Box<Expr>)>,
}

#[ast_node]
@@ -22,16 +22,10 @@ pub struct ClassMethod {
pub is_static: bool,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Fold)]
pub enum ClassMethodKind {
Constructor,
Method,
Getter,
Setter,
}

impl<F> FoldWith<F> for ClassMethodKind {
fn fold_children(self, _: &mut F) -> Self {
self
}
}
2 changes: 1 addition & 1 deletion ecmascript/ast/src/decl.rs
Original file line number Diff line number Diff line change
@@ -59,5 +59,5 @@ pub struct VarDeclarator {

pub name: Pat,
/// Initialization expresion.
pub init: Option<Box<Expr>>,
pub init: Option<(Box<Expr>)>,
}
13 changes: 7 additions & 6 deletions ecmascript/ast/src/expr.rs
Original file line number Diff line number Diff line change
@@ -79,7 +79,7 @@ pub enum ExprKind {
/// Array literal.
#[ast_node]
pub struct ArrayLit {
pub elems: Vec<Option<ExprOrSpread>>,
pub elems: Vec<(Option<ExprOrSpread>)>,
}

/// Object literal.
@@ -156,11 +156,12 @@ pub struct CallExpr {
#[ast_node]
pub struct NewExpr {
pub callee: Box<Expr>,
pub args: Option<Vec<ExprOrSpread>>,
// #[code = "$( $( $args ),* )?"]
pub args: Option<(Vec<ExprOrSpread>)>,
}
#[ast_node]
pub struct SeqExpr {
pub exprs: Vec<Box<Expr>>,
pub exprs: Vec<(Box<Expr>)>,
}
#[ast_node]
pub struct ArrowExpr {
@@ -173,7 +174,7 @@ pub struct ArrowExpr {

#[ast_node]
pub struct YieldExpr {
pub arg: Option<Box<Expr>>,
pub arg: Option<(Box<Expr>)>,
pub delegate: bool,
}
#[ast_node]
@@ -188,9 +189,9 @@ pub struct AwaitExpr {

#[ast_node]
pub struct TplLit {
pub tag: Option<Box<Expr>>,
pub tag: Option<(Box<Expr>)>,

pub exprs: Vec<Box<Expr>>,
pub exprs: Vec<(Box<Expr>)>,

pub quasis: Vec<TplElement>,
}
33 changes: 20 additions & 13 deletions ecmascript/ast/src/lib.rs
Original file line number Diff line number Diff line change
@@ -10,21 +10,28 @@ extern crate swc_common;
#[macro_use]
extern crate swc_macros;

pub use self::class::*;
pub use self::decl::*;
pub use self::expr::*;
pub use self::function::*;
pub use self::lit::*;
pub use self::module::*;
pub use self::module_decl::*;
pub use self::operators::*;
pub use self::pat::*;
pub use self::prop::*;
pub use self::stmt::*;
pub use self::class::{Class, ClassMethod, ClassMethodKind};
pub use self::decl::{ClassDecl, Decl, FnDecl, VarDecl, VarDeclKind, VarDeclarator};
pub use self::expr::{ArrayLit, ArrowExpr, AssignExpr, AwaitExpr, BinExpr, BlockStmtOrExpr,
CallExpr, ClassExpr, CondExpr, Expr, ExprKind, ExprOrSpread, ExprOrSuper,
FnExpr, MemberExpr, MetaPropExpr, NewExpr, ObjectLit, PatOrExpr, SeqExpr,
TplElement, TplLit, UnaryExpr, UpdateExpr, YieldExpr};
pub use self::function::Function;
pub use self::lit::{Lit, Number, Regex, RegexFlags};
pub use self::module::{Module, ModuleItem};
pub use self::module_decl::{ExportDefaultDecl, ExportSpecifier, ImportSpecifier,
ImportSpecifierKind, ModuleDecl, ModuleDeclKind};
pub use self::operators::{AssignOp, BinaryOp, UnaryOp, UpdateOp};
pub use self::pat::{ObjectPatProp, Pat, PatKind};
pub use self::prop::{Prop, PropKind, PropName};
pub use self::stmt::{BlockStmt, BreakStmt, CatchClause, ContinueStmt, DoWhileStmt, ForInStmt,
ForOfStmt, ForStmt, IfStmt, LabeledStmt, ReturnStmt, Stmt, StmtKind,
SwitchCase, SwitchStmt, ThrowStmt, TryStmt, VarDeclOrExpr, VarDeclOrPat,
WhileStmt, WithStmt};
use std::fmt::{self, Debug, Display, Formatter};
use swc_atoms::JsWord;
use swc_common::{Span, Spanned};
use swc_macros::AstNode;
use swc_macros::{AstNode, Fold};

mod macros;
mod class;
@@ -40,7 +47,7 @@ mod prop;
mod stmt;

/// Ident with span.
#[derive(AstNode, Clone, PartialEq)]
#[derive(AstNode, Fold, Clone, PartialEq)]
pub struct Ident {
pub span: Span,
#[fold(ignore)]
10 changes: 5 additions & 5 deletions ecmascript/ast/src/operators.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use swc_macros::{AstNode, Kind};
use swc_macros::{AstNode, Fold, Kind};

#[derive(Kind, AstNode, Debug, Clone, Copy, Eq, PartialEq, PartialOrd, Ord, Hash)]
#[derive(Kind, AstNode, Fold, Debug, Clone, Copy, Eq, PartialEq, PartialOrd, Ord, Hash)]
#[kind(function(precedence = "u8"))]
pub enum BinaryOp {
/// `==`
@@ -83,7 +83,7 @@ pub enum BinaryOp {
Exp,
}

#[derive(AstNode, Debug, Clone, Copy, Eq, PartialEq, PartialOrd, Ord, Hash)]
#[derive(AstNode, Fold, Debug, Clone, Copy, Eq, PartialEq, PartialOrd, Ord, Hash)]
pub enum AssignOp {
/// `=`
Assign,
@@ -114,15 +114,15 @@ pub enum AssignOp {
ExpAssign,
}

#[derive(AstNode, Debug, Clone, Copy, Eq, PartialEq, PartialOrd, Ord, Hash)]
#[derive(AstNode, Fold, Debug, Clone, Copy, Eq, PartialEq, PartialOrd, Ord, Hash)]
pub enum UpdateOp {
/// `++`
PlusPlus,
/// `--`
MinusMinus,
}

#[derive(AstNode, Debug, Clone, Copy, Eq, PartialEq, PartialOrd, Ord, Hash)]
#[derive(AstNode, Fold, Debug, Clone, Copy, Eq, PartialEq, PartialOrd, Ord, Hash)]
pub enum UnaryOp {
/// `-`
Minus,
4 changes: 2 additions & 2 deletions ecmascript/ast/src/pat.rs
Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@ impl Spanned<PatKind> for Pat {
pub enum PatKind {
Ident(Ident),

Array(Vec<Option<Pat>>),
Array(Vec<(Option<Pat>)>),

Rest(Box<Pat>),

@@ -41,7 +41,7 @@ pub enum ObjectPatProp {
Assign {
key: Ident,

value: Option<Box<Expr>>,
value: Option<(Box<Expr>)>,
},
}

21 changes: 15 additions & 6 deletions ecmascript/ast/src/stmt.rs
Original file line number Diff line number Diff line change
@@ -9,6 +9,15 @@ pub struct Stmt {
pub node: StmtKind,
}

impl From<(Box<Expr>)> for Stmt {
fn from(t: Box<Expr>) -> Self {
Stmt {
span: t.span,
node: StmtKind::Expr(t),
}
}
}

impl From<Decl> for Stmt {
fn from(decl: Decl) -> Self {
Stmt {
@@ -25,7 +34,7 @@ impl Spanned<StmtKind> for Stmt {
}

/// Use when only block statements are allowed.
#[ast_node]
#[derive(AstNode, Fold, Clone, Debug, PartialEq, Default)]
pub struct BlockStmt {
/// Span of brace.
pub span: Span,
@@ -89,7 +98,7 @@ pub struct WithStmt {

#[ast_node]
pub struct ReturnStmt {
pub arg: Option<Box<Expr>>,
pub arg: Option<(Box<Expr>)>,
}

#[ast_node]
@@ -109,7 +118,7 @@ pub struct ContinueStmt {
pub struct IfStmt {
pub test: Box<Expr>,
pub cons: Box<Stmt>,
pub alt: Option<Box<Stmt>>,
pub alt: Option<(Box<Stmt>)>,
}
#[ast_node]
pub struct SwitchStmt {
@@ -139,8 +148,8 @@ pub struct DoWhileStmt {
#[ast_node]
pub struct ForStmt {
pub init: Option<VarDeclOrExpr>,
pub test: Option<Box<Expr>>,
pub update: Option<Box<Expr>>,
pub test: Option<(Box<Expr>)>,
pub update: Option<(Box<Expr>)>,
pub body: Box<Stmt>,
}
#[ast_node]
@@ -160,7 +169,7 @@ pub struct ForOfStmt {
pub struct SwitchCase {
// pub span: Span,
/// None for `default:`
pub test: Option<Box<Expr>>,
pub test: Option<(Box<Expr>)>,

pub cons: Vec<Stmt>,
}
1 change: 1 addition & 0 deletions macros/ast_node/Cargo.toml
Original file line number Diff line number Diff line change
@@ -10,6 +10,7 @@ proc-macro = true
swc_macros_common = { path = "../common" }
pmutil = "0.1"
proc-macro2 = "0.2"
quote = "0.4"

[dependencies.syn]
version = "0.12"
12 changes: 6 additions & 6 deletions macros/ast_node/src/fold.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use common::prelude::*;

pub fn derive_fold(input: &DeriveInput) -> ItemImpl {
let mut derive_generics = Derive::new(input);
pub fn derive(input: DeriveInput) -> ItemImpl {
let mut derive_generics = Derive::new(&input);

let preds = derive_generics
.all_generic_fields()
@@ -17,13 +17,13 @@ pub fn derive_fold(input: &DeriveInput) -> ItemImpl {
Quote::new_call_site()
.quote_with(smart_quote!(
Vars { Type: &ty },
(Type: ::swc_common::FoldWith<__Folder>)
(Type: swc_common::FoldWith<__Folder>)
))
.parse()
});
derive_generics.add_where_predicates(preds);

let arms = Binder::new_from(input)
let arms = Binder::new_from(&input)
.variants()
.into_iter()
.map(|v| {
@@ -61,7 +61,7 @@ pub fn derive_fold(input: &DeriveInput) -> ItemImpl {
FieldType: &binding.field().ty,
binded_field: binding.name(),
},
{ ::swc_common::Folder::<FieldType>::fold(__folder, binded_field,) }
{ swc_common::Folder::<FieldType>::fold(__folder, binded_field,) }
)),
};

@@ -141,7 +141,7 @@ pub fn derive_fold(input: &DeriveInput) -> ItemImpl {
body,
},
{
impl<__Folder> ::swc_common::FoldWith<__Folder> for Type {
impl<__Folder> swc_common::FoldWith<__Folder> for Type {
fn fold_children(self, __folder: &mut __Folder) -> Self {
body
}
Loading

0 comments on commit ca663aa

Please sign in to comment.