Skip to content

Commit

Permalink
#1047 Hoist non-react statics in injectIntl (#1141)
Browse files Browse the repository at this point in the history
  • Loading branch information
bringking authored and redonkulus committed Sep 6, 2018
1 parent 763f3fc commit 6bfdb05
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 51 deletions.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,15 @@
}
},
"dependencies": {
"hoist-non-react-statics": "^2.5.5",
"intl-format-cache": "^2.0.5",
"intl-messageformat": "^2.1.0",
"intl-relativeformat": "^2.1.0",
"invariant": "^2.1.1"
},
"peerDependencies": {
"react": "^0.14.9 || ^15.0.0 || ^16.0.0",
"prop-types": "^15.5.4"
"prop-types": "^15.5.4",
"react": "^0.14.9 || ^15.0.0 || ^16.0.0"
},
"devDependencies": {
"babel-cli": "^6.2.0",
Expand Down
3 changes: 2 additions & 1 deletion src/inject.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
// https://github.com/rackt/react-redux

import React, {Component} from 'react';
import hoistNonReactStatics from 'hoist-non-react-statics';
import invariant from 'invariant';
import {intlShape} from './types';
import {invariantIntlContext} from './utils';
Expand Down Expand Up @@ -55,5 +56,5 @@ export default function injectIntl(WrappedComponent, options = {}) {
}
}

return InjectIntl;
return hoistNonReactStatics(InjectIntl, WrappedComponent);
}
7 changes: 7 additions & 0 deletions test/unit/inject.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ describe('injectIntl()', () => {
Wrapped.propTypes = {
intl: intlShape.isRequired,
};
Wrapped.someNonReactStatic = {
foo: true
};

renderer = createRenderer();
intlProvider = new IntlProvider({locale: 'en'}, {});
Expand All @@ -28,6 +31,10 @@ describe('injectIntl()', () => {
expect(injectIntl(Wrapped).WrappedComponent).toBe(Wrapped);
});

it('hoists non-react statics',() => {
expect(injectIntl(Wrapped).someNonReactStatic.foo).toBe(true)
})

describe('displayName', () => {
it('is descriptive by default', () => {
expect(injectIntl(() => null).displayName).toBe('InjectIntl(Component)');
Expand Down
106 changes: 58 additions & 48 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,14 @@ acorn@^3.0.4, acorn@^3.1.0:
version "3.3.0"
resolved "https://registry.yarnpkg.com/acorn/-/acorn-3.3.0.tgz#45e37fb39e8da3f25baee3ff5369e2bb5f22017a"

acorn@^4.0.1, acorn@^4.0.4:
acorn@^4.0.4:
version "4.0.11"
resolved "https://registry.yarnpkg.com/acorn/-/acorn-4.0.11.tgz#edcda3bd937e7556410d42ed5860f67399c794c0"

acorn@^5.2.1:
version "5.7.1"
resolved "https://registry.npmjs.org/acorn/-/acorn-5.7.1.tgz#f095829297706a7c9776958c0afc8930a9b9d9d8"

ajv-keywords@^1.0.0:
version "1.5.1"
resolved "https://registry.yarnpkg.com/ajv-keywords/-/ajv-keywords-1.5.1.tgz#314dd0a4b3368fad3dfcdc54ede6171b886daf3c"
Expand Down Expand Up @@ -276,7 +280,7 @@ babel-code-frame@^6.16.0, babel-code-frame@^6.22.0:
esutils "^2.0.2"
js-tokens "^3.0.0"

babel-core@6, babel-core@^6.0.0, babel-core@^6.0.14, babel-core@^6.23.0:
babel-core@^6.0.0, babel-core@^6.0.14, babel-core@^6.23.0:
version "6.23.1"
resolved "https://registry.yarnpkg.com/babel-core/-/babel-core-6.23.1.tgz#c143cb621bb2f621710c220c5d579d15b8a442df"
dependencies:
Expand Down Expand Up @@ -522,7 +526,7 @@ babel-plugin-transform-es2015-block-scoping@^6.22.0:
babel-types "^6.23.0"
lodash "^4.2.0"

babel-plugin-transform-es2015-classes@^6.22.0, babel-plugin-transform-es2015-classes@^6.9.0:
babel-plugin-transform-es2015-classes@^6.22.0:
version "6.23.0"
resolved "https://registry.yarnpkg.com/babel-plugin-transform-es2015-classes/-/babel-plugin-transform-es2015-classes-6.23.0.tgz#49b53f326202a2fd1b3bbaa5e2edd8a4f78643c1"
dependencies:
Expand Down Expand Up @@ -1804,9 +1808,9 @@ estree-walker@^0.2.1:
version "0.2.1"
resolved "https://registry.yarnpkg.com/estree-walker/-/estree-walker-0.2.1.tgz#bdafe8095383d8414d5dc2ecf4c9173b6db9412e"

estree-walker@^0.3.0:
version "0.3.1"
resolved "https://registry.yarnpkg.com/estree-walker/-/estree-walker-0.3.1.tgz#e6b1a51cf7292524e7237c312e5fe6660c1ce1aa"
estree-walker@^0.5.0, estree-walker@^0.5.2:
version "0.5.2"
resolved "https://registry.npmjs.org/estree-walker/-/estree-walker-0.5.2.tgz#d3850be7529c9580d815600b53126515e146dd39"

esutils@^2.0.0, esutils@^2.0.2:
version "2.0.2"
Expand Down Expand Up @@ -2294,6 +2298,10 @@ hoek@2.x.x:
version "2.16.3"
resolved "https://registry.yarnpkg.com/hoek/-/hoek-2.16.3.tgz#20bb7403d3cea398e91dc4710a8ff1b8274a25ed"

hoist-non-react-statics@^2.5.5:
version "2.5.5"
resolved "https://registry.npmjs.org/hoist-non-react-statics/-/hoist-non-react-statics-2.5.5.tgz#c5903cf409c0dfd908f388e619d86b9c1174cb47"

home-or-tmp@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/home-or-tmp/-/home-or-tmp-2.0.0.tgz#e36c3f2d2cae7d746a857e38d18d5f32a7882db8"
Expand Down Expand Up @@ -2429,9 +2437,9 @@ intl-messageformat@^2.0.0, intl-messageformat@^2.1.0:
dependencies:
intl-messageformat-parser "1.2.0"

intl-relativeformat@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/intl-relativeformat/-/intl-relativeformat-2.0.0.tgz#d6ba9dc6c625819bc0abdb1d4e238138b7488f26"
intl-relativeformat@^2.1.0:
version "2.1.0"
resolved "https://registry.npmjs.org/intl-relativeformat/-/intl-relativeformat-2.1.0.tgz#010f1105802251f40ac47d0e3e1a201348a255df"
dependencies:
intl-messageformat "^2.0.0"

Expand Down Expand Up @@ -3149,17 +3157,11 @@ lru-cache@^4.0.1:
pseudomap "^1.0.1"
yallist "^2.0.0"

magic-string@^0.15.2:
version "0.15.2"
resolved "https://registry.yarnpkg.com/magic-string/-/magic-string-0.15.2.tgz#0681d7388741bbc3addaa65060992624c6c09e9c"
magic-string@^0.22.4:
version "0.22.5"
resolved "https://registry.npmjs.org/magic-string/-/magic-string-0.22.5.tgz#8e9cf5afddf44385c1da5bc2a6a0dbd10b03657e"
dependencies:
vlq "^0.2.1"

magic-string@^0.19.0:
version "0.19.0"
resolved "https://registry.yarnpkg.com/magic-string/-/magic-string-0.19.0.tgz#198948217254e3e0b93080e01146b7c73b2a06b2"
dependencies:
vlq "^0.2.1"
vlq "^0.2.2"

make-plural@^2.1.3:
version "2.1.3"
Expand Down Expand Up @@ -3987,10 +3989,16 @@ resolve@1.1.7:
version "1.1.7"
resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.1.7.tgz#203114d82ad2c5ed9e8e0411b3932875e889e97b"

resolve@^1.1.3, resolve@^1.1.4, resolve@^1.1.6, resolve@^1.1.7, resolve@^1.2.0:
resolve@^1.1.3, resolve@^1.1.4, resolve@^1.1.6, resolve@^1.2.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.2.0.tgz#9589c3f2f6149d1417a40becc1663db6ec6bc26c"

resolve@^1.4.0:
version "1.8.1"
resolved "https://registry.npmjs.org/resolve/-/resolve-1.8.1.tgz#82f1ec19a423ac1fbd080b0bab06ba36e84a7a26"
dependencies:
path-parse "^1.0.5"

resolve@~0.6.1:
version "0.6.3"
resolved "https://registry.yarnpkg.com/resolve/-/resolve-0.6.3.tgz#dd957982e7e736debdf53b58a4dd91754575dd46"
Expand Down Expand Up @@ -4024,24 +4032,21 @@ ripemd160@^1.0.0:
version "1.0.1"
resolved "https://registry.yarnpkg.com/ripemd160/-/ripemd160-1.0.1.tgz#93a4bbd4942bc574b69a8fa57c71de10ecca7d6e"

rollup-plugin-babel@^2.3.9:
version "2.7.1"
resolved "https://registry.yarnpkg.com/rollup-plugin-babel/-/rollup-plugin-babel-2.7.1.tgz#16528197b0f938a1536f44683c7a93d573182f57"
rollup-plugin-babel@^3.0.2:
version "3.0.4"
resolved "https://registry.npmjs.org/rollup-plugin-babel/-/rollup-plugin-babel-3.0.4.tgz#41b3e762fe64450dd61da3105a2cf7ad76be4edc"
dependencies:
babel-core "6"
babel-plugin-transform-es2015-classes "^6.9.0"
object-assign "^4.1.0"
rollup-pluginutils "^1.5.0"

rollup-plugin-commonjs@^7.0.0:
version "7.0.0"
resolved "https://registry.yarnpkg.com/rollup-plugin-commonjs/-/rollup-plugin-commonjs-7.0.0.tgz#510762d5c423c761cd16d8e8451715b39f0ceb08"
rollup-plugin-commonjs@^8.2.1:
version "8.4.1"
resolved "https://registry.npmjs.org/rollup-plugin-commonjs/-/rollup-plugin-commonjs-8.4.1.tgz#5c9cea2b2c3de322f5fbccd147e07ed5e502d7a0"
dependencies:
acorn "^4.0.1"
estree-walker "^0.3.0"
magic-string "^0.19.0"
resolve "^1.1.7"
rollup-pluginutils "^1.5.1"
acorn "^5.2.1"
estree-walker "^0.5.0"
magic-string "^0.22.4"
resolve "^1.4.0"
rollup-pluginutils "^2.0.1"

rollup-plugin-memory@^2.0.0:
version "2.0.0"
Expand All @@ -4056,32 +4061,37 @@ rollup-plugin-node-resolve@^3.0.0:
is-module "^1.0.0"
resolve "^1.1.6"

rollup-plugin-replace@^1.1.0:
version "1.1.1"
resolved "https://registry.yarnpkg.com/rollup-plugin-replace/-/rollup-plugin-replace-1.1.1.tgz#396315ded050a6ce43b9518a886a3f60efb1ea33"
rollup-plugin-replace@^2.0.0:
version "2.0.0"
resolved "https://registry.npmjs.org/rollup-plugin-replace/-/rollup-plugin-replace-2.0.0.tgz#19074089c8ed57184b8cc64e967a03d095119277"
dependencies:
magic-string "^0.15.2"
magic-string "^0.22.4"
minimatch "^3.0.2"
rollup-pluginutils "^1.5.0"
rollup-pluginutils "^2.0.1"

rollup-plugin-uglify@^2.0.0:
version "2.0.1"
resolved "https://registry.yarnpkg.com/rollup-plugin-uglify/-/rollup-plugin-uglify-2.0.1.tgz#67b37ad1efdafbd83af4c36b40c189ee4866c969"
dependencies:
uglify-js "^3.0.9"

rollup-pluginutils@^1.5.0, rollup-pluginutils@^1.5.1:
rollup-pluginutils@^1.5.0:
version "1.5.2"
resolved "https://registry.yarnpkg.com/rollup-pluginutils/-/rollup-pluginutils-1.5.2.tgz#1e156e778f94b7255bfa1b3d0178be8f5c552408"
dependencies:
estree-walker "^0.2.1"
minimatch "^3.0.2"

rollup@^0.41.4:
version "0.41.4"
resolved "https://registry.yarnpkg.com/rollup/-/rollup-0.41.4.tgz#a970580176329f9ead86854d7fd4c46de752aef8"
rollup-pluginutils@^2.0.1:
version "2.3.0"
resolved "https://registry.npmjs.org/rollup-pluginutils/-/rollup-pluginutils-2.3.0.tgz#478ace04bd7f6da2e724356ca798214884738fc4"
dependencies:
source-map-support "^0.4.0"
estree-walker "^0.5.2"
micromatch "^2.3.11"

rollup@^0.50.0:
version "0.50.1"
resolved "https://registry.npmjs.org/rollup/-/rollup-0.50.1.tgz#e4dafcbf8d2bb0d9f5589d0cc6f64d76b8815730"

run-async@^0.1.0:
version "0.1.0"
Expand Down Expand Up @@ -4228,7 +4238,7 @@ sortobject@^1.0.0:
dependencies:
editions "^1.1.1"

source-map-support@^0.4.0, source-map-support@^0.4.2:
source-map-support@^0.4.2:
version "0.4.11"
resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.4.11.tgz#647f939978b38535909530885303daf23279f322"
dependencies:
Expand Down Expand Up @@ -4667,9 +4677,9 @@ verror@1.3.6:
dependencies:
extsprintf "1.0.2"

vlq@^0.2.1:
version "0.2.1"
resolved "https://registry.yarnpkg.com/vlq/-/vlq-0.2.1.tgz#14439d711891e682535467f8587c5630e4222a6c"
vlq@^0.2.2:
version "0.2.3"
resolved "https://registry.npmjs.org/vlq/-/vlq-0.2.3.tgz#8f3e4328cf63b1540c0d67e1b2778386f8975b26"

vm-browserify@~0.0.1:
version "0.0.4"
Expand Down

0 comments on commit 6bfdb05

Please sign in to comment.