diff --git a/jerry-core/parser/js/js-scanner.c b/jerry-core/parser/js/js-scanner.c index ce085a485..1c9bb192f 100644 --- a/jerry-core/parser/js/js-scanner.c +++ b/jerry-core/parser/js/js-scanner.c @@ -78,8 +78,8 @@ typedef enum SCAN_STACK_FOR_CONDITION, /**< condition part of "for" iterator */ SCAN_STACK_FOR_EXPRESSION, /**< expression part of "for" iterator */ SCAN_STACK_SWITCH_EXPRESSION, /**< expression part of "switch" statement */ - SCAN_STACK_COLON_EXPRESSION, /**< colon expression group */ - SCAN_STACK_CASE_STATEMENT, /**< colon statement group */ + SCAN_STACK_CASE_STATEMENT, /**< case statement inside a switch statement */ + SCAN_STACK_COLON_EXPRESSION, /**< expression between a question mark and colon */ SCAN_STACK_TRY_STATEMENT, /**< try statement */ SCAN_STACK_CATCH_STATEMENT, /**< catch statement */ SCAN_STACK_SQUARE_BRACKETED_EXPRESSION, /**< square bracketed expression group */ @@ -450,36 +450,6 @@ scanner_scan_primary_expression_end (parser_context_t *context_p, /**< context * scanner_context_p->mode = SCAN_MODE_PRIMARY_EXPRESSION; return SCAN_NEXT_TOKEN; } - case LEXER_COLON: - { - if (stack_top == SCAN_STACK_COLON_EXPRESSION) - { - scanner_context_p->mode = SCAN_MODE_PRIMARY_EXPRESSION; - parser_stack_pop_uint8 (context_p); - return SCAN_NEXT_TOKEN; - } - - if (stack_top != SCAN_STACK_CASE_STATEMENT) - { - break; - } - - scanner_source_start_t source_start; - - parser_stack_pop_uint8 (context_p); - parser_stack_pop (context_p, &source_start, sizeof (scanner_source_start_t)); - - scanner_location_info_t *location_info_p; - location_info_p = (scanner_location_info_t *) scanner_insert_info (context_p, - source_start.source_p, - sizeof (scanner_location_info_t)); - location_info_p->info.type = SCANNER_TYPE_CASE; - - scanner_get_location (&location_info_p->location, context_p); - - scanner_context_p->mode = SCAN_MODE_STATEMENT_OR_TERMINATOR; - return SCAN_NEXT_TOKEN; - } default: { break; @@ -700,6 +670,40 @@ scanner_scan_primary_expression_end (parser_context_t *context_p, /**< context * scanner_context_p->mode = SCAN_MODE_STATEMENT_OR_TERMINATOR; return SCAN_KEEP_TOKEN; } + case SCAN_STACK_CASE_STATEMENT: + { + if (type != LEXER_COLON) + { + break; + } + + scanner_source_start_t source_start; + + parser_stack_pop_uint8 (context_p); + parser_stack_pop (context_p, &source_start, sizeof (scanner_source_start_t)); + + scanner_location_info_t *location_info_p; + location_info_p = (scanner_location_info_t *) scanner_insert_info (context_p, + source_start.source_p, + sizeof (scanner_location_info_t)); + location_info_p->info.type = SCANNER_TYPE_CASE; + + scanner_get_location (&location_info_p->location, context_p); + + scanner_context_p->mode = SCAN_MODE_STATEMENT_OR_TERMINATOR; + return SCAN_NEXT_TOKEN; + } + case SCAN_STACK_COLON_EXPRESSION: + { + if (type != LEXER_COLON) + { + break; + } + + scanner_context_p->mode = SCAN_MODE_PRIMARY_EXPRESSION; + parser_stack_pop_uint8 (context_p); + return SCAN_NEXT_TOKEN; + } case SCAN_STACK_SQUARE_BRACKETED_EXPRESSION: { if (type != LEXER_RIGHT_SQUARE) diff --git a/tests/jerry/fail/regresssion-test-issue-3145.js b/tests/jerry/fail/regresssion-test-issue-3145.js new file mode 100644 index 000000000..cfd0d3eae --- /dev/null +++ b/tests/jerry/fail/regresssion-test-issue-3145.js @@ -0,0 +1,15 @@ +// Copyright JS Foundation and other contributors, http://js.foundation +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +[this?$