fix validate @Component member type for classA | null| undefined.

Signed-off-by: lihong <lihong67@huawei.com>
Change-Id: Ia7daa13f1643280c3bf079655026837bc09a8ca2
This commit is contained in:
lihong 2024-07-02 20:54:52 +08:00
parent 9c766b063b
commit 1683e70a3c
3 changed files with 5 additions and 2 deletions

View File

@ -354,12 +354,14 @@ async function transform(code: string, id: string) {
// init TypeChecker to run binding
globalProgram.checker = tsProgram.getTypeChecker();
globalProgram.strictChecker = tsProgram.getLinterTypeChecker();
targetSourceFile = tsProgram.getSourceFile(id)!;
storedFileInfo.reUseProgram = false;
collectAllFiles(tsProgram);
} else {
if (!storedFileInfo.reUseProgram) {
globalProgram.checker = globalProgram.program.getTypeChecker();
globalProgram.strictChecker = globalProgram.program.getLinterTypeChecker();
}
storedFileInfo.reUseProgram = true;
}

View File

@ -464,8 +464,8 @@ function isForbiddenTypeToComponentV1(type: ts.Type): boolean {
function isForbiddenAssignToComponentV2(item: ts.PropertyAssignment, itemName: string,
info: ChildAndParentComponentInfo): boolean {
if (!info.parentStructInfo.isComponentV2 && info.updatePropsDecoratorsV2.includes(itemName) &&
isObervedProperty(item.initializer, info) && globalProgram.checker) {
const type: ts.Type = globalProgram.checker.getTypeAtLocation(item.initializer);
isObervedProperty(item.initializer, info) && globalProgram.strictChecker) {
const type: ts.Type = globalProgram.strictChecker.getTypeAtLocation(item.initializer);
return !isAllowedTypeToComponentV2(type);
}
return false;

View File

@ -963,6 +963,7 @@ class SpecialArkTSFileInfo extends TSFileInfo {
export function setChecker(): void {
if (globalProgram.program) {
globalProgram.checker = globalProgram.program.getTypeChecker();
globalProgram.strictChecker = globalProgram.program.getLinterTypeChecker();
} else if (globalProgram.watchProgram) {
globalProgram.checker = globalProgram.watchProgram.getCurrentProgram().getProgram().getTypeChecker();
}