Fix unknow strict mode error

Issue: https://gitee.com/openharmony/third_party_typescript/issues/IANLIC

Signed-off-by: caiy <caiyu30@huawei.com>
This commit is contained in:
c30058867 2024-08-30 12:03:54 +08:00
parent de96c25960
commit 696a00f5ff
18 changed files with 196 additions and 92 deletions

View File

@ -194705,7 +194705,7 @@ var ts;
return true;
};
LibraryTypeCallDiagnosticChecker.checkMessageChain = function (chain, inLibCall) {
if (chain.code == LibraryTypeCallDiagnosticCheckerNamespace.TYPE_0_IS_NOT_ASSIGNABLE_TO_TYPE_1_ERROR_CODE) {
if (chain.code === LibraryTypeCallDiagnosticCheckerNamespace.TYPE_0_IS_NOT_ASSIGNABLE_TO_TYPE_1_ERROR_CODE) {
if (chain.messageText.match(LibraryTypeCallDiagnosticCheckerNamespace.TYPE_UNKNOWN_IS_NOT_ASSIGNABLE_TO_TYPE_1_RE)) {
return ErrorType.UNKNOW;
}
@ -194716,7 +194716,7 @@ var ts;
return ErrorType.NULL;
}
}
if (chain.code == LibraryTypeCallDiagnosticCheckerNamespace.ARGUMENT_OF_TYPE_0_IS_NOT_ASSIGNABLE_TO_PARAMETER_OF_TYPE_1_ERROR_CODE) {
if (chain.code === LibraryTypeCallDiagnosticCheckerNamespace.ARGUMENT_OF_TYPE_0_IS_NOT_ASSIGNABLE_TO_PARAMETER_OF_TYPE_1_ERROR_CODE) {
if (inLibCall && chain.messageText.match(LibraryTypeCallDiagnosticCheckerNamespace.ARGUMENT_OF_TYPE_UNDEFINED_IS_NOT_ASSIGNABLE_TO_PARAMETER_OF_TYPE_1_RE)) {
return ErrorType.UNDEFINED;
}
@ -194724,7 +194724,7 @@ var ts;
return ErrorType.NULL;
}
}
return chain.next == undefined ? ErrorType.NO_ERROR : LibraryTypeCallDiagnosticChecker.checkMessageChain(chain.next[0], inLibCall);
return chain.next === undefined ? ErrorType.NO_ERROR : LibraryTypeCallDiagnosticChecker.checkMessageChain(chain.next[0], inLibCall);
};
;
LibraryTypeCallDiagnosticChecker.prototype.checkFilteredDiagnosticMessages = function (msgText) {
@ -194805,34 +194805,43 @@ var ts;
* TypeScriptLinter. StrictDiagnosticCache can only keep by white list DiagnosticMessageChain type error and its matching success string type errors
*/
var textSet = new ts.Set();
var unknownSet = new ts.Set();
diagnosticMessageChainArr.forEach(function (item) {
var diagnosticMessageChain = item.messageText;
var isAllowFilter = LibraryTypeCallDiagnosticChecker.checkMessageChain(diagnosticMessageChain, true);
if (isAllowFilter === ErrorType.UNKNOW) {
LibraryTypeCallDiagnosticChecker.collectDiagnosticMessage(diagnosticMessageChain, unknownSet);
ArkTSLinter_1_1.TypeScriptLinter.unknowDiagnosticCache.add(item);
return;
}
if (isAllowFilter !== ErrorType.NO_ERROR) {
var isTypeError = diagnosticMessageChain.code === LibraryTypeCallDiagnosticCheckerNamespace.TYPE_0_IS_NOT_ASSIGNABLE_TO_TYPE_1_ERROR_CODE;
var typeText = isTypeError ?
diagnosticMessageChain.messageText :
diagnosticMessageChain.messageText.replace(LibraryTypeCallDiagnosticCheckerNamespace.ARGUMENT_OF_TYPE, LibraryTypeCallDiagnosticCheckerNamespace.TYPE)
.replace(LibraryTypeCallDiagnosticCheckerNamespace.IS_NOT_ASSIGNABLE_TO_PARAMETER_OF_TYPE, LibraryTypeCallDiagnosticCheckerNamespace.IS_NOT_ASSIGNABLE_TO_TYPE);
var argumentText = isTypeError ?
diagnosticMessageChain.messageText.replace(LibraryTypeCallDiagnosticCheckerNamespace.TYPE, LibraryTypeCallDiagnosticCheckerNamespace.ARGUMENT_OF_TYPE)
.replace(LibraryTypeCallDiagnosticCheckerNamespace.IS_NOT_ASSIGNABLE_TO_TYPE, LibraryTypeCallDiagnosticCheckerNamespace.IS_NOT_ASSIGNABLE_TO_PARAMETER_OF_TYPE) :
diagnosticMessageChain.messageText;
textSet.add(typeText);
textSet.add(argumentText);
LibraryTypeCallDiagnosticChecker.collectDiagnosticMessage(diagnosticMessageChain, textSet);
ArkTSLinter_1_1.TypeScriptLinter.strictDiagnosticCache.add(item);
}
});
strictArr.forEach(function (item) {
if (textSet.has(item.messageText)) {
var messageText = item.messageText;
if (unknownSet.has(messageText)) {
ArkTSLinter_1_1.TypeScriptLinter.unknowDiagnosticCache.add(item);
}
else if (textSet.has(messageText)) {
ArkTSLinter_1_1.TypeScriptLinter.strictDiagnosticCache.add(item);
}
});
};
LibraryTypeCallDiagnosticChecker.collectDiagnosticMessage = function (diagnosticMessageChain, textSet) {
var isTypeError = diagnosticMessageChain.code === LibraryTypeCallDiagnosticCheckerNamespace.TYPE_0_IS_NOT_ASSIGNABLE_TO_TYPE_1_ERROR_CODE;
var typeText = isTypeError ?
diagnosticMessageChain.messageText :
diagnosticMessageChain.messageText.replace(LibraryTypeCallDiagnosticCheckerNamespace.ARGUMENT_OF_TYPE, LibraryTypeCallDiagnosticCheckerNamespace.TYPE)
.replace(LibraryTypeCallDiagnosticCheckerNamespace.IS_NOT_ASSIGNABLE_TO_PARAMETER_OF_TYPE, LibraryTypeCallDiagnosticCheckerNamespace.IS_NOT_ASSIGNABLE_TO_TYPE);
var argumentText = isTypeError ?
diagnosticMessageChain.messageText.replace(LibraryTypeCallDiagnosticCheckerNamespace.TYPE, LibraryTypeCallDiagnosticCheckerNamespace.ARGUMENT_OF_TYPE)
.replace(LibraryTypeCallDiagnosticCheckerNamespace.IS_NOT_ASSIGNABLE_TO_TYPE, LibraryTypeCallDiagnosticCheckerNamespace.IS_NOT_ASSIGNABLE_TO_PARAMETER_OF_TYPE) :
diagnosticMessageChain.messageText;
textSet.add(typeText);
textSet.add(argumentText);
};
return LibraryTypeCallDiagnosticChecker;
}());
LibraryTypeCallDiagnosticCheckerNamespace.LibraryTypeCallDiagnosticChecker = LibraryTypeCallDiagnosticChecker;

View File

@ -13117,6 +13117,7 @@ declare namespace ts {
checkFilteredDiagnosticMessages(msgText: ts.DiagnosticMessageChain | string): boolean;
checkDiagnosticMessage(msgText: string | ts.DiagnosticMessageChain): boolean;
static rebuildTscDiagnostics(tscStrictDiagnostics: Map<Diagnostic[]>): void;
static collectDiagnosticMessage(diagnosticMessageChain: DiagnosticMessageChain, textSet: Set<string>): void;
}
}
}

View File

@ -194450,7 +194450,7 @@ var ts;
return true;
};
LibraryTypeCallDiagnosticChecker.checkMessageChain = function (chain, inLibCall) {
if (chain.code == LibraryTypeCallDiagnosticCheckerNamespace.TYPE_0_IS_NOT_ASSIGNABLE_TO_TYPE_1_ERROR_CODE) {
if (chain.code === LibraryTypeCallDiagnosticCheckerNamespace.TYPE_0_IS_NOT_ASSIGNABLE_TO_TYPE_1_ERROR_CODE) {
if (chain.messageText.match(LibraryTypeCallDiagnosticCheckerNamespace.TYPE_UNKNOWN_IS_NOT_ASSIGNABLE_TO_TYPE_1_RE)) {
return ErrorType.UNKNOW;
}
@ -194461,7 +194461,7 @@ var ts;
return ErrorType.NULL;
}
}
if (chain.code == LibraryTypeCallDiagnosticCheckerNamespace.ARGUMENT_OF_TYPE_0_IS_NOT_ASSIGNABLE_TO_PARAMETER_OF_TYPE_1_ERROR_CODE) {
if (chain.code === LibraryTypeCallDiagnosticCheckerNamespace.ARGUMENT_OF_TYPE_0_IS_NOT_ASSIGNABLE_TO_PARAMETER_OF_TYPE_1_ERROR_CODE) {
if (inLibCall && chain.messageText.match(LibraryTypeCallDiagnosticCheckerNamespace.ARGUMENT_OF_TYPE_UNDEFINED_IS_NOT_ASSIGNABLE_TO_PARAMETER_OF_TYPE_1_RE)) {
return ErrorType.UNDEFINED;
}
@ -194469,7 +194469,7 @@ var ts;
return ErrorType.NULL;
}
}
return chain.next == undefined ? ErrorType.NO_ERROR : LibraryTypeCallDiagnosticChecker.checkMessageChain(chain.next[0], inLibCall);
return chain.next === undefined ? ErrorType.NO_ERROR : LibraryTypeCallDiagnosticChecker.checkMessageChain(chain.next[0], inLibCall);
};
;
LibraryTypeCallDiagnosticChecker.prototype.checkFilteredDiagnosticMessages = function (msgText) {
@ -194550,34 +194550,43 @@ var ts;
* TypeScriptLinter. StrictDiagnosticCache can only keep by white list DiagnosticMessageChain type error and its matching success string type errors
*/
var textSet = new ts.Set();
var unknownSet = new ts.Set();
diagnosticMessageChainArr.forEach(function (item) {
var diagnosticMessageChain = item.messageText;
var isAllowFilter = LibraryTypeCallDiagnosticChecker.checkMessageChain(diagnosticMessageChain, true);
if (isAllowFilter === ErrorType.UNKNOW) {
LibraryTypeCallDiagnosticChecker.collectDiagnosticMessage(diagnosticMessageChain, unknownSet);
ArkTSLinter_1_1.TypeScriptLinter.unknowDiagnosticCache.add(item);
return;
}
if (isAllowFilter !== ErrorType.NO_ERROR) {
var isTypeError = diagnosticMessageChain.code === LibraryTypeCallDiagnosticCheckerNamespace.TYPE_0_IS_NOT_ASSIGNABLE_TO_TYPE_1_ERROR_CODE;
var typeText = isTypeError ?
diagnosticMessageChain.messageText :
diagnosticMessageChain.messageText.replace(LibraryTypeCallDiagnosticCheckerNamespace.ARGUMENT_OF_TYPE, LibraryTypeCallDiagnosticCheckerNamespace.TYPE)
.replace(LibraryTypeCallDiagnosticCheckerNamespace.IS_NOT_ASSIGNABLE_TO_PARAMETER_OF_TYPE, LibraryTypeCallDiagnosticCheckerNamespace.IS_NOT_ASSIGNABLE_TO_TYPE);
var argumentText = isTypeError ?
diagnosticMessageChain.messageText.replace(LibraryTypeCallDiagnosticCheckerNamespace.TYPE, LibraryTypeCallDiagnosticCheckerNamespace.ARGUMENT_OF_TYPE)
.replace(LibraryTypeCallDiagnosticCheckerNamespace.IS_NOT_ASSIGNABLE_TO_TYPE, LibraryTypeCallDiagnosticCheckerNamespace.IS_NOT_ASSIGNABLE_TO_PARAMETER_OF_TYPE) :
diagnosticMessageChain.messageText;
textSet.add(typeText);
textSet.add(argumentText);
LibraryTypeCallDiagnosticChecker.collectDiagnosticMessage(diagnosticMessageChain, textSet);
ArkTSLinter_1_1.TypeScriptLinter.strictDiagnosticCache.add(item);
}
});
strictArr.forEach(function (item) {
if (textSet.has(item.messageText)) {
var messageText = item.messageText;
if (unknownSet.has(messageText)) {
ArkTSLinter_1_1.TypeScriptLinter.unknowDiagnosticCache.add(item);
}
else if (textSet.has(messageText)) {
ArkTSLinter_1_1.TypeScriptLinter.strictDiagnosticCache.add(item);
}
});
};
LibraryTypeCallDiagnosticChecker.collectDiagnosticMessage = function (diagnosticMessageChain, textSet) {
var isTypeError = diagnosticMessageChain.code === LibraryTypeCallDiagnosticCheckerNamespace.TYPE_0_IS_NOT_ASSIGNABLE_TO_TYPE_1_ERROR_CODE;
var typeText = isTypeError ?
diagnosticMessageChain.messageText :
diagnosticMessageChain.messageText.replace(LibraryTypeCallDiagnosticCheckerNamespace.ARGUMENT_OF_TYPE, LibraryTypeCallDiagnosticCheckerNamespace.TYPE)
.replace(LibraryTypeCallDiagnosticCheckerNamespace.IS_NOT_ASSIGNABLE_TO_PARAMETER_OF_TYPE, LibraryTypeCallDiagnosticCheckerNamespace.IS_NOT_ASSIGNABLE_TO_TYPE);
var argumentText = isTypeError ?
diagnosticMessageChain.messageText.replace(LibraryTypeCallDiagnosticCheckerNamespace.TYPE, LibraryTypeCallDiagnosticCheckerNamespace.ARGUMENT_OF_TYPE)
.replace(LibraryTypeCallDiagnosticCheckerNamespace.IS_NOT_ASSIGNABLE_TO_TYPE, LibraryTypeCallDiagnosticCheckerNamespace.IS_NOT_ASSIGNABLE_TO_PARAMETER_OF_TYPE) :
diagnosticMessageChain.messageText;
textSet.add(typeText);
textSet.add(argumentText);
};
return LibraryTypeCallDiagnosticChecker;
}());
LibraryTypeCallDiagnosticCheckerNamespace.LibraryTypeCallDiagnosticChecker = LibraryTypeCallDiagnosticChecker;

1
lib/typescript.d.ts vendored
View File

@ -9171,6 +9171,7 @@ declare namespace ts {
checkFilteredDiagnosticMessages(msgText: ts.DiagnosticMessageChain | string): boolean;
checkDiagnosticMessage(msgText: string | ts.DiagnosticMessageChain): boolean;
static rebuildTscDiagnostics(tscStrictDiagnostics: Map<Diagnostic[]>): void;
static collectDiagnosticMessage(diagnosticMessageChain: DiagnosticMessageChain, textSet: Set<string>): void;
}
}
}

View File

@ -183544,7 +183544,7 @@ var ts;
return true;
};
LibraryTypeCallDiagnosticChecker.checkMessageChain = function (chain, inLibCall) {
if (chain.code == LibraryTypeCallDiagnosticCheckerNamespace.TYPE_0_IS_NOT_ASSIGNABLE_TO_TYPE_1_ERROR_CODE) {
if (chain.code === LibraryTypeCallDiagnosticCheckerNamespace.TYPE_0_IS_NOT_ASSIGNABLE_TO_TYPE_1_ERROR_CODE) {
if (chain.messageText.match(LibraryTypeCallDiagnosticCheckerNamespace.TYPE_UNKNOWN_IS_NOT_ASSIGNABLE_TO_TYPE_1_RE)) {
return ErrorType.UNKNOW;
}
@ -183555,7 +183555,7 @@ var ts;
return ErrorType.NULL;
}
}
if (chain.code == LibraryTypeCallDiagnosticCheckerNamespace.ARGUMENT_OF_TYPE_0_IS_NOT_ASSIGNABLE_TO_PARAMETER_OF_TYPE_1_ERROR_CODE) {
if (chain.code === LibraryTypeCallDiagnosticCheckerNamespace.ARGUMENT_OF_TYPE_0_IS_NOT_ASSIGNABLE_TO_PARAMETER_OF_TYPE_1_ERROR_CODE) {
if (inLibCall && chain.messageText.match(LibraryTypeCallDiagnosticCheckerNamespace.ARGUMENT_OF_TYPE_UNDEFINED_IS_NOT_ASSIGNABLE_TO_PARAMETER_OF_TYPE_1_RE)) {
return ErrorType.UNDEFINED;
}
@ -183563,7 +183563,7 @@ var ts;
return ErrorType.NULL;
}
}
return chain.next == undefined ? ErrorType.NO_ERROR : LibraryTypeCallDiagnosticChecker.checkMessageChain(chain.next[0], inLibCall);
return chain.next === undefined ? ErrorType.NO_ERROR : LibraryTypeCallDiagnosticChecker.checkMessageChain(chain.next[0], inLibCall);
};
;
LibraryTypeCallDiagnosticChecker.prototype.checkFilteredDiagnosticMessages = function (msgText) {
@ -183644,34 +183644,43 @@ var ts;
* TypeScriptLinter. StrictDiagnosticCache can only keep by white list DiagnosticMessageChain type error and its matching success string type errors
*/
var textSet = new ts.Set();
var unknownSet = new ts.Set();
diagnosticMessageChainArr.forEach(function (item) {
var diagnosticMessageChain = item.messageText;
var isAllowFilter = LibraryTypeCallDiagnosticChecker.checkMessageChain(diagnosticMessageChain, true);
if (isAllowFilter === ErrorType.UNKNOW) {
LibraryTypeCallDiagnosticChecker.collectDiagnosticMessage(diagnosticMessageChain, unknownSet);
ArkTSLinter_1_1.TypeScriptLinter.unknowDiagnosticCache.add(item);
return;
}
if (isAllowFilter !== ErrorType.NO_ERROR) {
var isTypeError = diagnosticMessageChain.code === LibraryTypeCallDiagnosticCheckerNamespace.TYPE_0_IS_NOT_ASSIGNABLE_TO_TYPE_1_ERROR_CODE;
var typeText = isTypeError ?
diagnosticMessageChain.messageText :
diagnosticMessageChain.messageText.replace(LibraryTypeCallDiagnosticCheckerNamespace.ARGUMENT_OF_TYPE, LibraryTypeCallDiagnosticCheckerNamespace.TYPE)
.replace(LibraryTypeCallDiagnosticCheckerNamespace.IS_NOT_ASSIGNABLE_TO_PARAMETER_OF_TYPE, LibraryTypeCallDiagnosticCheckerNamespace.IS_NOT_ASSIGNABLE_TO_TYPE);
var argumentText = isTypeError ?
diagnosticMessageChain.messageText.replace(LibraryTypeCallDiagnosticCheckerNamespace.TYPE, LibraryTypeCallDiagnosticCheckerNamespace.ARGUMENT_OF_TYPE)
.replace(LibraryTypeCallDiagnosticCheckerNamespace.IS_NOT_ASSIGNABLE_TO_TYPE, LibraryTypeCallDiagnosticCheckerNamespace.IS_NOT_ASSIGNABLE_TO_PARAMETER_OF_TYPE) :
diagnosticMessageChain.messageText;
textSet.add(typeText);
textSet.add(argumentText);
LibraryTypeCallDiagnosticChecker.collectDiagnosticMessage(diagnosticMessageChain, textSet);
ArkTSLinter_1_1.TypeScriptLinter.strictDiagnosticCache.add(item);
}
});
strictArr.forEach(function (item) {
if (textSet.has(item.messageText)) {
var messageText = item.messageText;
if (unknownSet.has(messageText)) {
ArkTSLinter_1_1.TypeScriptLinter.unknowDiagnosticCache.add(item);
}
else if (textSet.has(messageText)) {
ArkTSLinter_1_1.TypeScriptLinter.strictDiagnosticCache.add(item);
}
});
};
LibraryTypeCallDiagnosticChecker.collectDiagnosticMessage = function (diagnosticMessageChain, textSet) {
var isTypeError = diagnosticMessageChain.code === LibraryTypeCallDiagnosticCheckerNamespace.TYPE_0_IS_NOT_ASSIGNABLE_TO_TYPE_1_ERROR_CODE;
var typeText = isTypeError ?
diagnosticMessageChain.messageText :
diagnosticMessageChain.messageText.replace(LibraryTypeCallDiagnosticCheckerNamespace.ARGUMENT_OF_TYPE, LibraryTypeCallDiagnosticCheckerNamespace.TYPE)
.replace(LibraryTypeCallDiagnosticCheckerNamespace.IS_NOT_ASSIGNABLE_TO_PARAMETER_OF_TYPE, LibraryTypeCallDiagnosticCheckerNamespace.IS_NOT_ASSIGNABLE_TO_TYPE);
var argumentText = isTypeError ?
diagnosticMessageChain.messageText.replace(LibraryTypeCallDiagnosticCheckerNamespace.TYPE, LibraryTypeCallDiagnosticCheckerNamespace.ARGUMENT_OF_TYPE)
.replace(LibraryTypeCallDiagnosticCheckerNamespace.IS_NOT_ASSIGNABLE_TO_TYPE, LibraryTypeCallDiagnosticCheckerNamespace.IS_NOT_ASSIGNABLE_TO_PARAMETER_OF_TYPE) :
diagnosticMessageChain.messageText;
textSet.add(typeText);
textSet.add(argumentText);
};
return LibraryTypeCallDiagnosticChecker;
}());
LibraryTypeCallDiagnosticCheckerNamespace.LibraryTypeCallDiagnosticChecker = LibraryTypeCallDiagnosticChecker;

View File

@ -9171,6 +9171,7 @@ declare namespace ts {
checkFilteredDiagnosticMessages(msgText: ts.DiagnosticMessageChain | string): boolean;
checkDiagnosticMessage(msgText: string | ts.DiagnosticMessageChain): boolean;
static rebuildTscDiagnostics(tscStrictDiagnostics: Map<Diagnostic[]>): void;
static collectDiagnosticMessage(diagnosticMessageChain: DiagnosticMessageChain, textSet: Set<string>): void;
}
}
}

View File

@ -183544,7 +183544,7 @@ var ts;
return true;
};
LibraryTypeCallDiagnosticChecker.checkMessageChain = function (chain, inLibCall) {
if (chain.code == LibraryTypeCallDiagnosticCheckerNamespace.TYPE_0_IS_NOT_ASSIGNABLE_TO_TYPE_1_ERROR_CODE) {
if (chain.code === LibraryTypeCallDiagnosticCheckerNamespace.TYPE_0_IS_NOT_ASSIGNABLE_TO_TYPE_1_ERROR_CODE) {
if (chain.messageText.match(LibraryTypeCallDiagnosticCheckerNamespace.TYPE_UNKNOWN_IS_NOT_ASSIGNABLE_TO_TYPE_1_RE)) {
return ErrorType.UNKNOW;
}
@ -183555,7 +183555,7 @@ var ts;
return ErrorType.NULL;
}
}
if (chain.code == LibraryTypeCallDiagnosticCheckerNamespace.ARGUMENT_OF_TYPE_0_IS_NOT_ASSIGNABLE_TO_PARAMETER_OF_TYPE_1_ERROR_CODE) {
if (chain.code === LibraryTypeCallDiagnosticCheckerNamespace.ARGUMENT_OF_TYPE_0_IS_NOT_ASSIGNABLE_TO_PARAMETER_OF_TYPE_1_ERROR_CODE) {
if (inLibCall && chain.messageText.match(LibraryTypeCallDiagnosticCheckerNamespace.ARGUMENT_OF_TYPE_UNDEFINED_IS_NOT_ASSIGNABLE_TO_PARAMETER_OF_TYPE_1_RE)) {
return ErrorType.UNDEFINED;
}
@ -183563,7 +183563,7 @@ var ts;
return ErrorType.NULL;
}
}
return chain.next == undefined ? ErrorType.NO_ERROR : LibraryTypeCallDiagnosticChecker.checkMessageChain(chain.next[0], inLibCall);
return chain.next === undefined ? ErrorType.NO_ERROR : LibraryTypeCallDiagnosticChecker.checkMessageChain(chain.next[0], inLibCall);
};
;
LibraryTypeCallDiagnosticChecker.prototype.checkFilteredDiagnosticMessages = function (msgText) {
@ -183644,34 +183644,43 @@ var ts;
* TypeScriptLinter. StrictDiagnosticCache can only keep by white list DiagnosticMessageChain type error and its matching success string type errors
*/
var textSet = new ts.Set();
var unknownSet = new ts.Set();
diagnosticMessageChainArr.forEach(function (item) {
var diagnosticMessageChain = item.messageText;
var isAllowFilter = LibraryTypeCallDiagnosticChecker.checkMessageChain(diagnosticMessageChain, true);
if (isAllowFilter === ErrorType.UNKNOW) {
LibraryTypeCallDiagnosticChecker.collectDiagnosticMessage(diagnosticMessageChain, unknownSet);
ArkTSLinter_1_1.TypeScriptLinter.unknowDiagnosticCache.add(item);
return;
}
if (isAllowFilter !== ErrorType.NO_ERROR) {
var isTypeError = diagnosticMessageChain.code === LibraryTypeCallDiagnosticCheckerNamespace.TYPE_0_IS_NOT_ASSIGNABLE_TO_TYPE_1_ERROR_CODE;
var typeText = isTypeError ?
diagnosticMessageChain.messageText :
diagnosticMessageChain.messageText.replace(LibraryTypeCallDiagnosticCheckerNamespace.ARGUMENT_OF_TYPE, LibraryTypeCallDiagnosticCheckerNamespace.TYPE)
.replace(LibraryTypeCallDiagnosticCheckerNamespace.IS_NOT_ASSIGNABLE_TO_PARAMETER_OF_TYPE, LibraryTypeCallDiagnosticCheckerNamespace.IS_NOT_ASSIGNABLE_TO_TYPE);
var argumentText = isTypeError ?
diagnosticMessageChain.messageText.replace(LibraryTypeCallDiagnosticCheckerNamespace.TYPE, LibraryTypeCallDiagnosticCheckerNamespace.ARGUMENT_OF_TYPE)
.replace(LibraryTypeCallDiagnosticCheckerNamespace.IS_NOT_ASSIGNABLE_TO_TYPE, LibraryTypeCallDiagnosticCheckerNamespace.IS_NOT_ASSIGNABLE_TO_PARAMETER_OF_TYPE) :
diagnosticMessageChain.messageText;
textSet.add(typeText);
textSet.add(argumentText);
LibraryTypeCallDiagnosticChecker.collectDiagnosticMessage(diagnosticMessageChain, textSet);
ArkTSLinter_1_1.TypeScriptLinter.strictDiagnosticCache.add(item);
}
});
strictArr.forEach(function (item) {
if (textSet.has(item.messageText)) {
var messageText = item.messageText;
if (unknownSet.has(messageText)) {
ArkTSLinter_1_1.TypeScriptLinter.unknowDiagnosticCache.add(item);
}
else if (textSet.has(messageText)) {
ArkTSLinter_1_1.TypeScriptLinter.strictDiagnosticCache.add(item);
}
});
};
LibraryTypeCallDiagnosticChecker.collectDiagnosticMessage = function (diagnosticMessageChain, textSet) {
var isTypeError = diagnosticMessageChain.code === LibraryTypeCallDiagnosticCheckerNamespace.TYPE_0_IS_NOT_ASSIGNABLE_TO_TYPE_1_ERROR_CODE;
var typeText = isTypeError ?
diagnosticMessageChain.messageText :
diagnosticMessageChain.messageText.replace(LibraryTypeCallDiagnosticCheckerNamespace.ARGUMENT_OF_TYPE, LibraryTypeCallDiagnosticCheckerNamespace.TYPE)
.replace(LibraryTypeCallDiagnosticCheckerNamespace.IS_NOT_ASSIGNABLE_TO_PARAMETER_OF_TYPE, LibraryTypeCallDiagnosticCheckerNamespace.IS_NOT_ASSIGNABLE_TO_TYPE);
var argumentText = isTypeError ?
diagnosticMessageChain.messageText.replace(LibraryTypeCallDiagnosticCheckerNamespace.TYPE, LibraryTypeCallDiagnosticCheckerNamespace.ARGUMENT_OF_TYPE)
.replace(LibraryTypeCallDiagnosticCheckerNamespace.IS_NOT_ASSIGNABLE_TO_TYPE, LibraryTypeCallDiagnosticCheckerNamespace.IS_NOT_ASSIGNABLE_TO_PARAMETER_OF_TYPE) :
diagnosticMessageChain.messageText;
textSet.add(typeText);
textSet.add(argumentText);
};
return LibraryTypeCallDiagnosticChecker;
}());
LibraryTypeCallDiagnosticCheckerNamespace.LibraryTypeCallDiagnosticChecker = LibraryTypeCallDiagnosticChecker;

View File

@ -68,7 +68,7 @@ export class LibraryTypeCallDiagnosticChecker implements DiagnosticChecker {
}
static checkMessageChain(chain: ts.DiagnosticMessageChain, inLibCall: boolean): ErrorType {
if (chain.code == TYPE_0_IS_NOT_ASSIGNABLE_TO_TYPE_1_ERROR_CODE) {
if (chain.code === TYPE_0_IS_NOT_ASSIGNABLE_TO_TYPE_1_ERROR_CODE) {
if (chain.messageText.match(TYPE_UNKNOWN_IS_NOT_ASSIGNABLE_TO_TYPE_1_RE)) {
return ErrorType.UNKNOW;
}
@ -79,7 +79,7 @@ export class LibraryTypeCallDiagnosticChecker implements DiagnosticChecker {
return ErrorType.NULL;
}
}
if (chain.code == ARGUMENT_OF_TYPE_0_IS_NOT_ASSIGNABLE_TO_PARAMETER_OF_TYPE_1_ERROR_CODE) {
if (chain.code === ARGUMENT_OF_TYPE_0_IS_NOT_ASSIGNABLE_TO_PARAMETER_OF_TYPE_1_ERROR_CODE) {
if (inLibCall && chain.messageText.match(ARGUMENT_OF_TYPE_UNDEFINED_IS_NOT_ASSIGNABLE_TO_PARAMETER_OF_TYPE_1_RE)) {
return ErrorType.UNDEFINED;
}
@ -87,7 +87,7 @@ export class LibraryTypeCallDiagnosticChecker implements DiagnosticChecker {
return ErrorType.NULL;
}
}
return chain.next == undefined ? ErrorType.NO_ERROR : LibraryTypeCallDiagnosticChecker.checkMessageChain(chain.next[0], inLibCall);
return chain.next === undefined ? ErrorType.NO_ERROR : LibraryTypeCallDiagnosticChecker.checkMessageChain(chain.next[0], inLibCall);
};
checkFilteredDiagnosticMessages(msgText: ts.DiagnosticMessageChain | string) {
@ -182,34 +182,43 @@ export class LibraryTypeCallDiagnosticChecker implements DiagnosticChecker {
* TypeScriptLinter. StrictDiagnosticCache can only keep by white list DiagnosticMessageChain type error and its matching success string type errors
*/
const textSet: Set<string> = new Set<string>();
const unknownSet: Set<string> = new Set<string>();
diagnosticMessageChainArr.forEach((item) => {
const diagnosticMessageChain = item.messageText as DiagnosticMessageChain;
const isAllowFilter: ErrorType = LibraryTypeCallDiagnosticChecker.checkMessageChain(diagnosticMessageChain, true);
if (isAllowFilter === ErrorType.UNKNOW) {
LibraryTypeCallDiagnosticChecker.collectDiagnosticMessage(diagnosticMessageChain, unknownSet);
TypeScriptLinter.unknowDiagnosticCache.add(item);
return;
}
if(isAllowFilter !== ErrorType.NO_ERROR){
const isTypeError = diagnosticMessageChain.code === TYPE_0_IS_NOT_ASSIGNABLE_TO_TYPE_1_ERROR_CODE;
const typeText = isTypeError ?
diagnosticMessageChain.messageText :
diagnosticMessageChain.messageText.replace(ARGUMENT_OF_TYPE, TYPE)
.replace(IS_NOT_ASSIGNABLE_TO_PARAMETER_OF_TYPE, IS_NOT_ASSIGNABLE_TO_TYPE);
const argumentText = isTypeError ?
diagnosticMessageChain.messageText.replace(TYPE, ARGUMENT_OF_TYPE)
.replace(IS_NOT_ASSIGNABLE_TO_TYPE, IS_NOT_ASSIGNABLE_TO_PARAMETER_OF_TYPE) :
diagnosticMessageChain.messageText;
textSet.add(typeText);
textSet.add(argumentText);
if (isAllowFilter !== ErrorType.NO_ERROR) {
LibraryTypeCallDiagnosticChecker.collectDiagnosticMessage(diagnosticMessageChain, textSet);
TypeScriptLinter.strictDiagnosticCache.add(item);
}
});
strictArr.forEach((item) => {
if(textSet.has(item.messageText as string)) {
const messageText = item.messageText as string;
if (unknownSet.has(messageText)) {
TypeScriptLinter.unknowDiagnosticCache.add(item);
} else if (textSet.has(messageText)) {
TypeScriptLinter.strictDiagnosticCache.add(item);
}
});
}
static collectDiagnosticMessage(diagnosticMessageChain: DiagnosticMessageChain, textSet: Set<string>): void {
const isTypeError = diagnosticMessageChain.code === TYPE_0_IS_NOT_ASSIGNABLE_TO_TYPE_1_ERROR_CODE;
const typeText = isTypeError ?
diagnosticMessageChain.messageText :
diagnosticMessageChain.messageText.replace(ARGUMENT_OF_TYPE, TYPE)
.replace(IS_NOT_ASSIGNABLE_TO_PARAMETER_OF_TYPE, IS_NOT_ASSIGNABLE_TO_TYPE);
const argumentText = isTypeError ?
diagnosticMessageChain.messageText.replace(TYPE, ARGUMENT_OF_TYPE)
.replace(IS_NOT_ASSIGNABLE_TO_TYPE, IS_NOT_ASSIGNABLE_TO_PARAMETER_OF_TYPE) :
diagnosticMessageChain.messageText;
textSet.add(typeText);
textSet.add(argumentText);
}
}
}
}

View File

@ -13,14 +13,14 @@
* limitations under the License.
*/
import {doSomething, cc , dd} from "./test";
import {doSomething, TestClassC, TestClassD} from './test';
class bb {
private c:dd | undefined = new dd();
class TestClassB {
private c:TestClassD | undefined = new TestClassD();
add() {
doSomething({
topic: (topic: string) => {
let a = new cc();
let a = new TestClassC();
this.c = a;
this.c = a;
}

View File

@ -1,7 +1,7 @@
{
"arktsVersion_1_0": [
{
"messageText": "Type 'cc' is not assignable to type 'dd'.",
"messageText": "Type 'TestClassC' is not assignable to type 'TestClassD'.",
"expectLineAndCharacter": {
"line": 25,
"character": 9

View File

@ -13,19 +13,19 @@
* limitations under the License.
*/
import {doSomething, cc , dd, test} from "./test";
import {doSomething, TestClassC, TestClassD, test} from './test';
class bb {
private c:dd | undefined = new dd();
class TestClassB {
private c:TestClassD | undefined = new TestClassD();
add() {
doSomething({
topic: (topic: string) => {
let a = new cc();
let a = new TestClassC();
this.c = a;
this.c = a;
}
}, '');
let b = new cc();
let b = new TestClassC();
test(b);
test(b);
}

View File

@ -1,14 +1,14 @@
{
"arktsVersion_1_0": [
{
"messageText": "Type 'cc' is not assignable to type 'dd'.",
"messageText": "Type 'TestClassC' is not assignable to type 'TestClassD'.",
"expectLineAndCharacter": {
"line": 24,
"character": 9
}
},
{
"messageText": "Type 'cc' is not assignable to type 'dd'.",
"messageText": "Type 'TestClassC' is not assignable to type 'TestClassD'.",
"expectLineAndCharacter": {
"line": 25,
"character": 9

View File

@ -0,0 +1,23 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {CallbackType, callback} from './unknow-type';
function foo_local(callback: CallbackType): void {
}
foo_local(callback);
foo_local(callback);

View File

@ -0,0 +1,13 @@
{
"arktsVersion_1_0": [
{
"messageText": "Argument of type '(name: string, param: Object) => void' is not assignable to parameter of type 'CallbackType'.",
"expectLineAndCharacter": {
"line": 23,
"character": 11
}
}
],
"arktsVersion_1_1": [
]
}

View File

@ -17,18 +17,18 @@ export interface a {
test:(topic: string) => void
}
export function doSomething(a: a, topic: string) {
export function doSomething(a: a, topic: string): void {
}
export class cc {
export class TestClassC {
public ccc: null = null;
}
export class dd {
export class TestClassD {
public ccc: string = '';
}
export function test(b: dd) {
export function test(b: TestClassD): void {
}

View File

@ -0,0 +1,18 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export type CallbackType = (name: string, param: unknown) => void;
export const callback = (name: string, param: Object) => {}

View File

@ -13117,6 +13117,7 @@ declare namespace ts {
checkFilteredDiagnosticMessages(msgText: ts.DiagnosticMessageChain | string): boolean;
checkDiagnosticMessage(msgText: string | ts.DiagnosticMessageChain): boolean;
static rebuildTscDiagnostics(tscStrictDiagnostics: Map<Diagnostic[]>): void;
static collectDiagnosticMessage(diagnosticMessageChain: DiagnosticMessageChain, textSet: Set<string>): void;
}
}
}

View File

@ -9171,6 +9171,7 @@ declare namespace ts {
checkFilteredDiagnosticMessages(msgText: ts.DiagnosticMessageChain | string): boolean;
checkDiagnosticMessage(msgText: string | ts.DiagnosticMessageChain): boolean;
static rebuildTscDiagnostics(tscStrictDiagnostics: Map<Diagnostic[]>): void;
static collectDiagnosticMessage(diagnosticMessageChain: DiagnosticMessageChain, textSet: Set<string>): void;
}
}
}