Add arkts-no-side-effects-imports

Issue: I9JEGJ
Test: linter test

Signed-off-by: hid20141227 <yangrui185@huawei.com>
Change-Id: I04768483ef1bae32caeb50170b4c2b611e3d2744
This commit is contained in:
hid20141227 2024-04-24 11:57:54 +08:00
parent c5c31ffa75
commit 5fc907de6f
23 changed files with 417 additions and 15 deletions

View File

@ -192762,7 +192762,7 @@ var ts;
(function (ArkTSLinter_1_1) {
ArkTSLinter_1_1.cookBookMsg = [];
ArkTSLinter_1_1.cookBookTag = [];
for (var i = 0; i <= 161; i++) {
for (var i = 0; i <= 162; i++) {
ArkTSLinter_1_1.cookBookMsg[i] = "";
}
ArkTSLinter_1_1.cookBookTag[1] = "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)";
@ -192925,6 +192925,7 @@ var ts;
ArkTSLinter_1_1.cookBookTag[159] = 'Objects of "Sendable" type can not be initialized using object literal or array literal (arkts-sendable-obj-init)';
ArkTSLinter_1_1.cookBookTag[160] = 'Computed property names are not allowed in "Sendable" classes and interfaces (arkts-sendable-computed-prop-name)';
ArkTSLinter_1_1.cookBookTag[161] = 'Casting "Non-sendable" data to "Sendable" type is not allowed (arkts-sendable-as-expr)';
ArkTSLinter_1_1.cookBookTag[162] = "Shared module do not allow side effect import (arkts-no-side-effects-imports)";
})(ArkTSLinter_1_1 = ts.ArkTSLinter_1_1 || (ts.ArkTSLinter_1_1 = {}));
})(ts || (ts = {}));
/*
@ -193183,7 +193184,8 @@ var ts;
FaultID[FaultID["SendableObjectInitialization"] = 87] = "SendableObjectInitialization";
FaultID[FaultID["SendableComputedPropName"] = 88] = "SendableComputedPropName";
FaultID[FaultID["SendableAsExpr"] = 89] = "SendableAsExpr";
FaultID[FaultID["LAST_ID"] = 90] = "LAST_ID";
FaultID[FaultID["SharedNoSideEffectImport"] = 90] = "SharedNoSideEffectImport";
FaultID[FaultID["LAST_ID"] = 91] = "LAST_ID";
})(FaultID = Problems.FaultID || (Problems.FaultID = {}));
var FaultAttributes = /** @class */ (function () {
function FaultAttributes(cookBookRef, migratable, severity) {
@ -193287,6 +193289,7 @@ var ts;
Problems.faultsAttrs[FaultID.SendableObjectInitialization] = new FaultAttributes(159);
Problems.faultsAttrs[FaultID.SendableComputedPropName] = new FaultAttributes(160);
Problems.faultsAttrs[FaultID.SendableAsExpr] = new FaultAttributes(161);
Problems.faultsAttrs[FaultID.SharedNoSideEffectImport] = new FaultAttributes(162);
})(Problems = ArkTSLinter_1_1.Problems || (ArkTSLinter_1_1.Problems = {}));
})(ArkTSLinter_1_1 = ts.ArkTSLinter_1_1 || (ts.ArkTSLinter_1_1 = {}));
})(ts || (ts = {}));
@ -193334,6 +193337,7 @@ var ts;
Utils.ARKTS_LANG_D_ETS = '@arkts.lang.d.ets';
Utils.LANG_NAMESPACE = 'lang';
Utils.ISENDABLE_TYPE = 'ISendable';
Utils.USE_SHARED = 'use shared';
var typeChecker;
function setTypeChecker(tsTypeChecker) {
typeChecker = tsTypeChecker;
@ -195103,6 +195107,20 @@ var ts;
}
return true;
}
function isSharedModule(sourceFile) {
var statements = sourceFile.statements;
for (var _i = 0, statements_1 = statements; _i < statements_1.length; _i++) {
var statement = statements_1[_i];
if (ts.isImportDeclaration(statement)) {
continue;
}
return (ts.isExpressionStatement(statement) &&
ts.isStringLiteral(statement.expression) &&
statement.expression.text === Utils.USE_SHARED);
}
return false;
}
Utils.isSharedModule = isSharedModule;
})(Utils = ArkTSLinter_1_1.Utils || (ArkTSLinter_1_1.Utils = {}));
})(ArkTSLinter_1_1 = ts.ArkTSLinter_1_1 || (ts.ArkTSLinter_1_1 = {}));
})(ts || (ts = {}));
@ -195380,6 +195398,7 @@ var ts;
initialize a "Sendable" object';
LinterConfig.nodeDesc[FaultID.SendableComputedPropName] = 'Sendable computed property name';
LinterConfig.nodeDesc[FaultID.SendableAsExpr] = 'Sendable as expr';
LinterConfig.nodeDesc[FaultID.SharedNoSideEffectImport] = 'Shared no side effect import';
};
LinterConfig.nodeDesc = [];
// The SyntaxKind enum defines additional elements at the end of the enum
@ -195545,6 +195564,7 @@ var ts;
}
TypeScriptLinter.initGlobals = function () {
TypeScriptLinter.filteredDiagnosticMessages = [];
TypeScriptLinter.sharedModulesCache = new ts.Map();
};
TypeScriptLinter.initStatic = function () {
TypeScriptLinter.strictMode = true;
@ -195980,6 +196000,25 @@ var ts;
this.incrementCounters(importDeclNode.assertClause, FaultID.ImportAssertion);
}
}
//handle no side effect import in sendable module
this.handleSharedModuleNoSideEffectImport(importDeclNode);
};
TypeScriptLinter.prototype.handleSharedModuleNoSideEffectImport = function (node) {
//check 'use shared'
if (TypeScriptLinter.inSharedModule(node)) {
if (!node.importClause) {
this.incrementCounters(node, FaultID.SharedNoSideEffectImport);
}
}
};
TypeScriptLinter.inSharedModule = function (node) {
var sourceFile = node.getSourceFile();
if (TypeScriptLinter.sharedModulesCache.has(ts.normalizePath(sourceFile.fileName))) {
return TypeScriptLinter.sharedModulesCache.get(ts.normalizePath(sourceFile.fileName));
}
var isSharedModule = ArkTSLinter_1_1.Utils.isSharedModule(sourceFile);
TypeScriptLinter.sharedModulesCache.set(ts.normalizePath(sourceFile.fileName), isSharedModule);
return isSharedModule;
};
TypeScriptLinter.prototype.handlePropertyAccessExpression = function (node) {
if (ts.isCallExpression(node.parent) && node == node.parent.expression) {

View File

@ -13140,7 +13140,8 @@ declare namespace ts {
SendableObjectInitialization = 87,
SendableComputedPropName = 88,
SendableAsExpr = 89,
LAST_ID = 90
SharedNoSideEffectImport = 90,
LAST_ID = 91
}
class FaultAttributes {
cookBookRef: number;
@ -13171,6 +13172,7 @@ declare namespace ts {
const ARKTS_LANG_D_ETS = "@arkts.lang.d.ets";
const LANG_NAMESPACE = "lang";
const ISENDABLE_TYPE = "ISendable";
const USE_SHARED = "use shared";
function setTypeChecker(tsTypeChecker: TypeChecker): void;
function clearTypeChecker(): void;
function setTestMode(tsTestMode: boolean): void;
@ -13335,6 +13337,7 @@ declare namespace ts {
function getNonSendableDecorators(decl: ts.ClassDeclaration): ts.Decorator[] | undefined;
function getDecoratorsIfInSendableClass(declaration: ts.HasDecorators): readonly ts.Decorator[] | undefined;
function isISendableInterface(type: ts.Type): boolean;
function isSharedModule(sourceFile: ts.SourceFile): boolean;
}
}
}
@ -13407,6 +13410,7 @@ declare namespace ts {
static reportDiagnostics: boolean;
static problemsInfos: ProblemInfo[];
static filteredDiagnosticMessages: DiagnosticMessageChain[];
static sharedModulesCache: ESMap<string, boolean>;
static initGlobals(): void;
static initStatic(): void;
static tsTypeChecker: TypeChecker;
@ -13438,6 +13442,8 @@ declare namespace ts {
private handleForInStatement;
private handleForOfStatement;
private handleImportDeclaration;
private handleSharedModuleNoSideEffectImport;
private static inSharedModule;
private handlePropertyAccessExpression;
private handlePropertyDeclaration;
private handleSendableClassProperty;

View File

@ -192507,7 +192507,7 @@ var ts;
(function (ArkTSLinter_1_1) {
ArkTSLinter_1_1.cookBookMsg = [];
ArkTSLinter_1_1.cookBookTag = [];
for (var i = 0; i <= 161; i++) {
for (var i = 0; i <= 162; i++) {
ArkTSLinter_1_1.cookBookMsg[i] = "";
}
ArkTSLinter_1_1.cookBookTag[1] = "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)";
@ -192670,6 +192670,7 @@ var ts;
ArkTSLinter_1_1.cookBookTag[159] = 'Objects of "Sendable" type can not be initialized using object literal or array literal (arkts-sendable-obj-init)';
ArkTSLinter_1_1.cookBookTag[160] = 'Computed property names are not allowed in "Sendable" classes and interfaces (arkts-sendable-computed-prop-name)';
ArkTSLinter_1_1.cookBookTag[161] = 'Casting "Non-sendable" data to "Sendable" type is not allowed (arkts-sendable-as-expr)';
ArkTSLinter_1_1.cookBookTag[162] = "Shared module do not allow side effect import (arkts-no-side-effects-imports)";
})(ArkTSLinter_1_1 = ts.ArkTSLinter_1_1 || (ts.ArkTSLinter_1_1 = {}));
})(ts || (ts = {}));
/*
@ -192928,7 +192929,8 @@ var ts;
FaultID[FaultID["SendableObjectInitialization"] = 87] = "SendableObjectInitialization";
FaultID[FaultID["SendableComputedPropName"] = 88] = "SendableComputedPropName";
FaultID[FaultID["SendableAsExpr"] = 89] = "SendableAsExpr";
FaultID[FaultID["LAST_ID"] = 90] = "LAST_ID";
FaultID[FaultID["SharedNoSideEffectImport"] = 90] = "SharedNoSideEffectImport";
FaultID[FaultID["LAST_ID"] = 91] = "LAST_ID";
})(FaultID = Problems.FaultID || (Problems.FaultID = {}));
var FaultAttributes = /** @class */ (function () {
function FaultAttributes(cookBookRef, migratable, severity) {
@ -193032,6 +193034,7 @@ var ts;
Problems.faultsAttrs[FaultID.SendableObjectInitialization] = new FaultAttributes(159);
Problems.faultsAttrs[FaultID.SendableComputedPropName] = new FaultAttributes(160);
Problems.faultsAttrs[FaultID.SendableAsExpr] = new FaultAttributes(161);
Problems.faultsAttrs[FaultID.SharedNoSideEffectImport] = new FaultAttributes(162);
})(Problems = ArkTSLinter_1_1.Problems || (ArkTSLinter_1_1.Problems = {}));
})(ArkTSLinter_1_1 = ts.ArkTSLinter_1_1 || (ts.ArkTSLinter_1_1 = {}));
})(ts || (ts = {}));
@ -193079,6 +193082,7 @@ var ts;
Utils.ARKTS_LANG_D_ETS = '@arkts.lang.d.ets';
Utils.LANG_NAMESPACE = 'lang';
Utils.ISENDABLE_TYPE = 'ISendable';
Utils.USE_SHARED = 'use shared';
var typeChecker;
function setTypeChecker(tsTypeChecker) {
typeChecker = tsTypeChecker;
@ -194848,6 +194852,20 @@ var ts;
}
return true;
}
function isSharedModule(sourceFile) {
var statements = sourceFile.statements;
for (var _i = 0, statements_1 = statements; _i < statements_1.length; _i++) {
var statement = statements_1[_i];
if (ts.isImportDeclaration(statement)) {
continue;
}
return (ts.isExpressionStatement(statement) &&
ts.isStringLiteral(statement.expression) &&
statement.expression.text === Utils.USE_SHARED);
}
return false;
}
Utils.isSharedModule = isSharedModule;
})(Utils = ArkTSLinter_1_1.Utils || (ArkTSLinter_1_1.Utils = {}));
})(ArkTSLinter_1_1 = ts.ArkTSLinter_1_1 || (ts.ArkTSLinter_1_1 = {}));
})(ts || (ts = {}));
@ -195125,6 +195143,7 @@ var ts;
initialize a "Sendable" object';
LinterConfig.nodeDesc[FaultID.SendableComputedPropName] = 'Sendable computed property name';
LinterConfig.nodeDesc[FaultID.SendableAsExpr] = 'Sendable as expr';
LinterConfig.nodeDesc[FaultID.SharedNoSideEffectImport] = 'Shared no side effect import';
};
LinterConfig.nodeDesc = [];
// The SyntaxKind enum defines additional elements at the end of the enum
@ -195290,6 +195309,7 @@ var ts;
}
TypeScriptLinter.initGlobals = function () {
TypeScriptLinter.filteredDiagnosticMessages = [];
TypeScriptLinter.sharedModulesCache = new ts.Map();
};
TypeScriptLinter.initStatic = function () {
TypeScriptLinter.strictMode = true;
@ -195725,6 +195745,25 @@ var ts;
this.incrementCounters(importDeclNode.assertClause, FaultID.ImportAssertion);
}
}
//handle no side effect import in sendable module
this.handleSharedModuleNoSideEffectImport(importDeclNode);
};
TypeScriptLinter.prototype.handleSharedModuleNoSideEffectImport = function (node) {
//check 'use shared'
if (TypeScriptLinter.inSharedModule(node)) {
if (!node.importClause) {
this.incrementCounters(node, FaultID.SharedNoSideEffectImport);
}
}
};
TypeScriptLinter.inSharedModule = function (node) {
var sourceFile = node.getSourceFile();
if (TypeScriptLinter.sharedModulesCache.has(ts.normalizePath(sourceFile.fileName))) {
return TypeScriptLinter.sharedModulesCache.get(ts.normalizePath(sourceFile.fileName));
}
var isSharedModule = ArkTSLinter_1_1.Utils.isSharedModule(sourceFile);
TypeScriptLinter.sharedModulesCache.set(ts.normalizePath(sourceFile.fileName), isSharedModule);
return isSharedModule;
};
TypeScriptLinter.prototype.handlePropertyAccessExpression = function (node) {
if (ts.isCallExpression(node.parent) && node == node.parent.expression) {

8
lib/typescript.d.ts vendored
View File

@ -9201,7 +9201,8 @@ declare namespace ts {
SendableObjectInitialization = 87,
SendableComputedPropName = 88,
SendableAsExpr = 89,
LAST_ID = 90
SharedNoSideEffectImport = 90,
LAST_ID = 91
}
class FaultAttributes {
cookBookRef: number;
@ -9232,6 +9233,7 @@ declare namespace ts {
const ARKTS_LANG_D_ETS = "@arkts.lang.d.ets";
const LANG_NAMESPACE = "lang";
const ISENDABLE_TYPE = "ISendable";
const USE_SHARED = "use shared";
function setTypeChecker(tsTypeChecker: TypeChecker): void;
function clearTypeChecker(): void;
function setTestMode(tsTestMode: boolean): void;
@ -9396,6 +9398,7 @@ declare namespace ts {
function getNonSendableDecorators(decl: ts.ClassDeclaration): ts.Decorator[] | undefined;
function getDecoratorsIfInSendableClass(declaration: ts.HasDecorators): readonly ts.Decorator[] | undefined;
function isISendableInterface(type: ts.Type): boolean;
function isSharedModule(sourceFile: ts.SourceFile): boolean;
}
}
}
@ -9468,6 +9471,7 @@ declare namespace ts {
static reportDiagnostics: boolean;
static problemsInfos: ProblemInfo[];
static filteredDiagnosticMessages: DiagnosticMessageChain[];
static sharedModulesCache: ESMap<string, boolean>;
static initGlobals(): void;
static initStatic(): void;
static tsTypeChecker: TypeChecker;
@ -9499,6 +9503,8 @@ declare namespace ts {
private handleForInStatement;
private handleForOfStatement;
private handleImportDeclaration;
private handleSharedModuleNoSideEffectImport;
private static inSharedModule;
private handlePropertyAccessExpression;
private handlePropertyDeclaration;
private handleSendableClassProperty;

View File

@ -181601,7 +181601,7 @@ var ts;
(function (ArkTSLinter_1_1) {
ArkTSLinter_1_1.cookBookMsg = [];
ArkTSLinter_1_1.cookBookTag = [];
for (var i = 0; i <= 161; i++) {
for (var i = 0; i <= 162; i++) {
ArkTSLinter_1_1.cookBookMsg[i] = "";
}
ArkTSLinter_1_1.cookBookTag[1] = "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)";
@ -181764,6 +181764,7 @@ var ts;
ArkTSLinter_1_1.cookBookTag[159] = 'Objects of "Sendable" type can not be initialized using object literal or array literal (arkts-sendable-obj-init)';
ArkTSLinter_1_1.cookBookTag[160] = 'Computed property names are not allowed in "Sendable" classes and interfaces (arkts-sendable-computed-prop-name)';
ArkTSLinter_1_1.cookBookTag[161] = 'Casting "Non-sendable" data to "Sendable" type is not allowed (arkts-sendable-as-expr)';
ArkTSLinter_1_1.cookBookTag[162] = "Shared module do not allow side effect import (arkts-no-side-effects-imports)";
})(ArkTSLinter_1_1 = ts.ArkTSLinter_1_1 || (ts.ArkTSLinter_1_1 = {}));
})(ts || (ts = {}));
/*
@ -182022,7 +182023,8 @@ var ts;
FaultID[FaultID["SendableObjectInitialization"] = 87] = "SendableObjectInitialization";
FaultID[FaultID["SendableComputedPropName"] = 88] = "SendableComputedPropName";
FaultID[FaultID["SendableAsExpr"] = 89] = "SendableAsExpr";
FaultID[FaultID["LAST_ID"] = 90] = "LAST_ID";
FaultID[FaultID["SharedNoSideEffectImport"] = 90] = "SharedNoSideEffectImport";
FaultID[FaultID["LAST_ID"] = 91] = "LAST_ID";
})(FaultID = Problems.FaultID || (Problems.FaultID = {}));
var FaultAttributes = /** @class */ (function () {
function FaultAttributes(cookBookRef, migratable, severity) {
@ -182126,6 +182128,7 @@ var ts;
Problems.faultsAttrs[FaultID.SendableObjectInitialization] = new FaultAttributes(159);
Problems.faultsAttrs[FaultID.SendableComputedPropName] = new FaultAttributes(160);
Problems.faultsAttrs[FaultID.SendableAsExpr] = new FaultAttributes(161);
Problems.faultsAttrs[FaultID.SharedNoSideEffectImport] = new FaultAttributes(162);
})(Problems = ArkTSLinter_1_1.Problems || (ArkTSLinter_1_1.Problems = {}));
})(ArkTSLinter_1_1 = ts.ArkTSLinter_1_1 || (ts.ArkTSLinter_1_1 = {}));
})(ts || (ts = {}));
@ -182173,6 +182176,7 @@ var ts;
Utils.ARKTS_LANG_D_ETS = '@arkts.lang.d.ets';
Utils.LANG_NAMESPACE = 'lang';
Utils.ISENDABLE_TYPE = 'ISendable';
Utils.USE_SHARED = 'use shared';
var typeChecker;
function setTypeChecker(tsTypeChecker) {
typeChecker = tsTypeChecker;
@ -183942,6 +183946,20 @@ var ts;
}
return true;
}
function isSharedModule(sourceFile) {
var statements = sourceFile.statements;
for (var _i = 0, statements_1 = statements; _i < statements_1.length; _i++) {
var statement = statements_1[_i];
if (ts.isImportDeclaration(statement)) {
continue;
}
return (ts.isExpressionStatement(statement) &&
ts.isStringLiteral(statement.expression) &&
statement.expression.text === Utils.USE_SHARED);
}
return false;
}
Utils.isSharedModule = isSharedModule;
})(Utils = ArkTSLinter_1_1.Utils || (ArkTSLinter_1_1.Utils = {}));
})(ArkTSLinter_1_1 = ts.ArkTSLinter_1_1 || (ts.ArkTSLinter_1_1 = {}));
})(ts || (ts = {}));
@ -184219,6 +184237,7 @@ var ts;
initialize a "Sendable" object';
LinterConfig.nodeDesc[FaultID.SendableComputedPropName] = 'Sendable computed property name';
LinterConfig.nodeDesc[FaultID.SendableAsExpr] = 'Sendable as expr';
LinterConfig.nodeDesc[FaultID.SharedNoSideEffectImport] = 'Shared no side effect import';
};
LinterConfig.nodeDesc = [];
// The SyntaxKind enum defines additional elements at the end of the enum
@ -184384,6 +184403,7 @@ var ts;
}
TypeScriptLinter.initGlobals = function () {
TypeScriptLinter.filteredDiagnosticMessages = [];
TypeScriptLinter.sharedModulesCache = new ts.Map();
};
TypeScriptLinter.initStatic = function () {
TypeScriptLinter.strictMode = true;
@ -184819,6 +184839,25 @@ var ts;
this.incrementCounters(importDeclNode.assertClause, FaultID.ImportAssertion);
}
}
//handle no side effect import in sendable module
this.handleSharedModuleNoSideEffectImport(importDeclNode);
};
TypeScriptLinter.prototype.handleSharedModuleNoSideEffectImport = function (node) {
//check 'use shared'
if (TypeScriptLinter.inSharedModule(node)) {
if (!node.importClause) {
this.incrementCounters(node, FaultID.SharedNoSideEffectImport);
}
}
};
TypeScriptLinter.inSharedModule = function (node) {
var sourceFile = node.getSourceFile();
if (TypeScriptLinter.sharedModulesCache.has(ts.normalizePath(sourceFile.fileName))) {
return TypeScriptLinter.sharedModulesCache.get(ts.normalizePath(sourceFile.fileName));
}
var isSharedModule = ArkTSLinter_1_1.Utils.isSharedModule(sourceFile);
TypeScriptLinter.sharedModulesCache.set(ts.normalizePath(sourceFile.fileName), isSharedModule);
return isSharedModule;
};
TypeScriptLinter.prototype.handlePropertyAccessExpression = function (node) {
if (ts.isCallExpression(node.parent) && node == node.parent.expression) {

View File

@ -9201,7 +9201,8 @@ declare namespace ts {
SendableObjectInitialization = 87,
SendableComputedPropName = 88,
SendableAsExpr = 89,
LAST_ID = 90
SharedNoSideEffectImport = 90,
LAST_ID = 91
}
class FaultAttributes {
cookBookRef: number;
@ -9232,6 +9233,7 @@ declare namespace ts {
const ARKTS_LANG_D_ETS = "@arkts.lang.d.ets";
const LANG_NAMESPACE = "lang";
const ISENDABLE_TYPE = "ISendable";
const USE_SHARED = "use shared";
function setTypeChecker(tsTypeChecker: TypeChecker): void;
function clearTypeChecker(): void;
function setTestMode(tsTestMode: boolean): void;
@ -9396,6 +9398,7 @@ declare namespace ts {
function getNonSendableDecorators(decl: ts.ClassDeclaration): ts.Decorator[] | undefined;
function getDecoratorsIfInSendableClass(declaration: ts.HasDecorators): readonly ts.Decorator[] | undefined;
function isISendableInterface(type: ts.Type): boolean;
function isSharedModule(sourceFile: ts.SourceFile): boolean;
}
}
}
@ -9468,6 +9471,7 @@ declare namespace ts {
static reportDiagnostics: boolean;
static problemsInfos: ProblemInfo[];
static filteredDiagnosticMessages: DiagnosticMessageChain[];
static sharedModulesCache: ESMap<string, boolean>;
static initGlobals(): void;
static initStatic(): void;
static tsTypeChecker: TypeChecker;
@ -9499,6 +9503,8 @@ declare namespace ts {
private handleForInStatement;
private handleForOfStatement;
private handleImportDeclaration;
private handleSharedModuleNoSideEffectImport;
private static inSharedModule;
private handlePropertyAccessExpression;
private handlePropertyDeclaration;
private handleSendableClassProperty;

View File

@ -181601,7 +181601,7 @@ var ts;
(function (ArkTSLinter_1_1) {
ArkTSLinter_1_1.cookBookMsg = [];
ArkTSLinter_1_1.cookBookTag = [];
for (var i = 0; i <= 161; i++) {
for (var i = 0; i <= 162; i++) {
ArkTSLinter_1_1.cookBookMsg[i] = "";
}
ArkTSLinter_1_1.cookBookTag[1] = "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)";
@ -181764,6 +181764,7 @@ var ts;
ArkTSLinter_1_1.cookBookTag[159] = 'Objects of "Sendable" type can not be initialized using object literal or array literal (arkts-sendable-obj-init)';
ArkTSLinter_1_1.cookBookTag[160] = 'Computed property names are not allowed in "Sendable" classes and interfaces (arkts-sendable-computed-prop-name)';
ArkTSLinter_1_1.cookBookTag[161] = 'Casting "Non-sendable" data to "Sendable" type is not allowed (arkts-sendable-as-expr)';
ArkTSLinter_1_1.cookBookTag[162] = "Shared module do not allow side effect import (arkts-no-side-effects-imports)";
})(ArkTSLinter_1_1 = ts.ArkTSLinter_1_1 || (ts.ArkTSLinter_1_1 = {}));
})(ts || (ts = {}));
/*
@ -182022,7 +182023,8 @@ var ts;
FaultID[FaultID["SendableObjectInitialization"] = 87] = "SendableObjectInitialization";
FaultID[FaultID["SendableComputedPropName"] = 88] = "SendableComputedPropName";
FaultID[FaultID["SendableAsExpr"] = 89] = "SendableAsExpr";
FaultID[FaultID["LAST_ID"] = 90] = "LAST_ID";
FaultID[FaultID["SharedNoSideEffectImport"] = 90] = "SharedNoSideEffectImport";
FaultID[FaultID["LAST_ID"] = 91] = "LAST_ID";
})(FaultID = Problems.FaultID || (Problems.FaultID = {}));
var FaultAttributes = /** @class */ (function () {
function FaultAttributes(cookBookRef, migratable, severity) {
@ -182126,6 +182128,7 @@ var ts;
Problems.faultsAttrs[FaultID.SendableObjectInitialization] = new FaultAttributes(159);
Problems.faultsAttrs[FaultID.SendableComputedPropName] = new FaultAttributes(160);
Problems.faultsAttrs[FaultID.SendableAsExpr] = new FaultAttributes(161);
Problems.faultsAttrs[FaultID.SharedNoSideEffectImport] = new FaultAttributes(162);
})(Problems = ArkTSLinter_1_1.Problems || (ArkTSLinter_1_1.Problems = {}));
})(ArkTSLinter_1_1 = ts.ArkTSLinter_1_1 || (ts.ArkTSLinter_1_1 = {}));
})(ts || (ts = {}));
@ -182173,6 +182176,7 @@ var ts;
Utils.ARKTS_LANG_D_ETS = '@arkts.lang.d.ets';
Utils.LANG_NAMESPACE = 'lang';
Utils.ISENDABLE_TYPE = 'ISendable';
Utils.USE_SHARED = 'use shared';
var typeChecker;
function setTypeChecker(tsTypeChecker) {
typeChecker = tsTypeChecker;
@ -183942,6 +183946,20 @@ var ts;
}
return true;
}
function isSharedModule(sourceFile) {
var statements = sourceFile.statements;
for (var _i = 0, statements_1 = statements; _i < statements_1.length; _i++) {
var statement = statements_1[_i];
if (ts.isImportDeclaration(statement)) {
continue;
}
return (ts.isExpressionStatement(statement) &&
ts.isStringLiteral(statement.expression) &&
statement.expression.text === Utils.USE_SHARED);
}
return false;
}
Utils.isSharedModule = isSharedModule;
})(Utils = ArkTSLinter_1_1.Utils || (ArkTSLinter_1_1.Utils = {}));
})(ArkTSLinter_1_1 = ts.ArkTSLinter_1_1 || (ts.ArkTSLinter_1_1 = {}));
})(ts || (ts = {}));
@ -184219,6 +184237,7 @@ var ts;
initialize a "Sendable" object';
LinterConfig.nodeDesc[FaultID.SendableComputedPropName] = 'Sendable computed property name';
LinterConfig.nodeDesc[FaultID.SendableAsExpr] = 'Sendable as expr';
LinterConfig.nodeDesc[FaultID.SharedNoSideEffectImport] = 'Shared no side effect import';
};
LinterConfig.nodeDesc = [];
// The SyntaxKind enum defines additional elements at the end of the enum
@ -184384,6 +184403,7 @@ var ts;
}
TypeScriptLinter.initGlobals = function () {
TypeScriptLinter.filteredDiagnosticMessages = [];
TypeScriptLinter.sharedModulesCache = new ts.Map();
};
TypeScriptLinter.initStatic = function () {
TypeScriptLinter.strictMode = true;
@ -184819,6 +184839,25 @@ var ts;
this.incrementCounters(importDeclNode.assertClause, FaultID.ImportAssertion);
}
}
//handle no side effect import in sendable module
this.handleSharedModuleNoSideEffectImport(importDeclNode);
};
TypeScriptLinter.prototype.handleSharedModuleNoSideEffectImport = function (node) {
//check 'use shared'
if (TypeScriptLinter.inSharedModule(node)) {
if (!node.importClause) {
this.incrementCounters(node, FaultID.SharedNoSideEffectImport);
}
}
};
TypeScriptLinter.inSharedModule = function (node) {
var sourceFile = node.getSourceFile();
if (TypeScriptLinter.sharedModulesCache.has(ts.normalizePath(sourceFile.fileName))) {
return TypeScriptLinter.sharedModulesCache.get(ts.normalizePath(sourceFile.fileName));
}
var isSharedModule = ArkTSLinter_1_1.Utils.isSharedModule(sourceFile);
TypeScriptLinter.sharedModulesCache.set(ts.normalizePath(sourceFile.fileName), isSharedModule);
return isSharedModule;
};
TypeScriptLinter.prototype.handlePropertyAccessExpression = function (node) {
if (ts.isCallExpression(node.parent) && node == node.parent.expression) {

View File

@ -17,7 +17,7 @@ export namespace ArkTSLinter_1_1 {
export const cookBookMsg: string[] = [];
export const cookBookTag: string[] = [];
for (let i = 0; i <= 161; i++) {
for (let i = 0; i <= 162; i++) {
cookBookMsg[ i ] = "";
}
@ -181,5 +181,6 @@ cookBookTag[158] = 'Only "@Sendable" decorator can be used on "Sendable" class (
cookBookTag[159] = 'Objects of "Sendable" type can not be initialized using object literal or array literal (arkts-sendable-obj-init)';
cookBookTag[160] = 'Computed property names are not allowed in "Sendable" classes and interfaces (arkts-sendable-computed-prop-name)';
cookBookTag[161] = 'Casting "Non-sendable" data to "Sendable" type is not allowed (arkts-sendable-as-expr)';
cookBookTag[162] = "Shared module do not allow side effect import (arkts-no-side-effects-imports)";
}
}

View File

@ -40,7 +40,7 @@ export enum FaultID {
UtilityType, PropertyDeclOnFunction, FunctionApplyCall, FunctionBind, ConstAssertion, ImportAssertion,
SpreadOperator, LimitedStdLibApi, ErrorSuppression, StrictDiagnostic, ImportAfterStatement,
EsObjectType, SendableClassInheritance, SendablePropType, SendableDefiniteAssignment, SendableGenericTypes,
SendableClassDecorator, SendableObjectInitialization, SendableComputedPropName, SendableAsExpr,
SendableClassDecorator, SendableObjectInitialization, SendableComputedPropName, SendableAsExpr, SharedNoSideEffectImport,
LAST_ID, // this should always be last enum`
}
@ -144,6 +144,7 @@ faultsAttrs[FaultID.SendableClassDecorator] = new FaultAttributes(158);
faultsAttrs[FaultID.SendableObjectInitialization] = new FaultAttributes(159);
faultsAttrs[FaultID.SendableComputedPropName] = new FaultAttributes(160);
faultsAttrs[FaultID.SendableAsExpr] = new FaultAttributes(161);
faultsAttrs[FaultID.SharedNoSideEffectImport] = new FaultAttributes(162);
}
}
}

View File

@ -85,9 +85,11 @@ export class TypeScriptLinter {
static problemsInfos: ProblemInfo[] = [];
static filteredDiagnosticMessages: DiagnosticMessageChain[] = [];
static sharedModulesCache: ESMap<string, boolean>;
public static initGlobals(): void {
TypeScriptLinter.filteredDiagnosticMessages = []
TypeScriptLinter.sharedModulesCache = new Map<string, boolean>();
}
public static initStatic(): void {
@ -657,6 +659,29 @@ export class TypeScriptLinter {
this.incrementCounters(importDeclNode.assertClause, FaultID.ImportAssertion);
}
}
//handle no side effect import in sendable module
this.handleSharedModuleNoSideEffectImport(importDeclNode);
}
private handleSharedModuleNoSideEffectImport(node : ts.ImportDeclaration): void {
//check 'use shared'
if(TypeScriptLinter.inSharedModule(node)) {
if(!node.importClause){
this.incrementCounters(node, FaultID.SharedNoSideEffectImport);
}
}
}
private static inSharedModule(node: ts.Node): boolean {
const sourceFile: ts.SourceFile = node.getSourceFile();
if (TypeScriptLinter.sharedModulesCache.has(normalizePath(sourceFile.fileName))) {
return TypeScriptLinter.sharedModulesCache.get(normalizePath(sourceFile.fileName))!;
}
const isSharedModule: boolean = Utils.isSharedModule(sourceFile);
TypeScriptLinter.sharedModulesCache.set(normalizePath(sourceFile.fileName), isSharedModule);
return isSharedModule;
}
private handlePropertyAccessExpression(node: Node): void {

View File

@ -125,6 +125,7 @@ export class LinterConfig {
initialize a "Sendable" object';
LinterConfig.nodeDesc[FaultID.SendableComputedPropName] = 'Sendable computed property name';
LinterConfig.nodeDesc[FaultID.SendableAsExpr] = 'Sendable as expr';
LinterConfig.nodeDesc[FaultID.SharedNoSideEffectImport] = 'Shared no side effect import';
}
/*

View File

@ -58,6 +58,8 @@ export const LANG_NAMESPACE = 'lang';
export const ISENDABLE_TYPE = 'ISendable';
export const USE_SHARED = 'use shared';
let typeChecker: TypeChecker;
export function setTypeChecker(tsTypeChecker: TypeChecker): void {
typeChecker = tsTypeChecker;
@ -1971,6 +1973,23 @@ function isArkTSISendableDeclaration(decl: ts.Declaration): boolean {
return true;
}
export function isSharedModule(sourceFile: ts.SourceFile): boolean {
const statements = sourceFile.statements;
for (let statement of statements) {
if (ts.isImportDeclaration(statement)) {
continue;
}
return (
ts.isExpressionStatement(statement) &&
ts.isStringLiteral(statement.expression) &&
statement.expression.text === USE_SHARED
);
}
return false;
}
}
}
}

View File

@ -0,0 +1,26 @@
/*
* 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.
*/
// Description: shared module Import module
import 'lib1-dependencie'
import * as exampleValue from "lib1-dependencie";
import { export1 } from "lib1-dependencie";
import { exampleValue1, exampleValue2 } from "lib1-dependencie";
import { exampleValue1 as value1, exampleValue2 as value2 } from "lib1-dependencie";
'use shared'
window.MY_GLOBAL_VAR = 'Hello, world!'

View File

@ -0,0 +1,20 @@
{
"arktsVersion_1_0": [
{
"messageText": "Importing a module for side-effects only is not supported (arkts-no-side-effects-imports)",
"expectLineAndCharacter": {
"line": 19,
"character": 1
}
}
],
"arktsVersion_1_1": [
{
"messageText": "Shared module do not allow side effect import (arkts-no-side-effects-imports)",
"expectLineAndCharacter": {
"line": 19,
"character": 1
}
}
]
}

View File

@ -0,0 +1,17 @@
/*
* 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 const exampleValue = 42

View File

@ -0,0 +1,21 @@
/*
* 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.
*/
// Description: shared module Import module
import 'lib1-dependencie'
window.MY_GLOBAL_VAR = 'Hello, world!'

View File

@ -0,0 +1,12 @@
{
"arktsVersion_1_0": [
{
"messageText": "Importing a module for side-effects only is not supported (arkts-no-side-effects-imports)",
"expectLineAndCharacter": {
"line": 19,
"character": 1
}
}
],
"arktsVersion_1_1": []
}

View File

@ -0,0 +1,17 @@
/*
* 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 const exampleValue = 42

View File

@ -0,0 +1,26 @@
/*
* 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.
*/
// Description: shared module Import module
import exampleValue1 from 'lib1-dependencie'
import * as exampleValue from "lib1-dependencie";
import { export1 } from "lib1-dependencie";
import { exampleValue1, exampleValue2 } from "lib1-dependencie";
import { exampleValue1 as value1, exampleValue2 as value2 } from "lib1-dependencie";
'use shared'
window.MY_GLOBAL_VAR = 'Hello, world!'

View File

@ -0,0 +1,12 @@
{
"arktsVersion_1_0": [
{
"messageText": "Importing a module for side-effects only is not supported (arkts-no-side-effects-imports)",
"expectLineAndCharacter": {
"line": 19,
"character": 1
}
}
],
"arktsVersion_1_1": []
}

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 const exampleValue1 = 42
export const exampleValue2 = 22

View File

@ -13140,7 +13140,8 @@ declare namespace ts {
SendableObjectInitialization = 87,
SendableComputedPropName = 88,
SendableAsExpr = 89,
LAST_ID = 90
SharedNoSideEffectImport = 90,
LAST_ID = 91
}
class FaultAttributes {
cookBookRef: number;
@ -13171,6 +13172,7 @@ declare namespace ts {
const ARKTS_LANG_D_ETS = "@arkts.lang.d.ets";
const LANG_NAMESPACE = "lang";
const ISENDABLE_TYPE = "ISendable";
const USE_SHARED = "use shared";
function setTypeChecker(tsTypeChecker: TypeChecker): void;
function clearTypeChecker(): void;
function setTestMode(tsTestMode: boolean): void;
@ -13335,6 +13337,7 @@ declare namespace ts {
function getNonSendableDecorators(decl: ts.ClassDeclaration): ts.Decorator[] | undefined;
function getDecoratorsIfInSendableClass(declaration: ts.HasDecorators): readonly ts.Decorator[] | undefined;
function isISendableInterface(type: ts.Type): boolean;
function isSharedModule(sourceFile: ts.SourceFile): boolean;
}
}
}
@ -13407,6 +13410,7 @@ declare namespace ts {
static reportDiagnostics: boolean;
static problemsInfos: ProblemInfo[];
static filteredDiagnosticMessages: DiagnosticMessageChain[];
static sharedModulesCache: ESMap<string, boolean>;
static initGlobals(): void;
static initStatic(): void;
static tsTypeChecker: TypeChecker;
@ -13438,6 +13442,8 @@ declare namespace ts {
private handleForInStatement;
private handleForOfStatement;
private handleImportDeclaration;
private handleSharedModuleNoSideEffectImport;
private static inSharedModule;
private handlePropertyAccessExpression;
private handlePropertyDeclaration;
private handleSendableClassProperty;

View File

@ -9201,7 +9201,8 @@ declare namespace ts {
SendableObjectInitialization = 87,
SendableComputedPropName = 88,
SendableAsExpr = 89,
LAST_ID = 90
SharedNoSideEffectImport = 90,
LAST_ID = 91
}
class FaultAttributes {
cookBookRef: number;
@ -9232,6 +9233,7 @@ declare namespace ts {
const ARKTS_LANG_D_ETS = "@arkts.lang.d.ets";
const LANG_NAMESPACE = "lang";
const ISENDABLE_TYPE = "ISendable";
const USE_SHARED = "use shared";
function setTypeChecker(tsTypeChecker: TypeChecker): void;
function clearTypeChecker(): void;
function setTestMode(tsTestMode: boolean): void;
@ -9396,6 +9398,7 @@ declare namespace ts {
function getNonSendableDecorators(decl: ts.ClassDeclaration): ts.Decorator[] | undefined;
function getDecoratorsIfInSendableClass(declaration: ts.HasDecorators): readonly ts.Decorator[] | undefined;
function isISendableInterface(type: ts.Type): boolean;
function isSharedModule(sourceFile: ts.SourceFile): boolean;
}
}
}
@ -9468,6 +9471,7 @@ declare namespace ts {
static reportDiagnostics: boolean;
static problemsInfos: ProblemInfo[];
static filteredDiagnosticMessages: DiagnosticMessageChain[];
static sharedModulesCache: ESMap<string, boolean>;
static initGlobals(): void;
static initStatic(): void;
static tsTypeChecker: TypeChecker;
@ -9499,6 +9503,8 @@ declare namespace ts {
private handleForInStatement;
private handleForOfStatement;
private handleImportDeclaration;
private handleSharedModuleNoSideEffectImport;
private static inSharedModule;
private handlePropertyAccessExpression;
private handlePropertyDeclaration;
private handleSendableClassProperty;