babel-plugin-hyperlit
Advanced tools
Comparing version 0.1.3 to 0.1.5
23
index.js
@@ -42,3 +42,4 @@ | ||
buffer = '', | ||
mode = NEXT | ||
mode = NEXT, | ||
newline = true | ||
@@ -54,3 +55,4 @@ const listpush = (x) => list.push(x) | ||
if (trim) buffer = buffer.trimEnd() | ||
listpush(buffer) | ||
buffer && listpush(buffer) | ||
newline = false | ||
buffer = '' | ||
@@ -67,2 +69,3 @@ } | ||
tagname = buffer | ||
buffer = '' | ||
props = [{}] | ||
@@ -75,2 +78,3 @@ mode = m | ||
mode = m | ||
buffer = '' | ||
} | ||
@@ -81,2 +85,3 @@ | ||
mode = PROPS | ||
buffer = '' | ||
} | ||
@@ -96,5 +101,8 @@ | ||
mode = TAG | ||
} else if (!ws(ch)) { | ||
mode = TEXT | ||
buffer = ch | ||
} else if (ch == '\n') { | ||
buffer = ch | ||
} else if (!ws(ch) || !ws(buffer)) { | ||
newline = true | ||
} else if (!newline) { | ||
mode = TEXT | ||
@@ -105,4 +113,7 @@ buffer = ch | ||
if (ch == '<') { | ||
gotText(true) | ||
mode = TAG | ||
} else if (ch =='\n') { | ||
gotText(false) | ||
newline = true | ||
mode = NEXT | ||
} else { | ||
@@ -114,4 +125,6 @@ buffer += ch | ||
mode = CLOSINGTAG | ||
gotText(true) | ||
} else { | ||
mode = TAGNAME | ||
gotText(false) | ||
buffer = ch | ||
@@ -118,0 +131,0 @@ } |
{ | ||
"name": "babel-plugin-hyperlit", | ||
"version": "0.1.3", | ||
"version": "0.1.5", | ||
"description": "babel transform for hyperlit to hyperapp", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
66
test.js
@@ -422,22 +422,2 @@ const TEXT_NODE = 3 | ||
test( | ||
'whitespace between element and text preserved', | ||
` | ||
html\` | ||
<div> | ||
<span>a</span> b | ||
</div>\` | ||
`, | ||
h('div', {}, [h('span', {}, [text('a')]), text(' b')]), | ||
) | ||
test( | ||
'numeric values in content cast to strings', | ||
`html\`<div>My age: \${42}</div>\``, | ||
h('div', {}, [text('My age: '), text('42')]) | ||
) | ||
test( | ||
'compose arrays of arrays - 1', | ||
@@ -489,1 +469,47 @@ ` | ||
test( | ||
'whitespace between element and text preserved', | ||
` | ||
html\` | ||
<div> | ||
<span>a</span> b | ||
</div>\` | ||
`, | ||
h('div', {}, [h('span', {}, [text('a')]), text(' b')]), | ||
) | ||
test( | ||
'numeric values in content cast to strings', | ||
`html\`<div>My age: \${42}</div>\``, | ||
h('div', {}, [text('My age: '), text('42')]) | ||
) | ||
test( | ||
'preserve whitespace before element', | ||
` | ||
html\`<foo>aaa <bar>bbb</bar>ccc</foo>\` | ||
`, | ||
h('foo', {}, [ | ||
text('aaa '), | ||
h('bar', {}, [ | ||
text('bbb') | ||
]), | ||
text('ccc') | ||
]) | ||
) | ||
test( | ||
'preserve whitespace after element', | ||
` | ||
html\`<foo>aaa<bar>bbb</bar> ccc</foo>\` | ||
`, | ||
h('foo', {}, [ | ||
text('aaa'), | ||
h('bar', {}, [ | ||
text('bbb') | ||
]), | ||
text(' ccc') | ||
]) | ||
) |
21381
711