Closed khanayan123 closed 11 months ago
Going to work on getting the CI to pass & fix other linting/nitpick issues, but in the meanwhile wanted to open a PR to get opinions on the general approach
If needed we can also use https://swc.rs/ instead which is written in RUST and aims to be faster then recast/acorn.
We can draw inspiration from: https://github.com/DataDog/dd-native-iast-rewriter-js/
fixes loader cyclical dependency bug by forgoing module wrapping of file and embedding file contents within the patch instead.
To ensure the patch still works when embedding file content an AST is generated to make modifications to the file contents. The general flow is file content -> AST -> update const named exports to let & add a name to any non named default export -> regenerate file contents using updated AST -> embed the file contents in the patch.
Recast (https://github.com/benjamn/recast) is used as the AST transformer & code generator of choice since it seems to be great at maintaining original file content structure & thus subsequently maintaining original file stack trace. Although the use of source maps might be better.
This PR aims to solve this issue: https://github.com/DataDog/dd-trace-js/issues/3595