@@ -819,8 +819,8 @@ namespace ts {
819819 super ( kind , pos , end ) ;
820820 }
821821
822- public update ( newText : string , textChangeRange : TextChangeRange ) : SourceFile {
823- return updateSourceFile ( this , newText , textChangeRange ) ;
822+ public update ( newText : string , textChangeRange : TextChangeRange , scriptKind ?: ScriptKind ) : SourceFile {
823+ return updateSourceFile ( this , newText , textChangeRange , /*aggressiveChecks*/ undefined , scriptKind ) ;
824824 }
825825
826826 public getLineAndCharacterOfPosition ( position : number ) : LineAndCharacter {
@@ -1019,6 +1019,7 @@ namespace ts {
10191019 getNewLine ?( ) : string ;
10201020 getProjectVersion ?( ) : string ;
10211021 getScriptFileNames ( ) : string [ ] ;
1022+ getScriptKind ( fileName : string ) : ScriptKind ;
10221023 getScriptVersion ( fileName : string ) : string ;
10231024 getScriptSnapshot ( fileName : string ) : IScriptSnapshot ;
10241025 getLocalizedDiagnosticMessages ?( ) : any ;
@@ -1468,7 +1469,8 @@ namespace ts {
14681469 fileName : string ,
14691470 compilationSettings : CompilerOptions ,
14701471 scriptSnapshot : IScriptSnapshot ,
1471- version : string ) : SourceFile ;
1472+ version : string ,
1473+ scriptKind ?: ScriptKind ) : SourceFile ;
14721474
14731475 /**
14741476 * Request an updated version of an already existing SourceFile with a given fileName
@@ -1486,7 +1488,8 @@ namespace ts {
14861488 fileName : string ,
14871489 compilationSettings : CompilerOptions ,
14881490 scriptSnapshot : IScriptSnapshot ,
1489- version : string ) : SourceFile ;
1491+ version : string ,
1492+ scriptKind ?: ScriptKind ) : SourceFile ;
14901493
14911494 /**
14921495 * Informs the DocumentRegistry that a file is not needed any longer.
@@ -1657,6 +1660,7 @@ namespace ts {
16571660 hostFileName : string ;
16581661 version : string ;
16591662 scriptSnapshot : IScriptSnapshot ;
1663+ scriptKind : ScriptKind ;
16601664 }
16611665
16621666 interface DocumentRegistryEntry {
@@ -1746,12 +1750,14 @@ namespace ts {
17461750
17471751 private createEntry ( fileName : string , path : Path ) {
17481752 let entry : HostFileInformation ;
1753+ const scriptKind = this . host . getScriptKind ( fileName ) ;
17491754 const scriptSnapshot = this . host . getScriptSnapshot ( fileName ) ;
17501755 if ( scriptSnapshot ) {
17511756 entry = {
17521757 hostFileName : fileName ,
17531758 version : this . host . getScriptVersion ( fileName ) ,
1754- scriptSnapshot : scriptSnapshot
1759+ scriptSnapshot : scriptSnapshot ,
1760+ scriptKind : scriptKind
17551761 } ;
17561762 }
17571763
@@ -1817,17 +1823,18 @@ namespace ts {
18171823 throw new Error ( "Could not find file: '" + fileName + "'." ) ;
18181824 }
18191825
1826+ const scriptKind = this . host . getScriptKind ( fileName ) ;
18201827 const version = this . host . getScriptVersion ( fileName ) ;
18211828 let sourceFile : SourceFile ;
18221829
18231830 if ( this . currentFileName !== fileName ) {
18241831 // This is a new file, just parse it
1825- sourceFile = createLanguageServiceSourceFile ( fileName , scriptSnapshot , ScriptTarget . Latest , version , /*setNodeParents*/ true ) ;
1832+ sourceFile = createLanguageServiceSourceFile ( fileName , scriptSnapshot , ScriptTarget . Latest , version , /*setNodeParents*/ true , scriptKind ) ;
18261833 }
18271834 else if ( this . currentFileVersion !== version ) {
18281835 // This is the same file, just a newer version. Incrementally parse the file.
18291836 const editRange = scriptSnapshot . getChangeRange ( this . currentFileScriptSnapshot ) ;
1830- sourceFile = updateLanguageServiceSourceFile ( this . currentSourceFile , scriptSnapshot , version , editRange ) ;
1837+ sourceFile = updateLanguageServiceSourceFile ( this . currentSourceFile , scriptSnapshot , version , editRange , /*aggressiveChecks*/ undefined , scriptKind ) ;
18311838 }
18321839
18331840 if ( sourceFile ) {
@@ -1953,16 +1960,16 @@ namespace ts {
19531960 return output . outputText ;
19541961 }
19551962
1956- export function createLanguageServiceSourceFile ( fileName : string , scriptSnapshot : IScriptSnapshot , scriptTarget : ScriptTarget , version : string , setNodeParents : boolean ) : SourceFile {
1963+ export function createLanguageServiceSourceFile ( fileName : string , scriptSnapshot : IScriptSnapshot , scriptTarget : ScriptTarget , version : string , setNodeParents : boolean , scriptKind ?: ScriptKind ) : SourceFile {
19571964 const text = scriptSnapshot . getText ( 0 , scriptSnapshot . getLength ( ) ) ;
1958- const sourceFile = createSourceFile ( fileName , text , scriptTarget , setNodeParents ) ;
1965+ const sourceFile = createSourceFile ( fileName , text , scriptTarget , setNodeParents , scriptKind ) ;
19591966 setSourceFileFields ( sourceFile , scriptSnapshot , version ) ;
19601967 return sourceFile ;
19611968 }
19621969
19631970 export let disableIncrementalParsing = false ;
19641971
1965- export function updateLanguageServiceSourceFile ( sourceFile : SourceFile , scriptSnapshot : IScriptSnapshot , version : string , textChangeRange : TextChangeRange , aggressiveChecks ?: boolean ) : SourceFile {
1972+ export function updateLanguageServiceSourceFile ( sourceFile : SourceFile , scriptSnapshot : IScriptSnapshot , version : string , textChangeRange : TextChangeRange , aggressiveChecks ?: boolean , scriptKind ?: ScriptKind ) : SourceFile {
19661973 // If we were given a text change range, and our version or open-ness changed, then
19671974 // incrementally parse this file.
19681975 if ( textChangeRange ) {
@@ -1996,7 +2003,7 @@ namespace ts {
19962003 : ( changedText + suffix ) ;
19972004 }
19982005
1999- const newSourceFile = updateSourceFile ( sourceFile , newText , textChangeRange , aggressiveChecks ) ;
2006+ const newSourceFile = updateSourceFile ( sourceFile , newText , textChangeRange , aggressiveChecks , scriptKind ) ;
20002007 setSourceFileFields ( newSourceFile , scriptSnapshot , version ) ;
20012008 // after incremental parsing nameTable might not be up-to-date
20022009 // drop it so it can be lazily recreated later
@@ -2017,7 +2024,7 @@ namespace ts {
20172024 }
20182025
20192026 // Otherwise, just create a new source file.
2020- return createLanguageServiceSourceFile ( sourceFile . fileName , scriptSnapshot , sourceFile . languageVersion , version , /*setNodeParents*/ true ) ;
2027+ return createLanguageServiceSourceFile ( sourceFile . fileName , scriptSnapshot , sourceFile . languageVersion , version , /*setNodeParents*/ true , scriptKind ) ;
20212028 }
20222029
20232030 export function createDocumentRegistry ( useCaseSensitiveFileNames ?: boolean , currentDirectory = "" ) : DocumentRegistry {
@@ -2059,20 +2066,21 @@ namespace ts {
20592066 return JSON . stringify ( bucketInfoArray , undefined , 2 ) ;
20602067 }
20612068
2062- function acquireDocument ( fileName : string , compilationSettings : CompilerOptions , scriptSnapshot : IScriptSnapshot , version : string ) : SourceFile {
2063- return acquireOrUpdateDocument ( fileName , compilationSettings , scriptSnapshot , version , /*acquiring*/ true ) ;
2069+ function acquireDocument ( fileName : string , compilationSettings : CompilerOptions , scriptSnapshot : IScriptSnapshot , version : string , scriptKind ?: ScriptKind ) : SourceFile {
2070+ return acquireOrUpdateDocument ( fileName , compilationSettings , scriptSnapshot , version , /*acquiring*/ true , scriptKind ) ;
20642071 }
20652072
2066- function updateDocument ( fileName : string , compilationSettings : CompilerOptions , scriptSnapshot : IScriptSnapshot , version : string ) : SourceFile {
2067- return acquireOrUpdateDocument ( fileName , compilationSettings , scriptSnapshot , version , /*acquiring*/ false ) ;
2073+ function updateDocument ( fileName : string , compilationSettings : CompilerOptions , scriptSnapshot : IScriptSnapshot , version : string , scriptKind ?: ScriptKind ) : SourceFile {
2074+ return acquireOrUpdateDocument ( fileName , compilationSettings , scriptSnapshot , version , /*acquiring*/ false , scriptKind ) ;
20682075 }
20692076
20702077 function acquireOrUpdateDocument (
20712078 fileName : string ,
20722079 compilationSettings : CompilerOptions ,
20732080 scriptSnapshot : IScriptSnapshot ,
20742081 version : string ,
2075- acquiring : boolean ) : SourceFile {
2082+ acquiring : boolean ,
2083+ scriptKind ?: ScriptKind ) : SourceFile {
20762084
20772085 const bucket = getBucketForCompilationSettings ( compilationSettings , /*createIfMissing*/ true ) ;
20782086 const path = toPath ( fileName , currentDirectory , getCanonicalFileName ) ;
@@ -2081,7 +2089,7 @@ namespace ts {
20812089 Debug . assert ( acquiring , "How could we be trying to update a document that the registry doesn't have?" ) ;
20822090
20832091 // Have never seen this file with these settings. Create a new source file for it.
2084- const sourceFile = createLanguageServiceSourceFile ( fileName , scriptSnapshot , compilationSettings . target , version , /*setNodeParents*/ false ) ;
2092+ const sourceFile = createLanguageServiceSourceFile ( fileName , scriptSnapshot , compilationSettings . target , version , /*setNodeParents*/ false , scriptKind ) ;
20852093
20862094 entry = {
20872095 sourceFile : sourceFile ,
@@ -2095,8 +2103,8 @@ namespace ts {
20952103 // the script snapshot. If so, update it appropriately. Otherwise, we can just
20962104 // return it as is.
20972105 if ( entry . sourceFile . version !== version ) {
2098- entry . sourceFile = updateLanguageServiceSourceFile ( entry . sourceFile , scriptSnapshot , version ,
2099- scriptSnapshot . getChangeRange ( entry . sourceFile . scriptSnapshot ) ) ;
2106+ entry . sourceFile = updateLanguageServiceSourceFile ( entry . sourceFile , scriptSnapshot , version ,
2107+ scriptSnapshot . getChangeRange ( entry . sourceFile . scriptSnapshot ) , /*aggressiveChecks*/ undefined , scriptKind ) ;
21002108 }
21012109 }
21022110
@@ -2848,14 +2856,14 @@ namespace ts {
28482856 // it's source file any more, and instead defers to DocumentRegistry to get
28492857 // either version 1, version 2 (or some other version) depending on what the
28502858 // host says should be used.
2851- return documentRegistry . updateDocument ( fileName , newSettings , hostFileInformation . scriptSnapshot , hostFileInformation . version ) ;
2859+ return documentRegistry . updateDocument ( fileName , newSettings , hostFileInformation . scriptSnapshot , hostFileInformation . version , hostFileInformation . scriptKind ) ;
28522860 }
28532861
28542862 // We didn't already have the file. Fall through and acquire it from the registry.
28552863 }
28562864
28572865 // Could not find this file in the old program, create a new SourceFile for it.
2858- return documentRegistry . acquireDocument ( fileName , newSettings , hostFileInformation . scriptSnapshot , hostFileInformation . version ) ;
2866+ return documentRegistry . acquireDocument ( fileName , newSettings , hostFileInformation . scriptSnapshot , hostFileInformation . version , hostFileInformation . scriptKind ) ;
28592867 }
28602868
28612869 function sourceFileUpToDate ( sourceFile : SourceFile ) : boolean {
@@ -4641,7 +4649,7 @@ namespace ts {
46414649
46424650 // Go to the original declaration for cases:
46434651 //
4644- // (1) when the aliased symbol was declared in the location(parent).
4652+ // (1) when the aliased symbol was declared in the location(parent).
46454653 // (2) when the aliased symbol is originating from a named import.
46464654 //
46474655 if ( node . kind === SyntaxKind . Identifier &&
0 commit comments