From 02935fef009fad83bc060f30efeaca5d4473e18a Mon Sep 17 00:00:00 2001 From: xiaopeiyang Date: Fri, 18 Apr 2025 10:44:19 +0800 Subject: [PATCH] Find Record From static Issue: https://gitee.com/openharmony/third_party_typescript/issues/IC24NH Signed-off-by: xiaopeiyang Change-Id: Ia392d260fafbd89ef3e7ba2bd92aa22c1bc55595 --- lib/tsc.js | 21 +++++++++++++++++++++ lib/tsserver.js | 21 +++++++++++++++++++++ lib/tsserverlibrary.js | 21 +++++++++++++++++++++ lib/typescript.js | 21 +++++++++++++++++++++ lib/typescriptServices.js | 21 +++++++++++++++++++++ lib/typingsInstaller.js | 21 +++++++++++++++++++++ src/compiler/checker.ts | 24 ++++++++++++++++++++++++ src/compiler/types.ts | 1 + 8 files changed, 151 insertions(+) diff --git a/lib/tsc.js b/lib/tsc.js index 6b8181ca9e..b02cec7ed1 100644 --- a/lib/tsc.js +++ b/lib/tsc.js @@ -53658,14 +53658,35 @@ var ts; return unknownSymbol; } function resolveTypeReferenceName(typeReference, meaning, ignoreErrors) { + var _a; var name = getTypeReferenceName(typeReference); if (!name) { return unknownSymbol; } var symbol = resolveEntityName(name, meaning, ignoreErrors); + if (ts.isIdentifier(name) && name.escapedText === 'Record') { + var sourceFile = ts.getSourceFileOfNode(typeReference); + var declarationSourceFile = ((_a = symbol === null || symbol === void 0 ? void 0 : symbol.declarations) === null || _a === void 0 ? void 0 : _a[0]) && ts.getSourceFileOfNode(symbol.declarations[0]); + var isFromStatic = sourceFile && declarationSourceFile && isStaticSourceFile(sourceFile) && isDynamicSourceFile(declarationSourceFile); + if (isFromStatic) { + symbol.isStatic = true; + } + } return symbol && symbol !== unknownSymbol ? symbol : ignoreErrors ? unknownSymbol : getUnresolvedSymbolForEntityName(name); } + function isStaticSourceFile(sourceFile) { + if (sourceFile.fileName.includes('static')) { + return true; + } + return false; + } + function isDynamicSourceFile(sourceFile) { + if (sourceFile.fileName.endsWith('/openharmony/ets/build-tools/ets-loader/node_modules/typescript/lib/lib.es5.d.ts')) { + return true; + } + return false; + } function getTypeReferenceType(node, symbol) { if (symbol === unknownSymbol) { return errorType; diff --git a/lib/tsserver.js b/lib/tsserver.js index f595331263..44c14ec356 100644 --- a/lib/tsserver.js +++ b/lib/tsserver.js @@ -64390,14 +64390,35 @@ var ts; return unknownSymbol; } function resolveTypeReferenceName(typeReference, meaning, ignoreErrors) { + var _a; var name = getTypeReferenceName(typeReference); if (!name) { return unknownSymbol; } var symbol = resolveEntityName(name, meaning, ignoreErrors); + if (ts.isIdentifier(name) && name.escapedText === 'Record') { + var sourceFile = ts.getSourceFileOfNode(typeReference); + var declarationSourceFile = ((_a = symbol === null || symbol === void 0 ? void 0 : symbol.declarations) === null || _a === void 0 ? void 0 : _a[0]) && ts.getSourceFileOfNode(symbol.declarations[0]); + var isFromStatic = sourceFile && declarationSourceFile && isStaticSourceFile(sourceFile) && isDynamicSourceFile(declarationSourceFile); + if (isFromStatic) { + symbol.isStatic = true; + } + } return symbol && symbol !== unknownSymbol ? symbol : ignoreErrors ? unknownSymbol : getUnresolvedSymbolForEntityName(name); } + function isStaticSourceFile(sourceFile) { + if (sourceFile.fileName.includes('static')) { + return true; + } + return false; + } + function isDynamicSourceFile(sourceFile) { + if (sourceFile.fileName.endsWith('/openharmony/ets/build-tools/ets-loader/node_modules/typescript/lib/lib.es5.d.ts')) { + return true; + } + return false; + } function getTypeReferenceType(node, symbol) { if (symbol === unknownSymbol) { return errorType; diff --git a/lib/tsserverlibrary.js b/lib/tsserverlibrary.js index f1503e3e90..469ebff906 100644 --- a/lib/tsserverlibrary.js +++ b/lib/tsserverlibrary.js @@ -64389,14 +64389,35 @@ var ts; return unknownSymbol; } function resolveTypeReferenceName(typeReference, meaning, ignoreErrors) { + var _a; var name = getTypeReferenceName(typeReference); if (!name) { return unknownSymbol; } var symbol = resolveEntityName(name, meaning, ignoreErrors); + if (ts.isIdentifier(name) && name.escapedText === 'Record') { + var sourceFile = ts.getSourceFileOfNode(typeReference); + var declarationSourceFile = ((_a = symbol === null || symbol === void 0 ? void 0 : symbol.declarations) === null || _a === void 0 ? void 0 : _a[0]) && ts.getSourceFileOfNode(symbol.declarations[0]); + var isFromStatic = sourceFile && declarationSourceFile && isStaticSourceFile(sourceFile) && isDynamicSourceFile(declarationSourceFile); + if (isFromStatic) { + symbol.isStatic = true; + } + } return symbol && symbol !== unknownSymbol ? symbol : ignoreErrors ? unknownSymbol : getUnresolvedSymbolForEntityName(name); } + function isStaticSourceFile(sourceFile) { + if (sourceFile.fileName.includes('static')) { + return true; + } + return false; + } + function isDynamicSourceFile(sourceFile) { + if (sourceFile.fileName.endsWith('/openharmony/ets/build-tools/ets-loader/node_modules/typescript/lib/lib.es5.d.ts')) { + return true; + } + return false; + } function getTypeReferenceType(node, symbol) { if (symbol === unknownSymbol) { return errorType; diff --git a/lib/typescript.js b/lib/typescript.js index b3b12717bf..37a66474c5 100644 --- a/lib/typescript.js +++ b/lib/typescript.js @@ -64380,14 +64380,35 @@ var ts; return unknownSymbol; } function resolveTypeReferenceName(typeReference, meaning, ignoreErrors) { + var _a; var name = getTypeReferenceName(typeReference); if (!name) { return unknownSymbol; } var symbol = resolveEntityName(name, meaning, ignoreErrors); + if (ts.isIdentifier(name) && name.escapedText === 'Record') { + var sourceFile = ts.getSourceFileOfNode(typeReference); + var declarationSourceFile = ((_a = symbol === null || symbol === void 0 ? void 0 : symbol.declarations) === null || _a === void 0 ? void 0 : _a[0]) && ts.getSourceFileOfNode(symbol.declarations[0]); + var isFromStatic = sourceFile && declarationSourceFile && isStaticSourceFile(sourceFile) && isDynamicSourceFile(declarationSourceFile); + if (isFromStatic) { + symbol.isStatic = true; + } + } return symbol && symbol !== unknownSymbol ? symbol : ignoreErrors ? unknownSymbol : getUnresolvedSymbolForEntityName(name); } + function isStaticSourceFile(sourceFile) { + if (sourceFile.fileName.includes('static')) { + return true; + } + return false; + } + function isDynamicSourceFile(sourceFile) { + if (sourceFile.fileName.endsWith('/openharmony/ets/build-tools/ets-loader/node_modules/typescript/lib/lib.es5.d.ts')) { + return true; + } + return false; + } function getTypeReferenceType(node, symbol) { if (symbol === unknownSymbol) { return errorType; diff --git a/lib/typescriptServices.js b/lib/typescriptServices.js index 2c6f5d45c5..7d23378657 100644 --- a/lib/typescriptServices.js +++ b/lib/typescriptServices.js @@ -64380,14 +64380,35 @@ var ts; return unknownSymbol; } function resolveTypeReferenceName(typeReference, meaning, ignoreErrors) { + var _a; var name = getTypeReferenceName(typeReference); if (!name) { return unknownSymbol; } var symbol = resolveEntityName(name, meaning, ignoreErrors); + if (ts.isIdentifier(name) && name.escapedText === 'Record') { + var sourceFile = ts.getSourceFileOfNode(typeReference); + var declarationSourceFile = ((_a = symbol === null || symbol === void 0 ? void 0 : symbol.declarations) === null || _a === void 0 ? void 0 : _a[0]) && ts.getSourceFileOfNode(symbol.declarations[0]); + var isFromStatic = sourceFile && declarationSourceFile && isStaticSourceFile(sourceFile) && isDynamicSourceFile(declarationSourceFile); + if (isFromStatic) { + symbol.isStatic = true; + } + } return symbol && symbol !== unknownSymbol ? symbol : ignoreErrors ? unknownSymbol : getUnresolvedSymbolForEntityName(name); } + function isStaticSourceFile(sourceFile) { + if (sourceFile.fileName.includes('static')) { + return true; + } + return false; + } + function isDynamicSourceFile(sourceFile) { + if (sourceFile.fileName.endsWith('/openharmony/ets/build-tools/ets-loader/node_modules/typescript/lib/lib.es5.d.ts')) { + return true; + } + return false; + } function getTypeReferenceType(node, symbol) { if (symbol === unknownSymbol) { return errorType; diff --git a/lib/typingsInstaller.js b/lib/typingsInstaller.js index 8ddf991d82..c663b61690 100644 --- a/lib/typingsInstaller.js +++ b/lib/typingsInstaller.js @@ -64370,14 +64370,35 @@ var ts; return unknownSymbol; } function resolveTypeReferenceName(typeReference, meaning, ignoreErrors) { + var _a; var name = getTypeReferenceName(typeReference); if (!name) { return unknownSymbol; } var symbol = resolveEntityName(name, meaning, ignoreErrors); + if (ts.isIdentifier(name) && name.escapedText === 'Record') { + var sourceFile = ts.getSourceFileOfNode(typeReference); + var declarationSourceFile = ((_a = symbol === null || symbol === void 0 ? void 0 : symbol.declarations) === null || _a === void 0 ? void 0 : _a[0]) && ts.getSourceFileOfNode(symbol.declarations[0]); + var isFromStatic = sourceFile && declarationSourceFile && isStaticSourceFile(sourceFile) && isDynamicSourceFile(declarationSourceFile); + if (isFromStatic) { + symbol.isStatic = true; + } + } return symbol && symbol !== unknownSymbol ? symbol : ignoreErrors ? unknownSymbol : getUnresolvedSymbolForEntityName(name); } + function isStaticSourceFile(sourceFile) { + if (sourceFile.fileName.includes('static')) { + return true; + } + return false; + } + function isDynamicSourceFile(sourceFile) { + if (sourceFile.fileName.endsWith('/openharmony/ets/build-tools/ets-loader/node_modules/typescript/lib/lib.es5.d.ts')) { + return true; + } + return false; + } function getTypeReferenceType(node, symbol) { if (symbol === unknownSymbol) { return errorType; diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 0508afc088..8bfcd7c369 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -14125,10 +14125,34 @@ namespace ts { return unknownSymbol; } const symbol = resolveEntityName(name, meaning, ignoreErrors); + + if (isIdentifier(name) && name.escapedText === 'Record') { + const sourceFile = getSourceFileOfNode(typeReference); + const declarationSourceFile = symbol?.declarations?.[0] && getSourceFileOfNode(symbol.declarations[0]); + const isFromStatic = sourceFile && declarationSourceFile && isStaticSourceFile(sourceFile) && isDynamicSourceFile(declarationSourceFile); + if (isFromStatic) { + symbol.isStatic = true; + } + } + return symbol && symbol !== unknownSymbol ? symbol : ignoreErrors ? unknownSymbol : getUnresolvedSymbolForEntityName(name); } + function isStaticSourceFile(sourceFile: SourceFile): boolean { + if (sourceFile.fileName.includes('static')) { + return true; + } + return false; + } + + function isDynamicSourceFile(sourceFile: SourceFile): boolean { + if (sourceFile.fileName.endsWith('/openharmony/ets/build-tools/ets-loader/node_modules/typescript/lib/lib.es5.d.ts')) { + return true; + } + return false; + } + function getTypeReferenceType(node: NodeWithTypeArguments, symbol: Symbol): Type { if (symbol === unknownSymbol) { return errorType; diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 6146439dcf..c4ae4ad543 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -5503,6 +5503,7 @@ namespace ts { /* @internal */ isReplaceableByMethod?: boolean; // Can this Javascript class property be replaced by a method symbol? /* @internal */ isAssigned?: boolean; // True if the symbol is a parameter with assignments /* @internal */ assignmentDeclarationMembers?: ESMap; // detected late-bound assignment declarations associated with the symbol + /* @internal */ isStatic?: boolean; // If the symbol is from static file } /* @internal */ -- Gitee