@komaci/esm-generator 258.0.0 → 260.0.402
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.
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const common_shared_1 = require("@komaci/common-shared");
|
|
4
|
+
const metadata_1 = require("@lwc/metadata");
|
|
4
5
|
const functionAstGeneration_1 = require("../functionAstGeneration");
|
|
6
|
+
const index_1 = require("../index");
|
|
5
7
|
describe('getAdgFunctionBody', () => {
|
|
6
8
|
const moduleMetadata = (0, common_shared_1.initModuleMetadataObject)();
|
|
7
9
|
it('includes a statement for factory functions if needed', () => {
|
|
@@ -219,4 +221,207 @@ describe('composeAdgStaticMetadata', () => {
|
|
|
219
221
|
expect(properties[2].value.value).toBeFalsy();
|
|
220
222
|
});
|
|
221
223
|
});
|
|
224
|
+
describe('Actual TypeScript File Processing', () => {
|
|
225
|
+
it('includes .ts files when reading bundles', () => {
|
|
226
|
+
const testFiles = [
|
|
227
|
+
'component.js',
|
|
228
|
+
'component.ts',
|
|
229
|
+
'component.html',
|
|
230
|
+
'component.css',
|
|
231
|
+
'other.txt',
|
|
232
|
+
];
|
|
233
|
+
const LWC_EXT = ['.js', '.mjs', '.css', '.html', '.ts'];
|
|
234
|
+
const filtered = testFiles.filter((filename) => {
|
|
235
|
+
return LWC_EXT.some((ext) => filename.endsWith(ext));
|
|
236
|
+
});
|
|
237
|
+
expect(filtered).toContain('component.ts');
|
|
238
|
+
expect(filtered).not.toContain('other.txt');
|
|
239
|
+
});
|
|
240
|
+
// Test with actual TypeScript syntax
|
|
241
|
+
it('processes TypeScript files with type annotations', () => {
|
|
242
|
+
const typescriptSource = `
|
|
243
|
+
import { LightningElement, api } from 'lwc';
|
|
244
|
+
|
|
245
|
+
interface User {
|
|
246
|
+
id: string;
|
|
247
|
+
name: string;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
export default class TypeScriptComponent extends LightningElement {
|
|
251
|
+
@api recordId: string;
|
|
252
|
+
private users: User[] = [];
|
|
253
|
+
|
|
254
|
+
get userCount(): number {
|
|
255
|
+
return this.users.length;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
handleUserUpdate(user: User): void {
|
|
259
|
+
this.users = [...this.users, user];
|
|
260
|
+
}
|
|
261
|
+
}`;
|
|
262
|
+
// Create a proper KomaciDocument structure
|
|
263
|
+
const komaciDoc = {
|
|
264
|
+
adgs: [{}],
|
|
265
|
+
exports: {
|
|
266
|
+
default: {
|
|
267
|
+
type: 'AdgReference',
|
|
268
|
+
value: 0,
|
|
269
|
+
},
|
|
270
|
+
},
|
|
271
|
+
};
|
|
272
|
+
expect(() => {
|
|
273
|
+
const input = {
|
|
274
|
+
moduleInfo: {
|
|
275
|
+
name: 'typeScriptComponent',
|
|
276
|
+
namespace: 'c',
|
|
277
|
+
type: 'file',
|
|
278
|
+
fileName: 'typeScriptComponent.ts',
|
|
279
|
+
komaciDoc,
|
|
280
|
+
},
|
|
281
|
+
srcFileMap: {
|
|
282
|
+
'typeScriptComponent.ts': typescriptSource,
|
|
283
|
+
},
|
|
284
|
+
};
|
|
285
|
+
(0, index_1.generateKomaciModule)(input);
|
|
286
|
+
}).not.toThrow();
|
|
287
|
+
});
|
|
288
|
+
// Test that ensures TypeScript-specific syntax is parsed correctly
|
|
289
|
+
it('handles TypeScript generics and interfaces', () => {
|
|
290
|
+
const typescriptGenericSource = `
|
|
291
|
+
import { LightningElement } from 'lwc';
|
|
292
|
+
|
|
293
|
+
interface ApiResponse<T> {
|
|
294
|
+
data: T;
|
|
295
|
+
success: boolean;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
export default class GenericComponent<T = any> extends LightningElement {
|
|
299
|
+
private cache: Map<string, ApiResponse<T>> = new Map();
|
|
300
|
+
|
|
301
|
+
get cacheSize(): number {
|
|
302
|
+
return this.cache.size;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
processResponse<U extends T>(response: ApiResponse<U>): U | null {
|
|
306
|
+
if (response.success) {
|
|
307
|
+
return response.data;
|
|
308
|
+
}
|
|
309
|
+
return null;
|
|
310
|
+
}
|
|
311
|
+
}`;
|
|
312
|
+
// Create a proper KomaciDocument structure
|
|
313
|
+
const komaciDoc = {
|
|
314
|
+
adgs: [{}],
|
|
315
|
+
exports: {
|
|
316
|
+
default: {
|
|
317
|
+
type: 'AdgReference',
|
|
318
|
+
value: 0,
|
|
319
|
+
},
|
|
320
|
+
},
|
|
321
|
+
};
|
|
322
|
+
expect(() => {
|
|
323
|
+
const input = {
|
|
324
|
+
moduleInfo: {
|
|
325
|
+
name: 'genericComponent',
|
|
326
|
+
namespace: 'c',
|
|
327
|
+
type: 'file',
|
|
328
|
+
fileName: 'genericComponent.ts',
|
|
329
|
+
komaciDoc,
|
|
330
|
+
},
|
|
331
|
+
srcFileMap: {
|
|
332
|
+
'genericComponent.ts': typescriptGenericSource,
|
|
333
|
+
},
|
|
334
|
+
};
|
|
335
|
+
(0, index_1.generateKomaciModule)(input);
|
|
336
|
+
}).not.toThrow();
|
|
337
|
+
});
|
|
338
|
+
// Test bundle processing with .ts files
|
|
339
|
+
it('processes bundles containing TypeScript files', () => {
|
|
340
|
+
const bundleFiles = [
|
|
341
|
+
{
|
|
342
|
+
fileName: 'component.ts',
|
|
343
|
+
source: `
|
|
344
|
+
import { LightningElement, api } from 'lwc';
|
|
345
|
+
|
|
346
|
+
export default class Component extends LightningElement {
|
|
347
|
+
@api recordId: string;
|
|
348
|
+
|
|
349
|
+
get displayName(): string {
|
|
350
|
+
return 'TypeScript Component';
|
|
351
|
+
}
|
|
352
|
+
}`,
|
|
353
|
+
},
|
|
354
|
+
{
|
|
355
|
+
fileName: 'component.html',
|
|
356
|
+
source: '<template><div>{displayName}</div></template>',
|
|
357
|
+
},
|
|
358
|
+
{
|
|
359
|
+
fileName: 'component.css',
|
|
360
|
+
source: 'div { color: blue; }',
|
|
361
|
+
},
|
|
362
|
+
];
|
|
363
|
+
// Test that bundles with .ts files are processed correctly
|
|
364
|
+
expect(() => {
|
|
365
|
+
const bundleConfig = {
|
|
366
|
+
namespace: 'c',
|
|
367
|
+
name: 'tsComponent',
|
|
368
|
+
type: 'internal',
|
|
369
|
+
namespaceMapping: {},
|
|
370
|
+
npmModuleMapping: {},
|
|
371
|
+
files: bundleFiles,
|
|
372
|
+
enableKomaci: true,
|
|
373
|
+
};
|
|
374
|
+
// This should work with .ts files
|
|
375
|
+
const metadata = (0, metadata_1.collectBundleMetadata)(bundleConfig);
|
|
376
|
+
expect(metadata.files.length).toBeGreaterThan(0);
|
|
377
|
+
const tsFile = metadata.files.find((f) => f.fileName === 'component.ts');
|
|
378
|
+
expect(tsFile).toBeDefined();
|
|
379
|
+
}).not.toThrow();
|
|
380
|
+
});
|
|
381
|
+
// Test that verifies the file extension is properly detected
|
|
382
|
+
it('detects TypeScript files by .ts extension', () => {
|
|
383
|
+
// Create a proper KomaciDocument structure
|
|
384
|
+
const komaciDoc = {
|
|
385
|
+
adgs: [{}],
|
|
386
|
+
exports: {
|
|
387
|
+
default: {
|
|
388
|
+
type: 'AdgReference',
|
|
389
|
+
value: 0,
|
|
390
|
+
},
|
|
391
|
+
},
|
|
392
|
+
};
|
|
393
|
+
const input = {
|
|
394
|
+
moduleInfo: {
|
|
395
|
+
name: 'test',
|
|
396
|
+
namespace: 'c',
|
|
397
|
+
type: 'file',
|
|
398
|
+
fileName: 'test.ts',
|
|
399
|
+
komaciDoc,
|
|
400
|
+
},
|
|
401
|
+
srcFileMap: {
|
|
402
|
+
'test.ts': 'export default class Component {}',
|
|
403
|
+
},
|
|
404
|
+
};
|
|
405
|
+
// Verify the filename extension is preserved and recognized
|
|
406
|
+
expect(input.moduleInfo.fileName).toContain('.ts');
|
|
407
|
+
// The module generation should handle .ts files
|
|
408
|
+
expect(() => (0, index_1.generateKomaciModule)(input)).not.toThrow();
|
|
409
|
+
});
|
|
410
|
+
});
|
|
411
|
+
describe('TypeScript Parser Configuration', () => {
|
|
412
|
+
it('includes TypeScript plugin in Babel parser configuration', () => {
|
|
413
|
+
// This test ensures that when we fix the parser, it includes TS support
|
|
414
|
+
const typescriptCode = `
|
|
415
|
+
interface Props {
|
|
416
|
+
title: string;
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
export default class Component extends LightningElement {
|
|
420
|
+
@api title: string = '';
|
|
421
|
+
}`;
|
|
422
|
+
expect(() => {
|
|
423
|
+
(0, common_shared_1.generateAstFromSrcCode)(typescriptCode);
|
|
424
|
+
}).not.toThrow();
|
|
425
|
+
});
|
|
426
|
+
});
|
|
222
427
|
//# sourceMappingURL=adgAstGeneration.spec.js.map
|
|
@@ -15,7 +15,7 @@ function readBundle(path) {
|
|
|
15
15
|
path = (0, path_1.resolve)(path);
|
|
16
16
|
if ((0, fs_1.existsSync)(path)) {
|
|
17
17
|
const contents = (0, fs_1.readdirSync)(path);
|
|
18
|
-
const LWC_EXT = ['.js', '.mjs', '.css', '.html'];
|
|
18
|
+
const LWC_EXT = ['.js', '.mjs', '.css', '.html', '.ts'];
|
|
19
19
|
const lwcBundleFiles = contents.filter((filename) => {
|
|
20
20
|
return LWC_EXT.includes((0, path_1.extname)(filename));
|
|
21
21
|
});
|
|
@@ -15,7 +15,8 @@ function getComponentSrcJs(generatorInput) {
|
|
|
15
15
|
let sourceCode;
|
|
16
16
|
const moduleName = generatorInput.moduleInfo.name;
|
|
17
17
|
if (generatorInput.srcFileMap) {
|
|
18
|
-
const filename = Object.keys(generatorInput.srcFileMap).find((filename) => filename.endsWith('.js')
|
|
18
|
+
const filename = Object.keys(generatorInput.srcFileMap).find((filename) => (filename.endsWith('.js') || filename.endsWith('.ts')) &&
|
|
19
|
+
filename.startsWith(moduleName));
|
|
19
20
|
if (filename) {
|
|
20
21
|
sourceCode = generatorInput.srcFileMap[filename];
|
|
21
22
|
}
|
package/build/index.js
CHANGED
|
@@ -104,7 +104,7 @@ function processGeneratorInputAndState(input) {
|
|
|
104
104
|
templateMap[input.moduleInfo.name] = input.moduleInfo.komaciDoc;
|
|
105
105
|
sourceFile = (0, genericAstGeneration_1.generateResolvableModule)(input, undefined, templateMap, source);
|
|
106
106
|
}
|
|
107
|
-
else if (fileExt === 'js') {
|
|
107
|
+
else if (fileExt === 'js' || fileExt === 'ts') {
|
|
108
108
|
sourceFile = (0, genericAstGeneration_1.generateResolvableModule)(input, input.moduleInfo.komaciDoc, undefined, source);
|
|
109
109
|
}
|
|
110
110
|
else {
|