@komaci/esm-generator 242.1.6 → 242.1.8

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.
@@ -825,7 +825,7 @@ describe('collectMetadataForImportedTemplates', () => {
825
825
  };
826
826
  moduleMetadata.importsByName.set('child1', templateImport);
827
827
  //assuming that component-reference is the default.
828
- (0, genericAstGeneration_1.collectMetadataForImportedTemplates)(moduleMetadata, 'component-reference');
828
+ (0, genericAstGeneration_1.collectMetadataForImportedTemplates)(moduleMetadata);
829
829
  confirmBaselineAdgExpectations(Object.values(moduleMetadata.adgs));
830
830
  expect(moduleMetadata.adgGeneratorIndex).toBe(2);
831
831
  expect(moduleMetadata.importGeneratorIndex).toBe(2);
@@ -866,7 +866,7 @@ describe('collectMetadataForImportedTemplates', () => {
866
866
  };
867
867
  moduleMetadata.importsByName.set('child2', templateImport2);
868
868
  //assuming that component-reference is the default.
869
- (0, genericAstGeneration_1.collectMetadataForImportedTemplates)(moduleMetadata, 'default-template');
869
+ (0, genericAstGeneration_1.collectMetadataForImportedTemplates)(moduleMetadata);
870
870
  confirmBaselineAdgExpectations(Object.values(moduleMetadata.adgs));
871
871
  expect(moduleMetadata.adgGeneratorIndex).toBe(3);
872
872
  expect(moduleMetadata.importGeneratorIndex).toBe(5);
@@ -883,10 +883,36 @@ describe('collectMetadataForImportedTemplates', () => {
883
883
  const defaultAdg = (0, common_shared_1.initAdgMetadataObject)('adg0');
884
884
  moduleMetadata.adgs.set(0, defaultAdg);
885
885
  //assuming that component-reference is the default.
886
- (0, genericAstGeneration_1.collectMetadataForImportedTemplates)(moduleMetadata, 'component-reference');
886
+ (0, genericAstGeneration_1.collectMetadataForImportedTemplates)(moduleMetadata);
887
887
  confirmBaselineAdgExpectations(Object.values(moduleMetadata.adgs));
888
888
  expect(moduleMetadata.adgGeneratorIndex).toBe(1);
889
889
  expect(moduleMetadata.importGeneratorIndex).toBe(0);
890
890
  });
891
+ it('proerly sets the adgReference when importing default template', () => {
892
+ const moduleMetadata = (0, common_shared_1.initModuleMetadataObject)();
893
+ moduleMetadata.templateKomaciDocMap = templateMap;
894
+ moduleMetadata.adgGeneratorIndex = 1;
895
+ const defaultAdg = (0, common_shared_1.initAdgMetadataObject)('adg0');
896
+ moduleMetadata.adgs.set(0, defaultAdg);
897
+ //importing component-refernece explicitly.
898
+ const templateImport = {
899
+ name: 'default',
900
+ komaciDocImportRef: '0/names/0',
901
+ importAlias: 'defaultTemplate',
902
+ generatorAlias: 'i0',
903
+ resourceName: './component-reference',
904
+ staticallyAnalyzable: true,
905
+ templateKomaciDoc: templateMap['component-reference'],
906
+ usedInPriming: true,
907
+ isFromInternalNamespace: true,
908
+ isFromSupportedLibrary: true,
909
+ };
910
+ moduleMetadata.importsByName.set('defaultTemplate', templateImport);
911
+ //assuming that component-reference is the default.
912
+ (0, genericAstGeneration_1.collectMetadataForImportedTemplates)(moduleMetadata);
913
+ confirmBaselineAdgExpectations(Object.values(moduleMetadata.adgs));
914
+ expect(moduleMetadata.adgGeneratorIndex).toBe(2);
915
+ expect(templateImport.adgReference).toBe('adg1');
916
+ });
891
917
  });
892
918
  //# sourceMappingURL=genericAstGeneration.spec.js.map
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.processRenderFunction = exports.processTemplateStrings = exports.processGetters = exports.getComponentSrcJs = void 0;
4
+ const types_1 = require("./types");
4
5
  const static_analyzer_1 = require("@komaci/static-analyzer");
5
6
  const common_shared_1 = require("@komaci/common-shared");
6
7
  /**
@@ -121,7 +122,7 @@ function processRenderFunction(adgIndex, moduleContext, moduleMetadata, renderFu
121
122
  type: common_shared_1.FunctionTypes.RENDER_FUNCTION,
122
123
  componentAstNode: renderFunction,
123
124
  requiredProperties: identifiers,
124
- generatedName: `hoistedRenderFunction`,
125
+ generatedName: types_1.ID.HOISTED_RENDER_FUNC_ID.name,
125
126
  };
126
127
  (0, common_shared_1.updatePropertyUsage)('hoistedRenderFunction', identifiers, adg.properties, common_shared_1.PropertyTypes.RENDER_FUNCTION);
127
128
  return functionMeta;
@@ -68,7 +68,7 @@ export declare function getAdgFunctionBody(adg: AdgMetadata, moduleMetadata: Mod
68
68
  * @param {Composition[]} compositions array of Compositions to convert
69
69
  * @returns {t.ArrowFunctionExpression} an inline ArrowFunctionExpression representing the input Compositions
70
70
  */
71
- export declare function getInlineFunctionFromTemplateCompositions(moduleMetadata: ModuleMetadata, requiredFactoryFunctions: Set<IdKeys>, compositions: Composition[]): t.ArrowFunctionExpression;
71
+ export declare function getInlineFunctionFromTemplateCompositions(moduleMetadata: ModuleMetadata, requiredFactoryFunctions: Set<IdKeys>, compositions: Composition[], adgMetadata: AdgMetadata): t.ArrowFunctionExpression;
72
72
  /**
73
73
  * A barebones resolvable module default export with a singular node describing the context of an error.
74
74
  *
@@ -192,7 +192,7 @@ function adgToExpression(adg, moduleMetadata) {
192
192
  }
193
193
  // arg4: Imported in-line composition function.
194
194
  if (adg.compositions) {
195
- params.push(getInlineFunctionFromTemplateCompositions(moduleMetadata, adg.requiredCompositionFactoryFunctions, adg.compositions));
195
+ params.push(getInlineFunctionFromTemplateCompositions(moduleMetadata, adg.requiredCompositionFactoryFunctions, adg.compositions, adg));
196
196
  }
197
197
  else {
198
198
  params.push(types_1.ID.DEFAULT_COMP);
@@ -284,22 +284,37 @@ exports.getAdgFunctionBody = getAdgFunctionBody;
284
284
  * @param {Composition[]} compositions array of Compositions to convert
285
285
  * @returns {t.ArrowFunctionExpression} an inline ArrowFunctionExpression representing the input Compositions
286
286
  */
287
- function getInlineFunctionFromTemplateCompositions(moduleMetadata, requiredFactoryFunctions, compositions) {
287
+ function getInlineFunctionFromTemplateCompositions(moduleMetadata, requiredFactoryFunctions, compositions, adgMetadata) {
288
288
  const params = [types_1.ID.FACTORY, types_1.ID.CONTEXT];
289
289
  const statements = [];
290
290
  const body = t.blockStatement(statements);
291
291
  const emptyCompositionsArray = compositions.length < 1;
292
- const compositionArrayExpr = emptyCompositionsArray
293
- ? t.arrayExpression([])
294
- : (0, compositionAstGeneration_1.compositionsToArrayExpression)(moduleMetadata, compositions) ||
295
- t.arrayExpression([]);
296
- // function body destructured factory object. e.g. `const { cg } = fct;`
297
- const fctFuncs = getFactoryFuncDeclaration(requiredFactoryFunctions); // passing in false because we are not processing the script file in this method
298
- if (fctFuncs && !emptyCompositionsArray) {
299
- statements.push(fctFuncs);
292
+ if (moduleMetadata.hasRenderFunction && adgMetadata.exportName == 'default') {
293
+ // function body destructured factory object. e.g. `const { cg } = fct;`
294
+ const fctFuncs = getFactoryFuncDeclaration(requiredFactoryFunctions); // passing in false because we are not processing the script file in this method
295
+ if (fctFuncs) {
296
+ statements.push(fctFuncs);
297
+ }
298
+ const rtFuncParams = [types_1.ID.HOISTED_RENDER_FUNC_ID, types_1.ID.CONTEXT];
299
+ // rf(hoistedRenderFunction, CTX)
300
+ const rtFunc = t.callExpression(types_1.ID.RENDER_FUNC, rtFuncParams);
301
+ //creating the return statement
302
+ statements.push(t.returnStatement(rtFunc));
303
+ return t.arrowFunctionExpression(params, body);
304
+ }
305
+ else {
306
+ const compositionArrayExpr = emptyCompositionsArray
307
+ ? t.arrayExpression([])
308
+ : (0, compositionAstGeneration_1.compositionsToArrayExpression)(moduleMetadata, compositions) ||
309
+ t.arrayExpression([]);
310
+ // function body destructured factory object. e.g. `const { cg } = fct;`
311
+ const fctFuncs = getFactoryFuncDeclaration(requiredFactoryFunctions); // passing in false because we are not processing the script file in this method
312
+ if (fctFuncs && !emptyCompositionsArray) {
313
+ statements.push(fctFuncs);
314
+ }
315
+ statements.push(t.returnStatement(compositionArrayExpr));
316
+ return t.arrowFunctionExpression(params, body);
300
317
  }
301
- statements.push(t.returnStatement(compositionArrayExpr));
302
- return t.arrowFunctionExpression(params, body);
303
318
  }
304
319
  exports.getInlineFunctionFromTemplateCompositions = getInlineFunctionFromTemplateCompositions;
305
320
  /**
@@ -108,8 +108,7 @@ export declare function addUndefinedDefaultExport(): t.ExportDefaultDeclaration;
108
108
  export declare function exportNamedDeclarationForDynamicImport(moduleName: string, moduleNamespace: string, targetModule?: string): t.ExportNamedDeclaration;
109
109
  /**
110
110
  * Helper function to collect metadata for imported templates. NOTE: if the default html doc is being imported it will only update the associated ADG reference
111
- * @param templateMap the map of html filenames to its generated komaci document
112
- * @param defaultTemplateFileName the name of the default template.
111
+ * @param moduleMetadata the module metadata object.
113
112
  */
114
- export declare function collectMetadataForImportedTemplates(moduleMetadata: ModuleMetadata, defaultTemplateFileName: string, defaultAdgIndex?: number): void;
113
+ export declare function collectMetadataForImportedTemplates(moduleMetadata: ModuleMetadata): void;
115
114
  //# sourceMappingURL=genericAstGeneration.d.ts.map
@@ -86,11 +86,17 @@ function generateResolvableModule(input, scriptKomaciDoc, templateKomaciDocMap,
86
86
  //If there is a render function, process it.
87
87
  if (renderFunction) {
88
88
  renderFunctionMetadata = (0, componentAstProcessing_1.processRenderFunction)(componentDefaultAdgIndex, moduleContext, moduleMetadata, renderFunction);
89
+ if (renderFunctionMetadata) {
90
+ moduleMetadata.hasRenderFunction = true;
91
+ moduleMetadata.adgs
92
+ .get(componentDefaultAdgIndex)
93
+ ?.requiredCompositionFactoryFunctions.add(common_shared_1.IdKeys.RENDER_FUNC);
94
+ }
89
95
  }
90
96
  }
91
97
  }
92
- //has a default html file
93
- if (hasTemplateKomaciDoc) {
98
+ //has a default html file but no render funciton ***
99
+ if (hasTemplateKomaciDoc && !moduleMetadata.hasRenderFunction) {
94
100
  componentDefaultAdgIndex = (0, common_shared_1.reconcileDefaultAdg)(componentDefaultAdgIndex, moduleMetadata);
95
101
  if (componentDefaultAdgIndex !== undefined) {
96
102
  (0, common_shared_1.initializeImportMetdataFromKomaciDocument)(defaultTemplateKomaciDoc, moduleMetadata, componentDefaultAdgIndex);
@@ -109,9 +115,10 @@ function generateResolvableModule(input, scriptKomaciDoc, templateKomaciDocMap,
109
115
  newImport.isFromSupportedLibrary = true;
110
116
  newImport.generatorAlias = 'comp1';
111
117
  }
112
- //as long as we have at least one template, check to see if its imported. In the case the default html doc is imported, the assocated adg refernce will be set.
113
- if (Object.keys(moduleMetadata.templateKomaciDocMap).length > 0) {
114
- collectMetadataForImportedTemplates(moduleMetadata, input.moduleInfo.name, componentDefaultAdgIndex);
118
+ //as long as we have at least one template and theres a valid render function, check to see if its imported. In the case the default html doc is imported, the assocated adg refernce will be set.
119
+ if (Object.keys(moduleMetadata.templateKomaciDocMap).length > 0 &&
120
+ moduleMetadata.hasRenderFunction) {
121
+ collectMetadataForImportedTemplates(moduleMetadata);
115
122
  }
116
123
  // all metadata collected at this point, time to start building ast
117
124
  const statements = [];
@@ -631,26 +638,19 @@ function exportNamedDeclarationForDynamicImport(moduleName, moduleNamespace, tar
631
638
  exports.exportNamedDeclarationForDynamicImport = exportNamedDeclarationForDynamicImport;
632
639
  /**
633
640
  * Helper function to collect metadata for imported templates. NOTE: if the default html doc is being imported it will only update the associated ADG reference
634
- * @param templateMap the map of html filenames to its generated komaci document
635
- * @param defaultTemplateFileName the name of the default template.
641
+ * @param moduleMetadata the module metadata object.
636
642
  */
637
- function collectMetadataForImportedTemplates(moduleMetadata, defaultTemplateFileName, defaultAdgIndex) {
643
+ function collectMetadataForImportedTemplates(moduleMetadata) {
638
644
  moduleMetadata.importsByName.forEach((importMetadata) => {
639
645
  if ((0, common_shared_1.isTemplateImport)(importMetadata)) {
640
646
  const importedTemplateMetadata = importMetadata;
641
647
  const templateKomaciDoc = importedTemplateMetadata.templateKomaciDoc;
642
- const segs = (0, common_shared_1.getFilepathSegments)(importMetadata.resourceName);
643
- if (segs[1].replace('/', '') !== defaultTemplateFileName) {
644
- const templateAdgIndex = moduleMetadata.adgGeneratorIndex++;
645
- const templateAdgMetadata = (0, common_shared_1.initAdgMetadataObject)(`adg${templateAdgIndex}`);
646
- moduleMetadata.adgs.set(templateAdgIndex, templateAdgMetadata);
647
- importedTemplateMetadata.adgReference = `adg${templateAdgIndex}`;
648
- (0, common_shared_1.initializeImportMetdataFromKomaciDocument)(templateKomaciDoc, moduleMetadata, templateAdgIndex);
649
- (0, common_shared_1.addTemplateUsageForAdg)(templateKomaciDoc, templateAdgIndex, moduleMetadata);
650
- }
651
- else {
652
- importedTemplateMetadata.adgReference = `adg${defaultAdgIndex}`;
653
- }
648
+ const templateAdgIndex = moduleMetadata.adgGeneratorIndex++;
649
+ const templateAdgMetadata = (0, common_shared_1.initAdgMetadataObject)(`adg${templateAdgIndex}`);
650
+ moduleMetadata.adgs.set(templateAdgIndex, templateAdgMetadata);
651
+ importedTemplateMetadata.adgReference = `adg${templateAdgIndex}`;
652
+ (0, common_shared_1.initializeImportMetdataFromKomaciDocument)(templateKomaciDoc, moduleMetadata, templateAdgIndex);
653
+ (0, common_shared_1.addTemplateUsageForAdg)(templateKomaciDoc, templateAdgIndex, moduleMetadata);
654
654
  }
655
655
  });
656
656
  }
package/build/types.js CHANGED
@@ -48,6 +48,7 @@ exports.ID = {
48
48
  SLOT_FUNC: t.identifier('s'),
49
49
  ELEMENT_FUNC: t.identifier('e'),
50
50
  ADG_FUNC: t.identifier('adg'),
51
+ RENDER_FUNC: t.identifier('rf'),
51
52
  SLOT: t.identifier('slot'),
52
53
  COMPONENT_ID: t.identifier('componentId'),
53
54
  UNDEFINED: t.identifier('undefined'),
@@ -68,6 +69,7 @@ exports.ID = {
68
69
  REDUCER_FUNC_ID: t.identifier('r'),
69
70
  IMG_SRC: t.identifier('src'),
70
71
  IMG_FUNC: t.identifier('img'),
72
+ HOISTED_RENDER_FUNC_ID: t.identifier('hoistedRender'),
71
73
  };
72
74
  // enum representing the different states of the way an Import is used
73
75
  var ImportUsageState;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@komaci/esm-generator",
3
- "version": "242.1.6",
3
+ "version": "242.1.8",
4
4
  "description": "Komaci generator for ADG ES modules",
5
5
  "homepage": "https://komaci.dev/",
6
6
  "repository": {
@@ -28,13 +28,13 @@
28
28
  "dependencies": {
29
29
  "@babel/core": "^7.9.0",
30
30
  "@babel/generator": "^7.9.0",
31
- "@komaci/common-shared": "242.1.6",
32
- "@komaci/static-analyzer": "242.1.6",
31
+ "@komaci/common-shared": "242.1.8",
32
+ "@komaci/static-analyzer": "242.1.8",
33
33
  "o11y": "^240.7.0"
34
34
  },
35
35
  "devDependencies": {
36
36
  "@babel/types": "^7.9.0",
37
- "@komaci/types": "242.1.6",
37
+ "@komaci/types": "242.1.8",
38
38
  "@lwc-platform/sfdc-lwc-compiler": "^2.18.0-240.2"
39
39
  }
40
40
  }