Skip to content

Commit b1d5710

Browse files
committed
Get extra details from second argument.
1 parent f87c943 commit b1d5710

File tree

1 file changed

+22
-11
lines changed

1 file changed

+22
-11
lines changed

src/JSLint.coffee

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,25 @@ JSLINT = ctx.JSLINT
1010

1111
VERBOSE = false
1212

13+
if process.argv.length < 4
14+
console.error JSON.stringify {errors:[{id:"NOARGS"}]}
15+
process.exit 1
16+
1317
try
14-
if process.argv.length < 3
15-
console.error JSON.stringify {errors:[{id:"INVALID"}]}
16-
process.exit 1
1718
filename = process.argv[2]
1819
script = fs.readFileSync filename, 'utf8'
1920
catch e
2021
console.error JSON.stringify {errors:[{id:"NOTFOUND"}]}
2122
process.exit 1
2223

24+
try
25+
overrideDetails = JSON.parse process.argv[3]
26+
catch e
27+
console.error JSON.stringify {errors:[{id:"INVALIDJSON"}]}
28+
process.exit 1
29+
2330
details = null
24-
re = /\/\*\!(?:FLO|P)IM_PLUGIN([\s\S]+)\*\//
31+
re = /\/\*\![A-Z_]+([\s\S]+)\*\//
2532
script = script.replace re, (header) ->
2633
matches = header.match re
2734
if matches
@@ -32,13 +39,16 @@ unless details?
3239
console.error JSON.stringify {errors:[{id:"NOHEADER"}]}
3340
process.exit 1
3441

35-
details.id = 2
36-
details.revision = 1
42+
for k,v of overrideDetails
43+
details[k] = v
44+
45+
id = parseInt details.id
46+
if isNaN(id) or !isFinite(id)
47+
console.error JSON.stringify {errors:[{id:"IDNAN"}]}
48+
process.exit 1
3749

3850
# Alias dependencies.
3951
accessList = details.access ? []
40-
accessList.unshift "app"
41-
accessList.unshift "plugin"
4252
for access in accessList
4353
script = " var #{access} = lib.#{access}();\n#{script}"
4454

@@ -117,7 +127,6 @@ walk = (ast) ->
117127
ast[2] = walk ast[2]
118128
ast[3] = walk ast[3]
119129
else if type is 'while'
120-
#skip
121130
ast[2] = walk ast[2]
122131
if ast[1][0] is 'assign'
123132
# Rewrite this as a for loop
@@ -230,6 +239,7 @@ walk = (ast) ->
230239
console.error "Unknown type: '#{type}'"
231240
console.error util.inspect ast, false, null, true
232241
return ast
242+
233243
ast = parser.parse script
234244
if VERBOSE
235245
console.log util.inspect ast, false, null, true
@@ -244,7 +254,6 @@ script = uglify.gen_code ast, beautify: true, indent_start:4, indent_level:2, qu
244254
if VERBOSE
245255
console.log script
246256

247-
script = script.replace /(\n|^)\/\/.*(\n|$)/g, "$2"
248257
num2alphabet = (num) ->
249258
chars = "ABCDEFGHIJ".split("")
250259
num = parseInt num
@@ -255,16 +264,18 @@ num2alphabet = (num) ->
255264
for i in [0...num.length]
256265
out += chars[parseInt num.charAt(i)]
257266
return out
258-
id = details.id
267+
259268
adsafeId = "ZZZ#{num2alphabet id}_"
260269
head = "<div id=\"#{adsafeId}\"><script>\n"
261270
foot = "</script>\n</div>"
262271
script = "#{head} ADSAFE.go(\"#{adsafeId}\", function (dom, lib) {\n \"use strict\";\n#{script}\n });#{foot}"
272+
263273
ok = JSLINT script, {
264274
adsafe: true, fragment: true, browser: true, safe: true, bitwise: true, continue: true, eqeq: true, es5: true, evil: false, forin: true, newcap: true, nomen: true, plusplus: true, regexp: true, undef: true, unparam: true, sloppy: true, stupid: true, sub: true, vars: true, white: true, css: true
265275
}, {
266276
plugin: false
267277
}
278+
268279
unless ok
269280
result = JSLINT.data()
270281
if VERBOSE

0 commit comments

Comments
 (0)