@@ -394,7 +394,8 @@ namespace ts {
394394 return visitNodes ( cbNode , cbNodes , node . decorators ) ||
395395 visitNodes ( cbNode , cbNodes , node . modifiers ) ||
396396 visitNode ( cbNode , ( < ImportDeclaration > node ) . importClause ) ||
397- visitNode ( cbNode , ( < ImportDeclaration > node ) . moduleSpecifier ) ;
397+ visitNode ( cbNode , ( < ImportDeclaration > node ) . moduleSpecifier ) ||
398+ visitNode ( cbNode , ( < ImportDeclaration > node ) . assertClause ) ;
398399 case SyntaxKind . ImportClause :
399400 return visitNode ( cbNode , ( < ImportClause > node ) . name ) ||
400401 visitNode ( cbNode , ( < ImportClause > node ) . namedBindings ) ;
@@ -417,7 +418,8 @@ namespace ts {
417418 return visitNodes ( cbNode , cbNodes , node . decorators ) ||
418419 visitNodes ( cbNode , cbNodes , node . modifiers ) ||
419420 visitNode ( cbNode , ( < ExportDeclaration > node ) . exportClause ) ||
420- visitNode ( cbNode , ( < ExportDeclaration > node ) . moduleSpecifier ) ;
421+ visitNode ( cbNode , ( < ExportDeclaration > node ) . moduleSpecifier ) ||
422+ visitNode ( cbNode , ( < ExportDeclaration > node ) . assertClause ) ;
421423 case SyntaxKind . ImportSpecifier :
422424 case SyntaxKind . ExportSpecifier :
423425 return visitNode ( cbNode , ( < ImportOrExportSpecifier > node ) . propertyName ) ||
@@ -1698,7 +1700,7 @@ namespace ts {
16981700 function isAssertionKey ( ) : boolean {
16991701 return tokenIsIdentifierOrKeyword ( token ( ) ) ||
17001702 token ( ) === SyntaxKind . StringLiteral ;
1701- }
1703+ }
17021704
17031705 function parsePropertyNameWorker ( allowComputedPropertyNames : boolean ) : PropertyName {
17041706 if ( token ( ) === SyntaxKind . StringLiteral || token ( ) === SyntaxKind . NumericLiteral ) {
@@ -1865,7 +1867,7 @@ namespace ts {
18651867 case ParsingContext . ObjectBindingElements :
18661868 return token ( ) === SyntaxKind . OpenBracketToken || token ( ) === SyntaxKind . DotDotDotToken || isLiteralPropertyName ( ) ;
18671869 case ParsingContext . AssertEntries :
1868- return isAssertionKey ( )
1870+ return isAssertionKey ( ) ;
18691871 case ParsingContext . HeritageClauseElement :
18701872 // If we see `{ ... }` then only consume it as an expression if it is followed by `,` or `{`
18711873 // That way we won't consume the body of a class in its heritage clause.
@@ -6915,30 +6917,42 @@ namespace ts {
69156917 parseExpected ( SyntaxKind . FromKeyword ) ;
69166918 }
69176919 const moduleSpecifier = parseModuleSpecifier ( ) ;
6918- const afterSpecifierPos = scanner . getStartPos ( ) ;
69196920
69206921 let assertClause : AssertClause | undefined ;
69216922 if ( token ( ) === SyntaxKind . AssertKeyword && ! scanner . hasPrecedingLineBreak ( ) ) {
6922- assertClause = parseAssertClause ( afterSpecifierPos ) ;
6923+ assertClause = parseAssertClause ( ) ;
69236924 }
69246925
69256926 parseSemicolon ( ) ;
69266927 const node = factory . createImportDeclaration ( decorators , modifiers , importClause , moduleSpecifier , assertClause ) ;
69276928 return withJSDoc ( finishNode ( node , pos ) , hasJSDoc ) ;
69286929 }
69296930
6930- function parseAssertEntry ( ) {
6931+ function parseAssertEntry ( ) {
69316932 const pos = getNodePos ( ) ;
69326933 const name = tokenIsIdentifierOrKeyword ( token ( ) ) ? parseIdentifierName ( ) : parseLiteralLikeNode ( SyntaxKind . StringLiteral ) as StringLiteral ;
6933- parseExpected ( SyntaxKind . ColonToken )
6934+ parseExpected ( SyntaxKind . ColonToken ) ;
69346935 const value = parseLiteralLikeNode ( SyntaxKind . StringLiteral ) as StringLiteral ;
69356936 return finishNode ( factory . createAssertEntry ( name , value ) , pos ) ;
69366937 }
69376938
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 ) ;
69426956 }
69436957
69446958 function tokenAfterImportDefinitelyProducesImportDeclaration ( ) {
@@ -7111,9 +7125,8 @@ namespace ts {
71117125 moduleSpecifier = parseModuleSpecifier ( ) ;
71127126 }
71137127 }
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 ( ) ;
71177130 }
71187131 parseSemicolon ( ) ;
71197132 setAwaitContext ( savedAwaitContext ) ;
0 commit comments