From db5d9e7037347a904e0aff4afc0a6be74af7ca27 Mon Sep 17 00:00:00 2001 From: liyancheng2 Date: Sat, 25 Jan 2025 12:02:55 +0800 Subject: [PATCH] douyin try to improve performance Issue: https://gitee.com/openharmony/third_party_typescript/issues/IBJPTY Signed-off-by: liyancheng2 Change-Id: I78f4233399372fc3a435808cf717164c2da952db --- lib/tsc.js | 9 ++++++++- lib/tsserver.js | 11 +++++++++-- lib/tsserverlibrary.js | 11 +++++++++-- lib/typescript.js | 11 +++++++++-- lib/typescriptServices.js | 11 +++++++++-- lib/typingsInstaller.js | 11 +++++++++-- src/compiler/program.ts | 11 ++++++++++- 7 files changed, 63 insertions(+), 12 deletions(-) diff --git a/lib/tsc.js b/lib/tsc.js index 7c6da53912..bb7242611d 100644 --- a/lib/tsc.js +++ b/lib/tsc.js @@ -103285,7 +103285,8 @@ var ts; if (result) return result; } - var emitResolver = getTypeChecker().getEmitResolver(ts.outFile(options) ? undefined : sourceFile, cancellationToken); + var checker = (sourceFile === null || sourceFile === void 0 ? void 0 : sourceFile.scriptKind) === 8 ? getLinterTypeChecker() : getTypeChecker(); + var emitResolver = checker.getEmitResolver(ts.outFile(options) ? undefined : sourceFile, cancellationToken); ts.performance.mark("beforeEmit"); var emitResult = ts.emitFiles(emitResolver, getEmitHost(writeFileCallback), sourceFile, ts.getTransformers(options, customTransformers, emitOnlyDtsFiles), emitOnlyDtsFiles, false, forceDtsEmit); ts.performance.mark("afterEmit"); @@ -103390,6 +103391,12 @@ var ts; if (ts.skipTypeChecking(sourceFile, options, program)) { return ts.emptyArray; } + if (isForLinter && sourceFile.scriptKind !== 8) { + return ts.emptyArray; + } + if (!isForLinter && sourceFile.scriptKind === 8) { + return ts.emptyArray; + } var typeChecker = isForLinter ? getLinterTypeChecker() : getTypeChecker(); ts.Debug.assert(!!sourceFile.bindDiagnostics); var isJs = sourceFile.scriptKind === 1 || sourceFile.scriptKind === 2; diff --git a/lib/tsserver.js b/lib/tsserver.js index b578cf4c18..2d14cba6c1 100644 --- a/lib/tsserver.js +++ b/lib/tsserver.js @@ -39144,7 +39144,7 @@ var ts; return withJSDoc(finishNode(node, pos), hasJSDoc); } function isSetLazy(identifier) { - // 1. import lazy { export } from "mod"; + // 1. import lazy { export } from "mod"; // 2. import lazy defaultExport from "mod"; // 3. import lazy defaultExport, { export, /* ... */ } from "mod"; return (identifier === null || identifier === void 0 ? void 0 : identifier.escapedText) === 'lazy' && @@ -124405,7 +124405,8 @@ var ts; // This is because in the -out scenario all files need to be emitted, and therefore all // files need to be type checked. And the way to specify that all files need to be type // checked is to not pass the file to getEmitResolver. - var emitResolver = getTypeChecker().getEmitResolver(ts.outFile(options) ? undefined : sourceFile, cancellationToken); + var checker = (sourceFile === null || sourceFile === void 0 ? void 0 : sourceFile.scriptKind) === 8 /* ScriptKind.ETS */ ? getLinterTypeChecker() : getTypeChecker(); + var emitResolver = checker.getEmitResolver(ts.outFile(options) ? undefined : sourceFile, cancellationToken); ts.performance.mark("beforeEmit"); var emitResult = ts.emitFiles(emitResolver, getEmitHost(writeFileCallback), sourceFile, ts.getTransformers(options, customTransformers, emitOnlyDtsFiles), emitOnlyDtsFiles, /*onlyBuildInfo*/ false, forceDtsEmit); @@ -124517,6 +124518,12 @@ var ts; if (ts.skipTypeChecking(sourceFile, options, program)) { return ts.emptyArray; } + if (isForLinter && sourceFile.scriptKind !== 8 /* ScriptKind.ETS */) { + return ts.emptyArray; + } + if (!isForLinter && sourceFile.scriptKind === 8 /* ScriptKind.ETS */) { + return ts.emptyArray; + } var typeChecker = isForLinter ? getLinterTypeChecker() : getTypeChecker(); ts.Debug.assert(!!sourceFile.bindDiagnostics); var isJs = sourceFile.scriptKind === 1 /* ScriptKind.JS */ || sourceFile.scriptKind === 2 /* ScriptKind.JSX */; diff --git a/lib/tsserverlibrary.js b/lib/tsserverlibrary.js index ebee2765fb..3af22b1579 100644 --- a/lib/tsserverlibrary.js +++ b/lib/tsserverlibrary.js @@ -39143,7 +39143,7 @@ var ts; return withJSDoc(finishNode(node, pos), hasJSDoc); } function isSetLazy(identifier) { - // 1. import lazy { export } from "mod"; + // 1. import lazy { export } from "mod"; // 2. import lazy defaultExport from "mod"; // 3. import lazy defaultExport, { export, /* ... */ } from "mod"; return (identifier === null || identifier === void 0 ? void 0 : identifier.escapedText) === 'lazy' && @@ -124404,7 +124404,8 @@ var ts; // This is because in the -out scenario all files need to be emitted, and therefore all // files need to be type checked. And the way to specify that all files need to be type // checked is to not pass the file to getEmitResolver. - var emitResolver = getTypeChecker().getEmitResolver(ts.outFile(options) ? undefined : sourceFile, cancellationToken); + var checker = (sourceFile === null || sourceFile === void 0 ? void 0 : sourceFile.scriptKind) === 8 /* ScriptKind.ETS */ ? getLinterTypeChecker() : getTypeChecker(); + var emitResolver = checker.getEmitResolver(ts.outFile(options) ? undefined : sourceFile, cancellationToken); ts.performance.mark("beforeEmit"); var emitResult = ts.emitFiles(emitResolver, getEmitHost(writeFileCallback), sourceFile, ts.getTransformers(options, customTransformers, emitOnlyDtsFiles), emitOnlyDtsFiles, /*onlyBuildInfo*/ false, forceDtsEmit); @@ -124516,6 +124517,12 @@ var ts; if (ts.skipTypeChecking(sourceFile, options, program)) { return ts.emptyArray; } + if (isForLinter && sourceFile.scriptKind !== 8 /* ScriptKind.ETS */) { + return ts.emptyArray; + } + if (!isForLinter && sourceFile.scriptKind === 8 /* ScriptKind.ETS */) { + return ts.emptyArray; + } var typeChecker = isForLinter ? getLinterTypeChecker() : getTypeChecker(); ts.Debug.assert(!!sourceFile.bindDiagnostics); var isJs = sourceFile.scriptKind === 1 /* ScriptKind.JS */ || sourceFile.scriptKind === 2 /* ScriptKind.JSX */; diff --git a/lib/typescript.js b/lib/typescript.js index ec37e2214a..4dcf78e3bf 100644 --- a/lib/typescript.js +++ b/lib/typescript.js @@ -39134,7 +39134,7 @@ var ts; return withJSDoc(finishNode(node, pos), hasJSDoc); } function isSetLazy(identifier) { - // 1. import lazy { export } from "mod"; + // 1. import lazy { export } from "mod"; // 2. import lazy defaultExport from "mod"; // 3. import lazy defaultExport, { export, /* ... */ } from "mod"; return (identifier === null || identifier === void 0 ? void 0 : identifier.escapedText) === 'lazy' && @@ -124395,7 +124395,8 @@ var ts; // This is because in the -out scenario all files need to be emitted, and therefore all // files need to be type checked. And the way to specify that all files need to be type // checked is to not pass the file to getEmitResolver. - var emitResolver = getTypeChecker().getEmitResolver(ts.outFile(options) ? undefined : sourceFile, cancellationToken); + var checker = (sourceFile === null || sourceFile === void 0 ? void 0 : sourceFile.scriptKind) === 8 /* ScriptKind.ETS */ ? getLinterTypeChecker() : getTypeChecker(); + var emitResolver = checker.getEmitResolver(ts.outFile(options) ? undefined : sourceFile, cancellationToken); ts.performance.mark("beforeEmit"); var emitResult = ts.emitFiles(emitResolver, getEmitHost(writeFileCallback), sourceFile, ts.getTransformers(options, customTransformers, emitOnlyDtsFiles), emitOnlyDtsFiles, /*onlyBuildInfo*/ false, forceDtsEmit); @@ -124507,6 +124508,12 @@ var ts; if (ts.skipTypeChecking(sourceFile, options, program)) { return ts.emptyArray; } + if (isForLinter && sourceFile.scriptKind !== 8 /* ScriptKind.ETS */) { + return ts.emptyArray; + } + if (!isForLinter && sourceFile.scriptKind === 8 /* ScriptKind.ETS */) { + return ts.emptyArray; + } var typeChecker = isForLinter ? getLinterTypeChecker() : getTypeChecker(); ts.Debug.assert(!!sourceFile.bindDiagnostics); var isJs = sourceFile.scriptKind === 1 /* ScriptKind.JS */ || sourceFile.scriptKind === 2 /* ScriptKind.JSX */; diff --git a/lib/typescriptServices.js b/lib/typescriptServices.js index 70e94c0313..1eb8800d89 100644 --- a/lib/typescriptServices.js +++ b/lib/typescriptServices.js @@ -39134,7 +39134,7 @@ var ts; return withJSDoc(finishNode(node, pos), hasJSDoc); } function isSetLazy(identifier) { - // 1. import lazy { export } from "mod"; + // 1. import lazy { export } from "mod"; // 2. import lazy defaultExport from "mod"; // 3. import lazy defaultExport, { export, /* ... */ } from "mod"; return (identifier === null || identifier === void 0 ? void 0 : identifier.escapedText) === 'lazy' && @@ -124395,7 +124395,8 @@ var ts; // This is because in the -out scenario all files need to be emitted, and therefore all // files need to be type checked. And the way to specify that all files need to be type // checked is to not pass the file to getEmitResolver. - var emitResolver = getTypeChecker().getEmitResolver(ts.outFile(options) ? undefined : sourceFile, cancellationToken); + var checker = (sourceFile === null || sourceFile === void 0 ? void 0 : sourceFile.scriptKind) === 8 /* ScriptKind.ETS */ ? getLinterTypeChecker() : getTypeChecker(); + var emitResolver = checker.getEmitResolver(ts.outFile(options) ? undefined : sourceFile, cancellationToken); ts.performance.mark("beforeEmit"); var emitResult = ts.emitFiles(emitResolver, getEmitHost(writeFileCallback), sourceFile, ts.getTransformers(options, customTransformers, emitOnlyDtsFiles), emitOnlyDtsFiles, /*onlyBuildInfo*/ false, forceDtsEmit); @@ -124507,6 +124508,12 @@ var ts; if (ts.skipTypeChecking(sourceFile, options, program)) { return ts.emptyArray; } + if (isForLinter && sourceFile.scriptKind !== 8 /* ScriptKind.ETS */) { + return ts.emptyArray; + } + if (!isForLinter && sourceFile.scriptKind === 8 /* ScriptKind.ETS */) { + return ts.emptyArray; + } var typeChecker = isForLinter ? getLinterTypeChecker() : getTypeChecker(); ts.Debug.assert(!!sourceFile.bindDiagnostics); var isJs = sourceFile.scriptKind === 1 /* ScriptKind.JS */ || sourceFile.scriptKind === 2 /* ScriptKind.JSX */; diff --git a/lib/typingsInstaller.js b/lib/typingsInstaller.js index d65de5bf86..261347ad14 100644 --- a/lib/typingsInstaller.js +++ b/lib/typingsInstaller.js @@ -39124,7 +39124,7 @@ var ts; return withJSDoc(finishNode(node, pos), hasJSDoc); } function isSetLazy(identifier) { - // 1. import lazy { export } from "mod"; + // 1. import lazy { export } from "mod"; // 2. import lazy defaultExport from "mod"; // 3. import lazy defaultExport, { export, /* ... */ } from "mod"; return (identifier === null || identifier === void 0 ? void 0 : identifier.escapedText) === 'lazy' && @@ -124385,7 +124385,8 @@ var ts; // This is because in the -out scenario all files need to be emitted, and therefore all // files need to be type checked. And the way to specify that all files need to be type // checked is to not pass the file to getEmitResolver. - var emitResolver = getTypeChecker().getEmitResolver(ts.outFile(options) ? undefined : sourceFile, cancellationToken); + var checker = (sourceFile === null || sourceFile === void 0 ? void 0 : sourceFile.scriptKind) === 8 /* ScriptKind.ETS */ ? getLinterTypeChecker() : getTypeChecker(); + var emitResolver = checker.getEmitResolver(ts.outFile(options) ? undefined : sourceFile, cancellationToken); ts.performance.mark("beforeEmit"); var emitResult = ts.emitFiles(emitResolver, getEmitHost(writeFileCallback), sourceFile, ts.getTransformers(options, customTransformers, emitOnlyDtsFiles), emitOnlyDtsFiles, /*onlyBuildInfo*/ false, forceDtsEmit); @@ -124497,6 +124498,12 @@ var ts; if (ts.skipTypeChecking(sourceFile, options, program)) { return ts.emptyArray; } + if (isForLinter && sourceFile.scriptKind !== 8 /* ScriptKind.ETS */) { + return ts.emptyArray; + } + if (!isForLinter && sourceFile.scriptKind === 8 /* ScriptKind.ETS */) { + return ts.emptyArray; + } var typeChecker = isForLinter ? getLinterTypeChecker() : getTypeChecker(); ts.Debug.assert(!!sourceFile.bindDiagnostics); var isJs = sourceFile.scriptKind === 1 /* ScriptKind.JS */ || sourceFile.scriptKind === 2 /* ScriptKind.JSX */; diff --git a/src/compiler/program.ts b/src/compiler/program.ts index d512288cf1..6dd8067c72 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -2157,7 +2157,8 @@ namespace ts { // This is because in the -out scenario all files need to be emitted, and therefore all // files need to be type checked. And the way to specify that all files need to be type // checked is to not pass the file to getEmitResolver. - const emitResolver = getTypeChecker().getEmitResolver(outFile(options) ? undefined : sourceFile, cancellationToken); + const checker = sourceFile?.scriptKind === ScriptKind.ETS ? getLinterTypeChecker() : getTypeChecker(); + const emitResolver = checker.getEmitResolver(outFile(options) ? undefined : sourceFile, cancellationToken); performance.mark("beforeEmit"); @@ -2309,6 +2310,14 @@ namespace ts { return emptyArray; } + if (isForLinter && sourceFile.scriptKind !== ScriptKind.ETS) { + return emptyArray; + } + + if (!isForLinter && sourceFile.scriptKind === ScriptKind.ETS) { + return emptyArray; + } + const typeChecker = isForLinter ? getLinterTypeChecker() : getTypeChecker(); Debug.assert(!!sourceFile.bindDiagnostics); -- Gitee