"use strict" and other linty fixes
This commit is contained in:
parent
aaa6de784b
commit
1cc5fa5ba7
50 changed files with 463 additions and 478 deletions
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
})
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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})
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue