Open rob-myers opened 2 years ago
I wonder if this is a GopherJS bug, because we don't really control what JS code gets produced when transpiling.
Also, if WASM is an option, perhaps try https://github.com/rx-ts/sh-syntax. It does not use GopherJS, so it potentially sidesteps this bug. cc @JounQin
It seems the reproduction is using parser.Interactive
inside, which is not available in sh-syntax
yet.
This is because CodeSandbox
is polyfillng globalThis.process
unexpectedly, I think you should raise an issue for CodeSandbox
instead.
Workaround: delete window.process
before import 'mvdan-sh'
See https://codesandbox.io/s/tty-demo-1-forked-d6xg0p?file=/src/sh/parse/parse.service.ts
Also, there is also a fix in gopherjs https://github.com/gopherjs/gopherjs/pull/1117 which has not been released.
@JounQin thanks for looking into it. Great that there's a GopherJS fix in the works already.
I will try building using go get github.com/gopherjs/gopherjs@master
and see if it works.
Generally speaking, it would be nice to have a bunch of CodeSandbox links demoing mvdan-sh
on the web.
The example I provided is too complex, I'm thinking e.g. enter shell code and display AST etc.
Do such web-based examples exist anywhere at present?
I want to use version 0.5.0
, so I am using an old commit and go v1.2.17. Sadly, changing the build to go get github.com/gopherjs/gopherjs@master
yields the following error:
package github.com/gopherjs/gopherjs@master: can only use path@version syntax with 'go get'
I guess I'll just wait for a fix.
I have a demo using
mvdan-sh@0.5.0
working on CodeSandbox.But I had to comment out two similar lines:
Otherwise, I see
runtime error: makeslice: len out of range
. It is reproducible by switching the imports back in CodeSandbox link:The error occurs simply by importing the module, and also occurs for
mvdan-sh@0.10.1
.