From 1d0e68f5a19d721fe8799b1ea331041d8bf9120e Mon Sep 17 00:00:00 2001 From: Ben Alpert Date: Wed, 9 Sep 2015 23:53:17 -0700 Subject: [PATCH] Include $$typeof on inlined React elements See https://github.com/facebook/react/pull/4832. --- packages/babel/src/transformation/file/index.js | 1 + .../transformation/templates/helper-typeof-react-element.js | 1 + .../transformers/optimisation/react.inline-elements.js | 1 + .../inline-elements/expected.js | 6 +++++- .../component-with-props/expected.js | 3 ++- .../component/expected.js | 3 ++- .../html-element-with-props/expected.js | 3 ++- .../html-element/expected.js | 3 ++- .../optimisation.react.inline-elements/key/expected.js | 1 + .../nested-components/expected.js | 4 +++- .../nested-html-elements/expected.js | 3 ++- .../optimisation.react.inline-elements/nested/expected.js | 4 +++- .../self-closing-component-with-props/expected.js | 1 + .../self-closing-component/expected.js | 1 + .../self-closing-html-element-with-props/expected.js | 1 + .../self-closing-html-element/expected.js | 1 + .../shorthand-attributes/expected.js | 3 ++- 17 files changed, 31 insertions(+), 9 deletions(-) create mode 100644 packages/babel/src/transformation/templates/helper-typeof-react-element.js diff --git a/packages/babel/src/transformation/file/index.js b/packages/babel/src/transformation/file/index.js index e16aacb978da..aefe11e40b47 100644 --- a/packages/babel/src/transformation/file/index.js +++ b/packages/babel/src/transformation/file/index.js @@ -92,6 +92,7 @@ export default class File { "temporal-undefined", "temporal-assert-defined", "self-global", + "typeof-react-element", "default-props", "instanceof", diff --git a/packages/babel/src/transformation/templates/helper-typeof-react-element.js b/packages/babel/src/transformation/templates/helper-typeof-react-element.js new file mode 100644 index 000000000000..144051982f26 --- /dev/null +++ b/packages/babel/src/transformation/templates/helper-typeof-react-element.js @@ -0,0 +1 @@ +(typeof Symbol === "function" && Symbol.for && Symbol.for("react.element")) || 0xeac7 diff --git a/packages/babel/src/transformation/transformers/optimisation/react.inline-elements.js b/packages/babel/src/transformation/transformers/optimisation/react.inline-elements.js index 8c7c182ed430..5e3554262cf6 100644 --- a/packages/babel/src/transformation/transformers/optimisation/react.inline-elements.js +++ b/packages/babel/src/transformation/transformers/optimisation/react.inline-elements.js @@ -61,6 +61,7 @@ export var visitor = { } // metadata + pushElemProp("$$typeof", file.addHelper("typeof-react-element")); pushElemProp("type", type); pushElemProp("ref", t.literal(null)); diff --git a/packages/babel/test/fixtures/transformation/optimisation.react.constant-elements/inline-elements/expected.js b/packages/babel/test/fixtures/transformation/optimisation.react.constant-elements/inline-elements/expected.js index 338bdb7ee978..eaa34b334046 100644 --- a/packages/babel/test/fixtures/transformation/optimisation.react.constant-elements/inline-elements/expected.js +++ b/packages/babel/test/fixtures/transformation/optimisation.react.constant-elements/inline-elements/expected.js @@ -1,6 +1,9 @@ "use strict"; +var _typeofReactElement = typeof Symbol === "function" && Symbol["for"] && Symbol["for"]("react.element") || 60103; + var _ref = { + $$typeof: _typeofReactElement, type: "foo", ref: null, props: {}, @@ -13,6 +16,7 @@ function render() { function render() { var text = getText(); var _ref2 = { + $$typeof: _typeofReactElement, type: "foo", ref: null, props: { @@ -23,4 +27,4 @@ function render() { return function () { return _ref2; }; -} +} \ No newline at end of file diff --git a/packages/babel/test/fixtures/transformation/optimisation.react.inline-elements/component-with-props/expected.js b/packages/babel/test/fixtures/transformation/optimisation.react.inline-elements/component-with-props/expected.js index f12d308ad4c7..83e97ffb7c43 100644 --- a/packages/babel/test/fixtures/transformation/optimisation.react.inline-elements/component-with-props/expected.js +++ b/packages/babel/test/fixtures/transformation/optimisation.react.inline-elements/component-with-props/expected.js @@ -1,10 +1,11 @@ "use strict"; ({ + $$typeof: babelHelpers.typeofReactElement, type: Baz, ref: null, props: babelHelpers.defaultProps(Baz.defaultProps, { foo: "bar" }), key: null -}); +}); \ No newline at end of file diff --git a/packages/babel/test/fixtures/transformation/optimisation.react.inline-elements/component/expected.js b/packages/babel/test/fixtures/transformation/optimisation.react.inline-elements/component/expected.js index ce0544da352b..78504409d14e 100644 --- a/packages/babel/test/fixtures/transformation/optimisation.react.inline-elements/component/expected.js +++ b/packages/babel/test/fixtures/transformation/optimisation.react.inline-elements/component/expected.js @@ -1,8 +1,9 @@ "use strict"; ({ + $$typeof: babelHelpers.typeofReactElement, type: Baz, ref: null, props: babelHelpers.defaultProps(Baz.defaultProps, {}), key: null -}); +}); \ No newline at end of file diff --git a/packages/babel/test/fixtures/transformation/optimisation.react.inline-elements/html-element-with-props/expected.js b/packages/babel/test/fixtures/transformation/optimisation.react.inline-elements/html-element-with-props/expected.js index dfddc6e5beed..093fab077678 100644 --- a/packages/babel/test/fixtures/transformation/optimisation.react.inline-elements/html-element-with-props/expected.js +++ b/packages/babel/test/fixtures/transformation/optimisation.react.inline-elements/html-element-with-props/expected.js @@ -1,10 +1,11 @@ "use strict"; ({ + $$typeof: babelHelpers.typeofReactElement, type: "foo", ref: null, props: { bar: "foo" }, key: null -}); +}); \ No newline at end of file diff --git a/packages/babel/test/fixtures/transformation/optimisation.react.inline-elements/html-element/expected.js b/packages/babel/test/fixtures/transformation/optimisation.react.inline-elements/html-element/expected.js index bd6cead480c5..4b16b457e31a 100644 --- a/packages/babel/test/fixtures/transformation/optimisation.react.inline-elements/html-element/expected.js +++ b/packages/babel/test/fixtures/transformation/optimisation.react.inline-elements/html-element/expected.js @@ -1,8 +1,9 @@ "use strict"; ({ + $$typeof: babelHelpers.typeofReactElement, type: "foo", ref: null, props: {}, key: null -}); +}); \ No newline at end of file diff --git a/packages/babel/test/fixtures/transformation/optimisation.react.inline-elements/key/expected.js b/packages/babel/test/fixtures/transformation/optimisation.react.inline-elements/key/expected.js index f3ceb79ca1b9..3834cf1d1295 100644 --- a/packages/babel/test/fixtures/transformation/optimisation.react.inline-elements/key/expected.js +++ b/packages/babel/test/fixtures/transformation/optimisation.react.inline-elements/key/expected.js @@ -1,6 +1,7 @@ "use strict"; ({ + $$typeof: babelHelpers.typeofReactElement, type: Foo, ref: null, props: babelHelpers.defaultProps(Foo.defaultProps, {}), diff --git a/packages/babel/test/fixtures/transformation/optimisation.react.inline-elements/nested-components/expected.js b/packages/babel/test/fixtures/transformation/optimisation.react.inline-elements/nested-components/expected.js index cdb8f0053aaf..d61f6f2de3d4 100644 --- a/packages/babel/test/fixtures/transformation/optimisation.react.inline-elements/nested-components/expected.js +++ b/packages/babel/test/fixtures/transformation/optimisation.react.inline-elements/nested-components/expected.js @@ -1,10 +1,12 @@ "use strict"; ({ + $$typeof: babelHelpers.typeofReactElement, type: Foo, ref: null, props: babelHelpers.defaultProps(Foo.defaultProps, { children: [bar, { + $$typeof: babelHelpers.typeofReactElement, type: Baz, ref: null, props: babelHelpers.defaultProps(Baz.defaultProps, {}), @@ -13,4 +15,4 @@ className: "foo" }), key: null -}); +}); \ No newline at end of file diff --git a/packages/babel/test/fixtures/transformation/optimisation.react.inline-elements/nested-html-elements/expected.js b/packages/babel/test/fixtures/transformation/optimisation.react.inline-elements/nested-html-elements/expected.js index 90b1ad9b9370..f9518ba2b76f 100644 --- a/packages/babel/test/fixtures/transformation/optimisation.react.inline-elements/nested-html-elements/expected.js +++ b/packages/babel/test/fixtures/transformation/optimisation.react.inline-elements/nested-html-elements/expected.js @@ -1,6 +1,7 @@ "use strict"; ({ + $$typeof: babelHelpers.typeofReactElement, type: "div", ref: null, props: { @@ -8,4 +9,4 @@ className: "foo" }, key: null -}); +}); \ No newline at end of file diff --git a/packages/babel/test/fixtures/transformation/optimisation.react.inline-elements/nested/expected.js b/packages/babel/test/fixtures/transformation/optimisation.react.inline-elements/nested/expected.js index 6d9b9a1f1cd7..1f152abd0218 100644 --- a/packages/babel/test/fixtures/transformation/optimisation.react.inline-elements/nested/expected.js +++ b/packages/babel/test/fixtures/transformation/optimisation.react.inline-elements/nested/expected.js @@ -1,10 +1,12 @@ "use strict"; ({ + $$typeof: babelHelpers.typeofReactElement, type: "div", ref: null, props: { children: [bar, { + $$typeof: babelHelpers.typeofReactElement, type: Baz, ref: null, props: babelHelpers.defaultProps(Baz.defaultProps, {}), @@ -13,4 +15,4 @@ className: "foo" }, key: null -}); +}); \ No newline at end of file diff --git a/packages/babel/test/fixtures/transformation/optimisation.react.inline-elements/self-closing-component-with-props/expected.js b/packages/babel/test/fixtures/transformation/optimisation.react.inline-elements/self-closing-component-with-props/expected.js index 05d9b4afdeb8..83e97ffb7c43 100644 --- a/packages/babel/test/fixtures/transformation/optimisation.react.inline-elements/self-closing-component-with-props/expected.js +++ b/packages/babel/test/fixtures/transformation/optimisation.react.inline-elements/self-closing-component-with-props/expected.js @@ -1,6 +1,7 @@ "use strict"; ({ + $$typeof: babelHelpers.typeofReactElement, type: Baz, ref: null, props: babelHelpers.defaultProps(Baz.defaultProps, { diff --git a/packages/babel/test/fixtures/transformation/optimisation.react.inline-elements/self-closing-component/expected.js b/packages/babel/test/fixtures/transformation/optimisation.react.inline-elements/self-closing-component/expected.js index eebbcef9882c..78504409d14e 100644 --- a/packages/babel/test/fixtures/transformation/optimisation.react.inline-elements/self-closing-component/expected.js +++ b/packages/babel/test/fixtures/transformation/optimisation.react.inline-elements/self-closing-component/expected.js @@ -1,6 +1,7 @@ "use strict"; ({ + $$typeof: babelHelpers.typeofReactElement, type: Baz, ref: null, props: babelHelpers.defaultProps(Baz.defaultProps, {}), diff --git a/packages/babel/test/fixtures/transformation/optimisation.react.inline-elements/self-closing-html-element-with-props/expected.js b/packages/babel/test/fixtures/transformation/optimisation.react.inline-elements/self-closing-html-element-with-props/expected.js index 6e5aec9eec63..093fab077678 100644 --- a/packages/babel/test/fixtures/transformation/optimisation.react.inline-elements/self-closing-html-element-with-props/expected.js +++ b/packages/babel/test/fixtures/transformation/optimisation.react.inline-elements/self-closing-html-element-with-props/expected.js @@ -1,6 +1,7 @@ "use strict"; ({ + $$typeof: babelHelpers.typeofReactElement, type: "foo", ref: null, props: { diff --git a/packages/babel/test/fixtures/transformation/optimisation.react.inline-elements/self-closing-html-element/expected.js b/packages/babel/test/fixtures/transformation/optimisation.react.inline-elements/self-closing-html-element/expected.js index 87d6fdbd3362..4b16b457e31a 100644 --- a/packages/babel/test/fixtures/transformation/optimisation.react.inline-elements/self-closing-html-element/expected.js +++ b/packages/babel/test/fixtures/transformation/optimisation.react.inline-elements/self-closing-html-element/expected.js @@ -1,6 +1,7 @@ "use strict"; ({ + $$typeof: babelHelpers.typeofReactElement, type: "foo", ref: null, props: {}, diff --git a/packages/babel/test/fixtures/transformation/optimisation.react.inline-elements/shorthand-attributes/expected.js b/packages/babel/test/fixtures/transformation/optimisation.react.inline-elements/shorthand-attributes/expected.js index 452322c2dee3..0239a2fe422b 100644 --- a/packages/babel/test/fixtures/transformation/optimisation.react.inline-elements/shorthand-attributes/expected.js +++ b/packages/babel/test/fixtures/transformation/optimisation.react.inline-elements/shorthand-attributes/expected.js @@ -1,10 +1,11 @@ "use strict"; ({ + $$typeof: babelHelpers.typeofReactElement, type: Foo, ref: null, props: babelHelpers.defaultProps(Foo.defaultProps, { bar: true }), key: null -}); +}); \ No newline at end of file