@lwc/sfdc-lwc-compiler 13.3.25 → 13.3.27

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 (33) hide show
  1. package/dist/__tests__/compile-state-manager-instrumentation.spec.d.ts +1 -0
  2. package/dist/__tests__/compile-state-manager-instrumentation.spec.js +654 -0
  3. package/dist/__tests__/compile-state-manager-instrumentation.spec.js.map +1 -0
  4. package/dist/__tests__/compile.spec.js +1 -1
  5. package/dist/__tests__/compile.spec.js.map +1 -1
  6. package/dist/compile.d.ts +2 -1
  7. package/dist/compile.js +1 -1
  8. package/dist/compile.js.map +1 -1
  9. package/dist/compiler/__tests__/dynamic-imports.spec.js +1 -1
  10. package/dist/compiler/__tests__/dynamic-imports.spec.js.map +1 -1
  11. package/dist/compiler/__tests__/output.spec.js +1 -1
  12. package/dist/compiler/__tests__/output.spec.js.map +1 -1
  13. package/dist/compiler/compile.js +13 -2
  14. package/dist/compiler/compile.js.map +1 -1
  15. package/dist/compiler/plugins/__tests__/utils.spec.d.ts +1 -0
  16. package/dist/compiler/plugins/__tests__/utils.spec.js +127 -0
  17. package/dist/compiler/plugins/__tests__/utils.spec.js.map +1 -0
  18. package/dist/compiler/plugins/apexLoggingRollupPlugin.d.ts +3 -3
  19. package/dist/compiler/plugins/apexLoggingRollupPlugin.js +6 -57
  20. package/dist/compiler/plugins/apexLoggingRollupPlugin.js.map +1 -1
  21. package/dist/compiler/plugins/luvioRollupPlugin.d.ts +3 -3
  22. package/dist/compiler/plugins/luvioRollupPlugin.js +6 -57
  23. package/dist/compiler/plugins/luvioRollupPlugin.js.map +1 -1
  24. package/dist/compiler/plugins/plugins.d.ts +2 -1
  25. package/dist/compiler/plugins/plugins.js +4 -1
  26. package/dist/compiler/plugins/plugins.js.map +1 -1
  27. package/dist/compiler/plugins/stateManagerInstrumentationPlugin.d.ts +72 -0
  28. package/dist/compiler/plugins/stateManagerInstrumentationPlugin.js +170 -0
  29. package/dist/compiler/plugins/stateManagerInstrumentationPlugin.js.map +1 -0
  30. package/dist/compiler/plugins/utils.d.ts +12 -0
  31. package/dist/compiler/plugins/utils.js +62 -0
  32. package/dist/compiler/plugins/utils.js.map +1 -0
  33. package/package.json +21 -21
@@ -0,0 +1,654 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const common_tags_1 = require("common-tags");
4
+ const stateManagerInstrumentationPlugin_1 = require("../compiler/plugins/stateManagerInstrumentationPlugin");
5
+ const compiler_1 = require("../compiler");
6
+ const MODULE_NAMESPACE = 'c';
7
+ const MODULE_NAME = 'myComponent';
8
+ function transformWithStateManagerPlugin(src, { namespace, name, type, ...overrideTransformOptions } = {
9
+ namespace: MODULE_NAMESPACE,
10
+ name: MODULE_NAME,
11
+ type: 'platform',
12
+ }) {
13
+ return (0, stateManagerInstrumentationPlugin_1.transformSync)(src, 'foo.js', {
14
+ sourcemap: true,
15
+ name,
16
+ namespace,
17
+ type,
18
+ ...overrideTransformOptions,
19
+ });
20
+ }
21
+ // Helper function to create base configuration with overrides
22
+ function getConfig(overrides = {}) {
23
+ return {
24
+ name: 'test',
25
+ namespace: 'x',
26
+ type: 'platform',
27
+ files: {
28
+ 'test.js': `
29
+ import { LightningElement } from 'lwc';
30
+ import { defineState } from '@lwc/state';
31
+
32
+ const useCounter = defineState(({ atom }) => ({ count: atom(0) }));
33
+
34
+ export default class Test extends LightningElement {
35
+ counter = useCounter();
36
+ }
37
+ `,
38
+ 'test.html': `
39
+ <template>
40
+ <div>Counter: {counter.count.value}</div>
41
+ </template>
42
+ `,
43
+ },
44
+ options: {
45
+ enableLwcPluginStateManagerInstrumentation: true,
46
+ },
47
+ ...overrides,
48
+ };
49
+ }
50
+ describe('babel transform with state manager instrumentation plugin', () => {
51
+ describe('state manager instrumentation transform', () => {
52
+ test('injects metadata for single defineState call with one argument', () => {
53
+ const src = (0, common_tags_1.stripIndents) `
54
+ import { LightningElement } from 'lwc';
55
+ import { defineState } from '@lwc/state';
56
+
57
+ const useThemeManager = defineState(({ atom, computed, setAtom }, initialTheme = 'light') => {
58
+ const theme = atom(initialTheme);
59
+ const isDark = computed([theme], (themeValue) => themeValue === 'dark');
60
+
61
+ const toggleTheme = () => {
62
+ setAtom(theme, theme.value === 'light' ? 'dark' : 'light');
63
+ };
64
+
65
+ return { theme, isDark, toggleTheme };
66
+ });
67
+
68
+ export default class MyComponent extends LightningElement {
69
+ themeManager = useThemeManager();
70
+ }
71
+ `;
72
+ const result = transformWithStateManagerPlugin(src);
73
+ expect(result.code).toMatchInlineSnapshot(`
74
+ "import { LightningElement } from 'lwc';
75
+ import { defineState } from '@lwc/state';
76
+ const useThemeManager = defineState(({
77
+ atom,
78
+ computed,
79
+ setAtom
80
+ }, initialTheme = 'light') => {
81
+ const theme = atom(initialTheme);
82
+ const isDark = computed([theme], themeValue => themeValue === 'dark');
83
+ const toggleTheme = () => {
84
+ setAtom(theme, theme.value === 'light' ? 'dark' : 'light');
85
+ };
86
+ return {
87
+ theme,
88
+ isDark,
89
+ toggleTheme
90
+ };
91
+ }, {
92
+ metadata: {
93
+ definedBy: "c/myComponent",
94
+ type: "external"
95
+ }
96
+ });
97
+ export default class MyComponent extends LightningElement {
98
+ themeManager = useThemeManager();
99
+ }"
100
+ `);
101
+ });
102
+ test('injects metadata for multiple defineState calls with unique suffixes', () => {
103
+ const src = (0, common_tags_1.stripIndents) `
104
+ import { LightningElement } from 'lwc';
105
+ import { defineState } from '@lwc/state';
106
+
107
+ // Shopping cart state manager
108
+ const useShoppingCart = defineState(({ atom, computed, setAtom }) => {
109
+ const items = atom([]);
110
+ const total = computed([items], (itemsValue) =>
111
+ itemsValue.reduce((sum, item) => sum + item.price * item.quantity, 0)
112
+ );
113
+ return { items, total, setAtom };
114
+ });
115
+
116
+ // User authentication state manager
117
+ const useAuth = defineState(({ atom }) => {
118
+ const user = atom(null);
119
+ const isLoggedIn = computed([user], (userValue) => !!userValue);
120
+ return { user, isLoggedIn };
121
+ });
122
+
123
+ // App settings state manager
124
+ const useSettings = defineState(({ atom }) => {
125
+ const preferences = atom({ theme: 'light', language: 'en' });
126
+ return { preferences };
127
+ });
128
+
129
+ export default class ECommerceApp extends LightningElement {
130
+ cart = useShoppingCart();
131
+ auth = useAuth();
132
+ settings = useSettings();
133
+ }
134
+ `;
135
+ const result = transformWithStateManagerPlugin(src);
136
+ expect(result.code).toMatchInlineSnapshot(`
137
+ "import { LightningElement } from 'lwc';
138
+ import { defineState } from '@lwc/state';
139
+
140
+ // Shopping cart state manager
141
+ const useShoppingCart = defineState(({
142
+ atom,
143
+ computed,
144
+ setAtom
145
+ }) => {
146
+ const items = atom([]);
147
+ const total = computed([items], itemsValue => itemsValue.reduce((sum, item) => sum + item.price * item.quantity, 0));
148
+ return {
149
+ items,
150
+ total,
151
+ setAtom
152
+ };
153
+ }, {
154
+ metadata: {
155
+ definedBy: "c/myComponent",
156
+ type: "external"
157
+ }
158
+ });
159
+
160
+ // User authentication state manager
161
+ const useAuth = defineState(({
162
+ atom
163
+ }) => {
164
+ const user = atom(null);
165
+ const isLoggedIn = computed([user], userValue => !!userValue);
166
+ return {
167
+ user,
168
+ isLoggedIn
169
+ };
170
+ }, {
171
+ metadata: {
172
+ definedBy: "c/myComponent_1",
173
+ type: "external"
174
+ }
175
+ });
176
+
177
+ // App settings state manager
178
+ const useSettings = defineState(({
179
+ atom
180
+ }) => {
181
+ const preferences = atom({
182
+ theme: 'light',
183
+ language: 'en'
184
+ });
185
+ return {
186
+ preferences
187
+ };
188
+ }, {
189
+ metadata: {
190
+ definedBy: "c/myComponent_2",
191
+ type: "external"
192
+ }
193
+ });
194
+ export default class ECommerceApp extends LightningElement {
195
+ cart = useShoppingCart();
196
+ auth = useAuth();
197
+ settings = useSettings();
198
+ }"
199
+ `);
200
+ // Additional verification for unique suffixes
201
+ expect(result.code).toContain('definedBy: "c/myComponent"'); // First call - no suffix
202
+ expect(result.code).toContain('definedBy: "c/myComponent_1"'); // Second call
203
+ expect(result.code).toContain('definedBy: "c/myComponent_2"'); // Third call
204
+ });
205
+ test('does NOT transform defineState with 0 arguments', () => {
206
+ const src = (0, common_tags_1.stripIndents) `
207
+ import { LightningElement } from 'lwc';
208
+ import { defineState } from '@lwc/state';
209
+
210
+ export default class MyComponent extends LightningElement {
211
+ connectedCallback() {
212
+ const useSimple = defineState();
213
+ }
214
+ }
215
+ `;
216
+ const result = transformWithStateManagerPlugin(src);
217
+ expect(result.code).toMatchInlineSnapshot(`
218
+ "import { LightningElement } from 'lwc';
219
+ import { defineState } from '@lwc/state';
220
+ export default class MyComponent extends LightningElement {
221
+ connectedCallback() {
222
+ const useSimple = defineState();
223
+ }
224
+ }"
225
+ `);
226
+ expect(result.code).not.toContain('definedBy:');
227
+ });
228
+ test('does NOT transform defineState with 2+ arguments', () => {
229
+ const src = (0, common_tags_1.stripIndents) `
230
+ import { LightningElement } from 'lwc';
231
+ import { defineState } from '@lwc/state';
232
+
233
+ export default class MyComponent extends LightningElement {
234
+ connectedCallback() {
235
+ const useCounter = defineState(
236
+ ({ atom }) => ({ count: atom(0) }),
237
+ { customOption: true }
238
+ );
239
+ }
240
+ }
241
+ `;
242
+ const result = transformWithStateManagerPlugin(src);
243
+ expect(result.code).toMatchInlineSnapshot(`
244
+ "import { LightningElement } from 'lwc';
245
+ import { defineState } from '@lwc/state';
246
+ export default class MyComponent extends LightningElement {
247
+ connectedCallback() {
248
+ const useCounter = defineState(({
249
+ atom
250
+ }) => ({
251
+ count: atom(0)
252
+ }), {
253
+ customOption: true
254
+ });
255
+ }
256
+ }"
257
+ `);
258
+ expect(result.code).not.toContain('definedBy:');
259
+ });
260
+ test('classifies platform bundle type as external (customer modules)', () => {
261
+ const src = (0, common_tags_1.stripIndents) `
262
+ import { LightningElement } from 'lwc';
263
+ import { defineState } from '@lwc/state';
264
+
265
+ const useShoppingCart = defineState(({ atom, computed }) => {
266
+ const items = atom([]);
267
+ const totalPrice = computed([items], (itemsValue) =>
268
+ itemsValue.reduce((sum, item) => sum + item.price, 0)
269
+ );
270
+ return { items, totalPrice };
271
+ });
272
+
273
+ export default class CustomerComponent extends LightningElement {
274
+ shoppingCart = useShoppingCart();
275
+ }
276
+ `;
277
+ const result = transformWithStateManagerPlugin(src, {
278
+ namespace: 'c',
279
+ name: 'customerComponent',
280
+ type: 'platform',
281
+ });
282
+ expect(result.code).toContain('metadata: {');
283
+ expect(result.code).toContain('type: "external"');
284
+ expect(result.code).toContain('definedBy: "c/customerComponent"');
285
+ });
286
+ test('classifies internal bundle type as internal (Salesforce modules)', () => {
287
+ const src = (0, common_tags_1.stripIndents) `
288
+ import { LightningElement } from 'lwc';
289
+ import { defineState } from '@lwc/state';
290
+
291
+ const useMetricsCollector = defineState(({ atom, setAtom }) => {
292
+ const metrics = atom({ pageViews: 0, interactions: 0 });
293
+ const incrementPageViews = () => {
294
+ setAtom(metrics, { ...metrics.value, pageViews: metrics.value.pageViews + 1 });
295
+ };
296
+ return { metrics, incrementPageViews };
297
+ });
298
+
299
+ export default class SalesforceInternalComponent extends LightningElement {
300
+ metricsCollector = useMetricsCollector();
301
+ }
302
+ `;
303
+ const result = transformWithStateManagerPlugin(src, {
304
+ namespace: 'force',
305
+ name: 'metricsCollector',
306
+ type: 'internal',
307
+ });
308
+ expect(result.code).toContain('metadata: {');
309
+ expect(result.code).toContain('type: "internal"');
310
+ expect(result.code).toContain('definedBy: "force/metricsCollector"');
311
+ });
312
+ test('transforms defineState from force/lwcStateManager', () => {
313
+ const src = (0, common_tags_1.stripIndents) `
314
+ import { LightningElement } from 'lwc';
315
+ import { defineState } from 'force/lwcStateManager';
316
+
317
+ const useInternalMetrics = defineState(({ atom, computed }) => {
318
+ const interactions = atom(0);
319
+ const lastActivity = atom(Date.now());
320
+ const isActive = computed([lastActivity], (lastValue) =>
321
+ Date.now() - lastValue < 300000 // 5 minutes
322
+ );
323
+ return { interactions, lastActivity, isActive };
324
+ });
325
+
326
+ export default class InternalComponent extends LightningElement {
327
+ internalMetrics = useInternalMetrics();
328
+ }
329
+ `;
330
+ const result = transformWithStateManagerPlugin(src, {
331
+ namespace: 'force',
332
+ name: 'internalComponent',
333
+ type: 'internal',
334
+ });
335
+ expect(result.code).toMatchInlineSnapshot(`
336
+ "import { LightningElement } from 'lwc';
337
+ import { defineState } from 'force/lwcStateManager';
338
+ const useInternalMetrics = defineState(({
339
+ atom,
340
+ computed
341
+ }) => {
342
+ const interactions = atom(0);
343
+ const lastActivity = atom(Date.now());
344
+ const isActive = computed([lastActivity], lastValue => Date.now() - lastValue < 300000 // 5 minutes
345
+ );
346
+ return {
347
+ interactions,
348
+ lastActivity,
349
+ isActive
350
+ };
351
+ }, {
352
+ metadata: {
353
+ definedBy: "force/internalComponent",
354
+ type: "internal"
355
+ }
356
+ });
357
+ export default class InternalComponent extends LightningElement {
358
+ internalMetrics = useInternalMetrics();
359
+ }"
360
+ `);
361
+ });
362
+ test('does not transform when defineState is not from supported libraries', () => {
363
+ const src = (0, common_tags_1.stripIndents) `
364
+ import { LightningElement } from 'lwc';
365
+ import { defineState } from 'some-other-library';
366
+
367
+ export default class MyComponent extends LightningElement {
368
+ connectedCallback() {
369
+ const useCounter = defineState(({ atom }) => ({ count: atom(0) }));
370
+ }
371
+ }
372
+ `;
373
+ const result = transformWithStateManagerPlugin(src);
374
+ expect(result.code).toMatchInlineSnapshot(`
375
+ "import { LightningElement } from 'lwc';
376
+ import { defineState } from 'some-other-library';
377
+ export default class MyComponent extends LightningElement {
378
+ connectedCallback() {
379
+ const useCounter = defineState(({
380
+ atom
381
+ }) => ({
382
+ count: atom(0)
383
+ }));
384
+ }
385
+ }"
386
+ `);
387
+ expect(result.code).not.toContain('definedBy:');
388
+ });
389
+ test('does not transform when defineState is shadowed by parameter', () => {
390
+ const src = (0, common_tags_1.stripIndents) `
391
+ import { LightningElement } from 'lwc';
392
+ import { defineState } from '@lwc/state';
393
+
394
+ export default class MyComponent extends LightningElement {
395
+ someMethod(defineState) {
396
+ const useCounter = defineState(({ atom }) => ({ count: atom(0) }));
397
+ }
398
+ }
399
+ `;
400
+ const result = transformWithStateManagerPlugin(src);
401
+ expect(result.code).toMatchInlineSnapshot(`
402
+ "import { LightningElement } from 'lwc';
403
+ import { defineState } from '@lwc/state';
404
+ export default class MyComponent extends LightningElement {
405
+ someMethod(defineState) {
406
+ const useCounter = defineState(({
407
+ atom
408
+ }) => ({
409
+ count: atom(0)
410
+ }));
411
+ }
412
+ }"
413
+ `);
414
+ expect(result.code).not.toContain('definedBy:');
415
+ });
416
+ test('does not transform when defineState is shadowed by local variable', () => {
417
+ const src = (0, common_tags_1.stripIndents) `
418
+ import { LightningElement } from 'lwc';
419
+ import { defineState } from '@lwc/state';
420
+
421
+ export default class MyComponent extends LightningElement {
422
+ someMethod() {
423
+ function defineState() {}
424
+ const useCounter = defineState(({ atom }) => ({ count: atom(0) }));
425
+ }
426
+ }
427
+ `;
428
+ const result = transformWithStateManagerPlugin(src);
429
+ expect(result.code).toMatchInlineSnapshot(`
430
+ "import { LightningElement } from 'lwc';
431
+ import { defineState } from '@lwc/state';
432
+ export default class MyComponent extends LightningElement {
433
+ someMethod() {
434
+ function defineState() {}
435
+ const useCounter = defineState(({
436
+ atom
437
+ }) => ({
438
+ count: atom(0)
439
+ }));
440
+ }
441
+ }"
442
+ `);
443
+ expect(result.code).not.toContain('definedBy:');
444
+ });
445
+ test('transforms defineState with complex callback function', () => {
446
+ const src = (0, common_tags_1.stripIndents) `
447
+ import { LightningElement } from 'lwc';
448
+ import { defineState } from '@lwc/state';
449
+
450
+ const useComplexCounter = defineState(({ atom, computed, setAtom }, initialValue = 0) => {
451
+ const count = atom(initialValue);
452
+ const doubleCount = computed([count], (countValue) => countValue * 2);
453
+ const increment = () => setAtom(count, count.value + 1);
454
+ return { count, doubleCount, increment };
455
+ });
456
+
457
+ export default class MyComponent extends LightningElement {
458
+ complexCounter = useComplexCounter();
459
+ }
460
+ `;
461
+ const result = transformWithStateManagerPlugin(src);
462
+ expect(result.code).toContain('definedBy: "c/myComponent"');
463
+ expect(result.code).toContain('type: "external"');
464
+ });
465
+ test('handles aliased imports correctly', () => {
466
+ const src = (0, common_tags_1.stripIndents) `
467
+ import { LightningElement } from 'lwc';
468
+ import { defineState as createState } from '@lwc/state';
469
+
470
+ const useCounter = createState(({ atom }) => ({ count: atom(0) }));
471
+
472
+ export default class MyComponent extends LightningElement {
473
+ counter = useCounter();
474
+ }
475
+ `;
476
+ const result = transformWithStateManagerPlugin(src);
477
+ expect(result.code).toMatchInlineSnapshot(`
478
+ "import { LightningElement } from 'lwc';
479
+ import { defineState as createState } from '@lwc/state';
480
+ const useCounter = createState(({
481
+ atom
482
+ }) => ({
483
+ count: atom(0)
484
+ }), {
485
+ metadata: {
486
+ definedBy: "c/myComponent",
487
+ type: "external"
488
+ }
489
+ });
490
+ export default class MyComponent extends LightningElement {
491
+ counter = useCounter();
492
+ }"
493
+ `);
494
+ });
495
+ test('handles partner namespace with platform bundle type', () => {
496
+ const src = (0, common_tags_1.stripIndents) `
497
+ import { LightningElement } from 'lwc';
498
+ import { defineState } from '@lwc/state';
499
+
500
+ const useProductCatalog = defineState(({ atom, computed, setAtom }) => {
501
+ const products = atom([]);
502
+ const categories = atom([]);
503
+ const filteredProducts = computed([products, categories], (productsValue, categoriesValue) => {
504
+ return productsValue.filter(p => categoriesValue.includes(p.category));
505
+ });
506
+ return { products, categories, filteredProducts, setAtom };
507
+ });
508
+
509
+ export default class PartnerComponent extends LightningElement {
510
+ productCatalog = useProductCatalog();
511
+ }
512
+ `;
513
+ const result = transformWithStateManagerPlugin(src, {
514
+ namespace: 'partners',
515
+ name: 'eCommerceComponent',
516
+ type: 'platform',
517
+ });
518
+ expect(result.code).toContain('metadata: {');
519
+ expect(result.code).toContain('type: "external"');
520
+ expect(result.code).toContain('definedBy: "partners/eCommerceComponent"');
521
+ });
522
+ test('does not transform non-function calls', () => {
523
+ const src = (0, common_tags_1.stripIndents) `
524
+ import { LightningElement } from 'lwc';
525
+ import { defineState } from '@lwc/state';
526
+
527
+ export default class MyComponent extends LightningElement {
528
+ connectedCallback() {
529
+ const fn = defineState;
530
+ const useCounter = fn(({ atom }) => ({ count: atom(0) }));
531
+ }
532
+ }
533
+ `;
534
+ const result = transformWithStateManagerPlugin(src);
535
+ expect(result.code).toMatchInlineSnapshot(`
536
+ "import { LightningElement } from 'lwc';
537
+ import { defineState } from '@lwc/state';
538
+ export default class MyComponent extends LightningElement {
539
+ connectedCallback() {
540
+ const fn = defineState;
541
+ const useCounter = fn(({
542
+ atom
543
+ }) => ({
544
+ count: atom(0)
545
+ }));
546
+ }
547
+ }"
548
+ `);
549
+ expect(result.code).not.toContain('definedBy:');
550
+ });
551
+ test('handles aliased imports from force/lwcStateManager correctly', () => {
552
+ const src = (0, common_tags_1.stripIndents) `
553
+ import { LightningElement } from 'lwc';
554
+ import { defineState as createInternalState } from 'force/lwcStateManager';
555
+
556
+ const useInternalState = createInternalState(({ atom, setAtom }) => {
557
+ const config = atom({ debug: true, telemetry: true });
558
+ const updateConfig = (newConfig) => setAtom(config, { ...config.value, ...newConfig });
559
+ return { config, updateConfig };
560
+ });
561
+
562
+ export default class InternalComponent extends LightningElement {
563
+ internalState = useInternalState();
564
+ }
565
+ `;
566
+ const result = transformWithStateManagerPlugin(src, {
567
+ namespace: 'force',
568
+ name: 'configManager',
569
+ type: 'internal',
570
+ });
571
+ expect(result.code).toMatchInlineSnapshot(`
572
+ "import { LightningElement } from 'lwc';
573
+ import { defineState as createInternalState } from 'force/lwcStateManager';
574
+ const useInternalState = createInternalState(({
575
+ atom,
576
+ setAtom
577
+ }) => {
578
+ const config = atom({
579
+ debug: true,
580
+ telemetry: true
581
+ });
582
+ const updateConfig = newConfig => setAtom(config, {
583
+ ...config.value,
584
+ ...newConfig
585
+ });
586
+ return {
587
+ config,
588
+ updateConfig
589
+ };
590
+ }, {
591
+ metadata: {
592
+ definedBy: "force/configManager",
593
+ type: "internal"
594
+ }
595
+ });
596
+ export default class InternalComponent extends LightningElement {
597
+ internalState = useInternalState();
598
+ }"
599
+ `);
600
+ });
601
+ });
602
+ });
603
+ describe('state manager instrumentation integration', () => {
604
+ it('transforms defineState when plugin is enabled', async () => {
605
+ const { success, result, resultContext: { diagnostics }, } = await (0, compiler_1.compile)(getConfig());
606
+ expect(success).toBe(true);
607
+ expect(diagnostics).toEqual([]);
608
+ expect(result.code).toContain('defineState(');
609
+ expect(result.code).toContain('metadata: {');
610
+ expect(result.code).toContain('definedBy: "x/test"');
611
+ expect(result.code).toContain('type: "external"');
612
+ });
613
+ it('does not transform defineState when plugin is disabled', async () => {
614
+ const { success, result, resultContext: { diagnostics }, } = await (0, compiler_1.compile)(getConfig({
615
+ options: {
616
+ // Plugin not enabled (enableLwcPluginStateManagerInstrumentation omitted)
617
+ },
618
+ }));
619
+ expect(success).toBe(true);
620
+ expect(diagnostics).toEqual([]);
621
+ expect(result.code).toContain('defineState(');
622
+ expect(result.code).not.toContain('metadata: {');
623
+ expect(result.code).not.toContain('definedBy:');
624
+ });
625
+ it('compiles components without defineState normally when plugin is enabled', async () => {
626
+ const { success, result, resultContext: { diagnostics }, } = await (0, compiler_1.compile)(getConfig({
627
+ files: {
628
+ 'test.js': `
629
+ import { LightningElement } from 'lwc';
630
+
631
+ export default class Test extends LightningElement {
632
+ connectedCallback() {
633
+ console.log('Component connected');
634
+ }
635
+ }
636
+ `,
637
+ 'test.html': `
638
+ <template>
639
+ <div>Regular Component Without State</div>
640
+ </template>
641
+ `,
642
+ },
643
+ }));
644
+ expect(success).toBe(true);
645
+ expect(diagnostics).toEqual([]);
646
+ // Should NOT contain any defineState-related code
647
+ expect(result.code).not.toContain('defineState');
648
+ expect(result.code).not.toContain('metadata: {');
649
+ expect(result.code).not.toContain('definedBy:');
650
+ // Should contain the regular component code
651
+ expect(result.code).toContain('Component connected');
652
+ });
653
+ });
654
+ //# sourceMappingURL=compile-state-manager-instrumentation.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compile-state-manager-instrumentation.spec.js","sourceRoot":"","sources":["../../src/__tests__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yEAAyE,EAAE,KAAK,IAAI,EAAE;QACrF,MAAM,EACF,OAAO,EACP,MAAM,EACN,aAAa,EAAE,EAAE,WAAW,EAAE,GACjC,GAAG,MAAM,IAAA,kBAAO,EACb,SAAS,CAAC;YACN,KAAK,EAAE;gBACH,SAAS,EAAE;;;;;;;;iBAQd;gBACG,WAAW,EAAE;;;;iBAIhB;aACA;SACJ,CAAC,CACL,CAAC;QAEF,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC3B,MAAM,CAAC,WAAW,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;QAChC,kDAAkD;QAClD,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,SAAS,CAAC,aAAa,CAAC,CAAC;QACjD,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,SAAS,CAAC,aAAa,CAAC,CAAC;QACjD,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,SAAS,CAAC,YAAY,CAAC,CAAC;QAChD,4CAA4C;QAC5C,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,SAAS,CAAC,qBAAqB,CAAC,CAAC;IACzD,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
@@ -1024,7 +1024,7 @@ describe('compile', () => {
1024
1024
  },
1025
1025
  compilerConfigs: [
1026
1026
  {
1027
- experimentalDynamicComponent: {
1027
+ dynamicImports: {
1028
1028
  loader: '@test/loader',
1029
1029
  },
1030
1030
  },