lingui-react
Advanced tools
Comparing version 0.9.0 to 0.10.0
@@ -36,2 +36,9 @@ 'use strict'; | ||
var translation = _this.getTranslation(props); | ||
if (process.env.NODE_ENV !== 'production') { | ||
if (!translation && props.children) { | ||
console.warn('lingui-react preset is probably missing in babel config. ' + 'It causes that no content is rendered from any lingui-react ' + 'components. See installation guide for more info - ' + 'http://bit.ly/lingui-react-quickstart'); | ||
} | ||
} | ||
_this.state = { | ||
@@ -38,0 +45,0 @@ msgCache: _this.compileMessage(translation), |
@@ -28,11 +28,18 @@ 'use strict'; | ||
exports.default = function () { | ||
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}, | ||
_ref$update = _ref.update, | ||
update = _ref$update === undefined ? true : _ref$update, | ||
_ref$withRef = _ref.withRef, | ||
withRef = _ref$withRef === undefined ? false : _ref$withRef; | ||
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
return function (WrappedComponent) { | ||
var _class, _temp2; | ||
if (process.env.NODE_ENV !== 'production') { | ||
if (typeof options === 'function' || _react2.default.isValidElement(options)) { | ||
console.warn('WithI18n([options]) takes options as a first argument, ' + 'but received React component itself. Without options, the Component ' + 'should be wrapped as WithI18n()(Component), not WithI18n(Component).'); | ||
} | ||
} | ||
var _options$update = options.update, | ||
update = _options$update === undefined ? true : _options$update, | ||
_options$withRef = options.withRef, | ||
withRef = _options$withRef === undefined ? false : _options$withRef; | ||
return _temp2 = _class = function (_React$Component) { | ||
@@ -42,3 +49,3 @@ _inherits(WithI18n, _React$Component); | ||
function WithI18n() { | ||
var _ref2; | ||
var _ref; | ||
@@ -53,3 +60,3 @@ var _temp, _this, _ret; | ||
return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref2 = WithI18n.__proto__ || Object.getPrototypeOf(WithI18n)).call.apply(_ref2, [this].concat(args))), _this), _this.wrappedInstance = null, _this.setWrappedInstance = function (ref) { | ||
return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref = WithI18n.__proto__ || Object.getPrototypeOf(WithI18n)).call.apply(_ref, [this].concat(args))), _this), _this.wrappedInstance = null, _this.setWrappedInstance = function (ref) { | ||
if (withRef) _this.wrappedInstance = ref; | ||
@@ -56,0 +63,0 @@ }, _this.getWrappedInstance = function () { |
{ | ||
"name": "lingui-react", | ||
"version": "0.9.0", | ||
"version": "0.10.0", | ||
"description": "React components for translations", | ||
@@ -35,4 +35,4 @@ "main": "lib/index.js", | ||
"dependencies": { | ||
"lingui-formats": "^v0.3.0", | ||
"lingui-i18n": "^v0.6.0", | ||
"lingui-formats": "^undefined", | ||
"lingui-i18n": "^v0.6.1", | ||
"prop-types": "^15.5.10" | ||
@@ -39,0 +39,0 @@ }, |
@@ -15,7 +15,5 @@ // @flow | ||
// $FlowIgnore: missing annotation for dive() | ||
expect(node.dive().text()).toEqual('1 book') | ||
node.setProps({ value: 2 }) | ||
// $FlowIgnore: missing annotation for dive() | ||
expect(node.dive().text()).toEqual('2 books') | ||
@@ -30,11 +28,8 @@ }) | ||
// $FlowIgnore: missing annotation for dive() | ||
expect(node.dive().text()).toEqual('1 kniha') | ||
node.setProps({ value: 2 }) | ||
// $FlowIgnore: missing annotation for dive() | ||
expect(node.dive().text()).toEqual('2 knihy') | ||
node.setProps({ value: 5 }) | ||
// $FlowIgnore: missing annotation for dive() | ||
expect(node.dive().text()).toEqual('5 knih') | ||
@@ -49,13 +44,10 @@ }) | ||
// $FlowIgnore: missing annotation for dive() | ||
expect(node.dive().text()).toEqual('one') | ||
node.setProps({ value: 2 }) | ||
// $FlowIgnore: missing annotation for dive() | ||
expect(node.dive().text()).toEqual('one and one another') | ||
node.setProps({ value: 3 }) | ||
// $FlowIgnore: missing annotation for dive() | ||
expect(node.dive().text()).toEqual('other') | ||
}) | ||
}) |
@@ -15,15 +15,11 @@ // @flow | ||
// $FlowIgnore: missing annotation for dive() | ||
expect(node.dive().text()).toEqual('1st') | ||
node.setProps({ value: 2 }) | ||
// $FlowIgnore: missing annotation for dive() | ||
expect(node.dive().text()).toEqual('2nd') | ||
node.setProps({ value: 3 }) | ||
// $FlowIgnore: missing annotation for dive() | ||
expect(node.dive().text()).toEqual('3rd') | ||
node.setProps({ value: 4 }) | ||
// $FlowIgnore: missing annotation for dive() | ||
expect(node.dive().text()).toEqual('4th') | ||
@@ -48,23 +44,17 @@ }) | ||
// $FlowIgnore: missing annotation for dive() | ||
expect(node.dive().text()).toEqual('0 cŵn') | ||
node.setProps({ value: 1 }) | ||
// $FlowIgnore: missing annotation for dive() | ||
expect(node.dive().text()).toEqual('1 ci') | ||
node.setProps({ value: 2 }) | ||
// $FlowIgnore: missing annotation for dive() | ||
expect(node.dive().text()).toEqual('2 gi') | ||
node.setProps({ value: 3 }) | ||
// $FlowIgnore: missing annotation for dive() | ||
expect(node.dive().text()).toEqual('3 chi') | ||
node.setProps({ value: 5 }) | ||
// $FlowIgnore: missing annotation for dive() | ||
expect(node.dive().text()).toEqual('5 chi') | ||
node.setProps({ value: 10 }) | ||
// $FlowIgnore: missing annotation for dive() | ||
expect(node.dive().text()).toEqual('10 ci') | ||
@@ -79,3 +69,2 @@ }) | ||
// $FlowIgnore: missing annotation for dive() | ||
expect(node.dive().text()).toEqual('1. křižovatka') | ||
@@ -90,21 +79,16 @@ }) | ||
// $FlowIgnore: missing annotation for dive() | ||
expect(node.dive().text()).toEqual('This one') | ||
node.setProps({ value: 2 }) | ||
// $FlowIgnore: missing annotation for dive() | ||
expect(node.dive().text()).toEqual('This one and 1st') | ||
node.setProps({ value: 3 }) | ||
// $FlowIgnore: missing annotation for dive() | ||
expect(node.dive().text()).toEqual('This one and 2nd') | ||
node.setProps({ value: 4 }) | ||
// $FlowIgnore: missing annotation for dive() | ||
expect(node.dive().text()).toEqual('This one and 3rd') | ||
node.setProps({ value: 5 }) | ||
// $FlowIgnore: missing annotation for dive() | ||
expect(node.dive().text()).toEqual('This one and 4th') | ||
}) | ||
}) |
@@ -37,2 +37,14 @@ // @flow | ||
const translation = this.getTranslation(props) | ||
if (process.env.NODE_ENV !== 'production') { | ||
if (!translation && props.children) { | ||
console.warn( | ||
'lingui-react preset is probably missing in babel config. ' + | ||
'It causes that no content is rendered from any lingui-react ' + | ||
'components. See installation guide for more info - ' + | ||
'http://bit.ly/lingui-react-quickstart' | ||
) | ||
} | ||
} | ||
this.state = { | ||
@@ -39,0 +51,0 @@ msgCache: this.compileMessage(translation), |
@@ -24,3 +24,2 @@ /* @flow */ | ||
} | ||
// $FlowIgnore: missing annotation for dive() | ||
const text = (node) => shallow(node, { context }).dive().text() | ||
@@ -33,6 +32,18 @@ | ||
it("shouldn't throw runtime error without i18n context", function () { | ||
// $FlowIgnore: missing annotation for dive() | ||
expect(shallow(<Trans id="unknown" />).dive().text()).toEqual('unknown') | ||
}) | ||
it('should warn about possible missing babel-plugin', function () { | ||
const originalConsole = global.console | ||
global.console = { | ||
warn: jest.fn() | ||
} | ||
shallow(<Trans>Label</Trans>).dive() | ||
expect(global.console.warn).toBeCalledWith( | ||
expect.stringContaining('lingui-react preset')) | ||
global.console = originalConsole | ||
}) | ||
it('should recompile msg when id or defaults changes', function () { | ||
@@ -39,0 +50,0 @@ const node = mount(<Trans id="Original" defaults="Original" />, { context }) |
@@ -15,3 +15,15 @@ // @flow | ||
export default ({ update = true, withRef = false }: WithI18nOptions = {}) => function<P, C: React$Component<*, P, *>> (WrappedComponent: Class<C>): Class<React.Component<void, $Diff<P, WithI18nProps>, void>> { | ||
export default (options: WithI18nOptions = {}) => function<P, C: React$Component<*, P, *>> (WrappedComponent: Class<C>): Class<React.Component<void, $Diff<P, WithI18nProps>, void>> { | ||
if (process.env.NODE_ENV !== 'production') { | ||
if (typeof options === 'function' || React.isValidElement(options)) { | ||
console.warn( | ||
'WithI18n([options]) takes options as a first argument, ' + | ||
'but received React component itself. Without options, the Component ' + | ||
'should be wrapped as WithI18n()(Component), not WithI18n(Component).' | ||
) | ||
} | ||
} | ||
const { update = true, withRef = false } = options | ||
return class WithI18n extends React.Component { | ||
@@ -18,0 +30,0 @@ static contextTypes = { |
@@ -48,2 +48,23 @@ // @flow | ||
it('should warn if called incorrectly', function () { | ||
const originalConsole = global.console | ||
global.console = { | ||
warn: jest.fn(), | ||
error: jest.fn() | ||
} | ||
const Component = WithI18n(() => <span />) | ||
// Catch the React error. It will blow up user app, but at least they get | ||
// the warning about the cause. | ||
try { | ||
// $FlowIgnore: This is invalid, that's the point. | ||
mount(<Component />) | ||
} catch (e) {} | ||
expect(global.console.warn).toBeCalledWith( | ||
expect.stringContaining('WithI18n([options]) takes options')) | ||
global.console = originalConsole | ||
}) | ||
it('should pass all props to wrapped component', function () { | ||
@@ -50,0 +71,0 @@ const props = { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
120886
2165
4
- Removedlingui-formats@0.3.0(transitive)
Updatedlingui-formats@^undefined
Updatedlingui-i18n@^v0.6.1