nestdotland/analyzer

imports analysis: panicked when src is incorrect

Opened this issue · 0 comments

Hi Divy
I'm currently working on a rewrite of the dep tree module but I'm facing a few issues
Consider the folloing code:

import init, { source, tree } from "https://x.nest.land/analyzer@0.0.6/wasm/wasm.js";

await init(source);

try {
  tree("", "{{");
} catch (err) {
  console.log(err);
}

try {
  tree("", "const x = 5;");
} catch (err) {
  console.log(err);
}

The first call analyzes {{. This code is obviously not valid javascript.
Some error messages are displayed even if I remove the console.log.
The second call analyzes const x = 5; which is valid javascript but the wasm function is still stuck.

panicked at 'called `Result::unwrap()` on an `Err` value: SwcDiagnosticBuffer { diagnostics: ["Unexpected eof at :1:2"] }', src/lib.rs:19:6

Stack:

Error
    at Y.g.wbg.__wbg_new_59cb74e423758ede (https://3cfd3lulgczqtos7nd7bcmymng2nybpbdzsdljvpo64uo3vyx4kq.arweave.net/2Io9roswswm6X2j-ETMMabTcBeEeZDWmr3e5R264vxU/wasm/wasm.js:2:1169976)  
    at <anonymous> (<anonymous>:0:638559)
    at <anonymous> (<anonymous>:0:791204)
    at <anonymous> (<anonymous>:0:673555)
    at <anonymous> (<anonymous>:0:770656)
    at <anonymous> (<anonymous>:0:778289)
    at <anonymous> (<anonymous>:0:742880)
    at tree (<anonymous>:0:558415)
    at tree (https://3cfd3lulgczqtos7nd7bcmymng2nybpbdzsdljvpo64uo3vyx4kq.arweave.net/2Io9roswswm6X2j-ETMMabTcBeEeZDWmr3e5R264vxU/wasm/wasm.js:2:1168676)
    at graph.ts:137:3


RuntimeError: unreachable
    at <anonymous> (<anonymous>:0:673586)
    at <anonymous> (<anonymous>:0:770656)
    at <anonymous> (<anonymous>:0:778289)
    at <anonymous> (<anonymous>:0:742880)
    at tree (<anonymous>:0:558415)
    at tree (https://3cfd3lulgczqtos7nd7bcmymng2nybpbdzsdljvpo64uo3vyx4kq.arweave.net/2Io9roswswm6X2j-ETMMabTcBeEeZDWmr3e5R264vxU/wasm/wasm.js:2:1168676)
    at graph.ts:137:3
panicked at 'cannot modify the panic hook from a panicking thread', src/libstd/panicking.rs:106:9

Stack:

Error
    at Y.g.wbg.__wbg_new_59cb74e423758ede (https://3cfd3lulgczqtos7nd7bcmymng2nybpbdzsdljvpo64uo3vyx4kq.arweave.net/2Io9roswswm6X2j-ETMMabTcBeEeZDWmr3e5R264vxU/wasm/wasm.js:2:1169976)  
    at <anonymous> (<anonymous>:0:638559)
    at <anonymous> (<anonymous>:0:791204)
    at <anonymous> (<anonymous>:0:673555)
    at <anonymous> (<anonymous>:0:778894)
    at tree (<anonymous>:0:558349)
    at tree (https://3cfd3lulgczqtos7nd7bcmymng2nybpbdzsdljvpo64uo3vyx4kq.arweave.net/2Io9roswswm6X2j-ETMMabTcBeEeZDWmr3e5R264vxU/wasm/wasm.js:2:1168676)
    at graph.ts:143:3


RuntimeError: unreachable
    at <anonymous> (<anonymous>:0:673584)
    at <anonymous> (<anonymous>:0:778894)
    at tree (<anonymous>:0:558349)
    at tree (https://3cfd3lulgczqtos7nd7bcmymng2nybpbdzsdljvpo64uo3vyx4kq.arweave.net/2Io9roswswm6X2j-ETMMabTcBeEeZDWmr3e5R264vxU/wasm/wasm.js:2:1168676)
    at graph.ts:143:3

I really don't have any rust skills, I'd like to fix this bug, but I can't 😅
I've looked for other AST parsers but yours is really the most suitable.