@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.
Files changed (51) hide show
  1. package/README.md +1 -0
  2. package/dist/cjs/cli/init.cjs +15 -0
  3. package/dist/cjs/debug/diagnostics.cjs +57 -0
  4. package/dist/cjs/debug/diagnostics.d.cts +6 -0
  5. package/dist/cjs/debug/index.cjs +7 -0
  6. package/dist/cjs/debug/index.d.cts +2 -0
  7. package/dist/cjs/internal/attribute-resolution.cjs +22 -4
  8. package/dist/cjs/internal/attribute-resolution.d.cts +5 -0
  9. package/dist/cjs/internal/dev-environment.cjs +41 -0
  10. package/dist/cjs/internal/dev-environment.d.cts +4 -0
  11. package/dist/cjs/internal/event-bindings.cjs +11 -2
  12. package/dist/cjs/internal/event-bindings.d.cts +5 -1
  13. package/dist/cjs/internal/template-diagnostics.cjs +171 -0
  14. package/dist/cjs/internal/template-diagnostics.d.cts +13 -0
  15. package/dist/cjs/jsx.cjs +2 -2
  16. package/dist/cjs/loader/jsx.cjs +72 -20
  17. package/dist/cjs/loader/jsx.d.cts +6 -1
  18. package/dist/cjs/node/debug/index.cjs +6 -0
  19. package/dist/cjs/node/debug/index.d.cts +2 -0
  20. package/dist/cjs/react/react-jsx.cjs +1 -1
  21. package/dist/cjs/runtime/shared.cjs +41 -22
  22. package/dist/cjs/runtime/shared.d.cts +5 -2
  23. package/dist/cli/init.js +17 -0
  24. package/dist/debug/diagnostics.d.ts +6 -0
  25. package/dist/debug/diagnostics.js +52 -0
  26. package/dist/debug/index.d.ts +2 -0
  27. package/dist/debug/index.js +3 -0
  28. package/dist/internal/attribute-resolution.d.ts +5 -0
  29. package/dist/internal/attribute-resolution.js +20 -3
  30. package/dist/internal/dev-environment.d.ts +4 -0
  31. package/dist/internal/dev-environment.js +34 -0
  32. package/dist/internal/event-bindings.d.ts +5 -1
  33. package/dist/internal/event-bindings.js +9 -1
  34. package/dist/internal/template-diagnostics.d.ts +13 -0
  35. package/dist/internal/template-diagnostics.js +167 -0
  36. package/dist/jsx.js +3 -3
  37. package/dist/lite/debug/diagnostics.js +1 -0
  38. package/dist/lite/debug/index.js +8 -0
  39. package/dist/lite/index.js +8 -4
  40. package/dist/lite/node/debug/index.js +8 -0
  41. package/dist/lite/node/index.js +8 -4
  42. package/dist/lite/node/react/index.js +7 -3
  43. package/dist/lite/react/index.js +7 -3
  44. package/dist/loader/jsx.d.ts +6 -1
  45. package/dist/loader/jsx.js +72 -20
  46. package/dist/node/debug/index.d.ts +2 -0
  47. package/dist/node/debug/index.js +6 -0
  48. package/dist/react/react-jsx.js +2 -2
  49. package/dist/runtime/shared.d.ts +5 -2
  50. package/dist/runtime/shared.js +39 -21
  51. package/package.json +39 -7
package/README.md CHANGED
@@ -19,6 +19,7 @@ A runtime JSX template tag backed by the [`oxc-parser`](https://github.com/oxc-p
19
19
  - [Loader integration](#loader-integration)
20
20
  - [Node / SSR usage](#node--ssr-usage)
21
21
  - [Browser usage](#browser-usage)
22
+ - [Development diagnostics](docs/development-diagnostics.md)
22
23
  - [TypeScript plugin](docs/ts-plugin.md)
23
24
  - [TypeScript guide](docs/typescript.md)
24
25
  - [Component testing](docs/testing.md)
@@ -165,6 +165,21 @@ function parsePackageName(spec) {
165
165
  return { name, version };
166
166
  }
167
167
  function readLocalOxcParserVersion(resolver = CLI_REQUIRE) {
168
+ try {
169
+ // Prefer the version installed alongside this CLI package, not a hoisted sibling.
170
+ const jsxPkgPath = resolver.resolve('@knighted/jsx/package.json');
171
+ const jsxRoot = node_path_1.default.dirname(jsxPkgPath);
172
+ const localParserPkg = node_path_1.default.join(jsxRoot, 'node_modules', 'oxc-parser', 'package.json');
173
+ if (node_fs_1.default.existsSync(localParserPkg)) {
174
+ const pkgJson = JSON.parse(node_fs_1.default.readFileSync(localParserPkg, 'utf8'));
175
+ if (pkgJson && typeof pkgJson.version === 'string') {
176
+ return pkgJson.version;
177
+ }
178
+ }
179
+ }
180
+ catch {
181
+ // Ignore resolution failures and fall back below.
182
+ }
168
183
  try {
169
184
  const pkg = resolver('oxc-parser/package.json');
170
185
  if (pkg && typeof pkg.version === 'string') {
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.disableJsxDebugDiagnostics = exports.enableJsxDebugDiagnostics = void 0;
4
+ const attribute_resolution_js_1 = require("../internal/attribute-resolution.cjs");
5
+ const event_bindings_js_1 = require("../internal/event-bindings.cjs");
6
+ const dev_environment_js_1 = require("../internal/dev-environment.cjs");
7
+ const isAsciiLowercase = (char) => char >= 'a' && char <= 'z';
8
+ let diagnosticsMode = 'env';
9
+ const shouldRunDiagnostics = () => diagnosticsMode === 'always' || (diagnosticsMode === 'env' && (0, dev_environment_js_1.isDevEnvironment)());
10
+ const shouldForceWarnings = () => diagnosticsMode === 'always';
11
+ const attributeDiagnostics = {
12
+ warnLowercaseEventProp(name) {
13
+ if (!shouldRunDiagnostics()) {
14
+ return;
15
+ }
16
+ if (!name.startsWith('on') || name.startsWith('on:') || name.length < 3) {
17
+ return;
18
+ }
19
+ const indicator = name[2] ?? '';
20
+ if (!isAsciiLowercase(indicator)) {
21
+ return;
22
+ }
23
+ const suggestion = `${name.slice(0, 2)}${indicator.toUpperCase()}${name.slice(3)}`;
24
+ (0, dev_environment_js_1.emitDevWarning)(`Use camelCase DOM event props when targeting runtime jsx templates. Received "${name}"; did you mean "${suggestion}"?`, shouldForceWarnings());
25
+ },
26
+ ensureValidDangerouslySetInnerHTML(value) {
27
+ if (!shouldRunDiagnostics()) {
28
+ return;
29
+ }
30
+ if (!value || typeof value !== 'object' || Array.isArray(value)) {
31
+ throw (0, dev_environment_js_1.createDevError)('dangerouslySetInnerHTML expects an object with a string __html field.');
32
+ }
33
+ const html = value.__html;
34
+ if (typeof html !== 'string') {
35
+ throw (0, dev_environment_js_1.createDevError)(`dangerouslySetInnerHTML.__html must be a string but received ${(0, dev_environment_js_1.describeValue)(html)}.`);
36
+ }
37
+ },
38
+ };
39
+ const eventDiagnostics = {
40
+ onInvalidHandler(propName, value) {
41
+ if (!shouldRunDiagnostics()) {
42
+ return;
43
+ }
44
+ throw (0, dev_environment_js_1.createDevError)(`The "${propName}" prop expects a function, EventListenerObject, or descriptor ({ handler }) but received ${(0, dev_environment_js_1.describeValue)(value)}.`);
45
+ },
46
+ };
47
+ const enableJsxDebugDiagnostics = (options) => {
48
+ diagnosticsMode = options?.mode ?? 'env';
49
+ (0, attribute_resolution_js_1.setAttributeDiagnosticsHooks)(attributeDiagnostics);
50
+ (0, event_bindings_js_1.setEventDiagnosticsHooks)(eventDiagnostics);
51
+ };
52
+ exports.enableJsxDebugDiagnostics = enableJsxDebugDiagnostics;
53
+ const disableJsxDebugDiagnostics = () => {
54
+ (0, attribute_resolution_js_1.setAttributeDiagnosticsHooks)(null);
55
+ (0, event_bindings_js_1.setEventDiagnosticsHooks)(null);
56
+ };
57
+ exports.disableJsxDebugDiagnostics = disableJsxDebugDiagnostics;
@@ -0,0 +1,6 @@
1
+ export type JsxDiagnosticsMode = 'env' | 'always';
2
+ export type EnableJsxDebugDiagnosticsOptions = {
3
+ mode?: JsxDiagnosticsMode;
4
+ };
5
+ export declare const enableJsxDebugDiagnostics: (options?: EnableJsxDebugDiagnosticsOptions) => void;
6
+ export declare const disableJsxDebugDiagnostics: () => void;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.jsx = void 0;
4
+ const diagnostics_js_1 = require("./diagnostics.cjs");
5
+ (0, diagnostics_js_1.enableJsxDebugDiagnostics)({ mode: 'always' });
6
+ var jsx_js_1 = require("../jsx.cjs");
7
+ Object.defineProperty(exports, "jsx", { enumerable: true, get: function () { return jsx_js_1.jsx; } });
@@ -0,0 +1,2 @@
1
+ export { jsx } from '../jsx.cjs';
2
+ export type { JsxRenderable, JsxComponent } from '../jsx.cjs';
@@ -1,10 +1,27 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createResolveAttributes = void 0;
3
+ exports.createResolveAttributes = exports.setAttributeDiagnosticsHooks = void 0;
4
+ let attributeDiagnostics = null;
5
+ const setAttributeDiagnosticsHooks = (hooks) => {
6
+ attributeDiagnostics = hooks;
7
+ };
8
+ exports.setAttributeDiagnosticsHooks = setAttributeDiagnosticsHooks;
9
+ const warnLowercaseEventProp = (name) => {
10
+ attributeDiagnostics?.warnLowercaseEventProp?.(name);
11
+ };
12
+ const ensureValidDangerouslySetInnerHTML = (value) => {
13
+ attributeDiagnostics?.ensureValidDangerouslySetInnerHTML?.(value);
14
+ };
4
15
  const createResolveAttributes = (deps) => {
5
16
  const { getIdentifierName, evaluateExpressionWithNamespace } = deps;
6
17
  return (attributes, ctx, namespace) => {
7
18
  const props = {};
19
+ const assignProp = (propName, propValue) => {
20
+ if (propName === 'dangerouslySetInnerHTML') {
21
+ ensureValidDangerouslySetInnerHTML(propValue);
22
+ }
23
+ props[propName] = propValue;
24
+ };
8
25
  attributes.forEach(attribute => {
9
26
  if (attribute.type === 'JSXSpreadAttribute') {
10
27
  const spreadValue = evaluateExpressionWithNamespace(attribute.argument, ctx, namespace);
@@ -16,19 +33,20 @@ const createResolveAttributes = (deps) => {
16
33
  return;
17
34
  }
18
35
  const name = getIdentifierName(attribute.name);
36
+ warnLowercaseEventProp(name);
19
37
  if (!attribute.value) {
20
- props[name] = true;
38
+ assignProp(name, true);
21
39
  return;
22
40
  }
23
41
  if (attribute.value.type === 'Literal') {
24
- props[name] = attribute.value.value;
42
+ assignProp(name, attribute.value.value);
25
43
  return;
26
44
  }
27
45
  if (attribute.value.type === 'JSXExpressionContainer') {
28
46
  if (attribute.value.expression.type === 'JSXEmptyExpression') {
29
47
  return;
30
48
  }
31
- props[name] = evaluateExpressionWithNamespace(attribute.value.expression, ctx, namespace);
49
+ assignProp(name, evaluateExpressionWithNamespace(attribute.value.expression, ctx, namespace));
32
50
  }
33
51
  });
34
52
  return props;
@@ -1,5 +1,10 @@
1
1
  import type { Expression, JSXAttribute, JSXElement, JSXFragment, JSXSpreadAttribute } from '@oxc-project/types';
2
2
  import type { TemplateComponent, TemplateContext } from '../runtime/shared.cjs';
3
+ export type AttributeDiagnosticsHooks = {
4
+ warnLowercaseEventProp?: (name: string) => void;
5
+ ensureValidDangerouslySetInnerHTML?: (value: unknown) => void;
6
+ };
7
+ export declare const setAttributeDiagnosticsHooks: (hooks: AttributeDiagnosticsHooks | null) => void;
3
8
  export type Namespace = 'svg' | null;
4
9
  export type EvaluateExpressionWithNamespace<TComponent extends TemplateComponent> = (expression: Expression | JSXElement | JSXFragment, ctx: TemplateContext<TComponent>, namespace: Namespace) => unknown;
5
10
  export type ResolveAttributesDependencies<TComponent extends TemplateComponent> = {
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.emitDevWarning = exports.createDevError = exports.describeValue = exports.isDevEnvironment = void 0;
4
+ const DEV_PREFIX = '@knighted/jsx';
5
+ const formatDevMessage = (message) => `${DEV_PREFIX}: ${message}`;
6
+ const isDevEnvironment = () => typeof process !== 'undefined' && process.env?.KNIGHTED_JSX_DEBUG === '1';
7
+ exports.isDevEnvironment = isDevEnvironment;
8
+ const describeValue = (value) => {
9
+ if (value === null) {
10
+ return 'null';
11
+ }
12
+ if (value === undefined) {
13
+ return 'undefined';
14
+ }
15
+ if (typeof value === 'function') {
16
+ return value.name ? `function ${value.name}` : 'function';
17
+ }
18
+ if (Array.isArray(value)) {
19
+ return 'array';
20
+ }
21
+ if (typeof value === 'object') {
22
+ const ctor = value.constructor;
23
+ if (ctor && typeof ctor.name === 'string' && ctor.name && ctor.name !== 'Object') {
24
+ return `${ctor.name} instance`;
25
+ }
26
+ return 'object';
27
+ }
28
+ return typeof value;
29
+ };
30
+ exports.describeValue = describeValue;
31
+ const createDevError = (message) => new Error(formatDevMessage(message));
32
+ exports.createDevError = createDevError;
33
+ const emitDevWarning = (message, force = false) => {
34
+ if (!force && !(0, exports.isDevEnvironment)()) {
35
+ return;
36
+ }
37
+ if (typeof console !== 'undefined' && typeof console.warn === 'function') {
38
+ console.warn(formatDevMessage(message));
39
+ }
40
+ };
41
+ exports.emitDevWarning = emitDevWarning;
@@ -0,0 +1,4 @@
1
+ export declare const isDevEnvironment: () => boolean;
2
+ export declare const describeValue: (value: unknown) => string;
3
+ export declare const createDevError: (message: string) => Error;
4
+ export declare const emitDevWarning: (message: string, force?: boolean) => void;
@@ -1,6 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.resolveEventHandlerValue = exports.parseEventPropName = void 0;
3
+ exports.resolveEventHandlerValue = exports.parseEventPropName = exports.setEventDiagnosticsHooks = void 0;
4
+ let eventDiagnostics = null;
5
+ const setEventDiagnosticsHooks = (hooks) => {
6
+ eventDiagnostics = hooks;
7
+ };
8
+ exports.setEventDiagnosticsHooks = setEventDiagnosticsHooks;
4
9
  const captureSuffix = 'Capture';
5
10
  const stripCaptureSuffix = (rawName) => {
6
11
  if (rawName.endsWith(captureSuffix)) {
@@ -54,11 +59,15 @@ const isEventHandlerDescriptor = (value) => {
54
59
  }
55
60
  return isEventListenerObject(handler);
56
61
  };
57
- const resolveEventHandlerValue = (value) => {
62
+ const throwInvalidHandlerError = (propName, value) => {
63
+ eventDiagnostics?.onInvalidHandler?.(propName, value);
64
+ };
65
+ const resolveEventHandlerValue = (propName, value) => {
58
66
  if (typeof value === 'function' || isEventListenerObject(value)) {
59
67
  return { listener: value };
60
68
  }
61
69
  if (!isEventHandlerDescriptor(value)) {
70
+ throwInvalidHandlerError(propName, value);
62
71
  return null;
63
72
  }
64
73
  const descriptor = value;
@@ -1,3 +1,7 @@
1
+ export type EventDiagnosticsHooks = {
2
+ onInvalidHandler?: (propName: string, value: unknown) => void;
3
+ };
4
+ export declare const setEventDiagnosticsHooks: (hooks: EventDiagnosticsHooks | null) => void;
1
5
  export type ParsedEventBinding = {
2
6
  eventName: string;
3
7
  capture: boolean;
@@ -15,4 +19,4 @@ export type ResolvedEventHandler = {
15
19
  listener: EventListenerOrEventListenerObject;
16
20
  options?: AddEventListenerOptions;
17
21
  };
18
- export declare const resolveEventHandlerValue: (value: unknown) => ResolvedEventHandler | null;
22
+ export declare const resolveEventHandlerValue: (propName: string, value: unknown) => ResolvedEventHandler | null;
@@ -0,0 +1,171 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.formatTaggedTemplateParserError = void 0;
4
+ const DEFAULT_LABEL = 'oxc-parser';
5
+ const buildTemplateDisplaySource = (templates) => {
6
+ const raw = templates.raw ?? templates;
7
+ let source = raw[0] ?? '';
8
+ const spans = [];
9
+ for (let idx = 0; idx < raw.length - 1; idx++) {
10
+ const label = '${expr#' + idx + '}';
11
+ const templateStart = source.length;
12
+ source += label;
13
+ const templateEnd = source.length;
14
+ spans.push({ index: idx, templateStart, templateEnd, label });
15
+ source += raw[idx + 1] ?? '';
16
+ }
17
+ return { source, spans };
18
+ };
19
+ const combineExpressionSpans = (diagnostics, templateSpans) => {
20
+ const templateSpanMap = new Map();
21
+ templateSpans.forEach(span => {
22
+ templateSpanMap.set(span.index, span);
23
+ });
24
+ return diagnostics.expressionRanges
25
+ .map(span => {
26
+ const templateSpan = templateSpanMap.get(span.index);
27
+ if (!templateSpan) {
28
+ return null;
29
+ }
30
+ const sourceLength = Math.max(0, span.sourceEnd - span.sourceStart);
31
+ const templateLength = Math.max(0, templateSpan.templateEnd - templateSpan.templateStart);
32
+ return {
33
+ sourceStart: span.sourceStart,
34
+ sourceEnd: span.sourceEnd,
35
+ templateStart: templateSpan.templateStart,
36
+ templateEnd: templateSpan.templateEnd,
37
+ delta: templateLength - sourceLength,
38
+ };
39
+ })
40
+ .filter((span) => Boolean(span))
41
+ .sort((a, b) => a.sourceStart - b.sourceStart);
42
+ };
43
+ const mapIndexToTemplate = (index, spans, templateLength) => {
44
+ if (!Number.isFinite(index) || index <= 0) {
45
+ return 0;
46
+ }
47
+ let delta = 0;
48
+ for (const span of spans) {
49
+ if (index < span.sourceStart) {
50
+ break;
51
+ }
52
+ if (index < span.sourceEnd) {
53
+ const relative = Math.max(0, index - span.sourceStart);
54
+ const templateSpanLength = Math.max(0, span.templateEnd - span.templateStart);
55
+ if (templateSpanLength === 0) {
56
+ return span.templateStart;
57
+ }
58
+ const clamped = Math.min(relative, Math.max(0, templateSpanLength - 1));
59
+ return span.templateStart + clamped;
60
+ }
61
+ delta += span.delta;
62
+ }
63
+ const mapped = index + delta;
64
+ if (mapped <= 0) {
65
+ return 0;
66
+ }
67
+ if (mapped >= templateLength) {
68
+ return templateLength;
69
+ }
70
+ return mapped;
71
+ };
72
+ const getLineAndColumnFromIndex = (source, index) => {
73
+ const limit = Math.max(0, Math.min(index, source.length));
74
+ let line = 1;
75
+ let column = 1;
76
+ for (let idx = 0; idx < limit; idx++) {
77
+ if (source.charCodeAt(idx) === 10) {
78
+ line++;
79
+ column = 1;
80
+ continue;
81
+ }
82
+ column++;
83
+ }
84
+ return { line, column };
85
+ };
86
+ const computeLineOffsets = (lines) => {
87
+ const offsets = [];
88
+ let cursor = 0;
89
+ lines.forEach((line, index) => {
90
+ offsets.push(cursor);
91
+ cursor += line.length;
92
+ if (index < lines.length - 1) {
93
+ cursor += 1;
94
+ }
95
+ });
96
+ return offsets;
97
+ };
98
+ const createPointerLine = (lineNumber, lineText, lineStartOffset, rangeStart, rangeEnd, startLine, endLine) => {
99
+ const lineEndOffset = lineStartOffset + lineText.length;
100
+ const overlapStart = Math.max(rangeStart, lineStartOffset);
101
+ const overlapEnd = Math.min(rangeEnd, lineEndOffset);
102
+ if (overlapEnd > overlapStart) {
103
+ const pointerStart = Math.max(0, overlapStart - lineStartOffset);
104
+ const pointerWidth = Math.max(1, overlapEnd - overlapStart);
105
+ return ' '.repeat(pointerStart) + '^'.repeat(pointerWidth);
106
+ }
107
+ if (lineText.length === 0 && lineNumber >= startLine && lineNumber <= endLine) {
108
+ return '^';
109
+ }
110
+ if (lineNumber === startLine) {
111
+ const caretPos = Math.max(0, rangeStart - lineStartOffset);
112
+ return ' '.repeat(Math.min(caretPos, lineText.length)) + '^';
113
+ }
114
+ return '';
115
+ };
116
+ const buildCodeFrame = (source, start, end, startLine, endLine) => {
117
+ if (!source.length) {
118
+ return '';
119
+ }
120
+ const lines = source.split('\n');
121
+ const offsets = computeLineOffsets(lines);
122
+ const frameStart = Math.max(1, startLine - 1);
123
+ const frameEnd = Math.min(lines.length, endLine + 1);
124
+ const gutterWidth = String(frameEnd).length;
125
+ const frame = [];
126
+ for (let lineNumber = frameStart; lineNumber <= frameEnd; lineNumber++) {
127
+ const lineText = lines[lineNumber - 1] ?? '';
128
+ const gutter = String(lineNumber).padStart(gutterWidth, ' ');
129
+ frame.push(`${gutter} | ${lineText}`);
130
+ const pointer = createPointerLine(lineNumber, lineText, offsets[lineNumber - 1] ?? 0, start, end, startLine, endLine);
131
+ if (pointer) {
132
+ frame.push(`${' '.repeat(gutterWidth)} | ${pointer}`);
133
+ }
134
+ }
135
+ return frame.join('\n');
136
+ };
137
+ const formatTaggedTemplateParserError = (tagName, templates, diagnostics, error, options) => {
138
+ const label = options?.label ?? DEFAULT_LABEL;
139
+ const fallback = `[${label}] ${error.message}`;
140
+ const primaryLabel = error.labels?.[0];
141
+ if (!primaryLabel) {
142
+ return fallback;
143
+ }
144
+ const { source: templateSource, spans } = buildTemplateDisplaySource(templates);
145
+ const combinedSpans = combineExpressionSpans(diagnostics, spans);
146
+ const mapIndex = (value) => {
147
+ const numeric = typeof value === 'number' ? value : 0;
148
+ return mapIndexToTemplate(numeric, combinedSpans, templateSource.length);
149
+ };
150
+ const startIndex = mapIndex(primaryLabel.start);
151
+ let endIndex = mapIndex(primaryLabel.end);
152
+ if (endIndex <= startIndex) {
153
+ endIndex = Math.min(templateSource.length, startIndex + 1);
154
+ }
155
+ const startLocation = getLineAndColumnFromIndex(templateSource, startIndex);
156
+ const endLocation = getLineAndColumnFromIndex(templateSource, Math.max(startIndex, endIndex - 1));
157
+ const codeframe = buildCodeFrame(templateSource, startIndex, endIndex, startLocation.line, endLocation.line);
158
+ let message = `[${label}] ${error.message}`;
159
+ message += `\n--> ${tagName} template:${startLocation.line}:${startLocation.column}`;
160
+ if (primaryLabel.message) {
161
+ message += `\n${primaryLabel.message}`;
162
+ }
163
+ if (codeframe) {
164
+ message += `\n${codeframe}`;
165
+ }
166
+ if (error.helpMessage) {
167
+ message += `\n${error.helpMessage}`;
168
+ }
169
+ return message;
170
+ };
171
+ exports.formatTaggedTemplateParserError = formatTaggedTemplateParserError;
@@ -0,0 +1,13 @@
1
+ import type { OxcError } from 'oxc-parser';
2
+ export type TemplateExpressionRange = {
3
+ index: number;
4
+ sourceStart: number;
5
+ sourceEnd: number;
6
+ };
7
+ export type TemplateDiagnostics = {
8
+ expressionRanges: TemplateExpressionRange[];
9
+ };
10
+ export type TaggedTemplateFormatOptions = {
11
+ label?: string;
12
+ };
13
+ export declare const formatTaggedTemplateParserError: (tagName: string, templates: TemplateStringsArray, diagnostics: TemplateDiagnostics, error: OxcError, options?: TaggedTemplateFormatOptions) => string;
package/dist/cjs/jsx.cjs CHANGED
@@ -116,7 +116,7 @@ const setDomProp = (element, name, value, namespace) => {
116
116
  }
117
117
  const eventBinding = (0, event_bindings_js_1.parseEventPropName)(name);
118
118
  if (eventBinding) {
119
- const handlerValue = (0, event_bindings_js_1.resolveEventHandlerValue)(value);
119
+ const handlerValue = (0, event_bindings_js_1.resolveEventHandlerValue)(name, value);
120
120
  if (handlerValue) {
121
121
  let options = handlerValue.options ? { ...handlerValue.options } : undefined;
122
122
  if (eventBinding.capture) {
@@ -311,7 +311,7 @@ const jsx = (templates, ...values) => {
311
311
  const build = (0, shared_js_1.buildTemplate)(templates, values);
312
312
  const result = (0, oxc_parser_1.parseSync)('inline.jsx', build.source, shared_js_1.parserOptions);
313
313
  if (result.errors.length > 0) {
314
- throw new Error((0, shared_js_1.formatParserError)(result.errors[0]));
314
+ throw new Error((0, shared_js_1.formatTaggedTemplateParserError)('jsx', templates, build.diagnostics, result.errors[0]));
315
315
  }
316
316
  const root = (0, shared_js_1.extractRootNode)(result.program);
317
317
  const ctx = {