Merge pull request #557 from snabbdom/one-var

style: enable eslint rule one-var
pull/559/head
Simon Friis Vindum 5 years ago committed by GitHub
commit 5c63f59a1b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -22,7 +22,6 @@ module.exports = {
'no-unneeded-ternary': 'off', 'no-unneeded-ternary': 'off',
'no-unused-expressions': 'off', 'no-unused-expressions': 'off',
'no-unused-vars': 'off', 'no-unused-vars': 'off',
'one-var': 'off',
'prefer-const': 'off', 'prefer-const': 'off',
eqeqeq: 'off', eqeqeq: 'off',
semi: 'off' semi: 'off'

@ -23,7 +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 = {}, children: any, text: any, i: number; var data: VNodeData = {};
var children: any;
var text: any;
var i: number;
if (c !== undefined) { if (c !== undefined) {
if (b !== null) { if (b !== null) {
data = b; data = b;

@ -39,7 +39,8 @@ function destroy (vnode: VNodeWithAttachData): void {
} }
function create (_: any, vnode: VNodeWithAttachData): void { function create (_: any, vnode: VNodeWithAttachData): void {
const real = vnode.elm, attachData = vnode.data.attachData; const real = vnode.elm;
const attachData = vnode.data.attachData;
const placeholder = document.createElement('span'); const placeholder = document.createElement('span');
// Replace actual element with dummy placeholder // Replace actual element with dummy placeholder
// Snabbdom will then insert placeholder instead // Snabbdom will then insert placeholder instead

@ -17,9 +17,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, elm: Element = vnode.elm as Element, var key: string;
oldAttrs = (oldVnode.data as VNodeData).attrs, var elm: Element = vnode.elm as Element;
attrs = (vnode.data as VNodeData).attrs; var oldAttrs = (oldVnode.data as VNodeData).attrs;
var attrs = (vnode.data as VNodeData).attrs;
if (!oldAttrs && !attrs) return; if (!oldAttrs && !attrs) return;
if (oldAttrs === attrs) return; if (oldAttrs === attrs) return;

@ -4,9 +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, name: string, elm: Element = vnode.elm as Element, var cur: any;
oldClass = (oldVnode.data as VNodeData).class, var name: string;
klass = (vnode.data as VNodeData).class; var elm: Element = vnode.elm as Element;
var oldClass = (oldVnode.data as VNodeData).class;
var klass = (vnode.data as VNodeData).class;
if (!oldClass && !klass) return; if (!oldClass && !klass) return;
if (oldClass === klass) return; if (oldClass === klass) return;

@ -6,10 +6,10 @@ export type Dataset = Record<string, string>;
const CAPS_REGEX = /[A-Z]/g; const CAPS_REGEX = /[A-Z]/g;
function updateDataset (oldVnode: VNode, vnode: VNode): void { function updateDataset (oldVnode: VNode, vnode: VNode): void {
let elm: HTMLElement = vnode.elm as HTMLElement, let elm: HTMLElement = vnode.elm as HTMLElement;
oldDataset = (oldVnode.data as VNodeData).dataset, let oldDataset = (oldVnode.data as VNodeData).dataset;
dataset = (vnode.data as VNodeData).dataset, let dataset = (vnode.data as VNodeData).dataset;
key: string; let key: string;
if (!oldDataset && !dataset) return; if (!oldDataset && !dataset) return;
if (oldDataset === dataset) return; if (oldDataset === dataset) return;

@ -33,8 +33,8 @@ function invokeHandler (handler: any, vnode?: VNode, event?: Event): void {
} }
function handleEvent (event: Event, vnode: VNode) { function handleEvent (event: Event, vnode: VNode) {
var name = event.type, var name = event.type;
on = (vnode.data as VNodeData).on; var 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]) {
@ -49,12 +49,12 @@ function createListener () {
} }
function updateEventListeners (oldVnode: VNode, vnode?: VNode): void { function updateEventListeners (oldVnode: VNode, vnode?: VNode): void {
var oldOn = (oldVnode.data as VNodeData).on, var oldOn = (oldVnode.data as VNodeData).on;
oldListener = (oldVnode as any).listener, var oldListener = (oldVnode as any).listener;
oldElm: Element = oldVnode.elm as Element, var oldElm: Element = oldVnode.elm as Element;
on = vnode && (vnode.data as VNodeData).on, var on = vnode && (vnode.data as VNodeData).on;
elm: Element = (vnode && vnode.elm) as Element, var elm: Element = (vnode && vnode.elm) as Element;
name: string; var name: string;
// optimization for reused immutable handlers // optimization for reused immutable handlers
if (oldOn === on) { if (oldOn === on) {

@ -4,9 +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, cur: any, old: any, elm = vnode.elm, var key: string;
oldProps = (oldVnode.data as VNodeData).props, var cur: any;
props = (vnode.data as VNodeData).props; var old: any;
var elm = vnode.elm;
var oldProps = (oldVnode.data as VNodeData).props;
var props = (vnode.data as VNodeData).props;
if (!oldProps && !props) return; if (!oldProps && !props) return;
if (oldProps === props) return; if (oldProps === props) return;

@ -22,9 +22,11 @@ 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, name: string, elm = vnode.elm, var cur: any;
oldStyle = (oldVnode.data as VNodeData).style, var name: string;
style = (vnode.data as VNodeData).style; var elm = vnode.elm;
var oldStyle = (oldVnode.data as VNodeData).style;
var style = (vnode.data as VNodeData).style;
if (!oldStyle && !style) return; if (!oldStyle && !style) return;
if (oldStyle === style) return; if (oldStyle === style) return;
@ -61,7 +63,10 @@ function updateStyle (oldVnode: VNode, vnode: VNode): void {
} }
function applyDestroyStyle (vnode: VNode): void { function applyDestroyStyle (vnode: VNode): void {
var style: any, name: string, elm = vnode.elm, s = (vnode.data as VNodeData).style; var style: any;
var name: string;
var elm = vnode.elm;
var 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];
@ -78,8 +83,13 @@ function applyRemoveStyle (vnode: VNode, rm: () => void): void {
(vnode.elm as any).offsetLeft; (vnode.elm as any).offsetLeft;
reflowForced = true; reflowForced = true;
} }
var name: string, elm = vnode.elm, i = 0, compStyle: CSSStyleDeclaration, var name: string;
style = s.remove, amount = 0, applied: string[] = []; var elm = vnode.elm;
var i = 0;
var compStyle: CSSStyleDeclaration;
var style = s.remove;
var amount = 0;
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];

@ -50,7 +50,9 @@ export { h } from './h';
export { thunk } from './thunk'; export { thunk } from './thunk';
export function init (modules: Array<Partial<Module>>, domApi?: DOMAPI) { export function init (modules: Array<Partial<Module>>, domApi?: DOMAPI) {
let i: number, j: number, cbs = ({} as ModuleHooks); let i: number;
let j: number;
let cbs = ({} as ModuleHooks);
const api: DOMAPI = domApi !== undefined ? domApi : htmlDomApi; const api: DOMAPI = domApi !== undefined ? domApi : htmlDomApi;
@ -80,7 +82,8 @@ export function init (modules: Array<Partial<Module>>, domApi?: DOMAPI) {
} }
function createElm (vnode: VNode, insertedVnodeQueue: VNodeQueue): Node { function createElm (vnode: VNode, insertedVnodeQueue: VNodeQueue): Node {
let i: any, data = vnode.data; let i: any;
let data = vnode.data;
if (data !== undefined) { if (data !== undefined) {
const init = data.hook?.init; const init = data.hook?.init;
if (isDef(init)) { if (isDef(init)) {
@ -88,7 +91,8 @@ export function init (modules: Array<Partial<Module>>, domApi?: DOMAPI) {
data = vnode.data; data = vnode.data;
} }
} }
let children = vnode.children, sel = vnode.sel; let children = vnode.children;
let sel = vnode.sel;
if (sel === '!') { if (sel === '!') {
if (isUndef(vnode.text)) { if (isUndef(vnode.text)) {
vnode.text = ''; vnode.text = '';
@ -167,7 +171,9 @@ export function init (modules: Array<Partial<Module>>, domApi?: DOMAPI) {
startIdx: number, startIdx: number,
endIdx: number): void { endIdx: number): void {
for (; startIdx <= endIdx; ++startIdx) { for (; startIdx <= endIdx; ++startIdx) {
let listeners: number, rm: () => void, ch = vnodes[startIdx]; let listeners: number;
let rm: () => void;
let ch = vnodes[startIdx];
if (ch != null) { if (ch != null) {
if (isDef(ch.sel)) { if (isDef(ch.sel)) {
invokeDestroyHook(ch); invokeDestroyHook(ch);
@ -191,7 +197,8 @@ export function init (modules: Array<Partial<Module>>, domApi?: DOMAPI) {
oldCh: VNode[], oldCh: VNode[],
newCh: VNode[], newCh: VNode[],
insertedVnodeQueue: VNodeQueue) { insertedVnodeQueue: VNodeQueue) {
let oldStartIdx = 0, newStartIdx = 0; let oldStartIdx = 0;
let newStartIdx = 0;
let oldEndIdx = oldCh.length - 1; let oldEndIdx = oldCh.length - 1;
let oldStartVnode = oldCh[0]; let oldStartVnode = oldCh[0];
let oldEndVnode = oldCh[oldEndIdx]; let oldEndVnode = oldCh[oldEndIdx];

@ -608,7 +608,12 @@ describe('snabbdom', function () {
assert.deepEqual(map(inner, elm.children), ['4', '3', '2', '1', '5', '0']); assert.deepEqual(map(inner, elm.children), ['4', '3', '2', '1', '5', '0']);
}); });
it('handles random shuffles', function () { it('handles random shuffles', function () {
var n, i, arr = [], opacities: string[] = [], elms = 14, samples = 5; var n;
var i;
var arr = [];
var opacities: string[] = [];
var elms = 14;
var samples = 5;
function spanNumWithOpacity (n: number, o: string) { function spanNumWithOpacity (n: number, o: string) {
return h('span', { key: n, style: { opacity: o } }, n.toString()); return h('span', { key: n, style: { opacity: o } }, n.toString());
} }
@ -656,7 +661,15 @@ describe('snabbdom', function () {
assert.deepEqual(map(inner, elm.children), ['5', '4', '3', '2', '1', '0']); assert.deepEqual(map(inner, elm.children), ['5', '4', '3', '2', '1', '0']);
}); });
it('handles random shuffles with null/undefined children', function () { it('handles random shuffles with null/undefined children', function () {
var i, j, r, len, arr, maxArrLen = 15, samples = 5, vnode1 = vnode0, vnode2; var i;
var j;
var r;
var len;
var arr;
var maxArrLen = 15;
var samples = 5;
var vnode1 = vnode0;
var vnode2;
for (i = 0; i < samples; ++i, vnode1 = vnode2) { for (i = 0; i < samples; ++i, vnode1 = vnode2) {
len = Math.floor(Math.random() * maxArrLen); len = Math.floor(Math.random() * maxArrLen);
arr = []; arr = [];
@ -872,7 +885,8 @@ describe('snabbdom', function () {
assert.strictEqual(result.length, 1); assert.strictEqual(result.length, 1);
}); });
it('calls `postpatch` after `prepatch` listener', function () { it('calls `postpatch` after `prepatch` listener', function () {
var pre = 0, post = 0; var pre = 0;
var post = 0;
function preCb () { function preCb () {
pre++ pre++
} }

@ -32,8 +32,11 @@ function init (thunk: VNode): void {
} }
function prepatch (oldVnode: VNode, thunk: VNode): void { function prepatch (oldVnode: VNode, thunk: VNode): void {
let i: number, old = oldVnode.data as VNodeData, cur = thunk.data as VNodeData; let i: number;
const oldArgs = old.args, args = cur.args; let old = oldVnode.data as VNodeData;
let cur = thunk.data as VNodeData;
const oldArgs = old.args;
const args = cur.args;
if (old.fn !== cur.fn || (oldArgs as any).length !== (args as any).length) { if (old.fn !== cur.fn || (oldArgs as any).length !== (args as any).length) {
copyToThunk((cur.fn as any).apply(undefined, args), thunk); copyToThunk((cur.fn as any).apply(undefined, args), thunk);
return; return;

Loading…
Cancel
Save