Fix ArkTSLinter readonly array bug

Issue: https://gitee.com/openharmony/third_party_typescript/issues/I95QK4
Test: tsc tests

bugfix:
1. Fix the problem of error when readonly is used as function modification

internal: #15966

Change-Id: Ide8cbf598d6e6fc0454eea53d70075e13d4bd581
Signed-off-by: lizhonghan <lizhonghan1@huawei.com>
This commit is contained in:
lizhonghan 2024-03-04 20:37:59 +08:00
parent 4dae7e0292
commit f91082d982
10 changed files with 41 additions and 5 deletions

View File

@ -193409,6 +193409,12 @@ var ts;
((_c = tsType.getSymbol()) === null || _c === void 0 ? void 0 : _c.getName()) === "Array");
}
Utils.isGenericArrayType = isGenericArrayType;
function isReadonlyArrayType(tsType) {
var _a, _b, _c;
return (isTypeReference(tsType) && ((_a = tsType.typeArguments) === null || _a === void 0 ? void 0 : _a.length) === 1 && ((_b = tsType.target.typeParameters) === null || _b === void 0 ? void 0 : _b.length) === 1 &&
(((_c = tsType.getSymbol()) === null || _c === void 0 ? void 0 : _c.getName()) === "ReadonlyArray"));
}
Utils.isReadonlyArrayType = isReadonlyArrayType;
function isTypedArray(tsType) {
var symbol = tsType.symbol;
if (!symbol) {
@ -193419,7 +193425,7 @@ var ts;
}
Utils.isTypedArray = isTypedArray;
function isArray(tsType) {
return isGenericArrayType(tsType) || isTypedArray(tsType);
return isGenericArrayType(tsType) || isReadonlyArrayType(tsType) || isTypedArray(tsType);
}
Utils.isArray = isArray;
function isTuple(tsType) {

View File

@ -13196,6 +13196,7 @@ declare namespace ts {
function isPrimitiveType(type: Type): boolean;
function isTypeSymbol(symbol: Symbol | undefined): boolean;
function isGenericArrayType(tsType: Type): tsType is TypeReference;
function isReadonlyArrayType(tsType: Type): boolean;
function isTypedArray(tsType: ts.Type): boolean;
function isArray(tsType: ts.Type): boolean;
function isTuple(tsType: ts.Type): boolean;

View File

@ -193154,6 +193154,12 @@ var ts;
((_c = tsType.getSymbol()) === null || _c === void 0 ? void 0 : _c.getName()) === "Array");
}
Utils.isGenericArrayType = isGenericArrayType;
function isReadonlyArrayType(tsType) {
var _a, _b, _c;
return (isTypeReference(tsType) && ((_a = tsType.typeArguments) === null || _a === void 0 ? void 0 : _a.length) === 1 && ((_b = tsType.target.typeParameters) === null || _b === void 0 ? void 0 : _b.length) === 1 &&
(((_c = tsType.getSymbol()) === null || _c === void 0 ? void 0 : _c.getName()) === "ReadonlyArray"));
}
Utils.isReadonlyArrayType = isReadonlyArrayType;
function isTypedArray(tsType) {
var symbol = tsType.symbol;
if (!symbol) {
@ -193164,7 +193170,7 @@ var ts;
}
Utils.isTypedArray = isTypedArray;
function isArray(tsType) {
return isGenericArrayType(tsType) || isTypedArray(tsType);
return isGenericArrayType(tsType) || isReadonlyArrayType(tsType) || isTypedArray(tsType);
}
Utils.isArray = isArray;
function isTuple(tsType) {

1
lib/typescript.d.ts vendored
View File

@ -9257,6 +9257,7 @@ declare namespace ts {
function isPrimitiveType(type: Type): boolean;
function isTypeSymbol(symbol: Symbol | undefined): boolean;
function isGenericArrayType(tsType: Type): tsType is TypeReference;
function isReadonlyArrayType(tsType: Type): boolean;
function isTypedArray(tsType: ts.Type): boolean;
function isArray(tsType: ts.Type): boolean;
function isTuple(tsType: ts.Type): boolean;

View File

@ -182248,6 +182248,12 @@ var ts;
((_c = tsType.getSymbol()) === null || _c === void 0 ? void 0 : _c.getName()) === "Array");
}
Utils.isGenericArrayType = isGenericArrayType;
function isReadonlyArrayType(tsType) {
var _a, _b, _c;
return (isTypeReference(tsType) && ((_a = tsType.typeArguments) === null || _a === void 0 ? void 0 : _a.length) === 1 && ((_b = tsType.target.typeParameters) === null || _b === void 0 ? void 0 : _b.length) === 1 &&
(((_c = tsType.getSymbol()) === null || _c === void 0 ? void 0 : _c.getName()) === "ReadonlyArray"));
}
Utils.isReadonlyArrayType = isReadonlyArrayType;
function isTypedArray(tsType) {
var symbol = tsType.symbol;
if (!symbol) {
@ -182258,7 +182264,7 @@ var ts;
}
Utils.isTypedArray = isTypedArray;
function isArray(tsType) {
return isGenericArrayType(tsType) || isTypedArray(tsType);
return isGenericArrayType(tsType) || isReadonlyArrayType(tsType) || isTypedArray(tsType);
}
Utils.isArray = isArray;
function isTuple(tsType) {

View File

@ -9257,6 +9257,7 @@ declare namespace ts {
function isPrimitiveType(type: Type): boolean;
function isTypeSymbol(symbol: Symbol | undefined): boolean;
function isGenericArrayType(tsType: Type): tsType is TypeReference;
function isReadonlyArrayType(tsType: Type): boolean;
function isTypedArray(tsType: ts.Type): boolean;
function isArray(tsType: ts.Type): boolean;
function isTuple(tsType: ts.Type): boolean;

View File

@ -182248,6 +182248,12 @@ var ts;
((_c = tsType.getSymbol()) === null || _c === void 0 ? void 0 : _c.getName()) === "Array");
}
Utils.isGenericArrayType = isGenericArrayType;
function isReadonlyArrayType(tsType) {
var _a, _b, _c;
return (isTypeReference(tsType) && ((_a = tsType.typeArguments) === null || _a === void 0 ? void 0 : _a.length) === 1 && ((_b = tsType.target.typeParameters) === null || _b === void 0 ? void 0 : _b.length) === 1 &&
(((_c = tsType.getSymbol()) === null || _c === void 0 ? void 0 : _c.getName()) === "ReadonlyArray"));
}
Utils.isReadonlyArrayType = isReadonlyArrayType;
function isTypedArray(tsType) {
var symbol = tsType.symbol;
if (!symbol) {
@ -182258,7 +182264,7 @@ var ts;
}
Utils.isTypedArray = isTypedArray;
function isArray(tsType) {
return isGenericArrayType(tsType) || isTypedArray(tsType);
return isGenericArrayType(tsType) || isReadonlyArrayType(tsType) || isTypedArray(tsType);
}
Utils.isArray = isArray;
function isTuple(tsType) {

View File

@ -444,6 +444,13 @@ export function isGenericArrayType(tsType: Type): tsType is TypeReference {
);
}
export function isReadonlyArrayType(tsType: Type): boolean {
return (
isTypeReference(tsType) && tsType.typeArguments?.length === 1 && tsType.target.typeParameters?.length === 1 &&
(tsType.getSymbol()?.getName() === "ReadonlyArray")
);
}
export function isTypedArray(tsType: ts.Type): boolean {
const symbol = tsType.symbol;
if (!symbol) {
@ -454,7 +461,7 @@ export function isTypedArray(tsType: ts.Type): boolean {
}
export function isArray(tsType: ts.Type): boolean {
return isGenericArrayType(tsType) || isTypedArray(tsType);
return isGenericArrayType(tsType) || isReadonlyArrayType(tsType) || isTypedArray(tsType);
}
export function isTuple(tsType: ts.Type): boolean {

View File

@ -13196,6 +13196,7 @@ declare namespace ts {
function isPrimitiveType(type: Type): boolean;
function isTypeSymbol(symbol: Symbol | undefined): boolean;
function isGenericArrayType(tsType: Type): tsType is TypeReference;
function isReadonlyArrayType(tsType: Type): boolean;
function isTypedArray(tsType: ts.Type): boolean;
function isArray(tsType: ts.Type): boolean;
function isTuple(tsType: ts.Type): boolean;

View File

@ -9257,6 +9257,7 @@ declare namespace ts {
function isPrimitiveType(type: Type): boolean;
function isTypeSymbol(symbol: Symbol | undefined): boolean;
function isGenericArrayType(tsType: Type): tsType is TypeReference;
function isReadonlyArrayType(tsType: Type): boolean;
function isTypedArray(tsType: ts.Type): boolean;
function isArray(tsType: ts.Type): boolean;
function isTuple(tsType: ts.Type): boolean;