diff --git a/src/parser.js b/src/parser.js index 9cffaf3d..62bf05fa 100644 --- a/src/parser.js +++ b/src/parser.js @@ -759,9 +759,17 @@ const parser = (() => { if (node.id !== "}") { for (; ;) { var n = expression(0); - advance(":"); - var v = expression(0); - a.push([n, v]); // holds an array of name/value expression pairs + if((node.id === ',' || node.id === '}') && n.id === '(name)') { + const key = Object.create(symbol_table["(literal)"]); + key.value = n.value; + key.type = 'string'; + key.position = n.position; + a.push([key, n]); // shorthand property syntax + } else { + advance(":"); + var v = expression(0); + a.push([n, v]); // holds an array of name/value expression pairs + } if (node.id !== ",") { break; } diff --git a/test/test-suite/groups/shorthand-property-notation/case000.json b/test/test-suite/groups/shorthand-property-notation/case000.json new file mode 100644 index 00000000..271ec660 --- /dev/null +++ b/test/test-suite/groups/shorthand-property-notation/case000.json @@ -0,0 +1,9 @@ +{ + "expr": "{bar, \"foo\": foo.bar}", + "dataset": "dataset0", + "bindings": {}, + "result": { + "bar": 98, + "foo": 42 + } +} \ No newline at end of file diff --git a/test/test-suite/groups/shorthand-property-notation/case001.json b/test/test-suite/groups/shorthand-property-notation/case001.json new file mode 100644 index 00000000..73889440 --- /dev/null +++ b/test/test-suite/groups/shorthand-property-notation/case001.json @@ -0,0 +1,9 @@ +{ + "expr": "{\"foo\": foo.bar, bar}", + "dataset": "dataset0", + "bindings": {}, + "result": { + "bar": 98, + "foo": 42 + } +} \ No newline at end of file diff --git a/test/test-suite/groups/shorthand-property-notation/case002.json b/test/test-suite/groups/shorthand-property-notation/case002.json new file mode 100644 index 00000000..01b63f2a --- /dev/null +++ b/test/test-suite/groups/shorthand-property-notation/case002.json @@ -0,0 +1,8 @@ +{ + "expr": "($foobar:= 256; {$foobar})", + "dataset": "dataset0", + "bindings": {}, + "result": { + "foobar": 256 + } +} \ No newline at end of file diff --git a/test/test-suite/groups/shorthand-property-notation/case003.json b/test/test-suite/groups/shorthand-property-notation/case003.json new file mode 100644 index 00000000..51e36e16 --- /dev/null +++ b/test/test-suite/groups/shorthand-property-notation/case003.json @@ -0,0 +1,9 @@ +{ + "expr": "($bar:= 256; {\"foo\": foo.bar, $bar})", + "dataset": "dataset0", + "bindings": {}, + "result": { + "foo": 42, + "bar": 256 + } +} \ No newline at end of file diff --git a/test/test-suite/groups/shorthand-property-notation/case004.json b/test/test-suite/groups/shorthand-property-notation/case004.json new file mode 100644 index 00000000..b3fedba4 --- /dev/null +++ b/test/test-suite/groups/shorthand-property-notation/case004.json @@ -0,0 +1,6 @@ +{ + "expr": "($foo:= 256; {\"foo\": foo.bar, $foo})", + "dataset": "dataset0", + "bindings": {}, + "code": "D1009" +} \ No newline at end of file diff --git a/test/test-suite/groups/shorthand-property-notation/case005.json b/test/test-suite/groups/shorthand-property-notation/case005.json new file mode 100644 index 00000000..3b18fb67 --- /dev/null +++ b/test/test-suite/groups/shorthand-property-notation/case005.json @@ -0,0 +1,6 @@ +{ + "expr": "{foo.bar}", + "dataset": "dataset0", + "bindings": {}, + "code": "S0202" +} \ No newline at end of file