From 88ead2f704f1b60103903b836530cc21a3bf0d2a Mon Sep 17 00:00:00 2001
From: Jake Bailey <5341706+jakebailey@users.noreply.github.com>
Date: Tue, 1 Mar 2022 01:26:27 +0000
Subject: [PATCH] Cherry-pick PR #48067 into release-4.6
Component commits:
8d6b96500a Add failing test
64cfd700a7 Fix incorrect parser error assumption in semicolon handling leading to incremental parser brokenness
---
src/compiler/parser.ts | 13 +------------
.../reference/parser0_004152.errors.txt | 4 ++--
.../parserCorruptionAfterMapInClass.ts | 17 +++++++++++++++++
3 files changed, 20 insertions(+), 14 deletions(-)
create mode 100644 tests/cases/fourslash/parserCorruptionAfterMapInClass.ts
diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts
index c796e78d45190..0dea81baae43b 100644
--- a/src/compiler/parser.ts
+++ b/src/compiler/parser.ts
@@ -1680,19 +1680,8 @@ namespace ts {
return;
}
- // If an initializer was parsed but there is still an error in finding the next semicolon,
- // we generally know there was an error already reported in the initializer...
- // class Example { a = new Map([), ) }
- // ~
if (initializer) {
- // ...unless we've found the start of a block after a property declaration, in which
- // case we can know that regardless of the initializer we should complain on the block.
- // class Example { a = 0 {} }
- // ~
- if (token() === SyntaxKind.OpenBraceToken) {
- parseErrorAtCurrentToken(Diagnostics._0_expected, tokenToString(SyntaxKind.SemicolonToken));
- }
-
+ parseErrorAtCurrentToken(Diagnostics._0_expected, tokenToString(SyntaxKind.SemicolonToken));
return;
}
diff --git a/tests/baselines/reference/parser0_004152.errors.txt b/tests/baselines/reference/parser0_004152.errors.txt
index a1790a5f7305c..e0fc3f48e0843 100644
--- a/tests/baselines/reference/parser0_004152.errors.txt
+++ b/tests/baselines/reference/parser0_004152.errors.txt
@@ -1,6 +1,6 @@
tests/cases/conformance/parser/ecmascript5/Fuzz/parser0_004152.ts(2,28): error TS2304: Cannot find name 'DisplayPosition'.
tests/cases/conformance/parser/ecmascript5/Fuzz/parser0_004152.ts(2,45): error TS1137: Expression or comma expected.
-tests/cases/conformance/parser/ecmascript5/Fuzz/parser0_004152.ts(2,46): error TS1068: Unexpected token. A constructor, method, accessor, or property was expected.
+tests/cases/conformance/parser/ecmascript5/Fuzz/parser0_004152.ts(2,46): error TS1005: ';' expected.
tests/cases/conformance/parser/ecmascript5/Fuzz/parser0_004152.ts(2,49): error TS1005: ';' expected.
tests/cases/conformance/parser/ecmascript5/Fuzz/parser0_004152.ts(2,51): error TS2300: Duplicate identifier '3'.
tests/cases/conformance/parser/ecmascript5/Fuzz/parser0_004152.ts(2,52): error TS1005: ';' expected.
@@ -41,7 +41,7 @@ tests/cases/conformance/parser/ecmascript5/Fuzz/parser0_004152.ts(3,25): error T
~
!!! error TS1137: Expression or comma expected.
~
-!!! error TS1068: Unexpected token. A constructor, method, accessor, or property was expected.
+!!! error TS1005: ';' expected.
~
!!! error TS1005: ';' expected.
~
diff --git a/tests/cases/fourslash/parserCorruptionAfterMapInClass.ts b/tests/cases/fourslash/parserCorruptionAfterMapInClass.ts
new file mode 100644
index 0000000000000..65bc6c5b1ad70
--- /dev/null
+++ b/tests/cases/fourslash/parserCorruptionAfterMapInClass.ts
@@ -0,0 +1,17 @@
+///
+
+// @target: esnext
+// @lib: es2015
+// @strict: true
+
+//// class C {
+//// map = new Set/*$*/
+////
+//// foo() {
+////
+//// }
+//// }
+
+goTo.marker('$');
+edit.insert('()');
+verify.getSyntacticDiagnostics([]);