@komaci/esm-generator 248.1.10 → 252.0.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.
@@ -11,7 +11,7 @@ const compilerConfigs_1 = require("./compilerConfigs");
11
11
  const EXPECTED_SRC_FILENAME = 'expected.src';
12
12
  describe('fixtures', () => {
13
13
  //Adding filter on the resolvable modules we try to compile until the compiler has been updated to handle imported gql queries. Will be removed in W-14269523
14
- const fixtures = (0, glob_1.globSync)(path_1.default.resolve(__dirname, '**/expected.src')).filter((e) => e != `${__dirname}/fixtures-gql/multipleGqlQueries/expected.src`);
14
+ const fixtures = (0, glob_1.globSync)(path_1.default.resolve(__dirname, '**/expected.src')).filter((e) => !e.includes(`/fixtures-gql`));
15
15
  for (const caseEntry of fixtures) {
16
16
  const caseFolder = path_1.default.dirname(caseEntry);
17
17
  const caseName = path_1.default.relative(__dirname, caseFolder);
@@ -1,4 +1,4 @@
1
- export declare const sourceClass = "import test from 'force/shared'; // good import\nimport bad from 'invalid/import';\n\nexport default class Component {\n get testing() {\n return `A string that references ${test}`;\n }\n\n get badProp() {\n return `altho we reference ${test} we also reference ${bad}`;\n }\n}";
1
+ export declare const sourceClass = "import test from 'force/shared'; // good import\nimport bad from 'invalid/import';\n\nexport default class Component {\n get testing() {\n return `A string that references ${test}`;\n }\n\n get badProp() {\n return `altho we reference ${test} we also reference ${bad}`;\n }\n\n get thing() {\n const thing = { test123: { test: 'abc'}} //should not be altered by the import existing\n return thing?.test123?.test; //should not be altered by the import existing\n }\n \n get stringThing() {\n const test = \"hi\";\n return test;\n }\n}";
2
2
  export declare const expectedGoodHoist = "function g0(props) {\n return `A string that references ${i0}`;\n}";
3
3
  export declare const expectedGoodHoistAst: import("@babel/parser").ParseResult<import("@babel/types").File>;
4
4
  //# sourceMappingURL=badImportRef.d.ts.map
@@ -13,6 +13,16 @@ export default class Component {
13
13
  get badProp() {
14
14
  return \`altho we reference \${test} we also reference \${bad}\`;
15
15
  }
16
+
17
+ get thing() {
18
+ const thing = { test123: { test: 'abc'}} //should not be altered by the import existing
19
+ return thing?.test123?.test; //should not be altered by the import existing
20
+ }
21
+
22
+ get stringThing() {
23
+ const test = "hi";
24
+ return test;
25
+ }
16
26
  }`;
17
27
  exports.expectedGoodHoist = `function g0(props) {
18
28
  return \`A string that references \${i0}\`;
@@ -270,6 +270,36 @@ describe('sanitizeFunction', () => {
270
270
  const generatedFunction = (0, generator_1.default)((0, types_1.file)((0, types_1.program)([hoisted])));
271
271
  expect(generatedFunction.code).toBe(badImportRef_1.expectedGoodHoist);
272
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
+ });
273
303
  it('should throw an error if we try to reference a bad input', () => {
274
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`));
275
305
  });
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=compile-graphql-with-scoped-import.spec.d.ts.map
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const path_1 = __importDefault(require("path"));
7
+ const readAndParseBundle_1 = require("../readAndParseBundle");
8
+ describe('test komaci can build a correct module', () => {
9
+ it('can handle an import name conflicting with optional property name', () => {
10
+ //TODO: tweak this test pattern further so that it's even less repetitive while not generating tests.
11
+ const componentPath = path_1.default.join(__dirname, 'lightning', 'component');
12
+ const actualModuleSrc = (0, readAndParseBundle_1.readAndParseBundle)(componentPath, {
13
+ enableKomaci: true,
14
+ type: 'internal',
15
+ enableLuvio: true,
16
+ }).output.modGenOutput;
17
+ expect(actualModuleSrc).toMatchSnapshot();
18
+ });
19
+ });
20
+ //# sourceMappingURL=compile-graphql-with-scoped-import.spec.js.map
@@ -0,0 +1,18 @@
1
+ export default class MultipleGraphQL extends LightningElement {
2
+ recordId: any;
3
+ get woQuery(): any;
4
+ graphqlResult: any;
5
+ get accountIDs(): any;
6
+ get graphqlVariables(): {
7
+ recordId: any;
8
+ };
9
+ get accRelatedRecQuery(): any;
10
+ graphqlAccResult: any;
11
+ get graphqlAccVariables(): {
12
+ accId: any;
13
+ };
14
+ get accountResponseString(): any;
15
+ get accountResponse(): string;
16
+ }
17
+ import { LightningElement } from "lwc";
18
+ //# sourceMappingURL=component.d.ts.map
@@ -0,0 +1,168 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ const lwc_1 = require("lwc");
10
+ const uiGraphQLApi_1 = require("lightning/uiGraphQLApi");
11
+ class MultipleGraphQL extends lwc_1.LightningElement {
12
+ get woQuery() {
13
+ return (0, uiGraphQLApi_1.gql) `
14
+ query showWorkorder($recordId: ID) {
15
+ uiapi {
16
+ query {
17
+ WorkOrder(where: { Id: { eq: $recordId } })
18
+ @category(name: "recordQuery") {
19
+ edges {
20
+ node {
21
+ Id
22
+ Status @category(name: "StringValue") {
23
+ value
24
+ }
25
+ AccountId @category(name: "IDValue") {
26
+ value
27
+ }
28
+ }
29
+ }
30
+ }
31
+ }
32
+ }
33
+ }
34
+ `;
35
+ }
36
+ get accountIDs() {
37
+ return this.graphqlResult?.data?.uiapi.query.WorkOrder.edges[0].node.AccountId
38
+ .value; // Here's the bug
39
+ }
40
+ get graphqlVariables() {
41
+ return {
42
+ recordId: this.recordId,
43
+ };
44
+ }
45
+ //fetching Location and Asset from Account ID
46
+ get accRelatedRecQuery() {
47
+ return (0, uiGraphQLApi_1.gql) `
48
+ query showAccRelRecords($accId: ID) {
49
+ uiapi {
50
+ query {
51
+ Account(where: { Id: { eq: $accId } })
52
+ @category(name: "recordQuery") {
53
+ edges {
54
+ node {
55
+ Locations__r(where: { Active__c: { eq: true } })
56
+ @category(name: "childRelationship") {
57
+ edges {
58
+ node {
59
+ Name @category(name: "StringValue") {
60
+ value
61
+ }
62
+ LocationType
63
+ @category(name: "StringValue") {
64
+ value
65
+ }
66
+ Customer_Site__r
67
+ @category(
68
+ name: "parentRelationship"
69
+ ) {
70
+ Name @category(name: "StringValue") {
71
+ value
72
+ }
73
+ }
74
+ }
75
+ }
76
+ }
77
+ Assets(where: { Active__c: { eq: true } })
78
+ @category(name: "childRelationship") {
79
+ edges {
80
+ node {
81
+ Name @category(name: "StringValue") {
82
+ value
83
+ }
84
+ Linked_Asset_Name__c
85
+ @category(name: "StringValue") {
86
+ value
87
+ }
88
+ LocationId @category(name: "IDValue") {
89
+ value
90
+ }
91
+ Asset_Type__c
92
+ @category(name: "StringValue") {
93
+ value
94
+ }
95
+ Machine_Type__c
96
+ @category(name: "StringValue") {
97
+ value
98
+ }
99
+ Linked_Asset_Serial_Number__c
100
+ @category(name: "StringValue") {
101
+ value
102
+ }
103
+ AccountId @category(name: "IDValue") {
104
+ value
105
+ }
106
+ Account
107
+ @category(
108
+ name: "parentRelationship"
109
+ ) {
110
+ Name @category(name: "StringValue") {
111
+ value
112
+ }
113
+ }
114
+ Location
115
+ @category(
116
+ name: "parentRelationship"
117
+ ) {
118
+ Name @category(name: "StringValue") {
119
+ value
120
+ }
121
+ LocationType
122
+ @category(name: "StringValue") {
123
+ value
124
+ }
125
+ }
126
+ }
127
+ }
128
+ }
129
+ }
130
+ }
131
+ }
132
+ }
133
+ }
134
+ }
135
+ `;
136
+ }
137
+ //AccountID populated through result of other graphql
138
+ get graphqlAccVariables() {
139
+ return {
140
+ accId: this.accountIDs,
141
+ };
142
+ }
143
+ get accountResponseString() {
144
+ return this.graphqlAccResult;
145
+ }
146
+ get accountResponse() {
147
+ return JSON.stringify(this.graphqlAccResult);
148
+ }
149
+ }
150
+ __decorate([
151
+ lwc_1.api
152
+ ], MultipleGraphQL.prototype, "recordId", void 0);
153
+ __decorate([
154
+ (0, lwc_1.wire)(uiGraphQLApi_1.graphql, {
155
+ query: '$woQuery',
156
+ variables: '$graphqlVariables',
157
+ operationName: 'showWorkorder',
158
+ })
159
+ ], MultipleGraphQL.prototype, "graphqlResult", void 0);
160
+ __decorate([
161
+ (0, lwc_1.wire)(uiGraphQLApi_1.graphql, {
162
+ query: '$accRelatedRecQuery',
163
+ variables: '$graphqlAccVariables',
164
+ operationName: 'showAccRelRecords',
165
+ })
166
+ ], MultipleGraphQL.prototype, "graphqlAccResult", void 0);
167
+ exports.default = MultipleGraphQL;
168
+ //# sourceMappingURL=component.js.map
@@ -296,6 +296,7 @@ describe('processWireFunctionType', () => {
296
296
  (0, common_shared_1.composeImportMetadata)('bacth_getRecord', 'lightning/uiRecordApi', true, '2/names/1', moduleMetadata);
297
297
  (0, common_shared_1.composeImportMetadata)('reducer', 'lightning/uiRecordApi', true, '2/names/2', moduleMetadata);
298
298
  (0, common_shared_1.composeImportMetadata)('CurrentPageReference', 'laf/transformWire', true, '3/names/0', moduleMetadata);
299
+ (0, common_shared_1.composeImportMetadata)('getApexInvoker_imperative', 'force/ldsAdaptersApex', true, '4/names/0', moduleMetadata);
299
300
  it('throws an error when a function that isnt a wire is passed in', () => {
300
301
  const throwingFunc = () => (0, genericAstGeneration_1.processWireFunctionType)({
301
302
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -373,6 +374,44 @@ describe('processWireFunctionType', () => {
373
374
  t: "WireFunction",
374
375
  wt: "apex",
375
376
  c: ctx => ({})
377
+ }`);
378
+ });
379
+ it('effectively builds metadata for an apex priming adapter wire', () => {
380
+ const astStatements = (0, genericAstGeneration_1.processWireFunctionType)({
381
+ type: common_shared_1.FunctionTypes.PRIMING_FUNCTION,
382
+ requiredProperties: [],
383
+ importReference: { functionName: 'getApexInvoker_imperative' },
384
+ prevImportReference: '@salesforce/apex/foo.getBar',
385
+ }, moduleMetadata);
386
+ expect(astStatements).not.toBeUndefined();
387
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
388
+ const { code } = (0, generator_1.default)(t.objectExpression(astStatements));
389
+ expect(code).toBe(`{
390
+ f: i6,
391
+ fN: "getApexInvoker_imperative",
392
+ t: "PrimingFunction",
393
+ wt: "apex",
394
+ af: () => i6("", "foo", "getBar", false),
395
+ c: ctx => ({})
396
+ }`);
397
+ });
398
+ it('effectively builds metadata for an apexContinuation priming adapter wire', () => {
399
+ const astStatements = (0, genericAstGeneration_1.processWireFunctionType)({
400
+ type: common_shared_1.FunctionTypes.PRIMING_FUNCTION,
401
+ requiredProperties: [],
402
+ importReference: { functionName: 'getApexInvoker_imperative' },
403
+ prevImportReference: '@salesforce/apexContinuation/foo.getBar',
404
+ }, moduleMetadata);
405
+ expect(astStatements).not.toBeUndefined();
406
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
407
+ const { code } = (0, generator_1.default)(t.objectExpression(astStatements));
408
+ expect(code).toBe(`{
409
+ f: i6,
410
+ fN: "getApexInvoker_imperative",
411
+ t: "PrimingFunction",
412
+ wt: "apex",
413
+ af: () => i6("", "foo", "getBar", true),
414
+ c: ctx => ({})
376
415
  }`);
377
416
  });
378
417
  it('effectively builds metadata for a context wire', () => {
@@ -6,10 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const fs_1 = __importDefault(require("fs"));
7
7
  const glob_1 = require("glob");
8
8
  const path_1 = __importDefault(require("path"));
9
- const index_1 = require("../index");
10
- const fs_2 = require("fs");
11
- const path_2 = require("path");
12
- const metadata_1 = require("@lwc/metadata");
9
+ const readAndParseBundle_1 = require("./readAndParseBundle");
13
10
  const FIXTURES_DIR = path_1.default.join(__dirname, 'fixtures-gql');
14
11
  const EXPECTED_JS_FILENAME = 'expected.src';
15
12
  // eslint-disable-next-line jest/no-disabled-tests
@@ -35,7 +32,7 @@ describe('fixtures', () => {
35
32
  };
36
33
  it(`${caseName}`, () => {
37
34
  const expectedFilePath = expectedSrcFilePath();
38
- const actualModuleSrc = readAndParseBundle(caseEntry, {
35
+ const actualModuleSrc = (0, readAndParseBundle_1.readAndParseBundle)(caseEntry, {
39
36
  enableKomaci: true,
40
37
  type: 'internal',
41
38
  enableLuvio: true,
@@ -51,73 +48,4 @@ describe('fixtures', () => {
51
48
  });
52
49
  }
53
50
  });
54
- /**
55
- * Finds all .js, .mjs, .css, and .html files within the given directory, reads their contents, and combines them into a bundle,
56
- * and returning the array of BundleFile containing the file's fileName and source
57
- * @param path
58
- * @returns An array of BundleFile
59
- */
60
- function readBundle(path) {
61
- path = (0, path_2.resolve)(path);
62
- if ((0, fs_2.existsSync)(path)) {
63
- const contents = (0, fs_2.readdirSync)(path);
64
- const LWC_EXT = ['.js', '.mjs', '.css', '.html'];
65
- const lwcBundleFiles = contents.filter((filename) => {
66
- return LWC_EXT.includes((0, path_2.extname)(filename));
67
- });
68
- return lwcBundleFiles.map((fileName) => ({
69
- fileName,
70
- source: (0, fs_2.readFileSync)((0, path_2.resolve)(path, fileName), 'utf-8').toString(),
71
- }));
72
- }
73
- else {
74
- throw new Error(`path doesn't exist: ${path}`);
75
- }
76
- }
77
- /**
78
- * Takes the directory path of an LWC module bundle and an optional set of config overrides. Returns the ParsedBundle, inlcuding
79
- * the bundle's 1) LWC Metadata and 2) Komaci / Resolvable module.
80
- * @param path
81
- * @param configOverrides
82
- * @returns ParsedBundle that includes the BundleConfig & GeneratorInput inputs, and BundleMetadata and generated module output
83
- */
84
- function readAndParseBundle(path, configOverrides) {
85
- const files = readBundle(path);
86
- const name = (0, path_2.basename)(path);
87
- const namespace = (0, path_2.basename)((0, path_2.dirname)(path));
88
- const bundleConfig = {
89
- namespace,
90
- name,
91
- type: 'internal',
92
- namespaceMapping: {},
93
- files,
94
- enableKomaci: true,
95
- ...configOverrides,
96
- };
97
- const metadata = (0, metadata_1.collectBundleMetadata)(bundleConfig);
98
- // Create input to module generator.
99
- const srcFileMap = files.reduce((map, { fileName, source }) => ({ ...map, [fileName]: source }), {});
100
- const inputFiles = Object.fromEntries(metadata.files
101
- .map(({ fileName, komaciDoc }) => [fileName, komaciDoc])
102
- .filter(([, komaciDoc]) => !!komaciDoc));
103
- //Need to come back and clean this up, will be taken care of in a futire WI
104
- const luvioMetadata = metadata.files.filter((file) => file.fileType == 'js' &&
105
- file.luvioMetadata != undefined &&
106
- file.luvioMetadata.gqlTag.length > 0).map((file) => file.luvioMetadata)[0];
107
- const generatorInput = {
108
- moduleInfo: {
109
- name,
110
- namespace: bundleConfig.namespace,
111
- type: 'bundle',
112
- files: inputFiles,
113
- },
114
- srcFileMap,
115
- luvioMetadata: luvioMetadata,
116
- };
117
- const modGenOutput = (0, index_1.generateKomaciModule)(generatorInput);
118
- return {
119
- input: { bundleConfig, generatorInput },
120
- output: { modGenOutput, metadata },
121
- };
122
- }
123
51
  //# sourceMappingURL=komaci-gql.fixtures.spec.js.map
@@ -0,0 +1,22 @@
1
+ import { BundleConfig } from '@lwc/metadata';
2
+ declare type BundleFile = {
3
+ fileName: string;
4
+ source: string;
5
+ };
6
+ /**
7
+ * Finds all .js, .mjs, .css, and .html files within the given directory, reads their contents, and combines them into a bundle,
8
+ * and returning the array of BundleFile containing the file's fileName and source
9
+ * @param path
10
+ * @returns An array of BundleFile
11
+ */
12
+ export declare function readBundle(path: string): BundleFile[];
13
+ /**
14
+ * Takes the directory path of an LWC module bundle and an optional set of config overrides. Returns the ParsedBundle, inlcuding
15
+ * the bundle's 1) LWC Metadata and 2) Komaci / Resolvable module.
16
+ * @param path
17
+ * @param configOverrides
18
+ * @returns ParsedBundle that includes the BundleConfig & GeneratorInput inputs, and BundleMetadata and generated module output
19
+ */
20
+ export declare function readAndParseBundle(path: string, configOverrides: Partial<BundleConfig>): any;
21
+ export {};
22
+ //# sourceMappingURL=readAndParseBundle.d.ts.map
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.readAndParseBundle = exports.readBundle = void 0;
4
+ const index_1 = require("../index");
5
+ const fs_1 = require("fs");
6
+ const path_1 = require("path");
7
+ const metadata_1 = require("@lwc/metadata");
8
+ /**
9
+ * Finds all .js, .mjs, .css, and .html files within the given directory, reads their contents, and combines them into a bundle,
10
+ * and returning the array of BundleFile containing the file's fileName and source
11
+ * @param path
12
+ * @returns An array of BundleFile
13
+ */
14
+ function readBundle(path) {
15
+ path = (0, path_1.resolve)(path);
16
+ if ((0, fs_1.existsSync)(path)) {
17
+ const contents = (0, fs_1.readdirSync)(path);
18
+ const LWC_EXT = ['.js', '.mjs', '.css', '.html'];
19
+ const lwcBundleFiles = contents.filter((filename) => {
20
+ return LWC_EXT.includes((0, path_1.extname)(filename));
21
+ });
22
+ return lwcBundleFiles.map((fileName) => ({
23
+ fileName,
24
+ source: (0, fs_1.readFileSync)((0, path_1.resolve)(path, fileName), 'utf-8').toString(),
25
+ }));
26
+ }
27
+ else {
28
+ throw new Error(`path doesn't exist: ${path}`);
29
+ }
30
+ }
31
+ exports.readBundle = readBundle;
32
+ /**
33
+ * Takes the directory path of an LWC module bundle and an optional set of config overrides. Returns the ParsedBundle, inlcuding
34
+ * the bundle's 1) LWC Metadata and 2) Komaci / Resolvable module.
35
+ * @param path
36
+ * @param configOverrides
37
+ * @returns ParsedBundle that includes the BundleConfig & GeneratorInput inputs, and BundleMetadata and generated module output
38
+ */
39
+ function readAndParseBundle(path, configOverrides) {
40
+ const files = readBundle(path);
41
+ const name = (0, path_1.basename)(path);
42
+ const namespace = (0, path_1.basename)((0, path_1.dirname)(path));
43
+ const bundleConfig = {
44
+ namespace,
45
+ name,
46
+ type: 'internal',
47
+ namespaceMapping: {},
48
+ files,
49
+ enableKomaci: true,
50
+ ...configOverrides,
51
+ };
52
+ const metadata = (0, metadata_1.collectBundleMetadata)(bundleConfig);
53
+ // Create input to module generator.
54
+ const srcFileMap = files.reduce((map, { fileName, source }) => ({ ...map, [fileName]: source }), {});
55
+ const inputFiles = Object.fromEntries(metadata.files
56
+ .map(({ fileName, komaciDoc }) => [fileName, komaciDoc])
57
+ .filter(([, komaciDoc]) => !!komaciDoc));
58
+ //Need to come back and clean this up, will be taken care of in a futire WI
59
+ const luvioMetadata = metadata.files.filter((file) => file.fileType == 'js' &&
60
+ file.luvioMetadata != undefined &&
61
+ file.luvioMetadata.gqlTag.length > 0).map((file) => file.luvioMetadata)[0];
62
+ const generatorInput = {
63
+ moduleInfo: {
64
+ name,
65
+ namespace: bundleConfig.namespace,
66
+ type: 'bundle',
67
+ files: inputFiles,
68
+ },
69
+ srcFileMap,
70
+ luvioMetadata: luvioMetadata,
71
+ };
72
+ const modGenOutput = (0, index_1.generateKomaciModule)(generatorInput);
73
+ return {
74
+ input: { bundleConfig, generatorInput },
75
+ output: { modGenOutput, metadata },
76
+ };
77
+ }
78
+ exports.readAndParseBundle = readAndParseBundle;
79
+ //# sourceMappingURL=readAndParseBundle.js.map
@@ -69,9 +69,15 @@ exports.hoistLocalFunction = hoistLocalFunction;
69
69
  function sanitizeFunction(nodePath, importMetadata, gqlMetadataMap) {
70
70
  const Visitors = {
71
71
  Identifier(path) {
72
- if ((path.parent.type === 'MemberExpression' &&
72
+ if (((path.parent.type === 'MemberExpression' ||
73
+ path.parent.type === 'OptionalMemberExpression') &&
73
74
  path.parent.property === path.node) ||
74
- path.parent.type === 'Decorator') {
75
+ path.parent.type === 'Decorator' ||
76
+ path.parent.type === 'ObjectProperty' ||
77
+ path.parent.type === 'VariableDeclarator'
78
+ // TODO(W-14802236): Disabled this special case to avoid breaking reasonable scenarios returning a hoisted import
79
+ // (path.parent.type === 'ReturnStatement' && path.parent.argument === path.node)
80
+ ) {
75
81
  //when a property shares a same name with an import,
76
82
  //it will be identified as an import
77
83
  //this check skips the scenario
@@ -375,6 +375,27 @@ function processWireFunctionType(adgFunc, moduleMetadata) {
375
375
  funcObjProps.push(t.objectProperty(types_1.ID.REDUCER_FUNC_ID, t.identifier(reducerImport.generatorAlias)));
376
376
  }
377
377
  funcObjProps.push(t.objectProperty(types_1.ID.FUNC_TYPE, t.stringLiteral(types_1.PRIMING_FUNCTION)));
378
+ // Apex specific properties
379
+ if (wasApexWire(resourceName)) {
380
+ funcObjProps.push(t.objectProperty(types_1.ID.WIRE_TYPE, t.stringLiteral('apex')));
381
+ if (adgFunc.prevImportReference !== undefined) {
382
+ // build apex factory expression
383
+ // import ref split: example, ['@salesforce', 'apex', 'foo.bar']
384
+ const refSplit = adgFunc.prevImportReference.split('/');
385
+ const parts = refSplit[2].split('.');
386
+ const method = parts.pop() || '';
387
+ const classname = parts.pop() || '';
388
+ const namespace = parts.pop() || '';
389
+ const isContinuation = refSplit[1] === 'apexContinuation';
390
+ const apexFactory = t.arrowFunctionExpression([], t.callExpression(t.identifier(adapterImport.generatorAlias), [
391
+ t.stringLiteral(namespace),
392
+ t.stringLiteral(classname),
393
+ t.stringLiteral(method),
394
+ t.booleanLiteral(isContinuation),
395
+ ]));
396
+ funcObjProps.push(t.objectProperty(types_1.ID.APEX_FACTORY, apexFactory));
397
+ }
398
+ }
378
399
  }
379
400
  else {
380
401
  // Traditional wire adapter.
@@ -443,6 +464,14 @@ function isSupportedContextWire(exportName) {
443
464
  function isApexWire(resourceName) {
444
465
  return !!(resourceName && resourceName.startsWith('@salesforce/apex/'));
445
466
  }
467
+ /**
468
+ * Determines whether the resourceName of a priming function import statement is that of an Apex wire
469
+ * @param {string | undefined} resourceName a string representing the priming function resource name ('force/ldsAdaptersApex')
470
+ * @returns {boolean} true if the resource name represent that of an Apex wire, false otherwise
471
+ */
472
+ function wasApexWire(resourceName) {
473
+ return resourceName !== undefined && resourceName.startsWith('force/ldsAdaptersApex');
474
+ }
446
475
  /**
447
476
  * Retrieves the name of an Apex wire
448
477
  * @param {string} resourceName a string representing the resource name (ex: '@salesforce/apex/ContactController.getContactList')
package/build/types.js CHANGED
@@ -71,6 +71,7 @@ exports.ID = {
71
71
  IMG_FUNC: t.identifier('img'),
72
72
  HOISTED_RENDER_FUNC_ID: t.identifier('hoistedRender'),
73
73
  CONDITION_FUNC: t.identifier('c'),
74
+ APEX_FACTORY: t.identifier('af'),
74
75
  };
75
76
  // enum representing the different states of the way an Import is used
76
77
  var ImportUsageState;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@komaci/esm-generator",
3
- "version": "248.1.10",
3
+ "version": "252.0.0",
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": "248.1.10",
33
- "@komaci/static-analyzer": "248.1.10"
32
+ "@komaci/common-shared": "252.0.0",
33
+ "@komaci/static-analyzer": "252.0.0"
34
34
  },
35
35
  "devDependencies": {
36
- "@komaci/types": "248.1.10",
36
+ "@komaci/types": "252.0.0",
37
37
  "@lwc-platform/sfdc-lwc-compiler": "248.3.9-3.5.0",
38
38
  "@lwc/metadata": "3.5.0-0"
39
39
  }