diff --git a/.eslintignore b/.eslintignore index 1b9fe34c..08396583 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,11 +1,6 @@ -coverage .vscode -examples -docs -node_modules -tests -test-utils -ospec -mithril.js -mithril.min.js -archive +/node_modules +/examples +/docs/lib +/mithril.js +/mithril.min.js diff --git a/.eslintrc.js b/.eslintrc.js index 25278201..35fbbef6 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -188,7 +188,7 @@ module.exports = { "quotes": [ "error", "double", - "avoid-escape" + {"avoidEscape": true} ], "radix": [ "error", @@ -209,7 +209,7 @@ module.exports = { "space-infix-ops": "off", "space-unary-ops": "error", "spaced-comment": "off", - "strict": "off", + "strict": ["error", "global"], "template-curly-spacing": "error", "valid-jsdoc": "off", "vars-on-top": "off", @@ -218,4 +218,4 @@ module.exports = { "yield-star-spacing": "error", "yoda": "off" } -}; \ No newline at end of file +}; diff --git a/.gitignore b/.gitignore index 8af32a76..285af458 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ jsconfig.json npm-debug.log .vscode .DS_Store +.eslintcache diff --git a/api/tests/test-mount.js b/api/tests/test-mount.js index 4ba466c7..db2bee04 100644 --- a/api/tests/test-mount.js +++ b/api/tests/test-mount.js @@ -71,8 +71,8 @@ o.spec("mount", function() { o("redraws on events", function(done) { var onupdate = o.spy() - var oninit = o.spy() - var onclick = o.spy() + var oninit = o.spy() + var onclick = o.spy() var e = $window.document.createEvent("MouseEvents") e.initEvent("click", true, true) @@ -107,13 +107,13 @@ o.spec("mount", function() { o("redraws several mount points on events", function(done, timeout) { timeout(60) - + var onupdate0 = o.spy() - var oninit0 = o.spy() - var onclick0 = o.spy() + var oninit0 = o.spy() + var onclick0 = o.spy() var onupdate1 = o.spy() - var oninit1 = o.spy() - var onclick1 = o.spy() + var oninit1 = o.spy() + var onclick1 = o.spy() var e = $window.document.createEvent("MouseEvents") @@ -228,7 +228,7 @@ o.spec("mount", function() { done() }, FRAME_BUDGET) }) - + o("throttles", function(done, timeout) { timeout(200) @@ -252,4 +252,4 @@ o.spec("mount", function() { }) }) }) -}) \ No newline at end of file +}) diff --git a/api/tests/test-router.js b/api/tests/test-router.js index f43605e1..3fcfbae7 100644 --- a/api/tests/test-router.js +++ b/api/tests/test-router.js @@ -6,7 +6,6 @@ var browserMock = require("../../test-utils/browserMock") var m = require("../../render/hyperscript") var callAsync = require("../../test-utils/callAsync") -var coreRenderer = require("../../render/render") var apiRedraw = require("../../api/redraw") var apiRouter = require("../../api/router") var Promise = require("../../promise/promise") @@ -31,7 +30,7 @@ o.spec("route", function() { o("throws on invalid `root` DOM node", function() { var threw = false try { - route(null, '/', {'/':{view: function() {}}}) + route(null, "/", {"/":{view: function() {}}}) } catch (e) { threw = true } @@ -141,7 +140,7 @@ o.spec("route", function() { done() } }) - + o("redraws when render function is executed", function() { var onupdate = o.spy() var oninit = o.spy() @@ -206,7 +205,6 @@ o.spec("route", function() { o("event handlers can skip redraw", function(done) { var onupdate = o.spy() var oninit = o.spy() - var onclick = o.spy() var e = $window.document.createEvent("MouseEvents") e.initEvent("click", true, true) @@ -354,11 +352,6 @@ o.spec("route", function() { o("accepts RouteResolver with onmatch that returns Promise", function(done) { var matchCount = 0 var renderCount = 0 - var Component = { - view: function() { - return m("span") - } - } var resolver = { onmatch: function(args, requestedPath) { @@ -395,11 +388,6 @@ o.spec("route", function() { o("accepts RouteResolver with onmatch that returns Promise", function(done) { var matchCount = 0 var renderCount = 0 - var Component = { - view: function() { - return m("span") - } - } var resolver = { onmatch: function(args, requestedPath) { @@ -437,14 +425,9 @@ o.spec("route", function() { var matchCount = 0 var renderCount = 0 var spy = o.spy() - var Component = { - view: function() { - return m("span") - } - } var resolver = { - onmatch: function(args, requestedPath) { + onmatch: function() { matchCount++ return Promise.reject(new Error("error")) }, @@ -499,7 +482,7 @@ o.spec("route", function() { }) }) - o("changing `vnode.key` in `render` resets the component", function(done, timeout){ + o("changing `vnode.key` in `render` resets the component", function(done){ var oninit = o.spy() var Component = { oninit: oninit, @@ -548,22 +531,15 @@ o.spec("route", function() { }) o("RouteResolver `render` does not have component semantics", function(done) { - var renderCount = 0 - var A = { - view: function() { - return m("div") - } - } - $window.location.href = prefix + "/a" route(root, "/a", { "/a" : { - render: function(vnode) { + render: function() { return m("div") }, }, "/b" : { - render: function(vnode) { + render: function() { return m("div") }, }, @@ -632,7 +608,7 @@ o.spec("route", function() { onmatch: function() { matchCount++ }, - render: function(vnode) { + render: function() { renderCount++ return {tag: Component} }, @@ -726,7 +702,7 @@ o.spec("route", function() { render: render }, "/b" : { - render: function(vnode){ + render: function(){ redirected = true } } @@ -838,7 +814,7 @@ o.spec("route", function() { }) callAsync(function() { - route.set('/b') + route.set("/b") callAsync(function() { callAsync(function() { callAsync(function() { @@ -865,7 +841,7 @@ o.spec("route", function() { render: render }, "/b" : { - onmatch: function(vnode){ + onmatch: function(){ redirected = true return {view: function() {}} } @@ -895,7 +871,7 @@ o.spec("route", function() { render: render }, "/b" : { - render: function(vnode){ + render: function(){ redirected = true } } @@ -924,7 +900,7 @@ o.spec("route", function() { render: render }, "/b" : { - view: function(vnode){ + view: function(){ redirected = true } } @@ -1032,7 +1008,7 @@ o.spec("route", function() { var render = o.spy(function() {return m("div")}) $window.location.href = prefix + "/" - route(root, '/', { + route(root, "/", { "/": { onmatch: onmatch, render: render @@ -1081,23 +1057,23 @@ o.spec("route", function() { o("routing with RouteResolver works more than once", function(done) { $window.location.href = prefix + "/a" - route(root, '/a', { - '/a': { + route(root, "/a", { + "/a": { render: function() { return m("a", "a") } }, - '/b': { + "/b": { render: function() { return m("b", "b") } } }) - route.set('/b') + route.set("/b") callAsync(function() { - route.set('/a') + route.set("/a") callAsync(function() { o(root.firstChild.nodeName).equals("A") @@ -1122,7 +1098,7 @@ o.spec("route", function() { }) }) }, - render: function(vnode) { + render: function() { rendered = true resolved = "a" } @@ -1180,7 +1156,7 @@ o.spec("route", function() { route.set("/b") }) }, - render: function(vnode) { + render: function() { rendered = true resolved = "a" } @@ -1210,7 +1186,7 @@ o.spec("route", function() { var i = 0 $window.location.href = prefix + "/" route(root, "/", { - "/": {view: function(v) {i++}} + "/": {view: function() {i++}} }) var before = i diff --git a/browser.js b/browser.js index fed323f1..0debb4ea 100644 --- a/browser.js +++ b/browser.js @@ -1,3 +1,5 @@ +"use strict" + var m = require("./index") if (typeof module !== "undefined") module["exports"] = m else window.m = m diff --git a/bundler/bin/bundle b/bundler/bin/bundle index e0c4279a..81c65c90 100644 --- a/bundler/bin/bundle +++ b/bundler/bin/bundle @@ -1,3 +1,4 @@ #!/usr/bin/env node +"use strict" require("../cli") diff --git a/bundler/tests/test-bundler.js b/bundler/tests/test-bundler.js index 3055bf7c..40175e19 100644 --- a/bundler/tests/test-bundler.js +++ b/bundler/tests/test-bundler.js @@ -1,3 +1,5 @@ +"use strict" + var o = require("../../ospec/ospec") var bundle = require("../bundle") @@ -5,10 +7,10 @@ var fs = require("fs") var ns = "bundler/tests/" function read(filepath) { - try {return fs.readFileSync(ns + filepath, "utf8")} catch (e) {} + try {return fs.readFileSync(ns + filepath, "utf8")} catch (e) {/* ignore */} } function write(filepath, data) { - try {var exists = fs.statSync(ns + filepath).isFile()} catch (e) {} + try {var exists = fs.statSync(ns + filepath).isFile()} catch (e) {/* ignore */} if (exists) throw new Error("Don't call `write('" + filepath + "')`. Cannot overwrite file") fs.writeFileSync(ns + filepath, data, "utf8") } @@ -18,255 +20,255 @@ function remove(filepath) { o.spec("bundler", function() { o("relative imports works", function() { - write("a.js", `var b = require("./b")`) - write("b.js", `module.exports = 1`) + write("a.js", 'var b = require("./b")') + write("b.js", "module.exports = 1") bundle(ns + "a.js", ns + "out.js") - - o(read("out.js")).equals(`new function() {\nvar b = 1\n}`) - + + o(read("out.js")).equals("new function() {\nvar b = 1\n}") + remove("a.js") remove("b.js") remove("out.js") }) o("relative imports works with semicolons", function() { - write("a.js", `var b = require("./b");`) - write("b.js", `module.exports = 1;`) + write("a.js", 'var b = require("./b");') + write("b.js", "module.exports = 1;") bundle(ns + "a.js", ns + "out.js") - - o(read("out.js")).equals(`new function() {\nvar b = 1;\n}`) - + + o(read("out.js")).equals("new function() {\nvar b = 1;\n}") + remove("a.js") remove("b.js") remove("out.js") }) o("relative imports works with let", function() { - write("a.js", `let b = require("./b")`) - write("b.js", `module.exports = 1`) + write("a.js", 'let b = require("./b")') + write("b.js", "module.exports = 1") bundle(ns + "a.js", ns + "out.js") - - o(read("out.js")).equals(`new function() {\nlet b = 1\n}`) - + + o(read("out.js")).equals("new function() {\nlet b = 1\n}") + remove("a.js") remove("b.js") remove("out.js") }) o("relative imports works with const", function() { write("a.js", 'const b = require("./b")') - write("b.js", `module.exports = 1`) + write("b.js", "module.exports = 1") bundle(ns + "a.js", ns + "out.js") - - o(read("out.js")).equals(`new function() {\nconst b = 1\n}`) - + + o(read("out.js")).equals("new function() {\nconst b = 1\n}") + remove("a.js") remove("b.js") remove("out.js") }) o("relative imports works with assignment", function() { - write("a.js", `var a = {}\na.b = require("./b")`) - write("b.js", `module.exports = 1`) + write("a.js", 'var a = {}\na.b = require("./b")') + write("b.js", "module.exports = 1") bundle(ns + "a.js", ns + "out.js") - - o(read("out.js")).equals(`new function() {\nvar a = {}\na.b = 1\n}`) - + + o(read("out.js")).equals("new function() {\nvar a = {}\na.b = 1\n}") + remove("a.js") remove("b.js") remove("out.js") }) o("relative imports works with reassignment", function() { - write("a.js", `var b = {}\nb = require("./b")`) - write("b.js", `module.exports = 1`) + write("a.js", 'var b = {}\nb = require("./b")') + write("b.js", "module.exports = 1") bundle(ns + "a.js", ns + "out.js") - - o(read("out.js")).equals(`new function() {\nvar b = {}\nb = 1\n}`) - + + o(read("out.js")).equals("new function() {\nvar b = {}\nb = 1\n}") + remove("a.js") remove("b.js") remove("out.js") }) o("relative imports removes extra use strict", function() { - write("a.js", `"use strict"\nvar b = require("./b")`) - write("b.js", `"use strict"\nmodule.exports = 1`) + write("a.js", '"use strict"\nvar b = require("./b")') + write("b.js", '"use strict"\nmodule.exports = 1') bundle(ns + "a.js", ns + "out.js") - - o(read("out.js")).equals(`new function() {\n"use strict"\nvar b = 1\n}`) - + + o(read("out.js")).equals('new function() {\n"use strict"\nvar b = 1\n}') + remove("a.js") remove("b.js") remove("out.js") }) o("relative imports removes extra use strict using single quotes", function() { - write("a.js", `'use strict'\nvar b = require("./b")`) - write("b.js", `'use strict'\nmodule.exports = 1`) + write("a.js", "'use strict'\nvar b = require(\"./b\")") + write("b.js", "'use strict'\nmodule.exports = 1") bundle(ns + "a.js", ns + "out.js") - - o(read("out.js")).equals(`new function() {\n'use strict'\nvar b = 1\n}`) - + + o(read("out.js")).equals("new function() {\n'use strict'\nvar b = 1\n}") + remove("a.js") remove("b.js") remove("out.js") }) o("relative imports removes extra use strict using mixed quotes", function() { - write("a.js", `"use strict"\nvar b = require("./b")`) - write("b.js", `'use strict'\nmodule.exports = 1`) + write("a.js", '"use strict"\nvar b = require("./b")') + write("b.js", "'use strict'\nmodule.exports = 1") bundle(ns + "a.js", ns + "out.js") - - o(read("out.js")).equals(`new function() {\n"use strict"\nvar b = 1\n}`) - + + o(read("out.js")).equals('new function() {\n"use strict"\nvar b = 1\n}') + remove("a.js") remove("b.js") remove("out.js") }) o("works w/ window", function() { - write("a.js", `window.a = 1\nvar b = require("./b")`) - write("b.js", `module.exports = function() {return a}`) + write("a.js", 'window.a = 1\nvar b = require("./b")') + write("b.js", "module.exports = function() {return a}") bundle(ns + "a.js", ns + "out.js") - - o(read("out.js")).equals(`new function() {\nwindow.a = 1\nvar b = function() {return a}\n}`) - + + o(read("out.js")).equals("new function() {\nwindow.a = 1\nvar b = function() {return a}\n}") + remove("a.js") remove("b.js") remove("out.js") }) o("works without assignment", function() { - write("a.js", `require("./b")`) - write("b.js", `1 + 1`) + write("a.js", 'require("./b")') + write("b.js", "1 + 1") bundle(ns + "a.js", ns + "out.js") - - o(read("out.js")).equals(`new function() {\n1 + 1\n}`) - + + o(read("out.js")).equals("new function() {\n1 + 1\n}") + remove("a.js") remove("b.js") remove("out.js") }) o("works if used fluently", function() { - write("a.js", `var b = require("./b").toString()`) - write("b.js", `module.exports = []`) + write("a.js", 'var b = require("./b").toString()') + write("b.js", "module.exports = []") bundle(ns + "a.js", ns + "out.js") - - o(read("out.js")).equals(`new function() {\nvar _0 = []\nvar b = _0.toString()\n}`) - + + o(read("out.js")).equals("new function() {\nvar _0 = []\nvar b = _0.toString()\n}") + remove("a.js") remove("b.js") remove("out.js") }) o("works if used fluently w/ multiline", function() { - write("a.js", `var b = require("./b")\n\t.toString()`) - write("b.js", `module.exports = []`) + write("a.js", 'var b = require("./b")\n\t.toString()') + write("b.js", "module.exports = []") bundle(ns + "a.js", ns + "out.js") - - o(read("out.js")).equals(`new function() {\nvar _0 = []\nvar b = _0\n\t.toString()\n}`) - + + o(read("out.js")).equals("new function() {\nvar _0 = []\nvar b = _0\n\t.toString()\n}") + remove("a.js") remove("b.js") remove("out.js") }) o("works if used w/ curry", function() { - write("a.js", `var b = require("./b")()`) - write("b.js", `module.exports = function() {}`) + write("a.js", 'var b = require("./b")()') + write("b.js", "module.exports = function() {}") bundle(ns + "a.js", ns + "out.js") - - o(read("out.js")).equals(`new function() {\nvar _0 = function() {}\nvar b = _0()\n}`) - + + o(read("out.js")).equals("new function() {\nvar _0 = function() {}\nvar b = _0()\n}") + remove("a.js") remove("b.js") remove("out.js") }) o("works if used w/ curry w/ multiline", function() { - write("a.js", `var b = require("./b")\n()`) - write("b.js", `module.exports = function() {}`) + write("a.js", 'var b = require("./b")\n()') + write("b.js", "module.exports = function() {}") bundle(ns + "a.js", ns + "out.js") - - o(read("out.js")).equals(`new function() {\nvar _0 = function() {}\nvar b = _0\n()\n}`) - + + o(read("out.js")).equals("new function() {\nvar _0 = function() {}\nvar b = _0\n()\n}") + remove("a.js") remove("b.js") remove("out.js") }) o("works if used fluently in one place and not in another", function() { - write("a.js", `var b = require("./b").toString()\nvar c = require("./c")`) - write("b.js", `module.exports = []`) - write("c.js", `var b = require("./b")\nmodule.exports = function() {return b}`) + write("a.js", 'var b = require("./b").toString()\nvar c = require("./c")') + write("b.js", "module.exports = []") + write("c.js", 'var b = require("./b")\nmodule.exports = function() {return b}') bundle(ns + "a.js", ns + "out.js") - - o(read("out.js")).equals(`new function() {\nvar _0 = []\nvar b = _0.toString()\nvar b0 = _0\nvar c = function() {return b0}\n}`) - + + o(read("out.js")).equals("new function() {\nvar _0 = []\nvar b = _0.toString()\nvar b0 = _0\nvar c = function() {return b0}\n}") + remove("a.js") remove("b.js") remove("c.js") remove("out.js") }) o("works if used in sequence", function() { - write("a.js", `var b = require("./b"), c = require("./c")`) - write("b.js", `module.exports = 1`) - write("c.js", `var x\nmodule.exports = 2`) + write("a.js", 'var b = require("./b"), c = require("./c")') + write("b.js", "module.exports = 1") + write("c.js", "var x\nmodule.exports = 2") bundle(ns + "a.js", ns + "out.js") - - o(read("out.js")).equals(`new function() {\nvar b = 1\nvar x\nvar c = 2\n}`) - + + o(read("out.js")).equals("new function() {\nvar b = 1\nvar x\nvar c = 2\n}") + remove("a.js") remove("b.js") remove("c.js") remove("out.js") }) o("works if assigned to property", function() { - write("a.js", `var x = {}\nx.b = require("./b")\nx.c = require("./c")`) - write("b.js", `var bb = 1\nmodule.exports = bb`) - write("c.js", `var cc = 2\nmodule.exports = cc`) + write("a.js", 'var x = {}\nx.b = require("./b")\nx.c = require("./c")') + write("b.js", "var bb = 1\nmodule.exports = bb") + write("c.js", "var cc = 2\nmodule.exports = cc") bundle(ns + "a.js", ns + "out.js") - - o(read("out.js")).equals(`new function() {\nvar x = {}\nvar bb = 1\nx.b = bb\nvar cc = 2\nx.c = cc\n}`) - + + o(read("out.js")).equals("new function() {\nvar x = {}\nvar bb = 1\nx.b = bb\nvar cc = 2\nx.c = cc\n}") + remove("a.js") remove("b.js") remove("c.js") remove("out.js") }) o("works if assigned to property using bracket notation", function() { - write("a.js", `var x = {}\nx["b"] = require("./b")\nx["c"] = require("./c")`) - write("b.js", `var bb = 1\nmodule.exports = bb`) - write("c.js", `var cc = 2\nmodule.exports = cc`) + write("a.js", 'var x = {}\nx["b"] = require("./b")\nx["c"] = require("./c")') + write("b.js", "var bb = 1\nmodule.exports = bb") + write("c.js", "var cc = 2\nmodule.exports = cc") bundle(ns + "a.js", ns + "out.js") - - o(read("out.js")).equals(`new function() {\nvar x = {}\nvar bb = 1\nx["b"] = bb\nvar cc = 2\nx["c"] = cc\n}`) - + + o(read("out.js")).equals('new function() {\nvar x = {}\nvar bb = 1\nx["b"] = bb\nvar cc = 2\nx["c"] = cc\n}') + remove("a.js") remove("b.js") remove("c.js") remove("out.js") }) o("works if collision", function() { - write("a.js", `var b = require("./b")`) - write("b.js", `var b = 1\nmodule.exports = 2`) + write("a.js", 'var b = require("./b")') + write("b.js", "var b = 1\nmodule.exports = 2") bundle(ns + "a.js", ns + "out.js") - - o(read("out.js")).equals(`new function() {\nvar b0 = 1\nvar b = 2\n}`) - + + o(read("out.js")).equals("new function() {\nvar b0 = 1\nvar b = 2\n}") + remove("a.js") remove("b.js") remove("out.js") }) o("works if multiple aliases", function() { - write("a.js", `var b = require("./b")\n`) - write("b.js", `var b = require("./c")\nb.x = 1\nmodule.exports = b`) - write("c.js", `var b = {}\nmodule.exports = b`) + write("a.js", 'var b = require("./b")\n') + write("b.js", 'var b = require("./c")\nb.x = 1\nmodule.exports = b') + write("c.js", "var b = {}\nmodule.exports = b") bundle(ns + "a.js", ns + "out.js") - - o(read("out.js")).equals(`new function() {\nvar b = {}\nb.x = 1\n}`) - + + o(read("out.js")).equals("new function() {\nvar b = {}\nb.x = 1\n}") + remove("a.js") remove("b.js") remove("c.js") remove("out.js") }) o("works if multiple collision", function() { - write("a.js", `var b = require("./b")\nvar c = require("./c")\nvar d = require("./d")`) - write("b.js", `var a = 1\nmodule.exports = a`) - write("c.js", `var a = 2\nmodule.exports = a`) - write("d.js", `var a = 3\nmodule.exports = a`) + write("a.js", 'var b = require("./b")\nvar c = require("./c")\nvar d = require("./d")') + write("b.js", "var a = 1\nmodule.exports = a") + write("c.js", "var a = 2\nmodule.exports = a") + write("d.js", "var a = 3\nmodule.exports = a") bundle(ns + "a.js", ns + "out.js") - - o(read("out.js")).equals(`new function() {\nvar a = 1\nvar b = a\nvar a0 = 2\nvar c = a0\nvar a1 = 3\nvar d = a1\n}`) - + + o(read("out.js")).equals("new function() {\nvar a = 1\nvar b = a\nvar a0 = 2\nvar c = a0\nvar a1 = 3\nvar d = a1\n}") + remove("a.js") remove("b.js") remove("c.js") @@ -274,38 +276,38 @@ o.spec("bundler", function() { remove("out.js") }) o("works if included multiple times", function() { - write("a.js", `module.exports = 123`) - write("b.js", `var a = require("./a").toString()\nmodule.exports = a`) - write("c.js", `var a = require("./a").toString()\nvar b = require("./b")`) + write("a.js", "module.exports = 123") + write("b.js", 'var a = require("./a").toString()\nmodule.exports = a') + write("c.js", 'var a = require("./a").toString()\nvar b = require("./b")') bundle(ns + "c.js", ns + "out.js") - - o(read("out.js")).equals(`new function() {\nvar _0 = 123\nvar a = _0.toString()\nvar a0 = _0.toString()\nvar b = a0\n}`) - + + o(read("out.js")).equals("new function() {\nvar _0 = 123\nvar a = _0.toString()\nvar a0 = _0.toString()\nvar b = a0\n}") + remove("a.js") remove("b.js") remove("c.js") }) o("works if included multiple times reverse", function() { - write("a.js", `module.exports = 123`) - write("b.js", `var a = require("./a").toString()\nmodule.exports = a`) - write("c.js", `var b = require("./b")\nvar a = require("./a").toString()`) + write("a.js", "module.exports = 123") + write("b.js", 'var a = require("./a").toString()\nmodule.exports = a') + write("c.js", 'var b = require("./b")\nvar a = require("./a").toString()') bundle(ns + "c.js", ns + "out.js") - - o(read("out.js")).equals(`new function() {\nvar _0 = 123\nvar a0 = _0.toString()\nvar b = a0\nvar a = _0.toString()\n}`) - + + o(read("out.js")).equals("new function() {\nvar _0 = 123\nvar a0 = _0.toString()\nvar b = a0\nvar a = _0.toString()\n}") + remove("a.js") remove("b.js") remove("c.js") }) o("reuses binding if possible", function() { - write("a.js", `var b = require("./b")\nvar c = require("./c")`) - write("b.js", `var d = require("./d")\nmodule.exports = function() {return d + 1}`) - write("c.js", `var d = require("./d")\nmodule.exports = function() {return d + 2}`) - write("d.js", `module.exports = 1`) + write("a.js", 'var b = require("./b")\nvar c = require("./c")') + write("b.js", 'var d = require("./d")\nmodule.exports = function() {return d + 1}') + write("c.js", 'var d = require("./d")\nmodule.exports = function() {return d + 2}') + write("d.js", "module.exports = 1") bundle(ns + "a.js", ns + "out.js") - - o(read("out.js")).equals(`new function() {\nvar d = 1\nvar b = function() {return d + 1}\nvar c = function() {return d + 2}\n}`) - + + o(read("out.js")).equals("new function() {\nvar d = 1\nvar b = function() {return d + 1}\nvar c = function() {return d + 2}\n}") + remove("a.js") remove("b.js") remove("c.js") @@ -313,71 +315,71 @@ o.spec("bundler", function() { remove("out.js") }) o("disambiguates conflicts if imported collides with itself", function() { - write("a.js", `var b = require("./b")`) - write("b.js", `var b = 1\nmodule.exports = function() {return b}`) + write("a.js", 'var b = require("./b")') + write("b.js", "var b = 1\nmodule.exports = function() {return b}") bundle(ns + "a.js", ns + "out.js") - - o(read("out.js")).equals(`new function() {\nvar b0 = 1\nvar b = function() {return b0}\n}`) - + + o(read("out.js")).equals("new function() {\nvar b0 = 1\nvar b = function() {return b0}\n}") + remove("a.js") remove("b.js") remove("out.js") }) o("disambiguates conflicts if imported collides with something else", function() { - write("a.js", `var a = 1\nvar b = require("./b")`) - write("b.js", `var a = 2\nmodule.exports = function() {return a}`) + write("a.js", 'var a = 1\nvar b = require("./b")') + write("b.js", "var a = 2\nmodule.exports = function() {return a}") bundle(ns + "a.js", ns + "out.js") - - o(read("out.js")).equals(`new function() {\nvar a = 1\nvar a0 = 2\nvar b = function() {return a0}\n}`) - + + o(read("out.js")).equals("new function() {\nvar a = 1\nvar a0 = 2\nvar b = function() {return a0}\n}") + remove("a.js") remove("b.js") remove("out.js") }) o("disambiguates conflicts if imported collides with function declaration", function() { - write("a.js", `function a() {}\nvar b = require("./b")`) - write("b.js", `var a = 2\nmodule.exports = function() {return a}`) + write("a.js", 'function a() {}\nvar b = require("./b")') + write("b.js", "var a = 2\nmodule.exports = function() {return a}") bundle(ns + "a.js", ns + "out.js") - - o(read("out.js")).equals(`new function() {\nfunction a() {}\nvar a0 = 2\nvar b = function() {return a0}\n}`) - + + o(read("out.js")).equals("new function() {\nfunction a() {}\nvar a0 = 2\nvar b = function() {return a0}\n}") + remove("a.js") remove("b.js") remove("out.js") }) o("disambiguates conflicts if imported collides with another module's private", function() { - write("a.js", `var b = require("./b")\nvar c = require("./c")`) - write("b.js", `var a = 1\nmodule.exports = function() {return a}`) - write("c.js", `var a = 2\nmodule.exports = function() {return a}`) + write("a.js", 'var b = require("./b")\nvar c = require("./c")') + write("b.js", "var a = 1\nmodule.exports = function() {return a}") + write("c.js", "var a = 2\nmodule.exports = function() {return a}") bundle(ns + "a.js", ns + "out.js") - - o(read("out.js")).equals(`new function() {\nvar a = 1\nvar b = function() {return a}\nvar a0 = 2\nvar c = function() {return a0}\n}`) - + + o(read("out.js")).equals("new function() {\nvar a = 1\nvar b = function() {return a}\nvar a0 = 2\nvar c = function() {return a0}\n}") + remove("a.js") remove("b.js") remove("c.js") remove("out.js") }) o("does not mess up strings", function() { - write("a.js", `var b = require("./b")`) - write("b.js", `var b = "b b b \\\" b"\nmodule.exports = function() {return b}`) + write("a.js", 'var b = require("./b")') + write("b.js", 'var b = "b b b \\" b"\nmodule.exports = function() {return b}') bundle(ns + "a.js", ns + "out.js") - - o(read("out.js")).equals(`new function() {\nvar b0 = "b b b \\\" b"\nvar b = function() {return b0}\n}`) - + + o(read("out.js")).equals('new function() {\nvar b0 = "b b b \\" b"\nvar b = function() {return b0}\n}') + remove("a.js") remove("b.js") remove("out.js") }) o("does not mess up properties", function() { - write("a.js", `var b = require("./b")`) - write("b.js", `var b = {b: 1}\nmodule.exports = function() {return b.b}`) + write("a.js", 'var b = require("./b")') + write("b.js", "var b = {b: 1}\nmodule.exports = function() {return b.b}") bundle(ns + "a.js", ns + "out.js") - - o(read("out.js")).equals(`new function() {\nvar b0 = {b: 1}\nvar b = function() {return b0.b}\n}`) - + + o(read("out.js")).equals("new function() {\nvar b0 = {b: 1}\nvar b = function() {return b0.b}\n}") + remove("a.js") remove("b.js") remove("out.js") }) -}) \ No newline at end of file +}) diff --git a/docs/generate.js b/docs/generate.js index bcf5465e..789563c8 100644 --- a/docs/generate.js +++ b/docs/generate.js @@ -1,15 +1,17 @@ +"use strict" + var fs = require("fs") var path = require("path") var marked = require("marked") var layout = fs.readFileSync("./docs/layout.html", "utf-8") var version = JSON.parse(fs.readFileSync("./package.json", "utf-8")).version -try {fs.mkdirSync("../mithril")} catch (e) {} -try {fs.mkdirSync("../mithril/archive")} catch (e) {} -try {fs.mkdirSync("../mithril/archive/v" + version)} catch (e) {} -try {fs.mkdirSync("../mithril/archive/v" + version + "/lib")} catch (e) {} -try {fs.mkdirSync("../mithril/archive/v" + version + "/lib/prism")} catch (e) {} -try {fs.mkdirSync("../mithril/lib")} catch (e) {} -try {fs.mkdirSync("../mithril/lib/prism")} catch (e) {} +try {fs.mkdirSync("../mithril")} catch (e) {/* ignore */} +try {fs.mkdirSync("../mithril/archive")} catch (e) {/* ignore */} +try {fs.mkdirSync("../mithril/archive/v" + version)} catch (e) {/* ignore */} +try {fs.mkdirSync("../mithril/archive/v" + version + "/lib")} catch (e) {/* ignore */} +try {fs.mkdirSync("../mithril/archive/v" + version + "/lib/prism")} catch (e) {/* ignore */} +try {fs.mkdirSync("../mithril/lib")} catch (e) {/* ignore */} +try {fs.mkdirSync("../mithril/lib/prism")} catch (e) {/* ignore */} var guides = fs.readFileSync("docs/guides.md", "utf-8") var methods = fs.readFileSync("docs/methods.md", "utf-8") @@ -33,7 +35,7 @@ function generate(pathname) { .replace(/`((?:\S| -> |, )+)(\|)(\S+)`/gim, function(match, a, b, c) { // fix pipes in code tags return "" + (a + b + c).replace(/\|/g, "|") + "" }) - .replace(/(^# .+?(?:\r?\n){2,}?)(?:(-(?:.|\r|\n)+?)((?:\r?\n){2,})|)/m, function(match, title, nav, space) { // inject menu + .replace(/(^# .+?(?:\r?\n){2,}?)(?:(-(?:.|\r|\n)+?)((?:\r?\n){2,})|)/m, function(match, title, nav) { // inject menu var file = path.basename(pathname) var link = new RegExp("([ \t]*)(- )(\\[.+?\\]\\(" + file + "\\))") var replace = function(match, space, li, link) { @@ -53,7 +55,7 @@ function generate(pathname) { .replace(/\[version\]/, version) // update version .replace(/\[body\]/, markedHtml) .replace(/(.+?)<\/h.>/gim, function(match, n, id, text) { // fix anchors - return "/g, "").replace(/.+?<\/a>/g, "").replace(/\.|\[|\]|"|\/|\(|\)/g, "").replace(/\s/g, "-") + "\">" + text + "" + return ".+?<\/a>/g, "").replace(/\.|\[|\]|"|\/|\(|\)/g, "").replace(/\s/g, "-") + '">' + text + "" }) fs.writeFileSync("../mithril/archive/v" + version + "/" + outputFilename.replace(/^docs\//, ""), html, "utf-8") fs.writeFileSync("../mithril/" + outputFilename.replace(/^docs\//, ""), html, "utf-8") diff --git a/docs/lint.js b/docs/lint.js index 3ab0d559..2fb39e3b 100644 --- a/docs/lint.js +++ b/docs/lint.js @@ -1,4 +1,5 @@ #!/usr/bin/env node +"use strict" var fs = require("fs") var path = require("path") @@ -100,11 +101,11 @@ function ensureLinkIsValid(file, data) { } function initMocks() { - global.window = require("../test-utils/browserMock")() + global.window = require("../test-utils/browserMock")() // eslint-disable-line global-require global.document = window.document - global.m = require("../index") - global.o = require("../ospec/ospec") - global.stream = require("../stream") + global.m = require("../index") // eslint-disable-line global-require + global.o = require("../ospec/ospec") // eslint-disable-line global-require + global.stream = require("../stream") // eslint-disable-line global-require global.alert = function() {} //routes consumed by request.md @@ -121,7 +122,7 @@ function initMocks() { "GET /api/v1/todos": function() { return {status: 200, responseText: JSON.stringify([])} }, - "PUT /api/v1/users/1": function() { + "PUT /api/v1/users/1": function(request) { return {status: 200, responseText: request.query.callback ? request.query.callback + "([])" : "[]"} }, "POST /api/v1/upload": function() { diff --git a/hyperscript.js b/hyperscript.js index 880a1594..16bf033a 100644 --- a/hyperscript.js +++ b/hyperscript.js @@ -1,3 +1,5 @@ +"use strict" + var hyperscript = require("./render/hyperscript") hyperscript.trust = require("./render/trust") diff --git a/mount.js b/mount.js index 7e54a628..73fa1ce9 100644 --- a/mount.js +++ b/mount.js @@ -1,3 +1,5 @@ +"use strict" + var redrawService = require("./redraw") -module.exports = require("./api/mount")(redrawService) \ No newline at end of file +module.exports = require("./api/mount")(redrawService) diff --git a/ospec/bin/ospec b/ospec/bin/ospec index c5034d09..11777a09 100644 --- a/ospec/bin/ospec +++ b/ospec/bin/ospec @@ -1,4 +1,5 @@ #!/usr/bin/env node +"use strict" var fs = require("fs") var path = require("path") @@ -31,9 +32,9 @@ function traverseDirectory(pathname, callback) { }) } -traverseDirectory(".", function(pathname, stat, children) { +traverseDirectory(".", function(pathname) { if (pathname.match(/(?:^|\/)tests\/.*\.js$/)) { - require(path.normalize(process.cwd()) + "/" + pathname) + require(path.normalize(process.cwd()) + "/" + pathname) // eslint-disable-line global-require } }) .then(o.run) diff --git a/ospec/ospec.js b/ospec/ospec.js index 7edc7ecb..0c58b347 100644 --- a/ospec/ospec.js +++ b/ospec/ospec.js @@ -1,3 +1,4 @@ +/* eslint-disable no-bitwise, no-process-exit */ "use strict" module.exports = new function init() { @@ -121,8 +122,8 @@ module.exports = new function init() { } function unique(subject) { if (hasOwn.call(ctx, subject)) { - console.warn("A test or a spec named `" + subject + "` was already defined") - while (hasOwn.call(ctx, subject)) subject += '*' + console.warn("A test or a spec named `" + subject + "` was already defined") + while (hasOwn.call(ctx, subject)) subject += "*" } return subject } diff --git a/ospec/tests/test-ospec.js b/ospec/tests/test-ospec.js index ff5d1d8f..0367e6ec 100644 --- a/ospec/tests/test-ospec.js +++ b/ospec/tests/test-ospec.js @@ -28,11 +28,11 @@ o.spec("ospec", function() { o.beforeEach(function() {b = 1}) o.afterEach(function() {b = 0}) - try {o('illegal assertion')} catch (e) {illegalAssertionThrows = true} + try {o("illegal assertion")} catch (e) {illegalAssertionThrows = true} o("assertions", function() { var nestedTestDeclarationThrows = false - try {o('illegal nested test', function(){})} catch (e) {nestedTestDeclarationThrows = true} + try {o("illegal nested test", function(){})} catch (e) {nestedTestDeclarationThrows = true} o(illegalAssertionThrows).equals(true) o(nestedTestDeclarationThrows).equals(true) @@ -51,7 +51,7 @@ o.spec("ospec", function() { o(undef1).notDeepEquals(undef2) o(undef1).notDeepEquals({}) o({}).notDeepEquals(undef1) - + var sparse1 = [void 1, void 2, void 3] delete sparse1[0] var sparse2 = [void 1, void 2, void 3] @@ -63,7 +63,7 @@ o.spec("ospec", function() { monkeypatch1.field = 3 var monkeypatch2 = [1, 2] monkeypatch2.field = 4 - + o(monkeypatch1).notDeepEquals([1, 2]) o(monkeypatch1).notDeepEquals(monkeypatch2) diff --git a/promise/tests/test-promise.js b/promise/tests/test-promise.js index a91b0bcb..e52e792b 100644 --- a/promise/tests/test-promise.js +++ b/promise/tests/test-promise.js @@ -57,7 +57,7 @@ o.spec("promise", function() { o.spec("resolve", function() { o("resolves once", function(done) { var callCount = 0 - var promise = new Promise(function(resolve, reject) { + var promise = new Promise(function(resolve) { resolve(1) resolve(2) callAsync(function() {resolve(3)}) @@ -89,7 +89,7 @@ o.spec("promise", function() { var promise = Promise.resolve() state = 1 - promise.then(function(value) { + promise.then(function() { o(state).equals(2) done() }) @@ -104,7 +104,7 @@ o.spec("promise", function() { }) }) o("resolves asynchronously via executor", function(done) { - var promise = new Promise(function(resolve, reject) { + var promise = new Promise(function(resolve) { callAsync(function() {resolve(1)}) }) @@ -185,7 +185,7 @@ o.spec("promise", function() { var promise = Promise.reject() state = 1 - promise.then(null, function(value) { + promise.then(null, function() { o(state).equals(2) done() }) @@ -232,7 +232,7 @@ o.spec("promise", function() { }) }) o("rejects via executor on error", function(done) { - var promise = new Promise(function(resolve, reject) { + var promise = new Promise(function() { throw 1 }) @@ -281,7 +281,7 @@ o.spec("promise", function() { }).then(done) }) o("absorbs resolved promise in executor resolve", function(done) { - var promise = new Promise(function(resolve, reject) { + var promise = new Promise(function(resolve) { var p = Promise.resolve(1) resolve(p) }) @@ -310,7 +310,7 @@ o.spec("promise", function() { }) }) o("absorbs rejected promise in executor resolve", function(done) { - var promise = new Promise(function(resolve, reject) { + var promise = new Promise(function(resolve) { resolve(Promise.reject(1)) }) @@ -330,7 +330,7 @@ o.spec("promise", function() { }) }) o("absorbs pending promise that resolves via static resolver", function(done) { - var pending = new Promise(function(resolve, reject) { + var pending = new Promise(function(resolve) { setTimeout(function() {resolve(1)}, 10) }) var promise = Promise.resolve(pending) @@ -341,10 +341,10 @@ o.spec("promise", function() { }) }) o("absorbs pending promise that resolves in executor resolve", function(done) { - var pending = new Promise(function(resolve, reject) { + var pending = new Promise(function(resolve) { setTimeout(function() {resolve(1)}, 10) }) - var promise = new Promise(function(resolve, reject) { + var promise = new Promise(function(resolve) { resolve(pending) }) @@ -354,7 +354,7 @@ o.spec("promise", function() { }) }) o("absorbs pending promise that resolves on fulfillment", function(done) { - var pending = new Promise(function(resolve, reject) { + var pending = new Promise(function(resolve) { setTimeout(function() {resolve(1)}, 10) }) var promise = Promise.resolve() @@ -381,7 +381,7 @@ o.spec("promise", function() { var pending = new Promise(function(resolve, reject) { setTimeout(function() {reject(1)}, 10) }) - var promise = new Promise(function(resolve, reject) { + var promise = new Promise(function(resolve) { resolve(pending) }) @@ -521,7 +521,7 @@ o.spec("promise", function() { o.spec("race", function() { o("resolves to first resolved", function(done) { var a = Promise.resolve(1) - var b = new Promise(function(resolve, reject) { + var b = new Promise(function(resolve) { callAsync(function() {resolve(2)}) }) Promise.race([a, b]).then(function(value) { @@ -542,7 +542,7 @@ o.spec("promise", function() { }) o.spec("all", function() { o("resolves to array", function(done) { - var a = new Promise(function(resolve, reject) { + var a = new Promise(function(resolve) { callAsync(function() {resolve(1)}) }) var b = Promise.resolve(2) @@ -558,7 +558,7 @@ o.spec("promise", function() { }) }) o("resolves non-promise to itself", function(done) { - var a = new Promise(function(resolve, reject) { + var a = new Promise(function(resolve) { callAsync(function() {resolve(1)}) }) var b = Promise.resolve(2) @@ -595,7 +595,7 @@ o.spec("promise", function() { }) }) - promise.then(function(value) { + promise.then(function() { o(readCount).equals(1) done() }) diff --git a/redraw.js b/redraw.js index 01ac46f2..314e5002 100644 --- a/redraw.js +++ b/redraw.js @@ -1 +1,3 @@ -module.exports = require("./api/redraw")(window) \ No newline at end of file +"use strict" + +module.exports = require("./api/redraw")(window) diff --git a/render.js b/render.js index 5497c9bd..a6f8ce8d 100644 --- a/render.js +++ b/render.js @@ -1 +1,3 @@ -module.exports = require("./render/render")(window) \ No newline at end of file +"use strict" + +module.exports = require("./render/render")(window) diff --git a/render/tests/test-attributes.js b/render/tests/test-attributes.js index 2d08007b..c6a3df31 100644 --- a/render/tests/test-attributes.js +++ b/render/tests/test-attributes.js @@ -12,19 +12,19 @@ o.spec("attributes", function() { render = vdom($window).render }) o.spec("customElements", function(){ - + o("when vnode is customElement, custom setAttribute called", function(){ - var normal = [ - { tag: "input", attrs: { value: 'hello' } }, - { tag: "input", attrs: { value: 'hello' } }, - { tag: "input", attrs: { value: 'hello' } } + var normal = [ + {tag: "input", attrs: {value: "hello"}}, + {tag: "input", attrs: {value: "hello"}}, + {tag: "input", attrs: {value: "hello"}} ] - + var custom = [ - { tag: "custom-element", attrs: { custom: 'x' } }, - { tag: "input", attrs: { is: 'something-special', custom: 'x' } }, - { tag: "custom-element", attrs: { is: 'something-special', custom: 'x' } } + {tag: "custom-element", attrs: {custom: "x"}}, + {tag: "input", attrs: {is: "something-special", custom: "x"}}, + {tag: "custom-element", attrs: {is: "something-special", custom: "x"}} ] var view = normal.concat(custom) @@ -43,8 +43,8 @@ o.spec("attributes", function() { } render(root, view) - - o(spy.callCount).equals( custom.length ) + + o(spy.callCount).equals(custom.length) }) }) @@ -133,7 +133,7 @@ o.spec("attributes", function() { }) o.spec("contenteditable throws on untrusted children", function() { o("including text nodes", function() { - var div = {tag: "div", attrs: {contenteditable: true}, text: ''} + var div = {tag: "div", attrs: {contenteditable: true}, text: ""} var succeeded = false try { @@ -141,7 +141,7 @@ o.spec("attributes", function() { succeeded = true } - catch(e){} + catch(e){/* ignore */} o(succeeded).equals(false) }) @@ -154,7 +154,7 @@ o.spec("attributes", function() { succeeded = true } - catch(e){} + catch(e){/* ignore */} o(succeeded).equals(false) }) @@ -167,7 +167,7 @@ o.spec("attributes", function() { succeeded = true } - catch(e){} + catch(e){/* ignore */} o(succeeded).equals(true) }) @@ -180,7 +180,7 @@ o.spec("attributes", function() { succeeded = true } - catch(e){} + catch(e){/* ignore */} o(succeeded).equals(true) }) diff --git a/render/tests/test-component.js b/render/tests/test-component.js index 64cd6fcb..fcf206e8 100644 --- a/render/tests/test-component.js +++ b/render/tests/test-component.js @@ -63,7 +63,7 @@ o.spec("component", function() { o("updates root from null", function() { var visible = false var component = createComponent({ - view: function(vnode) { + view: function() { return visible ? {tag: "div"} : null } }) @@ -76,7 +76,7 @@ o.spec("component", function() { o("updates root from primitive", function() { var visible = false var component = createComponent({ - view: function(vnode) { + view: function() { return visible ? {tag: "div"} : false } }) @@ -89,7 +89,7 @@ o.spec("component", function() { o("updates root to null", function() { var visible = true var component = createComponent({ - view: function(vnode) { + view: function() { return visible ? {tag: "div"} : null } }) @@ -102,7 +102,7 @@ o.spec("component", function() { o("updates root to primitive", function() { var visible = true var component = createComponent({ - view: function(vnode) { + view: function() { return visible ? {tag: "div"} : false } }) @@ -114,7 +114,7 @@ o.spec("component", function() { }) o("updates root from null to null", function() { var component = createComponent({ - view: function(vnode) { + view: function() { return null } }) @@ -125,7 +125,7 @@ o.spec("component", function() { }) o("removes", function() { var component = createComponent({ - view: function(vnode) { + view: function() { return {tag: "div"} } }) @@ -138,7 +138,7 @@ o.spec("component", function() { }) o("svg works when creating across component boundary", function() { var component = createComponent({ - view: function(vnode) { + view: function() { return {tag: "g"} } }) @@ -148,7 +148,7 @@ o.spec("component", function() { }) o("svg works when updating across component boundary", function() { var component = createComponent({ - view: function(vnode) { + view: function() { return {tag: "g"} } }) @@ -161,7 +161,7 @@ o.spec("component", function() { o.spec("return value", function() { o("can return fragments", function() { var component = createComponent({ - view: function(vnode) { + view: function() { return [ {tag: "label"}, {tag: "input"}, @@ -176,7 +176,7 @@ o.spec("component", function() { }) o("can return string", function() { var component = createComponent({ - view: function(vnode) { + view: function() { return "a" } }) @@ -187,7 +187,7 @@ o.spec("component", function() { }) o("can return falsy string", function() { var component = createComponent({ - view: function(vnode) { + view: function() { return "" } }) @@ -198,7 +198,7 @@ o.spec("component", function() { }) o("can return number", function() { var component = createComponent({ - view: function(vnode) { + view: function() { return 1 } }) @@ -209,7 +209,7 @@ o.spec("component", function() { }) o("can return falsy number", function() { var component = createComponent({ - view: function(vnode) { + view: function() { return 0 } }) @@ -220,7 +220,7 @@ o.spec("component", function() { }) o("can return boolean", function() { var component = createComponent({ - view: function(vnode) { + view: function() { return true } }) @@ -231,7 +231,7 @@ o.spec("component", function() { }) o("can return falsy boolean", function() { var component = createComponent({ - view: function(vnode) { + view: function() { return false } }) @@ -242,7 +242,7 @@ o.spec("component", function() { }) o("can return null", function() { var component = createComponent({ - view: function(vnode) { + view: function() { return null } }) @@ -252,7 +252,7 @@ o.spec("component", function() { }) o("can return undefined", function() { var component = createComponent({ - view: function(vnode) { + view: function() { return undefined } }) @@ -278,7 +278,7 @@ o.spec("component", function() { }) o("can update when returning fragments", function() { var component = createComponent({ - view: function(vnode) { + view: function() { return [ {tag: "label"}, {tag: "input"}, @@ -294,7 +294,7 @@ o.spec("component", function() { }) o("can update when returning primitive", function() { var component = createComponent({ - view: function(vnode) { + view: function() { return "a" } }) @@ -306,7 +306,7 @@ o.spec("component", function() { }) o("can update when returning null", function() { var component = createComponent({ - view: function(vnode) { + view: function() { return null } }) @@ -317,7 +317,7 @@ o.spec("component", function() { }) o("can remove when returning fragments", function() { var component = createComponent({ - view: function(vnode) { + view: function() { return [ {tag: "label"}, {tag: "input"}, @@ -334,7 +334,7 @@ o.spec("component", function() { }) o("can remove when returning primitive", function() { var component = createComponent({ - view: function(vnode) { + view: function() { return "a" } }) @@ -403,7 +403,7 @@ o.spec("component", function() { viewCalled = true return [{tag: "div", attrs: {id: "a"}, text: "b"}] }, - oninit: function(vnode) { + oninit: function() { o(viewCalled).equals(false) }, } @@ -646,7 +646,6 @@ o.spec("component", function() { return {tag: "div"} } }) - var update = o.spy() var vnode = {tag: component, key: 1} var updated = {tag: component, key: 1} @@ -659,7 +658,6 @@ o.spec("component", function() { }) o.spec("state", function() { o("initializes state", function() { - var called = 0 var data = {a: 1} var component = createComponent(createComponent({ data: data, @@ -676,7 +674,6 @@ o.spec("component", function() { } }) o('state "copy" is shallow', function() { - var called = 0 var body = {a: 1} var data = [body] var component = createComponent(createComponent({ @@ -701,7 +698,6 @@ o.spec("component", function() { o.spec("POJO state", function() { o("copies state", function() { - var called = 0 var data = {a: 1} var component = { data: data, diff --git a/render/tests/test-createElement.js b/render/tests/test-createElement.js index 31599cfd..9e2827cf 100644 --- a/render/tests/test-createElement.js +++ b/render/tests/test-createElement.js @@ -1,3 +1,4 @@ +/* eslint-disable no-script-url */ "use strict" var o = require("../../ospec/ospec") diff --git a/render/tests/test-hyperscript.js b/render/tests/test-hyperscript.js index 9e554541..2264fe18 100644 --- a/render/tests/test-hyperscript.js +++ b/render/tests/test-hyperscript.js @@ -1,3 +1,5 @@ +"use strict" + var o = require("../../ospec/ospec") var m = require("../../render/hyperscript") diff --git a/render/tests/test-onbeforeremove.js b/render/tests/test-onbeforeremove.js index 4395f90a..2e23215b 100644 --- a/render/tests/test-onbeforeremove.js +++ b/render/tests/test-onbeforeremove.js @@ -17,7 +17,6 @@ o.spec("onbeforeremove", function() { o("does not call onbeforeremove when creating", function() { var create = o.spy() - var update = o.spy() var vnode = {tag: "div", attrs: {onbeforeremove: create}} render(root, [vnode]) @@ -142,7 +141,7 @@ o.spec("onbeforeremove", function() { o(vnode.dom.attributes["onbeforeremove"]).equals(undefined) }) o("does not recycle when there's an onbeforeremove", function() { - var remove = function(vnode) {} + var remove = function() {} var vnode = {tag: "div", key: 1, attrs: {onbeforeremove: remove}} var updated = {tag: "div", key: 1, attrs: {onbeforeremove: remove}} @@ -153,7 +152,7 @@ o.spec("onbeforeremove", function() { o(vnode.dom).notEquals(updated.dom) }) o("does not leave elements out of order during removal", function(done) { - var remove = function(vnode) {return Promise.resolve()} + var remove = function() {return Promise.resolve()} var vnodes = [{tag: "div", key: 1, attrs: {onbeforeremove: remove}, text: "1"}, {tag: "div", key: 2, attrs: {onbeforeremove: remove}, text: "2"}] var updated = {tag: "div", key: 2, attrs: {onbeforeremove: remove}, text: "2"} diff --git a/render/tests/test-onbeforeupdate.js b/render/tests/test-onbeforeupdate.js index cf16dd1c..a3a49a8a 100644 --- a/render/tests/test-onbeforeupdate.js +++ b/render/tests/test-onbeforeupdate.js @@ -92,11 +92,10 @@ o.spec("onbeforeupdate", function() { o("is not called on creation", function() { var count = 0 var vnode = {tag: "div", attrs: {id: "a", onbeforeupdate: onbeforeupdate}} - var updated = {tag: "div", attrs: {id: "b", onbeforeupdate: onbeforeupdate}} render(root, [vnode]) - function onbeforeupdate(vnode, old) { + function onbeforeupdate() { count++ return true } @@ -112,7 +111,7 @@ o.spec("onbeforeupdate", function() { render(root, [vnode]) render(root, [updated]) - function onbeforeupdate(vnode, old) { + function onbeforeupdate() { count++ return true } @@ -248,7 +247,7 @@ o.spec("onbeforeupdate", function() { }) o("is not called on component creation", function() { - var component = createComponent({ + createComponent({ onbeforeupdate: onbeforeupdate, view: function(vnode) { return {tag: "div", attrs: vnode.attrs} @@ -257,11 +256,10 @@ o.spec("onbeforeupdate", function() { var count = 0 var vnode = {tag: "div", attrs: {id: "a"}} - var updated = {tag: "div", attrs: {id: "b"}} render(root, [vnode]) - function onbeforeupdate(vnode, old) { + function onbeforeupdate() { count++ return true } @@ -284,7 +282,7 @@ o.spec("onbeforeupdate", function() { render(root, [vnode]) render(root, [updated]) - function onbeforeupdate(vnode, old) { + function onbeforeupdate() { count++ return true } @@ -293,4 +291,4 @@ o.spec("onbeforeupdate", function() { }) }) }) -}) \ No newline at end of file +}) diff --git a/render/tests/test-oncreate.js b/render/tests/test-oncreate.js index d6f275c2..eb1daa5e 100644 --- a/render/tests/test-oncreate.js +++ b/render/tests/test-oncreate.js @@ -128,7 +128,6 @@ o.spec("oncreate", function() { }) o("does not call oncreate when removing", function() { var create = o.spy() - var update = o.spy() var vnode = {tag: "div", attrs: {oncreate: create}, state: {}} render(root, [vnode]) diff --git a/render/tests/test-oninit.js b/render/tests/test-oninit.js index 3265cd8b..4d94cae4 100644 --- a/render/tests/test-oninit.js +++ b/render/tests/test-oninit.js @@ -128,7 +128,6 @@ o.spec("oninit", function() { }) o("does not call oninit when removing", function() { var create = o.spy() - var update = o.spy() var vnode = {tag: "div", attrs: {oninit: create}, state: {}} render(root, [vnode]) diff --git a/render/tests/test-onupdate.js b/render/tests/test-onupdate.js index 448a44f0..13f62c46 100644 --- a/render/tests/test-onupdate.js +++ b/render/tests/test-onupdate.js @@ -59,7 +59,6 @@ o.spec("onupdate", function() { }) o("does not call old onupdate when removing the onupdate property in new vnode", function() { var create = o.spy() - var update = o.spy() var vnode = {tag: "a", attrs: {onupdate: create}} var updated = {tag: "a"} diff --git a/render/tests/test-render.js b/render/tests/test-render.js index 82e5ddba..92bcd93c 100644 --- a/render/tests/test-render.js +++ b/render/tests/test-render.js @@ -1,7 +1,6 @@ "use strict" var o = require("../../ospec/ospec") -var components = require("../../test-utils/components") var domMock = require("../../test-utils/domMock") var vdom = require("../../render/render") @@ -124,7 +123,7 @@ o.spec("render", function() { var onbeforeupdate = o.spy() function A() { return { - view: function(vnode) {throw new Error("error")}, + view: function() {throw new Error("error")}, oninit: oninit, onbeforeupdate: onbeforeupdate } @@ -143,11 +142,11 @@ o.spec("render", function() { o(onbeforeupdate.callCount).equals(0) }) o("does not try to re-initialize a closure component whose oninit has thrown", function() { - var oninit = o.spy(function(vnode) {throw new Error("error")}) + var oninit = o.spy(function() {throw new Error("error")}) var onbeforeupdate = o.spy() function A() { return { - view: function(vnode) {}, + view: function() {}, oninit: oninit, onbeforeupdate: onbeforeupdate } diff --git a/render/tests/test-updateElement.js b/render/tests/test-updateElement.js index 2211efd1..1774e61f 100644 --- a/render/tests/test-updateElement.js +++ b/render/tests/test-updateElement.js @@ -213,10 +213,10 @@ o.spec("updateElement", function() { }) o("updates svg child", function() { var vnode = {tag: "svg", children: [{ - tag: 'circle' + tag: "circle" }]} var updated = {tag: "svg", children: [{ - tag: 'line' + tag: "line" }]} render(root, [vnode]) @@ -235,7 +235,7 @@ o.spec("updateElement", function() { render(root, [vnode]) var c = vnode.dom - + o(root.childNodes.length).equals(1) o(a).equals(c) }) @@ -254,7 +254,7 @@ o.spec("updateElement", function() { render(root, [e, b, f]) var y = root.childNodes[1] - + o(root.childNodes.length).equals(3) o(x).equals(y) }) diff --git a/render/tests/test-updateNodes.js b/render/tests/test-updateNodes.js index c58a29b4..fa5231ea 100644 --- a/render/tests/test-updateNodes.js +++ b/render/tests/test-updateNodes.js @@ -727,7 +727,7 @@ o.spec("updateNodes", function() { }) o("change type, position and length", function() { var vnodes = {tag: "div", children: [ - undefined, + undefined, {tag: "#", children: "a"} ]} var updated = {tag: "div", children: [ @@ -738,7 +738,7 @@ o.spec("updateNodes", function() { render(root, vnodes) render(root, updated) - + o(root.firstChild.childNodes.length).equals(1) }) o("removes then recreates then reverses children", function() { @@ -864,13 +864,13 @@ o.spec("updateNodes", function() { var vnodes = [{tag: "div"}, {tag: "a", attrs: {oncreate: create, onupdate: update, onremove: remove}}] var temp = [null, {tag: "a", attrs: {oncreate: create, onupdate: update, onremove: remove}}] var updated = [{tag: "div"}, {tag: "a", attrs: {oncreate: create, onupdate: update, onremove: remove}}] - + render(root, vnodes) var before = vnodes[1].dom render(root, temp) render(root, updated) var after = updated[1].dom - + o(before).equals(after) o(create.callCount).equals(1) o(update.callCount).equals(2) @@ -883,13 +883,13 @@ o.spec("updateNodes", function() { var vnodes = [{tag: "b"}, {tag: "div"}, {tag: "a", attrs: {oncreate: create, onupdate: update, onremove: remove}}] var temp = [{tag: "b"}, null, {tag: "a", attrs: {oncreate: create, onupdate: update, onremove: remove}}] var updated = [{tag: "b"}, {tag: "div"}, {tag: "a", attrs: {oncreate: create, onupdate: update, onremove: remove}}] - + render(root, vnodes) var before = vnodes[2].dom render(root, temp) render(root, updated) var after = updated[2].dom - + o(before).equals(after) o(create.callCount).equals(1) o(update.callCount).equals(2) @@ -898,11 +898,10 @@ o.spec("updateNodes", function() { o("node is recreated if key changes to undefined", function () { var vnode = {tag: "b", key: 1} var updated = {tag: "b"} - + render(root, vnode) - var dom = vnode.dom render(root, updated) - + o(vnode.dom).notEquals(updated.dom) }) components.forEach(function(cmp){ @@ -943,4 +942,4 @@ o.spec("updateNodes", function() { }) }) }) -}) \ No newline at end of file +}) diff --git a/render/vnode.js b/render/vnode.js index 56df8c81..48d37239 100644 --- a/render/vnode.js +++ b/render/vnode.js @@ -1,3 +1,5 @@ +"use strict" + function Vnode(tag, key, attrs, children, text, dom) { return {tag: tag, key: key, attrs: attrs, children: children, text: text, dom: dom, domSize: undefined, state: {}, events: undefined, instance: undefined, skip: false} } diff --git a/request.js b/request.js index 7e86421a..cb3bfbbe 100644 --- a/request.js +++ b/request.js @@ -1,2 +1,4 @@ +"use strict" + var PromisePolyfill = require("./promise/promise") module.exports = require("./request/request")(window, PromisePolyfill) diff --git a/request/tests/test-jsonp.js b/request/tests/test-jsonp.js index 7042274c..076ab26e 100644 --- a/request/tests/test-jsonp.js +++ b/request/tests/test-jsonp.js @@ -7,7 +7,7 @@ var Promise = require("../../promise/promise") var parseQueryString = require("../../querystring/parse") o.spec("jsonp", function() { - var mock, jsonp, spy, complete + var mock, jsonp, complete o.beforeEach(function() { mock = xhrMock() var requestService = Request(mock, Promise) @@ -28,7 +28,6 @@ o.spec("jsonp", function() { }).then(done) }) o("first argument can be a string aliasing url property", function(done){ - var s = new Date mock.$defineRoutes({ "GET /item": function(request) { var queryData = parseQueryString(request.query) @@ -104,8 +103,8 @@ o.spec("jsonp", function() { return {status: 200, responseText: queryData["callback"] + "([])"} } }) - var promise = jsonp("/item", {background: true}).then(function() {}) - + jsonp("/item", {background: true}).then(function() {}) + setTimeout(function() { o(complete.callCount).equals(0) done() diff --git a/request/tests/test-request.js b/request/tests/test-request.js index 273d592c..7f965498 100644 --- a/request/tests/test-request.js +++ b/request/tests/test-request.js @@ -18,7 +18,6 @@ o.spec("xhr", function() { o.spec("success", function() { o("works via GET", function(done) { - var s = new Date mock.$defineRoutes({ "GET /item": function() { return {status: 200, responseText: JSON.stringify({a: 1})} @@ -31,7 +30,6 @@ o.spec("xhr", function() { }) }) o("implicit GET method", function(done){ - var s = new Date mock.$defineRoutes({ "GET /item": function() { return {status: 200, responseText: JSON.stringify({a: 1})} @@ -44,7 +42,6 @@ o.spec("xhr", function() { }) }) o("first argument can be a string aliasing url property", function(done){ - var s = new Date mock.$defineRoutes({ "GET /item": function() { return {status: 200, responseText: JSON.stringify({a: 1})} @@ -172,7 +169,7 @@ o.spec("xhr", function() { } mock.$defineRoutes({ - "GET /item": function(request) { + "GET /item": function() { return {status: 200, responseText: JSON.stringify([{id: 1}, {id: 2}, {id: 3}])} } }) @@ -186,7 +183,7 @@ o.spec("xhr", function() { } mock.$defineRoutes({ - "GET /item": function(request) { + "GET /item": function() { return {status: 200, responseText: JSON.stringify({id: 1})} } }) @@ -228,12 +225,12 @@ o.spec("xhr", function() { } mock.$defineRoutes({ - "GET /item": function(request) { + "GET /item": function() { return {status: 200, responseText: JSON.stringify({test: 123})} } }) xhr({method: "GET", url: "/item", deserialize: deserialize}).then(function(data) { - o(data).equals("{\"test\":123}") + o(data).equals('{"test":123}') }).then(done) }) o("deserialize parameter works in POST", function(done) { @@ -242,40 +239,40 @@ o.spec("xhr", function() { } mock.$defineRoutes({ - "POST /item": function(request) { + "POST /item": function() { return {status: 200, responseText: JSON.stringify({test: 123})} } }) xhr({method: "POST", url: "/item", deserialize: deserialize}).then(function(data) { - o(data).equals("{\"test\":123}") + o(data).equals('{"test":123}') }).then(done) }) o("extract parameter works in GET", function(done) { - var extract = function(data) { + var extract = function() { return JSON.stringify({test: 123}) } mock.$defineRoutes({ - "GET /item": function(request) { + "GET /item": function() { return {status: 200, responseText: ""} } }) xhr({method: "GET", url: "/item", extract: extract}).then(function(data) { - o(data).equals("{\"test\":123}") + o(data).equals('{"test":123}') }).then(done) }) o("extract parameter works in POST", function(done) { - var extract = function(data) { + var extract = function() { return JSON.stringify({test: 123}) } mock.$defineRoutes({ - "POST /item": function(request) { + "POST /item": function() { return {status: 200, responseText: ""} } }) xhr({method: "POST", url: "/item", extract: extract}).then(function(data) { - o(data).equals("{\"test\":123}") + o(data).equals('{"test":123}') }).then(done) }) o("ignores deserialize if extract is defined", function(done) { @@ -285,7 +282,7 @@ o.spec("xhr", function() { var deserialize = o.spy() mock.$defineRoutes({ - "GET /item": function(request) { + "GET /item": function() { return {status: 200, responseText: ""} } }) @@ -297,7 +294,7 @@ o.spec("xhr", function() { }) o("config parameter works", function(done) { mock.$defineRoutes({ - "POST /item": function(request) { + "POST /item": function() { return {status: 200, responseText: ""} } }) @@ -311,7 +308,7 @@ o.spec("xhr", function() { }) o("requests don't block each other", function(done) { mock.$defineRoutes({ - "GET /item": function(request) { + "GET /item": function() { return {status: 200, responseText: "[]"} } }) @@ -328,7 +325,7 @@ o.spec("xhr", function() { }) o("requests trigger finally once with a chained then", function(done) { mock.$defineRoutes({ - "GET /item": function(request) { + "GET /item": function() { return {status: 200, responseText: "[]"} } }) @@ -342,11 +339,11 @@ o.spec("xhr", function() { }) o("requests does not trigger finally when background: true", function(done) { mock.$defineRoutes({ - "GET /item": function(request) { + "GET /item": function() { return {status: 200, responseText: "[]"} } }) - var promise = xhr("/item", {background: true}).then(function() {}) + xhr("/item", {background: true}).then(function() {}) setTimeout(function() { o(complete.callCount).equals(0) @@ -355,7 +352,7 @@ o.spec("xhr", function() { }) o("headers are set when header arg passed", function(done) { mock.$defineRoutes({ - "POST /item": function(request) { + "POST /item": function() { return {status: 200, responseText: ""} } }) @@ -367,7 +364,7 @@ o.spec("xhr", function() { }) o("headers are with higher precedence than default headers", function(done) { mock.$defineRoutes({ - "POST /item": function(request) { + "POST /item": function() { return {status: 200, responseText: ""} } }) @@ -379,7 +376,7 @@ o.spec("xhr", function() { }) o("json headers are set to the correct default value", function(done) { mock.$defineRoutes({ - "POST /item": function(request) { + "POST /item": function() { return {status: 200, responseText: ""} } }) @@ -391,7 +388,6 @@ o.spec("xhr", function() { } }) o("doesn't fail on abort", function(done) { - var s = new Date mock.$defineRoutes({ "GET /item": function() { return {status: 200, responseText: JSON.stringify({a: 1})} @@ -410,9 +406,9 @@ o.spec("xhr", function() { done() }, 0) } - Object.defineProperty(xhr, 'onreadystatechange', { - set: function(val) { onreadystatechange = val } - , get: function() { return testonreadystatechange } + Object.defineProperty(xhr, "onreadystatechange", { + set: function(val) { onreadystatechange = val }, + get: function() { return testonreadystatechange } }) xhr.abort() } @@ -424,7 +420,6 @@ o.spec("xhr", function() { }) }) o("doesn't fail on file:// status 0", function(done) { - var s = new Date mock.$defineRoutes({ "GET /item": function() { return {status: 0, responseText: JSON.stringify({a: 1})} @@ -456,7 +451,7 @@ o.spec("xhr", function() { o.spec("failure", function() { o("rejects on server error", function(done) { mock.$defineRoutes({ - "GET /item": function(request) { + "GET /item": function() { return {status: 500, responseText: JSON.stringify({error: "error"})} } }) @@ -467,7 +462,7 @@ o.spec("xhr", function() { }) o("extends Error with JSON response", function(done) { mock.$defineRoutes({ - "GET /item": function(request) { + "GET /item": function() { return {status: 500, responseText: JSON.stringify({message: "error", stack: "error on line 1"})} } }) @@ -479,7 +474,7 @@ o.spec("xhr", function() { }) o("rejects on non-JSON server error", function(done) { mock.$defineRoutes({ - "GET /item": function(request) { + "GET /item": function() { return {status: 500, responseText: "error"} } }) @@ -489,7 +484,7 @@ o.spec("xhr", function() { }) o("triggers all branched catches upon rejection", function(done) { mock.$defineRoutes({ - "GET /item": function(request) { + "GET /item": function() { return {status: 500, responseText: "error"} } }) @@ -515,7 +510,7 @@ o.spec("xhr", function() { }) o("rejects on cors-like error", function(done) { mock.$defineRoutes({ - "GET /item": function(request) { + "GET /item": function() { return {status: 0} } }) diff --git a/route.js b/route.js index b8c8a15a..4e829527 100644 --- a/route.js +++ b/route.js @@ -1,3 +1,5 @@ +"use strict" + var redrawService = require("./redraw") -module.exports = require("./api/router")(window, redrawService) \ No newline at end of file +module.exports = require("./api/router")(window, redrawService) diff --git a/router/tests/test-getPath.js b/router/tests/test-getPath.js index 6c5dc2b2..9b2603fa 100644 --- a/router/tests/test-getPath.js +++ b/router/tests/test-getPath.js @@ -6,7 +6,7 @@ var Router = require("../../router/router") o.spec("Router.getPath", function() { void [{protocol: "http:", hostname: "localhost"}, {protocol: "file:", hostname: "/"}].forEach(function(env) { - void ["#", "?", "", "#!", "?!", '/foo'].forEach(function(prefix) { + void ["#", "?", "", "#!", "?!", "/foo"].forEach(function(prefix) { o.spec("using prefix `" + prefix + "` starting on " + env.protocol + "//" + env.hostname, function() { var $window, router, onRouteChange, onFail diff --git a/stream.js b/stream.js index 06dcd5d4..89e5baab 100644 --- a/stream.js +++ b/stream.js @@ -1 +1,3 @@ -module.exports = require("./stream/stream") \ No newline at end of file +"use strict" + +module.exports = require("./stream/stream") diff --git a/stream/tests/test-scan.js b/stream/tests/test-scan.js index 72ef0277..5b44cdab 100644 --- a/stream/tests/test-scan.js +++ b/stream/tests/test-scan.js @@ -22,7 +22,7 @@ o.spec("scan", function() { parent(7) parent("11") parent(undefined) - parent({ a: 1 }) + parent({a: 1}) var result = child() // deepEquals fails on arrays? @@ -32,4 +32,3 @@ o.spec("scan", function() { o(result[3]).deepEquals({a: 1}) }) }) - diff --git a/stream/tests/test-stream.js b/stream/tests/test-stream.js index 92e16620..e435c888 100644 --- a/stream/tests/test-stream.js +++ b/stream/tests/test-stream.js @@ -1,7 +1,6 @@ "use strict" var o = require("../../ospec/ospec") -var callAsync = require("../../test-utils/callAsync") var Stream = require("../stream") o.spec("stream", function() { @@ -105,7 +104,7 @@ o.spec("stream", function() { var streams = [] var a = Stream() var b = Stream() - var c = Stream.combine(function(a, b, changed) { + Stream.combine(function(a, b, changed) { streams = changed }, [a, b]) @@ -119,7 +118,7 @@ o.spec("stream", function() { var streams = [] var a = Stream(3) var b = Stream(5) - var c = Stream.combine(function(a, b, changed) { + Stream.combine(function(a, b, changed) { streams = changed }, [a, b]) @@ -130,7 +129,7 @@ o.spec("stream", function() { }) o("combine can return undefined", function() { var a = Stream(1) - var b = Stream.combine(function(a) { + var b = Stream.combine(function() { return undefined }, [a]) @@ -138,7 +137,7 @@ o.spec("stream", function() { }) o("combine can return stream", function() { var a = Stream(1) - var b = Stream.combine(function(a) { + var b = Stream.combine(function() { return Stream(2) }, [a]) @@ -146,7 +145,7 @@ o.spec("stream", function() { }) o("combine can return pending stream", function() { var a = Stream(1) - var b = Stream.combine(function(a) { + var b = Stream.combine(function() { return Stream() }, [a]) @@ -155,10 +154,9 @@ o.spec("stream", function() { o("combine can halt", function() { var count = 0 var a = Stream(1) - var b = Stream.combine(function(a) { + var b = Stream.combine(function() { return Stream.HALT - }, [a]) - ["fantasy-land/map"](function() { + }, [a])["fantasy-land/map"](function() { count++ return 1 }) @@ -170,7 +168,7 @@ o.spec("stream", function() { var a = Stream(1) var thrown = null; try { - var b = Stream.combine(spy, [a, '']) + Stream.combine(spy, [a, ""]) } catch (e) { thrown = e } @@ -210,8 +208,9 @@ o.spec("stream", function() { var a = Stream() var b = Stream() - var all = Stream.merge([a.map(id), b.map(id)]).map(function(data) { + Stream.merge([a.map(id), b.map(id)]).map(function(data) { value = data[0] + data[1] + return undefined }) a(1) @@ -344,7 +343,7 @@ o.spec("stream", function() { }) o("works with pending stream", function() { var stream = Stream(undefined) - var mapped = stream["fantasy-land/map"](function(value) {return Stream()}) + var mapped = stream["fantasy-land/map"](function() {return Stream()}) o(mapped()()).equals(undefined) }) diff --git a/test-utils/components.js b/test-utils/components.js index c25ad5da..1e6fdd72 100644 --- a/test-utils/components.js +++ b/test-utils/components.js @@ -1,24 +1,26 @@ +"use strict" + module.exports = [ { - kind: 'POJO', + kind: "POJO", create: function(methods) { - var res = {view: function() {return {tag:'div'}}} + var res = {view: function() {return {tag:"div"}}} Object.keys(methods || {}).forEach(function(m){res[m] = methods[m]}) return res } }, { - kind: 'constructible', + kind: "constructible", create: function(methods) { function res(){} - res.prototype.view = function() {return {tag:'div'}} + res.prototype.view = function() {return {tag:"div"}} Object.keys(methods || {}).forEach(function(m){res.prototype[m] = methods[m]}) return res } }, { - kind: 'closure', + kind: "closure", create: function(methods) { return function() { - var res = {view: function() {return {tag:'div'}}} + var res = {view: function() {return {tag:"div"}}} Object.keys(methods || {}).forEach(function(m){res[m] = methods[m]}) return res } diff --git a/test-utils/domMock.js b/test-utils/domMock.js index 5da93b98..a827070a 100644 --- a/test-utils/domMock.js +++ b/test-utils/domMock.js @@ -96,7 +96,7 @@ module.exports = function() { declList = declList.replace( /("(?:\\.|[^"\n])*"|'(?:\\.|[^'\n])*')|\/\*[\s\S]*?\*\//g, function(m, str){ - return str || '' + return str || "" } ) /*eslint-disable no-cond-assign*/ @@ -115,7 +115,7 @@ module.exports = function() { var activeElement var $window = { document: { - createElement: function(tag, is) { + createElement: function(tag) { var cssText = "" var style = {} Object.defineProperty(style, "cssText", { @@ -211,11 +211,11 @@ module.exports = function() { else this.setAttribute("class", value) }, focus: function() {activeElement = this}, - addEventListener: function(type, callback, useCapture) { + addEventListener: function(type, callback) { if (events[type] == null) events[type] = [callback] else events[type].push(callback) }, - removeEventListener: function(type, callback, useCapture) { + removeEventListener: function(type, callback) { if (events[type] != null) { var index = events[type].indexOf(callback) if (index > -1) events[type].splice(index, 1) @@ -241,7 +241,6 @@ module.exports = function() { } if (element.nodeName === "A") { - var href Object.defineProperty(element, "href", { get: function() {return this.attributes["href"] === undefined ? "" : "[FIXME implement]"}, set: function(value) {this.setAttribute("href", value)}, @@ -271,7 +270,9 @@ module.exports = function() { enumerable: true, }) } - + + /* eslint-disable radix */ + if (element.nodeName === "CANVAS") { Object.defineProperty(element, "width", { get: function() {return this.attributes["width"] ? Math.floor(parseInt(this.attributes["width"].nodeValue) || 0) : 300}, @@ -283,6 +284,8 @@ module.exports = function() { }) } + /* eslint-enable radix */ + function getOptions(element) { var options = [] for (var i = 0; i < element.childNodes.length; i++) { @@ -297,17 +300,18 @@ module.exports = function() { element.firstChild != null ? element.firstChild.nodeValue : "" } if (element.nodeName === "SELECT") { - var selectedValue, selectedIndex = 0 + // var selectedValue + var selectedIndex = 0 Object.defineProperty(element, "selectedIndex", { get: function() {return getOptions(this).length > 0 ? selectedIndex : -1}, set: function(value) { var options = getOptions(this) if (value >= 0 && value < options.length) { - selectedValue = getOptionValue(options[selectedIndex]) + // selectedValue = getOptionValue(options[selectedIndex]) selectedIndex = value } else { - selectedValue = "" + // selectedValue = "" selectedIndex = -1 } }, @@ -323,12 +327,12 @@ module.exports = function() { var stringValue = String(value) for (var i = 0; i < options.length; i++) { if (getOptionValue(options[i]) === stringValue) { - selectedValue = stringValue + // selectedValue = stringValue selectedIndex = i return } } - selectedValue = stringValue + // selectedValue = stringValue selectedIndex = -1 }, enumerable: true, diff --git a/test-utils/parseURL.js b/test-utils/parseURL.js index f5e76e8d..e60cc531 100644 --- a/test-utils/parseURL.js +++ b/test-utils/parseURL.js @@ -3,7 +3,7 @@ module.exports = function parseURL(url, root) { var data = {} var protocolIndex = url.indexOf("://") - var pathnameIndex = protocolIndex > - 1 ? url.indexOf("/", protocolIndex + 3) : url.indexOf("/") + var pathnameIndex = protocolIndex > -1 ? url.indexOf("/", protocolIndex + 3) : url.indexOf("/") var searchIndex = url.indexOf("?") var hashIndex = url.indexOf("#") if ((pathnameIndex > searchIndex && searchIndex > -1) || (pathnameIndex > hashIndex && hashIndex > -1)) pathnameIndex = -1 diff --git a/test-utils/pushStateMock.js b/test-utils/pushStateMock.js index 91e7a136..ebd963fd 100644 --- a/test-utils/pushStateMock.js +++ b/test-utils/pushStateMock.js @@ -4,7 +4,7 @@ var parseURL = require("../test-utils/parseURL") module.exports = function(options) { if (options == null) options = {} - + var $window = options.window || {} var protocol = options.protocol || "http:" var hostname = options.hostname || "localhost" @@ -33,7 +33,7 @@ module.exports = function(options) { } return isNew } - + function prefix(prefix, value) { if (value === "") return "" return (value.charAt(0) !== prefix ? prefix : "") + value diff --git a/test-utils/tests/test-browserMock.js b/test-utils/tests/test-browserMock.js index d47c58ce..861f1ef0 100644 --- a/test-utils/tests/test-browserMock.js +++ b/test-utils/tests/test-browserMock.js @@ -17,7 +17,7 @@ o.spec("browserMock", function() { }) o("$window.onhashchange can be reached from the pushStateMock functions", function(done) { $window.onhashchange = o.spy() - $window.location.hash = '#a' + $window.location.hash = "#a" callAsync(function(){ o($window.onhashchange.callCount).equals(1) @@ -33,7 +33,7 @@ o.spec("browserMock", function() { }) o("$window.onunload can be reached from the pushStateMock functions", function() { $window.onunload = o.spy() - $window.location.href = '/a' + $window.location.href = "/a" o($window.onunload.callCount).equals(1) }) diff --git a/test-utils/tests/test-components.js b/test-utils/tests/test-components.js index cc9a091b..30ea6175 100644 --- a/test-utils/tests/test-components.js +++ b/test-utils/tests/test-components.js @@ -6,8 +6,8 @@ var components = require("../../test-utils/components") o.spec("test-utils/components", function() { var test = o.spy(function(component) { return function() { - o('works', function() { - o(typeof component.kind).equals('string') + o("works", function() { + o(typeof component.kind).equals("string") var methods = {oninit: function(){}, view: function(){}} @@ -21,7 +21,7 @@ o.spec("test-utils/components", function() { cmp2 = new (component.create(methods)) } else if (component.kind === "closure") { cmp1 = component.create()() - cmp2 = component.create(methods)() + cmp2 = component.create(methods)() } else { throw new Error("unexpected component kind") } @@ -34,7 +34,7 @@ o.spec("test-utils/components", function() { o(vnode != null).equals(true) o(vnode).deepEquals({tag: "div"}) - if (component.kind !== 'constructible') { + if (component.kind !== "constructible") { o(cmp2).deepEquals(methods) } else { // deepEquals doesn't search the prototype, do it manually diff --git a/test-utils/tests/test-domMock.js b/test-utils/tests/test-domMock.js index edd896d5..aee68832 100644 --- a/test-utils/tests/test-domMock.js +++ b/test-utils/tests/test-domMock.js @@ -321,7 +321,7 @@ o.spec("domMock", function() { o(div.getAttribute("id")).equals("aaa") }) }) - + o.spec("setAttribute", function() { o("works", function() { var div = $document.createElement("div") @@ -393,7 +393,6 @@ o.spec("domMock", function() { o.spec("textContent", function() { o("works", function() { var div = $document.createElement("div") - var a = $document.createElement("a") div.textContent = "aaa" o(div.childNodes.length).equals(1) @@ -402,7 +401,6 @@ o.spec("domMock", function() { }) o("works with empty string", function() { var div = $document.createElement("div") - var a = $document.createElement("a") div.textContent = "" o(div.childNodes.length).equals(0) @@ -514,8 +512,8 @@ o.spec("domMock", function() { var div = $document.createElement("div") div.style.cssText = "background: url(';'); font-family: \";\"" - o(div.style.background).equals("url(';')") - o(div.style.fontFamily).equals("\";\"") + o(div.style.background).equals("url(';')") + o(div.style.fontFamily).equals('";"') o(div.style.cssText).equals("background: url(';'); font-family: \";\";") }) o("comments in style.cssText are stripped", function(){ @@ -534,9 +532,10 @@ o.spec("domMock", function() { }) o("setting style throws", function () { + var div = $document.createElement("div") var err = false try { - div.style = '' + div.style = "" } catch (e) { err = e } @@ -919,55 +918,55 @@ o.spec("domMock", function() { o.spec("canvas width and height", function() { o("setting property works", function() { var canvas = $document.createElement("canvas") - + canvas.width = 100 o(canvas.attributes["width"].nodeValue).equals("100") o(canvas.width).equals(100) - + canvas.height = 100 o(canvas.attributes["height"].nodeValue).equals("100") o(canvas.height).equals(100) }) o("setting string casts to number", function() { var canvas = $document.createElement("canvas") - + canvas.width = "100" o(canvas.attributes["width"].nodeValue).equals("100") o(canvas.width).equals(100) - + canvas.height = "100" o(canvas.attributes["height"].nodeValue).equals("100") o(canvas.height).equals(100) }) o("setting float casts to int", function() { var canvas = $document.createElement("canvas") - + canvas.width = 1.2 o(canvas.attributes["width"].nodeValue).equals("1") o(canvas.width).equals(1) - + canvas.height = 1.2 o(canvas.attributes["height"].nodeValue).equals("1") o(canvas.height).equals(1) }) o("setting percentage fails", function() { var canvas = $document.createElement("canvas") - + canvas.width = "100%" o(canvas.attributes["width"].nodeValue).equals("0") o(canvas.width).equals(0) - + canvas.height = "100%" o(canvas.attributes["height"].nodeValue).equals("0") o(canvas.height).equals(0) }) o("setting attribute works", function() { var canvas = $document.createElement("canvas") - + canvas.setAttribute("width", "100%") o(canvas.attributes["width"].nodeValue).equals("100%") o(canvas.width).equals(100) - + canvas.setAttribute("height", "100%") o(canvas.attributes["height"].nodeValue).equals("100%") o(canvas.height).equals(100) diff --git a/test-utils/tests/test-pushStateMock.js b/test-utils/tests/test-pushStateMock.js index 3cb51716..41efacab 100644 --- a/test-utils/tests/test-pushStateMock.js +++ b/test-utils/tests/test-pushStateMock.js @@ -168,13 +168,13 @@ o.spec("pushStateMock", function() { }) o.spec("set protocol", function() { o("setting protocol throws", function(done) { - var old = $window.location.href try { $window.location.protocol = "https://" } catch (e) { - done() + return done() } + throw new Error("Expected an error") }) }) o.spec("set port", function() { @@ -413,17 +413,17 @@ o.spec("pushStateMock", function() { }) o("replaceState does not break forward history", function() { $window.onpopstate = o.spy() - + $window.history.pushState(null, null, "b") $window.history.back() o($window.onpopstate.callCount).equals(1) o($window.location.href).equals("http://localhost/") - + $window.history.replaceState(null, null, "a") - + o($window.location.href).equals("http://localhost/a") - + $window.history.forward() o($window.onpopstate.callCount).equals(2) @@ -431,46 +431,46 @@ o.spec("pushStateMock", function() { }) o("pushstate retains state", function() { $window.onpopstate = o.spy() - + $window.history.pushState({a: 1}, null, "#a") $window.history.pushState({b: 2}, null, "#b") - + o($window.onpopstate.callCount).equals(0) $window.history.back() - + o($window.onpopstate.callCount).equals(1) o($window.onpopstate.args[0].type).equals("popstate") o($window.onpopstate.args[0].state).deepEquals({a: 1}) $window.history.back() - + o($window.onpopstate.callCount).equals(2) o($window.onpopstate.args[0].type).equals("popstate") o($window.onpopstate.args[0].state).equals(null) $window.history.forward() - + o($window.onpopstate.callCount).equals(3) o($window.onpopstate.args[0].type).equals("popstate") o($window.onpopstate.args[0].state).deepEquals({a: 1}) $window.history.forward() - + o($window.onpopstate.callCount).equals(4) o($window.onpopstate.args[0].type).equals("popstate") o($window.onpopstate.args[0].state).deepEquals({b: 2}) }) o("replacestate replaces state", function() { $window.onpopstate = o.spy(pop) - + $window.history.replaceState({a: 1}, null, "a") - + o($window.history.state).deepEquals({a: 1}) - + $window.history.pushState(null, null, "a") $window.history.back() - + function pop(e) { o(e.state).deepEquals({a: 1}) o($window.history.state).deepEquals({a: 1}) diff --git a/test-utils/tests/test-xhrMock.js b/test-utils/tests/test-xhrMock.js index cef2d9ca..8bdfcf21 100644 --- a/test-utils/tests/test-xhrMock.js +++ b/test-utils/tests/test-xhrMock.js @@ -5,13 +5,13 @@ var xhrMock = require("../../test-utils/xhrMock") var parseQueryString = require("../../querystring/parse") o.spec("xhrMock", function() { - var $window, ajax + var $window o.beforeEach(function() { $window = xhrMock() }) o.spec("xhr", function() { - o("works", function(done, timeout) { + o("works", function(done) { $window.$defineRoutes({ "GET /item": function(request) { o(request.url).equals("/item") @@ -29,7 +29,7 @@ o.spec("xhrMock", function() { } xhr.send() }) - o("works w/ search", function(done, timeout) { + o("works w/ search", function(done) { $window.$defineRoutes({ "GET /item": function(request) { o(request.query).equals("?a=b") @@ -45,7 +45,7 @@ o.spec("xhrMock", function() { } xhr.send() }) - o("works w/ body", function(done, timeout) { + o("works w/ body", function(done) { $window.$defineRoutes({ "POST /item": function(request) { o(request.body).equals("a=b") @@ -61,7 +61,7 @@ o.spec("xhrMock", function() { } xhr.send("a=b") }) - o("handles routing error", function(done, timeout) { + o("handles routing error", function(done) { var xhr = new $window.XMLHttpRequest() xhr.open("GET", "/nonexistent") xhr.onreadystatechange = function() { @@ -113,7 +113,7 @@ o.spec("xhrMock", function() { done() } }) - o("works with other querystring params", function(done, timeout) { + o("works with other querystring params", function(done) { $window.$defineRoutes({ "GET /test": function(request) { var queryData = parseQueryString(request.query) diff --git a/test-utils/xhrMock.js b/test-utils/xhrMock.js index 57c2887f..d3bbf5b8 100644 --- a/test-utils/xhrMock.js +++ b/test-utils/xhrMock.js @@ -6,7 +6,7 @@ var parseQueryString = require("../querystring/parse") module.exports = function() { var routes = {} - var callback = "callback" + // var callback = "callback" var serverErrorHandler = function(url) { return {status: 500, responseText: "server error, most likely the URL was not defined " + url} } @@ -43,7 +43,6 @@ module.exports = function() { } self.readyState = 4 if (args.async === true) { - var s = new Date callAsync(function() { if (typeof self.onreadystatechange === "function") self.onreadystatechange() }) @@ -64,7 +63,7 @@ module.exports = function() { var urlData = parseURL(element.src, {protocol: "http:", hostname: "localhost", port: "", pathname: "/"}) var handler = routes["GET " + urlData.pathname] || serverErrorHandler.bind(null, element.src) var data = handler({url: urlData.pathname, query: urlData.search, body: null}) - var query = parseQueryString(urlData.search) + parseQueryString(urlData.search) callAsync(function() { if (data.status === 200) { new Function("$window", "with ($window) return " + data.responseText).call($window, $window) @@ -83,8 +82,8 @@ module.exports = function() { $defineRoutes: function(rules) { routes = rules }, - $defineJSONPCallbackKey: function(key) { - callback = key + $defineJSONPCallbackKey: function(/* key */) { + // callback = key }, } return $window diff --git a/tests/test-api.js b/tests/test-api.js index ec57a0f3..3240141c 100644 --- a/tests/test-api.js +++ b/tests/test-api.js @@ -10,7 +10,7 @@ o.spec("api", function() { o.beforeEach(function() { var mock = browserMock() if (typeof global !== "undefined") global.window = mock - m = require("../mithril") + m = require("../mithril") // eslint-disable-line global-require }) o.spec("m", function() { @@ -174,4 +174,4 @@ o.spec("api", function() { }) }) }) -}) \ No newline at end of file +})