@knighted/jsx 1.5.2 → 1.6.1
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 +1 -0
- package/dist/cjs/cli/init.cjs +15 -0
- package/dist/cjs/debug/diagnostics.cjs +57 -0
- package/dist/cjs/debug/diagnostics.d.cts +6 -0
- package/dist/cjs/debug/index.cjs +7 -0
- package/dist/cjs/debug/index.d.cts +2 -0
- package/dist/cjs/internal/attribute-resolution.cjs +22 -4
- package/dist/cjs/internal/attribute-resolution.d.cts +5 -0
- package/dist/cjs/internal/dev-environment.cjs +41 -0
- package/dist/cjs/internal/dev-environment.d.cts +4 -0
- package/dist/cjs/internal/event-bindings.cjs +11 -2
- package/dist/cjs/internal/event-bindings.d.cts +5 -1
- package/dist/cjs/internal/template-diagnostics.cjs +171 -0
- package/dist/cjs/internal/template-diagnostics.d.cts +13 -0
- package/dist/cjs/jsx.cjs +2 -2
- package/dist/cjs/loader/jsx.cjs +72 -20
- package/dist/cjs/loader/jsx.d.cts +6 -1
- package/dist/cjs/node/debug/index.cjs +6 -0
- package/dist/cjs/node/debug/index.d.cts +2 -0
- package/dist/cjs/react/react-jsx.cjs +1 -1
- package/dist/cjs/runtime/shared.cjs +41 -22
- package/dist/cjs/runtime/shared.d.cts +5 -2
- package/dist/cli/init.js +17 -0
- package/dist/debug/diagnostics.d.ts +6 -0
- package/dist/debug/diagnostics.js +52 -0
- package/dist/debug/index.d.ts +2 -0
- package/dist/debug/index.js +3 -0
- package/dist/internal/attribute-resolution.d.ts +5 -0
- package/dist/internal/attribute-resolution.js +20 -3
- package/dist/internal/dev-environment.d.ts +4 -0
- package/dist/internal/dev-environment.js +34 -0
- package/dist/internal/event-bindings.d.ts +5 -1
- package/dist/internal/event-bindings.js +9 -1
- package/dist/internal/template-diagnostics.d.ts +13 -0
- package/dist/internal/template-diagnostics.js +167 -0
- package/dist/jsx.js +3 -3
- package/dist/lite/debug/diagnostics.js +1 -0
- package/dist/lite/debug/index.js +8 -0
- package/dist/lite/index.js +8 -4
- package/dist/lite/node/debug/index.js +8 -0
- package/dist/lite/node/index.js +8 -4
- package/dist/lite/node/react/index.js +7 -3
- package/dist/lite/react/index.js +7 -3
- package/dist/loader/jsx.d.ts +6 -1
- package/dist/loader/jsx.js +72 -20
- package/dist/node/debug/index.d.ts +2 -0
- package/dist/node/debug/index.js +6 -0
- package/dist/react/react-jsx.js +2 -2
- package/dist/runtime/shared.d.ts +5 -2
- package/dist/runtime/shared.js +39 -21
- package/package.json +39 -7
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
const DEFAULT_LABEL = 'oxc-parser';
|
|
2
|
+
const buildTemplateDisplaySource = (templates) => {
|
|
3
|
+
const raw = templates.raw ?? templates;
|
|
4
|
+
let source = raw[0] ?? '';
|
|
5
|
+
const spans = [];
|
|
6
|
+
for (let idx = 0; idx < raw.length - 1; idx++) {
|
|
7
|
+
const label = '${expr#' + idx + '}';
|
|
8
|
+
const templateStart = source.length;
|
|
9
|
+
source += label;
|
|
10
|
+
const templateEnd = source.length;
|
|
11
|
+
spans.push({ index: idx, templateStart, templateEnd, label });
|
|
12
|
+
source += raw[idx + 1] ?? '';
|
|
13
|
+
}
|
|
14
|
+
return { source, spans };
|
|
15
|
+
};
|
|
16
|
+
const combineExpressionSpans = (diagnostics, templateSpans) => {
|
|
17
|
+
const templateSpanMap = new Map();
|
|
18
|
+
templateSpans.forEach(span => {
|
|
19
|
+
templateSpanMap.set(span.index, span);
|
|
20
|
+
});
|
|
21
|
+
return diagnostics.expressionRanges
|
|
22
|
+
.map(span => {
|
|
23
|
+
const templateSpan = templateSpanMap.get(span.index);
|
|
24
|
+
if (!templateSpan) {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
const sourceLength = Math.max(0, span.sourceEnd - span.sourceStart);
|
|
28
|
+
const templateLength = Math.max(0, templateSpan.templateEnd - templateSpan.templateStart);
|
|
29
|
+
return {
|
|
30
|
+
sourceStart: span.sourceStart,
|
|
31
|
+
sourceEnd: span.sourceEnd,
|
|
32
|
+
templateStart: templateSpan.templateStart,
|
|
33
|
+
templateEnd: templateSpan.templateEnd,
|
|
34
|
+
delta: templateLength - sourceLength,
|
|
35
|
+
};
|
|
36
|
+
})
|
|
37
|
+
.filter((span) => Boolean(span))
|
|
38
|
+
.sort((a, b) => a.sourceStart - b.sourceStart);
|
|
39
|
+
};
|
|
40
|
+
const mapIndexToTemplate = (index, spans, templateLength) => {
|
|
41
|
+
if (!Number.isFinite(index) || index <= 0) {
|
|
42
|
+
return 0;
|
|
43
|
+
}
|
|
44
|
+
let delta = 0;
|
|
45
|
+
for (const span of spans) {
|
|
46
|
+
if (index < span.sourceStart) {
|
|
47
|
+
break;
|
|
48
|
+
}
|
|
49
|
+
if (index < span.sourceEnd) {
|
|
50
|
+
const relative = Math.max(0, index - span.sourceStart);
|
|
51
|
+
const templateSpanLength = Math.max(0, span.templateEnd - span.templateStart);
|
|
52
|
+
if (templateSpanLength === 0) {
|
|
53
|
+
return span.templateStart;
|
|
54
|
+
}
|
|
55
|
+
const clamped = Math.min(relative, Math.max(0, templateSpanLength - 1));
|
|
56
|
+
return span.templateStart + clamped;
|
|
57
|
+
}
|
|
58
|
+
delta += span.delta;
|
|
59
|
+
}
|
|
60
|
+
const mapped = index + delta;
|
|
61
|
+
if (mapped <= 0) {
|
|
62
|
+
return 0;
|
|
63
|
+
}
|
|
64
|
+
if (mapped >= templateLength) {
|
|
65
|
+
return templateLength;
|
|
66
|
+
}
|
|
67
|
+
return mapped;
|
|
68
|
+
};
|
|
69
|
+
const getLineAndColumnFromIndex = (source, index) => {
|
|
70
|
+
const limit = Math.max(0, Math.min(index, source.length));
|
|
71
|
+
let line = 1;
|
|
72
|
+
let column = 1;
|
|
73
|
+
for (let idx = 0; idx < limit; idx++) {
|
|
74
|
+
if (source.charCodeAt(idx) === 10) {
|
|
75
|
+
line++;
|
|
76
|
+
column = 1;
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
column++;
|
|
80
|
+
}
|
|
81
|
+
return { line, column };
|
|
82
|
+
};
|
|
83
|
+
const computeLineOffsets = (lines) => {
|
|
84
|
+
const offsets = [];
|
|
85
|
+
let cursor = 0;
|
|
86
|
+
lines.forEach((line, index) => {
|
|
87
|
+
offsets.push(cursor);
|
|
88
|
+
cursor += line.length;
|
|
89
|
+
if (index < lines.length - 1) {
|
|
90
|
+
cursor += 1;
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
return offsets;
|
|
94
|
+
};
|
|
95
|
+
const createPointerLine = (lineNumber, lineText, lineStartOffset, rangeStart, rangeEnd, startLine, endLine) => {
|
|
96
|
+
const lineEndOffset = lineStartOffset + lineText.length;
|
|
97
|
+
const overlapStart = Math.max(rangeStart, lineStartOffset);
|
|
98
|
+
const overlapEnd = Math.min(rangeEnd, lineEndOffset);
|
|
99
|
+
if (overlapEnd > overlapStart) {
|
|
100
|
+
const pointerStart = Math.max(0, overlapStart - lineStartOffset);
|
|
101
|
+
const pointerWidth = Math.max(1, overlapEnd - overlapStart);
|
|
102
|
+
return ' '.repeat(pointerStart) + '^'.repeat(pointerWidth);
|
|
103
|
+
}
|
|
104
|
+
if (lineText.length === 0 && lineNumber >= startLine && lineNumber <= endLine) {
|
|
105
|
+
return '^';
|
|
106
|
+
}
|
|
107
|
+
if (lineNumber === startLine) {
|
|
108
|
+
const caretPos = Math.max(0, rangeStart - lineStartOffset);
|
|
109
|
+
return ' '.repeat(Math.min(caretPos, lineText.length)) + '^';
|
|
110
|
+
}
|
|
111
|
+
return '';
|
|
112
|
+
};
|
|
113
|
+
const buildCodeFrame = (source, start, end, startLine, endLine) => {
|
|
114
|
+
if (!source.length) {
|
|
115
|
+
return '';
|
|
116
|
+
}
|
|
117
|
+
const lines = source.split('\n');
|
|
118
|
+
const offsets = computeLineOffsets(lines);
|
|
119
|
+
const frameStart = Math.max(1, startLine - 1);
|
|
120
|
+
const frameEnd = Math.min(lines.length, endLine + 1);
|
|
121
|
+
const gutterWidth = String(frameEnd).length;
|
|
122
|
+
const frame = [];
|
|
123
|
+
for (let lineNumber = frameStart; lineNumber <= frameEnd; lineNumber++) {
|
|
124
|
+
const lineText = lines[lineNumber - 1] ?? '';
|
|
125
|
+
const gutter = String(lineNumber).padStart(gutterWidth, ' ');
|
|
126
|
+
frame.push(`${gutter} | ${lineText}`);
|
|
127
|
+
const pointer = createPointerLine(lineNumber, lineText, offsets[lineNumber - 1] ?? 0, start, end, startLine, endLine);
|
|
128
|
+
if (pointer) {
|
|
129
|
+
frame.push(`${' '.repeat(gutterWidth)} | ${pointer}`);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
return frame.join('\n');
|
|
133
|
+
};
|
|
134
|
+
export const formatTaggedTemplateParserError = (tagName, templates, diagnostics, error, options) => {
|
|
135
|
+
const label = options?.label ?? DEFAULT_LABEL;
|
|
136
|
+
const fallback = `[${label}] ${error.message}`;
|
|
137
|
+
const primaryLabel = error.labels?.[0];
|
|
138
|
+
if (!primaryLabel) {
|
|
139
|
+
return fallback;
|
|
140
|
+
}
|
|
141
|
+
const { source: templateSource, spans } = buildTemplateDisplaySource(templates);
|
|
142
|
+
const combinedSpans = combineExpressionSpans(diagnostics, spans);
|
|
143
|
+
const mapIndex = (value) => {
|
|
144
|
+
const numeric = typeof value === 'number' ? value : 0;
|
|
145
|
+
return mapIndexToTemplate(numeric, combinedSpans, templateSource.length);
|
|
146
|
+
};
|
|
147
|
+
const startIndex = mapIndex(primaryLabel.start);
|
|
148
|
+
let endIndex = mapIndex(primaryLabel.end);
|
|
149
|
+
if (endIndex <= startIndex) {
|
|
150
|
+
endIndex = Math.min(templateSource.length, startIndex + 1);
|
|
151
|
+
}
|
|
152
|
+
const startLocation = getLineAndColumnFromIndex(templateSource, startIndex);
|
|
153
|
+
const endLocation = getLineAndColumnFromIndex(templateSource, Math.max(startIndex, endIndex - 1));
|
|
154
|
+
const codeframe = buildCodeFrame(templateSource, startIndex, endIndex, startLocation.line, endLocation.line);
|
|
155
|
+
let message = `[${label}] ${error.message}`;
|
|
156
|
+
message += `\n--> ${tagName} template:${startLocation.line}:${startLocation.column}`;
|
|
157
|
+
if (primaryLabel.message) {
|
|
158
|
+
message += `\n${primaryLabel.message}`;
|
|
159
|
+
}
|
|
160
|
+
if (codeframe) {
|
|
161
|
+
message += `\n${codeframe}`;
|
|
162
|
+
}
|
|
163
|
+
if (error.helpMessage) {
|
|
164
|
+
message += `\n${error.helpMessage}`;
|
|
165
|
+
}
|
|
166
|
+
return message;
|
|
167
|
+
};
|
package/dist/jsx.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { parseSync } from 'oxc-parser';
|
|
2
|
-
import { buildTemplate, evaluateExpression, extractRootNode,
|
|
2
|
+
import { buildTemplate, evaluateExpression, extractRootNode, formatTaggedTemplateParserError, getIdentifierName, normalizeJsxTextSegments, parserOptions, } from './runtime/shared.js';
|
|
3
3
|
import { find as findPropertyInfo, html as htmlProperties, svg as svgProperties, } from 'property-information';
|
|
4
4
|
import { createResolveAttributes, } from './internal/attribute-resolution.js';
|
|
5
5
|
import { parseEventPropName, resolveEventHandlerValue, } from './internal/event-bindings.js';
|
|
@@ -113,7 +113,7 @@ const setDomProp = (element, name, value, namespace) => {
|
|
|
113
113
|
}
|
|
114
114
|
const eventBinding = parseEventPropName(name);
|
|
115
115
|
if (eventBinding) {
|
|
116
|
-
const handlerValue = resolveEventHandlerValue(value);
|
|
116
|
+
const handlerValue = resolveEventHandlerValue(name, value);
|
|
117
117
|
if (handlerValue) {
|
|
118
118
|
let options = handlerValue.options ? { ...handlerValue.options } : undefined;
|
|
119
119
|
if (eventBinding.capture) {
|
|
@@ -308,7 +308,7 @@ export const jsx = (templates, ...values) => {
|
|
|
308
308
|
const build = buildTemplate(templates, values);
|
|
309
309
|
const result = parseSync('inline.jsx', build.source, parserOptions);
|
|
310
310
|
if (result.errors.length > 0) {
|
|
311
|
-
throw new Error(
|
|
311
|
+
throw new Error(formatTaggedTemplateParserError('jsx', templates, build.diagnostics, result.errors[0]));
|
|
312
312
|
}
|
|
313
313
|
const root = extractRootNode(result.program);
|
|
314
314
|
const ctx = {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var k=e=>{e?.mode??"env";},A=()=>{};export{A as disableJsxDebugDiagnostics,k as enableJsxDebugDiagnostics};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import {parseSync}from'oxc-parser';import {find,svg,html}from'property-information';var T=null,$=e=>{T=e;},oe=e=>{T?.warnLowercaseEventProp?.(e);},se=e=>{T?.ensureValidDangerouslySetInnerHTML?.(e);},P=e=>{let{getIdentifierName:t,evaluateExpressionWithNamespace:n}=e;return (r,o,s)=>{let i={},p=(a,c)=>{a==="dangerouslySetInnerHTML"&&se(c),i[a]=c;};return r.forEach(a=>{if(a.type==="JSXSpreadAttribute"){let l=n(a.argument,o,s);l&&typeof l=="object"&&!Array.isArray(l)&&Object.assign(i,l);return}let c=t(a.name);if(oe(c),!a.value){p(c,true);return}if(a.value.type==="Literal"){p(c,a.value.value);return}if(a.value.type==="JSXExpressionContainer"){if(a.value.expression.type==="JSXEmptyExpression")return;p(c,n(a.value.expression,o,s));}}),i}};var L=null,O=e=>{L=e;},j="Capture",I=e=>e.endsWith(j)?{eventName:e.slice(0,-j.length),capture:true}:{eventName:e,capture:false},_=e=>{if(!e.startsWith("on"))return null;if(e.startsWith("on:")){let r=e.slice(3);if(!r)return null;let o=I(r);return o.eventName?o:null}let t=e.slice(2);if(!t)return null;let n=I(t);return n.eventName?{eventName:n.eventName.toLowerCase(),capture:n.capture}:null},H=e=>!e||typeof e!="object"?false:"handleEvent"in e&&typeof e.handleEvent=="function",ae=e=>{if(!e||typeof e!="object"||!("handler"in e))return false;let t=e.handler;return typeof t=="function"?true:H(t)},ie=(e,t)=>{L?.onInvalidHandler?.(e,t);},F=(e,t)=>{if(typeof t=="function"||H(t))return {listener:t};if(!ae(t))return ie(e,t),null;let n=t,r=n.options?{...n.options}:void 0,o=(s,i)=>{i!=null&&(r||(r={}),r[s]=i);};return o("capture",n.capture),o("once",n.once),o("passive",n.passive),o("signal",n.signal??void 0),{listener:n.handler,options:r}};var pe="@knighted/jsx",B=e=>`${pe}: ${e}`,J=()=>typeof process<"u"&&process.env?.KNIGHTED_JSX_DEBUG==="1",C=e=>{if(e===null)return "null";if(e===void 0)return "undefined";if(typeof e=="function")return e.name?`function ${e.name}`:"function";if(Array.isArray(e))return "array";if(typeof e=="object"){let t=e.constructor;return t&&typeof t.name=="string"&&t.name&&t.name!=="Object"?`${t.name} instance`:"object"}return typeof e},b=e=>new Error(B(e)),W=(e,t=false)=>{!t&&!J()||typeof console<"u"&&typeof console.warn=="function"&&console.warn(B(e));};var ce=e=>e>="a"&&e<="z",S="env",A=()=>S==="always"||S==="env"&&J(),le=()=>S==="always",me={warnLowercaseEventProp(e){if(!A()||!e.startsWith("on")||e.startsWith("on:")||e.length<3)return;let t=e[2]??"";if(!ce(t))return;let n=`${e.slice(0,2)}${t.toUpperCase()}${e.slice(3)}`;W(`Use camelCase DOM event props when targeting runtime jsx templates. Received "${e}"; did you mean "${n}"?`,le());},ensureValidDangerouslySetInnerHTML(e){if(!A())return;if(!e||typeof e!="object"||Array.isArray(e))throw b("dangerouslySetInnerHTML expects an object with a string __html field.");let t=e.__html;if(typeof t!="string")throw b(`dangerouslySetInnerHTML.__html must be a string but received ${C(t)}.`)}},ue={onInvalidHandler(e,t){if(A())throw b(`The "${e}" prop expects a function, EventListenerObject, or descriptor ({ handler }) but received ${C(t)}.`)}},V=e=>{S=e?.mode,$(me),O(ue);};var de="oxc-parser",ge=e=>{let t=e.raw??e,n=t[0]??"",r=[];for(let o=0;o<t.length-1;o++){let s="${expr#"+o+"}",i=n.length;n+=s;let p=n.length;r.push({index:o,templateStart:i,templateEnd:p,label:s}),n+=t[o+1]??"";}return {source:n,spans:r}},fe=(e,t)=>{let n=new Map;return t.forEach(r=>{n.set(r.index,r);}),e.expressionRanges.map(r=>{let o=n.get(r.index);if(!o)return null;let s=Math.max(0,r.sourceEnd-r.sourceStart),i=Math.max(0,o.templateEnd-o.templateStart);return {sourceStart:r.sourceStart,sourceEnd:r.sourceEnd,templateStart:o.templateStart,templateEnd:o.templateEnd,delta:i-s}}).filter(r=>!!r).sort((r,o)=>r.sourceStart-o.sourceStart)},xe=(e,t,n)=>{if(!Number.isFinite(e)||e<=0)return 0;let r=0;for(let s of t){if(e<s.sourceStart)break;if(e<s.sourceEnd){let i=Math.max(0,e-s.sourceStart),p=Math.max(0,s.templateEnd-s.templateStart);if(p===0)return s.templateStart;let a=Math.min(i,Math.max(0,p-1));return s.templateStart+a}r+=s.delta;}let o=e+r;return o<=0?0:o>=n?n:o},U=(e,t)=>{let n=Math.max(0,Math.min(t,e.length)),r=1,o=1;for(let s=0;s<n;s++){if(e.charCodeAt(s)===10){r++,o=1;continue}o++;}return {line:r,column:o}},ye=e=>{let t=[],n=0;return e.forEach((r,o)=>{t.push(n),n+=r.length,o<e.length-1&&(n+=1);}),t},Ee=(e,t,n,r,o,s,i)=>{let p=n+t.length,a=Math.max(r,n),c=Math.min(o,p);if(c>a){let l=Math.max(0,a-n),u=Math.max(1,c-a);return " ".repeat(l)+"^".repeat(u)}if(t.length===0&&e>=s&&e<=i)return "^";if(e===s){let l=Math.max(0,r-n);return " ".repeat(Math.min(l,t.length))+"^"}return ""},he=(e,t,n,r,o)=>{if(!e.length)return "";let s=e.split(`
|
|
2
|
+
`),i=ye(s),p=Math.max(1,r-1),a=Math.min(s.length,o+1),c=String(a).length,l=[];for(let u=p;u<=a;u++){let d=s[u-1]??"",m=String(u).padStart(c," ");l.push(`${m} | ${d}`);let g=Ee(u,d,i[u-1]??0,t,n,r,o);g&&l.push(`${" ".repeat(c)} | ${g}`);}return l.join(`
|
|
3
|
+
`)},k=(e,t,n,r,o)=>{let s=de,i=`[${s}] ${r.message}`,p=r.labels?.[0];if(!p)return i;let{source:a,spans:c}=ge(t),l=fe(n,c),u=y=>xe(typeof y=="number"?y:0,l,a.length),d=u(p.start),m=u(p.end);m<=d&&(m=Math.min(a.length,d+1));let g=U(a,d),x=U(a,Math.max(d,m-1)),h=he(a,d,m,g.line,x.line),f=`[${s}] ${r.message}`;return f+=`
|
|
4
|
+
--> ${e} template:${g.line}:${g.column}`,p.message&&(f+=`
|
|
5
|
+
${p.message}`),h&&(f+=`
|
|
6
|
+
${h}`),r.helpMessage&&(f+=`
|
|
7
|
+
${r.helpMessage}`),f};var be=/<\s*$/,Se=/<\/\s*$/,K="__KX_EXPR__",z=new RegExp(`${K}\\d+_\\d+__`,"g"),we=0;var G={lang:"jsx",sourceType:"module",range:true,preserveParens:true},Z=e=>{for(let t of e.body)if(t.type==="ExpressionStatement"){let n=t.expression;if(n.type==="JSXElement"||n.type==="JSXFragment")return n}throw new Error("The jsx template must contain a single JSX element or fragment.")},w=e=>{switch(e.type){case "JSXIdentifier":return e.name;case "JSXNamespacedName":return `${e.namespace.name}:${e.name.name}`;case "JSXMemberExpression":return `${w(e.object)}.${e.property.name}`;default:return ""}},v=(e,t)=>{if(!e||typeof e!="object")return;let n=e;typeof n.type=="string"&&(t(n),Object.values(n).forEach(r=>{if(r){if(Array.isArray(r)){r.forEach(o=>v(o,t));return}typeof r=="object"&&v(r,t);}}));},q=(e,t)=>{let n=e.replace(/\r/g,"").replace(/\n\s+/g," "),r=e.match(/^\s*/)?.[0]??"",o=e.match(/\s*$/)?.[0]??"",s=/\n/.test(r),i=/\n/.test(o),p=n;if(s&&(p=p.replace(/^\s+/,"")),i&&(p=p.replace(/\s+$/,"")),p.length===0||p.trim().length===0)return [];let a=[];z.lastIndex=0;let c=0,l;for(;l=z.exec(p);){let d=l.index,m=p.slice(c,d);m&&a.push(m);let g=l[0];t.has(g)?a.push(t.get(g)):a.push(g),c=d+g.length;}let u=p.slice(c);return u&&a.push(u),a},Te=(e,t)=>{let n=new Set;return v(e,r=>{r.type==="Identifier"&&t.placeholders.has(r.name)&&n.add(r.name);}),Array.from(n)},Q=(e,t,n)=>{if(e.type==="JSXElement"||e.type==="JSXFragment")return n(e);if(!("range"in e)||!e.range)throw new Error("Unable to evaluate expression: missing source range information.");let[r,o]=e.range,s=t.source.slice(r,o),i=Te(e,t);try{let p=new Function(...i,`"use strict"; return (${s});`),a=i.map(c=>t.placeholders.get(c));return p(...a)}catch(p){throw new Error(`Failed to evaluate expression ${s}: ${p.message}`)}},Je=e=>{let t=e.replace(/[^a-zA-Z0-9_$]/g,"");return t?/[A-Za-z_$]/.test(t[0])?t:`Component${t}`:"Component"},Ce=(e,t,n)=>{let r=n.get(e);if(r)return r;let o=e.displayName||e.name||`Component${t.length}`,s=Je(o??""),i=s,p=1;for(;t.some(c=>c.name===i);)i=`${s}${p++}`;let a={name:i,value:e};return t.push(a),n.set(e,a),a},Y=(e,t)=>{let n=e.raw??e,r=new Map,o=[],s=new Map,i=n[0]??"",p=we++,a=0,c=[];for(let l=0;l<t.length;l++){let u=n[l]??"",d=n[l+1]??"",m=t[l],g=be.test(u)||Se.test(u),x;if(g&&typeof m=="function")x=Ce(m,o,s).name;else if(g&&typeof m=="string")x=m;else {let y=`${K}${p}_${a++}__`;r.set(y,m),x=y;}let h=i.length;i+=x;let f=i.length;c.push({index:l,sourceStart:h,sourceEnd:f}),i+=d;}return {source:i,placeholders:r,bindings:o,diagnostics:{expressionRanges:c}}};var Ne=()=>{if(typeof document>"u"||typeof document.createElement!="function")throw new Error("The jsx template tag requires a DOM-like environment (document missing).")},Xe=e=>typeof Node>"u"?false:e instanceof Node||e instanceof DocumentFragment,Re=e=>!e||typeof e=="string"?false:typeof e[Symbol.iterator]=="function",te=e=>!e||typeof e!="object"&&typeof e!="function"?false:typeof e.then=="function",Me={xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace",xmlns:"http://www.w3.org/2000/xmlns/"},ne=e=>{if(!(!e||e==="html"||e==="svg"))return Me[e]},$e=e=>e==="svg"?svg:html,D=(e,t,n)=>{let r=ne(t.space),o=String(n);if(r){e.setAttributeNS(r,t.attribute,o);return}e.setAttribute(t.attribute,o);},ee=(e,t)=>{let n=ne(t.space);if(n){e.removeAttributeNS(n,t.attribute);return}e.removeAttribute(t.attribute);},N=(e,t)=>Array.isArray(e)?e.filter(Boolean).join(t):e,Pe=(e,t,n)=>t==="svg"||!n.property||n.property.includes(":")?false:n.property in e,je=(e,t,n,r)=>{if(n==null)return;if(t==="dangerouslySetInnerHTML"&&typeof n=="object"&&n&&"__html"in n){e.innerHTML=String(n.__html??"");return}if(t==="ref"){if(typeof n=="function"){n(e);return}if(n&&typeof n=="object"){n.current=e;return}}if(t==="style"&&typeof n=="object"&&n!==null){let c=n,l=e.style;if(!l)return;let u=l;Object.entries(c).forEach(([d,m])=>{if(m!=null){if(d.startsWith("--")){l.setProperty(d,String(m));return}u[d]=m;}});return}let o=_(t);if(o){let c=F(t,n);if(c){let l=c.options?{...c.options}:void 0;o.capture&&(l?l.capture=true:l={capture:true}),e.addEventListener(o.eventName,c.listener,l);return}}let s=find($e(r),t),i=e,p=Pe(e,r,s);if(s.mustUseProperty){let c=s.boolean?!!n:n;i[s.property]=c;return}if(s.boolean){let c=!!n;p&&(i[s.property]=c),c?D(e,s,""):ee(e,s);return}let a=n;if(s.spaceSeparated?a=N(n," "):s.commaSeparated?a=N(n,","):s.commaOrSpaceSeparated&&(a=N(n," ")),s.booleanish&&typeof a=="boolean"&&(a=a?"true":"false"),s.overloadedBoolean){if(a===false){ee(e,s);return}if(a===true){D(e,s,"");return}}if(p){i[s.property]=a;return}a!==false&&D(e,s,a);},E=(e,t)=>{if(t!=null&&typeof t!="boolean"){if(te(t))throw new Error("Async values are not supported inside jsx template results.");if(Array.isArray(t)){t.forEach(n=>E(e,n));return}if(Re(t)){for(let n of t)E(e,n);return}if(Xe(t)){e.appendChild(t);return}e.appendChild(document.createTextNode(String(t)));}},X=(e,t,n)=>Q(e,t,r=>M(r,t,n)),re=P({getIdentifierName:w,evaluateExpressionWithNamespace:X}),Ie=(e,t,n,r)=>{let o=re(t,n,r);Object.entries(o).forEach(([s,i])=>{if(s!=="key"){if(s==="children"){E(e,i);return}je(e,s,i,r);}});},R=(e,t,n)=>{let r=[];return e.forEach(o=>{switch(o.type){case "JSXText":{q(o.value,t.placeholders).forEach(i=>{r.push(i);});break}case "JSXExpressionContainer":{if(o.expression.type==="JSXEmptyExpression")break;r.push(X(o.expression,t,n));break}case "JSXSpreadChild":{let s=X(o.expression,t,n);s!=null&&r.push(s);break}case "JSXElement":case "JSXFragment":{r.push(M(o,t,n));break}}}),r},Le=(e,t,n,r)=>{let o=re(e.openingElement.attributes,t,r),s=R(e.children,t,r);s.length===1?o.children=s[0]:s.length>1&&(o.children=s);let i=n(o);if(te(i))throw new Error("Async jsx components are not supported.");return i},Oe=(e,t,n)=>{let r=e.openingElement,o=w(r.name),s=t.components.get(o);if(s)return Le(e,t,s,n);if(/[A-Z]/.test(o[0]??""))throw new Error(`Unknown component "${o}". Did you interpolate it with the template literal?`);let i=o==="svg"?"svg":n,p=o==="foreignObject"?null:i,a=i==="svg"?document.createElementNS("http://www.w3.org/2000/svg",o):document.createElement(o);return Ie(a,r.attributes,t,i),R(e.children,t,p).forEach(l=>E(a,l)),a},M=(e,t,n)=>{if(e.type==="JSXFragment"){let r=document.createDocumentFragment();return R(e.children,t,n).forEach(s=>E(r,s)),r}return Oe(e,t,n)},_e=(e,...t)=>{Ne();let n=Y(e,t),r=parseSync("inline.jsx",n.source,G);if(r.errors.length>0)throw new Error(k("jsx",e,n.diagnostics,r.errors[0]));let o=Z(r.program),s={source:n.source,placeholders:n.placeholders,components:new Map(n.bindings.map(i=>[i.name,i.value]))};return M(o,s,null)};V({mode:"always"});
|
|
8
|
+
export{_e as jsx};
|
package/dist/lite/index.js
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import {parseSync}from'oxc-parser';import {find,svg,html}from'property-information';var
|
|
2
|
-
${n.
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import {parseSync}from'oxc-parser';import {find,svg,html}from'property-information';var z="oxc-parser",K=e=>{let n=e.raw??e,t=n[0]??"",r=[];for(let o=0;o<n.length-1;o++){let s="${expr#"+o+"}",i=t.length;t+=s;let p=t.length;r.push({index:o,templateStart:i,templateEnd:p,label:s}),t+=n[o+1]??"";}return {source:t,spans:r}},Z=(e,n)=>{let t=new Map;return n.forEach(r=>{t.set(r.index,r);}),e.expressionRanges.map(r=>{let o=t.get(r.index);if(!o)return null;let s=Math.max(0,r.sourceEnd-r.sourceStart),i=Math.max(0,o.templateEnd-o.templateStart);return {sourceStart:r.sourceStart,sourceEnd:r.sourceEnd,templateStart:o.templateStart,templateEnd:o.templateEnd,delta:i-s}}).filter(r=>!!r).sort((r,o)=>r.sourceStart-o.sourceStart)},G=(e,n,t)=>{if(!Number.isFinite(e)||e<=0)return 0;let r=0;for(let s of n){if(e<s.sourceStart)break;if(e<s.sourceEnd){let i=Math.max(0,e-s.sourceStart),p=Math.max(0,s.templateEnd-s.templateStart);if(p===0)return s.templateStart;let a=Math.min(i,Math.max(0,p-1));return s.templateStart+a}r+=s.delta;}let o=e+r;return o<=0?0:o>=t?t:o},N=(e,n)=>{let t=Math.max(0,Math.min(n,e.length)),r=1,o=1;for(let s=0;s<t;s++){if(e.charCodeAt(s)===10){r++,o=1;continue}o++;}return {line:r,column:o}},q=e=>{let n=[],t=0;return e.forEach((r,o)=>{n.push(t),t+=r.length,o<e.length-1&&(t+=1);}),n},Q=(e,n,t,r,o,s,i)=>{let p=t+n.length,a=Math.max(r,t),c=Math.min(o,p);if(c>a){let l=Math.max(0,a-t),u=Math.max(1,c-a);return " ".repeat(l)+"^".repeat(u)}if(n.length===0&&e>=s&&e<=i)return "^";if(e===s){let l=Math.max(0,r-t);return " ".repeat(Math.min(l,n.length))+"^"}return ""},Y=(e,n,t,r,o)=>{if(!e.length)return "";let s=e.split(`
|
|
2
|
+
`),i=q(s),p=Math.max(1,r-1),a=Math.min(s.length,o+1),c=String(a).length,l=[];for(let u=p;u<=a;u++){let d=s[u-1]??"",m=String(u).padStart(c," ");l.push(`${m} | ${d}`);let g=Q(u,d,i[u-1]??0,n,t,r,o);g&&l.push(`${" ".repeat(c)} | ${g}`);}return l.join(`
|
|
3
|
+
`)},S=(e,n,t,r,o)=>{let s=z,i=`[${s}] ${r.message}`,p=r.labels?.[0];if(!p)return i;let{source:a,spans:c}=K(n),l=Z(t,c),u=y=>G(typeof y=="number"?y:0,l,a.length),d=u(p.start),m=u(p.end);m<=d&&(m=Math.min(a.length,d+1));let g=N(a,d),x=N(a,Math.max(d,m-1)),h=Y(a,d,m,g.line,x.line),f=`[${s}] ${r.message}`;return f+=`
|
|
4
|
+
--> ${e} template:${g.line}:${g.column}`,p.message&&(f+=`
|
|
5
|
+
${p.message}`),h&&(f+=`
|
|
6
|
+
${h}`),r.helpMessage&&(f+=`
|
|
7
|
+
${r.helpMessage}`),f};var ee=/<\s*$/,te=/<\/\s*$/,X="__KX_EXPR__",v=new RegExp(`${X}\\d+_\\d+__`,"g"),ne=0;var R={lang:"jsx",sourceType:"module",range:true,preserveParens:true},P=e=>{for(let n of e.body)if(n.type==="ExpressionStatement"){let t=n.expression;if(t.type==="JSXElement"||t.type==="JSXFragment")return t}throw new Error("The jsx template must contain a single JSX element or fragment.")},b=e=>{switch(e.type){case "JSXIdentifier":return e.name;case "JSXNamespacedName":return `${e.namespace.name}:${e.name.name}`;case "JSXMemberExpression":return `${b(e.object)}.${e.property.name}`;default:return ""}},T=(e,n)=>{if(!e||typeof e!="object")return;let t=e;typeof t.type=="string"&&(n(t),Object.values(t).forEach(r=>{if(r){if(Array.isArray(r)){r.forEach(o=>T(o,n));return}typeof r=="object"&&T(r,n);}}));},M=(e,n)=>{let t=e.replace(/\r/g,"").replace(/\n\s+/g," "),r=e.match(/^\s*/)?.[0]??"",o=e.match(/\s*$/)?.[0]??"",s=/\n/.test(r),i=/\n/.test(o),p=t;if(s&&(p=p.replace(/^\s+/,"")),i&&(p=p.replace(/\s+$/,"")),p.length===0||p.trim().length===0)return [];let a=[];v.lastIndex=0;let c=0,l;for(;l=v.exec(p);){let d=l.index,m=p.slice(c,d);m&&a.push(m);let g=l[0];n.has(g)?a.push(n.get(g)):a.push(g),c=d+g.length;}let u=p.slice(c);return u&&a.push(u),a},re=(e,n)=>{let t=new Set;return T(e,r=>{r.type==="Identifier"&&n.placeholders.has(r.name)&&t.add(r.name);}),Array.from(t)},D=(e,n,t)=>{if(e.type==="JSXElement"||e.type==="JSXFragment")return t(e);if(!("range"in e)||!e.range)throw new Error("Unable to evaluate expression: missing source range information.");let[r,o]=e.range,s=n.source.slice(r,o),i=re(e,n);try{let p=new Function(...i,`"use strict"; return (${s});`),a=i.map(c=>n.placeholders.get(c));return p(...a)}catch(p){throw new Error(`Failed to evaluate expression ${s}: ${p.message}`)}},oe=e=>{let n=e.replace(/[^a-zA-Z0-9_$]/g,"");return n?/[A-Za-z_$]/.test(n[0])?n:`Component${n}`:"Component"},se=(e,n,t)=>{let r=t.get(e);if(r)return r;let o=e.displayName||e.name||`Component${n.length}`,s=oe(o??""),i=s,p=1;for(;n.some(c=>c.name===i);)i=`${s}${p++}`;let a={name:i,value:e};return n.push(a),t.set(e,a),a},I=(e,n)=>{let t=e.raw??e,r=new Map,o=[],s=new Map,i=t[0]??"",p=ne++,a=0,c=[];for(let l=0;l<n.length;l++){let u=t[l]??"",d=t[l+1]??"",m=n[l],g=ee.test(u)||te.test(u),x;if(g&&typeof m=="function")x=se(m,o,s).name;else if(g&&typeof m=="string")x=m;else {let y=`${X}${p}_${a++}__`;r.set(y,m),x=y;}let h=i.length;i+=x;let f=i.length;c.push({index:l,sourceStart:h,sourceEnd:f}),i+=d;}return {source:i,placeholders:r,bindings:o,diagnostics:{expressionRanges:c}}};var j=e=>{let{getIdentifierName:n,evaluateExpressionWithNamespace:t}=e;return (r,o,s)=>{let i={},p=(a,c)=>{i[a]=c;};return r.forEach(a=>{if(a.type==="JSXSpreadAttribute"){let l=t(a.argument,o,s);l&&typeof l=="object"&&!Array.isArray(l)&&Object.assign(i,l);return}let c=n(a.name);if(!a.value){p(c,true);return}if(a.value.type==="Literal"){p(c,a.value.value);return}if(a.value.type==="JSXExpressionContainer"){if(a.value.expression.type==="JSXEmptyExpression")return;p(c,t(a.value.expression,o,s));}}),i}};var $="Capture",O=e=>e.endsWith($)?{eventName:e.slice(0,-$.length),capture:true}:{eventName:e,capture:false},F=e=>{if(!e.startsWith("on"))return null;if(e.startsWith("on:")){let r=e.slice(3);if(!r)return null;let o=O(r);return o.eventName?o:null}let n=e.slice(2);if(!n)return null;let t=O(n);return t.eventName?{eventName:t.eventName.toLowerCase(),capture:t.capture}:null},_=e=>!e||typeof e!="object"?false:"handleEvent"in e&&typeof e.handleEvent=="function",ce=e=>{if(!e||typeof e!="object"||!("handler"in e))return false;let n=e.handler;return typeof n=="function"?true:_(n)},H=(e,n)=>{if(typeof n=="function"||_(n))return {listener:n};if(!ce(n))return null;let t=n,r=t.options?{...t.options}:void 0,o=(s,i)=>{i!=null&&(r||(r={}),r[s]=i);};return o("capture",t.capture),o("once",t.once),o("passive",t.passive),o("signal",t.signal??void 0),{listener:t.handler,options:r}};var fe=()=>{if(typeof document>"u"||typeof document.createElement!="function")throw new Error("The jsx template tag requires a DOM-like environment (document missing).")},xe=e=>typeof Node>"u"?false:e instanceof Node||e instanceof DocumentFragment,ye=e=>!e||typeof e=="string"?false:typeof e[Symbol.iterator]=="function",W=e=>!e||typeof e!="object"&&typeof e!="function"?false:typeof e.then=="function",Ee={xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace",xmlns:"http://www.w3.org/2000/xmlns/"},V=e=>{if(!(!e||e==="html"||e==="svg"))return Ee[e]},he=e=>e==="svg"?svg:html,w=(e,n,t)=>{let r=V(n.space),o=String(t);if(r){e.setAttributeNS(r,n.attribute,o);return}e.setAttribute(n.attribute,o);},B=(e,n)=>{let t=V(n.space);if(t){e.removeAttributeNS(t,n.attribute);return}e.removeAttribute(n.attribute);},C=(e,n)=>Array.isArray(e)?e.filter(Boolean).join(n):e,be=(e,n,t)=>n==="svg"||!t.property||t.property.includes(":")?false:t.property in e,Se=(e,n,t,r)=>{if(t==null)return;if(n==="dangerouslySetInnerHTML"&&typeof t=="object"&&t&&"__html"in t){e.innerHTML=String(t.__html??"");return}if(n==="ref"){if(typeof t=="function"){t(e);return}if(t&&typeof t=="object"){t.current=e;return}}if(n==="style"&&typeof t=="object"&&t!==null){let c=t,l=e.style;if(!l)return;let u=l;Object.entries(c).forEach(([d,m])=>{if(m!=null){if(d.startsWith("--")){l.setProperty(d,String(m));return}u[d]=m;}});return}let o=F(n);if(o){let c=H(n,t);if(c){let l=c.options?{...c.options}:void 0;o.capture&&(l?l.capture=true:l={capture:true}),e.addEventListener(o.eventName,c.listener,l);return}}let s=find(he(r),n),i=e,p=be(e,r,s);if(s.mustUseProperty){let c=s.boolean?!!t:t;i[s.property]=c;return}if(s.boolean){let c=!!t;p&&(i[s.property]=c),c?w(e,s,""):B(e,s);return}let a=t;if(s.spaceSeparated?a=C(t," "):s.commaSeparated?a=C(t,","):s.commaOrSpaceSeparated&&(a=C(t," ")),s.booleanish&&typeof a=="boolean"&&(a=a?"true":"false"),s.overloadedBoolean){if(a===false){B(e,s);return}if(a===true){w(e,s,"");return}}if(p){i[s.property]=a;return}a!==false&&w(e,s,a);},E=(e,n)=>{if(n!=null&&typeof n!="boolean"){if(W(n))throw new Error("Async values are not supported inside jsx template results.");if(Array.isArray(n)){n.forEach(t=>E(e,t));return}if(ye(n)){for(let t of n)E(e,t);return}if(xe(n)){e.appendChild(n);return}e.appendChild(document.createTextNode(String(n)));}},J=(e,n,t)=>D(e,n,r=>k(r,n,t)),U=j({getIdentifierName:b,evaluateExpressionWithNamespace:J}),Te=(e,n,t,r)=>{let o=U(n,t,r);Object.entries(o).forEach(([s,i])=>{if(s!=="key"){if(s==="children"){E(e,i);return}Se(e,s,i,r);}});},A=(e,n,t)=>{let r=[];return e.forEach(o=>{switch(o.type){case "JSXText":{M(o.value,n.placeholders).forEach(i=>{r.push(i);});break}case "JSXExpressionContainer":{if(o.expression.type==="JSXEmptyExpression")break;r.push(J(o.expression,n,t));break}case "JSXSpreadChild":{let s=J(o.expression,n,t);s!=null&&r.push(s);break}case "JSXElement":case "JSXFragment":{r.push(k(o,n,t));break}}}),r},we=(e,n,t,r)=>{let o=U(e.openingElement.attributes,n,r),s=A(e.children,n,r);s.length===1?o.children=s[0]:s.length>1&&(o.children=s);let i=t(o);if(W(i))throw new Error("Async jsx components are not supported.");return i},Ce=(e,n,t)=>{let r=e.openingElement,o=b(r.name),s=n.components.get(o);if(s)return we(e,n,s,t);if(/[A-Z]/.test(o[0]??""))throw new Error(`Unknown component "${o}". Did you interpolate it with the template literal?`);let i=o==="svg"?"svg":t,p=o==="foreignObject"?null:i,a=i==="svg"?document.createElementNS("http://www.w3.org/2000/svg",o):document.createElement(o);return Te(a,r.attributes,n,i),A(e.children,n,p).forEach(l=>E(a,l)),a},k=(e,n,t)=>{if(e.type==="JSXFragment"){let r=document.createDocumentFragment();return A(e.children,n,t).forEach(s=>E(r,s)),r}return Ce(e,n,t)},Je=(e,...n)=>{fe();let t=I(e,n),r=parseSync("inline.jsx",t.source,R);if(r.errors.length>0)throw new Error(S("jsx",e,t.diagnostics,r.errors[0]));let o=P(r.program),s={source:t.source,placeholders:t.placeholders,components:new Map(t.bindings.map(i=>[i.name,i.value]))};return k(o,s,null)};
|
|
8
|
+
export{Je as jsx};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import {createRequire}from'module';import {parseSync}from'oxc-parser';import {find,svg,html}from'property-information';var T=null,I=e=>{T=e;},me=e=>{T?.warnLowercaseEventProp?.(e);},ue=e=>{T?.ensureValidDangerouslySetInnerHTML?.(e);},P=e=>{let{getIdentifierName:t,evaluateExpressionWithNamespace:n}=e;return (r,o,s)=>{let i={},p=(a,c)=>{a==="dangerouslySetInnerHTML"&&ue(c),i[a]=c;};return r.forEach(a=>{if(a.type==="JSXSpreadAttribute"){let l=n(a.argument,o,s);l&&typeof l=="object"&&!Array.isArray(l)&&Object.assign(i,l);return}let c=t(a.name);if(me(c),!a.value){p(c,true);return}if(a.value.type==="Literal"){p(c,a.value.value);return}if(a.value.type==="JSXExpressionContainer"){if(a.value.expression.type==="JSXEmptyExpression")return;p(c,n(a.value.expression,o,s));}}),i}};var _=null,H=e=>{_=e;},$="Capture",O=e=>e.endsWith($)?{eventName:e.slice(0,-$.length),capture:true}:{eventName:e,capture:false},F=e=>{if(!e.startsWith("on"))return null;if(e.startsWith("on:")){let r=e.slice(3);if(!r)return null;let o=O(r);return o.eventName?o:null}let t=e.slice(2);if(!t)return null;let n=O(t);return n.eventName?{eventName:n.eventName.toLowerCase(),capture:n.capture}:null},W=e=>!e||typeof e!="object"?false:"handleEvent"in e&&typeof e.handleEvent=="function",de=e=>{if(!e||typeof e!="object"||!("handler"in e))return false;let t=e.handler;return typeof t=="function"?true:W(t)},fe=(e,t)=>{_?.onInvalidHandler?.(e,t);},B=(e,t)=>{if(typeof t=="function"||W(t))return {listener:t};if(!de(t))return fe(e,t),null;let n=t,r=n.options?{...n.options}:void 0,o=(s,i)=>{i!=null&&(r||(r={}),r[s]=i);};return o("capture",n.capture),o("once",n.once),o("passive",n.passive),o("signal",n.signal??void 0),{listener:n.handler,options:r}};var ge="@knighted/jsx",V=e=>`${ge}: ${e}`,J=()=>typeof process<"u"&&process.env?.KNIGHTED_JSX_DEBUG==="1",C=e=>{if(e===null)return "null";if(e===void 0)return "undefined";if(typeof e=="function")return e.name?`function ${e.name}`:"function";if(Array.isArray(e))return "array";if(typeof e=="object"){let t=e.constructor;return t&&typeof t.name=="string"&&t.name&&t.name!=="Object"?`${t.name} instance`:"object"}return typeof e},b=e=>new Error(V(e)),U=(e,t=false)=>{!t&&!J()||typeof console<"u"&&typeof console.warn=="function"&&console.warn(V(e));};var xe=e=>e>="a"&&e<="z",S="env",k=()=>S==="always"||S==="env"&&J(),ye=()=>S==="always",he={warnLowercaseEventProp(e){if(!k()||!e.startsWith("on")||e.startsWith("on:")||e.length<3)return;let t=e[2]??"";if(!xe(t))return;let n=`${e.slice(0,2)}${t.toUpperCase()}${e.slice(3)}`;U(`Use camelCase DOM event props when targeting runtime jsx templates. Received "${e}"; did you mean "${n}"?`,ye());},ensureValidDangerouslySetInnerHTML(e){if(!k())return;if(!e||typeof e!="object"||Array.isArray(e))throw b("dangerouslySetInnerHTML expects an object with a string __html field.");let t=e.__html;if(typeof t!="string")throw b(`dangerouslySetInnerHTML.__html must be a string but received ${C(t)}.`)}},Ee={onInvalidHandler(e,t){if(k())throw b(`The "${e}" prop expects a function, EventListenerObject, or descriptor ({ handler }) but received ${C(t)}.`)}},G=e=>{S=e?.mode,I(he),H(Ee);};var Se=createRequire(import.meta.url),q=()=>Se,z="<!doctype html><html><body></body></html>",Te=["window","self","document","HTMLElement","Element","Node","DocumentFragment","customElements","Text","Comment","MutationObserver","navigator"],Je=()=>typeof document<"u"&&typeof document.createElement=="function",Ce=e=>{let t=globalThis,n=e;Te.forEach(r=>{t[r]===void 0&&n[r]!==void 0&&(t[r]=n[r]);});},D=()=>{let{parseHTML:e}=q()("linkedom"),{window:t}=e(z);return t},A=()=>{let{JSDOM:e}=q()("jsdom"),{window:t}=new e(z);return t},ke=()=>{let e=typeof process<"u"&&process.env?.KNIGHTED_JSX_NODE_SHIM?process.env.KNIGHTED_JSX_NODE_SHIM.toLowerCase():void 0;return e==="linkedom"||e==="jsdom"?e:"auto"},De=()=>{let e=ke();return e==="linkedom"?[D,A]:e==="jsdom"?[A,D]:[D,A]},Ae=()=>{let e=[];for(let n of De())try{return n()}catch(r){e.push(r);}let t='Unable to bootstrap a DOM-like environment. Install "linkedom" or "jsdom" (both optional peer dependencies) or set KNIGHTED_JSX_NODE_SHIM to pick one explicitly.';throw new AggregateError(e,t)},K=false,Z=()=>{if(Je()||K)return;let e=Ae();Ce(e),K=true;};var ve="oxc-parser",Ne=e=>{let t=e.raw??e,n=t[0]??"",r=[];for(let o=0;o<t.length-1;o++){let s="${expr#"+o+"}",i=n.length;n+=s;let p=n.length;r.push({index:o,templateStart:i,templateEnd:p,label:s}),n+=t[o+1]??"";}return {source:n,spans:r}},Me=(e,t)=>{let n=new Map;return t.forEach(r=>{n.set(r.index,r);}),e.expressionRanges.map(r=>{let o=n.get(r.index);if(!o)return null;let s=Math.max(0,r.sourceEnd-r.sourceStart),i=Math.max(0,o.templateEnd-o.templateStart);return {sourceStart:r.sourceStart,sourceEnd:r.sourceEnd,templateStart:o.templateStart,templateEnd:o.templateEnd,delta:i-s}}).filter(r=>!!r).sort((r,o)=>r.sourceStart-o.sourceStart)},Re=(e,t,n)=>{if(!Number.isFinite(e)||e<=0)return 0;let r=0;for(let s of t){if(e<s.sourceStart)break;if(e<s.sourceEnd){let i=Math.max(0,e-s.sourceStart),p=Math.max(0,s.templateEnd-s.templateStart);if(p===0)return s.templateStart;let a=Math.min(i,Math.max(0,p-1));return s.templateStart+a}r+=s.delta;}let o=e+r;return o<=0?0:o>=n?n:o},Y=(e,t)=>{let n=Math.max(0,Math.min(t,e.length)),r=1,o=1;for(let s=0;s<n;s++){if(e.charCodeAt(s)===10){r++,o=1;continue}o++;}return {line:r,column:o}},Xe=e=>{let t=[],n=0;return e.forEach((r,o)=>{t.push(n),n+=r.length,o<e.length-1&&(n+=1);}),t},Le=(e,t,n,r,o,s,i)=>{let p=n+t.length,a=Math.max(r,n),c=Math.min(o,p);if(c>a){let l=Math.max(0,a-n),u=Math.max(1,c-a);return " ".repeat(l)+"^".repeat(u)}if(t.length===0&&e>=s&&e<=i)return "^";if(e===s){let l=Math.max(0,r-n);return " ".repeat(Math.min(l,t.length))+"^"}return ""},je=(e,t,n,r,o)=>{if(!e.length)return "";let s=e.split(`
|
|
2
|
+
`),i=Xe(s),p=Math.max(1,r-1),a=Math.min(s.length,o+1),c=String(a).length,l=[];for(let u=p;u<=a;u++){let d=s[u-1]??"",m=String(u).padStart(c," ");l.push(`${m} | ${d}`);let f=Le(u,d,i[u-1]??0,t,n,r,o);f&&l.push(`${" ".repeat(c)} | ${f}`);}return l.join(`
|
|
3
|
+
`)},v=(e,t,n,r,o)=>{let s=ve,i=`[${s}] ${r.message}`,p=r.labels?.[0];if(!p)return i;let{source:a,spans:c}=Ne(t),l=Me(n,c),u=y=>Re(typeof y=="number"?y:0,l,a.length),d=u(p.start),m=u(p.end);m<=d&&(m=Math.min(a.length,d+1));let f=Y(a,d),x=Y(a,Math.max(d,m-1)),E=je(a,d,m,f.line,x.line),g=`[${s}] ${r.message}`;return g+=`
|
|
4
|
+
--> ${e} template:${f.line}:${f.column}`,p.message&&(g+=`
|
|
5
|
+
${p.message}`),E&&(g+=`
|
|
6
|
+
${E}`),r.helpMessage&&(g+=`
|
|
7
|
+
${r.helpMessage}`),g};var Ie=/<\s*$/,Pe=/<\/\s*$/,ee="__KX_EXPR__",Q=new RegExp(`${ee}\\d+_\\d+__`,"g"),$e=0;var te={lang:"jsx",sourceType:"module",range:true,preserveParens:true},ne=e=>{for(let t of e.body)if(t.type==="ExpressionStatement"){let n=t.expression;if(n.type==="JSXElement"||n.type==="JSXFragment")return n}throw new Error("The jsx template must contain a single JSX element or fragment.")},w=e=>{switch(e.type){case "JSXIdentifier":return e.name;case "JSXNamespacedName":return `${e.namespace.name}:${e.name.name}`;case "JSXMemberExpression":return `${w(e.object)}.${e.property.name}`;default:return ""}},N=(e,t)=>{if(!e||typeof e!="object")return;let n=e;typeof n.type=="string"&&(t(n),Object.values(n).forEach(r=>{if(r){if(Array.isArray(r)){r.forEach(o=>N(o,t));return}typeof r=="object"&&N(r,t);}}));},re=(e,t)=>{let n=e.replace(/\r/g,"").replace(/\n\s+/g," "),r=e.match(/^\s*/)?.[0]??"",o=e.match(/\s*$/)?.[0]??"",s=/\n/.test(r),i=/\n/.test(o),p=n;if(s&&(p=p.replace(/^\s+/,"")),i&&(p=p.replace(/\s+$/,"")),p.length===0||p.trim().length===0)return [];let a=[];Q.lastIndex=0;let c=0,l;for(;l=Q.exec(p);){let d=l.index,m=p.slice(c,d);m&&a.push(m);let f=l[0];t.has(f)?a.push(t.get(f)):a.push(f),c=d+f.length;}let u=p.slice(c);return u&&a.push(u),a},Oe=(e,t)=>{let n=new Set;return N(e,r=>{r.type==="Identifier"&&t.placeholders.has(r.name)&&n.add(r.name);}),Array.from(n)},oe=(e,t,n)=>{if(e.type==="JSXElement"||e.type==="JSXFragment")return n(e);if(!("range"in e)||!e.range)throw new Error("Unable to evaluate expression: missing source range information.");let[r,o]=e.range,s=t.source.slice(r,o),i=Oe(e,t);try{let p=new Function(...i,`"use strict"; return (${s});`),a=i.map(c=>t.placeholders.get(c));return p(...a)}catch(p){throw new Error(`Failed to evaluate expression ${s}: ${p.message}`)}},_e=e=>{let t=e.replace(/[^a-zA-Z0-9_$]/g,"");return t?/[A-Za-z_$]/.test(t[0])?t:`Component${t}`:"Component"},He=(e,t,n)=>{let r=n.get(e);if(r)return r;let o=e.displayName||e.name||`Component${t.length}`,s=_e(o??""),i=s,p=1;for(;t.some(c=>c.name===i);)i=`${s}${p++}`;let a={name:i,value:e};return t.push(a),n.set(e,a),a},se=(e,t)=>{let n=e.raw??e,r=new Map,o=[],s=new Map,i=n[0]??"",p=$e++,a=0,c=[];for(let l=0;l<t.length;l++){let u=n[l]??"",d=n[l+1]??"",m=t[l],f=Ie.test(u)||Pe.test(u),x;if(f&&typeof m=="function")x=He(m,o,s).name;else if(f&&typeof m=="string")x=m;else {let y=`${ee}${p}_${a++}__`;r.set(y,m),x=y;}let E=i.length;i+=x;let g=i.length;c.push({index:l,sourceStart:E,sourceEnd:g}),i+=d;}return {source:i,placeholders:r,bindings:o,diagnostics:{expressionRanges:c}}};var Ue=()=>{if(typeof document>"u"||typeof document.createElement!="function")throw new Error("The jsx template tag requires a DOM-like environment (document missing).")},Ge=e=>typeof Node>"u"?false:e instanceof Node||e instanceof DocumentFragment,Ke=e=>!e||typeof e=="string"?false:typeof e[Symbol.iterator]=="function",ie=e=>!e||typeof e!="object"&&typeof e!="function"?false:typeof e.then=="function",qe={xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace",xmlns:"http://www.w3.org/2000/xmlns/"},pe=e=>{if(!(!e||e==="html"||e==="svg"))return qe[e]},ze=e=>e==="svg"?svg:html,M=(e,t,n)=>{let r=pe(t.space),o=String(n);if(r){e.setAttributeNS(r,t.attribute,o);return}e.setAttribute(t.attribute,o);},ae=(e,t)=>{let n=pe(t.space);if(n){e.removeAttributeNS(n,t.attribute);return}e.removeAttribute(t.attribute);},R=(e,t)=>Array.isArray(e)?e.filter(Boolean).join(t):e,Ze=(e,t,n)=>t==="svg"||!n.property||n.property.includes(":")?false:n.property in e,Ye=(e,t,n,r)=>{if(n==null)return;if(t==="dangerouslySetInnerHTML"&&typeof n=="object"&&n&&"__html"in n){e.innerHTML=String(n.__html??"");return}if(t==="ref"){if(typeof n=="function"){n(e);return}if(n&&typeof n=="object"){n.current=e;return}}if(t==="style"&&typeof n=="object"&&n!==null){let c=n,l=e.style;if(!l)return;let u=l;Object.entries(c).forEach(([d,m])=>{if(m!=null){if(d.startsWith("--")){l.setProperty(d,String(m));return}u[d]=m;}});return}let o=F(t);if(o){let c=B(t,n);if(c){let l=c.options?{...c.options}:void 0;o.capture&&(l?l.capture=true:l={capture:true}),e.addEventListener(o.eventName,c.listener,l);return}}let s=find(ze(r),t),i=e,p=Ze(e,r,s);if(s.mustUseProperty){let c=s.boolean?!!n:n;i[s.property]=c;return}if(s.boolean){let c=!!n;p&&(i[s.property]=c),c?M(e,s,""):ae(e,s);return}let a=n;if(s.spaceSeparated?a=R(n," "):s.commaSeparated?a=R(n,","):s.commaOrSpaceSeparated&&(a=R(n," ")),s.booleanish&&typeof a=="boolean"&&(a=a?"true":"false"),s.overloadedBoolean){if(a===false){ae(e,s);return}if(a===true){M(e,s,"");return}}if(p){i[s.property]=a;return}a!==false&&M(e,s,a);},h=(e,t)=>{if(t!=null&&typeof t!="boolean"){if(ie(t))throw new Error("Async values are not supported inside jsx template results.");if(Array.isArray(t)){t.forEach(n=>h(e,n));return}if(Ke(t)){for(let n of t)h(e,n);return}if(Ge(t)){e.appendChild(t);return}e.appendChild(document.createTextNode(String(t)));}},X=(e,t,n)=>oe(e,t,r=>j(r,t,n)),ce=P({getIdentifierName:w,evaluateExpressionWithNamespace:X}),Qe=(e,t,n,r)=>{let o=ce(t,n,r);Object.entries(o).forEach(([s,i])=>{if(s!=="key"){if(s==="children"){h(e,i);return}Ye(e,s,i,r);}});},L=(e,t,n)=>{let r=[];return e.forEach(o=>{switch(o.type){case "JSXText":{re(o.value,t.placeholders).forEach(i=>{r.push(i);});break}case "JSXExpressionContainer":{if(o.expression.type==="JSXEmptyExpression")break;r.push(X(o.expression,t,n));break}case "JSXSpreadChild":{let s=X(o.expression,t,n);s!=null&&r.push(s);break}case "JSXElement":case "JSXFragment":{r.push(j(o,t,n));break}}}),r},et=(e,t,n,r)=>{let o=ce(e.openingElement.attributes,t,r),s=L(e.children,t,r);s.length===1?o.children=s[0]:s.length>1&&(o.children=s);let i=n(o);if(ie(i))throw new Error("Async jsx components are not supported.");return i},tt=(e,t,n)=>{let r=e.openingElement,o=w(r.name),s=t.components.get(o);if(s)return et(e,t,s,n);if(/[A-Z]/.test(o[0]??""))throw new Error(`Unknown component "${o}". Did you interpolate it with the template literal?`);let i=o==="svg"?"svg":n,p=o==="foreignObject"?null:i,a=i==="svg"?document.createElementNS("http://www.w3.org/2000/svg",o):document.createElement(o);return Qe(a,r.attributes,t,i),L(e.children,t,p).forEach(l=>h(a,l)),a},j=(e,t,n)=>{if(e.type==="JSXFragment"){let r=document.createDocumentFragment();return L(e.children,t,n).forEach(s=>h(r,s)),r}return tt(e,t,n)},le=(e,...t)=>{Ue();let n=se(e,t),r=parseSync("inline.jsx",n.source,te);if(r.errors.length>0)throw new Error(v("jsx",e,n.diagnostics,r.errors[0]));let o=ne(r.program),s={source:n.source,placeholders:n.placeholders,components:new Map(n.bindings.map(i=>[i.name,i.value]))};return j(o,s,null)};G({mode:"always"});Z();var Jt=le;
|
|
8
|
+
export{Jt as jsx};
|
package/dist/lite/node/index.js
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import {createRequire}from'module';import {parseSync}from'oxc-parser';import {find,svg,html}from'property-information';var
|
|
2
|
-
${n.
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import {createRequire}from'module';import {parseSync}from'oxc-parser';import {find,svg,html}from'property-information';var te=createRequire(import.meta.url),R=()=>te,M="<!doctype html><html><body></body></html>",re=["window","self","document","HTMLElement","Element","Node","DocumentFragment","customElements","Text","Comment","MutationObserver","navigator"],oe=()=>typeof document<"u"&&typeof document.createElement=="function",se=e=>{let t=globalThis,n=e;re.forEach(r=>{t[r]===void 0&&n[r]!==void 0&&(t[r]=n[r]);});},S=()=>{let{parseHTML:e}=R()("linkedom"),{window:t}=e(M);return t},w=()=>{let{JSDOM:e}=R()("jsdom"),{window:t}=new e(M);return t},ae=()=>{let e=typeof process<"u"&&process.env?.KNIGHTED_JSX_NODE_SHIM?process.env.KNIGHTED_JSX_NODE_SHIM.toLowerCase():void 0;return e==="linkedom"||e==="jsdom"?e:"auto"},ie=()=>{let e=ae();return e==="linkedom"?[S,w]:e==="jsdom"?[w,S]:[S,w]},pe=()=>{let e=[];for(let n of ie())try{return n()}catch(r){e.push(r);}let t='Unable to bootstrap a DOM-like environment. Install "linkedom" or "jsdom" (both optional peer dependencies) or set KNIGHTED_JSX_NODE_SHIM to pick one explicitly.';throw new AggregateError(e,t)},X=false,D=()=>{if(oe()||X)return;let e=pe();se(e),X=true;};var ce="oxc-parser",le=e=>{let t=e.raw??e,n=t[0]??"",r=[];for(let o=0;o<t.length-1;o++){let s="${expr#"+o+"}",i=n.length;n+=s;let p=n.length;r.push({index:o,templateStart:i,templateEnd:p,label:s}),n+=t[o+1]??"";}return {source:n,spans:r}},me=(e,t)=>{let n=new Map;return t.forEach(r=>{n.set(r.index,r);}),e.expressionRanges.map(r=>{let o=n.get(r.index);if(!o)return null;let s=Math.max(0,r.sourceEnd-r.sourceStart),i=Math.max(0,o.templateEnd-o.templateStart);return {sourceStart:r.sourceStart,sourceEnd:r.sourceEnd,templateStart:o.templateStart,templateEnd:o.templateEnd,delta:i-s}}).filter(r=>!!r).sort((r,o)=>r.sourceStart-o.sourceStart)},ue=(e,t,n)=>{if(!Number.isFinite(e)||e<=0)return 0;let r=0;for(let s of t){if(e<s.sourceStart)break;if(e<s.sourceEnd){let i=Math.max(0,e-s.sourceStart),p=Math.max(0,s.templateEnd-s.templateStart);if(p===0)return s.templateStart;let a=Math.min(i,Math.max(0,p-1));return s.templateStart+a}r+=s.delta;}let o=e+r;return o<=0?0:o>=n?n:o},L=(e,t)=>{let n=Math.max(0,Math.min(t,e.length)),r=1,o=1;for(let s=0;s<n;s++){if(e.charCodeAt(s)===10){r++,o=1;continue}o++;}return {line:r,column:o}},de=e=>{let t=[],n=0;return e.forEach((r,o)=>{t.push(n),n+=r.length,o<e.length-1&&(n+=1);}),t},fe=(e,t,n,r,o,s,i)=>{let p=n+t.length,a=Math.max(r,n),c=Math.min(o,p);if(c>a){let l=Math.max(0,a-n),u=Math.max(1,c-a);return " ".repeat(l)+"^".repeat(u)}if(t.length===0&&e>=s&&e<=i)return "^";if(e===s){let l=Math.max(0,r-n);return " ".repeat(Math.min(l,t.length))+"^"}return ""},ge=(e,t,n,r,o)=>{if(!e.length)return "";let s=e.split(`
|
|
2
|
+
`),i=de(s),p=Math.max(1,r-1),a=Math.min(s.length,o+1),c=String(a).length,l=[];for(let u=p;u<=a;u++){let d=s[u-1]??"",m=String(u).padStart(c," ");l.push(`${m} | ${d}`);let f=fe(u,d,i[u-1]??0,t,n,r,o);f&&l.push(`${" ".repeat(c)} | ${f}`);}return l.join(`
|
|
3
|
+
`)},T=(e,t,n,r,o)=>{let s=ce,i=`[${s}] ${r.message}`,p=r.labels?.[0];if(!p)return i;let{source:a,spans:c}=le(t),l=me(n,c),u=h=>ue(typeof h=="number"?h:0,l,a.length),d=u(p.start),m=u(p.end);m<=d&&(m=Math.min(a.length,d+1));let f=L(a,d),x=L(a,Math.max(d,m-1)),y=ge(a,d,m,f.line,x.line),g=`[${s}] ${r.message}`;return g+=`
|
|
4
|
+
--> ${e} template:${f.line}:${f.column}`,p.message&&(g+=`
|
|
5
|
+
${p.message}`),y&&(g+=`
|
|
6
|
+
${y}`),r.helpMessage&&(g+=`
|
|
7
|
+
${r.helpMessage}`),g};var xe=/<\s*$/,he=/<\/\s*$/,I="__KX_EXPR__",P=new RegExp(`${I}\\d+_\\d+__`,"g"),Ee=0;var j={lang:"jsx",sourceType:"module",range:true,preserveParens:true},O=e=>{for(let t of e.body)if(t.type==="ExpressionStatement"){let n=t.expression;if(n.type==="JSXElement"||n.type==="JSXFragment")return n}throw new Error("The jsx template must contain a single JSX element or fragment.")},b=e=>{switch(e.type){case "JSXIdentifier":return e.name;case "JSXNamespacedName":return `${e.namespace.name}:${e.name.name}`;case "JSXMemberExpression":return `${b(e.object)}.${e.property.name}`;default:return ""}},J=(e,t)=>{if(!e||typeof e!="object")return;let n=e;typeof n.type=="string"&&(t(n),Object.values(n).forEach(r=>{if(r){if(Array.isArray(r)){r.forEach(o=>J(o,t));return}typeof r=="object"&&J(r,t);}}));},$=(e,t)=>{let n=e.replace(/\r/g,"").replace(/\n\s+/g," "),r=e.match(/^\s*/)?.[0]??"",o=e.match(/\s*$/)?.[0]??"",s=/\n/.test(r),i=/\n/.test(o),p=n;if(s&&(p=p.replace(/^\s+/,"")),i&&(p=p.replace(/\s+$/,"")),p.length===0||p.trim().length===0)return [];let a=[];P.lastIndex=0;let c=0,l;for(;l=P.exec(p);){let d=l.index,m=p.slice(c,d);m&&a.push(m);let f=l[0];t.has(f)?a.push(t.get(f)):a.push(f),c=d+f.length;}let u=p.slice(c);return u&&a.push(u),a},ye=(e,t)=>{let n=new Set;return J(e,r=>{r.type==="Identifier"&&t.placeholders.has(r.name)&&n.add(r.name);}),Array.from(n)},_=(e,t,n)=>{if(e.type==="JSXElement"||e.type==="JSXFragment")return n(e);if(!("range"in e)||!e.range)throw new Error("Unable to evaluate expression: missing source range information.");let[r,o]=e.range,s=t.source.slice(r,o),i=ye(e,t);try{let p=new Function(...i,`"use strict"; return (${s});`),a=i.map(c=>t.placeholders.get(c));return p(...a)}catch(p){throw new Error(`Failed to evaluate expression ${s}: ${p.message}`)}},be=e=>{let t=e.replace(/[^a-zA-Z0-9_$]/g,"");return t?/[A-Za-z_$]/.test(t[0])?t:`Component${t}`:"Component"},Se=(e,t,n)=>{let r=n.get(e);if(r)return r;let o=e.displayName||e.name||`Component${t.length}`,s=be(o??""),i=s,p=1;for(;t.some(c=>c.name===i);)i=`${s}${p++}`;let a={name:i,value:e};return t.push(a),n.set(e,a),a},F=(e,t)=>{let n=e.raw??e,r=new Map,o=[],s=new Map,i=n[0]??"",p=Ee++,a=0,c=[];for(let l=0;l<t.length;l++){let u=n[l]??"",d=n[l+1]??"",m=t[l],f=xe.test(u)||he.test(u),x;if(f&&typeof m=="function")x=Se(m,o,s).name;else if(f&&typeof m=="string")x=m;else {let h=`${I}${p}_${a++}__`;r.set(h,m),x=h;}let y=i.length;i+=x;let g=i.length;c.push({index:l,sourceStart:y,sourceEnd:g}),i+=d;}return {source:i,placeholders:r,bindings:o,diagnostics:{expressionRanges:c}}};var W=e=>{let{getIdentifierName:t,evaluateExpressionWithNamespace:n}=e;return (r,o,s)=>{let i={},p=(a,c)=>{i[a]=c;};return r.forEach(a=>{if(a.type==="JSXSpreadAttribute"){let l=n(a.argument,o,s);l&&typeof l=="object"&&!Array.isArray(l)&&Object.assign(i,l);return}let c=t(a.name);if(!a.value){p(c,true);return}if(a.value.type==="Literal"){p(c,a.value.value);return}if(a.value.type==="JSXExpressionContainer"){if(a.value.expression.type==="JSXEmptyExpression")return;p(c,n(a.value.expression,o,s));}}),i}};var B="Capture",V=e=>e.endsWith(B)?{eventName:e.slice(0,-B.length),capture:true}:{eventName:e,capture:false},U=e=>{if(!e.startsWith("on"))return null;if(e.startsWith("on:")){let r=e.slice(3);if(!r)return null;let o=V(r);return o.eventName?o:null}let t=e.slice(2);if(!t)return null;let n=V(t);return n.eventName?{eventName:n.eventName.toLowerCase(),capture:n.capture}:null},q=e=>!e||typeof e!="object"?false:"handleEvent"in e&&typeof e.handleEvent=="function",Ce=e=>{if(!e||typeof e!="object"||!("handler"in e))return false;let t=e.handler;return typeof t=="function"?true:q(t)},K=(e,t)=>{if(typeof t=="function"||q(t))return {listener:t};if(!Ce(t))return null;let n=t,r=n.options?{...n.options}:void 0,o=(s,i)=>{i!=null&&(r||(r={}),r[s]=i);};return o("capture",n.capture),o("once",n.once),o("passive",n.passive),o("signal",n.signal??void 0),{listener:n.handler,options:r}};var Re=()=>{if(typeof document>"u"||typeof document.createElement!="function")throw new Error("The jsx template tag requires a DOM-like environment (document missing).")},Me=e=>typeof Node>"u"?false:e instanceof Node||e instanceof DocumentFragment,De=e=>!e||typeof e=="string"?false:typeof e[Symbol.iterator]=="function",G=e=>!e||typeof e!="object"&&typeof e!="function"?false:typeof e.then=="function",Le={xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace",xmlns:"http://www.w3.org/2000/xmlns/"},Z=e=>{if(!(!e||e==="html"||e==="svg"))return Le[e]},Pe=e=>e==="svg"?svg:html,C=(e,t,n)=>{let r=Z(t.space),o=String(n);if(r){e.setAttributeNS(r,t.attribute,o);return}e.setAttribute(t.attribute,o);},z=(e,t)=>{let n=Z(t.space);if(n){e.removeAttributeNS(n,t.attribute);return}e.removeAttribute(t.attribute);},k=(e,t)=>Array.isArray(e)?e.filter(Boolean).join(t):e,Ie=(e,t,n)=>t==="svg"||!n.property||n.property.includes(":")?false:n.property in e,je=(e,t,n,r)=>{if(n==null)return;if(t==="dangerouslySetInnerHTML"&&typeof n=="object"&&n&&"__html"in n){e.innerHTML=String(n.__html??"");return}if(t==="ref"){if(typeof n=="function"){n(e);return}if(n&&typeof n=="object"){n.current=e;return}}if(t==="style"&&typeof n=="object"&&n!==null){let c=n,l=e.style;if(!l)return;let u=l;Object.entries(c).forEach(([d,m])=>{if(m!=null){if(d.startsWith("--")){l.setProperty(d,String(m));return}u[d]=m;}});return}let o=U(t);if(o){let c=K(t,n);if(c){let l=c.options?{...c.options}:void 0;o.capture&&(l?l.capture=true:l={capture:true}),e.addEventListener(o.eventName,c.listener,l);return}}let s=find(Pe(r),t),i=e,p=Ie(e,r,s);if(s.mustUseProperty){let c=s.boolean?!!n:n;i[s.property]=c;return}if(s.boolean){let c=!!n;p&&(i[s.property]=c),c?C(e,s,""):z(e,s);return}let a=n;if(s.spaceSeparated?a=k(n," "):s.commaSeparated?a=k(n,","):s.commaOrSpaceSeparated&&(a=k(n," ")),s.booleanish&&typeof a=="boolean"&&(a=a?"true":"false"),s.overloadedBoolean){if(a===false){z(e,s);return}if(a===true){C(e,s,"");return}}if(p){i[s.property]=a;return}a!==false&&C(e,s,a);},E=(e,t)=>{if(t!=null&&typeof t!="boolean"){if(G(t))throw new Error("Async values are not supported inside jsx template results.");if(Array.isArray(t)){t.forEach(n=>E(e,n));return}if(De(t)){for(let n of t)E(e,n);return}if(Me(t)){e.appendChild(t);return}e.appendChild(document.createTextNode(String(t)));}},N=(e,t,n)=>_(e,t,r=>v(r,t,n)),Y=W({getIdentifierName:b,evaluateExpressionWithNamespace:N}),Oe=(e,t,n,r)=>{let o=Y(t,n,r);Object.entries(o).forEach(([s,i])=>{if(s!=="key"){if(s==="children"){E(e,i);return}je(e,s,i,r);}});},A=(e,t,n)=>{let r=[];return e.forEach(o=>{switch(o.type){case "JSXText":{$(o.value,t.placeholders).forEach(i=>{r.push(i);});break}case "JSXExpressionContainer":{if(o.expression.type==="JSXEmptyExpression")break;r.push(N(o.expression,t,n));break}case "JSXSpreadChild":{let s=N(o.expression,t,n);s!=null&&r.push(s);break}case "JSXElement":case "JSXFragment":{r.push(v(o,t,n));break}}}),r},$e=(e,t,n,r)=>{let o=Y(e.openingElement.attributes,t,r),s=A(e.children,t,r);s.length===1?o.children=s[0]:s.length>1&&(o.children=s);let i=n(o);if(G(i))throw new Error("Async jsx components are not supported.");return i},_e=(e,t,n)=>{let r=e.openingElement,o=b(r.name),s=t.components.get(o);if(s)return $e(e,t,s,n);if(/[A-Z]/.test(o[0]??""))throw new Error(`Unknown component "${o}". Did you interpolate it with the template literal?`);let i=o==="svg"?"svg":n,p=o==="foreignObject"?null:i,a=i==="svg"?document.createElementNS("http://www.w3.org/2000/svg",o):document.createElement(o);return Oe(a,r.attributes,t,i),A(e.children,t,p).forEach(l=>E(a,l)),a},v=(e,t,n)=>{if(e.type==="JSXFragment"){let r=document.createDocumentFragment();return A(e.children,t,n).forEach(s=>E(r,s)),r}return _e(e,t,n)},Q=(e,...t)=>{Re();let n=F(e,t),r=parseSync("inline.jsx",n.source,j);if(r.errors.length>0)throw new Error(T("jsx",e,n.diagnostics,r.errors[0]));let o=O(r.program),s={source:n.source,placeholders:n.placeholders,components:new Map(n.bindings.map(i=>[i.name,i.value]))};return v(o,s,null)};D();var rt=Q;
|
|
8
|
+
export{rt as jsx};
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
-
import {parseSync}from'oxc-parser';import {createElement,Fragment}from'react';var
|
|
2
|
-
${t.
|
|
3
|
-
|
|
1
|
+
import {parseSync}from'oxc-parser';import {createElement,Fragment}from'react';var _="oxc-parser",O=e=>{let n=e.raw??e,r=n[0]??"",t=[];for(let o=0;o<n.length-1;o++){let s="${expr#"+o+"}",a=r.length;r+=s;let p=r.length;t.push({index:o,templateStart:a,templateEnd:p,label:s}),r+=n[o+1]??"";}return {source:r,spans:t}},j=(e,n)=>{let r=new Map;return n.forEach(t=>{r.set(t.index,t);}),e.expressionRanges.map(t=>{let o=r.get(t.index);if(!o)return null;let s=Math.max(0,t.sourceEnd-t.sourceStart),a=Math.max(0,o.templateEnd-o.templateStart);return {sourceStart:t.sourceStart,sourceEnd:t.sourceEnd,templateStart:o.templateStart,templateEnd:o.templateEnd,delta:a-s}}).filter(t=>!!t).sort((t,o)=>t.sourceStart-o.sourceStart)},L=(e,n,r)=>{if(!Number.isFinite(e)||e<=0)return 0;let t=0;for(let s of n){if(e<s.sourceStart)break;if(e<s.sourceEnd){let a=Math.max(0,e-s.sourceStart),p=Math.max(0,s.templateEnd-s.templateStart);if(p===0)return s.templateStart;let i=Math.min(a,Math.max(0,p-1));return s.templateStart+i}t+=s.delta;}let o=e+t;return o<=0?0:o>=r?r:o},w=(e,n)=>{let r=Math.max(0,Math.min(n,e.length)),t=1,o=1;for(let s=0;s<r;s++){if(e.charCodeAt(s)===10){t++,o=1;continue}o++;}return {line:t,column:o}},D=e=>{let n=[],r=0;return e.forEach((t,o)=>{n.push(r),r+=t.length,o<e.length-1&&(r+=1);}),n},B=(e,n,r,t,o,s,a)=>{let p=r+n.length,i=Math.max(t,r),c=Math.min(o,p);if(c>i){let m=Math.max(0,i-r),l=Math.max(1,c-i);return " ".repeat(m)+"^".repeat(l)}if(n.length===0&&e>=s&&e<=a)return "^";if(e===s){let m=Math.max(0,t-r);return " ".repeat(Math.min(m,n.length))+"^"}return ""},v=(e,n,r,t,o)=>{if(!e.length)return "";let s=e.split(`
|
|
2
|
+
`),a=D(s),p=Math.max(1,t-1),i=Math.min(s.length,o+1),c=String(i).length,m=[];for(let l=p;l<=i;l++){let d=s[l-1]??"",u=String(l).padStart(c," ");m.push(`${u} | ${d}`);let g=B(l,d,a[l-1]??0,n,r,t,o);g&&m.push(`${" ".repeat(c)} | ${g}`);}return m.join(`
|
|
3
|
+
`)},b=(e,n,r,t,o)=>{let s=_,a=`[${s}] ${t.message}`,p=t.labels?.[0];if(!p)return a;let{source:i,spans:c}=O(n),m=j(r,c),l=h=>L(typeof h=="number"?h:0,m,i.length),d=l(p.start),u=l(p.end);u<=d&&(u=Math.min(i.length,d+1));let g=w(i,d),f=w(i,Math.max(d,u-1)),E=v(i,d,u,g.line,f.line),x=`[${s}] ${t.message}`;return x+=`
|
|
4
|
+
--> ${e} template:${g.line}:${g.column}`,p.message&&(x+=`
|
|
5
|
+
${p.message}`),E&&(x+=`
|
|
6
|
+
${E}`),t.helpMessage&&(x+=`
|
|
7
|
+
${t.helpMessage}`),x};var z=/<\s*$/,W=/<\/\s*$/,X="__KX_EXPR__",R=new RegExp(`${X}\\d+_\\d+__`,"g"),U=0;var $={lang:"jsx",sourceType:"module",range:true,preserveParens:true},A=e=>{for(let n of e.body)if(n.type==="ExpressionStatement"){let r=n.expression;if(r.type==="JSXElement"||r.type==="JSXFragment")return r}throw new Error("The jsx template must contain a single JSX element or fragment.")},S=e=>{switch(e.type){case "JSXIdentifier":return e.name;case "JSXNamespacedName":return `${e.namespace.name}:${e.name.name}`;case "JSXMemberExpression":return `${S(e.object)}.${e.property.name}`;default:return ""}},C=(e,n)=>{if(!e||typeof e!="object")return;let r=e;typeof r.type=="string"&&(n(r),Object.values(r).forEach(t=>{if(t){if(Array.isArray(t)){t.forEach(o=>C(o,n));return}typeof t=="object"&&C(t,n);}}));},k=(e,n)=>{let r=e.replace(/\r/g,"").replace(/\n\s+/g," "),t=e.match(/^\s*/)?.[0]??"",o=e.match(/\s*$/)?.[0]??"",s=/\n/.test(t),a=/\n/.test(o),p=r;if(s&&(p=p.replace(/^\s+/,"")),a&&(p=p.replace(/\s+$/,"")),p.length===0||p.trim().length===0)return [];let i=[];R.lastIndex=0;let c=0,m;for(;m=R.exec(p);){let d=m.index,u=p.slice(c,d);u&&i.push(u);let g=m[0];n.has(g)?i.push(n.get(g)):i.push(g),c=d+g.length;}let l=p.slice(c);return l&&i.push(l),i},V=(e,n)=>{let r=new Set;return C(e,t=>{t.type==="Identifier"&&n.placeholders.has(t.name)&&r.add(t.name);}),Array.from(r)},M=(e,n,r)=>{if(e.type==="JSXElement"||e.type==="JSXFragment")return r(e);if(!("range"in e)||!e.range)throw new Error("Unable to evaluate expression: missing source range information.");let[t,o]=e.range,s=n.source.slice(t,o),a=V(e,n);try{let p=new Function(...a,`"use strict"; return (${s});`),i=a.map(c=>n.placeholders.get(c));return p(...i)}catch(p){throw new Error(`Failed to evaluate expression ${s}: ${p.message}`)}},Z=e=>{let n=e.replace(/[^a-zA-Z0-9_$]/g,"");return n?/[A-Za-z_$]/.test(n[0])?n:`Component${n}`:"Component"},G=(e,n,r)=>{let t=r.get(e);if(t)return t;let o=e.displayName||e.name||`Component${n.length}`,s=Z(o??""),a=s,p=1;for(;n.some(c=>c.name===a);)a=`${s}${p++}`;let i={name:a,value:e};return n.push(i),r.set(e,i),i},N=(e,n)=>{let r=e.raw??e,t=new Map,o=[],s=new Map,a=r[0]??"",p=U++,i=0,c=[];for(let m=0;m<n.length;m++){let l=r[m]??"",d=r[m+1]??"",u=n[m],g=z.test(l)||W.test(l),f;if(g&&typeof u=="function")f=G(u,o,s).name;else if(g&&typeof u=="string")f=u;else {let h=`${X}${p}_${i++}__`;t.set(h,u),f=h;}let E=a.length;a+=f;let x=a.length;c.push({index:m,sourceStart:E,sourceEnd:x}),a+=d;}return {source:a,placeholders:t,bindings:o,diagnostics:{expressionRanges:c}}};var q=e=>!e||typeof e=="string"?false:typeof e[Symbol.iterator]=="function",Q=e=>!e||typeof e!="object"&&typeof e!="function"?false:typeof e.then=="function",y=(e,n)=>{if(n!=null&&typeof n!="boolean"){if(Q(n))throw new Error("Async values are not supported inside reactJsx template results.");if(Array.isArray(n)){n.forEach(r=>y(e,r));return}if(q(n)){for(let r of n)y(e,r);return}e.push(n);}},T=(e,n)=>M(e,n,r=>J(r,n)),Y=(e,n)=>{let r={};return e.forEach(t=>{if(t.type==="JSXSpreadAttribute"){let s=T(t.argument,n);s&&typeof s=="object"&&!Array.isArray(s)&&Object.assign(r,s);return}let o=S(t.name);if(!t.value){r[o]=true;return}if(t.value.type==="Literal"){r[o]=t.value.value;return}if(t.value.type==="JSXExpressionContainer"){if(t.value.expression.type==="JSXEmptyExpression")return;r[o]=T(t.value.expression,n);}}),r},I=(e,n)=>{let r=[];return e.forEach(t=>{switch(t.type){case "JSXText":{k(t.value,n.placeholders).forEach(s=>y(r,s));break}case "JSXExpressionContainer":{if(t.expression.type==="JSXEmptyExpression")break;y(r,T(t.expression,n));break}case "JSXSpreadChild":{let o=T(t.expression,n);o!=null&&y(r,o);break}case "JSXElement":case "JSXFragment":{r.push(J(t,n));break}}}),r},F=(e,n,r)=>createElement(e,n,...r),ee=(e,n)=>{let r=e.openingElement,t=S(r.name),o=n.components.get(t),s=Y(r.attributes,n),a=I(e.children,n);if(o)return F(o,s,a);if(/[A-Z]/.test(t[0]??""))throw new Error(`Unknown component "${t}". Did you interpolate it with the template literal?`);return F(t,s,a)},J=(e,n)=>{if(e.type==="JSXFragment"){let r=I(e.children,n);return createElement(Fragment,null,...r)}return ee(e,n)},te=(e,...n)=>{let r=N(e,n),t=parseSync("inline.jsx",r.source,$);if(t.errors.length>0)throw new Error(b("reactJsx",e,r.diagnostics,t.errors[0]));let o=A(t.program),s={source:r.source,placeholders:r.placeholders,components:new Map(r.bindings.map(a=>[a.name,a.value]))};return J(o,s)};export{te as reactJsx};
|
package/dist/lite/react/index.js
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
-
import {parseSync}from'oxc-parser';import {createElement,Fragment}from'react';var
|
|
2
|
-
${t.
|
|
3
|
-
|
|
1
|
+
import {parseSync}from'oxc-parser';import {createElement,Fragment}from'react';var _="oxc-parser",O=e=>{let n=e.raw??e,r=n[0]??"",t=[];for(let o=0;o<n.length-1;o++){let s="${expr#"+o+"}",a=r.length;r+=s;let p=r.length;t.push({index:o,templateStart:a,templateEnd:p,label:s}),r+=n[o+1]??"";}return {source:r,spans:t}},j=(e,n)=>{let r=new Map;return n.forEach(t=>{r.set(t.index,t);}),e.expressionRanges.map(t=>{let o=r.get(t.index);if(!o)return null;let s=Math.max(0,t.sourceEnd-t.sourceStart),a=Math.max(0,o.templateEnd-o.templateStart);return {sourceStart:t.sourceStart,sourceEnd:t.sourceEnd,templateStart:o.templateStart,templateEnd:o.templateEnd,delta:a-s}}).filter(t=>!!t).sort((t,o)=>t.sourceStart-o.sourceStart)},L=(e,n,r)=>{if(!Number.isFinite(e)||e<=0)return 0;let t=0;for(let s of n){if(e<s.sourceStart)break;if(e<s.sourceEnd){let a=Math.max(0,e-s.sourceStart),p=Math.max(0,s.templateEnd-s.templateStart);if(p===0)return s.templateStart;let i=Math.min(a,Math.max(0,p-1));return s.templateStart+i}t+=s.delta;}let o=e+t;return o<=0?0:o>=r?r:o},w=(e,n)=>{let r=Math.max(0,Math.min(n,e.length)),t=1,o=1;for(let s=0;s<r;s++){if(e.charCodeAt(s)===10){t++,o=1;continue}o++;}return {line:t,column:o}},D=e=>{let n=[],r=0;return e.forEach((t,o)=>{n.push(r),r+=t.length,o<e.length-1&&(r+=1);}),n},B=(e,n,r,t,o,s,a)=>{let p=r+n.length,i=Math.max(t,r),c=Math.min(o,p);if(c>i){let m=Math.max(0,i-r),l=Math.max(1,c-i);return " ".repeat(m)+"^".repeat(l)}if(n.length===0&&e>=s&&e<=a)return "^";if(e===s){let m=Math.max(0,t-r);return " ".repeat(Math.min(m,n.length))+"^"}return ""},v=(e,n,r,t,o)=>{if(!e.length)return "";let s=e.split(`
|
|
2
|
+
`),a=D(s),p=Math.max(1,t-1),i=Math.min(s.length,o+1),c=String(i).length,m=[];for(let l=p;l<=i;l++){let d=s[l-1]??"",u=String(l).padStart(c," ");m.push(`${u} | ${d}`);let g=B(l,d,a[l-1]??0,n,r,t,o);g&&m.push(`${" ".repeat(c)} | ${g}`);}return m.join(`
|
|
3
|
+
`)},b=(e,n,r,t,o)=>{let s=_,a=`[${s}] ${t.message}`,p=t.labels?.[0];if(!p)return a;let{source:i,spans:c}=O(n),m=j(r,c),l=h=>L(typeof h=="number"?h:0,m,i.length),d=l(p.start),u=l(p.end);u<=d&&(u=Math.min(i.length,d+1));let g=w(i,d),f=w(i,Math.max(d,u-1)),E=v(i,d,u,g.line,f.line),x=`[${s}] ${t.message}`;return x+=`
|
|
4
|
+
--> ${e} template:${g.line}:${g.column}`,p.message&&(x+=`
|
|
5
|
+
${p.message}`),E&&(x+=`
|
|
6
|
+
${E}`),t.helpMessage&&(x+=`
|
|
7
|
+
${t.helpMessage}`),x};var z=/<\s*$/,W=/<\/\s*$/,X="__KX_EXPR__",R=new RegExp(`${X}\\d+_\\d+__`,"g"),U=0;var $={lang:"jsx",sourceType:"module",range:true,preserveParens:true},A=e=>{for(let n of e.body)if(n.type==="ExpressionStatement"){let r=n.expression;if(r.type==="JSXElement"||r.type==="JSXFragment")return r}throw new Error("The jsx template must contain a single JSX element or fragment.")},S=e=>{switch(e.type){case "JSXIdentifier":return e.name;case "JSXNamespacedName":return `${e.namespace.name}:${e.name.name}`;case "JSXMemberExpression":return `${S(e.object)}.${e.property.name}`;default:return ""}},C=(e,n)=>{if(!e||typeof e!="object")return;let r=e;typeof r.type=="string"&&(n(r),Object.values(r).forEach(t=>{if(t){if(Array.isArray(t)){t.forEach(o=>C(o,n));return}typeof t=="object"&&C(t,n);}}));},k=(e,n)=>{let r=e.replace(/\r/g,"").replace(/\n\s+/g," "),t=e.match(/^\s*/)?.[0]??"",o=e.match(/\s*$/)?.[0]??"",s=/\n/.test(t),a=/\n/.test(o),p=r;if(s&&(p=p.replace(/^\s+/,"")),a&&(p=p.replace(/\s+$/,"")),p.length===0||p.trim().length===0)return [];let i=[];R.lastIndex=0;let c=0,m;for(;m=R.exec(p);){let d=m.index,u=p.slice(c,d);u&&i.push(u);let g=m[0];n.has(g)?i.push(n.get(g)):i.push(g),c=d+g.length;}let l=p.slice(c);return l&&i.push(l),i},V=(e,n)=>{let r=new Set;return C(e,t=>{t.type==="Identifier"&&n.placeholders.has(t.name)&&r.add(t.name);}),Array.from(r)},M=(e,n,r)=>{if(e.type==="JSXElement"||e.type==="JSXFragment")return r(e);if(!("range"in e)||!e.range)throw new Error("Unable to evaluate expression: missing source range information.");let[t,o]=e.range,s=n.source.slice(t,o),a=V(e,n);try{let p=new Function(...a,`"use strict"; return (${s});`),i=a.map(c=>n.placeholders.get(c));return p(...i)}catch(p){throw new Error(`Failed to evaluate expression ${s}: ${p.message}`)}},Z=e=>{let n=e.replace(/[^a-zA-Z0-9_$]/g,"");return n?/[A-Za-z_$]/.test(n[0])?n:`Component${n}`:"Component"},G=(e,n,r)=>{let t=r.get(e);if(t)return t;let o=e.displayName||e.name||`Component${n.length}`,s=Z(o??""),a=s,p=1;for(;n.some(c=>c.name===a);)a=`${s}${p++}`;let i={name:a,value:e};return n.push(i),r.set(e,i),i},N=(e,n)=>{let r=e.raw??e,t=new Map,o=[],s=new Map,a=r[0]??"",p=U++,i=0,c=[];for(let m=0;m<n.length;m++){let l=r[m]??"",d=r[m+1]??"",u=n[m],g=z.test(l)||W.test(l),f;if(g&&typeof u=="function")f=G(u,o,s).name;else if(g&&typeof u=="string")f=u;else {let h=`${X}${p}_${i++}__`;t.set(h,u),f=h;}let E=a.length;a+=f;let x=a.length;c.push({index:m,sourceStart:E,sourceEnd:x}),a+=d;}return {source:a,placeholders:t,bindings:o,diagnostics:{expressionRanges:c}}};var q=e=>!e||typeof e=="string"?false:typeof e[Symbol.iterator]=="function",Q=e=>!e||typeof e!="object"&&typeof e!="function"?false:typeof e.then=="function",y=(e,n)=>{if(n!=null&&typeof n!="boolean"){if(Q(n))throw new Error("Async values are not supported inside reactJsx template results.");if(Array.isArray(n)){n.forEach(r=>y(e,r));return}if(q(n)){for(let r of n)y(e,r);return}e.push(n);}},T=(e,n)=>M(e,n,r=>J(r,n)),Y=(e,n)=>{let r={};return e.forEach(t=>{if(t.type==="JSXSpreadAttribute"){let s=T(t.argument,n);s&&typeof s=="object"&&!Array.isArray(s)&&Object.assign(r,s);return}let o=S(t.name);if(!t.value){r[o]=true;return}if(t.value.type==="Literal"){r[o]=t.value.value;return}if(t.value.type==="JSXExpressionContainer"){if(t.value.expression.type==="JSXEmptyExpression")return;r[o]=T(t.value.expression,n);}}),r},I=(e,n)=>{let r=[];return e.forEach(t=>{switch(t.type){case "JSXText":{k(t.value,n.placeholders).forEach(s=>y(r,s));break}case "JSXExpressionContainer":{if(t.expression.type==="JSXEmptyExpression")break;y(r,T(t.expression,n));break}case "JSXSpreadChild":{let o=T(t.expression,n);o!=null&&y(r,o);break}case "JSXElement":case "JSXFragment":{r.push(J(t,n));break}}}),r},F=(e,n,r)=>createElement(e,n,...r),ee=(e,n)=>{let r=e.openingElement,t=S(r.name),o=n.components.get(t),s=Y(r.attributes,n),a=I(e.children,n);if(o)return F(o,s,a);if(/[A-Z]/.test(t[0]??""))throw new Error(`Unknown component "${t}". Did you interpolate it with the template literal?`);return F(t,s,a)},J=(e,n)=>{if(e.type==="JSXFragment"){let r=I(e.children,n);return createElement(Fragment,null,...r)}return ee(e,n)},te=(e,...n)=>{let r=N(e,n),t=parseSync("inline.jsx",r.source,$);if(t.errors.length>0)throw new Error(b("reactJsx",e,r.diagnostics,t.errors[0]));let o=A(t.program),s={source:r.source,placeholders:r.placeholders,components:new Map(r.bindings.map(a=>[a.name,a.value]))};return J(o,s)};export{te as reactJsx};
|
package/dist/loader/jsx.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
import { type SourceMap } from 'magic-string';
|
|
2
|
+
type LoaderCallback = (error: Error | null, content?: string, map?: SourceMap | null) => void;
|
|
2
3
|
type LoaderContext<TOptions> = {
|
|
3
4
|
resourcePath: string;
|
|
4
5
|
async(): LoaderCallback;
|
|
@@ -24,6 +25,10 @@ type LoaderOptions = {
|
|
|
24
25
|
* Optional per-tag override of the transformation mode. Keys map to tag names.
|
|
25
26
|
*/
|
|
26
27
|
tagModes?: Record<string, LoaderMode | undefined>;
|
|
28
|
+
/**
|
|
29
|
+
* When true, generate inline source maps for mutated files.
|
|
30
|
+
*/
|
|
31
|
+
sourceMap?: boolean;
|
|
27
32
|
};
|
|
28
33
|
export default function jsxLoader(this: LoaderContext<LoaderOptions>, input: string | Buffer): void;
|
|
29
34
|
export {};
|