@komaci/esm-generator 244.1.0 → 244.1.2

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.
@@ -34,7 +34,7 @@ describe('composeAdgStaticMetadata', () => {
34
34
  const moduleMetadata = (0, common_shared_1.initModuleMetadataObject)();
35
35
  const adg = (0, common_shared_1.initAdgMetadataObject)('adg0');
36
36
  adg.exportName = 'default';
37
- moduleMetadata.defaultComponentId = 'c-test-comp';
37
+ moduleMetadata.staticMetadataId = 'c-test-comp';
38
38
  const res = (0, functionAstGeneration_1.composeAdgStaticMetadata)(adg, moduleMetadata);
39
39
  expect(res.type).toBe('VariableDeclaration');
40
40
  const varDeclarator = res.declarations[0];
@@ -47,7 +47,7 @@ describe('composeAdgStaticMetadata', () => {
47
47
  const moduleMetadata = (0, common_shared_1.initModuleMetadataObject)();
48
48
  const adg = (0, common_shared_1.initAdgMetadataObject)('adg1');
49
49
  adg.exportName = 'base';
50
- moduleMetadata.defaultComponentId = 'c-test-comp';
50
+ moduleMetadata.staticMetadataId = 'c-test-comp';
51
51
  const res = (0, functionAstGeneration_1.composeAdgStaticMetadata)(adg, moduleMetadata);
52
52
  expect(res.type).toBe('VariableDeclaration');
53
53
  const varDeclarator = res.declarations[0];
@@ -60,7 +60,7 @@ describe('composeAdgStaticMetadata', () => {
60
60
  const moduleMetadata = (0, common_shared_1.initModuleMetadataObject)();
61
61
  const adg = (0, common_shared_1.initAdgMetadataObject)('adg0');
62
62
  adg.exportName = 'default';
63
- moduleMetadata.defaultComponentId = 'c-test-comp';
63
+ moduleMetadata.staticMetadataId = 'c-test-comp';
64
64
  adg.compositionRootIndex = 0;
65
65
  adg.compositions = [
66
66
  {
@@ -123,7 +123,7 @@ describe('composeAdgStaticMetadata', () => {
123
123
  const moduleMetadata = (0, common_shared_1.initModuleMetadataObject)();
124
124
  const adg = (0, common_shared_1.initAdgMetadataObject)('adg0');
125
125
  adg.exportName = 'default';
126
- moduleMetadata.defaultComponentId = 'c-test-comp';
126
+ moduleMetadata.staticMetadataId = 'c-test-comp';
127
127
  adg.compositionRootIndex = 0;
128
128
  const primingFunction = {
129
129
  requiredProperties: [],
@@ -144,7 +144,7 @@ describe('composeAdgStaticMetadata', () => {
144
144
  const moduleMetadata = (0, common_shared_1.initModuleMetadataObject)();
145
145
  const adg = (0, common_shared_1.initAdgMetadataObject)('adg0');
146
146
  adg.exportName = 'default';
147
- moduleMetadata.defaultComponentId = 'c-test-comp';
147
+ moduleMetadata.staticMetadataId = 'c-test-comp';
148
148
  adg.compositionRootIndex = 0;
149
149
  const primingFunction = {
150
150
  requiredProperties: [],
@@ -165,7 +165,7 @@ describe('composeAdgStaticMetadata', () => {
165
165
  const moduleMetadata = (0, common_shared_1.initModuleMetadataObject)();
166
166
  const adg = (0, common_shared_1.initAdgMetadataObject)('adg0');
167
167
  adg.exportName = 'default';
168
- moduleMetadata.defaultComponentId = 'c-test-comp';
168
+ moduleMetadata.staticMetadataId = 'c-test-comp';
169
169
  adg.compositionRootIndex = 0;
170
170
  const primingFunction = {
171
171
  requiredProperties: [],
@@ -181,5 +181,24 @@ describe('composeAdgStaticMetadata', () => {
181
181
  expect(properties[0].value.value).toBe('c-test-comp');
182
182
  expect(properties[2].value.value).toBeFalsy();
183
183
  });
184
+ it('Correct id for non exported class', () => {
185
+ const moduleMetadata = (0, common_shared_1.initModuleMetadataObject)();
186
+ const adg = (0, common_shared_1.initAdgMetadataObject)('adg0');
187
+ moduleMetadata.staticMetadataId = 'c-test-comp';
188
+ adg.compositionRootIndex = 0;
189
+ const primingFunction = {
190
+ requiredProperties: [],
191
+ type: common_shared_1.FunctionTypes.GETTER_FUNCTION,
192
+ };
193
+ adg.functions.push(primingFunction);
194
+ const res = (0, functionAstGeneration_1.composeAdgStaticMetadata)(adg, moduleMetadata);
195
+ expect(res.type).toBe('VariableDeclaration');
196
+ const varDeclarator = res.declarations[0];
197
+ expect(varDeclarator.id.name).toBe('adg0Meta');
198
+ const properties = varDeclarator.init.properties;
199
+ expect(properties).toHaveLength(4);
200
+ expect(properties[0].value.value).toBe('c-test-comp__$nonExportedClass$');
201
+ expect(properties[2].value.value).toBeFalsy();
202
+ });
184
203
  });
185
204
  //# sourceMappingURL=adgAstGeneration.spec.js.map
@@ -1,4 +1,27 @@
1
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
+ };
2
25
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
27
  };
@@ -11,6 +34,7 @@ const types_1 = require("@babel/types");
11
34
  const functionAstGeneration_1 = require("../functionAstGeneration");
12
35
  const generator_1 = __importDefault(require("@babel/generator"));
13
36
  const badImportRef_1 = require("./fixtures-source-code/badImportRef");
37
+ const t = __importStar(require("@babel/types"));
14
38
  const generalMockSourceCode_1 = require("./fixtures-source-code/generalMockSourceCode");
15
39
  describe('hoistLocalFunction', () => {
16
40
  const baseFilesPath = (0, path_1.join)(__dirname, 'general-komaci-docs/assorted-template-strings');
@@ -535,4 +559,16 @@ export default registerAdgFunction(adg0);`;
535
559
  expect((0, generator_1.default)((0, types_1.file)(res)).code).toBe(expected);
536
560
  });
537
561
  });
562
+ describe('composeStaticMetadataAssignmentExpression', () => {
563
+ it('returns proper expression statement', () => {
564
+ const metaVarDeclarator = t.variableDeclarator(t.identifier(`Adg0Meta`), t.objectExpression([]));
565
+ const staticMetadataObject = t.variableDeclaration('const', [metaVarDeclarator]);
566
+ const expr = (0, functionAstGeneration_1.composeStaticMetadataAssignmentExpression)('adg0', staticMetadataObject).expression;
567
+ const left = expr.left;
568
+ expect(left.object.name).toBe('adg0');
569
+ expect(left.property.name).toBe('meta');
570
+ const right = expr.right;
571
+ expect(right.name).toBe('Adg0Meta');
572
+ });
573
+ });
538
574
  //# sourceMappingURL=functionAstGeneration.spec.js.map
@@ -85,4 +85,11 @@ export declare function getInlineFunctionFromTemplateCompositions(moduleMetadata
85
85
  * @returns A default export representing the error state for this resolvable module
86
86
  */
87
87
  export declare function produceErrorAdgFunction(moduleMetadata: ModuleMetadata, error: Error): t.Program;
88
+ /**
89
+ * Helper function to return the static metadata assignemnt expression statement.
90
+ * @param adgName the name of the adg function to associate the adgMeta object with.
91
+ * @param staticMetadataObject the staticMetadatObject to get the assicated adgMeta object name.
92
+ * @returns an expression statement, eg: adg0.meta = adg0meta
93
+ */
94
+ export declare function composeStaticMetadataAssignmentExpression(adgName: string, staticMetadataObject: t.VariableDeclaration): t.ExpressionStatement;
88
95
  //# sourceMappingURL=functionAstGeneration.d.ts.map
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.produceErrorAdgFunction = exports.getInlineFunctionFromTemplateCompositions = exports.getAdgFunctionBody = exports.addExportStatement = exports.composeAdgStaticMetadata = exports.composeAdgFunction = exports.getFactoryFuncDeclaration = exports.adgToExpression = exports.sanitizeFunction = exports.hoistLocalFunction = void 0;
26
+ exports.composeStaticMetadataAssignmentExpression = exports.produceErrorAdgFunction = exports.getInlineFunctionFromTemplateCompositions = exports.getAdgFunctionBody = exports.addExportStatement = exports.composeAdgStaticMetadata = exports.composeAdgFunction = exports.getFactoryFuncDeclaration = exports.adgToExpression = exports.sanitizeFunction = exports.hoistLocalFunction = void 0;
27
27
  const t = __importStar(require("@babel/types"));
28
28
  const common_shared_1 = require("@komaci/common-shared");
29
29
  const compositionAstGeneration_1 = require("./compositionAstGeneration");
@@ -242,13 +242,35 @@ exports.composeAdgFunction = composeAdgFunction;
242
242
  * @returns a babel representation of a static metadata object.
243
243
  */
244
244
  function composeAdgStaticMetadata(adg, moduleMetadata) {
245
- const compId = adg.exportName == 'default'
246
- ? moduleMetadata.defaultComponentId
247
- : `${moduleMetadata.defaultComponentId}__${adg.exportName}`;
245
+ const Id = adg.exportName == 'default' ||
246
+ moduleMetadata.moduleType == common_shared_1.ModuleTypes.TEMPLATE_ONLY
247
+ ? moduleMetadata.staticMetadataId
248
+ : adg.exportName
249
+ ? `${moduleMetadata.staticMetadataId}__${adg.exportName}`
250
+ : `${moduleMetadata.staticMetadataId}__$nonExportedClass$`;
248
251
  const metaDataProps = [];
249
252
  //creating id: "comp-id";
250
- const idProp = t.objectProperty(t.identifier('id'), t.stringLiteral(compId));
253
+ const idProp = t.objectProperty(t.identifier('id'), t.stringLiteral(Id));
251
254
  metaDataProps.push(idProp);
255
+ if (adg.parentReference != undefined) {
256
+ if (adg.parentReference.type == 'ImportReference') {
257
+ const importName = moduleMetadata.importIndexReference.get(adg.parentReference.value);
258
+ if (importName) {
259
+ const importId = moduleMetadata.importsByName.get(importName)?.generatorAlias;
260
+ if (importId) {
261
+ const parentProp = t.objectProperty(t.identifier('p'), t.identifier(importId));
262
+ metaDataProps.push(parentProp);
263
+ }
264
+ }
265
+ }
266
+ else if (adg.parentReference.type == 'AdgReference') {
267
+ const parentAdgName = moduleMetadata.adgs.get(adg.parentReference.value)?.defaultGeneratedName;
268
+ if (parentAdgName) {
269
+ const parentProp = t.objectProperty(t.identifier('p'), t.identifier(parentAdgName));
270
+ metaDataProps.push(parentProp);
271
+ }
272
+ }
273
+ }
252
274
  const tPropBody = [];
253
275
  let hasImg = false;
254
276
  if (adg.compositions && adg.compositionRootIndex != undefined) {
@@ -267,7 +289,7 @@ function composeAdgStaticMetadata(adg, moduleMetadata) {
267
289
  //creating pf: false as the default.
268
290
  const pfProp = t.objectProperty(t.identifier('pf'), t.booleanLiteral(hasPrimableFunction));
269
291
  //creating img: prop based on if we found an img in the children traversal
270
- const imgProp = t.objectProperty(t.identifier('pf'), t.booleanLiteral(hasImg));
292
+ const imgProp = t.objectProperty(t.identifier('img'), t.booleanLiteral(hasImg));
271
293
  metaDataProps.push(pfProp);
272
294
  metaDataProps.push(imgProp);
273
295
  //eg: adg0Meta: {...metadataProps}
@@ -480,4 +502,15 @@ function produceErrorAdgFunction(moduleMetadata, error) {
480
502
  ]);
481
503
  }
482
504
  exports.produceErrorAdgFunction = produceErrorAdgFunction;
505
+ /**
506
+ * Helper function to return the static metadata assignemnt expression statement.
507
+ * @param adgName the name of the adg function to associate the adgMeta object with.
508
+ * @param staticMetadataObject the staticMetadatObject to get the assicated adgMeta object name.
509
+ * @returns an expression statement, eg: adg0.meta = adg0meta
510
+ */
511
+ function composeStaticMetadataAssignmentExpression(adgName, staticMetadataObject) {
512
+ return t.expressionStatement(t.assignmentExpression('=', t.memberExpression(t.identifier(adgName), t.identifier('meta')), t.identifier(staticMetadataObject.declarations[0]
513
+ .id.name)));
514
+ }
515
+ exports.composeStaticMetadataAssignmentExpression = composeStaticMetadataAssignmentExpression;
483
516
  //# sourceMappingURL=functionAstGeneration.js.map
@@ -61,12 +61,16 @@ function generateResolvableModule(input, scriptKomaciDoc, templateKomaciDocMap,
61
61
  : undefined;
62
62
  const hasScriptKomaciDoc = scriptKomaciDoc && Object.keys(scriptKomaciDoc).length !== 0;
63
63
  const hasTemplateKomaciDoc = defaultTemplateKomaciDoc && Object.keys(defaultTemplateKomaciDoc).length !== 0;
64
- if (hasTemplateKomaciDoc) {
65
- //generates the component name eg. komaciAction.js/html -> c-komaci-action
66
- moduleMetadata.defaultComponentId = (0, common_shared_1.getComponentId)(input.moduleInfo.namespace, input.moduleInfo.name);
67
- }
64
+ //generates the component name eg. komaciAction.js/html -> c-komaci-action
65
+ moduleMetadata.staticMetadataId = (0, common_shared_1.getComponentId)(input.moduleInfo.namespace, input.moduleInfo.name);
68
66
  const combinedModule = scriptKomaciDoc !== undefined && defaultTemplateKomaciDoc !== undefined;
69
67
  const isBundle = input.moduleInfo.type === 'bundle';
68
+ moduleMetadata.moduleType =
69
+ hasTemplateKomaciDoc && hasScriptKomaciDoc
70
+ ? common_shared_1.ModuleTypes.BUNDLE_MODULE
71
+ : hasScriptKomaciDoc
72
+ ? common_shared_1.ModuleTypes.SCRIPT_ONLY
73
+ : common_shared_1.ModuleTypes.TEMPLATE_ONLY;
70
74
  let renderFunctionMetadata = undefined;
71
75
  // start of metadata collection
72
76
  if (scriptKomaciDoc) {
@@ -179,7 +183,15 @@ function generateResolvableModule(input, scriptKomaciDoc, templateKomaciDocMap,
179
183
  statements.push(addUndefinedDefaultExport());
180
184
  }
181
185
  for (const adg of moduleMetadata.adgs.values()) {
182
- statements.push((0, functionAstGeneration_1.composeAdgFunction)(adg, moduleMetadata));
186
+ //eg: const adgoMeta = {...}
187
+ const staticMetadataObject = (0, functionAstGeneration_1.composeAdgStaticMetadata)(adg, moduleMetadata);
188
+ //eg: function adg0(fct, ctx) {...}
189
+ const adgFunctionDefinition = (0, functionAstGeneration_1.composeAdgFunction)(adg, moduleMetadata);
190
+ //eg: adg0.meta = adg0Meta;
191
+ const staticMetadataAssignmentExpression = (0, functionAstGeneration_1.composeStaticMetadataAssignmentExpression)(adg.defaultGeneratedName, staticMetadataObject);
192
+ statements.push(staticMetadataObject);
193
+ statements.push(adgFunctionDefinition);
194
+ statements.push(staticMetadataAssignmentExpression);
183
195
  }
184
196
  for (const [exportName, adg] of Object.entries(moduleMetadata.exports)) {
185
197
  statements.push((0, functionAstGeneration_1.addExportStatement)(adg.defaultGeneratedName, exportName));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@komaci/esm-generator",
3
- "version": "244.1.0",
3
+ "version": "244.1.2",
4
4
  "description": "Komaci generator for ADG ES modules",
5
5
  "homepage": "https://komaci.dev/",
6
6
  "repository": {
@@ -29,11 +29,11 @@
29
29
  "@babel/core": "^7.9.0",
30
30
  "@babel/generator": "^7.9.0",
31
31
  "@babel/types": "^7.9.0",
32
- "@komaci/common-shared": "244.1.0",
33
- "@komaci/static-analyzer": "244.1.0"
32
+ "@komaci/common-shared": "244.1.2",
33
+ "@komaci/static-analyzer": "244.1.2"
34
34
  },
35
35
  "devDependencies": {
36
- "@komaci/types": "244.1.0",
36
+ "@komaci/types": "244.1.2",
37
37
  "@lwc-platform/sfdc-lwc-compiler": "242.15.1-2.28.0",
38
38
  "@lwc/metadata": "^2.28.0-0"
39
39
  }