@komaci/esm-generator 240.1.3
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/__tests__/compile-generated-module-fixtures.spec.d.ts +2 -0
- package/build/__tests__/compile-generated-module-fixtures.spec.js +45 -0
- package/build/__tests__/fixtures-combined-files/exclude-comps-unused-import-prop/actual.d.ts +5 -0
- package/build/__tests__/fixtures-combined-files/exclude-comps-unused-import-prop/actual.js +28 -0
- package/build/__tests__/fixtures-combined-files/exclude-partial-classProps-indirect-importRef-getter/actual.d.ts +28 -0
- package/build/__tests__/fixtures-combined-files/exclude-partial-classProps-indirect-importRef-getter/actual.js +144 -0
- package/build/__tests__/fixtures-combined-files/exclude-total-unused-import-getter-from-one/actual.d.ts +8 -0
- package/build/__tests__/fixtures-combined-files/exclude-total-unused-import-getter-from-one/actual.js +35 -0
- package/build/__tests__/fixtures-combined-files/exclude-total-unused-import-getter-from-two/actual.d.ts +9 -0
- package/build/__tests__/fixtures-combined-files/exclude-total-unused-import-getter-from-two/actual.js +39 -0
- package/build/__tests__/fixtures-combined-files/exclude-wire-unused-import-prop/actual.d.ts +6 -0
- package/build/__tests__/fixtures-combined-files/exclude-wire-unused-import-prop/actual.js +34 -0
- package/build/__tests__/fixtures-combined-files/image-type/actual.d.ts +12 -0
- package/build/__tests__/fixtures-combined-files/image-type/actual.js +41 -0
- package/build/__tests__/fixtures-combined-files/include-all-indirect-importRef-getter-complex/actual.d.ts +13 -0
- package/build/__tests__/fixtures-combined-files/include-all-indirect-importRef-getter-complex/actual.js +75 -0
- package/build/__tests__/fixtures-combined-files/include-class-prop-indirect-importRef-getter/actual.d.ts +17 -0
- package/build/__tests__/fixtures-combined-files/include-class-prop-indirect-importRef-getter/actual.js +99 -0
- package/build/__tests__/fixtures-combined-files/include-comps-used-import-prop/actual.d.ts +5 -0
- package/build/__tests__/fixtures-combined-files/include-comps-used-import-prop/actual.js +28 -0
- package/build/__tests__/fixtures-combined-files/include-template-strings/actual.d.ts +9 -0
- package/build/__tests__/fixtures-combined-files/include-template-strings/actual.js +41 -0
- package/build/__tests__/fixtures-combined-files/include-used-import-getter/actual.d.ts +8 -0
- package/build/__tests__/fixtures-combined-files/include-used-import-getter/actual.js +38 -0
- package/build/__tests__/fixtures-combined-files/include-wire-used-import-prop/actual.d.ts +6 -0
- package/build/__tests__/fixtures-combined-files/include-wire-used-import-prop/actual.js +34 -0
- package/build/__tests__/fixtures-combined-files/unsupported-wire-from-supported-namespace/actual.d.ts +5 -0
- package/build/__tests__/fixtures-combined-files/unsupported-wire-from-supported-namespace/actual.js +19 -0
- package/build/__tests__/fixtures-script-files/class-extends-multiple-with-separate-imports/actual.d.ts +8 -0
- package/build/__tests__/fixtures-script-files/class-extends-multiple-with-separate-imports/actual.js +17 -0
- package/build/__tests__/fixtures-script-files/class-extends-separate-imports/actual.d.ts +4 -0
- package/build/__tests__/fixtures-script-files/class-extends-separate-imports/actual.js +13 -0
- package/build/__tests__/fixtures-script-files/class-extends-separate-imports-alias/actual.d.ts +4 -0
- package/build/__tests__/fixtures-script-files/class-extends-separate-imports-alias/actual.js +10 -0
- package/build/__tests__/fixtures-script-files/class-props/actual.d.ts +25 -0
- package/build/__tests__/fixtures-script-files/class-props/actual.js +92 -0
- package/build/__tests__/fixtures-script-files/empty-class/actual.d.ts +3 -0
- package/build/__tests__/fixtures-script-files/empty-class/actual.js +7 -0
- package/build/__tests__/fixtures-script-files/empty-doc/actual.d.ts +1 -0
- package/build/__tests__/fixtures-script-files/empty-doc/actual.js +2 -0
- package/build/__tests__/fixtures-script-files/empty-wire/actual.d.ts +4 -0
- package/build/__tests__/fixtures-script-files/empty-wire/actual.js +16 -0
- package/build/__tests__/fixtures-script-files/exclude-wire-unused-import-prop/actual.d.ts +6 -0
- package/build/__tests__/fixtures-script-files/exclude-wire-unused-import-prop/actual.js +34 -0
- package/build/__tests__/fixtures-script-files/exports/actual.d.ts +21 -0
- package/build/__tests__/fixtures-script-files/exports/actual.js +63 -0
- package/build/__tests__/fixtures-script-files/imports/actual.d.ts +10 -0
- package/build/__tests__/fixtures-script-files/imports/actual.js +76 -0
- package/build/__tests__/fixtures-script-files/imports-namespaced/actual.d.ts +9 -0
- package/build/__tests__/fixtures-script-files/imports-namespaced/actual.js +59 -0
- package/build/__tests__/fixtures-script-files/include-wire-unused-import-prop/actual.d.ts +6 -0
- package/build/__tests__/fixtures-script-files/include-wire-unused-import-prop/actual.js +34 -0
- package/build/__tests__/fixtures-script-files/inheritance-imports-default/actual.d.ts +3 -0
- package/build/__tests__/fixtures-script-files/inheritance-imports-default/actual.js +10 -0
- package/build/__tests__/fixtures-script-files/inheritance-imports-local/actual.d.ts +8 -0
- package/build/__tests__/fixtures-script-files/inheritance-imports-local/actual.js +24 -0
- package/build/__tests__/fixtures-script-files/inheritance-imports-named/actual.d.ts +4 -0
- package/build/__tests__/fixtures-script-files/inheritance-imports-named/actual.js +17 -0
- package/build/__tests__/fixtures-script-files/inheritance-parent-unresolved/actual.d.ts +4 -0
- package/build/__tests__/fixtures-script-files/inheritance-parent-unresolved/actual.js +17 -0
- package/build/__tests__/fixtures-script-files/unsupported-wire-from-supported-namespace/actual.d.ts +5 -0
- package/build/__tests__/fixtures-script-files/unsupported-wire-from-supported-namespace/actual.js +19 -0
- package/build/__tests__/fixtures-script-files/wire-basic/actual.d.ts +7 -0
- package/build/__tests__/fixtures-script-files/wire-basic/actual.js +30 -0
- package/build/__tests__/fixtures-script-files/wire-functions/actual.d.ts +12 -0
- package/build/__tests__/fixtures-script-files/wire-functions/actual.js +46 -0
- package/build/__tests__/fixtures-script-files/wire-imports/actual.d.ts +10 -0
- package/build/__tests__/fixtures-script-files/wire-imports/actual.js +59 -0
- package/build/__tests__/fixtures-source-code/badImportRef.d.ts +4 -0
- package/build/__tests__/fixtures-source-code/badImportRef.js +21 -0
- package/build/__tests__/fixtures-source-code/generalMockSourceCode.d.ts +5 -0
- package/build/__tests__/fixtures-source-code/generalMockSourceCode.js +93 -0
- package/build/__tests__/general-komaci-docs/assorted-template-strings/source.d.ts +9 -0
- package/build/__tests__/general-komaci-docs/assorted-template-strings/source.js +41 -0
- package/build/__tests__/general-komaci-docs/getters-and-compositions-collisions/source.d.ts +6 -0
- package/build/__tests__/general-komaci-docs/getters-and-compositions-collisions/source.js +31 -0
- package/build/__tests__/general-komaci-docs/import-types/source.d.ts +18 -0
- package/build/__tests__/general-komaci-docs/import-types/source.js +104 -0
- package/build/__tests__/general-komaci-docs/import-types/validationStuff.d.ts +18 -0
- package/build/__tests__/general-komaci-docs/import-types/validationStuff.js +63 -0
- package/build/__tests__/general-komaci-docs/template-component/source.d.ts +8 -0
- package/build/__tests__/general-komaci-docs/template-component/source.js +34 -0
- package/build/__tests__/index.spec.d.ts +2 -0
- package/build/__tests__/index.spec.js +124 -0
- package/build/__tests__/komaci-ast-unit.spec.d.ts +2 -0
- package/build/__tests__/komaci-ast-unit.spec.js +628 -0
- package/build/__tests__/komaci-bundle-module.fixtures.spec.d.ts +2 -0
- package/build/__tests__/komaci-bundle-module.fixtures.spec.js +75 -0
- package/build/__tests__/komaci-script-module.fixtures.spec.d.ts +2 -0
- package/build/__tests__/komaci-script-module.fixtures.spec.js +66 -0
- package/build/__tests__/komaci-template-module.fixtures.spec.d.ts +2 -0
- package/build/__tests__/komaci-template-module.fixtures.spec.js +56 -0
- package/build/__tests__/modGenScript.spec.d.ts +2 -0
- package/build/__tests__/modGenScript.spec.js +110 -0
- package/build/__tests__/modGenTemplate.spec.d.ts +2 -0
- package/build/__tests__/modGenTemplate.spec.js +196 -0
- package/build/__tests__/shared.spec.d.ts +2 -0
- package/build/__tests__/shared.spec.js +62 -0
- package/build/__tests__/templateStrings.spec.d.ts +2 -0
- package/build/__tests__/templateStrings.spec.js +130 -0
- package/build/index.d.ts +4 -0
- package/build/index.js +130 -0
- package/build/modGenScript.d.ts +38 -0
- package/build/modGenScript.js +1027 -0
- package/build/modGenTemplate.d.ts +37 -0
- package/build/modGenTemplate.js +402 -0
- package/build/shared.d.ts +170 -0
- package/build/shared.js +588 -0
- package/build/types.d.ts +132 -0
- package/build/types.js +14 -0
- package/package.json +40 -0
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import * as t from '@babel/types';
|
|
2
|
+
import { GeneratorState } from './types';
|
|
3
|
+
import { KomaciDocument, Composition, Image } from '@komaci/types';
|
|
4
|
+
/**
|
|
5
|
+
* Generates the resolvable module for a single template file
|
|
6
|
+
* @param {GeneratorState} generatorState the current state of the esm generator
|
|
7
|
+
* @param {KomaciDocument} komaciDoc the KomaciDocument representation of the Template (HTML) file
|
|
8
|
+
* @returns {File} the babel/types File representation of the Template (i.e. the AST of the Template file)
|
|
9
|
+
*/
|
|
10
|
+
export declare function generateTemplateModule(generatorState: GeneratorState, komaciDoc: KomaciDocument): t.File;
|
|
11
|
+
/**
|
|
12
|
+
* Processes the imports for the template Komaci document
|
|
13
|
+
* @param {KomaciDocument} komaciDoc KomaciDocument for the template file
|
|
14
|
+
* @param {GeneratorState} generatorState the current state of the esm generator
|
|
15
|
+
* @param {Statement[]} statements the array of Statement to which to add the import declaration. Should
|
|
16
|
+
* likely be empty as input.
|
|
17
|
+
*/
|
|
18
|
+
export declare function processTemplateImports(komaciDoc: KomaciDocument, generatorState: GeneratorState, statements: t.Statement[]): void;
|
|
19
|
+
/**
|
|
20
|
+
* Convert an array of Komaci Compositions into a babel array of expressions.
|
|
21
|
+
* This is used for both the top-level compositions in the Komaci Doc, as well
|
|
22
|
+
* as their nested child compositions.
|
|
23
|
+
* @param {GeneratorState} generatorState the current state of the esm generator
|
|
24
|
+
* @param {boolean} isScriptFile whether this method is called in the context of processing a Script (JS) file
|
|
25
|
+
* @param {Composition[]} compositions an array of Compositions from a Template JS
|
|
26
|
+
* @returns {ArrayExpression | undefined} an ArrayExpression representing the passed in Composition array, or undefined
|
|
27
|
+
* if no compositions were passed in
|
|
28
|
+
*/
|
|
29
|
+
export declare function compositionsToArrayExpression(generatorState: GeneratorState, isScriptFile: boolean, compositions?: Composition[]): t.ArrayExpression | undefined;
|
|
30
|
+
/**
|
|
31
|
+
* Converts Komaci Image into prompt for the Resolver API to make an image priming call
|
|
32
|
+
* @param {GeneratorState} generatorState the current state of the esm generator
|
|
33
|
+
* @param {Image} image the Image node from the KomaciDocument
|
|
34
|
+
* @returns {Expression} the babel Expression representing the Image prompt into the Resolver API
|
|
35
|
+
*/
|
|
36
|
+
export declare function imageToExpression(generatorState: GeneratorState, image: Image): t.Expression;
|
|
37
|
+
//# sourceMappingURL=modGenTemplate.d.ts.map
|
|
@@ -0,0 +1,402 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
+
exports.imageToExpression = exports.compositionsToArrayExpression = exports.processTemplateImports = exports.generateTemplateModule = void 0;
|
|
23
|
+
/* eslint-disable @typescript-eslint/no-use-before-define */
|
|
24
|
+
const t = __importStar(require("@babel/types"));
|
|
25
|
+
const shared_1 = require("./shared");
|
|
26
|
+
const types_1 = require("./types");
|
|
27
|
+
const common_shared_1 = require("@komaci/common-shared");
|
|
28
|
+
/**
|
|
29
|
+
* Generates the resolvable module for a single template file
|
|
30
|
+
* @param {GeneratorState} generatorState the current state of the esm generator
|
|
31
|
+
* @param {KomaciDocument} komaciDoc the KomaciDocument representation of the Template (HTML) file
|
|
32
|
+
* @returns {File} the babel/types File representation of the Template (i.e. the AST of the Template file)
|
|
33
|
+
*/
|
|
34
|
+
function generateTemplateModule(generatorState, komaciDoc) {
|
|
35
|
+
const statements = [];
|
|
36
|
+
const program = t.program(statements);
|
|
37
|
+
const file = t.file(program);
|
|
38
|
+
// Process the template's imports
|
|
39
|
+
processTemplateImports(komaciDoc, generatorState, statements);
|
|
40
|
+
// Traverse compositions tree to construct array of expressions.
|
|
41
|
+
// One for each Komaci Composition including it's nested children.
|
|
42
|
+
const compositionsArray = compositionsToArrayExpression(generatorState, false, komaciDoc.compositions) ||
|
|
43
|
+
t.arrayExpression([]);
|
|
44
|
+
// Create default export of the main template function.
|
|
45
|
+
// e.g. `export default function (fct, ctx) {...}`
|
|
46
|
+
statements.push(t.exportDefaultDeclaration(getMainFunction(generatorState, compositionsArray)));
|
|
47
|
+
return file;
|
|
48
|
+
}
|
|
49
|
+
exports.generateTemplateModule = generateTemplateModule;
|
|
50
|
+
/**
|
|
51
|
+
* Processes the imports for the template Komaci document
|
|
52
|
+
* @param {KomaciDocument} komaciDoc KomaciDocument for the template file
|
|
53
|
+
* @param {GeneratorState} generatorState the current state of the esm generator
|
|
54
|
+
* @param {Statement[]} statements the array of Statement to which to add the import declaration. Should
|
|
55
|
+
* likely be empty as input.
|
|
56
|
+
*/
|
|
57
|
+
function processTemplateImports(komaciDoc, generatorState, statements) {
|
|
58
|
+
if (komaciDoc.imports) {
|
|
59
|
+
for (let i = 0; i < komaciDoc.imports.length; ++i) {
|
|
60
|
+
const komaciImport = komaciDoc.imports[i];
|
|
61
|
+
const localName = t.identifier(`${shared_1.ADG_IMPORT_SUFFIX}${++generatorState.adgImportSuffix}`);
|
|
62
|
+
let resourceName = komaciImport.resourceName;
|
|
63
|
+
// If template is inline the imports will be for combined module,
|
|
64
|
+
// so remove the file portion of the import. For example:
|
|
65
|
+
// @salesforce/komaci/c__child1__child1.js -> @salesforce/komaci/c__child1
|
|
66
|
+
if (generatorState.inlineTemplateDoc) {
|
|
67
|
+
const lastIndex = resourceName.lastIndexOf('__');
|
|
68
|
+
resourceName = resourceName.slice(0, lastIndex);
|
|
69
|
+
}
|
|
70
|
+
// e.g. `import adg1 from "@salesforce/komaci/c__child1__child1.js";`
|
|
71
|
+
const specifier = t.importDefaultSpecifier(localName);
|
|
72
|
+
const source = t.stringLiteral(resourceName);
|
|
73
|
+
const importDeclaration = t.importDeclaration([specifier], source);
|
|
74
|
+
statements.push(importDeclaration);
|
|
75
|
+
const importInfo = {
|
|
76
|
+
localName,
|
|
77
|
+
componentId: importToComponentId(komaciImport),
|
|
78
|
+
resourceName,
|
|
79
|
+
// below fields not used for template ImportInfos
|
|
80
|
+
exportName: undefined,
|
|
81
|
+
importUsages: new Set(),
|
|
82
|
+
importSpecifier: specifier,
|
|
83
|
+
importDeclaration: importDeclaration,
|
|
84
|
+
};
|
|
85
|
+
generatorState.templateGenState.importRefsMap[`${i}/names/0`] = importInfo;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
exports.processTemplateImports = processTemplateImports;
|
|
90
|
+
/**
|
|
91
|
+
* Convert an array of Komaci Compositions into a babel array of expressions.
|
|
92
|
+
* This is used for both the top-level compositions in the Komaci Doc, as well
|
|
93
|
+
* as their nested child compositions.
|
|
94
|
+
* @param {GeneratorState} generatorState the current state of the esm generator
|
|
95
|
+
* @param {boolean} isScriptFile whether this method is called in the context of processing a Script (JS) file
|
|
96
|
+
* @param {Composition[]} compositions an array of Compositions from a Template JS
|
|
97
|
+
* @returns {ArrayExpression | undefined} an ArrayExpression representing the passed in Composition array, or undefined
|
|
98
|
+
* if no compositions were passed in
|
|
99
|
+
*/
|
|
100
|
+
function compositionsToArrayExpression(generatorState, isScriptFile, compositions) {
|
|
101
|
+
if (!compositions) {
|
|
102
|
+
return undefined;
|
|
103
|
+
}
|
|
104
|
+
const elements = [];
|
|
105
|
+
compositions.forEach((composition) => {
|
|
106
|
+
const expr = compositionToExpression(generatorState, composition, isScriptFile);
|
|
107
|
+
if (expr) {
|
|
108
|
+
if (t.isArrayExpression(expr)) {
|
|
109
|
+
// Special case, such as the top-most container, where the container has
|
|
110
|
+
// no impact on resolution process. In which case we want to flatten
|
|
111
|
+
// the array to effectively remove the container from the generated mod.
|
|
112
|
+
expr.elements.forEach((element) => {
|
|
113
|
+
if (t.isExpression(element)) {
|
|
114
|
+
elements.push(element);
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
elements.push(expr);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
return t.arrayExpression(elements);
|
|
124
|
+
}
|
|
125
|
+
exports.compositionsToArrayExpression = compositionsToArrayExpression;
|
|
126
|
+
/**
|
|
127
|
+
* Convert any of the Komaci composition types into a babel expression, to be included in the generated module.
|
|
128
|
+
* NOTE: For instances where a composition has an isActive coditional, the module will be using the u function provided by the fct factory object to
|
|
129
|
+
* to check for an unresolved value. This function can be overridden, otherwise the default implementaitno will be used. https://salesforce.quip.com/XY4WAbfaLR5E
|
|
130
|
+
* @param {GeneratorState} generatorState the current state of the esm generator
|
|
131
|
+
* @param {Composition} composition the Composition to covert
|
|
132
|
+
* @param {boolean} isScriptFile boolean indicating whether this method is being called in the context of processing a JS Script file
|
|
133
|
+
* @returns {Expression | ArrayExpression} the babel expression (Expression | ArrayExpression) to which the Composition was converted
|
|
134
|
+
*/
|
|
135
|
+
function compositionToExpression(generatorState, composition, isScriptFile) {
|
|
136
|
+
let expression;
|
|
137
|
+
// Get the expression specific to each type of composition.
|
|
138
|
+
switch (composition.type) {
|
|
139
|
+
case 'Container':
|
|
140
|
+
expression = containerToExpression(generatorState, composition, isScriptFile);
|
|
141
|
+
break;
|
|
142
|
+
case 'ComposedAdg':
|
|
143
|
+
expression = composedAdgToExpression(generatorState, composition, isScriptFile);
|
|
144
|
+
break;
|
|
145
|
+
case 'Iteration':
|
|
146
|
+
expression = iterationToExpression(generatorState, composition, isScriptFile);
|
|
147
|
+
break;
|
|
148
|
+
case 'Slot':
|
|
149
|
+
expression = slotToExpression(generatorState, composition);
|
|
150
|
+
break;
|
|
151
|
+
case 'Image':
|
|
152
|
+
expression = imageToExpression(generatorState, composition);
|
|
153
|
+
break;
|
|
154
|
+
}
|
|
155
|
+
// If the composition has an isActive condition, then
|
|
156
|
+
// expression needs to be proceded by a conditional check.
|
|
157
|
+
if (composition.isActive) {
|
|
158
|
+
// when checking conditional, always check unresolved
|
|
159
|
+
generatorState.templateGenState.requiredFactoryFunctions.add(shared_1.ID.UNRESOLVED_FUNC);
|
|
160
|
+
let conditionalTest = (0, shared_1.bindingToExpression)(generatorState, composition.isActive.input, isScriptFile);
|
|
161
|
+
if (composition.isActive.negate) {
|
|
162
|
+
conditionalTest = t.unaryExpression('!', conditionalTest);
|
|
163
|
+
}
|
|
164
|
+
const prop = (0, shared_1.bindingRootToExpression)(generatorState, composition.isActive.input);
|
|
165
|
+
const unresolvedTest = t.callExpression(shared_1.ID.UNRESOLVED_FUNC, [prop]);
|
|
166
|
+
const test = t.logicalExpression('||', unresolvedTest, conditionalTest);
|
|
167
|
+
expression = t.conditionalExpression(test, expression, shared_1.ID.UNDEFINED);
|
|
168
|
+
}
|
|
169
|
+
if ((0, common_shared_1.isCompositionAnImage)(composition) && expression) {
|
|
170
|
+
generatorState.templateGenState.requiredFactoryFunctions.add(shared_1.ID.IMG_FUNC);
|
|
171
|
+
}
|
|
172
|
+
return expression;
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Converts a Komaci container into a babel expression. If the container doesn't
|
|
176
|
+
* impact data flow, then an ArrayExpression is returned for its children.
|
|
177
|
+
* @param {GeneratorState} generatorState the current state of the esm generator
|
|
178
|
+
* @param {Container} container the Komaci container (i.e. <div> tag)
|
|
179
|
+
* @param {boolean} isScriptFile boolean indicating whether this method is being called in the context of processing a JS Script file
|
|
180
|
+
* @returns {Expression | ArrayExpression} The babel Expression or ArrayExpression converted from the input Container
|
|
181
|
+
*/
|
|
182
|
+
function containerToExpression(generatorState, container, isScriptFile) {
|
|
183
|
+
const children = compositionsToArrayExpression(generatorState, false, container.compositions) ||
|
|
184
|
+
t.arrayExpression([]);
|
|
185
|
+
// If key or slot is specified, then the container will need to be
|
|
186
|
+
// accounted for in the module via the element function.
|
|
187
|
+
if (container.key || container.slot) {
|
|
188
|
+
const params = [];
|
|
189
|
+
generatorState.templateGenState.requiredFactoryFunctions.add(shared_1.ID.ELEMENT_FUNC);
|
|
190
|
+
// arg1: Composition configuration.
|
|
191
|
+
params.push(getCompositionConfig(generatorState, container, isScriptFile));
|
|
192
|
+
// arg2: Context.
|
|
193
|
+
params.push(shared_1.ID.CONTEXT);
|
|
194
|
+
// arg3: Array of expressions for each child.
|
|
195
|
+
params.push(children);
|
|
196
|
+
return t.callExpression(shared_1.ID.ELEMENT_FUNC, params);
|
|
197
|
+
}
|
|
198
|
+
else {
|
|
199
|
+
// No key or slot, so only need to include it's children
|
|
200
|
+
// in the generated mod.
|
|
201
|
+
return children.elements.length === 1
|
|
202
|
+
? children.elements[0]
|
|
203
|
+
: children;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Converts a Komaci ComposedAdg (which references an Import) into a call to the Resolver API for a composed graph, `cg`.
|
|
208
|
+
* @param {GeneratorState} generatorState the current state of the esm generator
|
|
209
|
+
* @param {ComposedAdg} composedAdg the ComposedAdg whose input.type is an `ImportReference`
|
|
210
|
+
* @param {boolean} isScriptFile boolean indicating whether this method is being called in the context of processing a JS Script file
|
|
211
|
+
* @returns {Expression} a babel Expression representing the composed graph (cg) resolver API call. Throws an Error if the
|
|
212
|
+
* composedAdg.input.type is not equal to 'ImportReference'
|
|
213
|
+
*/
|
|
214
|
+
function composedAdgToExpression(generatorState, composedAdg, isScriptFile) {
|
|
215
|
+
let componentId;
|
|
216
|
+
const params = [];
|
|
217
|
+
generatorState.templateGenState.requiredFactoryFunctions.add(shared_1.ID.COMPOSED_GRAPH_FUNC);
|
|
218
|
+
// arg1: Input source to the composed graph function.
|
|
219
|
+
if (composedAdg.input.type === 'ImportReference') {
|
|
220
|
+
const importInfo = (0, shared_1.updateImportInfoState)(generatorState, composedAdg.input.value, false, types_1.ImportUsageState.composedadg);
|
|
221
|
+
componentId = importInfo.componentId;
|
|
222
|
+
params.push(importInfo.localName);
|
|
223
|
+
}
|
|
224
|
+
else {
|
|
225
|
+
// Schema supports this, but downstream logic (e.g. analysis) doesn't (yet).
|
|
226
|
+
throw new Error(shared_1.ERROR_PREFIX + 'binding not yet supported for ComposedAdg input');
|
|
227
|
+
}
|
|
228
|
+
// arg2: Composition configuration.
|
|
229
|
+
params.push(getCompositionConfig(generatorState, composedAdg, isScriptFile, componentId));
|
|
230
|
+
// arg3: Context.
|
|
231
|
+
params.push(shared_1.ID.CONTEXT);
|
|
232
|
+
// arg4: Array of expressions for each child.
|
|
233
|
+
const children = compositionsToArrayExpression(generatorState, isScriptFile, composedAdg.compositions);
|
|
234
|
+
if (children && children.elements.length) {
|
|
235
|
+
params.push(children);
|
|
236
|
+
}
|
|
237
|
+
return t.callExpression(shared_1.ID.COMPOSED_GRAPH_FUNC, params);
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Converts a Komaci Iteration into a call to Resolver API for an iteration, i.e `i`.
|
|
241
|
+
* @param {GeneratorState} generatorState the current state of the esm generator
|
|
242
|
+
* @param {Iteration} iteration the Iteration from a template file
|
|
243
|
+
* @param {boolean} isScriptFile boolean indicating whether this method is being called in the context of processing a JS Script file
|
|
244
|
+
* @returns {Expression} the babel Expression that represents the call into the Resolver API for an iteration
|
|
245
|
+
*/
|
|
246
|
+
function iterationToExpression(generatorState, iteration, isScriptFile) {
|
|
247
|
+
const params = [];
|
|
248
|
+
generatorState.templateGenState.requiredFactoryFunctions.add(shared_1.ID.ITERATION_FUNC);
|
|
249
|
+
// arg1: Expression for the collection being iterated.
|
|
250
|
+
params.push((0, shared_1.bindingToExpression)(generatorState, iteration.input, isScriptFile));
|
|
251
|
+
// arg2: Context.
|
|
252
|
+
params.push(shared_1.ID.CONTEXT);
|
|
253
|
+
// arg3: Function to return compositions inside the the iteration.
|
|
254
|
+
// Use context to understand which iterations contain the code being analyzed.
|
|
255
|
+
generatorState.iterationContext.unshift(iteration.iterator);
|
|
256
|
+
const children = compositionsToArrayExpression(generatorState, isScriptFile, iteration.compositions) || t.arrayExpression([]);
|
|
257
|
+
generatorState.iterationContext.shift();
|
|
258
|
+
// interation.iterator contains string variables like "i", "j", "k", or loop control
|
|
259
|
+
// variables must prepend user variable prefix "user_var_" to the variable when used
|
|
260
|
+
// in arrow function declaration, to prevent resolution issues
|
|
261
|
+
params.push(t.arrowFunctionExpression([t.identifier(shared_1.USER_VARIABLE_PREFIX + iteration.iterator)], t.blockStatement([t.returnStatement(children)])));
|
|
262
|
+
return t.callExpression(shared_1.ID.ITERATION_FUNC, params);
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Convert Komaci slot into call to Resolver API for a slot, `s`
|
|
266
|
+
* @param {GeneratorState} generatorState the current state of the esm generator
|
|
267
|
+
* @param {Slot} slot The Slot to be converted into an expression
|
|
268
|
+
* @returns {Expression} the babel Expression representing the Slot call into the Resolver API
|
|
269
|
+
*/
|
|
270
|
+
function slotToExpression(generatorState, slot) {
|
|
271
|
+
const params = [];
|
|
272
|
+
generatorState.templateGenState.requiredFactoryFunctions.add(shared_1.ID.SLOT_FUNC);
|
|
273
|
+
// arg1: Slot Name.
|
|
274
|
+
params.push(t.stringLiteral(slot.name));
|
|
275
|
+
// arg2: Composition configuration.
|
|
276
|
+
params.push(getCompositionConfig(generatorState, slot, false));
|
|
277
|
+
// arg3: Context.
|
|
278
|
+
params.push(shared_1.ID.CONTEXT);
|
|
279
|
+
// arg4: Array of expressions for each child.
|
|
280
|
+
const defaultContent = compositionsToArrayExpression(generatorState, false, slot.compositions);
|
|
281
|
+
if (defaultContent && defaultContent.elements.length) {
|
|
282
|
+
params.push(defaultContent);
|
|
283
|
+
}
|
|
284
|
+
return t.callExpression(shared_1.ID.SLOT_FUNC, params);
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* Converts Komaci Image into prompt for the Resolver API to make an image priming call
|
|
288
|
+
* @param {GeneratorState} generatorState the current state of the esm generator
|
|
289
|
+
* @param {Image} image the Image node from the KomaciDocument
|
|
290
|
+
* @returns {Expression} the babel Expression representing the Image prompt into the Resolver API
|
|
291
|
+
*/
|
|
292
|
+
function imageToExpression(generatorState, image) {
|
|
293
|
+
const params = [];
|
|
294
|
+
const funcObjProps = [];
|
|
295
|
+
if ((0, common_shared_1.isCompositionAnImage)(image)) {
|
|
296
|
+
if ((0, common_shared_1.isSrcPrimitiveValue)(image.src)) {
|
|
297
|
+
// type guard ensures `image.src` is a PrimitiveValue
|
|
298
|
+
// lwc-platform will NOT produce an Image KomaciNode with a blank or missing src attribute.
|
|
299
|
+
// However, just in case we do encounter this, we handle it here by simply NOT producing the
|
|
300
|
+
// function ObjectProperty for such a node.
|
|
301
|
+
if (image.src.value &&
|
|
302
|
+
typeof image.src.value === 'string' &&
|
|
303
|
+
image.src.value !== '') {
|
|
304
|
+
funcObjProps.push(t.objectProperty(shared_1.ID.IMG_SRC, t.stringLiteral(image.src.value)));
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
else if ((0, common_shared_1.isSrcABinding)(image.src)) {
|
|
308
|
+
// type guard ensures `image.src` is a Binding
|
|
309
|
+
// lwc-platform will NOT produce an Image KomaciNode with a blank or missing src attribute.
|
|
310
|
+
// However, just in case we do encounter this, we handle it here by simply NOT producing the
|
|
311
|
+
// function ObjectProperty for such a node.
|
|
312
|
+
if (image.src.value !== '') {
|
|
313
|
+
funcObjProps.push(t.objectProperty(shared_1.ID.IMG_SRC, (0, shared_1.bindingToExpression)(generatorState, image.src, true)));
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
params.push(t.objectExpression(funcObjProps));
|
|
318
|
+
return t.callExpression(shared_1.ID.IMG_FUNC, params);
|
|
319
|
+
}
|
|
320
|
+
exports.imageToExpression = imageToExpression;
|
|
321
|
+
/**
|
|
322
|
+
* Creates a babel configuration ObjectExpression for provided composition. This is the `CompositionConfig`
|
|
323
|
+
* from Resolver API in its babel ObjectExpression form.
|
|
324
|
+
* @param {GeneratorState} generatorState the curent state of the esm generator
|
|
325
|
+
* @param {ComposedAdg | Container | Slot} composition the Composition from which to create a configuration (as a ComposedAdg, Container, or Slot)
|
|
326
|
+
* @param {boolean} isScriptFile boolean indicating whether this method is being called in the context of processing a JS Script file
|
|
327
|
+
* @param {string} componentId the component indentifier, as a string
|
|
328
|
+
* @returns {ObjectExpression} the babel ObjectExpression representing the Resolver API CompositionConfig
|
|
329
|
+
*/
|
|
330
|
+
function getCompositionConfig(generatorState, composition, isScriptFile, componentId) {
|
|
331
|
+
const config = [];
|
|
332
|
+
if (composition.slot) {
|
|
333
|
+
config.push(t.objectProperty(shared_1.ID.SLOT, t.stringLiteral(composition.slot)));
|
|
334
|
+
}
|
|
335
|
+
// ComposedAdg config contains additional information.
|
|
336
|
+
if (composition.type === 'ComposedAdg') {
|
|
337
|
+
if (componentId) {
|
|
338
|
+
config.push(t.objectProperty(shared_1.ID.COMPONENT_ID, t.stringLiteral(componentId)));
|
|
339
|
+
}
|
|
340
|
+
if (composition.properties) {
|
|
341
|
+
const props = [];
|
|
342
|
+
for (const propName of Object.keys(composition.properties)) {
|
|
343
|
+
const prop = composition.properties[propName];
|
|
344
|
+
if (prop.type === 'Binding') {
|
|
345
|
+
props.push(t.objectProperty(t.identifier(propName), (0, shared_1.bindingToExpression)(generatorState, prop, isScriptFile)));
|
|
346
|
+
}
|
|
347
|
+
else if (prop.type === 'PrimitiveValue') {
|
|
348
|
+
props.push(t.objectProperty(t.identifier(propName), (0, shared_1.primitiveToExpression)(generatorState, prop)));
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
config.push(t.objectProperty(shared_1.ID.PROPS, t.objectExpression(props)));
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
return t.objectExpression(config);
|
|
355
|
+
}
|
|
356
|
+
/**
|
|
357
|
+
* Convers an import in a Komaci template doc to a component identifier.
|
|
358
|
+
* Example:
|
|
359
|
+
* From: @salesforce/komaci/c__child1__child1.js
|
|
360
|
+
* To: c-child1
|
|
361
|
+
* @param {Import} komaciImport Komaci representation of an Import
|
|
362
|
+
* @returns {string} a string representing the component id generated from the import resource name
|
|
363
|
+
*/
|
|
364
|
+
function importToComponentId(komaciImport) {
|
|
365
|
+
// First split by '/' and confirm expected # segments.
|
|
366
|
+
let segments = komaciImport.resourceName.split('/');
|
|
367
|
+
if (segments.length !== 3) {
|
|
368
|
+
throw new Error(shared_1.ERROR_PREFIX + 'komaciDoc contains invalid import');
|
|
369
|
+
}
|
|
370
|
+
// Now split last segment by '__' and confirm expected # segments.
|
|
371
|
+
segments = segments[2].split('__');
|
|
372
|
+
if (segments.length !== 3) {
|
|
373
|
+
throw new Error(shared_1.ERROR_PREFIX + 'komaciDoc contains invalid import');
|
|
374
|
+
}
|
|
375
|
+
const namespace = segments[0];
|
|
376
|
+
// name converted from camel case to kebab case.
|
|
377
|
+
const name = segments[1]
|
|
378
|
+
.replace(/([a-z0-9]|(?=[A-Z]))([A-Z])/g, '$1-$2')
|
|
379
|
+
.toLowerCase();
|
|
380
|
+
return `${namespace}-${name}`;
|
|
381
|
+
}
|
|
382
|
+
/**
|
|
383
|
+
* Retrieves the babel FunctionDeclaration representation of the main function exported from the module being generated.
|
|
384
|
+
* e.g. `function (fct, ctx) { return ... }`
|
|
385
|
+
* @param {GeneratorState} generatorState the current state of the esm generator
|
|
386
|
+
* @param compositionExpressionsArray babel ArrayExpression representing the compositions expresions array
|
|
387
|
+
* @returns babel FunctionDeclaration representation of the main function exported from the module
|
|
388
|
+
*/
|
|
389
|
+
function getMainFunction(generatorState, compositionExpressionsArray) {
|
|
390
|
+
const params = [shared_1.ID.FACTORY, shared_1.ID.CONTEXT];
|
|
391
|
+
const statements = [];
|
|
392
|
+
const body = t.blockStatement(statements);
|
|
393
|
+
// Destructuring of factory functions.
|
|
394
|
+
const fctFuncs = (0, shared_1.getFactoryFuncDeclaration)(generatorState, false);
|
|
395
|
+
if (fctFuncs) {
|
|
396
|
+
statements.push(fctFuncs);
|
|
397
|
+
}
|
|
398
|
+
// Return the array of composition expressions.
|
|
399
|
+
statements.push(t.returnStatement(compositionExpressionsArray));
|
|
400
|
+
return t.functionDeclaration(null, params, body);
|
|
401
|
+
}
|
|
402
|
+
//# sourceMappingURL=modGenTemplate.js.map
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import * as t from '@babel/types';
|
|
2
|
+
import { GeneratorState, ImportInfo, ImportUsageState } from './types';
|
|
3
|
+
import { Binding, PrimitiveValue, Value, PropertyReference, FunctionType, KomaciDocument, Adg } from '@komaci/types';
|
|
4
|
+
import { NodePath } from '@babel/core';
|
|
5
|
+
import { ValidGetterContext, ValidTemplateContext, ModuleLevelConsumption, AstContext, ClassPropertyContexts, ModuleContext } from '@komaci/common-shared';
|
|
6
|
+
export declare const ERROR_PREFIX = "[komaci esm-generator] ";
|
|
7
|
+
export declare const CONTEXT = "ctx";
|
|
8
|
+
export declare const PROPS = "props";
|
|
9
|
+
export declare const ADG_IMPORT_SUFFIX = "getAdgDefinition";
|
|
10
|
+
export declare const UNRESOLVED = "unresolved";
|
|
11
|
+
export declare const USER_VARIABLE_PREFIX = "user_var_";
|
|
12
|
+
export declare const WIRE_FUNCTION = "WireFunction";
|
|
13
|
+
export declare const GETTER_FUNCTION = "GetterFunction";
|
|
14
|
+
export declare const TEMPLATED_STRING_FUNCTION = "TemplatedStringFunction";
|
|
15
|
+
export declare const ERROR_FUNCTION = "ErrorFunction";
|
|
16
|
+
export declare const PRIMING_FUNCTION = "PrimingFunction";
|
|
17
|
+
export declare const ID: {
|
|
18
|
+
CONTEXT: t.Identifier;
|
|
19
|
+
PROPS: t.Identifier;
|
|
20
|
+
FACTORY: t.Identifier;
|
|
21
|
+
COMPOSED_GRAPH_FUNC: t.Identifier;
|
|
22
|
+
ITERATION_FUNC: t.Identifier;
|
|
23
|
+
UNRESOLVED_FUNC: t.Identifier;
|
|
24
|
+
SLOT_FUNC: t.Identifier;
|
|
25
|
+
ELEMENT_FUNC: t.Identifier;
|
|
26
|
+
ADG_FUNC: t.Identifier;
|
|
27
|
+
SLOT: t.Identifier;
|
|
28
|
+
COMPONENT_ID: t.Identifier;
|
|
29
|
+
UNDEFINED: t.Identifier;
|
|
30
|
+
PROP_API: t.Identifier;
|
|
31
|
+
PROP_INIT: t.Identifier;
|
|
32
|
+
PROP_FUNC: t.Identifier;
|
|
33
|
+
PROP_GETTER: t.Identifier;
|
|
34
|
+
DEFAULT_COMP: t.Identifier;
|
|
35
|
+
FUNC_ID: t.Identifier;
|
|
36
|
+
FUNC_NAME: t.Identifier;
|
|
37
|
+
FUNC_TYPE: t.Identifier;
|
|
38
|
+
FUNC_CONFIG: t.Identifier;
|
|
39
|
+
FUNC_INPUT: t.Identifier;
|
|
40
|
+
WIRE_TYPE: t.Identifier;
|
|
41
|
+
UNRESOLVED_VALUE: t.Identifier;
|
|
42
|
+
BATCH_FUNC_ID: t.Identifier;
|
|
43
|
+
BATCH_FUNC_NAME: t.Identifier;
|
|
44
|
+
REDUCER_FUNC_ID: t.Identifier;
|
|
45
|
+
IMG_SRC: t.Identifier;
|
|
46
|
+
IMG_FUNC: t.Identifier;
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* Retrieve info about an import given its reference value (e.g. 0/names/0), while initializing/updating its usageState, as well
|
|
50
|
+
* as updating required factory functions (if we are returning an ImportInfo for an unsupported namespace).
|
|
51
|
+
* @param generatorState the GeneratorState
|
|
52
|
+
* @param importRefValue import reference value, as a string. ex: "0/names/0"
|
|
53
|
+
* @param isScriptFile boolean indicating whether we are calling the method while processing a Script (JS file)[true], or a template (HTML file)[false]
|
|
54
|
+
* @param usageState ImportUsageState enum that represents the way the import will be used. Some example values are: composedadg, wireadapter,
|
|
55
|
+
* getter, initialvalue, wireconfig, parentadg
|
|
56
|
+
* @returns ImportInfo object, updated with latest usageState
|
|
57
|
+
*/
|
|
58
|
+
export declare function updateImportInfoState(generatorState: GeneratorState, importRefValue: string, isScriptFile: boolean, usageState: ImportUsageState): ImportInfo;
|
|
59
|
+
/**
|
|
60
|
+
* Retrieve info about an import given its reference value (e.g. 0/names/0), without updating its state.
|
|
61
|
+
* To update ImportInfo state, see method updateImportInfoState.
|
|
62
|
+
* @param generatorState the current GeneratorState for this module generation
|
|
63
|
+
* @param importRefValue the import reference value to use in looking up the ImportInfo. ex: "0/names/0"
|
|
64
|
+
* @param isScriptFile boolean determining whether we are processing a script (JS) or template (HTML)
|
|
65
|
+
* @returns ImportInfo corresponding to the importRefValue in the generatorState
|
|
66
|
+
*/
|
|
67
|
+
export declare function retrieveImportInfo(generatorState: GeneratorState, importRefValue: string, isScriptFile: boolean): ImportInfo;
|
|
68
|
+
export declare function getFactoryFuncDeclaration(generatorState: GeneratorState, isScriptFile: boolean): t.VariableDeclaration | undefined;
|
|
69
|
+
export declare function primitiveToExpression(generatorState: GeneratorState, primitive: PrimitiveValue): t.Expression;
|
|
70
|
+
export declare function bindingToExpression(generatorState: GeneratorState, binding: Binding | PropertyReference, isScriptFile: boolean): t.Expression;
|
|
71
|
+
export declare function bindingRootToExpression(generatorState: GeneratorState, binding: Binding | PropertyReference): t.Expression;
|
|
72
|
+
export declare function valueToExpression(generatorState: GeneratorState, komaciValue: Value, isScriptFile: boolean, usageState: ImportUsageState): t.Expression;
|
|
73
|
+
/**
|
|
74
|
+
* Retrieve the file path for the js of a component
|
|
75
|
+
* @param generatorState GeneratorState containg the GeneratorInput, which in turn contains the JS raw source file
|
|
76
|
+
* @returns Returns raw source code as string for the js of a component if it exists in the srcFileMap
|
|
77
|
+
* Returns undefined if no JS source file (whose filename also matches the LWC module name) was included in the
|
|
78
|
+
* GeneratorState.GeneratorInput by lwc-platform, other calling code.
|
|
79
|
+
*/
|
|
80
|
+
export declare function getComponentSrcJs(generatorState: GeneratorState): string | undefined;
|
|
81
|
+
/**
|
|
82
|
+
* AST is traversed to see if they contain getter functions that are not valid. For each getter that is valid, we will
|
|
83
|
+
* update contextual information about the class and pass back info about the valid getters.
|
|
84
|
+
*
|
|
85
|
+
* @param {ClassPropertyContexts} properties the Map of properties metadata, which tells whether a property is used by a wire functions
|
|
86
|
+
* @param {ModuleContext} moduleContext Contextual info about the module itself
|
|
87
|
+
* @param {ModuleLevelConsumption} moduleLevelConsumption Details about how things are consuming module level entities. NOTE: This is updated in here for import usage
|
|
88
|
+
* @param {t.File} ast The ast for the module
|
|
89
|
+
* @returns Information about valid getters to be added to the resolvable Module.
|
|
90
|
+
*/
|
|
91
|
+
export declare function processGetters(properties: ClassPropertyContexts, moduleContext: ModuleContext, moduleLevelConsumption: ModuleLevelConsumption, getterMethodPaths: NodePath<t.ClassMethod>[]): ValidGetterContext[];
|
|
92
|
+
/**
|
|
93
|
+
* This method takes in the generatedCombinedModule AST, the original source AST, the import references map from the
|
|
94
|
+
* GeneratorState, and the valid getter contexts (which contain the babel NodePaths to the getters) and transforms the generated
|
|
95
|
+
* combined module AST by hoisting any passed-in valid getters into top-level getter methods, adding `props` as input paramater to the
|
|
96
|
+
* same getter methods, replacing this.<var> references in the getter method to props.<var>, as well as replacing references of
|
|
97
|
+
* valid imports references in the getter with corresponding Komaci module unique identifiers (i1, i2, i3,...).
|
|
98
|
+
*
|
|
99
|
+
* @param genCombinedModuleAST the AST of the generated combined module
|
|
100
|
+
* @param importReferencesMap Map of importReferences (ex: "0/names/0") to ImportInfo, which comes from GeneratorState's scriptGenState.importRefsMap
|
|
101
|
+
* @param getterImportUsage All the imports decalred in the ast
|
|
102
|
+
* @param validGetterContexts Array of ValidGetterContext object which contain the NodePath representing the getter, as well as an Array<string> of
|
|
103
|
+
* memberUsages within the same getter.
|
|
104
|
+
*/
|
|
105
|
+
export declare function transformGetters(genCombinedModuleAST: t.File, importReferencesMap: {
|
|
106
|
+
[refId: string]: ImportInfo;
|
|
107
|
+
}, getterImportUsage: AstContext['importDeclarations'], validGetterContexts: ValidGetterContext[]): void;
|
|
108
|
+
/**
|
|
109
|
+
* Function to update the Komaci Document with validated getter information. This function will update the functions array in the
|
|
110
|
+
* export default adg along with the property references in the property array.
|
|
111
|
+
* @param komaciScriptDoc the komaci document
|
|
112
|
+
* @param validGetterContext a collection
|
|
113
|
+
*/
|
|
114
|
+
export declare function updateKomaciDocumentWithValidGetters(komaciScriptDoc: KomaciDocument, validGetterContext: ValidGetterContext[]): void;
|
|
115
|
+
/**
|
|
116
|
+
* Validate what templates are good and then uplift the metadata about how they interact with other portions of the modules.
|
|
117
|
+
* i.e. import, property references, used in priming
|
|
118
|
+
* @param {ClassPropertyContexts} properties the Map of properties metadata, which tells whether a property is used by a wire functions
|
|
119
|
+
* @param {ModuleContext} moduleContext Contextual info about the module itself
|
|
120
|
+
* @param {ModuleLevelConsumption} moduleLevelConsumption Details about how things are consuming module level entities. NOTE: This is updated in here for import usage
|
|
121
|
+
* @param {Array<NodePath<t.ClassProperty>>} templateStrings The templates to validate
|
|
122
|
+
* @returns Information about valid templates to be added to the resolvable Module.
|
|
123
|
+
*/
|
|
124
|
+
export declare function processTemplateStrings(properties: ClassPropertyContexts, moduleContext: ModuleContext, moduleLevelConsumption: ModuleLevelConsumption, templateStrings: Array<NodePath<t.ClassProperty>>): ValidTemplateContext[];
|
|
125
|
+
/**
|
|
126
|
+
* Converts templates into single line functions, hoisted to the top level of the resolvable module.
|
|
127
|
+
* Part of this hoisting is going through and updating references to properties or imports. similar to what we do for getters.
|
|
128
|
+
*
|
|
129
|
+
* @param genCombinedModuleAST the AST of the generated combined module
|
|
130
|
+
* @param importReferencesMap Map of importReferences (ex: "0/names/0") to ImportInfo, which comes from GeneratorState's scriptGenState.importRefsMap
|
|
131
|
+
* @param definedImports All the imports decalred in the ast
|
|
132
|
+
* @param validGetterContexts Array of valid templates
|
|
133
|
+
*/
|
|
134
|
+
export declare function hoistTemplateStrings(genCombinedModuleAST: t.File, importReferencesMap: {
|
|
135
|
+
[refId: string]: ImportInfo;
|
|
136
|
+
}, definedImports: AstContext['importDeclarations'], templateStrings: ValidTemplateContext[]): void;
|
|
137
|
+
/**
|
|
138
|
+
* Create a mapping from the original name of an import to the generated one made by komaci
|
|
139
|
+
* @param importReferencesMap The inverse mapping of generated name to info
|
|
140
|
+
* @returns A map of original import name to generated name
|
|
141
|
+
*/
|
|
142
|
+
export declare function mapRealNameToGenerated(importReferencesMap: {
|
|
143
|
+
[refId: string]: ImportInfo;
|
|
144
|
+
}): Map<string, string>;
|
|
145
|
+
/**
|
|
146
|
+
* Take a function defined on a class and sanitize it's interactions in preparation to be hoisted into resolvable module/
|
|
147
|
+
*
|
|
148
|
+
* Two main things happen during sanitization:
|
|
149
|
+
* - references to imports are updated to their generated name (i.e. i2)
|
|
150
|
+
* - references to `this` are replaced with references to `props`
|
|
151
|
+
*
|
|
152
|
+
* @param nodePath The node to sanitize
|
|
153
|
+
* @param definedImports Metadata about all the imports we know about
|
|
154
|
+
* @param trueToGeneratedImport Mapping of real import name to generated name
|
|
155
|
+
*/
|
|
156
|
+
export declare function sanitizeFunction(nodePath: NodePath<t.ClassProperty | t.ClassMethod>, definedImports: AstContext['importDeclarations'], trueToGeneratedImport: Map<string, string>): void;
|
|
157
|
+
/**
|
|
158
|
+
* Function to update the Komaci Document with validated template information. This function will update the functions array in the
|
|
159
|
+
* export default adg along with the property references in the property array.
|
|
160
|
+
* @param komaciScriptDoc the komaci document
|
|
161
|
+
* @param ValidTemplateContext details about the templates we've deemed to be valid
|
|
162
|
+
*/
|
|
163
|
+
export declare function updateKomaciDocumentWithValidTemplatedStrings(komaciScriptDoc: KomaciDocument, templateStrings: ValidTemplateContext[]): void;
|
|
164
|
+
/**
|
|
165
|
+
* Update the functions array with the newly formed function reference and point the property to it
|
|
166
|
+
* @param adg The adg to update
|
|
167
|
+
* @param propertyName name of the property to update
|
|
168
|
+
*/
|
|
169
|
+
export declare function addPropertyFunction(adg: Adg, propertyName: string, func: FunctionType): number;
|
|
170
|
+
//# sourceMappingURL=shared.d.ts.map
|