Parse and rewrite typescript files #5158
Closed
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.
What does this PR do?
This PR discusses different approaches to
Node.js
new Typescript support (--experimental-strip-types
and--experimental-transform-types
) and evaluates how they might impact our IAST module.It specifically implements the first approach.
Overview
With Node.js introducing native type stripping via SWC, we have three possible approaches:
Approach 1: Use
Module.stripTypeScriptTypes()
We directly invoke Module.stripTypeScriptTypes() to remove types from
.ts
files before passing the plain Javascript to our custom rewrite function.The flags
--experimental-strip-types
or--experimental-transform-types
will determine how Node.js transforms Typescript code.Pros:
Cons:
The approach described here is already implemented in this PR.
Approach 2: Use
dd-native-iast-rewriter-js
with configurationSince Node.js's Amaro and our rewriter both use SWC under the hood, we can streamline the process by forwarding the flags directly to our rewriter as additional configuration options, enabling it to handle both TS and JS files while applying our instrumentation logic in a single pass, eliminating the need for separate type stripping and transformation steps.
Pros:
Cons:
Approach 3: Use
dd-native-iast-rewriter-js
Typescript onlySimilar to the 2nd approach, but we always parse files (even plain Javascript) under SWC’s Typescript syntax, then we only do the rewriting in one pass.
Pros:
Cons:
There are other potential suggestions, such as using
Amaro
in a manner similar to the first approach, though this requires installing an additional dependency thatNode.js
already provides.Feel free to discuss each suggestion or propose new ones
Plugin Checklist
Additional Notes