From e1d35966438b7729f1f671a423695cceef0af0c8 Mon Sep 17 00:00:00 2001 From: Lukas Werling Date: Sat, 30 May 2015 22:17:58 +0200 Subject: [PATCH] Allow trailing comma in map literal --- src/vm/wren_compiler.c | 3 +++ test/language/map/trailing_comma.wren | 7 +++++++ 2 files changed, 10 insertions(+) create mode 100644 test/language/map/trailing_comma.wren diff --git a/src/vm/wren_compiler.c b/src/vm/wren_compiler.c index 48cc5659..390c7250 100644 --- a/src/vm/wren_compiler.c +++ b/src/vm/wren_compiler.c @@ -1853,6 +1853,9 @@ static void map(Compiler* compiler, bool allowAssignment) { ignoreNewlines(compiler); + // Map with trailing comma. + if (peek(compiler) == TOKEN_RIGHT_BRACE) break; + // Push a copy of the map since the subscript call will consume it. emit(compiler, CODE_DUP); diff --git a/test/language/map/trailing_comma.wren b/test/language/map/trailing_comma.wren new file mode 100644 index 00000000..7dd0a69f --- /dev/null +++ b/test/language/map/trailing_comma.wren @@ -0,0 +1,7 @@ +var map = { + "a": 1, + "b": 2, +} + +IO.print(map["a"]) // expect: 1 +IO.print(map["b"]) // expect: 2