`
# api
-```
-var hyperx = require('hyperx')
+```js
+import hyperx from 'hyperx'
```
-## var hx = hyperx(h, opts={})
+## const hx = hyperx(h, opts={})
Return a tagged template function `hx` from a hyperscript-style factory function
`h`.
@@ -205,17 +217,13 @@ hyperx syntax.
will be provided as an array to this function. the return value will then be returned
by the template literal
+
# prior art
* http://www.2ality.com/2014/07/jsx-template-strings.html?m=1
* http://facebook.github.io/jsx/#why-not-template-literals (respectfully disagree)
+
# license
BSD
-
-# install
-
-```
-npm install hyperx
-```
diff --git a/test/attr.js b/test/attr.js
index d4c94c7..8c2fd72 100644
--- a/test/attr.js
+++ b/test/attr.js
@@ -1,112 +1,114 @@
-var test = require('tape')
-var vdom = require('virtual-dom')
-var hyperx = require('../')
-var hx = hyperx(vdom.h)
+import hyperx from '../index.js'
+import test from 'tape'
+import vdom from 'virtual-dom'
+
+
+const hx = hyperx(vdom.h)
test('class', function (t) {
- var tree = hx``
+ const tree = hx``
t.equal(vdom.create(tree).toString(), '')
t.end()
})
test('boolean attribute', function (t) {
- var tree = hx``
+ const tree = hx``
t.equal(vdom.create(tree).toString(), '')
t.end()
})
test('boolean attribute followed by normal attribute', function (t) {
- var tree = hx``
+ const tree = hx``
t.equal(vdom.create(tree).toString(), '')
t.end()
})
test('boolean attribute preceded by normal attribute', function (t) {
- var tree = hx``
+ const tree = hx``
t.equal(vdom.create(tree).toString(), '')
t.end()
})
test('unquoted attribute', function (t) {
- var tree = hx``
+ const tree = hx``
t.equal(vdom.create(tree).toString(), '')
t.end()
})
test('unquoted attribute preceded by boolean attribute', function (t) {
- var tree = hx``
+ const tree = hx``
t.equal(vdom.create(tree).toString(), '')
t.end()
})
test('unquoted attribute succeeded by boolean attribute', function (t) {
- var tree = hx``
+ const tree = hx``
t.equal(vdom.create(tree).toString(), '')
t.end()
})
test('unquoted attribute preceded by normal attribute', function (t) {
- var tree = hx``
+ const tree = hx``
t.equal(vdom.create(tree).toString(), '')
t.end()
})
test('unquoted attribute succeeded by normal attribute', function (t) {
- var tree = hx``
+ const tree = hx``
t.equal(vdom.create(tree).toString(), '')
t.end()
})
test('consecutive unquoted attributes', function (t) {
- var tree = hx``
+ const tree = hx``
t.equal(vdom.create(tree).toString(), '')
t.end()
})
test('strange leading character attributes', function (t) {
- var tree = hx``
+ const tree = hx``
t.equal(vdom.create(tree).toString(), '')
t.end()
})
test('strange inbetween character attributes', function (t) {
- var tree = hx``
+ const tree = hx``
t.equal(vdom.create(tree).toString(), ``)
t.end()
})
test('null and undefined attributes', function (t) {
- var tree = hx``
+ const tree = hx``
t.equal(vdom.create(tree).toString(), ``)
t.end()
})
test('undefined (with quotes) attribute value is evaluated', function (t) {
- var tree = hx``
+ const tree = hx``
t.equal(vdom.create(tree).toString(), ``)
t.end()
})
test('null (with quotes) attribute value is evaluated', function (t) {
- var tree = hx``
+ const tree = hx``
t.equal(vdom.create(tree).toString(), ``)
t.end()
})
test('undefined (without quotes) attribute value is evaluated', function (t) {
- var tree = hx``
+ const tree = hx``
t.equal(vdom.create(tree).toString(), ``)
t.end()
})
test('null (without quotes) attribute value is evaluated', function (t) {
- var tree = hx``
+ const tree = hx``
t.equal(vdom.create(tree).toString(), ``)
t.end()
})
test('null is ignored and adjacent attribute is evaluated', function (t) {
- var tree = hx``
+ const tree = hx``
t.equal(vdom.create(tree).toString(), ``)
t.end()
})
diff --git a/test/attr_to_prop.js b/test/attr_to_prop.js
index 831fa85..ae9bb7f 100644
--- a/test/attr_to_prop.js
+++ b/test/attr_to_prop.js
@@ -1,29 +1,31 @@
-var test = require('tape')
-var vdom = require('virtual-dom')
-var hyperx = require('../')
-var hx = hyperx(vdom.h)
+import hyperx from '../index.js'
+import test from 'tape'
+import vdom from 'virtual-dom'
+
+
+const hx = hyperx(vdom.h)
test('class to className', function (t) {
- var tree = hx``
+ const tree = hx``
t.deepEqual(tree.properties, { className: 'wow' })
t.end()
})
test('for to htmlFor', function (t) {
- var tree = hx``
+ const tree = hx``
t.deepEqual(tree.properties, { htmlFor: 'wow' })
t.end()
})
test('http-equiv to httpEquiv', function (t) {
- var tree = hx``
+ const tree = hx``
t.deepEqual(tree.properties, { content: '30', httpEquiv: 'refresh' })
t.end()
})
test('no transform', t => {
- var hx = hyperx(vdom.h, { attrToProp: false })
- var tree = hx``
+ const hx = hyperx(vdom.h, { attrToProp: false })
+ const tree = hx``
t.deepEqual(tree.properties, { class: 'wow' })
t.end()
})
diff --git a/test/br.js b/test/br.js
index b2f437e..5ca7ceb 100644
--- a/test/br.js
+++ b/test/br.js
@@ -1,10 +1,12 @@
-var test = require('tape')
-var vdom = require('virtual-dom')
-var hyperx = require('../')
-var hx = hyperx(vdom.h)
+import hyperx from '../index.js'
+import test from 'tape'
+import vdom from 'virtual-dom'
+
+
+const hx = hyperx(vdom.h)
test('self closing tags without a space', function (t) {
- var tree = hx`
a b
`
+ const tree = hx`
a b
`
t.equal(vdom.create(tree).toString(), '
a b
')
t.end()
})
diff --git a/test/children.js b/test/children.js
index 654f368..850181e 100644
--- a/test/children.js
+++ b/test/children.js
@@ -1,22 +1,24 @@
-var test = require('tape')
-var vdom = require('virtual-dom')
-var hyperx = require('../')
-var hx = hyperx(vdom.h)
+import hyperx from '../index.js'
+import test from 'tape'
+import vdom from 'virtual-dom'
+
+
+const hx = hyperx(vdom.h)
test('1 child', function (t) {
- var tree = hx`
foobar
`
+ const tree = hx`
foobar
`
t.equal(vdom.create(tree).toString(), '
foobar
')
t.end()
})
test('no children', function (t) {
- var tree = hx``
+ const tree = hx``
t.equal(vdom.create(tree).toString(), '')
t.end()
})
test('multiple children', function (t) {
- var html = `
+ const html = `
title
@@ -26,7 +28,7 @@ test('multiple children', function (t) {
`
- var tree = hx`
+ const tree = hx`
title
diff --git a/test/comment.js b/test/comment.js
index 1f8da46..f93f251 100644
--- a/test/comment.js
+++ b/test/comment.js
@@ -1,7 +1,9 @@
-var test = require('tape')
-var hyperx = require('../')
-var hx = hyperx(createElement)
-var hxc = hyperx(createElement, {comments: true})
+import hyperx from '../index.js'
+import test from 'tape'
+
+
+const hx = hyperx(createElement)
+const hxc = hyperx(createElement, {comments: true})
function createElement(tag, props, children) {
if (tag === '!--') {
@@ -11,30 +13,30 @@ function createElement(tag, props, children) {
}
test('1 comment', function (t) {
- var tree = hxc``
+ const tree = hxc``
t.equal(tree, '')
t.end()
})
test('with crazy characters', function (t) {
- var tree = hxc``
+ const tree = hxc``
t.equal(tree, '')
t.end()
})
test('as child', function (t) {
- var tree = hxc``
+ const tree = hxc``
t.equal(tree, '')
t.end()
})
test('many comments', function (t) {
- var html = `
+ const html = `
bar
`
- var tree = hxc`
+ const tree = hxc`
bar
@@ -45,18 +47,18 @@ test('many comments', function (t) {
})
test('excluded by default', function (t) {
- var tree = hx``
+ const tree = hx``
t.equal(tree, '')
t.end()
})
test('template parts in comment, discard comments', function (t) {
- var child = 'something'
- var objectChild = {
+ const child = 'something'
+ const objectChild = {
type: 'div',
children: ['something']
}
- var tree = hx``
+ let tree = hx``
t.equal(tree, '')
tree = hx``
t.equal(tree, '')
@@ -64,12 +66,12 @@ test('template parts in comment, discard comments', function (t) {
})
test('template parts in comment, keep comments', function (t) {
- var child = 'something'
- var objectChild = {
+ const child = 'something'
+ const objectChild = {
type: 'div',
children: ['something']
}
- var tree = hxc``
+ let tree = hxc``
t.equal(tree, '')
tree = hxc``
t.equal(tree, '', 'stringifies comment contents')
diff --git a/test/concat.js b/test/concat.js
index b8b25d3..c8a6a26 100644
--- a/test/concat.js
+++ b/test/concat.js
@@ -1,7 +1,9 @@
-var test = require('tape')
-var vdom = require('virtual-dom')
-var hyperx = require('../')
-var hx = hyperx(function (tagName, opts, children) {
+import hyperx from '../index.js'
+import test from 'tape'
+import vdom from 'virtual-dom'
+
+
+const hx = hyperx(function (tagName, opts, children) {
return {
expr: 'h(' + JSON.stringify(tagName)
+ ',' + JSON.stringify(opts)
@@ -17,7 +19,7 @@ var hx = hyperx(function (tagName, opts, children) {
function concat (a, b) {
if (!a.expr && !b.expr) return String(a) + String(b)
- var aexpr, bexpr
+ let aexpr, bexpr
if (a.expr) aexpr = '(' + a.expr + ')'
else aexpr = JSON.stringify(a)
if (b.expr) bexpr = '(' + b.expr + ')'
@@ -25,7 +27,7 @@ function concat (a, b) {
return { expr: aexpr + '+' + bexpr }
}
-var expected = `
+const expected = `
hello world!
cool
wow
@@ -33,9 +35,9 @@ var expected = `
`
test('vdom', function (t) {
- var title = 'world'
- var wow = [1,2,3]
- var str = hx`