summaryrefslogtreecommitdiff
path: root/Libraries
diff options
context:
space:
mode:
authorStephan Unverwerth <s.unverwerth@gmx.de>2020-04-18 14:00:43 +0200
committerAndreas Kling <kling@serenityos.org>2020-04-18 14:04:24 +0200
commitcebb619f8e684e6ce844f83299c4abac57ab7fa3 (patch)
tree5038d4086b2a38fd67b43f50d38cd05614edde11 /Libraries
parent3072f9fd82c17049a5b54336cefc659724f5d661 (diff)
downloadserenity-cebb619f8e684e6ce844f83299c4abac57ab7fa3.zip
LibJS: Fix parsing of IfStatement, fixes #1829
Diffstat (limited to 'Libraries')
-rw-r--r--Libraries/LibJS/Parser.cpp5
-rw-r--r--Libraries/LibJS/Tests/automatic-semicolon-insertion.js19
2 files changed, 23 insertions, 1 deletions
diff --git a/Libraries/LibJS/Parser.cpp b/Libraries/LibJS/Parser.cpp
index 41f9c137dd..aafd977e63 100644
--- a/Libraries/LibJS/Parser.cpp
+++ b/Libraries/LibJS/Parser.cpp
@@ -664,8 +664,11 @@ NonnullRefPtr<ReturnStatement> Parser::parse_return_statement()
return create_ast_node<ReturnStatement>(nullptr);
if (match_expression()) {
- return create_ast_node<ReturnStatement>(parse_expression(0));
+ auto expression = parse_expression(0);
+ consume_or_insert_semicolon();
+ return create_ast_node<ReturnStatement>(move(expression));
}
+
consume_or_insert_semicolon();
return create_ast_node<ReturnStatement>(nullptr);
}
diff --git a/Libraries/LibJS/Tests/automatic-semicolon-insertion.js b/Libraries/LibJS/Tests/automatic-semicolon-insertion.js
index bec9c02252..0673e2bf69 100644
--- a/Libraries/LibJS/Tests/automatic-semicolon-insertion.js
+++ b/Libraries/LibJS/Tests/automatic-semicolon-insertion.js
@@ -5,6 +5,25 @@ load("test-common.js");
* If this file produces syntax errors, something is wrong.
*/
+function bar() {
+ // https://github.com/SerenityOS/serenity/issues/1829
+ if (1)
+ return 1;
+ else
+ return 0;
+
+ if (1)
+ return 1
+ else
+ return 0
+
+ if (1)
+ return 1
+ else
+ return 0;
+
+}
+
function foo() {
for (var i = 0; i < 4; i++) {
break // semicolon inserted here