@@ -568,7 +568,7 @@ namespace ts {
568568 const newSourceFile = IncrementalParser . updateSourceFile ( sourceFile , newText , textChangeRange , aggressiveChecks ) ;
569569 // Because new source file node is created, it may not have the flag PossiblyContainDynamicImport. This is the case if there is no new edit to add dynamic import.
570570 // We will manually port the flag to the new source file.
571- newSourceFile . flags |= ( sourceFile . flags & NodeFlags . PermanentlySetIncrementalFlags ) ;
571+ ( newSourceFile as Mutable < SourceFile > ) . flags |= ( sourceFile . flags & NodeFlags . PermanentlySetIncrementalFlags ) ;
572572 return newSourceFile ;
573573 }
574574
@@ -824,8 +824,7 @@ namespace ts {
824824 }
825825
826826 // Set source file so that errors will be reported with this file name
827- const sourceFile = createSourceFile ( fileName , ScriptTarget . ES2015 , ScriptKind . JSON , /*isDeclaration*/ false , statements , endOfFileToken ) ;
828- sourceFile . flags |= sourceFlags ;
827+ const sourceFile = createSourceFile ( fileName , ScriptTarget . ES2015 , ScriptKind . JSON , /*isDeclaration*/ false , statements , endOfFileToken , sourceFlags ) ;
829828
830829 if ( setParentNodes ) {
831830 fixupParentReferences ( sourceFile ) ;
@@ -923,8 +922,7 @@ namespace ts {
923922 Debug . assert ( token ( ) === SyntaxKind . EndOfFileToken ) ;
924923 const endOfFileToken = addJSDocComment ( parseTokenNode < EndOfFileToken > ( ) ) ;
925924
926- const sourceFile = createSourceFile ( fileName , languageVersion , scriptKind , isDeclarationFile , statements , endOfFileToken ) ;
927- sourceFile . flags |= sourceFlags ;
925+ const sourceFile = createSourceFile ( fileName , languageVersion , scriptKind , isDeclarationFile , statements , endOfFileToken , sourceFlags ) ;
928926
929927 // A member of ReadonlyArray<T> isn't assignable to a member of T[] (and prevents a direct cast) - but this is where we set up those members so they can be readonly in the future
930928 processCommentPragmas ( sourceFile as { } as PragmaContext , sourceText ) ;
@@ -994,10 +992,10 @@ namespace ts {
994992 }
995993 }
996994
997- function createSourceFile ( fileName : string , languageVersion : ScriptTarget , scriptKind : ScriptKind , isDeclarationFile : boolean , statements : readonly Statement [ ] , endOfFileToken : EndOfFileToken ) : SourceFile {
995+ function createSourceFile ( fileName : string , languageVersion : ScriptTarget , scriptKind : ScriptKind , isDeclarationFile : boolean , statements : readonly Statement [ ] , endOfFileToken : EndOfFileToken , flags : NodeFlags ) : SourceFile {
998996 // code from createNode is inlined here so createNode won't have to deal with special case of creating source files
999997 // this is quite rare comparing to other nodes and createNode should be as fast as possible
1000- const sourceFile = factory . createSourceFile ( statements , endOfFileToken ) ;
998+ const sourceFile = factory . createSourceFile ( statements , endOfFileToken , flags ) ;
1001999 sourceFile . pos = 0 ;
10021000 sourceFile . end = sourceText . length ;
10031001 sourceFile . text = sourceText ;
@@ -1411,15 +1409,15 @@ namespace ts {
14111409 node . end = end === undefined ? scanner . getStartPos ( ) : end ;
14121410
14131411 if ( contextFlags ) {
1414- node . flags |= contextFlags ;
1412+ ( node as Mutable < T > ) . flags |= contextFlags ;
14151413 }
14161414
14171415 // Keep track on the node if we encountered an error while parsing it. If we did, then
14181416 // we cannot reuse the node incrementally. Once we've marked this node, clear out the
14191417 // flag so that we don't mark any subsequent nodes.
14201418 if ( parseErrorBeforeNextFinishedNode ) {
14211419 parseErrorBeforeNextFinishedNode = false ;
1422- node . flags |= NodeFlags . ThisNodeHasError ;
1420+ ( node as Mutable < T > ) . flags |= NodeFlags . ThisNodeHasError ;
14231421 }
14241422
14251423 return node ;
@@ -3040,7 +3038,7 @@ namespace ts {
30403038 const node = factory . createOptionalTypeNode ( type . type ) ;
30413039 node . pos = type . pos ;
30423040 node . end = type . end ;
3043- node . flags = type . flags ;
3041+ ( node as Mutable < Node > ) . flags = type . flags ;
30443042 return node ;
30453043 }
30463044 return type ;
@@ -4783,7 +4781,7 @@ namespace ts {
47834781 parseTemplateExpression ( )
47844782 ) ;
47854783 if ( questionDotToken || tag . flags & NodeFlags . OptionalChain ) {
4786- tagExpression . flags |= NodeFlags . OptionalChain ;
4784+ ( tagExpression as Mutable < Node > ) . flags |= NodeFlags . OptionalChain ;
47874785 }
47884786 factory . trackExtraneousChildNode ( tagExpression , tagExpression . questionDotToken = questionDotToken ) ;
47894787 return finishNode ( tagExpression , pos ) ;
@@ -5019,7 +5017,7 @@ namespace ts {
50195017 // CoverInitializedName[Yield] :
50205018 // IdentifierReference[?Yield] Initializer[In, ?Yield]
50215019 // this is necessary because ObjectLiteral productions are also used to cover grammar for ObjectAssignmentPattern
5022- let node : ShorthandPropertyAssignment | PropertyAssignment ;
5020+ let node : Mutable < ShorthandPropertyAssignment | PropertyAssignment > ;
50235021 const isShorthandPropertyAssignment = tokenIsIdentifier && ( token ( ) !== SyntaxKind . ColonToken ) ;
50245022 if ( isShorthandPropertyAssignment ) {
50255023 const equalsToken = parseOptionalToken ( SyntaxKind . EqualsToken ) ;
@@ -5323,13 +5321,15 @@ namespace ts {
53235321 // ThrowStatement[Yield] :
53245322 // throw [no LineTerminator here]Expression[In, ?Yield];
53255323
5324+ const pos = getNodePos ( ) ;
5325+ parseExpected ( SyntaxKind . ThrowKeyword ) ;
5326+
53265327 // Because of automatic semicolon insertion, we need to report error if this
53275328 // throw could be terminated with a semicolon. Note: we can't call 'parseExpression'
53285329 // directly as that might consume an expression on the following line.
53295330 // We just return 'undefined' in that case. The actual error will be reported in the
53305331 // grammar walker.
5331- const pos = getNodePos ( ) ;
5332- parseExpected ( SyntaxKind . ThrowKeyword ) ;
5332+ // TODO(rbuckton): Should we use `createMissingNode` here instead?
53335333 const expression = scanner . hasPrecedingLineBreak ( ) ? undefined : allowInAnd ( parseExpression ) ;
53345334 parseSemicolon ( ) ;
53355335 return finishNode ( factory . createThrow ( expression ! ) , pos ) ;
@@ -5667,7 +5667,7 @@ namespace ts {
56675667 const modifiers = parseModifiers ( ) ;
56685668 if ( isAmbient ) {
56695669 for ( const m of modifiers ! ) {
5670- m . flags |= NodeFlags . Ambient ;
5670+ ( m as Mutable < Node > ) . flags |= NodeFlags . Ambient ;
56715671 }
56725672 return doInsideOfContext ( NodeFlags . Ambient , ( ) => parseDeclarationWorker ( pos , hasJSDoc , decorators , modifiers ) ) ;
56735673 }
@@ -5722,7 +5722,7 @@ namespace ts {
57225722 if ( decorators || modifiers ) {
57235723 // We reached this point because we encountered decorators and/or modifiers and assumed a declaration
57245724 // would follow. For recovery and error reporting purposes, return an incomplete declaration.
5725- const missing = createMissingNode < Statement > ( SyntaxKind . MissingDeclaration , /*reportAtCurrentPosition*/ true , Diagnostics . Declaration_expected ) ;
5725+ const missing = createMissingNode < MissingDeclaration > ( SyntaxKind . MissingDeclaration , /*reportAtCurrentPosition*/ true , Diagnostics . Declaration_expected ) ;
57265726 missing . pos = pos ;
57275727 missing . decorators = decorators ;
57285728 missing . modifiers = modifiers ;
@@ -6004,7 +6004,7 @@ namespace ts {
60046004 : factory . createSetAccessorDeclaration ( decorators , modifiers , name , parameters , body ) ;
60056005 // Keep track of `typeParameters` (for both) and `type` (for setters) if they were parsed those indicate grammar errors
60066006 if ( typeParameters ) factory . trackExtraneousChildNodes ( node , node . typeParameters = typeParameters ) ;
6007- if ( type && kind === SyntaxKind . SetAccessor ) factory . trackExtraneousChildNode ( node , node . type = type ) ;
6007+ if ( type && node . kind === SyntaxKind . SetAccessor ) factory . trackExtraneousChildNode ( node , node . type = type ) ;
60086008 return withJSDoc ( finishNode ( node , pos ) , hasJSDoc ) ;
60096009 }
60106010
@@ -6182,7 +6182,7 @@ namespace ts {
61826182 const isAmbient = some ( modifiers , isDeclareModifier ) ;
61836183 if ( isAmbient ) {
61846184 for ( const m of modifiers ! ) {
6185- m . flags |= NodeFlags . Ambient ;
6185+ ( m as Mutable < Node > ) . flags |= NodeFlags . Ambient ;
61866186 }
61876187 return doInsideOfContext ( NodeFlags . Ambient , ( ) => parsePropertyOrMethodDeclaration ( pos , hasJSDoc , decorators , modifiers ) ) ;
61886188 }
@@ -6690,7 +6690,7 @@ namespace ts {
66906690 currentToken = scanner . scan ( ) ;
66916691 const jsDocTypeExpression = parseJSDocTypeExpression ( ) ;
66926692
6693- const sourceFile = createSourceFile ( "file.js" , ScriptTarget . Latest , ScriptKind . JS , /*isDeclarationFile*/ false , [ ] , factory . createToken ( SyntaxKind . EndOfFileToken ) ) ;
6693+ const sourceFile = createSourceFile ( "file.js" , ScriptTarget . Latest , ScriptKind . JS , /*isDeclarationFile*/ false , [ ] , factory . createToken ( SyntaxKind . EndOfFileToken ) , NodeFlags . None ) ;
66946694 const diagnostics = attachFileToDiagnostics ( parseDiagnostics , sourceFile ) ;
66956695 if ( jsDocDiagnostics ) {
66966696 sourceFile . jsDocDiagnostics = attachFileToDiagnostics ( jsDocDiagnostics , sourceFile ) ;
0 commit comments