@komaci/static-analyzer 240.1.5 → 242.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -0
- package/RULES.md +1253 -0
- package/build/helpers.d.ts +10 -0
- package/build/helpers.js +87 -0
- package/build/index.d.ts +2 -2
- package/build/index.js +6 -4
- package/build/invariantFunctions/assignmentExpressionInvariantFunctions.js +2 -2
- package/build/invariantFunctions/callExpressionInvariantFunctions.d.ts +2 -2
- package/build/invariantFunctions/callExpressionInvariantFunctions.js +9 -9
- package/build/invariantFunctions/functionExpressionInvariantFunctions.js +4 -4
- package/build/invariantFunctions/identifierInvariantFunctions.d.ts +2 -2
- package/build/invariantFunctions/identifierInvariantFunctions.js +5 -3
- package/build/invariantFunctions/memberExpressionInvariantFunctions.d.ts +5 -5
- package/build/invariantFunctions/memberExpressionInvariantFunctions.js +21 -38
- package/build/invariantFunctions/taggedTemplateExpressionInvariantFunctions.d.ts +2 -2
- package/build/invariantFunctions/taggedTemplateExpressionInvariantFunctions.js +5 -5
- package/build/rules.js +8 -44
- package/build/shared.d.ts +21 -17
- package/build/shared.js +92 -81
- package/build/staticAnalyzer.d.ts +10 -22
- package/build/staticAnalyzer.js +91 -131
- package/build/types.d.ts +17 -0
- package/build/validateGetter.d.ts +4 -4
- package/build/validateGetter.js +65 -61
- package/package.json +7 -7
- package/build/adaptersMapping.d.ts +0 -3
- package/build/adaptersMapping.js +0 -25
- package/build/allowlistAdapters.d.ts +0 -6
- package/build/allowlistAdapters.js +0 -10
- package/build/komaci-mapping.json +0 -288
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Composition } from '@komaci/types';
|
|
2
|
+
import { CompositionProperty } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Given a list of compositions, get all the properties used in any of the compostion
|
|
5
|
+
*
|
|
6
|
+
* @param compositions array of compositions
|
|
7
|
+
* @returns array of analyzed composition properties
|
|
8
|
+
*/
|
|
9
|
+
export declare function findPropertiesUsedInCompositions(compositions: Composition[]): CompositionProperty[];
|
|
10
|
+
//# sourceMappingURL=helpers.d.ts.map
|
package/build/helpers.js
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.findPropertiesUsedInCompositions = void 0;
|
|
4
|
+
const common_shared_1 = require("@komaci/common-shared");
|
|
5
|
+
let iteratorMap;
|
|
6
|
+
/**
|
|
7
|
+
* Convert array of Compositions into flattened array of Compositions,
|
|
8
|
+
* visiting top-level and nested children compositions
|
|
9
|
+
*
|
|
10
|
+
* Collecting iterator on iterations
|
|
11
|
+
*/
|
|
12
|
+
function compositionsToArray(compositions, parentIterators) {
|
|
13
|
+
const compositionArray = [];
|
|
14
|
+
compositions.forEach((node) => {
|
|
15
|
+
compositionArray.push(node);
|
|
16
|
+
// set node -> iterators relation
|
|
17
|
+
iteratorMap.set(node, parentIterators);
|
|
18
|
+
if (node.compositions) {
|
|
19
|
+
// inherit parent or add current iterator
|
|
20
|
+
const iterators = (0, common_shared_1.isCompositionAnIteration)(node)
|
|
21
|
+
? [node.iterator, ...parentIterators]
|
|
22
|
+
: parentIterators;
|
|
23
|
+
compositionArray.push(...compositionsToArray(node.compositions, iterators));
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
return compositionArray;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Given a flattened array of compositions, get all the properties used in any of the compostion
|
|
30
|
+
*
|
|
31
|
+
* @param compositionArray the composition array
|
|
32
|
+
* @returns array of used properties of giving compositions
|
|
33
|
+
*/
|
|
34
|
+
function processPropertiesUsedInCompositions(compositionArray) {
|
|
35
|
+
const properties = [];
|
|
36
|
+
for (const composition of compositionArray) {
|
|
37
|
+
// Iteration tested by: artifact-combined-files/unresolvableIterator
|
|
38
|
+
if ((0, common_shared_1.isCompositionAnIteration)(composition)) {
|
|
39
|
+
const propertyName = (0, common_shared_1.stripChildReferenceFromValue)(composition.input.value);
|
|
40
|
+
if (!iteratorMap.get(composition)?.includes(propertyName)) {
|
|
41
|
+
properties.push({
|
|
42
|
+
propertyName: propertyName,
|
|
43
|
+
location: composition.location,
|
|
44
|
+
diagnosticMessageAct: 'iterator iterates upon',
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
// Image test by: artifact-combined-files/unresolvedImageBinding
|
|
49
|
+
if ((0, common_shared_1.isCompositionAnImage)(composition) && composition.src.type === 'Binding') {
|
|
50
|
+
const propertyName = (0, common_shared_1.stripChildReferenceFromValue)(composition.src.value);
|
|
51
|
+
if (!iteratorMap.get(composition)?.includes(propertyName)) {
|
|
52
|
+
properties.push({
|
|
53
|
+
propertyName: propertyName,
|
|
54
|
+
location: composition.location,
|
|
55
|
+
diagnosticMessageAct: "image's src attribute is bound to",
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
if ((0, common_shared_1.isCompositionAComposedAdg)(composition) && composition.properties) {
|
|
60
|
+
for (const property of Object.values(composition.properties)) {
|
|
61
|
+
if (property.type === 'Binding') {
|
|
62
|
+
const propertyName = (0, common_shared_1.stripChildReferenceFromValue)(property.value);
|
|
63
|
+
if (!iteratorMap.get(composition)?.includes(propertyName)) {
|
|
64
|
+
properties.push({
|
|
65
|
+
propertyName: propertyName,
|
|
66
|
+
location: composition.location,
|
|
67
|
+
diagnosticMessageAct: 'child component references',
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return properties;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Given a list of compositions, get all the properties used in any of the compostion
|
|
78
|
+
*
|
|
79
|
+
* @param compositions array of compositions
|
|
80
|
+
* @returns array of analyzed composition properties
|
|
81
|
+
*/
|
|
82
|
+
function findPropertiesUsedInCompositions(compositions) {
|
|
83
|
+
iteratorMap = new WeakMap();
|
|
84
|
+
return processPropertiesUsedInCompositions(compositionsToArray(compositions, []));
|
|
85
|
+
}
|
|
86
|
+
exports.findPropertiesUsedInCompositions = findPropertiesUsedInCompositions;
|
|
87
|
+
//# sourceMappingURL=helpers.js.map
|
package/build/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AnalyzerInput, PrimingDiagnostic } from './types';
|
|
2
2
|
export declare function generatePrimingDiagnosticsModule(input: AnalyzerInput): PrimingDiagnostic[];
|
|
3
|
-
export { AnalyzerInput, PrimingDiagnostic, Range, Position
|
|
4
|
-
export {
|
|
3
|
+
export { AnalyzerInput, PrimingDiagnostic, Range, Position } from './types';
|
|
4
|
+
export { isSupportedNamespace, isImageComposition } from './shared';
|
|
5
5
|
export { diagnosticMessages, getPrimingDiagnostic } from './rules';
|
|
6
6
|
export * from './validateGetter';
|
|
7
7
|
//# sourceMappingURL=index.d.ts.map
|
package/build/index.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -10,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
10
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
15
|
};
|
|
12
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
exports.getPrimingDiagnostic = exports.diagnosticMessages = exports.isImageComposition = exports.
|
|
17
|
+
exports.getPrimingDiagnostic = exports.diagnosticMessages = exports.isImageComposition = exports.isSupportedNamespace = exports.generatePrimingDiagnosticsModule = void 0;
|
|
14
18
|
const staticAnalyzer_1 = require("./staticAnalyzer");
|
|
15
19
|
function generatePrimingDiagnosticsModule(input) {
|
|
16
20
|
const analyzer = new staticAnalyzer_1.StaticAnalyzer();
|
|
@@ -24,9 +28,7 @@ function generatePrimingDiagnosticsModule(input) {
|
|
|
24
28
|
}
|
|
25
29
|
exports.generatePrimingDiagnosticsModule = generatePrimingDiagnosticsModule;
|
|
26
30
|
var shared_1 = require("./shared");
|
|
27
|
-
Object.defineProperty(exports, "getPrimingAdapter", { enumerable: true, get: function () { return shared_1.getPrimingAdapter; } });
|
|
28
31
|
Object.defineProperty(exports, "isSupportedNamespace", { enumerable: true, get: function () { return shared_1.isSupportedNamespace; } });
|
|
29
|
-
Object.defineProperty(exports, "isSupportedWireAdapter", { enumerable: true, get: function () { return shared_1.isSupportedWireAdapter; } });
|
|
30
32
|
Object.defineProperty(exports, "isImageComposition", { enumerable: true, get: function () { return shared_1.isImageComposition; } });
|
|
31
33
|
var rules_1 = require("./rules");
|
|
32
34
|
Object.defineProperty(exports, "diagnosticMessages", { enumerable: true, get: function () { return rules_1.diagnosticMessages; } });
|
|
@@ -12,7 +12,7 @@ function checkForNoMemberVariableAssignments(path) {
|
|
|
12
12
|
const assignmentExpr = path.node;
|
|
13
13
|
const leftNode = assignmentExpr.left;
|
|
14
14
|
if (leftNode.object?.type === 'ThisExpression') {
|
|
15
|
-
if (leftNode.loc
|
|
15
|
+
if (leftNode.loc) {
|
|
16
16
|
return (0, rules_1.getPrimingDiagnostic)(rules_1.diagnosticMessages.NO_ASSIGNMENT_EXPRESSION_ASSIGNS_VALUE_TO_MEMBER_VARIABLE, shared_1.LLSRange.fromBabelSourceLocation(leftNode.loc), [leftNode.property.name]);
|
|
17
17
|
}
|
|
18
18
|
}
|
|
@@ -26,7 +26,7 @@ exports.checkForNoMemberVariableAssignments = checkForNoMemberVariableAssignment
|
|
|
26
26
|
*/
|
|
27
27
|
function checkExternalComponentForAssignmentExpr(path) {
|
|
28
28
|
const assignmentExpr = path.node;
|
|
29
|
-
if (assignmentExpr.loc
|
|
29
|
+
if (assignmentExpr.loc) {
|
|
30
30
|
return (0, rules_1.getPrimingDiagnostic)(rules_1.diagnosticMessages.NO_ASSIGNMENT_EXPRESSION_FOR_EXTERNAL_COMPONENTS, shared_1.LLSRange.fromBabelSourceLocation(assignmentExpr.loc), []);
|
|
31
31
|
}
|
|
32
32
|
}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { NodePath } from '@babel/traverse';
|
|
2
2
|
import * as t from '@babel/types';
|
|
3
3
|
import { PrimingDiagnostic } from '../types';
|
|
4
|
-
import {
|
|
4
|
+
import { ImportMetadata } from '@komaci/common-shared';
|
|
5
5
|
/**
|
|
6
6
|
* Invariant function for checking if call expressions references an unsupported import.
|
|
7
7
|
* @param path the babel path object for the current call expression.
|
|
8
8
|
* @param importReferences a set of supported import references.
|
|
9
9
|
* @returns undefined if a call expression does NOT reference an unspoorted import, locatoin object if a call expression references an unsupported import.
|
|
10
10
|
*/
|
|
11
|
-
export declare function checkCallExpressionForNonSupportedNamespaceRefs(path: NodePath<t.CallExpression>, importReferences: Map<string,
|
|
11
|
+
export declare function checkCallExpressionForNonSupportedNamespaceRefs(path: NodePath<t.CallExpression>, importReferences: Map<string, ImportMetadata>): PrimingDiagnostic | undefined;
|
|
12
12
|
/**
|
|
13
13
|
* Validates whether a CallExpression Node on the AST adheres to a portability invariant (whether it doesn't
|
|
14
14
|
* contain 'eval()' call).
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.checkForNoReferenceToModuleFunctions = exports.checkForNoReferenceToClassFunctions = exports.checkNoUsageOfEval = exports.checkCallExpressionForNonSupportedNamespaceRefs = void 0;
|
|
4
4
|
const shared_1 = require("../shared");
|
|
5
|
+
const common_shared_1 = require("@komaci/common-shared");
|
|
5
6
|
const rules_1 = require("../rules");
|
|
6
7
|
/**
|
|
7
8
|
* Invariant function for checking if call expressions references an unsupported import.
|
|
@@ -12,11 +13,10 @@ const rules_1 = require("../rules");
|
|
|
12
13
|
function checkCallExpressionForNonSupportedNamespaceRefs(path, importReferences) {
|
|
13
14
|
const callExprNode = path.node;
|
|
14
15
|
const callee = callExprNode.callee;
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
16
|
+
const importRef = importReferences.get(callee.name);
|
|
17
|
+
if (importRef && (0, common_shared_1.isImportInvalid)(importRef)) {
|
|
18
|
+
if (callee.loc != null) {
|
|
19
|
+
return (0, rules_1.getPrimingDiagnostic)(rules_1.diagnosticMessages.NO_CALL_EXPRESSION_REFERENCES_UNSUPPORTED_NAMESPACE, shared_1.LLSRange.fromBabelSourceLocation(callee.loc), [callee.name]);
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
22
|
return undefined;
|
|
@@ -31,7 +31,7 @@ exports.checkCallExpressionForNonSupportedNamespaceRefs = checkCallExpressionFor
|
|
|
31
31
|
function checkNoUsageOfEval(path) {
|
|
32
32
|
const callExpr = path.node;
|
|
33
33
|
if (callExpr.callee.type === 'Identifier' && callExpr.callee.name === 'eval') {
|
|
34
|
-
if (callExpr.callee.loc
|
|
34
|
+
if (callExpr.callee.loc) {
|
|
35
35
|
return (0, rules_1.getPrimingDiagnostic)(rules_1.diagnosticMessages.NO_EVAL_USAGE, shared_1.LLSRange.fromBabelSourceLocation(callExpr.callee.loc), [callExpr.callee.name]);
|
|
36
36
|
}
|
|
37
37
|
}
|
|
@@ -49,7 +49,7 @@ function checkForNoReferenceToClassFunctions(path, classFunctions) {
|
|
|
49
49
|
if (callExpr.callee.type === 'MemberExpression') {
|
|
50
50
|
const memberExpr = callExpr.callee;
|
|
51
51
|
if (memberExpr.object.type === 'ThisExpression') {
|
|
52
|
-
if (memberExpr.object.loc
|
|
52
|
+
if (memberExpr.object.loc) {
|
|
53
53
|
return (0, rules_1.getPrimingDiagnostic)(rules_1.diagnosticMessages.NO_REFERENCE_TO_CLASS_FUNCTIONS, shared_1.LLSRange.fromBabelSourceLocation(memberExpr.object.loc), [memberExpr.property.name]);
|
|
54
54
|
}
|
|
55
55
|
}
|
|
@@ -57,7 +57,7 @@ function checkForNoReferenceToClassFunctions(path, classFunctions) {
|
|
|
57
57
|
if (callExpr.callee.type === 'Identifier') {
|
|
58
58
|
const identifier = callExpr.callee;
|
|
59
59
|
if (classFunctions.includes(identifier.name)) {
|
|
60
|
-
if (callExpr.callee.loc
|
|
60
|
+
if (callExpr.callee.loc) {
|
|
61
61
|
return (0, rules_1.getPrimingDiagnostic)(rules_1.diagnosticMessages.NO_REFERENCE_TO_CLASS_FUNCTIONS, shared_1.LLSRange.fromBabelSourceLocation(callExpr.callee.loc), [callExpr.callee.name]);
|
|
62
62
|
}
|
|
63
63
|
}
|
|
@@ -76,7 +76,7 @@ function checkForNoReferenceToModuleFunctions(path, moduleFunctions) {
|
|
|
76
76
|
if (callExpr.callee.type === 'Identifier') {
|
|
77
77
|
const identifier = callExpr.callee;
|
|
78
78
|
if (moduleFunctions.includes(identifier.name)) {
|
|
79
|
-
if (callExpr.callee.loc
|
|
79
|
+
if (callExpr.callee.loc) {
|
|
80
80
|
return (0, rules_1.getPrimingDiagnostic)(rules_1.diagnosticMessages.NO_REFERENCE_TO_MODULE_FUNCTIONS, shared_1.LLSRange.fromBabelSourceLocation(callExpr.callee.loc), [callExpr.callee.name]);
|
|
81
81
|
}
|
|
82
82
|
}
|
|
@@ -16,19 +16,19 @@ function checkForFunctionExpression(path) {
|
|
|
16
16
|
if (expr.type === 'FunctionExpression') {
|
|
17
17
|
const funcExpr = expr;
|
|
18
18
|
if (funcExpr.id === null) {
|
|
19
|
-
if (funcExpr.loc
|
|
19
|
+
if (funcExpr.loc) {
|
|
20
20
|
return (0, rules_1.getPrimingDiagnostic)(rules_1.diagnosticMessages.NO_FUNCTIONS_DECLARED_WITHIN_GETTER_METHOD, shared_1.LLSRange.fromBabelSourceLocation(funcExpr.loc), []);
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
23
|
else {
|
|
24
|
-
if (funcExpr.loc
|
|
24
|
+
if (funcExpr.loc) {
|
|
25
25
|
return (0, rules_1.getPrimingDiagnostic)(rules_1.diagnosticMessages.NO_FUNCTIONS_DECLARED_WITHIN_GETTER_METHOD, shared_1.LLSRange.fromBabelSourceLocation(funcExpr.loc), []);
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
29
|
else if (expr.type === 'ArrowFunctionExpression') {
|
|
30
30
|
const arrowFuncExpr = expr;
|
|
31
|
-
if (arrowFuncExpr.loc
|
|
31
|
+
if (arrowFuncExpr.loc) {
|
|
32
32
|
return (0, rules_1.getPrimingDiagnostic)(rules_1.diagnosticMessages.NO_FUNCTIONS_DECLARED_WITHIN_GETTER_METHOD, shared_1.LLSRange.fromBabelSourceLocation(arrowFuncExpr.loc), []);
|
|
33
33
|
}
|
|
34
34
|
}
|
|
@@ -58,7 +58,7 @@ function checkForObjectMethodFunctionDeclarations(moduleContext, path) {
|
|
|
58
58
|
const objMethod = path.node;
|
|
59
59
|
if (moduleContext.isExternal) {
|
|
60
60
|
if (objMethod.type === 'ObjectMethod') {
|
|
61
|
-
if (objMethod.loc
|
|
61
|
+
if (objMethod.loc) {
|
|
62
62
|
return (0, rules_1.getPrimingDiagnostic)(rules_1.diagnosticMessages.NO_FUNCTIONS_DECLARED_WITHIN_GETTER_METHOD, shared_1.LLSRange.fromBabelSourceLocation(objMethod.loc), []);
|
|
63
63
|
}
|
|
64
64
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { NodePath } from '@babel/traverse';
|
|
2
2
|
import * as t from '@babel/types';
|
|
3
|
-
import {
|
|
3
|
+
import { ImportMetadata } from '@komaci/common-shared';
|
|
4
4
|
import { PrimingDiagnostic } from '../types';
|
|
5
5
|
/**
|
|
6
6
|
* Invariant function to check for no references to module varaibles.
|
|
@@ -24,5 +24,5 @@ export declare function checkForNoReferenceToModuleVariables(path: NodePath<t.Id
|
|
|
24
24
|
* @returns undefined if a member expression does NOT reference an unsuppoerted import, PrimingDiagnostic object
|
|
25
25
|
* if an unsupported import is reference.
|
|
26
26
|
*/
|
|
27
|
-
export declare function checkIdentifierForNonSupportedNamespaceRefs(path: NodePath<t.Identifier>, importReferences: Map<string,
|
|
27
|
+
export declare function checkIdentifierForNonSupportedNamespaceRefs(path: NodePath<t.Identifier>, importReferences: Map<string, ImportMetadata>, declaredVariables: string[]): PrimingDiagnostic | undefined;
|
|
28
28
|
//# sourceMappingURL=identifierInvariantFunctions.d.ts.map
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.checkIdentifierForNonSupportedNamespaceRefs = exports.checkForNoReferenceToModuleVariables = void 0;
|
|
4
|
+
const common_shared_1 = require("@komaci/common-shared");
|
|
4
5
|
const rules_1 = require("../rules");
|
|
5
6
|
const shared_1 = require("../shared");
|
|
6
7
|
/**
|
|
@@ -38,15 +39,16 @@ exports.checkForNoReferenceToModuleVariables = checkForNoReferenceToModuleVariab
|
|
|
38
39
|
*/
|
|
39
40
|
function checkIdentifierForNonSupportedNamespaceRefs(path, importReferences, declaredVariables) {
|
|
40
41
|
const identifier = path.node;
|
|
42
|
+
const importRef = importReferences.get(identifier.name);
|
|
41
43
|
if (path.parent.type !== 'Decorator' &&
|
|
42
44
|
path.parent.type !== 'MemberExpression' &&
|
|
43
45
|
path.parent.type !== 'CallExpression' &&
|
|
44
46
|
path.parent.type !== 'TaggedTemplateExpression' &&
|
|
45
47
|
path.parent.type !== 'ThisExpression' &&
|
|
46
|
-
|
|
47
|
-
|
|
48
|
+
importRef &&
|
|
49
|
+
(0, common_shared_1.isImportInvalid)(importRef) &&
|
|
48
50
|
!declaredVariables.includes(identifier.name)) {
|
|
49
|
-
if (identifier.loc
|
|
51
|
+
if (identifier.loc) {
|
|
50
52
|
return (0, rules_1.getPrimingDiagnostic)(rules_1.diagnosticMessages.NO_REFERENCE_TO_UNSUPPORTED_NAMESPACE_REFERENCE, shared_1.LLSRange.fromBabelSourceLocation(identifier.loc), [identifier.name]);
|
|
51
53
|
}
|
|
52
54
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { NodePath } from '@babel/traverse';
|
|
2
2
|
import * as t from '@babel/types';
|
|
3
3
|
import { PrimingDiagnostic } from '../types';
|
|
4
|
-
import {
|
|
4
|
+
import { AstContext, ClassPropertyContexts, ImportMetadata } from '@komaci/common-shared';
|
|
5
5
|
/**
|
|
6
6
|
* Invariant function for checking if a member expression references a non decorated member var.
|
|
7
7
|
* @param path the babel path object for the current member expressoin
|
|
@@ -9,7 +9,7 @@ import { ClassPropertyInfo, ImportDeclarationInfo, AstContext } from '@komaci/co
|
|
|
9
9
|
* @returns undefined if the member expression does NOT reference an unsupported member var, PrimingDiagnostic object if an unsuppported
|
|
10
10
|
* member variable is referenced
|
|
11
11
|
*/
|
|
12
|
-
export declare function checkForNonSupportedMemberRefs(path: NodePath<t.MemberExpression>, memberVars:
|
|
12
|
+
export declare function checkForNonSupportedMemberRefs(path: NodePath<t.MemberExpression>, memberVars: ClassPropertyContexts): PrimingDiagnostic | undefined;
|
|
13
13
|
/**
|
|
14
14
|
* Invariant function for checking if a member expression references a non-existent member property variable
|
|
15
15
|
* @param {NodePath<MemberExpression>} path babel/types path object representing the current member expression
|
|
@@ -18,7 +18,7 @@ export declare function checkForNonSupportedMemberRefs(path: NodePath<t.MemberEx
|
|
|
18
18
|
* @returns {(PrimingDiagnostic | undefined)} undefined if the member expression does NOT reference a non-existent member property variable. Returns a
|
|
19
19
|
* PrimingDiagnostic object if a non-existent member property variable is referenced
|
|
20
20
|
*/
|
|
21
|
-
export declare function checkForNonExistentMemberRefs(path: NodePath<t.MemberExpression>, memberVars:
|
|
21
|
+
export declare function checkForNonExistentMemberRefs(path: NodePath<t.MemberExpression>, memberVars: ClassPropertyContexts, thisAliases: Set<string>): PrimingDiagnostic | undefined;
|
|
22
22
|
/**
|
|
23
23
|
* Invariant function to check if a member expression references an unsupported import.
|
|
24
24
|
* @param path the babel path object for the current member expression
|
|
@@ -26,7 +26,7 @@ export declare function checkForNonExistentMemberRefs(path: NodePath<t.MemberExp
|
|
|
26
26
|
* @returns undefined if a member expression does NOT reference an unsuppoerted import, PrimingDiagnostic object
|
|
27
27
|
* if an unsupported import is reference.
|
|
28
28
|
*/
|
|
29
|
-
export declare function checkMemberExpressionForNonSupportedNamespaceRefs(path: NodePath<t.MemberExpression>, importReferences: Map<string,
|
|
29
|
+
export declare function checkMemberExpressionForNonSupportedNamespaceRefs(path: NodePath<t.MemberExpression>, importReferences: Map<string, ImportMetadata>): PrimingDiagnostic | undefined;
|
|
30
30
|
/**
|
|
31
31
|
* Validates whether a MemberExpression Node on the AST adheres to a portability invariant (whether it doesn't
|
|
32
32
|
* contain 'document', 'window' indentifiers within an expression).
|
|
@@ -46,5 +46,5 @@ export declare function checkForNoUseOfSuper(path: NodePath<t.MemberExpression>)
|
|
|
46
46
|
* @param astContext the ast context that holds meta data about the scr code.
|
|
47
47
|
* @returns a Priming Diagnostic if there is a global reference undefined if none
|
|
48
48
|
*/
|
|
49
|
-
export declare function checkForUnsupportedGlobalRef(path: NodePath<t.MemberExpression>, astContext: AstContext, declaredGetterVars: string[]): PrimingDiagnostic | undefined;
|
|
49
|
+
export declare function checkForUnsupportedGlobalRef(path: NodePath<t.MemberExpression>, astContext: AstContext, imports: Map<string, ImportMetadata>, properties: ClassPropertyContexts, declaredGetterVars: string[]): PrimingDiagnostic | undefined;
|
|
50
50
|
//# sourceMappingURL=memberExpressionInvariantFunctions.d.ts.map
|
|
@@ -1,26 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
-
}) : (function(o, m, k, k2) {
|
|
6
|
-
if (k2 === undefined) k2 = k;
|
|
7
|
-
o[k2] = m[k];
|
|
8
|
-
}));
|
|
9
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
-
}) : function(o, v) {
|
|
12
|
-
o["default"] = v;
|
|
13
|
-
});
|
|
14
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
-
if (mod && mod.__esModule) return mod;
|
|
16
|
-
var result = {};
|
|
17
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
-
__setModuleDefault(result, mod);
|
|
19
|
-
return result;
|
|
20
|
-
};
|
|
21
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
3
|
exports.checkForUnsupportedGlobalRef = exports.checkForNoUseOfSuper = exports.checkNoUsageOfDocumentOrWindow = exports.checkMemberExpressionForNonSupportedNamespaceRefs = exports.checkForNonExistentMemberRefs = exports.checkForNonSupportedMemberRefs = void 0;
|
|
23
|
-
const t = __importStar(require("@babel/types"));
|
|
24
4
|
const shared_1 = require("../shared");
|
|
25
5
|
const common_shared_1 = require("@komaci/common-shared");
|
|
26
6
|
const rules_1 = require("../rules");
|
|
@@ -35,12 +15,16 @@ function checkForNonSupportedMemberRefs(path, memberVars) {
|
|
|
35
15
|
const memberExprNode = path.node;
|
|
36
16
|
if (memberExprNode.object.type == 'ThisExpression') {
|
|
37
17
|
const memberExprProperty = memberExprNode.property;
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
!
|
|
42
|
-
|
|
43
|
-
|
|
18
|
+
const memberExprName = (0, common_shared_1.getFromIdentifierOrStringLiteral)(memberExprProperty);
|
|
19
|
+
const prop = memberVars.get(memberExprName);
|
|
20
|
+
if (prop &&
|
|
21
|
+
!prop.inital &&
|
|
22
|
+
!((prop.type === common_shared_1.PropertyTypes.BASE && prop.isPublic) ||
|
|
23
|
+
prop.type === common_shared_1.PropertyTypes.WIRE ||
|
|
24
|
+
prop.type === common_shared_1.PropertyTypes.GETTER ||
|
|
25
|
+
prop.type === common_shared_1.PropertyTypes.TEMPLATE_STRING)) {
|
|
26
|
+
if (memberExprProperty.loc) {
|
|
27
|
+
return (0, rules_1.getPrimingDiagnostic)(rules_1.diagnosticMessages.NO_UNSUPPORTED_MEMBER_VARIABLE_IN_MEMBER_EXPRESSION, shared_1.LLSRange.fromBabelSourceLocation(memberExprProperty.loc), [memberExprName]);
|
|
44
28
|
}
|
|
45
29
|
}
|
|
46
30
|
}
|
|
@@ -63,9 +47,9 @@ function checkForNonExistentMemberRefs(path, memberVars, thisAliases) {
|
|
|
63
47
|
parentNode.type !== 'CallExpression' // check that this is not a part of a function call, which is already handled by invariant: `checkForNoReferenceToClassFunctions`
|
|
64
48
|
) {
|
|
65
49
|
const memberExprValue = (0, common_shared_1.getFromIdentifierOrStringLiteral)(memberExprProperty);
|
|
66
|
-
if (!memberVars.
|
|
50
|
+
if (!memberVars.has(memberExprValue)) {
|
|
67
51
|
const sourceLoc = memberExprProperty.loc;
|
|
68
|
-
if (sourceLoc !== null) {
|
|
52
|
+
if (sourceLoc !== null && sourceLoc !== undefined) {
|
|
69
53
|
return (0, rules_1.getPrimingDiagnostic)(rules_1.diagnosticMessages.NO_MEMBER_EXPRESSION_REFERENCE_TO_NON_EXISTENT_MEMBER_VARIABLE, shared_1.LLSRange.fromBabelSourceLocation(sourceLoc), [memberExprValue]);
|
|
70
54
|
}
|
|
71
55
|
}
|
|
@@ -83,11 +67,10 @@ exports.checkForNonExistentMemberRefs = checkForNonExistentMemberRefs;
|
|
|
83
67
|
function checkMemberExpressionForNonSupportedNamespaceRefs(path, importReferences) {
|
|
84
68
|
const mememberExprNode = path.node;
|
|
85
69
|
const objectIdentifier = mememberExprNode.object;
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
}
|
|
70
|
+
const importRef = importReferences.get(objectIdentifier.name);
|
|
71
|
+
if (importRef && (0, common_shared_1.isImportInvalid)(importRef)) {
|
|
72
|
+
if (objectIdentifier.loc !== null && objectIdentifier.loc !== undefined) {
|
|
73
|
+
return (0, rules_1.getPrimingDiagnostic)(rules_1.diagnosticMessages.NO_MEMBER_EXPRESSION_REFERENCE_TO_UNSUPPORTED_NAMESPACE_REFERENCE, shared_1.LLSRange.fromBabelSourceLocation(objectIdentifier.loc), [objectIdentifier.name]);
|
|
91
74
|
}
|
|
92
75
|
}
|
|
93
76
|
return undefined;
|
|
@@ -103,7 +86,7 @@ function checkNoUsageOfDocumentOrWindow(path) {
|
|
|
103
86
|
const memberExpr = path.node;
|
|
104
87
|
if (memberExpr.object.type === 'Identifier' &&
|
|
105
88
|
(memberExpr.object.name === 'window' || memberExpr.object.name === 'document')) {
|
|
106
|
-
if (memberExpr.loc
|
|
89
|
+
if (memberExpr.loc) {
|
|
107
90
|
return (0, rules_1.getPrimingDiagnostic)(rules_1.diagnosticMessages.NO_MEMBER_EXPRESSION_CONTAINS_NON_PORTABLE_IDENTIFIER, shared_1.LLSRange.fromBabelSourceLocation(memberExpr.loc), [memberExpr.object.name]);
|
|
108
91
|
}
|
|
109
92
|
}
|
|
@@ -118,7 +101,7 @@ exports.checkNoUsageOfDocumentOrWindow = checkNoUsageOfDocumentOrWindow;
|
|
|
118
101
|
function checkForNoUseOfSuper(path) {
|
|
119
102
|
const memberExpr = path.node;
|
|
120
103
|
if (memberExpr.object.type === 'Super') {
|
|
121
|
-
if (memberExpr.loc
|
|
104
|
+
if (memberExpr.loc) {
|
|
122
105
|
return (0, rules_1.getPrimingDiagnostic)(rules_1.diagnosticMessages.NO_MEMBER_EXPRESSION_REFERENCE_TO_SUPER_CLASS, shared_1.LLSRange.fromBabelSourceLocation(memberExpr.loc), [memberExpr.property.name]);
|
|
123
106
|
}
|
|
124
107
|
}
|
|
@@ -131,13 +114,13 @@ exports.checkForNoUseOfSuper = checkForNoUseOfSuper;
|
|
|
131
114
|
* @param astContext the ast context that holds meta data about the scr code.
|
|
132
115
|
* @returns a Priming Diagnostic if there is a global reference undefined if none
|
|
133
116
|
*/
|
|
134
|
-
function checkForUnsupportedGlobalRef(path, astContext, declaredGetterVars) {
|
|
117
|
+
function checkForUnsupportedGlobalRef(path, astContext, imports, properties, declaredGetterVars) {
|
|
135
118
|
const memberExpr = path.node;
|
|
136
119
|
const memberObj = memberExpr.object;
|
|
137
120
|
if (memberObj.type === 'Identifier' &&
|
|
138
|
-
!(0, common_shared_1.isDeclaredInAst)(astContext, declaredGetterVars, memberObj.name) &&
|
|
121
|
+
!(0, common_shared_1.isDeclaredInAst)(astContext, imports, properties, declaredGetterVars, memberObj.name) &&
|
|
139
122
|
!common_shared_1.allowlistGlobals.globals.has(memberObj.name) &&
|
|
140
|
-
memberExpr.loc
|
|
123
|
+
memberExpr.loc) {
|
|
141
124
|
return (0, rules_1.getPrimingDiagnostic)(rules_1.diagnosticMessages.NO_MEMBER_EXPRESSION_REFERENCE_TO_UNSUPPORTED_GLOBAL, shared_1.LLSRange.fromBabelSourceLocation(memberExpr.loc), [memberObj.name]);
|
|
142
125
|
}
|
|
143
126
|
return undefined;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { NodePath } from '@babel/traverse';
|
|
2
2
|
import * as t from '@babel/types';
|
|
3
|
-
import {
|
|
3
|
+
import { ImportMetadata } from '@komaci/common-shared';
|
|
4
4
|
import { PrimingDiagnostic } from '../types';
|
|
5
5
|
/**
|
|
6
6
|
* Invariant function for checking if a tagged template expression contains a reference to an unsupported namespace.
|
|
@@ -8,5 +8,5 @@ import { PrimingDiagnostic } from '../types';
|
|
|
8
8
|
* @param decoratedMemberVars a set of approved member variable names.
|
|
9
9
|
* @returns undefined if the member expressoin does NOT reference an unsupported member var, a location obj if an unsuppported namespace is referenced.
|
|
10
10
|
*/
|
|
11
|
-
export declare function checkTaggedTemplateExprForNonSupportedNamespaceRefs(path: NodePath<t.TaggedTemplateExpression>, importReferences: Map<string,
|
|
11
|
+
export declare function checkTaggedTemplateExprForNonSupportedNamespaceRefs(path: NodePath<t.TaggedTemplateExpression>, importReferences: Map<string, ImportMetadata>): PrimingDiagnostic | undefined;
|
|
12
12
|
//# sourceMappingURL=taggedTemplateExpressionInvariantFunctions.d.ts.map
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.checkTaggedTemplateExprForNonSupportedNamespaceRefs = void 0;
|
|
4
|
+
const common_shared_1 = require("@komaci/common-shared");
|
|
4
5
|
const rules_1 = require("../rules");
|
|
5
6
|
const shared_1 = require("../shared");
|
|
6
7
|
/**
|
|
@@ -12,11 +13,10 @@ const shared_1 = require("../shared");
|
|
|
12
13
|
function checkTaggedTemplateExprForNonSupportedNamespaceRefs(path, importReferences) {
|
|
13
14
|
const taggedTemplateExpr = path.node;
|
|
14
15
|
const identifier = taggedTemplateExpr.tag;
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
16
|
+
const importRef = importReferences.get(identifier.name);
|
|
17
|
+
if (importRef && (0, common_shared_1.isImportInvalid)(importRef)) {
|
|
18
|
+
if (identifier.loc) {
|
|
19
|
+
return (0, rules_1.getPrimingDiagnostic)(rules_1.diagnosticMessages.NO_TAGGED_TEMPLATE_EXPRESSION_CONTAINS_UNSUPPORTED_NAMESPACE, shared_1.LLSRange.fromBabelSourceLocation(identifier.loc), [identifier.name]);
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
22
|
return undefined;
|
package/build/rules.js
CHANGED
|
@@ -88,12 +88,6 @@ exports.diagnosticMessages = {
|
|
|
88
88
|
message: "This wire configuration uses a property '{0}' which is undefined",
|
|
89
89
|
source: SOURCE_PREFIX_OFFLINE_CODE_ANALYZER,
|
|
90
90
|
},
|
|
91
|
-
NO_CONDITIONAL_USING_PROPERTY_FROM_UNRESOLVABLE_WIRE: {
|
|
92
|
-
code: `${MESSAGE_CODE_PREFIX}1005`,
|
|
93
|
-
severity: SEVERITY.ERROR,
|
|
94
|
-
message: "This conditional acts upon an unanalyzable property '{0}' that is wired by a unresolvable wire",
|
|
95
|
-
source: SOURCE_PREFIX_OFFLINE_CODE_ANALYZER,
|
|
96
|
-
},
|
|
97
91
|
NO_WIRE_CONFIGURATION_PROPERTY_USING_OUTPUT_OF_NON_PRIMEABLE_WIRE: {
|
|
98
92
|
code: `${MESSAGE_CODE_PREFIX}1006`,
|
|
99
93
|
severity: SEVERITY.ERROR,
|
|
@@ -142,28 +136,28 @@ exports.diagnosticMessages = {
|
|
|
142
136
|
message: "This wire configuration references a reactive value '{0}' that is not a local property",
|
|
143
137
|
source: SOURCE_PREFIX_OFFLINE_CODE_ANALYZER,
|
|
144
138
|
},
|
|
145
|
-
|
|
139
|
+
NO_COMPOSITION_ON_UNANALYZABLE_PROPERTY_FROM_UNRESOLVABLE_WIRE: {
|
|
146
140
|
code: `${MESSAGE_CODE_PREFIX}1014`,
|
|
147
141
|
severity: SEVERITY.ERROR,
|
|
148
|
-
message: "This
|
|
142
|
+
message: "This {0} an unanalyzable property '{1}' that is wired by a unresolvable wire",
|
|
149
143
|
source: SOURCE_PREFIX_OFFLINE_CODE_ANALYZER,
|
|
150
144
|
},
|
|
151
|
-
|
|
145
|
+
NO_COMPOSITION_ON_UNANALYZABLE_PROPERTY_NON_PUBLIC: {
|
|
152
146
|
code: `${MESSAGE_CODE_PREFIX}1015`,
|
|
153
147
|
severity: SEVERITY.ERROR,
|
|
154
|
-
message: "This
|
|
148
|
+
message: "This {0} an unanalyzable property '{1}' that is not a public property",
|
|
155
149
|
source: SOURCE_PREFIX_OFFLINE_CODE_ANALYZER,
|
|
156
150
|
},
|
|
157
|
-
|
|
151
|
+
NO_COMPOSITION_ON_UNANALYZABLE_GETTER_PROPERTY: {
|
|
158
152
|
code: `${MESSAGE_CODE_PREFIX}1016`,
|
|
159
153
|
severity: SEVERITY.ERROR,
|
|
160
|
-
message: "This
|
|
154
|
+
message: "This {0} an unanalyzable getter property '{1}'",
|
|
161
155
|
source: SOURCE_PREFIX_OFFLINE_CODE_ANALYZER,
|
|
162
156
|
},
|
|
163
|
-
|
|
157
|
+
NO_COMPOSITION_ON_UNANALYZABLE_PROPERTY_MISSING: {
|
|
164
158
|
code: `${MESSAGE_CODE_PREFIX}1017`,
|
|
165
159
|
severity: SEVERITY.ERROR,
|
|
166
|
-
message: "This
|
|
160
|
+
message: "This {0} a property '{1}' which does not exist in the corresponding script file",
|
|
167
161
|
source: SOURCE_PREFIX_OFFLINE_CODE_ANALYZER,
|
|
168
162
|
},
|
|
169
163
|
NO_WIRE_CONFIG_PROPERTY_CIRCULAR_WIRE_DEPENDENCY: {
|
|
@@ -174,24 +168,6 @@ exports.diagnosticMessages = {
|
|
|
174
168
|
"code to remove the circular dependency. Dependency chain: '{1}'",
|
|
175
169
|
source: SOURCE_PREFIX_OFFLINE_CODE_ANALYZER,
|
|
176
170
|
},
|
|
177
|
-
NO_ITERATE_ON_UNANALYZABLE_GETTER_PROPERTY: {
|
|
178
|
-
code: `${MESSAGE_CODE_PREFIX}1019`,
|
|
179
|
-
severity: SEVERITY.ERROR,
|
|
180
|
-
message: "This iterator iterates upon an unanalyzable getter property '{0}'",
|
|
181
|
-
source: SOURCE_PREFIX_OFFLINE_CODE_ANALYZER,
|
|
182
|
-
},
|
|
183
|
-
NO_CONDITIONAL_USING_UNANALYZABLE_NON_PUBLIC_PROPERTY: {
|
|
184
|
-
code: `${MESSAGE_CODE_PREFIX}1020`,
|
|
185
|
-
severity: SEVERITY.ERROR,
|
|
186
|
-
message: "This conditional acts upon an unanalyzable property '{0}' that is not a public property",
|
|
187
|
-
source: SOURCE_PREFIX_OFFLINE_CODE_ANALYZER,
|
|
188
|
-
},
|
|
189
|
-
NO_ITERATE_ON_UNANALYZABLE_PROPERTY: {
|
|
190
|
-
code: `${MESSAGE_CODE_PREFIX}1021`,
|
|
191
|
-
severity: SEVERITY.ERROR,
|
|
192
|
-
message: "This iterator iterates upon an unanalyzable property '{0}'",
|
|
193
|
-
source: SOURCE_PREFIX_OFFLINE_CODE_ANALYZER,
|
|
194
|
-
},
|
|
195
171
|
NO_ASSIGNMENT_EXPRESSION_ASSIGNS_VALUE_TO_MEMBER_VARIABLE: {
|
|
196
172
|
code: `${MESSAGE_CODE_PREFIX}1022`,
|
|
197
173
|
severity: SEVERITY.ERROR,
|
|
@@ -294,17 +270,5 @@ exports.diagnosticMessages = {
|
|
|
294
270
|
message: "Reference to import '{0}' from an unsupported namespace is not allowed",
|
|
295
271
|
source: SOURCE_PREFIX_OFFLINE_CODE_ANALYZER,
|
|
296
272
|
},
|
|
297
|
-
NO_IMAGE_REFERENCE_UNANALYZABLE_SOURCE_PROPERTY: {
|
|
298
|
-
code: `${MESSAGE_CODE_PREFIX}1039`,
|
|
299
|
-
severity: SEVERITY.ERROR,
|
|
300
|
-
message: "Image tag references in its source attribute the unanalyzable property '{0}'",
|
|
301
|
-
source: SOURCE_PREFIX_OFFLINE_CODE_ANALYZER,
|
|
302
|
-
},
|
|
303
|
-
NO_IMAGE_REFERENCE_MISSING_SOURCE_PROPERTY: {
|
|
304
|
-
code: `${MESSAGE_CODE_PREFIX}1040`,
|
|
305
|
-
severity: SEVERITY.ERROR,
|
|
306
|
-
message: "Image tag references in its source attribute a property '{0}' which does not exist in the corresponding script file",
|
|
307
|
-
source: SOURCE_PREFIX_OFFLINE_CODE_ANALYZER,
|
|
308
|
-
},
|
|
309
273
|
};
|
|
310
274
|
//# sourceMappingURL=rules.js.map
|