mirror of
https://gitee.com/openharmony/third_party_typescript
synced 2024-11-23 06:50:54 +00:00
[ArkTS Linter] Fix #17839: function isSendableTypeNode
doesn't work for alias type node when it is a generic type
Issue:https://gitee.com/openharmony/third_party_typescript/issues/IAPPTT Test: tsc tests Signed-off-by: Okolnov Evgeniy <okolnov.evgeny1@huawei-partners.com>
This commit is contained in:
parent
89757fc159
commit
5c2690d1e3
@ -196925,6 +196925,13 @@ var ts;
|
||||
if (sym && sym.getFlags() & 524288 /* ts.SymbolFlags.TypeAlias */) {
|
||||
var typeDecl = getDeclaration(sym);
|
||||
if (typeDecl && ts.isTypeAliasDeclaration(typeDecl)) {
|
||||
var typeArgs = typeNode.typeArguments;
|
||||
if (typeArgs &&
|
||||
!typeArgs.every(function (typeArg) {
|
||||
return isSendableTypeNode(typeArg);
|
||||
})) {
|
||||
return false;
|
||||
}
|
||||
return isSendableTypeNode(typeDecl.type, isShared);
|
||||
}
|
||||
}
|
||||
|
@ -196670,6 +196670,13 @@ var ts;
|
||||
if (sym && sym.getFlags() & 524288 /* ts.SymbolFlags.TypeAlias */) {
|
||||
var typeDecl = getDeclaration(sym);
|
||||
if (typeDecl && ts.isTypeAliasDeclaration(typeDecl)) {
|
||||
var typeArgs = typeNode.typeArguments;
|
||||
if (typeArgs &&
|
||||
!typeArgs.every(function (typeArg) {
|
||||
return isSendableTypeNode(typeArg);
|
||||
})) {
|
||||
return false;
|
||||
}
|
||||
return isSendableTypeNode(typeDecl.type, isShared);
|
||||
}
|
||||
}
|
||||
|
@ -185764,6 +185764,13 @@ var ts;
|
||||
if (sym && sym.getFlags() & 524288 /* ts.SymbolFlags.TypeAlias */) {
|
||||
var typeDecl = getDeclaration(sym);
|
||||
if (typeDecl && ts.isTypeAliasDeclaration(typeDecl)) {
|
||||
var typeArgs = typeNode.typeArguments;
|
||||
if (typeArgs &&
|
||||
!typeArgs.every(function (typeArg) {
|
||||
return isSendableTypeNode(typeArg);
|
||||
})) {
|
||||
return false;
|
||||
}
|
||||
return isSendableTypeNode(typeDecl.type, isShared);
|
||||
}
|
||||
}
|
||||
|
@ -185764,6 +185764,13 @@ var ts;
|
||||
if (sym && sym.getFlags() & 524288 /* ts.SymbolFlags.TypeAlias */) {
|
||||
var typeDecl = getDeclaration(sym);
|
||||
if (typeDecl && ts.isTypeAliasDeclaration(typeDecl)) {
|
||||
var typeArgs = typeNode.typeArguments;
|
||||
if (typeArgs &&
|
||||
!typeArgs.every(function (typeArg) {
|
||||
return isSendableTypeNode(typeArg);
|
||||
})) {
|
||||
return false;
|
||||
}
|
||||
return isSendableTypeNode(typeDecl.type, isShared);
|
||||
}
|
||||
}
|
||||
|
@ -1971,6 +1971,15 @@ export function isSendableTypeNode(typeNode: ts.TypeNode, isShared: boolean = fa
|
||||
if (sym && sym.getFlags() & ts.SymbolFlags.TypeAlias) {
|
||||
const typeDecl = getDeclaration(sym);
|
||||
if (typeDecl && ts.isTypeAliasDeclaration(typeDecl)) {
|
||||
const typeArgs = (typeNode as ts.TypeReferenceNode).typeArguments;
|
||||
if (
|
||||
typeArgs &&
|
||||
!typeArgs.every((typeArg) => {
|
||||
return isSendableTypeNode(typeArg);
|
||||
})
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
return isSendableTypeNode(typeDecl.type, isShared);
|
||||
}
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ function getAllETSFiles(filePath) {
|
||||
const files = fs.readdirSync(filePath);
|
||||
for (let i = 0; i < files.length; i++) {
|
||||
let file = files[i]; // File name (excluding file path)
|
||||
let currentFilePath = path.join(filePath, file);
|
||||
let currentFilePath = path.normalize(path.join(filePath, file));
|
||||
let stats = fs.lstatSync(currentFilePath);
|
||||
if(ignoreList.includes(currentFilePath)){
|
||||
continue
|
||||
@ -324,7 +324,8 @@ function run(){
|
||||
ignoreCaseConfigList = JSON.parse(fs.readFileSync(ignoreCaseFilePath)).ignoreCase
|
||||
}
|
||||
|
||||
ignoreList = ignoreList.concat(ignoreCaseConfigList)
|
||||
ignoreList = ignoreList.concat(ignoreCaseConfigList).map(x => path.normalize(x))
|
||||
|
||||
let filePathStats = fs.lstatSync(filePath)
|
||||
if(!filePathStats.isDirectory()){
|
||||
runComp(filePath, path.basename(filePath))
|
||||
|
@ -0,0 +1,34 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
class A {}
|
||||
class B<T> {}
|
||||
|
||||
declare type Nullable<T> = T | undefined;
|
||||
type MyType<T> = B<T> | undefined;
|
||||
|
||||
class C {
|
||||
c: number;
|
||||
}
|
||||
|
||||
@Sendable
|
||||
class D {
|
||||
a: Nullable<A>; // NOT OK
|
||||
b: Nullable<C> = new C(); // NOT OK
|
||||
c: Nullable<number> = 1; // OK
|
||||
d: MyType<number>; // NOT OK
|
||||
}
|
||||
|
||||
let d = new D();
|
@ -0,0 +1,55 @@
|
||||
{
|
||||
"arktsVersion_1_0": [
|
||||
{
|
||||
"messageText": "Property 'c' has no initializer and is not definitely assigned in the constructor.",
|
||||
"expectLineAndCharacter": {
|
||||
"line": 23,
|
||||
"character": 3
|
||||
}
|
||||
},
|
||||
{
|
||||
"messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)",
|
||||
"expectLineAndCharacter": {
|
||||
"line": 26,
|
||||
"character": 1
|
||||
}
|
||||
}
|
||||
],
|
||||
"arktsVersion_1_1": [
|
||||
{
|
||||
"messageText": "Property 'c' has no initializer and is not definitely assigned in the constructor.",
|
||||
"expectLineAndCharacter": {
|
||||
"line": 23,
|
||||
"character": 3
|
||||
}
|
||||
},
|
||||
{
|
||||
"messageText": "Only imported variables can be captured by \"Sendable\" class (arkts-sendable-imported-variables)",
|
||||
"expectLineAndCharacter": {
|
||||
"line": 29,
|
||||
"character": 24
|
||||
}
|
||||
},
|
||||
{
|
||||
"messageText": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)",
|
||||
"expectLineAndCharacter": {
|
||||
"line": 28,
|
||||
"character": 3
|
||||
}
|
||||
},
|
||||
{
|
||||
"messageText": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)",
|
||||
"expectLineAndCharacter": {
|
||||
"line": 29,
|
||||
"character": 3
|
||||
}
|
||||
},
|
||||
{
|
||||
"messageText": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)",
|
||||
"expectLineAndCharacter": {
|
||||
"line": 31,
|
||||
"character": 3
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
Loading…
Reference in New Issue
Block a user