@komaci/esm-generator 262.15.0 → 262.16.0

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.
@@ -303,6 +303,42 @@ describe('sanitizeFunction', () => {
303
303
  it('should throw an error if we try to reference a bad input', () => {
304
304
  expect(() => (0, functionAstGeneration_1.sanitizeFunction)(getters[1], imports, new Map())).toThrowError(new Error(`${common_shared_1.ERROR_PREFIX}: 'bad' does not map to valid import`));
305
305
  });
306
+ it('should strip TypeScript non-null assertion operator (!)', () => {
307
+ const sourceWithNonNull = `
308
+ import accessCheck from '@salesforce/accessCheck/SomeCheck.enabled';
309
+ export default class TestComponent {
310
+ get showContent() {
311
+ return accessCheck! && this.isVisible;
312
+ }
313
+ }
314
+ `;
315
+ const ast = (0, common_shared_1.generateAstFromSrcCode)(sourceWithNonNull);
316
+ const { getters } = (0, common_shared_1.getPropertyMetadataFromAst)(ast);
317
+ const imports = new Map();
318
+ imports.set('accessCheck', {
319
+ name: 'accessCheck',
320
+ resourceName: '@salesforce/accessCheck/SomeCheck.enabled',
321
+ staticallyAnalyzable: false,
322
+ usedInPriming: true,
323
+ isFromInternalNamespace: true,
324
+ isFromSupportedLibrary: true,
325
+ generatorAlias: 'i0',
326
+ komaciDocImportRef: '0/names/0',
327
+ });
328
+ (0, functionAstGeneration_1.sanitizeFunction)(getters[0], imports, new Map());
329
+ const hoisted = (0, types_1.functionDeclaration)((0, types_1.identifier)('g0'), [(0, types_1.identifier)('props')], getters[0].node.body);
330
+ const generatedFunction = (0, generator_1.default)((0, types_1.file)((0, types_1.program)([hoisted])));
331
+ // The non-null assertion operator (!) should be removed
332
+ // Should generate: i0 && props.isVisible
333
+ // Should NOT generate: i0! && props.isVisible
334
+ expect(generatedFunction.code).not.toContain('!');
335
+ expect(generatedFunction.code).toContain('i0 && props.isVisible');
336
+ expect(generatedFunction.code).toMatchInlineSnapshot(`
337
+ "function g0(props) {
338
+ return i0 && props.isVisible;
339
+ }"
340
+ `);
341
+ });
306
342
  });
307
343
  describe('adgToExpression', () => {
308
344
  it('returns valid adg function from komaci doc', () => {
@@ -112,6 +112,11 @@ function sanitizeFunction(nodePath, importMetadata, gqlMetadataMap) {
112
112
  path.replaceWith(t.memberExpression(t.identifier(common_shared_1.PROPS), path.node.property)); // replace this.<var> with props.<var>
113
113
  }
114
114
  },
115
+ TSNonNullExpression(path) {
116
+ // syntax like foo! is a TypeScript syntax that means "foo is not null or undefined"
117
+ // we need to remove the ! to make the code valid JavaScript
118
+ path.replaceWith(path.node.expression);
119
+ },
115
120
  TaggedTemplateExpression(path) {
116
121
  const taggedTmplExpr = path.node;
117
122
  const taggedTmplLiteral = taggedTmplExpr.quasi;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@komaci/esm-generator",
3
- "version": "262.15.0",
3
+ "version": "262.16.0",
4
4
  "description": "Komaci generator for ADG ES modules",
5
5
  "homepage": "https://komaci.dev/",
6
6
  "repository": {