Skip to content

Commit 0cfe82d

Browse files
SyntaxError on statement without body (#6854)
According to the Rules of Automatic Semicolon Insertion: "a semicolon is never inserted automatically if the semicolon would then be parsed as an empty statement" Fix #6351 Fix #6553 (Closed as duplicate) Fix #5128
1 parent 9bf5a93 commit 0cfe82d

File tree

3 files changed

+313
-289
lines changed

3 files changed

+313
-289
lines changed

lib/Parser/Parse.cpp

+3-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//-------------------------------------------------------------------------------------------------------
22
// Copyright (C) Microsoft. All rights reserved.
3-
// Copyright (c) 2021 ChakraCore Project Contributors. All rights reserved.
3+
// Copyright (c) ChakraCore Project Contributors. All rights reserved.
44
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
55
//-------------------------------------------------------------------------------------------------------
66
#include "ParserPch.h"
@@ -10170,13 +10170,9 @@ ParseNodePtr Parser::ParseStatement()
1017010170
{
1017110171
case tkEOF:
1017210172
if (labelledStatement)
10173-
{
1017410173
Error(ERRLabelFollowedByEOF);
10175-
}
10176-
if (buildAST)
10177-
{
10178-
pnode = nullptr;
10179-
}
10174+
else
10175+
Error(ERRsyntaxEOF);
1018010176
break;
1018110177

1018210178
case tkFUNCTION:

lib/Parser/perrors.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//-------------------------------------------------------------------------------------------------------
22
// Copyright (C) Microsoft. All rights reserved.
3+
// Copyright (c) ChakraCore Project Contributors. All rights reserved.
34
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
45
//-------------------------------------------------------------------------------------------------------
56
// parser error messages
@@ -8,6 +9,7 @@
89

910
LSC_ERROR_MSG(1001, ERRnoMemory , "Out of memory")
1011
LSC_ERROR_MSG(1002, ERRsyntax , "Syntax error")
12+
LSC_ERROR_MSG(1104, ERRsyntaxEOF , "Unexpected end of script.")
1113
LSC_ERROR_MSG(1003, ERRnoColon , "Expected ':'")
1214
LSC_ERROR_MSG(1004, ERRnoSemic , "Expected ';'")
1315
LSC_ERROR_MSG(1005, ERRnoLparen , "Expected '('")
@@ -116,7 +118,9 @@ LSC_ERROR_MSG(1100, ERRUndeclaredExportName, "Export of name '%s' which has no l
116118
LSC_ERROR_MSG(1101, ERRModuleImportOrExportInScript, "'import' or 'export' can only be used in module code.")
117119
LSC_ERROR_MSG(1102, ERRInvalidAsgTarget, "Invalid left-hand side in assignment.")
118120
LSC_ERROR_MSG(1103, ERRMissingFrom, "Expected 'from' after import or export clause.")
119-
//1104-1199 available for future use
121+
122+
// 1104 ERRsyntaxEOF
123+
// 1105-1199 available for future use
120124

121125
// Generic errors intended to be re-usable
122126
LSC_ERROR_MSG(1200, ERRKeywordAfter, "Unexpected keyword '%s' after '%s'")

0 commit comments

Comments
 (0)