Skip to content

transformer: classic runtime jsx with a spread prop is transformed incorrectly #13009

@sapphi-red

Description

@sapphi-red

For the following input, Oxc does not merge the injected props (_self, _source) to the normal props, which is incorrect:

import * as React from "react";

export function Foo(props) {
  return (
    <div {...props}>
      <p>a</p>
    </div>
  );
}

The actual output is:

import * as React from "react";
var _jsxFileName = "foo.jsx";
export function Foo(props) {
        return /* @__PURE__ */ React.createElement("div", props, {
                __self: this,
                __source: {
                        fileName: _jsxFileName,
                        lineNumber: 6,
                        columnNumber: 5
                }
        }, /* @__PURE__ */ React.createElement("p", {
                __self: this,
                __source: {
                        fileName: _jsxFileName,
                        lineNumber: 7,
                        columnNumber: 7
                }
        }, "a"));
}

The expected output is:

import * as React from "react";
var _jsxFileName = "foo.jsx";
export function Foo(props) {
        return /* @__PURE__ */ React.createElement("div", {
                ...props,
                __self: this,
                __source: {
                        fileName: _jsxFileName,
                        lineNumber: 6,
                        columnNumber: 5
                }
        }, /* @__PURE__ */ React.createElement("p", {
                __self: this,
                __source: {
                        fileName: _jsxFileName,
                        lineNumber: 7,
                        columnNumber: 7
                }
        }, "a"));
}

reproduction using transform function exposed from rolldown
swc playground

Metadata

Metadata

Assignees

Labels

A-transformerArea - Transformer / TranspilerP-highPriority - High

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions