@@ -568,7 +568,7 @@ namespace ts {
568
568
const newSourceFile = IncrementalParser . updateSourceFile ( sourceFile , newText , textChangeRange , aggressiveChecks ) ;
569
569
// 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.
570
570
// 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 ) ;
572
572
return newSourceFile ;
573
573
}
574
574
@@ -824,8 +824,7 @@ namespace ts {
824
824
}
825
825
826
826
// 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 ) ;
829
828
830
829
if ( setParentNodes ) {
831
830
fixupParentReferences ( sourceFile ) ;
@@ -923,8 +922,7 @@ namespace ts {
923
922
Debug . assert ( token ( ) === SyntaxKind . EndOfFileToken ) ;
924
923
const endOfFileToken = addJSDocComment ( parseTokenNode < EndOfFileToken > ( ) ) ;
925
924
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 ) ;
928
926
929
927
// 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
930
928
processCommentPragmas ( sourceFile as { } as PragmaContext , sourceText ) ;
@@ -994,10 +992,10 @@ namespace ts {
994
992
}
995
993
}
996
994
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 {
998
996
// code from createNode is inlined here so createNode won't have to deal with special case of creating source files
999
997
// 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 ) ;
1001
999
sourceFile . pos = 0 ;
1002
1000
sourceFile . end = sourceText . length ;
1003
1001
sourceFile . text = sourceText ;
@@ -1411,15 +1409,15 @@ namespace ts {
1411
1409
node . end = end === undefined ? scanner . getStartPos ( ) : end ;
1412
1410
1413
1411
if ( contextFlags ) {
1414
- node . flags |= contextFlags ;
1412
+ ( node as Mutable < T > ) . flags |= contextFlags ;
1415
1413
}
1416
1414
1417
1415
// Keep track on the node if we encountered an error while parsing it. If we did, then
1418
1416
// we cannot reuse the node incrementally. Once we've marked this node, clear out the
1419
1417
// flag so that we don't mark any subsequent nodes.
1420
1418
if ( parseErrorBeforeNextFinishedNode ) {
1421
1419
parseErrorBeforeNextFinishedNode = false ;
1422
- node . flags |= NodeFlags . ThisNodeHasError ;
1420
+ ( node as Mutable < T > ) . flags |= NodeFlags . ThisNodeHasError ;
1423
1421
}
1424
1422
1425
1423
return node ;
@@ -3040,7 +3038,7 @@ namespace ts {
3040
3038
const node = factory . createOptionalTypeNode ( type . type ) ;
3041
3039
node . pos = type . pos ;
3042
3040
node . end = type . end ;
3043
- node . flags = type . flags ;
3041
+ ( node as Mutable < Node > ) . flags = type . flags ;
3044
3042
return node ;
3045
3043
}
3046
3044
return type ;
@@ -4783,7 +4781,7 @@ namespace ts {
4783
4781
parseTemplateExpression ( )
4784
4782
) ;
4785
4783
if ( questionDotToken || tag . flags & NodeFlags . OptionalChain ) {
4786
- tagExpression . flags |= NodeFlags . OptionalChain ;
4784
+ ( tagExpression as Mutable < Node > ) . flags |= NodeFlags . OptionalChain ;
4787
4785
}
4788
4786
factory . trackExtraneousChildNode ( tagExpression , tagExpression . questionDotToken = questionDotToken ) ;
4789
4787
return finishNode ( tagExpression , pos ) ;
@@ -5019,7 +5017,7 @@ namespace ts {
5019
5017
// CoverInitializedName[Yield] :
5020
5018
// IdentifierReference[?Yield] Initializer[In, ?Yield]
5021
5019
// 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 > ;
5023
5021
const isShorthandPropertyAssignment = tokenIsIdentifier && ( token ( ) !== SyntaxKind . ColonToken ) ;
5024
5022
if ( isShorthandPropertyAssignment ) {
5025
5023
const equalsToken = parseOptionalToken ( SyntaxKind . EqualsToken ) ;
@@ -5323,13 +5321,15 @@ namespace ts {
5323
5321
// ThrowStatement[Yield] :
5324
5322
// throw [no LineTerminator here]Expression[In, ?Yield];
5325
5323
5324
+ const pos = getNodePos ( ) ;
5325
+ parseExpected ( SyntaxKind . ThrowKeyword ) ;
5326
+
5326
5327
// Because of automatic semicolon insertion, we need to report error if this
5327
5328
// throw could be terminated with a semicolon. Note: we can't call 'parseExpression'
5328
5329
// directly as that might consume an expression on the following line.
5329
5330
// We just return 'undefined' in that case. The actual error will be reported in the
5330
5331
// grammar walker.
5331
- const pos = getNodePos ( ) ;
5332
- parseExpected ( SyntaxKind . ThrowKeyword ) ;
5332
+ // TODO(rbuckton): Should we use `createMissingNode` here instead?
5333
5333
const expression = scanner . hasPrecedingLineBreak ( ) ? undefined : allowInAnd ( parseExpression ) ;
5334
5334
parseSemicolon ( ) ;
5335
5335
return finishNode ( factory . createThrow ( expression ! ) , pos ) ;
@@ -5667,7 +5667,7 @@ namespace ts {
5667
5667
const modifiers = parseModifiers ( ) ;
5668
5668
if ( isAmbient ) {
5669
5669
for ( const m of modifiers ! ) {
5670
- m . flags |= NodeFlags . Ambient ;
5670
+ ( m as Mutable < Node > ) . flags |= NodeFlags . Ambient ;
5671
5671
}
5672
5672
return doInsideOfContext ( NodeFlags . Ambient , ( ) => parseDeclarationWorker ( pos , hasJSDoc , decorators , modifiers ) ) ;
5673
5673
}
@@ -5722,7 +5722,7 @@ namespace ts {
5722
5722
if ( decorators || modifiers ) {
5723
5723
// We reached this point because we encountered decorators and/or modifiers and assumed a declaration
5724
5724
// 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 ) ;
5726
5726
missing . pos = pos ;
5727
5727
missing . decorators = decorators ;
5728
5728
missing . modifiers = modifiers ;
@@ -6004,7 +6004,7 @@ namespace ts {
6004
6004
: factory . createSetAccessorDeclaration ( decorators , modifiers , name , parameters , body ) ;
6005
6005
// Keep track of `typeParameters` (for both) and `type` (for setters) if they were parsed those indicate grammar errors
6006
6006
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 ) ;
6008
6008
return withJSDoc ( finishNode ( node , pos ) , hasJSDoc ) ;
6009
6009
}
6010
6010
@@ -6182,7 +6182,7 @@ namespace ts {
6182
6182
const isAmbient = some ( modifiers , isDeclareModifier ) ;
6183
6183
if ( isAmbient ) {
6184
6184
for ( const m of modifiers ! ) {
6185
- m . flags |= NodeFlags . Ambient ;
6185
+ ( m as Mutable < Node > ) . flags |= NodeFlags . Ambient ;
6186
6186
}
6187
6187
return doInsideOfContext ( NodeFlags . Ambient , ( ) => parsePropertyOrMethodDeclaration ( pos , hasJSDoc , decorators , modifiers ) ) ;
6188
6188
}
@@ -6690,7 +6690,7 @@ namespace ts {
6690
6690
currentToken = scanner . scan ( ) ;
6691
6691
const jsDocTypeExpression = parseJSDocTypeExpression ( ) ;
6692
6692
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 ) ;
6694
6694
const diagnostics = attachFileToDiagnostics ( parseDiagnostics , sourceFile ) ;
6695
6695
if ( jsDocDiagnostics ) {
6696
6696
sourceFile . jsDocDiagnostics = attachFileToDiagnostics ( jsDocDiagnostics , sourceFile ) ;
0 commit comments