@arcmantle/lit-jsx 1.0.32 → 1.0.33
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 +109 -11
- package/dist/compiler/attribute-processor.d.ts +5 -0
- package/dist/compiler/attribute-processor.d.ts.map +1 -1
- package/dist/compiler/attribute-processor.js +21 -1
- package/dist/compiler/attribute-processor.js.map +1 -1
- package/dist/compiler/babel-plugin.d.ts +1 -0
- package/dist/compiler/babel-plugin.d.ts.map +1 -1
- package/dist/compiler/babel-plugin.js.map +1 -1
- package/dist/compiler/compiler-utils.d.ts +2 -1
- package/dist/compiler/compiler-utils.d.ts.map +1 -1
- package/dist/compiler/compiler-utils.js +26 -3
- package/dist/compiler/compiler-utils.js.map +1 -1
- package/dist/compiler/config.d.ts +8 -3
- package/dist/compiler/config.d.ts.map +1 -1
- package/dist/compiler/config.js +13 -3
- package/dist/compiler/config.js.map +1 -1
- package/dist/compiler/transpiler.d.ts.map +1 -1
- package/dist/compiler/transpiler.js +31 -13
- package/dist/compiler/transpiler.js.map +1 -1
- package/dist/compiler/vite-plugin.d.ts +3 -1
- package/dist/compiler/vite-plugin.d.ts.map +1 -1
- package/dist/compiler/vite-plugin.js +1 -0
- package/dist/compiler/vite-plugin.js.map +1 -1
- package/package.json +2 -2
- package/src/compiler/attribute-processor.ts +30 -0
- package/src/compiler/babel-plugin.ts +1 -0
- package/src/compiler/compiler-utils.ts +31 -4
- package/src/compiler/config.ts +26 -6
- package/src/compiler/transpiler.ts +31 -12
- package/src/compiler/vite-plugin.ts +4 -1
package/src/compiler/config.ts
CHANGED
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
import type { BabelFile, PluginPass } from '@babel/core';
|
|
2
2
|
|
|
3
|
+
|
|
3
4
|
export type BabelPlugins = NonNullable<NonNullable<babel.TransformOptions['parserOpts']>['plugins']>;
|
|
4
5
|
|
|
5
6
|
|
|
6
|
-
export const babelPlugins: Set<BabelPlugins[number]> = new Set([
|
|
7
|
+
export const babelPlugins: Set<BabelPlugins[number]> = new Set([
|
|
8
|
+
'jsx',
|
|
9
|
+
'typescript',
|
|
10
|
+
'decorators',
|
|
11
|
+
'decoratorAutoAccessors',
|
|
12
|
+
]);
|
|
7
13
|
export const debugMode = { value: false };
|
|
8
14
|
|
|
9
|
-
|
|
15
|
+
export const CE_ATTR_IDENTIFIER = 'static';
|
|
10
16
|
export const COMPONENT_LITERAL_PREFIX = '__$';
|
|
11
17
|
export const WHITESPACE_TAGS: string[] = [ 'pre', 'textarea' ];
|
|
12
18
|
export const SPECIAL_TAGS: string[] = [];
|
|
@@ -97,26 +103,40 @@ export const ERROR_MESSAGES = {
|
|
|
97
103
|
} as const;
|
|
98
104
|
|
|
99
105
|
|
|
106
|
+
interface PluginOptions {
|
|
107
|
+
useCompiledTemplates?: boolean;
|
|
108
|
+
useImportDiscovery?: boolean;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
|
|
100
112
|
export const initializePluginOptions = (file: BabelFile): { useCompiledTemplates?: boolean; } => {
|
|
101
113
|
if (optionsInitialized)
|
|
102
114
|
return options;
|
|
103
115
|
|
|
104
116
|
optionsInitialized = true;
|
|
105
117
|
|
|
106
|
-
const plugin = file.opts?.plugins
|
|
107
|
-
|
|
118
|
+
const plugin = file.opts?.plugins?.find(plugin =>
|
|
119
|
+
(plugin as PluginPass).key === 'lit-jsx-transform') as { options?: PluginOptions; };
|
|
108
120
|
|
|
109
121
|
const pluginOptions = plugin?.options || {};
|
|
122
|
+
pluginOptions.useCompiledTemplates ??= true;
|
|
110
123
|
|
|
111
124
|
for (const [ key, value ] of Object.entries(pluginOptions))
|
|
112
125
|
options[key as keyof typeof options] = value as any;
|
|
113
126
|
|
|
114
127
|
console.log(`Lit JSX plugin options initialized:`, options);
|
|
115
128
|
|
|
116
|
-
|
|
117
129
|
return pluginOptions;
|
|
118
130
|
};
|
|
119
131
|
|
|
120
132
|
|
|
133
|
+
export const getPluginOptions = (file: BabelFile): PluginOptions => {
|
|
134
|
+
const plugin = file.opts?.plugins?.find(plugin =>
|
|
135
|
+
(plugin as PluginPass).key === 'lit-jsx-transform') as { options?: PluginOptions; };
|
|
136
|
+
|
|
137
|
+
return plugin.options ?? {};
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
|
|
121
141
|
let optionsInitialized = false;
|
|
122
|
-
export const options:
|
|
142
|
+
export const options: PluginOptions = {};
|
|
@@ -16,6 +16,7 @@ import {
|
|
|
16
16
|
isJSXElementStatic,
|
|
17
17
|
isJSXFragmentPath,
|
|
18
18
|
isValidOpeningElement,
|
|
19
|
+
normalizeText,
|
|
19
20
|
} from './compiler-utils.js';
|
|
20
21
|
import {
|
|
21
22
|
Ensure,
|
|
@@ -160,10 +161,14 @@ export class TemplateTranspiler extends JSXTranspiler<TemplateContext> {
|
|
|
160
161
|
override children(context: TemplateContext): void {
|
|
161
162
|
for (const [ index, child ] of context.path.node.children.entries()) {
|
|
162
163
|
if (t.isJSXText(child)) {
|
|
163
|
-
if (WHITESPACE_TAGS.includes(context.tagName))
|
|
164
|
+
if (WHITESPACE_TAGS.includes(context.tagName)) {
|
|
164
165
|
context.builder.addText(child.value);
|
|
165
|
-
|
|
166
|
-
|
|
166
|
+
}
|
|
167
|
+
else {
|
|
168
|
+
const normalizedValue = normalizeText(child.value);
|
|
169
|
+
if (normalizedValue)
|
|
170
|
+
context.builder.addText(normalizedValue);
|
|
171
|
+
}
|
|
167
172
|
}
|
|
168
173
|
else if (t.isJSXExpressionContainer(child)) {
|
|
169
174
|
if (t.isJSXEmptyExpression(child.expression))
|
|
@@ -300,9 +305,14 @@ export class TemplateTranspiler extends JSXTranspiler<TemplateContext> {
|
|
|
300
305
|
const child = childPath.node;
|
|
301
306
|
|
|
302
307
|
if (t.isJSXText(child)) {
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
308
|
+
if (WHITESPACE_TAGS.includes(context.tagName)) {
|
|
309
|
+
childrenArray.push(t.stringLiteral(child.value));
|
|
310
|
+
}
|
|
311
|
+
else {
|
|
312
|
+
const normalizedValue = normalizeText(child.value);
|
|
313
|
+
if (normalizedValue)
|
|
314
|
+
childrenArray.push(t.stringLiteral(normalizedValue));
|
|
315
|
+
}
|
|
306
316
|
}
|
|
307
317
|
else if (t.isJSXExpressionContainer(child)) {
|
|
308
318
|
if (t.isJSXEmptyExpression(child.expression))
|
|
@@ -463,10 +473,14 @@ export class CompiledTranspiler extends JSXTranspiler<CompiledContext> {
|
|
|
463
473
|
const child = childPath.node;
|
|
464
474
|
|
|
465
475
|
if (t.isJSXText(child)) {
|
|
466
|
-
if (WHITESPACE_TAGS.includes(context.tagName))
|
|
476
|
+
if (WHITESPACE_TAGS.includes(context.tagName)) {
|
|
467
477
|
context.builder.addText(child.value);
|
|
468
|
-
|
|
469
|
-
|
|
478
|
+
}
|
|
479
|
+
else {
|
|
480
|
+
const normalizedValue = normalizeText(child.value);
|
|
481
|
+
if (normalizedValue)
|
|
482
|
+
context.builder.addText(normalizedValue);
|
|
483
|
+
}
|
|
470
484
|
}
|
|
471
485
|
else if (t.isJSXExpressionContainer(child)) {
|
|
472
486
|
if (t.isJSXEmptyExpression(child.expression))
|
|
@@ -560,9 +574,14 @@ export class CompiledTranspiler extends JSXTranspiler<CompiledContext> {
|
|
|
560
574
|
const child = childPath.node;
|
|
561
575
|
|
|
562
576
|
if (t.isJSXText(child)) {
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
577
|
+
if (WHITESPACE_TAGS.includes(context.tagName)) {
|
|
578
|
+
childrenArray.push(t.stringLiteral(child.value));
|
|
579
|
+
}
|
|
580
|
+
else {
|
|
581
|
+
const normalizedValue = normalizeText(child.value);
|
|
582
|
+
if (normalizedValue)
|
|
583
|
+
childrenArray.push(t.stringLiteral(normalizedValue));
|
|
584
|
+
}
|
|
566
585
|
}
|
|
567
586
|
else if (t.isJSXExpressionContainer(child)) {
|
|
568
587
|
if (t.isJSXEmptyExpression(child.expression))
|
|
@@ -16,8 +16,10 @@ import { ImportDiscovery } from './import-discovery.js';
|
|
|
16
16
|
export const litJsx = (options: {
|
|
17
17
|
/** Enable legacy decorators support */
|
|
18
18
|
legacyDecorators?: boolean;
|
|
19
|
-
/** Enables
|
|
19
|
+
/** Enables support for experimental compiled templates @default true */
|
|
20
20
|
useCompiledTemplates?: boolean;
|
|
21
|
+
/** Opts into the automatic discovery is custom elements instead of using the static attribute */
|
|
22
|
+
useImportDiscovery?: boolean;
|
|
21
23
|
/** Enable debug mode for additional logging */
|
|
22
24
|
debug?: boolean;
|
|
23
25
|
/** Options for the Babel transform */
|
|
@@ -65,6 +67,7 @@ export const litJsx = (options: {
|
|
|
65
67
|
plugins: [
|
|
66
68
|
litJsxBabelPlugin({
|
|
67
69
|
useCompiledTemplates: options.useCompiledTemplates,
|
|
70
|
+
useImportDiscovery: options.useImportDiscovery,
|
|
68
71
|
}),
|
|
69
72
|
],
|
|
70
73
|
ast: false,
|