Skip to content

Commit

Permalink
_js: expose syntax.SplitBraces
Browse files Browse the repository at this point in the history
  • Loading branch information
mvdan committed Feb 19, 2019
1 parent 03ce6be commit 49c0084
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion _js/build
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh

if ! go version | grep go1.11; then
if ! go version | grep -q go1.11; then
echo "Go 1.11.x required to build."
exit 1
fi
Expand Down
4 changes: 4 additions & 0 deletions _js/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ func main() {
stx.Set("DebugPrint", func(node syntax.Node) {
syntax.DebugPrint(os.Stdout, node)
})
stx.Set("SplitBraces", func(w *syntax.Word) *js.Object {
w = syntax.SplitBraces(w)
return js.MakeFullWrapper(w)
})
}

func throw(v interface{}) {
Expand Down
19 changes: 19 additions & 0 deletions _js/testmain.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,3 +167,22 @@ const printer = syntax.NewPrinter()
})
assert.deepEqual(gotCallbacks, wantCallbacks)
}

{
// splitting brace expressions
const parser = syntax.NewParser()
const src = "{foo,bar}"
var f = parser.Parse(src, "src")

var word = f.StmtList.Stmts[0].Cmd.Args[0]
assert.equal(word.Parts.length, 1)
assert.equal(syntax.NodeType(word.Parts[0]), "Lit")

word = syntax.SplitBraces(word)
// TODO: get rid of the empty lit
assert.equal(word.Parts.length, 2)
assert.equal(syntax.NodeType(word.Parts[0]), "BraceExp")
assert.equal(word.Parts[0].Elems.length, 2)
assert.equal(syntax.NodeType(word.Parts[1]), "Lit")
assert.equal(word.Parts[1].Value, "")
}

0 comments on commit 49c0084

Please sign in to comment.