Make FormatContext.host optional since it’s not necessary if format options are all applied

This commit is contained in:
Andrew Branch
2020-05-14 12:22:17 -07:00
parent 0a696c902d
commit ab09d67b49
3 changed files with 7 additions and 5 deletions
+1 -1
View File
@@ -3,7 +3,7 @@ namespace ts.formatting {
export interface FormatContext {
readonly options: FormatCodeSettings;
readonly getRules: RulesMap;
readonly host: FormattingHost;
readonly host?: FormattingHost;
}
export interface TextRangeWithKind<T extends SyntaxKind = SyntaxKind> extends TextRange {
+3 -1
View File
@@ -203,6 +203,7 @@ namespace ts {
has(dependencyName: string, inGroups?: PackageJsonDependencyGroup): boolean;
}
/** @internal */
export interface FormattingHost {
getNewLine?(): string;
}
@@ -210,8 +211,9 @@ namespace ts {
//
// Public interface of the host of a language service instance.
//
export interface LanguageServiceHost extends GetEffectiveTypeRootsHost, FormattingHost {
export interface LanguageServiceHost extends GetEffectiveTypeRootsHost {
getCompilationSettings(): CompilerOptions;
getNewLine?(): string;
getProjectVersion?(): string;
getScriptFileNames(): string[];
getScriptKind?(fileName: string): ScriptKind;
+3 -3
View File
@@ -2085,9 +2085,9 @@ namespace ts {
/**
* The default is CRLF.
*/
export function getNewLineOrDefaultFromHost(host: FormattingHost, formatSettings?: FormatCodeSettings) {
return (formatSettings && formatSettings.newLineCharacter) ||
(host.getNewLine && host.getNewLine()) ||
export function getNewLineOrDefaultFromHost(host: FormattingHost | undefined, formatSettings?: FormatCodeSettings) {
return formatSettings?.newLineCharacter ||
host?.getNewLine?.() ||
carriageReturnLineFeed;
}