@@ -394,7 +394,8 @@ namespace ts {
394
394
return visitNodes ( cbNode , cbNodes , node . decorators ) ||
395
395
visitNodes ( cbNode , cbNodes , node . modifiers ) ||
396
396
visitNode ( cbNode , ( < ImportDeclaration > node ) . importClause ) ||
397
- visitNode ( cbNode , ( < ImportDeclaration > node ) . moduleSpecifier ) ;
397
+ visitNode ( cbNode , ( < ImportDeclaration > node ) . moduleSpecifier ) ||
398
+ visitNode ( cbNode , ( < ImportDeclaration > node ) . assertClause ) ;
398
399
case SyntaxKind . ImportClause :
399
400
return visitNode ( cbNode , ( < ImportClause > node ) . name ) ||
400
401
visitNode ( cbNode , ( < ImportClause > node ) . namedBindings ) ;
@@ -417,7 +418,8 @@ namespace ts {
417
418
return visitNodes ( cbNode , cbNodes , node . decorators ) ||
418
419
visitNodes ( cbNode , cbNodes , node . modifiers ) ||
419
420
visitNode ( cbNode , ( < ExportDeclaration > node ) . exportClause ) ||
420
- visitNode ( cbNode , ( < ExportDeclaration > node ) . moduleSpecifier ) ;
421
+ visitNode ( cbNode , ( < ExportDeclaration > node ) . moduleSpecifier ) ||
422
+ visitNode ( cbNode , ( < ExportDeclaration > node ) . assertClause ) ;
421
423
case SyntaxKind . ImportSpecifier :
422
424
case SyntaxKind . ExportSpecifier :
423
425
return visitNode ( cbNode , ( < ImportOrExportSpecifier > node ) . propertyName ) ||
@@ -1698,7 +1700,7 @@ namespace ts {
1698
1700
function isAssertionKey ( ) : boolean {
1699
1701
return tokenIsIdentifierOrKeyword ( token ( ) ) ||
1700
1702
token ( ) === SyntaxKind . StringLiteral ;
1701
- }
1703
+ }
1702
1704
1703
1705
function parsePropertyNameWorker ( allowComputedPropertyNames : boolean ) : PropertyName {
1704
1706
if ( token ( ) === SyntaxKind . StringLiteral || token ( ) === SyntaxKind . NumericLiteral ) {
@@ -1865,7 +1867,7 @@ namespace ts {
1865
1867
case ParsingContext . ObjectBindingElements :
1866
1868
return token ( ) === SyntaxKind . OpenBracketToken || token ( ) === SyntaxKind . DotDotDotToken || isLiteralPropertyName ( ) ;
1867
1869
case ParsingContext . AssertEntries :
1868
- return isAssertionKey ( )
1870
+ return isAssertionKey ( ) ;
1869
1871
case ParsingContext . HeritageClauseElement :
1870
1872
// If we see `{ ... }` then only consume it as an expression if it is followed by `,` or `{`
1871
1873
// That way we won't consume the body of a class in its heritage clause.
@@ -6915,30 +6917,42 @@ namespace ts {
6915
6917
parseExpected ( SyntaxKind . FromKeyword ) ;
6916
6918
}
6917
6919
const moduleSpecifier = parseModuleSpecifier ( ) ;
6918
- const afterSpecifierPos = scanner . getStartPos ( ) ;
6919
6920
6920
6921
let assertClause : AssertClause | undefined ;
6921
6922
if ( token ( ) === SyntaxKind . AssertKeyword && ! scanner . hasPrecedingLineBreak ( ) ) {
6922
- assertClause = parseAssertClause ( afterSpecifierPos ) ;
6923
+ assertClause = parseAssertClause ( ) ;
6923
6924
}
6924
6925
6925
6926
parseSemicolon ( ) ;
6926
6927
const node = factory . createImportDeclaration ( decorators , modifiers , importClause , moduleSpecifier , assertClause ) ;
6927
6928
return withJSDoc ( finishNode ( node , pos ) , hasJSDoc ) ;
6928
6929
}
6929
6930
6930
- function parseAssertEntry ( ) {
6931
+ function parseAssertEntry ( ) {
6931
6932
const pos = getNodePos ( ) ;
6932
6933
const name = tokenIsIdentifierOrKeyword ( token ( ) ) ? parseIdentifierName ( ) : parseLiteralLikeNode ( SyntaxKind . StringLiteral ) as StringLiteral ;
6933
- parseExpected ( SyntaxKind . ColonToken )
6934
+ parseExpected ( SyntaxKind . ColonToken ) ;
6934
6935
const value = parseLiteralLikeNode ( SyntaxKind . StringLiteral ) as StringLiteral ;
6935
6936
return finishNode ( factory . createAssertEntry ( name , value ) , pos ) ;
6936
6937
}
6937
6938
6938
- function parseAssertClause ( pos : number ) {
6939
- parseExpected ( SyntaxKind . AssertKeyword )
6940
- const elements = parseList ( ParsingContext . AssertEntries , parseAssertEntry )
6941
- return finishNode ( factory . createAssertClause ( elements ) , pos ) ;
6939
+ function parseAssertClause ( ) {
6940
+ const pos = getNodePos ( ) ;
6941
+ parseExpected ( SyntaxKind . AssertKeyword ) ;
6942
+ const openBracePosition = scanner . getTokenPos ( ) ;
6943
+ parseExpected ( SyntaxKind . OpenBraceToken ) ;
6944
+ const multiLine = scanner . hasPrecedingLineBreak ( ) ;
6945
+ const elements = parseDelimitedList ( ParsingContext . AssertEntries , parseAssertEntry , /*considerSemicolonAsDelimiter*/ true ) ;
6946
+ if ( ! parseExpected ( SyntaxKind . CloseBraceToken ) ) {
6947
+ const lastError = lastOrUndefined ( parseDiagnostics ) ;
6948
+ if ( lastError && lastError . code === Diagnostics . _0_expected . code ) {
6949
+ addRelatedInfo (
6950
+ lastError ,
6951
+ createDetachedDiagnostic ( fileName , openBracePosition , 1 , Diagnostics . The_parser_expected_to_find_a_to_match_the_token_here )
6952
+ ) ;
6953
+ }
6954
+ }
6955
+ return finishNode ( factory . createAssertClause ( elements , multiLine ) , pos ) ;
6942
6956
}
6943
6957
6944
6958
function tokenAfterImportDefinitelyProducesImportDeclaration ( ) {
@@ -7111,9 +7125,8 @@ namespace ts {
7111
7125
moduleSpecifier = parseModuleSpecifier ( ) ;
7112
7126
}
7113
7127
}
7114
- if ( token ( ) === SyntaxKind . AssertKeyword && ! scanner . hasPrecedingLineBreak ( ) ) {
7115
- const posAfterSpecifier = getNodePos ( ) ;
7116
- assertClause = parseAssertClause ( posAfterSpecifier ) ;
7128
+ if ( moduleSpecifier && token ( ) === SyntaxKind . AssertKeyword && ! scanner . hasPrecedingLineBreak ( ) ) {
7129
+ assertClause = parseAssertClause ( ) ;
7117
7130
}
7118
7131
parseSemicolon ( ) ;
7119
7132
setAwaitContext ( savedAwaitContext ) ;
0 commit comments