Skip to content

Commit 08e666f

Browse files
committed
refactor(ast/estree): add #[estree] attrs to RegExpFlagsAlias (#11794)
Pure refactor. Add more `#[estree]` attributes to `RegExpFlagsAlias` type. These have no effect on generated code for JSON serialization or raw transfer deserialization, as `RegExpFlagsAlias` already has a custom converter. But it simplifies the codegen for lazy deserialization.
1 parent 3e0001d commit 08e666f

3 files changed

Lines changed: 4 additions & 15 deletions

File tree

crates/oxc_ast/src/ast/literal.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,6 @@ bitflags! {
227227
/// Dummy type to communicate the content of `RegExpFlags` to `oxc_ast_tools`.
228228
#[ast(foreign = RegExpFlags)]
229229
#[generate_derive(ESTree)]
230-
#[estree(via = RegExpFlagsConverter)]
230+
#[estree(no_type, via = RegExpFlagsConverter)]
231231
#[expect(dead_code)]
232-
struct RegExpFlagsAlias(u8);
232+
struct RegExpFlagsAlias(#[estree(skip)] u8);

napi/parser/generated/deserialize/lazy.js

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6661,7 +6661,6 @@ class RegExpPattern {
66616661
const DebugRegExpPattern = class RegExpPattern {};
66626662

66636663
class RegExpFlags {
6664-
type = 'RegExpFlags';
66656664
#internal;
66666665

66676666
constructor(pos, ast) {
@@ -6675,15 +6674,8 @@ class RegExpFlags {
66756674
nodes.set(pos, this);
66766675
}
66776676

6678-
get 0() {
6679-
const internal = this.#internal;
6680-
return constructU8(internal.pos, internal.ast);
6681-
}
6682-
66836677
toJSON() {
6684-
return {
6685-
type: 'RegExpFlags',
6686-
};
6678+
return {};
66876679
}
66886680

66896681
[inspectSymbol]() {

tasks/ast_tools/src/generators/raw_transfer_lazy.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -475,10 +475,7 @@ fn generate_struct(
475475
");
476476
}
477477

478-
// TODO: Remove this special case for `RegExpFlags`
479-
if struct_name != "RegExpFlags" {
480-
write_it!(to_json, "{field_name}: this.{field_name},\n");
481-
}
478+
write_it!(to_json, "{field_name}: this.{field_name},\n");
482479
}
483480

484481
let type_prop_init = if add_type_field {

0 commit comments

Comments
 (0)