Error if assignment after block (#41115)

* Error if assignment after block

* Update src/compiler/diagnosticMessages.json

Co-authored-by: Daniel Rosenwasser <DanielRosenwasser@users.noreply.github.com>

* Fix diags

* Error after block

Co-authored-by: Daniel Rosenwasser <DanielRosenwasser@users.noreply.github.com>
Co-authored-by: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com>
This commit is contained in:
Wenlu Wang
2021-04-01 06:57:25 +08:00
committed by GitHub
parent 76a2ae3d69
commit 62f3ccd9c0
9 changed files with 173 additions and 10 deletions

View File

@@ -2109,8 +2109,7 @@ namespace ts {
while (!isListTerminator(kind)) {
if (isListElement(kind, /*inErrorRecovery*/ false)) {
const element = parseListElement(kind, parseElement);
list.push(element);
list.push(parseListElement(kind, parseElement));
continue;
}
@@ -5602,7 +5601,13 @@ namespace ts {
const multiLine = scanner.hasPrecedingLineBreak();
const statements = parseList(ParsingContext.BlockStatements, parseStatement);
parseExpectedMatchingBrackets(SyntaxKind.OpenBraceToken, SyntaxKind.CloseBraceToken, openBracePosition);
return finishNode(factory.createBlock(statements, multiLine), pos);
const result = finishNode(factory.createBlock(statements, multiLine), pos);
if (token() === SyntaxKind.EqualsToken) {
parseErrorAtCurrentToken(Diagnostics.Declaration_or_statement_expected_This_follows_a_block_of_statements_so_if_you_intended_to_write_a_destructuring_assignment_you_might_need_to_wrap_the_the_whole_assignment_in_parentheses);
nextToken();
}
return result;
}
else {
const statements = createMissingList<Statement>();