fix(es/react): Align to babel@8 behavior (#7081)

**Related issue:**

 - Closes https://github.com/swc-project/swc/issues/7044.
This commit is contained in:
magic-akari 2023-03-16 11:35:17 +08:00 committed by GitHub
parent 60ccdab60e
commit 7b491a69a5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
76 changed files with 376 additions and 541 deletions

View File

@ -846,6 +846,7 @@ export interface ReactConfig {
development?: boolean;
/**
* Use `Object.assign()` instead of `_extends`. Defaults to false.
* @deprecated
*/
useBuiltins?: boolean;

View File

@ -1,4 +1,3 @@
import _extends from "@swc/helpers/src/_extends.mjs";
import { Writable } from "stream";
import React from "react";
import * as ReactDOMServer from "react-dom/server";
@ -248,14 +247,15 @@ export async function renderToHTML(req, res, pathname, query, renderOpts) {
locales: renderOpts.locales,
defaultLocale: renderOpts.defaultLocale,
AppTree: (props)=>{
return /*#__PURE__*/ React.createElement(AppContainer, null, /*#__PURE__*/ React.createElement(App, _extends({}, props, {
return /*#__PURE__*/ React.createElement(AppContainer, null, /*#__PURE__*/ React.createElement(App, {
...props,
Component: Component,
router: router
})));
}));
},
defaultGetInitialProps: async (docCtx)=>{
const enhanceApp = (AppComp)=>{
return (props)=>/*#__PURE__*/ React.createElement(AppComp, _extends({}, props));
return (props)=>/*#__PURE__*/ React.createElement(AppComp, props);
};
const { html , head } = await docCtx.renderPage({
enhanceApp
@ -559,10 +559,11 @@ export async function renderToHTML(req, res, pathname, query, renderOpts) {
throw new Error(`'router' and 'Component' can not be returned in getInitialProps from _app.js https://nextjs.org/docs/messages/cant-override-next-props`);
}
const { App: EnhancedApp , Component: EnhancedComponent } = enhanceComponents(options, App, Component);
const html = ReactDOMServer.renderToString(/*#__PURE__*/ React.createElement(AppContainer, null, /*#__PURE__*/ React.createElement(EnhancedApp, _extends({
const html = ReactDOMServer.renderToString(/*#__PURE__*/ React.createElement(AppContainer, null, /*#__PURE__*/ React.createElement(EnhancedApp, {
Component: EnhancedComponent,
router: router
}, props))));
router: router,
...props
})));
return {
html,
head
@ -583,7 +584,10 @@ export async function renderToHTML(req, res, pathname, query, renderOpts) {
bodyResult: piperFromArray([
docProps.html
]),
documentElement: (htmlProps)=>/*#__PURE__*/ React.createElement(Document, _extends({}, htmlProps, docProps)),
documentElement: (htmlProps)=>/*#__PURE__*/ React.createElement(Document, {
...htmlProps,
...docProps
}),
head: docProps.head,
headTags: await headTags(documentCtx),
styles: docProps.styles
@ -591,10 +595,11 @@ export async function renderToHTML(req, res, pathname, query, renderOpts) {
} else {
const content = ctx.err && ErrorDebug ? /*#__PURE__*/ React.createElement(ErrorDebug, {
error: ctx.err
}) : /*#__PURE__*/ React.createElement(AppContainer, null, /*#__PURE__*/ React.createElement(App, _extends({}, props, {
}) : /*#__PURE__*/ React.createElement(AppContainer, null, /*#__PURE__*/ React.createElement(App, {
...props,
Component: Component,
router: router
})));
}));
const bodyResult = concurrentFeatures ? await renderToStream(content, generateStaticHTML) : piperFromArray([
ReactDOMServer.renderToString(content)
]);

View File

@ -2,9 +2,8 @@
define([
"require",
"exports",
"@swc/helpers/src/_extends.mjs",
"react"
], function(require, exports, _extends, _react) {
], function(require, exports, _react) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
@ -26,7 +25,6 @@ define([
return NoOverload1;
}
});
_extends = _extends.default;
function MainButton(props) {
var linkProps = props;
if (linkProps.goTo) {
@ -34,24 +32,22 @@ define([
}
return this._buildMainButton(props);
}
var b0 = /*#__PURE__*/ _react.createElement(MainButton, _extends({}, {
var b0 = /*#__PURE__*/ _react.createElement(MainButton, {
onClick: function(k) {
console.log(k);
}
}, {
},
extra: true
})); // k has type "left" | "right"
}); // k has type "left" | "right"
var b2 = /*#__PURE__*/ _react.createElement(MainButton, {
onClick: function(k) {
console.log(k);
},
extra: true
}); // k has type "left" | "right"
var b3 = /*#__PURE__*/ _react.createElement(MainButton, _extends({}, {
goTo: "home"
}, {
var b3 = /*#__PURE__*/ _react.createElement(MainButton, {
goTo: "home",
extra: true
})); // goTo has type"home" | "contact"
}); // goTo has type"home" | "contact"
var b4 = /*#__PURE__*/ _react.createElement(MainButton, {
goTo: "home",
extra: true
@ -59,19 +55,17 @@ define([
function NoOverload(buttonProps) {
return undefined;
}
var c1 = /*#__PURE__*/ _react.createElement(NoOverload, _extends({}, {
var c1 = /*#__PURE__*/ _react.createElement(NoOverload, {
onClick: function(k) {
console.log(k);
}
}, {
},
extra: true
})); // k has type any
}); // k has type any
function NoOverload1(linkProps) {
return undefined;
}
var d1 = /*#__PURE__*/ _react.createElement(NoOverload1, _extends({}, {
goTo: "home"
}, {
var d1 = /*#__PURE__*/ _react.createElement(NoOverload1, {
goTo: "home",
extra: true
})); // goTo has type "home" | "contact"
}); // goTo has type "home" | "contact"
});

View File

@ -2,9 +2,8 @@
define([
"require",
"exports",
"@swc/helpers/src/_extends.mjs",
"react"
], function(require, exports, _extends, _react) {
], function(require, exports, _react) {
"use strict";
function MainButton(props) {
return props.goTo ? this._buildMainLink(props) : this._buildMainButton(props);
@ -28,25 +27,5 @@ define([
NoOverload1: function() {
return NoOverload1;
}
}), (_extends = _extends.default)({}, {
onClick: function(k) {
console.log(k);
}
}, {
extra: !0
}), _extends({}, {
goTo: "home"
}, {
extra: !0
}), _extends({}, {
onClick: function(k) {
console.log(k);
}
}, {
extra: !0
}), _extends({}, {
goTo: "home"
}, {
extra: !0
});
});

View File

@ -2,11 +2,10 @@
//// [declaration.d.ts]
//// [0.tsx]
///<reference path="declaration.d.ts" />
import _extends from "@swc/helpers/src/_extends.mjs";
import * as cx from 'classnames';
import * as React from "react";
let buttonProps; // any
let k = /*#__PURE__*/ React.createElement("button", _extends({}, buttonProps), /*#__PURE__*/ React.createElement("span", {
let k = /*#__PURE__*/ React.createElement("button", buttonProps, /*#__PURE__*/ React.createElement("span", {
className: cx('class1', {
class2: true
})

View File

@ -1,10 +1,8 @@
//// [correctlyMarkAliasAsReferences1.tsx]
//// [declaration.d.ts]
//// [0.tsx]
let buttonProps;
import _extends from "@swc/helpers/src/_extends.mjs";
import * as cx from 'classnames';
import * as React from "react";
_extends({}, buttonProps), cx('class1', {
cx('class1', {
class2: !0
});

View File

@ -2,11 +2,10 @@
//// [declaration.d.ts]
//// [0.tsx]
///<reference path="declaration.d.ts" />
import _extends from "@swc/helpers/src/_extends.mjs";
import * as cx from 'classnames';
import * as React from "react";
let buttonProps;
let k = /*#__PURE__*/ React.createElement("button", _extends({}, buttonProps), /*#__PURE__*/ React.createElement("span", {
let k = /*#__PURE__*/ React.createElement("button", buttonProps, /*#__PURE__*/ React.createElement("span", {
className: cx('class1', {
class2: true
})

View File

@ -1,10 +1,8 @@
//// [correctlyMarkAliasAsReferences2.tsx]
//// [declaration.d.ts]
//// [0.tsx]
let buttonProps;
import _extends from "@swc/helpers/src/_extends.mjs";
import * as cx from 'classnames';
import * as React from "react";
_extends({}, buttonProps), cx('class1', {
cx('class1', {
class2: !0
});

View File

@ -2,11 +2,10 @@
//// [declaration.d.ts]
//// [0.tsx]
///<reference path="declaration.d.ts" />
import _extends from "@swc/helpers/src/_extends.mjs";
import * as cx from 'classnames';
import * as React from "react";
let buttonProps;
let k = /*#__PURE__*/ React.createElement("button", _extends({}, buttonProps), /*#__PURE__*/ React.createElement("span", {
let k = /*#__PURE__*/ React.createElement("button", buttonProps, /*#__PURE__*/ React.createElement("span", {
className: cx('class1', {
class2: true
})

View File

@ -1,10 +1,8 @@
//// [correctlyMarkAliasAsReferences3.tsx]
//// [declaration.d.ts]
//// [0.tsx]
let buttonProps;
import _extends from "@swc/helpers/src/_extends.mjs";
import * as cx from 'classnames';
import * as React from "react";
_extends({}, buttonProps), cx('class1', {
cx('class1', {
class2: !0
});

View File

@ -2,11 +2,12 @@
//// [declaration.d.ts]
//// [0.tsx]
///<reference path="declaration.d.ts" />
import _extends from "@swc/helpers/src/_extends.mjs";
import _object_spread from "@swc/helpers/src/_object_spread.mjs";
import _object_spread_props from "@swc/helpers/src/_object_spread_props.mjs";
import * as cx from 'classnames';
import * as React from "react";
let buttonProps;
let k = /*#__PURE__*/ React.createElement("button", _extends({}, buttonProps, {
let k = /*#__PURE__*/ React.createElement("button", _object_spread_props(_object_spread({}, buttonProps), {
className: cx('class1', {
class2: true
})

View File

@ -2,10 +2,11 @@
//// [declaration.d.ts]
//// [0.tsx]
let buttonProps;
import _extends from "@swc/helpers/src/_extends.mjs";
import _object_spread from "@swc/helpers/src/_object_spread.mjs";
import _object_spread_props from "@swc/helpers/src/_object_spread_props.mjs";
import * as cx from 'classnames';
import * as React from "react";
_extends({}, buttonProps, {
_object_spread_props(_object_spread({}, buttonProps), {
className: cx('class1', {
class2: !0
})

View File

@ -4,13 +4,14 @@
Object.defineProperty(exports, "__esModule", {
value: true
});
var _extends = require("@swc/helpers/lib/_extends.js").default;
var _objectSpread = require("@swc/helpers/lib/_object_spread.js").default;
var _objectSpreadProps = require("@swc/helpers/lib/_object_spread_props.js").default;
var props = {
answer: 42
};
var a = /*#__PURE__*/ React.createElement("div", _extends({
var a = /*#__PURE__*/ React.createElement("div", _objectSpread({
key: "foo"
}, props), "text");
var b = /*#__PURE__*/ React.createElement("div", _extends({}, props, {
var b = /*#__PURE__*/ React.createElement("div", _objectSpreadProps(_objectSpread({}, props), {
key: "bar"
}), "text");

View File

@ -3,11 +3,11 @@
Object.defineProperty(exports, "__esModule", {
value: !0
});
var _extends = require("@swc/helpers/lib/_extends.js").default, props = {
var _objectSpread = require("@swc/helpers/lib/_object_spread.js").default, _objectSpreadProps = require("@swc/helpers/lib/_object_spread_props.js").default, props = {
answer: 42
};
_extends({
_objectSpread({
key: "foo"
}, props), _extends({}, props, {
}, props), _objectSpreadProps(_objectSpread({}, props), {
key: "bar"
});

View File

@ -4,13 +4,14 @@
Object.defineProperty(exports, "__esModule", {
value: true
});
var _extends = require("@swc/helpers/lib/_extends.js").default;
var _objectSpread = require("@swc/helpers/lib/_object_spread.js").default;
var _objectSpreadProps = require("@swc/helpers/lib/_object_spread_props.js").default;
var props = {
answer: 42
};
var a = /*#__PURE__*/ React.createElement("div", _extends({
var a = /*#__PURE__*/ React.createElement("div", _objectSpread({
key: "foo"
}, props), "text");
var b = /*#__PURE__*/ React.createElement("div", _extends({}, props, {
var b = /*#__PURE__*/ React.createElement("div", _objectSpreadProps(_objectSpread({}, props), {
key: "bar"
}), "text");

View File

@ -3,11 +3,11 @@
Object.defineProperty(exports, "__esModule", {
value: !0
});
var _extends = require("@swc/helpers/lib/_extends.js").default, props = {
var _objectSpread = require("@swc/helpers/lib/_object_spread.js").default, _objectSpreadProps = require("@swc/helpers/lib/_object_spread_props.js").default, props = {
answer: 42
};
_extends({
_objectSpread({
key: "foo"
}, props), _extends({}, props, {
}, props), _objectSpreadProps(_objectSpread({}, props), {
key: "bar"
});

View File

@ -1,5 +1,6 @@
//// [jsxReactTestSuite.tsx]
import _extends from "@swc/helpers/src/_extends.mjs";
import _object_spread from "@swc/helpers/src/_object_spread.mjs";
import _object_spread_props from "@swc/helpers/src/_object_spread_props.mjs";
/*#__PURE__*/ React.createElement("div", null, "text");
/*#__PURE__*/ React.createElement("div", null, this.props.children);
/*#__PURE__*/ React.createElement("div", null, /*#__PURE__*/ React.createElement("div", null, /*#__PURE__*/ React.createElement("br", null)), /*#__PURE__*/ React.createElement(Component, null, foo, /*#__PURE__*/ React.createElement("br", null), bar), /*#__PURE__*/ React.createElement("br", null));
@ -27,11 +28,11 @@ var x = /*#__PURE__*/ React.createElement("div", {
});
/*#__PURE__*/ React.createElement(Namespace.Component, null);
/*#__PURE__*/ React.createElement(Namespace.DeepNamespace.Component, null);
/*#__PURE__*/ React.createElement(Component, _extends({}, x, {
/*#__PURE__*/ React.createElement(Component, _object_spread_props(_object_spread({}, x), {
y: 2,
z: true
}));
/*#__PURE__*/ React.createElement(Component, _extends({}, this.props, {
/*#__PURE__*/ React.createElement(Component, _object_spread_props(_object_spread({}, this.props), {
sound: "moo"
}));
/*#__PURE__*/ React.createElement("font-face", null);
@ -39,25 +40,25 @@ var x = /*#__PURE__*/ React.createElement("div", {
x: y
});
/*#__PURE__*/ React.createElement("x-component", null);
/*#__PURE__*/ React.createElement(Component, _extends({}, x));
/*#__PURE__*/ React.createElement(Component, _extends({}, x, {
/*#__PURE__*/ React.createElement(Component, x);
/*#__PURE__*/ React.createElement(Component, _object_spread_props(_object_spread({}, x), {
y: 2
}));
/*#__PURE__*/ React.createElement(Component, _extends({}, x, {
/*#__PURE__*/ React.createElement(Component, _object_spread_props(_object_spread({}, x), {
y: 2,
z: true
}));
/*#__PURE__*/ React.createElement(Component, _extends({
/*#__PURE__*/ React.createElement(Component, _object_spread({
x: 1
}, y));
/*#__PURE__*/ React.createElement(Component, _extends({
/*#__PURE__*/ React.createElement(Component, _object_spread({
x: 1,
y: "2"
}, z, z), /*#__PURE__*/ React.createElement(Child, null));
/*#__PURE__*/ React.createElement(Component, _extends({
/*#__PURE__*/ React.createElement(Component, _object_spread_props(_object_spread({
x: "1"
}, (z = {
y: 2
}, z), {
}, z)), {
z: 3
}), "Text");

View File

@ -1,5 +1,6 @@
//// [jsxReactTestSuite.tsx]
import _extends from "@swc/helpers/src/_extends.mjs";
import _object_spread from "@swc/helpers/src/_object_spread.mjs";
import _object_spread_props from "@swc/helpers/src/_object_spread_props.mjs";
this.props.children, Component, foo, bar, Composite, this.props.children, Composite, Composite2;
var x = React.createElement("div", {
attr1: "foobar",
@ -7,25 +8,25 @@ var x = React.createElement("div", {
attr3: "foobarbazbug",
attr4: "baz"
});
Component, Namespace.Component, Namespace.DeepNamespace.Component, Component, _extends({}, x, {
Component, Namespace.Component, Namespace.DeepNamespace.Component, Component, _object_spread_props(_object_spread({}, x), {
y: 2,
z: !0
}), Component, _extends({}, this.props, {
}), Component, _object_spread_props(_object_spread({}, this.props), {
sound: "moo"
}), Component, y, Component, _extends({}, x), Component, _extends({}, x, {
}), Component, y, Component, Component, _object_spread_props(_object_spread({}, x), {
y: 2
}), Component, _extends({}, x, {
}), Component, _object_spread_props(_object_spread({}, x), {
y: 2,
z: !0
}), Component, _extends({
}), Component, _object_spread({
x: 1
}, y), Component, _extends({
}, y), Component, _object_spread({
x: 1,
y: "2"
}, z, z), Child, Component, _extends({
}, z, z), Child, Component, _object_spread_props(_object_spread({
x: "1"
}, z = {
y: 2
}, {
}), {
z: 3
});

View File

@ -1,5 +1,4 @@
//// [tsxAttributeErrors.tsx]
import _extends from "@swc/helpers/src/_extends.mjs";
// Error, number is not assignable to string
/*#__PURE__*/ React.createElement("div", {
text: 42
@ -12,7 +11,7 @@ import _extends from "@swc/helpers/src/_extends.mjs";
var attribs = {
text: 100
};
/*#__PURE__*/ React.createElement("div", _extends({}, attribs));
/*#__PURE__*/ React.createElement("div", attribs);
// No errors here
/*#__PURE__*/ React.createElement("span", {
foo: "bar",

View File

@ -1,5 +1 @@
//// [tsxAttributeErrors.tsx]
import _extends from "@swc/helpers/src/_extends.mjs";
_extends({}, {
text: 100
});

View File

@ -1,26 +1,27 @@
//// [file.tsx]
import _extends from "@swc/helpers/src/_extends.mjs";
import _object_spread from "@swc/helpers/src/_object_spread.mjs";
import _object_spread_props from "@swc/helpers/src/_object_spread_props.mjs";
// OK
var obj1 = {
x: "foo"
};
/*#__PURE__*/ React.createElement("test1", _extends({}, obj1));
/*#__PURE__*/ React.createElement("test1", obj1);
// Error, x is not string
var obj2 = {
x: 32
};
/*#__PURE__*/ React.createElement("test1", _extends({}, obj2));
/*#__PURE__*/ React.createElement("test1", obj2);
// Error, x is missing
var obj3 = {
y: 32
};
/*#__PURE__*/ React.createElement("test1", _extends({}, obj3));
/*#__PURE__*/ React.createElement("test1", obj3);
// OK
var obj4 = {
x: 32,
y: 32
};
/*#__PURE__*/ React.createElement("test1", _extends({}, obj4, {
/*#__PURE__*/ React.createElement("test1", _object_spread_props(_object_spread({}, obj4), {
x: "ok"
}));
// Error
@ -28,7 +29,7 @@ var obj5 = {
x: 32,
y: 32
};
/*#__PURE__*/ React.createElement("test1", _extends({
/*#__PURE__*/ React.createElement("test1", _object_spread({
x: "ok"
}, obj5));
// Ok
@ -37,11 +38,11 @@ var obj6 = {
y: 32,
extra: 100
};
/*#__PURE__*/ React.createElement("test1", _extends({}, obj6));
/*#__PURE__*/ React.createElement("test1", obj6);
// OK (spread override)
var obj7 = {
x: "foo"
};
/*#__PURE__*/ React.createElement("test1", _extends({
/*#__PURE__*/ React.createElement("test1", _object_spread({
x: 32
}, obj7));

View File

@ -1,26 +1,17 @@
//// [file.tsx]
import _extends from "@swc/helpers/src/_extends.mjs";
_extends({}, {
x: "foo"
}), _extends({}, {
x: 32
}), _extends({}, {
y: 32
}), _extends({}, {
import _object_spread from "@swc/helpers/src/_object_spread.mjs";
import _object_spread_props from "@swc/helpers/src/_object_spread_props.mjs";
_object_spread_props(_object_spread({}, {
x: 32,
y: 32
}, {
}), {
x: "ok"
}), _extends({
}), _object_spread({
x: "ok"
}, {
x: 32,
y: 32
}), _extends({}, {
x: "ok",
y: 32,
extra: 100
}), _extends({
}), _object_spread({
x: 32
}, {
x: "foo"

View File

@ -1,14 +1,13 @@
//// [file.tsx]
import _extends from "@swc/helpers/src/_extends.mjs";
// OK
/*#__PURE__*/ React.createElement("test1", _extends({}, {
/*#__PURE__*/ React.createElement("test1", {
x: function(n) {
return 0;
}
}));
});
// Error, no member 'len' on 'string'
/*#__PURE__*/ React.createElement("test1", _extends({}, {
/*#__PURE__*/ React.createElement("test1", {
x: function(n) {
return n.len;
}
}));
});

View File

@ -1,11 +1 @@
//// [file.tsx]
import _extends from "@swc/helpers/src/_extends.mjs";
_extends({}, {
x: function(n) {
return 0;
}
}), _extends({}, {
x: function(n) {
return n.len;
}
});

View File

@ -1,13 +1,12 @@
//// [file.tsx]
import _extends from "@swc/helpers/src/_extends.mjs";
function make1(obj) {
return /*#__PURE__*/ React.createElement("test1", _extends({}, obj)); // OK
return /*#__PURE__*/ React.createElement("test1", obj); // OK
}
function make2(obj) {
return /*#__PURE__*/ React.createElement("test1", _extends({}, obj)); // Error (x is number, not string)
return /*#__PURE__*/ React.createElement("test1", obj); // Error (x is number, not string)
}
function make3(obj) {
return /*#__PURE__*/ React.createElement("test1", _extends({}, obj)); // Error, missing x
return /*#__PURE__*/ React.createElement("test1", obj); // Error, missing x
}
/*#__PURE__*/ React.createElement("test1", _extends({}, {})); // Error, missing x
/*#__PURE__*/ React.createElement("test2", _extends({}, {})); // Error, missing toString
/*#__PURE__*/ React.createElement("test1", {}); // Error, missing x
/*#__PURE__*/ React.createElement("test2", {}); // Error, missing toString

View File

@ -1,3 +1 @@
//// [file.tsx]
import _extends from "@swc/helpers/src/_extends.mjs";
_extends({}, {}), _extends({}, {});

View File

@ -1,5 +1,4 @@
//// [file.tsx]
import _extends from "@swc/helpers/src/_extends.mjs";
var x;
// Should be OK
/*#__PURE__*/ React.createElement("test1", _extends({}, x));
/*#__PURE__*/ React.createElement("test1", x);

View File

@ -1,4 +1 @@
//// [file.tsx]
var x;
import _extends from "@swc/helpers/src/_extends.mjs";
_extends({}, x);

View File

@ -1,5 +1,4 @@
//// [file.tsx]
import _extends from "@swc/helpers/src/_extends.mjs";
var Obj1;
/*#__PURE__*/ React.createElement(Obj1, {
x: 10
@ -13,8 +12,8 @@ var Obj3;
x: 10
}); // Error
var attributes;
/*#__PURE__*/ React.createElement(Obj3, _extends({}, attributes)); // Error
/*#__PURE__*/ React.createElement(Obj3, _extends({}, {})); // OK
/*#__PURE__*/ React.createElement(Obj3, attributes); // Error
/*#__PURE__*/ React.createElement(Obj3, {}); // OK
var Obj4;
/*#__PURE__*/ React.createElement(Obj4, {
x: 10

View File

@ -1,4 +1 @@
//// [file.tsx]
var attributes;
import _extends from "@swc/helpers/src/_extends.mjs";
_extends({}, attributes), _extends({}, {});

View File

@ -1,16 +1,17 @@
//// [file.tsx]
import _extends from "@swc/helpers/src/_extends.mjs";
import _object_spread from "@swc/helpers/src/_object_spread.mjs";
import _object_spread_props from "@swc/helpers/src/_object_spread_props.mjs";
var p1, p2, p3;
var spreads1 = /*#__PURE__*/ React.createElement("div", _extends({}, p1), p2);
var spreads2 = /*#__PURE__*/ React.createElement("div", _extends({}, p1), p2);
var spreads3 = /*#__PURE__*/ React.createElement("div", _extends({
var spreads1 = /*#__PURE__*/ React.createElement("div", p1, p2);
var spreads2 = /*#__PURE__*/ React.createElement("div", p1, p2);
var spreads3 = /*#__PURE__*/ React.createElement("div", _object_spread({
x: p3
}, p1), p2);
var spreads4 = /*#__PURE__*/ React.createElement("div", _extends({}, p1, {
var spreads4 = /*#__PURE__*/ React.createElement("div", _object_spread_props(_object_spread({}, p1), {
x: p3
}), p2);
var spreads5 = /*#__PURE__*/ React.createElement("div", _extends({
var spreads5 = /*#__PURE__*/ React.createElement("div", _object_spread_props(_object_spread({
x: p2
}, p1, {
}, p1), {
y: p3
}), p2);

View File

@ -1,12 +1,13 @@
//// [file.tsx]
var p1, p2, p3;
import _extends from "@swc/helpers/src/_extends.mjs";
_extends({}, p1), _extends({}, p1), _extends({
import _object_spread from "@swc/helpers/src/_object_spread.mjs";
import _object_spread_props from "@swc/helpers/src/_object_spread_props.mjs";
_object_spread({
x: p3
}, p1), _extends({}, p1, {
}, p1), _object_spread_props(_object_spread({}, p1), {
x: p3
}), _extends({
}), _object_spread_props(_object_spread({
x: p2
}, p1, {
}, p1), {
y: p3
});

View File

@ -7,7 +7,6 @@
Object.defineProperty(exports, "__esModule", {
value: true
});
var _extends = require("@swc/helpers/lib/_extends.js").default;
var _interopRequireDefault = require("@swc/helpers/lib/_interop_require_default.js").default;
var _mod = /*#__PURE__*/ _interopRequireDefault(require("mod"));
// Should see mod_1['default'] in emit here
@ -15,4 +14,4 @@ var _mod = /*#__PURE__*/ _interopRequireDefault(require("mod"));
handler: _mod.default
});
// Should see mod_1['default'] in emit here
/*#__PURE__*/ React.createElement(Foo, _extends({}, _mod.default));
/*#__PURE__*/ React.createElement(Foo, _mod.default);

View File

@ -7,5 +7,5 @@
Object.defineProperty(exports, "__esModule", {
value: !0
});
var _extends = require("@swc/helpers/lib/_extends.js").default, _mod = (0, require("@swc/helpers/lib/_interop_require_default.js").default)(require("mod"));
Foo, _mod.default, Foo, _extends({}, _mod.default);
var _mod = (0, require("@swc/helpers/lib/_interop_require_default.js").default)(require("mod"));
Foo, _mod.default, Foo, _mod.default;

View File

@ -1,16 +1,17 @@
//// [file.tsx]
import _extends from "@swc/helpers/src/_extends.mjs";
import _object_spread from "@swc/helpers/src/_object_spread.mjs";
import _object_spread_props from "@swc/helpers/src/_object_spread_props.mjs";
var p1, p2, p3;
var spreads1 = /*#__PURE__*/ React.createElement("div", _extends({}, p1), p2);
var spreads2 = /*#__PURE__*/ React.createElement("div", _extends({}, p1), p2);
var spreads3 = /*#__PURE__*/ React.createElement("div", _extends({
var spreads1 = /*#__PURE__*/ React.createElement("div", p1, p2);
var spreads2 = /*#__PURE__*/ React.createElement("div", p1, p2);
var spreads3 = /*#__PURE__*/ React.createElement("div", _object_spread({
x: p3
}, p1), p2);
var spreads4 = /*#__PURE__*/ React.createElement("div", _extends({}, p1, {
var spreads4 = /*#__PURE__*/ React.createElement("div", _object_spread_props(_object_spread({}, p1), {
x: p3
}), p2);
var spreads5 = /*#__PURE__*/ React.createElement("div", _extends({
var spreads5 = /*#__PURE__*/ React.createElement("div", _object_spread_props(_object_spread({
x: p2
}, p1, {
}, p1), {
y: p3
}), p2);

View File

@ -1,12 +1,13 @@
//// [file.tsx]
var p1, p2, p3;
import _extends from "@swc/helpers/src/_extends.mjs";
_extends({}, p1), _extends({}, p1), _extends({
import _object_spread from "@swc/helpers/src/_object_spread.mjs";
import _object_spread_props from "@swc/helpers/src/_object_spread_props.mjs";
_object_spread({
x: p3
}, p1), _extends({}, p1, {
}, p1), _object_spread_props(_object_spread({}, p1), {
x: p3
}), _extends({
}), _object_spread_props(_object_spread({
x: p2
}, p1, {
}, p1), {
y: p3
});

View File

@ -1,8 +1,9 @@
//// [file.tsx]
import _extends from "@swc/helpers/src/_extends.mjs";
import _object_spread from "@swc/helpers/src/_object_spread.mjs";
import _object_spread_props from "@swc/helpers/src/_object_spread_props.mjs";
var p;
var openClosed1 = /*#__PURE__*/ React.createElement("div", null, blah);
// Should emit React.__spread({}, p, {x: 0})
var spread1 = /*#__PURE__*/ React.createElement("div", _extends({}, p, {
var spread1 = /*#__PURE__*/ React.createElement("div", _object_spread_props(_object_spread({}, p), {
x: 0
}));

View File

@ -1,6 +1,7 @@
//// [file.tsx]
var p;
import _extends from "@swc/helpers/src/_extends.mjs";
blah, _extends({}, p, {
import _object_spread from "@swc/helpers/src/_object_spread.mjs";
import _object_spread_props from "@swc/helpers/src/_object_spread_props.mjs";
blah, _object_spread_props(_object_spread({}, p), {
x: 0
});

View File

@ -19,13 +19,14 @@ var React;
Object.defineProperty(exports, "__esModule", {
value: true
});
var _extends = require("@swc/helpers/lib/_extends.js").default;
var _objectSpread = require("@swc/helpers/lib/_object_spread.js").default;
var _objectSpreadProps = require("@swc/helpers/lib/_object_spread_props.js").default;
var _test = require("./test");
// Should emit test_1.React.createElement
// and React.__spread
var foo;
var spread1 = /*#__PURE__*/ _test.React.createElement("div", _extends({
var spread1 = /*#__PURE__*/ _test.React.createElement("div", _objectSpreadProps(_objectSpread({
x: ""
}, foo, {
}, foo), {
y: ""
}));

View File

@ -18,9 +18,9 @@ Object.defineProperty(exports, "__esModule", {
Object.defineProperty(exports, "__esModule", {
value: !0
});
var foo, _extends = require("@swc/helpers/lib/_extends.js").default;
require("./test"), _extends({
var foo, _objectSpread = require("@swc/helpers/lib/_object_spread.js").default, _objectSpreadProps = require("@swc/helpers/lib/_object_spread_props.js").default;
require("./test"), _objectSpreadProps(_objectSpread({
x: ""
}, foo, {
}, foo), {
y: ""
});

View File

@ -7,7 +7,8 @@
Object.defineProperty(exports, "__esModule", {
value: true
});
var _extends = require("@swc/helpers/lib/_extends.js").default;
var _objectSpread = require("@swc/helpers/lib/_object_spread.js").default;
var _objectSpreadProps = require("@swc/helpers/lib/_object_spread_props.js").default;
var M;
(function(M) {
var React1;
@ -17,9 +18,9 @@ var M;
// Should emit M.React.createElement
// and M.React.__spread
var foo;
var spread1 = /*#__PURE__*/ React.createElement("div", _extends({
var spread1 = /*#__PURE__*/ React.createElement("div", _objectSpreadProps(_objectSpread({
x: ""
}, foo, {
}, foo), {
y: ""
}));
// Quotes

View File

@ -7,12 +7,12 @@
Object.defineProperty(exports, "__esModule", {
value: !0
});
var M, _extends = require("@swc/helpers/lib/_extends.js").default;
var M, _objectSpread = require("@swc/helpers/lib/_object_spread.js").default, _objectSpreadProps = require("@swc/helpers/lib/_object_spread_props.js").default;
!function(M) {
var React1;
M.React = React1;
}(M || (M = {})), M || (M = {}), _extends({
}(M || (M = {})), M || (M = {}), _objectSpreadProps(_objectSpread({
x: ""
}, void 0, {
}, void 0), {
y: ""
});

View File

@ -1,6 +1,5 @@
//// [file.tsx]
import _class_call_check from "@swc/helpers/src/_class_call_check.mjs";
import _extends from "@swc/helpers/src/_extends.mjs";
import _inherits from "@swc/helpers/src/_inherits.mjs";
import _create_super from "@swc/helpers/src/_create_super.mjs";
export var Empty = /*#__PURE__*/ function(_React_Component) {
@ -18,4 +17,4 @@ export var Empty = /*#__PURE__*/ function(_React_Component) {
return Empty;
}(React.Component);
// OK
var unionedSpread = /*#__PURE__*/ React.createElement(Empty, _extends({}, obj));
var unionedSpread = /*#__PURE__*/ React.createElement(Empty, obj);

View File

@ -1,6 +1,5 @@
//// [file.tsx]
import _class_call_check from "@swc/helpers/src/_class_call_check.mjs";
import _extends from "@swc/helpers/src/_extends.mjs";
import _inherits from "@swc/helpers/src/_inherits.mjs";
import _create_super from "@swc/helpers/src/_create_super.mjs";
export var Empty = function(_React_Component) {
@ -14,4 +13,4 @@ export var Empty = function(_React_Component) {
return React.createElement("div", null, "Hello");
}, Empty;
}(React.Component);
_extends({}, obj);
obj;

View File

@ -1,5 +1,4 @@
//// [tsxSpreadChildren.tsx]
import _extends from "@swc/helpers/src/_extends.mjs";
import _to_consumable_array from "@swc/helpers/src/_to_consumable_array.mjs";
function Todo(prop) {
return /*#__PURE__*/ React.createElement("div", null, prop.key.toString() + prop.todo);
@ -17,4 +16,4 @@ function TodoList(param) {
}))));
}
var x;
/*#__PURE__*/ React.createElement(TodoList, _extends({}, x));
/*#__PURE__*/ React.createElement(TodoList, x);

View File

@ -1,5 +1,2 @@
//// [tsxSpreadChildren.tsx]
var x;
import _extends from "@swc/helpers/src/_extends.mjs";
import _to_consumable_array from "@swc/helpers/src/_to_consumable_array.mjs";
_extends({}, x);

View File

@ -1,5 +1,4 @@
//// [tsxSpreadChildrenInvalidType.tsx]
import _extends from "@swc/helpers/src/_extends.mjs";
function Todo(prop) {
return /*#__PURE__*/ React.createElement("div", null, prop.key.toString() + prop.todo);
}
@ -17,4 +16,4 @@ function TodoListNoError({ todos }) {
}));
}
let x;
/*#__PURE__*/ React.createElement(TodoList, _extends({}, x));
/*#__PURE__*/ React.createElement(TodoList, x);

View File

@ -1,4 +1 @@
//// [tsxSpreadChildrenInvalidType.tsx]
let x;
import _extends from "@swc/helpers/src/_extends.mjs";
_extends({}, x);

View File

@ -1,5 +1,4 @@
//// [tsxSpreadChildrenInvalidType.tsx]
import _extends from "@swc/helpers/src/_extends.mjs";
import _to_consumable_array from "@swc/helpers/src/_to_consumable_array.mjs";
function Todo(prop) {
return /*#__PURE__*/ React.createElement("div", null, prop.key.toString() + prop.todo);
@ -26,4 +25,4 @@ function TodoListNoError(param) {
}))));
}
var x;
/*#__PURE__*/ React.createElement(TodoList, _extends({}, x));
/*#__PURE__*/ React.createElement(TodoList, x);

View File

@ -1,5 +1,2 @@
//// [tsxSpreadChildrenInvalidType.tsx]
var x;
import _extends from "@swc/helpers/src/_extends.mjs";
import _to_consumable_array from "@swc/helpers/src/_to_consumable_array.mjs";
_extends({}, x);

View File

@ -1,8 +1,7 @@
//// [a.tsx]
import _extends from "@swc/helpers/src/_extends.mjs";
var a = {};
var b = null;
var c = undefined;
var d = /*#__PURE__*/ React.createElement("div", _extends({}, a));
var e = /*#__PURE__*/ React.createElement("div", _extends({}, b));
var f = /*#__PURE__*/ React.createElement("div", _extends({}, c));
var d = /*#__PURE__*/ React.createElement("div", a);
var e = /*#__PURE__*/ React.createElement("div", b);
var f = /*#__PURE__*/ React.createElement("div", c);

View File

@ -1,3 +1 @@
//// [a.tsx]
import _extends from "@swc/helpers/src/_extends.mjs";
_extends({}, {}), _extends({}, null), _extends({}, void 0);

View File

@ -2,14 +2,16 @@
define([
"require",
"exports",
"@swc/helpers/src/_extends.mjs",
"@swc/helpers/src/_object_spread.mjs",
"@swc/helpers/src/_object_spread_props.mjs",
"react"
], function(require, exports, _extends, _react) {
], function(require, exports, _objectSpread, _objectSpreadProps, _react) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
_extends = _extends.default;
_objectSpread = _objectSpread.default;
_objectSpreadProps = _objectSpreadProps.default;
var obj = {
yy: 10,
yy1: "hello"
@ -24,28 +26,27 @@ define([
var defaultObj;
// OK
var c1 = /*#__PURE__*/ _react.createElement(OneThing, null);
var c2 = /*#__PURE__*/ _react.createElement(OneThing, _extends({}, obj));
var c3 = /*#__PURE__*/ _react.createElement(OneThing, _extends({}, {}));
var c4 = /*#__PURE__*/ _react.createElement(OneThing, _extends({}, obj1, obj));
var c5 = /*#__PURE__*/ _react.createElement(OneThing, _extends({}, obj1, {
yy: 42
}, {
var c2 = /*#__PURE__*/ _react.createElement(OneThing, obj);
var c3 = /*#__PURE__*/ _react.createElement(OneThing, {});
var c4 = /*#__PURE__*/ _react.createElement(OneThing, _objectSpread({}, obj1, obj));
var c5 = /*#__PURE__*/ _react.createElement(OneThing, _objectSpreadProps(_objectSpread({}, obj1), {
yy: 42,
yy1: "hi"
}));
var c6 = /*#__PURE__*/ _react.createElement(OneThing, _extends({}, obj1, {
var c6 = /*#__PURE__*/ _react.createElement(OneThing, _objectSpreadProps(_objectSpread({}, obj1), {
yy: 10000,
yy1: "true"
}));
var c7 = /*#__PURE__*/ _react.createElement(OneThing, _extends({}, defaultObj, {
var c7 = /*#__PURE__*/ _react.createElement(OneThing, _objectSpread(_objectSpreadProps(_objectSpread({}, defaultObj), {
yy: true
}, obj)); // No error. should pick second overload
}), obj)); // No error. should pick second overload
var c8 = /*#__PURE__*/ _react.createElement(OneThing, {
"ignore-prop": 100
});
var c9 = /*#__PURE__*/ _react.createElement(OneThing, _extends({}, {
var c9 = /*#__PURE__*/ _react.createElement(OneThing, {
"ignore-prop": 200
}));
var c10 = /*#__PURE__*/ _react.createElement(OneThing, _extends({}, obj2, {
});
var c10 = /*#__PURE__*/ _react.createElement(OneThing, _objectSpreadProps(_objectSpread({}, obj2), {
yy1: "boo"
}));
});

View File

@ -2,34 +2,32 @@
define([
"require",
"exports",
"@swc/helpers/src/_extends.mjs",
"@swc/helpers/src/_object_spread.mjs",
"@swc/helpers/src/_object_spread_props.mjs",
"react"
], function(require, exports, _extends, _react) {
], function(require, exports, _objectSpread, _objectSpreadProps, _react) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: !0
}), _extends = _extends.default;
}), _objectSpread = _objectSpread.default, _objectSpreadProps = _objectSpreadProps.default;
var defaultObj, obj = {
yy: 10,
yy1: "hello"
}, obj1 = {
yy: !0
};
OneThing, OneThing, _extends({}, obj), OneThing, _extends({}, {}), OneThing, _extends({}, obj1, obj), OneThing, _extends({}, obj1, {
yy: 42
}, {
OneThing, OneThing, OneThing, OneThing, _objectSpread({}, obj1, obj), OneThing, _objectSpreadProps(_objectSpread({}, obj1), {
yy: 42,
yy1: "hi"
}), OneThing, _extends({}, obj1, {
}), OneThing, _objectSpreadProps(_objectSpread({}, obj1), {
yy: 10000,
yy1: "true"
}), OneThing, _extends({}, defaultObj, {
}), OneThing, _objectSpread(_objectSpreadProps(_objectSpread({}, defaultObj), {
yy: !0
}, obj), OneThing, OneThing, _extends({}, {
"ignore-prop": 200
}), OneThing, _extends({}, {
}), obj), OneThing, OneThing, OneThing, _objectSpreadProps(_objectSpread({}, {
yy: 500,
"ignore-prop": "hello"
}, {
}), {
yy1: "boo"
});
});

View File

@ -2,13 +2,15 @@
define([
"require",
"exports",
"@swc/helpers/src/_extends.mjs"
], function(require, exports, _extends) {
"@swc/helpers/src/_object_spread.mjs",
"@swc/helpers/src/_object_spread_props.mjs"
], function(require, exports, _objectSpread, _objectSpreadProps) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
_extends = _extends.default;
_objectSpread = _objectSpread.default;
_objectSpreadProps = _objectSpreadProps.default;
var obj2;
// OK
var two1 = /*#__PURE__*/ React.createElement(ZeroThingOrTwoThing, null);
@ -16,11 +18,11 @@ define([
yy: 100,
yy1: "hello"
});
var two3 = /*#__PURE__*/ React.createElement(ZeroThingOrTwoThing, _extends({}, obj2)); // it is just any so we allow it to pass through
var two4 = /*#__PURE__*/ React.createElement(ZeroThingOrTwoThing, _extends({
var two3 = /*#__PURE__*/ React.createElement(ZeroThingOrTwoThing, obj2); // it is just any so we allow it to pass through
var two4 = /*#__PURE__*/ React.createElement(ZeroThingOrTwoThing, _objectSpread({
yy: 1000
}, obj2)); // it is just any so we allow it to pass through
var two5 = /*#__PURE__*/ React.createElement(ZeroThingOrTwoThing, _extends({}, obj2, {
var two5 = /*#__PURE__*/ React.createElement(ZeroThingOrTwoThing, _objectSpreadProps(_objectSpread({}, obj2), {
yy: 1000
})); // it is just any so we allow it to pass through
// OK
@ -31,7 +33,7 @@ define([
var three2 = /*#__PURE__*/ React.createElement(ThreeThing, {
y2: "Bye"
});
var three3 = /*#__PURE__*/ React.createElement(ThreeThing, _extends({}, obj2, {
var three3 = /*#__PURE__*/ React.createElement(ThreeThing, _objectSpreadProps(_objectSpread({}, obj2), {
y2: 10
})); // it is just any so we allow it to pass through
});

View File

@ -2,17 +2,18 @@
define([
"require",
"exports",
"@swc/helpers/src/_extends.mjs"
], function(require, exports, _extends) {
"@swc/helpers/src/_object_spread.mjs",
"@swc/helpers/src/_object_spread_props.mjs"
], function(require, exports, _objectSpread, _objectSpreadProps) {
"use strict";
var obj2;
Object.defineProperty(exports, "__esModule", {
value: !0
}), _extends = _extends.default, ZeroThingOrTwoThing, ZeroThingOrTwoThing, ZeroThingOrTwoThing, _extends({}, obj2), ZeroThingOrTwoThing, _extends({
}), _objectSpread = _objectSpread.default, _objectSpreadProps = _objectSpreadProps.default, ZeroThingOrTwoThing, ZeroThingOrTwoThing, ZeroThingOrTwoThing, ZeroThingOrTwoThing, _objectSpread({
yy: 1000
}, obj2), ZeroThingOrTwoThing, _extends({}, obj2, {
}, obj2), ZeroThingOrTwoThing, _objectSpreadProps(_objectSpread({}, obj2), {
yy: 1000
}), ThreeThing, ThreeThing, ThreeThing, _extends({}, obj2, {
}), ThreeThing, ThreeThing, ThreeThing, _objectSpreadProps(_objectSpread({}, obj2), {
y2: 10
});
});

View File

@ -2,14 +2,16 @@
define([
"require",
"exports",
"@swc/helpers/src/_extends.mjs",
"@swc/helpers/src/_object_spread.mjs",
"@swc/helpers/src/_object_spread_props.mjs",
"react"
], function(require, exports, _extends, _react) {
], function(require, exports, _objectSpread, _objectSpreadProps, _react) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
_extends = _extends.default;
_objectSpread = _objectSpread.default;
_objectSpreadProps = _objectSpreadProps.default;
var obj = {
yy: 10,
yy1: "hello"
@ -22,22 +24,22 @@ define([
var c1 = /*#__PURE__*/ _react.createElement(OneThing, {
yy: 10
}); // missing property;
var c2 = /*#__PURE__*/ _react.createElement(OneThing, _extends({}, obj, {
var c2 = /*#__PURE__*/ _react.createElement(OneThing, _objectSpreadProps(_objectSpread({}, obj), {
yy1: true
})); // type incompatible;
var c3 = /*#__PURE__*/ _react.createElement(OneThing, _extends({}, obj, {
var c3 = /*#__PURE__*/ _react.createElement(OneThing, _objectSpreadProps(_objectSpread({}, obj), {
extra: "extra attr"
})); // This is OK because all attribute are spread
var c4 = /*#__PURE__*/ _react.createElement(OneThing, _extends({}, obj, {
var c4 = /*#__PURE__*/ _react.createElement(OneThing, _objectSpreadProps(_objectSpread({}, obj), {
y1: 10000
})); // extra property;
var c5 = /*#__PURE__*/ _react.createElement(OneThing, _extends({}, obj, {
var c5 = /*#__PURE__*/ _react.createElement(OneThing, _objectSpreadProps(_objectSpread({}, obj), {
yy: true
})); // type incompatible;
var c6 = /*#__PURE__*/ _react.createElement(OneThing, _extends({}, obj2, {
var c6 = /*#__PURE__*/ _react.createElement(OneThing, _objectSpreadProps(_objectSpread({}, obj2), {
extra: "extra attr"
})); // Should error as there is extra attribute that doesn't match any. Current it is not
var c7 = /*#__PURE__*/ _react.createElement(OneThing, _extends({}, obj2, {
var c7 = /*#__PURE__*/ _react.createElement(OneThing, _objectSpreadProps(_objectSpread({}, obj2), {
yy: true
})); // Should error as there is extra attribute that doesn't match any. Current it is not
// Error

View File

@ -2,28 +2,29 @@
define([
"require",
"exports",
"@swc/helpers/src/_extends.mjs",
"@swc/helpers/src/_object_spread.mjs",
"@swc/helpers/src/_object_spread_props.mjs",
"react"
], function(require, exports, _extends, _react) {
], function(require, exports, _objectSpread, _objectSpreadProps, _react) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: !0
}), _extends = _extends.default;
}), _objectSpread = _objectSpread.default, _objectSpreadProps = _objectSpreadProps.default;
var obj2, obj = {
yy: 10,
yy1: "hello"
};
OneThing, OneThing, OneThing, _extends({}, obj, {
OneThing, OneThing, OneThing, _objectSpreadProps(_objectSpread({}, obj), {
yy1: !0
}), OneThing, _extends({}, obj, {
}), OneThing, _objectSpreadProps(_objectSpread({}, obj), {
extra: "extra attr"
}), OneThing, _extends({}, obj, {
}), OneThing, _objectSpreadProps(_objectSpread({}, obj), {
y1: 10000
}), OneThing, _extends({}, obj, {
}), OneThing, _objectSpreadProps(_objectSpread({}, obj), {
yy: !0
}), OneThing, _extends({}, obj2, {
}), OneThing, _objectSpreadProps(_objectSpread({}, obj2), {
extra: "extra attr"
}), OneThing, _extends({}, obj2, {
}), OneThing, _objectSpreadProps(_objectSpread({}, obj2), {
yy: !0
}), TestingOneThing, TestingOneThing, TestingOptional, TestingOptional, TestingOptional, TestingOptional;
});

View File

@ -2,9 +2,10 @@
define([
"require",
"exports",
"@swc/helpers/src/_extends.mjs",
"@swc/helpers/src/_object_spread.mjs",
"@swc/helpers/src/_object_spread_props.mjs",
"react"
], function(require, exports, _extends, _react) {
], function(require, exports, _objectSpread, _objectSpreadProps, _react) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
@ -15,7 +16,8 @@ define([
return MainButton;
}
});
_extends = _extends.default;
_objectSpread = _objectSpread.default;
_objectSpreadProps = _objectSpreadProps.default;
var obj0 = {
to: "world"
};
@ -39,34 +41,31 @@ define([
to: "/some/path",
onClick: function(e) {}
}, "GO"); // extra property;
var b1 = /*#__PURE__*/ _react.createElement(MainButton, _extends({
var b1 = /*#__PURE__*/ _react.createElement(MainButton, _objectSpread({
onClick: function(e) {}
}, obj0), "Hello world"); // extra property;
var b2 = /*#__PURE__*/ _react.createElement(MainButton, _extends({}, {
var b2 = /*#__PURE__*/ _react.createElement(MainButton, _objectSpread({
to: "10000"
}, obj2)); // extra property
var b3 = /*#__PURE__*/ _react.createElement(MainButton, _extends({}, {
to: "10000"
}, {
var b3 = /*#__PURE__*/ _react.createElement(MainButton, {
to: "10000",
onClick: function(k) {}
})); // extra property
var b4 = /*#__PURE__*/ _react.createElement(MainButton, _extends({}, obj3, {
}); // extra property
var b4 = /*#__PURE__*/ _react.createElement(MainButton, _objectSpreadProps(_objectSpread({}, obj3), {
to: true
})); // Should error because Incorrect type; but attributes are any so everything is allowed
var b5 = /*#__PURE__*/ _react.createElement(MainButton, _extends({}, {
var b5 = /*#__PURE__*/ _react.createElement(MainButton, _objectSpread({
onClick: function onClick(e) {}
}, obj0)); // Spread retain method declaration (see GitHub #13365), so now there is an extra attributes
var b6 = /*#__PURE__*/ _react.createElement(MainButton, _extends({}, {
onClick: function onClick(e) {}
}, {
var b6 = /*#__PURE__*/ _react.createElement(MainButton, {
onClick: function onClick(e) {},
children: 10
})); // incorrect type for optional attribute
var b7 = /*#__PURE__*/ _react.createElement(MainButton, _extends({}, {
onClick: function onClick(e) {}
}, {
}); // incorrect type for optional attribute
var b7 = /*#__PURE__*/ _react.createElement(MainButton, {
onClick: function onClick(e) {},
children: "hello",
className: true
})); // incorrect type for optional attribute
}); // incorrect type for optional attribute
var b8 = /*#__PURE__*/ _react.createElement(MainButton, {
"data-format": true
}); // incorrect type for specified hyphanated name

View File

@ -2,9 +2,10 @@
define([
"require",
"exports",
"@swc/helpers/src/_extends.mjs",
"@swc/helpers/src/_object_spread.mjs",
"@swc/helpers/src/_object_spread_props.mjs",
"react"
], function(require, exports, _extends, _react) {
], function(require, exports, _objectSpread, _objectSpreadProps, _react) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: !0
@ -13,35 +14,22 @@ define([
get: function() {
return MainButton;
}
});
}), _objectSpread = _objectSpread.default, _objectSpreadProps = _objectSpreadProps.default;
var obj3, obj0 = {
to: "world"
};
function MainButton(props) {
return props.to ? this._buildMainLink(props) : this._buildMainButton(props);
}
(_extends = _extends.default)({
_objectSpread({
onClick: function(e) {}
}, obj0), _extends({}, {
}, obj0), _objectSpread({
to: "10000"
}, {
onClick: function() {}
}), _extends({}, {
to: "10000"
}, {
onClick: function(k) {}
}), _extends({}, obj3, {
}), _objectSpreadProps(_objectSpread({}, obj3), {
to: !0
}), _extends({}, {
}), _objectSpread({
onClick: function(e) {}
}, obj0), _extends({}, {
onClick: function(e) {}
}, {
children: 10
}), _extends({}, {
onClick: function(e) {}
}, {
children: "hello",
className: !0
});
}, obj0);
});

View File

@ -2,9 +2,10 @@
define([
"require",
"exports",
"@swc/helpers/src/_extends.mjs",
"@swc/helpers/src/_object_spread.mjs",
"@swc/helpers/src/_object_spread_props.mjs",
"react"
], function(require, exports, _extends, _react) {
], function(require, exports, _objectSpread, _objectSpreadProps, _react) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
@ -15,7 +16,8 @@ define([
return MainButton;
}
});
_extends = _extends.default;
_objectSpread = _objectSpread.default;
_objectSpreadProps = _objectSpreadProps.default;
var obj = {
children: "hi",
to: "boo"
@ -38,23 +40,23 @@ define([
var b1 = /*#__PURE__*/ _react.createElement(MainButton, {
onClick: function(e) {}
}, "Hello world");
var b2 = /*#__PURE__*/ _react.createElement(MainButton, _extends({}, obj));
var b3 = /*#__PURE__*/ _react.createElement(MainButton, _extends({}, {
var b2 = /*#__PURE__*/ _react.createElement(MainButton, obj);
var b3 = /*#__PURE__*/ _react.createElement(MainButton, _objectSpread({
to: 10000
}, obj));
var b4 = /*#__PURE__*/ _react.createElement(MainButton, _extends({}, obj1)); // any; just pick the first overload
var b5 = /*#__PURE__*/ _react.createElement(MainButton, _extends({}, obj1, {
var b4 = /*#__PURE__*/ _react.createElement(MainButton, obj1); // any; just pick the first overload
var b5 = /*#__PURE__*/ _react.createElement(MainButton, _objectSpreadProps(_objectSpread({}, obj1), {
to: "/to/somewhere"
})); // should pick the second overload
var b6 = /*#__PURE__*/ _react.createElement(MainButton, _extends({}, obj2));
var b7 = /*#__PURE__*/ _react.createElement(MainButton, _extends({}, {
var b6 = /*#__PURE__*/ _react.createElement(MainButton, obj2);
var b7 = /*#__PURE__*/ _react.createElement(MainButton, {
onClick: function() {
console.log("hi");
}
}));
var b8 = /*#__PURE__*/ _react.createElement(MainButton, _extends({}, {
});
var b8 = /*#__PURE__*/ _react.createElement(MainButton, {
onClick: function onClick() {}
})); // OK; method declaration get retained (See GitHub #13365)
}); // OK; method declaration get retained (See GitHub #13365)
var b9 = /*#__PURE__*/ _react.createElement(MainButton, {
to: "/some/path",
"extra-prop": true

View File

@ -2,10 +2,15 @@
define([
"require",
"exports",
"@swc/helpers/src/_extends.mjs",
"@swc/helpers/src/_object_spread.mjs",
"@swc/helpers/src/_object_spread_props.mjs",
"react"
], function(require, exports, _extends, _react) {
], function(require, exports, _objectSpread, _objectSpreadProps, _react) {
"use strict";
var obj1;
function MainButton(props) {
return props.to ? this._buildMainLink(props) : this._buildMainButton(props);
}
Object.defineProperty(exports, "__esModule", {
value: !0
}), Object.defineProperty(exports, "MainButton", {
@ -13,25 +18,12 @@ define([
get: function() {
return MainButton;
}
});
var obj1, obj = {
}), _objectSpread = _objectSpread.default, _objectSpreadProps = _objectSpreadProps.default, _objectSpread({
to: 10000
}, {
children: "hi",
to: "boo"
};
function MainButton(props) {
return props.to ? this._buildMainLink(props) : this._buildMainButton(props);
}
(_extends = _extends.default)({}, obj), _extends({}, {
to: 10000
}, obj), _extends({}, obj1), _extends({}, obj1, {
}), _objectSpreadProps(_objectSpread({}, obj1), {
to: "/to/somewhere"
}), _extends({}, {
onClick: function() {}
}), _extends({}, {
onClick: function() {
console.log("hi");
}
}), _extends({}, {
onClick: function() {}
});
});

View File

@ -2,26 +2,23 @@
define([
"require",
"exports",
"@swc/helpers/src/_extends.mjs",
"react"
], function(require, exports, _extends, _react) {
], function(require, exports, _react) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
_extends = _extends.default;
// OK
function Baz(key1, value) {
var a0 = /*#__PURE__*/ _react.createElement(ComponentWithTwoAttributes, {
key1: key1,
value: value
});
var a1 = /*#__PURE__*/ _react.createElement(ComponentWithTwoAttributes, _extends({}, {
var a1 = /*#__PURE__*/ _react.createElement(ComponentWithTwoAttributes, {
key1: key1,
value: value
}, {
value: value,
key: "Component"
}));
});
}
// OK
function createLink(func) {

View File

@ -2,11 +2,10 @@
define([
"require",
"exports",
"@swc/helpers/src/_extends.mjs",
"react"
], function(require, exports, _extends, _react) {
], function(require, exports, _react) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: !0
}), _extends = _extends.default, InferParamComponent;
}), InferParamComponent;
});

View File

@ -2,23 +2,25 @@
define([
"require",
"exports",
"@swc/helpers/src/_extends.mjs",
"@swc/helpers/src/_object_spread.mjs",
"@swc/helpers/src/_object_spread_props.mjs",
"react"
], function(require, exports, _extends, _react) {
], function(require, exports, _objectSpread, _objectSpreadProps, _react) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
_extends = _extends.default;
_objectSpread = _objectSpread.default;
_objectSpreadProps = _objectSpreadProps.default;
// Error
function Bar(arg) {
var a1 = /*#__PURE__*/ _react.createElement(ComponentSpecific1, _extends({}, arg, {
var a1 = /*#__PURE__*/ _react.createElement(ComponentSpecific1, _objectSpreadProps(_objectSpread({}, arg), {
"ignore-prop": 10
}));
}
// Error
function Baz(arg) {
var a0 = /*#__PURE__*/ _react.createElement(ComponentSpecific1, _extends({}, arg));
var a0 = /*#__PURE__*/ _react.createElement(ComponentSpecific1, arg);
}
// Error
function createLink(func) {

View File

@ -2,11 +2,12 @@
define([
"require",
"exports",
"@swc/helpers/src/_extends.mjs",
"@swc/helpers/src/_object_spread.mjs",
"@swc/helpers/src/_object_spread_props.mjs",
"react"
], function(require, exports, _extends, _react) {
], function(require, exports, _objectSpread, _objectSpreadProps, _react) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: !0
}), _extends = _extends.default, InferParamComponent;
}), _objectSpread = _objectSpread.default, _objectSpreadProps = _objectSpreadProps.default, InferParamComponent;
});

View File

@ -2,34 +2,36 @@
define([
"require",
"exports",
"@swc/helpers/src/_extends.mjs",
"@swc/helpers/src/_object_spread.mjs",
"@swc/helpers/src/_object_spread_props.mjs",
"react"
], function(require, exports, _extends, _react) {
], function(require, exports, _objectSpread, _objectSpreadProps, _react) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
_extends = _extends.default;
_objectSpread = _objectSpread.default;
_objectSpreadProps = _objectSpreadProps.default;
// OK
function Baz(arg1, arg2) {
var a0 = /*#__PURE__*/ _react.createElement(OverloadComponent, _extends({}, arg1, {
var a0 = /*#__PURE__*/ _react.createElement(OverloadComponent, _objectSpreadProps(_objectSpread({}, arg1), {
a: "hello",
"ignore-prop": true
}));
var a1 = /*#__PURE__*/ _react.createElement(OverloadComponent, _extends({}, arg2, {
var a1 = /*#__PURE__*/ _react.createElement(OverloadComponent, _objectSpreadProps(_objectSpread({}, arg2), {
"ignore-pro": "hello world"
}));
var a2 = /*#__PURE__*/ _react.createElement(OverloadComponent, _extends({}, arg2));
var a3 = /*#__PURE__*/ _react.createElement(OverloadComponent, _extends({}, arg1, {
var a2 = /*#__PURE__*/ _react.createElement(OverloadComponent, arg2);
var a3 = /*#__PURE__*/ _react.createElement(OverloadComponent, _objectSpreadProps(_objectSpread({}, arg1), {
"ignore-prop": true
}));
var a4 = /*#__PURE__*/ _react.createElement(OverloadComponent, null);
var a5 = /*#__PURE__*/ _react.createElement(OverloadComponent, _extends({}, arg2, {
var a5 = /*#__PURE__*/ _react.createElement(OverloadComponent, _objectSpread(_objectSpreadProps(_objectSpread({}, arg2), {
"ignore-prop": "hello"
}, arg1));
var a6 = /*#__PURE__*/ _react.createElement(OverloadComponent, _extends({}, arg2, {
}), arg1));
var a6 = /*#__PURE__*/ _react.createElement(OverloadComponent, _objectSpread(_objectSpreadProps(_objectSpread({}, arg2), {
"ignore-prop": true
}, arg1));
}), arg1));
}
function createLink(func) {
var o = /*#__PURE__*/ _react.createElement(Link, {

View File

@ -2,11 +2,12 @@
define([
"require",
"exports",
"@swc/helpers/src/_extends.mjs",
"@swc/helpers/src/_object_spread.mjs",
"@swc/helpers/src/_object_spread_props.mjs",
"react"
], function(require, exports, _extends, _react) {
], function(require, exports, _objectSpread, _objectSpreadProps, _react) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: !0
}), _extends = _extends.default;
}), _objectSpread = _objectSpread.default, _objectSpreadProps = _objectSpreadProps.default;
});

View File

@ -2,20 +2,22 @@
define([
"require",
"exports",
"@swc/helpers/src/_extends.mjs",
"@swc/helpers/src/_object_spread.mjs",
"@swc/helpers/src/_object_spread_props.mjs",
"react"
], function(require, exports, _extends, _react) {
], function(require, exports, _objectSpread, _objectSpreadProps, _react) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
_extends = _extends.default;
_objectSpread = _objectSpread.default;
_objectSpreadProps = _objectSpreadProps.default;
// Error
function Baz(arg1, arg2) {
var a0 = /*#__PURE__*/ _react.createElement(OverloadComponent, {
a: arg1.b
});
var a2 = /*#__PURE__*/ _react.createElement(OverloadComponent, _extends({}, arg1, {
var a2 = /*#__PURE__*/ _react.createElement(OverloadComponent, _objectSpreadProps(_objectSpread({}, arg1), {
"ignore-prop": true
})) // missing a
;

View File

@ -2,11 +2,12 @@
define([
"require",
"exports",
"@swc/helpers/src/_extends.mjs",
"@swc/helpers/src/_object_spread.mjs",
"@swc/helpers/src/_object_spread_props.mjs",
"react"
], function(require, exports, _extends, _react) {
], function(require, exports, _objectSpread, _objectSpreadProps, _react) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: !0
}), _extends = _extends.default;
}), _objectSpread = _objectSpread.default, _objectSpreadProps = _objectSpreadProps.default;
});

View File

@ -2,31 +2,33 @@
define([
"require",
"exports",
"@swc/helpers/src/_extends.mjs",
"@swc/helpers/src/_object_spread.mjs",
"@swc/helpers/src/_object_spread_props.mjs",
"react"
], function(require, exports, _extends, _react) {
], function(require, exports, _objectSpread, _objectSpreadProps, _react) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
_extends = _extends.default;
_objectSpread = _objectSpread.default;
_objectSpreadProps = _objectSpreadProps.default;
function createComponent(arg) {
var a1 = /*#__PURE__*/ _react.createElement(Component, _extends({}, arg));
var a2 = /*#__PURE__*/ _react.createElement(Component, _extends({}, arg, {
var a1 = /*#__PURE__*/ _react.createElement(Component, arg);
var a2 = /*#__PURE__*/ _react.createElement(Component, _objectSpreadProps(_objectSpread({}, arg), {
prop1: true
}));
}
function Bar(arg) {
var a1 = /*#__PURE__*/ _react.createElement(ComponentSpecific, _extends({}, arg, {
var a1 = /*#__PURE__*/ _react.createElement(ComponentSpecific, _objectSpreadProps(_objectSpread({}, arg), {
"ignore-prop": "hi"
})); // U is number
var a2 = /*#__PURE__*/ _react.createElement(ComponentSpecific1, _extends({}, arg, {
var a2 = /*#__PURE__*/ _react.createElement(ComponentSpecific1, _objectSpreadProps(_objectSpread({}, arg), {
"ignore-prop": 10
})); // U is number
var a3 = /*#__PURE__*/ _react.createElement(ComponentSpecific, _extends({}, arg, {
var a3 = /*#__PURE__*/ _react.createElement(ComponentSpecific, _objectSpreadProps(_objectSpread({}, arg), {
prop: "hello"
})); // U is "hello"
var a4 = /*#__PURE__*/ _react.createElement(ComponentSpecific, _extends({}, arg, {
var a4 = /*#__PURE__*/ _react.createElement(ComponentSpecific, _objectSpreadProps(_objectSpread({}, arg), {
prop1: "hello"
})); // U is "hello"
}

View File

@ -2,11 +2,12 @@
define([
"require",
"exports",
"@swc/helpers/src/_extends.mjs",
"@swc/helpers/src/_object_spread.mjs",
"@swc/helpers/src/_object_spread_props.mjs",
"react"
], function(require, exports, _extends, _react) {
], function(require, exports, _objectSpread, _objectSpreadProps, _react) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: !0
}), _extends = _extends.default;
}), _objectSpread = _objectSpread.default, _objectSpreadProps = _objectSpreadProps.default;
});

View File

@ -1,3 +1,5 @@
import _object_spread from "@swc/helpers/src/_object_spread.mjs";
import _object_spread_props from "@swc/helpers/src/_object_spread_props.mjs";
import _object_without_properties from "@swc/helpers/src/_object_without_properties.mjs";
import Head from "next/head";
import Image from "next/image";
@ -50,9 +52,9 @@ export default function Home() {
var href = _param.href, linkProps = _object_without_properties(_param, [
"href"
]);
return React.createElement("link", Object.assign({
return React.createElement("link", _object_spread_props(_object_spread({
href: href
}, linkProps, {
}, linkProps), {
rel: "icon",
key: href,
__source: {

View File

@ -1,6 +1,6 @@
#![allow(clippy::redundant_allocation)]
use std::{borrow::Cow, iter, iter::once, mem, sync::Arc};
use std::{borrow::Cow, iter, iter::once, sync::Arc};
use once_cell::sync::Lazy;
use regex::Regex;
@ -18,10 +18,7 @@ use swc_common::{
use swc_config::merge::Merge;
use swc_ecma_ast::*;
use swc_ecma_parser::{parse_file_as_expr, Syntax};
use swc_ecma_transforms_base::helper;
use swc_ecma_utils::{
drop_span, member_expr, prepend_stmt, private_ident, quote_ident, undefined, ExprFactory,
};
use swc_ecma_utils::{drop_span, prepend_stmt, private_ident, quote_ident, undefined, ExprFactory};
use swc_ecma_visit::{as_folder, noop_visit_mut_type, Fold, VisitMut, VisitMutWith};
use self::static_check::should_use_create_element;
@ -74,10 +71,22 @@ pub struct Options {
#[serde(default)]
pub development: Option<bool>,
/// TODO: Remove this field.
// @babel/plugin-transform-react-jsx: Since "useBuiltIns" is removed in Babel 8, you can remove
// it from the config.
#[deprecated(
since = "0.167.4",
note = r#"Since `useBuiltIns` is removed in swc, you can remove it from the config."#
)]
#[serde(default, alias = "useBuiltIns")]
pub use_builtins: Option<bool>,
// '@babel/plugin-transform-react-jsx: Since Babel 8, an inline object with spread elements is
// always used, and the "useSpread" option is no longer available. Please remove it from your
// config.',
#[deprecated(
since = "0.167.4",
note = r#"An inline object with spread elements is always used, and the `useSpread` option is no longer available. Please remove it from your config."#
)]
#[serde(default)]
pub use_spread: Option<bool>,
@ -185,7 +194,6 @@ where
as_folder(Jsx {
cm: cm.clone(),
top_level_mark,
next: options.next.unwrap_or(false),
runtime: options.runtime.unwrap_or_default(),
import_source: options
.import_source
@ -209,8 +217,6 @@ where
options.pragma_frag.unwrap_or_else(default_pragma_frag),
top_level_mark,
),
use_builtins: options.use_builtins.unwrap_or_default(),
use_spread: options.use_spread.unwrap_or_default(),
development: options.development.unwrap_or_default(),
throw_if_namespace: options
.throw_if_namespace
@ -227,7 +233,6 @@ where
top_level_mark: Mark,
next: bool,
runtime: Runtime,
/// For automatic runtime.
import_source: JsWord,
@ -244,8 +249,6 @@ where
pragma: Arc<Box<Expr>>,
comments: Option<C>,
pragma_frag: Arc<Box<Expr>>,
use_builtins: bool,
use_spread: bool,
development: bool,
throw_if_namespace: bool,
}
@ -785,15 +788,6 @@ where
}
fn fold_attrs_for_classic(&mut self, attrs: Vec<JSXAttrOrSpread>) -> Box<Expr> {
if self.next {
self.fold_attrs_for_next_classic(attrs)
} else {
self.fold_attrs_for_old_classic(attrs)
}
}
/// Runtime; `classic`
fn fold_attrs_for_next_classic(&mut self, attrs: Vec<JSXAttrOrSpread>) -> Box<Expr> {
if attrs.is_empty() {
return Box::new(Expr::Lit(Lit::Null(Null { span: DUMMY_SP })));
}
@ -826,83 +820,6 @@ where
Box::new(Expr::Object(obj))
}
/// Runtime: `automatic`
fn fold_attrs_for_old_classic(&mut self, attrs: Vec<JSXAttrOrSpread>) -> Box<Expr> {
if attrs.is_empty() {
return Box::new(Expr::Lit(Lit::Null(Null { span: DUMMY_SP })));
}
if self.use_spread {
return self.fold_attrs_for_next_classic(attrs);
}
let is_complex = attrs
.iter()
.any(|a| matches!(*a, JSXAttrOrSpread::SpreadElement(..)));
if is_complex {
let mut args = vec![];
let mut cur_obj_props = vec![];
macro_rules! check {
() => {{
if args.is_empty() || !cur_obj_props.is_empty() {
args.push(
ObjectLit {
span: DUMMY_SP,
props: mem::take(&mut cur_obj_props),
}
.as_arg(),
)
}
}};
}
for attr in attrs {
match attr {
JSXAttrOrSpread::JSXAttr(a) => {
cur_obj_props.push(PropOrSpread::Prop(Box::new(self.attr_to_prop(a))))
}
JSXAttrOrSpread::SpreadElement(e) => {
check!();
args.push(e.expr.as_arg());
}
}
}
check!();
// calls `_extends` or `Object.assign`
Box::new(Expr::Call(CallExpr {
span: DUMMY_SP,
callee: {
if self.use_builtins {
member_expr!(DUMMY_SP, Object.assign).as_callee()
} else {
helper!(extends, "extends")
}
},
args,
type_args: None,
}))
} else {
Box::new(Expr::Object(ObjectLit {
span: DUMMY_SP,
props: attrs
.into_iter()
.map(|a| match a {
JSXAttrOrSpread::JSXAttr(a) => a,
_ => unreachable!(),
})
.map(|attr| {
let mut v = self.attr_to_prop(attr);
v.visit_mut_with(self);
v
})
.map(Box::new)
.map(PropOrSpread::Prop)
.collect(),
}))
}
}
fn attr_to_prop(&mut self, a: JSXAttr) -> Prop {
let key = to_prop_name(a.name);
let value = a

View File

@ -65,9 +65,6 @@ fn fixture_tr(t: &mut Tester, mut options: FixtureOptions) -> impl Fold {
options.options.runtime = Some(Runtime::Classic);
}
if options.use_builtins {
options.options.use_builtins = Some(true);
}
chain!(
resolver(unresolved_mark, top_level_mark, false),
jsx(
@ -91,9 +88,6 @@ fn integration_tr(t: &mut Tester, mut options: FixtureOptions) -> impl Fold {
options.options.runtime = Some(Runtime::Classic);
}
if options.use_builtins {
options.options.use_builtins = Some(true);
}
chain!(
resolver(unresolved_mark, top_level_mark, false),
react(
@ -118,9 +112,10 @@ test!(
sound="moo" />
"#,
r#"
React.createElement(Component, _extends({}, props, {
React.createElement(Component, {
...props,
sound: "moo"
}));
});
"#
);
@ -1105,10 +1100,11 @@ test!(
={2 } z />
"#,
r#"
React.createElement(Component, _extends({}, x, {
React.createElement(Component, {
...x,
y: 2,
z: true
}));
});
"#
);
@ -1121,10 +1117,11 @@ test!(
react_wraps_props_in_react_spread_for_last_spread_attributes,
r#"<Component y={2} z { ... x } />"#,
r#"
React.createElement(Component, _extends({
React.createElement(Component, {
y: 2,
z: true
}, x));
z: true,
...x
});
"#
);
@ -1137,11 +1134,11 @@ test!(
react_wraps_props_in_react_spread_for_middle_spread_attributes,
r#"<Component y={2} { ... x } z />"#,
r#"
React.createElement(Component, _extends({
y: 2
}, x, {
z: true
}));"#
React.createElement(Component, {
y: 2,
...x,
z: true
});"#
);
test!(
@ -1166,7 +1163,6 @@ test!(
|t| tr(
t,
Options {
use_builtins: true.into(),
..Default::default()
},
Mark::fresh(Mark::root())
@ -1174,10 +1170,10 @@ test!(
use_builtins_assignment,
r#"var div = <Component {...props} foo="bar" />"#,
r#"
var div = React.createElement(Component, Object.assign({}, props, {
foo: "bar"
}));
"#
var div = React.createElement(Component, {
...props,
foo: "bar"
});"#
);
test!(
@ -1188,7 +1184,6 @@ test!(
|t| tr(
t,
Options {
use_spread: true.into(),
..Default::default()
},
Mark::fresh(Mark::root())
@ -1207,7 +1202,6 @@ test!(
|t| tr(
t,
Options {
use_builtins: true.into(),
..Default::default()
},
Mark::fresh(Mark::root())
@ -1230,7 +1224,6 @@ test!(
tr(
t,
Options {
use_builtins: true.into(),
..Default::default()
},
top_level_mark
@ -1263,7 +1256,6 @@ test!(
|t| tr(
t,
Options {
use_builtins: true.into(),
..Default::default()
},
Mark::fresh(Mark::root())
@ -1285,7 +1277,6 @@ test!(
tr(
t,
Options {
use_builtins: true.into(),
..Default::default()
},
top_level_mark
@ -1327,7 +1318,6 @@ test!(
|t| tr(
t,
Options {
use_builtins: true.into(),
..Default::default()
},
Mark::fresh(Mark::root())

View File

@ -834,6 +834,7 @@ export interface ReactConfig {
development?: boolean;
/**
* Use `Object.assign()` instead of `_extends`. Defaults to false.
* @deprecated
*/
useBuiltins?: boolean;