From 49c0084a1f197f994858468a98449e10e7c331a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Tue, 19 Feb 2019 18:56:22 +0000 Subject: [PATCH] _js: expose syntax.SplitBraces --- _js/build | 2 +- _js/main.go | 4 ++++ _js/testmain.js | 19 +++++++++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/_js/build b/_js/build index 05beec628..ba82a5e33 100755 --- a/_js/build +++ b/_js/build @@ -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 diff --git a/_js/main.go b/_js/main.go index c86233333..c60e27b05 100644 --- a/_js/main.go +++ b/_js/main.go @@ -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{}) { diff --git a/_js/testmain.js b/_js/testmain.js index 128b8417a..62be18618 100644 --- a/_js/testmain.js +++ b/_js/testmain.js @@ -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, "") +}