From b7ecfb2f113a3ab826f06bd11d8cc9c7e9352525 Mon Sep 17 00:00:00 2001 From: kthjm Date: Fri, 24 Nov 2017 10:59:59 +0900 Subject: [PATCH 1/4] Fix addAttribute for React --- index.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index e5d592b..e6c51bc 100644 --- a/index.js +++ b/index.js @@ -131,7 +131,16 @@ function addAttribute(props, name, value, ctx) { return; } - name = info.name || paramCase(name); + if (ctx.react) { + var beginFour = name.slice(0, 4); + if ((beginFour === 'data' || beginFour === 'aria') && name.length > 4) { + name = paramCase(name); + } else { + name = info.name || camelCase(name); + } + } else { + name = info.name || paramCase(name); + } if (value !== null && typeof value === 'object' && 'length' in value) { /* Accept `array`. Most props are space-separater. */ From dc3ded71f32e5460da96aeba3a74489a13ebc454 Mon Sep 17 00:00:00 2001 From: kthjm Date: Fri, 24 Nov 2017 11:33:52 +0900 Subject: [PATCH 2/4] Fix test new failed --- test.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test.js b/test.js index aa5c6bd..8796234 100644 --- a/test.js +++ b/test.js @@ -143,7 +143,7 @@ test('hast-to-hyperscript', function (t) { t.test('should support `React.createElement` in `development`', function (st) { var currentEnv = process.env.NODE_ENV; - var baseline = doc.replace(/color:red;/, 'color:red'); + var baseline = doc.replace(/color:red;/, 'color:red').replace(/camel-case/, 'camelCase'); process.env.NODE_ENV = 'development'; var actual = toH(r, hast); @@ -160,7 +160,7 @@ test('hast-to-hyperscript', function (t) { r('strong', { key: 'h-2', style: {color: 'red'}, - 'camel-case': 'on off', + 'camelCase': 'on off', 'data-some': 'yes', 'aria-valuenow': '1' }, ['charlie']), @@ -180,7 +180,7 @@ test('hast-to-hyperscript', function (t) { t.test('should support `React.createElement` in `production`', function (st) { var currentEnv = process.env.NODE_ENV; - var baseline = doc.replace(/color:red;/, 'color:red'); + var baseline = doc.replace(/color:red;/, 'color:red').replace(/camel-case/, 'camelCase'); process.env.NODE_ENV = 'production'; var actual = toH(r, hast); @@ -197,7 +197,7 @@ test('hast-to-hyperscript', function (t) { r('strong', { key: 'h-2', style: {color: 'red'}, - 'camel-case': 'on off', + 'camelCase': 'on off', 'data-some': 'yes', 'aria-valuenow': '1' }, ['charlie']), From 2fa2b709cc6e64545ffd0bf80d2a1766862d2ebe Mon Sep 17 00:00:00 2001 From: kthjm Date: Fri, 24 Nov 2017 11:36:39 +0900 Subject: [PATCH 3/4] Fix lint new failed --- test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test.js b/test.js index 8796234..9fd17f0 100644 --- a/test.js +++ b/test.js @@ -160,7 +160,7 @@ test('hast-to-hyperscript', function (t) { r('strong', { key: 'h-2', style: {color: 'red'}, - 'camelCase': 'on off', + camelCase: 'on off', 'data-some': 'yes', 'aria-valuenow': '1' }, ['charlie']), @@ -197,7 +197,7 @@ test('hast-to-hyperscript', function (t) { r('strong', { key: 'h-2', style: {color: 'red'}, - 'camelCase': 'on off', + camelCase: 'on off', 'data-some': 'yes', 'aria-valuenow': '1' }, ['charlie']), From 9b01297ff3f5a5227b47af894349469903122c00 Mon Sep 17 00:00:00 2001 From: kthjm Date: Fri, 24 Nov 2017 11:51:50 +0900 Subject: [PATCH 4/4] Update test for react/attributeName --- test.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/test.js b/test.js index 9fd17f0..84a4c44 100644 --- a/test.js +++ b/test.js @@ -271,6 +271,20 @@ test('hast-to-hyperscript', function (t) { 'react: should parse an invalid style declaration' ); + st.deepEqual( + toH(r, u('element', {tagName: 'div', properties: { + 'camel-case': 'on off', + 'data-some': 'yes', + 'aria-valuenow': '1' + }})).props, + { + camelCase: 'on off', + 'data-some': 'yes', + 'aria-valuenow': '1' + }, + 'react: should parse attributeName as camelCase with the exceptions' + ); + st.end(); });