Skip to content
This repository has been archived by the owner on Dec 23, 2022. It is now read-only.

parse methods are returning an array #1

Open
markmelville opened this issue Jun 17, 2021 · 1 comment · May be fixed by #2
Open

parse methods are returning an array #1

markmelville opened this issue Jun 17, 2021 · 1 comment · May be fixed by #2

Comments

@markmelville
Copy link

I saw your comment that you don't know why the result is an array. I think it's because the GO method has a dual return type: (output *js.Object, err error)
I'm very new to GO and gopherjs (in fact I found your repo after spending loo long spinning my wheels on trying to do this exact thing: build a HCL2 parser for node.js), but from what I have seen the convention in GO is that errors are not thrown but signaled using this dual-return type pattern. I suspect that if you changed the signature to:

func parseToObject(input string) (output *js.Object)

then the result via JS would not be enclosed in an array. I would hope that there is a way to make the JS version throw the error using the gopherjs lib. If I get some more time, I may try some things out and make a PR, but for now I just wanted to mention this.

But, thanks for making this repo. I was about to give up hope.

@fearphage
Copy link

I'm having the same issue. I'm writing a loader to allow you to require() HCL files. My initial implementation used the parseToString method, but due to the returned array I had to use JSON.stringify(parseToObject(hcl)[0]) instead.

@fearphage fearphage linked a pull request Aug 15, 2021 that will close this issue
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants