From bad1b7c41a60672f8fd3f1a6c65e5530640da3b7 Mon Sep 17 00:00:00 2001 From: Sebastian Markbage Date: Fri, 29 Aug 2014 08:51:37 -0700 Subject: [PATCH] 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. --- src/core/ReactLegacyDescriptor.js | 17 +++++++------- src/core/__tests__/ReactDescriptor-test.js | 27 ++++++++++------------ 2 files changed, 21 insertions(+), 23 deletions(-) diff --git a/src/core/ReactLegacyDescriptor.js b/src/core/ReactLegacyDescriptor.js index 4c76f50443..764380e13b 100644 --- a/src/core/ReactLegacyDescriptor.js +++ b/src/core/ReactLegacyDescriptor.js @@ -65,15 +65,16 @@ function warnForPlainFunctionType(type) { } catch (x) { // just incase this is a frozen object or some special object } - monitorCodeUse('react_non_component_in_jsx', { name: type.name }); + monitorCodeUse( + 'react_non_component_in_jsx', + { version: 2, name: type.name } + ); } - // TODO: This pattern is heavily used by ReactMenu and therefore we - // cannot yet warn without spamming users too much. - // warning( - // false, - // 'This JSX uses a plain function. Only React components are ' + - // 'valid in React\'s JSX transform.' - // ); + warning( + false, + 'This JSX uses a plain function. Only React components are ' + + 'valid in React\'s JSX transform.' + ); } } diff --git a/src/core/__tests__/ReactDescriptor-test.js b/src/core/__tests__/ReactDescriptor-test.js index 0e767346d7..782ee91e3a 100644 --- a/src/core/__tests__/ReactDescriptor-test.js +++ b/src/core/__tests__/ReactDescriptor-test.js @@ -248,11 +248,10 @@ describe('ReactDescriptor', function() { return 21 + x; }); expect(factory(21)).toBe(42); - // TODO: This warning is temporarily disabled - expect(console.warn.argsForCall.length).toBe(0); - // expect(console.warn.argsForCall[0][0]).toContain( - // 'This JSX uses a plain function.' - // ); + expect(console.warn.argsForCall.length).toBe(1); + expect(console.warn.argsForCall[0][0]).toContain( + 'This JSX uses a plain function.' + ); }); it('warns but allow a plain function to be immediately invoked', function() { @@ -261,11 +260,10 @@ describe('ReactDescriptor', function() { return 21 + x + y; }, 11, 10); expect(result).toBe(42); - // TODO: This warning is temporarily disabled - expect(console.warn.argsForCall.length).toBe(0); - // expect(console.warn.argsForCall[0][0]).toContain( - // 'This JSX uses a plain function.' - // ); + expect(console.warn.argsForCall.length).toBe(1); + expect(console.warn.argsForCall[0][0]).toContain( + 'This JSX uses a plain function.' + ); }); it('warns but does not fail on undefined results', function() { @@ -273,11 +271,10 @@ describe('ReactDescriptor', function() { var fn = function () { }; var result = React.createDescriptor(fn, 1, 2, null); expect(result).toBe(undefined); - // TODO: This warning is temporarily disabled - expect(console.warn.argsForCall.length).toBe(0); - // expect(console.warn.argsForCall[0][0]).toContain( - // 'This JSX uses a plain function.' - // ); + expect(console.warn.argsForCall.length).toBe(1); + expect(console.warn.argsForCall[0][0]).toContain( + 'This JSX uses a plain function.' + ); });