@komaci/static-analyzer 260.30.0 → 262.3.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/shared.d.ts +2 -2
- package/build/shared.js +3 -7
- package/build/staticAnalyzer.d.ts +2 -0
- package/build/staticAnalyzer.js +34 -2
- package/package.json +1 -1
package/build/shared.d.ts
CHANGED
|
@@ -35,10 +35,10 @@ export declare const LLSRange: {
|
|
|
35
35
|
* @param rootAst the Abstract Syntax Tree for the component
|
|
36
36
|
* @param moduleMetadata metadata about the given component
|
|
37
37
|
* @param moduleContext contextual details about the component, like module level variables, etc
|
|
38
|
-
* @param
|
|
38
|
+
* @param templateReferences an optional list of template reference names. If specified, only getter functions that are in this list will be validated.
|
|
39
39
|
* @returns diagnostics for the getters
|
|
40
40
|
*/
|
|
41
|
-
export declare function analyzeSrcForInvalidGetterFunctions(adgIndex: number, rootAst: t.File, moduleMetadata: ModuleMetadata, moduleContext: ModuleContext): GetterDiagnosticsContext;
|
|
41
|
+
export declare function analyzeSrcForInvalidGetterFunctions(adgIndex: number, rootAst: t.File, moduleMetadata: ModuleMetadata, moduleContext: ModuleContext, templateReferences?: string[]): GetterDiagnosticsContext;
|
|
42
42
|
/**
|
|
43
43
|
* Function to analyze tempplate strings and collect any Priming Diagnostic info for them along with returning valid templates contexts
|
|
44
44
|
* @param adgIndex index of the current adg to process
|
package/build/shared.js
CHANGED
|
@@ -89,10 +89,10 @@ exports.LLSRange = {
|
|
|
89
89
|
* @param rootAst the Abstract Syntax Tree for the component
|
|
90
90
|
* @param moduleMetadata metadata about the given component
|
|
91
91
|
* @param moduleContext contextual details about the component, like module level variables, etc
|
|
92
|
-
* @param
|
|
92
|
+
* @param templateReferences an optional list of template reference names. If specified, only getter functions that are in this list will be validated.
|
|
93
93
|
* @returns diagnostics for the getters
|
|
94
94
|
*/
|
|
95
|
-
function analyzeSrcForInvalidGetterFunctions(adgIndex, rootAst, moduleMetadata, moduleContext) {
|
|
95
|
+
function analyzeSrcForInvalidGetterFunctions(adgIndex, rootAst, moduleMetadata, moduleContext, templateReferences) {
|
|
96
96
|
const diagnostics = [];
|
|
97
97
|
const validGetters = [];
|
|
98
98
|
const { getters } = (0, common_shared_1.getPropertyMetadataFromAst)(rootAst);
|
|
@@ -100,20 +100,16 @@ function analyzeSrcForInvalidGetterFunctions(adgIndex, rootAst, moduleMetadata,
|
|
|
100
100
|
const adg = moduleMetadata.adgs.get(adgIndex);
|
|
101
101
|
if (getters.length > 0 && adg) {
|
|
102
102
|
const usedByPrimingFunctions = new Set();
|
|
103
|
-
const usedByTemplates = new Set();
|
|
104
103
|
adg.functions.forEach((func) => {
|
|
105
104
|
if (func.type === common_shared_1.FunctionTypes.PRIMING_FUNCTION) {
|
|
106
105
|
func.requiredProperties.forEach((prop) => usedByPrimingFunctions.add(prop));
|
|
107
106
|
}
|
|
108
|
-
if (func.type === common_shared_1.FunctionTypes.TEMPLATE_STRING) {
|
|
109
|
-
func.requiredProperties.forEach((prop) => usedByTemplates.add(prop));
|
|
110
|
-
}
|
|
111
107
|
});
|
|
112
108
|
getters.forEach((getterFunc, index) => {
|
|
113
109
|
const getterName = (0, common_shared_1.getClassMethodName)(getterFunc);
|
|
114
110
|
const property = adg.properties.get(getterName);
|
|
115
111
|
const usedByPrimingFunction = usedByPrimingFunctions.has(getterName);
|
|
116
|
-
const usedInTemplate =
|
|
112
|
+
const usedInTemplate = templateReferences?.includes(getterName);
|
|
117
113
|
const usedInPriming = typeof property !== 'undefined' ? property.usedInPriming : false;
|
|
118
114
|
// Only validate getters that are used by priming or the template
|
|
119
115
|
if (usedInPriming || usedByPrimingFunction || usedInTemplate) {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { KomaciDocument } from '@komaci/types';
|
|
2
|
+
import type { ChildNode } from '@lwc/template-compiler';
|
|
2
3
|
import { AnalyzerInput, PrimingDiagnostic, Range, Position, WireInfo } from './types';
|
|
3
4
|
export declare class StaticAnalyzer {
|
|
4
5
|
startPos: Position;
|
|
@@ -84,5 +85,6 @@ export declare class StaticAnalyzer {
|
|
|
84
85
|
private reorderFunctionsByWireDependency;
|
|
85
86
|
private dependsOn;
|
|
86
87
|
private findWireInfo;
|
|
88
|
+
findReferences(node: ChildNode, functionNames: string[]): void;
|
|
87
89
|
}
|
|
88
90
|
//# sourceMappingURL=staticAnalyzer.d.ts.map
|
package/build/staticAnalyzer.js
CHANGED
|
@@ -55,9 +55,10 @@ class StaticAnalyzer {
|
|
|
55
55
|
// generate komaciDoc from source file from collector in lwc-metadata-next package
|
|
56
56
|
const metadataObj = this.getMetadata(input);
|
|
57
57
|
if (metadataObj) {
|
|
58
|
-
let templateKomaciDoc;
|
|
59
58
|
let scriptKomaciDoc;
|
|
60
59
|
let sourceFileName;
|
|
60
|
+
let templateKomaciDoc;
|
|
61
|
+
let templateFile;
|
|
61
62
|
let templateLimitReached = false;
|
|
62
63
|
for (const file of metadataObj.files) {
|
|
63
64
|
if (file.komaciDoc) {
|
|
@@ -76,6 +77,7 @@ class StaticAnalyzer {
|
|
|
76
77
|
diagnostics.push((0, rules_1.updatePrimingDiagnosticWithFileInfo)((0, rules_1.getPrimingDiagnostic)(rules_1.diagnosticMessages.NO_MULTIPLE_TEMPLATE_FILES, this.emptyRange, []), this.fileNamesMap.get('html')));
|
|
77
78
|
}
|
|
78
79
|
else {
|
|
80
|
+
templateFile = file;
|
|
79
81
|
templateKomaciDoc = file.komaciDoc;
|
|
80
82
|
templateLimitReached = true;
|
|
81
83
|
this.fileNamesMap.set('html', file.fileName);
|
|
@@ -101,10 +103,14 @@ class StaticAnalyzer {
|
|
|
101
103
|
astContext: (0, common_shared_1.getAstContextObject)(rootAst),
|
|
102
104
|
isExternal: (0, common_shared_1.isExternalModule)(input.namespace),
|
|
103
105
|
};
|
|
106
|
+
const templateReferences = [];
|
|
104
107
|
if (templateKomaciDoc !== undefined) {
|
|
108
|
+
if (templateFile && templateFile.ast) {
|
|
109
|
+
templateFile.ast.children.forEach((child) => this.findReferences(child, templateReferences));
|
|
110
|
+
}
|
|
105
111
|
(0, common_shared_1.addTemplateUsageForAdg)(templateKomaciDoc, adgIndex, moduleMetadata);
|
|
106
112
|
}
|
|
107
|
-
const { getterFunctionDiagnostics, validGetters } = (0, shared_1.analyzeSrcForInvalidGetterFunctions)(adgIndex, rootAst, moduleMetadata, moduleContext);
|
|
113
|
+
const { getterFunctionDiagnostics, validGetters } = (0, shared_1.analyzeSrcForInvalidGetterFunctions)(adgIndex, rootAst, moduleMetadata, moduleContext, templateReferences);
|
|
108
114
|
const { templateDiagnostics, validTemplates } = (0, shared_1.analyzeSrcForTemplateStringDiagnostics)(adgIndex, rootAst, moduleMetadata, moduleContext);
|
|
109
115
|
const getterAndTemplateDiagnostics = [
|
|
110
116
|
...getterFunctionDiagnostics,
|
|
@@ -782,6 +788,32 @@ class StaticAnalyzer {
|
|
|
782
788
|
}
|
|
783
789
|
return wireInfo;
|
|
784
790
|
}
|
|
791
|
+
findReferences(node, functionNames) {
|
|
792
|
+
// Rule: If type is "If", "ForEach", or "ForOf" and condition.type is "Identifier"
|
|
793
|
+
if ((node.type === 'If' || node.type === 'ForEach' || node.type === 'ForOf') &&
|
|
794
|
+
'condition' in node &&
|
|
795
|
+
node.condition &&
|
|
796
|
+
typeof node.condition === 'object' &&
|
|
797
|
+
'type' in node.condition &&
|
|
798
|
+
node.condition.type === 'Identifier' &&
|
|
799
|
+
'name' in node.condition) {
|
|
800
|
+
functionNames.push(node.condition.name);
|
|
801
|
+
}
|
|
802
|
+
// Rule: If type is "Text" and value.type is "Identifier"
|
|
803
|
+
if (node.type === 'Text' &&
|
|
804
|
+
'value' in node &&
|
|
805
|
+
node.value &&
|
|
806
|
+
typeof node.value === 'object' &&
|
|
807
|
+
'type' in node.value &&
|
|
808
|
+
node.value.type === 'Identifier' &&
|
|
809
|
+
'name' in node.value) {
|
|
810
|
+
functionNames.push(node.value.name);
|
|
811
|
+
}
|
|
812
|
+
// Recurse into children
|
|
813
|
+
if ('children' in node && Array.isArray(node.children)) {
|
|
814
|
+
node.children.forEach((child) => this.findReferences(child, functionNames));
|
|
815
|
+
}
|
|
816
|
+
}
|
|
785
817
|
}
|
|
786
818
|
exports.StaticAnalyzer = StaticAnalyzer;
|
|
787
819
|
//# sourceMappingURL=staticAnalyzer.js.map
|