@samitouri / QOS-React-2 / commits / bad1b7c41a

Start warning for JSX on plain functions

Let's also bump the version number for the log so that we can start filtering out the other logs.

Sebastian Markbage committed Aug 29, 2014 at 08:51 UTC bad1b7c41a60672f8fd3f1a6c65e5530640da3b7
2 files changed +21 -23
src/core/ReactLegacyDescriptor.js
+9 -8
@@ -65,15 +65,16 @@ function warnForPlainFunctionType(type) {
65 } catch (x) {
66 // just incase this is a frozen object or some special object
67 }
68 - monitorCodeUse('react_non_component_in_jsx', { name: type.name });
68 + monitorCodeUse(
69 + 'react_non_component_in_jsx',
70 + { version: 2, name: type.name }
71 + );
72 }
70 - // TODO: This pattern is heavily used by ReactMenu and therefore we
71 - // cannot yet warn without spamming users too much.
72 - // warning(
73 - // false,
74 - // 'This JSX uses a plain function. Only React components are ' +
75 - // 'valid in React\'s JSX transform.'
76 - // );
73 + warning(
74 + false,
75 + 'This JSX uses a plain function. Only React components are ' +
76 + 'valid in React\'s JSX transform.'
77 + );
78 }
79 }
80
src/core/__tests__/ReactDescriptor-test.js
+12 -15
@@ -248,11 +248,10 @@ describe('ReactDescriptor', function() {
248 return 21 + x;
249 });
250 expect(factory(21)).toBe(42);
251 - // TODO: This warning is temporarily disabled
252 - expect(console.warn.argsForCall.length).toBe(0);
253 - // expect(console.warn.argsForCall[0][0]).toContain(
254 - // 'This JSX uses a plain function.'
255 - // );
251 + expect(console.warn.argsForCall.length).toBe(1);
252 + expect(console.warn.argsForCall[0][0]).toContain(
253 + 'This JSX uses a plain function.'
254 + );
255 });
256
257 it('warns but allow a plain function to be immediately invoked', function() {
@@ -261,11 +260,10 @@ describe('ReactDescriptor', function() {
260 return 21 + x + y;
261 }, 11, 10);
262 expect(result).toBe(42);
264 - // TODO: This warning is temporarily disabled
265 - expect(console.warn.argsForCall.length).toBe(0);
266 - // expect(console.warn.argsForCall[0][0]).toContain(
267 - // 'This JSX uses a plain function.'
268 - // );
263 + expect(console.warn.argsForCall.length).toBe(1);
264 + expect(console.warn.argsForCall[0][0]).toContain(
265 + 'This JSX uses a plain function.'
266 + );
267 });
268
269 it('warns but does not fail on undefined results', function() {
@@ -273,11 +271,10 @@ describe('ReactDescriptor', function() {
271 var fn = function () { };
272 var result = React.createDescriptor(fn, 1, 2, null);
273 expect(result).toBe(undefined);
276 - // TODO: This warning is temporarily disabled
277 - expect(console.warn.argsForCall.length).toBe(0);
278 - // expect(console.warn.argsForCall[0][0]).toContain(
279 - // 'This JSX uses a plain function.'
280 - // );
274 + expect(console.warn.argsForCall.length).toBe(1);
275 + expect(console.warn.argsForCall[0][0]).toContain(
276 + 'This JSX uses a plain function.'
277 + );
278 });
279
280