Skip to content

Commit 05b4bda

Browse files
rerobikadbatyai
authored andcommitted
Colon must be expected after computed property name in object destructuring (#3529)
This patch fixes #3527. JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
1 parent 24af089 commit 05b4bda

2 files changed

Lines changed: 42 additions & 4 deletions

File tree

jerry-core/parser/js/js-parser-expr.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2831,10 +2831,14 @@ parser_parse_object_initializer (parser_context_t *context_p, /**< context */
28312831
}
28322832
else
28332833
{
2834-
if (push_prop_opcode != CBC_EXT_INITIALIZER_PUSH_PROP
2835-
&& (context_p->token.type == LEXER_RIGHT_BRACE
2836-
|| context_p->token.type == LEXER_ASSIGN
2837-
|| context_p->token.type == LEXER_COMMA))
2834+
if (push_prop_opcode == CBC_EXT_INITIALIZER_PUSH_PROP)
2835+
{
2836+
parser_raise_error (context_p, PARSER_ERR_COLON_EXPECTED);
2837+
}
2838+
2839+
if (context_p->token.type == LEXER_RIGHT_BRACE
2840+
|| context_p->token.type == LEXER_ASSIGN
2841+
|| context_p->token.type == LEXER_COMMA)
28382842
{
28392843
parser_reparse_as_common_identifier (context_p, start_line, start_column);
28402844
lexer_next_token (context_p);
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Copyright JS Foundation and other contributors, http://js.foundation
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
function assertThrows(src) {
16+
try {
17+
eval(src);
18+
assert(false);
19+
} catch (e) {
20+
assert(e instanceof SyntaxError);
21+
}
22+
}
23+
24+
assertThrows(`function $({
25+
$: {
26+
[$.$]
27+
}
28+
}) {}`);
29+
30+
assertThrows(`function $({
31+
$: {
32+
[$]
33+
}
34+
}) {}`);

0 commit comments

Comments
 (0)