@arcmantle/lit-jsx 1.0.5 → 1.0.7
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 +22 -16
- package/dist/compiler/babel-plugin.d.ts +4 -0
- package/dist/compiler/babel-plugin.d.ts.map +1 -0
- package/dist/compiler/babel-plugin.js +20 -0
- package/dist/compiler/babel-plugin.js.map +1 -0
- package/dist/compiler/babel-traverse.d.ts +3 -0
- package/dist/compiler/babel-traverse.d.ts.map +1 -0
- package/dist/compiler/babel-traverse.js +7 -0
- package/dist/compiler/babel-traverse.js.map +1 -0
- package/dist/compiler/compiler-utils.d.ts +3 -2
- package/dist/compiler/compiler-utils.d.ts.map +1 -1
- package/dist/compiler/compiler-utils.js +25 -23
- package/dist/compiler/compiler-utils.js.map +1 -1
- package/dist/compiler/config.d.ts +5 -1
- package/dist/compiler/config.d.ts.map +1 -1
- package/dist/compiler/config.js +2 -2
- package/dist/compiler/config.js.map +1 -1
- package/dist/compiler/create-logger.d.ts +3 -0
- package/dist/compiler/create-logger.d.ts.map +1 -0
- package/dist/compiler/create-logger.js +32 -0
- package/dist/compiler/create-logger.js.map +1 -0
- package/dist/compiler/import-discovery.d.ts +51 -0
- package/dist/compiler/import-discovery.d.ts.map +1 -0
- package/dist/compiler/import-discovery.js +325 -0
- package/dist/compiler/import-discovery.js.map +1 -0
- package/dist/compiler/preprocess.d.ts +1 -1
- package/dist/compiler/preprocess.d.ts.map +1 -1
- package/dist/compiler/preprocess.js +5 -4
- package/dist/compiler/preprocess.js.map +1 -1
- package/dist/compiler/transpiler.js +4 -4
- package/dist/compiler/transpiler.js.map +1 -1
- package/dist/compiler/vite-plugin.d.ts +1 -0
- package/dist/compiler/vite-plugin.d.ts.map +1 -1
- package/dist/compiler/vite-plugin.js +9 -13
- package/dist/compiler/vite-plugin.js.map +1 -1
- package/dist/runtime/type-helpers.d.ts +24 -36
- package/dist/runtime/type-helpers.d.ts.map +1 -1
- package/dist/runtime/type-helpers.js +22 -34
- package/dist/runtime/type-helpers.js.map +1 -1
- package/package.json +5 -2
- package/src/compiler/babel-plugin.ts +23 -0
- package/src/compiler/babel-traverse.ts +7 -0
- package/src/compiler/compiler-utils.ts +35 -25
- package/src/compiler/config.ts +7 -2
- package/src/compiler/create-logger.ts +35 -0
- package/src/compiler/import-discovery.ts +460 -0
- package/src/compiler/preprocess.ts +9 -7
- package/src/compiler/transpiler.ts +4 -4
- package/src/compiler/vite-plugin.ts +16 -22
- package/src/runtime/type-helpers.ts +24 -36
- package/dist/compiler/babel-preset.d.ts +0 -6
- package/dist/compiler/babel-preset.d.ts.map +0 -1
- package/dist/compiler/babel-preset.js +0 -27
- package/dist/compiler/babel-preset.js.map +0 -1
- package/src/compiler/babel-preset.ts +0 -34
|
@@ -1,81 +1,69 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Creates a
|
|
2
|
+
* Creates a component that can be used directly in JSX syntax.
|
|
3
3
|
* Also registers the custom element if it hasn't been registered yet.
|
|
4
4
|
*
|
|
5
5
|
* @example
|
|
6
6
|
* ```tsx
|
|
7
|
-
* import {
|
|
7
|
+
* import { toComponent } from 'jsx-lit';
|
|
8
8
|
*
|
|
9
9
|
* export class MyButton extends LitElement {
|
|
10
10
|
* static tagName = 'my-button';
|
|
11
|
-
* static tag = toJSX(MyButton);
|
|
12
|
-
*
|
|
13
|
-
* render() {
|
|
14
|
-
* return html`<button><slot></slot></button>`;
|
|
15
|
-
* }
|
|
16
11
|
* }
|
|
17
12
|
*
|
|
18
|
-
*
|
|
13
|
+
* const MyButtonComponent = toComponent(MyButton);
|
|
14
|
+
*
|
|
15
|
+
* // Usage in JSX - compiler automatically detects this as a custom element
|
|
19
16
|
* const jsx = (
|
|
20
|
-
* <
|
|
17
|
+
* <MyButtonComponent
|
|
21
18
|
* class="my-button"
|
|
22
19
|
* on-click={() => { console.log('Clicked!'); }}
|
|
23
20
|
* />
|
|
24
21
|
* );
|
|
25
22
|
* ```
|
|
26
23
|
*/
|
|
27
|
-
export declare const
|
|
24
|
+
export declare const toComponent: <T extends {
|
|
28
25
|
new (...args: any): any;
|
|
29
26
|
tagName: string;
|
|
30
|
-
}>(element: T) =>
|
|
31
|
-
export type
|
|
27
|
+
}>(element: T) => ToComponent<InstanceType<T>>;
|
|
28
|
+
export type ToComponent<T extends object> = (props: JSX.JSXProps<T>) => string;
|
|
32
29
|
/**
|
|
33
|
-
* Creates a dynamic tag
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
* **IMPORTANT**: Dynamic tag names must use the `.tag` property pattern to be properly
|
|
37
|
-
* compiled to lit-html static templates. Without this pattern, jsx-lit cannot detect
|
|
38
|
-
* and transform the dynamic tag name into efficient static template literals.
|
|
30
|
+
* Creates a dynamic tag that can be used directly in JSX syntax.
|
|
31
|
+
* The compiler automatically detects when this helper is used and compiles
|
|
32
|
+
* it to efficient static lit-html templates.
|
|
39
33
|
*
|
|
40
34
|
* @example
|
|
41
35
|
* ```tsx
|
|
42
36
|
* import { toTag } from 'jsx-lit';
|
|
43
37
|
*
|
|
44
|
-
* //
|
|
38
|
+
* // Creates a dynamic tag that the compiler will recognize
|
|
45
39
|
* const DynamicDiv = toTag('div');
|
|
46
40
|
* const DynamicCustomElement = toTag('my-custom-element');
|
|
47
41
|
*
|
|
48
|
-
* // Usage in JSX
|
|
42
|
+
* // Usage in JSX - compiler automatically handles the transformation
|
|
49
43
|
* function renderConditional({ useDiv }) {
|
|
50
44
|
* const Tag = toTag(useDiv ? 'div' : 'span');
|
|
51
|
-
* return <Tag
|
|
45
|
+
* return <Tag class="dynamic">Content</Tag>;
|
|
52
46
|
* }
|
|
53
47
|
*
|
|
54
|
-
* // Compiles to efficient static templates:
|
|
48
|
+
* // Compiles to efficient static templates automatically:
|
|
55
49
|
* // const Tag = toTag(useDiv ? 'div' : 'span');
|
|
56
|
-
* // const __$Tag = __$literalMap.get(Tag
|
|
50
|
+
* // const __$Tag = __$literalMap.get(Tag);
|
|
57
51
|
* // htmlStatic`<${__$Tag} class="dynamic">Content</${__$Tag}>`
|
|
58
52
|
* ```
|
|
59
53
|
*
|
|
60
54
|
* @example
|
|
61
55
|
* ```tsx
|
|
62
|
-
* // ❌
|
|
63
|
-
* const
|
|
64
|
-
* return <
|
|
65
|
-
*
|
|
66
|
-
* // ❌ Incorrect usage - missing .tag property
|
|
67
|
-
* const BadTag = toTag('div');
|
|
68
|
-
* return <BadTag>Content</BadTag>; // Won't compile correctly
|
|
56
|
+
* // ❌ Without toTag helper - won't compile to static templates
|
|
57
|
+
* const BadTag = 'div';
|
|
58
|
+
* return <BadTag>Content</BadTag>; // This won't work with jsx-lit
|
|
69
59
|
*
|
|
70
|
-
* // ✅
|
|
60
|
+
* // ✅ With toTag helper - compiler automatically optimizes
|
|
71
61
|
* const GoodTag = toTag('div');
|
|
72
|
-
* return <GoodTag
|
|
62
|
+
* return <GoodTag>Content</GoodTag>; // Compiles to static templates
|
|
73
63
|
* ```
|
|
74
64
|
*
|
|
75
65
|
* @param tag - The HTML tag name (standard HTML elements or custom element names)
|
|
76
|
-
* @returns
|
|
66
|
+
* @returns A tag identifier that the compiler recognizes for optimization
|
|
77
67
|
*/
|
|
78
|
-
export declare const toTag: <T extends keyof HTMLElementTagNameMap | (string & {})>(tag: T) =>
|
|
79
|
-
tag: T;
|
|
80
|
-
};
|
|
68
|
+
export declare const toTag: <T extends keyof HTMLElementTagNameMap | (string & {})>(tag: T) => T;
|
|
81
69
|
//# sourceMappingURL=type-helpers.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"type-helpers.d.ts","sourceRoot":"","sources":["../../src/runtime/type-helpers.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"type-helpers.d.ts","sourceRoot":"","sources":["../../src/runtime/type-helpers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,eAAO,MAAM,WAAW,GAAI,CAAC,SAAS;IAAE,KAAI,GAAG,IAAI,EAAE,GAAG,GAAG,GAAG,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;CAAE,EACjF,SAAS,CAAC,KACR,WAAW,CAAC,YAAY,CAAC,CAAC,CAAC,CAY7B,CAAC;AAEF,MAAM,MAAM,WAAW,CAAC,CAAC,SAAS,MAAM,IAAI,CAAC,KAAK,EAAE,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,KAAK,MAAM,CAAC;AAG/E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,eAAO,MAAM,KAAK,GAAI,CAAC,SAAS,MAAM,qBAAqB,GAAG,CAAC,MAAM,GAAG,EAAE,CAAC,EAC1E,KAAK,CAAC,KACJ,CAAQ,CAAC"}
|
|
@@ -1,30 +1,27 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Creates a
|
|
2
|
+
* Creates a component that can be used directly in JSX syntax.
|
|
3
3
|
* Also registers the custom element if it hasn't been registered yet.
|
|
4
4
|
*
|
|
5
5
|
* @example
|
|
6
6
|
* ```tsx
|
|
7
|
-
* import {
|
|
7
|
+
* import { toComponent } from 'jsx-lit';
|
|
8
8
|
*
|
|
9
9
|
* export class MyButton extends LitElement {
|
|
10
10
|
* static tagName = 'my-button';
|
|
11
|
-
* static tag = toJSX(MyButton);
|
|
12
|
-
*
|
|
13
|
-
* render() {
|
|
14
|
-
* return html`<button><slot></slot></button>`;
|
|
15
|
-
* }
|
|
16
11
|
* }
|
|
17
12
|
*
|
|
18
|
-
*
|
|
13
|
+
* const MyButtonComponent = toComponent(MyButton);
|
|
14
|
+
*
|
|
15
|
+
* // Usage in JSX - compiler automatically detects this as a custom element
|
|
19
16
|
* const jsx = (
|
|
20
|
-
* <
|
|
17
|
+
* <MyButtonComponent
|
|
21
18
|
* class="my-button"
|
|
22
19
|
* on-click={() => { console.log('Clicked!'); }}
|
|
23
20
|
* />
|
|
24
21
|
* );
|
|
25
22
|
* ```
|
|
26
23
|
*/
|
|
27
|
-
export const
|
|
24
|
+
export const toComponent = (element) => {
|
|
28
25
|
if (!element.tagName)
|
|
29
26
|
throw new Error('Element must have a static tagName property');
|
|
30
27
|
queueMicrotask(() => {
|
|
@@ -36,52 +33,43 @@ export const toJSX = (element) => {
|
|
|
36
33
|
return element.tagName;
|
|
37
34
|
};
|
|
38
35
|
/**
|
|
39
|
-
* Creates a dynamic tag
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
* **IMPORTANT**: Dynamic tag names must use the `.tag` property pattern to be properly
|
|
43
|
-
* compiled to lit-html static templates. Without this pattern, jsx-lit cannot detect
|
|
44
|
-
* and transform the dynamic tag name into efficient static template literals.
|
|
36
|
+
* Creates a dynamic tag that can be used directly in JSX syntax.
|
|
37
|
+
* The compiler automatically detects when this helper is used and compiles
|
|
38
|
+
* it to efficient static lit-html templates.
|
|
45
39
|
*
|
|
46
40
|
* @example
|
|
47
41
|
* ```tsx
|
|
48
42
|
* import { toTag } from 'jsx-lit';
|
|
49
43
|
*
|
|
50
|
-
* //
|
|
44
|
+
* // Creates a dynamic tag that the compiler will recognize
|
|
51
45
|
* const DynamicDiv = toTag('div');
|
|
52
46
|
* const DynamicCustomElement = toTag('my-custom-element');
|
|
53
47
|
*
|
|
54
|
-
* // Usage in JSX
|
|
48
|
+
* // Usage in JSX - compiler automatically handles the transformation
|
|
55
49
|
* function renderConditional({ useDiv }) {
|
|
56
50
|
* const Tag = toTag(useDiv ? 'div' : 'span');
|
|
57
|
-
* return <Tag
|
|
51
|
+
* return <Tag class="dynamic">Content</Tag>;
|
|
58
52
|
* }
|
|
59
53
|
*
|
|
60
|
-
* // Compiles to efficient static templates:
|
|
54
|
+
* // Compiles to efficient static templates automatically:
|
|
61
55
|
* // const Tag = toTag(useDiv ? 'div' : 'span');
|
|
62
|
-
* // const __$Tag = __$literalMap.get(Tag
|
|
56
|
+
* // const __$Tag = __$literalMap.get(Tag);
|
|
63
57
|
* // htmlStatic`<${__$Tag} class="dynamic">Content</${__$Tag}>`
|
|
64
58
|
* ```
|
|
65
59
|
*
|
|
66
60
|
* @example
|
|
67
61
|
* ```tsx
|
|
68
|
-
* // ❌
|
|
69
|
-
* const
|
|
70
|
-
* return <
|
|
62
|
+
* // ❌ Without toTag helper - won't compile to static templates
|
|
63
|
+
* const BadTag = 'div';
|
|
64
|
+
* return <BadTag>Content</BadTag>; // This won't work with jsx-lit
|
|
71
65
|
*
|
|
72
|
-
* //
|
|
73
|
-
* const BadTag = toTag('div');
|
|
74
|
-
* return <BadTag>Content</BadTag>; // Won't compile correctly
|
|
75
|
-
*
|
|
76
|
-
* // ✅ Correct usage - with .tag property
|
|
66
|
+
* // ✅ With toTag helper - compiler automatically optimizes
|
|
77
67
|
* const GoodTag = toTag('div');
|
|
78
|
-
* return <GoodTag
|
|
68
|
+
* return <GoodTag>Content</GoodTag>; // Compiles to static templates
|
|
79
69
|
* ```
|
|
80
70
|
*
|
|
81
71
|
* @param tag - The HTML tag name (standard HTML elements or custom element names)
|
|
82
|
-
* @returns
|
|
72
|
+
* @returns A tag identifier that the compiler recognizes for optimization
|
|
83
73
|
*/
|
|
84
|
-
export const toTag = (tag) =>
|
|
85
|
-
return { tag };
|
|
86
|
-
};
|
|
74
|
+
export const toTag = (tag) => tag;
|
|
87
75
|
//# sourceMappingURL=type-helpers.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"type-helpers.js","sourceRoot":"","sources":["../../src/runtime/type-helpers.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"type-helpers.js","sourceRoot":"","sources":["../../src/runtime/type-helpers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,CAC1B,OAAU,EACqB,EAAE;IACjC,IAAI,CAAC,OAAO,CAAC,OAAO;QACnB,MAAM,IAAI,KAAK,CAAC,6CAA6C,CAAC,CAAC;IAEhE,cAAc,CAAC,GAAG,EAAE;QACnB,IAAI,UAAU,IAAI,OAAO,IAAI,OAAO,OAAO,CAAC,QAAQ,KAAK,UAAU;YAClE,OAAO,CAAC,QAAQ,EAAE,CAAC;aACf,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC;YAC5C,cAAc,CAAC,MAAM,CAAC,OAAO,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAClD,CAAC,CAAC,CAAC;IAEH,OAAO,OAAO,CAAC,OAAc,CAAC;AAC/B,CAAC,CAAC;AAKF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,MAAM,CAAC,MAAM,KAAK,GAAG,CACpB,GAAM,EACF,EAAE,CAAC,GAAG,CAAC"}
|
package/package.json
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"type": "git",
|
|
10
10
|
"url": "git+https://github.com/arcmantle/lit-jsx.git"
|
|
11
11
|
},
|
|
12
|
-
"version": "1.0.
|
|
12
|
+
"version": "1.0.7",
|
|
13
13
|
"files": [
|
|
14
14
|
"dist",
|
|
15
15
|
"src"
|
|
@@ -33,11 +33,14 @@
|
|
|
33
33
|
"@types/babel__traverse": "^7.20.7",
|
|
34
34
|
"csstype": "^3.1.3",
|
|
35
35
|
"merge-anything": "^6.0.6",
|
|
36
|
+
"oxc-resolver": "^11.5.0",
|
|
37
|
+
"pino": "^9.7.0",
|
|
38
|
+
"pino-pretty": "^13.0.0",
|
|
36
39
|
"validate-html-nesting": "^1.2.1"
|
|
37
40
|
},
|
|
38
41
|
"devDependencies": {
|
|
39
42
|
"@arcmantle/tsconfig": "^1.0.5",
|
|
40
|
-
"@types/node": "^24.0.
|
|
43
|
+
"@types/node": "^24.0.13",
|
|
41
44
|
"lit-html": "^3.3.0",
|
|
42
45
|
"rimraf": "^6.0.1",
|
|
43
46
|
"typescript": "^5.8.3",
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { PluginItem } from '@babel/core';
|
|
2
|
+
import SyntaxJSX from '@babel/plugin-syntax-jsx';
|
|
3
|
+
|
|
4
|
+
import { postprocess } from './postprocess.js';
|
|
5
|
+
import { preprocess } from './preprocess.js';
|
|
6
|
+
import { transformJSXElement } from './transform-jsx.js';
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
/** Compiles jsx to a combination of standard and compiled lit-html */
|
|
10
|
+
export const litJsxBabelPlugin = (): PluginItem => {
|
|
11
|
+
return {
|
|
12
|
+
name: 'lit-jsx-transform',
|
|
13
|
+
inherits: SyntaxJSX.default,
|
|
14
|
+
visitor: {
|
|
15
|
+
JSXElement: transformJSXElement,
|
|
16
|
+
JSXFragment: transformJSXElement,
|
|
17
|
+
Program: {
|
|
18
|
+
enter: preprocess,
|
|
19
|
+
exit: postprocess,
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
} satisfies PluginItem;
|
|
23
|
+
};
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import type { Binding, NodePath } from '@babel/traverse';
|
|
1
|
+
import type { Binding, Hub, NodePath } from '@babel/traverse';
|
|
2
2
|
import * as t from '@babel/types';
|
|
3
3
|
|
|
4
4
|
import { isMathmlTag } from '../shared/mathml-tags.js';
|
|
5
5
|
import { isSvgTag } from '../shared/svg-tags.js';
|
|
6
6
|
import type { ProcessorContext } from './attribute-processor.js';
|
|
7
|
-
import {
|
|
7
|
+
import { ERROR_MESSAGES, SOURCES, VARIABLES } from './config.js';
|
|
8
|
+
import { findElementDefinition } from './import-discovery.js';
|
|
8
9
|
|
|
9
10
|
|
|
10
11
|
export type Values<T> = T[keyof T];
|
|
@@ -25,6 +26,14 @@ export const getProgramFromPath = (path: NodePath): t.Program => {
|
|
|
25
26
|
};
|
|
26
27
|
|
|
27
28
|
|
|
29
|
+
export const getPathFilename = (path: NodePath): string => {
|
|
30
|
+
const hub = path.hub as Hub & { file: { opts: { filename: string; }; }; };
|
|
31
|
+
const currentFileName = hub.file.opts.filename;
|
|
32
|
+
|
|
33
|
+
return currentFileName;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
|
|
28
37
|
export class Ensure {
|
|
29
38
|
|
|
30
39
|
static findProgram(path: NodePath): NodePath<t.Program> {
|
|
@@ -328,9 +337,6 @@ export class Ensure {
|
|
|
328
337
|
): t.Identifier {
|
|
329
338
|
EnsureImport.literalMap(program, path);
|
|
330
339
|
|
|
331
|
-
variableName = variableName.replace(COMPONENT_POSTFIX, '');
|
|
332
|
-
tagName = tagName.replace(COMPONENT_POSTFIX, '');
|
|
333
|
-
|
|
334
340
|
return this.componentTagDeclaration(
|
|
335
341
|
path,
|
|
336
342
|
tagName,
|
|
@@ -342,7 +348,7 @@ export class Ensure {
|
|
|
342
348
|
t.identifier(VARIABLES.LITERAL_MAP),
|
|
343
349
|
t.identifier('get'),
|
|
344
350
|
),
|
|
345
|
-
[ t.identifier(tagName
|
|
351
|
+
[ t.identifier(tagName) ],
|
|
346
352
|
),
|
|
347
353
|
),
|
|
348
354
|
);
|
|
@@ -698,12 +704,21 @@ export const getJSXElementName = (node: t.JSXElement): string => {
|
|
|
698
704
|
};
|
|
699
705
|
|
|
700
706
|
|
|
701
|
-
export const isJSXCustomElementComponent = (
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
707
|
+
export const isJSXCustomElementComponent = (
|
|
708
|
+
path: NodePath<t.JSXElement | t.JSXFragment>,
|
|
709
|
+
): boolean => {
|
|
710
|
+
const node = path.node;
|
|
711
|
+
|
|
712
|
+
if (t.isJSXFragment(node))
|
|
713
|
+
return false;
|
|
714
|
+
|
|
715
|
+
const tagName: string = getJSXElementName(node);
|
|
705
716
|
|
|
706
|
-
if (tagName
|
|
717
|
+
if (!isComponent(tagName))
|
|
718
|
+
return false;
|
|
719
|
+
|
|
720
|
+
const type = findElementDefinition(path.get('openingElement'));
|
|
721
|
+
if (type.type === 'custom-element')
|
|
707
722
|
return true;
|
|
708
723
|
|
|
709
724
|
return false;
|
|
@@ -711,25 +726,20 @@ export const isJSXCustomElementComponent = (nodeOrName: t.JSXElement | string):
|
|
|
711
726
|
|
|
712
727
|
|
|
713
728
|
export const isJSXFunctionElementComponent = (
|
|
714
|
-
|
|
729
|
+
path: NodePath<t.JSXElement | t.JSXFragment>,
|
|
715
730
|
): boolean => {
|
|
716
|
-
|
|
717
|
-
if (typeof pathOrName === 'string') {
|
|
718
|
-
tagName = pathOrName;
|
|
719
|
-
}
|
|
720
|
-
else {
|
|
721
|
-
const node = pathOrName.node;
|
|
722
|
-
// If it's a fragment, we cannot determine the tag name.
|
|
723
|
-
if (t.isJSXFragment(node))
|
|
724
|
-
return false;
|
|
731
|
+
const node = path.node;
|
|
725
732
|
|
|
726
|
-
|
|
727
|
-
|
|
733
|
+
if (t.isJSXFragment(node))
|
|
734
|
+
return false;
|
|
735
|
+
|
|
736
|
+
const tagName: string = getJSXElementName(node);
|
|
728
737
|
|
|
729
738
|
if (!isComponent(tagName))
|
|
730
739
|
return false;
|
|
731
740
|
|
|
732
|
-
|
|
741
|
+
const type = findElementDefinition(path.get('openingElement'));
|
|
742
|
+
if (type.type === 'custom-element')
|
|
733
743
|
return false;
|
|
734
744
|
|
|
735
745
|
return true;
|
|
@@ -749,7 +759,7 @@ export const isJSXFragmentPath = (path: NodePath): path is NodePath<t.JSXFragmen
|
|
|
749
759
|
* @returns true if the template will be static, false otherwise
|
|
750
760
|
*/
|
|
751
761
|
export const isJSXElementStatic = (path: NodePath<t.JSXElement | t.JSXFragment>): boolean => {
|
|
752
|
-
if (t.isJSXElement(path.node) && isJSXCustomElementComponent(path
|
|
762
|
+
if (t.isJSXElement(path.node) && isJSXCustomElementComponent(path))
|
|
753
763
|
return true;
|
|
754
764
|
|
|
755
765
|
for (const childPath of path.get('children')) {
|
package/src/compiler/config.ts
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
export type BabelPlugins = NonNullable<NonNullable<babel.TransformOptions['parserOpts']>['plugins']>;
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
export const babelPlugins: BabelPlugins = [ 'jsx', 'typescript', 'decorators', 'decoratorAutoAccessors' ];
|
|
5
|
+
export const debugMode = { value: false };
|
|
6
|
+
|
|
7
|
+
|
|
2
8
|
export const COMPONENT_LITERAL_PREFIX = '__$';
|
|
3
|
-
export const COMPONENT_POSTFIX = '.tag';
|
|
4
9
|
export const WHITESPACE_TAGS: string[] = [ 'pre', 'textarea' ];
|
|
5
10
|
export const SPECIAL_TAGS: string[] = [];
|
|
6
11
|
export const ATTR_NAMES = {
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import pino, { type Logger } from 'pino';
|
|
2
|
+
import { prettyFactory } from 'pino-pretty';
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
export const createLogger = (name: string, debug?: boolean): Logger<never, boolean> => {
|
|
6
|
+
const prettify = prettyFactory({
|
|
7
|
+
sync: true,
|
|
8
|
+
colorize: true,
|
|
9
|
+
ignore: 'pid,hostname',
|
|
10
|
+
translateTime: 'HH:MM:ss',
|
|
11
|
+
});
|
|
12
|
+
const hooks: pino.LoggerOptions['hooks'] | undefined = {
|
|
13
|
+
streamWrite: (s) => {
|
|
14
|
+
console.log(prettify(s));
|
|
15
|
+
|
|
16
|
+
return '';
|
|
17
|
+
},
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
return pino({
|
|
21
|
+
name,
|
|
22
|
+
level: debug ? 'trace' : 'info',
|
|
23
|
+
hooks,
|
|
24
|
+
//...(debug && {
|
|
25
|
+
// transport: {
|
|
26
|
+
// target: 'pino-pretty',
|
|
27
|
+
// options: {
|
|
28
|
+
// colorize: true,
|
|
29
|
+
// translateTime: 'HH:MM:ss',
|
|
30
|
+
// ignore: 'pid,hostname',
|
|
31
|
+
// },
|
|
32
|
+
// },
|
|
33
|
+
//}),
|
|
34
|
+
});
|
|
35
|
+
};
|