From ca2f0a5bbb57bc629a5bf859c8aae8f4d45b2e19 Mon Sep 17 00:00:00 2001 From: Paul Sauve Date: Fri, 30 Dec 2016 21:33:05 -0600 Subject: [PATCH 1/2] Fix partial numbers being detected as numbers --- .../dom/visitors/attributes/addComponentAttributes.js | 2 +- .../generator/attribute-partial-number/Component.html | 1 + test/generator/attribute-partial-number/_config.js | 3 +++ test/generator/attribute-partial-number/main.html | 11 +++++++++++ 4 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 test/generator/attribute-partial-number/Component.html create mode 100644 test/generator/attribute-partial-number/_config.js create mode 100644 test/generator/attribute-partial-number/main.html diff --git a/src/generators/dom/visitors/attributes/addComponentAttributes.js b/src/generators/dom/visitors/attributes/addComponentAttributes.js index d1c70a574a26..77bc99ea4c55 100644 --- a/src/generators/dom/visitors/attributes/addComponentAttributes.js +++ b/src/generators/dom/visitors/attributes/addComponentAttributes.js @@ -28,7 +28,7 @@ export default function addComponentAttributes ( generator, node, local ) { if ( value.type === 'Text' ) { // static attributes - const result = isNaN( parseFloat( value.data ) ) ? JSON.stringify( value.data ) : value.data; + const result = String( parseFloat( value.data ) ) !== value.data ? JSON.stringify( value.data ) : value.data; local.staticAttributes.push({ name: attribute.name, value: result diff --git a/test/generator/attribute-partial-number/Component.html b/test/generator/attribute-partial-number/Component.html new file mode 100644 index 000000000000..c48ee295fcad --- /dev/null +++ b/test/generator/attribute-partial-number/Component.html @@ -0,0 +1 @@ +

diff --git a/test/generator/attribute-partial-number/_config.js b/test/generator/attribute-partial-number/_config.js new file mode 100644 index 000000000000..acb585989730 --- /dev/null +++ b/test/generator/attribute-partial-number/_config.js @@ -0,0 +1,3 @@ +export default { + html: '

' +}; diff --git a/test/generator/attribute-partial-number/main.html b/test/generator/attribute-partial-number/main.html new file mode 100644 index 000000000000..7f56dcb44775 --- /dev/null +++ b/test/generator/attribute-partial-number/main.html @@ -0,0 +1,11 @@ + + + From 6679aef5681da40d5e97fa9156a8a3e2c96ae988 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Tue, 3 Jan 2017 17:48:01 -0500 Subject: [PATCH 2/2] just use isNaN --- .../dom/visitors/attributes/addComponentAttributes.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/generators/dom/visitors/attributes/addComponentAttributes.js b/src/generators/dom/visitors/attributes/addComponentAttributes.js index 77bc99ea4c55..e3471c6d3745 100644 --- a/src/generators/dom/visitors/attributes/addComponentAttributes.js +++ b/src/generators/dom/visitors/attributes/addComponentAttributes.js @@ -28,7 +28,7 @@ export default function addComponentAttributes ( generator, node, local ) { if ( value.type === 'Text' ) { // static attributes - const result = String( parseFloat( value.data ) ) !== value.data ? JSON.stringify( value.data ) : value.data; + const result = isNaN( value.data ) ? JSON.stringify( value.data ) : value.data; local.staticAttributes.push({ name: attribute.name, value: result