@komaci/esm-generator 244.1.2 → 244.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.
@@ -419,5 +419,40 @@ describe('getCompositionConfig', () => {
419
419
  const code = (0, generator_1.default)(res).code;
420
420
  expect(code).toBe('{}');
421
421
  });
422
+ it('can handle a prop name having special characters', () => {
423
+ const res = (0, compositionAstGeneration_1.getCompositionConfig)({
424
+ type: 'ComposedAdg',
425
+ input: {
426
+ type: 'ImportReference',
427
+ value: '0/names/0',
428
+ },
429
+ properties: {
430
+ 'foo:baz': {
431
+ type: 'PrimitiveValue',
432
+ value: 'bar',
433
+ },
434
+ 'baz:foo': {
435
+ type: 'Binding',
436
+ value: 'bar',
437
+ },
438
+ baz: {
439
+ type: 'Binding',
440
+ value: 'bar',
441
+ },
442
+ foo: {
443
+ type: 'PrimitiveValue',
444
+ value: 'bar',
445
+ },
446
+ },
447
+ });
448
+ expect(res.properties[0].value
449
+ .properties[0].key.type).toBe('Identifier');
450
+ expect(res.properties[0].value
451
+ .properties[1].key.type).toBe('StringLiteral');
452
+ expect(res.properties[0].value
453
+ .properties[2].key.type).toBe('Identifier');
454
+ expect(res.properties[0].value
455
+ .properties[3].key.type).toBe('StringLiteral');
456
+ });
422
457
  });
423
458
  //# sourceMappingURL=compositionAstGeneration.spec.js.map
@@ -494,6 +494,7 @@ describe('addImportStatements', () => {
494
494
  (0, common_shared_1.composeImportMetadata)('adg', '@salesforce/komaci/c__foo__foo.js', true, '4/names/0', moduleMetadata);
495
495
  moduleMetadata.importsByNamespace.set('lightning/uiTestingApi', {
496
496
  names: new Set(['default', 'regularImport']),
497
+ originalNames: new Set(['default', 'regularImport']),
497
498
  isDefaultSpecifier: true,
498
499
  isSupported: true,
499
500
  isNamespaceSpecifier: false,
@@ -501,6 +502,7 @@ describe('addImportStatements', () => {
501
502
  });
502
503
  moduleMetadata.importsByNamespace.set('badImport', {
503
504
  names: new Set(['tes1', 'tes2']),
505
+ originalNames: new Set(['tes1', 'tes2']),
504
506
  isDefaultSpecifier: false,
505
507
  isSupported: false,
506
508
  isNamespaceSpecifier: false,
@@ -508,6 +510,7 @@ describe('addImportStatements', () => {
508
510
  });
509
511
  moduleMetadata.importsByNamespace.set('@salesforce/labels', {
510
512
  names: new Set(['*']),
513
+ originalNames: new Set(['*']),
511
514
  isDefaultSpecifier: false,
512
515
  isSupported: true,
513
516
  isNamespaceSpecifier: true,
@@ -515,6 +518,7 @@ describe('addImportStatements', () => {
515
518
  });
516
519
  moduleMetadata.importsByNamespace.set('lightning/uiRecordApi', {
517
520
  names: new Set(['tes3', 'tes4', 'tes5']),
521
+ originalNames: new Set(['tes3', 'tes4', 'tes5']),
518
522
  isDefaultSpecifier: false,
519
523
  isSupported: true,
520
524
  isNamespaceSpecifier: false,
@@ -522,6 +526,7 @@ describe('addImportStatements', () => {
522
526
  });
523
527
  moduleMetadata.importsByNamespace.set('@salesforce/komaci/c__foo__foo.js', {
524
528
  names: new Set(['adg']),
529
+ originalNames: new Set(['adg']),
525
530
  isDefaultSpecifier: false,
526
531
  isSupported: true,
527
532
  isNamespaceSpecifier: false,
@@ -28,6 +28,7 @@ const common_shared_1 = require("@komaci/common-shared");
28
28
  const t = __importStar(require("@babel/types"));
29
29
  const genericAstGeneration_1 = require("./genericAstGeneration");
30
30
  const types_1 = require("./types");
31
+ const hasSpecialCharacters = /^([0-9]+|(.*[^A-Za-z0-9]+.*))$/;
31
32
  /**
32
33
  * Convert an array of Komaci Compositions into a babel array of expressions.
33
34
  * This is used for both the top-level compositions in the Komaci Doc, as well
@@ -285,10 +286,14 @@ function getCompositionConfig(composition, componentId, iterationContext) {
285
286
  for (const propName of sortedCompositions) {
286
287
  const prop = composition.properties[propName];
287
288
  if (prop.type === 'Binding') {
288
- props.push(t.objectProperty(t.identifier(propName), (0, genericAstGeneration_1.bindingToExpression)(prop, iterationContext)));
289
+ props.push(t.objectProperty(hasSpecialCharacters.test(propName)
290
+ ? t.stringLiteral(propName)
291
+ : t.identifier(propName), (0, genericAstGeneration_1.bindingToExpression)(prop, iterationContext)));
289
292
  }
290
293
  else if (prop.type === 'PrimitiveValue') {
291
- props.push(t.objectProperty(t.identifier(propName), (0, genericAstGeneration_1.primitiveToExpression)(prop)));
294
+ props.push(t.objectProperty(hasSpecialCharacters.test(propName)
295
+ ? t.stringLiteral(propName)
296
+ : t.identifier(propName), (0, genericAstGeneration_1.primitiveToExpression)(prop)));
292
297
  }
293
298
  }
294
299
  config.push(t.objectProperty(types_1.ID.PROPS, t.objectExpression(props)));
@@ -215,6 +215,7 @@ exports.generateResolvableModule = generateResolvableModule;
215
215
  */
216
216
  function addImportStatements(moduleMetadata, statements, options) {
217
217
  if (moduleMetadata.importsByName.size > 0) {
218
+ const seenImports = new Set();
218
219
  const imports = Array.from(moduleMetadata.importsByName.values())
219
220
  .sort((a, b) => {
220
221
  if (a.resourceName < b.resourceName) {
@@ -227,7 +228,16 @@ function addImportStatements(moduleMetadata, statements, options) {
227
228
  return 0;
228
229
  }
229
230
  })
230
- .filter((value) => value.isFromInternalNamespace && value.usedInPriming);
231
+ .filter((value) => {
232
+ // sometimes we can have multiple import names mapped to the same import. so we want to dedup those before running them through composition
233
+ const isComposable = !seenImports.has(value.generatorAlias) &&
234
+ value.isFromInternalNamespace &&
235
+ value.usedInPriming;
236
+ if (isComposable) {
237
+ seenImports.add(value.generatorAlias);
238
+ }
239
+ return isComposable;
240
+ });
231
241
  let i = 0;
232
242
  while (i < imports.length) {
233
243
  const specifiers = [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@komaci/esm-generator",
3
- "version": "244.1.2",
3
+ "version": "244.1.3",
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.2",
33
- "@komaci/static-analyzer": "244.1.2"
32
+ "@komaci/common-shared": "244.1.3",
33
+ "@komaci/static-analyzer": "244.1.3"
34
34
  },
35
35
  "devDependencies": {
36
- "@komaci/types": "244.1.2",
36
+ "@komaci/types": "244.1.3",
37
37
  "@lwc-platform/sfdc-lwc-compiler": "242.15.1-2.28.0",
38
38
  "@lwc/metadata": "^2.28.0-0"
39
39
  }