"use strict" and other linty fixes

This commit is contained in:
Isiah Meadows 2017-03-02 07:26:52 -05:00
parent aaa6de784b
commit 1cc5fa5ba7
50 changed files with 463 additions and 478 deletions

View file

@ -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

View file

@ -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",

1
.gitignore vendored
View file

@ -4,3 +4,4 @@ jsconfig.json
npm-debug.log
.vscode
.DS_Store
.eslintcache

View file

@ -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
}
@ -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<undefined>", 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<any>", 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

View file

@ -1,3 +1,5 @@
"use strict"
var m = require("./index")
if (typeof module !== "undefined") module["exports"] = m
else window.m = m

View file

@ -1,3 +1,4 @@
#!/usr/bin/env node
"use strict"
require("../cli")

View file

@ -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,33 +20,33 @@ 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")
@ -52,143 +54,143 @@ o.spec("bundler", function() {
})
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")
@ -196,12 +198,12 @@ o.spec("bundler", function() {
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")
@ -209,12 +211,12 @@ o.spec("bundler", function() {
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")
@ -222,12 +224,12 @@ o.spec("bundler", function() {
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")
@ -235,23 +237,23 @@ o.spec("bundler", function() {
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")
@ -259,13 +261,13 @@ o.spec("bundler", function() {
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")
@ -274,37 +276,37 @@ 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")
@ -313,45 +315,45 @@ 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")
@ -359,22 +361,22 @@ o.spec("bundler", function() {
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")

View file

@ -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 "<code>" + (a + b + c).replace(/\|/g, "&#124;") + "</code>"
})
.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(.) id="([^"]+?)">(.+?)<\/h.>/gim, function(match, n, id, text) { // fix anchors
return "<h" + n + " id=\"" + text.toLowerCase().replace(/<(\/?)code>/g, "").replace(/<a.*?>.+?<\/a>/g, "").replace(/\.|\[|\]|&quot;|\/|\(|\)/g, "").replace(/\s/g, "-") + "\">" + text + "</h" + n + ">"
return "<h" + n + ' id="' + text.toLowerCase().replace(/<(\/?)code>/g, "").replace(/<a.*?>.+?<\/a>/g, "").replace(/\.|\[|\]|&quot;|\/|\(|\)/g, "").replace(/\s/g, "-") + '">' + text + "</h" + n + ">"
})
fs.writeFileSync("../mithril/archive/v" + version + "/" + outputFilename.replace(/^docs\//, ""), html, "utf-8")
fs.writeFileSync("../mithril/" + outputFilename.replace(/^docs\//, ""), html, "utf-8")

View file

@ -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() {

View file

@ -1,3 +1,5 @@
"use strict"
var hyperscript = require("./render/hyperscript")
hyperscript.trust = require("./render/trust")

View file

@ -1,3 +1,5 @@
"use strict"
var redrawService = require("./redraw")
module.exports = require("./api/mount")(redrawService)

View file

@ -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)

View file

@ -1,3 +1,4 @@
/* eslint-disable no-bitwise, no-process-exit */
"use strict"
module.exports = new function init() {
@ -122,7 +123,7 @@ 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 += '*'
while (hasOwn.call(ctx, subject)) subject += "*"
}
return subject
}

View file

@ -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)

View file

@ -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()
})

View file

@ -1 +1,3 @@
"use strict"
module.exports = require("./api/redraw")(window)

View file

@ -1 +1,3 @@
"use strict"
module.exports = require("./render/render")(window)

View file

@ -16,15 +16,15 @@ o.spec("attributes", 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' } }
{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)
@ -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)
})

View file

@ -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,

View file

@ -1,3 +1,4 @@
/* eslint-disable no-script-url */
"use strict"
var o = require("../../ospec/ospec")

View file

@ -1,3 +1,5 @@
"use strict"
var o = require("../../ospec/ospec")
var m = require("../../render/hyperscript")

View file

@ -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"}

View file

@ -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
}

View file

@ -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])

View file

@ -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])

View file

@ -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"}

View file

@ -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
}

View file

@ -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])

View file

@ -900,7 +900,6 @@ o.spec("updateNodes", function() {
var updated = {tag: "b"}
render(root, vnode)
var dom = vnode.dom
render(root, updated)
o(vnode.dom).notEquals(updated.dom)

View file

@ -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}
}

View file

@ -1,2 +1,4 @@
"use strict"
var PromisePolyfill = require("./promise/promise")
module.exports = require("./request/request")(window, PromisePolyfill)

View file

@ -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,7 +103,7 @@ 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)

View file

@ -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}
}
})

View file

@ -1,3 +1,5 @@
"use strict"
var redrawService = require("./redraw")
module.exports = require("./api/router")(window, redrawService)

View file

@ -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

View file

@ -1 +1,3 @@
"use strict"
module.exports = require("./stream/stream")

View file

@ -32,4 +32,3 @@ o.spec("scan", function() {
o(result[3]).deepEquals({a: 1})
})
})

View file

@ -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)
})

View file

@ -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
}

View file

@ -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)},
@ -272,6 +271,8 @@ module.exports = function() {
})
}
/* 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,

View file

@ -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)
})

View file

@ -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(){}}
@ -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

View file

@ -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)
@ -515,7 +513,7 @@ o.spec("domMock", function() {
div.style.cssText = "background: url(';'); font-family: \";\""
o(div.style.background).equals("url(';')")
o(div.style.fontFamily).equals("\";\"")
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
}

View file

@ -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() {

View file

@ -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)

View file

@ -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

View file

@ -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() {