@arcmantle/lit-jsx 1.0.33 → 1.1.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.
- package/README.md +95 -145
- package/dist/compiler/attribute-processor.d.ts +4 -19
- package/dist/compiler/attribute-processor.d.ts.map +1 -1
- package/dist/compiler/attribute-processor.js +1 -38
- package/dist/compiler/attribute-processor.js.map +1 -1
- package/dist/compiler/babel-plugin.d.ts.map +1 -1
- package/dist/compiler/babel-plugin.js +2 -1
- package/dist/compiler/babel-plugin.js.map +1 -1
- package/dist/compiler/compiler-utils.d.ts +7 -0
- package/dist/compiler/compiler-utils.d.ts.map +1 -1
- package/dist/compiler/compiler-utils.js +45 -57
- package/dist/compiler/compiler-utils.js.map +1 -1
- package/dist/compiler/config.d.ts +15 -25
- package/dist/compiler/config.d.ts.map +1 -1
- package/dist/compiler/config.js +15 -25
- package/dist/compiler/config.js.map +1 -1
- package/dist/compiler/oxc-walker.d.ts +4 -4
- package/dist/compiler/oxc-walker.d.ts.map +1 -1
- package/dist/compiler/oxc-walker.js +1 -1
- package/dist/compiler/oxc-walker.js.map +1 -1
- package/dist/compiler/preprocess.d.ts +1 -0
- package/dist/compiler/preprocess.d.ts.map +1 -1
- package/dist/compiler/preprocess.js +31 -0
- package/dist/compiler/preprocess.js.map +1 -1
- package/dist/runtime/choose-component.d.ts +2 -2
- package/dist/runtime/choose-component.d.ts.map +1 -1
- package/dist/runtime/for-component.d.ts +3 -3
- package/dist/runtime/for-component.d.ts.map +1 -1
- package/dist/runtime/for-component.js.map +1 -1
- package/dist/runtime/lit-reexports.d.ts +11 -0
- package/dist/runtime/lit-reexports.d.ts.map +1 -0
- package/dist/runtime/lit-reexports.js +14 -0
- package/dist/runtime/lit-reexports.js.map +1 -0
- package/dist/runtime/show-component.d.ts +4 -4
- package/dist/runtime/show-component.d.ts.map +1 -1
- package/dist/runtime/type-helpers.d.ts +1 -1
- package/dist/runtime/type-helpers.d.ts.map +1 -1
- package/dist/shared/jsx-core.d.ts +83 -0
- package/dist/shared/jsx-core.d.ts.map +1 -0
- package/dist/shared/jsx-core.js +2 -0
- package/dist/shared/jsx-core.js.map +1 -0
- package/dist/shared/jsx-dom.d.ts +26 -0
- package/dist/shared/jsx-dom.d.ts.map +1 -0
- package/dist/shared/jsx-dom.js +2 -0
- package/dist/shared/jsx-dom.js.map +1 -0
- package/dist/shared/jsx-hooks.d.ts +69 -0
- package/dist/shared/jsx-hooks.d.ts.map +1 -0
- package/dist/shared/jsx-hooks.js +2 -0
- package/dist/shared/jsx-hooks.js.map +1 -0
- package/dist/shared/jsx-types.d.ts +3 -2140
- package/dist/shared/jsx-types.d.ts.map +1 -1
- package/dist/shared/jsx-types.js +3 -1
- package/dist/shared/jsx-types.js.map +1 -1
- package/dist/utils.d.ts +1 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +3 -0
- package/dist/utils.js.map +1 -1
- package/package.json +17 -17
- package/src/compiler/attribute-processor.ts +5 -62
- package/src/compiler/babel-plugin.ts +2 -1
- package/src/compiler/compiler-utils.ts +60 -255
- package/src/compiler/config.ts +26 -37
- package/src/compiler/oxc-walker.ts +5 -5
- package/src/compiler/preprocess.ts +41 -0
- package/src/runtime/choose-component.ts +2 -2
- package/src/runtime/for-component.ts +3 -3
- package/src/runtime/lit-reexports.ts +16 -0
- package/src/runtime/show-component.ts +4 -4
- package/src/runtime/type-helpers.ts +1 -1
- package/src/shared/jsx-core.ts +123 -0
- package/src/shared/jsx-dom.ts +29 -0
- package/src/shared/jsx-hooks.ts +86 -0
- package/src/shared/jsx-types.ts +3 -2559
- package/src/utils.ts +15 -0
|
@@ -420,327 +420,132 @@ export class Ensure {
|
|
|
420
420
|
}
|
|
421
421
|
|
|
422
422
|
|
|
423
|
+
interface ImportConfig {
|
|
424
|
+
source: string;
|
|
425
|
+
name: string;
|
|
426
|
+
local: string;
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
const IMPORT_CONFIGS = {
|
|
430
|
+
html: { source: SOURCES.HTML, name: VARIABLES.HTML, local: VARIABLES.HTML_LOCAL },
|
|
431
|
+
htmlStatic: { source: SOURCES.HTML_STATIC, name: VARIABLES.HTML_STATIC, local: VARIABLES.HTML_STATIC_LOCAL },
|
|
432
|
+
svg: { source: SOURCES.SVG, name: VARIABLES.SVG, local: VARIABLES.SVG_LOCAL },
|
|
433
|
+
svgStatic: { source: SOURCES.SVG_STATIC, name: VARIABLES.SVG_STATIC, local: VARIABLES.SVG_STATIC_LOCAL },
|
|
434
|
+
mathml: { source: SOURCES.MATHML, name: VARIABLES.MATHML, local: VARIABLES.MATHML_LOCAL },
|
|
435
|
+
mathmlStatic: { source: SOURCES.MATHML_STATIC, name: VARIABLES.MATHML_STATIC, local: VARIABLES.MATHML_STATIC_LOCAL },
|
|
436
|
+
unsafeStatic: { source: SOURCES.UNSAFE_STATIC, name: VARIABLES.UNSAFE_STATIC, local: VARIABLES.UNSAFE_STATIC_LOCAL },
|
|
437
|
+
createRef: { source: SOURCES.REF, name: VARIABLES.REF, local: VARIABLES.REF_LOCAL },
|
|
438
|
+
styleMap: { source: SOURCES.STYLE_MAP, name: VARIABLES.STYLE_MAP, local: VARIABLES.STYLE_MAP_LOCAL },
|
|
439
|
+
classMap: { source: SOURCES.CLASS_MAP, name: VARIABLES.CLASS_MAP, local: VARIABLES.CLASS_MAP_LOCAL },
|
|
440
|
+
rest: { source: SOURCES.REST, name: VARIABLES.REST, local: VARIABLES.REST },
|
|
441
|
+
literalMap: { source: SOURCES.LITERAL_MAP, name: VARIABLES.LITERAL_MAP, local: VARIABLES.LITERAL_MAP },
|
|
442
|
+
booleanPart: { source: SOURCES.JSX_LIT, name: VARIABLES.BOOLEAN_PART, local: VARIABLES.BOOLEAN_PART },
|
|
443
|
+
attributePart: { source: SOURCES.JSX_LIT, name: VARIABLES.ATTRIBUTE_PART, local: VARIABLES.ATTRIBUTE_PART },
|
|
444
|
+
propertyPart: { source: SOURCES.JSX_LIT, name: VARIABLES.PROPERTY_PART, local: VARIABLES.PROPERTY_PART },
|
|
445
|
+
elementPart: { source: SOURCES.JSX_LIT, name: VARIABLES.ELEMENT_PART, local: VARIABLES.ELEMENT_PART },
|
|
446
|
+
eventPart: { source: SOURCES.JSX_LIT, name: VARIABLES.EVENT_PART, local: VARIABLES.EVENT_PART },
|
|
447
|
+
childPart: { source: SOURCES.JSX_LIT, name: VARIABLES.CHILD_PART, local: VARIABLES.CHILD_PART },
|
|
448
|
+
tTemplateUtil: { source: SOURCES.JSX_LIT, name: VARIABLES.T_TEMPLATE_UTIL, local: VARIABLES.T_TEMPLATE_UTIL },
|
|
449
|
+
} as const;
|
|
450
|
+
|
|
423
451
|
export class EnsureImport {
|
|
424
452
|
|
|
425
|
-
static
|
|
453
|
+
protected static ensureImport(
|
|
454
|
+
config: ImportConfig,
|
|
455
|
+
program: t.Program,
|
|
456
|
+
path: NodePath,
|
|
457
|
+
): void {
|
|
426
458
|
Ensure.import(
|
|
427
|
-
(source) => source ===
|
|
428
|
-
(name) => name ===
|
|
459
|
+
(source) => source === config.source,
|
|
460
|
+
(name) => name === config.name,
|
|
429
461
|
() => t.importDeclaration(
|
|
430
462
|
[
|
|
431
463
|
t.importSpecifier(
|
|
432
|
-
t.identifier(
|
|
433
|
-
t.identifier(
|
|
464
|
+
t.identifier(config.local),
|
|
465
|
+
t.identifier(config.name),
|
|
434
466
|
),
|
|
435
467
|
],
|
|
436
|
-
t.stringLiteral(
|
|
468
|
+
t.stringLiteral(config.source),
|
|
437
469
|
),
|
|
438
470
|
program,
|
|
439
471
|
path,
|
|
440
472
|
);
|
|
441
473
|
}
|
|
442
474
|
|
|
475
|
+
static html(program: t.Program, path: NodePath): void {
|
|
476
|
+
this.ensureImport(IMPORT_CONFIGS.html, program, path);
|
|
477
|
+
}
|
|
478
|
+
|
|
443
479
|
static htmlStatic(program: t.Program, path: NodePath): void {
|
|
444
|
-
|
|
445
|
-
(source) => source === SOURCES.HTML_STATIC || source === SOURCES.HTML_STATIC_ALT,
|
|
446
|
-
(name) => name === VARIABLES.HTML,
|
|
447
|
-
() => t.importDeclaration(
|
|
448
|
-
[
|
|
449
|
-
t.importSpecifier(
|
|
450
|
-
t.identifier(VARIABLES.HTML_STATIC_LOCAL),
|
|
451
|
-
t.identifier(VARIABLES.HTML_STATIC),
|
|
452
|
-
),
|
|
453
|
-
],
|
|
454
|
-
t.stringLiteral(SOURCES.HTML_STATIC),
|
|
455
|
-
),
|
|
456
|
-
program,
|
|
457
|
-
path,
|
|
458
|
-
);
|
|
480
|
+
this.ensureImport(IMPORT_CONFIGS.htmlStatic, program, path);
|
|
459
481
|
}
|
|
460
482
|
|
|
461
483
|
static svg(program: t.Program, path: NodePath): void {
|
|
462
|
-
|
|
463
|
-
(source) => source === SOURCES.SVG || source === SOURCES.SVG_ALT,
|
|
464
|
-
(name) => name === VARIABLES.SVG,
|
|
465
|
-
() => t.importDeclaration(
|
|
466
|
-
[
|
|
467
|
-
t.importSpecifier(
|
|
468
|
-
t.identifier(VARIABLES.SVG_LOCAL),
|
|
469
|
-
t.identifier(VARIABLES.SVG),
|
|
470
|
-
),
|
|
471
|
-
],
|
|
472
|
-
t.stringLiteral(SOURCES.SVG),
|
|
473
|
-
),
|
|
474
|
-
program,
|
|
475
|
-
path,
|
|
476
|
-
);
|
|
484
|
+
this.ensureImport(IMPORT_CONFIGS.svg, program, path);
|
|
477
485
|
}
|
|
478
486
|
|
|
479
487
|
static svgStatic(program: t.Program, path: NodePath): void {
|
|
480
|
-
|
|
481
|
-
(source) => source === SOURCES.SVG_STATIC || source === SOURCES.SVG_STATIC_ALT,
|
|
482
|
-
(name) => name === VARIABLES.SVG,
|
|
483
|
-
() => t.importDeclaration(
|
|
484
|
-
[
|
|
485
|
-
t.importSpecifier(
|
|
486
|
-
t.identifier(VARIABLES.SVG_STATIC_LOCAL),
|
|
487
|
-
t.identifier(VARIABLES.SVG_STATIC),
|
|
488
|
-
),
|
|
489
|
-
],
|
|
490
|
-
t.stringLiteral(SOURCES.SVG_STATIC),
|
|
491
|
-
),
|
|
492
|
-
program,
|
|
493
|
-
path,
|
|
494
|
-
);
|
|
488
|
+
this.ensureImport(IMPORT_CONFIGS.svgStatic, program, path);
|
|
495
489
|
}
|
|
496
490
|
|
|
497
491
|
static mathml(program: t.Program, path: NodePath): void {
|
|
498
|
-
|
|
499
|
-
(source) => source === SOURCES.MATHML || source === SOURCES.MATHML_ALT,
|
|
500
|
-
(name) => name === VARIABLES.MATHML,
|
|
501
|
-
() => t.importDeclaration(
|
|
502
|
-
[
|
|
503
|
-
t.importSpecifier(
|
|
504
|
-
t.identifier(VARIABLES.MATHML_LOCAL),
|
|
505
|
-
t.identifier(VARIABLES.MATHML),
|
|
506
|
-
),
|
|
507
|
-
],
|
|
508
|
-
t.stringLiteral(SOURCES.MATHML),
|
|
509
|
-
),
|
|
510
|
-
program,
|
|
511
|
-
path,
|
|
512
|
-
);
|
|
492
|
+
this.ensureImport(IMPORT_CONFIGS.mathml, program, path);
|
|
513
493
|
}
|
|
514
494
|
|
|
515
495
|
static mathmlStatic(program: t.Program, path: NodePath): void {
|
|
516
|
-
|
|
517
|
-
(source) => source === SOURCES.MATHML_STATIC || source === SOURCES.MATHML_STATIC_ALT,
|
|
518
|
-
(name) => name === VARIABLES.MATHML,
|
|
519
|
-
() => t.importDeclaration(
|
|
520
|
-
[
|
|
521
|
-
t.importSpecifier(
|
|
522
|
-
t.identifier(VARIABLES.MATHML_STATIC_LOCAL),
|
|
523
|
-
t.identifier(VARIABLES.MATHML_STATIC),
|
|
524
|
-
),
|
|
525
|
-
],
|
|
526
|
-
t.stringLiteral(SOURCES.MATHML_STATIC),
|
|
527
|
-
),
|
|
528
|
-
program,
|
|
529
|
-
path,
|
|
530
|
-
);
|
|
496
|
+
this.ensureImport(IMPORT_CONFIGS.mathmlStatic, program, path);
|
|
531
497
|
}
|
|
532
498
|
|
|
533
499
|
static unsafeStatic(program: t.Program, path: NodePath): void {
|
|
534
|
-
|
|
535
|
-
(source) => source === SOURCES.UNSAFE_STATIC || source === SOURCES.UNSAFE_STATIC_ALT,
|
|
536
|
-
(name) => name === VARIABLES.UNSAFE_STATIC,
|
|
537
|
-
() => t.importDeclaration(
|
|
538
|
-
[
|
|
539
|
-
t.importSpecifier(
|
|
540
|
-
t.identifier(VARIABLES.UNSAFE_STATIC_LOCAL),
|
|
541
|
-
t.identifier(VARIABLES.UNSAFE_STATIC),
|
|
542
|
-
),
|
|
543
|
-
],
|
|
544
|
-
t.stringLiteral(SOURCES.UNSAFE_STATIC),
|
|
545
|
-
),
|
|
546
|
-
program,
|
|
547
|
-
path,
|
|
548
|
-
);
|
|
500
|
+
this.ensureImport(IMPORT_CONFIGS.unsafeStatic, program, path);
|
|
549
501
|
}
|
|
550
502
|
|
|
551
503
|
static createRef(program: t.Program, path: NodePath): void {
|
|
552
|
-
|
|
553
|
-
(source) => source === SOURCES.REF_ALT || source === SOURCES.REF,
|
|
554
|
-
(name) => name === VARIABLES.REF,
|
|
555
|
-
() => t.importDeclaration(
|
|
556
|
-
[
|
|
557
|
-
t.importSpecifier(
|
|
558
|
-
t.identifier(VARIABLES.REF_LOCAL),
|
|
559
|
-
t.identifier(VARIABLES.REF),
|
|
560
|
-
),
|
|
561
|
-
],
|
|
562
|
-
t.stringLiteral(SOURCES.REF),
|
|
563
|
-
),
|
|
564
|
-
program,
|
|
565
|
-
path,
|
|
566
|
-
);
|
|
504
|
+
this.ensureImport(IMPORT_CONFIGS.createRef, program, path);
|
|
567
505
|
}
|
|
568
506
|
|
|
569
507
|
static styleMap(program: t.Program, path: NodePath): void {
|
|
570
|
-
|
|
571
|
-
(source) => source === SOURCES.STYLE_MAP_ALT || source === SOURCES.STYLE_MAP,
|
|
572
|
-
(name) => name === VARIABLES.STYLE_MAP,
|
|
573
|
-
() => t.importDeclaration(
|
|
574
|
-
[
|
|
575
|
-
t.importSpecifier(
|
|
576
|
-
t.identifier(VARIABLES.STYLE_MAP_LOCAL),
|
|
577
|
-
t.identifier(VARIABLES.STYLE_MAP),
|
|
578
|
-
),
|
|
579
|
-
],
|
|
580
|
-
t.stringLiteral(SOURCES.STYLE_MAP),
|
|
581
|
-
),
|
|
582
|
-
program,
|
|
583
|
-
path,
|
|
584
|
-
);
|
|
508
|
+
this.ensureImport(IMPORT_CONFIGS.styleMap, program, path);
|
|
585
509
|
}
|
|
586
510
|
|
|
587
511
|
static classMap(program: t.Program, path: NodePath): void {
|
|
588
|
-
|
|
589
|
-
(source) => source === SOURCES.CLASS_MAP_ALT || source === SOURCES.CLASS_MAP,
|
|
590
|
-
(name) => name === VARIABLES.CLASS_MAP,
|
|
591
|
-
() => t.importDeclaration(
|
|
592
|
-
[
|
|
593
|
-
t.importSpecifier(
|
|
594
|
-
t.identifier(VARIABLES.CLASS_MAP_LOCAL),
|
|
595
|
-
t.identifier(VARIABLES.CLASS_MAP),
|
|
596
|
-
),
|
|
597
|
-
],
|
|
598
|
-
t.stringLiteral(SOURCES.CLASS_MAP),
|
|
599
|
-
),
|
|
600
|
-
program,
|
|
601
|
-
path,
|
|
602
|
-
);
|
|
512
|
+
this.ensureImport(IMPORT_CONFIGS.classMap, program, path);
|
|
603
513
|
}
|
|
604
514
|
|
|
605
515
|
static rest(program: t.Program, path: NodePath): void {
|
|
606
|
-
|
|
607
|
-
(source) => source === SOURCES.REST,
|
|
608
|
-
(name) => name === VARIABLES.REST,
|
|
609
|
-
() => t.importDeclaration(
|
|
610
|
-
[
|
|
611
|
-
t.importSpecifier(
|
|
612
|
-
t.identifier(VARIABLES.REST),
|
|
613
|
-
t.identifier(VARIABLES.REST),
|
|
614
|
-
),
|
|
615
|
-
],
|
|
616
|
-
t.stringLiteral(SOURCES.REST),
|
|
617
|
-
),
|
|
618
|
-
program,
|
|
619
|
-
path,
|
|
620
|
-
);
|
|
516
|
+
this.ensureImport(IMPORT_CONFIGS.rest, program, path);
|
|
621
517
|
}
|
|
622
518
|
|
|
623
519
|
static literalMap(program: t.Program, path: NodePath): void {
|
|
624
|
-
|
|
625
|
-
(source) => source === SOURCES.LITERAL_MAP,
|
|
626
|
-
(name) => name === VARIABLES.LITERAL_MAP,
|
|
627
|
-
() => t.importDeclaration(
|
|
628
|
-
[
|
|
629
|
-
t.importSpecifier(
|
|
630
|
-
t.identifier(VARIABLES.LITERAL_MAP),
|
|
631
|
-
t.identifier(VARIABLES.LITERAL_MAP),
|
|
632
|
-
),
|
|
633
|
-
],
|
|
634
|
-
t.stringLiteral(SOURCES.LITERAL_MAP),
|
|
635
|
-
),
|
|
636
|
-
program,
|
|
637
|
-
path,
|
|
638
|
-
);
|
|
520
|
+
this.ensureImport(IMPORT_CONFIGS.literalMap, program, path);
|
|
639
521
|
}
|
|
640
522
|
|
|
641
523
|
static taggedTemplateUtil(program: t.Program, path: NodePath): void {
|
|
642
|
-
|
|
643
|
-
(source) => source === SOURCES.JSX_LIT,
|
|
644
|
-
(name) => name === VARIABLES.TAGGED_TEMPLATE_UTIL,
|
|
645
|
-
() => t.importDeclaration([
|
|
646
|
-
t.importSpecifier(
|
|
647
|
-
t.identifier(VARIABLES.TAGGED_TEMPLATE_UTIL),
|
|
648
|
-
t.identifier(VARIABLES.TAGGED_TEMPLATE_UTIL),
|
|
649
|
-
),
|
|
650
|
-
], t.stringLiteral(SOURCES.JSX_LIT)),
|
|
651
|
-
program,
|
|
652
|
-
path,
|
|
653
|
-
);
|
|
524
|
+
this.ensureImport(IMPORT_CONFIGS.tTemplateUtil, program, path);
|
|
654
525
|
}
|
|
655
526
|
|
|
656
527
|
static booleanPart(program: t.Program, path: NodePath): void {
|
|
657
|
-
|
|
658
|
-
(source) => source === SOURCES.JSX_LIT,
|
|
659
|
-
(name) => name === VARIABLES.BOOLEAN_PART,
|
|
660
|
-
() => t.importDeclaration([
|
|
661
|
-
t.importSpecifier(
|
|
662
|
-
t.identifier(VARIABLES.BOOLEAN_PART),
|
|
663
|
-
t.identifier(VARIABLES.BOOLEAN_PART),
|
|
664
|
-
),
|
|
665
|
-
], t.stringLiteral(SOURCES.JSX_LIT)),
|
|
666
|
-
program,
|
|
667
|
-
path,
|
|
668
|
-
);
|
|
528
|
+
this.ensureImport(IMPORT_CONFIGS.booleanPart, program, path);
|
|
669
529
|
}
|
|
670
530
|
|
|
671
531
|
static attributePart(program: t.Program, path: NodePath): void {
|
|
672
|
-
|
|
673
|
-
(source) => source === SOURCES.JSX_LIT,
|
|
674
|
-
(name) => name === VARIABLES.ATTRIBUTE_PART,
|
|
675
|
-
() => t.importDeclaration([
|
|
676
|
-
t.importSpecifier(
|
|
677
|
-
t.identifier(VARIABLES.ATTRIBUTE_PART),
|
|
678
|
-
t.identifier(VARIABLES.ATTRIBUTE_PART),
|
|
679
|
-
),
|
|
680
|
-
], t.stringLiteral(SOURCES.JSX_LIT)),
|
|
681
|
-
program,
|
|
682
|
-
path,
|
|
683
|
-
);
|
|
532
|
+
this.ensureImport(IMPORT_CONFIGS.attributePart, program, path);
|
|
684
533
|
}
|
|
685
534
|
|
|
686
535
|
static propertyPart(program: t.Program, path: NodePath): void {
|
|
687
|
-
|
|
688
|
-
(source) => source === SOURCES.JSX_LIT,
|
|
689
|
-
(name) => name === VARIABLES.PROPERTY_PART,
|
|
690
|
-
() => t.importDeclaration([
|
|
691
|
-
t.importSpecifier(
|
|
692
|
-
t.identifier(VARIABLES.PROPERTY_PART),
|
|
693
|
-
t.identifier(VARIABLES.PROPERTY_PART),
|
|
694
|
-
),
|
|
695
|
-
], t.stringLiteral(SOURCES.JSX_LIT)),
|
|
696
|
-
program,
|
|
697
|
-
path,
|
|
698
|
-
);
|
|
536
|
+
this.ensureImport(IMPORT_CONFIGS.propertyPart, program, path);
|
|
699
537
|
}
|
|
700
538
|
|
|
701
539
|
static elementPart(program: t.Program, path: NodePath): void {
|
|
702
|
-
|
|
703
|
-
(source) => source === SOURCES.JSX_LIT,
|
|
704
|
-
(name) => name === VARIABLES.ELEMENT_PART,
|
|
705
|
-
() => t.importDeclaration([
|
|
706
|
-
t.importSpecifier(
|
|
707
|
-
t.identifier(VARIABLES.ELEMENT_PART),
|
|
708
|
-
t.identifier(VARIABLES.ELEMENT_PART),
|
|
709
|
-
),
|
|
710
|
-
], t.stringLiteral(SOURCES.JSX_LIT)),
|
|
711
|
-
program,
|
|
712
|
-
path,
|
|
713
|
-
);
|
|
540
|
+
this.ensureImport(IMPORT_CONFIGS.elementPart, program, path);
|
|
714
541
|
}
|
|
715
542
|
|
|
716
543
|
static eventPart(program: t.Program, path: NodePath): void {
|
|
717
|
-
|
|
718
|
-
(source) => source === SOURCES.JSX_LIT,
|
|
719
|
-
(name) => name === VARIABLES.EVENT_PART,
|
|
720
|
-
() => t.importDeclaration([
|
|
721
|
-
t.importSpecifier(
|
|
722
|
-
t.identifier(VARIABLES.EVENT_PART),
|
|
723
|
-
t.identifier(VARIABLES.EVENT_PART),
|
|
724
|
-
),
|
|
725
|
-
], t.stringLiteral(SOURCES.JSX_LIT)),
|
|
726
|
-
program,
|
|
727
|
-
path,
|
|
728
|
-
);
|
|
544
|
+
this.ensureImport(IMPORT_CONFIGS.eventPart, program, path);
|
|
729
545
|
}
|
|
730
546
|
|
|
731
547
|
static childPart(program: t.Program, path: NodePath): void {
|
|
732
|
-
|
|
733
|
-
(source) => source === SOURCES.JSX_LIT,
|
|
734
|
-
(name) => name === VARIABLES.CHILD_PART,
|
|
735
|
-
() => t.importDeclaration([
|
|
736
|
-
t.importSpecifier(
|
|
737
|
-
t.identifier(VARIABLES.CHILD_PART),
|
|
738
|
-
t.identifier(VARIABLES.CHILD_PART),
|
|
739
|
-
),
|
|
740
|
-
], t.stringLiteral(SOURCES.JSX_LIT)),
|
|
741
|
-
program,
|
|
742
|
-
path,
|
|
743
|
-
);
|
|
548
|
+
this.ensureImport(IMPORT_CONFIGS.childPart, program, path);
|
|
744
549
|
}
|
|
745
550
|
|
|
746
551
|
}
|
package/src/compiler/config.ts
CHANGED
|
@@ -21,7 +21,7 @@ export const ATTR_NAMES = {
|
|
|
21
21
|
CLASS_LIST: 'classList',
|
|
22
22
|
STYLE_LIST: 'styleList',
|
|
23
23
|
DIRECTIVE: 'directive',
|
|
24
|
-
EVENT_PREFIX: 'on
|
|
24
|
+
EVENT_PREFIX: 'on',
|
|
25
25
|
} as const;
|
|
26
26
|
export const ATTR_BIND_OBJ_NAME = 'as';
|
|
27
27
|
export const ATTR_VALUES = {
|
|
@@ -31,15 +31,15 @@ export const ATTR_VALUES = {
|
|
|
31
31
|
export const VARIABLES = {
|
|
32
32
|
HTML: 'html',
|
|
33
33
|
HTML_LOCAL: '__$html',
|
|
34
|
-
HTML_STATIC: '
|
|
34
|
+
HTML_STATIC: 'htmlStatic',
|
|
35
35
|
HTML_STATIC_LOCAL: '__$htmlStatic',
|
|
36
36
|
SVG: 'svg',
|
|
37
37
|
SVG_LOCAL: '__$svg',
|
|
38
|
-
SVG_STATIC: '
|
|
38
|
+
SVG_STATIC: 'svgStatic',
|
|
39
39
|
SVG_STATIC_LOCAL: '__$svgStatic',
|
|
40
40
|
MATHML: 'mathml',
|
|
41
41
|
MATHML_LOCAL: '__$mathml',
|
|
42
|
-
MATHML_STATIC: '
|
|
42
|
+
MATHML_STATIC: 'mathmlStatic',
|
|
43
43
|
MATHML_STATIC_LOCAL: '__$mathmlStatic',
|
|
44
44
|
UNSAFE_STATIC: 'unsafeStatic',
|
|
45
45
|
UNSAFE_STATIC_LOCAL: '__$unsafeStatic',
|
|
@@ -49,41 +49,30 @@ export const VARIABLES = {
|
|
|
49
49
|
STYLE_MAP_LOCAL: '__$styleMap',
|
|
50
50
|
REF: 'ref',
|
|
51
51
|
REF_LOCAL: '__$ref',
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
CHILD_PART: 'ChildPart',
|
|
52
|
+
REST: '__$rest',
|
|
53
|
+
LITERAL_MAP: '__$literalMap',
|
|
54
|
+
T_TEMPLATE_UTIL: '__$t',
|
|
55
|
+
BOOLEAN_PART: 'BooleanPart',
|
|
56
|
+
ATTRIBUTE_PART: 'AttributePart',
|
|
57
|
+
PROPERTY_PART: 'PropertyPart',
|
|
58
|
+
ELEMENT_PART: 'ElementPart',
|
|
59
|
+
EVENT_PART: 'EventPart',
|
|
60
|
+
CHILD_PART: 'ChildPart',
|
|
62
61
|
} as const;
|
|
63
62
|
export const SOURCES = {
|
|
64
|
-
HTML:
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
UNSAFE_STATIC_ALT: 'lit/static-html.js',
|
|
78
|
-
REF: 'lit-html/directives/ref.js',
|
|
79
|
-
REF_ALT: 'lit/directives/ref.js',
|
|
80
|
-
CLASS_MAP: 'lit-html/directives/class-map.js',
|
|
81
|
-
CLASS_MAP_ALT: 'lit/directives/class-map.js',
|
|
82
|
-
STYLE_MAP: 'lit-html/directives/style-map.js',
|
|
83
|
-
STYLE_MAP_ALT: 'lit/directives/style-map.js',
|
|
84
|
-
REST: '@arcmantle/lit-jsx',
|
|
85
|
-
LITERAL_MAP: '@arcmantle/lit-jsx',
|
|
86
|
-
JSX_LIT: '@arcmantle/lit-jsx',
|
|
63
|
+
HTML: '@arcmantle/lit-jsx',
|
|
64
|
+
HTML_STATIC: '@arcmantle/lit-jsx',
|
|
65
|
+
SVG: '@arcmantle/lit-jsx',
|
|
66
|
+
SVG_STATIC: '@arcmantle/lit-jsx',
|
|
67
|
+
MATHML: '@arcmantle/lit-jsx',
|
|
68
|
+
MATHML_STATIC: '@arcmantle/lit-jsx',
|
|
69
|
+
UNSAFE_STATIC: '@arcmantle/lit-jsx',
|
|
70
|
+
REF: '@arcmantle/lit-jsx',
|
|
71
|
+
CLASS_MAP: '@arcmantle/lit-jsx',
|
|
72
|
+
STYLE_MAP: '@arcmantle/lit-jsx',
|
|
73
|
+
REST: '@arcmantle/lit-jsx',
|
|
74
|
+
LITERAL_MAP: '@arcmantle/lit-jsx',
|
|
75
|
+
JSX_LIT: '@arcmantle/lit-jsx',
|
|
87
76
|
} as const;
|
|
88
77
|
export const ERROR_MESSAGES = {
|
|
89
78
|
INVALID_INITIAL_ELEMENT: 'Invalid initial element found. The first element must be a JSX element.',
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { type Node, type Program } from 'oxc-parser';
|
|
2
2
|
import { ScopeTracker, walk } from 'oxc-walker';
|
|
3
3
|
|
|
4
4
|
|
|
5
5
|
type WalkerContext = ThisParameterType<NonNullable<Parameters<typeof walk>[1]['enter']>>;
|
|
6
6
|
type WalkerCallbackContext = Parameters<NonNullable<Parameters<typeof walk>[1]['enter']>>[2];
|
|
7
|
-
type NodeWalker<T extends
|
|
8
|
-
node: Extract<
|
|
9
|
-
parent:
|
|
7
|
+
type NodeWalker<T extends Node['type']> = (
|
|
8
|
+
node: Extract<Node, { type: T; }>,
|
|
9
|
+
parent: Node | null,
|
|
10
10
|
ctx: WalkerContext,
|
|
11
11
|
scope: ScopeTracker,
|
|
12
12
|
cbCtx: WalkerCallbackContext
|
|
13
13
|
) => void;
|
|
14
14
|
|
|
15
15
|
|
|
16
|
-
export const oxcWalker = (input:
|
|
16
|
+
export const oxcWalker = (input: Program | Node, options: Partial<{
|
|
17
17
|
callExpression: NodeWalker<'CallExpression'>;
|
|
18
18
|
}>): void => {
|
|
19
19
|
const scopeTracker = new ScopeTracker();
|
|
@@ -76,3 +76,44 @@ export const preprocess: VisitNodeFunction<PluginPass, t.Program> = (path): void
|
|
|
76
76
|
path.traverse(ensureValidJSXNesting);
|
|
77
77
|
path.traverse(ensureValidFunctionsReturningJSX);
|
|
78
78
|
};
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Strips all compiler-only helper calls like `as.prop(x)`, `as.bool(x)`, and `as.tag(x)`.
|
|
83
|
+
*
|
|
84
|
+
* These helpers are declared as type-only globals and must never survive into emitted JS.
|
|
85
|
+
* This runs AFTER JSX transformation, so the JSX transformer has already used as.prop() and
|
|
86
|
+
* as.bool() to determine the correct part types (BooleanPart, PropertyPart, etc).
|
|
87
|
+
*/
|
|
88
|
+
const stripCompilerOnlyAsHelpers: TraverseOptions = {
|
|
89
|
+
CallExpression(path) {
|
|
90
|
+
const { node } = path;
|
|
91
|
+
|
|
92
|
+
if (!t.isMemberExpression(node.callee))
|
|
93
|
+
return;
|
|
94
|
+
|
|
95
|
+
if (!t.isIdentifier(node.callee.object) || node.callee.object.name !== 'as')
|
|
96
|
+
return;
|
|
97
|
+
|
|
98
|
+
if (!t.isIdentifier(node.callee.property))
|
|
99
|
+
return;
|
|
100
|
+
|
|
101
|
+
const name = node.callee.property.name;
|
|
102
|
+
if (name !== 'prop' && name !== 'bool' && name !== 'tag')
|
|
103
|
+
return;
|
|
104
|
+
|
|
105
|
+
if (node.arguments.length !== 1)
|
|
106
|
+
return;
|
|
107
|
+
|
|
108
|
+
const arg = node.arguments[0];
|
|
109
|
+
if (!t.isExpression(arg))
|
|
110
|
+
return;
|
|
111
|
+
|
|
112
|
+
// Strip all as.* helper calls after JSX transformation
|
|
113
|
+
path.replaceWith(arg);
|
|
114
|
+
},
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
export const postprocess: VisitNodeFunction<PluginPass, t.Program> = (path): void => {
|
|
118
|
+
path.traverse(stripCompilerOnlyAsHelpers);
|
|
119
|
+
};
|
|
@@ -4,7 +4,7 @@ import { nothing } from 'lit-html';
|
|
|
4
4
|
type ChooseValue<T> = T extends undefined ? never : T;
|
|
5
5
|
type ChooseChild<T> = [
|
|
6
6
|
condition: (value: ChooseValue<T>) => boolean,
|
|
7
|
-
output: (value: ChooseValue<T>) =>
|
|
7
|
+
output: (value: ChooseValue<T>) => LitJSX.Child,
|
|
8
8
|
];
|
|
9
9
|
|
|
10
10
|
|
|
@@ -39,7 +39,7 @@ type ChooseChild<T> = [
|
|
|
39
39
|
export function Choose<T = undefined>(props: {
|
|
40
40
|
value?: T;
|
|
41
41
|
children: ChooseChild<T> | ChooseChild<T>[];
|
|
42
|
-
}):
|
|
42
|
+
}): LitJSX.Child {
|
|
43
43
|
const children = Array.isArray(props.children.at(-1))
|
|
44
44
|
? props.children as ChooseChild<T>[]
|
|
45
45
|
: [ props.children as ChooseChild<T> ];
|
|
@@ -21,12 +21,12 @@ import { repeat } from 'lit-html/directives/repeat.js';
|
|
|
21
21
|
* </For>
|
|
22
22
|
* ```
|
|
23
23
|
*/
|
|
24
|
-
export function For<T, U extends
|
|
24
|
+
export function For<T, U extends LitJSX.Child>(props: {
|
|
25
25
|
each: readonly T[];
|
|
26
26
|
key?: (item: T, index: number) => any;
|
|
27
|
-
separator?:
|
|
27
|
+
separator?: LitJSX.Child;
|
|
28
28
|
children: (item: T, index: number) => U;
|
|
29
|
-
}):
|
|
29
|
+
}): LitJSX.Child {
|
|
30
30
|
if (props.key) {
|
|
31
31
|
return repeat(
|
|
32
32
|
props.each,
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Re-exports of lit-html functionality used by the transpiler.
|
|
3
|
+
* This allows consumers to use @arcmantle/lit-jsx without having direct lit-html dependencies.
|
|
4
|
+
* Only exports what the transpiler actually generates in its output code.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
// Core template tags
|
|
8
|
+
export { html, mathml, svg } from 'lit-html';
|
|
9
|
+
|
|
10
|
+
// Static template tags
|
|
11
|
+
export { html as htmlStatic, mathml as mathmlStatic, svg as svgStatic, unsafeStatic } from 'lit-html/static.js';
|
|
12
|
+
|
|
13
|
+
// Directives
|
|
14
|
+
export { classMap } from 'lit-html/directives/class-map.js';
|
|
15
|
+
export { ref } from 'lit-html/directives/ref.js';
|
|
16
|
+
export { styleMap } from 'lit-html/directives/style-map.js';
|
|
@@ -26,12 +26,12 @@ import { when } from 'lit-html/directives/when.js';
|
|
|
26
26
|
export function Show<C>(props: {
|
|
27
27
|
when: C;
|
|
28
28
|
children:
|
|
29
|
-
| ((value: NoInfer<C>) =>
|
|
29
|
+
| ((value: NoInfer<C>) => LitJSX.Child)
|
|
30
30
|
| [
|
|
31
|
-
true: ((value: NoInfer<C>) =>
|
|
32
|
-
false: ((value: NoInfer<C>) =>
|
|
31
|
+
true: ((value: NoInfer<C>) => LitJSX.Child),
|
|
32
|
+
false: ((value: NoInfer<C>) => LitJSX.Child),
|
|
33
33
|
];
|
|
34
|
-
}):
|
|
34
|
+
}): LitJSX.Child {
|
|
35
35
|
if (Array.isArray(props.children))
|
|
36
36
|
return when(props.when, props.children[0], props.children[1]);
|
|
37
37
|
|
|
@@ -36,7 +36,7 @@ export const toComponent = <T extends { new(...args: any): any; tagName: string;
|
|
|
36
36
|
};
|
|
37
37
|
|
|
38
38
|
export type ToComponent<T extends object = object> =
|
|
39
|
-
(props:
|
|
39
|
+
(props: LitJSX.JSXProps<T> & { static: any; }) => string;
|
|
40
40
|
|
|
41
41
|
|
|
42
42
|
/**
|