Memoize rule provider (#19501)

This commit is contained in:
Wesley Wigham 2017-10-26 13:01:48 -07:00 committed by GitHub
parent 9c96eee7a4
commit 940175e23f

View File

@ -67,7 +67,8 @@ namespace ts {
}
export const newLineCharacter = "\n";
export function getRuleProvider(action?: (opts: FormatCodeSettings) => void) {
export const getRuleProvider = memoize(getRuleProviderInternal);
function getRuleProviderInternal() {
const options = {
indentSize: 4,
tabSize: 4,
@ -89,9 +90,6 @@ namespace ts {
placeOpenBraceOnNewLineForFunctions: false,
placeOpenBraceOnNewLineForControlBlocks: false,
};
if (action) {
action(options);
}
const rulesProvider = new formatting.RulesProvider();
rulesProvider.ensureUpToDate(options);
return rulesProvider;