Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Node type #49

Open
tdurieux opened this issue Jul 10, 2022 · 5 comments
Open

Node type #49

tdurieux opened this issue Jul 10, 2022 · 5 comments
Labels
enhancement New feature or request feature good first issue Good for newcomers PR welcome

Comments

@tdurieux
Copy link

Hello,

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

@JounQin
Copy link
Member

JounQin commented Jul 10, 2022

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/[email protected]/syntax#Node

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

@JounQin JounQin closed this as not planned Won't fix, can't repro, duplicate, stale Jul 10, 2022
@tdurieux
Copy link
Author

tdurieux commented Jul 10, 2022

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
Copy link
Member

JounQin commented Jul 10, 2022

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
Copy link
Member

JounQin commented Jul 10, 2022

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

func mapNode(node syntax.Node) *Node {
if node == nil {
return nil
}
return &Node{
Pos: mapPos(node.Pos()),
End: mapPos(node.End()),
}
}

PR welcome.

@JounQin JounQin reopened this Jul 10, 2022
@JounQin JounQin added enhancement New feature or request good first issue Good for newcomers feature PR welcome labels Jul 10, 2022
@tdurieux
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request feature good first issue Good for newcomers PR welcome
Projects
None yet
Development

No branches or pull requests

2 participants