MCPcopy Create free account
hub / github.com/nodejs/node / updateLanguageServiceSourceFile

Function updateLanguageServiceSourceFile

test/fixtures/snapshot/typescript.js:164806–164856  ·  view source on GitHub ↗
(sourceFile, scriptSnapshot, version, textChangeRange, aggressiveChecks)

Source from the content-addressed store, hash-verified

164804 }
164805 ts.createLanguageServiceSourceFile = createLanguageServiceSourceFile;
164806 function updateLanguageServiceSourceFile(sourceFile, scriptSnapshot, version, textChangeRange, aggressiveChecks) {
164807 // If we were given a text change range, and our version or open-ness changed, then
164808 // incrementally parse this file.
164809 if (textChangeRange) {
164810 if (version !== sourceFile.version) {
164811 var newText = void 0;
164812 // grab the fragment from the beginning of the original text to the beginning of the span
164813 var prefix = textChangeRange.span.start !== 0
164814 ? sourceFile.text.substr(0, textChangeRange.span.start)
164815 : "";
164816 // grab the fragment from the end of the span till the end of the original text
164817 var suffix = ts.textSpanEnd(textChangeRange.span) !== sourceFile.text.length
164818 ? sourceFile.text.substr(ts.textSpanEnd(textChangeRange.span))
164819 : "";
164820 if (textChangeRange.newLength === 0) {
164821 // edit was a deletion - just combine prefix and suffix
164822 newText = prefix && suffix ? prefix + suffix : prefix || suffix;
164823 }
164824 else {
164825 // it was actual edit, fetch the fragment of new text that correspond to new span
164826 var changedText = scriptSnapshot.getText(textChangeRange.span.start, textChangeRange.span.start + textChangeRange.newLength);
164827 // combine prefix, changed text and suffix
164828 newText = prefix && suffix
164829 ? prefix + changedText + suffix
164830 : prefix
164831 ? (prefix + changedText)
164832 : (changedText + suffix);
164833 }
164834 var newSourceFile = ts.updateSourceFile(sourceFile, newText, textChangeRange, aggressiveChecks);
164835 setSourceFileFields(newSourceFile, scriptSnapshot, version);
164836 // after incremental parsing nameTable might not be up-to-date
164837 // drop it so it can be lazily recreated later
164838 newSourceFile.nameTable = undefined;
164839 // dispose all resources held by old script snapshot
164840 if (sourceFile !== newSourceFile && sourceFile.scriptSnapshot) {
164841 if (sourceFile.scriptSnapshot.dispose) {
164842 sourceFile.scriptSnapshot.dispose();
164843 }
164844 sourceFile.scriptSnapshot = undefined;
164845 }
164846 return newSourceFile;
164847 }
164848 }
164849 var options = {
164850 languageVersion: sourceFile.languageVersion,
164851 impliedNodeFormat: sourceFile.impliedNodeFormat,
164852 setExternalModuleIndicator: sourceFile.setExternalModuleIndicator,
164853 };
164854 // Otherwise, just create a new source file.
164855 return createLanguageServiceSourceFile(sourceFile.fileName, scriptSnapshot, options, version, /*setNodeParents*/ true, sourceFile.scriptKind);
164856 }
164857 ts.updateLanguageServiceSourceFile = updateLanguageServiceSourceFile;
164858 var NoopCancellationToken = {
164859 isCancellationRequested: ts.returnFalse,

Callers 1

typescript.jsFile · 0.85

Calls 3

setSourceFileFieldsFunction · 0.85
disposeMethod · 0.80

Tested by

no test coverage detected