mirror of
https://github.com/swc-project/swc.git
synced 2024-11-23 09:38:16 +03:00
Merge #23
23: Update rustfmt to 0.3.5 and format literals. r=kdy1 a=kdy1
This commit is contained in:
commit
135e606f38
@ -1,6 +1,7 @@
|
||||
required_version = "0.3.5"
|
||||
reorder_imports = true
|
||||
reorder_imports_in_group = true
|
||||
reorder_imported_names = true
|
||||
wrap_comments = true
|
||||
write_mode = "replace"
|
||||
same_line_attributes = false
|
||||
format_strings = true
|
@ -26,35 +26,61 @@ pub mod util;
|
||||
|
||||
#[derive(Fail, Debug, PartialEq, Eq, Hash)]
|
||||
pub enum Error<InputError> {
|
||||
#[fail(display = "input error: {}", err)]
|
||||
Input { err: InputError },
|
||||
#[fail(display = "input error: {}", err)] Input {
|
||||
err: InputError,
|
||||
},
|
||||
#[fail(display = "unterminated string constant: {}", start)]
|
||||
UnterminatedStrLit { start: BytePos },
|
||||
UnterminatedStrLit {
|
||||
start: BytePos,
|
||||
},
|
||||
#[fail(display = "expected unicode escape sequence: {}", pos)]
|
||||
ExpectedUnicodeEscape { pos: BytePos },
|
||||
ExpectedUnicodeEscape {
|
||||
pos: BytePos,
|
||||
},
|
||||
#[fail(display = "unexpected escape sequence in reserved word: {:?}", word)]
|
||||
EscapeInReservedWord { word: Word },
|
||||
EscapeInReservedWord {
|
||||
word: Word,
|
||||
},
|
||||
#[fail(display = "unterminated regexp (regexp started at {})", start)]
|
||||
UnterminatedRegxp { start: BytePos },
|
||||
UnterminatedRegxp {
|
||||
start: BytePos,
|
||||
},
|
||||
#[fail(display = "identifier directly after number at {}", pos)]
|
||||
IdentAfterNum { pos: BytePos },
|
||||
IdentAfterNum {
|
||||
pos: BytePos,
|
||||
},
|
||||
#[fail(display = "Decimals with leading zeros (at {}) are not allowed in strict mode", start)]
|
||||
DecimalStartsWithZero { start: BytePos },
|
||||
DecimalStartsWithZero {
|
||||
start: BytePos,
|
||||
},
|
||||
#[fail(display = "Octals with leading zeros (at {}) are not allowed in strict mode", start)]
|
||||
ImplicitOctalOnStrict { start: BytePos },
|
||||
ImplicitOctalOnStrict {
|
||||
start: BytePos,
|
||||
},
|
||||
#[fail(display = "Unexpected character '{}' at {}", c, pos)]
|
||||
UnexpectedChar { pos: BytePos, c: char },
|
||||
UnexpectedChar {
|
||||
pos: BytePos,
|
||||
c: char,
|
||||
},
|
||||
#[fail(display = "Invalid string escape at {}", start)]
|
||||
InvalidStrEscape { start: BytePos },
|
||||
InvalidStrEscape {
|
||||
start: BytePos,
|
||||
},
|
||||
|
||||
#[fail(display = "Invalid unciode escape at {:?}", pos)]
|
||||
InvalidUnicodeEscape { pos: Span },
|
||||
InvalidUnicodeEscape {
|
||||
pos: Span,
|
||||
},
|
||||
|
||||
#[fail(display = "Invalid unciode code point at {:?}", pos)]
|
||||
InvalidCodePoint { pos: Span },
|
||||
InvalidCodePoint {
|
||||
pos: Span,
|
||||
},
|
||||
|
||||
#[fail(display = "Invalid identifier character at {:?}", pos)]
|
||||
InvalidIdentChar { pos: Span },
|
||||
InvalidIdentChar {
|
||||
pos: Span,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
|
||||
|
@ -313,18 +313,13 @@ impl Context {
|
||||
#[kind(fucntion(is_expr = "bool", preserve_space = "bool"))]
|
||||
enum Type {
|
||||
BraceStmt,
|
||||
#[kind(is_expr)]
|
||||
BraceExpr,
|
||||
#[kind(is_expr)]
|
||||
TplQuasi,
|
||||
#[kind(is_expr)] BraceExpr,
|
||||
#[kind(is_expr)] TplQuasi,
|
||||
ParenStmt {
|
||||
/// Is this `for` loop?
|
||||
is_for_loop: bool,
|
||||
},
|
||||
#[kind(is_expr)]
|
||||
ParenExpr,
|
||||
#[kind(is_expr, preserve_space)]
|
||||
Tpl,
|
||||
#[kind(is_expr)]
|
||||
FnExpr,
|
||||
#[kind(is_expr)] ParenExpr,
|
||||
#[kind(is_expr, preserve_space)] Tpl,
|
||||
#[kind(is_expr)] FnExpr,
|
||||
}
|
||||
|
@ -20,13 +20,13 @@ extern crate slog;
|
||||
#[macro_use(js_word)]
|
||||
extern crate swc_atoms;
|
||||
extern crate swc_common;
|
||||
pub extern crate swc_ecma_ast as ast;
|
||||
#[macro_use]
|
||||
extern crate swc_macros;
|
||||
#[cfg(test)]
|
||||
#[macro_use]
|
||||
extern crate testing;
|
||||
extern crate unicode_xid;
|
||||
pub extern crate swc_ecma_ast as ast;
|
||||
|
||||
#[macro_use]
|
||||
mod macros;
|
||||
|
@ -68,8 +68,7 @@ impl<I: Input> ParserInput<I> {
|
||||
/// Returns current token.
|
||||
pub fn bump(&mut self) -> Token {
|
||||
self.bump_inner().expect(
|
||||
"Current token is `None`. Parser should not call bump()\
|
||||
without knowing current token",
|
||||
"Current token is `None`. Parser should not call bump()without knowing current token",
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -189,25 +189,25 @@ impl<I: Input> Parser<I> {
|
||||
span,
|
||||
node: PatKind::Object(props
|
||||
.into_iter()
|
||||
.map(|prop| {
|
||||
match prop.node {
|
||||
PropKind::Shorthand(id) => Ok(ObjectPatProp::Assign {
|
||||
key: id.into(),
|
||||
value: None,
|
||||
}),
|
||||
PropKind::KeyValue { key, value } => Ok(ObjectPatProp::KeyValue {
|
||||
key,
|
||||
value: box self.reparse_expr_as_pat(value)?,
|
||||
}),
|
||||
PropKind::Assign { key, value } => Ok(ObjectPatProp::Assign {
|
||||
key,
|
||||
value: Some(value),
|
||||
}),
|
||||
.map(|prop| match prop.node {
|
||||
PropKind::Shorthand(id) => Ok(ObjectPatProp::Assign {
|
||||
key: id.into(),
|
||||
value: None,
|
||||
}),
|
||||
PropKind::KeyValue { key, value } => Ok(ObjectPatProp::KeyValue {
|
||||
key,
|
||||
value: box self.reparse_expr_as_pat(value)?,
|
||||
}),
|
||||
PropKind::Assign { key, value } => Ok(ObjectPatProp::Assign {
|
||||
key,
|
||||
value: Some(value),
|
||||
}),
|
||||
|
||||
_ => {
|
||||
unimplemented!("error reporting: object pattern cannot contain method property: {:?}", prop)
|
||||
}
|
||||
}
|
||||
_ => unimplemented!(
|
||||
"error reporting: object pattern cannot contain method property: \
|
||||
{:?}",
|
||||
prop
|
||||
),
|
||||
})
|
||||
.collect::<PResult<_>>()?),
|
||||
});
|
||||
|
@ -257,7 +257,10 @@ impl<I: Input> StmtLikeParser<ModuleItem> for Parser<I> {
|
||||
} else if is!("export") {
|
||||
self.parse_export()?
|
||||
} else {
|
||||
unreachable!("handle_import_export should not be called if current token isn't import nor export")
|
||||
unreachable!(
|
||||
"handle_import_export should not be called if current token isn't import nor \
|
||||
export"
|
||||
)
|
||||
};
|
||||
|
||||
Ok(ModuleItem::ModuleDecl(decl))
|
||||
|
@ -187,18 +187,13 @@ pub struct TokenAndSpan {
|
||||
#[derive(Kind, Clone, PartialEq, Eq, Hash)]
|
||||
#[kind(functions(starts_expr = "bool", before_expr = "bool"))]
|
||||
pub enum Word {
|
||||
#[kind(delegate)]
|
||||
Keyword(Keyword),
|
||||
#[kind(delegate)] Keyword(Keyword),
|
||||
|
||||
#[kind(starts_expr)]
|
||||
Null,
|
||||
#[kind(starts_expr)]
|
||||
True,
|
||||
#[kind(starts_expr)]
|
||||
False,
|
||||
#[kind(starts_expr)] Null,
|
||||
#[kind(starts_expr)] True,
|
||||
#[kind(starts_expr)] False,
|
||||
|
||||
#[kind(starts_expr)]
|
||||
Ident(JsWord),
|
||||
#[kind(starts_expr)] Ident(JsWord),
|
||||
}
|
||||
|
||||
impl From<JsWord> for Word {
|
||||
@ -363,33 +358,26 @@ pub enum Keyword {
|
||||
Await,
|
||||
|
||||
Break,
|
||||
#[kind(before_expr)]
|
||||
Case,
|
||||
#[kind(before_expr)] Case,
|
||||
Catch,
|
||||
Continue,
|
||||
Debugger,
|
||||
#[kind(before_expr)]
|
||||
Default_,
|
||||
#[kind(before_expr)]
|
||||
Do,
|
||||
#[kind(before_expr)]
|
||||
Else,
|
||||
#[kind(before_expr)] Default_,
|
||||
#[kind(before_expr)] Do,
|
||||
#[kind(before_expr)] Else,
|
||||
|
||||
Finally,
|
||||
For,
|
||||
|
||||
#[kind(starts_expr)]
|
||||
Function,
|
||||
#[kind(starts_expr)] Function,
|
||||
|
||||
If,
|
||||
|
||||
#[kind(before_expr)]
|
||||
Return,
|
||||
#[kind(before_expr)] Return,
|
||||
|
||||
Switch,
|
||||
|
||||
#[kind(before_expr, starts_expr)]
|
||||
Throw,
|
||||
#[kind(before_expr, starts_expr)] Throw,
|
||||
|
||||
Try,
|
||||
Var,
|
||||
@ -398,40 +386,29 @@ pub enum Keyword {
|
||||
While,
|
||||
With,
|
||||
|
||||
#[kind(before_expr, starts_expr)]
|
||||
New,
|
||||
#[kind(starts_expr)]
|
||||
This,
|
||||
#[kind(starts_expr)]
|
||||
Super,
|
||||
#[kind(before_expr, starts_expr)] New,
|
||||
#[kind(starts_expr)] This,
|
||||
#[kind(starts_expr)] Super,
|
||||
|
||||
#[kind(starts_expr)]
|
||||
Class,
|
||||
#[kind(starts_expr)] Class,
|
||||
|
||||
#[kind(before_expr)]
|
||||
Extends,
|
||||
#[kind(before_expr)] Extends,
|
||||
|
||||
Export,
|
||||
#[kind(starts_expr)]
|
||||
Import,
|
||||
#[kind(starts_expr)] Import,
|
||||
|
||||
/// Spec says this might be identifier.
|
||||
#[kind(before_expr, starts_expr)]
|
||||
Yield,
|
||||
|
||||
#[kind(before_expr)]
|
||||
In,
|
||||
#[kind(before_expr)]
|
||||
InstanceOf,
|
||||
#[kind(before_expr)] In,
|
||||
#[kind(before_expr)] InstanceOf,
|
||||
|
||||
#[kind(before_expr, starts_expr)]
|
||||
TypeOf,
|
||||
#[kind(before_expr, starts_expr)] TypeOf,
|
||||
|
||||
#[kind(before_expr, starts_expr)]
|
||||
Void,
|
||||
#[kind(before_expr, starts_expr)] Void,
|
||||
|
||||
#[kind(before_expr, starts_expr)]
|
||||
Delete,
|
||||
#[kind(before_expr, starts_expr)] Delete,
|
||||
}
|
||||
|
||||
impl From<BinOpToken> for BinaryOp {
|
||||
|
@ -8,8 +8,8 @@
|
||||
|
||||
#![feature(proc_macro)]
|
||||
|
||||
extern crate proc_macro2;
|
||||
extern crate proc_macro;
|
||||
extern crate proc_macro2;
|
||||
#[macro_use]
|
||||
extern crate quote;
|
||||
extern crate swc_macros_common;
|
||||
|
@ -2,8 +2,8 @@
|
||||
|
||||
#[macro_use]
|
||||
extern crate pmutil;
|
||||
extern crate proc_macro2;
|
||||
extern crate proc_macro;
|
||||
extern crate proc_macro2;
|
||||
extern crate swc_macros_common as common;
|
||||
extern crate syn;
|
||||
|
||||
|
@ -26,10 +26,7 @@ pub struct Expr<A: Ast> {
|
||||
|
||||
#[ast_node]
|
||||
pub enum ExprKind<A: Ast> {
|
||||
Custom(
|
||||
#[fold(bound)]
|
||||
A::CustomExpr,
|
||||
),
|
||||
Custom(#[fold(bound)] A::CustomExpr),
|
||||
/// Recursive
|
||||
Stmt(Box<Stmt<A>>),
|
||||
}
|
||||
|
@ -5,23 +5,26 @@
|
||||
//!
|
||||
//! ```rust
|
||||
//! struct S {
|
||||
//! a: u8,
|
||||
//! b: u16,
|
||||
//! a: u8,
|
||||
//! b: u16,
|
||||
//! }
|
||||
//! let s = S { a: 0, b: 0, };
|
||||
//! let s = S { a: 0, b: 0 };
|
||||
//! match s {
|
||||
//! S { a: _binded_a, b: _binded_b } => {}
|
||||
//! S {
|
||||
//! a: _binded_a,
|
||||
//! b: _binded_b,
|
||||
//! } => {}
|
||||
//! }
|
||||
//! enum E {
|
||||
//! V1 { a: u8 },
|
||||
//! V2(u16),
|
||||
//! V3,
|
||||
//! V1 { a: u8 },
|
||||
//! V2(u16),
|
||||
//! V3,
|
||||
//! }
|
||||
//! let e = E::V1{ a: 0 };
|
||||
//! let e = E::V1 { a: 0 };
|
||||
//! match e {
|
||||
//! E::V1 { a: _binded_a } => {}
|
||||
//! E::V2(_binded_0) => {}
|
||||
//! E::V3 => {}
|
||||
//! E::V1 { a: _binded_a } => {}
|
||||
//! E::V2(_binded_0) => {}
|
||||
//! E::V3 => {}
|
||||
//! }
|
||||
//! ```
|
||||
//!
|
||||
|
@ -4,8 +4,8 @@
|
||||
|
||||
#[macro_use]
|
||||
extern crate pmutil;
|
||||
extern crate proc_macro2;
|
||||
extern crate proc_macro;
|
||||
extern crate proc_macro2;
|
||||
#[macro_use]
|
||||
extern crate quote;
|
||||
extern crate syn;
|
||||
|
@ -12,17 +12,17 @@ pub trait ItemImplExt {
|
||||
///
|
||||
/// let item: Item = Quote::new_call_site()
|
||||
/// .quote_with(smart_quote!(
|
||||
/// Vars {
|
||||
/// Type: type_name,
|
||||
/// impl_generics,
|
||||
/// ty_generics,
|
||||
/// where_clause,
|
||||
/// },
|
||||
/// {
|
||||
/// impl impl_generics ::swc_common::AstNode for Type ty_generics
|
||||
/// where_clause {}
|
||||
/// }
|
||||
/// ))
|
||||
/// Vars {
|
||||
/// Type: type_name,
|
||||
/// impl_generics,
|
||||
/// ty_generics,
|
||||
/// where_clause,
|
||||
/// },
|
||||
/// {
|
||||
/// impl impl_generics ::swc_common::AstNode for Type ty_generics
|
||||
/// where_clause {}
|
||||
/// }
|
||||
/// ))
|
||||
/// .parse();
|
||||
/// ```
|
||||
///
|
||||
@ -36,7 +36,6 @@ pub trait ItemImplExt {
|
||||
/// .parse::<ItemImpl>()
|
||||
/// .with_generics(input.generics);
|
||||
/// ```
|
||||
///
|
||||
fn with_generics(self, generics: Generics) -> Self;
|
||||
}
|
||||
|
||||
|
@ -139,8 +139,8 @@
|
||||
|
||||
#[macro_use]
|
||||
extern crate pmutil;
|
||||
extern crate proc_macro2;
|
||||
extern crate proc_macro;
|
||||
extern crate proc_macro2;
|
||||
extern crate swc_macros_common as common;
|
||||
#[macro_use]
|
||||
extern crate syn;
|
||||
|
@ -7,10 +7,8 @@ pub enum Tokens {
|
||||
#[kind(is_a)]
|
||||
#[kind(prec = "7")]
|
||||
A,
|
||||
#[kind(prec = "6")]
|
||||
StructLike {},
|
||||
#[kind(prec = "5")]
|
||||
TupleLike(u8),
|
||||
#[kind(prec = "6")] StructLike {},
|
||||
#[kind(prec = "5")] TupleLike(u8),
|
||||
|
||||
#[kind(prec = "6")]
|
||||
#[cfg(feature = "not-used")]
|
||||
@ -27,16 +25,13 @@ fn simple_bool() {
|
||||
#[derive(Debug, Kind)]
|
||||
#[kind(functions(wanted = "bool"))]
|
||||
pub enum Delegate {
|
||||
#[kind(wanted)]
|
||||
Wanted,
|
||||
#[kind(delegate)]
|
||||
May(Del),
|
||||
#[kind(wanted)] Wanted,
|
||||
#[kind(delegate)] May(Del),
|
||||
}
|
||||
|
||||
#[derive(Debug, Kind)]
|
||||
#[kind(functions(wanted = "bool"))]
|
||||
pub enum Del {
|
||||
#[kind(wanted)]
|
||||
Yes,
|
||||
#[kind(wanted)] Yes,
|
||||
No,
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user