Himujjal / tree-sitter-svelte

Tree sitter grammar for Svelte
MIT License
81 stars 14 forks source link

Not able to parse Svelte code with `web-tree-sitter` #38

Closed sebastinez closed 1 year ago

sebastinez commented 1 year ago

Hi @Himujjal,

Great work on the library, and looking great on nvim. In my case I'm trying to get it to work with the web bindings in a Svelte app, and while Rust, Javascript, Typescript, C work good so far, I'm not able to run the tree-sitter-svelte wasm.

I have built the wasm file locally with npx tree-sitter build-wasm node_modules/tree-sitter-svelt --docker and also tried using the one you provide in this repo, but I get the same following error.

Blob.svelte:49 TypeError: Cannot read properties of undefined (reading 'apply')
    at e.<computed> (tree-sitter.js:1:16465)
    at 00022c9e:0x1272
    at 00022c9e:0x25d1
    at 00022c9e:0x294f
    at 00022c9e:0x2ebe
    at 00022c9e:0x2f0c
    at tree-sitter.wasm:0x25842
    at _Parser.parse (tree-sitter.js:1:53325)
    at Syntax.parse (syntax.ts:52:25)

Do you have any idea whats going on? I also tried different versions of the tree-sitter-cli and of emscripten to build the wasm, also tried to generate new parsers but I don't think that's be the issue.

EDIT: I get the same issue with some other pointers with tree-sitter-html so it could also be some version mismatch.

sebastinez commented 1 year ago

Just did some tests to highlight code with the tree-sitter CLI and works great, so it's either a version mismatch or something between the web bindings and the parser?

savetheclocktower commented 1 year ago

This happens when a Tree-sitter parser uses an external scanner and that scanner uses any C/C++ stdlib function that web-tree-sitter is unaware of. Right now, the only workaround is to build a custom web-tree-sitter; this page explains how we do it in the Pulsar project.

tree-sitter#949 and tree-sitter#1906 are the relevant issues. The long-term fix is described in a comment on the latter ticket. The short-term fix for tree-sitter (IMO) is to figure out how to show the user a better error message, and the short-term fix for individual parsers is to rewrite their scanners so that they don't use any functions that aren't in this list of exports.

sebastinez commented 1 year ago

Thank you very much @savetheclocktower this looks very promising to resolve my issue!

Will get back to you here if that's the case

sebastinez commented 1 year ago

Okay just had to try it out and works like a gem πŸ’Ž tyvm πŸ™‡