@komaci/esm-generator 240.1.5 → 242.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/build/__tests__/adgAstGeneration.spec.d.ts +2 -0
  2. package/build/__tests__/adgAstGeneration.spec.js +31 -0
  3. package/build/__tests__/compositionAstGeneration.spec.d.ts +2 -0
  4. package/build/__tests__/compositionAstGeneration.spec.js +396 -0
  5. package/build/__tests__/fixtures-combined-files/exclude-partial-classProps-indirect-importRef-getter/actual.js +5 -1
  6. package/build/__tests__/fixtures-combined-files/include-all-indirect-importRef-getter-complex/actual.js +5 -1
  7. package/build/__tests__/fixtures-combined-files/include-class-prop-indirect-importRef-getter/actual.js +5 -1
  8. package/build/__tests__/fixtures-combined-files/only-named-export-with-template/actual.d.ts +1 -0
  9. package/build/__tests__/fixtures-combined-files/only-named-export-with-template/actual.js +2 -0
  10. package/build/__tests__/fixtures-script-files/imports/actual.js +5 -1
  11. package/build/__tests__/fixtures-script-files/imports-namespaced/actual.js +5 -1
  12. package/build/__tests__/fixtures-script-files/wire-imports/actual.js +5 -1
  13. package/build/__tests__/functionAstGeneration.spec.d.ts +2 -0
  14. package/build/__tests__/functionAstGeneration.spec.js +416 -0
  15. package/build/__tests__/general-komaci-docs/import-types/source.js +5 -1
  16. package/build/__tests__/general-komaci-docs/template-component/source.js +3 -3
  17. package/build/__tests__/genericAstGeneration.spec.d.ts +2 -0
  18. package/build/__tests__/genericAstGeneration.spec.js +877 -0
  19. package/build/__tests__/index.spec.js +34 -18
  20. package/build/__tests__/komaci-ast-unit.spec.js +240 -448
  21. package/build/__tests__/komaci-bundle-module.fixtures.spec.js +1 -0
  22. package/build/__tests__/komaci-script-module.fixtures.spec.js +5 -1
  23. package/build/__tests__/komaci-template-module.fixtures.spec.js +2 -1
  24. package/build/componentAstProcessing.d.ts +34 -0
  25. package/build/componentAstProcessing.js +105 -0
  26. package/build/compositionAstGeneration.d.ts +76 -0
  27. package/build/compositionAstGeneration.js +299 -0
  28. package/build/functionAstGeneration.d.ts +81 -0
  29. package/build/functionAstGeneration.js +345 -0
  30. package/build/genericAstGeneration.d.ts +115 -0
  31. package/build/genericAstGeneration.js +644 -0
  32. package/build/index.d.ts +6 -0
  33. package/build/index.js +77 -89
  34. package/build/types.d.ts +13 -2
  35. package/build/types.js +69 -1
  36. package/package.json +4 -4
  37. package/build/__tests__/modGenScript.spec.d.ts +0 -2
  38. package/build/__tests__/modGenScript.spec.js +0 -110
  39. package/build/__tests__/modGenTemplate.spec.d.ts +0 -2
  40. package/build/__tests__/modGenTemplate.spec.js +0 -196
  41. package/build/__tests__/shared.spec.d.ts +0 -2
  42. package/build/__tests__/shared.spec.js +0 -62
  43. package/build/__tests__/templateStrings.spec.d.ts +0 -2
  44. package/build/__tests__/templateStrings.spec.js +0 -130
  45. package/build/modGenScript.d.ts +0 -38
  46. package/build/modGenScript.js +0 -1027
  47. package/build/modGenTemplate.d.ts +0 -37
  48. package/build/modGenTemplate.js +0 -402
  49. package/build/shared.d.ts +0 -170
  50. package/build/shared.js +0 -588
@@ -0,0 +1,345 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
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);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.produceErrorAdgFunction = exports.getInlineFunctionFromTemplateCompositions = exports.getAdgFunctionBody = exports.addExportStatement = exports.composeAdgFunction = exports.getFactoryFuncDeclaration = exports.adgToExpression = exports.sanitizeFunction = exports.hoistLocalFunction = void 0;
27
+ const t = __importStar(require("@babel/types"));
28
+ const common_shared_1 = require("@komaci/common-shared");
29
+ const compositionAstGeneration_1 = require("./compositionAstGeneration");
30
+ const genericAstGeneration_1 = require("./genericAstGeneration");
31
+ const types_1 = require("./types");
32
+ /**
33
+ * Take a local function (getter, template string, etc) and prepare it for the resolvable module
34
+ * - sanitize the function
35
+ * - give the function a module level signature with generated name
36
+ *
37
+ * @param functionMetadata Metadata about the function to hoist
38
+ * @param importMetadata Map of all the import metadata we know about
39
+ *
40
+ * @returns a composed module level function or undefined if we don't have the
41
+ * information for composing the funciton
42
+ */
43
+ function hoistLocalFunction(functionMetadata, importMetadata) {
44
+ if (functionMetadata.componentAstNode && functionMetadata.generatedName) {
45
+ sanitizeFunction(functionMetadata.componentAstNode, importMetadata);
46
+ const propsId = t.identifier(common_shared_1.PROPS);
47
+ const functionBody = t.isClassMethod(functionMetadata.componentAstNode.node)
48
+ ? functionMetadata.componentAstNode.node.body
49
+ : t.blockStatement([
50
+ t.returnStatement(functionMetadata.componentAstNode.node.value),
51
+ ]);
52
+ const hoistedFunction = t.functionDeclaration(t.identifier(functionMetadata.generatedName), [propsId], // make 'props' an input parameter to the hoisted getter
53
+ functionBody);
54
+ return hoistedFunction;
55
+ }
56
+ return undefined;
57
+ }
58
+ exports.hoistLocalFunction = hoistLocalFunction;
59
+ /**
60
+ * Take a function defined on a class and sanitize it's interactions in preparation to be hoisted into resolvable module/
61
+ *
62
+ * Two main things happen during sanitization:
63
+ * - references to imports are updated to their generated name (i.e. i2)
64
+ * - references to `this` are replaced with references to `props`
65
+ *
66
+ * @param nodePath The node to sanitize
67
+ * @param importMetadata Metadata about all the imports we know about
68
+ */
69
+ function sanitizeFunction(nodePath, importMetadata) {
70
+ const Visitors = {
71
+ Identifier(path) {
72
+ if ((path.parent.type === 'MemberExpression' &&
73
+ path.parent.property === path.node) ||
74
+ path.parent.type === 'Decorator') {
75
+ //when a property shares a same name with an import,
76
+ //it will be identified as an import
77
+ //this check skips the scenario
78
+ return;
79
+ }
80
+ const info = importMetadata.get(path.node.name);
81
+ if (info && info.isFromInternalNamespace && info.isFromSupportedLibrary) {
82
+ path.replaceWith(t.identifier(info.generatorAlias)); // replace usage of import specifier
83
+ }
84
+ else if (info &&
85
+ !(info.isFromInternalNamespace && info.isFromSupportedLibrary)) {
86
+ // legit this should never happen but if we somehow missed an edge case somewhere this will prevent a malformed module from going out
87
+ throw new Error(`${common_shared_1.ERROR_PREFIX}: '${path.node.name}' does not map to valid import`);
88
+ }
89
+ },
90
+ MemberExpression(path) {
91
+ if (path.node.object.type === 'ThisExpression') {
92
+ path.replaceWith(t.memberExpression(t.identifier(common_shared_1.PROPS), path.node.property)); // replace this.<var> with props.<var>
93
+ }
94
+ },
95
+ };
96
+ nodePath.traverse(Visitors);
97
+ }
98
+ exports.sanitizeFunction = sanitizeFunction;
99
+ /**
100
+ * Converts a Komaci ADG into a CallExpression to the ADG factory function
101
+ * call for the Resolver API.
102
+ * @param {GeneratorState} generatorState the current state of the esm generator
103
+ * @param {Adg} adg the current ADG to convert into an Expression
104
+ * @returns {t.Expression} Babel Expression representation of the adg() factory function call
105
+ */
106
+ function adgToExpression(adg, moduleMetadata) {
107
+ const params = [];
108
+ // arg1: Parent Class.
109
+ if (adg.parentReference) {
110
+ let exp;
111
+ if (adg.parentReference.type === 'Unresolved') {
112
+ params.push(types_1.ID.UNRESOLVED_VALUE);
113
+ }
114
+ else if (adg.parentReference.type === 'ImportReference') {
115
+ const importId = moduleMetadata.importIndexReference.get(adg.parentReference.value);
116
+ if (importId) {
117
+ const importMetadata = moduleMetadata.importsByName.get(importId);
118
+ if (!importMetadata?.isFromInternalNamespace ||
119
+ !importMetadata.isFromSupportedLibrary) {
120
+ params.push(types_1.ID.UNRESOLVED_VALUE);
121
+ }
122
+ else {
123
+ exp = t.identifier(importMetadata.generatorAlias);
124
+ params.push(exp);
125
+ }
126
+ }
127
+ }
128
+ else {
129
+ if (adg.parentReference.type === 'AdgReference') {
130
+ const adgIndex = adg.parentReference.value;
131
+ const parentAdgRef = moduleMetadata.adgs.get(adgIndex);
132
+ if (parentAdgRef) {
133
+ exp = t.identifier(parentAdgRef.defaultGeneratedName);
134
+ }
135
+ else {
136
+ exp = types_1.ID.UNDEFINED;
137
+ }
138
+ }
139
+ else {
140
+ exp = (0, genericAstGeneration_1.valueToExpression)(adg.parentReference, moduleMetadata);
141
+ }
142
+ const parentFunc = t.callExpression(exp, [types_1.ID.FACTORY, types_1.ID.CONTEXT]);
143
+ params.push(parentFunc);
144
+ }
145
+ }
146
+ else {
147
+ params.push(types_1.ID.UNDEFINED);
148
+ }
149
+ // arg2: Properties object.
150
+ if (adg.properties) {
151
+ const objProps = [];
152
+ for (const [propName, propValue] of adg.properties) {
153
+ objProps.push(t.objectProperty(t.identifier(propName), (0, genericAstGeneration_1.propertyToExpression)(moduleMetadata, propValue)));
154
+ }
155
+ params.push(t.objectExpression(objProps));
156
+ }
157
+ else {
158
+ params.push(t.objectExpression([]));
159
+ }
160
+ // arg3: Functions array.
161
+ const functionsArray = [];
162
+ if (adg.functions) {
163
+ adg.functions.forEach((adgFunc) => {
164
+ const expr = (0, genericAstGeneration_1.functionToExpression)(moduleMetadata, adgFunc);
165
+ if (expr) {
166
+ functionsArray.push(expr);
167
+ }
168
+ else {
169
+ functionsArray.push(null);
170
+ }
171
+ });
172
+ }
173
+ if (functionsArray.length) {
174
+ params.push(t.arrayExpression(functionsArray));
175
+ }
176
+ else {
177
+ params.push(t.arrayExpression([]));
178
+ }
179
+ // arg4: Imported in-line composition function.
180
+ if (adg.compositions) {
181
+ params.push(getInlineFunctionFromTemplateCompositions(moduleMetadata, adg.requiredCompositionFactoryFunctions, adg.compositions));
182
+ }
183
+ else {
184
+ params.push(types_1.ID.DEFAULT_COMP);
185
+ }
186
+ // arg5: pass properties that the template references (only if processing a bundle)
187
+ // this array of t.stringLiterals may include properties mentioned the Template that aren't necessarily
188
+ // defined in the Script. Resolution engine has logic to handle these
189
+ params.push(t.arrayExpression(Array.from(adg.propertiesUsedInTemplate).map((v) => t.stringLiteral(v))));
190
+ return t.callExpression(types_1.ID.ADG_FUNC, params);
191
+ }
192
+ exports.adgToExpression = adgToExpression;
193
+ /**
194
+ * Return the variable declaration done via destructuring the factory object
195
+ * (e.g. const { i, cg } = fct;) or undefined if no fct functions are used.
196
+ * @param factoryFuncs Set of strings that represent used factory functions
197
+ * @returns composed ast statement for factory functions
198
+ */
199
+ function getFactoryFuncDeclaration(factoryFuncs) {
200
+ const fctFunctions = Array.from(factoryFuncs).map((func) => {
201
+ const funcId = types_1.ID[func];
202
+ return t.objectProperty(funcId, funcId, false, true);
203
+ });
204
+ if (fctFunctions.length) {
205
+ const declarator = t.variableDeclarator(t.objectPattern(fctFunctions), types_1.ID.FACTORY);
206
+ return t.variableDeclaration('const', [declarator]);
207
+ }
208
+ }
209
+ exports.getFactoryFuncDeclaration = getFactoryFuncDeclaration;
210
+ /**
211
+ * composes ast statements for a given set of ADG Metadata
212
+ *
213
+ * @param adg the metadata for the adg we want to compose an ast for
214
+ * @param moduleMetadata Metadata about the entire module
215
+ * @returns the declaration for a given adg
216
+ */
217
+ function composeAdgFunction(adg, moduleMetadata) {
218
+ // For each exported Adg create a corresponding export of a function
219
+ // which returns the AdgDefinition described in Resolver API.
220
+ const body = getAdgFunctionBody(adg, moduleMetadata);
221
+ return t.functionDeclaration(t.identifier(adg.defaultGeneratedName), [types_1.ID.FACTORY, types_1.ID.CONTEXT], body);
222
+ }
223
+ exports.composeAdgFunction = composeAdgFunction;
224
+ /**
225
+ * associate composed adgs with their exported names
226
+ * @param adgName the name of the adg
227
+ * @param exportName the name it will be exported as
228
+ * @returns the composed export statement
229
+ */
230
+ function addExportStatement(adgName, exportName) {
231
+ if (exportName === 'default') {
232
+ // e.g. `export default registerAdgFunction(adg0)`
233
+ return t.exportDefaultDeclaration(t.callExpression(t.identifier('registerAdgFunction'), [
234
+ t.identifier(adgName),
235
+ ]));
236
+ }
237
+ else {
238
+ // e.g `export const Foo = registerAdgFunction(adg0)`
239
+ const expVar = t.variableDeclarator(t.identifier(exportName), t.callExpression(t.identifier('registerAdgFunction'), [
240
+ t.identifier(adgName),
241
+ ]));
242
+ return t.exportNamedDeclaration(t.variableDeclaration('const', [expVar]));
243
+ }
244
+ }
245
+ exports.addExportStatement = addExportStatement;
246
+ /**
247
+ * Compose the function that calls the `adg` function with all of it's needful info
248
+ * @param {GeneratorState} generatorState the current state of the esm generator
249
+ * @param {Adg} adg The current ADG for which to compose the babel statements
250
+ * @returns the babel statements to represent the function
251
+ */
252
+ function getAdgFunctionBody(adg, moduleMetadata) {
253
+ const adgFuncCall = adgToExpression(adg, moduleMetadata);
254
+ const fctFuncs = getFactoryFuncDeclaration(adg.requiredAdgFactoryFunctions);
255
+ const funcStatements = [];
256
+ const body = t.blockStatement(funcStatements);
257
+ // Function body will be destructuring of factory object and the return
258
+ // statement for the adg() function call from Resolver API.
259
+ // e.g. `{ const { adg } = fct; return adg({...}); }`
260
+ if (fctFuncs) {
261
+ funcStatements.push(fctFuncs);
262
+ }
263
+ funcStatements.push(t.returnStatement(adgFuncCall));
264
+ return body;
265
+ }
266
+ exports.getAdgFunctionBody = getAdgFunctionBody;
267
+ /**
268
+ * Converts array of template Compositions into a representation that is an inline function
269
+ * @param {GeneratorState} generatorState the current state of esm-generator
270
+ * @param {Composition[]} compositions array of Compositions to convert
271
+ * @returns {t.ArrowFunctionExpression} an inline ArrowFunctionExpression representing the input Compositions
272
+ */
273
+ function getInlineFunctionFromTemplateCompositions(moduleMetadata, requiredFactoryFunctions, compositions) {
274
+ const params = [types_1.ID.FACTORY, types_1.ID.CONTEXT];
275
+ const statements = [];
276
+ const body = t.blockStatement(statements);
277
+ const emptyCompositionsArray = compositions.length < 1;
278
+ const compositionArrayExpr = emptyCompositionsArray
279
+ ? t.arrayExpression([])
280
+ : (0, compositionAstGeneration_1.compositionsToArrayExpression)(moduleMetadata, compositions) ||
281
+ t.arrayExpression([]);
282
+ // function body destructured factory object. e.g. `const { cg } = fct;`
283
+ const fctFuncs = getFactoryFuncDeclaration(requiredFactoryFunctions); // passing in false because we are not processing the script file in this method
284
+ if (fctFuncs && !emptyCompositionsArray) {
285
+ statements.push(fctFuncs);
286
+ }
287
+ statements.push(t.returnStatement(compositionArrayExpr));
288
+ return t.arrowFunctionExpression(params, body);
289
+ }
290
+ exports.getInlineFunctionFromTemplateCompositions = getInlineFunctionFromTemplateCompositions;
291
+ /**
292
+ * A barebones resolvable module default export with a singular node describing the context of an error.
293
+ *
294
+ * We return this instead of a real resolvable module if something throws an error during resolvable module generation
295
+ * @param generatorState The state of the generator for pass through to adgToExpression
296
+ * @param error The error that was thrown
297
+ * @returns A default export representing the error state for this resolvable module
298
+ */
299
+ function produceErrorAdgFunction(moduleMetadata, error) {
300
+ const functionValues = {
301
+ error: {
302
+ type: 'PrimitiveValue',
303
+ value: error instanceof Error
304
+ ? error.message
305
+ : common_shared_1.ERROR_PREFIX + 'Something that is not an error was thrown',
306
+ },
307
+ };
308
+ if (error instanceof Error && error.stack) {
309
+ functionValues.stack = {
310
+ type: 'PrimitiveValue',
311
+ value: error.stack,
312
+ };
313
+ }
314
+ const registerAdgImport = t.importDeclaration([t.importDefaultSpecifier(t.identifier('registerAdgFunction'))], t.stringLiteral('komaci/registerAdgFunction'));
315
+ const adg = (0, common_shared_1.initAdgMetadataObject)('adg0');
316
+ adg.compositions = [];
317
+ adg.requiredAdgFactoryFunctions.add(common_shared_1.IdKeys.ADG_FUNC);
318
+ adg.functions.push({
319
+ type: common_shared_1.FunctionTypes.ERROR,
320
+ input: [
321
+ {
322
+ type: 'ObjectValue',
323
+ value: functionValues,
324
+ },
325
+ ],
326
+ });
327
+ adg.requiredAdgFactoryFunctions.add(common_shared_1.IdKeys.ADG_FUNC);
328
+ const adgFuncCall = adgToExpression(adg, moduleMetadata);
329
+ const factoryFuncs = getFactoryFuncDeclaration(adg.requiredAdgFactoryFunctions);
330
+ const funcDec = t.functionDeclaration(t.identifier(adg.defaultGeneratedName), [types_1.ID.FACTORY, types_1.ID.CONTEXT], t.blockStatement([
331
+ // it is literally impossible for this to be undefined given the adgToExpression call
332
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
333
+ factoryFuncs,
334
+ t.returnStatement(adgFuncCall),
335
+ ]));
336
+ return t.program([
337
+ registerAdgImport,
338
+ funcDec,
339
+ t.exportDefaultDeclaration(t.callExpression(t.identifier('registerAdgFunction'), [
340
+ t.identifier(adg.defaultGeneratedName),
341
+ ])),
342
+ ]);
343
+ }
344
+ exports.produceErrorAdgFunction = produceErrorAdgFunction;
345
+ //# sourceMappingURL=functionAstGeneration.js.map
@@ -0,0 +1,115 @@
1
+ import { ClassPropertyContext, ErrorFunctionMetadata, FunctionMetadata, ModuleMetadata, WireFunctionMetadata } from '@komaci/common-shared';
2
+ import * as t from '@babel/types';
3
+ import { GeneratorInput } from './types';
4
+ import { Binding, PrimitiveValue, PropertyReference, Value, KomaciDocument } from '@komaci/types';
5
+ /**
6
+ * Compose a resolvable module for a component. There are three types of outputted resolvable modules
7
+ * - A resolvable module built from a component with ONLY a template
8
+ * - A resolvable module built from a component with ONLY a js file
9
+ * - A resolvable module that has both a template a js file
10
+ *
11
+ * Currently we only support JS and template files that match the names of components
12
+ *
13
+ * @param input Generator input
14
+ * @param scriptKomaciDoc The js komaci doc if it exists
15
+ * @param templateKomaciDocMap A map of template komaci docs.
16
+ * @param source string pointing to the source of the script doc if it exists
17
+ * @returns The babel AST for the generated resolvable module
18
+ */
19
+ export declare function generateResolvableModule(input: GeneratorInput, scriptKomaciDoc?: KomaciDocument, templateKomaciDocMap?: {
20
+ [fName: string]: KomaciDocument;
21
+ }, source?: string): t.File;
22
+ /**
23
+ * Adds a babel import decleration to the AST for each Komaci import
24
+ *
25
+ * Note: While this method does not return anything, it does modify the input Statement array.
26
+ *
27
+ * @param {ModuleMetadata} moduleMetadata metadata about the lwc module we are building a resolvable module for
28
+ * @param {Statement[]} statements Array of Statement to be modified by this method for this program
29
+ * @param {{ calledFromGenerateCombinedModule: boolean }} options flag to distinguish whether we have been called
30
+ * to generate a combined module or not.
31
+ */
32
+ export declare function addImportStatements(moduleMetadata: ModuleMetadata, statements: t.Statement[], options: {
33
+ calledFromGenerateCombinedModule: boolean;
34
+ }): void;
35
+ /**
36
+ * Make ast statements for the details about an error we received
37
+ * @param adgFunc The error function metadata
38
+ * @param moduleMetadata metadata about the module as whole
39
+ * @returns ast statemenets representing config for this function node
40
+ */
41
+ export declare function processErrorFunction(adgFunc: ErrorFunctionMetadata, moduleMetadata: ModuleMetadata): t.ObjectProperty[];
42
+ /**
43
+ * Function to generate the object property array for a wire function node type.
44
+ *
45
+ * NOTE: if the obj representing the function is from an unsupported namespace, and it
46
+ * is for a wire function, then leave out the function node from the generated resolvable
47
+ * module, by returning undefined.
48
+ * @param {ImportInfo} importInfo import information against which to check the wire function's validity
49
+ * @param {GeneratorState} generatorState the current state of the esm generator
50
+ * @param {FunctionType} adgFunc a wire function from the adg functions array.
51
+ * @returns {ObjectProperty[]} an representation of the wire function node as array of ObjectProperty
52
+ */
53
+ export declare function processWireFunctionType(adgFunc: WireFunctionMetadata, moduleMetadata: ModuleMetadata): t.ObjectProperty[] | undefined;
54
+ /**
55
+ * Convert any possible value within a Komaci ADG to a babel expression.
56
+ * @param komaciValue the komaci value
57
+ * @param moduleMetadata the module meta data object
58
+ * @returns a babel expression for the komaci value.
59
+ */
60
+ export declare function valueToExpression(komaciValue: Value, moduleMetadata: ModuleMetadata): t.Expression;
61
+ /**
62
+ * Convert a Komaci primitive value to babel expression.
63
+ * @param primitive a primitve value
64
+ * @returns an expression that represents the primitive value.
65
+ */
66
+ export declare function primitiveToExpression(primitive: PrimitiveValue): t.Expression;
67
+ /**
68
+ * Convert binding (or PropertyReference) to a babel expr (e.g. record.value?.Id).
69
+ * @param binding The binding object
70
+ * @param iterationContext If this binding is inside an iteration we need the contextual details about the iteration to build the proper expression
71
+ * @param parseRootOnly There are some cases where we only care about the first piece of the binding. in the example above we might need to only check `record` instead of `record.value?.Id`
72
+ * @returns A composed member expression
73
+ */
74
+ export declare function bindingToExpression(binding: Binding | PropertyReference, iterationContext?: string[], parseRootOnly?: boolean): t.Identifier | t.OptionalMemberExpression;
75
+ /**
76
+ * Convert a single Komaci function to an object expression in the shape of a
77
+ * FunctionDefinition as defined in Resolver API.
78
+ * @param {GeneratorState} generatorState the current esm generator state
79
+ * @param {FunctionType} adgFunc a function from the adg functions arrray.
80
+ * @returns {Expression} a babel Expression if propertly processed or undefined.
81
+ */
82
+ export declare function functionToExpression(moduleMetadata: ModuleMetadata, adgFunc: FunctionMetadata): t.ObjectExpression | undefined;
83
+ /**
84
+ * Convert a single Komaci property to an object expression in the shape of
85
+ * a PropertyDefinition as defined in Resolver API.
86
+ * @param {GeneratorState} generatorState the current state of esm-generator
87
+ * @param {Adg} adg the current ADG from which to seek out FunctionReferences
88
+ * @param {Propery} property the Komaci property to process
89
+ * @returns {Expression} the komaci property converted to an object Expression
90
+ */
91
+ export declare function propertyToExpression(moduleMetadata: ModuleMetadata, property: ClassPropertyContext): t.ObjectExpression;
92
+ /**
93
+ * Adds a default export to the program statements, if no default export that is derived from an AdgReference already exists
94
+ *
95
+ * @returns composed AST statement for undefined default export
96
+ */
97
+ export declare function addUndefinedDefaultExport(): t.ExportDefaultDeclaration;
98
+ /**
99
+ * Adds the dynamic import of target module, but only for bundles (if moduleInfo.type === "bundle").
100
+ *
101
+ * Returns an export named declaration. The declaration is assigned an arrowFunctionExpression, which returns
102
+ * a dynamic import based on the moduleInfo namespace and name.
103
+ * @param moduleName The name of module we're making
104
+ * @param moduleNamespace the namespace for this given module
105
+ * @param targetModule name of the target module if it exists
106
+ * @returns ExportNamedDeclaration containing the statement of the dynamic import of the target module
107
+ */
108
+ export declare function exportNamedDeclarationForDynamicImport(moduleName: string, moduleNamespace: string, targetModule?: string): t.ExportNamedDeclaration;
109
+ /**
110
+ * Helper function to collect metadata for non default templates.
111
+ * @param templateMap the map of html filenames to its generated komaci document
112
+ * @param defaultTemplateFileName the name of the default template.
113
+ */
114
+ export declare function collectMetadataForNonDefaultTemplates(moduleMetadata: ModuleMetadata, defaultTemplateFileName: string): void;
115
+ //# sourceMappingURL=genericAstGeneration.d.ts.map