|
97
|
1 |
// jslint.js
|
|
|
2 |
// 2011-10-17
|
|
|
3 |
|
|
|
4 |
// Copyright (c) 2002 Douglas Crockford (www.JSLint.com)
|
|
|
5 |
|
|
|
6 |
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
7 |
// of this software and associated documentation files (the "Software"), to deal
|
|
|
8 |
// in the Software without restriction, including without limitation the rights
|
|
|
9 |
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
10 |
// copies of the Software, and to permit persons to whom the Software is
|
|
|
11 |
// furnished to do so, subject to the following conditions:
|
|
|
12 |
|
|
|
13 |
// The above copyright notice and this permission notice shall be included in
|
|
|
14 |
// all copies or substantial portions of the Software.
|
|
|
15 |
|
|
|
16 |
// The Software shall be used for Good, not Evil.
|
|
|
17 |
|
|
|
18 |
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
19 |
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
20 |
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
21 |
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
22 |
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
23 |
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
24 |
// SOFTWARE.
|
|
|
25 |
|
|
|
26 |
// WARNING: JSLint will hurt your feelings.
|
|
|
27 |
|
|
|
28 |
// JSLINT is a global function. It takes two parameters.
|
|
|
29 |
|
|
|
30 |
// var myResult = JSLINT(source, option);
|
|
|
31 |
|
|
|
32 |
// The first parameter is either a string or an array of strings. If it is a
|
|
|
33 |
// string, it will be split on '\n' or '\r'. If it is an array of strings, it
|
|
|
34 |
// is assumed that each string represents one line. The source can be a
|
|
|
35 |
// JavaScript text, or HTML text, or a JSON text, or a CSS text.
|
|
|
36 |
|
|
|
37 |
// The second parameter is an optional object of options that control the
|
|
|
38 |
// operation of JSLINT. Most of the options are booleans: They are all
|
|
|
39 |
// optional and have a default value of false. One of the options, predef,
|
|
|
40 |
// can be an array of names, which will be used to declare global variables,
|
|
|
41 |
// or an object whose keys are used as global names, with a boolean value
|
|
|
42 |
// that determines if they are assignable.
|
|
|
43 |
|
|
|
44 |
// If it checks out, JSLINT returns true. Otherwise, it returns false.
|
|
|
45 |
|
|
|
46 |
// If false, you can inspect JSLINT.errors to find out the problems.
|
|
|
47 |
// JSLINT.errors is an array of objects containing these properties:
|
|
|
48 |
|
|
|
49 |
// {
|
|
|
50 |
// line : The line (relative to 0) at which the lint was found
|
|
|
51 |
// character : The character (relative to 0) at which the lint was found
|
|
|
52 |
// reason : The problem
|
|
|
53 |
// evidence : The text line in which the problem occurred
|
|
|
54 |
// raw : The raw message before the details were inserted
|
|
|
55 |
// a : The first detail
|
|
|
56 |
// b : The second detail
|
|
|
57 |
// c : The third detail
|
|
|
58 |
// d : The fourth detail
|
|
|
59 |
// }
|
|
|
60 |
|
|
|
61 |
// If a stopping error was found, a null will be the last element of the
|
|
|
62 |
// JSLINT.errors array. A stopping error means that JSLint was not confident
|
|
|
63 |
// enough to continue. It does not necessarily mean that the error was
|
|
|
64 |
// especially heinous.
|
|
|
65 |
|
|
|
66 |
// You can request a Function Report, which shows all of the functions
|
|
|
67 |
// and the parameters and vars that they use. This can be used to find
|
|
|
68 |
// implied global variables and other problems. The report is in HTML and
|
|
|
69 |
// can be inserted in an HTML <body>.
|
|
|
70 |
|
|
|
71 |
// var myReport = JSLINT.report(errors_only);
|
|
|
72 |
|
|
|
73 |
// If errors_only is true, then the report will be limited to only errors.
|
|
|
74 |
|
|
|
75 |
// You can request a data structure that contains JSLint's results.
|
|
|
76 |
|
|
|
77 |
// var myData = JSLINT.data();
|
|
|
78 |
|
|
|
79 |
// It returns a structure with this form:
|
|
|
80 |
|
|
|
81 |
// {
|
|
|
82 |
// errors: [
|
|
|
83 |
// {
|
|
|
84 |
// line: NUMBER,
|
|
|
85 |
// character: NUMBER,
|
|
|
86 |
// reason: STRING,
|
|
|
87 |
// evidence: STRING
|
|
|
88 |
// }
|
|
|
89 |
// ],
|
|
|
90 |
// functions: [
|
|
|
91 |
// {
|
|
|
92 |
// name: STRING,
|
|
|
93 |
// line: NUMBER,
|
|
|
94 |
// last: NUMBER,
|
|
|
95 |
// params: [
|
|
|
96 |
// {
|
|
|
97 |
// string: STRING
|
|
|
98 |
// }
|
|
|
99 |
// ],
|
|
|
100 |
// closure: [
|
|
|
101 |
// STRING
|
|
|
102 |
// ],
|
|
|
103 |
// var: [
|
|
|
104 |
// STRING
|
|
|
105 |
// ],
|
|
|
106 |
// exception: [
|
|
|
107 |
// STRING
|
|
|
108 |
// ],
|
|
|
109 |
// outer: [
|
|
|
110 |
// STRING
|
|
|
111 |
// ],
|
|
|
112 |
// unused: [
|
|
|
113 |
// STRING
|
|
|
114 |
// ],
|
|
|
115 |
// undef: [
|
|
|
116 |
// STRING
|
|
|
117 |
// ],
|
|
|
118 |
// global: [
|
|
|
119 |
// STRING
|
|
|
120 |
// ],
|
|
|
121 |
// label: [
|
|
|
122 |
// STRING
|
|
|
123 |
// ]
|
|
|
124 |
// }
|
|
|
125 |
// ],
|
|
|
126 |
// globals: [
|
|
|
127 |
// STRING
|
|
|
128 |
// ],
|
|
|
129 |
// member: {
|
|
|
130 |
// STRING: NUMBER
|
|
|
131 |
// },
|
|
|
132 |
// urls: [
|
|
|
133 |
// STRING
|
|
|
134 |
// ],
|
|
|
135 |
// json: BOOLEAN
|
|
|
136 |
// }
|
|
|
137 |
|
|
|
138 |
// Empty arrays will not be included.
|
|
|
139 |
|
|
|
140 |
// You can obtain the parse tree that JSLint constructed while parsing. The
|
|
|
141 |
// latest tree is kept in JSLINT.tree. A nice stringication can be produced
|
|
|
142 |
// with
|
|
|
143 |
|
|
|
144 |
// JSON.stringify(JSLINT.tree, [
|
|
|
145 |
// 'string', 'arity', 'name', 'first',
|
|
|
146 |
// 'second', 'third', 'block', 'else'
|
|
|
147 |
// ], 4));
|
|
|
148 |
|
|
|
149 |
// JSLint provides three directives. They look like slashstar comments, and
|
|
|
150 |
// allow for setting options, declaring global variables, and establishing a
|
|
|
151 |
// set of allowed property names.
|
|
|
152 |
|
|
|
153 |
// These directives respect function scope.
|
|
|
154 |
|
|
|
155 |
// The jslint directive is a special comment that can set one or more options.
|
|
|
156 |
// The current option set is
|
|
|
157 |
|
|
|
158 |
// adsafe true, if ADsafe rules should be enforced
|
|
|
159 |
// bitwise true, if bitwise operators should be allowed
|
|
|
160 |
// browser true, if the standard browser globals should be predefined
|
|
|
161 |
// cap true, if upper case HTML should be allowed
|
|
|
162 |
// confusion true, if types can be used inconsistently
|
|
|
163 |
// 'continue' true, if the continuation statement should be tolerated
|
|
|
164 |
// css true, if CSS workarounds should be tolerated
|
|
|
165 |
// debug true, if debugger statements should be allowed
|
|
|
166 |
// devel true, if logging should be allowed (console, alert, etc.)
|
|
|
167 |
// eqeq true, if == should be allowed
|
|
|
168 |
// es5 true, if ES5 syntax should be allowed
|
|
|
169 |
// evil true, if eval should be allowed
|
|
|
170 |
// forin true, if for in statements need not filter
|
|
|
171 |
// fragment true, if HTML fragments should be allowed
|
|
|
172 |
// indent the indentation factor
|
|
|
173 |
// maxerr the maximum number of errors to allow
|
|
|
174 |
// maxlen the maximum length of a source line
|
|
|
175 |
// newcap true, if constructor names capitalization is ignored
|
|
|
176 |
// node true, if Node.js globals should be predefined
|
|
|
177 |
// nomen true, if names may have dangling _
|
|
|
178 |
// on true, if HTML event handlers should be allowed
|
|
|
179 |
// passfail true, if the scan should stop on first error
|
|
|
180 |
// plusplus true, if increment/decrement should be allowed
|
|
|
181 |
// properties true, if all property names must be declared with /*properties*/
|
|
|
182 |
// regexp true, if the . should be allowed in regexp literals
|
|
|
183 |
// rhino true, if the Rhino environment globals should be predefined
|
|
|
184 |
// undef true, if variables can be declared out of order
|
|
|
185 |
// unparam true, if unused parameters should be tolerated
|
|
|
186 |
// safe true, if use of some browser features should be restricted
|
|
|
187 |
// sloppy true, if the 'use strict'; pragma is optional
|
|
|
188 |
// sub true, if all forms of subscript notation are tolerated
|
|
|
189 |
// vars true, if multiple var statements per function should be allowed
|
|
|
190 |
// white true, if sloppy whitespace is tolerated
|
|
|
191 |
// widget true if the Yahoo Widgets globals should be predefined
|
|
|
192 |
// windows true, if MS Windows-specific globals should be predefined
|
|
|
193 |
|
|
|
194 |
// For example:
|
|
|
195 |
|
|
|
196 |
/*jslint
|
|
|
197 |
evil: true, nomen: true, regexp: true
|
|
|
198 |
*/
|
|
|
199 |
|
|
|
200 |
// The properties directive declares an exclusive list of property names.
|
|
|
201 |
// Any properties named in the program that are not in the list will
|
|
|
202 |
// produce a warning.
|
|
|
203 |
|
|
|
204 |
// For example:
|
|
|
205 |
|
|
|
206 |
/*properties
|
|
|
207 |
'\b': string, '\t': string, '\n': string, '\f': string, '\r': string,
|
|
|
208 |
'!=': boolean, '!==': boolean, '"': string, '%': boolean, '\'': string,
|
|
|
209 |
'(begin)', '(breakage)': number, '(complexity)', '(confusion)': boolean,
|
|
|
210 |
'(context)': object, '(error)', '(identifier)', '(line)': number,
|
|
|
211 |
'(loopage)': number, '(name)', '(old_property_type)', '(params)',
|
|
|
212 |
'(scope)': object, '(token)', '(vars)', '(verb)', '*': boolean,
|
|
|
213 |
'+': boolean, '-': boolean, '/': *, '<': boolean, '<=': boolean,
|
|
|
214 |
'==': boolean, '===': boolean, '>': boolean, '>=': boolean,
|
|
|
215 |
ADSAFE: boolean, Array, Date, E: string, Function, LN10: string,
|
|
|
216 |
LN2: string, LOG10E: string, LOG2E: string, MAX_VALUE: string,
|
|
|
217 |
MIN_VALUE: string, NEGATIVE_INFINITY: string, Object, PI: string,
|
|
|
218 |
POSITIVE_INFINITY: string, SQRT1_2: string, SQRT2: string, '\\': string,
|
|
|
219 |
a: object, a_label: string, a_not_allowed: string, a_not_defined: string,
|
|
|
220 |
a_scope: string, abbr: object, acronym: object, address: object, adsafe,
|
|
|
221 |
adsafe_a: string, adsafe_autocomplete: string, adsafe_bad_id: string,
|
|
|
222 |
adsafe_div: string, adsafe_fragment: string, adsafe_go: string,
|
|
|
223 |
adsafe_html: string, adsafe_id: string, adsafe_id_go: string,
|
|
|
224 |
adsafe_lib: string, adsafe_lib_second: string, adsafe_missing_id: string,
|
|
|
225 |
adsafe_name_a: string, adsafe_placement: string, adsafe_prefix_a: string,
|
|
|
226 |
adsafe_script: string, adsafe_source: string, adsafe_subscript_a: string,
|
|
|
227 |
adsafe_tag: string, all: boolean, already_defined: string, and: string,
|
|
|
228 |
applet: object, apply: string, approved: array, area: object,
|
|
|
229 |
arity: string, article: object, aside: object, assign: boolean,
|
|
|
230 |
assign_exception: string, assignment_function_expression: string,
|
|
|
231 |
at: number, attribute_case_a: string, audio: object, autocomplete: string,
|
|
|
232 |
avoid_a: string, b: *, background: array, 'background-attachment': array,
|
|
|
233 |
'background-color': array, 'background-image': array,
|
|
|
234 |
'background-position': array, 'background-repeat': array,
|
|
|
235 |
bad_assignment: string, bad_color_a: string, bad_constructor: string,
|
|
|
236 |
bad_entity: string, bad_html: string, bad_id_a: string, bad_in_a: string,
|
|
|
237 |
bad_invocation: string, bad_name_a: string, bad_new: string,
|
|
|
238 |
bad_number: string, bad_operand: string, bad_style: string,
|
|
|
239 |
bad_type: string, bad_url_a: string, bad_wrap: string, base: object,
|
|
|
240 |
bdo: object, big: object, bind: string, bitwise: boolean, block: array,
|
|
|
241 |
blockquote: object, body: object, border: array, 'border-bottom': array,
|
|
|
242 |
'border-bottom-color', 'border-bottom-left-radius',
|
|
|
243 |
'border-bottom-right-radius', 'border-bottom-style': array,
|
|
|
244 |
'border-bottom-width', 'border-collapse': array, 'border-color': array,
|
|
|
245 |
'border-left': array, 'border-left-color', 'border-left-style': array,
|
|
|
246 |
'border-left-width', 'border-radius', 'border-right': array,
|
|
|
247 |
'border-right-color', 'border-right-style': array, 'border-right-width',
|
|
|
248 |
'border-spacing': array, 'border-style': array, 'border-top': array,
|
|
|
249 |
'border-top-color', 'border-top-left-radius', 'border-top-right-radius',
|
|
|
250 |
'border-top-style': array, 'border-top-width', 'border-width': array,
|
|
|
251 |
bottom: array, br: object, braille: boolean, browser: boolean,
|
|
|
252 |
button: object, c, call: string, canvas: object, cap, caption: object,
|
|
|
253 |
'caption-side': array, ceil: string, center: object, charAt: *,
|
|
|
254 |
charCodeAt: *, character, cite: object, clear: array, clip: array, closure,
|
|
|
255 |
cm: boolean, code: object, col: object, colgroup: object, color,
|
|
|
256 |
combine_var: string, command: object, concat: string,
|
|
|
257 |
conditional_assignment: string, confusing_a: string,
|
|
|
258 |
confusing_regexp: string, confusion: boolean, constructor: string,
|
|
|
259 |
constructor_name_a: string, content: array, continue, control_a: string,
|
|
|
260 |
'counter-increment': array, 'counter-reset': array, create: *, css: string,
|
|
|
261 |
cursor: array, d, dangerous_comment: string, dangling_a: string,
|
|
|
262 |
data: function object, datalist: object, dd: object, debug,
|
|
|
263 |
defineProperties: string, defineProperty: string, del: object,
|
|
|
264 |
deleted: string, details: object, devel: boolean, dfn: object,
|
|
|
265 |
dialog: object, dir: object, direction: array, display: array,
|
|
|
266 |
disrupt: boolean, div: object, dl: object, dt: object, duplicate_a: string,
|
|
|
267 |
edge: string, edition: string, else, em: *, embed: object,
|
|
|
268 |
embossed: boolean, empty: boolean, 'empty-cells': array,
|
|
|
269 |
empty_block: string, empty_case: string, empty_class: string,
|
|
|
270 |
entityify: function, eqeq, errors: array, es5: string, eval, every: string,
|
|
|
271 |
evidence, evil: string, ex: boolean, exception, exec: *,
|
|
|
272 |
expected_a: string, expected_a_at_b_c: string, expected_a_b: string,
|
|
|
273 |
expected_a_b_from_c_d: string, expected_at_a: string,
|
|
|
274 |
expected_attribute_a: string, expected_attribute_value_a: string,
|
|
|
275 |
expected_class_a: string, expected_fraction_a: string,
|
|
|
276 |
expected_id_a: string, expected_identifier_a: string,
|
|
|
277 |
expected_identifier_a_reserved: string, expected_lang_a: string,
|
|
|
278 |
expected_linear_a: string, expected_media_a: string,
|
|
|
279 |
expected_name_a: string, expected_nonstandard_style_attribute: string,
|
|
|
280 |
expected_number_a: string, expected_operator_a: string,
|
|
|
281 |
expected_percent_a: string, expected_positive_a: string,
|
|
|
282 |
expected_pseudo_a: string, expected_selector_a: string,
|
|
|
283 |
expected_small_a: string, expected_space_a_b: string,
|
|
|
284 |
expected_string_a: string, expected_style_attribute: string,
|
|
|
285 |
expected_style_pattern: string, expected_tagname_a: string,
|
|
|
286 |
expected_type_a: string, f: string, fieldset: object, figure: object,
|
|
|
287 |
filter: *, first: *, flag, float: array, floor: *, font: *, 'font-family',
|
|
|
288 |
'font-size': array, 'font-size-adjust': array, 'font-stretch': array,
|
|
|
289 |
'font-style': array, 'font-variant': array, 'font-weight': array,
|
|
|
290 |
footer: object, for, forEach: *, for_if: string, forin, form: object,
|
|
|
291 |
fragment, frame: object, frameset: object, freeze: string, from: number,
|
|
|
292 |
fromCharCode: function, fud: function, funct: object, function,
|
|
|
293 |
function_block: string, function_eval: string, function_loop: string,
|
|
|
294 |
function_statement: string, function_strict: string, functions: array,
|
|
|
295 |
getDate: string, getDay: string, getFullYear: string, getHours: string,
|
|
|
296 |
getMilliseconds: string, getMinutes: string, getMonth: string,
|
|
|
297 |
getOwnPropertyDescriptor: string, getOwnPropertyNames: string,
|
|
|
298 |
getPrototypeOf: string, getSeconds: string, getTime: string,
|
|
|
299 |
getTimezoneOffset: string, getUTCDate: string, getUTCDay: string,
|
|
|
300 |
getUTCFullYear: string, getUTCHours: string, getUTCMilliseconds: string,
|
|
|
301 |
getUTCMinutes: string, getUTCMonth: string, getUTCSeconds: string,
|
|
|
302 |
getYear: string, global, globals, h1: object, h2: object, h3: object,
|
|
|
303 |
h4: object, h5: object, h6: object, handheld: boolean, hasOwnProperty: *,
|
|
|
304 |
head: object, header: object, height: array, hgroup: object, hr: object,
|
|
|
305 |
'hta:application': object, html: *, html_confusion_a: string,
|
|
|
306 |
html_handlers: string, i: object, id: string, identifier: boolean,
|
|
|
307 |
identifier_function: string, iframe: object, img: object, immed: boolean,
|
|
|
308 |
implied_evil: string, in, indent: number, indexOf: *, infix_in: string,
|
|
|
309 |
init: function, input: object, ins: object, insecure_a: string,
|
|
|
310 |
isAlpha: function, isArray: function boolean, isDigit: function,
|
|
|
311 |
isExtensible: string, isFrozen: string, isNaN: string,
|
|
|
312 |
isPrototypeOf: string, isSealed: string, join: *, jslint: function boolean,
|
|
|
313 |
json: boolean, kbd: object, keygen: object, keys: *, label: object,
|
|
|
314 |
label_a_b: string, labeled: boolean, lang: string, lastIndex: string,
|
|
|
315 |
lastIndexOf: *, lbp: number, leading_decimal_a: string, led: function,
|
|
|
316 |
left: array, legend: object, length: *, 'letter-spacing': array,
|
|
|
317 |
li: object, lib: boolean, line: number, 'line-height': array, link: object,
|
|
|
318 |
'list-style': array, 'list-style-image': array,
|
|
|
319 |
'list-style-position': array, 'list-style-type': array, map: *,
|
|
|
320 |
margin: array, 'margin-bottom', 'margin-left', 'margin-right',
|
|
|
321 |
'margin-top', mark: object, 'marker-offset': array, match: function,
|
|
|
322 |
'max-height': array, 'max-width': array, maxerr: number,
|
|
|
323 |
maxlen: number, member: object, menu: object, message, meta: object,
|
|
|
324 |
meter: object, 'min-height': function, 'min-width': function,
|
|
|
325 |
missing_a: string, missing_a_after_b: string, missing_option: string,
|
|
|
326 |
missing_property: string, missing_space_a_b: string, missing_url: string,
|
|
|
327 |
missing_use_strict: string, mixed: string, mm: boolean, mode: string,
|
|
|
328 |
move_invocation: string, move_var: string, n: string, name: string,
|
|
|
329 |
name_function: string, nav: object, nested_comment: string,
|
|
|
330 |
newcap: boolean, node: boolean, noframes: object, nomen, noscript: object,
|
|
|
331 |
not: string, not_a_constructor: string, not_a_defined: string,
|
|
|
332 |
not_a_function: string, not_a_label: string, not_a_scope: string,
|
|
|
333 |
not_greater: string, now: string, nud: function, number: number,
|
|
|
334 |
object: object, ol: object, on, opacity, open: boolean, optgroup: object,
|
|
|
335 |
option: object, outer: regexp, outline: array, 'outline-color': array,
|
|
|
336 |
'outline-style': array, 'outline-width', output: object, overflow: array,
|
|
|
337 |
'overflow-x': array, 'overflow-y': array, p: object, padding: array,
|
|
|
338 |
'padding-bottom': function, 'padding-left': function,
|
|
|
339 |
'padding-right': function, 'padding-top': function,
|
|
|
340 |
'page-break-after': array, 'page-break-before': array, param: object,
|
|
|
341 |
parameter_a_get_b: string, parameter_set_a: string, params: array,
|
|
|
342 |
paren: boolean, parent: string, parse: string, passfail, pc: boolean,
|
|
|
343 |
plusplus, pop: *, position: array, postscript: boolean, pre: object,
|
|
|
344 |
predef, preventExtensions: string, print: boolean, progress: object,
|
|
|
345 |
projection: boolean, properties: boolean, propertyIsEnumerable: string,
|
|
|
346 |
prototype: string, pt: boolean, push: *, px: boolean, q: object, quote,
|
|
|
347 |
quotes: array, r: string, radix: string, range: function, raw,
|
|
|
348 |
read_only: string, reason, redefinition_a: string, reduce: string,
|
|
|
349 |
reduceRight: string, regexp, replace: function, report: function,
|
|
|
350 |
reserved: boolean, reserved_a: string, reverse: string, rhino: boolean,
|
|
|
351 |
right: array, rp: object, rt: object, ruby: object, safe: boolean,
|
|
|
352 |
samp: object, scanned_a_b: string, screen: boolean, script: object,
|
|
|
353 |
seal: string, search: function, second: *, section: object, select: object,
|
|
|
354 |
setDate: string, setDay: string, setFullYear: string, setHours: string,
|
|
|
355 |
setMilliseconds: string, setMinutes: string, setMonth: string,
|
|
|
356 |
setSeconds: string, setTime: string, setTimezoneOffset: string,
|
|
|
357 |
setUTCDate: string, setUTCDay: string, setUTCFullYear: string,
|
|
|
358 |
setUTCHours: string, setUTCMilliseconds: string, setUTCMinutes: string,
|
|
|
359 |
setUTCMonth: string, setUTCSeconds: string, setYear: string, shift: *,
|
|
|
360 |
slash_equal: string, slice: string, sloppy, small: object, some: string,
|
|
|
361 |
sort: *, source: object, span: object, speech: boolean, splice: string,
|
|
|
362 |
split: function, src, statement_block: string, stopping: string,
|
|
|
363 |
strange_loop: string, strict: string, string: string, stringify: string,
|
|
|
364 |
strong: object, style: *, styleproperty: regexp, sub: object,
|
|
|
365 |
subscript: string, substr: *, substring: string, sup: object,
|
|
|
366 |
supplant: function, t: string, table: object, 'table-layout': array,
|
|
|
367 |
tag_a_in_b: string, tbody: object, td: object, test: *,
|
|
|
368 |
'text-align': array, 'text-decoration': array, 'text-indent': function,
|
|
|
369 |
'text-shadow': array, 'text-transform': array, textarea: object,
|
|
|
370 |
tfoot: object, th: object, thead: object, third: array, thru: number,
|
|
|
371 |
time: object, title: object, toDateString: string, toExponential: string,
|
|
|
372 |
toFixed: string, toISOString: string, toJSON: string,
|
|
|
373 |
toLocaleDateString: string, toLocaleLowerCase: string,
|
|
|
374 |
toLocaleString: string, toLocaleTimeString: string,
|
|
|
375 |
toLocaleUpperCase: string, toLowerCase: *, toPrecision: string,
|
|
|
376 |
toString: function, toTimeString: string, toUTCString: string,
|
|
|
377 |
toUpperCase: *, token: function, too_long: string, too_many: string,
|
|
|
378 |
top: array, tr: object, trailing_decimal_a: string, tree: string,
|
|
|
379 |
trim: string, tt: object, tty: boolean, tv: boolean, type: string,
|
|
|
380 |
type_confusion_a_b: string, u: object, ul: object, unclosed: string,
|
|
|
381 |
unclosed_comment: string, unclosed_regexp: string, undef: boolean,
|
|
|
382 |
undefined, unescaped_a: string, unexpected_a: string,
|
|
|
383 |
unexpected_char_a_b: string, unexpected_comment: string,
|
|
|
384 |
unexpected_property_a: string, unexpected_space_a_b: string,
|
|
|
385 |
'unicode-bidi': array, unnecessary_initialize: string,
|
|
|
386 |
unnecessary_use: string, unparam, unreachable_a_b: string,
|
|
|
387 |
unrecognized_style_attribute_a: string, unrecognized_tag_a: string,
|
|
|
388 |
unsafe: string, unshift: string, unused: array, url: string, urls: array,
|
|
|
389 |
use_array: string, use_braces: string, use_charAt: string,
|
|
|
390 |
use_object: string, use_or: string, use_param: string,
|
|
|
391 |
used_before_a: string, valueOf: string, var: object, var_a_not: string,
|
|
|
392 |
vars, 'vertical-align': array, video: object, visibility: array,
|
|
|
393 |
warn: boolean, was: object, weird_assignment: string,
|
|
|
394 |
weird_condition: string, weird_new: string, weird_program: string,
|
|
|
395 |
weird_relation: string, weird_ternary: string, white: boolean,
|
|
|
396 |
'white-space': array, widget: boolean, width: array, windows: boolean,
|
|
|
397 |
'word-spacing': array, 'word-wrap': array, wrap: boolean,
|
|
|
398 |
wrap_immediate: string, wrap_regexp: string, write_is_wrong: string,
|
|
|
399 |
writeable: boolean, 'z-index': array
|
|
|
400 |
*/
|
|
|
401 |
|
|
|
402 |
// The global directive is used to declare global variables that can
|
|
|
403 |
// be accessed by the program. If a declaration is true, then the variable
|
|
|
404 |
// is writeable. Otherwise, it is read-only.
|
|
|
405 |
|
|
|
406 |
// We build the application inside a function so that we produce only a single
|
|
|
407 |
// global variable. That function will be invoked immediately, and its return
|
|
|
408 |
// value is the JSLINT function itself. That function is also an object that
|
|
|
409 |
// can contain data and other functions.
|
|
|
410 |
|
|
|
411 |
var JSLINT = (function () {
|
|
|
412 |
'use strict';
|
|
|
413 |
|
|
|
414 |
function array_to_object(array, value) {
|
|
|
415 |
|
|
|
416 |
// Make an object from an array of keys and a common value.
|
|
|
417 |
|
|
|
418 |
var i, length = array.length, object = {};
|
|
|
419 |
for (i = 0; i < length; i += 1) {
|
|
|
420 |
object[array[i]] = value;
|
|
|
421 |
}
|
|
|
422 |
return object;
|
|
|
423 |
}
|
|
|
424 |
|
|
|
425 |
|
|
|
426 |
var adsafe_id, // The widget's ADsafe id.
|
|
|
427 |
adsafe_may, // The widget may load approved scripts.
|
|
|
428 |
adsafe_top, // At the top of the widget script.
|
|
|
429 |
adsafe_went, // ADSAFE.go has been called.
|
|
|
430 |
anonname, // The guessed name for anonymous functions.
|
|
|
431 |
approved, // ADsafe approved urls.
|
|
|
432 |
|
|
|
433 |
// These are operators that should not be used with the ! operator.
|
|
|
434 |
|
|
|
435 |
bang = {
|
|
|
436 |
'<' : true,
|
|
|
437 |
'<=' : true,
|
|
|
438 |
'==' : true,
|
|
|
439 |
'===': true,
|
|
|
440 |
'!==': true,
|
|
|
441 |
'!=' : true,
|
|
|
442 |
'>' : true,
|
|
|
443 |
'>=' : true,
|
|
|
444 |
'+' : true,
|
|
|
445 |
'-' : true,
|
|
|
446 |
'*' : true,
|
|
|
447 |
'/' : true,
|
|
|
448 |
'%' : true
|
|
|
449 |
},
|
|
|
450 |
|
|
|
451 |
// These are property names that should not be permitted in the safe subset.
|
|
|
452 |
|
|
|
453 |
banned = array_to_object([
|
|
|
454 |
'arguments', 'callee', 'caller', 'constructor', 'eval', 'prototype',
|
|
|
455 |
'stack', 'unwatch', 'valueOf', 'watch'
|
|
|
456 |
], true),
|
|
|
457 |
begin, // The root token
|
|
|
458 |
|
|
|
459 |
// browser contains a set of global names that are commonly provided by a
|
|
|
460 |
// web browser environment.
|
|
|
461 |
|
|
|
462 |
browser = array_to_object([
|
|
|
463 |
'clearInterval', 'clearTimeout', 'document', 'event', 'frames',
|
|
|
464 |
'history', 'Image', 'localStorage', 'location', 'name', 'navigator',
|
|
|
465 |
'Option', 'parent', 'screen', 'sessionStorage', 'setInterval',
|
|
|
466 |
'setTimeout', 'Storage', 'window', 'XMLHttpRequest'
|
|
|
467 |
], false),
|
|
|
468 |
|
|
|
469 |
// bundle contains the text messages.
|
|
|
470 |
|
|
|
471 |
bundle = {
|
|
|
472 |
a_label: "'{a}' is a statement label.",
|
|
|
473 |
a_not_allowed: "'{a}' is not allowed.",
|
|
|
474 |
a_not_defined: "'{a}' is not defined.",
|
|
|
475 |
a_scope: "'{a}' used out of scope.",
|
|
|
476 |
adsafe_a: "ADsafe violation: '{a}'.",
|
|
|
477 |
adsafe_autocomplete: "ADsafe autocomplete violation.",
|
|
|
478 |
adsafe_bad_id: "ADSAFE violation: bad id.",
|
|
|
479 |
adsafe_div: "ADsafe violation: Wrap the widget in a div.",
|
|
|
480 |
adsafe_fragment: "ADSAFE: Use the fragment option.",
|
|
|
481 |
adsafe_go: "ADsafe violation: Misformed ADSAFE.go.",
|
|
|
482 |
adsafe_html: "Currently, ADsafe does not operate on whole HTML " +
|
|
|
483 |
"documents. It operates on <div> fragments and .js files.",
|
|
|
484 |
adsafe_id: "ADsafe violation: id does not match.",
|
|
|
485 |
adsafe_id_go: "ADsafe violation: Missing ADSAFE.id or ADSAFE.go.",
|
|
|
486 |
adsafe_lib: "ADsafe lib violation.",
|
|
|
487 |
adsafe_lib_second: "ADsafe: The second argument to lib must be a function.",
|
|
|
488 |
adsafe_missing_id: "ADSAFE violation: missing ID_.",
|
|
|
489 |
adsafe_name_a: "ADsafe name violation: '{a}'.",
|
|
|
490 |
adsafe_placement: "ADsafe script placement violation.",
|
|
|
491 |
adsafe_prefix_a: "ADsafe violation: An id must have a '{a}' prefix",
|
|
|
492 |
adsafe_script: "ADsafe script violation.",
|
|
|
493 |
adsafe_source: "ADsafe unapproved script source.",
|
|
|
494 |
adsafe_subscript_a: "ADsafe subscript '{a}'.",
|
|
|
495 |
adsafe_tag: "ADsafe violation: Disallowed tag '{a}'.",
|
|
|
496 |
already_defined: "'{a}' is already defined.",
|
|
|
497 |
and: "The '&&' subexpression should be wrapped in parens.",
|
|
|
498 |
assign_exception: "Do not assign to the exception parameter.",
|
|
|
499 |
assignment_function_expression: "Expected an assignment or " +
|
|
|
500 |
"function call and instead saw an expression.",
|
|
|
501 |
attribute_case_a: "Attribute '{a}' not all lower case.",
|
|
|
502 |
avoid_a: "Avoid '{a}'.",
|
|
|
503 |
bad_assignment: "Bad assignment.",
|
|
|
504 |
bad_color_a: "Bad hex color '{a}'.",
|
|
|
505 |
bad_constructor: "Bad constructor.",
|
|
|
506 |
bad_entity: "Bad entity.",
|
|
|
507 |
bad_html: "Bad HTML string",
|
|
|
508 |
bad_id_a: "Bad id: '{a}'.",
|
|
|
509 |
bad_in_a: "Bad for in variable '{a}'.",
|
|
|
510 |
bad_invocation: "Bad invocation.",
|
|
|
511 |
bad_name_a: "Bad name: '{a}'.",
|
|
|
512 |
bad_new: "Do not use 'new' for side effects.",
|
|
|
513 |
bad_number: "Bad number '{a}'.",
|
|
|
514 |
bad_operand: "Bad operand.",
|
|
|
515 |
bad_style: "Bad style.",
|
|
|
516 |
bad_type: "Bad type.",
|
|
|
517 |
bad_url_a: "Bad url '{a}'.",
|
|
|
518 |
bad_wrap: "Do not wrap function literals in parens unless they " +
|
|
|
519 |
"are to be immediately invoked.",
|
|
|
520 |
combine_var: "Combine this with the previous 'var' statement.",
|
|
|
521 |
conditional_assignment: "Expected a conditional expression and " +
|
|
|
522 |
"instead saw an assignment.",
|
|
|
523 |
confusing_a: "Confusing use of '{a}'.",
|
|
|
524 |
confusing_regexp: "Confusing regular expression.",
|
|
|
525 |
constructor_name_a: "A constructor name '{a}' should start with " +
|
|
|
526 |
"an uppercase letter.",
|
|
|
527 |
control_a: "Unexpected control character '{a}'.",
|
|
|
528 |
css: "A css file should begin with @charset 'UTF-8';",
|
|
|
529 |
dangling_a: "Unexpected dangling '_' in '{a}'.",
|
|
|
530 |
dangerous_comment: "Dangerous comment.",
|
|
|
531 |
deleted: "Only properties should be deleted.",
|
|
|
532 |
duplicate_a: "Duplicate '{a}'.",
|
|
|
533 |
empty_block: "Empty block.",
|
|
|
534 |
empty_case: "Empty case.",
|
|
|
535 |
empty_class: "Empty class.",
|
|
|
536 |
es5: "This is an ES5 feature.",
|
|
|
537 |
evil: "eval is evil.",
|
|
|
538 |
expected_a: "Expected '{a}'.",
|
|
|
539 |
expected_a_b: "Expected '{a}' and instead saw '{b}'.",
|
|
|
540 |
expected_a_b_from_c_d: "Expected '{a}' to match '{b}' from line " +
|
|
|
541 |
"{c} and instead saw '{d}'.",
|
|
|
542 |
expected_at_a: "Expected an at-rule, and instead saw @{a}.",
|
|
|
543 |
expected_a_at_b_c: "Expected '{a}' at column {b}, not column {c}.",
|
|
|
544 |
expected_attribute_a: "Expected an attribute, and instead saw [{a}].",
|
|
|
545 |
expected_attribute_value_a: "Expected an attribute value and " +
|
|
|
546 |
"instead saw '{a}'.",
|
|
|
547 |
expected_class_a: "Expected a class, and instead saw .{a}.",
|
|
|
548 |
expected_fraction_a: "Expected a number between 0 and 1 and " +
|
|
|
549 |
"instead saw '{a}'",
|
|
|
550 |
expected_id_a: "Expected an id, and instead saw #{a}.",
|
|
|
551 |
expected_identifier_a: "Expected an identifier and instead saw '{a}'.",
|
|
|
552 |
expected_identifier_a_reserved: "Expected an identifier and " +
|
|
|
553 |
"instead saw '{a}' (a reserved word).",
|
|
|
554 |
expected_linear_a: "Expected a linear unit and instead saw '{a}'.",
|
|
|
555 |
expected_lang_a: "Expected a lang code, and instead saw :{a}.",
|
|
|
556 |
expected_media_a: "Expected a CSS media type, and instead saw '{a}'.",
|
|
|
557 |
expected_name_a: "Expected a name and instead saw '{a}'.",
|
|
|
558 |
expected_nonstandard_style_attribute: "Expected a non-standard " +
|
|
|
559 |
"style attribute and instead saw '{a}'.",
|
|
|
560 |
expected_number_a: "Expected a number and instead saw '{a}'.",
|
|
|
561 |
expected_operator_a: "Expected an operator and instead saw '{a}'.",
|
|
|
562 |
expected_percent_a: "Expected a percentage and instead saw '{a}'",
|
|
|
563 |
expected_positive_a: "Expected a positive number and instead saw '{a}'",
|
|
|
564 |
expected_pseudo_a: "Expected a pseudo, and instead saw :{a}.",
|
|
|
565 |
expected_selector_a: "Expected a CSS selector, and instead saw {a}.",
|
|
|
566 |
expected_small_a: "Expected a small positive integer and instead saw '{a}'",
|
|
|
567 |
expected_space_a_b: "Expected exactly one space between '{a}' and '{b}'.",
|
|
|
568 |
expected_string_a: "Expected a string and instead saw {a}.",
|
|
|
569 |
expected_style_attribute: "Excepted a style attribute, and instead saw '{a}'.",
|
|
|
570 |
expected_style_pattern: "Expected a style pattern, and instead saw '{a}'.",
|
|
|
571 |
expected_tagname_a: "Expected a tagName, and instead saw {a}.",
|
|
|
572 |
expected_type_a: "Expected a type, and instead saw {a}.",
|
|
|
573 |
for_if: "The body of a for in should be wrapped in an if " +
|
|
|
574 |
"statement to filter unwanted properties from the prototype.",
|
|
|
575 |
function_block: "Function statements should not be placed in blocks. " +
|
|
|
576 |
"Use a function expression or move the statement to the top of " +
|
|
|
577 |
"the outer function.",
|
|
|
578 |
function_eval: "The Function constructor is eval.",
|
|
|
579 |
function_loop: "Don't make functions within a loop.",
|
|
|
580 |
function_statement: "Function statements are not invocable. " +
|
|
|
581 |
"Wrap the whole function invocation in parens.",
|
|
|
582 |
function_strict: "Use the function form of 'use strict'.",
|
|
|
583 |
html_confusion_a: "HTML confusion in regular expression '<{a}'.",
|
|
|
584 |
html_handlers: "Avoid HTML event handlers.",
|
|
|
585 |
identifier_function: "Expected an identifier in an assignment " +
|
|
|
586 |
"and instead saw a function invocation.",
|
|
|
587 |
implied_evil: "Implied eval is evil. Pass a function instead of a string.",
|
|
|
588 |
infix_in: "Unexpected 'in'. Compare with undefined, or use the " +
|
|
|
589 |
"hasOwnProperty method instead.",
|
|
|
590 |
insecure_a: "Insecure '{a}'.",
|
|
|
591 |
isNaN: "Use the isNaN function to compare with NaN.",
|
|
|
592 |
label_a_b: "Label '{a}' on '{b}' statement.",
|
|
|
593 |
lang: "lang is deprecated.",
|
|
|
594 |
leading_decimal_a: "A leading decimal point can be confused with a dot: '.{a}'.",
|
|
|
595 |
missing_a: "Missing '{a}'.",
|
|
|
596 |
missing_a_after_b: "Missing '{a}' after '{b}'.",
|
|
|
597 |
missing_option: "Missing option value.",
|
|
|
598 |
missing_property: "Missing property name.",
|
|
|
599 |
missing_space_a_b: "Missing space between '{a}' and '{b}'.",
|
|
|
600 |
missing_url: "Missing url.",
|
|
|
601 |
missing_use_strict: "Missing 'use strict' statement.",
|
|
|
602 |
mixed: "Mixed spaces and tabs.",
|
|
|
603 |
move_invocation: "Move the invocation into the parens that " +
|
|
|
604 |
"contain the function.",
|
|
|
605 |
move_var: "Move 'var' declarations to the top of the function.",
|
|
|
606 |
name_function: "Missing name in function statement.",
|
|
|
607 |
nested_comment: "Nested comment.",
|
|
|
608 |
not: "Nested not.",
|
|
|
609 |
not_a_constructor: "Do not use {a} as a constructor.",
|
|
|
610 |
not_a_defined: "'{a}' has not been fully defined yet.",
|
|
|
611 |
not_a_function: "'{a}' is not a function.",
|
|
|
612 |
not_a_label: "'{a}' is not a label.",
|
|
|
613 |
not_a_scope: "'{a}' is out of scope.",
|
|
|
614 |
not_greater: "'{a}' should not be greater than '{b}'.",
|
|
|
615 |
parameter_a_get_b: "Unexpected parameter '{a}' in get {b} function.",
|
|
|
616 |
parameter_set_a: "Expected parameter (value) in set {a} function.",
|
|
|
617 |
radix: "Missing radix parameter.",
|
|
|
618 |
read_only: "Read only.",
|
|
|
619 |
redefinition_a: "Redefinition of '{a}'.",
|
|
|
620 |
reserved_a: "Reserved name '{a}'.",
|
|
|
621 |
scanned_a_b: "{a} ({b}% scanned).",
|
|
|
622 |
slash_equal: "A regular expression literal can be confused with '/='.",
|
|
|
623 |
statement_block: "Expected to see a statement and instead saw a block.",
|
|
|
624 |
stopping: "Stopping. ",
|
|
|
625 |
strange_loop: "Strange loop.",
|
|
|
626 |
strict: "Strict violation.",
|
|
|
627 |
subscript: "['{a}'] is better written in dot notation.",
|
|
|
628 |
tag_a_in_b: "A '<{a}>' must be within '<{b}>'.",
|
|
|
629 |
too_long: "Line too long.",
|
|
|
630 |
too_many: "Too many errors.",
|
|
|
631 |
trailing_decimal_a: "A trailing decimal point can be confused " +
|
|
|
632 |
"with a dot: '.{a}'.",
|
|
|
633 |
type: "type is unnecessary.",
|
|
|
634 |
type_confusion_a_b: "Type confusion: {a} and {b}.",
|
|
|
635 |
unclosed: "Unclosed string.",
|
|
|
636 |
unclosed_comment: "Unclosed comment.",
|
|
|
637 |
unclosed_regexp: "Unclosed regular expression.",
|
|
|
638 |
unescaped_a: "Unescaped '{a}'.",
|
|
|
639 |
unexpected_a: "Unexpected '{a}'.",
|
|
|
640 |
unexpected_char_a_b: "Unexpected character '{a}' in {b}.",
|
|
|
641 |
unexpected_comment: "Unexpected comment.",
|
|
|
642 |
unexpected_property_a: "Unexpected /*property*/ '{a}'.",
|
|
|
643 |
unexpected_space_a_b: "Unexpected space between '{a}' and '{b}'.",
|
|
|
644 |
unnecessary_initialize: "It is not necessary to initialize '{a}' " +
|
|
|
645 |
"to 'undefined'.",
|
|
|
646 |
unnecessary_use: "Unnecessary 'use strict'.",
|
|
|
647 |
unreachable_a_b: "Unreachable '{a}' after '{b}'.",
|
|
|
648 |
unrecognized_style_attribute_a: "Unrecognized style attribute '{a}'.",
|
|
|
649 |
unrecognized_tag_a: "Unrecognized tag '<{a}>'.",
|
|
|
650 |
unsafe: "Unsafe character.",
|
|
|
651 |
url: "JavaScript URL.",
|
|
|
652 |
use_array: "Use the array literal notation [].",
|
|
|
653 |
use_braces: "Spaces are hard to count. Use {{a}}.",
|
|
|
654 |
use_charAt: "Use the charAt method.",
|
|
|
655 |
use_object: "Use the object literal notation {}.",
|
|
|
656 |
use_or: "Use the || operator.",
|
|
|
657 |
use_param: "Use a named parameter.",
|
|
|
658 |
used_before_a: "'{a}' was used before it was defined.",
|
|
|
659 |
var_a_not: "Variable {a} was not declared correctly.",
|
|
|
660 |
weird_assignment: "Weird assignment.",
|
|
|
661 |
weird_condition: "Weird condition.",
|
|
|
662 |
weird_new: "Weird construction. Delete 'new'.",
|
|
|
663 |
weird_program: "Weird program.",
|
|
|
664 |
weird_relation: "Weird relation.",
|
|
|
665 |
weird_ternary: "Weird ternary.",
|
|
|
666 |
wrap_immediate: "Wrap an immediate function invocation in parentheses " +
|
|
|
667 |
"to assist the reader in understanding that the expression " +
|
|
|
668 |
"is the result of a function, and not the function itself.",
|
|
|
669 |
wrap_regexp: "Wrap the /regexp/ literal in parens to " +
|
|
|
670 |
"disambiguate the slash operator.",
|
|
|
671 |
write_is_wrong: "document.write can be a form of eval."
|
|
|
672 |
},
|
|
|
673 |
comments_off,
|
|
|
674 |
css_attribute_data,
|
|
|
675 |
css_any,
|
|
|
676 |
|
|
|
677 |
css_colorData = array_to_object([
|
|
|
678 |
"aliceblue", "antiquewhite", "aqua", "aquamarine", "azure", "beige",
|
|
|
679 |
"bisque", "black", "blanchedalmond", "blue", "blueviolet", "brown",
|
|
|
680 |
"burlywood", "cadetblue", "chartreuse", "chocolate", "coral",
|
|
|
681 |
"cornflowerblue", "cornsilk", "crimson", "cyan", "darkblue",
|
|
|
682 |
"darkcyan", "darkgoldenrod", "darkgray", "darkgreen", "darkkhaki",
|
|
|
683 |
"darkmagenta", "darkolivegreen", "darkorange", "darkorchid",
|
|
|
684 |
"darkred", "darksalmon", "darkseagreen", "darkslateblue",
|
|
|
685 |
"darkslategray", "darkturquoise", "darkviolet", "deeppink",
|
|
|
686 |
"deepskyblue", "dimgray", "dodgerblue", "firebrick", "floralwhite",
|
|
|
687 |
"forestgreen", "fuchsia", "gainsboro", "ghostwhite", "gold",
|
|
|
688 |
"goldenrod", "gray", "green", "greenyellow", "honeydew", "hotpink",
|
|
|
689 |
"indianred", "indigo", "ivory", "khaki", "lavender",
|
|
|
690 |
"lavenderblush", "lawngreen", "lemonchiffon", "lightblue",
|
|
|
691 |
"lightcoral", "lightcyan", "lightgoldenrodyellow", "lightgreen",
|
|
|
692 |
"lightpink", "lightsalmon", "lightseagreen", "lightskyblue",
|
|
|
693 |
"lightslategray", "lightsteelblue", "lightyellow", "lime",
|
|
|
694 |
"limegreen", "linen", "magenta", "maroon", "mediumaquamarine",
|
|
|
695 |
"mediumblue", "mediumorchid", "mediumpurple", "mediumseagreen",
|
|
|
696 |
"mediumslateblue", "mediumspringgreen", "mediumturquoise",
|
|
|
697 |
"mediumvioletred", "midnightblue", "mintcream", "mistyrose",
|
|
|
698 |
"moccasin", "navajowhite", "navy", "oldlace", "olive", "olivedrab",
|
|
|
699 |
"orange", "orangered", "orchid", "palegoldenrod", "palegreen",
|
|
|
700 |
"paleturquoise", "palevioletred", "papayawhip", "peachpuff",
|
|
|
701 |
"peru", "pink", "plum", "powderblue", "purple", "red", "rosybrown",
|
|
|
702 |
"royalblue", "saddlebrown", "salmon", "sandybrown", "seagreen",
|
|
|
703 |
"seashell", "sienna", "silver", "skyblue", "slateblue", "slategray",
|
|
|
704 |
"snow", "springgreen", "steelblue", "tan", "teal", "thistle",
|
|
|
705 |
"tomato", "turquoise", "violet", "wheat", "white", "whitesmoke",
|
|
|
706 |
"yellow", "yellowgreen",
|
|
|
707 |
|
|
|
708 |
"activeborder", "activecaption", "appworkspace", "background",
|
|
|
709 |
"buttonface", "buttonhighlight", "buttonshadow", "buttontext",
|
|
|
710 |
"captiontext", "graytext", "highlight", "highlighttext",
|
|
|
711 |
"inactiveborder", "inactivecaption", "inactivecaptiontext",
|
|
|
712 |
"infobackground", "infotext", "menu", "menutext", "scrollbar",
|
|
|
713 |
"threeddarkshadow", "threedface", "threedhighlight",
|
|
|
714 |
"threedlightshadow", "threedshadow", "window", "windowframe",
|
|
|
715 |
"windowtext"
|
|
|
716 |
], true),
|
|
|
717 |
|
|
|
718 |
css_border_style,
|
|
|
719 |
css_break,
|
|
|
720 |
|
|
|
721 |
css_lengthData = {
|
|
|
722 |
'%': true,
|
|
|
723 |
'cm': true,
|
|
|
724 |
'em': true,
|
|
|
725 |
'ex': true,
|
|
|
726 |
'in': true,
|
|
|
727 |
'mm': true,
|
|
|
728 |
'pc': true,
|
|
|
729 |
'pt': true,
|
|
|
730 |
'px': true
|
|
|
731 |
},
|
|
|
732 |
|
|
|
733 |
css_media,
|
|
|
734 |
css_overflow,
|
|
|
735 |
|
|
|
736 |
descapes = {
|
|
|
737 |
'b': '\b',
|
|
|
738 |
't': '\t',
|
|
|
739 |
'n': '\n',
|
|
|
740 |
'f': '\f',
|
|
|
741 |
'r': '\r',
|
|
|
742 |
'"': '"',
|
|
|
743 |
'/': '/',
|
|
|
744 |
'\\': '\\'
|
|
|
745 |
},
|
|
|
746 |
|
|
|
747 |
devel = array_to_object([
|
|
|
748 |
'alert', 'confirm', 'console', 'Debug', 'opera', 'prompt', 'WSH'
|
|
|
749 |
], false),
|
|
|
750 |
directive,
|
|
|
751 |
escapes = {
|
|
|
752 |
'\b': '\\b',
|
|
|
753 |
'\t': '\\t',
|
|
|
754 |
'\n': '\\n',
|
|
|
755 |
'\f': '\\f',
|
|
|
756 |
'\r': '\\r',
|
|
|
757 |
'\'': '\\\'',
|
|
|
758 |
'"' : '\\"',
|
|
|
759 |
'/' : '\\/',
|
|
|
760 |
'\\': '\\\\'
|
|
|
761 |
},
|
|
|
762 |
|
|
|
763 |
funct, // The current function, including the labels used in
|
|
|
764 |
// the function, as well as (breakage), (complexity),
|
|
|
765 |
// (context), (loopage), (name), (params), (token),
|
|
|
766 |
// (vars), (verb)
|
|
|
767 |
|
|
|
768 |
functionicity = [
|
|
|
769 |
'closure', 'exception', 'global', 'label', 'outer', 'undef',
|
|
|
770 |
'unused', 'var'
|
|
|
771 |
],
|
|
|
772 |
|
|
|
773 |
functions, // All of the functions
|
|
|
774 |
global_funct, // The global body
|
|
|
775 |
global_scope, // The global scope
|
|
|
776 |
html_tag = {
|
|
|
777 |
a: {},
|
|
|
778 |
abbr: {},
|
|
|
779 |
acronym: {},
|
|
|
780 |
address: {},
|
|
|
781 |
applet: {},
|
|
|
782 |
area: {empty: true, parent: ' map '},
|
|
|
783 |
article: {},
|
|
|
784 |
aside: {},
|
|
|
785 |
audio: {},
|
|
|
786 |
b: {},
|
|
|
787 |
base: {empty: true, parent: ' head '},
|
|
|
788 |
bdo: {},
|
|
|
789 |
big: {},
|
|
|
790 |
blockquote: {},
|
|
|
791 |
body: {parent: ' html noframes '},
|
|
|
792 |
br: {empty: true},
|
|
|
793 |
button: {},
|
|
|
794 |
canvas: {parent: ' body p div th td '},
|
|
|
795 |
caption: {parent: ' table '},
|
|
|
796 |
center: {},
|
|
|
797 |
cite: {},
|
|
|
798 |
code: {},
|
|
|
799 |
col: {empty: true, parent: ' table colgroup '},
|
|
|
800 |
colgroup: {parent: ' table '},
|
|
|
801 |
command: {parent: ' menu '},
|
|
|
802 |
datalist: {},
|
|
|
803 |
dd: {parent: ' dl '},
|
|
|
804 |
del: {},
|
|
|
805 |
details: {},
|
|
|
806 |
dialog: {},
|
|
|
807 |
dfn: {},
|
|
|
808 |
dir: {},
|
|
|
809 |
div: {},
|
|
|
810 |
dl: {},
|
|
|
811 |
dt: {parent: ' dl '},
|
|
|
812 |
em: {},
|
|
|
813 |
embed: {},
|
|
|
814 |
fieldset: {},
|
|
|
815 |
figure: {},
|
|
|
816 |
font: {},
|
|
|
817 |
footer: {},
|
|
|
818 |
form: {},
|
|
|
819 |
frame: {empty: true, parent: ' frameset '},
|
|
|
820 |
frameset: {parent: ' html frameset '},
|
|
|
821 |
h1: {},
|
|
|
822 |
h2: {},
|
|
|
823 |
h3: {},
|
|
|
824 |
h4: {},
|
|
|
825 |
h5: {},
|
|
|
826 |
h6: {},
|
|
|
827 |
head: {parent: ' html '},
|
|
|
828 |
header: {},
|
|
|
829 |
hgroup: {},
|
|
|
830 |
hr: {empty: true},
|
|
|
831 |
'hta:application':
|
|
|
832 |
{empty: true, parent: ' head '},
|
|
|
833 |
html: {parent: '*'},
|
|
|
834 |
i: {},
|
|
|
835 |
iframe: {},
|
|
|
836 |
img: {empty: true},
|
|
|
837 |
input: {empty: true},
|
|
|
838 |
ins: {},
|
|
|
839 |
kbd: {},
|
|
|
840 |
keygen: {},
|
|
|
841 |
label: {},
|
|
|
842 |
legend: {parent: ' details fieldset figure '},
|
|
|
843 |
li: {parent: ' dir menu ol ul '},
|
|
|
844 |
link: {empty: true, parent: ' head '},
|
|
|
845 |
map: {},
|
|
|
846 |
mark: {},
|
|
|
847 |
menu: {},
|
|
|
848 |
meta: {empty: true, parent: ' head noframes noscript '},
|
|
|
849 |
meter: {},
|
|
|
850 |
nav: {},
|
|
|
851 |
noframes: {parent: ' html body '},
|
|
|
852 |
noscript: {parent: ' body head noframes '},
|
|
|
853 |
object: {},
|
|
|
854 |
ol: {},
|
|
|
855 |
optgroup: {parent: ' select '},
|
|
|
856 |
option: {parent: ' optgroup select '},
|
|
|
857 |
output: {},
|
|
|
858 |
p: {},
|
|
|
859 |
param: {empty: true, parent: ' applet object '},
|
|
|
860 |
pre: {},
|
|
|
861 |
progress: {},
|
|
|
862 |
q: {},
|
|
|
863 |
rp: {},
|
|
|
864 |
rt: {},
|
|
|
865 |
ruby: {},
|
|
|
866 |
samp: {},
|
|
|
867 |
script: {empty: true, parent: ' body div frame head iframe p pre span '},
|
|
|
868 |
section: {},
|
|
|
869 |
select: {},
|
|
|
870 |
small: {},
|
|
|
871 |
span: {},
|
|
|
872 |
source: {},
|
|
|
873 |
strong: {},
|
|
|
874 |
style: {parent: ' head ', empty: true},
|
|
|
875 |
sub: {},
|
|
|
876 |
sup: {},
|
|
|
877 |
table: {},
|
|
|
878 |
tbody: {parent: ' table '},
|
|
|
879 |
td: {parent: ' tr '},
|
|
|
880 |
textarea: {},
|
|
|
881 |
tfoot: {parent: ' table '},
|
|
|
882 |
th: {parent: ' tr '},
|
|
|
883 |
thead: {parent: ' table '},
|
|
|
884 |
time: {},
|
|
|
885 |
title: {parent: ' head '},
|
|
|
886 |
tr: {parent: ' table tbody thead tfoot '},
|
|
|
887 |
tt: {},
|
|
|
888 |
u: {},
|
|
|
889 |
ul: {},
|
|
|
890 |
'var': {},
|
|
|
891 |
video: {}
|
|
|
892 |
},
|
|
|
893 |
|
|
|
894 |
ids, // HTML ids
|
|
|
895 |
in_block,
|
|
|
896 |
indent,
|
|
|
897 |
// infer_statement,// Inference rules for statements
|
|
|
898 |
is_type = array_to_object([
|
|
|
899 |
'*', 'array', 'boolean', 'function', 'number', 'object',
|
|
|
900 |
'regexp', 'string'
|
|
|
901 |
], true),
|
|
|
902 |
itself, // JSLint itself
|
|
|
903 |
jslint_limit = {
|
|
|
904 |
indent: 10,
|
|
|
905 |
maxerr: 1000,
|
|
|
906 |
maxlen: 256
|
|
|
907 |
},
|
|
|
908 |
json_mode,
|
|
|
909 |
lex, // the tokenizer
|
|
|
910 |
lines,
|
|
|
911 |
lookahead,
|
|
|
912 |
member,
|
|
|
913 |
node = array_to_object([
|
|
|
914 |
'Buffer', 'clearInterval', 'clearTimeout', 'console', 'exports',
|
|
|
915 |
'global', 'module', 'process', 'querystring', 'require',
|
|
|
916 |
'setInterval', 'setTimeout', '__dirname', '__filename'
|
|
|
917 |
], false),
|
|
|
918 |
node_js,
|
|
|
919 |
numbery = array_to_object(['indexOf', 'lastIndexOf', 'search'], true),
|
|
|
920 |
next_token,
|
|
|
921 |
option,
|
|
|
922 |
predefined, // Global variables defined by option
|
|
|
923 |
prereg,
|
|
|
924 |
prev_token,
|
|
|
925 |
property_type,
|
|
|
926 |
regexp_flag = array_to_object(['g', 'i', 'm'], true),
|
|
|
927 |
return_this = function return_this() {
|
|
|
928 |
return this;
|
|
|
929 |
},
|
|
|
930 |
rhino = array_to_object([
|
|
|
931 |
'defineClass', 'deserialize', 'gc', 'help', 'load', 'loadClass',
|
|
|
932 |
'print', 'quit', 'readFile', 'readUrl', 'runCommand', 'seal',
|
|
|
933 |
'serialize', 'spawn', 'sync', 'toint32', 'version'
|
|
|
934 |
], false),
|
|
|
935 |
|
|
|
936 |
scope, // An object containing an object for each variable in scope
|
|
|
937 |
semicolon_coda = array_to_object([';', '"', '\'', ')'], true),
|
|
|
938 |
src,
|
|
|
939 |
stack,
|
|
|
940 |
|
|
|
941 |
// standard contains the global names that are provided by the
|
|
|
942 |
// ECMAScript standard.
|
|
|
943 |
|
|
|
944 |
standard = array_to_object([
|
|
|
945 |
'Array', 'Boolean', 'Date', 'decodeURI', 'decodeURIComponent',
|
|
|
946 |
'encodeURI', 'encodeURIComponent', 'Error', 'eval', 'EvalError',
|
|
|
947 |
'Function', 'isFinite', 'isNaN', 'JSON', 'Math', 'Number', 'Object',
|
|
|
948 |
'parseInt', 'parseFloat', 'RangeError', 'ReferenceError', 'RegExp',
|
|
|
949 |
'String', 'SyntaxError', 'TypeError', 'URIError'
|
|
|
950 |
], false),
|
|
|
951 |
|
|
|
952 |
standard_property_type = {
|
|
|
953 |
E : 'number',
|
|
|
954 |
LN2 : 'number',
|
|
|
955 |
LN10 : 'number',
|
|
|
956 |
LOG2E : 'number',
|
|
|
957 |
LOG10E : 'number',
|
|
|
958 |
MAX_VALUE : 'number',
|
|
|
959 |
MIN_VALUE : 'number',
|
|
|
960 |
NEGATIVE_INFINITY : 'number',
|
|
|
961 |
PI : 'number',
|
|
|
962 |
POSITIVE_INFINITY : 'number',
|
|
|
963 |
SQRT1_2 : 'number',
|
|
|
964 |
SQRT2 : 'number',
|
|
|
965 |
apply : 'function',
|
|
|
966 |
bind : 'function function',
|
|
|
967 |
call : 'function',
|
|
|
968 |
ceil : 'function number',
|
|
|
969 |
charAt : 'function string',
|
|
|
970 |
concat : 'function',
|
|
|
971 |
constructor : 'function object',
|
|
|
972 |
create : 'function object',
|
|
|
973 |
defineProperty : 'function object',
|
|
|
974 |
defineProperties : 'function object',
|
|
|
975 |
every : 'function boolean',
|
|
|
976 |
exec : 'function array',
|
|
|
977 |
filter : 'function array',
|
|
|
978 |
floor : 'function number',
|
|
|
979 |
forEach : 'function',
|
|
|
980 |
freeze : 'function object',
|
|
|
981 |
getDate : 'function number',
|
|
|
982 |
getDay : 'function number',
|
|
|
983 |
getFullYear : 'function number',
|
|
|
984 |
getHours : 'function number',
|
|
|
985 |
getMilliseconds : 'function number',
|
|
|
986 |
getMinutes : 'function number',
|
|
|
987 |
getMonth : 'function number',
|
|
|
988 |
getOwnPropertyDescriptor
|
|
|
989 |
: 'function object',
|
|
|
990 |
getOwnPropertyNames : 'function array',
|
|
|
991 |
getPrototypeOf : 'function object',
|
|
|
992 |
getSeconds : 'function number',
|
|
|
993 |
getTime : 'function number',
|
|
|
994 |
getTimezoneOffset : 'function number',
|
|
|
995 |
getUTCDate : 'function number',
|
|
|
996 |
getUTCDay : 'function number',
|
|
|
997 |
getUTCFullYear : 'function number',
|
|
|
998 |
getUTCHours : 'function number',
|
|
|
999 |
getUTCMilliseconds : 'function number',
|
|
|
1000 |
getUTCMinutes : 'function number',
|
|
|
1001 |
getUTCMonth : 'function number',
|
|
|
1002 |
getUTCSeconds : 'function number',
|
|
|
1003 |
getYear : 'function number',
|
|
|
1004 |
hasOwnProperty : 'function boolean',
|
|
|
1005 |
indexOf : 'function number',
|
|
|
1006 |
isExtensible : 'function boolean',
|
|
|
1007 |
isFrozen : 'function boolean',
|
|
|
1008 |
isPrototypeOf : 'function boolean',
|
|
|
1009 |
isSealed : 'function boolean',
|
|
|
1010 |
join : 'function string',
|
|
|
1011 |
keys : 'function array',
|
|
|
1012 |
lastIndexOf : 'function number',
|
|
|
1013 |
lastIndex : 'number',
|
|
|
1014 |
length : 'number',
|
|
|
1015 |
map : 'function array',
|
|
|
1016 |
now : 'function number',
|
|
|
1017 |
parse : 'function',
|
|
|
1018 |
pop : 'function',
|
|
|
1019 |
preventExtensions : 'function object',
|
|
|
1020 |
propertyIsEnumerable: 'function boolean',
|
|
|
1021 |
prototype : 'object',
|
|
|
1022 |
push : 'function number',
|
|
|
1023 |
reduce : 'function',
|
|
|
1024 |
reduceRight : 'function',
|
|
|
1025 |
reverse : 'function',
|
|
|
1026 |
seal : 'function object',
|
|
|
1027 |
setDate : 'function',
|
|
|
1028 |
setDay : 'function',
|
|
|
1029 |
setFullYear : 'function',
|
|
|
1030 |
setHours : 'function',
|
|
|
1031 |
setMilliseconds : 'function',
|
|
|
1032 |
setMinutes : 'function',
|
|
|
1033 |
setMonth : 'function',
|
|
|
1034 |
setSeconds : 'function',
|
|
|
1035 |
setTime : 'function',
|
|
|
1036 |
setTimezoneOffset : 'function',
|
|
|
1037 |
setUTCDate : 'function',
|
|
|
1038 |
setUTCDay : 'function',
|
|
|
1039 |
setUTCFullYear : 'function',
|
|
|
1040 |
setUTCHours : 'function',
|
|
|
1041 |
setUTCMilliseconds : 'function',
|
|
|
1042 |
setUTCMinutes : 'function',
|
|
|
1043 |
setUTCMonth : 'function',
|
|
|
1044 |
setUTCSeconds : 'function',
|
|
|
1045 |
setYear : 'function',
|
|
|
1046 |
shift : 'function',
|
|
|
1047 |
slice : 'function',
|
|
|
1048 |
some : 'function boolean',
|
|
|
1049 |
sort : 'function',
|
|
|
1050 |
splice : 'function',
|
|
|
1051 |
stringify : 'function string',
|
|
|
1052 |
substr : 'function string',
|
|
|
1053 |
substring : 'function string',
|
|
|
1054 |
test : 'function boolean',
|
|
|
1055 |
toDateString : 'function string',
|
|
|
1056 |
toExponential : 'function string',
|
|
|
1057 |
toFixed : 'function string',
|
|
|
1058 |
toJSON : 'function',
|
|
|
1059 |
toISOString : 'function string',
|
|
|
1060 |
toLocaleDateString : 'function string',
|
|
|
1061 |
toLocaleLowerCase : 'function string',
|
|
|
1062 |
toLocaleUpperCase : 'function string',
|
|
|
1063 |
toLocaleString : 'function string',
|
|
|
1064 |
toLocaleTimeString : 'function string',
|
|
|
1065 |
toLowerCase : 'function string',
|
|
|
1066 |
toPrecision : 'function string',
|
|
|
1067 |
toTimeString : 'function string',
|
|
|
1068 |
toUpperCase : 'function string',
|
|
|
1069 |
toUTCString : 'function string',
|
|
|
1070 |
trim : 'function string',
|
|
|
1071 |
unshift : 'function number',
|
|
|
1072 |
valueOf : 'function'
|
|
|
1073 |
},
|
|
|
1074 |
|
|
|
1075 |
strict_mode,
|
|
|
1076 |
syntax = {},
|
|
|
1077 |
tab,
|
|
|
1078 |
token,
|
|
|
1079 |
// type_state_change,
|
|
|
1080 |
urls,
|
|
|
1081 |
var_mode,
|
|
|
1082 |
warnings,
|
|
|
1083 |
|
|
|
1084 |
// widget contains the global names which are provided to a Yahoo
|
|
|
1085 |
// (fna Konfabulator) widget.
|
|
|
1086 |
|
|
|
1087 |
widget = array_to_object([
|
|
|
1088 |
'alert', 'animator', 'appleScript', 'beep', 'bytesToUIString',
|
|
|
1089 |
'Canvas', 'chooseColor', 'chooseFile', 'chooseFolder',
|
|
|
1090 |
'closeWidget', 'COM', 'convertPathToHFS', 'convertPathToPlatform',
|
|
|
1091 |
'CustomAnimation', 'escape', 'FadeAnimation', 'filesystem', 'Flash',
|
|
|
1092 |
'focusWidget', 'form', 'FormField', 'Frame', 'HotKey', 'Image',
|
|
|
1093 |
'include', 'isApplicationRunning', 'iTunes', 'konfabulatorVersion',
|
|
|
1094 |
'log', 'md5', 'MenuItem', 'MoveAnimation', 'openURL', 'play',
|
|
|
1095 |
'Point', 'popupMenu', 'preferenceGroups', 'preferences', 'print',
|
|
|
1096 |
'prompt', 'random', 'Rectangle', 'reloadWidget', 'ResizeAnimation',
|
|
|
1097 |
'resolvePath', 'resumeUpdates', 'RotateAnimation', 'runCommand',
|
|
|
1098 |
'runCommandInBg', 'saveAs', 'savePreferences', 'screen',
|
|
|
1099 |
'ScrollBar', 'showWidgetPreferences', 'sleep', 'speak', 'Style',
|
|
|
1100 |
'suppressUpdates', 'system', 'tellWidget', 'Text', 'TextArea',
|
|
|
1101 |
'Timer', 'unescape', 'updateNow', 'URL', 'Web', 'widget', 'Window',
|
|
|
1102 |
'XMLDOM', 'XMLHttpRequest', 'yahooCheckLogin', 'yahooLogin',
|
|
|
1103 |
'yahooLogout'
|
|
|
1104 |
], true),
|
|
|
1105 |
|
|
|
1106 |
windows = array_to_object([
|
|
|
1107 |
'ActiveXObject', 'CScript', 'Debug', 'Enumerator', 'System',
|
|
|
1108 |
'VBArray', 'WScript', 'WSH'
|
|
|
1109 |
], false),
|
|
|
1110 |
|
|
|
1111 |
// xmode is used to adapt to the exceptions in html parsing.
|
|
|
1112 |
// It can have these states:
|
|
|
1113 |
// '' .js script file
|
|
|
1114 |
// 'html'
|
|
|
1115 |
// 'outer'
|
|
|
1116 |
// 'script'
|
|
|
1117 |
// 'style'
|
|
|
1118 |
// 'scriptstring'
|
|
|
1119 |
// 'styleproperty'
|
|
|
1120 |
|
|
|
1121 |
xmode,
|
|
|
1122 |
xquote,
|
|
|
1123 |
|
|
|
1124 |
// Regular expressions. Some of these are stupidly long.
|
|
|
1125 |
|
|
|
1126 |
// unsafe comment or string
|
|
|
1127 |
ax = /@cc|<\/?|script|\]\s*\]|<\s*!|</i,
|
|
|
1128 |
// carriage return, or carriage return linefeed
|
|
|
1129 |
crx = /\r/g,
|
|
|
1130 |
crlfx = /\r\n/g,
|
|
|
1131 |
// unsafe characters that are silently deleted by one or more browsers
|
|
|
1132 |
cx = /[\u0000-\u001f\u007f-\u009f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/,
|
|
|
1133 |
// query characters for ids
|
|
|
1134 |
dx = /[\[\]\/\\"'*<>.&:(){}+=#]/,
|
|
|
1135 |
// html token
|
|
|
1136 |
hx = /^\s*(['"=>\/&#]|<(?:\/|\!(?:--)?)?|[a-zA-Z][a-zA-Z0-9_\-:]*|[0-9]+|--)/,
|
|
|
1137 |
// identifier
|
|
|
1138 |
ix = /^([a-zA-Z_$][a-zA-Z0-9_$]*)$/,
|
|
|
1139 |
// javascript url
|
|
|
1140 |
jx = /^(?:javascript|jscript|ecmascript|vbscript|mocha|livescript)\s*:/i,
|
|
|
1141 |
// star slash
|
|
|
1142 |
lx = /\*\/|\/\*/,
|
|
|
1143 |
// characters in strings that need escapement
|
|
|
1144 |
nx = /[\u0000-\u001f'\\\u007f-\u009f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
|
|
|
1145 |
// outer html token
|
|
|
1146 |
ox = /[>&]|<[\/!]?|--/,
|
|
|
1147 |
// attributes characters
|
|
|
1148 |
qx = /[^a-zA-Z0-9+\-_\/ ]/,
|
|
|
1149 |
// style
|
|
|
1150 |
sx = /^\s*([{}:#%.=,>+\[\]@()"';]|\*=?|\$=|\|=|\^=|~=|[a-zA-Z_][a-zA-Z0-9_\-]*|[0-9]+|<\/|\/\*)/,
|
|
|
1151 |
ssx = /^\s*([@#!"'};:\-%.=,+\[\]()*_]|[a-zA-Z][a-zA-Z0-9._\-]*|\/\*?|\d+(?:\.\d+)?|<\/)/,
|
|
|
1152 |
// token
|
|
|
1153 |
tx = /^\s*([(){}\[.,:;'"~\?\]#@]|==?=?|\/(\*(jslint|properties|property|members?|globals?)?|=|\/)?|\*[\/=]?|\+(?:=|\++)?|-(?:=|-+)?|%=?|&[&=]?|\|[|=]?|>>?>?=?|<([\/=!]|\!(\[|--)?|<=?)?|\^=?|\!=?=?|[a-zA-Z_$][a-zA-Z0-9_$]*|[0-9]+([xX][0-9a-fA-F]+|\.[0-9]*)?([eE][+\-]?[0-9]+)?)/,
|
|
|
1154 |
// url badness
|
|
|
1155 |
ux = /&|\+|\u00AD|\.\.|\/\*|%[^;]|base64|url|expression|data|mailto|script/i,
|
|
|
1156 |
|
|
|
1157 |
rx = {
|
|
|
1158 |
outer: hx,
|
|
|
1159 |
html: hx,
|
|
|
1160 |
style: sx,
|
|
|
1161 |
styleproperty: ssx
|
|
|
1162 |
};
|
|
|
1163 |
|
|
|
1164 |
|
|
|
1165 |
function F() {} // Used by Object.create
|
|
|
1166 |
|
|
|
1167 |
// Provide critical ES5 functions to ES3.
|
|
|
1168 |
|
|
|
1169 |
if (typeof Array.prototype.filter !== 'function') {
|
|
|
1170 |
Array.prototype.filter = function (f) {
|
|
|
1171 |
var i, length = this.length, result = [], value;
|
|
|
1172 |
for (i = 0; i < length; i += 1) {
|
|
|
1173 |
try {
|
|
|
1174 |
value = this[i];
|
|
|
1175 |
if (f(value)) {
|
|
|
1176 |
result.push(value);
|
|
|
1177 |
}
|
|
|
1178 |
} catch (ignore) {
|
|
|
1179 |
}
|
|
|
1180 |
}
|
|
|
1181 |
return result;
|
|
|
1182 |
};
|
|
|
1183 |
}
|
|
|
1184 |
|
|
|
1185 |
if (typeof Array.prototype.forEach !== 'function') {
|
|
|
1186 |
Array.prototype.forEach = function (f) {
|
|
|
1187 |
var i, length = this.length;
|
|
|
1188 |
for (i = 0; i < length; i += 1) {
|
|
|
1189 |
try {
|
|
|
1190 |
f(this[i]);
|
|
|
1191 |
} catch (ignore) {
|
|
|
1192 |
}
|
|
|
1193 |
}
|
|
|
1194 |
};
|
|
|
1195 |
}
|
|
|
1196 |
|
|
|
1197 |
if (typeof Array.isArray !== 'function') {
|
|
|
1198 |
Array.isArray = function (o) {
|
|
|
1199 |
return Object.prototype.toString.apply(o) === '[object Array]';
|
|
|
1200 |
};
|
|
|
1201 |
}
|
|
|
1202 |
|
|
|
1203 |
if (!Object.prototype.hasOwnProperty.call(Object, 'create')) {
|
|
|
1204 |
Object.create = function (o) {
|
|
|
1205 |
F.prototype = o;
|
|
|
1206 |
return new F();
|
|
|
1207 |
};
|
|
|
1208 |
}
|
|
|
1209 |
|
|
|
1210 |
if (typeof Object.keys !== 'function') {
|
|
|
1211 |
Object.keys = function (o) {
|
|
|
1212 |
var array = [], key;
|
|
|
1213 |
for (key in o) {
|
|
|
1214 |
if (Object.prototype.hasOwnProperty.call(o, key)) {
|
|
|
1215 |
array.push(key);
|
|
|
1216 |
}
|
|
|
1217 |
}
|
|
|
1218 |
return array;
|
|
|
1219 |
};
|
|
|
1220 |
}
|
|
|
1221 |
|
|
|
1222 |
if (typeof String.prototype.entityify !== 'function') {
|
|
|
1223 |
String.prototype.entityify = function () {
|
|
|
1224 |
return this
|
|
|
1225 |
.replace(/&/g, '&')
|
|
|
1226 |
.replace(/</g, '<')
|
|
|
1227 |
.replace(/>/g, '>');
|
|
|
1228 |
};
|
|
|
1229 |
}
|
|
|
1230 |
|
|
|
1231 |
if (typeof String.prototype.isAlpha !== 'function') {
|
|
|
1232 |
String.prototype.isAlpha = function () {
|
|
|
1233 |
return (this >= 'a' && this <= 'z\uffff') ||
|
|
|
1234 |
(this >= 'A' && this <= 'Z\uffff');
|
|
|
1235 |
};
|
|
|
1236 |
}
|
|
|
1237 |
|
|
|
1238 |
if (typeof String.prototype.isDigit !== 'function') {
|
|
|
1239 |
String.prototype.isDigit = function () {
|
|
|
1240 |
return (this >= '0' && this <= '9');
|
|
|
1241 |
};
|
|
|
1242 |
}
|
|
|
1243 |
|
|
|
1244 |
if (typeof String.prototype.supplant !== 'function') {
|
|
|
1245 |
String.prototype.supplant = function (o) {
|
|
|
1246 |
return this.replace(/\{([^{}]*)\}/g, function (a, b) {
|
|
|
1247 |
var replacement = o[b];
|
|
|
1248 |
return typeof replacement === 'string' ||
|
|
|
1249 |
typeof replacement === 'number' ? replacement : a;
|
|
|
1250 |
});
|
|
|
1251 |
};
|
|
|
1252 |
}
|
|
|
1253 |
|
|
|
1254 |
|
|
|
1255 |
function sanitize(a) {
|
|
|
1256 |
|
|
|
1257 |
// Escapify a troublesome character.
|
|
|
1258 |
|
|
|
1259 |
return escapes[a] ||
|
|
|
1260 |
'\\u' + ('0000' + a.charCodeAt().toString(16)).slice(-4);
|
|
|
1261 |
}
|
|
|
1262 |
|
|
|
1263 |
|
|
|
1264 |
function add_to_predefined(group) {
|
|
|
1265 |
Object.keys(group).forEach(function (name) {
|
|
|
1266 |
predefined[name] = group[name];
|
|
|
1267 |
});
|
|
|
1268 |
}
|
|
|
1269 |
|
|
|
1270 |
|
|
|
1271 |
function assume() {
|
|
|
1272 |
if (!option.safe) {
|
|
|
1273 |
if (option.rhino) {
|
|
|
1274 |
add_to_predefined(rhino);
|
|
|
1275 |
option.rhino = false;
|
|
|
1276 |
}
|
|
|
1277 |
if (option.devel) {
|
|
|
1278 |
add_to_predefined(devel);
|
|
|
1279 |
option.devel = false;
|
|
|
1280 |
}
|
|
|
1281 |
if (option.browser) {
|
|
|
1282 |
add_to_predefined(browser);
|
|
|
1283 |
option.browser = false;
|
|
|
1284 |
}
|
|
|
1285 |
if (option.windows) {
|
|
|
1286 |
add_to_predefined(windows);
|
|
|
1287 |
option.windows = false;
|
|
|
1288 |
}
|
|
|
1289 |
if (option.node) {
|
|
|
1290 |
add_to_predefined(node);
|
|
|
1291 |
option.node = false;
|
|
|
1292 |
node_js = true;
|
|
|
1293 |
}
|
|
|
1294 |
if (option.widget) {
|
|
|
1295 |
add_to_predefined(widget);
|
|
|
1296 |
option.widget = false;
|
|
|
1297 |
}
|
|
|
1298 |
}
|
|
|
1299 |
if (option.type) {
|
|
|
1300 |
option.confusion = true;
|
|
|
1301 |
}
|
|
|
1302 |
}
|
|
|
1303 |
|
|
|
1304 |
|
|
|
1305 |
// Produce an error warning.
|
|
|
1306 |
|
|
|
1307 |
function artifact(tok) {
|
|
|
1308 |
if (!tok) {
|
|
|
1309 |
tok = next_token;
|
|
|
1310 |
}
|
|
|
1311 |
return tok.number || tok.string;
|
|
|
1312 |
}
|
|
|
1313 |
|
|
|
1314 |
function quit(message, line, character) {
|
|
|
1315 |
throw {
|
|
|
1316 |
name: 'JSLintError',
|
|
|
1317 |
line: line,
|
|
|
1318 |
character: character,
|
|
|
1319 |
message: bundle.scanned_a_b.supplant({
|
|
|
1320 |
a: message,
|
|
|
1321 |
b: Math.floor((line / lines.length) * 100)
|
|
|
1322 |
})
|
|
|
1323 |
};
|
|
|
1324 |
}
|
|
|
1325 |
|
|
|
1326 |
function warn(message, offender, a, b, c, d) {
|
|
|
1327 |
var character, line, warning;
|
|
|
1328 |
offender = offender || next_token; // `~
|
|
|
1329 |
line = offender.line || 0;
|
|
|
1330 |
character = offender.from || 0;
|
|
|
1331 |
warning = {
|
|
|
1332 |
id: '(error)',
|
|
|
1333 |
raw: bundle[message] || message,
|
|
|
1334 |
evidence: lines[line - 1] || '',
|
|
|
1335 |
line: line,
|
|
|
1336 |
character: character,
|
|
|
1337 |
a: a || (offender.id === '(number)'
|
|
|
1338 |
? String(offender.number)
|
|
|
1339 |
: offender.string),
|
|
|
1340 |
b: b,
|
|
|
1341 |
c: c,
|
|
|
1342 |
d: d
|
|
|
1343 |
};
|
|
|
1344 |
warning.reason = warning.raw.supplant(warning);
|
|
|
1345 |
JSLINT.errors.push(warning);
|
|
|
1346 |
if (option.passfail) {
|
|
|
1347 |
quit(bundle.stopping, line, character);
|
|
|
1348 |
}
|
|
|
1349 |
warnings += 1;
|
|
|
1350 |
if (warnings >= option.maxerr) {
|
|
|
1351 |
quit(bundle.too_many, line, character);
|
|
|
1352 |
}
|
|
|
1353 |
return warning;
|
|
|
1354 |
}
|
|
|
1355 |
|
|
|
1356 |
function warn_at(message, line, character, a, b, c, d) {
|
|
|
1357 |
return warn(message, {
|
|
|
1358 |
line: line,
|
|
|
1359 |
from: character
|
|
|
1360 |
}, a, b, c, d);
|
|
|
1361 |
}
|
|
|
1362 |
|
|
|
1363 |
function stop(message, offender, a, b, c, d) {
|
|
|
1364 |
var warning = warn(message, offender, a, b, c, d);
|
|
|
1365 |
quit(bundle.stopping, warning.line, warning.character);
|
|
|
1366 |
}
|
|
|
1367 |
|
|
|
1368 |
function stop_at(message, line, character, a, b, c, d) {
|
|
|
1369 |
return stop(message, {
|
|
|
1370 |
line: line,
|
|
|
1371 |
from: character
|
|
|
1372 |
}, a, b, c, d);
|
|
|
1373 |
}
|
|
|
1374 |
|
|
|
1375 |
function expected_at(at) {
|
|
|
1376 |
if (!option.white && next_token.from !== at) {
|
|
|
1377 |
warn('expected_a_at_b_c', next_token, '', at,
|
|
|
1378 |
next_token.from);
|
|
|
1379 |
}
|
|
|
1380 |
}
|
|
|
1381 |
|
|
|
1382 |
function aint(it, name, expected) {
|
|
|
1383 |
if (it[name] !== expected) {
|
|
|
1384 |
warn('expected_a_b', it, expected, it[name]);
|
|
|
1385 |
return true;
|
|
|
1386 |
} else {
|
|
|
1387 |
return false;
|
|
|
1388 |
}
|
|
|
1389 |
}
|
|
|
1390 |
|
|
|
1391 |
|
|
|
1392 |
// lexical analysis and token construction
|
|
|
1393 |
|
|
|
1394 |
lex = (function lex() {
|
|
|
1395 |
var character, c, from, length, line, pos, source_row;
|
|
|
1396 |
|
|
|
1397 |
// Private lex methods
|
|
|
1398 |
|
|
|
1399 |
function next_line() {
|
|
|
1400 |
var at;
|
|
|
1401 |
if (line >= lines.length) {
|
|
|
1402 |
return false;
|
|
|
1403 |
}
|
|
|
1404 |
character = 1;
|
|
|
1405 |
source_row = lines[line];
|
|
|
1406 |
line += 1;
|
|
|
1407 |
at = source_row.search(/ \t/);
|
|
|
1408 |
if (at >= 0) {
|
|
|
1409 |
warn_at('mixed', line, at + 1);
|
|
|
1410 |
}
|
|
|
1411 |
source_row = source_row.replace(/\t/g, tab);
|
|
|
1412 |
at = source_row.search(cx);
|
|
|
1413 |
if (at >= 0) {
|
|
|
1414 |
warn_at('unsafe', line, at);
|
|
|
1415 |
}
|
|
|
1416 |
if (option.maxlen && option.maxlen < source_row.length) {
|
|
|
1417 |
warn_at('too_long', line, source_row.length);
|
|
|
1418 |
}
|
|
|
1419 |
return true;
|
|
|
1420 |
}
|
|
|
1421 |
|
|
|
1422 |
// Produce a token object. The token inherits from a syntax symbol.
|
|
|
1423 |
|
|
|
1424 |
function it(type, value) {
|
|
|
1425 |
var id, the_token;
|
|
|
1426 |
if (type === '(string)' || type === '(range)') {
|
|
|
1427 |
if (jx.test(value)) {
|
|
|
1428 |
warn_at('url', line, from);
|
|
|
1429 |
}
|
|
|
1430 |
}
|
|
|
1431 |
the_token = Object.create(syntax[(
|
|
|
1432 |
type === '(punctuator)' || (type === '(identifier)' &&
|
|
|
1433 |
Object.prototype.hasOwnProperty.call(syntax, value))
|
|
|
1434 |
? value
|
|
|
1435 |
: type
|
|
|
1436 |
)] || syntax['(error)']);
|
|
|
1437 |
if (type === '(identifier)') {
|
|
|
1438 |
the_token.identifier = true;
|
|
|
1439 |
if (value === '__iterator__' || value === '__proto__') {
|
|
|
1440 |
stop_at('reserved_a', line, from, value);
|
|
|
1441 |
} else if (!option.nomen &&
|
|
|
1442 |
(value.charAt(0) === '_' ||
|
|
|
1443 |
value.charAt(value.length - 1) === '_')) {
|
|
|
1444 |
warn_at('dangling_a', line, from, value);
|
|
|
1445 |
}
|
|
|
1446 |
}
|
|
|
1447 |
if (type === '(number)') {
|
|
|
1448 |
the_token.number = +value;
|
|
|
1449 |
} else if (value !== undefined) {
|
|
|
1450 |
the_token.string = String(value);
|
|
|
1451 |
}
|
|
|
1452 |
the_token.line = line;
|
|
|
1453 |
the_token.from = from;
|
|
|
1454 |
the_token.thru = character;
|
|
|
1455 |
id = the_token.id;
|
|
|
1456 |
prereg = id && (
|
|
|
1457 |
('(,=:[!&|?{};'.indexOf(id.charAt(id.length - 1)) >= 0) ||
|
|
|
1458 |
id === 'return' || id === 'case'
|
|
|
1459 |
);
|
|
|
1460 |
return the_token;
|
|
|
1461 |
}
|
|
|
1462 |
|
|
|
1463 |
function match(x) {
|
|
|
1464 |
var exec = x.exec(source_row), first;
|
|
|
1465 |
if (exec) {
|
|
|
1466 |
length = exec[0].length;
|
|
|
1467 |
first = exec[1];
|
|
|
1468 |
c = first.charAt(0);
|
|
|
1469 |
source_row = source_row.slice(length);
|
|
|
1470 |
from = character + length - first.length;
|
|
|
1471 |
character += length;
|
|
|
1472 |
return first;
|
|
|
1473 |
}
|
|
|
1474 |
}
|
|
|
1475 |
|
|
|
1476 |
function string(x) {
|
|
|
1477 |
var c, pos = 0, r = '', result;
|
|
|
1478 |
|
|
|
1479 |
function hex(n) {
|
|
|
1480 |
var i = parseInt(source_row.substr(pos + 1, n), 16);
|
|
|
1481 |
pos += n;
|
|
|
1482 |
if (i >= 32 && i <= 126 &&
|
|
|
1483 |
i !== 34 && i !== 92 && i !== 39) {
|
|
|
1484 |
warn_at('unexpected_a', line, character, '\\');
|
|
|
1485 |
}
|
|
|
1486 |
character += n;
|
|
|
1487 |
c = String.fromCharCode(i);
|
|
|
1488 |
}
|
|
|
1489 |
|
|
|
1490 |
if (json_mode && x !== '"') {
|
|
|
1491 |
warn_at('expected_a', line, character, '"');
|
|
|
1492 |
}
|
|
|
1493 |
|
|
|
1494 |
if (xquote === x || (xmode === 'scriptstring' && !xquote)) {
|
|
|
1495 |
return it('(punctuator)', x);
|
|
|
1496 |
}
|
|
|
1497 |
|
|
|
1498 |
for (;;) {
|
|
|
1499 |
while (pos >= source_row.length) {
|
|
|
1500 |
pos = 0;
|
|
|
1501 |
if (xmode !== 'html' || !next_line()) {
|
|
|
1502 |
stop_at('unclosed', line, from);
|
|
|
1503 |
}
|
|
|
1504 |
}
|
|
|
1505 |
c = source_row.charAt(pos);
|
|
|
1506 |
if (c === x) {
|
|
|
1507 |
character += 1;
|
|
|
1508 |
source_row = source_row.slice(pos + 1);
|
|
|
1509 |
result = it('(string)', r);
|
|
|
1510 |
result.quote = x;
|
|
|
1511 |
return result;
|
|
|
1512 |
}
|
|
|
1513 |
if (c < ' ') {
|
|
|
1514 |
if (c === '\n' || c === '\r') {
|
|
|
1515 |
break;
|
|
|
1516 |
}
|
|
|
1517 |
warn_at('control_a', line, character + pos,
|
|
|
1518 |
source_row.slice(0, pos));
|
|
|
1519 |
} else if (c === xquote) {
|
|
|
1520 |
warn_at('bad_html', line, character + pos);
|
|
|
1521 |
} else if (c === '<') {
|
|
|
1522 |
if (option.safe && xmode === 'html') {
|
|
|
1523 |
warn_at('adsafe_a', line, character + pos, c);
|
|
|
1524 |
} else if (source_row.charAt(pos + 1) === '/' && (xmode || option.safe)) {
|
|
|
1525 |
warn_at('expected_a_b', line, character,
|
|
|
1526 |
'<\\/', '</');
|
|
|
1527 |
} else if (source_row.charAt(pos + 1) === '!' && (xmode || option.safe)) {
|
|
|
1528 |
warn_at('unexpected_a', line, character, '<!');
|
|
|
1529 |
}
|
|
|
1530 |
} else if (c === '\\') {
|
|
|
1531 |
if (xmode === 'html') {
|
|
|
1532 |
if (option.safe) {
|
|
|
1533 |
warn_at('adsafe_a', line, character + pos, c);
|
|
|
1534 |
}
|
|
|
1535 |
} else if (xmode === 'styleproperty') {
|
|
|
1536 |
pos += 1;
|
|
|
1537 |
character += 1;
|
|
|
1538 |
c = source_row.charAt(pos);
|
|
|
1539 |
if (c !== x) {
|
|
|
1540 |
warn_at('unexpected_a', line, character, '\\');
|
|
|
1541 |
}
|
|
|
1542 |
} else {
|
|
|
1543 |
pos += 1;
|
|
|
1544 |
character += 1;
|
|
|
1545 |
c = source_row.charAt(pos);
|
|
|
1546 |
switch (c) {
|
|
|
1547 |
case '':
|
|
|
1548 |
if (!option.es5) {
|
|
|
1549 |
warn_at('es5', line, character);
|
|
|
1550 |
}
|
|
|
1551 |
next_line();
|
|
|
1552 |
pos = -1;
|
|
|
1553 |
break;
|
|
|
1554 |
case xquote:
|
|
|
1555 |
warn_at('bad_html', line, character + pos);
|
|
|
1556 |
break;
|
|
|
1557 |
case '\'':
|
|
|
1558 |
if (json_mode) {
|
|
|
1559 |
warn_at('unexpected_a', line, character, '\\\'');
|
|
|
1560 |
}
|
|
|
1561 |
break;
|
|
|
1562 |
case 'u':
|
|
|
1563 |
hex(4);
|
|
|
1564 |
break;
|
|
|
1565 |
case 'v':
|
|
|
1566 |
if (json_mode) {
|
|
|
1567 |
warn_at('unexpected_a', line, character, '\\v');
|
|
|
1568 |
}
|
|
|
1569 |
c = '\v';
|
|
|
1570 |
break;
|
|
|
1571 |
case 'x':
|
|
|
1572 |
if (json_mode) {
|
|
|
1573 |
warn_at('unexpected_a', line, character, '\\x');
|
|
|
1574 |
}
|
|
|
1575 |
hex(2);
|
|
|
1576 |
break;
|
|
|
1577 |
default:
|
|
|
1578 |
c = descapes[c];
|
|
|
1579 |
if (typeof c !== 'string') {
|
|
|
1580 |
warn_at('unexpected_a', line, character, '\\');
|
|
|
1581 |
}
|
|
|
1582 |
}
|
|
|
1583 |
}
|
|
|
1584 |
}
|
|
|
1585 |
r += c;
|
|
|
1586 |
character += 1;
|
|
|
1587 |
pos += 1;
|
|
|
1588 |
}
|
|
|
1589 |
}
|
|
|
1590 |
|
|
|
1591 |
function number(snippet) {
|
|
|
1592 |
var digit;
|
|
|
1593 |
if (xmode !== 'style' && xmode !== 'styleproperty' &&
|
|
|
1594 |
source_row.charAt(0).isAlpha()) {
|
|
|
1595 |
warn_at('expected_space_a_b',
|
|
|
1596 |
line, character, c, source_row.charAt(0));
|
|
|
1597 |
}
|
|
|
1598 |
if (c === '0') {
|
|
|
1599 |
digit = snippet.charAt(1);
|
|
|
1600 |
if (digit.isDigit()) {
|
|
|
1601 |
if (token.id !== '.' && xmode !== 'styleproperty') {
|
|
|
1602 |
warn_at('unexpected_a', line, character, snippet);
|
|
|
1603 |
}
|
|
|
1604 |
} else if (json_mode && (digit === 'x' || digit === 'X')) {
|
|
|
1605 |
warn_at('unexpected_a', line, character, '0x');
|
|
|
1606 |
}
|
|
|
1607 |
}
|
|
|
1608 |
if (snippet.slice(snippet.length - 1) === '.') {
|
|
|
1609 |
warn_at('trailing_decimal_a', line, character, snippet);
|
|
|
1610 |
}
|
|
|
1611 |
if (xmode !== 'style') {
|
|
|
1612 |
digit = +snippet;
|
|
|
1613 |
if (!isFinite(digit)) {
|
|
|
1614 |
warn_at('bad_number', line, character, snippet);
|
|
|
1615 |
}
|
|
|
1616 |
snippet = digit;
|
|
|
1617 |
}
|
|
|
1618 |
return it('(number)', snippet);
|
|
|
1619 |
}
|
|
|
1620 |
|
|
|
1621 |
function comment(snippet) {
|
|
|
1622 |
if (comments_off || src || (xmode && xmode !== 'script' &&
|
|
|
1623 |
xmode !== 'style' && xmode !== 'styleproperty')) {
|
|
|
1624 |
warn_at('unexpected_comment', line, character);
|
|
|
1625 |
} else if (xmode === 'script' && /<\//i.test(source_row)) {
|
|
|
1626 |
warn_at('unexpected_a', line, character, '<\/');
|
|
|
1627 |
} else if (option.safe && ax.test(snippet)) {
|
|
|
1628 |
warn_at('dangerous_comment', line, character);
|
|
|
1629 |
}
|
|
|
1630 |
}
|
|
|
1631 |
|
|
|
1632 |
function regexp() {
|
|
|
1633 |
var b,
|
|
|
1634 |
bit,
|
|
|
1635 |
captures = 0,
|
|
|
1636 |
depth = 0,
|
|
|
1637 |
flag = '',
|
|
|
1638 |
high,
|
|
|
1639 |
letter,
|
|
|
1640 |
length = 0,
|
|
|
1641 |
low,
|
|
|
1642 |
potential,
|
|
|
1643 |
quote,
|
|
|
1644 |
result;
|
|
|
1645 |
for (;;) {
|
|
|
1646 |
b = true;
|
|
|
1647 |
c = source_row.charAt(length);
|
|
|
1648 |
length += 1;
|
|
|
1649 |
switch (c) {
|
|
|
1650 |
case '':
|
|
|
1651 |
stop_at('unclosed_regexp', line, from);
|
|
|
1652 |
return;
|
|
|
1653 |
case '/':
|
|
|
1654 |
if (depth > 0) {
|
|
|
1655 |
warn_at('unescaped_a', line, from + length, '/');
|
|
|
1656 |
}
|
|
|
1657 |
c = source_row.slice(0, length - 1);
|
|
|
1658 |
potential = Object.create(regexp_flag);
|
|
|
1659 |
for (;;) {
|
|
|
1660 |
letter = source_row.charAt(length);
|
|
|
1661 |
if (potential[letter] !== true) {
|
|
|
1662 |
break;
|
|
|
1663 |
}
|
|
|
1664 |
potential[letter] = false;
|
|
|
1665 |
length += 1;
|
|
|
1666 |
flag += letter;
|
|
|
1667 |
}
|
|
|
1668 |
if (source_row.charAt(length).isAlpha()) {
|
|
|
1669 |
stop_at('unexpected_a', line, from, source_row.charAt(length));
|
|
|
1670 |
}
|
|
|
1671 |
character += length;
|
|
|
1672 |
source_row = source_row.slice(length);
|
|
|
1673 |
quote = source_row.charAt(0);
|
|
|
1674 |
if (quote === '/' || quote === '*') {
|
|
|
1675 |
stop_at('confusing_regexp', line, from);
|
|
|
1676 |
}
|
|
|
1677 |
result = it('(regexp)', c);
|
|
|
1678 |
result.flag = flag;
|
|
|
1679 |
return result;
|
|
|
1680 |
case '\\':
|
|
|
1681 |
c = source_row.charAt(length);
|
|
|
1682 |
if (c < ' ') {
|
|
|
1683 |
warn_at('control_a', line, from + length, String(c));
|
|
|
1684 |
} else if (c === '<') {
|
|
|
1685 |
warn_at(bundle.unexpected_a, line, from + length, '\\');
|
|
|
1686 |
}
|
|
|
1687 |
length += 1;
|
|
|
1688 |
break;
|
|
|
1689 |
case '(':
|
|
|
1690 |
depth += 1;
|
|
|
1691 |
b = false;
|
|
|
1692 |
if (source_row.charAt(length) === '?') {
|
|
|
1693 |
length += 1;
|
|
|
1694 |
switch (source_row.charAt(length)) {
|
|
|
1695 |
case ':':
|
|
|
1696 |
case '=':
|
|
|
1697 |
case '!':
|
|
|
1698 |
length += 1;
|
|
|
1699 |
break;
|
|
|
1700 |
default:
|
|
|
1701 |
warn_at(bundle.expected_a_b, line, from + length,
|
|
|
1702 |
':', source_row.charAt(length));
|
|
|
1703 |
}
|
|
|
1704 |
} else {
|
|
|
1705 |
captures += 1;
|
|
|
1706 |
}
|
|
|
1707 |
break;
|
|
|
1708 |
case '|':
|
|
|
1709 |
b = false;
|
|
|
1710 |
break;
|
|
|
1711 |
case ')':
|
|
|
1712 |
if (depth === 0) {
|
|
|
1713 |
warn_at('unescaped_a', line, from + length, ')');
|
|
|
1714 |
} else {
|
|
|
1715 |
depth -= 1;
|
|
|
1716 |
}
|
|
|
1717 |
break;
|
|
|
1718 |
case ' ':
|
|
|
1719 |
pos = 1;
|
|
|
1720 |
while (source_row.charAt(length) === ' ') {
|
|
|
1721 |
length += 1;
|
|
|
1722 |
pos += 1;
|
|
|
1723 |
}
|
|
|
1724 |
if (pos > 1) {
|
|
|
1725 |
warn_at('use_braces', line, from + length, pos);
|
|
|
1726 |
}
|
|
|
1727 |
break;
|
|
|
1728 |
case '[':
|
|
|
1729 |
c = source_row.charAt(length);
|
|
|
1730 |
if (c === '^') {
|
|
|
1731 |
length += 1;
|
|
|
1732 |
if (!option.regexp) {
|
|
|
1733 |
warn_at('insecure_a', line, from + length, c);
|
|
|
1734 |
} else if (source_row.charAt(length) === ']') {
|
|
|
1735 |
stop_at('unescaped_a', line, from + length, '^');
|
|
|
1736 |
}
|
|
|
1737 |
}
|
|
|
1738 |
bit = false;
|
|
|
1739 |
if (c === ']') {
|
|
|
1740 |
warn_at('empty_class', line, from + length - 1);
|
|
|
1741 |
bit = true;
|
|
|
1742 |
}
|
|
|
1743 |
klass: do {
|
|
|
1744 |
c = source_row.charAt(length);
|
|
|
1745 |
length += 1;
|
|
|
1746 |
switch (c) {
|
|
|
1747 |
case '[':
|
|
|
1748 |
case '^':
|
|
|
1749 |
warn_at('unescaped_a', line, from + length, c);
|
|
|
1750 |
bit = true;
|
|
|
1751 |
break;
|
|
|
1752 |
case '-':
|
|
|
1753 |
if (bit) {
|
|
|
1754 |
bit = false;
|
|
|
1755 |
} else {
|
|
|
1756 |
warn_at('unescaped_a', line, from + length, '-');
|
|
|
1757 |
bit = true;
|
|
|
1758 |
}
|
|
|
1759 |
break;
|
|
|
1760 |
case ']':
|
|
|
1761 |
if (!bit) {
|
|
|
1762 |
warn_at('unescaped_a', line, from + length - 1, '-');
|
|
|
1763 |
}
|
|
|
1764 |
break klass;
|
|
|
1765 |
case '\\':
|
|
|
1766 |
c = source_row.charAt(length);
|
|
|
1767 |
if (c < ' ') {
|
|
|
1768 |
warn_at(bundle.control_a, line, from + length, String(c));
|
|
|
1769 |
} else if (c === '<') {
|
|
|
1770 |
warn_at(bundle.unexpected_a, line, from + length, '\\');
|
|
|
1771 |
}
|
|
|
1772 |
length += 1;
|
|
|
1773 |
bit = true;
|
|
|
1774 |
break;
|
|
|
1775 |
case '/':
|
|
|
1776 |
warn_at('unescaped_a', line, from + length - 1, '/');
|
|
|
1777 |
bit = true;
|
|
|
1778 |
break;
|
|
|
1779 |
case '<':
|
|
|
1780 |
if (xmode === 'script') {
|
|
|
1781 |
c = source_row.charAt(length);
|
|
|
1782 |
if (c === '!' || c === '/') {
|
|
|
1783 |
warn_at(bundle.html_confusion_a, line,
|
|
|
1784 |
from + length, c);
|
|
|
1785 |
}
|
|
|
1786 |
}
|
|
|
1787 |
bit = true;
|
|
|
1788 |
break;
|
|
|
1789 |
default:
|
|
|
1790 |
bit = true;
|
|
|
1791 |
}
|
|
|
1792 |
} while (c);
|
|
|
1793 |
break;
|
|
|
1794 |
case '.':
|
|
|
1795 |
if (!option.regexp) {
|
|
|
1796 |
warn_at('insecure_a', line, from + length, c);
|
|
|
1797 |
}
|
|
|
1798 |
break;
|
|
|
1799 |
case ']':
|
|
|
1800 |
case '?':
|
|
|
1801 |
case '{':
|
|
|
1802 |
case '}':
|
|
|
1803 |
case '+':
|
|
|
1804 |
case '*':
|
|
|
1805 |
warn_at('unescaped_a', line, from + length, c);
|
|
|
1806 |
break;
|
|
|
1807 |
case '<':
|
|
|
1808 |
if (xmode === 'script') {
|
|
|
1809 |
c = source_row.charAt(length);
|
|
|
1810 |
if (c === '!' || c === '/') {
|
|
|
1811 |
warn_at(bundle.html_confusion_a, line, from + length, c);
|
|
|
1812 |
}
|
|
|
1813 |
}
|
|
|
1814 |
break;
|
|
|
1815 |
}
|
|
|
1816 |
if (b) {
|
|
|
1817 |
switch (source_row.charAt(length)) {
|
|
|
1818 |
case '?':
|
|
|
1819 |
case '+':
|
|
|
1820 |
case '*':
|
|
|
1821 |
length += 1;
|
|
|
1822 |
if (source_row.charAt(length) === '?') {
|
|
|
1823 |
length += 1;
|
|
|
1824 |
}
|
|
|
1825 |
break;
|
|
|
1826 |
case '{':
|
|
|
1827 |
length += 1;
|
|
|
1828 |
c = source_row.charAt(length);
|
|
|
1829 |
if (c < '0' || c > '9') {
|
|
|
1830 |
warn_at(bundle.expected_number_a, line,
|
|
|
1831 |
from + length, c);
|
|
|
1832 |
}
|
|
|
1833 |
length += 1;
|
|
|
1834 |
low = +c;
|
|
|
1835 |
for (;;) {
|
|
|
1836 |
c = source_row.charAt(length);
|
|
|
1837 |
if (c < '0' || c > '9') {
|
|
|
1838 |
break;
|
|
|
1839 |
}
|
|
|
1840 |
length += 1;
|
|
|
1841 |
low = +c + (low * 10);
|
|
|
1842 |
}
|
|
|
1843 |
high = low;
|
|
|
1844 |
if (c === ',') {
|
|
|
1845 |
length += 1;
|
|
|
1846 |
high = Infinity;
|
|
|
1847 |
c = source_row.charAt(length);
|
|
|
1848 |
if (c >= '0' && c <= '9') {
|
|
|
1849 |
length += 1;
|
|
|
1850 |
high = +c;
|
|
|
1851 |
for (;;) {
|
|
|
1852 |
c = source_row.charAt(length);
|
|
|
1853 |
if (c < '0' || c > '9') {
|
|
|
1854 |
break;
|
|
|
1855 |
}
|
|
|
1856 |
length += 1;
|
|
|
1857 |
high = +c + (high * 10);
|
|
|
1858 |
}
|
|
|
1859 |
}
|
|
|
1860 |
}
|
|
|
1861 |
if (source_row.charAt(length) !== '}') {
|
|
|
1862 |
warn_at(bundle.expected_a_b, line, from + length,
|
|
|
1863 |
'}', c);
|
|
|
1864 |
} else {
|
|
|
1865 |
length += 1;
|
|
|
1866 |
}
|
|
|
1867 |
if (source_row.charAt(length) === '?') {
|
|
|
1868 |
length += 1;
|
|
|
1869 |
}
|
|
|
1870 |
if (low > high) {
|
|
|
1871 |
warn_at(bundle.not_greater, line, from + length,
|
|
|
1872 |
low, high);
|
|
|
1873 |
}
|
|
|
1874 |
break;
|
|
|
1875 |
}
|
|
|
1876 |
}
|
|
|
1877 |
}
|
|
|
1878 |
c = source_row.slice(0, length - 1);
|
|
|
1879 |
character += length;
|
|
|
1880 |
source_row = source_row.slice(length);
|
|
|
1881 |
return it('(regexp)', c);
|
|
|
1882 |
}
|
|
|
1883 |
|
|
|
1884 |
// Public lex methods
|
|
|
1885 |
|
|
|
1886 |
return {
|
|
|
1887 |
init: function (source) {
|
|
|
1888 |
if (typeof source === 'string') {
|
|
|
1889 |
lines = source
|
|
|
1890 |
.replace(crlfx, '\n')
|
|
|
1891 |
.replace(crx, '\n')
|
|
|
1892 |
.split('\n');
|
|
|
1893 |
} else {
|
|
|
1894 |
lines = source;
|
|
|
1895 |
}
|
|
|
1896 |
line = 0;
|
|
|
1897 |
next_line();
|
|
|
1898 |
from = 1;
|
|
|
1899 |
},
|
|
|
1900 |
|
|
|
1901 |
range: function (begin, end) {
|
|
|
1902 |
var c, value = '';
|
|
|
1903 |
from = character;
|
|
|
1904 |
if (source_row.charAt(0) !== begin) {
|
|
|
1905 |
stop_at('expected_a_b', line, character, begin,
|
|
|
1906 |
source_row.charAt(0));
|
|
|
1907 |
}
|
|
|
1908 |
for (;;) {
|
|
|
1909 |
source_row = source_row.slice(1);
|
|
|
1910 |
character += 1;
|
|
|
1911 |
c = source_row.charAt(0);
|
|
|
1912 |
switch (c) {
|
|
|
1913 |
case '':
|
|
|
1914 |
stop_at('missing_a', line, character, c);
|
|
|
1915 |
break;
|
|
|
1916 |
case end:
|
|
|
1917 |
source_row = source_row.slice(1);
|
|
|
1918 |
character += 1;
|
|
|
1919 |
return it('(range)', value);
|
|
|
1920 |
case xquote:
|
|
|
1921 |
case '\\':
|
|
|
1922 |
warn_at('unexpected_a', line, character, c);
|
|
|
1923 |
break;
|
|
|
1924 |
}
|
|
|
1925 |
value += c;
|
|
|
1926 |
}
|
|
|
1927 |
},
|
|
|
1928 |
|
|
|
1929 |
// token -- this is called by advance to get the next token.
|
|
|
1930 |
|
|
|
1931 |
token: function () {
|
|
|
1932 |
var c, i, snippet;
|
|
|
1933 |
|
|
|
1934 |
for (;;) {
|
|
|
1935 |
while (!source_row) {
|
|
|
1936 |
if (!next_line()) {
|
|
|
1937 |
return it('(end)');
|
|
|
1938 |
}
|
|
|
1939 |
}
|
|
|
1940 |
while (xmode === 'outer') {
|
|
|
1941 |
i = source_row.search(ox);
|
|
|
1942 |
if (i === 0) {
|
|
|
1943 |
break;
|
|
|
1944 |
} else if (i > 0) {
|
|
|
1945 |
character += 1;
|
|
|
1946 |
source_row = source_row.slice(i);
|
|
|
1947 |
break;
|
|
|
1948 |
} else {
|
|
|
1949 |
if (!next_line()) {
|
|
|
1950 |
return it('(end)', '');
|
|
|
1951 |
}
|
|
|
1952 |
}
|
|
|
1953 |
}
|
|
|
1954 |
snippet = match(rx[xmode] || tx);
|
|
|
1955 |
if (!snippet) {
|
|
|
1956 |
if (source_row) {
|
|
|
1957 |
if (source_row.charAt(0) === ' ') {
|
|
|
1958 |
if (!option.white) {
|
|
|
1959 |
warn_at('unexpected_a', line, character,
|
|
|
1960 |
'(space)');
|
|
|
1961 |
}
|
|
|
1962 |
character += 1;
|
|
|
1963 |
source_row = '';
|
|
|
1964 |
} else {
|
|
|
1965 |
stop_at('unexpected_a', line, character,
|
|
|
1966 |
source_row.charAt(0));
|
|
|
1967 |
}
|
|
|
1968 |
}
|
|
|
1969 |
} else {
|
|
|
1970 |
|
|
|
1971 |
// identifier
|
|
|
1972 |
|
|
|
1973 |
c = snippet.charAt(0);
|
|
|
1974 |
if (c.isAlpha() || c === '_' || c === '$') {
|
|
|
1975 |
return it('(identifier)', snippet);
|
|
|
1976 |
}
|
|
|
1977 |
|
|
|
1978 |
// number
|
|
|
1979 |
|
|
|
1980 |
if (c.isDigit()) {
|
|
|
1981 |
return number(snippet);
|
|
|
1982 |
}
|
|
|
1983 |
switch (snippet) {
|
|
|
1984 |
|
|
|
1985 |
// string
|
|
|
1986 |
|
|
|
1987 |
case '"':
|
|
|
1988 |
case "'":
|
|
|
1989 |
return string(snippet);
|
|
|
1990 |
|
|
|
1991 |
// // comment
|
|
|
1992 |
|
|
|
1993 |
case '//':
|
|
|
1994 |
comment(source_row);
|
|
|
1995 |
source_row = '';
|
|
|
1996 |
break;
|
|
|
1997 |
|
|
|
1998 |
// /* comment
|
|
|
1999 |
|
|
|
2000 |
case '/*':
|
|
|
2001 |
for (;;) {
|
|
|
2002 |
i = source_row.search(lx);
|
|
|
2003 |
if (i >= 0) {
|
|
|
2004 |
break;
|
|
|
2005 |
}
|
|
|
2006 |
comment(source_row);
|
|
|
2007 |
if (!next_line()) {
|
|
|
2008 |
stop_at('unclosed_comment', line, character);
|
|
|
2009 |
}
|
|
|
2010 |
}
|
|
|
2011 |
comment(source_row.slice(0, i));
|
|
|
2012 |
character += i + 2;
|
|
|
2013 |
if (source_row.charAt(i) === '/') {
|
|
|
2014 |
stop_at('nested_comment', line, character);
|
|
|
2015 |
}
|
|
|
2016 |
source_row = source_row.slice(i + 2);
|
|
|
2017 |
break;
|
|
|
2018 |
|
|
|
2019 |
case '':
|
|
|
2020 |
break;
|
|
|
2021 |
// /
|
|
|
2022 |
case '/':
|
|
|
2023 |
if (token.id === '/=') {
|
|
|
2024 |
stop_at(
|
|
|
2025 |
bundle.slash_equal,
|
|
|
2026 |
line,
|
|
|
2027 |
from
|
|
|
2028 |
);
|
|
|
2029 |
}
|
|
|
2030 |
return prereg
|
|
|
2031 |
? regexp()
|
|
|
2032 |
: it('(punctuator)', snippet);
|
|
|
2033 |
|
|
|
2034 |
// punctuator
|
|
|
2035 |
|
|
|
2036 |
case '<!--':
|
|
|
2037 |
length = line;
|
|
|
2038 |
// c = character;
|
|
|
2039 |
for (;;) {
|
|
|
2040 |
i = source_row.indexOf('--');
|
|
|
2041 |
if (i >= 0) {
|
|
|
2042 |
break;
|
|
|
2043 |
}
|
|
|
2044 |
i = source_row.indexOf('<!');
|
|
|
2045 |
if (i >= 0) {
|
|
|
2046 |
stop_at('nested_comment',
|
|
|
2047 |
line, character + i);
|
|
|
2048 |
}
|
|
|
2049 |
if (!next_line()) {
|
|
|
2050 |
stop_at('unclosed_comment', length, c);
|
|
|
2051 |
}
|
|
|
2052 |
}
|
|
|
2053 |
length = source_row.indexOf('<!');
|
|
|
2054 |
if (length >= 0 && length < i) {
|
|
|
2055 |
stop_at('nested_comment',
|
|
|
2056 |
line, character + length);
|
|
|
2057 |
}
|
|
|
2058 |
character += i;
|
|
|
2059 |
if (source_row.charAt(i + 2) !== '>') {
|
|
|
2060 |
stop_at('expected_a', line, character, '-->');
|
|
|
2061 |
}
|
|
|
2062 |
character += 3;
|
|
|
2063 |
source_row = source_row.slice(i + 3);
|
|
|
2064 |
break;
|
|
|
2065 |
case '#':
|
|
|
2066 |
if (xmode === 'html' || xmode === 'styleproperty') {
|
|
|
2067 |
for (;;) {
|
|
|
2068 |
c = source_row.charAt(0);
|
|
|
2069 |
if ((c < '0' || c > '9') &&
|
|
|
2070 |
(c < 'a' || c > 'f') &&
|
|
|
2071 |
(c < 'A' || c > 'F')) {
|
|
|
2072 |
break;
|
|
|
2073 |
}
|
|
|
2074 |
character += 1;
|
|
|
2075 |
source_row = source_row.slice(1);
|
|
|
2076 |
snippet += c;
|
|
|
2077 |
}
|
|
|
2078 |
if (snippet.length !== 4 && snippet.length !== 7) {
|
|
|
2079 |
warn_at('bad_color_a', line,
|
|
|
2080 |
from + length, snippet);
|
|
|
2081 |
}
|
|
|
2082 |
return it('(color)', snippet);
|
|
|
2083 |
}
|
|
|
2084 |
return it('(punctuator)', snippet);
|
|
|
2085 |
|
|
|
2086 |
default:
|
|
|
2087 |
if (xmode === 'outer' && c === '&') {
|
|
|
2088 |
character += 1;
|
|
|
2089 |
source_row = source_row.slice(1);
|
|
|
2090 |
for (;;) {
|
|
|
2091 |
c = source_row.charAt(0);
|
|
|
2092 |
character += 1;
|
|
|
2093 |
source_row = source_row.slice(1);
|
|
|
2094 |
if (c === ';') {
|
|
|
2095 |
break;
|
|
|
2096 |
}
|
|
|
2097 |
if (!((c >= '0' && c <= '9') ||
|
|
|
2098 |
(c >= 'a' && c <= 'z') ||
|
|
|
2099 |
c === '#')) {
|
|
|
2100 |
stop_at('bad_entity', line, from + length,
|
|
|
2101 |
character);
|
|
|
2102 |
}
|
|
|
2103 |
}
|
|
|
2104 |
break;
|
|
|
2105 |
}
|
|
|
2106 |
return it('(punctuator)', snippet);
|
|
|
2107 |
}
|
|
|
2108 |
}
|
|
|
2109 |
}
|
|
|
2110 |
}
|
|
|
2111 |
};
|
|
|
2112 |
}());
|
|
|
2113 |
|
|
|
2114 |
|
|
|
2115 |
function add_label(token, kind, name) {
|
|
|
2116 |
|
|
|
2117 |
// Define the symbol in the current function in the current scope.
|
|
|
2118 |
|
|
|
2119 |
name = name || token.string;
|
|
|
2120 |
|
|
|
2121 |
// Global variables cannot be created in the safe subset. If a global variable
|
|
|
2122 |
// already exists, do nothing. If it is predefined, define it.
|
|
|
2123 |
|
|
|
2124 |
if (funct === global_funct) {
|
|
|
2125 |
if (option.safe) {
|
|
|
2126 |
warn('adsafe_a', token, name);
|
|
|
2127 |
}
|
|
|
2128 |
if (typeof global_funct[name] !== 'string') {
|
|
|
2129 |
token.writeable = typeof predefined[name] === 'boolean'
|
|
|
2130 |
? predefined[name]
|
|
|
2131 |
: true;
|
|
|
2132 |
token.funct = funct;
|
|
|
2133 |
global_scope[name] = token;
|
|
|
2134 |
}
|
|
|
2135 |
if (kind === 'becoming') {
|
|
|
2136 |
kind = 'var';
|
|
|
2137 |
}
|
|
|
2138 |
|
|
|
2139 |
// Ordinary variables.
|
|
|
2140 |
|
|
|
2141 |
} else {
|
|
|
2142 |
|
|
|
2143 |
// Warn if the variable already exists.
|
|
|
2144 |
|
|
|
2145 |
if (typeof funct[name] === 'string') {
|
|
|
2146 |
if (funct[name] === 'undef') {
|
|
|
2147 |
if (!option.undef) {
|
|
|
2148 |
warn('used_before_a', token, name);
|
|
|
2149 |
}
|
|
|
2150 |
kind = 'var';
|
|
|
2151 |
} else {
|
|
|
2152 |
warn('already_defined', token, name);
|
|
|
2153 |
}
|
|
|
2154 |
} else {
|
|
|
2155 |
|
|
|
2156 |
// Add the symbol to the current function.
|
|
|
2157 |
|
|
|
2158 |
token.funct = funct;
|
|
|
2159 |
token.writeable = true;
|
|
|
2160 |
scope[name] = token;
|
|
|
2161 |
}
|
|
|
2162 |
}
|
|
|
2163 |
funct[name] = kind;
|
|
|
2164 |
}
|
|
|
2165 |
|
|
|
2166 |
|
|
|
2167 |
function peek(distance) {
|
|
|
2168 |
|
|
|
2169 |
// Peek ahead to a future token. The distance is how far ahead to look. The
|
|
|
2170 |
// default is the next token.
|
|
|
2171 |
|
|
|
2172 |
var found, slot = 0;
|
|
|
2173 |
|
|
|
2174 |
distance = distance || 0;
|
|
|
2175 |
while (slot <= distance) {
|
|
|
2176 |
found = lookahead[slot];
|
|
|
2177 |
if (!found) {
|
|
|
2178 |
found = lookahead[slot] = lex.token();
|
|
|
2179 |
}
|
|
|
2180 |
slot += 1;
|
|
|
2181 |
}
|
|
|
2182 |
return found;
|
|
|
2183 |
}
|
|
|
2184 |
|
|
|
2185 |
|
|
|
2186 |
function advance(id, match) {
|
|
|
2187 |
|
|
|
2188 |
// Produce the next token, also looking for programming errors.
|
|
|
2189 |
|
|
|
2190 |
if (indent) {
|
|
|
2191 |
|
|
|
2192 |
// If indentation checking was requested, then inspect all of the line breakings.
|
|
|
2193 |
// The var statement is tricky because the names might be aligned or not. We
|
|
|
2194 |
// look at the first line break after the var to determine the programmer's
|
|
|
2195 |
// intention.
|
|
|
2196 |
|
|
|
2197 |
if (var_mode && next_token.line !== token.line) {
|
|
|
2198 |
if ((var_mode !== indent || !next_token.edge) &&
|
|
|
2199 |
next_token.from === indent.at -
|
|
|
2200 |
(next_token.edge ? option.indent : 0)) {
|
|
|
2201 |
var dent = indent;
|
|
|
2202 |
for (;;) {
|
|
|
2203 |
dent.at -= option.indent;
|
|
|
2204 |
if (dent === var_mode) {
|
|
|
2205 |
break;
|
|
|
2206 |
}
|
|
|
2207 |
dent = dent.was;
|
|
|
2208 |
}
|
|
|
2209 |
dent.open = false;
|
|
|
2210 |
}
|
|
|
2211 |
var_mode = null;
|
|
|
2212 |
}
|
|
|
2213 |
if (next_token.id === '?' && indent.mode === ':' &&
|
|
|
2214 |
token.line !== next_token.line) {
|
|
|
2215 |
indent.at -= option.indent;
|
|
|
2216 |
}
|
|
|
2217 |
if (indent.open) {
|
|
|
2218 |
|
|
|
2219 |
// If the token is an edge.
|
|
|
2220 |
|
|
|
2221 |
if (next_token.edge) {
|
|
|
2222 |
if (next_token.edge === 'label') {
|
|
|
2223 |
expected_at(1);
|
|
|
2224 |
} else if (next_token.edge === 'case') {
|
|
|
2225 |
expected_at(indent.at - option.indent);
|
|
|
2226 |
} else if (indent.mode !== 'array' || next_token.line !== token.line) {
|
|
|
2227 |
expected_at(indent.at);
|
|
|
2228 |
}
|
|
|
2229 |
|
|
|
2230 |
// If the token is not an edge, but is the first token on the line.
|
|
|
2231 |
|
|
|
2232 |
} else if (next_token.line !== token.line) {
|
|
|
2233 |
if (next_token.from < indent.at + (indent.mode ===
|
|
|
2234 |
'expression' ? 0 : option.indent)) {
|
|
|
2235 |
expected_at(indent.at + option.indent);
|
|
|
2236 |
}
|
|
|
2237 |
indent.wrap = true;
|
|
|
2238 |
}
|
|
|
2239 |
} else if (next_token.line !== token.line) {
|
|
|
2240 |
if (next_token.edge) {
|
|
|
2241 |
expected_at(indent.at);
|
|
|
2242 |
} else {
|
|
|
2243 |
indent.wrap = true;
|
|
|
2244 |
if (indent.mode === 'statement' || indent.mode === 'var') {
|
|
|
2245 |
expected_at(indent.at + option.indent);
|
|
|
2246 |
} else if (next_token.from < indent.at + (indent.mode ===
|
|
|
2247 |
'expression' ? 0 : option.indent)) {
|
|
|
2248 |
expected_at(indent.at + option.indent);
|
|
|
2249 |
}
|
|
|
2250 |
}
|
|
|
2251 |
}
|
|
|
2252 |
}
|
|
|
2253 |
|
|
|
2254 |
switch (token.id) {
|
|
|
2255 |
case '(number)':
|
|
|
2256 |
if (next_token.id === '.') {
|
|
|
2257 |
warn('trailing_decimal_a');
|
|
|
2258 |
}
|
|
|
2259 |
break;
|
|
|
2260 |
case '-':
|
|
|
2261 |
if (next_token.id === '-' || next_token.id === '--') {
|
|
|
2262 |
warn('confusing_a');
|
|
|
2263 |
}
|
|
|
2264 |
break;
|
|
|
2265 |
case '+':
|
|
|
2266 |
if (next_token.id === '+' || next_token.id === '++') {
|
|
|
2267 |
warn('confusing_a');
|
|
|
2268 |
}
|
|
|
2269 |
break;
|
|
|
2270 |
}
|
|
|
2271 |
if (token.id === '(string)' || token.identifier) {
|
|
|
2272 |
anonname = token.string;
|
|
|
2273 |
}
|
|
|
2274 |
|
|
|
2275 |
if (id && next_token.id !== id) {
|
|
|
2276 |
if (match) {
|
|
|
2277 |
warn('expected_a_b_from_c_d', next_token, id,
|
|
|
2278 |
match.id, match.line, artifact());
|
|
|
2279 |
} else if (!next_token.identifier || next_token.string !== id) {
|
|
|
2280 |
warn('expected_a_b', next_token, id, artifact());
|
|
|
2281 |
}
|
|
|
2282 |
}
|
|
|
2283 |
prev_token = token;
|
|
|
2284 |
token = next_token;
|
|
|
2285 |
next_token = lookahead.shift() || lex.token();
|
|
|
2286 |
}
|
|
|
2287 |
|
|
|
2288 |
|
|
|
2289 |
function advance_identifier(string) {
|
|
|
2290 |
if (next_token.identifier && next_token.string === string) {
|
|
|
2291 |
advance();
|
|
|
2292 |
} else {
|
|
|
2293 |
warn('expected_a_b', next_token, string, artifact());
|
|
|
2294 |
}
|
|
|
2295 |
}
|
|
|
2296 |
|
|
|
2297 |
|
|
|
2298 |
function do_safe() {
|
|
|
2299 |
if (option.adsafe) {
|
|
|
2300 |
option.safe = true;
|
|
|
2301 |
}
|
|
|
2302 |
if (option.safe) {
|
|
|
2303 |
option.browser =
|
|
|
2304 |
option['continue'] =
|
|
|
2305 |
option.css =
|
|
|
2306 |
option.debug =
|
|
|
2307 |
option.devel =
|
|
|
2308 |
option.evil =
|
|
|
2309 |
option.forin =
|
|
|
2310 |
option.newcap =
|
|
|
2311 |
option.nomen =
|
|
|
2312 |
option.on =
|
|
|
2313 |
option.rhino =
|
|
|
2314 |
option.sloppy =
|
|
|
2315 |
option.sub =
|
|
|
2316 |
option.undef =
|
|
|
2317 |
option.widget =
|
|
|
2318 |
option.windows = false;
|
|
|
2319 |
|
|
|
2320 |
|
|
|
2321 |
delete predefined.Array;
|
|
|
2322 |
delete predefined.Date;
|
|
|
2323 |
delete predefined.Function;
|
|
|
2324 |
delete predefined.Object;
|
|
|
2325 |
delete predefined['eval'];
|
|
|
2326 |
|
|
|
2327 |
add_to_predefined({
|
|
|
2328 |
ADSAFE: false,
|
|
|
2329 |
lib: false
|
|
|
2330 |
});
|
|
|
2331 |
}
|
|
|
2332 |
}
|
|
|
2333 |
|
|
|
2334 |
|
|
|
2335 |
function do_globals() {
|
|
|
2336 |
var name, writeable;
|
|
|
2337 |
for (;;) {
|
|
|
2338 |
if (next_token.id !== '(string)' && !next_token.identifier) {
|
|
|
2339 |
return;
|
|
|
2340 |
}
|
|
|
2341 |
name = next_token.string;
|
|
|
2342 |
advance();
|
|
|
2343 |
writeable = false;
|
|
|
2344 |
if (next_token.id === ':') {
|
|
|
2345 |
advance(':');
|
|
|
2346 |
switch (next_token.id) {
|
|
|
2347 |
case 'true':
|
|
|
2348 |
writeable = predefined[name] !== false;
|
|
|
2349 |
advance('true');
|
|
|
2350 |
break;
|
|
|
2351 |
case 'false':
|
|
|
2352 |
advance('false');
|
|
|
2353 |
break;
|
|
|
2354 |
default:
|
|
|
2355 |
stop('unexpected_a');
|
|
|
2356 |
}
|
|
|
2357 |
}
|
|
|
2358 |
predefined[name] = writeable;
|
|
|
2359 |
if (next_token.id !== ',') {
|
|
|
2360 |
return;
|
|
|
2361 |
}
|
|
|
2362 |
advance(',');
|
|
|
2363 |
}
|
|
|
2364 |
}
|
|
|
2365 |
|
|
|
2366 |
|
|
|
2367 |
function do_jslint() {
|
|
|
2368 |
var name, value;
|
|
|
2369 |
while (next_token.id === '(string)' || next_token.identifier) {
|
|
|
2370 |
name = next_token.string;
|
|
|
2371 |
advance();
|
|
|
2372 |
if (next_token.id !== ':') {
|
|
|
2373 |
stop('expected_a_b', next_token, ':', artifact());
|
|
|
2374 |
}
|
|
|
2375 |
advance(':');
|
|
|
2376 |
if (typeof jslint_limit[name] === 'number') {
|
|
|
2377 |
value = next_token.number;
|
|
|
2378 |
if (value > jslint_limit[name] || value <= 0 ||
|
|
|
2379 |
Math.floor(value) !== value) {
|
|
|
2380 |
stop('expected_small_a');
|
|
|
2381 |
}
|
|
|
2382 |
option[name] = value;
|
|
|
2383 |
} else {
|
|
|
2384 |
if (next_token.id === 'true') {
|
|
|
2385 |
option[name] = true;
|
|
|
2386 |
} else if (next_token.id === 'false') {
|
|
|
2387 |
option[name] = false;
|
|
|
2388 |
} else {
|
|
|
2389 |
stop('unexpected_a');
|
|
|
2390 |
}
|
|
|
2391 |
switch (name) {
|
|
|
2392 |
case 'adsafe':
|
|
|
2393 |
option.safe = true;
|
|
|
2394 |
do_safe();
|
|
|
2395 |
break;
|
|
|
2396 |
case 'safe':
|
|
|
2397 |
do_safe();
|
|
|
2398 |
break;
|
|
|
2399 |
}
|
|
|
2400 |
}
|
|
|
2401 |
advance();
|
|
|
2402 |
if (next_token.id === ',') {
|
|
|
2403 |
advance(',');
|
|
|
2404 |
}
|
|
|
2405 |
}
|
|
|
2406 |
assume();
|
|
|
2407 |
}
|
|
|
2408 |
|
|
|
2409 |
|
|
|
2410 |
function do_properties() {
|
|
|
2411 |
var name, type;
|
|
|
2412 |
option.properties = true;
|
|
|
2413 |
if (!funct['(old_property_type)']) {
|
|
|
2414 |
funct['(old_property_type)'] = property_type;
|
|
|
2415 |
property_type = Object.create(property_type);
|
|
|
2416 |
}
|
|
|
2417 |
for (;;) {
|
|
|
2418 |
if (next_token.id !== '(string)' && !next_token.identifier) {
|
|
|
2419 |
return;
|
|
|
2420 |
}
|
|
|
2421 |
name = next_token.string;
|
|
|
2422 |
type = '';
|
|
|
2423 |
advance();
|
|
|
2424 |
if (next_token.id === ':') {
|
|
|
2425 |
advance(':');
|
|
|
2426 |
if (next_token.id === 'function') {
|
|
|
2427 |
advance('function');
|
|
|
2428 |
if (is_type[next_token.string] === true) {
|
|
|
2429 |
type = 'function ' + next_token.string;
|
|
|
2430 |
advance();
|
|
|
2431 |
} else {
|
|
|
2432 |
type = 'function';
|
|
|
2433 |
}
|
|
|
2434 |
} else {
|
|
|
2435 |
type = next_token.string;
|
|
|
2436 |
if (is_type[type] !== true) {
|
|
|
2437 |
warn('expected_type_a', next_token);
|
|
|
2438 |
type = '';
|
|
|
2439 |
}
|
|
|
2440 |
advance();
|
|
|
2441 |
}
|
|
|
2442 |
}
|
|
|
2443 |
property_type[name] = type;
|
|
|
2444 |
if (next_token.id !== ',') {
|
|
|
2445 |
return;
|
|
|
2446 |
}
|
|
|
2447 |
advance(',');
|
|
|
2448 |
}
|
|
|
2449 |
}
|
|
|
2450 |
|
|
|
2451 |
|
|
|
2452 |
directive = function directive() {
|
|
|
2453 |
var command = this.id,
|
|
|
2454 |
old_comments_off = comments_off,
|
|
|
2455 |
old_indent = indent;
|
|
|
2456 |
comments_off = true;
|
|
|
2457 |
indent = null;
|
|
|
2458 |
if (next_token.line === token.line && next_token.from === token.thru) {
|
|
|
2459 |
warn('missing_space_a_b', next_token, artifact(token), artifact());
|
|
|
2460 |
}
|
|
|
2461 |
if (lookahead.length > 0) {
|
|
|
2462 |
warn('unexpected_a', this);
|
|
|
2463 |
}
|
|
|
2464 |
switch (command) {
|
|
|
2465 |
case '/*properties':
|
|
|
2466 |
case '/*property':
|
|
|
2467 |
case '/*members':
|
|
|
2468 |
case '/*member':
|
|
|
2469 |
do_properties();
|
|
|
2470 |
break;
|
|
|
2471 |
case '/*jslint':
|
|
|
2472 |
if (option.safe) {
|
|
|
2473 |
warn('adsafe_a', this);
|
|
|
2474 |
}
|
|
|
2475 |
do_jslint();
|
|
|
2476 |
break;
|
|
|
2477 |
case '/*globals':
|
|
|
2478 |
case '/*global':
|
|
|
2479 |
if (option.safe) {
|
|
|
2480 |
warn('adsafe_a', this);
|
|
|
2481 |
}
|
|
|
2482 |
do_globals();
|
|
|
2483 |
break;
|
|
|
2484 |
default:
|
|
|
2485 |
stop('unexpected_a', this);
|
|
|
2486 |
}
|
|
|
2487 |
comments_off = old_comments_off;
|
|
|
2488 |
advance('*/');
|
|
|
2489 |
indent = old_indent;
|
|
|
2490 |
};
|
|
|
2491 |
|
|
|
2492 |
|
|
|
2493 |
// Indentation intention
|
|
|
2494 |
|
|
|
2495 |
function edge(mode) {
|
|
|
2496 |
next_token.edge = indent ? indent.open && (mode || 'edge') : '';
|
|
|
2497 |
}
|
|
|
2498 |
|
|
|
2499 |
|
|
|
2500 |
function step_in(mode) {
|
|
|
2501 |
var open;
|
|
|
2502 |
if (typeof mode === 'number') {
|
|
|
2503 |
indent = {
|
|
|
2504 |
at: +mode,
|
|
|
2505 |
open: true,
|
|
|
2506 |
was: indent
|
|
|
2507 |
};
|
|
|
2508 |
} else if (!indent) {
|
|
|
2509 |
indent = {
|
|
|
2510 |
at: 1,
|
|
|
2511 |
mode: 'statement',
|
|
|
2512 |
open: true
|
|
|
2513 |
};
|
|
|
2514 |
} else {
|
|
|
2515 |
open = mode === 'var' ||
|
|
|
2516 |
(next_token.line !== token.line && mode !== 'statement');
|
|
|
2517 |
indent = {
|
|
|
2518 |
at: (open || mode === 'control'
|
|
|
2519 |
? indent.at + option.indent
|
|
|
2520 |
: indent.at) + (indent.wrap ? option.indent : 0),
|
|
|
2521 |
mode: mode,
|
|
|
2522 |
open: open,
|
|
|
2523 |
was: indent
|
|
|
2524 |
};
|
|
|
2525 |
if (mode === 'var' && open) {
|
|
|
2526 |
var_mode = indent;
|
|
|
2527 |
}
|
|
|
2528 |
}
|
|
|
2529 |
}
|
|
|
2530 |
|
|
|
2531 |
function step_out(id, symbol) {
|
|
|
2532 |
if (id) {
|
|
|
2533 |
if (indent && indent.open) {
|
|
|
2534 |
indent.at -= option.indent;
|
|
|
2535 |
edge();
|
|
|
2536 |
}
|
|
|
2537 |
advance(id, symbol);
|
|
|
2538 |
}
|
|
|
2539 |
if (indent) {
|
|
|
2540 |
indent = indent.was;
|
|
|
2541 |
}
|
|
|
2542 |
}
|
|
|
2543 |
|
|
|
2544 |
// Functions for conformance of whitespace.
|
|
|
2545 |
|
|
|
2546 |
function one_space(left, right) {
|
|
|
2547 |
left = left || token;
|
|
|
2548 |
right = right || next_token;
|
|
|
2549 |
if (right.id !== '(end)' && !option.white &&
|
|
|
2550 |
(token.line !== right.line ||
|
|
|
2551 |
token.thru + 1 !== right.from)) {
|
|
|
2552 |
warn('expected_space_a_b', right, artifact(token), artifact(right));
|
|
|
2553 |
}
|
|
|
2554 |
}
|
|
|
2555 |
|
|
|
2556 |
function one_space_only(left, right) {
|
|
|
2557 |
left = left || token;
|
|
|
2558 |
right = right || next_token;
|
|
|
2559 |
if (right.id !== '(end)' && (left.line !== right.line ||
|
|
|
2560 |
(!option.white && left.thru + 1 !== right.from))) {
|
|
|
2561 |
warn('expected_space_a_b', right, artifact(left), artifact(right));
|
|
|
2562 |
}
|
|
|
2563 |
}
|
|
|
2564 |
|
|
|
2565 |
function no_space(left, right) {
|
|
|
2566 |
left = left || token;
|
|
|
2567 |
right = right || next_token;
|
|
|
2568 |
if ((!option.white || xmode === 'styleproperty' || xmode === 'style') &&
|
|
|
2569 |
left.thru !== right.from && left.line === right.line) {
|
|
|
2570 |
warn('unexpected_space_a_b', right, artifact(left), artifact(right));
|
|
|
2571 |
}
|
|
|
2572 |
}
|
|
|
2573 |
|
|
|
2574 |
function no_space_only(left, right) {
|
|
|
2575 |
left = left || token;
|
|
|
2576 |
right = right || next_token;
|
|
|
2577 |
if (right.id !== '(end)' && (left.line !== right.line ||
|
|
|
2578 |
(!option.white && left.thru !== right.from))) {
|
|
|
2579 |
warn('unexpected_space_a_b', right, artifact(left), artifact(right));
|
|
|
2580 |
}
|
|
|
2581 |
}
|
|
|
2582 |
|
|
|
2583 |
function spaces(left, right) {
|
|
|
2584 |
if (!option.white) {
|
|
|
2585 |
left = left || token;
|
|
|
2586 |
right = right || next_token;
|
|
|
2587 |
if (left.thru === right.from && left.line === right.line) {
|
|
|
2588 |
warn('missing_space_a_b', right, artifact(left), artifact(right));
|
|
|
2589 |
}
|
|
|
2590 |
}
|
|
|
2591 |
}
|
|
|
2592 |
|
|
|
2593 |
function comma() {
|
|
|
2594 |
if (next_token.id !== ',') {
|
|
|
2595 |
warn_at('expected_a_b', token.line, token.thru, ',', artifact());
|
|
|
2596 |
} else {
|
|
|
2597 |
if (!option.white) {
|
|
|
2598 |
no_space_only();
|
|
|
2599 |
}
|
|
|
2600 |
advance(',');
|
|
|
2601 |
spaces();
|
|
|
2602 |
}
|
|
|
2603 |
}
|
|
|
2604 |
|
|
|
2605 |
|
|
|
2606 |
function semicolon() {
|
|
|
2607 |
if (next_token.id !== ';') {
|
|
|
2608 |
warn_at('expected_a_b', token.line, token.thru, ';', artifact());
|
|
|
2609 |
} else {
|
|
|
2610 |
if (!option.white) {
|
|
|
2611 |
no_space_only();
|
|
|
2612 |
}
|
|
|
2613 |
advance(';');
|
|
|
2614 |
if (semicolon_coda[next_token.id] !== true) {
|
|
|
2615 |
spaces();
|
|
|
2616 |
}
|
|
|
2617 |
}
|
|
|
2618 |
}
|
|
|
2619 |
|
|
|
2620 |
function use_strict() {
|
|
|
2621 |
if (next_token.string === 'use strict') {
|
|
|
2622 |
if (strict_mode) {
|
|
|
2623 |
warn('unnecessary_use');
|
|
|
2624 |
}
|
|
|
2625 |
edge();
|
|
|
2626 |
advance();
|
|
|
2627 |
semicolon();
|
|
|
2628 |
strict_mode = true;
|
|
|
2629 |
option.newcap = false;
|
|
|
2630 |
option.undef = false;
|
|
|
2631 |
return true;
|
|
|
2632 |
} else {
|
|
|
2633 |
return false;
|
|
|
2634 |
}
|
|
|
2635 |
}
|
|
|
2636 |
|
|
|
2637 |
|
|
|
2638 |
function are_similar(a, b) {
|
|
|
2639 |
if (a === b) {
|
|
|
2640 |
return true;
|
|
|
2641 |
}
|
|
|
2642 |
if (Array.isArray(a)) {
|
|
|
2643 |
if (Array.isArray(b) && a.length === b.length) {
|
|
|
2644 |
var i;
|
|
|
2645 |
for (i = 0; i < a.length; i += 1) {
|
|
|
2646 |
if (!are_similar(a[i], b[i])) {
|
|
|
2647 |
return false;
|
|
|
2648 |
}
|
|
|
2649 |
}
|
|
|
2650 |
return true;
|
|
|
2651 |
}
|
|
|
2652 |
return false;
|
|
|
2653 |
}
|
|
|
2654 |
if (Array.isArray(b)) {
|
|
|
2655 |
return false;
|
|
|
2656 |
}
|
|
|
2657 |
if (a.id === '(number)' && b.id === '(number)') {
|
|
|
2658 |
return a.number === b.number;
|
|
|
2659 |
}
|
|
|
2660 |
if (a.arity === b.arity && a.string === b.string) {
|
|
|
2661 |
switch (a.arity) {
|
|
|
2662 |
case 'prefix':
|
|
|
2663 |
case 'suffix':
|
|
|
2664 |
case undefined:
|
|
|
2665 |
return a.id === b.id && are_similar(a.first, b.first);
|
|
|
2666 |
case 'infix':
|
|
|
2667 |
return are_similar(a.first, b.first) &&
|
|
|
2668 |
are_similar(a.second, b.second);
|
|
|
2669 |
case 'ternary':
|
|
|
2670 |
return are_similar(a.first, b.first) &&
|
|
|
2671 |
are_similar(a.second, b.second) &&
|
|
|
2672 |
are_similar(a.third, b.third);
|
|
|
2673 |
case 'function':
|
|
|
2674 |
case 'regexp':
|
|
|
2675 |
return false;
|
|
|
2676 |
default:
|
|
|
2677 |
return true;
|
|
|
2678 |
}
|
|
|
2679 |
} else {
|
|
|
2680 |
if (a.id === '.' && b.id === '[' && b.arity === 'infix') {
|
|
|
2681 |
return a.second.string === b.second.string && b.second.id === '(string)';
|
|
|
2682 |
} else if (a.id === '[' && a.arity === 'infix' && b.id === '.') {
|
|
|
2683 |
return a.second.string === b.second.string && a.second.id === '(string)';
|
|
|
2684 |
}
|
|
|
2685 |
}
|
|
|
2686 |
return false;
|
|
|
2687 |
}
|
|
|
2688 |
|
|
|
2689 |
|
|
|
2690 |
// This is the heart of JSLINT, the Pratt parser. In addition to parsing, it
|
|
|
2691 |
// is looking for ad hoc lint patterns. We add .fud to Pratt's model, which is
|
|
|
2692 |
// like .nud except that it is only used on the first token of a statement.
|
|
|
2693 |
// Having .fud makes it much easier to define statement-oriented languages like
|
|
|
2694 |
// JavaScript. I retained Pratt's nomenclature.
|
|
|
2695 |
|
|
|
2696 |
// .nud Null denotation
|
|
|
2697 |
// .fud First null denotation
|
|
|
2698 |
// .led Left denotation
|
|
|
2699 |
// lbp Left binding power
|
|
|
2700 |
// rbp Right binding power
|
|
|
2701 |
|
|
|
2702 |
// They are elements of the parsing method called Top Down Operator Precedence.
|
|
|
2703 |
|
|
|
2704 |
function expression(rbp, initial) {
|
|
|
2705 |
|
|
|
2706 |
// rbp is the right binding power.
|
|
|
2707 |
// initial indicates that this is the first expression of a statement.
|
|
|
2708 |
|
|
|
2709 |
var left;
|
|
|
2710 |
if (next_token.id === '(end)') {
|
|
|
2711 |
stop('unexpected_a', token, next_token.id);
|
|
|
2712 |
}
|
|
|
2713 |
advance();
|
|
|
2714 |
if (option.safe && scope[token.string] &&
|
|
|
2715 |
scope[token.string] === global_scope[token.string] &&
|
|
|
2716 |
(next_token.id !== '(' && next_token.id !== '.')) {
|
|
|
2717 |
warn('adsafe_a', token);
|
|
|
2718 |
}
|
|
|
2719 |
if (initial) {
|
|
|
2720 |
anonname = 'anonymous';
|
|
|
2721 |
funct['(verb)'] = token.string;
|
|
|
2722 |
}
|
|
|
2723 |
if (initial === true && token.fud) {
|
|
|
2724 |
left = token.fud();
|
|
|
2725 |
} else {
|
|
|
2726 |
if (token.nud) {
|
|
|
2727 |
left = token.nud();
|
|
|
2728 |
} else {
|
|
|
2729 |
if (next_token.id === '(number)' && token.id === '.') {
|
|
|
2730 |
warn('leading_decimal_a', token, artifact());
|
|
|
2731 |
advance();
|
|
|
2732 |
return token;
|
|
|
2733 |
} else {
|
|
|
2734 |
stop('expected_identifier_a', token, token.id);
|
|
|
2735 |
}
|
|
|
2736 |
}
|
|
|
2737 |
while (rbp < next_token.lbp) {
|
|
|
2738 |
advance();
|
|
|
2739 |
if (token.led) {
|
|
|
2740 |
left = token.led(left);
|
|
|
2741 |
} else {
|
|
|
2742 |
stop('expected_operator_a', token, token.id);
|
|
|
2743 |
}
|
|
|
2744 |
}
|
|
|
2745 |
}
|
|
|
2746 |
return left;
|
|
|
2747 |
}
|
|
|
2748 |
|
|
|
2749 |
|
|
|
2750 |
// Functional constructors for making the symbols that will be inherited by
|
|
|
2751 |
// tokens.
|
|
|
2752 |
|
|
|
2753 |
function symbol(s, p) {
|
|
|
2754 |
var x = syntax[s];
|
|
|
2755 |
if (!x || typeof x !== 'object') {
|
|
|
2756 |
syntax[s] = x = {
|
|
|
2757 |
id: s,
|
|
|
2758 |
lbp: p || 0,
|
|
|
2759 |
string: s
|
|
|
2760 |
};
|
|
|
2761 |
}
|
|
|
2762 |
return x;
|
|
|
2763 |
}
|
|
|
2764 |
|
|
|
2765 |
function postscript(x) {
|
|
|
2766 |
x.postscript = true;
|
|
|
2767 |
return x;
|
|
|
2768 |
}
|
|
|
2769 |
|
|
|
2770 |
function ultimate(s) {
|
|
|
2771 |
var x = symbol(s, 0);
|
|
|
2772 |
x.from = 1;
|
|
|
2773 |
x.thru = 1;
|
|
|
2774 |
x.line = 0;
|
|
|
2775 |
x.edge = 'edge';
|
|
|
2776 |
s.string = s;
|
|
|
2777 |
return postscript(x);
|
|
|
2778 |
}
|
|
|
2779 |
|
|
|
2780 |
|
|
|
2781 |
function stmt(s, f) {
|
|
|
2782 |
var x = symbol(s);
|
|
|
2783 |
x.identifier = x.reserved = true;
|
|
|
2784 |
x.fud = f;
|
|
|
2785 |
return x;
|
|
|
2786 |
}
|
|
|
2787 |
|
|
|
2788 |
function labeled_stmt(s, f) {
|
|
|
2789 |
var x = stmt(s, f);
|
|
|
2790 |
x.labeled = true;
|
|
|
2791 |
}
|
|
|
2792 |
|
|
|
2793 |
function disrupt_stmt(s, f) {
|
|
|
2794 |
var x = stmt(s, f);
|
|
|
2795 |
x.disrupt = true;
|
|
|
2796 |
}
|
|
|
2797 |
|
|
|
2798 |
|
|
|
2799 |
function reserve_name(x) {
|
|
|
2800 |
var c = x.id.charAt(0);
|
|
|
2801 |
if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) {
|
|
|
2802 |
x.identifier = x.reserved = true;
|
|
|
2803 |
}
|
|
|
2804 |
return x;
|
|
|
2805 |
}
|
|
|
2806 |
|
|
|
2807 |
|
|
|
2808 |
function prefix(s, f, type) {
|
|
|
2809 |
var x = symbol(s, 150);
|
|
|
2810 |
reserve_name(x);
|
|
|
2811 |
x.nud = typeof f === 'function'
|
|
|
2812 |
? f
|
|
|
2813 |
: function () {
|
|
|
2814 |
if (s === 'typeof') {
|
|
|
2815 |
one_space();
|
|
|
2816 |
} else {
|
|
|
2817 |
no_space_only();
|
|
|
2818 |
}
|
|
|
2819 |
this.first = expression(150);
|
|
|
2820 |
this.arity = 'prefix';
|
|
|
2821 |
if (this.id === '++' || this.id === '--') {
|
|
|
2822 |
if (!option.plusplus) {
|
|
|
2823 |
warn('unexpected_a', this);
|
|
|
2824 |
} else if ((!this.first.identifier || this.first.reserved) &&
|
|
|
2825 |
this.first.id !== '.' && this.first.id !== '[') {
|
|
|
2826 |
warn('bad_operand', this);
|
|
|
2827 |
}
|
|
|
2828 |
}
|
|
|
2829 |
this.type = type;
|
|
|
2830 |
return this;
|
|
|
2831 |
};
|
|
|
2832 |
return x;
|
|
|
2833 |
}
|
|
|
2834 |
|
|
|
2835 |
|
|
|
2836 |
function type(s, t, nud) {
|
|
|
2837 |
var x = symbol(s);
|
|
|
2838 |
x.arity = x.type = t;
|
|
|
2839 |
if (nud) {
|
|
|
2840 |
x.nud = nud;
|
|
|
2841 |
}
|
|
|
2842 |
return x;
|
|
|
2843 |
}
|
|
|
2844 |
|
|
|
2845 |
|
|
|
2846 |
function reserve(s, f) {
|
|
|
2847 |
var x = symbol(s);
|
|
|
2848 |
x.identifier = x.reserved = true;
|
|
|
2849 |
if (typeof f === 'function') {
|
|
|
2850 |
x.nud = f;
|
|
|
2851 |
}
|
|
|
2852 |
return x;
|
|
|
2853 |
}
|
|
|
2854 |
|
|
|
2855 |
|
|
|
2856 |
function constant(name, type) {
|
|
|
2857 |
var x = reserve(name);
|
|
|
2858 |
x.type = type;
|
|
|
2859 |
x.string = name;
|
|
|
2860 |
x.nud = return_this;
|
|
|
2861 |
return x;
|
|
|
2862 |
}
|
|
|
2863 |
|
|
|
2864 |
|
|
|
2865 |
function reservevar(s, v) {
|
|
|
2866 |
return reserve(s, function () {
|
|
|
2867 |
if (typeof v === 'function') {
|
|
|
2868 |
v(this);
|
|
|
2869 |
}
|
|
|
2870 |
return this;
|
|
|
2871 |
});
|
|
|
2872 |
}
|
|
|
2873 |
|
|
|
2874 |
|
|
|
2875 |
function infix(s, p, f, type, w) {
|
|
|
2876 |
var x = symbol(s, p);
|
|
|
2877 |
reserve_name(x);
|
|
|
2878 |
x.led = function (left) {
|
|
|
2879 |
this.arity = 'infix';
|
|
|
2880 |
if (!w) {
|
|
|
2881 |
spaces(prev_token, token);
|
|
|
2882 |
spaces();
|
|
|
2883 |
}
|
|
|
2884 |
if (!option.bitwise && this.bitwise) {
|
|
|
2885 |
warn('unexpected_a', this);
|
|
|
2886 |
}
|
|
|
2887 |
if (typeof f === 'function') {
|
|
|
2888 |
return f(left, this);
|
|
|
2889 |
} else {
|
|
|
2890 |
this.first = left;
|
|
|
2891 |
this.second = expression(p);
|
|
|
2892 |
return this;
|
|
|
2893 |
}
|
|
|
2894 |
};
|
|
|
2895 |
if (type) {
|
|
|
2896 |
x.type = type;
|
|
|
2897 |
}
|
|
|
2898 |
return x;
|
|
|
2899 |
}
|
|
|
2900 |
|
|
|
2901 |
function expected_relation(node, message) {
|
|
|
2902 |
if (node.assign) {
|
|
|
2903 |
warn(message || bundle.conditional_assignment, node);
|
|
|
2904 |
}
|
|
|
2905 |
return node;
|
|
|
2906 |
}
|
|
|
2907 |
|
|
|
2908 |
function expected_condition(node, message) {
|
|
|
2909 |
switch (node.id) {
|
|
|
2910 |
case '[':
|
|
|
2911 |
case '-':
|
|
|
2912 |
if (node.arity !== 'infix') {
|
|
|
2913 |
warn(message || bundle.weird_condition, node);
|
|
|
2914 |
}
|
|
|
2915 |
break;
|
|
|
2916 |
case 'false':
|
|
|
2917 |
case 'function':
|
|
|
2918 |
case 'Infinity':
|
|
|
2919 |
case 'NaN':
|
|
|
2920 |
case 'null':
|
|
|
2921 |
case 'true':
|
|
|
2922 |
case 'undefined':
|
|
|
2923 |
case 'void':
|
|
|
2924 |
case '(number)':
|
|
|
2925 |
case '(regexp)':
|
|
|
2926 |
case '(string)':
|
|
|
2927 |
case '{':
|
|
|
2928 |
warn(message || bundle.weird_condition, node);
|
|
|
2929 |
break;
|
|
|
2930 |
case '(':
|
|
|
2931 |
if (node.first.id === '.' && numbery[node.first.second.string] === true) {
|
|
|
2932 |
warn(message || bundle.weird_condition, node);
|
|
|
2933 |
}
|
|
|
2934 |
break;
|
|
|
2935 |
}
|
|
|
2936 |
return node;
|
|
|
2937 |
}
|
|
|
2938 |
|
|
|
2939 |
function check_relation(node) {
|
|
|
2940 |
switch (node.arity) {
|
|
|
2941 |
case 'prefix':
|
|
|
2942 |
switch (node.id) {
|
|
|
2943 |
case '{':
|
|
|
2944 |
case '[':
|
|
|
2945 |
warn('unexpected_a', node);
|
|
|
2946 |
break;
|
|
|
2947 |
case '!':
|
|
|
2948 |
warn('confusing_a', node);
|
|
|
2949 |
break;
|
|
|
2950 |
}
|
|
|
2951 |
break;
|
|
|
2952 |
case 'function':
|
|
|
2953 |
case 'regexp':
|
|
|
2954 |
warn('unexpected_a', node);
|
|
|
2955 |
break;
|
|
|
2956 |
default:
|
|
|
2957 |
if (node.id === 'NaN') {
|
|
|
2958 |
warn('isnan', node);
|
|
|
2959 |
}
|
|
|
2960 |
}
|
|
|
2961 |
return node;
|
|
|
2962 |
}
|
|
|
2963 |
|
|
|
2964 |
|
|
|
2965 |
function relation(s, eqeq) {
|
|
|
2966 |
return infix(s, 100, function (left, that) {
|
|
|
2967 |
check_relation(left);
|
|
|
2968 |
if (eqeq && !option.eqeq) {
|
|
|
2969 |
warn('expected_a_b', that, eqeq, that.id);
|
|
|
2970 |
}
|
|
|
2971 |
var right = expression(100);
|
|
|
2972 |
if (are_similar(left, right) ||
|
|
|
2973 |
((left.id === '(string)' || left.id === '(number)') &&
|
|
|
2974 |
(right.id === '(string)' || right.id === '(number)'))) {
|
|
|
2975 |
warn('weird_relation', that);
|
|
|
2976 |
}
|
|
|
2977 |
that.first = left;
|
|
|
2978 |
that.second = check_relation(right);
|
|
|
2979 |
return that;
|
|
|
2980 |
}, 'boolean');
|
|
|
2981 |
}
|
|
|
2982 |
|
|
|
2983 |
|
|
|
2984 |
function assignop(s, op) {
|
|
|
2985 |
var x = infix(s, 20, function (left, that) {
|
|
|
2986 |
var l;
|
|
|
2987 |
that.first = left;
|
|
|
2988 |
if (left.identifier) {
|
|
|
2989 |
if (scope[left.string]) {
|
|
|
2990 |
if (scope[left.string].writeable === false) {
|
|
|
2991 |
warn('read_only', left);
|
|
|
2992 |
}
|
|
|
2993 |
} else {
|
|
|
2994 |
stop('read_only');
|
|
|
2995 |
}
|
|
|
2996 |
} else if (option.safe) {
|
|
|
2997 |
l = left;
|
|
|
2998 |
do {
|
|
|
2999 |
if (typeof predefined[l.string] === 'boolean') {
|
|
|
3000 |
warn('adsafe_a', l);
|
|
|
3001 |
}
|
|
|
3002 |
l = l.first;
|
|
|
3003 |
} while (l);
|
|
|
3004 |
}
|
|
|
3005 |
if (left === syntax['function']) {
|
|
|
3006 |
warn('identifier_function', token);
|
|
|
3007 |
}
|
|
|
3008 |
if (left.id === '.' || left.id === '[') {
|
|
|
3009 |
if (!left.first || left.first.string === 'arguments') {
|
|
|
3010 |
warn('bad_assignment', that);
|
|
|
3011 |
}
|
|
|
3012 |
} else if (left.identifier && !left.reserved) {
|
|
|
3013 |
if (funct[left.string] === 'exception') {
|
|
|
3014 |
warn('assign_exception', left);
|
|
|
3015 |
}
|
|
|
3016 |
}
|
|
|
3017 |
that.second = expression(19);
|
|
|
3018 |
if (that.id === '=' && are_similar(that.first, that.second)) {
|
|
|
3019 |
warn('weird_assignment', that);
|
|
|
3020 |
}
|
|
|
3021 |
return that;
|
|
|
3022 |
});
|
|
|
3023 |
x.assign = true;
|
|
|
3024 |
if (op) {
|
|
|
3025 |
if (syntax[op].type) {
|
|
|
3026 |
x.type = syntax[op].type;
|
|
|
3027 |
}
|
|
|
3028 |
if (syntax[op].bitwise) {
|
|
|
3029 |
x.bitwise = true;
|
|
|
3030 |
}
|
|
|
3031 |
}
|
|
|
3032 |
return x;
|
|
|
3033 |
}
|
|
|
3034 |
|
|
|
3035 |
|
|
|
3036 |
function bitwise(s, p) {
|
|
|
3037 |
var x = infix(s, p, 'number');
|
|
|
3038 |
x.bitwise = true;
|
|
|
3039 |
return x;
|
|
|
3040 |
}
|
|
|
3041 |
|
|
|
3042 |
|
|
|
3043 |
function suffix(s) {
|
|
|
3044 |
var x = symbol(s, 150);
|
|
|
3045 |
x.led = function (left) {
|
|
|
3046 |
no_space_only(prev_token, token);
|
|
|
3047 |
if (!option.plusplus) {
|
|
|
3048 |
warn('unexpected_a', this);
|
|
|
3049 |
} else if ((!left.identifier || left.reserved) &&
|
|
|
3050 |
left.id !== '.' && left.id !== '[') {
|
|
|
3051 |
warn('bad_operand', this);
|
|
|
3052 |
}
|
|
|
3053 |
this.first = left;
|
|
|
3054 |
this.arity = 'suffix';
|
|
|
3055 |
return this;
|
|
|
3056 |
};
|
|
|
3057 |
return x;
|
|
|
3058 |
}
|
|
|
3059 |
|
|
|
3060 |
|
|
|
3061 |
function optional_identifier() {
|
|
|
3062 |
if (next_token.identifier) {
|
|
|
3063 |
advance();
|
|
|
3064 |
if (option.safe && banned[token.string]) {
|
|
|
3065 |
warn('adsafe_a', token);
|
|
|
3066 |
} else if (token.reserved && !option.es5) {
|
|
|
3067 |
warn('expected_identifier_a_reserved', token);
|
|
|
3068 |
}
|
|
|
3069 |
return token.string;
|
|
|
3070 |
}
|
|
|
3071 |
}
|
|
|
3072 |
|
|
|
3073 |
|
|
|
3074 |
function identifier() {
|
|
|
3075 |
var i = optional_identifier();
|
|
|
3076 |
if (!i) {
|
|
|
3077 |
stop(token.id === 'function' && next_token.id === '('
|
|
|
3078 |
? 'name_function'
|
|
|
3079 |
: 'expected_identifier_a');
|
|
|
3080 |
}
|
|
|
3081 |
return i;
|
|
|
3082 |
}
|
|
|
3083 |
|
|
|
3084 |
|
|
|
3085 |
function statement() {
|
|
|
3086 |
|
|
|
3087 |
var label, old_scope = scope, the_statement;
|
|
|
3088 |
|
|
|
3089 |
// We don't like the empty statement.
|
|
|
3090 |
|
|
|
3091 |
if (next_token.id === ';') {
|
|
|
3092 |
warn('unexpected_a');
|
|
|
3093 |
semicolon();
|
|
|
3094 |
return;
|
|
|
3095 |
}
|
|
|
3096 |
|
|
|
3097 |
// Is this a labeled statement?
|
|
|
3098 |
|
|
|
3099 |
if (next_token.identifier && !next_token.reserved && peek().id === ':') {
|
|
|
3100 |
edge('label');
|
|
|
3101 |
label = next_token;
|
|
|
3102 |
advance();
|
|
|
3103 |
advance(':');
|
|
|
3104 |
scope = Object.create(old_scope);
|
|
|
3105 |
add_label(label, 'label');
|
|
|
3106 |
if (next_token.labeled !== true) {
|
|
|
3107 |
warn('label_a_b', next_token, label.string, artifact());
|
|
|
3108 |
} else if (jx.test(label.string + ':')) {
|
|
|
3109 |
warn('url', label);
|
|
|
3110 |
} else if (funct === global_funct) {
|
|
|
3111 |
stop('unexpected_a', token);
|
|
|
3112 |
}
|
|
|
3113 |
next_token.label = label;
|
|
|
3114 |
}
|
|
|
3115 |
|
|
|
3116 |
// Parse the statement.
|
|
|
3117 |
|
|
|
3118 |
edge();
|
|
|
3119 |
step_in('statement');
|
|
|
3120 |
the_statement = expression(0, true);
|
|
|
3121 |
if (the_statement) {
|
|
|
3122 |
|
|
|
3123 |
// Look for the final semicolon.
|
|
|
3124 |
|
|
|
3125 |
if (the_statement.arity === 'statement') {
|
|
|
3126 |
if (the_statement.id === 'switch' ||
|
|
|
3127 |
(the_statement.block && the_statement.id !== 'do')) {
|
|
|
3128 |
spaces();
|
|
|
3129 |
} else {
|
|
|
3130 |
semicolon();
|
|
|
3131 |
}
|
|
|
3132 |
} else {
|
|
|
3133 |
|
|
|
3134 |
// If this is an expression statement, determine if it is acceptable.
|
|
|
3135 |
// We do not like
|
|
|
3136 |
// new Blah();
|
|
|
3137 |
// statments. If it is to be used at all, new should only be used to make
|
|
|
3138 |
// objects, not side effects. The expression statements we do like do
|
|
|
3139 |
// assignment or invocation or delete.
|
|
|
3140 |
|
|
|
3141 |
if (the_statement.id === '(') {
|
|
|
3142 |
if (the_statement.first.id === 'new') {
|
|
|
3143 |
warn('bad_new');
|
|
|
3144 |
}
|
|
|
3145 |
} else if (!the_statement.assign &&
|
|
|
3146 |
the_statement.id !== 'delete' &&
|
|
|
3147 |
the_statement.id !== '++' &&
|
|
|
3148 |
the_statement.id !== '--') {
|
|
|
3149 |
warn('assignment_function_expression', token);
|
|
|
3150 |
}
|
|
|
3151 |
semicolon();
|
|
|
3152 |
}
|
|
|
3153 |
}
|
|
|
3154 |
step_out();
|
|
|
3155 |
scope = old_scope;
|
|
|
3156 |
return the_statement;
|
|
|
3157 |
}
|
|
|
3158 |
|
|
|
3159 |
|
|
|
3160 |
function statements() {
|
|
|
3161 |
var array = [], disruptor, the_statement;
|
|
|
3162 |
|
|
|
3163 |
// A disrupt statement may not be followed by any other statement.
|
|
|
3164 |
// If the last statement is disrupt, then the sequence is disrupt.
|
|
|
3165 |
|
|
|
3166 |
while (next_token.postscript !== true) {
|
|
|
3167 |
if (next_token.id === ';') {
|
|
|
3168 |
warn('unexpected_a', next_token);
|
|
|
3169 |
semicolon();
|
|
|
3170 |
} else {
|
|
|
3171 |
if (next_token.string === 'use strict') {
|
|
|
3172 |
if ((!node_js && xmode !== 'script') || funct !== global_funct || array.length > 0) {
|
|
|
3173 |
warn('function_strict');
|
|
|
3174 |
}
|
|
|
3175 |
use_strict();
|
|
|
3176 |
}
|
|
|
3177 |
if (disruptor) {
|
|
|
3178 |
warn('unreachable_a_b', next_token, next_token.string,
|
|
|
3179 |
disruptor.string);
|
|
|
3180 |
disruptor = null;
|
|
|
3181 |
}
|
|
|
3182 |
the_statement = statement();
|
|
|
3183 |
if (the_statement) {
|
|
|
3184 |
array.push(the_statement);
|
|
|
3185 |
if (the_statement.disrupt) {
|
|
|
3186 |
disruptor = the_statement;
|
|
|
3187 |
array.disrupt = true;
|
|
|
3188 |
}
|
|
|
3189 |
}
|
|
|
3190 |
}
|
|
|
3191 |
}
|
|
|
3192 |
return array;
|
|
|
3193 |
}
|
|
|
3194 |
|
|
|
3195 |
|
|
|
3196 |
function block(ordinary) {
|
|
|
3197 |
|
|
|
3198 |
// array block is array sequence of statements wrapped in braces.
|
|
|
3199 |
// ordinary is false for function bodies and try blocks.
|
|
|
3200 |
// ordinary is true for if statements, while, etc.
|
|
|
3201 |
|
|
|
3202 |
var array,
|
|
|
3203 |
curly = next_token,
|
|
|
3204 |
old_in_block = in_block,
|
|
|
3205 |
old_scope = scope,
|
|
|
3206 |
old_strict_mode = strict_mode;
|
|
|
3207 |
|
|
|
3208 |
in_block = ordinary;
|
|
|
3209 |
scope = Object.create(scope);
|
|
|
3210 |
spaces();
|
|
|
3211 |
if (next_token.id === '{') {
|
|
|
3212 |
advance('{');
|
|
|
3213 |
step_in();
|
|
|
3214 |
if (!ordinary && !use_strict() && !old_strict_mode &&
|
|
|
3215 |
!option.sloppy && funct['(context)'] === global_funct) {
|
|
|
3216 |
warn('missing_use_strict');
|
|
|
3217 |
}
|
|
|
3218 |
array = statements();
|
|
|
3219 |
strict_mode = old_strict_mode;
|
|
|
3220 |
step_out('}', curly);
|
|
|
3221 |
} else if (!ordinary) {
|
|
|
3222 |
stop('expected_a_b', next_token, '{', artifact());
|
|
|
3223 |
} else {
|
|
|
3224 |
warn('expected_a_b', next_token, '{', artifact());
|
|
|
3225 |
array = [statement()];
|
|
|
3226 |
array.disrupt = array[0].disrupt;
|
|
|
3227 |
}
|
|
|
3228 |
funct['(verb)'] = null;
|
|
|
3229 |
scope = old_scope;
|
|
|
3230 |
in_block = old_in_block;
|
|
|
3231 |
if (ordinary && array.length === 0) {
|
|
|
3232 |
warn('empty_block');
|
|
|
3233 |
}
|
|
|
3234 |
return array;
|
|
|
3235 |
}
|
|
|
3236 |
|
|
|
3237 |
|
|
|
3238 |
function tally_property(name) {
|
|
|
3239 |
if (option.properties && typeof property_type[name] !== 'string') {
|
|
|
3240 |
warn('unexpected_property_a', token, name);
|
|
|
3241 |
}
|
|
|
3242 |
if (typeof member[name] === 'number') {
|
|
|
3243 |
member[name] += 1;
|
|
|
3244 |
} else {
|
|
|
3245 |
member[name] = 1;
|
|
|
3246 |
}
|
|
|
3247 |
}
|
|
|
3248 |
|
|
|
3249 |
|
|
|
3250 |
// ECMAScript parser
|
|
|
3251 |
|
|
|
3252 |
syntax['(identifier)'] = {
|
|
|
3253 |
id: '(identifier)',
|
|
|
3254 |
lbp: 0,
|
|
|
3255 |
identifier: true,
|
|
|
3256 |
nud: function () {
|
|
|
3257 |
var name = this.string,
|
|
|
3258 |
variable = scope[name],
|
|
|
3259 |
site,
|
|
|
3260 |
writeable;
|
|
|
3261 |
|
|
|
3262 |
// If the variable is not in scope, then we may have an undeclared variable.
|
|
|
3263 |
// Check the predefined list. If it was predefined, create the global
|
|
|
3264 |
// variable.
|
|
|
3265 |
|
|
|
3266 |
if (typeof variable !== 'object') {
|
|
|
3267 |
writeable = predefined[name];
|
|
|
3268 |
if (typeof writeable === 'boolean') {
|
|
|
3269 |
global_scope[name] = variable = {
|
|
|
3270 |
string: name,
|
|
|
3271 |
writeable: writeable,
|
|
|
3272 |
funct: global_funct
|
|
|
3273 |
};
|
|
|
3274 |
global_funct[name] = 'var';
|
|
|
3275 |
|
|
|
3276 |
// But if the variable is not in scope, and is not predefined, and if we are not
|
|
|
3277 |
// in the global scope, then we have an undefined variable error.
|
|
|
3278 |
|
|
|
3279 |
} else {
|
|
|
3280 |
if (!option.undef) {
|
|
|
3281 |
warn('used_before_a', token);
|
|
|
3282 |
}
|
|
|
3283 |
scope[name] = variable = {
|
|
|
3284 |
string: name,
|
|
|
3285 |
writeable: true,
|
|
|
3286 |
funct: funct
|
|
|
3287 |
};
|
|
|
3288 |
funct[name] = 'undef';
|
|
|
3289 |
}
|
|
|
3290 |
|
|
|
3291 |
}
|
|
|
3292 |
site = variable.funct;
|
|
|
3293 |
|
|
|
3294 |
// The name is in scope and defined in the current function.
|
|
|
3295 |
|
|
|
3296 |
if (funct === site) {
|
|
|
3297 |
|
|
|
3298 |
// Change 'unused' to 'var', and reject labels.
|
|
|
3299 |
|
|
|
3300 |
switch (funct[name]) {
|
|
|
3301 |
case 'becoming':
|
|
|
3302 |
warn('unexpected_a', token);
|
|
|
3303 |
funct[name] = 'var';
|
|
|
3304 |
break;
|
|
|
3305 |
case 'unused':
|
|
|
3306 |
funct[name] = 'var';
|
|
|
3307 |
break;
|
|
|
3308 |
case 'unparam':
|
|
|
3309 |
funct[name] = 'parameter';
|
|
|
3310 |
break;
|
|
|
3311 |
case 'unction':
|
|
|
3312 |
funct[name] = 'function';
|
|
|
3313 |
break;
|
|
|
3314 |
case 'label':
|
|
|
3315 |
warn('a_label', token, name);
|
|
|
3316 |
break;
|
|
|
3317 |
}
|
|
|
3318 |
|
|
|
3319 |
// If the name is already defined in the current
|
|
|
3320 |
// function, but not as outer, then there is a scope error.
|
|
|
3321 |
|
|
|
3322 |
} else {
|
|
|
3323 |
switch (funct[name]) {
|
|
|
3324 |
case 'closure':
|
|
|
3325 |
case 'function':
|
|
|
3326 |
case 'var':
|
|
|
3327 |
case 'unused':
|
|
|
3328 |
warn('a_scope', token, name);
|
|
|
3329 |
break;
|
|
|
3330 |
case 'label':
|
|
|
3331 |
warn('a_label', token, name);
|
|
|
3332 |
break;
|
|
|
3333 |
case 'outer':
|
|
|
3334 |
case 'global':
|
|
|
3335 |
break;
|
|
|
3336 |
default:
|
|
|
3337 |
|
|
|
3338 |
// If the name is defined in an outer function, make an outer entry, and if
|
|
|
3339 |
// it was unused, make it var.
|
|
|
3340 |
|
|
|
3341 |
switch (site[name]) {
|
|
|
3342 |
case 'becoming':
|
|
|
3343 |
case 'closure':
|
|
|
3344 |
case 'function':
|
|
|
3345 |
case 'parameter':
|
|
|
3346 |
case 'unction':
|
|
|
3347 |
case 'unused':
|
|
|
3348 |
case 'var':
|
|
|
3349 |
site[name] = 'closure';
|
|
|
3350 |
funct[name] = site === global_funct
|
|
|
3351 |
? 'global'
|
|
|
3352 |
: 'outer';
|
|
|
3353 |
break;
|
|
|
3354 |
case 'unparam':
|
|
|
3355 |
site[name] = 'parameter';
|
|
|
3356 |
funct[name] = 'outer';
|
|
|
3357 |
break;
|
|
|
3358 |
case 'undef':
|
|
|
3359 |
funct[name] = 'undef';
|
|
|
3360 |
break;
|
|
|
3361 |
case 'label':
|
|
|
3362 |
warn('a_label', token, name);
|
|
|
3363 |
break;
|
|
|
3364 |
}
|
|
|
3365 |
}
|
|
|
3366 |
}
|
|
|
3367 |
return this;
|
|
|
3368 |
},
|
|
|
3369 |
led: function () {
|
|
|
3370 |
stop('expected_operator_a');
|
|
|
3371 |
}
|
|
|
3372 |
};
|
|
|
3373 |
|
|
|
3374 |
// Build the syntax table by declaring the syntactic elements.
|
|
|
3375 |
|
|
|
3376 |
type('(array)', 'array');
|
|
|
3377 |
type('(color)', 'color');
|
|
|
3378 |
type('(function)', 'function');
|
|
|
3379 |
type('(number)', 'number', return_this);
|
|
|
3380 |
type('(object)', 'object');
|
|
|
3381 |
type('(string)', 'string', return_this);
|
|
|
3382 |
type('(boolean)', 'boolean', return_this);
|
|
|
3383 |
type('(range)', 'range');
|
|
|
3384 |
type('(regexp)', 'regexp', return_this);
|
|
|
3385 |
|
|
|
3386 |
ultimate('(begin)');
|
|
|
3387 |
ultimate('(end)');
|
|
|
3388 |
ultimate('(error)');
|
|
|
3389 |
postscript(symbol('</'));
|
|
|
3390 |
symbol('<!');
|
|
|
3391 |
symbol('<!--');
|
|
|
3392 |
symbol('-->');
|
|
|
3393 |
postscript(symbol('}'));
|
|
|
3394 |
symbol(')');
|
|
|
3395 |
symbol(']');
|
|
|
3396 |
postscript(symbol('"'));
|
|
|
3397 |
postscript(symbol('\''));
|
|
|
3398 |
symbol(';');
|
|
|
3399 |
symbol(':');
|
|
|
3400 |
symbol(',');
|
|
|
3401 |
symbol('#');
|
|
|
3402 |
symbol('@');
|
|
|
3403 |
symbol('*/');
|
|
|
3404 |
postscript(reserve('case'));
|
|
|
3405 |
reserve('catch');
|
|
|
3406 |
postscript(reserve('default'));
|
|
|
3407 |
reserve('else');
|
|
|
3408 |
reserve('finally');
|
|
|
3409 |
|
|
|
3410 |
reservevar('arguments', function (x) {
|
|
|
3411 |
if (strict_mode && funct === global_funct) {
|
|
|
3412 |
warn('strict', x);
|
|
|
3413 |
} else if (option.safe) {
|
|
|
3414 |
warn('adsafe_a', x);
|
|
|
3415 |
}
|
|
|
3416 |
});
|
|
|
3417 |
reservevar('eval', function (x) {
|
|
|
3418 |
if (option.safe) {
|
|
|
3419 |
warn('adsafe_a', x);
|
|
|
3420 |
}
|
|
|
3421 |
});
|
|
|
3422 |
constant('false', 'boolean');
|
|
|
3423 |
constant('Infinity', 'number');
|
|
|
3424 |
constant('NaN', 'number');
|
|
|
3425 |
constant('null', '');
|
|
|
3426 |
reservevar('this', function (x) {
|
|
|
3427 |
if (option.safe) {
|
|
|
3428 |
warn('adsafe_a', x);
|
|
|
3429 |
} else if (strict_mode && funct['(token)'].arity === 'statement' &&
|
|
|
3430 |
funct['(name)'].charAt(0) > 'Z') {
|
|
|
3431 |
warn('strict', x);
|
|
|
3432 |
}
|
|
|
3433 |
});
|
|
|
3434 |
constant('true', 'boolean');
|
|
|
3435 |
constant('undefined', '');
|
|
|
3436 |
|
|
|
3437 |
infix('?', 30, function (left, that) {
|
|
|
3438 |
step_in('?');
|
|
|
3439 |
that.first = expected_condition(expected_relation(left));
|
|
|
3440 |
that.second = expression(0);
|
|
|
3441 |
spaces();
|
|
|
3442 |
step_out();
|
|
|
3443 |
var colon = next_token;
|
|
|
3444 |
advance(':');
|
|
|
3445 |
step_in(':');
|
|
|
3446 |
spaces();
|
|
|
3447 |
that.third = expression(10);
|
|
|
3448 |
that.arity = 'ternary';
|
|
|
3449 |
if (are_similar(that.second, that.third)) {
|
|
|
3450 |
warn('weird_ternary', colon);
|
|
|
3451 |
} else if (are_similar(that.first, that.second)) {
|
|
|
3452 |
warn('use_or', that);
|
|
|
3453 |
}
|
|
|
3454 |
step_out();
|
|
|
3455 |
return that;
|
|
|
3456 |
});
|
|
|
3457 |
|
|
|
3458 |
infix('||', 40, function (left, that) {
|
|
|
3459 |
function paren_check(that) {
|
|
|
3460 |
if (that.id === '&&' && !that.paren) {
|
|
|
3461 |
warn('and', that);
|
|
|
3462 |
}
|
|
|
3463 |
return that;
|
|
|
3464 |
}
|
|
|
3465 |
|
|
|
3466 |
that.first = paren_check(expected_condition(expected_relation(left)));
|
|
|
3467 |
that.second = paren_check(expected_relation(expression(40)));
|
|
|
3468 |
if (are_similar(that.first, that.second)) {
|
|
|
3469 |
warn('weird_condition', that);
|
|
|
3470 |
}
|
|
|
3471 |
return that;
|
|
|
3472 |
});
|
|
|
3473 |
|
|
|
3474 |
infix('&&', 50, function (left, that) {
|
|
|
3475 |
that.first = expected_condition(expected_relation(left));
|
|
|
3476 |
that.second = expected_relation(expression(50));
|
|
|
3477 |
if (are_similar(that.first, that.second)) {
|
|
|
3478 |
warn('weird_condition', that);
|
|
|
3479 |
}
|
|
|
3480 |
return that;
|
|
|
3481 |
});
|
|
|
3482 |
|
|
|
3483 |
prefix('void', function () {
|
|
|
3484 |
this.first = expression(0);
|
|
|
3485 |
this.arity = 'prefix';
|
|
|
3486 |
if (option.es5) {
|
|
|
3487 |
warn('expected_a_b', this, 'undefined', 'void');
|
|
|
3488 |
} else if (this.first.number !== 0) {
|
|
|
3489 |
warn('expected_a_b', this.first, '0', artifact(this.first));
|
|
|
3490 |
}
|
|
|
3491 |
this.type = 'undefined';
|
|
|
3492 |
return this;
|
|
|
3493 |
});
|
|
|
3494 |
|
|
|
3495 |
bitwise('|', 70);
|
|
|
3496 |
bitwise('^', 80);
|
|
|
3497 |
bitwise('&', 90);
|
|
|
3498 |
|
|
|
3499 |
relation('==', '===');
|
|
|
3500 |
relation('===');
|
|
|
3501 |
relation('!=', '!==');
|
|
|
3502 |
relation('!==');
|
|
|
3503 |
relation('<');
|
|
|
3504 |
relation('>');
|
|
|
3505 |
relation('<=');
|
|
|
3506 |
relation('>=');
|
|
|
3507 |
|
|
|
3508 |
bitwise('<<', 120);
|
|
|
3509 |
bitwise('>>', 120);
|
|
|
3510 |
bitwise('>>>', 120);
|
|
|
3511 |
|
|
|
3512 |
infix('in', 120, function (left, that) {
|
|
|
3513 |
warn('infix_in', that);
|
|
|
3514 |
that.left = left;
|
|
|
3515 |
that.right = expression(130);
|
|
|
3516 |
return that;
|
|
|
3517 |
}, 'boolean');
|
|
|
3518 |
infix('instanceof', 120, null, 'boolean');
|
|
|
3519 |
infix('+', 130, function (left, that) {
|
|
|
3520 |
if (left.id === '(number)') {
|
|
|
3521 |
if (left.number === 0) {
|
|
|
3522 |
warn('unexpected_a', left, '0');
|
|
|
3523 |
}
|
|
|
3524 |
} else if (left.id === '(string)') {
|
|
|
3525 |
if (left.string === '') {
|
|
|
3526 |
warn('expected_a_b', left, 'String', '\'\'');
|
|
|
3527 |
}
|
|
|
3528 |
}
|
|
|
3529 |
var right = expression(130);
|
|
|
3530 |
if (right.id === '(number)') {
|
|
|
3531 |
if (right.number === 0) {
|
|
|
3532 |
warn('unexpected_a', right, '0');
|
|
|
3533 |
}
|
|
|
3534 |
} else if (right.id === '(string)') {
|
|
|
3535 |
if (right.string === '') {
|
|
|
3536 |
warn('expected_a_b', right, 'String', '\'\'');
|
|
|
3537 |
}
|
|
|
3538 |
}
|
|
|
3539 |
if (left.id === right.id) {
|
|
|
3540 |
if (left.id === '(string)' || left.id === '(number)') {
|
|
|
3541 |
if (left.id === '(string)') {
|
|
|
3542 |
left.string += right.string;
|
|
|
3543 |
if (jx.test(left.string)) {
|
|
|
3544 |
warn('url', left);
|
|
|
3545 |
}
|
|
|
3546 |
} else {
|
|
|
3547 |
left.number += right.number;
|
|
|
3548 |
}
|
|
|
3549 |
left.thru = right.thru;
|
|
|
3550 |
return left;
|
|
|
3551 |
}
|
|
|
3552 |
}
|
|
|
3553 |
that.first = left;
|
|
|
3554 |
that.second = right;
|
|
|
3555 |
return that;
|
|
|
3556 |
});
|
|
|
3557 |
prefix('+', 'num');
|
|
|
3558 |
prefix('+++', function () {
|
|
|
3559 |
warn('confusing_a', token);
|
|
|
3560 |
this.first = expression(150);
|
|
|
3561 |
this.arity = 'prefix';
|
|
|
3562 |
return this;
|
|
|
3563 |
});
|
|
|
3564 |
infix('+++', 130, function (left) {
|
|
|
3565 |
warn('confusing_a', token);
|
|
|
3566 |
this.first = left;
|
|
|
3567 |
this.second = expression(130);
|
|
|
3568 |
return this;
|
|
|
3569 |
});
|
|
|
3570 |
infix('-', 130, function (left, that) {
|
|
|
3571 |
if ((left.id === '(number)' && left.number === 0) || left.id === '(string)') {
|
|
|
3572 |
warn('unexpected_a', left);
|
|
|
3573 |
}
|
|
|
3574 |
var right = expression(130);
|
|
|
3575 |
if ((right.id === '(number)' && right.number === 0) || right.id === '(string)') {
|
|
|
3576 |
warn('unexpected_a', left);
|
|
|
3577 |
}
|
|
|
3578 |
if (left.id === right.id && left.id === '(number)') {
|
|
|
3579 |
left.number -= right.number;
|
|
|
3580 |
left.thru = right.thru;
|
|
|
3581 |
return left;
|
|
|
3582 |
}
|
|
|
3583 |
that.first = left;
|
|
|
3584 |
that.second = right;
|
|
|
3585 |
return that;
|
|
|
3586 |
}, 'number');
|
|
|
3587 |
prefix('-');
|
|
|
3588 |
prefix('---', function () {
|
|
|
3589 |
warn('confusing_a', token);
|
|
|
3590 |
this.first = expression(150);
|
|
|
3591 |
this.arity = 'prefix';
|
|
|
3592 |
return this;
|
|
|
3593 |
});
|
|
|
3594 |
infix('---', 130, function (left) {
|
|
|
3595 |
warn('confusing_a', token);
|
|
|
3596 |
this.first = left;
|
|
|
3597 |
this.second = expression(130);
|
|
|
3598 |
return this;
|
|
|
3599 |
});
|
|
|
3600 |
infix('*', 140, function (left, that) {
|
|
|
3601 |
if ((left.id === '(number)' && (left.number === 0 || left.number === 1)) || left.id === '(string)') {
|
|
|
3602 |
warn('unexpected_a', left);
|
|
|
3603 |
}
|
|
|
3604 |
var right = expression(140);
|
|
|
3605 |
if ((right.id === '(number)' && (right.number === 0 || right.number === 1)) || right.id === '(string)') {
|
|
|
3606 |
warn('unexpected_a', right);
|
|
|
3607 |
}
|
|
|
3608 |
if (left.id === right.id && left.id === '(number)') {
|
|
|
3609 |
left.number *= right.number;
|
|
|
3610 |
left.thru = right.thru;
|
|
|
3611 |
return left;
|
|
|
3612 |
}
|
|
|
3613 |
that.first = left;
|
|
|
3614 |
that.second = right;
|
|
|
3615 |
return that;
|
|
|
3616 |
}, 'number');
|
|
|
3617 |
infix('/', 140, function (left, that) {
|
|
|
3618 |
if ((left.id === '(number)' && left.number === 0) || left.id === '(string)') {
|
|
|
3619 |
warn('unexpected_a', left);
|
|
|
3620 |
}
|
|
|
3621 |
var right = expression(140);
|
|
|
3622 |
if ((right.id === '(number)' && (right.number === 0 || right.number === 1)) || right.id === '(string)') {
|
|
|
3623 |
warn('unexpected_a', right);
|
|
|
3624 |
}
|
|
|
3625 |
if (left.id === right.id && left.id === '(number)') {
|
|
|
3626 |
left.number /= right.number;
|
|
|
3627 |
left.thru = right.thru;
|
|
|
3628 |
return left;
|
|
|
3629 |
}
|
|
|
3630 |
that.first = left;
|
|
|
3631 |
that.second = right;
|
|
|
3632 |
return that;
|
|
|
3633 |
}, 'number');
|
|
|
3634 |
infix('%', 140, function (left, that) {
|
|
|
3635 |
if ((left.id === '(number)' && (left.number === 0 || left.number === 1)) || left.id === '(string)') {
|
|
|
3636 |
warn('unexpected_a', left);
|
|
|
3637 |
}
|
|
|
3638 |
var right = expression(140);
|
|
|
3639 |
if ((right.id === '(number)' && right.number === 0) || right.id === '(string)') {
|
|
|
3640 |
warn('unexpected_a', right);
|
|
|
3641 |
}
|
|
|
3642 |
if (left.id === right.id && left.id === '(number)') {
|
|
|
3643 |
left.number %= right.number;
|
|
|
3644 |
left.thru = right.thru;
|
|
|
3645 |
return left;
|
|
|
3646 |
}
|
|
|
3647 |
that.first = left;
|
|
|
3648 |
that.second = right;
|
|
|
3649 |
return that;
|
|
|
3650 |
}, 'number');
|
|
|
3651 |
|
|
|
3652 |
suffix('++');
|
|
|
3653 |
prefix('++');
|
|
|
3654 |
|
|
|
3655 |
suffix('--');
|
|
|
3656 |
prefix('--');
|
|
|
3657 |
prefix('delete', function () {
|
|
|
3658 |
one_space();
|
|
|
3659 |
var p = expression(0);
|
|
|
3660 |
if (!p || (p.id !== '.' && p.id !== '[')) {
|
|
|
3661 |
warn('deleted');
|
|
|
3662 |
}
|
|
|
3663 |
this.first = p;
|
|
|
3664 |
return this;
|
|
|
3665 |
});
|
|
|
3666 |
|
|
|
3667 |
|
|
|
3668 |
prefix('~', function () {
|
|
|
3669 |
no_space_only();
|
|
|
3670 |
if (!option.bitwise) {
|
|
|
3671 |
warn('unexpected_a', this);
|
|
|
3672 |
}
|
|
|
3673 |
expression(150);
|
|
|
3674 |
return this;
|
|
|
3675 |
}, 'number');
|
|
|
3676 |
prefix('!', function () {
|
|
|
3677 |
no_space_only();
|
|
|
3678 |
this.first = expected_condition(expression(150));
|
|
|
3679 |
this.arity = 'prefix';
|
|
|
3680 |
if (bang[this.first.id] === true || this.first.assign) {
|
|
|
3681 |
warn('confusing_a', this);
|
|
|
3682 |
}
|
|
|
3683 |
return this;
|
|
|
3684 |
}, 'boolean');
|
|
|
3685 |
prefix('typeof', null, 'string');
|
|
|
3686 |
prefix('new', function () {
|
|
|
3687 |
one_space();
|
|
|
3688 |
var c = expression(160), n, p, v;
|
|
|
3689 |
this.first = c;
|
|
|
3690 |
if (c.id !== 'function') {
|
|
|
3691 |
if (c.identifier) {
|
|
|
3692 |
switch (c.string) {
|
|
|
3693 |
case 'Object':
|
|
|
3694 |
warn('use_object', token);
|
|
|
3695 |
break;
|
|
|
3696 |
case 'Array':
|
|
|
3697 |
if (next_token.id === '(') {
|
|
|
3698 |
p = next_token;
|
|
|
3699 |
p.first = this;
|
|
|
3700 |
advance('(');
|
|
|
3701 |
if (next_token.id !== ')') {
|
|
|
3702 |
n = expression(0);
|
|
|
3703 |
p.second = [n];
|
|
|
3704 |
if (n.type !== 'number' || next_token.id === ',') {
|
|
|
3705 |
warn('use_array', p);
|
|
|
3706 |
}
|
|
|
3707 |
while (next_token.id === ',') {
|
|
|
3708 |
advance(',');
|
|
|
3709 |
p.second.push(expression(0));
|
|
|
3710 |
}
|
|
|
3711 |
} else {
|
|
|
3712 |
warn('use_array', token);
|
|
|
3713 |
}
|
|
|
3714 |
advance(')', p);
|
|
|
3715 |
return p;
|
|
|
3716 |
}
|
|
|
3717 |
warn('use_array', token);
|
|
|
3718 |
break;
|
|
|
3719 |
case 'Number':
|
|
|
3720 |
case 'String':
|
|
|
3721 |
case 'Boolean':
|
|
|
3722 |
case 'Math':
|
|
|
3723 |
case 'JSON':
|
|
|
3724 |
warn('not_a_constructor', c);
|
|
|
3725 |
break;
|
|
|
3726 |
case 'Function':
|
|
|
3727 |
if (!option.evil) {
|
|
|
3728 |
warn('function_eval');
|
|
|
3729 |
}
|
|
|
3730 |
break;
|
|
|
3731 |
case 'Date':
|
|
|
3732 |
case 'RegExp':
|
|
|
3733 |
break;
|
|
|
3734 |
default:
|
|
|
3735 |
if (c.id !== 'function') {
|
|
|
3736 |
v = c.string.charAt(0);
|
|
|
3737 |
if (!option.newcap && (v < 'A' || v > 'Z')) {
|
|
|
3738 |
warn('constructor_name_a', token);
|
|
|
3739 |
}
|
|
|
3740 |
}
|
|
|
3741 |
}
|
|
|
3742 |
} else {
|
|
|
3743 |
if (c.id !== '.' && c.id !== '[' && c.id !== '(') {
|
|
|
3744 |
warn('bad_constructor', token);
|
|
|
3745 |
}
|
|
|
3746 |
}
|
|
|
3747 |
} else {
|
|
|
3748 |
warn('weird_new', this);
|
|
|
3749 |
}
|
|
|
3750 |
if (next_token.id !== '(') {
|
|
|
3751 |
warn('missing_a', next_token, '()');
|
|
|
3752 |
}
|
|
|
3753 |
return this;
|
|
|
3754 |
});
|
|
|
3755 |
|
|
|
3756 |
infix('(', 160, function (left, that) {
|
|
|
3757 |
var p;
|
|
|
3758 |
if (indent && indent.mode === 'expression') {
|
|
|
3759 |
no_space(prev_token, token);
|
|
|
3760 |
} else {
|
|
|
3761 |
no_space_only(prev_token, token);
|
|
|
3762 |
}
|
|
|
3763 |
if (!left.immed && left.id === 'function') {
|
|
|
3764 |
warn('wrap_immediate');
|
|
|
3765 |
}
|
|
|
3766 |
p = [];
|
|
|
3767 |
if (left.identifier) {
|
|
|
3768 |
if (left.string.match(/^[A-Z]([A-Z0-9_$]*[a-z][A-Za-z0-9_$]*)?$/)) {
|
|
|
3769 |
if (left.string !== 'Number' && left.string !== 'String' &&
|
|
|
3770 |
left.string !== 'Boolean' && left.string !== 'Date') {
|
|
|
3771 |
if (left.string === 'Math' || left.string === 'JSON') {
|
|
|
3772 |
warn('not_a_function', left);
|
|
|
3773 |
} else if (left.string === 'Object') {
|
|
|
3774 |
warn('use_object', token);
|
|
|
3775 |
} else if (left.string === 'Array' || !option.newcap) {
|
|
|
3776 |
warn('missing_a', left, 'new');
|
|
|
3777 |
}
|
|
|
3778 |
}
|
|
|
3779 |
}
|
|
|
3780 |
} else if (left.id === '.') {
|
|
|
3781 |
if (option.safe && left.first.string === 'Math' &&
|
|
|
3782 |
left.second === 'random') {
|
|
|
3783 |
warn('adsafe_a', left);
|
|
|
3784 |
} else if (left.second.string === 'split' &&
|
|
|
3785 |
left.first.id === '(string)') {
|
|
|
3786 |
warn('use_array', left.second);
|
|
|
3787 |
}
|
|
|
3788 |
}
|
|
|
3789 |
step_in();
|
|
|
3790 |
if (next_token.id !== ')') {
|
|
|
3791 |
no_space();
|
|
|
3792 |
for (;;) {
|
|
|
3793 |
edge();
|
|
|
3794 |
p.push(expression(10));
|
|
|
3795 |
if (next_token.id !== ',') {
|
|
|
3796 |
break;
|
|
|
3797 |
}
|
|
|
3798 |
comma();
|
|
|
3799 |
}
|
|
|
3800 |
}
|
|
|
3801 |
no_space();
|
|
|
3802 |
step_out(')', that);
|
|
|
3803 |
if (typeof left === 'object') {
|
|
|
3804 |
if (left.string === 'parseInt' && p.length === 1) {
|
|
|
3805 |
warn('radix', left);
|
|
|
3806 |
}
|
|
|
3807 |
if (!option.evil) {
|
|
|
3808 |
if (left.string === 'eval' || left.string === 'Function' ||
|
|
|
3809 |
left.string === 'execScript') {
|
|
|
3810 |
warn('evil', left);
|
|
|
3811 |
} else if (p[0] && p[0].id === '(string)' &&
|
|
|
3812 |
(left.string === 'setTimeout' ||
|
|
|
3813 |
left.string === 'setInterval')) {
|
|
|
3814 |
warn('implied_evil', left);
|
|
|
3815 |
}
|
|
|
3816 |
}
|
|
|
3817 |
if (!left.identifier && left.id !== '.' && left.id !== '[' &&
|
|
|
3818 |
left.id !== '(' && left.id !== '&&' && left.id !== '||' &&
|
|
|
3819 |
left.id !== '?') {
|
|
|
3820 |
warn('bad_invocation', left);
|
|
|
3821 |
}
|
|
|
3822 |
}
|
|
|
3823 |
that.first = left;
|
|
|
3824 |
that.second = p;
|
|
|
3825 |
return that;
|
|
|
3826 |
}, '', true);
|
|
|
3827 |
|
|
|
3828 |
prefix('(', function () {
|
|
|
3829 |
step_in('expression');
|
|
|
3830 |
no_space();
|
|
|
3831 |
edge();
|
|
|
3832 |
if (next_token.id === 'function') {
|
|
|
3833 |
next_token.immed = true;
|
|
|
3834 |
}
|
|
|
3835 |
var value = expression(0);
|
|
|
3836 |
value.paren = true;
|
|
|
3837 |
no_space();
|
|
|
3838 |
step_out(')', this);
|
|
|
3839 |
if (value.id === 'function') {
|
|
|
3840 |
if (next_token.id === '(') {
|
|
|
3841 |
warn('move_invocation');
|
|
|
3842 |
} else {
|
|
|
3843 |
warn('bad_wrap', this);
|
|
|
3844 |
}
|
|
|
3845 |
}
|
|
|
3846 |
return value;
|
|
|
3847 |
});
|
|
|
3848 |
|
|
|
3849 |
infix('.', 170, function (left, that) {
|
|
|
3850 |
no_space(prev_token, token);
|
|
|
3851 |
no_space();
|
|
|
3852 |
var name = identifier(), type;
|
|
|
3853 |
if (typeof name === 'string') {
|
|
|
3854 |
tally_property(name);
|
|
|
3855 |
}
|
|
|
3856 |
that.first = left;
|
|
|
3857 |
that.second = token;
|
|
|
3858 |
if (left && left.string === 'arguments' &&
|
|
|
3859 |
(name === 'callee' || name === 'caller')) {
|
|
|
3860 |
warn('avoid_a', left, 'arguments.' + name);
|
|
|
3861 |
} else if (!option.evil && left && left.string === 'document' &&
|
|
|
3862 |
(name === 'write' || name === 'writeln')) {
|
|
|
3863 |
warn('write_is_wrong', left);
|
|
|
3864 |
} else if (option.adsafe) {
|
|
|
3865 |
if (!adsafe_top && left.string === 'ADSAFE') {
|
|
|
3866 |
if (name === 'id' || name === 'lib') {
|
|
|
3867 |
warn('adsafe_a', that);
|
|
|
3868 |
} else if (name === 'go') {
|
|
|
3869 |
if (xmode !== 'script') {
|
|
|
3870 |
warn('adsafe_a', that);
|
|
|
3871 |
} else if (adsafe_went || next_token.id !== '(' ||
|
|
|
3872 |
peek(0).id !== '(string)' ||
|
|
|
3873 |
peek(0).string !== adsafe_id ||
|
|
|
3874 |
peek(1).id !== ',') {
|
|
|
3875 |
stop('adsafe_a', that, 'go');
|
|
|
3876 |
}
|
|
|
3877 |
adsafe_went = true;
|
|
|
3878 |
adsafe_may = false;
|
|
|
3879 |
}
|
|
|
3880 |
}
|
|
|
3881 |
adsafe_top = false;
|
|
|
3882 |
}
|
|
|
3883 |
if (!option.evil && (name === 'eval' || name === 'execScript')) {
|
|
|
3884 |
warn('evil');
|
|
|
3885 |
} else if (option.safe) {
|
|
|
3886 |
for (;;) {
|
|
|
3887 |
if (banned[name] === true) {
|
|
|
3888 |
warn('adsafe_a', token, name);
|
|
|
3889 |
}
|
|
|
3890 |
if (typeof predefined[left.string] !== 'boolean' || //// check for writeable
|
|
|
3891 |
next_token.id === '(') {
|
|
|
3892 |
break;
|
|
|
3893 |
}
|
|
|
3894 |
if (next_token.id !== '.') {
|
|
|
3895 |
warn('adsafe_a', that);
|
|
|
3896 |
break;
|
|
|
3897 |
}
|
|
|
3898 |
advance('.');
|
|
|
3899 |
token.first = that;
|
|
|
3900 |
token.second = name;
|
|
|
3901 |
that = token;
|
|
|
3902 |
name = identifier();
|
|
|
3903 |
if (typeof name === 'string') {
|
|
|
3904 |
tally_property(name);
|
|
|
3905 |
}
|
|
|
3906 |
}
|
|
|
3907 |
}
|
|
|
3908 |
type = property_type[name];
|
|
|
3909 |
if (type && typeof type === 'string' && type !== '*') {
|
|
|
3910 |
that.type = type;
|
|
|
3911 |
}
|
|
|
3912 |
return that;
|
|
|
3913 |
}, '', true);
|
|
|
3914 |
|
|
|
3915 |
infix('[', 170, function (left, that) {
|
|
|
3916 |
var e, s;
|
|
|
3917 |
no_space_only(prev_token, token);
|
|
|
3918 |
no_space();
|
|
|
3919 |
step_in();
|
|
|
3920 |
edge();
|
|
|
3921 |
e = expression(0);
|
|
|
3922 |
switch (e.type) {
|
|
|
3923 |
case 'number':
|
|
|
3924 |
if (e.id === '(number)' && left.id === 'arguments') {
|
|
|
3925 |
warn('use_param', left);
|
|
|
3926 |
}
|
|
|
3927 |
break;
|
|
|
3928 |
case 'string':
|
|
|
3929 |
if (e.id === '(string)') {
|
|
|
3930 |
if (option.safe && (banned[e.string] ||
|
|
|
3931 |
e.string.charAt(0) === '_' || e.string.slice(-1) === '_')) {
|
|
|
3932 |
warn('adsafe_subscript_a', e);
|
|
|
3933 |
} else if (!option.evil &&
|
|
|
3934 |
(e.string === 'eval' || e.string === 'execScript')) {
|
|
|
3935 |
warn('evil', e);
|
|
|
3936 |
} else if (!option.sub && ix.test(e.string)) {
|
|
|
3937 |
s = syntax[e.string];
|
|
|
3938 |
if (!s || !s.reserved) {
|
|
|
3939 |
warn('subscript', e);
|
|
|
3940 |
}
|
|
|
3941 |
}
|
|
|
3942 |
tally_property(e.string);
|
|
|
3943 |
} else if (option.safe && e.id !== 'typeof') {
|
|
|
3944 |
warn('adsafe_subscript_a', e);
|
|
|
3945 |
}
|
|
|
3946 |
break;
|
|
|
3947 |
case undefined:
|
|
|
3948 |
if (option.safe) {
|
|
|
3949 |
warn('adsafe_subscript_a', e);
|
|
|
3950 |
}
|
|
|
3951 |
break;
|
|
|
3952 |
default:
|
|
|
3953 |
if (option.safe) {
|
|
|
3954 |
warn('adsafe_subscript_a', e);
|
|
|
3955 |
}
|
|
|
3956 |
}
|
|
|
3957 |
step_out(']', that);
|
|
|
3958 |
no_space(prev_token, token);
|
|
|
3959 |
that.first = left;
|
|
|
3960 |
that.second = e;
|
|
|
3961 |
return that;
|
|
|
3962 |
}, '', true);
|
|
|
3963 |
|
|
|
3964 |
prefix('[', function () {
|
|
|
3965 |
this.arity = 'prefix';
|
|
|
3966 |
this.first = [];
|
|
|
3967 |
step_in('array');
|
|
|
3968 |
while (next_token.id !== '(end)') {
|
|
|
3969 |
while (next_token.id === ',') {
|
|
|
3970 |
warn('unexpected_a', next_token);
|
|
|
3971 |
advance(',');
|
|
|
3972 |
}
|
|
|
3973 |
if (next_token.id === ']') {
|
|
|
3974 |
break;
|
|
|
3975 |
}
|
|
|
3976 |
indent.wrap = false;
|
|
|
3977 |
edge();
|
|
|
3978 |
this.first.push(expression(10));
|
|
|
3979 |
if (next_token.id === ',') {
|
|
|
3980 |
comma();
|
|
|
3981 |
if (next_token.id === ']' && !option.es5) {
|
|
|
3982 |
warn('unexpected_a', token);
|
|
|
3983 |
break;
|
|
|
3984 |
}
|
|
|
3985 |
} else {
|
|
|
3986 |
break;
|
|
|
3987 |
}
|
|
|
3988 |
}
|
|
|
3989 |
step_out(']', this);
|
|
|
3990 |
return this;
|
|
|
3991 |
}, 170);
|
|
|
3992 |
|
|
|
3993 |
|
|
|
3994 |
function property_name() {
|
|
|
3995 |
var id = optional_identifier(true);
|
|
|
3996 |
if (!id) {
|
|
|
3997 |
if (next_token.id === '(string)') {
|
|
|
3998 |
id = next_token.string;
|
|
|
3999 |
if (option.safe) {
|
|
|
4000 |
if (banned[id]) {
|
|
|
4001 |
warn('adsafe_a');
|
|
|
4002 |
} else if (id.charAt(0) === '_' ||
|
|
|
4003 |
id.charAt(id.length - 1) === '_') {
|
|
|
4004 |
warn('dangling_a');
|
|
|
4005 |
}
|
|
|
4006 |
}
|
|
|
4007 |
advance();
|
|
|
4008 |
} else if (next_token.id === '(number)') {
|
|
|
4009 |
id = next_token.number.toString();
|
|
|
4010 |
advance();
|
|
|
4011 |
}
|
|
|
4012 |
}
|
|
|
4013 |
return id;
|
|
|
4014 |
}
|
|
|
4015 |
|
|
|
4016 |
|
|
|
4017 |
function function_params() {
|
|
|
4018 |
var id, paren = next_token, params = [];
|
|
|
4019 |
advance('(');
|
|
|
4020 |
step_in();
|
|
|
4021 |
no_space();
|
|
|
4022 |
if (next_token.id === ')') {
|
|
|
4023 |
no_space();
|
|
|
4024 |
step_out(')', paren);
|
|
|
4025 |
return;
|
|
|
4026 |
}
|
|
|
4027 |
for (;;) {
|
|
|
4028 |
edge();
|
|
|
4029 |
id = identifier();
|
|
|
4030 |
params.push(token);
|
|
|
4031 |
add_label(token, option.unparam ? 'parameter' : 'unparam');
|
|
|
4032 |
if (next_token.id === ',') {
|
|
|
4033 |
comma();
|
|
|
4034 |
} else {
|
|
|
4035 |
no_space();
|
|
|
4036 |
step_out(')', paren);
|
|
|
4037 |
return params;
|
|
|
4038 |
}
|
|
|
4039 |
}
|
|
|
4040 |
}
|
|
|
4041 |
|
|
|
4042 |
|
|
|
4043 |
function complexity(exp) {
|
|
|
4044 |
var score = 0;
|
|
|
4045 |
if (exp) {
|
|
|
4046 |
if (Array.isArray(exp)) {
|
|
|
4047 |
exp.forEach(function (tok) {
|
|
|
4048 |
score += complexity(tok);
|
|
|
4049 |
});
|
|
|
4050 |
} else {
|
|
|
4051 |
switch (exp.arity) {
|
|
|
4052 |
case 'statement':
|
|
|
4053 |
switch (exp.id) {
|
|
|
4054 |
case 'if':
|
|
|
4055 |
score += complexity(exp.first) + complexity(exp.block) +
|
|
|
4056 |
complexity(exp['else']) + 1;
|
|
|
4057 |
break;
|
|
|
4058 |
case 'while':
|
|
|
4059 |
case 'do':
|
|
|
4060 |
if (exp.first.id !== 'true' && exp.first.number !== 1) {
|
|
|
4061 |
score += 1;
|
|
|
4062 |
}
|
|
|
4063 |
score += complexity(exp.first) + complexity(exp.block);
|
|
|
4064 |
break;
|
|
|
4065 |
case 'for':
|
|
|
4066 |
if (exp.second !== undefined &&
|
|
|
4067 |
exp.second.id !== 'true' &&
|
|
|
4068 |
exp.second.number !== 1) {
|
|
|
4069 |
score += 1;
|
|
|
4070 |
}
|
|
|
4071 |
score += complexity(exp.first) + complexity(exp.second) +
|
|
|
4072 |
complexity(exp.third) + complexity(exp.block);
|
|
|
4073 |
break;
|
|
|
4074 |
case 'switch':
|
|
|
4075 |
score += complexity(exp.first) +
|
|
|
4076 |
complexity(exp.second) + exp.second.length;
|
|
|
4077 |
if (exp.second[exp.second.length - 1].id === 'default') {
|
|
|
4078 |
score -= 1;
|
|
|
4079 |
}
|
|
|
4080 |
break;
|
|
|
4081 |
case 'try':
|
|
|
4082 |
if (exp.second) {
|
|
|
4083 |
score += 1;
|
|
|
4084 |
}
|
|
|
4085 |
if (exp.third) {
|
|
|
4086 |
score += 1;
|
|
|
4087 |
}
|
|
|
4088 |
score += complexity(exp.first) + complexity(exp.second) +
|
|
|
4089 |
complexity(exp.third) + complexity(exp.block);
|
|
|
4090 |
break;
|
|
|
4091 |
}
|
|
|
4092 |
break;
|
|
|
4093 |
case 'prefix':
|
|
|
4094 |
score += complexity(exp.first);
|
|
|
4095 |
break;
|
|
|
4096 |
case 'case':
|
|
|
4097 |
case 'infix':
|
|
|
4098 |
score += complexity(exp.first) + complexity(exp.second);
|
|
|
4099 |
if (exp.id === '&&' || exp.id === '||') {
|
|
|
4100 |
score += 1;
|
|
|
4101 |
}
|
|
|
4102 |
break;
|
|
|
4103 |
case 'ternary':
|
|
|
4104 |
score += complexity(exp.first) + complexity(exp.second) + complexity(exp.third);
|
|
|
4105 |
break;
|
|
|
4106 |
}
|
|
|
4107 |
}
|
|
|
4108 |
}
|
|
|
4109 |
return score;
|
|
|
4110 |
}
|
|
|
4111 |
|
|
|
4112 |
|
|
|
4113 |
function do_function(func, name) {
|
|
|
4114 |
var old_funct = funct,
|
|
|
4115 |
old_option = option,
|
|
|
4116 |
old_scope = scope;
|
|
|
4117 |
funct = {
|
|
|
4118 |
'(name)' : name || '\'' + (anonname || '').replace(nx, sanitize) + '\'',
|
|
|
4119 |
'(line)' : next_token.line,
|
|
|
4120 |
'(context)' : old_funct,
|
|
|
4121 |
'(breakage)' : 0,
|
|
|
4122 |
'(loopage)' : 0,
|
|
|
4123 |
'(scope)' : scope,
|
|
|
4124 |
'(token)' : func
|
|
|
4125 |
};
|
|
|
4126 |
option = Object.create(old_option);
|
|
|
4127 |
scope = Object.create(old_scope);
|
|
|
4128 |
functions.push(funct);
|
|
|
4129 |
func.name = name;
|
|
|
4130 |
if (name) {
|
|
|
4131 |
add_label(func, 'function', name);
|
|
|
4132 |
}
|
|
|
4133 |
func.writeable = false;
|
|
|
4134 |
func.first = funct['(params)'] = function_params();
|
|
|
4135 |
one_space();
|
|
|
4136 |
func.block = block(false);
|
|
|
4137 |
if (funct['(old_property_type)']) {
|
|
|
4138 |
property_type = funct['(old_property_type)'];
|
|
|
4139 |
delete funct['(old_property_type)'];
|
|
|
4140 |
}
|
|
|
4141 |
funct['(complexity)'] = complexity(func.block) + 1;
|
|
|
4142 |
if (option.confusion) {
|
|
|
4143 |
funct['(confusion)'] = true;
|
|
|
4144 |
}
|
|
|
4145 |
funct = old_funct;
|
|
|
4146 |
option = old_option;
|
|
|
4147 |
scope = old_scope;
|
|
|
4148 |
}
|
|
|
4149 |
|
|
|
4150 |
|
|
|
4151 |
assignop('=');
|
|
|
4152 |
assignop('+=', '+');
|
|
|
4153 |
assignop('-=', '-');
|
|
|
4154 |
assignop('*=', '*');
|
|
|
4155 |
assignop('/=', '/').nud = function () {
|
|
|
4156 |
stop('slash_equal');
|
|
|
4157 |
};
|
|
|
4158 |
assignop('%=', '%');
|
|
|
4159 |
assignop('&=', '&');
|
|
|
4160 |
assignop('|=', '|');
|
|
|
4161 |
assignop('^=', '^');
|
|
|
4162 |
assignop('<<=', '<<');
|
|
|
4163 |
assignop('>>=', '>>');
|
|
|
4164 |
assignop('>>>=', '>>>');
|
|
|
4165 |
|
|
|
4166 |
|
|
|
4167 |
prefix('{', function () {
|
|
|
4168 |
var get, i, j, name, p, set, seen = {};
|
|
|
4169 |
this.arity = 'prefix';
|
|
|
4170 |
this.first = [];
|
|
|
4171 |
step_in();
|
|
|
4172 |
while (next_token.id !== '}') {
|
|
|
4173 |
indent.wrap = false;
|
|
|
4174 |
|
|
|
4175 |
// JSLint recognizes the ES5 extension for get/set in object literals,
|
|
|
4176 |
// but requires that they be used in pairs.
|
|
|
4177 |
|
|
|
4178 |
edge();
|
|
|
4179 |
if (next_token.string === 'get' && peek().id !== ':') {
|
|
|
4180 |
if (!option.es5) {
|
|
|
4181 |
warn('es5');
|
|
|
4182 |
}
|
|
|
4183 |
get = next_token;
|
|
|
4184 |
advance('get');
|
|
|
4185 |
one_space_only();
|
|
|
4186 |
name = next_token;
|
|
|
4187 |
i = property_name();
|
|
|
4188 |
if (!i) {
|
|
|
4189 |
stop('missing_property');
|
|
|
4190 |
}
|
|
|
4191 |
get.string = '';
|
|
|
4192 |
do_function(get);
|
|
|
4193 |
if (funct['(loopage)']) {
|
|
|
4194 |
warn('function_loop', get);
|
|
|
4195 |
}
|
|
|
4196 |
p = get.first;
|
|
|
4197 |
if (p) {
|
|
|
4198 |
warn('parameter_a_get_b', p[0], p[0].string, i);
|
|
|
4199 |
}
|
|
|
4200 |
comma();
|
|
|
4201 |
set = next_token;
|
|
|
4202 |
spaces();
|
|
|
4203 |
edge();
|
|
|
4204 |
advance('set');
|
|
|
4205 |
set.string = '';
|
|
|
4206 |
one_space_only();
|
|
|
4207 |
j = property_name();
|
|
|
4208 |
if (i !== j) {
|
|
|
4209 |
stop('expected_a_b', token, i, j || next_token.string);
|
|
|
4210 |
}
|
|
|
4211 |
do_function(set);
|
|
|
4212 |
p = set.first;
|
|
|
4213 |
if (!p || p.length !== 1) {
|
|
|
4214 |
stop('parameter_set_a', set, 'value');
|
|
|
4215 |
} else if (p[0].string !== 'value') {
|
|
|
4216 |
stop('expected_a_b', p[0], 'value', p[0].string);
|
|
|
4217 |
}
|
|
|
4218 |
name.first = [get, set];
|
|
|
4219 |
} else {
|
|
|
4220 |
name = next_token;
|
|
|
4221 |
i = property_name();
|
|
|
4222 |
if (typeof i !== 'string') {
|
|
|
4223 |
stop('missing_property');
|
|
|
4224 |
}
|
|
|
4225 |
advance(':');
|
|
|
4226 |
spaces();
|
|
|
4227 |
name.first = expression(10);
|
|
|
4228 |
}
|
|
|
4229 |
this.first.push(name);
|
|
|
4230 |
if (seen[i] === true) {
|
|
|
4231 |
warn('duplicate_a', next_token, i);
|
|
|
4232 |
}
|
|
|
4233 |
seen[i] = true;
|
|
|
4234 |
tally_property(i);
|
|
|
4235 |
if (next_token.id !== ',') {
|
|
|
4236 |
break;
|
|
|
4237 |
}
|
|
|
4238 |
for (;;) {
|
|
|
4239 |
comma();
|
|
|
4240 |
if (next_token.id !== ',') {
|
|
|
4241 |
break;
|
|
|
4242 |
}
|
|
|
4243 |
warn('unexpected_a', next_token);
|
|
|
4244 |
}
|
|
|
4245 |
if (next_token.id === '}' && !option.es5) {
|
|
|
4246 |
warn('unexpected_a', token);
|
|
|
4247 |
}
|
|
|
4248 |
}
|
|
|
4249 |
step_out('}', this);
|
|
|
4250 |
return this;
|
|
|
4251 |
});
|
|
|
4252 |
|
|
|
4253 |
stmt('{', function () {
|
|
|
4254 |
warn('statement_block');
|
|
|
4255 |
this.arity = 'statement';
|
|
|
4256 |
this.block = statements();
|
|
|
4257 |
this.disrupt = this.block.disrupt;
|
|
|
4258 |
advance('}', this);
|
|
|
4259 |
return this;
|
|
|
4260 |
});
|
|
|
4261 |
|
|
|
4262 |
stmt('/*global', directive);
|
|
|
4263 |
stmt('/*globals', directive);
|
|
|
4264 |
stmt('/*jslint', directive);
|
|
|
4265 |
stmt('/*member', directive);
|
|
|
4266 |
stmt('/*members', directive);
|
|
|
4267 |
stmt('/*property', directive);
|
|
|
4268 |
stmt('/*properties', directive);
|
|
|
4269 |
|
|
|
4270 |
stmt('var', function () {
|
|
|
4271 |
|
|
|
4272 |
// JavaScript does not have block scope. It only has function scope. So,
|
|
|
4273 |
// declaring a variable in a block can have unexpected consequences.
|
|
|
4274 |
|
|
|
4275 |
// var.first will contain an array, the array containing name tokens
|
|
|
4276 |
// and assignment tokens.
|
|
|
4277 |
|
|
|
4278 |
var assign, id, name;
|
|
|
4279 |
|
|
|
4280 |
if (funct['(vars)'] && !option.vars) {
|
|
|
4281 |
warn('combine_var');
|
|
|
4282 |
} else if (funct !== global_funct) {
|
|
|
4283 |
funct['(vars)'] = true;
|
|
|
4284 |
}
|
|
|
4285 |
this.arity = 'statement';
|
|
|
4286 |
this.first = [];
|
|
|
4287 |
step_in('var');
|
|
|
4288 |
for (;;) {
|
|
|
4289 |
name = next_token;
|
|
|
4290 |
id = identifier();
|
|
|
4291 |
add_label(name, 'becoming');
|
|
|
4292 |
|
|
|
4293 |
if (next_token.id === '=') {
|
|
|
4294 |
assign = next_token;
|
|
|
4295 |
assign.first = name;
|
|
|
4296 |
spaces();
|
|
|
4297 |
advance('=');
|
|
|
4298 |
spaces();
|
|
|
4299 |
if (next_token.id === 'undefined') {
|
|
|
4300 |
warn('unnecessary_initialize', token, id);
|
|
|
4301 |
}
|
|
|
4302 |
if (peek(0).id === '=' && next_token.identifier) {
|
|
|
4303 |
stop('var_a_not');
|
|
|
4304 |
}
|
|
|
4305 |
assign.second = expression(0);
|
|
|
4306 |
assign.arity = 'infix';
|
|
|
4307 |
this.first.push(assign);
|
|
|
4308 |
} else {
|
|
|
4309 |
this.first.push(name);
|
|
|
4310 |
}
|
|
|
4311 |
if (funct[id] === 'becoming') {
|
|
|
4312 |
funct[id] = 'unused';
|
|
|
4313 |
}
|
|
|
4314 |
if (next_token.id !== ',') {
|
|
|
4315 |
break;
|
|
|
4316 |
}
|
|
|
4317 |
comma();
|
|
|
4318 |
indent.wrap = false;
|
|
|
4319 |
if (var_mode && next_token.line === token.line &&
|
|
|
4320 |
this.first.length === 1) {
|
|
|
4321 |
var_mode = null;
|
|
|
4322 |
indent.open = false;
|
|
|
4323 |
indent.at -= option.indent;
|
|
|
4324 |
}
|
|
|
4325 |
spaces();
|
|
|
4326 |
edge();
|
|
|
4327 |
}
|
|
|
4328 |
var_mode = null;
|
|
|
4329 |
step_out();
|
|
|
4330 |
return this;
|
|
|
4331 |
});
|
|
|
4332 |
|
|
|
4333 |
stmt('function', function () {
|
|
|
4334 |
one_space();
|
|
|
4335 |
if (in_block) {
|
|
|
4336 |
warn('function_block', token);
|
|
|
4337 |
}
|
|
|
4338 |
var name = next_token, id = identifier();
|
|
|
4339 |
add_label(name, 'unction');
|
|
|
4340 |
no_space();
|
|
|
4341 |
this.arity = 'statement';
|
|
|
4342 |
do_function(this, id);
|
|
|
4343 |
if (next_token.id === '(' && next_token.line === token.line) {
|
|
|
4344 |
stop('function_statement');
|
|
|
4345 |
}
|
|
|
4346 |
return this;
|
|
|
4347 |
});
|
|
|
4348 |
|
|
|
4349 |
prefix('function', function () {
|
|
|
4350 |
one_space();
|
|
|
4351 |
var id = optional_identifier();
|
|
|
4352 |
if (id) {
|
|
|
4353 |
no_space();
|
|
|
4354 |
} else {
|
|
|
4355 |
id = '';
|
|
|
4356 |
}
|
|
|
4357 |
do_function(this, id);
|
|
|
4358 |
if (funct['(loopage)']) {
|
|
|
4359 |
warn('function_loop');
|
|
|
4360 |
}
|
|
|
4361 |
this.arity = 'function';
|
|
|
4362 |
return this;
|
|
|
4363 |
});
|
|
|
4364 |
|
|
|
4365 |
stmt('if', function () {
|
|
|
4366 |
var paren = next_token;
|
|
|
4367 |
one_space();
|
|
|
4368 |
advance('(');
|
|
|
4369 |
step_in('control');
|
|
|
4370 |
no_space();
|
|
|
4371 |
edge();
|
|
|
4372 |
this.arity = 'statement';
|
|
|
4373 |
this.first = expected_condition(expected_relation(expression(0)));
|
|
|
4374 |
no_space();
|
|
|
4375 |
step_out(')', paren);
|
|
|
4376 |
one_space();
|
|
|
4377 |
this.block = block(true);
|
|
|
4378 |
if (next_token.id === 'else') {
|
|
|
4379 |
one_space();
|
|
|
4380 |
advance('else');
|
|
|
4381 |
one_space();
|
|
|
4382 |
this['else'] = next_token.id === 'if' || next_token.id === 'switch'
|
|
|
4383 |
? statement(true)
|
|
|
4384 |
: block(true);
|
|
|
4385 |
if (this['else'].disrupt && this.block.disrupt) {
|
|
|
4386 |
this.disrupt = true;
|
|
|
4387 |
}
|
|
|
4388 |
}
|
|
|
4389 |
return this;
|
|
|
4390 |
});
|
|
|
4391 |
|
|
|
4392 |
stmt('try', function () {
|
|
|
4393 |
|
|
|
4394 |
// try.first The catch variable
|
|
|
4395 |
// try.second The catch clause
|
|
|
4396 |
// try.third The finally clause
|
|
|
4397 |
// try.block The try block
|
|
|
4398 |
|
|
|
4399 |
var exception_variable, old_scope, paren;
|
|
|
4400 |
if (option.adsafe) {
|
|
|
4401 |
warn('adsafe_a', this);
|
|
|
4402 |
}
|
|
|
4403 |
one_space();
|
|
|
4404 |
this.arity = 'statement';
|
|
|
4405 |
this.block = block(false);
|
|
|
4406 |
if (next_token.id === 'catch') {
|
|
|
4407 |
one_space();
|
|
|
4408 |
advance('catch');
|
|
|
4409 |
one_space();
|
|
|
4410 |
paren = next_token;
|
|
|
4411 |
advance('(');
|
|
|
4412 |
step_in('control');
|
|
|
4413 |
no_space();
|
|
|
4414 |
edge();
|
|
|
4415 |
old_scope = scope;
|
|
|
4416 |
scope = Object.create(old_scope);
|
|
|
4417 |
exception_variable = next_token.string;
|
|
|
4418 |
this.first = exception_variable;
|
|
|
4419 |
if (!next_token.identifier) {
|
|
|
4420 |
warn('expected_identifier_a', next_token);
|
|
|
4421 |
} else {
|
|
|
4422 |
add_label(next_token, 'exception');
|
|
|
4423 |
}
|
|
|
4424 |
advance();
|
|
|
4425 |
no_space();
|
|
|
4426 |
step_out(')', paren);
|
|
|
4427 |
one_space();
|
|
|
4428 |
this.second = block(false);
|
|
|
4429 |
scope = old_scope;
|
|
|
4430 |
}
|
|
|
4431 |
if (next_token.id === 'finally') {
|
|
|
4432 |
one_space();
|
|
|
4433 |
advance('finally');
|
|
|
4434 |
one_space();
|
|
|
4435 |
this.third = block(false);
|
|
|
4436 |
} else if (!this.second) {
|
|
|
4437 |
stop('expected_a_b', next_token, 'catch', artifact());
|
|
|
4438 |
}
|
|
|
4439 |
return this;
|
|
|
4440 |
});
|
|
|
4441 |
|
|
|
4442 |
labeled_stmt('while', function () {
|
|
|
4443 |
one_space();
|
|
|
4444 |
var paren = next_token;
|
|
|
4445 |
funct['(breakage)'] += 1;
|
|
|
4446 |
funct['(loopage)'] += 1;
|
|
|
4447 |
advance('(');
|
|
|
4448 |
step_in('control');
|
|
|
4449 |
no_space();
|
|
|
4450 |
edge();
|
|
|
4451 |
this.arity = 'statement';
|
|
|
4452 |
this.first = expected_relation(expression(0));
|
|
|
4453 |
if (this.first.id !== 'true') {
|
|
|
4454 |
expected_condition(this.first, bundle.unexpected_a);
|
|
|
4455 |
}
|
|
|
4456 |
no_space();
|
|
|
4457 |
step_out(')', paren);
|
|
|
4458 |
one_space();
|
|
|
4459 |
this.block = block(true);
|
|
|
4460 |
if (this.block.disrupt) {
|
|
|
4461 |
warn('strange_loop', prev_token);
|
|
|
4462 |
}
|
|
|
4463 |
funct['(breakage)'] -= 1;
|
|
|
4464 |
funct['(loopage)'] -= 1;
|
|
|
4465 |
return this;
|
|
|
4466 |
});
|
|
|
4467 |
|
|
|
4468 |
reserve('with');
|
|
|
4469 |
|
|
|
4470 |
labeled_stmt('switch', function () {
|
|
|
4471 |
|
|
|
4472 |
// switch.first the switch expression
|
|
|
4473 |
// switch.second the array of cases. A case is 'case' or 'default' token:
|
|
|
4474 |
// case.first the array of case expressions
|
|
|
4475 |
// case.second the array of statements
|
|
|
4476 |
// If all of the arrays of statements are disrupt, then the switch is disrupt.
|
|
|
4477 |
|
|
|
4478 |
var cases = [],
|
|
|
4479 |
old_in_block = in_block,
|
|
|
4480 |
particular,
|
|
|
4481 |
the_case = next_token,
|
|
|
4482 |
unbroken = true;
|
|
|
4483 |
|
|
|
4484 |
function find_duplicate_case(value) {
|
|
|
4485 |
if (are_similar(particular, value)) {
|
|
|
4486 |
warn('duplicate_a', value);
|
|
|
4487 |
}
|
|
|
4488 |
}
|
|
|
4489 |
|
|
|
4490 |
funct['(breakage)'] += 1;
|
|
|
4491 |
one_space();
|
|
|
4492 |
advance('(');
|
|
|
4493 |
no_space();
|
|
|
4494 |
step_in();
|
|
|
4495 |
this.arity = 'statement';
|
|
|
4496 |
this.first = expected_condition(expected_relation(expression(0)));
|
|
|
4497 |
no_space();
|
|
|
4498 |
step_out(')', the_case);
|
|
|
4499 |
one_space();
|
|
|
4500 |
advance('{');
|
|
|
4501 |
step_in();
|
|
|
4502 |
in_block = true;
|
|
|
4503 |
this.second = [];
|
|
|
4504 |
while (next_token.id === 'case') {
|
|
|
4505 |
the_case = next_token;
|
|
|
4506 |
cases.forEach(find_duplicate_case);
|
|
|
4507 |
the_case.first = [];
|
|
|
4508 |
the_case.arity = 'case';
|
|
|
4509 |
spaces();
|
|
|
4510 |
edge('case');
|
|
|
4511 |
advance('case');
|
|
|
4512 |
for (;;) {
|
|
|
4513 |
one_space();
|
|
|
4514 |
particular = expression(0);
|
|
|
4515 |
cases.forEach(find_duplicate_case);
|
|
|
4516 |
cases.push(particular);
|
|
|
4517 |
the_case.first.push(particular);
|
|
|
4518 |
if (particular.id === 'NaN') {
|
|
|
4519 |
warn('unexpected_a', particular);
|
|
|
4520 |
}
|
|
|
4521 |
no_space_only();
|
|
|
4522 |
advance(':');
|
|
|
4523 |
if (next_token.id !== 'case') {
|
|
|
4524 |
break;
|
|
|
4525 |
}
|
|
|
4526 |
spaces();
|
|
|
4527 |
edge('case');
|
|
|
4528 |
advance('case');
|
|
|
4529 |
}
|
|
|
4530 |
spaces();
|
|
|
4531 |
the_case.second = statements();
|
|
|
4532 |
if (the_case.second && the_case.second.length > 0) {
|
|
|
4533 |
particular = the_case.second[the_case.second.length - 1];
|
|
|
4534 |
if (particular.disrupt) {
|
|
|
4535 |
if (particular.id === 'break') {
|
|
|
4536 |
unbroken = false;
|
|
|
4537 |
}
|
|
|
4538 |
} else {
|
|
|
4539 |
warn('missing_a_after_b', next_token, 'break', 'case');
|
|
|
4540 |
}
|
|
|
4541 |
} else {
|
|
|
4542 |
warn('empty_case');
|
|
|
4543 |
}
|
|
|
4544 |
this.second.push(the_case);
|
|
|
4545 |
}
|
|
|
4546 |
if (this.second.length === 0) {
|
|
|
4547 |
warn('missing_a', next_token, 'case');
|
|
|
4548 |
}
|
|
|
4549 |
if (next_token.id === 'default') {
|
|
|
4550 |
spaces();
|
|
|
4551 |
the_case = next_token;
|
|
|
4552 |
the_case.arity = 'case';
|
|
|
4553 |
edge('case');
|
|
|
4554 |
advance('default');
|
|
|
4555 |
no_space_only();
|
|
|
4556 |
advance(':');
|
|
|
4557 |
spaces();
|
|
|
4558 |
the_case.second = statements();
|
|
|
4559 |
if (the_case.second && the_case.second.length > 0) {
|
|
|
4560 |
particular = the_case.second[the_case.second.length - 1];
|
|
|
4561 |
if (unbroken && particular.disrupt && particular.id !== 'break') {
|
|
|
4562 |
this.disrupt = true;
|
|
|
4563 |
}
|
|
|
4564 |
}
|
|
|
4565 |
this.second.push(the_case);
|
|
|
4566 |
}
|
|
|
4567 |
funct['(breakage)'] -= 1;
|
|
|
4568 |
spaces();
|
|
|
4569 |
step_out('}', this);
|
|
|
4570 |
in_block = old_in_block;
|
|
|
4571 |
return this;
|
|
|
4572 |
});
|
|
|
4573 |
|
|
|
4574 |
stmt('debugger', function () {
|
|
|
4575 |
if (!option.debug) {
|
|
|
4576 |
warn('unexpected_a', this);
|
|
|
4577 |
}
|
|
|
4578 |
this.arity = 'statement';
|
|
|
4579 |
return this;
|
|
|
4580 |
});
|
|
|
4581 |
|
|
|
4582 |
labeled_stmt('do', function () {
|
|
|
4583 |
funct['(breakage)'] += 1;
|
|
|
4584 |
funct['(loopage)'] += 1;
|
|
|
4585 |
one_space();
|
|
|
4586 |
this.arity = 'statement';
|
|
|
4587 |
this.block = block(true);
|
|
|
4588 |
if (this.block.disrupt) {
|
|
|
4589 |
warn('strange_loop', prev_token);
|
|
|
4590 |
}
|
|
|
4591 |
one_space();
|
|
|
4592 |
advance('while');
|
|
|
4593 |
var paren = next_token;
|
|
|
4594 |
one_space();
|
|
|
4595 |
advance('(');
|
|
|
4596 |
step_in();
|
|
|
4597 |
no_space();
|
|
|
4598 |
edge();
|
|
|
4599 |
this.first = expected_condition(expected_relation(expression(0)), bundle.unexpected_a);
|
|
|
4600 |
no_space();
|
|
|
4601 |
step_out(')', paren);
|
|
|
4602 |
funct['(breakage)'] -= 1;
|
|
|
4603 |
funct['(loopage)'] -= 1;
|
|
|
4604 |
return this;
|
|
|
4605 |
});
|
|
|
4606 |
|
|
|
4607 |
labeled_stmt('for', function () {
|
|
|
4608 |
|
|
|
4609 |
var blok, filter, ok = false, paren = next_token, value;
|
|
|
4610 |
this.arity = 'statement';
|
|
|
4611 |
funct['(breakage)'] += 1;
|
|
|
4612 |
funct['(loopage)'] += 1;
|
|
|
4613 |
advance('(');
|
|
|
4614 |
if (next_token.id === ';') {
|
|
|
4615 |
no_space();
|
|
|
4616 |
advance(';');
|
|
|
4617 |
no_space();
|
|
|
4618 |
advance(';');
|
|
|
4619 |
no_space();
|
|
|
4620 |
advance(')');
|
|
|
4621 |
blok = block(true);
|
|
|
4622 |
} else {
|
|
|
4623 |
step_in('control');
|
|
|
4624 |
spaces(this, paren);
|
|
|
4625 |
no_space();
|
|
|
4626 |
if (next_token.id === 'var') {
|
|
|
4627 |
stop('move_var');
|
|
|
4628 |
}
|
|
|
4629 |
edge();
|
|
|
4630 |
if (peek(0).id === 'in') {
|
|
|
4631 |
this.forin = true;
|
|
|
4632 |
value = next_token;
|
|
|
4633 |
switch (funct[value.string]) {
|
|
|
4634 |
case 'unused':
|
|
|
4635 |
funct[value.string] = 'var';
|
|
|
4636 |
break;
|
|
|
4637 |
case 'closure':
|
|
|
4638 |
case 'var':
|
|
|
4639 |
break;
|
|
|
4640 |
default:
|
|
|
4641 |
warn('bad_in_a', value);
|
|
|
4642 |
}
|
|
|
4643 |
advance();
|
|
|
4644 |
advance('in');
|
|
|
4645 |
this.first = value;
|
|
|
4646 |
this.second = expression(20);
|
|
|
4647 |
step_out(')', paren);
|
|
|
4648 |
blok = block(true);
|
|
|
4649 |
if (!option.forin) {
|
|
|
4650 |
if (blok.length === 1 && typeof blok[0] === 'object' &&
|
|
|
4651 |
blok[0].string === 'if' && !blok[0]['else']) {
|
|
|
4652 |
filter = blok[0].first;
|
|
|
4653 |
while (filter.id === '&&') {
|
|
|
4654 |
filter = filter.first;
|
|
|
4655 |
}
|
|
|
4656 |
switch (filter.id) {
|
|
|
4657 |
case '===':
|
|
|
4658 |
case '!==':
|
|
|
4659 |
ok = filter.first.id === '['
|
|
|
4660 |
? filter.first.first.string === this.second.string &&
|
|
|
4661 |
filter.first.second.string === this.first.string
|
|
|
4662 |
: filter.first.id === 'typeof' &&
|
|
|
4663 |
filter.first.first.id === '[' &&
|
|
|
4664 |
filter.first.first.first.string === this.second.string &&
|
|
|
4665 |
filter.first.first.second.string === this.first.string;
|
|
|
4666 |
break;
|
|
|
4667 |
case '(':
|
|
|
4668 |
ok = filter.first.id === '.' && ((
|
|
|
4669 |
filter.first.first.string === this.second.string &&
|
|
|
4670 |
filter.first.second.string === 'hasOwnProperty' &&
|
|
|
4671 |
filter.second[0].string === this.first.string
|
|
|
4672 |
) || (
|
|
|
4673 |
filter.first.first.string === 'ADSAFE' &&
|
|
|
4674 |
filter.first.second.string === 'has' &&
|
|
|
4675 |
filter.second[0].string === this.second.string &&
|
|
|
4676 |
filter.second[1].string === this.first.string
|
|
|
4677 |
) || (
|
|
|
4678 |
filter.first.first.id === '.' &&
|
|
|
4679 |
filter.first.first.first.id === '.' &&
|
|
|
4680 |
filter.first.first.first.first.string === 'Object' &&
|
|
|
4681 |
filter.first.first.first.second.string === 'prototype' &&
|
|
|
4682 |
filter.first.first.second.string === 'hasOwnProperty' &&
|
|
|
4683 |
filter.first.second.string === 'call' &&
|
|
|
4684 |
filter.second[0].string === this.second.string &&
|
|
|
4685 |
filter.second[1].string === this.first.string
|
|
|
4686 |
));
|
|
|
4687 |
break;
|
|
|
4688 |
}
|
|
|
4689 |
}
|
|
|
4690 |
if (!ok) {
|
|
|
4691 |
warn('for_if', this);
|
|
|
4692 |
}
|
|
|
4693 |
}
|
|
|
4694 |
} else {
|
|
|
4695 |
edge();
|
|
|
4696 |
this.first = [];
|
|
|
4697 |
for (;;) {
|
|
|
4698 |
this.first.push(expression(0, 'for'));
|
|
|
4699 |
if (next_token.id !== ',') {
|
|
|
4700 |
break;
|
|
|
4701 |
}
|
|
|
4702 |
comma();
|
|
|
4703 |
}
|
|
|
4704 |
semicolon();
|
|
|
4705 |
edge();
|
|
|
4706 |
this.second = expected_relation(expression(0));
|
|
|
4707 |
if (this.second.id !== 'true') {
|
|
|
4708 |
expected_condition(this.second, bundle.unexpected_a);
|
|
|
4709 |
}
|
|
|
4710 |
semicolon(token);
|
|
|
4711 |
if (next_token.id === ';') {
|
|
|
4712 |
stop('expected_a_b', next_token, ')', ';');
|
|
|
4713 |
}
|
|
|
4714 |
this.third = [];
|
|
|
4715 |
edge();
|
|
|
4716 |
for (;;) {
|
|
|
4717 |
this.third.push(expression(0, 'for'));
|
|
|
4718 |
if (next_token.id !== ',') {
|
|
|
4719 |
break;
|
|
|
4720 |
}
|
|
|
4721 |
comma();
|
|
|
4722 |
}
|
|
|
4723 |
no_space();
|
|
|
4724 |
step_out(')', paren);
|
|
|
4725 |
one_space();
|
|
|
4726 |
blok = block(true);
|
|
|
4727 |
}
|
|
|
4728 |
}
|
|
|
4729 |
if (blok.disrupt) {
|
|
|
4730 |
warn('strange_loop', prev_token);
|
|
|
4731 |
}
|
|
|
4732 |
this.block = blok;
|
|
|
4733 |
funct['(breakage)'] -= 1;
|
|
|
4734 |
funct['(loopage)'] -= 1;
|
|
|
4735 |
return this;
|
|
|
4736 |
});
|
|
|
4737 |
|
|
|
4738 |
disrupt_stmt('break', function () {
|
|
|
4739 |
var label = next_token.string;
|
|
|
4740 |
this.arity = 'statement';
|
|
|
4741 |
if (funct['(breakage)'] === 0) {
|
|
|
4742 |
warn('unexpected_a', this);
|
|
|
4743 |
}
|
|
|
4744 |
if (next_token.identifier && token.line === next_token.line) {
|
|
|
4745 |
one_space_only();
|
|
|
4746 |
if (funct[label] !== 'label') {
|
|
|
4747 |
warn('not_a_label', next_token);
|
|
|
4748 |
} else if (scope[label].funct !== funct) {
|
|
|
4749 |
warn('not_a_scope', next_token);
|
|
|
4750 |
}
|
|
|
4751 |
this.first = next_token;
|
|
|
4752 |
advance();
|
|
|
4753 |
}
|
|
|
4754 |
return this;
|
|
|
4755 |
});
|
|
|
4756 |
|
|
|
4757 |
disrupt_stmt('continue', function () {
|
|
|
4758 |
if (!option['continue']) {
|
|
|
4759 |
warn('unexpected_a', this);
|
|
|
4760 |
}
|
|
|
4761 |
var label = next_token.string;
|
|
|
4762 |
this.arity = 'statement';
|
|
|
4763 |
if (funct['(breakage)'] === 0) {
|
|
|
4764 |
warn('unexpected_a', this);
|
|
|
4765 |
}
|
|
|
4766 |
if (next_token.identifier && token.line === next_token.line) {
|
|
|
4767 |
one_space_only();
|
|
|
4768 |
if (funct[label] !== 'label') {
|
|
|
4769 |
warn('not_a_label', next_token);
|
|
|
4770 |
} else if (scope[label].funct !== funct) {
|
|
|
4771 |
warn('not_a_scope', next_token);
|
|
|
4772 |
}
|
|
|
4773 |
this.first = next_token;
|
|
|
4774 |
advance();
|
|
|
4775 |
}
|
|
|
4776 |
return this;
|
|
|
4777 |
});
|
|
|
4778 |
|
|
|
4779 |
disrupt_stmt('return', function () {
|
|
|
4780 |
if (funct === global_funct) {
|
|
|
4781 |
warn('unexpected_a', this);
|
|
|
4782 |
}
|
|
|
4783 |
this.arity = 'statement';
|
|
|
4784 |
if (next_token.id !== ';' && next_token.line === token.line) {
|
|
|
4785 |
one_space_only();
|
|
|
4786 |
if (next_token.id === '/' || next_token.id === '(regexp)') {
|
|
|
4787 |
warn('wrap_regexp');
|
|
|
4788 |
}
|
|
|
4789 |
this.first = expression(20);
|
|
|
4790 |
}
|
|
|
4791 |
return this;
|
|
|
4792 |
});
|
|
|
4793 |
|
|
|
4794 |
disrupt_stmt('throw', function () {
|
|
|
4795 |
this.arity = 'statement';
|
|
|
4796 |
one_space_only();
|
|
|
4797 |
this.first = expression(20);
|
|
|
4798 |
return this;
|
|
|
4799 |
});
|
|
|
4800 |
|
|
|
4801 |
|
|
|
4802 |
// Superfluous reserved words
|
|
|
4803 |
|
|
|
4804 |
reserve('class');
|
|
|
4805 |
reserve('const');
|
|
|
4806 |
reserve('enum');
|
|
|
4807 |
reserve('export');
|
|
|
4808 |
reserve('extends');
|
|
|
4809 |
reserve('import');
|
|
|
4810 |
reserve('super');
|
|
|
4811 |
|
|
|
4812 |
// Harmony reserved words
|
|
|
4813 |
|
|
|
4814 |
reserve('implements');
|
|
|
4815 |
reserve('interface');
|
|
|
4816 |
reserve('let');
|
|
|
4817 |
reserve('package');
|
|
|
4818 |
reserve('private');
|
|
|
4819 |
reserve('protected');
|
|
|
4820 |
reserve('public');
|
|
|
4821 |
reserve('static');
|
|
|
4822 |
reserve('yield');
|
|
|
4823 |
|
|
|
4824 |
|
|
|
4825 |
// Type inference
|
|
|
4826 |
|
|
|
4827 |
// function get_type(one) {
|
|
|
4828 |
// var type;
|
|
|
4829 |
// if (typeof one === 'string') {
|
|
|
4830 |
// return one;
|
|
|
4831 |
// } else if (one.type) {
|
|
|
4832 |
// return one.type;
|
|
|
4833 |
// } else if (one.id === '.') {
|
|
|
4834 |
// type = property_type[one.second.string];
|
|
|
4835 |
// return typeof type === 'string' ? type : '';
|
|
|
4836 |
// } else {
|
|
|
4837 |
// return ((one.identifier && scope[one.string]) || one).type;
|
|
|
4838 |
// }
|
|
|
4839 |
// }
|
|
|
4840 |
|
|
|
4841 |
|
|
|
4842 |
// function match_type(one_type, two_type, one, two) {
|
|
|
4843 |
// if (one_type === two_type) {
|
|
|
4844 |
// return true;
|
|
|
4845 |
// } else {
|
|
|
4846 |
// if (!funct.confusion && !two.warn) {
|
|
|
4847 |
// if (typeof one !== 'string') {
|
|
|
4848 |
// if (one.id === '.') {
|
|
|
4849 |
// one_type = '.' + one.second.string + ': ' + one_type;
|
|
|
4850 |
// } else {
|
|
|
4851 |
// one_type = one.string + ': ' + one_type;
|
|
|
4852 |
// }
|
|
|
4853 |
// }
|
|
|
4854 |
// if (two.id === '.') {
|
|
|
4855 |
// two_type = '.' + two.second.string + ': ' + one_type;
|
|
|
4856 |
// } else {
|
|
|
4857 |
// two_type = two.string + ': ' + one_type;
|
|
|
4858 |
// }
|
|
|
4859 |
// warn('type_confusion_a_b', two, one_type, two_type);
|
|
|
4860 |
// two.warn = true;
|
|
|
4861 |
// }
|
|
|
4862 |
// return false;
|
|
|
4863 |
// }
|
|
|
4864 |
// }
|
|
|
4865 |
|
|
|
4866 |
|
|
|
4867 |
// function conform(one, two) {
|
|
|
4868 |
//
|
|
|
4869 |
// // The conform function takes a type string and a token, or two tokens.
|
|
|
4870 |
//
|
|
|
4871 |
// var one_type = typeof one === 'string' ? one : one.type,
|
|
|
4872 |
// two_type = two.type,
|
|
|
4873 |
// two_thing;
|
|
|
4874 |
//
|
|
|
4875 |
// // If both tokens already have a type, and if they match, then we are done.
|
|
|
4876 |
// // Once a token has a type, it is locked. Neither token will change, but if
|
|
|
4877 |
// // they do not match, there will be a warning.
|
|
|
4878 |
//
|
|
|
4879 |
// if (one_type) {
|
|
|
4880 |
// if (two_type) {
|
|
|
4881 |
// match_type(one_type, two_type, one, two);
|
|
|
4882 |
// } else {
|
|
|
4883 |
//
|
|
|
4884 |
// // two does not have a type, so look deeper. If two is a variable or property,
|
|
|
4885 |
// // then use its type if it has one, and make the deep type one's type if it
|
|
|
4886 |
// // doesn't. If the type was *, or if there was a mismatch, don't change the
|
|
|
4887 |
// // deep type.
|
|
|
4888 |
//
|
|
|
4889 |
// two_thing = two.id === '(identifier)'
|
|
|
4890 |
// ? scope[two.string]
|
|
|
4891 |
// : two.id === '.'
|
|
|
4892 |
// ? property_type[two.second.string]
|
|
|
4893 |
// : null;
|
|
|
4894 |
// if (two_thing) {
|
|
|
4895 |
// two_type = two_thing.type;
|
|
|
4896 |
// if (two_type) {
|
|
|
4897 |
// if (two_type !== '*') {
|
|
|
4898 |
// if (!match_type(one_type, two_type, one, two)) {
|
|
|
4899 |
// return '';
|
|
|
4900 |
// }
|
|
|
4901 |
// }
|
|
|
4902 |
// } else {
|
|
|
4903 |
// two_thing.type = one_type;
|
|
|
4904 |
// }
|
|
|
4905 |
// }
|
|
|
4906 |
//
|
|
|
4907 |
// // In any case, we give two a type.
|
|
|
4908 |
//
|
|
|
4909 |
// two.type = one_type;
|
|
|
4910 |
// type_state_change = true;
|
|
|
4911 |
// return one_type;
|
|
|
4912 |
// }
|
|
|
4913 |
//
|
|
|
4914 |
// // one does not have a type, but two does, so do the old switcheroo.
|
|
|
4915 |
//
|
|
|
4916 |
// } else {
|
|
|
4917 |
// if (two_type) {
|
|
|
4918 |
// return conform(two, one);
|
|
|
4919 |
//
|
|
|
4920 |
// // Neither token has a type yet. So we have to look deeper to see if either
|
|
|
4921 |
// // is a variable or property.
|
|
|
4922 |
//
|
|
|
4923 |
// } else {
|
|
|
4924 |
// if (one.id === '(identifier)') {
|
|
|
4925 |
// one_type = scope[one.string].type;
|
|
|
4926 |
// if (one_type && one_type !== '*') {
|
|
|
4927 |
// one.type = one_type;
|
|
|
4928 |
// return conform(one, two);
|
|
|
4929 |
// }
|
|
|
4930 |
// } else if (one.id === '.') {
|
|
|
4931 |
// one_type = property_type[one.second.string];
|
|
|
4932 |
// if (one_type && one_type !== '*') {
|
|
|
4933 |
// one.type = scope[one.string].type;
|
|
|
4934 |
// return conform(one, two);
|
|
|
4935 |
// }
|
|
|
4936 |
// }
|
|
|
4937 |
// if (two.id === '(identifier)') {
|
|
|
4938 |
// two_type = scope[two.string].type;
|
|
|
4939 |
// if (two_type && two_type !== '*') {
|
|
|
4940 |
// two.type = two_type;
|
|
|
4941 |
// return conform(two, one);
|
|
|
4942 |
// }
|
|
|
4943 |
// } else if (two.id === '.') {
|
|
|
4944 |
// two_type = property_type[two.second.string];
|
|
|
4945 |
// if (two_type && two_type !== '*') {
|
|
|
4946 |
// two.type = scope[two.string].type;
|
|
|
4947 |
// return conform(two, one);
|
|
|
4948 |
// }
|
|
|
4949 |
// }
|
|
|
4950 |
// }
|
|
|
4951 |
// }
|
|
|
4952 |
//
|
|
|
4953 |
// // Return a falsy string if we were unable to determine the type of either token.
|
|
|
4954 |
//
|
|
|
4955 |
// return '';
|
|
|
4956 |
// }
|
|
|
4957 |
|
|
|
4958 |
// function conform_array(type, array) {
|
|
|
4959 |
// array.forEach(function (item) {
|
|
|
4960 |
// return conform(type, item);
|
|
|
4961 |
// }, type);
|
|
|
4962 |
// }
|
|
|
4963 |
|
|
|
4964 |
|
|
|
4965 |
// function infer(node) {
|
|
|
4966 |
// if (Array.isArray(node)) {
|
|
|
4967 |
// node.forEach(infer);
|
|
|
4968 |
// } else {
|
|
|
4969 |
// switch (node.arity) {
|
|
|
4970 |
// case 'statement':
|
|
|
4971 |
// infer_statement[node.id](node);
|
|
|
4972 |
// break;
|
|
|
4973 |
// case 'infix':
|
|
|
4974 |
// infer(node.first);
|
|
|
4975 |
// infer(node.second);
|
|
|
4976 |
// switch (node.id) {
|
|
|
4977 |
// case '(':
|
|
|
4978 |
// conform('function', node.first);
|
|
|
4979 |
// break;
|
|
|
4980 |
// default:
|
|
|
4981 |
// stop('unfinished');
|
|
|
4982 |
// }
|
|
|
4983 |
// break;
|
|
|
4984 |
// case 'number':
|
|
|
4985 |
// case 'string':
|
|
|
4986 |
// case 'boolean':
|
|
|
4987 |
// break;
|
|
|
4988 |
// default:
|
|
|
4989 |
// stop('unfinished');
|
|
|
4990 |
// }
|
|
|
4991 |
// }
|
|
|
4992 |
// }
|
|
|
4993 |
|
|
|
4994 |
|
|
|
4995 |
// infer_statement = {
|
|
|
4996 |
// 'var': function (node) {
|
|
|
4997 |
// var i, item, list = node.first;
|
|
|
4998 |
// for (i = 0; i < list.length; i += 1) {
|
|
|
4999 |
// item = list[i];
|
|
|
5000 |
// if (item.id === '=') {
|
|
|
5001 |
// infer(item.second);
|
|
|
5002 |
// conform(item.first, item.second);
|
|
|
5003 |
// conform(item.first, item);
|
|
|
5004 |
// }
|
|
|
5005 |
// }
|
|
|
5006 |
// },
|
|
|
5007 |
// 'for': function (node) {
|
|
|
5008 |
// infer(node.first);
|
|
|
5009 |
// infer(node.second);
|
|
|
5010 |
// if (node.forin) {
|
|
|
5011 |
// conform('string', node.first);
|
|
|
5012 |
// conform('object', node.second);
|
|
|
5013 |
// } else {
|
|
|
5014 |
// infer(node.third);
|
|
|
5015 |
// conform_array('number', node.first);
|
|
|
5016 |
// conform('boolean', node.second);
|
|
|
5017 |
// conform_array('number', node.third);
|
|
|
5018 |
// }
|
|
|
5019 |
// infer(node.block);
|
|
|
5020 |
// }
|
|
|
5021 |
// };
|
|
|
5022 |
|
|
|
5023 |
|
|
|
5024 |
// function infer_types(node) {
|
|
|
5025 |
// do {
|
|
|
5026 |
// funct = global_funct;
|
|
|
5027 |
// scope = global_scope;
|
|
|
5028 |
// type_state_change = false;
|
|
|
5029 |
// infer(node);
|
|
|
5030 |
// } while (type_state_change);
|
|
|
5031 |
// }
|
|
|
5032 |
|
|
|
5033 |
|
|
|
5034 |
// Parse JSON
|
|
|
5035 |
|
|
|
5036 |
function json_value() {
|
|
|
5037 |
|
|
|
5038 |
function json_object() {
|
|
|
5039 |
var brace = next_token, object = {};
|
|
|
5040 |
advance('{');
|
|
|
5041 |
if (next_token.id !== '}') {
|
|
|
5042 |
while (next_token.id !== '(end)') {
|
|
|
5043 |
while (next_token.id === ',') {
|
|
|
5044 |
warn('unexpected_a', next_token);
|
|
|
5045 |
advance(',');
|
|
|
5046 |
}
|
|
|
5047 |
if (next_token.id !== '(string)') {
|
|
|
5048 |
warn('expected_string_a');
|
|
|
5049 |
}
|
|
|
5050 |
if (object[next_token.string] === true) {
|
|
|
5051 |
warn('duplicate_a');
|
|
|
5052 |
} else if (next_token.string === '__proto__') {
|
|
|
5053 |
warn('dangling_a');
|
|
|
5054 |
} else {
|
|
|
5055 |
object[next_token.string] = true;
|
|
|
5056 |
}
|
|
|
5057 |
advance();
|
|
|
5058 |
advance(':');
|
|
|
5059 |
json_value();
|
|
|
5060 |
if (next_token.id !== ',') {
|
|
|
5061 |
break;
|
|
|
5062 |
}
|
|
|
5063 |
advance(',');
|
|
|
5064 |
if (next_token.id === '}') {
|
|
|
5065 |
warn('unexpected_a', token);
|
|
|
5066 |
break;
|
|
|
5067 |
}
|
|
|
5068 |
}
|
|
|
5069 |
}
|
|
|
5070 |
advance('}', brace);
|
|
|
5071 |
}
|
|
|
5072 |
|
|
|
5073 |
function json_array() {
|
|
|
5074 |
var bracket = next_token;
|
|
|
5075 |
advance('[');
|
|
|
5076 |
if (next_token.id !== ']') {
|
|
|
5077 |
while (next_token.id !== '(end)') {
|
|
|
5078 |
while (next_token.id === ',') {
|
|
|
5079 |
warn('unexpected_a', next_token);
|
|
|
5080 |
advance(',');
|
|
|
5081 |
}
|
|
|
5082 |
json_value();
|
|
|
5083 |
if (next_token.id !== ',') {
|
|
|
5084 |
break;
|
|
|
5085 |
}
|
|
|
5086 |
advance(',');
|
|
|
5087 |
if (next_token.id === ']') {
|
|
|
5088 |
warn('unexpected_a', token);
|
|
|
5089 |
break;
|
|
|
5090 |
}
|
|
|
5091 |
}
|
|
|
5092 |
}
|
|
|
5093 |
advance(']', bracket);
|
|
|
5094 |
}
|
|
|
5095 |
|
|
|
5096 |
switch (next_token.id) {
|
|
|
5097 |
case '{':
|
|
|
5098 |
json_object();
|
|
|
5099 |
break;
|
|
|
5100 |
case '[':
|
|
|
5101 |
json_array();
|
|
|
5102 |
break;
|
|
|
5103 |
case 'true':
|
|
|
5104 |
case 'false':
|
|
|
5105 |
case 'null':
|
|
|
5106 |
case '(number)':
|
|
|
5107 |
case '(string)':
|
|
|
5108 |
advance();
|
|
|
5109 |
break;
|
|
|
5110 |
case '-':
|
|
|
5111 |
advance('-');
|
|
|
5112 |
no_space_only();
|
|
|
5113 |
advance('(number)');
|
|
|
5114 |
break;
|
|
|
5115 |
default:
|
|
|
5116 |
stop('unexpected_a');
|
|
|
5117 |
}
|
|
|
5118 |
}
|
|
|
5119 |
|
|
|
5120 |
|
|
|
5121 |
// CSS parsing.
|
|
|
5122 |
|
|
|
5123 |
function css_name() {
|
|
|
5124 |
if (next_token.identifier) {
|
|
|
5125 |
advance();
|
|
|
5126 |
return true;
|
|
|
5127 |
}
|
|
|
5128 |
}
|
|
|
5129 |
|
|
|
5130 |
|
|
|
5131 |
function css_number() {
|
|
|
5132 |
if (next_token.id === '-') {
|
|
|
5133 |
advance('-');
|
|
|
5134 |
no_space_only();
|
|
|
5135 |
}
|
|
|
5136 |
if (next_token.id === '(number)') {
|
|
|
5137 |
advance('(number)');
|
|
|
5138 |
return true;
|
|
|
5139 |
}
|
|
|
5140 |
}
|
|
|
5141 |
|
|
|
5142 |
|
|
|
5143 |
function css_string() {
|
|
|
5144 |
if (next_token.id === '(string)') {
|
|
|
5145 |
advance();
|
|
|
5146 |
return true;
|
|
|
5147 |
}
|
|
|
5148 |
}
|
|
|
5149 |
|
|
|
5150 |
function css_color() {
|
|
|
5151 |
var i, number, paren, value;
|
|
|
5152 |
if (next_token.identifier) {
|
|
|
5153 |
value = next_token.string;
|
|
|
5154 |
if (value === 'rgb' || value === 'rgba') {
|
|
|
5155 |
advance();
|
|
|
5156 |
paren = next_token;
|
|
|
5157 |
advance('(');
|
|
|
5158 |
for (i = 0; i < 3; i += 1) {
|
|
|
5159 |
if (i) {
|
|
|
5160 |
comma();
|
|
|
5161 |
}
|
|
|
5162 |
number = next_token.number;
|
|
|
5163 |
if (next_token.id !== '(number)' || number < 0) {
|
|
|
5164 |
warn('expected_positive_a', next_token);
|
|
|
5165 |
advance();
|
|
|
5166 |
} else {
|
|
|
5167 |
advance();
|
|
|
5168 |
if (next_token.id === '%') {
|
|
|
5169 |
advance('%');
|
|
|
5170 |
if (number > 100) {
|
|
|
5171 |
warn('expected_percent_a', token, number);
|
|
|
5172 |
}
|
|
|
5173 |
} else {
|
|
|
5174 |
if (number > 255) {
|
|
|
5175 |
warn('expected_small_a', token, number);
|
|
|
5176 |
}
|
|
|
5177 |
}
|
|
|
5178 |
}
|
|
|
5179 |
}
|
|
|
5180 |
if (value === 'rgba') {
|
|
|
5181 |
comma();
|
|
|
5182 |
number = next_token.number;
|
|
|
5183 |
if (next_token.id !== '(number)' || number < 0 || number > 1) {
|
|
|
5184 |
warn('expected_fraction_a', next_token);
|
|
|
5185 |
}
|
|
|
5186 |
advance();
|
|
|
5187 |
if (next_token.id === '%') {
|
|
|
5188 |
warn('unexpected_a');
|
|
|
5189 |
advance('%');
|
|
|
5190 |
}
|
|
|
5191 |
}
|
|
|
5192 |
advance(')', paren);
|
|
|
5193 |
return true;
|
|
|
5194 |
} else if (css_colorData[next_token.string] === true) {
|
|
|
5195 |
advance();
|
|
|
5196 |
return true;
|
|
|
5197 |
}
|
|
|
5198 |
} else if (next_token.id === '(color)') {
|
|
|
5199 |
advance();
|
|
|
5200 |
return true;
|
|
|
5201 |
}
|
|
|
5202 |
return false;
|
|
|
5203 |
}
|
|
|
5204 |
|
|
|
5205 |
|
|
|
5206 |
function css_length() {
|
|
|
5207 |
if (next_token.id === '-') {
|
|
|
5208 |
advance('-');
|
|
|
5209 |
no_space_only();
|
|
|
5210 |
}
|
|
|
5211 |
if (next_token.id === '(number)') {
|
|
|
5212 |
advance();
|
|
|
5213 |
if (next_token.id !== '(string)' &&
|
|
|
5214 |
css_lengthData[next_token.string] === true) {
|
|
|
5215 |
no_space_only();
|
|
|
5216 |
advance();
|
|
|
5217 |
} else if (+token.number !== 0) {
|
|
|
5218 |
warn('expected_linear_a');
|
|
|
5219 |
}
|
|
|
5220 |
return true;
|
|
|
5221 |
}
|
|
|
5222 |
return false;
|
|
|
5223 |
}
|
|
|
5224 |
|
|
|
5225 |
|
|
|
5226 |
function css_line_height() {
|
|
|
5227 |
if (next_token.id === '-') {
|
|
|
5228 |
advance('-');
|
|
|
5229 |
no_space_only();
|
|
|
5230 |
}
|
|
|
5231 |
if (next_token.id === '(number)') {
|
|
|
5232 |
advance();
|
|
|
5233 |
if (next_token.id !== '(string)' &&
|
|
|
5234 |
css_lengthData[next_token.string] === true) {
|
|
|
5235 |
no_space_only();
|
|
|
5236 |
advance();
|
|
|
5237 |
}
|
|
|
5238 |
return true;
|
|
|
5239 |
}
|
|
|
5240 |
return false;
|
|
|
5241 |
}
|
|
|
5242 |
|
|
|
5243 |
|
|
|
5244 |
function css_width() {
|
|
|
5245 |
if (next_token.identifier) {
|
|
|
5246 |
switch (next_token.string) {
|
|
|
5247 |
case 'thin':
|
|
|
5248 |
case 'medium':
|
|
|
5249 |
case 'thick':
|
|
|
5250 |
advance();
|
|
|
5251 |
return true;
|
|
|
5252 |
}
|
|
|
5253 |
} else {
|
|
|
5254 |
return css_length();
|
|
|
5255 |
}
|
|
|
5256 |
}
|
|
|
5257 |
|
|
|
5258 |
|
|
|
5259 |
function css_margin() {
|
|
|
5260 |
if (next_token.identifier) {
|
|
|
5261 |
if (next_token.string === 'auto') {
|
|
|
5262 |
advance();
|
|
|
5263 |
return true;
|
|
|
5264 |
}
|
|
|
5265 |
} else {
|
|
|
5266 |
return css_length();
|
|
|
5267 |
}
|
|
|
5268 |
}
|
|
|
5269 |
|
|
|
5270 |
function css_attr() {
|
|
|
5271 |
if (next_token.identifier && next_token.string === 'attr') {
|
|
|
5272 |
advance();
|
|
|
5273 |
advance('(');
|
|
|
5274 |
if (!next_token.identifier) {
|
|
|
5275 |
warn('expected_name_a');
|
|
|
5276 |
}
|
|
|
5277 |
advance();
|
|
|
5278 |
advance(')');
|
|
|
5279 |
return true;
|
|
|
5280 |
}
|
|
|
5281 |
return false;
|
|
|
5282 |
}
|
|
|
5283 |
|
|
|
5284 |
|
|
|
5285 |
function css_comma_list() {
|
|
|
5286 |
while (next_token.id !== ';') {
|
|
|
5287 |
if (!css_name() && !css_string()) {
|
|
|
5288 |
warn('expected_name_a');
|
|
|
5289 |
}
|
|
|
5290 |
if (next_token.id !== ',') {
|
|
|
5291 |
return true;
|
|
|
5292 |
}
|
|
|
5293 |
comma();
|
|
|
5294 |
}
|
|
|
5295 |
}
|
|
|
5296 |
|
|
|
5297 |
|
|
|
5298 |
function css_counter() {
|
|
|
5299 |
if (next_token.identifier && next_token.string === 'counter') {
|
|
|
5300 |
advance();
|
|
|
5301 |
advance('(');
|
|
|
5302 |
advance();
|
|
|
5303 |
if (next_token.id === ',') {
|
|
|
5304 |
comma();
|
|
|
5305 |
if (next_token.id !== '(string)') {
|
|
|
5306 |
warn('expected_string_a');
|
|
|
5307 |
}
|
|
|
5308 |
advance();
|
|
|
5309 |
}
|
|
|
5310 |
advance(')');
|
|
|
5311 |
return true;
|
|
|
5312 |
}
|
|
|
5313 |
if (next_token.identifier && next_token.string === 'counters') {
|
|
|
5314 |
advance();
|
|
|
5315 |
advance('(');
|
|
|
5316 |
if (!next_token.identifier) {
|
|
|
5317 |
warn('expected_name_a');
|
|
|
5318 |
}
|
|
|
5319 |
advance();
|
|
|
5320 |
if (next_token.id === ',') {
|
|
|
5321 |
comma();
|
|
|
5322 |
if (next_token.id !== '(string)') {
|
|
|
5323 |
warn('expected_string_a');
|
|
|
5324 |
}
|
|
|
5325 |
advance();
|
|
|
5326 |
}
|
|
|
5327 |
if (next_token.id === ',') {
|
|
|
5328 |
comma();
|
|
|
5329 |
if (next_token.id !== '(string)') {
|
|
|
5330 |
warn('expected_string_a');
|
|
|
5331 |
}
|
|
|
5332 |
advance();
|
|
|
5333 |
}
|
|
|
5334 |
advance(')');
|
|
|
5335 |
return true;
|
|
|
5336 |
}
|
|
|
5337 |
return false;
|
|
|
5338 |
}
|
|
|
5339 |
|
|
|
5340 |
|
|
|
5341 |
function css_radius() {
|
|
|
5342 |
return css_length() && (next_token.id !== '(number)' || css_length());
|
|
|
5343 |
}
|
|
|
5344 |
|
|
|
5345 |
|
|
|
5346 |
function css_shape() {
|
|
|
5347 |
var i;
|
|
|
5348 |
if (next_token.identifier && next_token.string === 'rect') {
|
|
|
5349 |
advance();
|
|
|
5350 |
advance('(');
|
|
|
5351 |
for (i = 0; i < 4; i += 1) {
|
|
|
5352 |
if (!css_length()) {
|
|
|
5353 |
warn('expected_number_a');
|
|
|
5354 |
break;
|
|
|
5355 |
}
|
|
|
5356 |
}
|
|
|
5357 |
advance(')');
|
|
|
5358 |
return true;
|
|
|
5359 |
}
|
|
|
5360 |
return false;
|
|
|
5361 |
}
|
|
|
5362 |
|
|
|
5363 |
|
|
|
5364 |
function css_url() {
|
|
|
5365 |
var c, url;
|
|
|
5366 |
if (next_token.identifier && next_token.string === 'url') {
|
|
|
5367 |
next_token = lex.range('(', ')');
|
|
|
5368 |
url = next_token.string;
|
|
|
5369 |
c = url.charAt(0);
|
|
|
5370 |
if (c === '"' || c === '\'') {
|
|
|
5371 |
if (url.slice(-1) !== c) {
|
|
|
5372 |
warn('bad_url_a');
|
|
|
5373 |
} else {
|
|
|
5374 |
url = url.slice(1, -1);
|
|
|
5375 |
if (url.indexOf(c) >= 0) {
|
|
|
5376 |
warn('bad_url_a');
|
|
|
5377 |
}
|
|
|
5378 |
}
|
|
|
5379 |
}
|
|
|
5380 |
if (!url) {
|
|
|
5381 |
warn('missing_url');
|
|
|
5382 |
}
|
|
|
5383 |
if (ux.test(url)) {
|
|
|
5384 |
stop('bad_url_a');
|
|
|
5385 |
}
|
|
|
5386 |
urls.push(url);
|
|
|
5387 |
advance();
|
|
|
5388 |
return true;
|
|
|
5389 |
}
|
|
|
5390 |
return false;
|
|
|
5391 |
}
|
|
|
5392 |
|
|
|
5393 |
|
|
|
5394 |
css_any = [css_url, function () {
|
|
|
5395 |
for (;;) {
|
|
|
5396 |
if (next_token.identifier) {
|
|
|
5397 |
switch (next_token.string.toLowerCase()) {
|
|
|
5398 |
case 'url':
|
|
|
5399 |
css_url();
|
|
|
5400 |
break;
|
|
|
5401 |
case 'expression':
|
|
|
5402 |
warn('unexpected_a');
|
|
|
5403 |
advance();
|
|
|
5404 |
break;
|
|
|
5405 |
default:
|
|
|
5406 |
advance();
|
|
|
5407 |
}
|
|
|
5408 |
} else {
|
|
|
5409 |
if (next_token.id === ';' || next_token.id === '!' ||
|
|
|
5410 |
next_token.id === '(end)' || next_token.id === '}') {
|
|
|
5411 |
return true;
|
|
|
5412 |
}
|
|
|
5413 |
advance();
|
|
|
5414 |
}
|
|
|
5415 |
}
|
|
|
5416 |
}];
|
|
|
5417 |
|
|
|
5418 |
|
|
|
5419 |
function font_face() {
|
|
|
5420 |
advance_identifier('font-family');
|
|
|
5421 |
advance(':');
|
|
|
5422 |
if (!css_name() && !css_string()) {
|
|
|
5423 |
stop('expected_name_a');
|
|
|
5424 |
}
|
|
|
5425 |
semicolon();
|
|
|
5426 |
advance_identifier('src');
|
|
|
5427 |
advance(':');
|
|
|
5428 |
while (true) {
|
|
|
5429 |
if (next_token.string === 'local') {
|
|
|
5430 |
advance_identifier('local');
|
|
|
5431 |
advance('(');
|
|
|
5432 |
if (ux.test(next_token.string)) {
|
|
|
5433 |
stop('bad_url_a');
|
|
|
5434 |
}
|
|
|
5435 |
|
|
|
5436 |
if (!css_name() && !css_string()) {
|
|
|
5437 |
stop('expected_name_a');
|
|
|
5438 |
}
|
|
|
5439 |
advance(')');
|
|
|
5440 |
} else if (!css_url()) {
|
|
|
5441 |
stop('expected_a_b', next_token, 'url', artifact());
|
|
|
5442 |
}
|
|
|
5443 |
if (next_token.id !== ',') {
|
|
|
5444 |
break;
|
|
|
5445 |
}
|
|
|
5446 |
comma();
|
|
|
5447 |
}
|
|
|
5448 |
semicolon();
|
|
|
5449 |
}
|
|
|
5450 |
|
|
|
5451 |
|
|
|
5452 |
css_border_style = [
|
|
|
5453 |
'none', 'dashed', 'dotted', 'double', 'groove',
|
|
|
5454 |
'hidden', 'inset', 'outset', 'ridge', 'solid'
|
|
|
5455 |
];
|
|
|
5456 |
|
|
|
5457 |
css_break = [
|
|
|
5458 |
'auto', 'always', 'avoid', 'left', 'right'
|
|
|
5459 |
];
|
|
|
5460 |
|
|
|
5461 |
css_media = {
|
|
|
5462 |
'all': true,
|
|
|
5463 |
'braille': true,
|
|
|
5464 |
'embossed': true,
|
|
|
5465 |
'handheld': true,
|
|
|
5466 |
'print': true,
|
|
|
5467 |
'projection': true,
|
|
|
5468 |
'screen': true,
|
|
|
5469 |
'speech': true,
|
|
|
5470 |
'tty': true,
|
|
|
5471 |
'tv': true
|
|
|
5472 |
};
|
|
|
5473 |
|
|
|
5474 |
css_overflow = [
|
|
|
5475 |
'auto', 'hidden', 'scroll', 'visible'
|
|
|
5476 |
];
|
|
|
5477 |
|
|
|
5478 |
css_attribute_data = {
|
|
|
5479 |
background: [
|
|
|
5480 |
true, 'background-attachment', 'background-color',
|
|
|
5481 |
'background-image', 'background-position', 'background-repeat'
|
|
|
5482 |
],
|
|
|
5483 |
'background-attachment': ['scroll', 'fixed'],
|
|
|
5484 |
'background-color': ['transparent', css_color],
|
|
|
5485 |
'background-image': ['none', css_url],
|
|
|
5486 |
'background-position': [
|
|
|
5487 |
2, [css_length, 'top', 'bottom', 'left', 'right', 'center']
|
|
|
5488 |
],
|
|
|
5489 |
'background-repeat': [
|
|
|
5490 |
'repeat', 'repeat-x', 'repeat-y', 'no-repeat'
|
|
|
5491 |
],
|
|
|
5492 |
'border': [true, 'border-color', 'border-style', 'border-width'],
|
|
|
5493 |
'border-bottom': [
|
|
|
5494 |
true, 'border-bottom-color', 'border-bottom-style',
|
|
|
5495 |
'border-bottom-width'
|
|
|
5496 |
],
|
|
|
5497 |
'border-bottom-color': css_color,
|
|
|
5498 |
'border-bottom-left-radius': css_radius,
|
|
|
5499 |
'border-bottom-right-radius': css_radius,
|
|
|
5500 |
'border-bottom-style': css_border_style,
|
|
|
5501 |
'border-bottom-width': css_width,
|
|
|
5502 |
'border-collapse': ['collapse', 'separate'],
|
|
|
5503 |
'border-color': ['transparent', 4, css_color],
|
|
|
5504 |
'border-left': [
|
|
|
5505 |
true, 'border-left-color', 'border-left-style', 'border-left-width'
|
|
|
5506 |
],
|
|
|
5507 |
'border-left-color': css_color,
|
|
|
5508 |
'border-left-style': css_border_style,
|
|
|
5509 |
'border-left-width': css_width,
|
|
|
5510 |
'border-radius': function () {
|
|
|
5511 |
function count(separator) {
|
|
|
5512 |
var n = 1;
|
|
|
5513 |
if (separator) {
|
|
|
5514 |
advance(separator);
|
|
|
5515 |
}
|
|
|
5516 |
if (!css_length()) {
|
|
|
5517 |
return false;
|
|
|
5518 |
}
|
|
|
5519 |
while (next_token.id === '(number)') {
|
|
|
5520 |
if (!css_length()) {
|
|
|
5521 |
return false;
|
|
|
5522 |
}
|
|
|
5523 |
n += 1;
|
|
|
5524 |
}
|
|
|
5525 |
if (n > 4) {
|
|
|
5526 |
warn('bad_style');
|
|
|
5527 |
}
|
|
|
5528 |
return true;
|
|
|
5529 |
}
|
|
|
5530 |
|
|
|
5531 |
return count() && (next_token.id !== '/' || count('/'));
|
|
|
5532 |
},
|
|
|
5533 |
'border-right': [
|
|
|
5534 |
true, 'border-right-color', 'border-right-style',
|
|
|
5535 |
'border-right-width'
|
|
|
5536 |
],
|
|
|
5537 |
'border-right-color': css_color,
|
|
|
5538 |
'border-right-style': css_border_style,
|
|
|
5539 |
'border-right-width': css_width,
|
|
|
5540 |
'border-spacing': [2, css_length],
|
|
|
5541 |
'border-style': [4, css_border_style],
|
|
|
5542 |
'border-top': [
|
|
|
5543 |
true, 'border-top-color', 'border-top-style', 'border-top-width'
|
|
|
5544 |
],
|
|
|
5545 |
'border-top-color': css_color,
|
|
|
5546 |
'border-top-left-radius': css_radius,
|
|
|
5547 |
'border-top-right-radius': css_radius,
|
|
|
5548 |
'border-top-style': css_border_style,
|
|
|
5549 |
'border-top-width': css_width,
|
|
|
5550 |
'border-width': [4, css_width],
|
|
|
5551 |
bottom: [css_length, 'auto'],
|
|
|
5552 |
'caption-side' : ['bottom', 'left', 'right', 'top'],
|
|
|
5553 |
clear: ['both', 'left', 'none', 'right'],
|
|
|
5554 |
clip: [css_shape, 'auto'],
|
|
|
5555 |
color: css_color,
|
|
|
5556 |
content: [
|
|
|
5557 |
'open-quote', 'close-quote', 'no-open-quote', 'no-close-quote',
|
|
|
5558 |
css_string, css_url, css_counter, css_attr
|
|
|
5559 |
],
|
|
|
5560 |
'counter-increment': [
|
|
|
5561 |
css_name, 'none'
|
|
|
5562 |
],
|
|
|
5563 |
'counter-reset': [
|
|
|
5564 |
css_name, 'none'
|
|
|
5565 |
],
|
|
|
5566 |
cursor: [
|
|
|
5567 |
css_url, 'auto', 'crosshair', 'default', 'e-resize', 'help', 'move',
|
|
|
5568 |
'n-resize', 'ne-resize', 'nw-resize', 'pointer', 's-resize',
|
|
|
5569 |
'se-resize', 'sw-resize', 'w-resize', 'text', 'wait'
|
|
|
5570 |
],
|
|
|
5571 |
direction: ['ltr', 'rtl'],
|
|
|
5572 |
display: [
|
|
|
5573 |
'block', 'compact', 'inline', 'inline-block', 'inline-table',
|
|
|
5574 |
'list-item', 'marker', 'none', 'run-in', 'table', 'table-caption',
|
|
|
5575 |
'table-cell', 'table-column', 'table-column-group',
|
|
|
5576 |
'table-footer-group', 'table-header-group', 'table-row',
|
|
|
5577 |
'table-row-group'
|
|
|
5578 |
],
|
|
|
5579 |
'empty-cells': ['show', 'hide'],
|
|
|
5580 |
'float': ['left', 'none', 'right'],
|
|
|
5581 |
font: [
|
|
|
5582 |
'caption', 'icon', 'menu', 'message-box', 'small-caption',
|
|
|
5583 |
'status-bar', true, 'font-size', 'font-style', 'font-weight',
|
|
|
5584 |
'font-family'
|
|
|
5585 |
],
|
|
|
5586 |
'font-family': css_comma_list,
|
|
|
5587 |
'font-size': [
|
|
|
5588 |
'xx-small', 'x-small', 'small', 'medium', 'large', 'x-large',
|
|
|
5589 |
'xx-large', 'larger', 'smaller', css_length
|
|
|
5590 |
],
|
|
|
5591 |
'font-size-adjust': ['none', css_number],
|
|
|
5592 |
'font-stretch': [
|
|
|
5593 |
'normal', 'wider', 'narrower', 'ultra-condensed',
|
|
|
5594 |
'extra-condensed', 'condensed', 'semi-condensed',
|
|
|
5595 |
'semi-expanded', 'expanded', 'extra-expanded'
|
|
|
5596 |
],
|
|
|
5597 |
'font-style': [
|
|
|
5598 |
'normal', 'italic', 'oblique'
|
|
|
5599 |
],
|
|
|
5600 |
'font-variant': [
|
|
|
5601 |
'normal', 'small-caps'
|
|
|
5602 |
],
|
|
|
5603 |
'font-weight': [
|
|
|
5604 |
'normal', 'bold', 'bolder', 'lighter', css_number
|
|
|
5605 |
],
|
|
|
5606 |
height: [css_length, 'auto'],
|
|
|
5607 |
left: [css_length, 'auto'],
|
|
|
5608 |
'letter-spacing': ['normal', css_length],
|
|
|
5609 |
'line-height': ['normal', css_line_height],
|
|
|
5610 |
'list-style': [
|
|
|
5611 |
true, 'list-style-image', 'list-style-position', 'list-style-type'
|
|
|
5612 |
],
|
|
|
5613 |
'list-style-image': ['none', css_url],
|
|
|
5614 |
'list-style-position': ['inside', 'outside'],
|
|
|
5615 |
'list-style-type': [
|
|
|
5616 |
'circle', 'disc', 'square', 'decimal', 'decimal-leading-zero',
|
|
|
5617 |
'lower-roman', 'upper-roman', 'lower-greek', 'lower-alpha',
|
|
|
5618 |
'lower-latin', 'upper-alpha', 'upper-latin', 'hebrew', 'katakana',
|
|
|
5619 |
'hiragana-iroha', 'katakana-oroha', 'none'
|
|
|
5620 |
],
|
|
|
5621 |
margin: [4, css_margin],
|
|
|
5622 |
'margin-bottom': css_margin,
|
|
|
5623 |
'margin-left': css_margin,
|
|
|
5624 |
'margin-right': css_margin,
|
|
|
5625 |
'margin-top': css_margin,
|
|
|
5626 |
'marker-offset': [css_length, 'auto'],
|
|
|
5627 |
'max-height': [css_length, 'none'],
|
|
|
5628 |
'max-width': [css_length, 'none'],
|
|
|
5629 |
'min-height': css_length,
|
|
|
5630 |
'min-width': css_length,
|
|
|
5631 |
opacity: css_number,
|
|
|
5632 |
outline: [true, 'outline-color', 'outline-style', 'outline-width'],
|
|
|
5633 |
'outline-color': ['invert', css_color],
|
|
|
5634 |
'outline-style': [
|
|
|
5635 |
'dashed', 'dotted', 'double', 'groove', 'inset', 'none',
|
|
|
5636 |
'outset', 'ridge', 'solid'
|
|
|
5637 |
],
|
|
|
5638 |
'outline-width': css_width,
|
|
|
5639 |
overflow: css_overflow,
|
|
|
5640 |
'overflow-x': css_overflow,
|
|
|
5641 |
'overflow-y': css_overflow,
|
|
|
5642 |
padding: [4, css_length],
|
|
|
5643 |
'padding-bottom': css_length,
|
|
|
5644 |
'padding-left': css_length,
|
|
|
5645 |
'padding-right': css_length,
|
|
|
5646 |
'padding-top': css_length,
|
|
|
5647 |
'page-break-after': css_break,
|
|
|
5648 |
'page-break-before': css_break,
|
|
|
5649 |
position: ['absolute', 'fixed', 'relative', 'static'],
|
|
|
5650 |
quotes: [8, css_string],
|
|
|
5651 |
right: [css_length, 'auto'],
|
|
|
5652 |
'table-layout': ['auto', 'fixed'],
|
|
|
5653 |
'text-align': ['center', 'justify', 'left', 'right'],
|
|
|
5654 |
'text-decoration': [
|
|
|
5655 |
'none', 'underline', 'overline', 'line-through', 'blink'
|
|
|
5656 |
],
|
|
|
5657 |
'text-indent': css_length,
|
|
|
5658 |
'text-shadow': ['none', 4, [css_color, css_length]],
|
|
|
5659 |
'text-transform': ['capitalize', 'uppercase', 'lowercase', 'none'],
|
|
|
5660 |
top: [css_length, 'auto'],
|
|
|
5661 |
'unicode-bidi': ['normal', 'embed', 'bidi-override'],
|
|
|
5662 |
'vertical-align': [
|
|
|
5663 |
'baseline', 'bottom', 'sub', 'super', 'top', 'text-top', 'middle',
|
|
|
5664 |
'text-bottom', css_length
|
|
|
5665 |
],
|
|
|
5666 |
visibility: ['visible', 'hidden', 'collapse'],
|
|
|
5667 |
'white-space': [
|
|
|
5668 |
'normal', 'nowrap', 'pre', 'pre-line', 'pre-wrap', 'inherit'
|
|
|
5669 |
],
|
|
|
5670 |
width: [css_length, 'auto'],
|
|
|
5671 |
'word-spacing': ['normal', css_length],
|
|
|
5672 |
'word-wrap': ['break-word', 'normal'],
|
|
|
5673 |
'z-index': ['auto', css_number]
|
|
|
5674 |
};
|
|
|
5675 |
|
|
|
5676 |
function style_attribute() {
|
|
|
5677 |
var v;
|
|
|
5678 |
while (next_token.id === '*' || next_token.id === '#' ||
|
|
|
5679 |
next_token.string === '_') {
|
|
|
5680 |
if (!option.css) {
|
|
|
5681 |
warn('unexpected_a');
|
|
|
5682 |
}
|
|
|
5683 |
advance();
|
|
|
5684 |
}
|
|
|
5685 |
if (next_token.id === '-') {
|
|
|
5686 |
if (!option.css) {
|
|
|
5687 |
warn('unexpected_a');
|
|
|
5688 |
}
|
|
|
5689 |
advance('-');
|
|
|
5690 |
if (!next_token.identifier) {
|
|
|
5691 |
warn('expected_nonstandard_style_attribute');
|
|
|
5692 |
}
|
|
|
5693 |
advance();
|
|
|
5694 |
return css_any;
|
|
|
5695 |
} else {
|
|
|
5696 |
if (!next_token.identifier) {
|
|
|
5697 |
warn('expected_style_attribute');
|
|
|
5698 |
} else {
|
|
|
5699 |
if (Object.prototype.hasOwnProperty.call(css_attribute_data,
|
|
|
5700 |
next_token.string)) {
|
|
|
5701 |
v = css_attribute_data[next_token.string];
|
|
|
5702 |
} else {
|
|
|
5703 |
v = css_any;
|
|
|
5704 |
if (!option.css) {
|
|
|
5705 |
warn('unrecognized_style_attribute_a');
|
|
|
5706 |
}
|
|
|
5707 |
}
|
|
|
5708 |
}
|
|
|
5709 |
advance();
|
|
|
5710 |
return v;
|
|
|
5711 |
}
|
|
|
5712 |
}
|
|
|
5713 |
|
|
|
5714 |
|
|
|
5715 |
function style_value(v) {
|
|
|
5716 |
|
|
|
5717 |
/*jslint confusion: true */
|
|
|
5718 |
|
|
|
5719 |
var i = 0,
|
|
|
5720 |
n,
|
|
|
5721 |
once,
|
|
|
5722 |
match,
|
|
|
5723 |
round,
|
|
|
5724 |
start = 0,
|
|
|
5725 |
vi;
|
|
|
5726 |
switch (typeof v) {
|
|
|
5727 |
case 'function':
|
|
|
5728 |
return v();
|
|
|
5729 |
case 'string':
|
|
|
5730 |
if (next_token.identifier && next_token.string === v) {
|
|
|
5731 |
advance();
|
|
|
5732 |
return true;
|
|
|
5733 |
}
|
|
|
5734 |
return false;
|
|
|
5735 |
}
|
|
|
5736 |
for (;;) {
|
|
|
5737 |
if (i >= v.length) {
|
|
|
5738 |
return false;
|
|
|
5739 |
}
|
|
|
5740 |
vi = v[i];
|
|
|
5741 |
i += 1;
|
|
|
5742 |
if (typeof vi === 'boolean') {
|
|
|
5743 |
break;
|
|
|
5744 |
} else if (typeof vi === 'number') {
|
|
|
5745 |
n = vi;
|
|
|
5746 |
vi = v[i];
|
|
|
5747 |
i += 1;
|
|
|
5748 |
} else {
|
|
|
5749 |
n = 1;
|
|
|
5750 |
}
|
|
|
5751 |
match = false;
|
|
|
5752 |
while (n > 0) {
|
|
|
5753 |
if (style_value(vi)) {
|
|
|
5754 |
match = true;
|
|
|
5755 |
n -= 1;
|
|
|
5756 |
} else {
|
|
|
5757 |
break;
|
|
|
5758 |
}
|
|
|
5759 |
}
|
|
|
5760 |
if (match) {
|
|
|
5761 |
return true;
|
|
|
5762 |
}
|
|
|
5763 |
}
|
|
|
5764 |
start = i;
|
|
|
5765 |
once = [];
|
|
|
5766 |
for (;;) {
|
|
|
5767 |
round = false;
|
|
|
5768 |
for (i = start; i < v.length; i += 1) {
|
|
|
5769 |
if (!once[i]) {
|
|
|
5770 |
if (style_value(css_attribute_data[v[i]])) {
|
|
|
5771 |
match = true;
|
|
|
5772 |
round = true;
|
|
|
5773 |
once[i] = true;
|
|
|
5774 |
break;
|
|
|
5775 |
}
|
|
|
5776 |
}
|
|
|
5777 |
}
|
|
|
5778 |
if (!round) {
|
|
|
5779 |
return match;
|
|
|
5780 |
}
|
|
|
5781 |
}
|
|
|
5782 |
}
|
|
|
5783 |
|
|
|
5784 |
function style_child() {
|
|
|
5785 |
if (next_token.id === '(number)') {
|
|
|
5786 |
advance();
|
|
|
5787 |
if (next_token.string === 'n' && next_token.identifier) {
|
|
|
5788 |
no_space_only();
|
|
|
5789 |
advance();
|
|
|
5790 |
if (next_token.id === '+') {
|
|
|
5791 |
no_space_only();
|
|
|
5792 |
advance('+');
|
|
|
5793 |
no_space_only();
|
|
|
5794 |
advance('(number)');
|
|
|
5795 |
}
|
|
|
5796 |
}
|
|
|
5797 |
return;
|
|
|
5798 |
} else {
|
|
|
5799 |
if (next_token.identifier &&
|
|
|
5800 |
(next_token.string === 'odd' || next_token.string === 'even')) {
|
|
|
5801 |
advance();
|
|
|
5802 |
return;
|
|
|
5803 |
}
|
|
|
5804 |
}
|
|
|
5805 |
warn('unexpected_a');
|
|
|
5806 |
}
|
|
|
5807 |
|
|
|
5808 |
function substyle() {
|
|
|
5809 |
var v;
|
|
|
5810 |
for (;;) {
|
|
|
5811 |
if (next_token.id === '}' || next_token.id === '(end)' ||
|
|
|
5812 |
(xquote && next_token.id === xquote)) {
|
|
|
5813 |
return;
|
|
|
5814 |
}
|
|
|
5815 |
v = style_attribute();
|
|
|
5816 |
advance(':');
|
|
|
5817 |
if (next_token.identifier && next_token.string === 'inherit') {
|
|
|
5818 |
advance();
|
|
|
5819 |
} else {
|
|
|
5820 |
if (!style_value(v)) {
|
|
|
5821 |
warn('unexpected_a');
|
|
|
5822 |
advance();
|
|
|
5823 |
}
|
|
|
5824 |
}
|
|
|
5825 |
if (next_token.id === '!') {
|
|
|
5826 |
advance('!');
|
|
|
5827 |
no_space_only();
|
|
|
5828 |
if (next_token.identifier && next_token.string === 'important') {
|
|
|
5829 |
advance();
|
|
|
5830 |
} else {
|
|
|
5831 |
warn('expected_a_b',
|
|
|
5832 |
next_token, 'important', artifact());
|
|
|
5833 |
}
|
|
|
5834 |
}
|
|
|
5835 |
if (next_token.id === '}' || next_token.id === xquote) {
|
|
|
5836 |
warn('expected_a_b', next_token, ';', artifact());
|
|
|
5837 |
} else {
|
|
|
5838 |
semicolon();
|
|
|
5839 |
}
|
|
|
5840 |
}
|
|
|
5841 |
}
|
|
|
5842 |
|
|
|
5843 |
function style_selector() {
|
|
|
5844 |
if (next_token.identifier) {
|
|
|
5845 |
if (!Object.prototype.hasOwnProperty.call(html_tag, option.cap
|
|
|
5846 |
? next_token.string.toLowerCase()
|
|
|
5847 |
: next_token.string)) {
|
|
|
5848 |
warn('expected_tagname_a');
|
|
|
5849 |
}
|
|
|
5850 |
advance();
|
|
|
5851 |
} else {
|
|
|
5852 |
switch (next_token.id) {
|
|
|
5853 |
case '>':
|
|
|
5854 |
case '+':
|
|
|
5855 |
advance();
|
|
|
5856 |
style_selector();
|
|
|
5857 |
break;
|
|
|
5858 |
case ':':
|
|
|
5859 |
advance(':');
|
|
|
5860 |
switch (next_token.string) {
|
|
|
5861 |
case 'active':
|
|
|
5862 |
case 'after':
|
|
|
5863 |
case 'before':
|
|
|
5864 |
case 'checked':
|
|
|
5865 |
case 'disabled':
|
|
|
5866 |
case 'empty':
|
|
|
5867 |
case 'enabled':
|
|
|
5868 |
case 'first-child':
|
|
|
5869 |
case 'first-letter':
|
|
|
5870 |
case 'first-line':
|
|
|
5871 |
case 'first-of-type':
|
|
|
5872 |
case 'focus':
|
|
|
5873 |
case 'hover':
|
|
|
5874 |
case 'last-child':
|
|
|
5875 |
case 'last-of-type':
|
|
|
5876 |
case 'link':
|
|
|
5877 |
case 'only-of-type':
|
|
|
5878 |
case 'root':
|
|
|
5879 |
case 'target':
|
|
|
5880 |
case 'visited':
|
|
|
5881 |
advance_identifier(next_token.string);
|
|
|
5882 |
break;
|
|
|
5883 |
case 'lang':
|
|
|
5884 |
advance_identifier('lang');
|
|
|
5885 |
advance('(');
|
|
|
5886 |
if (!next_token.identifier) {
|
|
|
5887 |
warn('expected_lang_a');
|
|
|
5888 |
}
|
|
|
5889 |
advance(')');
|
|
|
5890 |
break;
|
|
|
5891 |
case 'nth-child':
|
|
|
5892 |
case 'nth-last-child':
|
|
|
5893 |
case 'nth-last-of-type':
|
|
|
5894 |
case 'nth-of-type':
|
|
|
5895 |
advance_identifier(next_token.string);
|
|
|
5896 |
advance('(');
|
|
|
5897 |
style_child();
|
|
|
5898 |
advance(')');
|
|
|
5899 |
break;
|
|
|
5900 |
case 'not':
|
|
|
5901 |
advance_identifier('not');
|
|
|
5902 |
advance('(');
|
|
|
5903 |
if (next_token.id === ':' && peek(0).string === 'not') {
|
|
|
5904 |
warn('not');
|
|
|
5905 |
}
|
|
|
5906 |
style_selector();
|
|
|
5907 |
advance(')');
|
|
|
5908 |
break;
|
|
|
5909 |
default:
|
|
|
5910 |
warn('expected_pseudo_a');
|
|
|
5911 |
}
|
|
|
5912 |
break;
|
|
|
5913 |
case '#':
|
|
|
5914 |
advance('#');
|
|
|
5915 |
if (!next_token.identifier) {
|
|
|
5916 |
warn('expected_id_a');
|
|
|
5917 |
}
|
|
|
5918 |
advance();
|
|
|
5919 |
break;
|
|
|
5920 |
case '*':
|
|
|
5921 |
advance('*');
|
|
|
5922 |
break;
|
|
|
5923 |
case '.':
|
|
|
5924 |
advance('.');
|
|
|
5925 |
if (!next_token.identifier) {
|
|
|
5926 |
warn('expected_class_a');
|
|
|
5927 |
}
|
|
|
5928 |
advance();
|
|
|
5929 |
break;
|
|
|
5930 |
case '[':
|
|
|
5931 |
advance('[');
|
|
|
5932 |
if (!next_token.identifier) {
|
|
|
5933 |
warn('expected_attribute_a');
|
|
|
5934 |
}
|
|
|
5935 |
advance();
|
|
|
5936 |
if (next_token.id === '=' || next_token.string === '~=' ||
|
|
|
5937 |
next_token.string === '$=' ||
|
|
|
5938 |
next_token.string === '|=' ||
|
|
|
5939 |
next_token.id === '*=' ||
|
|
|
5940 |
next_token.id === '^=') {
|
|
|
5941 |
advance();
|
|
|
5942 |
if (next_token.id !== '(string)') {
|
|
|
5943 |
warn('expected_string_a');
|
|
|
5944 |
}
|
|
|
5945 |
advance();
|
|
|
5946 |
}
|
|
|
5947 |
advance(']');
|
|
|
5948 |
break;
|
|
|
5949 |
default:
|
|
|
5950 |
stop('expected_selector_a');
|
|
|
5951 |
}
|
|
|
5952 |
}
|
|
|
5953 |
}
|
|
|
5954 |
|
|
|
5955 |
function style_pattern() {
|
|
|
5956 |
if (next_token.id === '{') {
|
|
|
5957 |
warn('expected_style_pattern');
|
|
|
5958 |
}
|
|
|
5959 |
for (;;) {
|
|
|
5960 |
style_selector();
|
|
|
5961 |
if (next_token.id === '</' || next_token.id === '{' ||
|
|
|
5962 |
next_token.id === '}' || next_token.id === '(end)') {
|
|
|
5963 |
return '';
|
|
|
5964 |
}
|
|
|
5965 |
if (next_token.id === ',') {
|
|
|
5966 |
comma();
|
|
|
5967 |
}
|
|
|
5968 |
}
|
|
|
5969 |
}
|
|
|
5970 |
|
|
|
5971 |
function style_list() {
|
|
|
5972 |
while (next_token.id !== '}' && next_token.id !== '</' &&
|
|
|
5973 |
next_token.id !== '(end)') {
|
|
|
5974 |
style_pattern();
|
|
|
5975 |
xmode = 'styleproperty';
|
|
|
5976 |
if (next_token.id === ';') {
|
|
|
5977 |
semicolon();
|
|
|
5978 |
} else {
|
|
|
5979 |
advance('{');
|
|
|
5980 |
substyle();
|
|
|
5981 |
xmode = 'style';
|
|
|
5982 |
advance('}');
|
|
|
5983 |
}
|
|
|
5984 |
}
|
|
|
5985 |
}
|
|
|
5986 |
|
|
|
5987 |
function styles() {
|
|
|
5988 |
var i;
|
|
|
5989 |
while (next_token.id === '@') {
|
|
|
5990 |
i = peek();
|
|
|
5991 |
advance('@');
|
|
|
5992 |
switch (next_token.string) {
|
|
|
5993 |
case 'import':
|
|
|
5994 |
advance_identifier('import');
|
|
|
5995 |
if (!css_url()) {
|
|
|
5996 |
warn('expected_a_b',
|
|
|
5997 |
next_token, 'url', artifact());
|
|
|
5998 |
advance();
|
|
|
5999 |
}
|
|
|
6000 |
semicolon();
|
|
|
6001 |
break;
|
|
|
6002 |
case 'media':
|
|
|
6003 |
advance_identifier('media');
|
|
|
6004 |
for (;;) {
|
|
|
6005 |
if (!next_token.identifier || css_media[next_token.string] !== true) {
|
|
|
6006 |
stop('expected_media_a');
|
|
|
6007 |
}
|
|
|
6008 |
advance();
|
|
|
6009 |
if (next_token.id !== ',') {
|
|
|
6010 |
break;
|
|
|
6011 |
}
|
|
|
6012 |
comma();
|
|
|
6013 |
}
|
|
|
6014 |
advance('{');
|
|
|
6015 |
style_list();
|
|
|
6016 |
advance('}');
|
|
|
6017 |
break;
|
|
|
6018 |
case 'font-face':
|
|
|
6019 |
advance_identifier('font-face');
|
|
|
6020 |
advance('{');
|
|
|
6021 |
font_face();
|
|
|
6022 |
advance('}');
|
|
|
6023 |
break;
|
|
|
6024 |
default:
|
|
|
6025 |
stop('expected_at_a');
|
|
|
6026 |
}
|
|
|
6027 |
}
|
|
|
6028 |
style_list();
|
|
|
6029 |
}
|
|
|
6030 |
|
|
|
6031 |
|
|
|
6032 |
// Parse HTML
|
|
|
6033 |
|
|
|
6034 |
function do_begin(n) {
|
|
|
6035 |
if (n !== 'html' && !option.fragment) {
|
|
|
6036 |
if (n === 'div' && option.adsafe) {
|
|
|
6037 |
stop('adsafe_fragment');
|
|
|
6038 |
} else {
|
|
|
6039 |
stop('expected_a_b', token, 'html', n);
|
|
|
6040 |
}
|
|
|
6041 |
}
|
|
|
6042 |
if (option.adsafe) {
|
|
|
6043 |
if (n === 'html') {
|
|
|
6044 |
stop('adsafe_html', token);
|
|
|
6045 |
}
|
|
|
6046 |
if (option.fragment) {
|
|
|
6047 |
if (n !== 'div') {
|
|
|
6048 |
stop('adsafe_div', token);
|
|
|
6049 |
}
|
|
|
6050 |
} else {
|
|
|
6051 |
stop('adsafe_fragment', token);
|
|
|
6052 |
}
|
|
|
6053 |
}
|
|
|
6054 |
option.browser = true;
|
|
|
6055 |
}
|
|
|
6056 |
|
|
|
6057 |
function do_attribute(a, v) {
|
|
|
6058 |
var u, x;
|
|
|
6059 |
if (a === 'id') {
|
|
|
6060 |
u = typeof v === 'string' ? v.toUpperCase() : '';
|
|
|
6061 |
if (ids[u] === true) {
|
|
|
6062 |
warn('duplicate_a', next_token, v);
|
|
|
6063 |
}
|
|
|
6064 |
if (!/^[A-Za-z][A-Za-z0-9._:\-]*$/.test(v)) {
|
|
|
6065 |
warn('bad_id_a', next_token, v);
|
|
|
6066 |
} else if (option.adsafe) {
|
|
|
6067 |
if (adsafe_id) {
|
|
|
6068 |
if (v.slice(0, adsafe_id.length) !== adsafe_id) {
|
|
|
6069 |
warn('adsafe_prefix_a', next_token, adsafe_id);
|
|
|
6070 |
} else if (!/^[A-Z]+_[A-Z]+$/.test(v)) {
|
|
|
6071 |
warn('adsafe_bad_id');
|
|
|
6072 |
}
|
|
|
6073 |
} else {
|
|
|
6074 |
adsafe_id = v;
|
|
|
6075 |
if (!/^[A-Z]+_$/.test(v)) {
|
|
|
6076 |
warn('adsafe_bad_id');
|
|
|
6077 |
}
|
|
|
6078 |
}
|
|
|
6079 |
}
|
|
|
6080 |
x = v.search(dx);
|
|
|
6081 |
if (x >= 0) {
|
|
|
6082 |
warn('unexpected_char_a_b', token, v.charAt(x), a);
|
|
|
6083 |
}
|
|
|
6084 |
ids[u] = true;
|
|
|
6085 |
} else if (a === 'class' || a === 'type' || a === 'name') {
|
|
|
6086 |
x = v.search(qx);
|
|
|
6087 |
if (x >= 0) {
|
|
|
6088 |
warn('unexpected_char_a_b', token, v.charAt(x), a);
|
|
|
6089 |
}
|
|
|
6090 |
ids[u] = true;
|
|
|
6091 |
} else if (a === 'href' || a === 'background' ||
|
|
|
6092 |
a === 'content' || a === 'data' ||
|
|
|
6093 |
a.indexOf('src') >= 0 || a.indexOf('url') >= 0) {
|
|
|
6094 |
if (option.safe && ux.test(v)) {
|
|
|
6095 |
stop('bad_url_a', next_token, v);
|
|
|
6096 |
}
|
|
|
6097 |
urls.push(v);
|
|
|
6098 |
} else if (a === 'for') {
|
|
|
6099 |
if (option.adsafe) {
|
|
|
6100 |
if (adsafe_id) {
|
|
|
6101 |
if (v.slice(0, adsafe_id.length) !== adsafe_id) {
|
|
|
6102 |
warn('adsafe_prefix_a', next_token, adsafe_id);
|
|
|
6103 |
} else if (!/^[A-Z]+_[A-Z]+$/.test(v)) {
|
|
|
6104 |
warn('adsafe_bad_id');
|
|
|
6105 |
}
|
|
|
6106 |
} else {
|
|
|
6107 |
warn('adsafe_bad_id');
|
|
|
6108 |
}
|
|
|
6109 |
}
|
|
|
6110 |
} else if (a === 'name') {
|
|
|
6111 |
if (option.adsafe && v.indexOf('_') >= 0) {
|
|
|
6112 |
warn('adsafe_name_a', next_token, v);
|
|
|
6113 |
}
|
|
|
6114 |
}
|
|
|
6115 |
}
|
|
|
6116 |
|
|
|
6117 |
function do_tag(name, attribute) {
|
|
|
6118 |
var i, tag = html_tag[name], script, x;
|
|
|
6119 |
src = false;
|
|
|
6120 |
if (!tag) {
|
|
|
6121 |
stop(
|
|
|
6122 |
bundle.unrecognized_tag_a,
|
|
|
6123 |
next_token,
|
|
|
6124 |
name === name.toLowerCase()
|
|
|
6125 |
? name
|
|
|
6126 |
: name + ' (capitalization error)'
|
|
|
6127 |
);
|
|
|
6128 |
}
|
|
|
6129 |
if (stack.length > 0) {
|
|
|
6130 |
if (name === 'html') {
|
|
|
6131 |
stop('unexpected_a', token, name);
|
|
|
6132 |
}
|
|
|
6133 |
x = tag.parent;
|
|
|
6134 |
if (x) {
|
|
|
6135 |
if (x.indexOf(' ' + stack[stack.length - 1].name + ' ') < 0) {
|
|
|
6136 |
stop('tag_a_in_b', token, name, x);
|
|
|
6137 |
}
|
|
|
6138 |
} else if (!option.adsafe && !option.fragment) {
|
|
|
6139 |
i = stack.length;
|
|
|
6140 |
do {
|
|
|
6141 |
if (i <= 0) {
|
|
|
6142 |
stop('tag_a_in_b', token, name, 'body');
|
|
|
6143 |
}
|
|
|
6144 |
i -= 1;
|
|
|
6145 |
} while (stack[i].name !== 'body');
|
|
|
6146 |
}
|
|
|
6147 |
}
|
|
|
6148 |
switch (name) {
|
|
|
6149 |
case 'div':
|
|
|
6150 |
if (option.adsafe && stack.length === 1 && !adsafe_id) {
|
|
|
6151 |
warn('adsafe_missing_id');
|
|
|
6152 |
}
|
|
|
6153 |
break;
|
|
|
6154 |
case 'script':
|
|
|
6155 |
xmode = 'script';
|
|
|
6156 |
advance('>');
|
|
|
6157 |
if (attribute.lang) {
|
|
|
6158 |
warn('lang', token);
|
|
|
6159 |
}
|
|
|
6160 |
if (option.adsafe && stack.length !== 1) {
|
|
|
6161 |
warn('adsafe_placement', token);
|
|
|
6162 |
}
|
|
|
6163 |
if (attribute.src) {
|
|
|
6164 |
if (option.adsafe && (!adsafe_may || !approved[attribute.src])) {
|
|
|
6165 |
warn('adsafe_source', token);
|
|
|
6166 |
}
|
|
|
6167 |
if (attribute.type) {
|
|
|
6168 |
warn('type', token);
|
|
|
6169 |
}
|
|
|
6170 |
} else {
|
|
|
6171 |
step_in(next_token.from);
|
|
|
6172 |
edge();
|
|
|
6173 |
use_strict();
|
|
|
6174 |
adsafe_top = true;
|
|
|
6175 |
script = statements();
|
|
|
6176 |
|
|
|
6177 |
// JSLint is also the static analyzer for ADsafe. See www.ADsafe.org.
|
|
|
6178 |
|
|
|
6179 |
if (option.adsafe) {
|
|
|
6180 |
if (adsafe_went) {
|
|
|
6181 |
stop('adsafe_script', token);
|
|
|
6182 |
}
|
|
|
6183 |
if (script.length !== 1 ||
|
|
|
6184 |
aint(script[0], 'id', '(') ||
|
|
|
6185 |
aint(script[0].first, 'id', '.') ||
|
|
|
6186 |
aint(script[0].first.first, 'string', 'ADSAFE') ||
|
|
|
6187 |
aint(script[0].second[0], 'string', adsafe_id)) {
|
|
|
6188 |
stop('adsafe_id_go');
|
|
|
6189 |
}
|
|
|
6190 |
switch (script[0].first.second.string) {
|
|
|
6191 |
case 'id':
|
|
|
6192 |
if (adsafe_may || adsafe_went ||
|
|
|
6193 |
script[0].second.length !== 1) {
|
|
|
6194 |
stop('adsafe_id', next_token);
|
|
|
6195 |
}
|
|
|
6196 |
adsafe_may = true;
|
|
|
6197 |
break;
|
|
|
6198 |
case 'go':
|
|
|
6199 |
if (adsafe_went) {
|
|
|
6200 |
stop('adsafe_go');
|
|
|
6201 |
}
|
|
|
6202 |
if (script[0].second.length !== 2 ||
|
|
|
6203 |
aint(script[0].second[1], 'id', 'function') ||
|
|
|
6204 |
!script[0].second[1].first ||
|
|
|
6205 |
script[0].second[1].first.length !== 2 ||
|
|
|
6206 |
aint(script[0].second[1].first[0], 'string', 'dom') ||
|
|
|
6207 |
aint(script[0].second[1].first[1], 'string', 'lib')) {
|
|
|
6208 |
stop('adsafe_go', next_token);
|
|
|
6209 |
}
|
|
|
6210 |
adsafe_went = true;
|
|
|
6211 |
break;
|
|
|
6212 |
default:
|
|
|
6213 |
stop('adsafe_id_go');
|
|
|
6214 |
}
|
|
|
6215 |
}
|
|
|
6216 |
indent = null;
|
|
|
6217 |
}
|
|
|
6218 |
xmode = 'html';
|
|
|
6219 |
advance('</');
|
|
|
6220 |
advance_identifier('script');
|
|
|
6221 |
xmode = 'outer';
|
|
|
6222 |
break;
|
|
|
6223 |
case 'style':
|
|
|
6224 |
xmode = 'style';
|
|
|
6225 |
advance('>');
|
|
|
6226 |
styles();
|
|
|
6227 |
xmode = 'html';
|
|
|
6228 |
advance('</');
|
|
|
6229 |
advance_identifier('style');
|
|
|
6230 |
break;
|
|
|
6231 |
case 'input':
|
|
|
6232 |
switch (attribute.type) {
|
|
|
6233 |
case 'button':
|
|
|
6234 |
case 'checkbox':
|
|
|
6235 |
case 'radio':
|
|
|
6236 |
case 'reset':
|
|
|
6237 |
case 'submit':
|
|
|
6238 |
break;
|
|
|
6239 |
case 'file':
|
|
|
6240 |
case 'hidden':
|
|
|
6241 |
case 'image':
|
|
|
6242 |
case 'password':
|
|
|
6243 |
case 'text':
|
|
|
6244 |
if (option.adsafe && attribute.autocomplete !== 'off') {
|
|
|
6245 |
warn('adsafe_autocomplete');
|
|
|
6246 |
}
|
|
|
6247 |
break;
|
|
|
6248 |
default:
|
|
|
6249 |
warn('bad_type');
|
|
|
6250 |
}
|
|
|
6251 |
break;
|
|
|
6252 |
case 'applet':
|
|
|
6253 |
case 'body':
|
|
|
6254 |
case 'embed':
|
|
|
6255 |
case 'frame':
|
|
|
6256 |
case 'frameset':
|
|
|
6257 |
case 'head':
|
|
|
6258 |
case 'iframe':
|
|
|
6259 |
case 'noembed':
|
|
|
6260 |
case 'noframes':
|
|
|
6261 |
case 'object':
|
|
|
6262 |
case 'param':
|
|
|
6263 |
if (option.adsafe) {
|
|
|
6264 |
warn('adsafe_tag', next_token, name);
|
|
|
6265 |
}
|
|
|
6266 |
break;
|
|
|
6267 |
}
|
|
|
6268 |
}
|
|
|
6269 |
|
|
|
6270 |
|
|
|
6271 |
function closetag(name) {
|
|
|
6272 |
return '</' + name + '>';
|
|
|
6273 |
}
|
|
|
6274 |
|
|
|
6275 |
function html() {
|
|
|
6276 |
|
|
|
6277 |
/*jslint confusion: true */
|
|
|
6278 |
|
|
|
6279 |
var attribute, attributes, is_empty, name, old_white = option.white,
|
|
|
6280 |
quote, tag_name, tag, wmode;
|
|
|
6281 |
xmode = 'html';
|
|
|
6282 |
xquote = '';
|
|
|
6283 |
stack = null;
|
|
|
6284 |
for (;;) {
|
|
|
6285 |
switch (next_token.string) {
|
|
|
6286 |
case '<':
|
|
|
6287 |
xmode = 'html';
|
|
|
6288 |
advance('<');
|
|
|
6289 |
attributes = {};
|
|
|
6290 |
tag_name = next_token;
|
|
|
6291 |
name = tag_name.string;
|
|
|
6292 |
advance_identifier(name);
|
|
|
6293 |
if (option.cap) {
|
|
|
6294 |
name = name.toLowerCase();
|
|
|
6295 |
}
|
|
|
6296 |
tag_name.name = name;
|
|
|
6297 |
if (!stack) {
|
|
|
6298 |
stack = [];
|
|
|
6299 |
do_begin(name);
|
|
|
6300 |
}
|
|
|
6301 |
tag = html_tag[name];
|
|
|
6302 |
if (typeof tag !== 'object') {
|
|
|
6303 |
stop('unrecognized_tag_a', tag_name, name);
|
|
|
6304 |
}
|
|
|
6305 |
is_empty = tag.empty;
|
|
|
6306 |
tag_name.type = name;
|
|
|
6307 |
for (;;) {
|
|
|
6308 |
if (next_token.id === '/') {
|
|
|
6309 |
advance('/');
|
|
|
6310 |
if (next_token.id !== '>') {
|
|
|
6311 |
warn('expected_a_b', next_token, '>', artifact());
|
|
|
6312 |
}
|
|
|
6313 |
break;
|
|
|
6314 |
}
|
|
|
6315 |
if (next_token.id && next_token.id.charAt(0) === '>') {
|
|
|
6316 |
break;
|
|
|
6317 |
}
|
|
|
6318 |
if (!next_token.identifier) {
|
|
|
6319 |
if (next_token.id === '(end)' || next_token.id === '(error)') {
|
|
|
6320 |
warn('expected_a_b', next_token, '>', artifact());
|
|
|
6321 |
}
|
|
|
6322 |
warn('bad_name_a');
|
|
|
6323 |
}
|
|
|
6324 |
option.white = false;
|
|
|
6325 |
spaces();
|
|
|
6326 |
attribute = next_token.string;
|
|
|
6327 |
option.white = old_white;
|
|
|
6328 |
advance();
|
|
|
6329 |
if (!option.cap && attribute !== attribute.toLowerCase()) {
|
|
|
6330 |
warn('attribute_case_a', token);
|
|
|
6331 |
}
|
|
|
6332 |
attribute = attribute.toLowerCase();
|
|
|
6333 |
xquote = '';
|
|
|
6334 |
if (Object.prototype.hasOwnProperty.call(attributes, attribute)) {
|
|
|
6335 |
warn('duplicate_a', token, attribute);
|
|
|
6336 |
}
|
|
|
6337 |
if (attribute.slice(0, 2) === 'on') {
|
|
|
6338 |
if (!option.on) {
|
|
|
6339 |
warn('html_handlers');
|
|
|
6340 |
}
|
|
|
6341 |
xmode = 'scriptstring';
|
|
|
6342 |
advance('=');
|
|
|
6343 |
quote = next_token.id;
|
|
|
6344 |
if (quote !== '"' && quote !== '\'') {
|
|
|
6345 |
stop('expected_a_b', next_token, '"', artifact());
|
|
|
6346 |
}
|
|
|
6347 |
xquote = quote;
|
|
|
6348 |
wmode = option.white;
|
|
|
6349 |
option.white = true;
|
|
|
6350 |
advance(quote);
|
|
|
6351 |
use_strict();
|
|
|
6352 |
statements();
|
|
|
6353 |
option.white = wmode;
|
|
|
6354 |
if (next_token.id !== quote) {
|
|
|
6355 |
stop('expected_a_b', next_token, quote, artifact());
|
|
|
6356 |
}
|
|
|
6357 |
xmode = 'html';
|
|
|
6358 |
xquote = '';
|
|
|
6359 |
advance(quote);
|
|
|
6360 |
tag = false;
|
|
|
6361 |
} else if (attribute === 'style') {
|
|
|
6362 |
xmode = 'scriptstring';
|
|
|
6363 |
advance('=');
|
|
|
6364 |
quote = next_token.id;
|
|
|
6365 |
if (quote !== '"' && quote !== '\'') {
|
|
|
6366 |
stop('expected_a_b', next_token, '"', artifact());
|
|
|
6367 |
}
|
|
|
6368 |
xmode = 'styleproperty';
|
|
|
6369 |
xquote = quote;
|
|
|
6370 |
advance(quote);
|
|
|
6371 |
substyle();
|
|
|
6372 |
xmode = 'html';
|
|
|
6373 |
xquote = '';
|
|
|
6374 |
advance(quote);
|
|
|
6375 |
tag = false;
|
|
|
6376 |
} else {
|
|
|
6377 |
if (next_token.id === '=') {
|
|
|
6378 |
advance('=');
|
|
|
6379 |
tag = next_token.string;
|
|
|
6380 |
if (!next_token.identifier &&
|
|
|
6381 |
next_token.id !== '"' &&
|
|
|
6382 |
next_token.id !== '\'' &&
|
|
|
6383 |
next_token.id !== '(string)' &&
|
|
|
6384 |
next_token.id !== '(string)' &&
|
|
|
6385 |
next_token.id !== '(color)') {
|
|
|
6386 |
warn('expected_attribute_value_a', token, attribute);
|
|
|
6387 |
}
|
|
|
6388 |
advance();
|
|
|
6389 |
} else {
|
|
|
6390 |
tag = true;
|
|
|
6391 |
}
|
|
|
6392 |
}
|
|
|
6393 |
attributes[attribute] = tag;
|
|
|
6394 |
do_attribute(attribute, tag);
|
|
|
6395 |
}
|
|
|
6396 |
do_tag(name, attributes);
|
|
|
6397 |
if (!is_empty) {
|
|
|
6398 |
stack.push(tag_name);
|
|
|
6399 |
}
|
|
|
6400 |
xmode = 'outer';
|
|
|
6401 |
advance('>');
|
|
|
6402 |
break;
|
|
|
6403 |
case '</':
|
|
|
6404 |
xmode = 'html';
|
|
|
6405 |
advance('</');
|
|
|
6406 |
if (!next_token.identifier) {
|
|
|
6407 |
warn('bad_name_a');
|
|
|
6408 |
}
|
|
|
6409 |
name = next_token.string;
|
|
|
6410 |
if (option.cap) {
|
|
|
6411 |
name = name.toLowerCase();
|
|
|
6412 |
}
|
|
|
6413 |
advance();
|
|
|
6414 |
if (!stack) {
|
|
|
6415 |
stop('unexpected_a', next_token, closetag(name));
|
|
|
6416 |
}
|
|
|
6417 |
tag_name = stack.pop();
|
|
|
6418 |
if (!tag_name) {
|
|
|
6419 |
stop('unexpected_a', next_token, closetag(name));
|
|
|
6420 |
}
|
|
|
6421 |
if (tag_name.name !== name) {
|
|
|
6422 |
stop('expected_a_b',
|
|
|
6423 |
next_token, closetag(tag_name.name), closetag(name));
|
|
|
6424 |
}
|
|
|
6425 |
if (next_token.id !== '>') {
|
|
|
6426 |
stop('expected_a_b', next_token, '>', artifact());
|
|
|
6427 |
}
|
|
|
6428 |
xmode = 'outer';
|
|
|
6429 |
advance('>');
|
|
|
6430 |
break;
|
|
|
6431 |
case '<!':
|
|
|
6432 |
if (option.safe) {
|
|
|
6433 |
warn('adsafe_a');
|
|
|
6434 |
}
|
|
|
6435 |
xmode = 'html';
|
|
|
6436 |
for (;;) {
|
|
|
6437 |
advance();
|
|
|
6438 |
if (next_token.id === '>' || next_token.id === '(end)') {
|
|
|
6439 |
break;
|
|
|
6440 |
}
|
|
|
6441 |
if (next_token.string.indexOf('--') >= 0) {
|
|
|
6442 |
stop('unexpected_a', next_token, '--');
|
|
|
6443 |
}
|
|
|
6444 |
if (next_token.string.indexOf('<') >= 0) {
|
|
|
6445 |
stop('unexpected_a', next_token, '<');
|
|
|
6446 |
}
|
|
|
6447 |
if (next_token.string.indexOf('>') >= 0) {
|
|
|
6448 |
stop('unexpected_a', next_token, '>');
|
|
|
6449 |
}
|
|
|
6450 |
}
|
|
|
6451 |
xmode = 'outer';
|
|
|
6452 |
advance('>');
|
|
|
6453 |
break;
|
|
|
6454 |
case '(end)':
|
|
|
6455 |
return;
|
|
|
6456 |
default:
|
|
|
6457 |
if (next_token.id === '(end)') {
|
|
|
6458 |
stop('missing_a', next_token,
|
|
|
6459 |
'</' + stack[stack.length - 1].string + '>');
|
|
|
6460 |
} else {
|
|
|
6461 |
advance();
|
|
|
6462 |
}
|
|
|
6463 |
}
|
|
|
6464 |
if (stack && stack.length === 0 && (option.adsafe ||
|
|
|
6465 |
!option.fragment || next_token.id === '(end)')) {
|
|
|
6466 |
break;
|
|
|
6467 |
}
|
|
|
6468 |
}
|
|
|
6469 |
if (next_token.id !== '(end)') {
|
|
|
6470 |
stop('unexpected_a');
|
|
|
6471 |
}
|
|
|
6472 |
}
|
|
|
6473 |
|
|
|
6474 |
|
|
|
6475 |
// The actual JSLINT function itself.
|
|
|
6476 |
|
|
|
6477 |
itself = function JSLint(the_source, the_option) {
|
|
|
6478 |
|
|
|
6479 |
var i, predef, tree;
|
|
|
6480 |
JSLINT.errors = [];
|
|
|
6481 |
JSLINT.tree = '';
|
|
|
6482 |
begin = prev_token = token = next_token =
|
|
|
6483 |
Object.create(syntax['(begin)']);
|
|
|
6484 |
predefined = {};
|
|
|
6485 |
add_to_predefined(standard);
|
|
|
6486 |
property_type = Object.create(standard_property_type);
|
|
|
6487 |
if (the_option) {
|
|
|
6488 |
option = Object.create(the_option);
|
|
|
6489 |
predef = option.predef;
|
|
|
6490 |
if (predef) {
|
|
|
6491 |
if (Array.isArray(predef)) {
|
|
|
6492 |
for (i = 0; i < predef.length; i += 1) {
|
|
|
6493 |
predefined[predef[i]] = true;
|
|
|
6494 |
}
|
|
|
6495 |
} else if (typeof predef === 'object') {
|
|
|
6496 |
add_to_predefined(predef);
|
|
|
6497 |
}
|
|
|
6498 |
}
|
|
|
6499 |
do_safe();
|
|
|
6500 |
} else {
|
|
|
6501 |
option = {};
|
|
|
6502 |
}
|
|
|
6503 |
option.indent = +option.indent || 4;
|
|
|
6504 |
option.maxerr = +option.maxerr || 50;
|
|
|
6505 |
adsafe_id = '';
|
|
|
6506 |
adsafe_may = adsafe_top = adsafe_went = false;
|
|
|
6507 |
approved = {};
|
|
|
6508 |
if (option.approved) {
|
|
|
6509 |
for (i = 0; i < option.approved.length; i += 1) {
|
|
|
6510 |
approved[option.approved[i]] = option.approved[i];
|
|
|
6511 |
}
|
|
|
6512 |
} else {
|
|
|
6513 |
approved.test = 'test';
|
|
|
6514 |
}
|
|
|
6515 |
tab = '';
|
|
|
6516 |
for (i = 0; i < option.indent; i += 1) {
|
|
|
6517 |
tab += ' ';
|
|
|
6518 |
}
|
|
|
6519 |
global_scope = scope = {};
|
|
|
6520 |
global_funct = funct = {
|
|
|
6521 |
'(scope)': scope,
|
|
|
6522 |
'(breakage)': 0,
|
|
|
6523 |
'(loopage)': 0
|
|
|
6524 |
};
|
|
|
6525 |
functions = [funct];
|
|
|
6526 |
|
|
|
6527 |
comments_off = false;
|
|
|
6528 |
ids = {};
|
|
|
6529 |
in_block = false;
|
|
|
6530 |
indent = null;
|
|
|
6531 |
json_mode = false;
|
|
|
6532 |
lookahead = [];
|
|
|
6533 |
member = {};
|
|
|
6534 |
node_js = false;
|
|
|
6535 |
prereg = true;
|
|
|
6536 |
src = false;
|
|
|
6537 |
stack = null;
|
|
|
6538 |
strict_mode = false;
|
|
|
6539 |
urls = [];
|
|
|
6540 |
var_mode = null;
|
|
|
6541 |
warnings = 0;
|
|
|
6542 |
xmode = '';
|
|
|
6543 |
lex.init(the_source);
|
|
|
6544 |
|
|
|
6545 |
assume();
|
|
|
6546 |
|
|
|
6547 |
try {
|
|
|
6548 |
advance();
|
|
|
6549 |
if (next_token.id === '(number)') {
|
|
|
6550 |
stop('unexpected_a');
|
|
|
6551 |
} else if (next_token.string.charAt(0) === '<') {
|
|
|
6552 |
html();
|
|
|
6553 |
if (option.adsafe && !adsafe_went) {
|
|
|
6554 |
warn('adsafe_go', this);
|
|
|
6555 |
}
|
|
|
6556 |
} else {
|
|
|
6557 |
switch (next_token.id) {
|
|
|
6558 |
case '{':
|
|
|
6559 |
case '[':
|
|
|
6560 |
json_mode = true;
|
|
|
6561 |
json_value();
|
|
|
6562 |
break;
|
|
|
6563 |
case '@':
|
|
|
6564 |
case '*':
|
|
|
6565 |
case '#':
|
|
|
6566 |
case '.':
|
|
|
6567 |
case ':':
|
|
|
6568 |
xmode = 'style';
|
|
|
6569 |
advance();
|
|
|
6570 |
if (token.id !== '@' || !next_token.identifier ||
|
|
|
6571 |
next_token.string !== 'charset' || token.line !== 1 ||
|
|
|
6572 |
token.from !== 1) {
|
|
|
6573 |
stop('css');
|
|
|
6574 |
}
|
|
|
6575 |
advance();
|
|
|
6576 |
if (next_token.id !== '(string)' &&
|
|
|
6577 |
next_token.string !== 'UTF-8') {
|
|
|
6578 |
stop('css');
|
|
|
6579 |
}
|
|
|
6580 |
advance();
|
|
|
6581 |
semicolon();
|
|
|
6582 |
styles();
|
|
|
6583 |
break;
|
|
|
6584 |
|
|
|
6585 |
default:
|
|
|
6586 |
if (option.adsafe && option.fragment) {
|
|
|
6587 |
stop('expected_a_b',
|
|
|
6588 |
next_token, '<div>', artifact());
|
|
|
6589 |
}
|
|
|
6590 |
|
|
|
6591 |
// If the first token is a semicolon, ignore it. This is sometimes used when
|
|
|
6592 |
// files are intended to be appended to files that may be sloppy. A sloppy
|
|
|
6593 |
// file may be depending on semicolon insertion on its last line.
|
|
|
6594 |
|
|
|
6595 |
step_in(1);
|
|
|
6596 |
if (next_token.id === ';' && !node_js) {
|
|
|
6597 |
semicolon();
|
|
|
6598 |
}
|
|
|
6599 |
adsafe_top = true;
|
|
|
6600 |
tree = statements();
|
|
|
6601 |
begin.first = tree;
|
|
|
6602 |
JSLINT.tree = begin;
|
|
|
6603 |
// infer_types(tree);
|
|
|
6604 |
if (option.adsafe && (tree.length !== 1 ||
|
|
|
6605 |
aint(tree[0], 'id', '(') ||
|
|
|
6606 |
aint(tree[0].first, 'id', '.') ||
|
|
|
6607 |
aint(tree[0].first.first, 'string', 'ADSAFE') ||
|
|
|
6608 |
aint(tree[0].first.second, 'string', 'lib') ||
|
|
|
6609 |
tree[0].second.length !== 2 ||
|
|
|
6610 |
tree[0].second[0].id !== '(string)' ||
|
|
|
6611 |
aint(tree[0].second[1], 'id', 'function'))) {
|
|
|
6612 |
stop('adsafe_lib');
|
|
|
6613 |
}
|
|
|
6614 |
if (tree.disrupt) {
|
|
|
6615 |
warn('weird_program', prev_token);
|
|
|
6616 |
}
|
|
|
6617 |
}
|
|
|
6618 |
}
|
|
|
6619 |
indent = null;
|
|
|
6620 |
advance('(end)');
|
|
|
6621 |
} catch (e) {
|
|
|
6622 |
if (e) { // `~
|
|
|
6623 |
JSLINT.errors.push({
|
|
|
6624 |
reason : e.message,
|
|
|
6625 |
line : e.line || next_token.line,
|
|
|
6626 |
character : e.character || next_token.from
|
|
|
6627 |
}, null);
|
|
|
6628 |
}
|
|
|
6629 |
}
|
|
|
6630 |
return JSLINT.errors.length === 0;
|
|
|
6631 |
};
|
|
|
6632 |
|
|
|
6633 |
|
|
|
6634 |
// Data summary.
|
|
|
6635 |
|
|
|
6636 |
itself.data = function () {
|
|
|
6637 |
var data = {functions: []},
|
|
|
6638 |
function_data,
|
|
|
6639 |
globals,
|
|
|
6640 |
i,
|
|
|
6641 |
j,
|
|
|
6642 |
kind,
|
|
|
6643 |
members = [],
|
|
|
6644 |
name,
|
|
|
6645 |
the_function,
|
|
|
6646 |
undef = [],
|
|
|
6647 |
unused = [];
|
|
|
6648 |
if (itself.errors.length) {
|
|
|
6649 |
data.errors = itself.errors;
|
|
|
6650 |
}
|
|
|
6651 |
|
|
|
6652 |
if (json_mode) {
|
|
|
6653 |
data.json = true;
|
|
|
6654 |
}
|
|
|
6655 |
|
|
|
6656 |
if (urls.length > 0) {
|
|
|
6657 |
data.urls = urls;
|
|
|
6658 |
}
|
|
|
6659 |
|
|
|
6660 |
globals = Object.keys(global_scope).filter(function (value) {
|
|
|
6661 |
return value.charAt(0) !== '(' && typeof standard[value] !== 'boolean';
|
|
|
6662 |
});
|
|
|
6663 |
if (globals.length > 0) {
|
|
|
6664 |
data.globals = globals;
|
|
|
6665 |
}
|
|
|
6666 |
|
|
|
6667 |
for (i = 1; i < functions.length; i += 1) {
|
|
|
6668 |
the_function = functions[i];
|
|
|
6669 |
function_data = {};
|
|
|
6670 |
for (j = 0; j < functionicity.length; j += 1) {
|
|
|
6671 |
function_data[functionicity[j]] = [];
|
|
|
6672 |
}
|
|
|
6673 |
for (name in the_function) {
|
|
|
6674 |
if (Object.prototype.hasOwnProperty.call(the_function, name)) {
|
|
|
6675 |
if (name.charAt(0) !== '(') {
|
|
|
6676 |
kind = the_function[name];
|
|
|
6677 |
if (kind === 'unction' || kind === 'unparam') {
|
|
|
6678 |
kind = 'unused';
|
|
|
6679 |
}
|
|
|
6680 |
if (Array.isArray(function_data[kind])) {
|
|
|
6681 |
function_data[kind].push(name);
|
|
|
6682 |
if (kind === 'unused') {
|
|
|
6683 |
unused.push({
|
|
|
6684 |
name: name,
|
|
|
6685 |
line: the_function['(line)'],
|
|
|
6686 |
'function': the_function['(name)']
|
|
|
6687 |
});
|
|
|
6688 |
} else if (kind === 'undef') {
|
|
|
6689 |
undef.push({
|
|
|
6690 |
name: name,
|
|
|
6691 |
line: the_function['(line)'],
|
|
|
6692 |
'function': the_function['(name)']
|
|
|
6693 |
});
|
|
|
6694 |
}
|
|
|
6695 |
}
|
|
|
6696 |
}
|
|
|
6697 |
}
|
|
|
6698 |
}
|
|
|
6699 |
for (j = 0; j < functionicity.length; j += 1) {
|
|
|
6700 |
if (function_data[functionicity[j]].length === 0) {
|
|
|
6701 |
delete function_data[functionicity[j]];
|
|
|
6702 |
}
|
|
|
6703 |
}
|
|
|
6704 |
function_data.name = the_function['(name)'];
|
|
|
6705 |
function_data.params = the_function['(params)'];
|
|
|
6706 |
function_data.line = the_function['(line)'];
|
|
|
6707 |
function_data['(complexity)'] = the_function['(complexity)'];
|
|
|
6708 |
data.functions.push(function_data);
|
|
|
6709 |
}
|
|
|
6710 |
|
|
|
6711 |
if (unused.length > 0) {
|
|
|
6712 |
data.unused = unused;
|
|
|
6713 |
}
|
|
|
6714 |
if (undef.length > 0) {
|
|
|
6715 |
data['undefined'] = undef;
|
|
|
6716 |
}
|
|
|
6717 |
|
|
|
6718 |
members = [];
|
|
|
6719 |
for (name in member) {
|
|
|
6720 |
if (typeof member[name] === 'number') {
|
|
|
6721 |
data.member = member;
|
|
|
6722 |
break;
|
|
|
6723 |
}
|
|
|
6724 |
}
|
|
|
6725 |
|
|
|
6726 |
return data;
|
|
|
6727 |
};
|
|
|
6728 |
|
|
|
6729 |
|
|
|
6730 |
itself.report = function (errors_only) {
|
|
|
6731 |
var data = itself.data(), err, evidence, i, italics, j, key, keys, length,
|
|
|
6732 |
mem = '', name, names, output = [], snippets, the_function, type,
|
|
|
6733 |
warning;
|
|
|
6734 |
|
|
|
6735 |
function detail(h, value) {
|
|
|
6736 |
var comma_needed, singularity;
|
|
|
6737 |
if (Array.isArray(value)) {
|
|
|
6738 |
output.push('<div><i>' + h + '</i> ');
|
|
|
6739 |
value.sort().forEach(function (item) {
|
|
|
6740 |
if (item !== singularity) {
|
|
|
6741 |
singularity = item;
|
|
|
6742 |
output.push((comma_needed ? ', ' : '') + singularity);
|
|
|
6743 |
comma_needed = true;
|
|
|
6744 |
}
|
|
|
6745 |
});
|
|
|
6746 |
output.push('</div>');
|
|
|
6747 |
} else if (value) {
|
|
|
6748 |
output.push('<div><i>' + h + '</i> ' + value + '</div>');
|
|
|
6749 |
}
|
|
|
6750 |
}
|
|
|
6751 |
|
|
|
6752 |
if (data.errors || data.unused || data['undefined']) {
|
|
|
6753 |
err = true;
|
|
|
6754 |
output.push('<div id=errors><i>Error:</i>');
|
|
|
6755 |
if (data.errors) {
|
|
|
6756 |
for (i = 0; i < data.errors.length; i += 1) {
|
|
|
6757 |
warning = data.errors[i];
|
|
|
6758 |
if (warning) {
|
|
|
6759 |
evidence = warning.evidence || '';
|
|
|
6760 |
output.push('<p>Problem' + (isFinite(warning.line)
|
|
|
6761 |
? ' at line ' + String(warning.line) +
|
|
|
6762 |
' character ' + String(warning.character)
|
|
|
6763 |
: '') +
|
|
|
6764 |
': ' + warning.reason.entityify() +
|
|
|
6765 |
'</p><p class=evidence>' +
|
|
|
6766 |
(evidence && (evidence.length > 80
|
|
|
6767 |
? evidence.slice(0, 77) + '...'
|
|
|
6768 |
: evidence).entityify()) + '</p>');
|
|
|
6769 |
}
|
|
|
6770 |
}
|
|
|
6771 |
}
|
|
|
6772 |
|
|
|
6773 |
if (data['undefined']) {
|
|
|
6774 |
snippets = [];
|
|
|
6775 |
for (i = 0; i < data['undefined'].length; i += 1) {
|
|
|
6776 |
snippets[i] = '<code><u>' + data['undefined'][i].name + '</u></code> <i>' +
|
|
|
6777 |
String(data['undefined'][i].line) + ' </i> <small>' +
|
|
|
6778 |
data['undefined'][i]['function'] + '</small>';
|
|
|
6779 |
}
|
|
|
6780 |
output.push('<p><i>Undefined variable:</i> ' + snippets.join(', ') + '</p>');
|
|
|
6781 |
}
|
|
|
6782 |
if (data.unused) {
|
|
|
6783 |
snippets = [];
|
|
|
6784 |
for (i = 0; i < data.unused.length; i += 1) {
|
|
|
6785 |
snippets[i] = '<code><u>' + data.unused[i].name + '</u></code> <i>' +
|
|
|
6786 |
String(data.unused[i].line) + ' </i> <small>' +
|
|
|
6787 |
data.unused[i]['function'] + '</small>';
|
|
|
6788 |
}
|
|
|
6789 |
output.push('<p><i>Unused variable:</i> ' + snippets.join(', ') + '</p>');
|
|
|
6790 |
}
|
|
|
6791 |
if (data.json) {
|
|
|
6792 |
output.push('<p>JSON: bad.</p>');
|
|
|
6793 |
}
|
|
|
6794 |
output.push('</div>');
|
|
|
6795 |
}
|
|
|
6796 |
|
|
|
6797 |
if (!errors_only) {
|
|
|
6798 |
|
|
|
6799 |
output.push('<br><div id=functions>');
|
|
|
6800 |
|
|
|
6801 |
if (data.urls) {
|
|
|
6802 |
detail("URLs<br>", data.urls, '<br>');
|
|
|
6803 |
}
|
|
|
6804 |
|
|
|
6805 |
if (xmode === 'style') {
|
|
|
6806 |
output.push('<p>CSS.</p>');
|
|
|
6807 |
} else if (data.json && !err) {
|
|
|
6808 |
output.push('<p>JSON: good.</p>');
|
|
|
6809 |
} else if (data.globals) {
|
|
|
6810 |
output.push('<div><i>Global</i> ' +
|
|
|
6811 |
data.globals.sort().join(', ') + '</div>');
|
|
|
6812 |
} else {
|
|
|
6813 |
output.push('<div><i>No new global variables introduced.</i></div>');
|
|
|
6814 |
}
|
|
|
6815 |
|
|
|
6816 |
for (i = 0; i < data.functions.length; i += 1) {
|
|
|
6817 |
the_function = data.functions[i];
|
|
|
6818 |
names = [];
|
|
|
6819 |
if (the_function.params) {
|
|
|
6820 |
for (j = 0; j < the_function.params.length; j += 1) {
|
|
|
6821 |
names[j] = the_function.params[j].string;
|
|
|
6822 |
}
|
|
|
6823 |
}
|
|
|
6824 |
output.push('<br><div class=function><i>' +
|
|
|
6825 |
String(the_function.line) + '</i> ' +
|
|
|
6826 |
the_function.name.entityify() +
|
|
|
6827 |
'(' + names.join(', ') + ')</div>');
|
|
|
6828 |
detail('<big><b>Undefined</b></big>', the_function['undefined']);
|
|
|
6829 |
detail('<big><b>Unused</b></big>', the_function.unused);
|
|
|
6830 |
detail('Closure', the_function.closure);
|
|
|
6831 |
detail('Variable', the_function['var']);
|
|
|
6832 |
detail('Exception', the_function.exception);
|
|
|
6833 |
detail('Outer', the_function.outer);
|
|
|
6834 |
detail('Global', the_function.global);
|
|
|
6835 |
detail('Label', the_function.label);
|
|
|
6836 |
detail('Complexity', the_function['(complexity)']);
|
|
|
6837 |
}
|
|
|
6838 |
|
|
|
6839 |
if (data.member) {
|
|
|
6840 |
keys = Object.keys(data.member);
|
|
|
6841 |
if (keys.length) {
|
|
|
6842 |
keys = keys.sort();
|
|
|
6843 |
output.push('<br><pre id=properties>/*properties<br>');
|
|
|
6844 |
mem = ' ';
|
|
|
6845 |
italics = 0;
|
|
|
6846 |
j = 0;
|
|
|
6847 |
if (option.confusion) {
|
|
|
6848 |
for (i = 0; i < keys.length; i += 1) {
|
|
|
6849 |
key = keys[i];
|
|
|
6850 |
if (typeof standard_property_type[key] !== 'string') {
|
|
|
6851 |
name = ix.test(key)
|
|
|
6852 |
? key
|
|
|
6853 |
: '\'' + key.entityify().replace(nx, sanitize) + '\'';
|
|
|
6854 |
if (data.member[key] === 1) {
|
|
|
6855 |
name = '<i>' + name + '</i>';
|
|
|
6856 |
italics += 1;
|
|
|
6857 |
j = 1;
|
|
|
6858 |
}
|
|
|
6859 |
if (i < keys.length - 1) {
|
|
|
6860 |
name += ', ';
|
|
|
6861 |
}
|
|
|
6862 |
if (mem.length + name.length - (italics * 7) > 80) {
|
|
|
6863 |
output.push(mem + '<br>');
|
|
|
6864 |
mem = ' ';
|
|
|
6865 |
italics = j;
|
|
|
6866 |
}
|
|
|
6867 |
mem += name;
|
|
|
6868 |
j = 0;
|
|
|
6869 |
}
|
|
|
6870 |
}
|
|
|
6871 |
} else {
|
|
|
6872 |
for (i = 0; i < keys.length; i += 1) {
|
|
|
6873 |
key = keys[i];
|
|
|
6874 |
type = property_type[key];
|
|
|
6875 |
if (typeof type !== 'string') {
|
|
|
6876 |
type = '';
|
|
|
6877 |
}
|
|
|
6878 |
if (standard_property_type[key] !== type) {
|
|
|
6879 |
name = ix.test(key)
|
|
|
6880 |
? key
|
|
|
6881 |
: '\'' + key.entityify().replace(nx, sanitize) + '\'';
|
|
|
6882 |
length += name.length + 2;
|
|
|
6883 |
if (data.member[key] === 1) {
|
|
|
6884 |
name = '<i>' + name + '</i>';
|
|
|
6885 |
italics += 1;
|
|
|
6886 |
j = 1;
|
|
|
6887 |
}
|
|
|
6888 |
if (type) {
|
|
|
6889 |
name += ': ' + type;
|
|
|
6890 |
}
|
|
|
6891 |
if (i < keys.length - 1) {
|
|
|
6892 |
name += ', ';
|
|
|
6893 |
}
|
|
|
6894 |
if (mem.length + name.length - (italics * 7) > 80) {
|
|
|
6895 |
output.push(mem + '<br>');
|
|
|
6896 |
mem = ' ';
|
|
|
6897 |
italics = j;
|
|
|
6898 |
}
|
|
|
6899 |
mem += name;
|
|
|
6900 |
j = 0;
|
|
|
6901 |
}
|
|
|
6902 |
}
|
|
|
6903 |
}
|
|
|
6904 |
output.push(mem + '<br>*/</pre>');
|
|
|
6905 |
}
|
|
|
6906 |
output.push('</div>');
|
|
|
6907 |
}
|
|
|
6908 |
}
|
|
|
6909 |
return output.join('');
|
|
|
6910 |
};
|
|
|
6911 |
itself.jslint = itself;
|
|
|
6912 |
|
|
|
6913 |
itself.edition = '2011-10-17';
|
|
|
6914 |
|
|
|
6915 |
return itself;
|
|
|
6916 |
|
|
|
6917 |
}()); |