mirror of
https://github.com/swc-project/swc.git
synced 2024-12-29 00:23:10 +03:00
refactor(common): Remove add_bitflags
and update bitflags
(#7571)
This commit is contained in:
parent
068c17206a
commit
95ac74e6e4
20
Cargo.lock
generated
20
Cargo.lock
generated
@ -260,9 +260,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
|
||||
|
||||
[[package]]
|
||||
name = "bitflags"
|
||||
version = "2.1.0"
|
||||
version = "2.3.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c70beb79cbb5ce9c4f8e20849978f34225931f665bb49efa6982875a4d5facb3"
|
||||
checksum = "6dbe3c979c178231552ecba20214a8272df4e09f232a87aef4320cf06539aded"
|
||||
|
||||
[[package]]
|
||||
name = "bitvec"
|
||||
@ -3635,7 +3635,6 @@ dependencies = [
|
||||
"ast_node",
|
||||
"atty",
|
||||
"better_scoped_tls",
|
||||
"bitflags 2.1.0",
|
||||
"bytecheck",
|
||||
"cfg-if",
|
||||
"criterion",
|
||||
@ -3766,7 +3765,7 @@ name = "swc_css_codegen"
|
||||
version = "0.147.18"
|
||||
dependencies = [
|
||||
"auto_impl",
|
||||
"bitflags 2.1.0",
|
||||
"bitflags 2.3.2",
|
||||
"rustc-hash",
|
||||
"serde",
|
||||
"swc_atoms",
|
||||
@ -3794,7 +3793,7 @@ dependencies = [
|
||||
name = "swc_css_compat"
|
||||
version = "0.23.18"
|
||||
dependencies = [
|
||||
"bitflags 2.1.0",
|
||||
"bitflags 2.3.2",
|
||||
"once_cell",
|
||||
"serde",
|
||||
"serde_json",
|
||||
@ -3865,7 +3864,6 @@ dependencies = [
|
||||
name = "swc_css_parser"
|
||||
version = "0.146.18"
|
||||
dependencies = [
|
||||
"bitflags 2.1.0",
|
||||
"criterion",
|
||||
"lexical",
|
||||
"serde",
|
||||
@ -3925,7 +3923,7 @@ name = "swc_ecma_ast"
|
||||
version = "0.106.5"
|
||||
dependencies = [
|
||||
"arbitrary",
|
||||
"bitflags 2.1.0",
|
||||
"bitflags 2.3.2",
|
||||
"bytecheck",
|
||||
"is-macro",
|
||||
"num-bigint",
|
||||
@ -4207,7 +4205,7 @@ name = "swc_ecma_transforms_base"
|
||||
version = "0.129.12"
|
||||
dependencies = [
|
||||
"better_scoped_tls",
|
||||
"bitflags 2.1.0",
|
||||
"bitflags 2.3.2",
|
||||
"criterion",
|
||||
"indexmap",
|
||||
"once_cell",
|
||||
@ -4288,7 +4286,7 @@ dependencies = [
|
||||
"Inflector",
|
||||
"ahash 0.8.3",
|
||||
"anyhow",
|
||||
"bitflags 2.1.0",
|
||||
"bitflags 2.3.2",
|
||||
"indexmap",
|
||||
"is-macro",
|
||||
"path-clean",
|
||||
@ -4612,7 +4610,7 @@ name = "swc_html_codegen"
|
||||
version = "0.40.18"
|
||||
dependencies = [
|
||||
"auto_impl",
|
||||
"bitflags 2.1.0",
|
||||
"bitflags 2.3.2",
|
||||
"rustc-hash",
|
||||
"swc_atoms",
|
||||
"swc_common",
|
||||
@ -4897,7 +4895,7 @@ name = "swc_xml_codegen"
|
||||
version = "0.11.19"
|
||||
dependencies = [
|
||||
"auto_impl",
|
||||
"bitflags 2.1.0",
|
||||
"bitflags 2.3.2",
|
||||
"rustc-hash",
|
||||
"swc_atoms",
|
||||
"swc_common",
|
||||
|
@ -72,7 +72,6 @@ swc_visit = { version = "0.5.7", path = "../swc_visit" }
|
||||
|
||||
|
||||
[dev-dependencies]
|
||||
bitflags = "2.1.0"
|
||||
criterion = "0.5"
|
||||
rayon = "1"
|
||||
serde_json = "1"
|
||||
|
@ -1,169 +0,0 @@
|
||||
#![allow(non_upper_case_globals)]
|
||||
#![recursion_limit = "512"]
|
||||
|
||||
use swc_common::add_bitflags;
|
||||
|
||||
fn main() {
|
||||
// NOOP
|
||||
}
|
||||
|
||||
bitflags::bitflags! {
|
||||
pub struct ListFormat: u32 {
|
||||
const None = 0;
|
||||
}
|
||||
}
|
||||
|
||||
add_bitflags!(
|
||||
ListFormat,
|
||||
// Handled by bitflags! macro.
|
||||
// Values { None: 0 },
|
||||
/// Line separators
|
||||
Values {
|
||||
/// Prints the list on a single line (default).
|
||||
SingleLine: 0,
|
||||
/// Prints the list on multiple lines.
|
||||
MultiLine: 1 << 0,
|
||||
/// Prints the list using line preservation if possible.
|
||||
PreserveLines: 1 << 1,
|
||||
LinesMask: SingleLine | MultiLine | PreserveLines,
|
||||
},
|
||||
/// Delimiters
|
||||
Values {
|
||||
/// There is no delimiter between list items (default).
|
||||
NotDelimited: 0,
|
||||
/// Each list item is space-and-bar (" |") delimited.
|
||||
BarDelimited: 1 << 2,
|
||||
/// Each list item is space-and-ampersand (" &") delimited.
|
||||
AmpersandDelimited: 1 << 3,
|
||||
/// Each list item is comma (",") delimited.
|
||||
CommaDelimited: 1 << 4,
|
||||
DelimitersMask: BarDelimited | AmpersandDelimited | CommaDelimited,
|
||||
},
|
||||
Values {
|
||||
/// Write a trailing comma (",") if present.
|
||||
AllowTrailingComma: 1 << 5,
|
||||
},
|
||||
/// Whitespace
|
||||
Values {
|
||||
/// The list should be indented.
|
||||
Indented: 1 << 6,
|
||||
/// Inserts a space after the opening brace and before the closing
|
||||
/// brace.
|
||||
SpaceBetweenBraces: 1 << 7,
|
||||
/// Inserts a space between each sibling node.
|
||||
SpaceBetweenSiblings: 1 << 8,
|
||||
},
|
||||
/// Brackets/Braces
|
||||
Values {
|
||||
/// The list is surrounded by "{" and "}".
|
||||
Braces: 1 << 9,
|
||||
/// The list is surrounded by "(" and ")".
|
||||
Parenthesis: 1 << 10,
|
||||
/// The list is surrounded by "<" and ">".
|
||||
AngleBrackets: 1 << 11,
|
||||
/// The list is surrounded by "[" and "]".
|
||||
SquareBrackets: 1 << 12,
|
||||
BracketsMask: Braces | Parenthesis | AngleBrackets | SquareBrackets,
|
||||
},
|
||||
Values {
|
||||
/// Do not emit brackets if the list is undefined.
|
||||
OptionalIfUndefined: 1 << 13,
|
||||
/// Do not emit brackets if the list is empty.
|
||||
OptionalIfEmpty: 1 << 14,
|
||||
Optional: OptionalIfUndefined | OptionalIfEmpty,
|
||||
},
|
||||
/// Others
|
||||
Values {
|
||||
/// Prefer adding a LineTerminator between synthesized nodes.
|
||||
PreferNewLine: 1 << 15,
|
||||
/// Do not emit a trailing NewLine for a MultiLine list.
|
||||
NoTrailingNewLine: 1 << 16,
|
||||
/// Do not emit comments between each node
|
||||
NoInterveningComments: 1 << 17,
|
||||
/// If the literal is empty, do not add spaces between braces.
|
||||
NoSpaceIfEmpty: 1 << 18,
|
||||
SingleElement: 1 << 19,
|
||||
},
|
||||
/// Precomputed Formats
|
||||
Values {
|
||||
Modifiers: SingleLine | SpaceBetweenSiblings | NoInterveningComments,
|
||||
HeritageClauses: SingleLine | SpaceBetweenSiblings,
|
||||
SingleLineTypeLiteralMembers: SingleLine
|
||||
| SpaceBetweenBraces
|
||||
| SpaceBetweenSiblings
|
||||
| Indented,
|
||||
MultiLineTypeLiteralMembers: MultiLine | Indented,
|
||||
TupleTypeElements: CommaDelimited | SpaceBetweenSiblings | SingleLine | Indented,
|
||||
UnionTypeConstituents: BarDelimited | SpaceBetweenSiblings | SingleLine,
|
||||
IntersectionTypeConstituents: AmpersandDelimited | SpaceBetweenSiblings | SingleLine,
|
||||
ObjectBindingPatternElements: SingleLine
|
||||
| AllowTrailingComma
|
||||
| SpaceBetweenBraces
|
||||
| CommaDelimited
|
||||
| SpaceBetweenSiblings
|
||||
| NoSpaceIfEmpty,
|
||||
ArrayBindingPatternElements: SingleLine
|
||||
| AllowTrailingComma
|
||||
| CommaDelimited
|
||||
| SpaceBetweenSiblings
|
||||
| NoSpaceIfEmpty,
|
||||
ObjectLiteralExpressionProperties: PreserveLines
|
||||
| CommaDelimited
|
||||
| SpaceBetweenSiblings
|
||||
| SpaceBetweenBraces
|
||||
| Indented
|
||||
| Braces
|
||||
| NoSpaceIfEmpty,
|
||||
ArrayLiteralExpressionElements: PreserveLines
|
||||
| CommaDelimited
|
||||
| SpaceBetweenSiblings
|
||||
| AllowTrailingComma
|
||||
| Indented
|
||||
| SquareBrackets,
|
||||
CommaListElements: CommaDelimited | SpaceBetweenSiblings | SingleLine,
|
||||
CallExpressionArguments: CommaDelimited | SpaceBetweenSiblings | SingleLine | Parenthesis,
|
||||
NewExpressionArguments: CommaDelimited
|
||||
| SpaceBetweenSiblings
|
||||
| SingleLine
|
||||
| Parenthesis
|
||||
| OptionalIfUndefined,
|
||||
TemplateExpressionSpans: SingleLine | NoInterveningComments,
|
||||
SingleLineBlockStatements: SpaceBetweenBraces | SpaceBetweenSiblings | SingleLine,
|
||||
MultiLineBlockStatements: Indented | MultiLine,
|
||||
VariableDeclarationList: CommaDelimited | SpaceBetweenSiblings | SingleLine,
|
||||
SingleLineFunctionBodyStatements: SingleLine | SpaceBetweenSiblings | SpaceBetweenBraces,
|
||||
MultiLineFunctionBodyStatements: MultiLine,
|
||||
ClassHeritageClauses: SingleLine | SpaceBetweenSiblings,
|
||||
ClassMembers: Indented | MultiLine,
|
||||
InterfaceMembers: Indented | MultiLine,
|
||||
EnumMembers: CommaDelimited | Indented | MultiLine,
|
||||
CaseBlockClauses: Indented | MultiLine,
|
||||
NamedImportsOrExportsElements: CommaDelimited
|
||||
| SpaceBetweenSiblings
|
||||
| AllowTrailingComma
|
||||
| SingleLine
|
||||
| SpaceBetweenBraces,
|
||||
JsxElementOrFragmentChildren: SingleLine | NoInterveningComments,
|
||||
JsxElementAttributes: SingleLine | SpaceBetweenSiblings | NoInterveningComments,
|
||||
CaseOrDefaultClauseStatements: Indented | MultiLine | NoTrailingNewLine | OptionalIfEmpty,
|
||||
HeritageClauseTypes: CommaDelimited | SpaceBetweenSiblings | SingleLine,
|
||||
SourceFileStatements: MultiLine | NoTrailingNewLine,
|
||||
Decorators: MultiLine | Optional,
|
||||
TypeArguments: CommaDelimited
|
||||
| SpaceBetweenSiblings
|
||||
| SingleLine
|
||||
| AngleBrackets
|
||||
| Optional,
|
||||
TypeParameters: CommaDelimited
|
||||
| SpaceBetweenSiblings
|
||||
| SingleLine
|
||||
| AngleBrackets
|
||||
| Optional,
|
||||
Parameters: CommaDelimited | SpaceBetweenSiblings | SingleLine | Parenthesis,
|
||||
IndexSignatureParameters: CommaDelimited
|
||||
| SpaceBetweenSiblings
|
||||
| SingleLine
|
||||
| Indented
|
||||
| SquareBrackets,
|
||||
},
|
||||
);
|
@ -66,7 +66,6 @@ mod eq;
|
||||
pub mod errors;
|
||||
pub mod input;
|
||||
pub mod iter;
|
||||
pub mod macros;
|
||||
pub mod pass;
|
||||
pub mod plugin;
|
||||
mod pos;
|
||||
|
@ -1,177 +0,0 @@
|
||||
/// Create a impl block with some bitflags.
|
||||
#[doc(hidden)]
|
||||
#[macro_export]
|
||||
macro_rules! make_impl_block {
|
||||
(
|
||||
@NAME,
|
||||
Done {
|
||||
$($done:tt)*
|
||||
},
|
||||
|
||||
$(#[$attr:meta])*
|
||||
$name:ident:
|
||||
|
||||
$($rest:tt)+
|
||||
) => {
|
||||
$crate::make_impl_block!(
|
||||
@VALUE,
|
||||
Cur {},
|
||||
Done {
|
||||
$($done)*
|
||||
|
||||
$(#[$attr])*
|
||||
$name :
|
||||
},
|
||||
|
||||
$($rest)*
|
||||
);
|
||||
};
|
||||
|
||||
// Handle comma.
|
||||
(
|
||||
@VALUE,
|
||||
Cur {
|
||||
$($cur:tt)+
|
||||
},
|
||||
Done {
|
||||
$($done:tt)*
|
||||
},
|
||||
|
||||
,
|
||||
|
||||
$($rest:tt)*
|
||||
) => {
|
||||
$crate::make_impl_block!(
|
||||
@NAME,
|
||||
Done {
|
||||
$($done)*
|
||||
|
||||
( $($cur)* ),
|
||||
},
|
||||
|
||||
$($rest)*
|
||||
);
|
||||
};
|
||||
|
||||
// Handle value.
|
||||
(
|
||||
@VALUE,
|
||||
Cur {
|
||||
$($cur:tt)*
|
||||
},
|
||||
Done {
|
||||
$($done:tt)*
|
||||
},
|
||||
|
||||
$tok:tt
|
||||
|
||||
$($rest:tt)+
|
||||
) => {
|
||||
$crate::make_impl_block!(
|
||||
@VALUE,
|
||||
Cur {
|
||||
$($cur)*
|
||||
$tok
|
||||
},
|
||||
Done {
|
||||
$($done)*
|
||||
},
|
||||
|
||||
$($rest)*
|
||||
);
|
||||
};
|
||||
|
||||
// Handle value without trailing comma.
|
||||
(
|
||||
@VALUE,
|
||||
Cur {
|
||||
$($cur:tt)*
|
||||
},
|
||||
Done {
|
||||
$($done:tt)*
|
||||
},
|
||||
|
||||
$tok:tt
|
||||
) => {
|
||||
$crate::make_impl_block!(
|
||||
@VALUE,
|
||||
Cur {
|
||||
$($cur)*
|
||||
$tok
|
||||
},
|
||||
Done {
|
||||
$($done)*
|
||||
},
|
||||
|
||||
,
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
// Done.
|
||||
(
|
||||
@NAME,
|
||||
Done {
|
||||
$STRUCT:ident;
|
||||
$(
|
||||
$(#[$attr:meta])*
|
||||
$name:ident: ( $($val:tt)* ),
|
||||
)*
|
||||
},
|
||||
) => {
|
||||
impl $STRUCT {
|
||||
$(
|
||||
$(#[$attr])*
|
||||
pub const $name: Self = Self::from_bits_retain( $crate::value_of_bitflag!($($val)*) );
|
||||
)*
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
#[macro_export]
|
||||
macro_rules! value_of_bitflag {
|
||||
(
|
||||
$i:ident |
|
||||
$($rest:tt)*
|
||||
) => {
|
||||
Self::$i.bits() | $crate::value_of_bitflag!($($rest)*)
|
||||
};
|
||||
|
||||
(
|
||||
$i:ident
|
||||
) => {
|
||||
Self::$i.bits()
|
||||
};
|
||||
|
||||
($e:expr) => { $e };
|
||||
}
|
||||
|
||||
/// rustfmt-friendly version of `bitflags!`.
|
||||
#[macro_export]
|
||||
macro_rules! add_bitflags {
|
||||
// Done
|
||||
($STRUCT:ident,) => {};
|
||||
|
||||
(
|
||||
$STRUCT:ident,
|
||||
$(#[$attr:meta])*
|
||||
Values {
|
||||
$($tt:tt)*
|
||||
},
|
||||
|
||||
$($rest:tt)*
|
||||
) => {
|
||||
$(#[$attr])*
|
||||
$crate::make_impl_block!(@NAME, Done {
|
||||
$STRUCT;
|
||||
}, $($tt)*);
|
||||
|
||||
$crate::add_bitflags!(
|
||||
$STRUCT,
|
||||
$($rest)*
|
||||
);
|
||||
};
|
||||
}
|
@ -14,7 +14,7 @@ bench = false
|
||||
|
||||
[dependencies]
|
||||
auto_impl = "1.1.0"
|
||||
bitflags = "2.1.0"
|
||||
bitflags = "2.3.2"
|
||||
rustc-hash = "1.1.0"
|
||||
serde = "1.0.127"
|
||||
|
||||
|
@ -1,40 +1,30 @@
|
||||
#![allow(non_upper_case_globals)]
|
||||
use bitflags::bitflags;
|
||||
use swc_common::add_bitflags;
|
||||
|
||||
bitflags! {
|
||||
#[derive(PartialEq, Eq, Copy, Clone)]
|
||||
pub struct ListFormat: u16 {
|
||||
const None = 0;
|
||||
|
||||
// Line separators
|
||||
/// Prints the list on a single line (default).
|
||||
const SingleLine = 0;
|
||||
/// Prints the list on multiple lines.
|
||||
const MultiLine = 1 << 0;
|
||||
/// Prints the list using line preservation if possible.
|
||||
const PreserveLines = 1 << 1;
|
||||
const LinesMask = Self::MultiLine.bits() | Self::PreserveLines.bits();
|
||||
|
||||
// Delimiters
|
||||
const NotDelimited = 0;
|
||||
const SpaceDelimited = 1 << 2;
|
||||
/// There is no delimiter between list items (default).
|
||||
const SemiDelimited = 1 << 3;
|
||||
const CommaDelimited = 1 << 4;
|
||||
const DotDelimited = 1 << 5;
|
||||
const DelimitersMask = Self::SpaceDelimited.bits()
|
||||
| Self::SemiDelimited.bits()
|
||||
| Self::CommaDelimited.bits()
|
||||
| Self::DotDelimited.bits();
|
||||
}
|
||||
}
|
||||
|
||||
add_bitflags!(
|
||||
ListFormat,
|
||||
// Handled by bitflags! macro.
|
||||
// Values { None: 0 },
|
||||
/// Line separators
|
||||
Values {
|
||||
/// Prints the list on a single line (default).
|
||||
SingleLine: 0,
|
||||
/// Prints the list on multiple lines.
|
||||
MultiLine: 1 << 0,
|
||||
/// Prints the list using line preservation if possible.
|
||||
PreserveLines: 1 << 1,
|
||||
LinesMask: SingleLine | MultiLine | PreserveLines,
|
||||
},
|
||||
/// Delimiters
|
||||
Values {
|
||||
NotDelimited: 0,
|
||||
SpaceDelimited: 1 << 2,
|
||||
/// There is no delimiter between list items (default).
|
||||
SemiDelimited: 1 << 3,
|
||||
CommaDelimited: 1 << 4,
|
||||
DotDelimited: 1 << 5,
|
||||
DelimitersMask: SpaceDelimited | SemiDelimited | CommaDelimited | DotDelimited,
|
||||
},
|
||||
Values {
|
||||
/// Write a trailing comma (",") if present.
|
||||
AllowTrailingComma: 1 << 6,
|
||||
},
|
||||
);
|
||||
|
@ -13,7 +13,7 @@ version = "0.23.18"
|
||||
bench = false
|
||||
|
||||
[dependencies]
|
||||
bitflags = "2.1.0"
|
||||
bitflags = "2.3.2"
|
||||
once_cell = "1.18.0"
|
||||
serde = { version = "1.0.118", features = ["derive"] }
|
||||
serde_json = "1.0.61"
|
||||
|
@ -16,7 +16,6 @@ bench = false
|
||||
debug = []
|
||||
|
||||
[dependencies]
|
||||
bitflags = "2.1.0"
|
||||
lexical = "6.1.0"
|
||||
serde = "1.0.127"
|
||||
|
||||
|
@ -30,7 +30,7 @@ serde-impl = ["serde"]
|
||||
|
||||
[dependencies]
|
||||
arbitrary = { version = "1", optional = true, features = ["derive"] }
|
||||
bitflags = "2.1.0"
|
||||
bitflags = "2.3.2"
|
||||
# bytecheck version should be in sync with rkyv version. Do not bump individually.
|
||||
bytecheck = { version = "0.6.10", optional = true }
|
||||
is-macro = "0.3.0"
|
||||
|
@ -1,7 +1,6 @@
|
||||
#![allow(unused)]
|
||||
#![allow(non_upper_case_globals)]
|
||||
use bitflags::bitflags;
|
||||
use swc_common::add_bitflags;
|
||||
|
||||
bitflags! {
|
||||
/// Represents the formatting rule for a list of nodes.
|
||||
@ -9,172 +8,185 @@ bitflags! {
|
||||
pub struct ListFormat: u32 {
|
||||
/// Default value.
|
||||
const None = 0;
|
||||
}
|
||||
}
|
||||
|
||||
add_bitflags!(
|
||||
ListFormat,
|
||||
// Handled by bitflags! macro.
|
||||
// Values { None: 0 },
|
||||
/// Line separators
|
||||
Values {
|
||||
// Line separators
|
||||
/// Prints the list on a single line (default).
|
||||
SingleLine: 0,
|
||||
const SingleLine = 0;
|
||||
/// Prints the list on multiple lines.
|
||||
MultiLine: 1 << 0,
|
||||
const MultiLine = 1 << 0;
|
||||
/// Prints the list using line preservation if possible.
|
||||
PreserveLines: 1 << 1,
|
||||
LinesMask: SingleLine | MultiLine | PreserveLines,
|
||||
},
|
||||
/// Delimiters
|
||||
Values {
|
||||
const PreserveLines = 1 << 1;
|
||||
const LinesMask = Self::MultiLine.bits() | Self::PreserveLines.bits();
|
||||
|
||||
// Delimiters
|
||||
/// There is no delimiter between list items (default).
|
||||
NotDelimited: 0,
|
||||
const NotDelimited = 0;
|
||||
/// Each list item is space-and-bar (" |") delimited.
|
||||
BarDelimited: 1 << 2,
|
||||
const BarDelimited = 1 << 2;
|
||||
/// Each list item is space-and-ampersand (" &") delimited.
|
||||
AmpersandDelimited: 1 << 3,
|
||||
/// Each list item is comma (",") delimited.
|
||||
CommaDelimited: 1 << 4,
|
||||
DelimitersMask: BarDelimited | AmpersandDelimited | CommaDelimited,
|
||||
},
|
||||
Values {
|
||||
/// Write a trailing comma (",") if present.
|
||||
AllowTrailingComma: 1 << 5,
|
||||
},
|
||||
/// Whitespace
|
||||
Values {
|
||||
const AmpersandDelimited = 1 << 3;
|
||||
/// Each list item is comma (";") delimited.
|
||||
const CommaDelimited = 1 << 4;
|
||||
const DelimitersMask = Self::BarDelimited.bits()
|
||||
| Self::AmpersandDelimited.bits()
|
||||
| Self::CommaDelimited.bits();
|
||||
|
||||
// Write a trailing comma (";") if present.
|
||||
const AllowTrailingComma = 1 << 5;
|
||||
|
||||
// Whitespace
|
||||
/// The list should be indented.
|
||||
Indented: 1 << 6,
|
||||
const Indented = 1 << 6;
|
||||
/// Inserts a space after the opening brace and before the closing
|
||||
/// brace.
|
||||
SpaceBetweenBraces: 1 << 7,
|
||||
const SpaceBetweenBraces = 1 << 7;
|
||||
/// Inserts a space between each sibling node.
|
||||
SpaceBetweenSiblings: 1 << 8,
|
||||
},
|
||||
/// Brackets/Braces
|
||||
Values {
|
||||
const SpaceBetweenSiblings = 1 << 8;
|
||||
|
||||
// Brackets/Braces
|
||||
/// The list is surrounded by "{" and "}".
|
||||
Braces: 1 << 9,
|
||||
const Braces = 1 << 9;
|
||||
/// The list is surrounded by "(" and ")".
|
||||
Parenthesis: 1 << 10,
|
||||
const Parenthesis = 1 << 10;
|
||||
/// The list is surrounded by "<" and ">".
|
||||
AngleBrackets: 1 << 11,
|
||||
const AngleBrackets = 1 << 11;
|
||||
/// The list is surrounded by "[" and "]".
|
||||
SquareBrackets: 1 << 12,
|
||||
BracketsMask: Braces | Parenthesis | AngleBrackets | SquareBrackets,
|
||||
},
|
||||
Values {
|
||||
const SquareBrackets = 1 << 12;
|
||||
const BracketsMask = Self::Braces.bits()
|
||||
| Self::Parenthesis.bits()
|
||||
| Self::AngleBrackets.bits()
|
||||
| Self::SquareBrackets.bits();
|
||||
|
||||
/// Do not emit brackets if the list is undefined.
|
||||
OptionalIfUndefined: 1 << 13,
|
||||
const OptionalIfUndefined = 1 << 13;
|
||||
/// Do not emit brackets if the list is empty.
|
||||
OptionalIfEmpty: 1 << 14,
|
||||
Optional: OptionalIfUndefined | OptionalIfEmpty,
|
||||
},
|
||||
/// Others
|
||||
Values {
|
||||
const OptionalIfEmpty = 1 << 14;
|
||||
const Optional = Self::OptionalIfUndefined.bits() | Self::OptionalIfEmpty.bits();
|
||||
|
||||
// Others
|
||||
/// Prefer adding a LineTerminator between synthesized nodes.
|
||||
PreferNewLine: 1 << 15,
|
||||
const PreferNewLine = 1 << 15;
|
||||
/// Do not emit a trailing NewLine for a MultiLine list.
|
||||
NoTrailingNewLine: 1 << 16,
|
||||
const NoTrailingNewLine = 1 << 16;
|
||||
/// Do not emit comments between each node
|
||||
NoInterveningComments: 1 << 17,
|
||||
/// If the literal is empty, do not add spaces between braces.
|
||||
NoSpaceIfEmpty: 1 << 18,
|
||||
SingleElement: 1 << 19,
|
||||
ForceTrailingComma: 1 << 20,
|
||||
},
|
||||
// Optimization.
|
||||
Values {
|
||||
CanSkipTrailingComma: 1 << 21
|
||||
},
|
||||
/// Precomputed Formats
|
||||
Values {
|
||||
Modifiers: SingleLine | SpaceBetweenSiblings | NoInterveningComments,
|
||||
HeritageClauses: SingleLine | SpaceBetweenSiblings,
|
||||
SingleLineTypeLiteralMembers: SingleLine
|
||||
| SpaceBetweenBraces
|
||||
| SpaceBetweenSiblings
|
||||
| Indented,
|
||||
MultiLineTypeLiteralMembers: MultiLine | Indented,
|
||||
TupleTypeElements: CommaDelimited | SpaceBetweenSiblings | SingleLine | Indented,
|
||||
UnionTypeConstituents: BarDelimited | SpaceBetweenSiblings | SingleLine,
|
||||
IntersectionTypeConstituents: AmpersandDelimited | SpaceBetweenSiblings | SingleLine,
|
||||
ObjectBindingPatternElements: SingleLine
|
||||
| SpaceBetweenBraces
|
||||
| CommaDelimited
|
||||
| SpaceBetweenSiblings
|
||||
| NoSpaceIfEmpty,
|
||||
ArrayBindingPatternElements: SingleLine
|
||||
| CommaDelimited
|
||||
| SpaceBetweenSiblings
|
||||
| NoSpaceIfEmpty,
|
||||
// ObjectLiteralExpressionProperties: PreserveLines
|
||||
// | CommaDelimited
|
||||
// | SpaceBetweenSiblings
|
||||
// | SpaceBetweenBraces
|
||||
// | Indented
|
||||
// | Braces
|
||||
// | NoSpaceIfEmpty,
|
||||
ObjectLiteralExpressionProperties: MultiLine
|
||||
| CommaDelimited
|
||||
| SpaceBetweenSiblings
|
||||
| SpaceBetweenBraces
|
||||
| Indented
|
||||
| Braces
|
||||
| NoSpaceIfEmpty,
|
||||
ArrayLiteralExpressionElements: PreserveLines
|
||||
| CommaDelimited
|
||||
| SpaceBetweenSiblings
|
||||
| Indented
|
||||
| SquareBrackets,
|
||||
CommaListElements: CommaDelimited | SpaceBetweenSiblings | SingleLine,
|
||||
CallExpressionArguments: CommaDelimited | SpaceBetweenSiblings | SingleLine | Parenthesis,
|
||||
NewExpressionArguments: CommaDelimited
|
||||
| SpaceBetweenSiblings
|
||||
| SingleLine
|
||||
| Parenthesis
|
||||
| OptionalIfUndefined,
|
||||
TemplateExpressionSpans: SingleLine | NoInterveningComments,
|
||||
SingleLineBlockStatements: SpaceBetweenBraces | SpaceBetweenSiblings | SingleLine,
|
||||
MultiLineBlockStatements: Indented | MultiLine,
|
||||
VariableDeclarationList: CommaDelimited | SpaceBetweenSiblings | SingleLine,
|
||||
SingleLineFunctionBodyStatements: SingleLine | SpaceBetweenSiblings | SpaceBetweenBraces,
|
||||
MultiLineFunctionBodyStatements: MultiLine,
|
||||
ClassHeritageClauses: SingleLine | SpaceBetweenSiblings,
|
||||
ClassMembers: Indented | MultiLine,
|
||||
InterfaceMembers: Indented | MultiLine,
|
||||
EnumMembers: CommaDelimited | Indented | MultiLine,
|
||||
CaseBlockClauses: Indented | MultiLine,
|
||||
NamedImportsOrExportsElements: CommaDelimited
|
||||
| SpaceBetweenSiblings
|
||||
| AllowTrailingComma
|
||||
| SingleLine
|
||||
| SpaceBetweenBraces,
|
||||
JsxElementOrFragmentChildren: SingleLine | NoInterveningComments,
|
||||
JsxElementAttributes: SingleLine | SpaceBetweenSiblings | NoInterveningComments,
|
||||
CaseOrDefaultClauseStatements: Indented | MultiLine | NoTrailingNewLine | OptionalIfEmpty,
|
||||
HeritageClauseTypes: CommaDelimited | SpaceBetweenSiblings | SingleLine,
|
||||
SourceFileStatements: MultiLine | NoTrailingNewLine,
|
||||
Decorators: MultiLine | Optional,
|
||||
TypeArguments: CommaDelimited
|
||||
| SpaceBetweenSiblings
|
||||
| SingleLine
|
||||
| AngleBrackets
|
||||
| Optional,
|
||||
TypeParameters: CommaDelimited
|
||||
| SpaceBetweenSiblings
|
||||
| SingleLine
|
||||
| AngleBrackets
|
||||
| Optional,
|
||||
Parameters: CommaDelimited | SpaceBetweenSiblings | SingleLine | Parenthesis,
|
||||
IndexSignatureParameters: CommaDelimited
|
||||
| SpaceBetweenSiblings
|
||||
| SingleLine
|
||||
| Indented
|
||||
| SquareBrackets,
|
||||
},
|
||||
);
|
||||
const NoInterveningComments = 1 << 17;
|
||||
/// If the literal is empty; do not add spaces between braces.
|
||||
const NoSpaceIfEmpty = 1 << 18;
|
||||
const SingleElement = 1 << 19;
|
||||
const ForceTrailingComma = 1 << 20;
|
||||
|
||||
// Optimization.
|
||||
const CanSkipTrailingComma = 1 << 21;
|
||||
|
||||
// Precomputed Formats
|
||||
const Modifiers = Self::SingleLine.bits()
|
||||
| Self::SpaceBetweenSiblings.bits()
|
||||
| Self::NoInterveningComments.bits();
|
||||
const HeritageClauses = Self::SingleLine.bits() | Self::SpaceBetweenSiblings.bits();
|
||||
const SingleLineTypeLiteralMembers = Self::SingleLine.bits()
|
||||
| Self::SpaceBetweenBraces.bits()
|
||||
| Self::SpaceBetweenSiblings.bits()
|
||||
| Self::Indented.bits();
|
||||
const MultiLineTypeLiteralMembers = Self::MultiLine.bits() | Self::Indented.bits();
|
||||
const TupleTypeElements = Self::CommaDelimited.bits()
|
||||
| Self::SpaceBetweenSiblings.bits()
|
||||
| Self::SingleLine.bits()
|
||||
| Self::Indented.bits();
|
||||
const UnionTypeConstituents = Self::BarDelimited.bits()
|
||||
| Self::SpaceBetweenSiblings.bits()
|
||||
| Self::SingleLine.bits();
|
||||
const IntersectionTypeConstituents = Self::AmpersandDelimited.bits()
|
||||
| Self::SpaceBetweenSiblings.bits()
|
||||
| Self::SingleLine.bits();
|
||||
const ObjectBindingPatternElements = Self::SingleLine.bits()
|
||||
| Self::SpaceBetweenBraces.bits()
|
||||
| Self::CommaDelimited.bits()
|
||||
| Self::SpaceBetweenSiblings.bits()
|
||||
| Self::NoSpaceIfEmpty.bits();
|
||||
const ArrayBindingPatternElements = Self::SingleLine.bits()
|
||||
| Self::CommaDelimited.bits()
|
||||
| Self::SpaceBetweenSiblings.bits()
|
||||
| Self::NoSpaceIfEmpty.bits();
|
||||
const ObjectLiteralExpressionProperties = Self::MultiLine.bits()
|
||||
| Self::CommaDelimited.bits()
|
||||
| Self::SpaceBetweenSiblings.bits()
|
||||
| Self::SpaceBetweenBraces.bits()
|
||||
| Self::Indented.bits()
|
||||
| Self::Braces.bits()
|
||||
| Self::NoSpaceIfEmpty.bits();
|
||||
const ArrayLiteralExpressionElements = Self::PreserveLines.bits()
|
||||
| Self::CommaDelimited.bits()
|
||||
| Self::SpaceBetweenSiblings.bits()
|
||||
| Self::Indented.bits()
|
||||
| Self::SquareBrackets.bits();
|
||||
const CommaListElements = Self::CommaDelimited.bits()
|
||||
| Self::SpaceBetweenSiblings.bits()
|
||||
| Self::SingleLine.bits();
|
||||
const CallExpressionArguments = Self::CommaDelimited.bits()
|
||||
| Self::SpaceBetweenSiblings.bits()
|
||||
| Self::SingleLine.bits()
|
||||
| Self::Parenthesis.bits();
|
||||
const NewExpressionArguments = Self::CommaDelimited.bits()
|
||||
| Self::SpaceBetweenSiblings.bits()
|
||||
| Self::SingleLine.bits()
|
||||
| Self::Parenthesis.bits()
|
||||
| Self::OptionalIfUndefined.bits();
|
||||
const TemplateExpressionSpans = Self::SingleLine.bits() | Self::NoInterveningComments.bits();
|
||||
const SingleLineBlockStatements = Self::SpaceBetweenBraces.bits()
|
||||
| Self::SpaceBetweenSiblings.bits()
|
||||
| Self::SingleLine.bits();
|
||||
const MultiLineBlockStatements = Self::Indented.bits() | Self::MultiLine.bits();
|
||||
const VariableDeclarationList = Self::CommaDelimited.bits()
|
||||
| Self::SpaceBetweenSiblings.bits()
|
||||
| Self::SingleLine.bits();
|
||||
const SingleLineFunctionBodyStatements = Self::SingleLine.bits()
|
||||
| Self::SpaceBetweenSiblings.bits()
|
||||
| Self::SpaceBetweenBraces.bits();
|
||||
const MultiLineFunctionBodyStatements = Self::MultiLine.bits();
|
||||
const ClassHeritageClauses = Self::SingleLine.bits() | Self::SpaceBetweenSiblings.bits();
|
||||
const ClassMembers = Self::Indented.bits() | Self::MultiLine.bits();
|
||||
const InterfaceMembers = Self::Indented.bits() | Self::MultiLine.bits();
|
||||
const EnumMembers = Self::CommaDelimited.bits() | Self::Indented.bits() | Self::MultiLine.bits();
|
||||
const CaseBlockClauses = Self::Indented.bits() | Self::MultiLine.bits();
|
||||
const NamedImportsOrExportsElements = Self::CommaDelimited.bits()
|
||||
| Self::SpaceBetweenSiblings.bits()
|
||||
| Self::AllowTrailingComma.bits()
|
||||
| Self::SingleLine.bits()
|
||||
| Self::SpaceBetweenBraces.bits();
|
||||
const JsxElementOrFragmentChildren = Self::SingleLine.bits() | Self::NoInterveningComments.bits();
|
||||
const JsxElementAttributes = Self::SingleLine.bits()
|
||||
| Self::SpaceBetweenSiblings.bits()
|
||||
| Self::NoInterveningComments.bits();
|
||||
const CaseOrDefaultClauseStatements = Self::Indented.bits()
|
||||
| Self::MultiLine.bits()
|
||||
| Self::NoTrailingNewLine.bits()
|
||||
| Self::OptionalIfEmpty.bits();
|
||||
const HeritageClauseTypes = Self::CommaDelimited.bits()
|
||||
| Self::SpaceBetweenSiblings.bits()
|
||||
| Self::SingleLine.bits();
|
||||
const SourceFileStatements = Self::MultiLine.bits() | Self::NoTrailingNewLine.bits();
|
||||
const Decorators = Self::MultiLine.bits() | Self::Optional.bits();
|
||||
const TypeArguments = Self::CommaDelimited.bits()
|
||||
| Self::SpaceBetweenSiblings.bits()
|
||||
| Self::SingleLine.bits()
|
||||
| Self::AngleBrackets.bits()
|
||||
| Self::Optional.bits();
|
||||
const TypeParameters = Self::CommaDelimited.bits()
|
||||
| Self::SpaceBetweenSiblings.bits()
|
||||
| Self::SingleLine.bits()
|
||||
| Self::AngleBrackets.bits()
|
||||
| Self::Optional.bits();
|
||||
const Parameters = Self::CommaDelimited.bits()
|
||||
| Self::SpaceBetweenSiblings.bits()
|
||||
| Self::SingleLine.bits()
|
||||
| Self::Parenthesis.bits();
|
||||
const IndexSignatureParameters = Self::CommaDelimited.bits()
|
||||
| Self::SpaceBetweenSiblings.bits()
|
||||
| Self::SingleLine.bits()
|
||||
| Self::Indented.bits()
|
||||
| Self::SquareBrackets.bits();
|
||||
}
|
||||
}
|
||||
|
||||
impl ListFormat {
|
||||
pub fn opening_bracket(self) -> &'static str {
|
||||
|
@ -18,7 +18,7 @@ concurrent-renamer = ["rayon"]
|
||||
|
||||
[dependencies]
|
||||
better_scoped_tls = { version = "0.1.1", path = "../better_scoped_tls" }
|
||||
bitflags = "2.1.0"
|
||||
bitflags = "2.3.2"
|
||||
indexmap = "1.9.3"
|
||||
once_cell = "1.18.0"
|
||||
phf = { version = "0.10", features = ["macros"] }
|
||||
|
@ -16,7 +16,7 @@ bench = false
|
||||
Inflector = "0.11.4"
|
||||
ahash = "0.8.3"
|
||||
anyhow = "1.0.71"
|
||||
bitflags = "2.1.0"
|
||||
bitflags = "2.3.2"
|
||||
indexmap = "1.9.3"
|
||||
is-macro = "0.3.0"
|
||||
path-clean = "0.1.0"
|
||||
|
@ -17,7 +17,7 @@ bench = false
|
||||
|
||||
[dependencies]
|
||||
auto_impl = "1.1.0"
|
||||
bitflags = "2.1.0"
|
||||
bitflags = "2.3.2"
|
||||
rustc-hash = "1.1.0"
|
||||
|
||||
swc_atoms = { version = "0.5.6", path = "../swc_atoms" }
|
||||
|
@ -1,32 +1,23 @@
|
||||
#![allow(non_upper_case_globals)]
|
||||
use bitflags::bitflags;
|
||||
use swc_common::add_bitflags;
|
||||
|
||||
bitflags! {
|
||||
#[derive(PartialEq, Eq, Copy, Clone)]
|
||||
pub struct ListFormat: u16 {
|
||||
const None = 0;
|
||||
|
||||
// Line separators
|
||||
/// Prints the list on a single line (default).
|
||||
const SingleLine = 0;
|
||||
/// Prints the list on multiple lines.
|
||||
const MultiLine = 1 << 0;
|
||||
/// Prints the list using line preservation if possible.
|
||||
const PreserveLines = 1 << 1;
|
||||
const LinesMask = Self::MultiLine.bits() | Self::PreserveLines.bits();
|
||||
|
||||
// Delimiters
|
||||
const NotDelimited = 0;
|
||||
const SpaceDelimited = 1 << 2;
|
||||
const DelimitersMask = Self::SpaceDelimited.bits();
|
||||
}
|
||||
}
|
||||
|
||||
add_bitflags!(
|
||||
ListFormat,
|
||||
// Handled by bitflags! macro.
|
||||
// Values { None: 0 },
|
||||
/// Line separators
|
||||
Values {
|
||||
/// Prints the list on a single line (default).
|
||||
SingleLine: 0,
|
||||
/// Prints the list on multiple lines.
|
||||
MultiLine: 1 << 0,
|
||||
/// Prints the list using line preservation if possible.
|
||||
PreserveLines: 1 << 1,
|
||||
LinesMask: SingleLine | MultiLine | PreserveLines,
|
||||
},
|
||||
/// Delimiters
|
||||
Values {
|
||||
NotDelimited: 0,
|
||||
SpaceDelimited: 1 << 2,
|
||||
DelimitersMask: SpaceDelimited,
|
||||
},
|
||||
);
|
||||
|
@ -17,7 +17,7 @@ bench = false
|
||||
|
||||
[dependencies]
|
||||
auto_impl = "1.1.0"
|
||||
bitflags = "2.1.0"
|
||||
bitflags = "2.3.2"
|
||||
rustc-hash = "1.1.0"
|
||||
|
||||
swc_atoms = { version = "0.5.6", path = "../swc_atoms" }
|
||||
|
@ -1,32 +1,23 @@
|
||||
#![allow(non_upper_case_globals)]
|
||||
use bitflags::bitflags;
|
||||
use swc_common::add_bitflags;
|
||||
|
||||
bitflags! {
|
||||
#[derive(PartialEq, Eq, Clone, Copy)]
|
||||
pub struct ListFormat: u16 {
|
||||
const None = 0;
|
||||
|
||||
// Line separators
|
||||
/// Prints the list on a single line (default).
|
||||
const SingleLine = 0;
|
||||
/// Prints the list on multiple lines.
|
||||
const MultiLine = 1 << 0;
|
||||
/// Prints the list using line preservation if possible.
|
||||
const PreserveLines = 1 << 1;
|
||||
const LinesMask = Self::MultiLine.bits() | Self::PreserveLines.bits();
|
||||
|
||||
// Delimiters
|
||||
const NotDelimited = 0;
|
||||
const SpaceDelimited = 1 << 2;
|
||||
const DelimitersMask = Self::SpaceDelimited.bits();
|
||||
}
|
||||
}
|
||||
|
||||
add_bitflags!(
|
||||
ListFormat,
|
||||
// Handled by bitflags! macro.
|
||||
// Values { None: 0 },
|
||||
/// Line separators
|
||||
Values {
|
||||
/// Prints the list on a single line (default).
|
||||
SingleLine: 0,
|
||||
/// Prints the list on multiple lines.
|
||||
MultiLine: 1 << 0,
|
||||
/// Prints the list using line preservation if possible.
|
||||
PreserveLines: 1 << 1,
|
||||
LinesMask: SingleLine | MultiLine | PreserveLines,
|
||||
},
|
||||
/// Delimiters
|
||||
Values {
|
||||
NotDelimited: 0,
|
||||
SpaceDelimited: 1 << 2,
|
||||
DelimitersMask: SpaceDelimited,
|
||||
},
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user