refactor(common): Remove add_bitflags
and update bitflags
#7571
+217
−584
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The
add_flags
macro makesimpl
blocks for the bitflags struct separately from the one generated bybitflags
. This is incorrect because thebitflags
implementation uses the listed constants to generate certain method bodies.I opted to manually specify the
bitflags
macro instead of modifying theadd_flags
macro to remove complexity (the bitflags structs are not changed often).The PR also bumps the version of
bitflags
to 2.3.2 to ensure that the added tests #7542, #7545 still pass.Fixes: #7513
Related: bitflags/bitflags#365
Details
In the linked issue, commas were not added in the minified codegen because this line:
swc/crates/swc_ecma_codegen/src/lib.rs
Lines 1944 to 1948 in 068c172
Causes
list_format
to be set to the emptyListFormat
due to theSubAssign
implementation.The implementation is like this:
The implementation is like this:
The key is the change to use
from_bits_truncate
. This code:generates this output:
Using the
add_bitflags!
macro inswc_common
, the flags are manually added to the struct afterbitflags
code generation, so the middle parts are not generated, eventually causingSubAssign
to return an empty flag struct.