diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 6d94ef225b14c..59eaaa2efbbfc 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -7277,19 +7277,24 @@ namespace ts { const pos = getNodePos(); parseExpected(SyntaxKind.AssertKeyword); const openBracePosition = scanner.getTokenPos(); - parseExpected(SyntaxKind.OpenBraceToken); - const multiLine = scanner.hasPrecedingLineBreak(); - const elements = parseDelimitedList(ParsingContext.AssertEntries, parseAssertEntry, /*considerSemicolonAsDelimiter*/ true); - if (!parseExpected(SyntaxKind.CloseBraceToken)) { - const lastError = lastOrUndefined(parseDiagnostics); - if (lastError && lastError.code === Diagnostics._0_expected.code) { - addRelatedInfo( - lastError, - createDetachedDiagnostic(fileName, openBracePosition, 1, Diagnostics.The_parser_expected_to_find_a_to_match_the_token_here) - ); + if (parseExpected(SyntaxKind.OpenBraceToken)) { + const multiLine = scanner.hasPrecedingLineBreak(); + const elements = parseDelimitedList(ParsingContext.AssertEntries, parseAssertEntry, /*considerSemicolonAsDelimiter*/ true); + if (!parseExpected(SyntaxKind.CloseBraceToken)) { + const lastError = lastOrUndefined(parseDiagnostics); + if (lastError && lastError.code === Diagnostics._0_expected.code) { + addRelatedInfo( + lastError, + createDetachedDiagnostic(fileName, openBracePosition, 1, Diagnostics.The_parser_expected_to_find_a_to_match_the_token_here) + ); + } } + return finishNode(factory.createAssertClause(elements, multiLine), pos); + } + else { + const elements = createNodeArray([], getNodePos(), /*end*/ undefined, /*hasTrailingComma*/ false); + return finishNode(factory.createAssertClause(elements, /*multiLine*/ false), pos); } - return finishNode(factory.createAssertClause(elements, multiLine), pos); } function tokenAfterImportDefinitelyProducesImportDeclaration() { diff --git a/tests/baselines/reference/importAssertion4.errors.txt b/tests/baselines/reference/importAssertion4.errors.txt new file mode 100644 index 0000000000000..fb1810d26fcc7 --- /dev/null +++ b/tests/baselines/reference/importAssertion4.errors.txt @@ -0,0 +1,11 @@ +tests/cases/conformance/importAssertion/importAssertion4.ts(1,20): error TS2307: Cannot find module './first' or its corresponding type declarations. +tests/cases/conformance/importAssertion/importAssertion4.ts(2,1): error TS1005: '{' expected. + + +==== tests/cases/conformance/importAssertion/importAssertion4.ts (2 errors) ==== + import * as f from "./first" assert + ~~~~~~~~~ +!!! error TS2307: Cannot find module './first' or its corresponding type declarations. + + +!!! error TS1005: '{' expected. \ No newline at end of file diff --git a/tests/baselines/reference/importAssertion4.js b/tests/baselines/reference/importAssertion4.js new file mode 100644 index 0000000000000..24bd2f287e078 --- /dev/null +++ b/tests/baselines/reference/importAssertion4.js @@ -0,0 +1,7 @@ +//// [importAssertion4.ts] +import * as f from "./first" assert + + +//// [importAssertion4.js] +"use strict"; +exports.__esModule = true; diff --git a/tests/baselines/reference/importAssertion4.symbols b/tests/baselines/reference/importAssertion4.symbols new file mode 100644 index 0000000000000..d904f15902198 --- /dev/null +++ b/tests/baselines/reference/importAssertion4.symbols @@ -0,0 +1,4 @@ +=== tests/cases/conformance/importAssertion/importAssertion4.ts === +import * as f from "./first" assert +>f : Symbol(f, Decl(importAssertion4.ts, 0, 6)) + diff --git a/tests/baselines/reference/importAssertion4.types b/tests/baselines/reference/importAssertion4.types new file mode 100644 index 0000000000000..6c828613032fe --- /dev/null +++ b/tests/baselines/reference/importAssertion4.types @@ -0,0 +1,4 @@ +=== tests/cases/conformance/importAssertion/importAssertion4.ts === +import * as f from "./first" assert +>f : any + diff --git a/tests/baselines/reference/importAssertion5.errors.txt b/tests/baselines/reference/importAssertion5.errors.txt new file mode 100644 index 0000000000000..ccc17ec0cad1a --- /dev/null +++ b/tests/baselines/reference/importAssertion5.errors.txt @@ -0,0 +1,12 @@ +tests/cases/conformance/importAssertion/importAssertion5.ts(1,20): error TS2307: Cannot find module './first' or its corresponding type declarations. +tests/cases/conformance/importAssertion/importAssertion5.ts(2,1): error TS1005: '}' expected. + + +==== tests/cases/conformance/importAssertion/importAssertion5.ts (2 errors) ==== + import * as f from "./first" assert { + ~~~~~~~~~ +!!! error TS2307: Cannot find module './first' or its corresponding type declarations. + + +!!! error TS1005: '}' expected. +!!! related TS1007 tests/cases/conformance/importAssertion/importAssertion5.ts:1:37: The parser expected to find a '}' to match the '{' token here. \ No newline at end of file diff --git a/tests/baselines/reference/importAssertion5.js b/tests/baselines/reference/importAssertion5.js new file mode 100644 index 0000000000000..5237c5f2805cc --- /dev/null +++ b/tests/baselines/reference/importAssertion5.js @@ -0,0 +1,7 @@ +//// [importAssertion5.ts] +import * as f from "./first" assert { + + +//// [importAssertion5.js] +"use strict"; +exports.__esModule = true; diff --git a/tests/baselines/reference/importAssertion5.symbols b/tests/baselines/reference/importAssertion5.symbols new file mode 100644 index 0000000000000..2f3b7f00ad3ce --- /dev/null +++ b/tests/baselines/reference/importAssertion5.symbols @@ -0,0 +1,4 @@ +=== tests/cases/conformance/importAssertion/importAssertion5.ts === +import * as f from "./first" assert { +>f : Symbol(f, Decl(importAssertion5.ts, 0, 6)) + diff --git a/tests/baselines/reference/importAssertion5.types b/tests/baselines/reference/importAssertion5.types new file mode 100644 index 0000000000000..55c946ea4cc43 --- /dev/null +++ b/tests/baselines/reference/importAssertion5.types @@ -0,0 +1,4 @@ +=== tests/cases/conformance/importAssertion/importAssertion5.ts === +import * as f from "./first" assert { +>f : any + diff --git a/tests/cases/conformance/importAssertion/importAssertion4.ts b/tests/cases/conformance/importAssertion/importAssertion4.ts new file mode 100644 index 0000000000000..242d7dd375a58 --- /dev/null +++ b/tests/cases/conformance/importAssertion/importAssertion4.ts @@ -0,0 +1 @@ +import * as f from "./first" assert diff --git a/tests/cases/conformance/importAssertion/importAssertion5.ts b/tests/cases/conformance/importAssertion/importAssertion5.ts new file mode 100644 index 0000000000000..ef09d84e66ccb --- /dev/null +++ b/tests/cases/conformance/importAssertion/importAssertion5.ts @@ -0,0 +1 @@ +import * as f from "./first" assert {