thx / gogocode

GoGoCode is a transformer for JavaScript/Typescript/HTML based on AST but providing a more intuitive API.
MIT License
5.47k stars 417 forks source link

The use of import.meta.env causes the AST parsing to fail. #250

Closed PlutoZX closed 5 months ago

PlutoZX commented 5 months ago

Hello, in my project, I used the Vite environment variable syntax import.meta.env.VITE_BUILD_ENV. Through my testing, I found that if the code contains this, it will throw an error when parsing the AST.

/packages/cradle-compiler/node_modules/gogocode/src/js-core/core.js:155 throw new Error(buildAstByAstStr failed:${str}) ^ Error: buildAstByAstStr failed:

It works fine when it's removed. How should I handle this?

PlutoZX commented 5 months ago

Viewing other answers has resolved the issue. Add sourceType: 'module' to parseOptions.