@komaci/esm-generator 264.5.0 → 266.3.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.
Files changed (130) hide show
  1. package/build/genericAstGeneration.js +80 -34
  2. package/package.json +1 -1
  3. package/build/__tests__/adgAstGeneration.spec.d.ts +0 -2
  4. package/build/__tests__/adgAstGeneration.spec.js +0 -447
  5. package/build/__tests__/compile-generated-module-fixtures.spec.d.ts +0 -2
  6. package/build/__tests__/compile-generated-module-fixtures.spec.js +0 -49
  7. package/build/__tests__/compilerConfigs.d.ts +0 -24
  8. package/build/__tests__/compilerConfigs.js +0 -126
  9. package/build/__tests__/compositionAstGeneration.spec.d.ts +0 -2
  10. package/build/__tests__/compositionAstGeneration.spec.js +0 -676
  11. package/build/__tests__/fixtures-combined-files/exclude-comps-unused-import-prop/actual.d.ts +0 -6
  12. package/build/__tests__/fixtures-combined-files/exclude-comps-unused-import-prop/actual.js +0 -28
  13. package/build/__tests__/fixtures-combined-files/exclude-partial-classProps-indirect-importRef-getter/actual.d.ts +0 -29
  14. package/build/__tests__/fixtures-combined-files/exclude-partial-classProps-indirect-importRef-getter/actual.js +0 -148
  15. package/build/__tests__/fixtures-combined-files/exclude-total-unused-import-getter-from-one/actual.d.ts +0 -9
  16. package/build/__tests__/fixtures-combined-files/exclude-total-unused-import-getter-from-one/actual.js +0 -35
  17. package/build/__tests__/fixtures-combined-files/exclude-total-unused-import-getter-from-two/actual.d.ts +0 -10
  18. package/build/__tests__/fixtures-combined-files/exclude-total-unused-import-getter-from-two/actual.js +0 -39
  19. package/build/__tests__/fixtures-combined-files/exclude-wire-unused-import-prop/actual.d.ts +0 -7
  20. package/build/__tests__/fixtures-combined-files/exclude-wire-unused-import-prop/actual.js +0 -34
  21. package/build/__tests__/fixtures-combined-files/image-type/actual.d.ts +0 -13
  22. package/build/__tests__/fixtures-combined-files/image-type/actual.js +0 -41
  23. package/build/__tests__/fixtures-combined-files/include-all-indirect-importRef-getter-complex/actual.d.ts +0 -14
  24. package/build/__tests__/fixtures-combined-files/include-all-indirect-importRef-getter-complex/actual.js +0 -79
  25. package/build/__tests__/fixtures-combined-files/include-class-prop-indirect-importRef-getter/actual.d.ts +0 -18
  26. package/build/__tests__/fixtures-combined-files/include-class-prop-indirect-importRef-getter/actual.js +0 -103
  27. package/build/__tests__/fixtures-combined-files/include-comps-used-import-prop/actual.d.ts +0 -6
  28. package/build/__tests__/fixtures-combined-files/include-comps-used-import-prop/actual.js +0 -28
  29. package/build/__tests__/fixtures-combined-files/include-salesforce-resourceUrl-imports/actual.d.ts +0 -6
  30. package/build/__tests__/fixtures-combined-files/include-salesforce-resourceUrl-imports/actual.js +0 -16
  31. package/build/__tests__/fixtures-combined-files/include-salesforce-resourceUrl-nonAnalyzable-imports/actual.d.ts +0 -4
  32. package/build/__tests__/fixtures-combined-files/include-salesforce-resourceUrl-nonAnalyzable-imports/actual.js +0 -18
  33. package/build/__tests__/fixtures-combined-files/include-template-strings/actual.d.ts +0 -10
  34. package/build/__tests__/fixtures-combined-files/include-template-strings/actual.js +0 -41
  35. package/build/__tests__/fixtures-combined-files/include-used-import-getter/actual.d.ts +0 -9
  36. package/build/__tests__/fixtures-combined-files/include-used-import-getter/actual.js +0 -38
  37. package/build/__tests__/fixtures-combined-files/include-wire-used-import-prop/actual.d.ts +0 -7
  38. package/build/__tests__/fixtures-combined-files/include-wire-used-import-prop/actual.js +0 -34
  39. package/build/__tests__/fixtures-combined-files/only-named-export-with-template/actual.d.ts +0 -1
  40. package/build/__tests__/fixtures-combined-files/only-named-export-with-template/actual.js +0 -2
  41. package/build/__tests__/fixtures-combined-files/unsupported-wire-from-supported-namespace/actual.d.ts +0 -6
  42. package/build/__tests__/fixtures-combined-files/unsupported-wire-from-supported-namespace/actual.js +0 -19
  43. package/build/__tests__/fixtures-combined-files-multiple-templates/invalid-renderFunc-no-valid-imports/c/component/component.d.ts +0 -5
  44. package/build/__tests__/fixtures-combined-files-multiple-templates/invalid-renderFunc-no-valid-imports/c/component/component.js +0 -14
  45. package/build/__tests__/fixtures-combined-files-multiple-templates/valid-render-function-complex/lightning/component/component.d.ts +0 -6
  46. package/build/__tests__/fixtures-combined-files-multiple-templates/valid-render-function-complex/lightning/component/component.js +0 -31
  47. package/build/__tests__/fixtures-combined-files-multiple-templates/valid-render-function-simple/lightning/component/component.d.ts +0 -6
  48. package/build/__tests__/fixtures-combined-files-multiple-templates/valid-render-function-simple/lightning/component/component.js +0 -27
  49. package/build/__tests__/fixtures-gql/multipleGqlQueries/c/component/component.d.ts +0 -15
  50. package/build/__tests__/fixtures-gql/multipleGqlQueries/c/component/component.js +0 -104
  51. package/build/__tests__/fixtures-script-files/class-extends-multiple-with-separate-imports/actual.d.ts +0 -8
  52. package/build/__tests__/fixtures-script-files/class-extends-multiple-with-separate-imports/actual.js +0 -17
  53. package/build/__tests__/fixtures-script-files/class-extends-separate-imports/actual.d.ts +0 -4
  54. package/build/__tests__/fixtures-script-files/class-extends-separate-imports/actual.js +0 -13
  55. package/build/__tests__/fixtures-script-files/class-extends-separate-imports-alias/actual.d.ts +0 -4
  56. package/build/__tests__/fixtures-script-files/class-extends-separate-imports-alias/actual.js +0 -10
  57. package/build/__tests__/fixtures-script-files/class-props/actual.d.ts +0 -30
  58. package/build/__tests__/fixtures-script-files/class-props/actual.js +0 -103
  59. package/build/__tests__/fixtures-script-files/empty-class/actual.d.ts +0 -4
  60. package/build/__tests__/fixtures-script-files/empty-class/actual.js +0 -7
  61. package/build/__tests__/fixtures-script-files/empty-doc/actual.d.ts +0 -1
  62. package/build/__tests__/fixtures-script-files/empty-doc/actual.js +0 -2
  63. package/build/__tests__/fixtures-script-files/empty-wire/actual.d.ts +0 -5
  64. package/build/__tests__/fixtures-script-files/empty-wire/actual.js +0 -16
  65. package/build/__tests__/fixtures-script-files/exclude-wire-unused-import-prop/actual.d.ts +0 -7
  66. package/build/__tests__/fixtures-script-files/exclude-wire-unused-import-prop/actual.js +0 -34
  67. package/build/__tests__/fixtures-script-files/exports/actual.d.ts +0 -22
  68. package/build/__tests__/fixtures-script-files/exports/actual.js +0 -63
  69. package/build/__tests__/fixtures-script-files/imports/actual.d.ts +0 -11
  70. package/build/__tests__/fixtures-script-files/imports/actual.js +0 -80
  71. package/build/__tests__/fixtures-script-files/imports-namespaced/actual.d.ts +0 -10
  72. package/build/__tests__/fixtures-script-files/imports-namespaced/actual.js +0 -63
  73. package/build/__tests__/fixtures-script-files/include-wire-unused-import-prop/actual.d.ts +0 -7
  74. package/build/__tests__/fixtures-script-files/include-wire-unused-import-prop/actual.js +0 -34
  75. package/build/__tests__/fixtures-script-files/inheritance-imports-default/actual.d.ts +0 -3
  76. package/build/__tests__/fixtures-script-files/inheritance-imports-default/actual.js +0 -10
  77. package/build/__tests__/fixtures-script-files/inheritance-imports-local/actual.d.ts +0 -9
  78. package/build/__tests__/fixtures-script-files/inheritance-imports-local/actual.js +0 -24
  79. package/build/__tests__/fixtures-script-files/inheritance-imports-named/actual.d.ts +0 -4
  80. package/build/__tests__/fixtures-script-files/inheritance-imports-named/actual.js +0 -17
  81. package/build/__tests__/fixtures-script-files/inheritance-parent-unresolved/actual.d.ts +0 -4
  82. package/build/__tests__/fixtures-script-files/inheritance-parent-unresolved/actual.js +0 -17
  83. package/build/__tests__/fixtures-script-files/unsupported-wire-from-supported-namespace/actual.d.ts +0 -6
  84. package/build/__tests__/fixtures-script-files/unsupported-wire-from-supported-namespace/actual.js +0 -19
  85. package/build/__tests__/fixtures-script-files/wire-basic/actual.d.ts +0 -8
  86. package/build/__tests__/fixtures-script-files/wire-basic/actual.js +0 -30
  87. package/build/__tests__/fixtures-script-files/wire-functions/actual.d.ts +0 -13
  88. package/build/__tests__/fixtures-script-files/wire-functions/actual.js +0 -46
  89. package/build/__tests__/fixtures-script-files/wire-imports/actual.d.ts +0 -11
  90. package/build/__tests__/fixtures-script-files/wire-imports/actual.js +0 -63
  91. package/build/__tests__/fixtures-source-code/badImportRef.d.ts +0 -4
  92. package/build/__tests__/fixtures-source-code/badImportRef.js +0 -31
  93. package/build/__tests__/fixtures-source-code/generalMockSourceCode.d.ts +0 -8
  94. package/build/__tests__/fixtures-source-code/generalMockSourceCode.js +0 -127
  95. package/build/__tests__/fixtures-source-code/gqlMockSource.d.ts +0 -3
  96. package/build/__tests__/fixtures-source-code/gqlMockSource.js +0 -95
  97. package/build/__tests__/functionAstGeneration.spec.d.ts +0 -2
  98. package/build/__tests__/functionAstGeneration.spec.js +0 -727
  99. package/build/__tests__/general-komaci-docs/assorted-template-strings/source.d.ts +0 -10
  100. package/build/__tests__/general-komaci-docs/assorted-template-strings/source.js +0 -41
  101. package/build/__tests__/general-komaci-docs/getters-and-compositions-collisions/source.d.ts +0 -7
  102. package/build/__tests__/general-komaci-docs/getters-and-compositions-collisions/source.js +0 -31
  103. package/build/__tests__/general-komaci-docs/import-types/source.d.ts +0 -18
  104. package/build/__tests__/general-komaci-docs/import-types/source.js +0 -108
  105. package/build/__tests__/general-komaci-docs/import-types/validationStuff.d.ts +0 -18
  106. package/build/__tests__/general-komaci-docs/import-types/validationStuff.js +0 -63
  107. package/build/__tests__/general-komaci-docs/template-component/source.d.ts +0 -8
  108. package/build/__tests__/general-komaci-docs/template-component/source.js +0 -34
  109. package/build/__tests__/generated-module/compile-graphql-with-scoped-import.spec.d.ts +0 -2
  110. package/build/__tests__/generated-module/compile-graphql-with-scoped-import.spec.js +0 -20
  111. package/build/__tests__/generated-module/lightning/component/component.d.ts +0 -18
  112. package/build/__tests__/generated-module/lightning/component/component.js +0 -168
  113. package/build/__tests__/genericAstGeneration.spec.d.ts +0 -2
  114. package/build/__tests__/genericAstGeneration.spec.js +0 -1052
  115. package/build/__tests__/index.spec.d.ts +0 -2
  116. package/build/__tests__/index.spec.js +0 -393
  117. package/build/__tests__/komaci-ast-unit.spec.d.ts +0 -2
  118. package/build/__tests__/komaci-ast-unit.spec.js +0 -422
  119. package/build/__tests__/komaci-bundle-module.fixtures.spec.d.ts +0 -2
  120. package/build/__tests__/komaci-bundle-module.fixtures.spec.js +0 -76
  121. package/build/__tests__/komaci-bundle-multiple-templates-module.fixtures.spec.d.ts +0 -2
  122. package/build/__tests__/komaci-bundle-multiple-templates-module.fixtures.spec.js +0 -117
  123. package/build/__tests__/komaci-gql.fixtures.spec.d.ts +0 -2
  124. package/build/__tests__/komaci-gql.fixtures.spec.js +0 -51
  125. package/build/__tests__/komaci-script-module.fixtures.spec.d.ts +0 -2
  126. package/build/__tests__/komaci-script-module.fixtures.spec.js +0 -70
  127. package/build/__tests__/komaci-template-module.fixtures.spec.d.ts +0 -2
  128. package/build/__tests__/komaci-template-module.fixtures.spec.js +0 -57
  129. package/build/__tests__/readAndParseBundle.d.ts +0 -22
  130. package/build/__tests__/readAndParseBundle.js +0 -80
@@ -1,727 +0,0 @@
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
- var __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
27
- };
28
- Object.defineProperty(exports, "__esModule", { value: true });
29
- /* eslint-disable @typescript-eslint/no-non-null-assertion */
30
- const path_1 = require("path");
31
- const fs_1 = require("fs");
32
- const common_shared_1 = require("@komaci/common-shared");
33
- const types_1 = require("@babel/types");
34
- const functionAstGeneration_1 = require("../functionAstGeneration");
35
- const generator_1 = __importDefault(require("@babel/generator"));
36
- const badImportRef_1 = require("./fixtures-source-code/badImportRef");
37
- const t = __importStar(require("@babel/types"));
38
- const generalMockSourceCode_1 = require("./fixtures-source-code/generalMockSourceCode");
39
- const gqlMockSource_1 = require("./fixtures-source-code/gqlMockSource");
40
- describe('hoistLocalFunction', () => {
41
- const baseFilesPath = (0, path_1.join)(__dirname, 'general-komaci-docs/assorted-template-strings');
42
- const src = (0, fs_1.readFileSync)((0, path_1.join)(baseFilesPath, 'source.js'), {
43
- encoding: 'utf-8',
44
- });
45
- const ast = (0, common_shared_1.generateAstFromSrcCode)(src);
46
- const { templateStrings } = (0, common_shared_1.getPropertyMetadataFromAst)(ast);
47
- const firstTemplateStringFunc = {
48
- generatedName: 't0',
49
- type: common_shared_1.FunctionTypes.TEMPLATE_STRING,
50
- componentAstNode: templateStrings[0],
51
- requiredProperties: [],
52
- };
53
- const secondTemplateStringFunc = {
54
- generatedName: 't1',
55
- type: common_shared_1.FunctionTypes.TEMPLATE_STRING,
56
- componentAstNode: templateStrings[1],
57
- requiredProperties: [],
58
- };
59
- const imports = new Map();
60
- imports.set('gql', {
61
- generatorAlias: 'i1',
62
- resourceName: 'lightning/graphql',
63
- isFromInternalNamespace: true,
64
- isFromSupportedLibrary: true,
65
- name: 'gql',
66
- komaciDocImportRef: '1/names/0',
67
- usedInPriming: true,
68
- staticallyAnalyzable: false,
69
- });
70
- imports.set('sneaky', {
71
- generatorAlias: 'i2',
72
- resourceName: 'snoop',
73
- isFromInternalNamespace: true,
74
- isFromSupportedLibrary: true,
75
- name: 'sneaky',
76
- komaciDocImportRef: '2/names/0',
77
- usedInPriming: true,
78
- staticallyAnalyzable: false,
79
- });
80
- const moduleMetadata = (0, common_shared_1.initModuleMetadataObject)();
81
- moduleMetadata.importsByName = imports;
82
- const hoistedFirstFunc = (0, functionAstGeneration_1.hoistLocalFunction)(firstTemplateStringFunc, moduleMetadata);
83
- const hoistedSecondFunc = (0, functionAstGeneration_1.hoistLocalFunction)(secondTemplateStringFunc, moduleMetadata);
84
- it('can compose a template string for a public api prop', () => {
85
- expect(hoistedFirstFunc).not.toBeUndefined();
86
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
87
- expect(hoistedFirstFunc.type).toBe('FunctionDeclaration');
88
- expect(hoistedFirstFunc.id.name).toBe('t0');
89
- expect(hoistedFirstFunc.body.body).toHaveLength(1);
90
- expect(hoistedFirstFunc.body.body[0].type).toBe('ReturnStatement');
91
- expect(hoistedFirstFunc.body.body[0]
92
- .argument?.type).toBe('TemplateLiteral');
93
- expect(hoistedFirstFunc.body
94
- .body[0].argument.expressions).toHaveLength(2);
95
- expect(hoistedFirstFunc.body
96
- .body[0].argument.expressions[0].type).toBe('MemberExpression');
97
- expect(hoistedFirstFunc.body
98
- .body[0].argument.expressions[0].object.name).toBe('props');
99
- expect(hoistedFirstFunc.body
100
- .body[0].argument.expressions[0].property.name).toBe('basicInit');
101
- expect(hoistedFirstFunc.body
102
- .body[0].argument.expressions[1].type).toBe('Identifier');
103
- expect(hoistedFirstFunc.body
104
- .body[0].argument.expressions[1].name).toBe('i2');
105
- });
106
- it('can compose a template string for an internal prop', () => {
107
- expect(hoistedSecondFunc).not.toBeUndefined();
108
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
109
- expect(hoistedSecondFunc.type).toBe('FunctionDeclaration');
110
- expect(hoistedSecondFunc.id.name).toBe('t1');
111
- expect(hoistedSecondFunc.body.body).toHaveLength(1);
112
- expect(hoistedSecondFunc.body.body[0].type).toBe('ReturnStatement');
113
- expect(hoistedSecondFunc.body.body[0]
114
- .argument?.type).toBe('TaggedTemplateExpression');
115
- expect(hoistedSecondFunc.body
116
- .body[0].argument.quasi.expressions).toHaveLength(1);
117
- expect(hoistedSecondFunc.body
118
- .body[0].argument.tag.name).toBe('i1');
119
- });
120
- });
121
- describe('hoistlocalfunction for render function', () => {
122
- const templateOneImportMetaData = {
123
- name: 'i0',
124
- generatorAlias: 'templateOne',
125
- resourceName: './templateOne.html',
126
- komaciDocImportRef: 'nil',
127
- isFromInternalNamespace: true,
128
- isFromSupportedLibrary: true,
129
- usedInPriming: false,
130
- staticallyAnalyzable: false,
131
- templateKomaciDoc: {},
132
- adgReference: 'adg1',
133
- };
134
- const templateTwoImportMetaData = {
135
- name: 'i1',
136
- generatorAlias: 'templateTwo',
137
- resourceName: './templateTwo.html',
138
- komaciDocImportRef: 'nil',
139
- isFromInternalNamespace: true,
140
- isFromSupportedLibrary: true,
141
- usedInPriming: false,
142
- staticallyAnalyzable: false,
143
- templateKomaciDoc: {},
144
- adgReference: 'adg2',
145
- };
146
- const defaultTemplateImportMetadata = {
147
- name: 'i0',
148
- generatorAlias: 'defaultTemplate',
149
- resourceName: './komaciAction.html',
150
- komaciDocImportRef: 'nil',
151
- isFromInternalNamespace: true,
152
- isFromSupportedLibrary: true,
153
- usedInPriming: false,
154
- staticallyAnalyzable: false,
155
- templateKomaciDoc: {},
156
- adgReference: 'adg0',
157
- };
158
- it('can hoist a validated render function, conditional return', () => {
159
- const moduleMetadata = (0, common_shared_1.initModuleMetadataObject)();
160
- moduleMetadata.importsByName.set('templateOne', templateOneImportMetaData);
161
- moduleMetadata.importsByName.set('templateTwo', templateTwoImportMetaData);
162
- const renderFunctionExampleAst = (0, common_shared_1.generateAstFromSrcCode)(generalMockSourceCode_1.mockSrcCode_Pass_Valid_Render_Conditional);
163
- const { renderFunction } = (0, common_shared_1.getPropertyMetadataFromAst)(renderFunctionExampleAst);
164
- const renderFunctionMetadata = {
165
- type: common_shared_1.FunctionTypes.RENDER_FUNCTION,
166
- componentAstNode: renderFunction,
167
- requiredProperties: ['templateOne'],
168
- generatedName: `hoistedRenderFunction`,
169
- };
170
- const hoistedRenderFunction = (0, functionAstGeneration_1.hoistLocalFunction)(renderFunctionMetadata, moduleMetadata);
171
- expect(hoistedRenderFunction).not.toBeUndefined();
172
- const hoistedBodyStatements = hoistedRenderFunction?.body.body;
173
- expect(hoistedBodyStatements).not.toBeUndefined();
174
- expect(hoistedBodyStatements).toHaveLength(1);
175
- const returnStmt = hoistedBodyStatements != undefined ? hoistedBodyStatements[0] : undefined;
176
- expect(returnStmt).not.toBeUndefined();
177
- expect(returnStmt?.type).toBe('ReturnStatement');
178
- const argument = returnStmt.argument;
179
- expect(argument?.type).toBe('ConditionalExpression');
180
- const consequent = argument.consequent;
181
- const alternate = argument.alternate;
182
- expect(consequent.name).toBe(templateOneImportMetaData.adgReference);
183
- expect(alternate.name).toBe(templateTwoImportMetaData.adgReference);
184
- });
185
- it('can hoist a validated render when returning default template', () => {
186
- const moduleMetadata = (0, common_shared_1.initModuleMetadataObject)();
187
- moduleMetadata.importsByName.set('defaultTemplate', defaultTemplateImportMetadata);
188
- const renderFunctionExampleAst = (0, common_shared_1.generateAstFromSrcCode)(generalMockSourceCode_1.mockSrcCode_Pass_Valid_Render_DefaultTemplate);
189
- const { renderFunction } = (0, common_shared_1.getPropertyMetadataFromAst)(renderFunctionExampleAst);
190
- const renderFunctionMetadata = {
191
- type: common_shared_1.FunctionTypes.RENDER_FUNCTION,
192
- componentAstNode: renderFunction,
193
- requiredProperties: ['templateOne'],
194
- generatedName: `hoistedRenderFunction`,
195
- };
196
- const hoistedRenderFunction = (0, functionAstGeneration_1.hoistLocalFunction)(renderFunctionMetadata, moduleMetadata);
197
- expect(hoistedRenderFunction).not.toBeUndefined();
198
- const hoistedBodyStatements = hoistedRenderFunction?.body.body;
199
- expect(hoistedBodyStatements).not.toBeUndefined();
200
- expect(hoistedBodyStatements).toHaveLength(1);
201
- const returnStmt = hoistedBodyStatements != undefined ? hoistedBodyStatements[0] : undefined;
202
- expect(returnStmt).not.toBeUndefined();
203
- expect(returnStmt?.type).toBe('ReturnStatement');
204
- const argument = returnStmt.argument;
205
- expect(argument?.type).toBe('Identifier');
206
- expect(argument.name).toBe(defaultTemplateImportMetadata.adgReference);
207
- });
208
- it('can hoist a validated render function with multiple valid returns', () => {
209
- const moduleMetadata = (0, common_shared_1.initModuleMetadataObject)();
210
- moduleMetadata.importsByName.set('templateOne', templateOneImportMetaData);
211
- moduleMetadata.importsByName.set('defaultTemplate', defaultTemplateImportMetadata);
212
- const renderFunctionExampleAst = (0, common_shared_1.generateAstFromSrcCode)(generalMockSourceCode_1.mockSrcCode_Pass_Valid_Render_MultipleReturns);
213
- const { renderFunction } = (0, common_shared_1.getPropertyMetadataFromAst)(renderFunctionExampleAst);
214
- const renderFunctionMetadata = {
215
- type: common_shared_1.FunctionTypes.RENDER_FUNCTION,
216
- componentAstNode: renderFunction,
217
- requiredProperties: ['templateOne'],
218
- generatedName: `hoistedRenderFunction`,
219
- };
220
- const hoistedRenderFunction = (0, functionAstGeneration_1.hoistLocalFunction)(renderFunctionMetadata, moduleMetadata);
221
- expect(hoistedRenderFunction).not.toBeUndefined();
222
- const hoistedBodyStatements = hoistedRenderFunction?.body.body;
223
- expect(hoistedBodyStatements).not.toBeUndefined();
224
- expect(hoistedBodyStatements).not.toBeUndefined();
225
- expect(hoistedBodyStatements).toHaveLength(2);
226
- const ifStmt = hoistedBodyStatements != undefined ? hoistedBodyStatements[0] : undefined;
227
- expect(ifStmt).not.toBeUndefined();
228
- expect(ifStmt?.type).toBe('IfStatement');
229
- const ifBody = ifStmt.consequent.body;
230
- expect(ifBody).toHaveLength(1);
231
- const ifReturnStmt = ifBody[0];
232
- expect(ifReturnStmt).not.toBeUndefined();
233
- expect(ifReturnStmt.argument.name).toBe(templateOneImportMetaData.adgReference);
234
- const returnStmt = hoistedBodyStatements != undefined ? hoistedBodyStatements[1] : undefined;
235
- expect(returnStmt).not.toBeUndefined();
236
- expect(returnStmt?.type).toBe('ReturnStatement');
237
- const argument = returnStmt.argument;
238
- expect(argument?.type).toBe('Identifier');
239
- expect(argument.name).toBe(defaultTemplateImportMetadata.adgReference);
240
- });
241
- });
242
- describe('sanitizeFunction', () => {
243
- const ast = (0, common_shared_1.generateAstFromSrcCode)(badImportRef_1.sourceClass);
244
- const { getters } = (0, common_shared_1.getPropertyMetadataFromAst)(ast);
245
- const imports = new Map();
246
- imports.set('test', {
247
- name: 'test',
248
- resourceName: 'force/shared',
249
- staticallyAnalyzable: false,
250
- usedInPriming: true,
251
- isFromInternalNamespace: true,
252
- isFromSupportedLibrary: true,
253
- generatorAlias: 'i0',
254
- komaciDocImportRef: '0/names/0',
255
- });
256
- imports.set('bad', {
257
- name: 'test',
258
- resourceName: 'invalid/import',
259
- isFromInternalNamespace: true,
260
- isFromSupportedLibrary: false,
261
- staticallyAnalyzable: false,
262
- usedInPriming: true,
263
- generatorAlias: 'i1',
264
- komaciDocImportRef: '1/names/0',
265
- });
266
- it('should be able to clean up and hoist a function with valid import references', () => {
267
- (0, functionAstGeneration_1.sanitizeFunction)(getters[0], imports, new Map());
268
- const hoisted = (0, types_1.functionDeclaration)((0, types_1.identifier)('g0'), [(0, types_1.identifier)('props')], // make 'props' an input parameter to the hoisted getter
269
- getters[0].node.body);
270
- const generatedFunction = (0, generator_1.default)((0, types_1.file)((0, types_1.program)([hoisted])));
271
- expect(generatedFunction.code).toBe(badImportRef_1.expectedGoodHoist);
272
- });
273
- it('should be able to hoist a function without breaking optional object props', () => {
274
- (0, functionAstGeneration_1.sanitizeFunction)(getters[2], imports, new Map());
275
- const hoisted = (0, types_1.functionDeclaration)((0, types_1.identifier)('g1'), [], // make 'props' an input parameter to the hoisted getter
276
- getters[2].node.body);
277
- const generatedFunction = (0, generator_1.default)((0, types_1.file)((0, types_1.program)([hoisted])));
278
- expect(generatedFunction.code).toMatchInlineSnapshot(`
279
- "function g1() {
280
- const thing = {
281
- test123: {
282
- test: 'abc'
283
- }
284
- }; //should not be altered by the import existing
285
-
286
- return thing?.test123?.test; //should not be altered by the import existing
287
- }"
288
- `);
289
- });
290
- //TODO(W-14802236): g2 should return test, not i0
291
- it('should be able to hoist a function with local-only variables', () => {
292
- (0, functionAstGeneration_1.sanitizeFunction)(getters[3], imports, new Map());
293
- const hoisted = (0, types_1.functionDeclaration)((0, types_1.identifier)('g2'), [], // make 'props' an input parameter to the hoisted getter
294
- getters[3].node.body);
295
- const generatedFunction = (0, generator_1.default)((0, types_1.file)((0, types_1.program)([hoisted])));
296
- expect(generatedFunction.code).toMatchInlineSnapshot(`
297
- "function g2() {
298
- const test = \\"hi\\";
299
- return i0;
300
- }"
301
- `);
302
- });
303
- it('should throw an error if we try to reference a bad input', () => {
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
- });
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
- expect(generatedFunction.code).toContain('i0! && props.isVisible');
332
- expect(generatedFunction.code).toMatchInlineSnapshot(`
333
- "function g0(props) {
334
- return i0! && props.isVisible;
335
- }"
336
- `);
337
- });
338
- });
339
- describe('adgToExpression', () => {
340
- it('returns valid adg function from komaci doc', () => {
341
- const komaciDoc = {
342
- adgs: [
343
- {
344
- properties: {
345
- getter0: {
346
- isPublic: false,
347
- input: { type: 'ImportReference', value: '0/names/0' },
348
- },
349
- prop1: {
350
- isPublic: true,
351
- initial: {
352
- type: 'ImportReference',
353
- value: '0/names/0',
354
- namespacedMember: 'p1',
355
- },
356
- },
357
- prop2: {
358
- isPublic: true,
359
- initial: {
360
- type: 'ImportReference',
361
- value: '1/names/0',
362
- namespacedMember: 'p2',
363
- },
364
- },
365
- record1: {
366
- isPublic: false,
367
- input: { type: 'FunctionReference', value: 0 },
368
- },
369
- record2: {
370
- isPublic: false,
371
- input: { type: 'FunctionReference', value: 1 },
372
- },
373
- record3: {
374
- isPublic: false,
375
- input: { type: 'FunctionReference', value: 2 },
376
- },
377
- },
378
- functions: [
379
- {
380
- type: 'WireFunction',
381
- reference: { type: 'ImportReference', value: '2/names/0' },
382
- input: [
383
- {
384
- type: 'ObjectValue',
385
- value: {
386
- recordId: {
387
- type: 'PropertyReference',
388
- value: 'prop1',
389
- },
390
- },
391
- },
392
- ],
393
- location: {
394
- startLine: 19,
395
- startColumn: 5,
396
- endLine: 19,
397
- endColumn: 45,
398
- },
399
- },
400
- {
401
- type: 'WireFunction',
402
- reference: { type: 'ImportReference', value: '2/names/0' },
403
- input: [
404
- {
405
- type: 'ObjectValue',
406
- value: {
407
- recordId: {
408
- type: 'PropertyReference',
409
- value: 'getter0',
410
- },
411
- },
412
- },
413
- ],
414
- location: {
415
- startLine: 23,
416
- startColumn: 5,
417
- endLine: 23,
418
- endColumn: 47,
419
- },
420
- },
421
- {
422
- type: 'WireFunction',
423
- reference: { type: 'ImportReference', value: '2/names/0' },
424
- input: [
425
- {
426
- type: 'ObjectValue',
427
- value: {
428
- recordId: {
429
- type: 'PropertyReference',
430
- value: 'prop2',
431
- },
432
- },
433
- },
434
- ],
435
- location: {
436
- startLine: 27,
437
- startColumn: 5,
438
- endLine: 27,
439
- endColumn: 45,
440
- },
441
- },
442
- ],
443
- },
444
- ],
445
- imports: [
446
- { resourceName: 'force/shared', names: ['*'] },
447
- { resourceName: 'laf/transformWire', names: ['*'] },
448
- { resourceName: 'lightning/uiRecordApi', names: ['getRecord'] },
449
- ],
450
- exports: { default: { type: 'AdgReference', value: 0 } },
451
- };
452
- const moduleMetadata = (0, common_shared_1.initModuleMetadataObject)();
453
- (0, common_shared_1.initializeImportMetdataFromKomaciDocument)(komaciDoc, moduleMetadata);
454
- (0, common_shared_1.initalizeAdgMetadata)(0, komaciDoc, moduleMetadata, false, false);
455
- const adgMetadata = moduleMetadata.adgs.get(0);
456
- const result = (0, functionAstGeneration_1.adgToExpression)(adgMetadata, moduleMetadata);
457
- expect(result).not.toBeUndefined();
458
- expect(result.arguments).toHaveLength(5);
459
- expect(result.arguments[0].type).toBe('Identifier');
460
- expect(result.arguments[0].name).toBe('undefined');
461
- expect(result.arguments[1].type).toBe('ObjectExpression');
462
- expect(result.arguments[2].type).toBe('ArrayExpression');
463
- expect(result.arguments[2].elements).toHaveLength(3);
464
- expect(result.arguments[3].type).toBe('Identifier');
465
- expect(result.arguments[3].name).toBe('comp1');
466
- expect(result.arguments[4].type).toBe('ArrayExpression');
467
- });
468
- it('returns valid adg function from komaci doc with local parent', () => {
469
- const komaciDoc = {
470
- adgs: [
471
- {
472
- properties: {
473
- parentProp: {
474
- isPublic: true,
475
- },
476
- },
477
- },
478
- {
479
- parentClass: {
480
- type: 'AdgReference',
481
- value: 0,
482
- },
483
- properties: {
484
- testProp: {
485
- isPublic: false,
486
- input: {
487
- type: 'FunctionReference',
488
- value: 0,
489
- },
490
- },
491
- },
492
- functions: [
493
- {
494
- type: 'WireFunction',
495
- reference: {
496
- type: 'ImportReference',
497
- value: '0/names/0',
498
- },
499
- input: [
500
- {
501
- type: 'ObjectValue',
502
- value: {
503
- id: {
504
- type: 'PropertyReference',
505
- value: 'parentProp',
506
- },
507
- },
508
- },
509
- ],
510
- },
511
- ],
512
- },
513
- ],
514
- imports: [
515
- {
516
- resourceName: 'lightning/uiRecordApi',
517
- names: ['getRecord'],
518
- },
519
- ],
520
- exports: {
521
- Foo: {
522
- type: 'AdgReference',
523
- value: 0,
524
- },
525
- default: {
526
- type: 'AdgReference',
527
- value: 1,
528
- },
529
- },
530
- };
531
- const moduleMetadata = (0, common_shared_1.initModuleMetadataObject)();
532
- (0, common_shared_1.initializeImportMetdataFromKomaciDocument)(komaciDoc, moduleMetadata);
533
- (0, common_shared_1.initalizeAdgMetadata)(1, komaciDoc, moduleMetadata, false, false);
534
- const adgMetadata = moduleMetadata.adgs.get(1);
535
- const result = (0, functionAstGeneration_1.adgToExpression)(adgMetadata, moduleMetadata);
536
- expect(result).not.toBeUndefined();
537
- expect(result).not.toBeUndefined();
538
- expect(result.arguments).toHaveLength(5);
539
- expect(result.arguments[0].type).toBe('CallExpression');
540
- expect(result.arguments[0].callee.name).toBe('adg0');
541
- expect(result.arguments[1].type).toBe('ObjectExpression');
542
- expect(result.arguments[2].type).toBe('ArrayExpression');
543
- expect(result.arguments[2].elements).toHaveLength(1);
544
- expect(result.arguments[3].type).toBe('Identifier');
545
- expect(result.arguments[3].name).toBe('comp1');
546
- expect(result.arguments[4].type).toBe('ArrayExpression');
547
- });
548
- it('returns valid adg function from komaci doc with import parent', () => {
549
- const komaciDoc = {
550
- adgs: [
551
- {
552
- properties: {
553
- getterProp: {
554
- isPublic: false,
555
- input: {
556
- type: 'ImportReference',
557
- value: '0/names/0',
558
- },
559
- },
560
- },
561
- parentClass: {
562
- type: 'ImportReference',
563
- value: '1/names/0',
564
- },
565
- },
566
- ],
567
- imports: [
568
- {
569
- resourceName: 'force/shared',
570
- names: ['default'],
571
- },
572
- {
573
- resourceName: '@salesforce/komaci/force__shared__shared.js',
574
- names: ['default'],
575
- },
576
- ],
577
- exports: {
578
- default: {
579
- type: 'AdgReference',
580
- value: 0,
581
- },
582
- },
583
- };
584
- const moduleMetadata = (0, common_shared_1.initModuleMetadataObject)();
585
- (0, common_shared_1.initializeImportMetdataFromKomaciDocument)(komaciDoc, moduleMetadata);
586
- (0, common_shared_1.initalizeAdgMetadata)(0, komaciDoc, moduleMetadata, false, false);
587
- const adgMetadata = moduleMetadata.adgs.get(0);
588
- const result = (0, functionAstGeneration_1.adgToExpression)(adgMetadata, moduleMetadata);
589
- expect(result).not.toBeUndefined();
590
- expect(result.arguments).toHaveLength(5);
591
- expect(result.arguments[0].type).toBe('Identifier');
592
- expect(result.arguments[0].name).toBe('i1');
593
- expect(result.arguments[1].type).toBe('ObjectExpression');
594
- expect(result.arguments[2].type).toBe('ArrayExpression');
595
- expect(result.arguments[2].elements).toHaveLength(0);
596
- expect(result.arguments[3].type).toBe('Identifier');
597
- expect(result.arguments[3].name).toBe('comp1');
598
- expect(result.arguments[4].type).toBe('ArrayExpression');
599
- });
600
- });
601
- describe('produceErrorAdgFunction', () => {
602
- it('should produce a resolvable module with an adg with only one node that shows what the error was', () => {
603
- const expected = `import registerAdgFunction from "komaci/registerAdgFunction";
604
-
605
- function adg0(fct, ctx) {
606
- const {
607
- adg
608
- } = fct;
609
- return adg(undefined, {}, [{
610
- t: "ErrorFunction",
611
- c: {
612
- "error": "something bad happened"
613
- }
614
- }], (fct, ctx) => {
615
- return [];
616
- }, []);
617
- }
618
-
619
- export default registerAdgFunction(adg0);`;
620
- const testError = new Error('something bad happened');
621
- const res = (0, functionAstGeneration_1.produceErrorAdgFunction)((0, common_shared_1.initModuleMetadataObject)(), testError);
622
- expect((0, generator_1.default)((0, types_1.file)(res)).code).toBe(expected);
623
- });
624
- });
625
- describe('composeStaticMetadataAssignmentExpression', () => {
626
- it('returns proper expression statement', () => {
627
- const metaVarDeclarator = t.variableDeclarator(t.identifier(`Adg0Meta`), t.objectExpression([]));
628
- const staticMetadataObject = t.variableDeclaration('const', [metaVarDeclarator]);
629
- const expr = (0, functionAstGeneration_1.composeStaticMetadataAssignmentExpression)('adg0', staticMetadataObject).expression;
630
- const left = expr.left;
631
- expect(left.object.name).toBe('adg0');
632
- expect(left.property.name).toBe('meta');
633
- const right = expr.right;
634
- expect(right.name).toBe('Adg0Meta');
635
- });
636
- });
637
- describe('composeSelfServiceAssignmentExpression', () => {
638
- it('returns proper expression statement', () => {
639
- const expr = (0, functionAstGeneration_1.composeSelfServiceAssignmentExpression)('adg0')
640
- .expression;
641
- const left = expr.left;
642
- expect(left.object.name).toBe('adg0');
643
- expect(left.property.name).toBe('self');
644
- const right = expr.right;
645
- expect(right.value).toBeTruthy();
646
- });
647
- });
648
- describe('sanitizeFunction gql usecases', () => {
649
- const ast = (0, common_shared_1.generateAstFromSrcCode)(gqlMockSource_1.mockGqlQueries);
650
- const { getters, templateStrings } = (0, common_shared_1.getPropertyMetadataFromAst)(ast);
651
- const imports = new Map();
652
- const gqlMetadata = new Map();
653
- //Gql query from getter
654
- const gqlMetadata0 = {
655
- hash: '123456',
656
- hasExpressions: false,
657
- location: {
658
- startLine: 0,
659
- endLine: 0,
660
- startColumn: 0,
661
- endColumn: 0,
662
- start: 1345,
663
- end: 1845,
664
- },
665
- isHoisted: false,
666
- valid: true,
667
- generatedImportAlias: 'gql0',
668
- importPath: 'temp/path',
669
- };
670
- gqlMetadata.set('loc_1354_1845', gqlMetadata0);
671
- //Invalid gql query
672
- const gqlMetadata1 = {
673
- hash: '123456',
674
- hasExpressions: true,
675
- location: {
676
- startLine: 0,
677
- endLine: 0,
678
- startColumn: 0,
679
- endColumn: 0,
680
- start: 826,
681
- end: 1316,
682
- },
683
- isHoisted: false,
684
- valid: false,
685
- generatedImportAlias: 'gql1',
686
- importPath: 'temp/path',
687
- };
688
- gqlMetadata.set('loc_826_1316', gqlMetadata1);
689
- //valid gql query
690
- const gqlMetadata2 = {
691
- hash: '123456',
692
- hasExpressions: false,
693
- location: {
694
- startLine: 0,
695
- endLine: 0,
696
- startColumn: 0,
697
- endColumn: 0,
698
- start: 242,
699
- end: 801,
700
- },
701
- isHoisted: false,
702
- valid: true,
703
- generatedImportAlias: 'gql2',
704
- importPath: 'temp/path',
705
- };
706
- gqlMetadata.set('loc_242_801', gqlMetadata2);
707
- it('should replace getter return with proper import id', () => {
708
- (0, functionAstGeneration_1.sanitizeFunction)(getters[0], imports, gqlMetadata);
709
- const hoisted = (0, types_1.functionDeclaration)((0, types_1.identifier)('g0'), [(0, types_1.identifier)('props')], // make 'props' an input parameter to the hoisted getter
710
- getters[0].node.body);
711
- const generatedFunction = (0, generator_1.default)((0, types_1.file)((0, types_1.program)([hoisted])));
712
- expect(generatedFunction.code.trim).toBe(gqlMockSource_1.expectedGetterWithGql.trim);
713
- });
714
- it('swaps out the gql query with the proper generated import alias', () => {
715
- (0, functionAstGeneration_1.sanitizeFunction)(templateStrings[0], imports, gqlMetadata);
716
- const tmplString = templateStrings[0];
717
- expect(tmplString.node.value?.type).toBe('Identifier');
718
- const id = tmplString.node.value.name;
719
- expect(id).toBe('gql2');
720
- });
721
- it('does not swap out gql query if has expression or is invalid', () => {
722
- (0, functionAstGeneration_1.sanitizeFunction)(templateStrings[1], imports, gqlMetadata);
723
- const tmplString = templateStrings[1];
724
- expect(tmplString.node.value?.type).toBe('TaggedTemplateExpression');
725
- });
726
- });
727
- //# sourceMappingURL=functionAstGeneration.spec.js.map