chore(deps): update eslint packages

pull/943/head
Shahar Or (mightyiam) 4 years ago committed by Shahar Dawn Or
parent f4e0b1a12a
commit 2d88e73c13

@ -26,6 +26,7 @@ module.exports = {
rules: { rules: {
'import/newline-after-import': 'error', 'import/newline-after-import': 'error',
'max-statements-per-line': 'error', 'max-statements-per-line': 'error',
'no-var': 'error',
'@typescript-eslint/no-non-null-assertion': 'off', '@typescript-eslint/no-non-null-assertion': 'off',
'@typescript-eslint/consistent-type-definitions': 'off', '@typescript-eslint/consistent-type-definitions': 'off',
'@typescript-eslint/explicit-function-return-type': 'off', '@typescript-eslint/explicit-function-return-type': 'off',

@ -69,16 +69,16 @@ import { styleModule } from 'snabbdom/modules/style'
import { eventListenersModule } from 'snabbdom/modules/eventlisteners' import { eventListenersModule } from 'snabbdom/modules/eventlisteners'
import { h } from 'snabbdom/h' // helper function for creating vnodes import { h } from 'snabbdom/h' // helper function for creating vnodes
var patch = init([ // Init patch function with chosen modules const patch = init([ // Init patch function with chosen modules
classModule, // makes it easy to toggle classes classModule, // makes it easy to toggle classes
propsModule, // for setting properties on DOM elements propsModule, // for setting properties on DOM elements
styleModule, // handles styling on elements with support for animations styleModule, // handles styling on elements with support for animations
eventListenersModule, // attaches event listeners eventListenersModule, // attaches event listeners
]) ])
var container = document.getElementById('container') const container = document.getElementById('container')
var vnode = h('div#container.two.classes', { on: { click: someFn } }, [ const vnode = h('div#container.two.classes', { on: { click: someFn } }, [
h('span', { style: { fontWeight: 'bold' } }, 'This is bold'), h('span', { style: { fontWeight: 'bold' } }, 'This is bold'),
' and this is just normal text', ' and this is just normal text',
h('a', { props: { href: '/foo' } }, 'I\'ll take you places!') h('a', { props: { href: '/foo' } }, 'I\'ll take you places!')
@ -86,7 +86,7 @@ var vnode = h('div#container.two.classes', { on: { click: someFn } }, [
// Patch into empty DOM element this modifies the DOM as a side effect // Patch into empty DOM element this modifies the DOM as a side effect
patch(container, vnode) patch(container, vnode)
var newVnode = h('div#container.two.classes', { on: { click: anotherEventHandler } }, [ const newVnode = h('div#container.two.classes', { on: { click: anotherEventHandler } }, [
h('span', { style: { fontWeight: 'normal', fontStyle: 'italic' } }, 'This is now italic type'), h('span', { style: { fontWeight: 'normal', fontStyle: 'italic' } }, 'This is now italic type'),
' and this is still just normal text', ' and this is still just normal text',
h('a', { props: { href: '/bar' } }, 'I\'ll take you places!') h('a', { props: { href: '/bar' } }, 'I\'ll take you places!')
@ -160,7 +160,7 @@ specified set of modules.
import { classModule } from 'snabbdom/modules/class' import { classModule } from 'snabbdom/modules/class'
import { styleModule } from 'snabbdom/modules/style' import { styleModule } from 'snabbdom/modules/style'
var patch = init([classModule, styleModule]) const patch = init([classModule, styleModule])
``` ```
### `patch` ### `patch`
@ -203,7 +203,7 @@ array of children.
```mjs ```mjs
import { h } from 'snabbdom/h' import { h } from 'snabbdom/h'
var vnode = h('div', { style: { color: '#000' } }, [ const vnode = h('div', { style: { color: '#000' } }, [
h('h1', 'Headline'), h('h1', 'Headline'),
h('p', 'A paragraph'), h('p', 'A paragraph'),
]) ])
@ -223,14 +223,14 @@ import { eventListenersModule } from 'snabbdom/modules/eventlisteners'
import { h } from 'snabbdom/h' // helper function for creating vnodes import { h } from 'snabbdom/h' // helper function for creating vnodes
import { toVNode } from 'snabbdom/tovnode' import { toVNode } from 'snabbdom/tovnode'
var patch = init([ // Init patch function with chosen modules const patch = init([ // Init patch function with chosen modules
classModule, // makes it easy to toggle classes classModule, // makes it easy to toggle classes
propsModule, // for setting properties on DOM elements propsModule, // for setting properties on DOM elements
styleModule, // handles styling on elements with support for animations styleModule, // handles styling on elements with support for animations
eventListenersModule, // attaches event listeners eventListenersModule, // attaches event listeners
]) ])
var newVNode = h('div', { style: { color: '#000' } }, [ const newVNode = h('div', { style: { color: '#000' } }, [
h('h1', 'Headline'), h('h1', 'Headline'),
h('p', 'A paragraph'), h('p', 'A paragraph'),
]) ])
@ -319,8 +319,8 @@ To see the difference between this hook and the `remove` hook,
consider an example. consider an example.
```mjs ```mjs
var vnode1 = h('div', [h('div', [h('span', 'Hello')])]) const vnode1 = h('div', [h('div', [h('span', 'Hello')])])
var vnode2 = h('div', []) const vnode2 = h('div', [])
patch(container, vnode1) patch(container, vnode1)
patch(vnode1, vnode2) patch(vnode1, vnode2)
``` ```
@ -339,7 +339,7 @@ animate the disappearance of the removed element's children.
Modules works by registering global listeners for [hooks](#hooks). A module is simply a dictionary mapping hook names to functions. Modules works by registering global listeners for [hooks](#hooks). A module is simply a dictionary mapping hook names to functions.
```mjs ```mjs
var myModule = { const myModule = {
create: function (oldVnode, vnode) { create: function (oldVnode, vnode) {
// invoked whenever a new virtual node is created // invoked whenever a new virtual node is created
}, },
@ -564,7 +564,7 @@ In particular, you should **not** do something like this:
```mjs ```mjs
// Does not work // Does not work
var sharedHandler = { const sharedHandler = {
change: function (e) { console.log('you chose: ' + e.target.value) } change: function (e) { console.log('you chose: ' + e.target.value) }
} }
h('div', [ h('div', [
@ -588,7 +588,7 @@ Alternatively, simply make sure each node is passed unique `on` values:
```mjs ```mjs
// Works // Works
var sharedHandler = function (e) { const sharedHandler = function (e) {
console.log('you chose: ' + e.target.value) console.log('you chose: ' + e.target.value)
} }
h('div', [ h('div', [
@ -614,7 +614,7 @@ nodes. SVG elements are automatically created with the appropriate
namespaces. namespaces.
```mjs ```mjs
var vnode = h('div', [ const vnode = h('div', [
h('svg', { attrs: { width: 100, height: 100 } }, [ h('svg', { attrs: { width: 100, height: 100 } }, [
h('circle', { attrs: { cx: 50, cy: 50, r: 40, stroke: 'green', 'stroke-width': 4, fill: 'yellow' } }) h('circle', { attrs: { cx: 50, cy: 50, r: 40, stroke: 'green', 'stroke-width': 4, fill: 'yellow' } })
]) ])
@ -819,13 +819,13 @@ Uncaught NotFoundError: Failed to execute 'insertBefore' on 'Node':
The reason for this error is reusing of vnodes between patches (see code example), snabbdom stores actual dom nodes inside the virtual dom nodes passed to it as performance improvement, so reusing nodes between patches is not supported. The reason for this error is reusing of vnodes between patches (see code example), snabbdom stores actual dom nodes inside the virtual dom nodes passed to it as performance improvement, so reusing nodes between patches is not supported.
```mjs ```mjs
var sharedNode = h('div', {}, 'Selected') const sharedNode = h('div', {}, 'Selected')
var vnode1 = h('div', [ const vnode1 = h('div', [
h('div', {}, ['One']), h('div', {}, ['One']),
h('div', {}, ['Two']), h('div', {}, ['Two']),
h('div', {}, [sharedNode]), h('div', {}, [sharedNode]),
]) ])
var vnode2 = h('div', [ const vnode2 = h('div', [
h('div', {}, ['One']), h('div', {}, ['One']),
h('div', {}, [sharedNode]), h('div', {}, [sharedNode]),
h('div', {}, ['Three']), h('div', {}, ['Three']),
@ -837,7 +837,7 @@ patch(vnode1, vnode2)
You can fix this issue by creating a shallow copy of the object (here with object spread syntax): You can fix this issue by creating a shallow copy of the object (here with object spread syntax):
```mjs ```mjs
var vnode2 = h('div', [ const vnode2 = h('div', [
h('div', {}, ['One']), h('div', {}, ['One']),
h('div', {}, [{ ...sharedNode }]), h('div', {}, [{ ...sharedNode }]),
h('div', {}, ['Three']), h('div', {}, ['Three']),
@ -847,8 +847,8 @@ var vnode2 = h('div', [
Another solution would be to wrap shared vnodes in a factory function: Another solution would be to wrap shared vnodes in a factory function:
```mjs ```mjs
var sharedNode = () => h('div', {}, 'Selected') const sharedNode = () => h('div', {}, 'Selected')
var vnode1 = h('div', [ const vnode1 = h('div', [
h('div', {}, ['One']), h('div', {}, ['One']),
h('div', {}, ['Two']), h('div', {}, ['Two']),
h('div', {}, [sharedNode()]), h('div', {}, [sharedNode()]),

1308
package-lock.json generated

File diff suppressed because it is too large Load Diff

@ -34,7 +34,7 @@
"@types/lodash.shuffle": "4.2.6", "@types/lodash.shuffle": "4.2.6",
"@types/mathjs": "6.0.5", "@types/mathjs": "6.0.5",
"@types/mocha": "8.0.3", "@types/mocha": "8.0.3",
"@typescript-eslint/eslint-plugin": "4.2.0", "@typescript-eslint/eslint-plugin": "4.15.1",
"babel-loader": "8.1.0", "babel-loader": "8.1.0",
"benchmark": "2.1.4", "benchmark": "2.1.4",
"chai": "4.2.0", "chai": "4.2.0",
@ -42,13 +42,12 @@
"core-js": "3.6.5", "core-js": "3.6.5",
"cross-env": "7.0.3", "cross-env": "7.0.3",
"editorconfig-checker": "3.2.0", "editorconfig-checker": "3.2.0",
"eslint": "7.9.0", "eslint": "7.20.0",
"eslint-config-standard-with-typescript": "19.0.1", "eslint-config-standard-with-typescript": "20.0.0",
"eslint-plugin-import": "2.22.0", "eslint-plugin-import": "2.22.1",
"eslint-plugin-markdown": "2.0.0-rc.0", "eslint-plugin-markdown": "2.0.0",
"eslint-plugin-node": "11.1.0", "eslint-plugin-node": "11.1.0",
"eslint-plugin-promise": "4.3.1", "eslint-plugin-promise": "4.3.1",
"eslint-plugin-standard": "4.0.1",
"faker": "5.4.0", "faker": "5.4.0",
"globby": "11.0.2", "globby": "11.0.2",
"husky": "5.0.9", "husky": "5.0.9",

@ -23,10 +23,10 @@ export function h (sel: string, data: VNodeData | null): VNode
export function h (sel: string, children: VNodeChildren): VNode export function h (sel: string, children: VNodeChildren): VNode
export function h (sel: string, data: VNodeData | null, children: VNodeChildren): VNode export function h (sel: string, data: VNodeData | null, children: VNodeChildren): VNode
export function h (sel: any, b?: any, c?: any): VNode { export function h (sel: any, b?: any, c?: any): VNode {
var data: VNodeData = {} let data: VNodeData = {}
var children: any let children: any
var text: any let text: any
var i: number let i: number
if (c !== undefined) { if (c !== undefined) {
if (b !== null) { if (b !== null) {
data = b data = b

@ -9,10 +9,10 @@ const colonChar = 58
const xChar = 120 const xChar = 120
function updateAttrs (oldVnode: VNode, vnode: VNode): void { function updateAttrs (oldVnode: VNode, vnode: VNode): void {
var key: string let key: string
var elm: Element = vnode.elm as Element const elm: Element = vnode.elm as Element
var oldAttrs = (oldVnode.data as VNodeData).attrs let oldAttrs = (oldVnode.data as VNodeData).attrs
var attrs = (vnode.data as VNodeData).attrs let attrs = (vnode.data as VNodeData).attrs
if (!oldAttrs && !attrs) return if (!oldAttrs && !attrs) return
if (oldAttrs === attrs) return if (oldAttrs === attrs) return

@ -4,11 +4,11 @@ import { Module } from './module'
export type Classes = Record<string, boolean> export type Classes = Record<string, boolean>
function updateClass (oldVnode: VNode, vnode: VNode): void { function updateClass (oldVnode: VNode, vnode: VNode): void {
var cur: any let cur: any
var name: string let name: string
var elm: Element = vnode.elm as Element const elm: Element = vnode.elm as Element
var oldClass = (oldVnode.data as VNodeData).class let oldClass = (oldVnode.data as VNodeData).class
var klass = (vnode.data as VNodeData).class let klass = (vnode.data as VNodeData).class
if (!oldClass && !klass) return if (!oldClass && !klass) return
if (oldClass === klass) return if (oldClass === klass) return

@ -17,15 +17,15 @@ function invokeHandler<N extends keyof HTMLElementEventMap> (handler: SomeListen
handler.call(vnode, event, vnode) handler.call(vnode, event, vnode)
} else if (typeof handler === 'object') { } else if (typeof handler === 'object') {
// call multiple handlers // call multiple handlers
for (var i = 0; i < handler.length; i++) { for (let i = 0; i < handler.length; i++) {
invokeHandler(handler[i], vnode, event) invokeHandler(handler[i], vnode, event)
} }
} }
} }
function handleEvent (event: Event, vnode: VNode) { function handleEvent (event: Event, vnode: VNode) {
var name = event.type const name = event.type
var on = (vnode.data as VNodeData).on const on = (vnode.data as VNodeData).on
// call event handler(s) if exists // call event handler(s) if exists
if (on && on[name]) { if (on && on[name]) {
@ -40,12 +40,12 @@ function createListener () {
} }
function updateEventListeners (oldVnode: VNode, vnode?: VNode): void { function updateEventListeners (oldVnode: VNode, vnode?: VNode): void {
var oldOn = (oldVnode.data as VNodeData).on const oldOn = (oldVnode.data as VNodeData).on
var oldListener = (oldVnode as any).listener const oldListener = (oldVnode as any).listener
var oldElm: Element = oldVnode.elm as Element const oldElm: Element = oldVnode.elm as Element
var on = vnode && (vnode.data as VNodeData).on const on = vnode && (vnode.data as VNodeData).on
var elm: Element = (vnode && vnode.elm) as Element const elm: Element = (vnode && vnode.elm) as Element
var name: string let name: string
// optimization for reused immutable handlers // optimization for reused immutable handlers
if (oldOn === on) { if (oldOn === on) {
@ -73,7 +73,7 @@ function updateEventListeners (oldVnode: VNode, vnode?: VNode): void {
// add new listeners which has not already attached // add new listeners which has not already attached
if (on) { if (on) {
// reuse existing listener or create new // reuse existing listener or create new
var listener = (vnode as any).listener = (oldVnode as any).listener || createListener() const listener = (vnode as any).listener = (oldVnode as any).listener || createListener()
// update vnode for listener // update vnode for listener
listener.vnode = vnode listener.vnode = vnode

@ -3,8 +3,8 @@ import { Module } from './module'
export type Hero = { id: string } export type Hero = { id: string }
var raf = (typeof window !== 'undefined' && window.requestAnimationFrame) || setTimeout const raf = (typeof window !== 'undefined' && window.requestAnimationFrame) || setTimeout
var nextFrame = function (fn: any) { const nextFrame = function (fn: any) {
raf(function () { raf(function () {
raf(fn) raf(fn)
}) })
@ -17,9 +17,9 @@ function setNextFrame (obj: any, prop: string, val: any): void {
} }
function getTextNodeRect (textNode: Text): ClientRect | undefined { function getTextNodeRect (textNode: Text): ClientRect | undefined {
var rect: ClientRect | undefined let rect: ClientRect | undefined
if (document.createRange) { if (document.createRange) {
var range = document.createRange() const range = document.createRange()
range.selectNodeContents(textNode) range.selectNodeContents(textNode)
if (range.getBoundingClientRect) { if (range.getBoundingClientRect) {
rect = range.getBoundingClientRect() rect = range.getBoundingClientRect()
@ -36,8 +36,8 @@ function calcTransformOrigin (
if (isTextNode) { if (isTextNode) {
if (textRect) { if (textRect) {
// calculate pixels to center of text from left edge of bounding box // calculate pixels to center of text from left edge of bounding box
var relativeCenterX = textRect.left + textRect.width / 2 - boundingRect.left const relativeCenterX = textRect.left + textRect.width / 2 - boundingRect.left
var relativeCenterY = textRect.top + textRect.height / 2 - boundingRect.top const relativeCenterY = textRect.top + textRect.height / 2 - boundingRect.top
return relativeCenterX + 'px ' + relativeCenterY + 'px' return relativeCenterX + 'px ' + relativeCenterY + 'px'
} }
} }
@ -67,7 +67,7 @@ function isTextElement (elm: Element | Text): elm is Text {
return elm.childNodes.length === 1 && elm.childNodes[0].nodeType === 3 return elm.childNodes.length === 1 && elm.childNodes[0].nodeType === 3
} }
var removed: any, created: any let removed: any, created: any
function pre () { function pre () {
removed = {} removed = {}
@ -75,7 +75,7 @@ function pre () {
} }
function create (oldVnode: VNode, vnode: VNode): void { function create (oldVnode: VNode, vnode: VNode): void {
var hero = (vnode.data as VNodeData).hero const hero = (vnode.data as VNodeData).hero
if (hero && hero.id) { if (hero && hero.id) {
created.push(hero.id) created.push(hero.id)
created.push(vnode) created.push(vnode)
@ -83,20 +83,20 @@ function create (oldVnode: VNode, vnode: VNode): void {
} }
function destroy (vnode: VNode): void { function destroy (vnode: VNode): void {
var hero = (vnode.data as VNodeData).hero const hero = (vnode.data as VNodeData).hero
if (hero && hero.id) { if (hero && hero.id) {
var elm = vnode.elm; const elm = vnode.elm;
(vnode as any).isTextNode = isTextElement(elm as Element | Text); // is this a text node? (vnode as any).isTextNode = isTextElement(elm as Element | Text); // is this a text node?
(vnode as any).boundingRect = (elm as Element).getBoundingClientRect(); // save the bounding rectangle to a new property on the vnode (vnode as any).boundingRect = (elm as Element).getBoundingClientRect(); // save the bounding rectangle to a new property on the vnode
(vnode as any).textRect = (vnode as any).isTextNode ? getTextNodeRect((elm as Element).childNodes[0] as Text) : null // save bounding rect of inner text node (vnode as any).textRect = (vnode as any).isTextNode ? getTextNodeRect((elm as Element).childNodes[0] as Text) : null // save bounding rect of inner text node
var computedStyle = window.getComputedStyle(elm as Element, undefined); // get current styles (includes inherited properties) const computedStyle = window.getComputedStyle(elm as Element, undefined); // get current styles (includes inherited properties)
(vnode as any).savedStyle = JSON.parse(JSON.stringify(computedStyle)) // save a copy of computed style values (vnode as any).savedStyle = JSON.parse(JSON.stringify(computedStyle)) // save a copy of computed style values
removed[hero.id] = vnode removed[hero.id] = vnode
} }
} }
function post () { function post () {
var i: number, id: any, newElm: Element, oldVnode: VNode, oldElm: Element, let i: number, id: any, newElm: Element, oldVnode: VNode, oldElm: Element,
hRatio: number, wRatio: number, hRatio: number, wRatio: number,
oldRect: ClientRect, newRect: ClientRect, dx: number, dy: number, oldRect: ClientRect, newRect: ClientRect, dx: number, dy: number,
origTransform: string | null, origTransition: string | null, origTransform: string | null, origTransition: string | null,
@ -146,11 +146,11 @@ function post () {
setNextFrame(newStyle, 'transform', origTransform) setNextFrame(newStyle, 'transform', origTransform)
setNextFrame(newStyle, 'opacity', '1') setNextFrame(newStyle, 'opacity', '1')
// Animate old element // Animate old element
for (var key in (oldVnode as any).savedStyle) { // re-apply saved inherited properties for (const key in (oldVnode as any).savedStyle) { // re-apply saved inherited properties
if (String(parseInt(key)) !== key) { if (String(parseInt(key)) !== key) {
var ms = key.substring(0, 2) === 'ms' const ms = key.substring(0, 2) === 'ms'
var moz = key.substring(0, 3) === 'moz' const moz = key.substring(0, 3) === 'moz'
var webkit = key.substring(0, 6) === 'webkit' const webkit = key.substring(0, 6) === 'webkit'
if (!ms && !moz && !webkit) { if (!ms && !moz && !webkit) {
// ignore prefixed style properties // ignore prefixed style properties
(oldStyle as any)[key] = (oldVnode as any).savedStyle[key] (oldStyle as any)[key] = (oldVnode as any).savedStyle[key]

@ -4,12 +4,12 @@ import { Module } from './module'
export type Props = Record<string, any> export type Props = Record<string, any>
function updateProps (oldVnode: VNode, vnode: VNode): void { function updateProps (oldVnode: VNode, vnode: VNode): void {
var key: string let key: string
var cur: any let cur: any
var old: any let old: any
var elm = vnode.elm const elm = vnode.elm
var oldProps = (oldVnode.data as VNodeData).props let oldProps = (oldVnode.data as VNodeData).props
var props = (vnode.data as VNodeData).props let props = (vnode.data as VNodeData).props
if (!oldProps && !props) return if (!oldProps && !props) return
if (oldProps === props) return if (oldProps === props) return

@ -7,13 +7,13 @@ export type VNodeStyle = Record<string, string> & {
} }
// Bindig `requestAnimationFrame` like this fixes a bug in IE/Edge. See #360 and #409. // Bindig `requestAnimationFrame` like this fixes a bug in IE/Edge. See #360 and #409.
var raf = (typeof window !== 'undefined' && (window.requestAnimationFrame).bind(window)) || setTimeout const raf = (typeof window !== 'undefined' && (window.requestAnimationFrame).bind(window)) || setTimeout
var nextFrame = function (fn: any) { const nextFrame = function (fn: any) {
raf(function () { raf(function () {
raf(fn) raf(fn)
}) })
} }
var reflowForced = false let reflowForced = false
function setNextFrame (obj: any, prop: string, val: any): void { function setNextFrame (obj: any, prop: string, val: any): void {
nextFrame(function () { nextFrame(function () {
@ -22,17 +22,17 @@ function setNextFrame (obj: any, prop: string, val: any): void {
} }
function updateStyle (oldVnode: VNode, vnode: VNode): void { function updateStyle (oldVnode: VNode, vnode: VNode): void {
var cur: any let cur: any
var name: string let name: string
var elm = vnode.elm const elm = vnode.elm
var oldStyle = (oldVnode.data as VNodeData).style let oldStyle = (oldVnode.data as VNodeData).style
var style = (vnode.data as VNodeData).style let style = (vnode.data as VNodeData).style
if (!oldStyle && !style) return if (!oldStyle && !style) return
if (oldStyle === style) return if (oldStyle === style) return
oldStyle = oldStyle || {} oldStyle = oldStyle || {}
style = style || {} style = style || {}
var oldHasDel = 'delayed' in oldStyle const oldHasDel = 'delayed' in oldStyle
for (name in oldStyle) { for (name in oldStyle) {
if (!style[name]) { if (!style[name]) {
@ -63,10 +63,10 @@ function updateStyle (oldVnode: VNode, vnode: VNode): void {
} }
function applyDestroyStyle (vnode: VNode): void { function applyDestroyStyle (vnode: VNode): void {
var style: any let style: any
var name: string let name: string
var elm = vnode.elm const elm = vnode.elm
var s = (vnode.data as VNodeData).style const s = (vnode.data as VNodeData).style
if (!s || !(style = s.destroy)) return if (!s || !(style = s.destroy)) return
for (name in style) { for (name in style) {
(elm as any).style[name] = style[name] (elm as any).style[name] = style[name]
@ -74,7 +74,7 @@ function applyDestroyStyle (vnode: VNode): void {
} }
function applyRemoveStyle (vnode: VNode, rm: () => void): void { function applyRemoveStyle (vnode: VNode, rm: () => void): void {
var s = (vnode.data as VNodeData).style const s = (vnode.data as VNodeData).style
if (!s || !s.remove) { if (!s || !s.remove) {
rm() rm()
return return
@ -84,19 +84,18 @@ function applyRemoveStyle (vnode: VNode, rm: () => void): void {
(vnode.elm as any).offsetLeft (vnode.elm as any).offsetLeft
reflowForced = true reflowForced = true
} }
var name: string let name: string
var elm = vnode.elm const elm = vnode.elm
var i = 0 let i = 0
var compStyle: CSSStyleDeclaration const style = s.remove
var style = s.remove let amount = 0
var amount = 0 const applied: string[] = []
var applied: string[] = []
for (name in style) { for (name in style) {
applied.push(name); applied.push(name);
(elm as any).style[name] = style[name] (elm as any).style[name] = style[name]
} }
compStyle = getComputedStyle(elm as Element) const compStyle = getComputedStyle(elm as Element)
var props = (compStyle as any)['transition-property'].split(', ') const props = (compStyle as any)['transition-property'].split(', ')
for (; i < props.length; ++i) { for (; i < props.length; ++i) {
if (applied.indexOf(props[i]) !== -1) amount++ if (applied.indexOf(props[i]) !== -1) amount++
} }

@ -8,12 +8,12 @@ module.exports.transform = (ctx) => (sf) => ts.visitNode(sf, (node) => {
node.moduleSpecifier node.moduleSpecifier
? node.moduleSpecifier.getText(sf).slice(1, -1) ? node.moduleSpecifier.getText(sf).slice(1, -1)
: ( : (
ts.isImportTypeNode(node) && ts.isImportTypeNode(node) &&
ts.isLiteralTypeNode(node.argument) && ts.isLiteralTypeNode(node.argument) &&
ts.isStringLiteral(node.argument.literal) ts.isStringLiteral(node.argument.literal)
) )
? node.argument.literal.text ? node.argument.literal.text
: null : null
if (originalPath === null) return node if (originalPath === null) return node
const pathWithExtension = originalPath.endsWith('.js') const pathWithExtension = originalPath.endsWith('.js')

@ -4,16 +4,16 @@ import { RemoveHook } from '../../package/hooks'
import { attachTo } from '../../package/helpers/attachto' import { attachTo } from '../../package/helpers/attachto'
import { h } from '../../package/h' import { h } from '../../package/h'
var patch = init([]) const patch = init([])
describe('attachTo', function () { describe('attachTo', function () {
var elm: any, vnode0: any let elm: any, vnode0: any
beforeEach(function () { beforeEach(function () {
elm = document.createElement('div') elm = document.createElement('div')
vnode0 = elm vnode0 = elm
}) })
it('adds element to target', function () { it('adds element to target', function () {
var vnode1 = h('div', [ const vnode1 = h('div', [
h('div#wrapper', [ h('div#wrapper', [
h('div', 'Some element'), h('div', 'Some element'),
attachTo(elm, h('div#attached', 'Test')), attachTo(elm, h('div#attached', 'Test')),
@ -23,13 +23,13 @@ describe('attachTo', function () {
assert.strictEqual(elm.children.length, 2) assert.strictEqual(elm.children.length, 2)
}) })
it('updates element at target', function () { it('updates element at target', function () {
var vnode1 = h('div', [ const vnode1 = h('div', [
h('div#wrapper', [ h('div#wrapper', [
h('div', 'Some element'), h('div', 'Some element'),
attachTo(elm, h('div#attached', 'First text')), attachTo(elm, h('div#attached', 'First text')),
]), ]),
]) ])
var vnode2 = h('div', [ const vnode2 = h('div', [
h('div#wrapper', [ h('div#wrapper', [
h('div', 'Some element'), h('div', 'Some element'),
attachTo(elm, h('div#attached', 'New text')), attachTo(elm, h('div#attached', 'New text')),
@ -41,13 +41,13 @@ describe('attachTo', function () {
assert.strictEqual(elm.children[0].innerHTML, 'New text') assert.strictEqual(elm.children[0].innerHTML, 'New text')
}) })
it('element can be inserted before modal', function () { it('element can be inserted before modal', function () {
var vnode1 = h('div', [ const vnode1 = h('div', [
h('div#wrapper', [ h('div#wrapper', [
h('div', 'Some element'), h('div', 'Some element'),
attachTo(elm, h('div#attached', 'Text')), attachTo(elm, h('div#attached', 'Text')),
]), ]),
]) ])
var vnode2 = h('div', [ const vnode2 = h('div', [
h('div#wrapper', [ h('div#wrapper', [
h('div', 'Some element'), h('div', 'Some element'),
h('div', 'A new element'), h('div', 'A new element'),
@ -60,13 +60,13 @@ describe('attachTo', function () {
assert.strictEqual(elm.children[0].innerHTML, 'Text') assert.strictEqual(elm.children[0].innerHTML, 'Text')
}) })
it('removes element at target', function () { it('removes element at target', function () {
var vnode1 = h('div', [ const vnode1 = h('div', [
h('div#wrapper', [ h('div#wrapper', [
h('div', 'Some element'), h('div', 'Some element'),
attachTo(elm, h('div#attached', 'First text')), attachTo(elm, h('div#attached', 'First text')),
]), ]),
]) ])
var vnode2 = h('div', [ const vnode2 = h('div', [
h('div#wrapper', [ h('div#wrapper', [
h('div', 'Some element'), h('div', 'Some element'),
]), ]),
@ -83,13 +83,13 @@ describe('attachTo', function () {
assert.strictEqual(elm.innerHTML, 'First text') assert.strictEqual(elm.innerHTML, 'First text')
cb() cb()
} }
var vnode1 = h('div', [ const vnode1 = h('div', [
h('div#wrapper', [ h('div#wrapper', [
h('div', 'Some element'), h('div', 'Some element'),
attachTo(elm, h('div#attached', { hook: { remove: rm } }, 'First text')), attachTo(elm, h('div#attached', { hook: { remove: rm } }, 'First text')),
]), ]),
]) ])
var vnode2 = h('div', [ const vnode2 = h('div', [
h('div#wrapper', [ h('div#wrapper', [
h('div', 'Some element'), h('div', 'Some element'),
]), ]),

@ -3,18 +3,18 @@ import { init } from '../../package/init'
import { attributesModule } from '../../package/modules/attributes' import { attributesModule } from '../../package/modules/attributes'
import { h } from '../../package/h' import { h } from '../../package/h'
var patch = init([ const patch = init([
attributesModule attributesModule
]) ])
describe('attributes', function () { describe('attributes', function () {
var elm: any, vnode0: any let elm: any, vnode0: any
beforeEach(function () { beforeEach(function () {
elm = document.createElement('div') elm = document.createElement('div')
vnode0 = elm vnode0 = elm
}) })
it('have their provided values', function () { it('have their provided values', function () {
var vnode1 = h('div', { attrs: { href: '/foo', minlength: 1, selected: true, disabled: false } }) const vnode1 = h('div', { attrs: { href: '/foo', minlength: 1, selected: true, disabled: false } })
elm = patch(vnode0, vnode1).elm elm = patch(vnode0, vnode1).elm
assert.strictEqual(elm.getAttribute('href'), '/foo') assert.strictEqual(elm.getAttribute('href'), '/foo')
assert.strictEqual(elm.getAttribute('minlength'), '1') assert.strictEqual(elm.getAttribute('minlength'), '1')
@ -23,9 +23,9 @@ describe('attributes', function () {
assert.strictEqual(elm.hasAttribute('disabled'), false) assert.strictEqual(elm.hasAttribute('disabled'), false)
}) })
it('can be memoized', function () { it('can be memoized', function () {
var cachedAttrs = { href: '/foo', minlength: 1, selected: true } const cachedAttrs = { href: '/foo', minlength: 1, selected: true }
var vnode1 = h('div', { attrs: cachedAttrs }) const vnode1 = h('div', { attrs: cachedAttrs })
var vnode2 = h('div', { attrs: cachedAttrs }) const vnode2 = h('div', { attrs: cachedAttrs })
elm = patch(vnode0, vnode1).elm elm = patch(vnode0, vnode1).elm
assert.strictEqual(elm.getAttribute('href'), '/foo') assert.strictEqual(elm.getAttribute('href'), '/foo')
assert.strictEqual(elm.getAttribute('minlength'), '1') assert.strictEqual(elm.getAttribute('minlength'), '1')
@ -36,7 +36,7 @@ describe('attributes', function () {
assert.strictEqual(elm.getAttribute('selected'), '') assert.strictEqual(elm.getAttribute('selected'), '')
}) })
it('are not omitted when falsy values are provided', function () { it('are not omitted when falsy values are provided', function () {
var vnode1 = h('div', { attrs: { href: null as any, minlength: 0, value: '', title: 'undefined' } }) const vnode1 = h('div', { attrs: { href: null as any, minlength: 0, value: '', title: 'undefined' } })
elm = patch(vnode0, vnode1).elm elm = patch(vnode0, vnode1).elm
assert.ok(elm.hasAttribute('href')) assert.ok(elm.hasAttribute('href'))
assert.ok(elm.hasAttribute('minlength')) assert.ok(elm.hasAttribute('minlength'))
@ -44,7 +44,7 @@ describe('attributes', function () {
assert.ok(elm.hasAttribute('title')) assert.ok(elm.hasAttribute('title'))
}) })
it('are set correctly when namespaced', function () { it('are set correctly when namespaced', function () {
var vnode1 = h('div', { attrs: { 'xlink:href': '#foo' } }) const vnode1 = h('div', { attrs: { 'xlink:href': '#foo' } })
elm = patch(vnode0, vnode1).elm elm = patch(vnode0, vnode1).elm
assert.strictEqual(elm.getAttributeNS('http://www.w3.org/1999/xlink', 'href'), '#foo') assert.strictEqual(elm.getAttributeNS('http://www.w3.org/1999/xlink', 'href'), '#foo')
}) })
@ -53,7 +53,7 @@ describe('attributes', function () {
elm.id = 'myId' elm.id = 'myId'
elm.className = 'myClass' elm.className = 'myClass'
vnode0 = elm vnode0 = elm
var vnode1 = h('div#myId.myClass', { attrs: {} }, ['Hello']) const vnode1 = h('div#myId.myClass', { attrs: {} }, ['Hello'])
elm = patch(vnode0, vnode1).elm elm = patch(vnode0, vnode1).elm
assert.strictEqual(elm.tagName, 'DIV') assert.strictEqual(elm.tagName, 'DIV')
assert.strictEqual(elm.id, 'myId') assert.strictEqual(elm.id, 'myId')
@ -62,7 +62,7 @@ describe('attributes', function () {
}) })
describe('boolean attribute', function () { describe('boolean attribute', function () {
it('is present and empty string if the value is truthy', function () { it('is present and empty string if the value is truthy', function () {
var vnode1 = h('div', { attrs: { required: true, readonly: 1, noresize: 'truthy' } }) const vnode1 = h('div', { attrs: { required: true, readonly: 1, noresize: 'truthy' } })
elm = patch(vnode0, vnode1).elm elm = patch(vnode0, vnode1).elm
assert.strictEqual(elm.hasAttribute('required'), true) assert.strictEqual(elm.hasAttribute('required'), true)
assert.strictEqual(elm.getAttribute('required'), '') assert.strictEqual(elm.getAttribute('required'), '')
@ -72,13 +72,13 @@ describe('attributes', function () {
assert.strictEqual(elm.getAttribute('noresize'), 'truthy') assert.strictEqual(elm.getAttribute('noresize'), 'truthy')
}) })
it('is omitted if the value is false', function () { it('is omitted if the value is false', function () {
var vnode1 = h('div', { attrs: { required: false } }) const vnode1 = h('div', { attrs: { required: false } })
elm = patch(vnode0, vnode1).elm elm = patch(vnode0, vnode1).elm
assert.strictEqual(elm.hasAttribute('required'), false) assert.strictEqual(elm.hasAttribute('required'), false)
assert.strictEqual(elm.getAttribute('required'), null) assert.strictEqual(elm.getAttribute('required'), null)
}) })
it('is not omitted if the value is falsy', function () { it('is not omitted if the value is falsy', function () {
var vnode1 = h('div', { attrs: { readonly: 0, noresize: null as any } }) const vnode1 = h('div', { attrs: { readonly: 0, noresize: null as any } })
elm = patch(vnode0, vnode1).elm elm = patch(vnode0, vnode1).elm
assert.ok(elm.hasAttribute('readonly')) assert.ok(elm.hasAttribute('readonly'))
assert.ok(elm.hasAttribute('noresize')) assert.ok(elm.hasAttribute('noresize'))
@ -86,11 +86,11 @@ describe('attributes', function () {
}) })
describe('Object.prototype property', function () { describe('Object.prototype property', function () {
it('is not considered as a boolean attribute and shouldn\'t be omitted', function () { it('is not considered as a boolean attribute and shouldn\'t be omitted', function () {
var vnode1 = h('div', { attrs: { constructor: true } }) const vnode1 = h('div', { attrs: { constructor: true } })
elm = patch(vnode0, vnode1).elm elm = patch(vnode0, vnode1).elm
assert.strictEqual(elm.hasAttribute('constructor'), true) assert.strictEqual(elm.hasAttribute('constructor'), true)
assert.strictEqual(elm.getAttribute('constructor'), '') assert.strictEqual(elm.getAttribute('constructor'), '')
var vnode2 = h('div', { attrs: { constructor: false } }) const vnode2 = h('div', { attrs: { constructor: false } })
elm = patch(vnode0, vnode2).elm elm = patch(vnode0, vnode2).elm
assert.strictEqual(elm.hasAttribute('constructor'), false) assert.strictEqual(elm.hasAttribute('constructor'), false)
}) })

File diff suppressed because it is too large Load Diff

@ -4,7 +4,7 @@ import { datasetModule } from '../../package/modules/dataset'
import { init } from '../../package/init' import { init } from '../../package/init'
import { h } from '../../package/h' import { h } from '../../package/h'
var patch = init([ const patch = init([
datasetModule datasetModule
]) ])
@ -15,7 +15,7 @@ describe('dataset', function () {
} }
}) })
var elm: any, vnode0: any let elm: any, vnode0: any
beforeEach(function () { beforeEach(function () {
elm = document.createElement('div') elm = document.createElement('div')
vnode0 = elm vnode0 = elm
@ -25,8 +25,8 @@ describe('dataset', function () {
assert.strictEqual(elm.dataset.foo, 'foo') assert.strictEqual(elm.dataset.foo, 'foo')
}) })
it('updates dataset', function () { it('updates dataset', function () {
var vnode1 = h('i', { dataset: { foo: 'foo', bar: 'bar' } }) const vnode1 = h('i', { dataset: { foo: 'foo', bar: 'bar' } })
var vnode2 = h('i', { dataset: { baz: 'baz' } }) const vnode2 = h('i', { dataset: { baz: 'baz' } })
elm = patch(vnode0, vnode1).elm elm = patch(vnode0, vnode1).elm
assert.strictEqual(elm.dataset.foo, 'foo') assert.strictEqual(elm.dataset.foo, 'foo')
assert.strictEqual(elm.dataset.bar, 'bar') assert.strictEqual(elm.dataset.bar, 'bar')
@ -35,9 +35,9 @@ describe('dataset', function () {
assert.strictEqual(elm.dataset.foo, undefined) assert.strictEqual(elm.dataset.foo, undefined)
}) })
it('can be memoized', function () { it('can be memoized', function () {
var cachedDataset = { foo: 'foo', bar: 'bar' } const cachedDataset = { foo: 'foo', bar: 'bar' }
var vnode1 = h('i', { dataset: cachedDataset }) const vnode1 = h('i', { dataset: cachedDataset })
var vnode2 = h('i', { dataset: cachedDataset }) const vnode2 = h('i', { dataset: cachedDataset })
elm = patch(vnode0, vnode1).elm elm = patch(vnode0, vnode1).elm
assert.strictEqual(elm.dataset.foo, 'foo') assert.strictEqual(elm.dataset.foo, 'foo')
assert.strictEqual(elm.dataset.bar, 'bar') assert.strictEqual(elm.dataset.bar, 'bar')
@ -46,7 +46,7 @@ describe('dataset', function () {
assert.strictEqual(elm.dataset.bar, 'bar') assert.strictEqual(elm.dataset.bar, 'bar')
}) })
it('handles string conversions', function () { it('handles string conversions', function () {
var vnode1 = h('i', { dataset: { empty: '', dash: '-', dashed: 'foo-bar', camel: 'fooBar', integer: 0 as any, float: 0.1 as any } }) const vnode1 = h('i', { dataset: { empty: '', dash: '-', dashed: 'foo-bar', camel: 'fooBar', integer: 0 as any, float: 0.1 as any } })
elm = patch(vnode0, vnode1).elm elm = patch(vnode0, vnode1).elm
assert.strictEqual(elm.dataset.empty, '') assert.strictEqual(elm.dataset.empty, '')

@ -5,22 +5,22 @@ import { init } from '../../package/init'
import { eventListenersModule } from '../../package/modules/eventlisteners' import { eventListenersModule } from '../../package/modules/eventlisteners'
import { h } from '../../package/h' import { h } from '../../package/h'
var patch = init([ const patch = init([
eventListenersModule eventListenersModule
]) ])
describe('event listeners', function () { describe('event listeners', function () {
var elm: any, vnode0: any let elm: any, vnode0: any
beforeEach(function () { beforeEach(function () {
elm = document.createElement('div') elm = document.createElement('div')
vnode0 = elm vnode0 = elm
}) })
it('attaches click event handler to element', function () { it('attaches click event handler to element', function () {
var result = [] const result = []
function clicked (ev: Event) { function clicked (ev: Event) {
result.push(ev) result.push(ev)
} }
var vnode = h('div', { on: { click: clicked } }, [ const vnode = h('div', { on: { click: clicked } }, [
h('a', 'Click my parent'), h('a', 'Click my parent'),
]) ])
elm = patch(vnode0, vnode).elm elm = patch(vnode0, vnode).elm
@ -28,9 +28,9 @@ describe('event listeners', function () {
assert.strictEqual(1, result.length) assert.strictEqual(1, result.length)
}) })
it('does not attach new listener', function () { it('does not attach new listener', function () {
var result: number[] = [] const result: number[] = []
// function clicked(ev) { result.push(ev); } // function clicked(ev) { result.push(ev); }
var vnode1 = h('div', { const vnode1 = h('div', {
on: { on: {
click: function (ev) { click: function (ev) {
result.push(1) result.push(1)
@ -39,7 +39,7 @@ describe('event listeners', function () {
}, [ }, [
h('a', 'Click my parent'), h('a', 'Click my parent'),
]) ])
var vnode2 = h('div', { const vnode2 = h('div', {
on: { on: {
click: function (ev) { click: function (ev) {
result.push(2) result.push(2)
@ -55,17 +55,17 @@ describe('event listeners', function () {
assert.deepEqual(result, [1, 2]) assert.deepEqual(result, [1, 2])
}) })
it('detach attached click event handler to element', function () { it('detach attached click event handler to element', function () {
var result: Event[] = [] const result: Event[] = []
function clicked (ev: Event) { function clicked (ev: Event) {
result.push(ev) result.push(ev)
} }
var vnode1 = h('div', { on: { click: clicked } }, [ const vnode1 = h('div', { on: { click: clicked } }, [
h('a', 'Click my parent'), h('a', 'Click my parent'),
]) ])
elm = patch(vnode0, vnode1).elm elm = patch(vnode0, vnode1).elm
elm.click() elm.click()
assert.strictEqual(1, result.length) assert.strictEqual(1, result.length)
var vnode2 = h('div', { on: {} }, [ const vnode2 = h('div', { on: {} }, [
h('a', 'Click my parent'), h('a', 'Click my parent'),
]) ])
elm = patch(vnode1, vnode2).elm elm = patch(vnode1, vnode2).elm
@ -73,7 +73,7 @@ describe('event listeners', function () {
assert.strictEqual(1, result.length) assert.strictEqual(1, result.length)
}) })
it('multiple event handlers for same event on same element', function () { it('multiple event handlers for same event on same element', function () {
var called = 0 let called = 0
function clicked (ev: Event, vnode: VNode) { function clicked (ev: Event, vnode: VNode) {
++called ++called
// Check that the first argument is an event // Check that the first argument is an event
@ -81,13 +81,13 @@ describe('event listeners', function () {
// Check that the second argument was a vnode // Check that the second argument was a vnode
assert.strictEqual(vnode.sel, 'div') assert.strictEqual(vnode.sel, 'div')
} }
var vnode1 = h('div', { on: { click: [clicked, clicked, clicked] } }, [ const vnode1 = h('div', { on: { click: [clicked, clicked, clicked] } }, [
h('a', 'Click my parent'), h('a', 'Click my parent'),
]) ])
elm = patch(vnode0, vnode1).elm elm = patch(vnode0, vnode1).elm
elm.click() elm.click()
assert.strictEqual(3, called) assert.strictEqual(3, called)
var vnode2 = h('div', { on: { click: [clicked, clicked] } }, [ const vnode2 = h('div', { on: { click: [clicked, clicked] } }, [
h('a', 'Click my parent'), h('a', 'Click my parent'),
]) ])
elm = patch(vnode1, vnode2).elm elm = patch(vnode1, vnode2).elm
@ -95,12 +95,12 @@ describe('event listeners', function () {
assert.strictEqual(5, called) assert.strictEqual(5, called)
}) })
it('access to virtual node in event handler', function () { it('access to virtual node in event handler', function () {
var result: VNode[] = [] const result: VNode[] = []
function clicked (this: VNode, ev: Event, vnode: VNode) { function clicked (this: VNode, ev: Event, vnode: VNode) {
result.push(this) result.push(this)
result.push(vnode) result.push(vnode)
} }
var vnode1 = h('div', { on: { click: clicked } }, [ const vnode1 = h('div', { on: { click: clicked } }, [
h('a', 'Click my parent'), h('a', 'Click my parent'),
]) ])
elm = patch(vnode0, vnode1).elm elm = patch(vnode0, vnode1).elm
@ -110,11 +110,11 @@ describe('event listeners', function () {
assert.strictEqual(vnode1, result[1]) assert.strictEqual(vnode1, result[1])
}) })
it('shared handlers in parent and child nodes', function () { it('shared handlers in parent and child nodes', function () {
var result = [] const result = []
var sharedHandlers = { const sharedHandlers = {
click: function (ev: Event) { result.push(ev) } click: function (ev: Event) { result.push(ev) }
} }
var vnode1 = h('div', { on: sharedHandlers }, [ const vnode1 = h('div', { on: sharedHandlers }, [
h('a', { on: sharedHandlers }, 'Click my parent'), h('a', { on: sharedHandlers }, 'Click my parent'),
]) ])
elm = patch(vnode0, vnode1).elm elm = patch(vnode0, vnode1).elm

@ -4,39 +4,39 @@ import { init } from '../../package/init'
import { h } from '../../package/h' import { h } from '../../package/h'
import { attributesModule } from '../../package/modules/attributes' import { attributesModule } from '../../package/modules/attributes'
var patch = init([ const patch = init([
attributesModule attributesModule
]) ])
describe('svg', function () { describe('svg', function () {
var elm: any, vnode0: any let elm: any, vnode0: any
beforeEach(function () { beforeEach(function () {
elm = document.createElement('svg') elm = document.createElement('svg')
vnode0 = elm vnode0 = elm
}) })
it('removes child svg elements', function () { it('removes child svg elements', function () {
var a = h('svg', {}, [ const a = h('svg', {}, [
h('g'), h('g'),
h('g') h('g')
]) ])
var b = h('svg', {}, [ const b = h('svg', {}, [
h('g') h('g')
]) ])
var result = patch(patch(vnode0, a), b).elm as SVGElement const result = patch(patch(vnode0, a), b).elm as SVGElement
assert.strictEqual(result.childNodes.length, 1) assert.strictEqual(result.childNodes.length, 1)
}) })
it('adds correctly xlink namespaced attribute', function () { it('adds correctly xlink namespaced attribute', function () {
var xlinkNS = 'http://www.w3.org/1999/xlink' const xlinkNS = 'http://www.w3.org/1999/xlink'
var testUrl = '/test' const testUrl = '/test'
var a = h('svg', {}, [ const a = h('svg', {}, [
h('use', { h('use', {
attrs: { 'xlink:href': testUrl } attrs: { 'xlink:href': testUrl }
}, []) }, [])
]) ])
var result = patch(vnode0, a).elm as SVGElement const result = patch(vnode0, a).elm as SVGElement
assert.strictEqual(result.childNodes.length, 1) assert.strictEqual(result.childNodes.length, 1)
const child = result.childNodes[0] as SVGUseElement const child = result.childNodes[0] as SVGUseElement
assert.strictEqual(child.getAttribute('xlink:href'), testUrl) assert.strictEqual(child.getAttribute('xlink:href'), testUrl)
@ -44,11 +44,11 @@ describe('svg', function () {
}) })
it('adds correctly xml namespaced attribute', function () { it('adds correctly xml namespaced attribute', function () {
var xmlNS = 'http://www.w3.org/XML/1998/namespace' const xmlNS = 'http://www.w3.org/XML/1998/namespace'
var testAttrValue = 'und' const testAttrValue = 'und'
var a = h('svg', { attrs: { 'xml:lang': testAttrValue } }, []) const a = h('svg', { attrs: { 'xml:lang': testAttrValue } }, [])
var result = patch(vnode0, a).elm as SVGElement const result = patch(vnode0, a).elm as SVGElement
assert.strictEqual(result.getAttributeNS(xmlNS, 'lang'), testAttrValue) assert.strictEqual(result.getAttributeNS(xmlNS, 'lang'), testAttrValue)
assert.strictEqual(result.getAttribute('xml:lang'), testAttrValue) assert.strictEqual(result.getAttribute('xml:lang'), testAttrValue)
}) })

@ -5,7 +5,7 @@ import { styleModule } from '../../package/modules/style'
import { h } from '../../package/h' import { h } from '../../package/h'
import { toVNode } from '../../package/tovnode' import { toVNode } from '../../package/tovnode'
var patch = init([ const patch = init([
styleModule styleModule
]) ])
@ -14,7 +14,7 @@ featureDiscoveryElm.style.setProperty('--foo', 'foo')
const hasCssVariables = featureDiscoveryElm.style.getPropertyValue('--foo') === 'foo' const hasCssVariables = featureDiscoveryElm.style.getPropertyValue('--foo') === 'foo'
describe('style', function () { describe('style', function () {
var elm: any, vnode0: any let elm: any, vnode0: any
beforeEach(function () { beforeEach(function () {
elm = document.createElement('div') elm = document.createElement('div')
vnode0 = elm vnode0 = elm
@ -24,9 +24,9 @@ describe('style', function () {
assert.strictEqual(elm.style.fontSize, '12px') assert.strictEqual(elm.style.fontSize, '12px')
}) })
it('can be memoized', function () { it('can be memoized', function () {
var cachedStyles = { fontSize: '14px', display: 'inline' } const cachedStyles = { fontSize: '14px', display: 'inline' }
var vnode1 = h('i', { style: cachedStyles }) const vnode1 = h('i', { style: cachedStyles })
var vnode2 = h('i', { style: cachedStyles }) const vnode2 = h('i', { style: cachedStyles })
elm = patch(vnode0, vnode1).elm elm = patch(vnode0, vnode1).elm
assert.strictEqual(elm.style.fontSize, '14px') assert.strictEqual(elm.style.fontSize, '14px')
assert.strictEqual(elm.style.display, 'inline') assert.strictEqual(elm.style.display, 'inline')
@ -35,9 +35,9 @@ describe('style', function () {
assert.strictEqual(elm.style.display, 'inline') assert.strictEqual(elm.style.display, 'inline')
}) })
it('updates styles', function () { it('updates styles', function () {
var vnode1 = h('i', { style: { fontSize: '14px', display: 'inline' } }) const vnode1 = h('i', { style: { fontSize: '14px', display: 'inline' } })
var vnode2 = h('i', { style: { fontSize: '12px', display: 'block' } }) const vnode2 = h('i', { style: { fontSize: '12px', display: 'block' } })
var vnode3 = h('i', { style: { fontSize: '10px', display: 'block' } }) const vnode3 = h('i', { style: { fontSize: '10px', display: 'block' } })
elm = patch(vnode0, vnode1).elm elm = patch(vnode0, vnode1).elm
assert.strictEqual(elm.style.fontSize, '14px') assert.strictEqual(elm.style.fontSize, '14px')
assert.strictEqual(elm.style.display, 'inline') assert.strictEqual(elm.style.display, 'inline')
@ -49,9 +49,9 @@ describe('style', function () {
assert.strictEqual(elm.style.display, 'block') assert.strictEqual(elm.style.display, 'block')
}) })
it('explicialy removes styles', function () { it('explicialy removes styles', function () {
var vnode1 = h('i', { style: { fontSize: '14px' } }) const vnode1 = h('i', { style: { fontSize: '14px' } })
var vnode2 = h('i', { style: { fontSize: '' } }) const vnode2 = h('i', { style: { fontSize: '' } })
var vnode3 = h('i', { style: { fontSize: '10px' } }) const vnode3 = h('i', { style: { fontSize: '10px' } })
elm = patch(vnode0, vnode1).elm elm = patch(vnode0, vnode1).elm
assert.strictEqual(elm.style.fontSize, '14px') assert.strictEqual(elm.style.fontSize, '14px')
patch(vnode1, vnode2) patch(vnode1, vnode2)
@ -60,9 +60,9 @@ describe('style', function () {
assert.strictEqual(elm.style.fontSize, '10px') assert.strictEqual(elm.style.fontSize, '10px')
}) })
it('implicially removes styles from element', function () { it('implicially removes styles from element', function () {
var vnode1 = h('div', [h('i', { style: { fontSize: '14px' } })]) const vnode1 = h('div', [h('i', { style: { fontSize: '14px' } })])
var vnode2 = h('div', [h('i')]) const vnode2 = h('div', [h('i')])
var vnode3 = h('div', [h('i', { style: { fontSize: '10px' } })]) const vnode3 = h('div', [h('i', { style: { fontSize: '10px' } })])
patch(vnode0, vnode1) patch(vnode0, vnode1)
assert.strictEqual(elm.firstChild.style.fontSize, '14px') assert.strictEqual(elm.firstChild.style.fontSize, '14px')
patch(vnode1, vnode2) patch(vnode1, vnode2)
@ -74,9 +74,9 @@ describe('style', function () {
if (!hasCssVariables) { if (!hasCssVariables) {
this.skip() this.skip()
} else { } else {
var vnode1 = h('div', { style: { '--myVar': 1 as any } }) const vnode1 = h('div', { style: { '--myVar': 1 as any } })
var vnode2 = h('div', { style: { '--myVar': 2 as any } }) const vnode2 = h('div', { style: { '--myVar': 2 as any } })
var vnode3 = h('div', { style: { '--myVar': 3 as any } }) const vnode3 = h('div', { style: { '--myVar': 3 as any } })
elm = patch(vnode0, vnode1).elm elm = patch(vnode0, vnode1).elm
assert.strictEqual(elm.style.getPropertyValue('--myVar'), '1') assert.strictEqual(elm.style.getPropertyValue('--myVar'), '1')
elm = patch(vnode1, vnode2).elm elm = patch(vnode1, vnode2).elm
@ -89,9 +89,9 @@ describe('style', function () {
if (!hasCssVariables) { if (!hasCssVariables) {
this.skip() this.skip()
} else { } else {
var vnode1 = h('i', { style: { '--myVar': 1 as any } }) const vnode1 = h('i', { style: { '--myVar': 1 as any } })
var vnode2 = h('i', { style: { '--myVar': '' } }) const vnode2 = h('i', { style: { '--myVar': '' } })
var vnode3 = h('i', { style: { '--myVar': 2 as any } }) const vnode3 = h('i', { style: { '--myVar': 2 as any } })
elm = patch(vnode0, vnode1).elm elm = patch(vnode0, vnode1).elm
assert.strictEqual(elm.style.getPropertyValue('--myVar'), '1') assert.strictEqual(elm.style.getPropertyValue('--myVar'), '1')
patch(vnode1, vnode2) patch(vnode1, vnode2)
@ -104,9 +104,9 @@ describe('style', function () {
if (!hasCssVariables) { if (!hasCssVariables) {
this.skip() this.skip()
} else { } else {
var vnode1 = h('div', [h('i', { style: { '--myVar': 1 as any } })]) const vnode1 = h('div', [h('i', { style: { '--myVar': 1 as any } })])
var vnode2 = h('div', [h('i')]) const vnode2 = h('div', [h('i')])
var vnode3 = h('div', [h('i', { style: { '--myVar': 2 as any } })]) const vnode3 = h('div', [h('i', { style: { '--myVar': 2 as any } })])
patch(vnode0, vnode1) patch(vnode0, vnode1)
assert.strictEqual(elm.firstChild.style.getPropertyValue('--myVar'), '1') assert.strictEqual(elm.firstChild.style.getPropertyValue('--myVar'), '1')
patch(vnode1, vnode2) patch(vnode1, vnode2)
@ -116,8 +116,8 @@ describe('style', function () {
} }
}) })
it('updates delayed styles in next frame', function (done) { it('updates delayed styles in next frame', function (done) {
var vnode1 = h('i', { style: { fontSize: '14px', delayed: { fontSize: '16px' } as any } }) const vnode1 = h('i', { style: { fontSize: '14px', delayed: { fontSize: '16px' } as any } })
var vnode2 = h('i', { style: { fontSize: '18px', delayed: { fontSize: '20px' } as any } }) const vnode2 = h('i', { style: { fontSize: '18px', delayed: { fontSize: '20px' } as any } })
elm = patch(vnode0, vnode1).elm elm = patch(vnode0, vnode1).elm
assert.strictEqual(elm.style.fontSize, '14px') assert.strictEqual(elm.style.fontSize, '14px')
requestAnimationFrame(() => { requestAnimationFrame(() => {
@ -135,14 +135,14 @@ describe('style', function () {
}) })
}) })
it('applies tranform as transition on remove', function (done) { it('applies tranform as transition on remove', function (done) {
var btn = h('button', { const btn = h('button', {
style: { style: {
transition: 'transform 0.1s', transition: 'transform 0.1s',
remove: { transform: 'translateY(100%)' } as any remove: { transform: 'translateY(100%)' } as any
} }
}, ['A button']) }, ['A button'])
var vnode1 = h('div.parent', {}, [btn]) const vnode1 = h('div.parent', {}, [btn])
var vnode2 = h('div.parent', {}, [null]) const vnode2 = h('div.parent', {}, [null])
document.body.appendChild(vnode0) document.body.appendChild(vnode0)
patch(vnode0, vnode1) patch(vnode0, vnode1)
patch(vnode1, vnode2) patch(vnode1, vnode2)
@ -155,10 +155,10 @@ describe('style', function () {
}) })
describe('using toVNode()', function () { describe('using toVNode()', function () {
it('handles (ignoring) comment nodes', function () { it('handles (ignoring) comment nodes', function () {
var comment = document.createComment('yolo') const comment = document.createComment('yolo')
var prevElm = document.createElement('div') const prevElm = document.createElement('div')
prevElm.appendChild(comment) prevElm.appendChild(comment)
var nextVNode = h('div', [h('span', 'Hi')]) const nextVNode = h('div', [h('span', 'Hi')])
elm = patch(toVNode(prevElm), nextVNode).elm elm = patch(toVNode(prevElm), nextVNode).elm
assert.strictEqual(elm, prevElm) assert.strictEqual(elm, prevElm)
assert.strictEqual(elm.tagName, 'DIV') assert.strictEqual(elm.tagName, 'DIV')

@ -5,11 +5,11 @@ import { h } from '../../package/h'
import { thunk } from '../../package/thunk' import { thunk } from '../../package/thunk'
import { VNode } from '../../package/vnode' import { VNode } from '../../package/vnode'
var patch = init([ const patch = init([
]) ])
describe('thunk', function () { describe('thunk', function () {
var elm: any, vnode0: any let elm: any, vnode0: any
beforeEach(function () { beforeEach(function () {
elm = vnode0 = document.createElement('div') elm = vnode0 = document.createElement('div')
}) })
@ -17,21 +17,21 @@ describe('thunk', function () {
function numberInSpan (n: number) { function numberInSpan (n: number) {
return h('span', 'Number is ' + n) return h('span', 'Number is ' + n)
} }
var vnode = thunk('span', 'num', numberInSpan, [22]) const vnode = thunk('span', 'num', numberInSpan, [22])
assert.deepEqual(vnode.sel, 'span') assert.deepEqual(vnode.sel, 'span')
assert.deepEqual(vnode.data.key, 'num') assert.deepEqual(vnode.data.key, 'num')
assert.deepEqual(vnode.data.args, [22]) assert.deepEqual(vnode.data.args, [22])
}) })
it('calls render function once on data change', function () { it('calls render function once on data change', function () {
var called = 0 let called = 0
function numberInSpan (n: number) { function numberInSpan (n: number) {
called++ called++
return h('span', { key: 'num' }, 'Number is ' + n) return h('span', { key: 'num' }, 'Number is ' + n)
} }
var vnode1 = h('div', [ const vnode1 = h('div', [
thunk('span', 'num', numberInSpan, [1]) thunk('span', 'num', numberInSpan, [1])
]) ])
var vnode2 = h('div', [ const vnode2 = h('div', [
thunk('span', 'num', numberInSpan, [2]) thunk('span', 'num', numberInSpan, [2])
]) ])
patch(vnode0, vnode1) patch(vnode0, vnode1)
@ -40,15 +40,15 @@ describe('thunk', function () {
assert.strictEqual(called, 2) assert.strictEqual(called, 2)
}) })
it('does not call render function on data unchanged', function () { it('does not call render function on data unchanged', function () {
var called = 0 let called = 0
function numberInSpan (n: number) { function numberInSpan (n: number) {
called++ called++
return h('span', { key: 'num' }, 'Number is ' + n) return h('span', { key: 'num' }, 'Number is ' + n)
} }
var vnode1 = h('div', [ const vnode1 = h('div', [
thunk('span', 'num', numberInSpan, [1]) thunk('span', 'num', numberInSpan, [1])
]) ])
var vnode2 = h('div', [ const vnode2 = h('div', [
thunk('span', 'num', numberInSpan, [1]) thunk('span', 'num', numberInSpan, [1])
]) ])
patch(vnode0, vnode1) patch(vnode0, vnode1)
@ -57,15 +57,15 @@ describe('thunk', function () {
assert.strictEqual(called, 1) assert.strictEqual(called, 1)
}) })
it('calls render function once on data-length change', function () { it('calls render function once on data-length change', function () {
var called = 0 let called = 0
function numberInSpan (n: number) { function numberInSpan (n: number) {
called++ called++
return h('span', { key: 'num' }, 'Number is ' + n) return h('span', { key: 'num' }, 'Number is ' + n)
} }
var vnode1 = h('div', [ const vnode1 = h('div', [
thunk('span', 'num', numberInSpan, [1]) thunk('span', 'num', numberInSpan, [1])
]) ])
var vnode2 = h('div', [ const vnode2 = h('div', [
thunk('span', 'num', numberInSpan, [1, 2]) thunk('span', 'num', numberInSpan, [1, 2])
]) ])
patch(vnode0, vnode1) patch(vnode0, vnode1)
@ -74,7 +74,7 @@ describe('thunk', function () {
assert.strictEqual(called, 2) assert.strictEqual(called, 2)
}) })
it('calls render function once on function change', function () { it('calls render function once on function change', function () {
var called = 0 let called = 0
function numberInSpan (n: number) { function numberInSpan (n: number) {
called++ called++
return h('span', { key: 'num' }, 'Number is ' + n) return h('span', { key: 'num' }, 'Number is ' + n)
@ -83,10 +83,10 @@ describe('thunk', function () {
called++ called++
return h('span', { key: 'num' }, 'Number really is ' + n) return h('span', { key: 'num' }, 'Number really is ' + n)
} }
var vnode1 = h('div', [ const vnode1 = h('div', [
thunk('span', 'num', numberInSpan, [1]) thunk('span', 'num', numberInSpan, [1])
]) ])
var vnode2 = h('div', [ const vnode2 = h('div', [
thunk('span', 'num', numberInSpan2, [1]) thunk('span', 'num', numberInSpan2, [1])
]) ])
patch(vnode0, vnode1) patch(vnode0, vnode1)
@ -95,18 +95,18 @@ describe('thunk', function () {
assert.strictEqual(called, 2) assert.strictEqual(called, 2)
}) })
it('renders correctly', function () { it('renders correctly', function () {
var called = 0 let called = 0
function numberInSpan (n: number) { function numberInSpan (n: number) {
called++ called++
return h('span', { key: 'num' }, 'Number is ' + n) return h('span', { key: 'num' }, 'Number is ' + n)
} }
var vnode1 = h('div', [ const vnode1 = h('div', [
thunk('span', 'num', numberInSpan, [1]) thunk('span', 'num', numberInSpan, [1])
]) ])
var vnode2 = h('div', [ const vnode2 = h('div', [
thunk('span', 'num', numberInSpan, [1]) thunk('span', 'num', numberInSpan, [1])
]) ])
var vnode3 = h('div', [ const vnode3 = h('div', [
thunk('span', 'num', numberInSpan, [2]) thunk('span', 'num', numberInSpan, [2])
]) ])
elm = patch(vnode0, vnode1).elm elm = patch(vnode0, vnode1).elm
@ -124,19 +124,19 @@ describe('thunk', function () {
function vnodeFn (s: string) { function vnodeFn (s: string) {
return h('span.number', 'Hello ' + s) return h('span.number', 'Hello ' + s)
} }
var vnode1 = thunk('span.number', vnodeFn, ['World!']) const vnode1 = thunk('span.number', vnodeFn, ['World!'])
elm = patch(vnode0, vnode1).elm elm = patch(vnode0, vnode1).elm
assert.strictEqual(elm.innerText, 'Hello World!') assert.strictEqual(elm.innerText, 'Hello World!')
}) })
it('renders correctly when root', function () { it('renders correctly when root', function () {
var called = 0 let called = 0
function numberInSpan (n: number) { function numberInSpan (n: number) {
called++ called++
return h('span', { key: 'num' }, 'Number is ' + n) return h('span', { key: 'num' }, 'Number is ' + n)
} }
var vnode1 = thunk('span', 'num', numberInSpan, [1]) const vnode1 = thunk('span', 'num', numberInSpan, [1])
var vnode2 = thunk('span', 'num', numberInSpan, [1]) const vnode2 = thunk('span', 'num', numberInSpan, [1])
var vnode3 = thunk('span', 'num', numberInSpan, [2]) const vnode3 = thunk('span', 'num', numberInSpan, [2])
elm = patch(vnode0, vnode1).elm elm = patch(vnode0, vnode1).elm
assert.strictEqual(elm.tagName.toLowerCase(), 'span') assert.strictEqual(elm.tagName.toLowerCase(), 'span')
@ -156,11 +156,11 @@ describe('thunk', function () {
return h('span', { key: 'num' }, 'Number is ' + n) return h('span', { key: 'num' }, 'Number is ' + n)
} }
function oddEven (n: number): VNode { function oddEven (n: number): VNode {
var prefix = (n % 2) === 0 ? 'Even' : 'Odd' const prefix = (n % 2) === 0 ? 'Even' : 'Odd'
return h('div', { key: oddEven as any }, prefix + ': ' + n) return h('div', { key: oddEven as any }, prefix + ': ' + n)
} }
var vnode1 = h('div', [thunk('span', 'num', numberInSpan, [1])]) const vnode1 = h('div', [thunk('span', 'num', numberInSpan, [1])])
var vnode2 = h('div', [thunk('div', 'oddEven', oddEven, [4])]) const vnode2 = h('div', [thunk('div', 'oddEven', oddEven, [4])])
elm = patch(vnode0, vnode1).elm elm = patch(vnode0, vnode1).elm
assert.strictEqual(elm.firstChild.tagName.toLowerCase(), 'span') assert.strictEqual(elm.firstChild.tagName.toLowerCase(), 'span')
@ -175,11 +175,11 @@ describe('thunk', function () {
return h('span', { key: 'num' }, 'Number is ' + n) return h('span', { key: 'num' }, 'Number is ' + n)
} }
function oddEven (n: number): VNode { function oddEven (n: number): VNode {
var prefix = (n % 2) === 0 ? 'Even' : 'Odd' const prefix = (n % 2) === 0 ? 'Even' : 'Odd'
return h('div', { key: oddEven as any }, prefix + ': ' + n) return h('div', { key: oddEven as any }, prefix + ': ' + n)
} }
var vnode1 = thunk('span', 'num', numberInSpan, [1]) const vnode1 = thunk('span', 'num', numberInSpan, [1])
var vnode2 = thunk('div', 'oddEven', oddEven, [4]) const vnode2 = thunk('div', 'oddEven', oddEven, [4])
elm = patch(vnode0, vnode1).elm elm = patch(vnode0, vnode1).elm
assert.strictEqual(elm.tagName.toLowerCase(), 'span') assert.strictEqual(elm.tagName.toLowerCase(), 'span')
@ -190,19 +190,19 @@ describe('thunk', function () {
assert.strictEqual(elm.innerHTML, 'Even: 4') assert.strictEqual(elm.innerHTML, 'Even: 4')
}) })
it('invokes destroy hook on thunks', function () { it('invokes destroy hook on thunks', function () {
var called = 0 let called = 0
function destroyHook () { function destroyHook () {
called++ called++
} }
function numberInSpan (n: number) { function numberInSpan (n: number) {
return h('span', { key: 'num', hook: { destroy: destroyHook } }, 'Number is ' + n) return h('span', { key: 'num', hook: { destroy: destroyHook } }, 'Number is ' + n)
} }
var vnode1 = h('div', [ const vnode1 = h('div', [
h('div', 'Foo'), h('div', 'Foo'),
thunk('span', 'num', numberInSpan, [1]), thunk('span', 'num', numberInSpan, [1]),
h('div', 'Foo') h('div', 'Foo')
]) ])
var vnode2 = h('div', [ const vnode2 = h('div', [
h('div', 'Foo'), h('div', 'Foo'),
h('div', 'Foo') h('div', 'Foo')
]) ])
@ -211,19 +211,19 @@ describe('thunk', function () {
assert.strictEqual(called, 1) assert.strictEqual(called, 1)
}) })
it('invokes remove hook on thunks', function () { it('invokes remove hook on thunks', function () {
var called = 0 let called = 0
function hook () { function hook () {
called++ called++
} }
function numberInSpan (n: number) { function numberInSpan (n: number) {
return h('span', { key: 'num', hook: { remove: hook } }, 'Number is ' + n) return h('span', { key: 'num', hook: { remove: hook } }, 'Number is ' + n)
} }
var vnode1 = h('div', [ const vnode1 = h('div', [
h('div', 'Foo'), h('div', 'Foo'),
thunk('span', 'num', numberInSpan, [1]), thunk('span', 'num', numberInSpan, [1]),
h('div', 'Foo') h('div', 'Foo')
]) ])
var vnode2 = h('div', [ const vnode2 = h('div', [
h('div', 'Foo'), h('div', 'Foo'),
h('div', 'Foo') h('div', 'Foo')
]) ])

Loading…
Cancel
Save