Skip to content

Commit 1a8c3e4

Browse files
committed
Format code with prettier-eslint.
1 parent eb11b5f commit 1a8c3e4

File tree

5 files changed

+101
-154
lines changed

5 files changed

+101
-154
lines changed

js/compile.js

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
var regexp = /<script( id="([\w-]+)")? type="text\/x-tmpl"( id="([\w-]+)")?>([\s\S]+?)<\/script>/gi
2222
// A regular expression to match the helper function names:
2323
var helperRegexp = new RegExp(
24-
tmpl.helper.match(/\w+(?=\s*=\s*function\s*\()/g).join('\\s*\\(|') + '\\s*\\('
24+
tmpl.helper.match(/\w+(?=\s*=\s*function\s*\()/g).join('\\s*\\(|') +
25+
'\\s*\\('
2526
)
2627
// A list to store the function bodies:
2728
var list = []
@@ -31,12 +32,18 @@
3132
// Only add helper functions if they are used inside of the template:
3233
var helper = helperRegexp.test(str) ? tmpl.helper : ''
3334
var body = str.replace(tmpl.regexp, tmpl.func)
34-
if (helper || (/_e\s*\(/.test(body))) {
35+
if (helper || /_e\s*\(/.test(body)) {
3536
helper = '_e=tmpl.encode' + helper + ','
3637
}
37-
return 'function(' + tmpl.arg + ',tmpl){' +
38-
('var ' + helper + "_s='" + body + "';return _s;")
39-
.split("_s+='';").join('') + '}'
38+
return (
39+
'function(' +
40+
tmpl.arg +
41+
',tmpl){' +
42+
('var ' + helper + "_s='" + body + "';return _s;")
43+
.split("_s+='';")
44+
.join('') +
45+
'}'
46+
)
4047
}
4148
// Loop through the command line arguments:
4249
process.argv.forEach(function (file, index) {
@@ -77,4 +84,4 @@
7784
code = runtime.replace('{}', '{' + list.join(',') + '}')
7885
// Print the resulting code to the console output:
7986
console.log(code)
80-
}())
87+
})()

js/runtime.js

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@
1515
'use strict'
1616
var tmpl = function (id, data) {
1717
var f = tmpl.cache[id]
18-
return data ? f(data, tmpl) : function (data) {
19-
return f(data, tmpl)
20-
}
18+
return data
19+
? f(data, tmpl)
20+
: function (data) {
21+
return f(data, tmpl)
22+
}
2123
}
2224
tmpl.cache = {}
2325
tmpl.encReg = /[<>&"'\x00]/g // eslint-disable-line no-control-regex
@@ -29,12 +31,9 @@
2931
"'": '&#39;'
3032
}
3133
tmpl.encode = function (s) {
32-
return (s == null ? '' : '' + s).replace(
33-
tmpl.encReg,
34-
function (c) {
35-
return tmpl.encMap[c] || ''
36-
}
37-
)
34+
return (s == null ? '' : '' + s).replace(tmpl.encReg, function (c) {
35+
return tmpl.encMap[c] || ''
36+
})
3837
}
3938
if (typeof define === 'function' && define.amd) {
4039
define(function () {
@@ -45,4 +44,4 @@
4544
} else {
4645
$.tmpl = tmpl
4746
}
48-
}(this))
47+
})(this)

js/tmpl.js

Lines changed: 35 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -18,40 +18,51 @@
1818
'use strict'
1919
var tmpl = function (str, data) {
2020
var f = !/[^\w\-.:]/.test(str)
21-
? tmpl.cache[str] = tmpl.cache[str] || tmpl(tmpl.load(str))
22-
: new Function(// eslint-disable-line no-new-func
21+
? (tmpl.cache[str] = tmpl.cache[str] || tmpl(tmpl.load(str)))
22+
: new Function( // eslint-disable-line no-new-func
2323
tmpl.arg + ',tmpl',
24-
'var _e=tmpl.encode' + tmpl.helper + ",_s='" +
25-
str.replace(tmpl.regexp, tmpl.func) + "';return _s;"
24+
'var _e=tmpl.encode' +
25+
tmpl.helper +
26+
",_s='" +
27+
str.replace(tmpl.regexp, tmpl.func) +
28+
"';return _s;"
2629
)
27-
return data ? f(data, tmpl) : function (data) {
28-
return f(data, tmpl)
29-
}
30+
return data
31+
? f(data, tmpl)
32+
: function (data) {
33+
return f(data, tmpl)
34+
}
3035
}
3136
tmpl.cache = {}
3237
tmpl.load = function (id) {
3338
return document.getElementById(id).innerHTML
3439
}
3540
tmpl.regexp = /([\s'\\])(?!(?:[^{]|\{(?!%))*%\})|(?:\{%(=|#)([\s\S]+?)%\})|(\{%)|(%\})/g
3641
tmpl.func = function (s, p1, p2, p3, p4, p5) {
37-
if (p1) { // whitespace, quote and backspace in HTML context
38-
return {
39-
'\n': '\\n',
40-
'\r': '\\r',
41-
'\t': '\\t',
42-
' ': ' '
43-
}[p1] || '\\' + p1
42+
if (p1) {
43+
// whitespace, quote and backspace in HTML context
44+
return (
45+
{
46+
'\n': '\\n',
47+
'\r': '\\r',
48+
'\t': '\\t',
49+
' ': ' '
50+
}[p1] || '\\' + p1
51+
)
4452
}
45-
if (p2) { // interpolation: {%=prop%}, or unescaped: {%#prop%}
53+
if (p2) {
54+
// interpolation: {%=prop%}, or unescaped: {%#prop%}
4655
if (p2 === '=') {
4756
return "'+_e(" + p3 + ")+'"
4857
}
4958
return "'+(" + p3 + "==null?'':" + p3 + ")+'"
5059
}
51-
if (p4) { // evaluation start tag: {%
60+
if (p4) {
61+
// evaluation start tag: {%
5262
return "';"
5363
}
54-
if (p5) { // evaluation end tag: %}
64+
if (p5) {
65+
// evaluation end tag: %}
5566
return "_s+='"
5667
}
5768
}
@@ -64,16 +75,14 @@
6475
"'": '&#39;'
6576
}
6677
tmpl.encode = function (s) {
67-
return (s == null ? '' : '' + s).replace(
68-
tmpl.encReg,
69-
function (c) {
70-
return tmpl.encMap[c] || ''
71-
}
72-
)
78+
return (s == null ? '' : '' + s).replace(tmpl.encReg, function (c) {
79+
return tmpl.encMap[c] || ''
80+
})
7381
}
7482
tmpl.arg = 'o'
75-
tmpl.helper = ",print=function(s,e){_s+=e?(s==null?'':s):_e(s);}" +
76-
',include=function(s,d){_s+=tmpl(s,d);}'
83+
tmpl.helper =
84+
",print=function(s,e){_s+=e?(s==null?'':s):_e(s);}" +
85+
',include=function(s,d){_s+=tmpl(s,d);}'
7786
if (typeof define === 'function' && define.amd) {
7887
define(function () {
7988
return tmpl
@@ -83,4 +92,4 @@
8392
} else {
8493
$.tmpl = tmpl
8594
}
86-
}(this))
95+
})(this)

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,11 @@
2727
"eslint-plugin-promise": "^3.5.0",
2828
"eslint-plugin-standard": "^3.0.1",
2929
"mocha": "^3.5.0",
30+
"prettier-eslint-cli": "^4.2.1",
3031
"uglify-js": "^3.0.28"
3132
},
3233
"scripts": {
34+
"format": "prettier-eslint --no-semi --single-quote --write **/*.js",
3335
"lint": "eslint .",
3436
"unit": "mocha",
3537
"test": "npm run lint && npm run unit",

0 commit comments

Comments
 (0)