Merge pull request #19301 from Microsoft/dev/bill/port19228toMaster
Port #19228 to master
This commit is contained in:
commit
89e19fff35
|
@ -2691,6 +2691,16 @@ namespace ts {
|
|||
return find<Extension>(supportedTypescriptExtensionsForExtractExtension, e => fileExtensionIs(path, e)) || find(supportedJavascriptExtensions, e => fileExtensionIs(path, e));
|
||||
}
|
||||
|
||||
// Retrieves any string from the final "." onwards from a base file name.
|
||||
// Unlike extensionFromPath, which throws an exception on unrecognized extensions.
|
||||
export function getAnyExtensionFromPath(path: string): string | undefined {
|
||||
const baseFileName = getBaseFileName(path);
|
||||
const extensionIndex = baseFileName.lastIndexOf(".");
|
||||
if (extensionIndex >= 0) {
|
||||
return baseFileName.substring(extensionIndex);
|
||||
}
|
||||
}
|
||||
|
||||
export function isCheckJsEnabledForFile(sourceFile: SourceFile, compilerOptions: CompilerOptions) {
|
||||
return sourceFile.checkJsDirective ? sourceFile.checkJsDirective.enabled : compilerOptions.checkJs;
|
||||
}
|
||||
|
|
|
@ -1278,8 +1278,10 @@ namespace ts {
|
|||
const typeChecker = getDiagnosticsProducingTypeChecker();
|
||||
|
||||
Debug.assert(!!sourceFile.bindDiagnostics);
|
||||
// For JavaScript files, we don't want to report semantic errors unless explicitly requested.
|
||||
const includeBindAndCheckDiagnostics = !isSourceFileJavaScript(sourceFile) || isCheckJsEnabledForFile(sourceFile, options);
|
||||
|
||||
// By default, only type-check .ts, .tsx, and 'External' files (external files are added by plugins)
|
||||
const includeBindAndCheckDiagnostics = sourceFile.scriptKind === ScriptKind.TS || sourceFile.scriptKind === ScriptKind.TSX ||
|
||||
sourceFile.scriptKind === ScriptKind.External || isCheckJsEnabledForFile(sourceFile, options);
|
||||
const bindDiagnostics = includeBindAndCheckDiagnostics ? sourceFile.bindDiagnostics : emptyArray;
|
||||
const checkDiagnostics = includeBindAndCheckDiagnostics ? typeChecker.getDiagnostics(sourceFile, cancellationToken) : emptyArray;
|
||||
const fileProcessingDiagnosticsInFile = fileProcessingDiagnostics.getDiagnostics(sourceFile.fileName);
|
||||
|
|
|
@ -3626,6 +3626,7 @@ namespace ts {
|
|||
export interface JsFileExtensionInfo {
|
||||
extension: string;
|
||||
isMixedContent: boolean;
|
||||
scriptKind?: ScriptKind;
|
||||
}
|
||||
|
||||
export interface DiagnosticMessage {
|
||||
|
|
|
@ -220,13 +220,28 @@ namespace ts.server {
|
|||
|
||||
interface FilePropertyReader<T> {
|
||||
getFileName(f: T): string;
|
||||
getScriptKind(f: T): ScriptKind;
|
||||
getScriptKind(f: T, extraFileExtensions?: JsFileExtensionInfo[]): ScriptKind;
|
||||
hasMixedContent(f: T, extraFileExtensions: JsFileExtensionInfo[]): boolean;
|
||||
}
|
||||
|
||||
const fileNamePropertyReader: FilePropertyReader<string> = {
|
||||
getFileName: x => x,
|
||||
getScriptKind: _ => undefined,
|
||||
getScriptKind: (fileName, extraFileExtensions) => {
|
||||
let result: ScriptKind;
|
||||
if (extraFileExtensions) {
|
||||
const fileExtension = getAnyExtensionFromPath(fileName);
|
||||
if (fileExtension) {
|
||||
some(extraFileExtensions, info => {
|
||||
if (info.extension === fileExtension) {
|
||||
result = info.scriptKind;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
}
|
||||
}
|
||||
return result;
|
||||
},
|
||||
hasMixedContent: (fileName, extraFileExtensions) => some(extraFileExtensions, ext => ext.isMixedContent && fileExtensionIs(fileName, ext.extension)),
|
||||
};
|
||||
|
||||
|
@ -1504,7 +1519,7 @@ namespace ts.server {
|
|||
scriptInfo = normalizedPath;
|
||||
}
|
||||
else {
|
||||
const scriptKind = propertyReader.getScriptKind(f);
|
||||
const scriptKind = propertyReader.getScriptKind(f, this.hostConfiguration.extraFileExtensions);
|
||||
const hasMixedContent = propertyReader.hasMixedContent(f, this.hostConfiguration.extraFileExtensions);
|
||||
scriptInfo = this.getOrCreateScriptInfoNotOpenedByClientForNormalizedPath(normalizedPath, scriptKind, hasMixedContent, project.directoryStructureHost);
|
||||
path = scriptInfo.path;
|
||||
|
|
|
@ -2158,6 +2158,7 @@ declare namespace ts {
|
|||
interface JsFileExtensionInfo {
|
||||
extension: string;
|
||||
isMixedContent: boolean;
|
||||
scriptKind?: ScriptKind;
|
||||
}
|
||||
interface DiagnosticMessage {
|
||||
key: string;
|
||||
|
|
|
@ -2158,6 +2158,7 @@ declare namespace ts {
|
|||
interface JsFileExtensionInfo {
|
||||
extension: string;
|
||||
isMixedContent: boolean;
|
||||
scriptKind?: ScriptKind;
|
||||
}
|
||||
interface DiagnosticMessage {
|
||||
key: string;
|
||||
|
|
Loading…
Reference in a new issue