un-ts / sh-syntax

A WASM shell parser and formatter with bash support, based on `mvdan/sh`
MIT License
15 stars 4 forks source link

Node type #49

Open tdurieux opened 2 years ago

tdurieux commented 2 years ago

Hello,

Thank you for providing the WASM version of mvdan-sh. Is there a way to obtain the node type?

JounQin commented 2 years ago

It requires the upstream project to support that, see also #20

I don't think we have node type info on the AST.

https://pkg.go.dev/mvdan.cc/sh/v3@v3.5.1/syntax#Node

You can post a feature request issue on the upstream project instead.

tdurieux commented 2 years ago

That is really unfortunate, I was hoping there would be a trick where we could include the go structure name inside the output. Thank you for your super fast answer. I am impatient to be able to compare the perf of WASM vs GopherJS.

JounQin commented 2 years ago

I am impatient to be able to compare the perf of WASM vs GopherJS

We do have a benchmark at https://github.com/un-ts/sh-syntax/blob/main/benchmark/benchmark.txt

You can try it on your own machine easily by running node benchmark, see also https://github.com/un-ts/sh-syntax/blob/main/benchmark/index.js.

JounQin commented 2 years ago

That is really unfortunate, I was hoping there would be a trick where we could include the go structure name inside the output.

Maybe you can try to add the type info at

https://github.com/un-ts/sh-syntax/blob/775b7e74ee352bbd89233e97531ef9aa30e8ea19/processor/structs.go#L108-L116

PR welcome.

tdurieux commented 2 years ago

Currently, the type is added in the interface between the JS and GopherJS output and is available in property '$type' and is exploited here: https://github.com/mvdan/sh/blob/f33507475241da6fc37b972d825c351b94300bab/_js/main.go#L39.

I can probably update the mapNode to have the same output as the GopherJS version. I will have a look.