guybedford / es-module-lexer

Low-overhead lexer dedicated to ES module parsing for fast analysis
MIT License
917 stars 48 forks source link

how to parse .tsx file? #126

Closed lili21 closed 2 years ago

lili21 commented 2 years ago

do I need to compile it to js file first ?

guybedford commented 2 years ago

Parsing tsx is not a goal of this project. It's advisable to uses a parser with typescript support, there are many out there like Babel, Acorn, SWC, etc.

ice1000 commented 1 year ago

It seems that vite is parsing tsx files with this project... I got a parse error like the following:

vitepress v1.0.0-alpha.31
⠧ building client + server bundles...[vite:build-import-analysis] Parse error @:21:26
file: /home/ice1000/git-repos/aya-prover-docs/src/.vitepress/components/Publications/Publications.tsx:17:68
15:   },
16:   setup(props) {
17:     // const links: Record<string, { name: string, link: (s: string) => string }> = {
                                                                        ^
18:     //   arxiv: {
19:     //     name: 'arXiv preprint',
✖ building client + server bundles...
build error:
 Error: Parse error @:21:26
    at parse$e (file:///home/ice1000/git-repos/aya-prover-docs/node_modules/.pnpm/vite@4.0.0/node_modules/vite/dist/node/chunks/dep-ed9cb113.js:15843:355)

The line dep-ed9cb113.js:15843:355 starts with /* es-module-lexer 1.1.0 */. I'm not familiar with programming, so I'm not sure if that means this line is compiled from this project, but really it seems they are abusing this project

guybedford commented 1 year ago

That sounds like a Vite issue if you are parsing tsx with this project.

ice1000 commented 1 year ago

Yes, I know. I'm leaving a comment for the record :)