Skip to content

Commit c40b775

Browse files
committed
helping to uglify
1 parent 457842a commit c40b775

File tree

9 files changed

+24
-22
lines changed

9 files changed

+24
-22
lines changed

lib/browser/compiler/core.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ function compileScripts(fn) {
6161
riot.compile = function(arg, fn) {
6262

6363
// string
64-
if (typeof arg == 'string') {
64+
if (typeof arg === T_STRING) {
6565

6666
// compile & return
6767
if (arg.trim()[0] == '<') {
@@ -80,7 +80,7 @@ riot.compile = function(arg, fn) {
8080
}
8181

8282
// must be a function
83-
if (typeof arg != 'function') arg = undefined
83+
if (typeof arg !== 'function') arg = undefined
8484

8585
// all compiled
8686
if (ready) return arg && arg()

lib/browser/compiler/wrap/prefix.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,6 @@
44
else if (typeof exports === 'object')
55
factory(require('riot'))
66
else factory(root.riot)
7-
}(this, function (riot) {
7+
}(this, function (riot, undefined) {
8+
9+
var T_STRING = 'string'

lib/browser/observable.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ riot.observable = function(el) {
88

99
el.on = function(events, fn) {
1010
if (isFunction(fn)) {
11-
fn._id = typeof fn._id == 'undefined' ? _id++ : fn._id
11+
if (typeof fn.id === T_UNDEF) fn._id = _id++
1212

1313
events.replace(/\S+/g, function(name, pos) {
1414
(callbacks[name] = callbacks[name] || []).push(fn)
@@ -25,7 +25,7 @@ riot.observable = function(el) {
2525
if (fn) {
2626
var arr = callbacks[name]
2727
for (var i = 0, cb; (cb = arr && arr[i]); ++i) {
28-
if (cb._id == fn._id) { arr.splice(i, 1); i-- }
28+
if (cb._id == fn._id) arr.splice(i--, 1)
2929
}
3030
} else {
3131
callbacks[name] = []

lib/browser/router.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11

2-
;(function(riot, evt, window) {
2+
;(function(riot, evt, win) {
33

44
// browsers only
5-
if (!window) return
5+
if (!win) return
66

7-
var loc = window.location,
7+
var loc = win.location,
88
fns = riot.observable(),
9-
win = window,
109
started = false,
1110
current
1211

lib/browser/tag/tag.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ function Tag(impl, conf, innerHTML) {
7272

7373
function normalizeData(data) {
7474
for (var key in item) {
75-
if (typeof self[key] != 'undefined')
75+
if (typeof self[key] !== T_UNDEF)
7676
self[key] = data[key]
7777
}
7878
}
@@ -82,7 +82,7 @@ function Tag(impl, conf, innerHTML) {
8282
each(Object.keys(self.parent), function(k) {
8383
// some properties must be always in sync with the parent tag
8484
var mustSync = ~propsInSyncWithParent.indexOf(k)
85-
if (typeof self[k] == 'undefined' || mustSync) {
85+
if (typeof self[k] === T_UNDEF || mustSync) {
8686
// track the property to keep in sync
8787
// so we can keep it updated
8888
if (!mustSync) propsInSyncWithParent.push(k)
@@ -95,7 +95,7 @@ function Tag(impl, conf, innerHTML) {
9595
// inherit properties from the parent
9696
inheritFromParent()
9797
// normalize the tag properties in case an item object was initially passed
98-
if (typeof item == T_OBJECT || isArray(item)) {
98+
if (typeof item === T_OBJECT || isArray(item)) {
9999
normalizeData(data)
100100
item = data
101101
}
@@ -109,11 +109,11 @@ function Tag(impl, conf, innerHTML) {
109109

110110
this.mixin = function() {
111111
each(arguments, function(mix) {
112-
mix = typeof mix == 'string' ? riot.mixin(mix) : mix
112+
mix = typeof mix === T_STRING ? riot.mixin(mix) : mix
113113
each(Object.keys(mix), function(key) {
114114
// bind methods to self
115115
if (key != 'init')
116-
self[key] = typeof mix[key] == 'function' ? mix[key].bind(self) : mix[key]
116+
self[key] = isFunction(mix[key]) ? mix[key].bind(self) : mix[key]
117117
})
118118
// init method will be called automatically
119119
if (mix.init) mix.init.bind(self)()

lib/browser/tag/update.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ function update(expressions, tag) {
7272
remAttr(dom, attrName)
7373

7474
// event handler
75-
if (typeof value == 'function') {
75+
if (isFunction(value)) {
7676
setEventHandler(attrName, value, dom, tag)
7777

7878
// if- conditional
@@ -119,7 +119,7 @@ function update(expressions, tag) {
119119
value = attrName
120120
}
121121

122-
if (typeof value != 'object') dom.setAttribute(attrName, value)
122+
if (typeof value !== T_OBJECT) dom.setAttribute(attrName, value)
123123

124124
}
125125

lib/browser/wrap/prefix.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
/* Riot WIP, @license MIT, (c) 2015 Muut Inc. + contributors */
22

3-
;(function(window) {
3+
;(function(window, undefined) {
44
'use strict'
55
var riot = { version: 'WIP', settings: {} }
66

77
// This globals 'const' helps code size reduction
88

99
// for typeof == '' comparisons
1010
var T_STRING = 'string',
11-
T_OBJECT = 'object'
11+
T_OBJECT = 'object',
12+
T_UNDEF = 'undefined'
1213

1314
// for IE8 and rest of the world
1415
var isArray = Array.isArray || (function () {
@@ -18,5 +19,5 @@
1819

1920
// Version# for IE 8-11, 0 for others
2021
var ieVersion = (function (win) {
21-
return (win && win.document || {}).documentMode | 0
22-
})(window)
22+
return (window && window.document || {}).documentMode | 0
23+
})()

lib/browser/wrap/suffix.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
riot.util = { brackets: brackets, tmpl: tmpl }
44

55
// support CommonJS, AMD & browser
6-
if (typeof exports === 'object')
6+
if (typeof exports === T_OBJECT)
77
module.exports = riot
88
else if (typeof define === 'function' && define.amd)
99
define(function() { return window.riot = riot })

test/specs/compiler-browser.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -733,7 +733,7 @@ describe('Compiler Browser', function() {
733733
expect(normalizeHTML(root.getElementsByTagName('div')[0].innerHTML))
734734
.to.be('<p>zero = 0</p><p>one = 1</p><p>two = 2</p><p>three = 3</p>')
735735

736-
for (key in tag.obj)
736+
for (key in tag.obj) // eslint-disable-line guard-for-in
737737
tag.obj[key] = tag.obj[key] * 2
738738
tag.update()
739739
expect(normalizeHTML(root.getElementsByTagName('div')[0].innerHTML))

0 commit comments

Comments
 (0)