refactor(napi/parser): use minifier to generate JS/TS raw transfer deserializers from single source#14312
Merged
graphite-app[bot] merged 1 commit intomainfrom Oct 4, 2025
Conversation
Member
Author
How to use the Graphite Merge QueueAdd either label to this PR to merge it via the merge queue:
You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. This stack of pull requests is managed by Graphite. Learn more about stacking. |
CodSpeed Instrumentation Performance ReportMerging #14312 will not alter performanceComparing Summary
Footnotes |
0b616e8 to
1fbda58
Compare
This was referenced Oct 3, 2025
8dea470 to
066f4a5
Compare
1fbda58 to
77bc09c
Compare
Member
Author
Merge activity
|
…serializers from single source (#14312) Pure refactor. Makes only minor cosmetic changes to the generated raw transfer deserializer code, mainly just alters *how* that code is generated. Previously we generated the source for the 2 different deserializers (JS and TS) separately, with the JS deserializer leaving out some fields e.g. `typeAnnotation`. Instead, generate only 1 base implementation, with TS-only fields gated by `IS_TS`. `IS_TS` is defined as a `const` at top of the file. ```js const IS_TS = true; function deserializeFunction(pos) { const params = deserializeBoxFormalParameters(pos + 56); if (IS_TS) { const thisParam = deserializeOptionBoxTSThisParameter(pos + 48); if (thisParam !== null) params.unshift(thisParam); } return { type: deserializeFunctionType(pos + 84), params, ...(IS_TS && { declare: deserializeBool(pos + 87), typeParameters: deserializeOptionBoxTSTypeParameterDeclaration(pos + 40), }), // ... etc ... }; } ``` Then we generate both the JS and TS deserializers from this same file, by setting the `IS_TS` const to `true` or `false`, and using minifier to shake out the dead code. This: 1. Simplifies custom deserializers. 2. Opens the door to add more `const` flags, e.g. `RANGES` to switch on/off including `range` field in AST nodes.
066f4a5 to
a98757a
Compare
77bc09c to
34e1c0b
Compare
Base automatically changed from
10-02-refactor_napi_parser_minify_syntax_in_raw_transfer_deserializers
to
main
October 4, 2025 14:16
graphite-app bot
pushed a commit
that referenced
this pull request
Oct 6, 2025
…4372) Pure refactor. Codegen for raw transfer contains logic for generating multiple deserializer variants from a single base implementation, using feature flags to gate certain code, and minifier to shake out dead code in each (#14312). Abstract this functionality into a `VariantGenerator` trait, and move it into the `output` module. This allows reusing the same functionality for other generators.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.

Pure refactor. Makes only minor cosmetic changes to the generated raw transfer deserializer code, mainly just alters how that code is generated.
Previously we generated the source for the 2 different deserializers (JS and TS) separately, with the JS deserializer leaving out some fields e.g.
typeAnnotation.Instead, generate only 1 base implementation, with TS-only fields gated by
IS_TS.IS_TSis defined as aconstat top of the file.Then we generate both the JS and TS deserializers from this same file, by setting the
IS_TSconst totrueorfalse, and using minifier to shake out the dead code.This:
constflags, e.g.RANGESto switch on/off includingrangefield in AST nodes.