@komaci/static-analyzer 240.1.4 → 242.0.0
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/build/adaptersMapping.js +5 -1
- package/build/helpers.d.ts +10 -0
- package/build/helpers.js +87 -0
- package/build/index.d.ts +1 -1
- package/build/index.js +6 -3
- package/build/invariantFunctions/assignmentExpressionInvariantFunctions.js +2 -2
- package/build/invariantFunctions/callExpressionInvariantFunctions.js +4 -4
- package/build/invariantFunctions/functionExpressionInvariantFunctions.js +4 -4
- package/build/invariantFunctions/identifierInvariantFunctions.js +1 -1
- package/build/invariantFunctions/memberExpressionInvariantFunctions.js +11 -7
- package/build/invariantFunctions/taggedTemplateExpressionInvariantFunctions.js +1 -1
- package/build/rules.js +8 -44
- package/build/shared.d.ts +11 -10
- package/build/shared.js +82 -32
- package/build/staticAnalyzer.d.ts +8 -21
- package/build/staticAnalyzer.js +76 -124
- package/build/types.d.ts +17 -0
- package/package.json +5 -6
package/build/adaptersMapping.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];
|
|
@@ -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
3
|
export { AnalyzerInput, PrimingDiagnostic, Range, Position, PrimingAdapterDefinition, } from './types';
|
|
4
|
-
export { getPrimingAdapter, isSupportedNamespace, isSupportedWireAdapter,
|
|
4
|
+
export { getPrimingAdapter, isSupportedNamespace, isSupportedWireAdapter, } 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.
|
|
17
|
+
exports.getPrimingDiagnostic = exports.diagnosticMessages = exports.isSupportedWireAdapter = exports.isSupportedNamespace = exports.getPrimingAdapter = exports.generatePrimingDiagnosticsModule = void 0;
|
|
14
18
|
const staticAnalyzer_1 = require("./staticAnalyzer");
|
|
15
19
|
function generatePrimingDiagnosticsModule(input) {
|
|
16
20
|
const analyzer = new staticAnalyzer_1.StaticAnalyzer();
|
|
@@ -27,7 +31,6 @@ var shared_1 = require("./shared");
|
|
|
27
31
|
Object.defineProperty(exports, "getPrimingAdapter", { enumerable: true, get: function () { return shared_1.getPrimingAdapter; } });
|
|
28
32
|
Object.defineProperty(exports, "isSupportedNamespace", { enumerable: true, get: function () { return shared_1.isSupportedNamespace; } });
|
|
29
33
|
Object.defineProperty(exports, "isSupportedWireAdapter", { enumerable: true, get: function () { return shared_1.isSupportedWireAdapter; } });
|
|
30
|
-
Object.defineProperty(exports, "isImageComposition", { enumerable: true, get: function () { return shared_1.isImageComposition; } });
|
|
31
34
|
var rules_1 = require("./rules");
|
|
32
35
|
Object.defineProperty(exports, "diagnosticMessages", { enumerable: true, get: function () { return rules_1.diagnosticMessages; } });
|
|
33
36
|
Object.defineProperty(exports, "getPrimingDiagnostic", { enumerable: true, get: function () { return rules_1.getPrimingDiagnostic; } });
|
|
@@ -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
|
}
|
|
@@ -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
|
}
|
|
@@ -46,7 +46,7 @@ function checkIdentifierForNonSupportedNamespaceRefs(path, importReferences, dec
|
|
|
46
46
|
importReferences.get(identifier.name) &&
|
|
47
47
|
!importReferences.get(identifier.name)?.isSupported &&
|
|
48
48
|
!declaredVariables.includes(identifier.name)) {
|
|
49
|
-
if (identifier.loc
|
|
49
|
+
if (identifier.loc) {
|
|
50
50
|
return (0, rules_1.getPrimingDiagnostic)(rules_1.diagnosticMessages.NO_REFERENCE_TO_UNSUPPORTED_NAMESPACE_REFERENCE, shared_1.LLSRange.fromBabelSourceLocation(identifier.loc), [identifier.name]);
|
|
51
51
|
}
|
|
52
52
|
}
|
|
@@ -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];
|
|
@@ -39,7 +43,7 @@ function checkForNonSupportedMemberRefs(path, memberVars) {
|
|
|
39
43
|
!classPropInfo.isDecorated &&
|
|
40
44
|
!classPropInfo.hasInitialValue &&
|
|
41
45
|
!t.isClassMethod(classPropInfo.classProp))) {
|
|
42
|
-
if (memberExprProperty.loc
|
|
46
|
+
if (memberExprProperty.loc) {
|
|
43
47
|
return (0, rules_1.getPrimingDiagnostic)(rules_1.diagnosticMessages.NO_UNSUPPORTED_MEMBER_VARIABLE_IN_MEMBER_EXPRESSION, shared_1.LLSRange.fromBabelSourceLocation(memberExprProperty.loc), [memberExprProperty.name]);
|
|
44
48
|
}
|
|
45
49
|
}
|
|
@@ -65,7 +69,7 @@ function checkForNonExistentMemberRefs(path, memberVars, thisAliases) {
|
|
|
65
69
|
const memberExprValue = (0, common_shared_1.getFromIdentifierOrStringLiteral)(memberExprProperty);
|
|
66
70
|
if (!memberVars.find((classPropInfo) => classPropInfo.classPropId === memberExprValue)) {
|
|
67
71
|
const sourceLoc = memberExprProperty.loc;
|
|
68
|
-
if (sourceLoc
|
|
72
|
+
if (sourceLoc) {
|
|
69
73
|
return (0, rules_1.getPrimingDiagnostic)(rules_1.diagnosticMessages.NO_MEMBER_EXPRESSION_REFERENCE_TO_NON_EXISTENT_MEMBER_VARIABLE, shared_1.LLSRange.fromBabelSourceLocation(sourceLoc), [memberExprValue]);
|
|
70
74
|
}
|
|
71
75
|
}
|
|
@@ -85,7 +89,7 @@ function checkMemberExpressionForNonSupportedNamespaceRefs(path, importReference
|
|
|
85
89
|
const objectIdentifier = mememberExprNode.object;
|
|
86
90
|
if (importReferences.get(objectIdentifier.name)) {
|
|
87
91
|
if (!importReferences.get(objectIdentifier.name)?.isSupported) {
|
|
88
|
-
if (objectIdentifier.loc
|
|
92
|
+
if (objectIdentifier.loc) {
|
|
89
93
|
return (0, rules_1.getPrimingDiagnostic)(rules_1.diagnosticMessages.NO_MEMBER_EXPRESSION_REFERENCE_TO_UNSUPPORTED_NAMESPACE_REFERENCE, shared_1.LLSRange.fromBabelSourceLocation(objectIdentifier.loc), [objectIdentifier.name]);
|
|
90
94
|
}
|
|
91
95
|
}
|
|
@@ -103,7 +107,7 @@ function checkNoUsageOfDocumentOrWindow(path) {
|
|
|
103
107
|
const memberExpr = path.node;
|
|
104
108
|
if (memberExpr.object.type === 'Identifier' &&
|
|
105
109
|
(memberExpr.object.name === 'window' || memberExpr.object.name === 'document')) {
|
|
106
|
-
if (memberExpr.loc
|
|
110
|
+
if (memberExpr.loc) {
|
|
107
111
|
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
112
|
}
|
|
109
113
|
}
|
|
@@ -118,7 +122,7 @@ exports.checkNoUsageOfDocumentOrWindow = checkNoUsageOfDocumentOrWindow;
|
|
|
118
122
|
function checkForNoUseOfSuper(path) {
|
|
119
123
|
const memberExpr = path.node;
|
|
120
124
|
if (memberExpr.object.type === 'Super') {
|
|
121
|
-
if (memberExpr.loc
|
|
125
|
+
if (memberExpr.loc) {
|
|
122
126
|
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
127
|
}
|
|
124
128
|
}
|
|
@@ -137,7 +141,7 @@ function checkForUnsupportedGlobalRef(path, astContext, declaredGetterVars) {
|
|
|
137
141
|
if (memberObj.type === 'Identifier' &&
|
|
138
142
|
!(0, common_shared_1.isDeclaredInAst)(astContext, declaredGetterVars, memberObj.name) &&
|
|
139
143
|
!common_shared_1.allowlistGlobals.globals.has(memberObj.name) &&
|
|
140
|
-
memberExpr.loc
|
|
144
|
+
memberExpr.loc) {
|
|
141
145
|
return (0, rules_1.getPrimingDiagnostic)(rules_1.diagnosticMessages.NO_MEMBER_EXPRESSION_REFERENCE_TO_UNSUPPORTED_GLOBAL, shared_1.LLSRange.fromBabelSourceLocation(memberExpr.loc), [memberObj.name]);
|
|
142
146
|
}
|
|
143
147
|
return undefined;
|
|
@@ -14,7 +14,7 @@ function checkTaggedTemplateExprForNonSupportedNamespaceRefs(path, importReferen
|
|
|
14
14
|
const identifier = taggedTemplateExpr.tag;
|
|
15
15
|
if (importReferences.has(identifier.name)) {
|
|
16
16
|
if (!importReferences.get(identifier.name)?.isSupported) {
|
|
17
|
-
if (identifier.loc
|
|
17
|
+
if (identifier.loc) {
|
|
18
18
|
return (0, rules_1.getPrimingDiagnostic)(rules_1.diagnosticMessages.NO_TAGGED_TEMPLATE_EXPRESSION_CONTAINS_UNSUPPORTED_NAMESPACE, shared_1.LLSRange.fromBabelSourceLocation(identifier.loc), [identifier.name]);
|
|
19
19
|
}
|
|
20
20
|
}
|
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
|
package/build/shared.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
1
|
+
import * as t from '@babel/types';
|
|
2
|
+
import { ClassPropertyContexts, ModuleLevelConsumption, ModuleContext } from '@komaci/common-shared';
|
|
3
|
+
import { GetPrimingAdapter, GetterDiagnosticsContext, TemplateDiagnosticsContext } from './types';
|
|
3
4
|
import { SourceLocation } from '@babel/types';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
5
|
+
import { Range } from '.';
|
|
6
|
+
import { SourceLocation as KomaciSourceLocation } from '@komaci/types';
|
|
6
7
|
export declare const WIRE_FUNCTION = "WireFunction";
|
|
7
8
|
export declare const ERROR_PREFIX = "[komaci static-analyzer] ";
|
|
8
9
|
/**
|
|
@@ -38,15 +39,15 @@ export declare const LLSRange: {
|
|
|
38
39
|
fromBabelSourceLocation({ start, end }: SourceLocation): Range;
|
|
39
40
|
};
|
|
40
41
|
/**
|
|
41
|
-
* Function to analyze
|
|
42
|
+
* Function to analyze src code and returns any diagnostics found and valid getter contexts in a GetterDiagnosticContext
|
|
42
43
|
* @param srcCode the source code to analyze.
|
|
43
44
|
* @param namespace the namespace of src file.
|
|
44
45
|
*/
|
|
45
|
-
export declare function analyzeSrcForInvalidGetterFunctions(
|
|
46
|
+
export declare function analyzeSrcForInvalidGetterFunctions(rootAst: t.File, moduleContext: ModuleContext, moduleLevelConsumption: ModuleLevelConsumption, properties: ClassPropertyContexts): GetterDiagnosticsContext;
|
|
46
47
|
/**
|
|
47
|
-
*
|
|
48
|
-
* @param
|
|
49
|
-
* @
|
|
48
|
+
* Function to analyze tempplate strings and collect any Priming Diagnostic info for them along with returning valid templates contexts
|
|
49
|
+
* @param srcCode the source code to analyze.
|
|
50
|
+
* @param namespace the namespace of src file.
|
|
50
51
|
*/
|
|
51
|
-
export declare function
|
|
52
|
+
export declare function analyzeSrcForTemplateDiagnostics(rootAst: t.File, moduleContext: ModuleContext, moduleLevelConsumption: ModuleLevelConsumption, properties: ClassPropertyContexts): TemplateDiagnosticsContext;
|
|
52
53
|
//# sourceMappingURL=shared.d.ts.map
|
package/build/shared.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.analyzeSrcForTemplateDiagnostics = exports.analyzeSrcForInvalidGetterFunctions = exports.LLSRange = exports.getPrimingAdapter = exports.isSupportedNamespace = exports.isSupportedWireAdapter = exports.ERROR_PREFIX = exports.WIRE_FUNCTION = void 0;
|
|
4
4
|
const adaptersMapping_1 = require("./adaptersMapping");
|
|
5
5
|
const allowlistAdapters_1 = require("./allowlistAdapters");
|
|
6
6
|
const common_shared_1 = require("@komaci/common-shared");
|
|
7
|
+
const _1 = require(".");
|
|
7
8
|
const validateGetter_1 = require("./validateGetter");
|
|
8
9
|
// TODO: eventually refactor list consts into their own file
|
|
9
10
|
exports.WIRE_FUNCTION = 'WireFunction';
|
|
@@ -135,50 +136,99 @@ exports.LLSRange = {
|
|
|
135
136
|
},
|
|
136
137
|
};
|
|
137
138
|
/**
|
|
138
|
-
* Function to analyze
|
|
139
|
+
* Function to analyze src code and returns any diagnostics found and valid getter contexts in a GetterDiagnosticContext
|
|
139
140
|
* @param srcCode the source code to analyze.
|
|
140
141
|
* @param namespace the namespace of src file.
|
|
141
142
|
*/
|
|
142
|
-
function analyzeSrcForInvalidGetterFunctions(
|
|
143
|
-
const rootAst = (0, common_shared_1.generateAstFromSrcCode)(srcCode);
|
|
144
|
-
const moduleContext = {
|
|
145
|
-
astContext: (0, common_shared_1.getAstContextObject)(rootAst),
|
|
146
|
-
isExternal: (0, common_shared_1.isExternalModule)(namespace),
|
|
147
|
-
};
|
|
143
|
+
function analyzeSrcForInvalidGetterFunctions(rootAst, moduleContext, moduleLevelConsumption, properties) {
|
|
148
144
|
const diagnostics = [];
|
|
145
|
+
const validGetters = [];
|
|
149
146
|
const { getters } = (0, common_shared_1.getPropertyMetadataFromAst)(rootAst);
|
|
150
|
-
const identifiers = new Set();
|
|
151
|
-
const checkForPropertyReferences = {
|
|
152
|
-
// visitor for each type
|
|
153
|
-
MemberExpression(path) {
|
|
154
|
-
(0, common_shared_1.getMemberVarsFromGetter)(path, identifiers);
|
|
155
|
-
},
|
|
156
|
-
};
|
|
157
147
|
if (getters.length > 0) {
|
|
158
|
-
getters
|
|
159
|
-
.
|
|
160
|
-
identifiers.clear();
|
|
161
|
-
getter.traverse(checkForPropertyReferences);
|
|
162
|
-
const name = (0, common_shared_1.getClassMethodName)(getter);
|
|
163
|
-
(0, common_shared_1.updatePropertyUsage)(name, Array.from(identifiers), properties, common_shared_1.PropertyTypes.GETTER);
|
|
164
|
-
return getter;
|
|
165
|
-
})
|
|
166
|
-
.forEach((func) => {
|
|
167
|
-
const res = (0, validateGetter_1.validateGetter)(func, moduleContext, true);
|
|
148
|
+
getters.forEach((getterFunc, index) => {
|
|
149
|
+
const res = (0, validateGetter_1.validateGetter)(getterFunc, moduleContext, true);
|
|
168
150
|
const getterDiagnostics = res;
|
|
151
|
+
//Same thing as passing false into validate getter and getting a boolean back. If there are no diagnostics its valid.
|
|
152
|
+
if (getterDiagnostics.length == 0) {
|
|
153
|
+
const validGetter = generateValidGetterContext(getterFunc, moduleContext, moduleLevelConsumption, properties, index);
|
|
154
|
+
validGetters.push(validGetter);
|
|
155
|
+
const name = (0, common_shared_1.getClassMethodName)(getterFunc);
|
|
156
|
+
(0, common_shared_1.updatePropertyUsage)(name, validGetter.memberUsage, properties, common_shared_1.PropertyTypes.GETTER);
|
|
157
|
+
}
|
|
169
158
|
diagnostics.push(...getterDiagnostics);
|
|
170
159
|
});
|
|
171
160
|
}
|
|
172
|
-
return
|
|
161
|
+
return {
|
|
162
|
+
getterFunctionDiagnostics: diagnostics,
|
|
163
|
+
validGetters: validGetters,
|
|
164
|
+
};
|
|
173
165
|
}
|
|
174
166
|
exports.analyzeSrcForInvalidGetterFunctions = analyzeSrcForInvalidGetterFunctions;
|
|
175
167
|
/**
|
|
176
|
-
*
|
|
177
|
-
* @param
|
|
178
|
-
* @
|
|
168
|
+
* Function to analyze tempplate strings and collect any Priming Diagnostic info for them along with returning valid templates contexts
|
|
169
|
+
* @param srcCode the source code to analyze.
|
|
170
|
+
* @param namespace the namespace of src file.
|
|
179
171
|
*/
|
|
180
|
-
function
|
|
181
|
-
|
|
172
|
+
function analyzeSrcForTemplateDiagnostics(rootAst, moduleContext, moduleLevelConsumption, properties) {
|
|
173
|
+
const diagnostics = [];
|
|
174
|
+
const validTemplates = [];
|
|
175
|
+
const { templateStrings } = (0, common_shared_1.getPropertyMetadataFromAst)(rootAst);
|
|
176
|
+
if (templateStrings.length > 0) {
|
|
177
|
+
templateStrings.forEach((templateString, index) => {
|
|
178
|
+
const res = (0, _1.validateTemplateString)(templateString, moduleContext, true);
|
|
179
|
+
const templateDiagnostics = res;
|
|
180
|
+
//Same thing as passing false into validate getter and getting a boolean back. If there are no diagnostics its valid.
|
|
181
|
+
if (templateDiagnostics.length == 0) {
|
|
182
|
+
const validTemplate = generateValidTemplateContext(templateString, moduleContext, moduleLevelConsumption, properties, index);
|
|
183
|
+
validTemplates.push(validTemplate);
|
|
184
|
+
(0, common_shared_1.updatePropertyUsage)((0, common_shared_1.getFromIdentifierOrStringLiteral)(templateString.node.key), validTemplate.memberUsage, properties, common_shared_1.PropertyTypes.TEMPLATE_STRING);
|
|
185
|
+
}
|
|
186
|
+
diagnostics.push(...templateDiagnostics);
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
return {
|
|
190
|
+
templateDiagnostics: diagnostics,
|
|
191
|
+
validTemplates: validTemplates,
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
exports.analyzeSrcForTemplateDiagnostics = analyzeSrcForTemplateDiagnostics;
|
|
195
|
+
/**
|
|
196
|
+
* Helper function to generate a validGetterContext
|
|
197
|
+
* @param getterFunc the valid getter function
|
|
198
|
+
* @param moduleContext the module context
|
|
199
|
+
* @param moduleLevelConsumption a moduleLevelConsumption object
|
|
200
|
+
* @param properties properties array
|
|
201
|
+
* @param index index of the getter function
|
|
202
|
+
* @returns a valid getter context
|
|
203
|
+
*/
|
|
204
|
+
function generateValidGetterContext(getterFunc, moduleContext, moduleLevelConsumption, properties, index) {
|
|
205
|
+
const { identifiers } = (0, common_shared_1.implicitConsumptionMetadata)(getterFunc, moduleContext.astContext.classProperties, // info on all class properties
|
|
206
|
+
moduleContext.astContext.importDeclarations, // import metadata info
|
|
207
|
+
moduleLevelConsumption);
|
|
208
|
+
const validGetter = {
|
|
209
|
+
getter: getterFunc,
|
|
210
|
+
generatedName: `g${index}`,
|
|
211
|
+
memberUsage: identifiers,
|
|
212
|
+
};
|
|
213
|
+
return validGetter;
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Helper function to generate a validTemplateContext
|
|
217
|
+
* @param template the valid template string
|
|
218
|
+
* @param moduleContext the module context
|
|
219
|
+
* @param moduleLevelConsumption a moduleLevelConsumption object
|
|
220
|
+
* @param properties properties array
|
|
221
|
+
* @param index index of the template string
|
|
222
|
+
* @returns a valid template context
|
|
223
|
+
*/
|
|
224
|
+
function generateValidTemplateContext(template, moduleContext, moduleLevelConsumption, properties, index) {
|
|
225
|
+
const { identifiers } = (0, common_shared_1.implicitConsumptionMetadata)(template, moduleContext.astContext.classProperties, // info on all class properties
|
|
226
|
+
moduleContext.astContext.importDeclarations, // import metadata info
|
|
227
|
+
moduleLevelConsumption);
|
|
228
|
+
return {
|
|
229
|
+
template,
|
|
230
|
+
generatedName: `t${index}`,
|
|
231
|
+
memberUsage: identifiers,
|
|
232
|
+
};
|
|
182
233
|
}
|
|
183
|
-
exports.isImageComposition = isImageComposition;
|
|
184
234
|
//# sourceMappingURL=shared.js.map
|
|
@@ -55,29 +55,16 @@ export declare class StaticAnalyzer {
|
|
|
55
55
|
private findNestedUnsupportedNSObject;
|
|
56
56
|
private findWireConfigReferenceNonExistProperty;
|
|
57
57
|
/**
|
|
58
|
-
* Produce diagnostics for
|
|
59
|
-
* or wired properties which associated to unresolvable wires
|
|
60
|
-
*/
|
|
61
|
-
private findUnresolvableIterator;
|
|
62
|
-
/**
|
|
63
|
-
* Produce diagnostics for conditionals which act upon unresolvable inputs, such as private properties
|
|
64
|
-
* or wired properties which associated to unresolvable wires
|
|
65
|
-
*/
|
|
66
|
-
private findUnresolvableConditional;
|
|
67
|
-
/**
|
|
68
|
-
* Produces diagnostic for images which refer to unresolvable `src` attributes within the `<img>` tag.
|
|
69
|
-
* Note that Images are a type of Composition
|
|
58
|
+
* Produce diagnostics for compositions which use unresolvable inputs, such as private properties
|
|
59
|
+
* or wired properties which associated to unresolvable wires.
|
|
70
60
|
*
|
|
71
|
-
* @param
|
|
72
|
-
* @param
|
|
73
|
-
* @
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* Convert array of Compositions into flattened array of Compositions,
|
|
78
|
-
* visiting top-level and nested children compositions
|
|
61
|
+
* @param properties the properties array
|
|
62
|
+
* @param adgs the adgs associated with the template
|
|
63
|
+
* @param diagnosics the diagnosics array
|
|
64
|
+
* @param defaultHasParent if the default expored ADG inherent a parent class
|
|
65
|
+
* @returns void
|
|
79
66
|
*/
|
|
80
|
-
private
|
|
67
|
+
private findUnresolvableCompositionProperty;
|
|
81
68
|
/**
|
|
82
69
|
* find Import name information (resourceName, importName) given komaciDoc imports and reference
|
|
83
70
|
*/
|
package/build/staticAnalyzer.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];
|
|
@@ -20,11 +24,12 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
20
24
|
};
|
|
21
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
26
|
exports.StaticAnalyzer = void 0;
|
|
23
|
-
const collector = __importStar(require("@lwc
|
|
27
|
+
const collector = __importStar(require("@lwc/metadata"));
|
|
24
28
|
const rules_1 = require("./rules");
|
|
25
29
|
const common_shared_1 = require("@komaci/common-shared");
|
|
26
30
|
const shared_1 = require("./shared");
|
|
27
31
|
const WireGraph_1 = require("./WireGraph");
|
|
32
|
+
const helpers_1 = require("./helpers");
|
|
28
33
|
class StaticAnalyzer {
|
|
29
34
|
constructor() {
|
|
30
35
|
// TODO: Remove this sample Range when it is no longer needed as a placeholder
|
|
@@ -84,11 +89,28 @@ class StaticAnalyzer {
|
|
|
84
89
|
(0, common_shared_1.updatePropertyMetadataFromTemplateDoc)(templateKomaciDoc, properties);
|
|
85
90
|
}
|
|
86
91
|
const srcCode = input.files[sourceFileName];
|
|
87
|
-
const
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
92
|
+
const rootAst = (0, common_shared_1.generateAstFromSrcCode)(srcCode);
|
|
93
|
+
const moduleContext = {
|
|
94
|
+
astContext: (0, common_shared_1.getAstContextObject)(rootAst),
|
|
95
|
+
isExternal: (0, common_shared_1.isExternalModule)(input.namespace),
|
|
96
|
+
};
|
|
97
|
+
const moduleLevelConsumption = {
|
|
98
|
+
consumedImports: new Map(),
|
|
99
|
+
};
|
|
100
|
+
const { getterFunctionDiagnostics, validGetters } = (0, shared_1.analyzeSrcForInvalidGetterFunctions)(rootAst, moduleContext, moduleLevelConsumption, properties);
|
|
101
|
+
const { templateDiagnostics, validTemplates } = (0, shared_1.analyzeSrcForTemplateDiagnostics)(rootAst, moduleContext, moduleLevelConsumption, properties);
|
|
102
|
+
const getterAndTemplateDiagnostics = [
|
|
103
|
+
...getterFunctionDiagnostics,
|
|
104
|
+
...templateDiagnostics,
|
|
105
|
+
];
|
|
106
|
+
if (getterAndTemplateDiagnostics.length > 0) {
|
|
107
|
+
getterAndTemplateDiagnostics.forEach((diagnostic) => {
|
|
108
|
+
(0, rules_1.updatePrimingDiagnosticWithFileInfo)(diagnostic, sourceFileName);
|
|
109
|
+
diagnostics.push(diagnostic);
|
|
110
|
+
});
|
|
91
111
|
}
|
|
112
|
+
(0, common_shared_1.updateKomaciDocumentWithValidGetters)(scriptKomaciDoc, validGetters);
|
|
113
|
+
(0, common_shared_1.updateKomaciDocumentWithValidTemplatedStrings)(scriptKomaciDoc, validTemplates);
|
|
92
114
|
}
|
|
93
115
|
this.processKomaciScriptDoc(scriptKomaciDoc, diagnostics);
|
|
94
116
|
this.processKomaciTemplateDoc(templateKomaciDoc, scriptKomaciDoc, diagnostics);
|
|
@@ -120,10 +142,25 @@ class StaticAnalyzer {
|
|
|
120
142
|
if (komaciDoc) {
|
|
121
143
|
const properties = (0, common_shared_1.collectPropertyMetadataFromScriptDoc)(komaciDoc);
|
|
122
144
|
const srcCode = input.sourceFile;
|
|
123
|
-
const
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
145
|
+
const rootAst = (0, common_shared_1.generateAstFromSrcCode)(srcCode);
|
|
146
|
+
const moduleContext = {
|
|
147
|
+
astContext: (0, common_shared_1.getAstContextObject)(rootAst),
|
|
148
|
+
isExternal: (0, common_shared_1.isExternalModule)(input.namespace),
|
|
149
|
+
};
|
|
150
|
+
const moduleLevelConsumption = {
|
|
151
|
+
consumedImports: new Map(),
|
|
152
|
+
};
|
|
153
|
+
const { getterFunctionDiagnostics } = (0, shared_1.analyzeSrcForInvalidGetterFunctions)(rootAst, moduleContext, moduleLevelConsumption, properties);
|
|
154
|
+
const { templateDiagnostics } = (0, shared_1.analyzeSrcForTemplateDiagnostics)(rootAst, moduleContext, moduleLevelConsumption, properties);
|
|
155
|
+
const getterAndTemplateDiagnostics = [
|
|
156
|
+
...getterFunctionDiagnostics,
|
|
157
|
+
...templateDiagnostics,
|
|
158
|
+
];
|
|
159
|
+
if (getterAndTemplateDiagnostics.length > 0) {
|
|
160
|
+
getterAndTemplateDiagnostics.forEach((diagnostic) => {
|
|
161
|
+
(0, rules_1.updatePrimingDiagnosticWithFileInfo)(diagnostic, this.fileNamesMap.get('js'));
|
|
162
|
+
diagnostics.push(diagnostic);
|
|
163
|
+
});
|
|
127
164
|
}
|
|
128
165
|
}
|
|
129
166
|
return this.processKomaciScriptDoc(komaciDoc, diagnostics);
|
|
@@ -220,34 +257,20 @@ class StaticAnalyzer {
|
|
|
220
257
|
scriptKomaciDoc?.exports) {
|
|
221
258
|
const adgs = [];
|
|
222
259
|
const defaultExport = scriptKomaciDoc.exports['default'];
|
|
260
|
+
let defaultHasParent = false;
|
|
223
261
|
if (defaultExport && defaultExport.type === 'AdgReference') {
|
|
224
262
|
const defaultAdg = scriptKomaciDoc.adgs[defaultExport.value];
|
|
225
263
|
adgs.push(defaultAdg);
|
|
226
264
|
let parentClass = defaultAdg.parentClass;
|
|
227
265
|
while (parentClass?.type === 'AdgReference') {
|
|
266
|
+
defaultHasParent = true;
|
|
228
267
|
const parentAdg = scriptKomaciDoc.adgs[parentClass.value];
|
|
229
268
|
adgs.push(parentAdg);
|
|
230
269
|
parentClass = parentAdg.parentClass;
|
|
231
270
|
}
|
|
232
271
|
}
|
|
233
|
-
const
|
|
234
|
-
|
|
235
|
-
// tested by: artifact-combined-files/unresolvableIterator
|
|
236
|
-
let diagnostic = this.findUnresolvableIterator(composition, adgs);
|
|
237
|
-
if (diagnostic) {
|
|
238
|
-
diagnostics.push(diagnostic);
|
|
239
|
-
}
|
|
240
|
-
// tested by: artifact-combined-files/unresolvableConditional
|
|
241
|
-
diagnostic = this.findUnresolvableConditional(composition, adgs);
|
|
242
|
-
if (diagnostic) {
|
|
243
|
-
diagnostics.push(diagnostic);
|
|
244
|
-
}
|
|
245
|
-
// test by: artifact-combined-files/unresolvedImageBinding
|
|
246
|
-
diagnostic = this.findUnresolvableImage(composition, adgs);
|
|
247
|
-
if (diagnostic) {
|
|
248
|
-
diagnostics.push(diagnostic);
|
|
249
|
-
}
|
|
250
|
-
}
|
|
272
|
+
const properties = (0, helpers_1.findPropertiesUsedInCompositions)(templateKomaciDoc.compositions);
|
|
273
|
+
this.findUnresolvableCompositionProperty(properties, adgs, diagnostics, defaultHasParent);
|
|
251
274
|
}
|
|
252
275
|
return diagnostics;
|
|
253
276
|
}
|
|
@@ -541,121 +564,50 @@ class StaticAnalyzer {
|
|
|
541
564
|
return diagnostics;
|
|
542
565
|
}
|
|
543
566
|
/**
|
|
544
|
-
* Produce diagnostics for
|
|
545
|
-
* or wired properties which associated to unresolvable wires
|
|
567
|
+
* Produce diagnostics for compositions which use unresolvable inputs, such as private properties
|
|
568
|
+
* or wired properties which associated to unresolvable wires.
|
|
569
|
+
*
|
|
570
|
+
* @param properties the properties array
|
|
571
|
+
* @param adgs the adgs associated with the template
|
|
572
|
+
* @param diagnosics the diagnosics array
|
|
573
|
+
* @param defaultHasParent if the default expored ADG inherent a parent class
|
|
574
|
+
* @returns void
|
|
546
575
|
*/
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
const
|
|
550
|
-
const propName = iteration.input.value.split('/')[0];
|
|
576
|
+
findUnresolvableCompositionProperty(properties, adgs, diagnosics, defaultHasParent) {
|
|
577
|
+
for (const compositionProperty of properties) {
|
|
578
|
+
const { propertyName, diagnosticMessageAct, location } = compositionProperty;
|
|
551
579
|
for (const wire of this.orderedWireInfos) {
|
|
552
|
-
if (wire.propName ===
|
|
580
|
+
if (wire.propName === propertyName &&
|
|
553
581
|
wire.isNonAnalyzable &&
|
|
554
582
|
adgs.includes(wire.adg)) {
|
|
555
|
-
|
|
583
|
+
// property on unresolvable wire
|
|
584
|
+
diagnosics.push((0, rules_1.updatePrimingDiagnosticWithFileInfo)((0, rules_1.getPrimingDiagnostic)(rules_1.diagnosticMessages.NO_COMPOSITION_ON_UNANALYZABLE_PROPERTY_FROM_UNRESOLVABLE_WIRE, shared_1.LLSRange.fromLWCSourceLocation(location), [diagnosticMessageAct, propertyName]), this.fileNamesMap.get('html')));
|
|
556
585
|
}
|
|
557
586
|
}
|
|
587
|
+
let propertyFound = false;
|
|
558
588
|
for (const adg of adgs) {
|
|
559
|
-
if (adg.properties && adg.properties[
|
|
560
|
-
|
|
589
|
+
if (adg.properties && adg.properties[propertyName]) {
|
|
590
|
+
propertyFound = true;
|
|
591
|
+
const prop = adg.properties[propertyName];
|
|
561
592
|
if (prop.input) {
|
|
593
|
+
// getter
|
|
562
594
|
if (prop.input.type === 'Unresolved') {
|
|
563
|
-
|
|
595
|
+
diagnosics.push((0, rules_1.updatePrimingDiagnosticWithFileInfo)((0, rules_1.getPrimingDiagnostic)(rules_1.diagnosticMessages.NO_COMPOSITION_ON_UNANALYZABLE_GETTER_PROPERTY, shared_1.LLSRange.fromLWCSourceLocation(location), [diagnosticMessageAct, propertyName]), this.fileNamesMap.get('html')));
|
|
564
596
|
}
|
|
565
597
|
}
|
|
566
598
|
else {
|
|
567
599
|
if (!prop.isPublic) {
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
}
|
|
571
|
-
}
|
|
572
|
-
}
|
|
573
|
-
}
|
|
574
|
-
return;
|
|
575
|
-
}
|
|
576
|
-
/**
|
|
577
|
-
* Produce diagnostics for conditionals which act upon unresolvable inputs, such as private properties
|
|
578
|
-
* or wired properties which associated to unresolvable wires
|
|
579
|
-
*/
|
|
580
|
-
findUnresolvableConditional(composition, adgs) {
|
|
581
|
-
if (composition.type === 'Container') {
|
|
582
|
-
if (composition.isActive) {
|
|
583
|
-
const propName = composition.isActive.input.value.split('/')[0];
|
|
584
|
-
for (const wire of this.orderedWireInfos) {
|
|
585
|
-
if (wire.propName === propName &&
|
|
586
|
-
wire.isNonAnalyzable &&
|
|
587
|
-
adgs.includes(wire.adg)) {
|
|
588
|
-
const fileNameHTML = this.fileNamesMap.get('html');
|
|
589
|
-
return (0, rules_1.updatePrimingDiagnosticWithFileInfo)((0, rules_1.getPrimingDiagnostic)(rules_1.diagnosticMessages.NO_CONDITIONAL_USING_PROPERTY_FROM_UNRESOLVABLE_WIRE, shared_1.LLSRange.fromLWCSourceLocation(composition.location), [propName]), fileNameHTML);
|
|
590
|
-
}
|
|
591
|
-
}
|
|
592
|
-
for (const adg of adgs) {
|
|
593
|
-
if (adg.properties && adg.properties[propName]) {
|
|
594
|
-
const prop = adg.properties[propName];
|
|
595
|
-
if (prop.input) {
|
|
596
|
-
if (prop.input.type === 'Unresolved') {
|
|
597
|
-
return (0, rules_1.updatePrimingDiagnosticWithFileInfo)((0, rules_1.getPrimingDiagnostic)(rules_1.diagnosticMessages.NO_CONDITIONAL_ON_UNANALYZABLE_GETTER_PROPERTY, shared_1.LLSRange.fromLWCSourceLocation(composition.location), [propName]), this.fileNamesMap.get('html'));
|
|
598
|
-
}
|
|
599
|
-
}
|
|
600
|
-
else {
|
|
601
|
-
if (!prop.isPublic) {
|
|
602
|
-
return (0, rules_1.updatePrimingDiagnosticWithFileInfo)((0, rules_1.getPrimingDiagnostic)(rules_1.diagnosticMessages.NO_CONDITIONAL_USING_UNANALYZABLE_NON_PUBLIC_PROPERTY, shared_1.LLSRange.fromLWCSourceLocation(composition.location), [propName]), this.fileNamesMap.get('html'));
|
|
603
|
-
}
|
|
600
|
+
// private property
|
|
601
|
+
diagnosics.push((0, rules_1.updatePrimingDiagnosticWithFileInfo)((0, rules_1.getPrimingDiagnostic)(rules_1.diagnosticMessages.NO_COMPOSITION_ON_UNANALYZABLE_PROPERTY_NON_PUBLIC, shared_1.LLSRange.fromLWCSourceLocation(location), [diagnosticMessageAct, propertyName]), this.fileNamesMap.get('html')));
|
|
604
602
|
}
|
|
605
603
|
}
|
|
606
604
|
}
|
|
607
605
|
}
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
/**
|
|
612
|
-
* Produces diagnostic for images which refer to unresolvable `src` attributes within the `<img>` tag.
|
|
613
|
-
* Note that Images are a type of Composition
|
|
614
|
-
*
|
|
615
|
-
* @param {Composition} image the composition containing the Image
|
|
616
|
-
* @param {Adg[]} adgs an array of ADGs
|
|
617
|
-
* @returns {PrimingDiagnostic} a PrimingDiagnostic if an image with unresolvable `src` attribute is found. void otherwise
|
|
618
|
-
*/
|
|
619
|
-
findUnresolvableImage(image, adgs) {
|
|
620
|
-
if ((0, shared_1.isImageComposition)(image)) {
|
|
621
|
-
if (image.src.type === 'Binding') {
|
|
622
|
-
const propName = image.src.value;
|
|
623
|
-
for (const adg of adgs) {
|
|
624
|
-
if (adg.properties?.[propName]) {
|
|
625
|
-
const prop = adg.properties[propName];
|
|
626
|
-
if (prop.initial?.type === 'Unresolved') {
|
|
627
|
-
return (0, rules_1.updatePrimingDiagnosticWithFileInfo)((0, rules_1.getPrimingDiagnostic)(rules_1.diagnosticMessages.NO_IMAGE_REFERENCE_UNANALYZABLE_SOURCE_PROPERTY,
|
|
628
|
-
// TODO: currently is an emptyRange location. May need to add support
|
|
629
|
-
// for location of image tags. Created work item W-11309043 for this
|
|
630
|
-
shared_1.LLSRange.fromLWCSourceLocation(image.location), [propName]), this.fileNamesMap.get('html'));
|
|
631
|
-
}
|
|
632
|
-
}
|
|
633
|
-
else {
|
|
634
|
-
// property in image src attribute is not found in the script file, so return a dianostic
|
|
635
|
-
// for this situation too.
|
|
636
|
-
return (0, rules_1.updatePrimingDiagnosticWithFileInfo)((0, rules_1.getPrimingDiagnostic)(rules_1.diagnosticMessages.NO_IMAGE_REFERENCE_MISSING_SOURCE_PROPERTY,
|
|
637
|
-
// TODO: currently is an emptyRange location. May need to add support
|
|
638
|
-
// for location of image tags. Created work item W-11309043 for this
|
|
639
|
-
shared_1.LLSRange.fromLWCSourceLocation(image.location), [propName]), this.fileNamesMap.get('html'));
|
|
640
|
-
}
|
|
641
|
-
}
|
|
606
|
+
if (!propertyFound && !defaultHasParent) {
|
|
607
|
+
// property not exist
|
|
608
|
+
diagnosics.push((0, rules_1.updatePrimingDiagnosticWithFileInfo)((0, rules_1.getPrimingDiagnostic)(rules_1.diagnosticMessages.NO_COMPOSITION_ON_UNANALYZABLE_PROPERTY_MISSING, shared_1.LLSRange.fromLWCSourceLocation(location), [diagnosticMessageAct, propertyName]), this.fileNamesMap.get('html')));
|
|
642
609
|
}
|
|
643
610
|
}
|
|
644
|
-
return;
|
|
645
|
-
}
|
|
646
|
-
/**
|
|
647
|
-
* Convert array of Compositions into flattened array of Compositions,
|
|
648
|
-
* visiting top-level and nested children compositions
|
|
649
|
-
*/
|
|
650
|
-
compositionsToArray(compositions) {
|
|
651
|
-
const compositionArray = [];
|
|
652
|
-
compositions.forEach((node) => {
|
|
653
|
-
compositionArray.push(node);
|
|
654
|
-
if (node.compositions) {
|
|
655
|
-
compositionArray.push(...this.compositionsToArray(node.compositions));
|
|
656
|
-
}
|
|
657
|
-
});
|
|
658
|
-
return compositionArray;
|
|
659
611
|
}
|
|
660
612
|
/**
|
|
661
613
|
* find Import name information (resourceName, importName) given komaciDoc imports and reference
|
package/build/types.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Adg, FunctionType, SourceLocation } from '@komaci/types';
|
|
2
|
+
import { ValidGetterContext, ValidTemplateContext } from '@komaci/common-shared';
|
|
2
3
|
/** Representation of a source code file being analyzed, in format neeed by the VSCode language server */
|
|
3
4
|
export declare type Uri = {
|
|
4
5
|
path: string;
|
|
@@ -99,4 +100,20 @@ export declare type FunctionalContext = {
|
|
|
99
100
|
declaredVariables: string[];
|
|
100
101
|
thisAliases: Set<string>;
|
|
101
102
|
};
|
|
103
|
+
export declare type GetterDiagnosticsContext = {
|
|
104
|
+
getterFunctionDiagnostics: PrimingDiagnostic[];
|
|
105
|
+
validGetters: ValidGetterContext[];
|
|
106
|
+
};
|
|
107
|
+
export declare type TemplateDiagnosticsContext = {
|
|
108
|
+
templateDiagnostics: PrimingDiagnostic[];
|
|
109
|
+
validTemplates: ValidTemplateContext[];
|
|
110
|
+
};
|
|
111
|
+
/**
|
|
112
|
+
* Internal type for a composition property
|
|
113
|
+
*/
|
|
114
|
+
export declare type CompositionProperty = {
|
|
115
|
+
propertyName: string;
|
|
116
|
+
location?: SourceLocation;
|
|
117
|
+
diagnosticMessageAct: 'iterator iterates upon' | "image's src attribute is bound to" | 'child component references';
|
|
118
|
+
};
|
|
102
119
|
//# sourceMappingURL=types.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@komaci/static-analyzer",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "242.0.0",
|
|
4
4
|
"description": "Komaci Diagnostics API",
|
|
5
5
|
"homepage": "https://komaci.dev/",
|
|
6
6
|
"repository": {
|
|
@@ -26,14 +26,13 @@
|
|
|
26
26
|
"build/**/*.d.ts",
|
|
27
27
|
"build/komaci-mapping.json"
|
|
28
28
|
],
|
|
29
|
-
"peerDependencies": {
|
|
30
|
-
"@lwc-platform/lwc-metadata-next": "^2.18.0-240.2"
|
|
31
|
-
},
|
|
32
29
|
"dependencies": {
|
|
33
|
-
"@komaci/common-shared": "
|
|
30
|
+
"@komaci/common-shared": "242.0.0",
|
|
31
|
+
"@lwc/metadata": "2.22.0-0",
|
|
32
|
+
"@lwc/sfdc-compiler-utils": "2.22.0-0"
|
|
34
33
|
},
|
|
35
34
|
"devDependencies": {
|
|
36
35
|
"@babel/types": "^7.9.0",
|
|
37
|
-
"@komaci/types": "
|
|
36
|
+
"@komaci/types": "242.0.0"
|
|
38
37
|
}
|
|
39
38
|
}
|