From 5abc986fb039263be06312afef1adebc56539a62 Mon Sep 17 00:00:00 2001 From: Mark Weaver Date: Wed, 2 Oct 2019 14:04:20 +0000 Subject: [PATCH 1/2] hoist static functions in withLocalization --- fluent-react/package.json | 1 + fluent-react/src/with_localization.js | 4 +++- fluent-react/test/with_localization_test.js | 16 ++++++++++++++-- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/fluent-react/package.json b/fluent-react/package.json index 32e1be8a3..eed2808e0 100644 --- a/fluent-react/package.json +++ b/fluent-react/package.json @@ -48,6 +48,7 @@ "dependencies": { "cached-iterable": "^0.2.1", "@fluent/sequence": "0.4.0", + "hoist-non-react-statics": "^3.0.0", "prop-types": "^15.6.0" }, "peerDependencies": { diff --git a/fluent-react/src/with_localization.js b/fluent-react/src/with_localization.js index 0a210aab0..3e7a60649 100644 --- a/fluent-react/src/with_localization.js +++ b/fluent-react/src/with_localization.js @@ -2,6 +2,8 @@ import { createElement, Component } from "react"; import { isReactLocalization } from "./localization"; +import hoistNonReactStatics from "hoist-non-react-statics"; + export default function withLocalization(Inner) { class WithLocalization extends Component { componentDidMount() { @@ -60,7 +62,7 @@ export default function withLocalization(Inner) { l10n: isReactLocalization }; - return WithLocalization; + return hoistNonReactStatics(WithLocalization, Inner); } function displayName(component) { diff --git a/fluent-react/test/with_localization_test.js b/fluent-react/test/with_localization_test.js index a280fd3f7..8dfdf4f00 100644 --- a/fluent-react/test/with_localization_test.js +++ b/fluent-react/test/with_localization_test.js @@ -5,8 +5,14 @@ import { FluentBundle, FluentResource } from '../../fluent-bundle/src'; import ReactLocalization from '../src/localization'; import { withLocalization, LocalizationProvider } from '../src'; -function DummyComponent() { - return
; +class DummyComponent extends React.Component { + static doStaticThing() { + return "done"; + } + + render() { + return
; + } } suite('withLocalization', function() { @@ -123,4 +129,10 @@ bar = BAR {$arg} wrapper.update(); assert.strictEqual(wrapper.text(), 'BAR'); }) + + test('static function is hoisted onto the wrapped component', function() { + const EnhancedComponent = withLocalization(DummyComponent); + const result = EnhancedComponent.doStaticThing(); + assert.strictEqual(result, "done"); + }) }); From b40b22b8df127596702d66c2b4f5a6632a5aaecb Mon Sep 17 00:00:00 2001 From: Mark Weaver Date: Wed, 2 Oct 2019 14:57:58 +0000 Subject: [PATCH 2/2] fix rollup vs hoist-non-react-statics --- fluent-gecko/vendor_config.js | 6 ++++++ package.json | 1 + 2 files changed, 7 insertions(+) diff --git a/fluent-gecko/vendor_config.js b/fluent-gecko/vendor_config.js index 4ae0f0d59..0bf5e87aa 100644 --- a/fluent-gecko/vendor_config.js +++ b/fluent-gecko/vendor_config.js @@ -1,4 +1,5 @@ import nodeResolve from 'rollup-plugin-node-resolve'; +import commonjs from 'rollup-plugin-commonjs'; import bundleConfig from '../bundle_config'; export default Object.assign({}, bundleConfig, { @@ -30,5 +31,10 @@ export default Object.assign({}, bundleConfig, { ], plugins: [ nodeResolve(), + commonjs({ + namedExports: { + "hoist-non-react-statics": [ "hoistNonReactStatics" ] + } + }) ] }); diff --git a/package.json b/package.json index 06031a50e..641a1a861 100644 --- a/package.json +++ b/package.json @@ -32,6 +32,7 @@ "prettyjson": "^1.2.1", "rollup": "^1.9.3", "rollup-plugin-babel": "^4.3.2", + "rollup-plugin-commonjs": "^10.1.0", "rollup-plugin-node-resolve": "^4.2.2" } }