@lwc/sfdc-lwc-compiler 13.2.16 → 13.2.18
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.
- package/dist/__tests__/compile-apex-logging.spec.d.ts +1 -0
- package/dist/__tests__/compile-apex-logging.spec.js +725 -0
- package/dist/__tests__/compile-apex-logging.spec.js.map +1 -0
- package/dist/__tests__/compile-luvio.spec.js +0 -584
- package/dist/__tests__/compile-luvio.spec.js.map +1 -1
- package/dist/compile.d.ts +1 -0
- package/dist/compile.js.map +1 -1
- package/dist/compiler/compile.js +10 -4
- package/dist/compiler/compile.js.map +1 -1
- package/dist/compiler/plugins/apexLoggingRollupPlugin.d.ts +54 -0
- package/dist/compiler/plugins/apexLoggingRollupPlugin.js +208 -0
- package/dist/compiler/plugins/apexLoggingRollupPlugin.js.map +1 -0
- package/dist/compiler/plugins/luvioRollupPlugin.d.ts +0 -27
- package/dist/compiler/plugins/luvioRollupPlugin.js +0 -111
- package/dist/compiler/plugins/luvioRollupPlugin.js.map +1 -1
- package/dist/compiler/plugins/plugins.d.ts +2 -1
- package/dist/compiler/plugins/plugins.js +4 -1
- package/dist/compiler/plugins/plugins.js.map +1 -1
- package/package.json +30 -30
|
@@ -0,0 +1,725 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const common_tags_1 = require("common-tags");
|
|
4
|
+
const apexLoggingRollupPlugin_1 = require("../compiler/plugins/apexLoggingRollupPlugin");
|
|
5
|
+
const main_1 = require("../main");
|
|
6
|
+
const MODULE_NAMESPACE = 'x';
|
|
7
|
+
const MODULE_NAME = 'foo';
|
|
8
|
+
function compileApexLogging(bundleConfig) {
|
|
9
|
+
return (0, main_1.compile)({
|
|
10
|
+
bundle: {
|
|
11
|
+
namespace: MODULE_NAMESPACE,
|
|
12
|
+
name: MODULE_NAME,
|
|
13
|
+
type: 'platform',
|
|
14
|
+
files: {},
|
|
15
|
+
options: {
|
|
16
|
+
enableLwcPluginImperativeApexLogging: true,
|
|
17
|
+
},
|
|
18
|
+
...bundleConfig,
|
|
19
|
+
},
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
function transformWithLuvioPlugin(src, overrideTransformOptions = {}) {
|
|
23
|
+
return (0, apexLoggingRollupPlugin_1.transformSync)(src, 'foo.js', {
|
|
24
|
+
sourcemap: true,
|
|
25
|
+
name: MODULE_NAME,
|
|
26
|
+
namespace: MODULE_NAMESPACE,
|
|
27
|
+
...overrideTransformOptions,
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
describe('babel transform with luvio plugin', () => {
|
|
31
|
+
describe('apex logging transform', () => {
|
|
32
|
+
test('injects tagName for default Apex import with 0 args', () => {
|
|
33
|
+
const src = (0, common_tags_1.stripIndents) `
|
|
34
|
+
import { LightningElement } from 'lwc';
|
|
35
|
+
import methodA from '@salesforce/apex/MyClass.methodA';
|
|
36
|
+
|
|
37
|
+
export default class Test extends LightningElement {
|
|
38
|
+
connectedCallback() {
|
|
39
|
+
methodA();
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
`;
|
|
43
|
+
const result = transformWithLuvioPlugin(src);
|
|
44
|
+
expect(result.code).toMatchInlineSnapshot(`
|
|
45
|
+
"import { LightningElement } from 'lwc';
|
|
46
|
+
import methodA from '@salesforce/apex/MyClass.methodA';
|
|
47
|
+
export default class Test extends LightningElement {
|
|
48
|
+
connectedCallback() {
|
|
49
|
+
methodA(undefined, {
|
|
50
|
+
sourceContext: {
|
|
51
|
+
tagName: "x/foo"
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
}"
|
|
56
|
+
`);
|
|
57
|
+
});
|
|
58
|
+
test('injects tagName for default Apex import with 1 arg', () => {
|
|
59
|
+
const src = (0, common_tags_1.stripIndents) `
|
|
60
|
+
import { LightningElement } from 'lwc';
|
|
61
|
+
import methodA from '@salesforce/apex/MyClass.methodA';
|
|
62
|
+
|
|
63
|
+
export default class Test extends LightningElement {
|
|
64
|
+
connectedCallback() {
|
|
65
|
+
methodA({ abc: 123 });
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
`;
|
|
69
|
+
const result = transformWithLuvioPlugin(src);
|
|
70
|
+
expect(result.code).toMatchInlineSnapshot(`
|
|
71
|
+
"import { LightningElement } from 'lwc';
|
|
72
|
+
import methodA from '@salesforce/apex/MyClass.methodA';
|
|
73
|
+
export default class Test extends LightningElement {
|
|
74
|
+
connectedCallback() {
|
|
75
|
+
methodA({
|
|
76
|
+
abc: 123
|
|
77
|
+
}, {
|
|
78
|
+
sourceContext: {
|
|
79
|
+
tagName: "x/foo"
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
}"
|
|
84
|
+
`);
|
|
85
|
+
});
|
|
86
|
+
test('does not modify when 2 args are present', () => {
|
|
87
|
+
const src = (0, common_tags_1.stripIndents) `
|
|
88
|
+
import { LightningElement } from 'lwc';
|
|
89
|
+
import methodA from '@salesforce/apex/MyClass.methodA';
|
|
90
|
+
|
|
91
|
+
export default class Test extends LightningElement {
|
|
92
|
+
connectedCallback() {
|
|
93
|
+
methodA({ abc: 123 }, { extraData: 'foo'});
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
`;
|
|
97
|
+
const result = transformWithLuvioPlugin(src);
|
|
98
|
+
expect(result.code).toMatchInlineSnapshot(`
|
|
99
|
+
"import { LightningElement } from 'lwc';
|
|
100
|
+
import methodA from '@salesforce/apex/MyClass.methodA';
|
|
101
|
+
export default class Test extends LightningElement {
|
|
102
|
+
connectedCallback() {
|
|
103
|
+
methodA({
|
|
104
|
+
abc: 123
|
|
105
|
+
}, {
|
|
106
|
+
extraData: 'foo'
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
}"
|
|
110
|
+
`);
|
|
111
|
+
expect(result.code).not.toContain("'x/foo'");
|
|
112
|
+
});
|
|
113
|
+
test('does not modify when more than 2 args are present', () => {
|
|
114
|
+
const src = (0, common_tags_1.stripIndents) `
|
|
115
|
+
import { LightningElement } from 'lwc';
|
|
116
|
+
import methodA from '@salesforce/apex/MyClass.methodA';
|
|
117
|
+
|
|
118
|
+
export default class Test extends LightningElement {
|
|
119
|
+
connectedCallback() {
|
|
120
|
+
methodA({ abc: 123 }, { extraData: 'foo'}, { extraData: 'bar'});
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
`;
|
|
124
|
+
const result = transformWithLuvioPlugin(src);
|
|
125
|
+
expect(result.code).toMatchInlineSnapshot(`
|
|
126
|
+
"import { LightningElement } from 'lwc';
|
|
127
|
+
import methodA from '@salesforce/apex/MyClass.methodA';
|
|
128
|
+
export default class Test extends LightningElement {
|
|
129
|
+
connectedCallback() {
|
|
130
|
+
methodA({
|
|
131
|
+
abc: 123
|
|
132
|
+
}, {
|
|
133
|
+
extraData: 'foo'
|
|
134
|
+
}, {
|
|
135
|
+
extraData: 'bar'
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
}"
|
|
139
|
+
`);
|
|
140
|
+
expect(result.code).not.toContain("'x/foo'");
|
|
141
|
+
});
|
|
142
|
+
test('does not modify when using a spread operator', () => {
|
|
143
|
+
const src = (0, common_tags_1.stripIndents) `
|
|
144
|
+
import { LightningElement } from 'lwc';
|
|
145
|
+
import methodA from '@salesforce/apex/MyClass.methodA';
|
|
146
|
+
const args = { abc: 123 };
|
|
147
|
+
const args2 = { extraData: 'foo' };
|
|
148
|
+
export default class Test extends LightningElement {
|
|
149
|
+
connectedCallback() {
|
|
150
|
+
methodA(...args, ...args2);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
`;
|
|
154
|
+
const result = transformWithLuvioPlugin(src);
|
|
155
|
+
expect(result.code).toMatchInlineSnapshot(`
|
|
156
|
+
"import { LightningElement } from 'lwc';
|
|
157
|
+
import methodA from '@salesforce/apex/MyClass.methodA';
|
|
158
|
+
const args = {
|
|
159
|
+
abc: 123
|
|
160
|
+
};
|
|
161
|
+
const args2 = {
|
|
162
|
+
extraData: 'foo'
|
|
163
|
+
};
|
|
164
|
+
export default class Test extends LightningElement {
|
|
165
|
+
connectedCallback() {
|
|
166
|
+
methodA(...args, ...args2);
|
|
167
|
+
}
|
|
168
|
+
}"
|
|
169
|
+
`);
|
|
170
|
+
expect(result.code).not.toContain("'x/foo'");
|
|
171
|
+
});
|
|
172
|
+
test('resolves module for unnamed default class export', () => {
|
|
173
|
+
const src = (0, common_tags_1.stripIndents) `
|
|
174
|
+
import { LightningElement } from 'lwc';
|
|
175
|
+
import methodA from '@salesforce/apex/MyClass.methodA';
|
|
176
|
+
|
|
177
|
+
export default class extends LightningElement {
|
|
178
|
+
connectedCallback() {
|
|
179
|
+
methodA();
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
`;
|
|
183
|
+
const result = transformWithLuvioPlugin(src);
|
|
184
|
+
expect(result.code).toMatchInlineSnapshot(`
|
|
185
|
+
"import { LightningElement } from 'lwc';
|
|
186
|
+
import methodA from '@salesforce/apex/MyClass.methodA';
|
|
187
|
+
export default class extends LightningElement {
|
|
188
|
+
connectedCallback() {
|
|
189
|
+
methodA(undefined, {
|
|
190
|
+
sourceContext: {
|
|
191
|
+
tagName: "x/foo"
|
|
192
|
+
}
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
}"
|
|
196
|
+
`);
|
|
197
|
+
});
|
|
198
|
+
test('resolves component class name from default export identifier bound to named class expression', () => {
|
|
199
|
+
const src = (0, common_tags_1.stripIndents) `
|
|
200
|
+
import { LightningElement } from 'lwc';
|
|
201
|
+
import methodA from '@salesforce/apex/MyClass.methodA';
|
|
202
|
+
|
|
203
|
+
const Comp = class NamedComp extends LightningElement {
|
|
204
|
+
connectedCallback() {
|
|
205
|
+
methodA();
|
|
206
|
+
}
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
export default Comp;
|
|
210
|
+
`;
|
|
211
|
+
const result = transformWithLuvioPlugin(src);
|
|
212
|
+
expect(result.code).toMatchInlineSnapshot(`
|
|
213
|
+
"import { LightningElement } from 'lwc';
|
|
214
|
+
import methodA from '@salesforce/apex/MyClass.methodA';
|
|
215
|
+
const Comp = class NamedComp extends LightningElement {
|
|
216
|
+
connectedCallback() {
|
|
217
|
+
methodA(undefined, {
|
|
218
|
+
sourceContext: {
|
|
219
|
+
tagName: "x/foo"
|
|
220
|
+
}
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
};
|
|
224
|
+
export default Comp;"
|
|
225
|
+
`);
|
|
226
|
+
});
|
|
227
|
+
test('injects tagName for apexContinuation import', () => {
|
|
228
|
+
const src = (0, common_tags_1.stripIndents) `
|
|
229
|
+
import { LightningElement } from 'lwc';
|
|
230
|
+
import cont from '@salesforce/apexContinuation/MyClass.methodB';
|
|
231
|
+
|
|
232
|
+
export default class Test extends LightningElement {
|
|
233
|
+
connectedCallback() {
|
|
234
|
+
cont();
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
`;
|
|
238
|
+
const result = transformWithLuvioPlugin(src);
|
|
239
|
+
expect(result.code).toMatchInlineSnapshot(`
|
|
240
|
+
"import { LightningElement } from 'lwc';
|
|
241
|
+
import cont from '@salesforce/apexContinuation/MyClass.methodB';
|
|
242
|
+
export default class Test extends LightningElement {
|
|
243
|
+
connectedCallback() {
|
|
244
|
+
cont(undefined, {
|
|
245
|
+
sourceContext: {
|
|
246
|
+
tagName: "x/foo"
|
|
247
|
+
}
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
}"
|
|
251
|
+
`);
|
|
252
|
+
});
|
|
253
|
+
test('injects tagName for non default exported functions', () => {
|
|
254
|
+
const src = (0, common_tags_1.stripIndents) `
|
|
255
|
+
import foo from '@salesforce/apex/ns.class.fooMethod';
|
|
256
|
+
import bar from '@salesforce/apex/ns.class.barMethod';
|
|
257
|
+
|
|
258
|
+
export function callFoo() {
|
|
259
|
+
foo();
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
export function callBar() {
|
|
263
|
+
bar();
|
|
264
|
+
}
|
|
265
|
+
`;
|
|
266
|
+
const result = transformWithLuvioPlugin(src);
|
|
267
|
+
expect(result.code).toMatchInlineSnapshot(`
|
|
268
|
+
"import foo from '@salesforce/apex/ns.class.fooMethod';
|
|
269
|
+
import bar from '@salesforce/apex/ns.class.barMethod';
|
|
270
|
+
export function callFoo() {
|
|
271
|
+
foo(undefined, {
|
|
272
|
+
sourceContext: {
|
|
273
|
+
tagName: "x/foo"
|
|
274
|
+
}
|
|
275
|
+
});
|
|
276
|
+
}
|
|
277
|
+
export function callBar() {
|
|
278
|
+
bar(undefined, {
|
|
279
|
+
sourceContext: {
|
|
280
|
+
tagName: "x/foo"
|
|
281
|
+
}
|
|
282
|
+
});
|
|
283
|
+
}"
|
|
284
|
+
`);
|
|
285
|
+
});
|
|
286
|
+
test('injects tagName for default imported function', () => {
|
|
287
|
+
const src = (0, common_tags_1.stripIndents) `
|
|
288
|
+
import { LightningElement } from 'lwc';
|
|
289
|
+
import { default as methodA } from '@salesforce/apex/MyClass.methodA';
|
|
290
|
+
|
|
291
|
+
export default class Test extends LightningElement {
|
|
292
|
+
connectedCallback() {
|
|
293
|
+
methodA({ abc: 123 });
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
`;
|
|
297
|
+
const result = transformWithLuvioPlugin(src);
|
|
298
|
+
expect(result.code).toMatchInlineSnapshot(`
|
|
299
|
+
"import { LightningElement } from 'lwc';
|
|
300
|
+
import { default as methodA } from '@salesforce/apex/MyClass.methodA';
|
|
301
|
+
export default class Test extends LightningElement {
|
|
302
|
+
connectedCallback() {
|
|
303
|
+
methodA({
|
|
304
|
+
abc: 123
|
|
305
|
+
}, {
|
|
306
|
+
sourceContext: {
|
|
307
|
+
tagName: "x/foo"
|
|
308
|
+
}
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
}"
|
|
312
|
+
`);
|
|
313
|
+
});
|
|
314
|
+
test('injects tagName for non default exported functions with 1 arg', () => {
|
|
315
|
+
const src = (0, common_tags_1.stripIndents) `
|
|
316
|
+
import foo from '@salesforce/apex/ns.class.fooMethod';
|
|
317
|
+
import bar from '@salesforce/apex/ns.class.barMethod';
|
|
318
|
+
|
|
319
|
+
export function callFoo() {
|
|
320
|
+
foo({ abc: 123 });
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
export function callBar() {
|
|
324
|
+
bar({ abc: 123 });
|
|
325
|
+
}
|
|
326
|
+
`;
|
|
327
|
+
const result = transformWithLuvioPlugin(src);
|
|
328
|
+
expect(result.code).toMatchInlineSnapshot(`
|
|
329
|
+
"import foo from '@salesforce/apex/ns.class.fooMethod';
|
|
330
|
+
import bar from '@salesforce/apex/ns.class.barMethod';
|
|
331
|
+
export function callFoo() {
|
|
332
|
+
foo({
|
|
333
|
+
abc: 123
|
|
334
|
+
}, {
|
|
335
|
+
sourceContext: {
|
|
336
|
+
tagName: "x/foo"
|
|
337
|
+
}
|
|
338
|
+
});
|
|
339
|
+
}
|
|
340
|
+
export function callBar() {
|
|
341
|
+
bar({
|
|
342
|
+
abc: 123
|
|
343
|
+
}, {
|
|
344
|
+
sourceContext: {
|
|
345
|
+
tagName: "x/foo"
|
|
346
|
+
}
|
|
347
|
+
});
|
|
348
|
+
}"
|
|
349
|
+
`);
|
|
350
|
+
});
|
|
351
|
+
test('does not inject tagName for non default exported functions with 2 args', () => {
|
|
352
|
+
const src = (0, common_tags_1.stripIndents) `
|
|
353
|
+
import foo from '@salesforce/apex/ns.class.fooMethod';
|
|
354
|
+
import bar from '@salesforce/apex/ns.class.barMethod';
|
|
355
|
+
|
|
356
|
+
export function callFoo() {
|
|
357
|
+
foo({ abc: 123 }, { extraData: 'foo'});
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
export function callBar() {
|
|
361
|
+
bar({ abc: 123 }, { extraData: 'foo'});
|
|
362
|
+
}
|
|
363
|
+
`;
|
|
364
|
+
const result = transformWithLuvioPlugin(src);
|
|
365
|
+
expect(result.code).toMatchInlineSnapshot(`
|
|
366
|
+
"import foo from '@salesforce/apex/ns.class.fooMethod';
|
|
367
|
+
import bar from '@salesforce/apex/ns.class.barMethod';
|
|
368
|
+
export function callFoo() {
|
|
369
|
+
foo({
|
|
370
|
+
abc: 123
|
|
371
|
+
}, {
|
|
372
|
+
extraData: 'foo'
|
|
373
|
+
});
|
|
374
|
+
}
|
|
375
|
+
export function callBar() {
|
|
376
|
+
bar({
|
|
377
|
+
abc: 123
|
|
378
|
+
}, {
|
|
379
|
+
extraData: 'foo'
|
|
380
|
+
});
|
|
381
|
+
}"
|
|
382
|
+
`);
|
|
383
|
+
});
|
|
384
|
+
test('does not inject tagName for non default exported functions with 2 empty args', () => {
|
|
385
|
+
const src = (0, common_tags_1.stripIndents) `
|
|
386
|
+
import foo from '@salesforce/apex/ns.class.fooMethod';
|
|
387
|
+
import bar from '@salesforce/apex/ns.class.barMethod';
|
|
388
|
+
|
|
389
|
+
export function callFoo() {
|
|
390
|
+
foo({}, {});
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
export function callBar() {
|
|
394
|
+
bar({}, {});
|
|
395
|
+
}
|
|
396
|
+
`;
|
|
397
|
+
const result = transformWithLuvioPlugin(src);
|
|
398
|
+
expect(result.code).toMatchInlineSnapshot(`
|
|
399
|
+
"import foo from '@salesforce/apex/ns.class.fooMethod';
|
|
400
|
+
import bar from '@salesforce/apex/ns.class.barMethod';
|
|
401
|
+
export function callFoo() {
|
|
402
|
+
foo({}, {});
|
|
403
|
+
}
|
|
404
|
+
export function callBar() {
|
|
405
|
+
bar({}, {});
|
|
406
|
+
}"
|
|
407
|
+
`);
|
|
408
|
+
});
|
|
409
|
+
test('does not inject tagName for re-exported apex function', () => {
|
|
410
|
+
const src = (0, common_tags_1.stripIndents) `
|
|
411
|
+
import foo from '@salesforce/apex/ns.class.fooMethod';
|
|
412
|
+
export const fooAsBar = foo;
|
|
413
|
+
`;
|
|
414
|
+
const result = transformWithLuvioPlugin(src);
|
|
415
|
+
expect(result.code).toMatchInlineSnapshot(`
|
|
416
|
+
"import foo from '@salesforce/apex/ns.class.fooMethod';
|
|
417
|
+
export const fooAsBar = foo;"
|
|
418
|
+
`);
|
|
419
|
+
});
|
|
420
|
+
test('does not inject tagName for exported function with parameter shadowing', () => {
|
|
421
|
+
const src = (0, common_tags_1.stripIndents) `
|
|
422
|
+
import foo from '@salesforce/apex/ns.class.fooMethod';
|
|
423
|
+
|
|
424
|
+
export function callFoo() {
|
|
425
|
+
foo();
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
export function callBar(foo) {
|
|
429
|
+
foo({abc: 123});
|
|
430
|
+
}
|
|
431
|
+
`;
|
|
432
|
+
const result = transformWithLuvioPlugin(src);
|
|
433
|
+
expect(result.code).toMatchInlineSnapshot(`
|
|
434
|
+
"import foo from '@salesforce/apex/ns.class.fooMethod';
|
|
435
|
+
export function callFoo() {
|
|
436
|
+
foo(undefined, {
|
|
437
|
+
sourceContext: {
|
|
438
|
+
tagName: "x/foo"
|
|
439
|
+
}
|
|
440
|
+
});
|
|
441
|
+
}
|
|
442
|
+
export function callBar(foo) {
|
|
443
|
+
foo({
|
|
444
|
+
abc: 123
|
|
445
|
+
});
|
|
446
|
+
}"
|
|
447
|
+
`);
|
|
448
|
+
});
|
|
449
|
+
test('does not inject tagName for exported function with parameter shadowing, variation 1', () => {
|
|
450
|
+
const src = (0, common_tags_1.stripIndents) `
|
|
451
|
+
import getContactList from '@salesforce/apex/ContactController.getContactList';
|
|
452
|
+
|
|
453
|
+
export default class ApexWireMethodToProperty extends LightningElement {
|
|
454
|
+
|
|
455
|
+
foo() {
|
|
456
|
+
function getContactList() {}
|
|
457
|
+
getContactList(); // should not be transformed
|
|
458
|
+
}
|
|
459
|
+
@wire(getContactList, {
|
|
460
|
+
abc: 123
|
|
461
|
+
})
|
|
462
|
+
contacts;
|
|
463
|
+
}
|
|
464
|
+
`;
|
|
465
|
+
const result = transformWithLuvioPlugin(src);
|
|
466
|
+
expect(result.code).toMatchInlineSnapshot(`
|
|
467
|
+
"import getContactList from '@salesforce/apex/ContactController.getContactList';
|
|
468
|
+
export default class ApexWireMethodToProperty extends LightningElement {
|
|
469
|
+
foo() {
|
|
470
|
+
function getContactList() {}
|
|
471
|
+
getContactList(); // should not be transformed
|
|
472
|
+
}
|
|
473
|
+
@wire(getContactList, {
|
|
474
|
+
abc: 123
|
|
475
|
+
})
|
|
476
|
+
contacts;
|
|
477
|
+
}"
|
|
478
|
+
`);
|
|
479
|
+
});
|
|
480
|
+
test('does not inject tagName for exported function with parameter shadowing, variation 2', () => {
|
|
481
|
+
const src = (0, common_tags_1.stripIndents) `
|
|
482
|
+
import getContactList from '@salesforce/apex/ContactController.getContactList';
|
|
483
|
+
|
|
484
|
+
export default class ApexWireMethodToProperty extends LightningElement {
|
|
485
|
+
|
|
486
|
+
foo() {
|
|
487
|
+
function getContactList() {}
|
|
488
|
+
getContactList(); // should not be transformed
|
|
489
|
+
}
|
|
490
|
+
@wire(getContactList, {
|
|
491
|
+
abc: 123
|
|
492
|
+
})
|
|
493
|
+
contacts;
|
|
494
|
+
}
|
|
495
|
+
`;
|
|
496
|
+
const result = transformWithLuvioPlugin(src);
|
|
497
|
+
expect(result.code).toMatchInlineSnapshot(`
|
|
498
|
+
"import getContactList from '@salesforce/apex/ContactController.getContactList';
|
|
499
|
+
export default class ApexWireMethodToProperty extends LightningElement {
|
|
500
|
+
foo() {
|
|
501
|
+
function getContactList() {}
|
|
502
|
+
getContactList(); // should not be transformed
|
|
503
|
+
}
|
|
504
|
+
@wire(getContactList, {
|
|
505
|
+
abc: 123
|
|
506
|
+
})
|
|
507
|
+
contacts;
|
|
508
|
+
}"
|
|
509
|
+
`);
|
|
510
|
+
});
|
|
511
|
+
test('does not inject for refreshApex usages', () => {
|
|
512
|
+
const src = (0, common_tags_1.stripIndents) `
|
|
513
|
+
// Example of refreshing data for a wired property
|
|
514
|
+
// after you update data via imperative Apex.
|
|
515
|
+
import { LightningElement, wire } from 'lwc';
|
|
516
|
+
import { refreshApex } from '@salesforce/apex';
|
|
517
|
+
import { notifyRecordUpdateAvailable } from 'lightning/uiRecordApi';
|
|
518
|
+
import getOpptyOverAmount from '@salesforce/apex/OpptyController.getOpptyOverAmount';
|
|
519
|
+
import apexUpdateRecord from '@salesforce/apex/Controller.apexUpdateRecord';
|
|
520
|
+
|
|
521
|
+
export default class RefreshDataImperativeExample extends LightningElement {
|
|
522
|
+
@wire(getOpptyOverAmount, { amount: '$amount' })
|
|
523
|
+
opptiesOverAmount;
|
|
524
|
+
|
|
525
|
+
// Update the record in Apex, such as via a button click
|
|
526
|
+
// Refresh Apex data that the wire service provisioned
|
|
527
|
+
async handler() {
|
|
528
|
+
try {
|
|
529
|
+
await apexUpdateRecord(recordIds);
|
|
530
|
+
refreshApex(this.opptiesOverAmount);
|
|
531
|
+
notifyRecordUpdateAvailable(recordIds); // Refresh the Lightning Data Service cache
|
|
532
|
+
} catch (error) {
|
|
533
|
+
this.error = error;
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
`;
|
|
538
|
+
const result = transformWithLuvioPlugin(src);
|
|
539
|
+
expect(result.code).toMatchInlineSnapshot(`
|
|
540
|
+
"// Example of refreshing data for a wired property
|
|
541
|
+
// after you update data via imperative Apex.
|
|
542
|
+
import { LightningElement, wire } from 'lwc';
|
|
543
|
+
import { refreshApex } from '@salesforce/apex';
|
|
544
|
+
import { notifyRecordUpdateAvailable } from 'lightning/uiRecordApi';
|
|
545
|
+
import getOpptyOverAmount from '@salesforce/apex/OpptyController.getOpptyOverAmount';
|
|
546
|
+
import apexUpdateRecord from '@salesforce/apex/Controller.apexUpdateRecord';
|
|
547
|
+
export default class RefreshDataImperativeExample extends LightningElement {
|
|
548
|
+
@wire(getOpptyOverAmount, {
|
|
549
|
+
amount: '$amount'
|
|
550
|
+
})
|
|
551
|
+
opptiesOverAmount;
|
|
552
|
+
|
|
553
|
+
// Update the record in Apex, such as via a button click
|
|
554
|
+
// Refresh Apex data that the wire service provisioned
|
|
555
|
+
async handler() {
|
|
556
|
+
try {
|
|
557
|
+
await apexUpdateRecord(recordIds, {
|
|
558
|
+
sourceContext: {
|
|
559
|
+
tagName: "x/foo"
|
|
560
|
+
}
|
|
561
|
+
});
|
|
562
|
+
refreshApex(this.opptiesOverAmount);
|
|
563
|
+
notifyRecordUpdateAvailable(recordIds); // Refresh the Lightning Data Service cache
|
|
564
|
+
} catch (error) {
|
|
565
|
+
this.error = error;
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
}"
|
|
569
|
+
`);
|
|
570
|
+
});
|
|
571
|
+
test('does not inject for non-apex imports', () => {
|
|
572
|
+
const src = (0, common_tags_1.stripIndents) `
|
|
573
|
+
import { LightningElement } from 'lwc';
|
|
574
|
+
import doThing from 'c/someModule';
|
|
575
|
+
|
|
576
|
+
export default class Test extends LightningElement {
|
|
577
|
+
connectedCallback() {
|
|
578
|
+
doThing();
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
`;
|
|
582
|
+
const result = transformWithLuvioPlugin(src);
|
|
583
|
+
expect(result.code).toMatchInlineSnapshot(`
|
|
584
|
+
"import { LightningElement } from 'lwc';
|
|
585
|
+
import doThing from 'c/someModule';
|
|
586
|
+
export default class Test extends LightningElement {
|
|
587
|
+
connectedCallback() {
|
|
588
|
+
doThing();
|
|
589
|
+
}
|
|
590
|
+
}"
|
|
591
|
+
`);
|
|
592
|
+
});
|
|
593
|
+
test('does not inject for @wire apex usages', () => {
|
|
594
|
+
const src = (0, common_tags_1.stripIndents) `
|
|
595
|
+
import { LightningElement, wire } from 'lwc';
|
|
596
|
+
import getContactList from '@salesforce/apex/ContactController.getContactList';
|
|
597
|
+
|
|
598
|
+
export default class ApexWireMethodToProperty extends LightningElement {
|
|
599
|
+
@wire(getContactList, { abc: 123 }) contacts;
|
|
600
|
+
}
|
|
601
|
+
`;
|
|
602
|
+
const result = transformWithLuvioPlugin(src);
|
|
603
|
+
expect(result.code).toMatchInlineSnapshot(`
|
|
604
|
+
"import { LightningElement, wire } from 'lwc';
|
|
605
|
+
import getContactList from '@salesforce/apex/ContactController.getContactList';
|
|
606
|
+
export default class ApexWireMethodToProperty extends LightningElement {
|
|
607
|
+
@wire(getContactList, {
|
|
608
|
+
abc: 123
|
|
609
|
+
})
|
|
610
|
+
contacts;
|
|
611
|
+
}"
|
|
612
|
+
`);
|
|
613
|
+
});
|
|
614
|
+
});
|
|
615
|
+
});
|
|
616
|
+
describe('rollup compilation with luvio plugin enabled', () => {
|
|
617
|
+
test('verify the correctness of the compiler output on a valid source foo.js', async () => {
|
|
618
|
+
const res = await compileApexLogging({
|
|
619
|
+
type: 'platform',
|
|
620
|
+
files: {
|
|
621
|
+
'foo.js': (0, common_tags_1.stripIndents) `
|
|
622
|
+
import { LightningElement } from 'lwc';
|
|
623
|
+
import methodA from '@salesforce/apex/MyClass.methodA';
|
|
624
|
+
|
|
625
|
+
export default class Test extends LightningElement {
|
|
626
|
+
connectedCallback() {
|
|
627
|
+
methodA();
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
`,
|
|
631
|
+
},
|
|
632
|
+
namespaceMapping: {
|
|
633
|
+
x: 'ns',
|
|
634
|
+
},
|
|
635
|
+
});
|
|
636
|
+
const { success, results, diagnostics } = res;
|
|
637
|
+
expect(success).toBe(true);
|
|
638
|
+
expect(diagnostics.length).toBe(0);
|
|
639
|
+
expect(results[0].code).toMatchInlineSnapshot(`
|
|
640
|
+
"define('ns/foo', ['lwc', '@salesforce/apex/MyClass.methodA'], (function (lwc, methodA) {
|
|
641
|
+
|
|
642
|
+
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
|
|
643
|
+
|
|
644
|
+
var methodA__default = /*#__PURE__*/_interopDefaultCompat(methodA);
|
|
645
|
+
|
|
646
|
+
var _tmpl = void 0;
|
|
647
|
+
|
|
648
|
+
class Test extends lwc.LightningElement {
|
|
649
|
+
connectedCallback() {
|
|
650
|
+
methodA__default.default(undefined, {
|
|
651
|
+
sourceContext: {
|
|
652
|
+
tagName: "ns/foo"
|
|
653
|
+
}
|
|
654
|
+
});
|
|
655
|
+
}
|
|
656
|
+
/*LWC compiler v8.23.0*/
|
|
657
|
+
}
|
|
658
|
+
const __lwc_component_class_internal = lwc.registerComponent(Test, {
|
|
659
|
+
tmpl: _tmpl,
|
|
660
|
+
sel: "x-foo",
|
|
661
|
+
apiVersion: 66
|
|
662
|
+
});
|
|
663
|
+
|
|
664
|
+
return __lwc_component_class_internal;
|
|
665
|
+
|
|
666
|
+
}));
|
|
667
|
+
"
|
|
668
|
+
`);
|
|
669
|
+
});
|
|
670
|
+
test('verify the correctness of the compiler output on a valid source foo.ts', async () => {
|
|
671
|
+
const res = await compileApexLogging({
|
|
672
|
+
type: 'internal',
|
|
673
|
+
files: {
|
|
674
|
+
'foo.ts': (0, common_tags_1.stripIndents) `
|
|
675
|
+
import { LightningElement } from 'lwc';
|
|
676
|
+
import methodA from '@salesforce/apex/MyClass.methodA';
|
|
677
|
+
|
|
678
|
+
export default class Test extends LightningElement {
|
|
679
|
+
connectedCallback() {
|
|
680
|
+
methodA();
|
|
681
|
+
}
|
|
682
|
+
}
|
|
683
|
+
`,
|
|
684
|
+
},
|
|
685
|
+
namespaceMapping: {
|
|
686
|
+
x: 'ns',
|
|
687
|
+
},
|
|
688
|
+
});
|
|
689
|
+
const { success, results, diagnostics } = res;
|
|
690
|
+
expect(success).toBe(true);
|
|
691
|
+
expect(diagnostics.length).toBe(0);
|
|
692
|
+
expect(results[0].code).toMatchInlineSnapshot(`
|
|
693
|
+
"define('ns/foo', ['lwc', '@salesforce/apex/MyClass.methodA'], (function (lwc, methodA) {
|
|
694
|
+
|
|
695
|
+
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
|
|
696
|
+
|
|
697
|
+
var methodA__default = /*#__PURE__*/_interopDefaultCompat(methodA);
|
|
698
|
+
|
|
699
|
+
var _tmpl = void 0;
|
|
700
|
+
|
|
701
|
+
class Test extends lwc.LightningElement {
|
|
702
|
+
connectedCallback() {
|
|
703
|
+
methodA__default.default(undefined, {
|
|
704
|
+
sourceContext: {
|
|
705
|
+
tagName: "ns/foo"
|
|
706
|
+
}
|
|
707
|
+
});
|
|
708
|
+
}
|
|
709
|
+
/*LWC compiler v8.23.0*/
|
|
710
|
+
}
|
|
711
|
+
const __lwc_component_class_internal = lwc.registerComponent(Test, {
|
|
712
|
+
tmpl: _tmpl,
|
|
713
|
+
sel: "x-foo",
|
|
714
|
+
apiVersion: 66,
|
|
715
|
+
enableSyntheticElementInternals: true
|
|
716
|
+
});
|
|
717
|
+
|
|
718
|
+
return __lwc_component_class_internal;
|
|
719
|
+
|
|
720
|
+
}));
|
|
721
|
+
"
|
|
722
|
+
`);
|
|
723
|
+
});
|
|
724
|
+
});
|
|
725
|
+
//# sourceMappingURL=compile-apex-logging.spec.js.map
|