feature: Support whitelisting mutable props for react-constant-elements (#5307)

This commit is contained in:
Samuel Reed
2017-07-25 13:34:21 -05:00
committed by Brian Ng
parent 248743e6c5
commit e0b4543601
11 changed files with 166 additions and 2 deletions

View File

@@ -0,0 +1,20 @@
// This is the same as the pure-expression-whitelist test, but 'FormattedMessage' is *not* whitelisted
// so it should not be hoisted.
var Foo = React.createClass({
render: function () {
return (
<FormattedMessage
id="someMessage.foo"
defaultMessage={
"Some text, " +
"and some more too. {someValue}"
}
description="A test message for babel."
values={{
someValue: "A value."
}}
/>
);
}
});

View File

@@ -0,0 +1,9 @@
// This is the same as the pure-expression-whitelist test, but 'FormattedMessage' is *not* whitelisted
// so it should not be hoisted.
var Foo = React.createClass({
render: function () {
return <FormattedMessage id="someMessage.foo" defaultMessage={"Some text, " + "and some more too. {someValue}"} description="A test message for babel." values={{
someValue: "A value."
}} />;
}
});

View File

@@ -0,0 +1,7 @@
{
"plugins": [
["transform-react-constant-elements", {"allowMutablePropsOnTags": ["FormattedNumber"]}],
"syntax-jsx"
]
}

View File

@@ -0,0 +1,20 @@
import Intl from 'react-intl';
var Foo = React.createClass({
render: function () {
return (
<Intl.FormattedMessage
id="someMessage.foo"
defaultMessage={
"Some text, " +
"and some more too. {someValue}"
}
description="A test message for babel."
values={{
someValue: "A value."
}}
/>
);
}
});

View File

@@ -0,0 +1,11 @@
import Intl from 'react-intl';
var _ref = <Intl.FormattedMessage id="someMessage.foo" defaultMessage={"Some text, " + "and some more too. {someValue}"} description="A test message for babel." values={{
someValue: "A value."
}} />;
var Foo = React.createClass({
render: function () {
return _ref;
}
});

View File

@@ -0,0 +1,7 @@
{
"plugins": [
["transform-react-constant-elements", {"allowMutablePropsOnTags": ["FormattedMessage"]}],
"syntax-jsx"
]
}

View File

@@ -0,0 +1,18 @@
var Foo = React.createClass({
render: function () {
return (
<FormattedMessage
id="someMessage.foo"
defaultMessage={
"Some text, " +
"and some more too. {someValue}"
}
description="A test message for babel."
values={{
someValue: "A value."
}}
/>
);
}
});

View File

@@ -0,0 +1,9 @@
var _ref = <FormattedMessage id="someMessage.foo" defaultMessage={"Some text, " + "and some more too. {someValue}"} description="A test message for babel." values={{
someValue: "A value."
}} />;
var Foo = React.createClass({
render: function () {
return _ref;
}
});

View File

@@ -0,0 +1,7 @@
{
"plugins": [
["transform-react-constant-elements", {"allowMutablePropsOnTags": ["FormattedMessage"]}],
"syntax-jsx"
]
}