Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 16 additions & 11 deletions src/compiler/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
11 changes: 11 additions & 0 deletions tests/baselines/reference/importAssertion4.errors.txt
Original file line number Diff line number Diff line change
@@ -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.
7 changes: 7 additions & 0 deletions tests/baselines/reference/importAssertion4.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//// [importAssertion4.ts]
import * as f from "./first" assert


//// [importAssertion4.js]
"use strict";
exports.__esModule = true;
4 changes: 4 additions & 0 deletions tests/baselines/reference/importAssertion4.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
=== tests/cases/conformance/importAssertion/importAssertion4.ts ===
import * as f from "./first" assert
>f : Symbol(f, Decl(importAssertion4.ts, 0, 6))

4 changes: 4 additions & 0 deletions tests/baselines/reference/importAssertion4.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
=== tests/cases/conformance/importAssertion/importAssertion4.ts ===
import * as f from "./first" assert
>f : any

12 changes: 12 additions & 0 deletions tests/baselines/reference/importAssertion5.errors.txt
Original file line number Diff line number Diff line change
@@ -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.
7 changes: 7 additions & 0 deletions tests/baselines/reference/importAssertion5.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//// [importAssertion5.ts]
import * as f from "./first" assert {


//// [importAssertion5.js]
"use strict";
exports.__esModule = true;
4 changes: 4 additions & 0 deletions tests/baselines/reference/importAssertion5.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
=== tests/cases/conformance/importAssertion/importAssertion5.ts ===
import * as f from "./first" assert {
>f : Symbol(f, Decl(importAssertion5.ts, 0, 6))

4 changes: 4 additions & 0 deletions tests/baselines/reference/importAssertion5.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
=== tests/cases/conformance/importAssertion/importAssertion5.ts ===
import * as f from "./first" assert {
>f : any

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import * as f from "./first" assert
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import * as f from "./first" assert {