diff --git a/compiler/packages/babel-plugin-react-forget/src/HIR/BuildHIR.ts b/compiler/packages/babel-plugin-react-forget/src/HIR/BuildHIR.ts index 468a81b1d8..c68fc05ba0 100644 --- a/compiler/packages/babel-plugin-react-forget/src/HIR/BuildHIR.ts +++ b/compiler/packages/babel-plugin-react-forget/src/HIR/BuildHIR.ts @@ -1967,6 +1967,7 @@ function lowerExpression( case "JSXElement": { const expr = exprPath as NodePath; const opening = expr.get("openingElement"); + const openingLoc = opening.node.loc ?? GeneratedSource; const tag = lowerJsxElementName(builder, opening.get("name")); const props: Array = []; for (const attribute of opening.get("attributes")) { @@ -2073,7 +2074,7 @@ function lowerExpression( return lowerValueToTemporary(builder, { kind: "JSXText", value: text, - loc: exprLoc, + loc: child.node.loc ?? GeneratedSource, }); } return lowerJsxElement(builder, child); @@ -2091,6 +2092,8 @@ function lowerExpression( props, children: children.length === 0 ? null : children, loc: exprLoc, + openingLoc: openingLoc, + closingLoc: expr.get("closingElement").node?.loc ?? GeneratedSource, }; } case "JSXFragment": { diff --git a/compiler/packages/babel-plugin-react-forget/src/HIR/HIR.ts b/compiler/packages/babel-plugin-react-forget/src/HIR/HIR.ts index 4e152e6974..fac8d7b7c3 100644 --- a/compiler/packages/babel-plugin-react-forget/src/HIR/HIR.ts +++ b/compiler/packages/babel-plugin-react-forget/src/HIR/HIR.ts @@ -795,6 +795,8 @@ export type InstructionValue = props: Array; children: Array | null; // null === no children loc: SourceLocation; + openingLoc: SourceLocation; + closingLoc: SourceLocation; } | { kind: "ObjectExpression"; diff --git a/compiler/packages/babel-plugin-react-forget/src/ReactiveScopes/CodegenReactiveFunction.ts b/compiler/packages/babel-plugin-react-forget/src/ReactiveScopes/CodegenReactiveFunction.ts index e16c23a940..61651c2f0d 100644 --- a/compiler/packages/babel-plugin-react-forget/src/ReactiveScopes/CodegenReactiveFunction.ts +++ b/compiler/packages/babel-plugin-react-forget/src/ReactiveScopes/CodegenReactiveFunction.ts @@ -1089,6 +1089,7 @@ const createJsxIdentifier = withLoc(t.jsxIdentifier); const createJsxExpressionContainer = withLoc(t.jsxExpressionContainer); const createJsxText = withLoc(t.jsxText); const createJsxClosingElement = withLoc(t.jsxClosingElement); +const createJsxOpeningElement = withLoc(t.jsxOpeningElement); const createStringLiteral = withLoc(t.stringLiteral); function createHookGuard( @@ -1515,9 +1516,14 @@ function codegenInstructionValue( } value = createJsxElement( instrValue.loc, - t.jsxOpeningElement(tag, attributes, instrValue.children === null), + createJsxOpeningElement( + instrValue.openingLoc, + tag, + attributes, + instrValue.children === null + ), instrValue.children !== null - ? createJsxClosingElement(instrValue.tag.loc, tag) + ? createJsxClosingElement(instrValue.closingLoc, tag) : null, children, instrValue.children === null