From bcc27738f206b3bc7d28fb81717336f04a6ad426 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Donny/=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Fri, 24 Mar 2023 10:40:12 +0900 Subject: [PATCH 01/22] Remove --- crates/enum_kind/Cargo.toml | 22 --- crates/enum_kind/src/expand.rs | 213 ----------------------------- crates/enum_kind/src/input.rs | 56 -------- crates/enum_kind/src/lib.rs | 149 -------------------- crates/enum_kind/src/parse.rs | 231 -------------------------------- crates/enum_kind/src/util.rs | 19 --- crates/enum_kind/tests/usage.rs | 41 ------ 7 files changed, 731 deletions(-) delete mode 100644 crates/enum_kind/Cargo.toml delete mode 100644 crates/enum_kind/src/expand.rs delete mode 100644 crates/enum_kind/src/input.rs delete mode 100644 crates/enum_kind/src/lib.rs delete mode 100644 crates/enum_kind/src/parse.rs delete mode 100644 crates/enum_kind/src/util.rs delete mode 100644 crates/enum_kind/tests/usage.rs diff --git a/crates/enum_kind/Cargo.toml b/crates/enum_kind/Cargo.toml deleted file mode 100644 index 297549042bd3..000000000000 --- a/crates/enum_kind/Cargo.toml +++ /dev/null @@ -1,22 +0,0 @@ -[package] -authors = ["강동윤 "] -description = "Easily manage values related to enum." -documentation = "https://rustdoc.swc.rs/enum_kind/" -edition = "2021" -license = "Apache-2.0" -name = "enum_kind" -repository = "https://github.com/swc-project/swc.git" -version = "0.2.2" - -[lib] -bench = false -proc-macro = true - -[dependencies] -pmutil = "0.5.1" -proc-macro2 = "1" -swc_macros_common = {version = "0.3.7", path = "../swc_macros_common"} - -[dependencies.syn] -features = ["full", "parsing", "printing", "extra-traits"] -version = "1" diff --git a/crates/enum_kind/src/expand.rs b/crates/enum_kind/src/expand.rs deleted file mode 100644 index 4c37f7a8c93a..000000000000 --- a/crates/enum_kind/src/expand.rs +++ /dev/null @@ -1,213 +0,0 @@ -use pmutil::{smart_quote, Quote, SpanExt}; -use swc_macros_common::prelude::*; -use syn::*; - -use crate::{input::*, util::is_bool}; - -pub fn expand( - Input { - attrs, - name, - variants, - generics, - vis, - }: Input, -) -> Item { - // verify variant attributes. - { - for v in &variants { - if v.attrs.has_delegate { - match v.data { - Fields::Named(FieldsNamed { - named: ref fields, .. - }) - | Fields::Unnamed(FieldsUnnamed { - unnamed: ref fields, - .. - }) if fields.len() == 1 => {} - _ => panic!( - "currently #[kind(delegate)] can be applied to variant with only one field" - ), - } - } - for value in &v.attrs.fn_values { - let used = attrs - .fns - .iter() - .map(|f| &f.name) - .any(|fn_name| value.fn_name == *fn_name || value.fn_name == "delegate"); - if !used { - panic!("Unknown function `{}` on variant {}", value.fn_name, v.name) - } - } - } - } - - let items = attrs - .fns - .into_iter() - .map(|f| f.expand(&name, vis.clone(), &variants)) - .map(ImplItem::Method) - .fold(TokenStream::new(), |mut t, i| { - i.to_tokens(&mut t); - t - }); - - Quote::new_call_site() - .quote_with(smart_quote!( - Vars { - Type: name, - items, - }, - { - impl Type { - items - } - } - )) - .parse::() - .with_generics(generics) - .into() -} - -impl FnDef { - fn expand(self, enum_name: &Ident, vis: Visibility, variants: &[EnumVar]) -> ImplItemMethod { - let FnDef { - name, - return_type, - default_value, - } = self; - - let name_span = name.span(); - - let arms = - variants - .iter() - .map(|v| -> Arm { - // Bind this variant. - let (pat, mut fields) = - VariantBinder::new(Some(enum_name), &v.name, &v.data, &v.attrs.extras) - .bind("_", Some(call_site()), None); - - let body = { - let value = match v - .attrs - .fn_values - .iter() - .find(|fn_val| fn_val.fn_name == name) - .map(|attr| attr.value.clone()) - { - Some(Some(value)) => Some(value), - - // not specified, but has `#[kind(delegate)]` - None if v.attrs.has_delegate => { - assert_eq!(fields.len(), 1); - let field = fields.remove(0); - Some( - Quote::new_call_site() - .quote_with(smart_quote!( - Vars { - field, - method: &name, - }, - { field.method() } - )) - .parse(), - ) - } - - // if return type is bool and attribute is specified, value is true. - Some(None) if is_bool(&return_type) => Some(Expr::Lit(ExprLit { - attrs: Default::default(), - lit: Lit::Bool(LitBool { - value: true, - span: Span::call_site(), - }), - })), - _ => None, - }; - - value - .or_else(|| default_value.clone()) - .map(Box::new) - .unwrap_or_else(|| { - panic!( - "value of {fn_name} for {variant} is not specified.", - fn_name = name, - variant = v.name - ); - }) - }; - - Arm { - pat, - body, - - // Forward cfg attributes. - attrs: v - .attrs - .extras - .iter() - .filter(|attr| is_attr_name(attr, "cfg")) - .cloned() - .collect(), - fat_arrow_token: call_site(), - comma: Some(call_site()), - guard: None, - } - }) - .collect(); - - // match self {} - let match_expr = Expr::Match(ExprMatch { - attrs: Default::default(), - match_token: call_site(), - brace_token: call_site(), - - expr: Quote::new_call_site() - .quote_with(smart_quote!(Vars {}, { self })) - .parse::() - .into(), - - arms, - }); - - ImplItemMethod { - // fn (&self) -> ReturnTpe - sig: Signature { - asyncness: None, - constness: None, - unsafety: None, - abi: None, - fn_token: name.span().as_token(), - paren_token: name.span().as_token(), - inputs: vec![ - // TODO - Element::End(FnArg::Receiver(Receiver { - reference: Some((name_span.as_token(), None)), - self_token: name_span.as_token(), - mutability: None, - attrs: Default::default(), - })), - ] - .into_iter() - .collect(), - ident: name, - generics: Default::default(), - variadic: None, - output: ReturnType::Type(name_span.as_token(), Box::new(return_type)), - }, - - block: Block { - brace_token: call_site(), - stmts: vec![Stmt::Expr(match_expr)], - }, - - // TODO - vis, - - attrs: Default::default(), - defaultness: None, - } - } -} diff --git a/crates/enum_kind/src/input.rs b/crates/enum_kind/src/input.rs deleted file mode 100644 index b7db6c16d263..000000000000 --- a/crates/enum_kind/src/input.rs +++ /dev/null @@ -1,56 +0,0 @@ -use syn::*; - -/// Parsed input. -#[derive(Debug)] -pub struct Input { - pub attrs: EnumAttrs, - /// Name of enum. - pub name: Ident, - pub vis: Visibility, - pub generics: Generics, - - pub variants: Vec, -} - -/// -#[derive(Debug, Default)] -pub struct EnumAttrs { - pub fns: Vec, - pub extras: Vec, -} - -/// Function to generate. -/// -/// `#[kind(function(name = "bool"))]` -#[derive(Debug)] -pub struct FnDef { - /// Name of function. - pub name: Ident, - pub return_type: Type, - - pub default_value: Option, -} - -/// Variant of enum. -#[derive(Debug)] -pub struct EnumVar { - /// Name of variant. - pub name: Ident, - pub attrs: VariantAttrs, - pub data: Fields, -} - -/// Parsed attributes. -#[derive(Debug, Default)] -pub struct VariantAttrs { - pub fn_values: Vec, - pub extras: Vec, - /// Does this variant has `#[kind(delegate)]`? - pub has_delegate: bool, -} - -#[derive(Debug)] -pub struct VariantAttr { - pub fn_name: Ident, - pub value: Option, -} diff --git a/crates/enum_kind/src/lib.rs b/crates/enum_kind/src/lib.rs deleted file mode 100644 index ee8edc39c250..000000000000 --- a/crates/enum_kind/src/lib.rs +++ /dev/null @@ -1,149 +0,0 @@ -extern crate proc_macro; - -use swc_macros_common::prelude::*; - -mod expand; -mod input; -mod parse; -mod util; - -/// # Attributes on enum -/// ## functions -/// `#[kind(functions(name = "return_type"))]` -/// -/// ```rust,ignore -/// #[macro_use] -/// extern crate enum_kind; -/// -/// /// You can split attributes if you want. -/// #[derive(Kind)] -/// #[kind(functions(is_a = "bool", is_b = "bool"))] -/// #[kind(functions(is_a_or_b = "bool", num = "u8"))] -/// pub enum E { -/// #[kind(is_a, is_a_or_b, num = "1")] -/// A, -/// /// You can split attributes if you want. -/// #[kind(is_b)] -/// #[kind(is_a_or_b)] -/// #[kind(num = "2")] -/// B(u8), -/// /// Default value of bool is false if not specified and true if specified. -/// /// -/// /// Both struct like variant and tuple like variant are supported. -/// #[kind(num = "3")] -/// C {}, -/// } -/// -/// # fn main() { -/// assert!(E::A.is_a() && E::A.is_a_or_b() && !E::A.is_b()); -/// assert_eq!(E::A.num(), 1); -/// -/// assert!(!E::B(0).is_a() && E::B(0).is_a_or_b() && E::B(0).is_b()); -/// assert_eq!(E::B(0).num(), 2); -/// -/// assert!(!E::C {}.is_a() && !E::C {}.is_a_or_b() && !E::C {}.is_b()); -/// assert_eq!(E::C {}.num(), 3); -/// -/// # } -/// ``` -/// -/// ----- -/// -/// # Real usecase -/// -/// ```rust,ignore -/// #[macro_use] -/// extern crate enum_kind; -/// -/// #[derive(Kind, Debug, Clone, Eq, PartialEq, Hash)] -/// #[kind(function(precedence = "u8"))] -/// pub enum BinOpToken { -/// /// `==` -/// #[kind(precedence = "6")] -/// EqEq, -/// /// `!=` -/// #[kind(precedence = "6")] -/// NotEq, -/// /// `===` -/// #[kind(precedence = "6")] -/// EqEqEq, -/// /// `!==` -/// #[kind(precedence = "6")] -/// NotEqEq, -/// /// `<` -/// #[kind(precedence = "7")] -/// Lt, -/// /// `<=` -/// #[kind(precedence = "7")] -/// LtEq, -/// /// `>` -/// #[kind(precedence = "7")] -/// Gt, -/// #[kind(precedence = "7")] -/// /// `>=` -/// #[kind(precedence = "7")] -/// GtEq, -/// /// `<<` -/// #[kind(precedence = "8")] -/// LShift, -/// /// `>>` -/// #[kind(precedence = "8")] -/// RShift, -/// /// `>>>` -/// #[kind(precedence = "8")] -/// ZeroFillRShift, -/// /// `+` -/// #[kind(precedence = "9")] -/// Plus, -/// /// `-` -/// #[kind(precedence = "9")] -/// Minus, -/// /// `*` -/// #[kind(precedence = "10")] -/// Mul, -/// /// `/` -/// #[kind(precedence = "10")] -/// Div, -/// /// `%` -/// #[kind(precedence = "10")] -/// Mod, -/// /// `|` -/// #[kind(precedence = "3")] -/// BitOr, -/// /// `^` -/// #[kind(precedence = "4")] -/// BitXor, -/// /// `&` -/// #[kind(precedence = "5")] -/// BitAnd, -/// /// `in` -/// #[kind(precedence = "7")] -/// In, -/// /// `instanceof` -/// #[kind(precedence = "7")] -/// InstanceOf, -/// /// `**` -/// #[kind(precedence = "10")] -/// Exp, -/// /// `||` -/// #[kind(precedence = "1")] -/// LogicalOr, -/// /// `&&` -/// #[kind(precedence = "2")] -/// LogicalAnd, -/// } -/// -/// # fn main() {} -/// ``` -#[proc_macro_derive(Kind, attributes(kind))] -pub fn derive_kind(input: proc_macro::TokenStream) -> proc_macro::TokenStream { - let input = syn::parse::(input) - .map(From::from) - .expect("failed to parse derive input"); - let item = expand::expand(input); - let tokens = item.into_token_stream(); - - // println!("Expanded:{}", tokens); - - tokens.into() -} diff --git a/crates/enum_kind/src/parse.rs b/crates/enum_kind/src/parse.rs deleted file mode 100644 index 51ecece57a00..000000000000 --- a/crates/enum_kind/src/parse.rs +++ /dev/null @@ -1,231 +0,0 @@ -use std::{fmt::Display, ops::AddAssign, result::Result as StdResult}; - -use swc_macros_common::prelude::*; -use syn::{ - parse::{Parse, ParseStream}, - *, -}; - -use crate::{input::*, util::is_bool}; - -impl From for Input { - fn from( - DeriveInput { - ident: name, - vis, - attrs, - generics, - data, - }: DeriveInput, - ) -> Self { - let variants = match data { - Data::Enum(data) => data.variants.into_iter().map(From::from).collect(), - _ => panic!("#[derive(Kind)] only works for enums"), - }; - - Input { - name, - vis, - generics, - attrs: parse_attrs(attrs), - variants, - } - } -} - -impl Parse for EnumAttrs { - fn parse(input: ParseStream<'_>) -> Result { - let _function: Ident = input.parse()?; - - let fns; - let _paren_token = parenthesized!(fns in input); - - let fns: Punctuated = fns.parse_terminated(FnDef::parse)?; - Ok(EnumAttrs { - fns: fns.into_iter().collect(), - extras: Default::default(), - }) - } -} - -impl AddAssign> for EnumAttrs { - fn add_assign(&mut self, rhs: StdResult) { - match rhs { - Ok(attr) => { - self.fns.extend(attr.fns); - self.extras.extend(attr.extras); - } - Err(attr) => self.extras.push(attr), - } - } -} - -impl FnDef { - fn def_value_for_type(ty: &Type) -> Option { - if is_bool(ty) { - return Some(Expr::Lit(ExprLit { - attrs: Default::default(), - lit: Lit::Bool(LitBool { - value: false, - span: def_site::(), - }), - })); - } - - None - } -} - -impl Parse for FnDef { - fn parse(input: ParseStream<'_>) -> Result { - let name: Ident = input.parse()?; - let _: Token!(=) = input.parse()?; - let return_type: LitStr = input.parse()?; - - if name == "delegate" { - panic!("function name cannot be `delegate`") - } - - let return_type = parse_str_as_tokens(return_type); - Ok(FnDef { - default_value: FnDef::def_value_for_type(&return_type), - name, - return_type, - }) - } -} - -impl From for EnumVar { - fn from( - Variant { - attrs, - fields, - ident: name, - .. - }: Variant, - ) -> Self { - EnumVar { - name, - data: fields, - attrs: parse_attrs(attrs), - } - } -} - -impl Parse for VariantAttrs { - fn parse(input: ParseStream<'_>) -> Result { - let fn_values: Punctuated<_, token::Comma> = Punctuated::parse_terminated(input)?; - let has_delegate = fn_values - .iter() - .any(|f: &VariantAttr| f.fn_name == "delegate"); - Ok(VariantAttrs { - fn_values: fn_values.into_iter().collect(), - extras: Default::default(), - has_delegate, - }) - } -} - -impl AddAssign> for VariantAttrs { - fn add_assign(&mut self, rhs: StdResult) { - #[allow(clippy::suspicious_op_assign_impl)] - match rhs { - Ok(attr) => { - self.fn_values.extend(attr.fn_values); - self.extras.extend(attr.extras); - self.has_delegate = self.has_delegate || attr.has_delegate; - } - Err(attr) => self.extras.push(attr), - } - } -} - -impl Parse for VariantAttr { - fn parse(input: ParseStream<'_>) -> Result { - let fn_name: Ident = input.parse()?; - - let lookahead = input.lookahead1(); - let value = if lookahead.peek(Token![=]) { - let _: Token![=] = input.parse()?; - Some(input.parse().map(parse_str_as_tokens)?) - } else { - None - }; - - Ok(VariantAttr { fn_name, value }) - } -} - -/// Parse kind attr as MetaItem. -fn parse_attrs(attrs: Vec) -> T -where - T: Default + Parse + AddAssign>, -{ - /// returns `tokens` where `tts` = `vec![Group(Paren, tokens)]` - fn unwrap_paren(tts: I) -> TokenStream - where - I: IntoIterator, - { - let mut tts = tts.into_iter(); - let tt = tts.next(); - - match tt { - Some(TokenTree::Group(ref g)) if g.delimiter() == Delimiter::Parenthesis => { - if tts.next().is_none() { - return g.stream(); - } - g.stream() - } - tt => panic!( - "expected tokens to be wrapped in a paren like #[kind(tokens)]\ngot {}", - match tt { - Some(ref tt) => tt as &dyn Display, - None => &"None" as &dyn Display, - } - ), - } - } - - let mut res = Default::default(); - for attr in attrs { - if is_attr_name(&attr, "doc") { - continue; - } - - if is_attr_name(&attr, "kind") { - let tts = unwrap_paren(attr.tokens); - let parsed: T = parse(tts.into()) - .unwrap_or_else(|err| panic!("failed to parse attribute: {}", err)); - - res += Ok(parsed); - } else { - res += Err(attr) - } - } - - res -} - -/// Parse content of string literal. -fn parse_str_as_tokens(lit: LitStr) -> T -where - T: Parse, -{ - let span = lit.span(); - // WTF? Literal does not provide a way to get string... - let tt = lit.value(); - - // TODO:Remove '"' only for first and last. - let tts = tt - .replace('\"', "") - .parse::() - .expect("failed to create TokenStream for return type") - .into_iter() - .map(|mut tt| { - tt.set_span(span); - tt - }) - .collect::(); - - parse(tts.into()).expect("failed to parse string literal") -} diff --git a/crates/enum_kind/src/util.rs b/crates/enum_kind/src/util.rs deleted file mode 100644 index 1395a27cb609..000000000000 --- a/crates/enum_kind/src/util.rs +++ /dev/null @@ -1,19 +0,0 @@ -use syn::*; - -pub fn is_bool(ty: &Type) -> bool { - if let Type::Path(TypePath { - qself: None, - path: Path { - leading_colon: None, - ref segments, - }, - }) = ty - { - // check for bool - if segments.len() == 1 && segments.first().unwrap().ident == "bool" { - return true; - } - } - - false -} diff --git a/crates/enum_kind/tests/usage.rs b/crates/enum_kind/tests/usage.rs deleted file mode 100644 index 76c63dbbaaa0..000000000000 --- a/crates/enum_kind/tests/usage.rs +++ /dev/null @@ -1,41 +0,0 @@ -use enum_kind::*; - -#[derive(Debug, Kind)] -#[kind(functions(is_a = "bool", prec = "u8"))] -pub enum Tokens { - #[kind(is_a)] - #[kind(prec = "7")] - A, - #[kind(prec = "6")] - StructLike {}, - #[kind(prec = "5")] - TupleLike(u8), - - #[kind(prec = "6")] - #[cfg(feature = "not-used")] - Unused, -} - -#[test] -fn simple_bool() { - assert!(Tokens::A.is_a()); - assert!(!Tokens::StructLike {}.is_a()); - assert!(!Tokens::TupleLike(5).is_a()); -} - -#[derive(Debug, Kind)] -#[kind(functions(wanted = "bool"))] -pub enum Delegate { - #[kind(wanted)] - Wanted, - #[kind(delegate)] - May(Del), -} - -#[derive(Debug, Kind)] -#[kind(functions(wanted = "bool"))] -pub enum Del { - #[kind(wanted)] - Yes, - No, -} From 887f7a9b9bbe7111119d017f2622cef2ad29882a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Donny/=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Fri, 24 Mar 2023 10:41:35 +0900 Subject: [PATCH 02/22] Drop dep --- crates/swc_ecma_parser/Cargo.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/crates/swc_ecma_parser/Cargo.toml b/crates/swc_ecma_parser/Cargo.toml index 5c2783f16b8c..83dc0503fad8 100644 --- a/crates/swc_ecma_parser/Cargo.toml +++ b/crates/swc_ecma_parser/Cargo.toml @@ -25,7 +25,6 @@ verify = ["swc_ecma_visit"] [dependencies] either = { version = "1.4" } -enum_kind = { version = "0.2.2", path = "../enum_kind" } lexical = { version = "6.1.0", features = ["power-of-two"] } num-bigint = "0.4" serde = { version = "1", features = ["derive"] } From f446537e143c3a82d8ad8f9644aeb7662db4d474 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Donny/=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Fri, 24 Mar 2023 10:41:41 +0900 Subject: [PATCH 03/22] lockfile --- Cargo.lock | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2052982f1767..72f5fceccf3a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -982,16 +982,6 @@ dependencies = [ "syn", ] -[[package]] -name = "enum_kind" -version = "0.2.2" -dependencies = [ - "pmutil", - "proc-macro2", - "swc_macros_common", - "syn", -] - [[package]] name = "enumset" version = "1.0.12" @@ -3727,7 +3717,6 @@ version = "0.130.9" dependencies = [ "criterion", "either", - "enum_kind", "lexical", "num-bigint", "pretty_assertions", From 9fc51220ef71c9c0e725d9a56e8d7e4ef9429855 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Donny/=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Fri, 24 Mar 2023 10:45:41 +0900 Subject: [PATCH 04/22] Fix more --- crates/swc_ecma_parser/src/lexer/state.rs | 1 - crates/swc_ecma_parser/src/token.rs | 38 +++++++++++++++++------ 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/crates/swc_ecma_parser/src/lexer/state.rs b/crates/swc_ecma_parser/src/lexer/state.rs index 357162e661fc..a1a8750a772f 100644 --- a/crates/swc_ecma_parser/src/lexer/state.rs +++ b/crates/swc_ecma_parser/src/lexer/state.rs @@ -1,6 +1,5 @@ use std::mem::take; -use enum_kind::Kind; use swc_common::{BytePos, Span}; use tracing::trace; diff --git a/crates/swc_ecma_parser/src/token.rs b/crates/swc_ecma_parser/src/token.rs index 01fa2ca725e8..7b61fa9826c2 100644 --- a/crates/swc_ecma_parser/src/token.rs +++ b/crates/swc_ecma_parser/src/token.rs @@ -6,7 +6,6 @@ use std::{ fmt::{self, Debug, Display, Formatter}, }; -use enum_kind::Kind; use num_bigint::BigInt as BigIntValue; use swc_atoms::{js_word, Atom, JsWord}; use swc_common::{Span, Spanned}; @@ -16,8 +15,7 @@ use swc_ecma_ast::BinaryOp; pub(crate) use self::{AssignOpToken::*, BinOpToken::*, Keyword::*, Token::*}; use crate::{error::Error, lexer::LexResult}; -#[derive(Kind, Clone, PartialEq)] -#[kind(functions(starts_expr = "bool", before_expr = "bool"))] +#[derive(Clone, PartialEq)] pub enum Token { /// Identifier, "null", "true", "false". /// @@ -145,6 +143,16 @@ pub enum Token { Error(Error), } +impl Token { + pub(crate) fn before_expr(&self) -> bool { + match self { + Token::Word(w) => w.before_expr(), + } + } + + pub(crate) fn starts_expr(&self) -> bool {} +} + #[derive(Kind, Debug, Clone, Copy, Eq, PartialEq, Hash)] #[kind(functions(starts_expr = "bool"))] pub enum BinOpToken { @@ -230,23 +238,33 @@ impl Spanned for TokenAndSpan { } } -#[derive(Kind, Clone, PartialEq, Eq, Hash)] -#[kind(functions(starts_expr = "bool", before_expr = "bool"))] +#[derive(Clone, PartialEq, Eq, Hash)] pub enum Word { - #[kind(delegate)] Keyword(Keyword), - #[kind(starts_expr)] Null, - #[kind(starts_expr)] True, - #[kind(starts_expr)] False, - #[kind(starts_expr)] Ident(JsWord), } +impl Word { + pub(crate) fn before_expr(&self) -> bool { + match self { + Word::Keyword(k) => k.before_expr(), + _ => false, + } + } + + pub(crate) fn starts_expr(&self) -> bool { + match self { + Word::Keyword(k) => k.starts_expr(), + _ => true, + } + } +} + impl From for Word { fn from(i: JsWord) -> Self { match i { From 7e8990a80545b6441ea8e8c371ca9113ac69954e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Donny/=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Fri, 24 Mar 2023 10:47:04 +0900 Subject: [PATCH 05/22] Fix more --- crates/swc_ecma_parser/src/lexer/state.rs | 13 +++++++++++-- crates/swc_ecma_parser/src/token.rs | 7 +++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/crates/swc_ecma_parser/src/lexer/state.rs b/crates/swc_ecma_parser/src/lexer/state.rs index a1a8750a772f..c955daf60b7c 100644 --- a/crates/swc_ecma_parser/src/lexer/state.rs +++ b/crates/swc_ecma_parser/src/lexer/state.rs @@ -759,8 +759,7 @@ impl TokenContexts { /// given point in the program is loosely based on sweet.js' approach. /// See https://github.com/mozilla/sweet.js/wiki/design #[repr(u8)] -#[derive(Debug, Clone, Copy, PartialEq, Eq, Kind)] -#[kind(function(is_expr = "bool", preserve_space = "bool"))] +#[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum TokenContext { BraceStmt, #[kind(is_expr)] @@ -788,6 +787,16 @@ pub enum TokenContext { JSXExpr, } +impl TokenContext { + pub fn is_expr(&self) -> bool { + match self {} + } + + pub fn preserve_space(&self) -> bool { + match self {} + } +} + #[cfg(test)] pub(crate) fn with_lexer( syntax: Syntax, diff --git a/crates/swc_ecma_parser/src/token.rs b/crates/swc_ecma_parser/src/token.rs index 7b61fa9826c2..b07d1d079f63 100644 --- a/crates/swc_ecma_parser/src/token.rs +++ b/crates/swc_ecma_parser/src/token.rs @@ -395,8 +395,7 @@ impl Debug for Word { } /// Keywords -#[derive(Kind, Clone, Copy, PartialEq, Eq, Hash)] -#[kind(function(before_expr = "bool", starts_expr = "bool"))] +#[derive(Clone, Copy, PartialEq, Eq, Hash)] pub enum Keyword { /// Spec says this might be identifier. #[kind(before_expr, starts_expr)] @@ -475,6 +474,10 @@ pub enum Keyword { } impl Keyword { + pub(crate) fn before_expr(&self) -> bool {} + + pub(crate) fn starts_expr(&self) -> bool {} + pub(crate) fn into_js_word(self) -> JsWord { match self { Await => js_word!("await"), From a3772744c86940b3e654aee4d922ba8bd7301805 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Donny/=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Fri, 24 Mar 2023 10:49:51 +0900 Subject: [PATCH 06/22] Fix more --- crates/swc_ecma_parser/src/token.rs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/crates/swc_ecma_parser/src/token.rs b/crates/swc_ecma_parser/src/token.rs index b07d1d079f63..ba33c3a01fbc 100644 --- a/crates/swc_ecma_parser/src/token.rs +++ b/crates/swc_ecma_parser/src/token.rs @@ -474,7 +474,26 @@ pub enum Keyword { } impl Keyword { - pub(crate) fn before_expr(&self) -> bool {} + pub(crate) const fn before_expr(&self) -> bool { + matches!( + self, + Self::Await + | Self::Case + | Self::Default_ + | Self::Do + | Self::Else + | Self::Return + | Self::Throw + | Self::New + | Self::Extends + | Self::Yield + | Self::In + | Self::InstanceOf + | Self::TypeOf + | Self::Void + | Self::Delete + ) + } pub(crate) fn starts_expr(&self) -> bool {} From ef8843d24fef09ae2a4bbab23260628b424e0a8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Donny/=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Fri, 24 Mar 2023 10:51:04 +0900 Subject: [PATCH 07/22] Fix more --- crates/swc_ecma_parser/src/lexer/state.rs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/crates/swc_ecma_parser/src/lexer/state.rs b/crates/swc_ecma_parser/src/lexer/state.rs index c955daf60b7c..df3d873d0b5a 100644 --- a/crates/swc_ecma_parser/src/lexer/state.rs +++ b/crates/swc_ecma_parser/src/lexer/state.rs @@ -788,11 +788,20 @@ pub enum TokenContext { } impl TokenContext { - pub fn is_expr(&self) -> bool { - match self {} + pub(crate) const fn is_expr(&self) -> bool { + matches!( + self, + Self::BraceExpr + | Self::TplQuasi + | Self::ParenExpr + | Self::Tpl { .. } + | Self::FnExpr + | Self::ClassExpr + | Self::JSXExpr + ) } - pub fn preserve_space(&self) -> bool { + pub(crate) fn preserve_space(&self) -> bool { match self {} } } From bc886a8e97d969947a28a4a59e23c7ade7c4614b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Donny/=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Fri, 24 Mar 2023 10:51:43 +0900 Subject: [PATCH 08/22] Fix more --- crates/swc_ecma_parser/src/lexer/state.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/crates/swc_ecma_parser/src/lexer/state.rs b/crates/swc_ecma_parser/src/lexer/state.rs index df3d873d0b5a..6b2e34b7f07d 100644 --- a/crates/swc_ecma_parser/src/lexer/state.rs +++ b/crates/swc_ecma_parser/src/lexer/state.rs @@ -801,8 +801,11 @@ impl TokenContext { ) } - pub(crate) fn preserve_space(&self) -> bool { - match self {} + pub(crate) const fn preserve_space(&self) -> bool { + match self { + Self::Tpl { .. } | Self::JSXExpr => true, + _ => false, + } } } From 0dd35a9620bc104ea510bbc1c814bae9dec4d73d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Donny/=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Fri, 24 Mar 2023 10:51:55 +0900 Subject: [PATCH 09/22] Fix more --- crates/swc_ecma_parser/src/lexer/state.rs | 7 ------- 1 file changed, 7 deletions(-) diff --git a/crates/swc_ecma_parser/src/lexer/state.rs b/crates/swc_ecma_parser/src/lexer/state.rs index 6b2e34b7f07d..93a61db6d2d6 100644 --- a/crates/swc_ecma_parser/src/lexer/state.rs +++ b/crates/swc_ecma_parser/src/lexer/state.rs @@ -762,28 +762,21 @@ impl TokenContexts { #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum TokenContext { BraceStmt, - #[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 { /// Start of a template literal. start: BytePos, }, - #[kind(is_expr)] FnExpr, - #[kind(is_expr)] ClassExpr, JSXOpeningTag, JSXClosingTag, - #[kind(is_expr, preserve_space)] JSXExpr, } From 833b3661fadbaa174f847863e8b34535d2baaebd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Donny/=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Fri, 24 Mar 2023 10:52:24 +0900 Subject: [PATCH 10/22] const --- crates/swc_ecma_parser/src/token.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/swc_ecma_parser/src/token.rs b/crates/swc_ecma_parser/src/token.rs index ba33c3a01fbc..94ccc2493af0 100644 --- a/crates/swc_ecma_parser/src/token.rs +++ b/crates/swc_ecma_parser/src/token.rs @@ -497,7 +497,7 @@ impl Keyword { pub(crate) fn starts_expr(&self) -> bool {} - pub(crate) fn into_js_word(self) -> JsWord { + pub(crate) const fn into_js_word(self) -> JsWord { match self { Await => js_word!("await"), Break => js_word!("break"), From 1b290017366a837ac19f0654e62a5b26efc11ef0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Donny/=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Fri, 24 Mar 2023 10:54:02 +0900 Subject: [PATCH 11/22] Fix more --- crates/swc_ecma_parser/src/token.rs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/crates/swc_ecma_parser/src/token.rs b/crates/swc_ecma_parser/src/token.rs index 94ccc2493af0..7e502cf9a0a4 100644 --- a/crates/swc_ecma_parser/src/token.rs +++ b/crates/swc_ecma_parser/src/token.rs @@ -495,7 +495,23 @@ impl Keyword { ) } - pub(crate) fn starts_expr(&self) -> bool {} + pub(crate) const fn starts_expr(&self) -> bool { + matches!( + self, + Self::Await + | Self::Function + | Self::Throw + | Self::New + | Self::This + | Self::Super + | Self::Class + | Self::Import + | Self::Yield + | Self::TypeOf + | Self::Void + | Self::Delete + ) + } pub(crate) const fn into_js_word(self) -> JsWord { match self { From 85d4cea925a78258d63d94989e76c69b4d68e476 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Donny/=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Fri, 24 Mar 2023 10:54:24 +0900 Subject: [PATCH 12/22] Fix more --- crates/swc_ecma_parser/src/token.rs | 24 ------------------------ 1 file changed, 24 deletions(-) diff --git a/crates/swc_ecma_parser/src/token.rs b/crates/swc_ecma_parser/src/token.rs index 7e502cf9a0a4..4d8d931bd1e5 100644 --- a/crates/swc_ecma_parser/src/token.rs +++ b/crates/swc_ecma_parser/src/token.rs @@ -398,36 +398,27 @@ impl Debug for Word { #[derive(Clone, Copy, PartialEq, Eq, Hash)] pub enum Keyword { /// Spec says this might be identifier. - #[kind(before_expr, starts_expr)] Await, - Break, - #[kind(before_expr)] Case, Catch, Continue, Debugger, - #[kind(before_expr)] Default_, - #[kind(before_expr)] Do, - #[kind(before_expr)] Else, Finally, For, - #[kind(starts_expr)] Function, If, - #[kind(before_expr)] Return, Switch, - #[kind(before_expr, starts_expr)] Throw, Try, @@ -437,39 +428,24 @@ pub enum Keyword { While, With, - #[kind(before_expr, starts_expr)] New, - #[kind(starts_expr)] This, - #[kind(starts_expr)] Super, - #[kind(starts_expr)] Class, - #[kind(before_expr)] Extends, Export, - #[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, starts_expr)] TypeOf, - - #[kind(before_expr, starts_expr)] Void, - - #[kind(before_expr, starts_expr)] Delete, } From 273194681bef22f63cffd5504653f9f45e05f693 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Donny/=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Fri, 24 Mar 2023 10:55:24 +0900 Subject: [PATCH 13/22] Fix more --- crates/swc_ecma_parser/src/token.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/crates/swc_ecma_parser/src/token.rs b/crates/swc_ecma_parser/src/token.rs index 4d8d931bd1e5..c5c69a734ca2 100644 --- a/crates/swc_ecma_parser/src/token.rs +++ b/crates/swc_ecma_parser/src/token.rs @@ -153,8 +153,7 @@ impl Token { pub(crate) fn starts_expr(&self) -> bool {} } -#[derive(Kind, Debug, Clone, Copy, Eq, PartialEq, Hash)] -#[kind(functions(starts_expr = "bool"))] +#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash)] pub enum BinOpToken { /// `==` EqEq, @@ -180,10 +179,8 @@ pub enum BinOpToken { ZeroFillRShift, /// `+` - #[kind(starts_expr)] Add, /// `-` - #[kind(starts_expr)] Sub, /// `*` Mul, @@ -218,7 +215,11 @@ pub enum BinOpToken { } impl BinOpToken { - pub const fn before_expr(self) -> bool { + pub(crate) const fn starts_expr(&self) -> bool { + matches!(self, Self::Add | Self::Sub) + } + + pub(crate) const fn before_expr(self) -> bool { true } } From f814eb50cb9ad33817e3ebfd0a45b247af6161d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Donny/=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Fri, 24 Mar 2023 10:56:55 +0900 Subject: [PATCH 14/22] Fix more --- crates/swc_ecma_parser/src/token.rs | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/crates/swc_ecma_parser/src/token.rs b/crates/swc_ecma_parser/src/token.rs index c5c69a734ca2..ad21155b877f 100644 --- a/crates/swc_ecma_parser/src/token.rs +++ b/crates/swc_ecma_parser/src/token.rs @@ -20,11 +20,9 @@ pub enum Token { /// Identifier, "null", "true", "false". /// /// Contains `null` and `` - #[kind(delegate)] Word(Word), /// '=>' - #[kind(before_expr)] Arrow, /// '#' @@ -36,24 +34,19 @@ pub enum Token { Dot, /// '...' - #[kind(before_expr)] DotDotDot, /// '!' - #[kind(before_expr, starts_expr)] Bang, /// '(' - #[kind(before_expr, starts_expr)] LParen, /// ')' RParen, /// `[` - #[kind(before_expr, starts_expr)] LBracket, /// ']' RBracket, /// '{' - #[kind(before_expr, starts_expr)] LBrace, /// '}' RBrace, @@ -146,11 +139,22 @@ pub enum Token { impl Token { pub(crate) fn before_expr(&self) -> bool { match self { - Token::Word(w) => w.before_expr(), + Self::Word(w) => w.before_expr(), + Self::Arrow + | Self::DotDotDot + | Self::Bang + | Self::LParen + | Self::LBrace + | Self::LBracket => true, } } - pub(crate) fn starts_expr(&self) -> bool {} + pub(crate) fn starts_expr(&self) -> bool { + match self { + Self::Word(w) => w.starts_expr(), + Self::Bang | Self::LParen | Self::LBrace | Self::LBracket => true, + } + } } #[derive(Debug, Clone, Copy, Eq, PartialEq, Hash)] From 113b837c5153071b986ae940108c9642b20b67b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Donny/=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Fri, 24 Mar 2023 10:58:22 +0900 Subject: [PATCH 15/22] Fix more --- crates/swc_ecma_parser/src/token.rs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/crates/swc_ecma_parser/src/token.rs b/crates/swc_ecma_parser/src/token.rs index ad21155b877f..ffcf4683fdda 100644 --- a/crates/swc_ecma_parser/src/token.rs +++ b/crates/swc_ecma_parser/src/token.rs @@ -52,14 +52,11 @@ pub enum Token { RBrace, /// ';' - #[kind(before_expr)] Semi, /// ',' - #[kind(before_expr)] Comma, /// '`' - #[kind(starts_expr)] BackQuote, Template { raw: Atom, @@ -145,14 +142,16 @@ impl Token { | Self::Bang | Self::LParen | Self::LBrace - | Self::LBracket => true, + | Self::LBracket + | Self::Semi + | Self::Comma => true, } } pub(crate) fn starts_expr(&self) -> bool { match self { Self::Word(w) => w.starts_expr(), - Self::Bang | Self::LParen | Self::LBrace | Self::LBracket => true, + Self::Bang | Self::LParen | Self::LBrace | Self::LBracket | Self::BackQuote => true, } } } @@ -255,14 +254,14 @@ pub enum Word { } impl Word { - pub(crate) fn before_expr(&self) -> bool { + pub(crate) const fn before_expr(&self) -> bool { match self { Word::Keyword(k) => k.before_expr(), _ => false, } } - pub(crate) fn starts_expr(&self) -> bool { + pub(crate) const fn starts_expr(&self) -> bool { match self { Word::Keyword(k) => k.starts_expr(), _ => true, From 8bcde9ca6c15704ec02543b1ccd02012dd4a56a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Donny/=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Fri, 24 Mar 2023 10:59:42 +0900 Subject: [PATCH 16/22] Fix more --- crates/swc_ecma_parser/src/token.rs | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/crates/swc_ecma_parser/src/token.rs b/crates/swc_ecma_parser/src/token.rs index ffcf4683fdda..6bfb77f7726c 100644 --- a/crates/swc_ecma_parser/src/token.rs +++ b/crates/swc_ecma_parser/src/token.rs @@ -63,20 +63,15 @@ pub enum Token { cooked: LexResult, }, /// ':' - #[kind(before_expr)] Colon, /// '::' - #[kind(before_expr)] ColonColon, /// - #[kind(delegate)] BinOp(BinOpToken), /// - #[kind(before_expr)] AssignOp(AssignOpToken), /// '${' - #[kind(before_expr, starts_expr)] DollarLBrace, /// '?' @@ -137,6 +132,7 @@ impl Token { pub(crate) fn before_expr(&self) -> bool { match self { Self::Word(w) => w.before_expr(), + Self::BinOpToken(w) => w.before_expr(), Self::Arrow | Self::DotDotDot | Self::Bang @@ -144,14 +140,24 @@ impl Token { | Self::LBrace | Self::LBracket | Self::Semi - | Self::Comma => true, + | Self::Comma + | Self::Colon + | Self::ColonColon + | Self::AssignOp(..) + | Self::DollarLBrace => true, } } pub(crate) fn starts_expr(&self) -> bool { match self { Self::Word(w) => w.starts_expr(), - Self::Bang | Self::LParen | Self::LBrace | Self::LBracket | Self::BackQuote => true, + Self::BinOpToken(w) => w.starts_expr(), + Self::Bang + | Self::LParen + | Self::LBrace + | Self::LBracket + | Self::BackQuote + | Self::DollarLBrace => true, } } } From 8dfbe74ed1c764c7cc943a71b46726da53646863 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Donny/=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Fri, 24 Mar 2023 11:00:10 +0900 Subject: [PATCH 17/22] Fix more --- crates/swc_ecma_parser/src/token.rs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/crates/swc_ecma_parser/src/token.rs b/crates/swc_ecma_parser/src/token.rs index 6bfb77f7726c..ddce93c5ae87 100644 --- a/crates/swc_ecma_parser/src/token.rs +++ b/crates/swc_ecma_parser/src/token.rs @@ -75,18 +75,14 @@ pub enum Token { DollarLBrace, /// '?' - #[kind(before_expr)] QuestionMark, /// `++` - #[kind(before_expr, starts_expr)] PlusPlus, /// `--` - #[kind(before_expr, starts_expr)] MinusMinus, /// `~` - #[kind(before_expr, starts_expr)] Tilde, /// String literal. Span of this token contains quote. @@ -144,7 +140,11 @@ impl Token { | Self::Colon | Self::ColonColon | Self::AssignOp(..) - | Self::DollarLBrace => true, + | Self::DollarLBrace + | Self::QuestionMark + | Self::PlusPlus + | Self::MinusMinus + | Self::Tilde => true, } } @@ -157,7 +157,10 @@ impl Token { | Self::LBrace | Self::LBracket | Self::BackQuote - | Self::DollarLBrace => true, + | Self::DollarLBrac + | Self::PlusPlus + | Self::MinusMinus + | Self::Tilde => true, } } } From 3c00480409863fc0b8add9978a47d9c09c32cb31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Donny/=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Fri, 24 Mar 2023 11:01:39 +0900 Subject: [PATCH 18/22] Fix more --- crates/swc_ecma_parser/src/token.rs | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/crates/swc_ecma_parser/src/token.rs b/crates/swc_ecma_parser/src/token.rs index ddce93c5ae87..51cea339c5e2 100644 --- a/crates/swc_ecma_parser/src/token.rs +++ b/crates/swc_ecma_parser/src/token.rs @@ -86,24 +86,20 @@ pub enum Token { Tilde, /// String literal. Span of this token contains quote. - #[kind(starts_expr)] Str { value: JsWord, raw: Atom, }, /// Regexp literal. - #[kind(starts_expr)] Regex(Atom, Atom), /// TODO: Make Num as enum and separate decimal, binary, ..etc - #[kind(starts_expr)] Num { value: f64, raw: Atom, }, - #[kind(starts_expr)] BigInt { value: Box, raw: Atom, @@ -112,11 +108,9 @@ pub enum Token { JSXName { name: JsWord, }, - #[kind(before_expr)] JSXText { raw: Atom, }, - #[kind(starts_expr)] JSXTagStart, JSXTagEnd, @@ -125,10 +119,10 @@ pub enum Token { } impl Token { - pub(crate) fn before_expr(&self) -> bool { + pub(crate) const fn before_expr(&self) -> bool { match self { Self::Word(w) => w.before_expr(), - Self::BinOpToken(w) => w.before_expr(), + Self::BinOp(w) => w.before_expr(), Self::Arrow | Self::DotDotDot | Self::Bang @@ -144,23 +138,31 @@ impl Token { | Self::QuestionMark | Self::PlusPlus | Self::MinusMinus - | Self::Tilde => true, + | Self::Tilde + | Self::Str { .. } + | Self::Regex(..) + | Self::Num { .. } + | Self::BigInt { .. } + | Self::JSXText { .. } => true, + _ => false, } } - pub(crate) fn starts_expr(&self) -> bool { + pub(crate) const fn starts_expr(&self) -> bool { match self { Self::Word(w) => w.starts_expr(), - Self::BinOpToken(w) => w.starts_expr(), + Self::BinOp(w) => w.starts_expr(), Self::Bang | Self::LParen | Self::LBrace | Self::LBracket | Self::BackQuote - | Self::DollarLBrac + | Self::DollarLBrace | Self::PlusPlus | Self::MinusMinus - | Self::Tilde => true, + | Self::Tilde + | Self::JSXTagStart => true, + _ => false, } } } From 5f8a7070aa06c380cfc4be48ec40e42fad5d60f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Donny/=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Fri, 24 Mar 2023 11:02:12 +0900 Subject: [PATCH 19/22] const --- crates/swc_ecma_parser/src/lexer/state.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/swc_ecma_parser/src/lexer/state.rs b/crates/swc_ecma_parser/src/lexer/state.rs index 93a61db6d2d6..363b8d6edbd7 100644 --- a/crates/swc_ecma_parser/src/lexer/state.rs +++ b/crates/swc_ecma_parser/src/lexer/state.rs @@ -61,7 +61,7 @@ enum TokenType { } impl TokenType { #[inline] - fn before_expr(self) -> bool { + const fn before_expr(self) -> bool { match self { TokenType::JSXName | TokenType::JSXTagStart From 1e5216d3c61b322f64771d3dfc860b17487a22ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Donny/=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Fri, 24 Mar 2023 11:03:12 +0900 Subject: [PATCH 20/22] CI --- .github/workflows/CI.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 2e7524f47d5f..8ce3554c1ec8 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -216,9 +216,6 @@ jobs: - crate: dbg-swc os: ubuntu-latest runner: ubuntu-latest - - crate: enum_kind - os: ubuntu-latest - runner: ubuntu-latest - crate: from_variant os: ubuntu-latest runner: ubuntu-latest From a838a95e989d17f23400f2356442c76926e42dd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Donny/=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Fri, 24 Mar 2023 11:21:10 +0900 Subject: [PATCH 21/22] Fix --- crates/swc_ecma_parser/src/token.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/swc_ecma_parser/src/token.rs b/crates/swc_ecma_parser/src/token.rs index 51cea339c5e2..f5ca0e42defa 100644 --- a/crates/swc_ecma_parser/src/token.rs +++ b/crates/swc_ecma_parser/src/token.rs @@ -139,10 +139,6 @@ impl Token { | Self::PlusPlus | Self::MinusMinus | Self::Tilde - | Self::Str { .. } - | Self::Regex(..) - | Self::Num { .. } - | Self::BigInt { .. } | Self::JSXText { .. } => true, _ => false, } @@ -161,6 +157,10 @@ impl Token { | Self::PlusPlus | Self::MinusMinus | Self::Tilde + | Self::Str { .. } + | Self::Regex(..) + | Self::Num { .. } + | Self::BigInt { .. } | Self::JSXTagStart => true, _ => false, } From 616a6701114680477e82c3a456e5403e74736742 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Donny/=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Fri, 24 Mar 2023 11:30:41 +0900 Subject: [PATCH 22/22] Fix cargo deny --- Cargo.lock | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 72f5fceccf3a..b87a8923b4d9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2046,9 +2046,9 @@ checksum = "0ab1bc2a289d34bd04a330323ac98a1b4bc82c9d9fcb1e66b63caa84da26b575" [[package]] name = "openssl" -version = "0.10.43" +version = "0.10.48" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "020433887e44c27ff16365eaa2d380547a94544ad509aff6eb5b6e3e0b27b376" +checksum = "518915b97df115dd36109bfa429a48b8f737bd05508cf9588977b599648926d2" dependencies = [ "bitflags", "cfg-if 1.0.0", @@ -2078,9 +2078,9 @@ checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" [[package]] name = "openssl-sys" -version = "0.9.79" +version = "0.9.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5454462c0eced1e97f2ec09036abc8da362e66802f66fd20f86854d9d8cbcbc4" +checksum = "666416d899cf077260dac8698d60a60b435a46d57e82acb1be3d0dad87284e5b" dependencies = [ "autocfg", "cc",