You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
refactor(napi/parser): use minifier to generate JS/TS raw transfer deserializers 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.
0 commit comments