xtensio icon indicating copy to clipboard operation
xtensio copied to clipboard

[Contents]: Extract getConfig with the help of static analysis.

Open doc-han opened this issue 1 year ago • 2 comments

Description

Currently, when extracting getConfig object from content files. We simulate an environment to execute the file. The issue is that in this same file exists some other JS code that is waiting to be executed on the web. This other code might fail at the stage we're trying to just extract the getConfig object.

Example getConfig function Screenshot 2024-10-26 at 10 38 25 AM

What to look for

  • With static analysis, can we cleanup content files to contain just getConfig function and its dependency modules so that we don't execute extra code.
  • checkout the typescript compiler api or recast

doc-han avatar Oct 26 '24 10:10 doc-han

Idea 01 I think with static analysis we can just check the children nodes of program and find an exported function or variable with name getConfig then remove all other children nodes that aren't that or imports. When it comes to cleaning up imports, how about running eslint --fix with a single rule remove-ununsed-imports to avoid walking down the tree.

doc-han avatar Oct 26 '24 10:10 doc-han

Final Entirely achievable with static analysis only. ⚡️

doc-han avatar Nov 10 '24 04:11 doc-han