Skip to content

Commit

Permalink
fix: skip flattening spread object with __proto__
Browse files Browse the repository at this point in the history
  • Loading branch information
JLHwung committed Jul 14, 2022
1 parent bcf8b22 commit 35da60b
Show file tree
Hide file tree
Showing 9 changed files with 94 additions and 1 deletion.
11 changes: 10 additions & 1 deletion packages/babel-plugin-transform-react-jsx/src/create-plugin.ts
Expand Up @@ -39,6 +39,15 @@ const get = (pass: PluginPass, name: string) =>
const set = (pass: PluginPass, name: string, v: any) =>
pass.set(`@babel/plugin-react-jsx/${name}`, v);

function hasProto(node: t.ObjectExpression) {
return node.properties.some(
value =>
t.isObjectProperty(value, { computed: false }) &&
(t.isIdentifier(value.key, { name: "__proto__" }) ||
t.isStringLiteral(value.key, { value: "__proto__" })),
);
}

export interface Options {
filter?: (node: t.Node, pass: PluginPass) => boolean;
importSource?: string;
Expand Down Expand Up @@ -422,7 +431,7 @@ You can set \`throwIfNamespace: false\` to bypass this warning.`,
if (t.isJSXSpreadAttribute(attribute.node)) {
const arg = attribute.node.argument;
// Collect properties into props array if spreading object expression
if (t.isObjectExpression(arg)) {
if (t.isObjectExpression(arg) && !hasProto(arg)) {
array.push(...arg.properties);
} else {
array.push(t.spreadElement(arg));
Expand Down
Expand Up @@ -5,3 +5,7 @@
<img alt="" {...{src, title}} />;

<blockquote {...{cite}}>{items}</blockquote>;

<pre {...{["__proto__"]: null }}></pre>;

<code {...{[__proto__]: null }}></code>;
Expand Up @@ -22,3 +22,13 @@ _jsx("blockquote", {
cite,
children: items
});

/*#__PURE__*/
_jsx("pre", {
["__proto__"]: null
});

/*#__PURE__*/
_jsx("code", {
[__proto__]: null
});
@@ -0,0 +1,7 @@
var __proto__ = null;

<p {...{__proto__: null}}>text</p>;

<div {...{"__proto__": null}}>{contents}</div>;

<img alt="" {...{__proto__}} />;
@@ -0,0 +1,24 @@
import { jsx as _jsx } from "react/jsx-runtime";
var __proto__ = null;

/*#__PURE__*/
_jsx("p", { ...{
__proto__: null
},
children: "text"
});

/*#__PURE__*/
_jsx("div", { ...{
"__proto__": null
},
children: contents
});

/*#__PURE__*/
_jsx("img", {
alt: "",
...{
__proto__
}
});
Expand Up @@ -5,3 +5,7 @@
<img alt="" {...{src, title}} />;

<blockquote {...{cite}}>{items}</blockquote>;

<pre {...{["__proto__"]: null }}></pre>;

<code {...{[__proto__]: null }}></code>;
Expand Up @@ -15,3 +15,13 @@ React.createElement("img", {
React.createElement("blockquote", {
cite
}, items);

/*#__PURE__*/
React.createElement("pre", {
["__proto__"]: null
});

/*#__PURE__*/
React.createElement("code", {
[__proto__]: null
});
@@ -0,0 +1,7 @@
var __proto__ = null;

<p {...{__proto__: null}}>text</p>;

<div {...{"__proto__": null}}>{contents}</div>;

<img alt="" {...{__proto__}} />;
@@ -0,0 +1,18 @@
var __proto__ = null;

/*#__PURE__*/
React.createElement("p", {
__proto__: null
}, "text");

/*#__PURE__*/
React.createElement("div", {
"__proto__": null
}, contents);

/*#__PURE__*/
React.createElement("img", babelHelpers.extends({
alt: ""
}, {
__proto__
}));

0 comments on commit 35da60b

Please sign in to comment.