How to use BadURLToken method in Playwright Internal

Best JavaScript code snippet using playwright-internal

Run Playwright Internal automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

tokenizer.js

Source: tokenizer.js Github

copy
1(function (root, factory) {
2    // Universal Module Definition (UMD) to support AMD, CommonJS/Node.js,
3    // Rhino, and plain browser loading.
4    if (typeof define === 'function' && define.amd) {
5        define(['exports'], factory);
6    } else if (typeof exports !== 'undefined') {
7        factory(exports);
8    } else {
9        factory(root);
10    }
11}(this, function (exports) {
12
13var between = function (num, first, last) { return num >= first && num <= last; }
14function digit(code) { return between(code, 0x30,0x39); }
15function hexdigit(code) { return digit(code) || between(code, 0x41,0x46) || between(code, 0x61,0x66); }
16function uppercaseletter(code) { return between(code, 0x41,0x5a); }
17function lowercaseletter(code) { return between(code, 0x61,0x7a); }
18function letter(code) { return uppercaseletter(code) || lowercaseletter(code); }
19function nonascii(code) { return code >= 0xa0; }
20function namestartchar(code) { return letter(code) || nonascii(code) || code == 0x5f; }
21function namechar(code) { return namestartchar(code) || digit(code) || code == 0x2d; }
22function nonprintable(code) { return between(code, 0,8) || between(code, 0xe,0x1f) || between(code, 0x7f,0x9f); }
23function newline(code) { return code == 0xa || code == 0xc; }
24function whitespace(code) { return newline(code) || code == 9 || code == 0x20; }
25function badescape(code) { return newline(code) || isNaN(code); }
26
27// Note: I'm not yet acting smart enough to actually handle astral characters.
28var maximumallowedcodepoint = 0x10ffff;
29
30function tokenize(str, options) {
31	if(options == undefined) options = {transformFunctionWhitespace:false, scientificNotation:false};
32	var i = -1;
33	var tokens = [];
34	var state = "data";
35	var code;
36	var currtoken;
37
38	// Line number information.
39	var line = 0;
40	var column = 0;
41	// The only use of lastLineLength is in reconsume().
42	var lastLineLength = 0;
43	var incrLineno = function() {
44		line += 1;
45		lastLineLength = column;
46		column = 0;
47	};
48	var locStart = {line:line, column:column};
49
50	var next = function(num) { if(num === undefined) num = 1; return str.charCodeAt(i+num); };
51	var consume = function(num) {
52		if(num === undefined)
53			num = 1;
54		i += num;
55		code = str.charCodeAt(i);
56		if (newline(code)) incrLineno();
57		else column += num;
58		//console.log('Consume '+i+' '+String.fromCharCode(code) + ' 0x' + code.toString(16));
59		return true;
60	};
61	var reconsume = function() {
62		i -= 1;
63		if (newline(code)) {
64			line -= 1;
65			column = lastLineLength;
66		} else {
67			column -= 1;
68		}
69		locStart.line = line;
70		locStart.column = column;
71		return true;
72	};
73	var eof = function() { return i >= str.length; };
74	var donothing = function() {};
75	var emit = function(token) {
76		if(token) {
77			token.finish();
78		} else {
79			token = currtoken.finish();
80		}
81		if (options.loc === true) {
82			token.loc = {};
83			token.loc.start = {line:locStart.line, column:locStart.column};
84			locStart = {line: line, column: column};
85			token.loc.end = locStart;
86		}
87		tokens.push(token);
88		//console.log('Emitting ' + token);
89		currtoken = undefined;
90		return true;
91	};
92	var create = function(token) { currtoken = token; return true; };
93	var parseerror = function() { console.log("Parse error at index " + i + ", processing codepoint 0x" + code.toString(16) + " in state " + state + ".");return true; };
94	var catchfire = function(msg) { console.log("MAJOR SPEC ERROR: " + msg); return true;}
95	var switchto = function(newstate) {
96		state = newstate;
97		//console.log('Switching to ' + state);
98		return true;
99	};
100	var consumeEscape = function() {
101		// Assume the the current character is the \
102		consume();
103		if(hexdigit(code)) {
104			// Consume 1-6 hex digits
105			var digits = [];
106			for(var total = 0; total < 6; total++) {
107				if(hexdigit(code)) {
108					digits.push(code);
109					consume();
110				} else { break; }
111			}
112			var value = parseInt(digits.map(String.fromCharCode).join(''), 16);
113			if( value > maximumallowedcodepoint ) value = 0xfffd;
114			// If the current char is whitespace, cool, we'll just eat it.
115			// Otherwise, put it back.
116			if(!whitespace(code)) reconsume();
117			return value;
118		} else {
119			return code;
120		}
121	};
122
123	for(;;) {
124		if(i > str.length*2) return "I'm infinite-looping!";
125		consume();
126		switch(state) {
127		case "data":
128			if(whitespace(code)) {
129				emit(new WhitespaceToken);
130				while(whitespace(next())) consume();
131			}
132			else if(code == 0x22) switchto("double-quote-string");
133			else if(code == 0x23) switchto("hash");
134			else if(code == 0x27) switchto("single-quote-string");
135			else if(code == 0x28) emit(new OpenParenToken);
136			else if(code == 0x29) emit(new CloseParenToken);
137			else if(code == 0x2b) {
138				if(digit(next()) || (next() == 0x2e && digit(next(2)))) switchto("number") && reconsume();
139				else emit(new DelimToken(code));
140			}
141			else if(code == 0x2d) {
142				if(next(1) == 0x2d && next(2) == 0x3e) consume(2) && emit(new CDCToken);
143				else if(digit(next()) || (next(1) == 0x2e && digit(next(2)))) switchto("number") && reconsume();
144				else switchto('ident') && reconsume();
145			}
146			else if(code == 0x2e) {
147				if(digit(next())) switchto("number") && reconsume();
148				else emit(new DelimToken(code));
149			}
150			else if(code == 0x2f) {
151				if(next() == 0x2a) consume() && switchto("comment");
152				else emit(new DelimToken(code));
153			}
154			else if(code == 0x3a) emit(new ColonToken);
155			else if(code == 0x3b) emit(new SemicolonToken);
156			else if(code == 0x3c) {
157				if(next(1) == 0x21 && next(2) == 0x2d && next(3) == 0x2d) consume(3) && emit(new CDOToken);
158				else emit(new DelimToken(code));
159			}
160			else if(code == 0x40) switchto("at-keyword");
161			else if(code == 0x5b) emit(new OpenSquareToken);
162			else if(code == 0x5c) {
163				if(badescape(next())) parseerror() && emit(new DelimToken(code));
164				else switchto('ident') && reconsume();
165			}
166			else if(code == 0x5d) emit(new CloseSquareToken);
167			else if(code == 0x7b) emit(new OpenCurlyToken);
168			else if(code == 0x7d) emit(new CloseCurlyToken);
169			else if(digit(code)) switchto("number") && reconsume();
170			else if(code == 0x55 || code == 0x75) {
171				if(next(1) == 0x2b && hexdigit(next(2))) consume() && switchto("unicode-range");
172				else switchto('ident') && reconsume();
173			}
174			else if(namestartchar(code)) switchto('ident') && reconsume();
175			else if(eof()) { emit(new EOFToken); return tokens; }
176			else emit(new DelimToken(code));
177			break;
178
179		case "double-quote-string":
180			if(currtoken == undefined) create(new StringToken);
181
182			if(code == 0x22) emit() && switchto("data");
183			else if(eof()) parseerror() && emit() && switchto("data") && reconsume();
184			else if(newline(code)) parseerror() && emit(new BadStringToken) && switchto("data") && reconsume();
185			else if(code == 0x5c) {
186				if(badescape(next())) parseerror() && emit(new BadStringToken) && switchto("data");
187				else if(newline(next())) consume();
188				else currtoken.append(consumeEscape());
189			}
190			else currtoken.append(code);
191			break;
192
193		case "single-quote-string":
194			if(currtoken == undefined) create(new StringToken);
195
196			if(code == 0x27) emit() && switchto("data");
197			else if(eof()) parseerror() && emit() && switchto("data");
198			else if(newline(code)) parseerror() && emit(new BadStringToken) && switchto("data") && reconsume();
199			else if(code == 0x5c) {
200				if(badescape(next())) parseerror() && emit(new BadStringToken) && switchto("data");
201				else if(newline(next())) consume();
202				else currtoken.append(consumeEscape());
203			}
204			else currtoken.append(code);
205			break;
206
207		case "hash":
208			if(namechar(code)) create(new HashToken(code)) && switchto("hash-rest");
209			else if(code == 0x5c) {
210				if(badescape(next())) parseerror() && emit(new DelimToken(0x23)) && switchto("data") && reconsume();
211				else create(new HashToken(consumeEscape())) && switchto('hash-rest');
212			}
213			else emit(new DelimToken(0x23)) && switchto('data') && reconsume();
214			break;
215
216		case "hash-rest":
217			if(namechar(code)) currtoken.append(code);
218			else if(code == 0x5c) {
219				if(badescape(next())) parseerror() && emit() && switchto("data") && reconsume();
220				else currtoken.append(consumeEscape());
221			}
222			else emit() && switchto('data') && reconsume();
223			break;
224
225		case "comment":
226			if(code == 0x2a) {
227				if(next() == 0x2f) consume() && switchto('data');
228				else donothing();
229			}
230			else if(eof()) parseerror() && switchto('data') && reconsume();
231			else donothing();
232			break;
233
234		case "at-keyword":
235			if(code == 0x2d) {
236				if(namestartchar(next())) create(new AtKeywordToken(0x2d)) && switchto('at-keyword-rest');
237				else if(next(1) == 0x5c && !badescape(next(2))) create(new AtKeywordtoken(0x2d)) && switchto('at-keyword-rest');
238				else parseerror() && emit(new DelimToken(0x40)) && switchto('data') && reconsume();
239			}
240			else if(namestartchar(code)) create(new AtKeywordToken(code)) && switchto('at-keyword-rest');
241			else if(code == 0x5c) {
242				if(badescape(next())) parseerror() && emit(new DelimToken(0x23)) && switchto("data") && reconsume();
243				else create(new AtKeywordToken(consumeEscape())) && switchto('at-keyword-rest');
244			}
245			else emit(new DelimToken(0x40)) && switchto('data') && reconsume();
246			break;
247
248		case "at-keyword-rest":
249			if(namechar(code)) currtoken.append(code);
250			else if(code == 0x5c) {
251				if(badescape(next())) parseerror() && emit() && switchto("data") && reconsume();
252				else currtoken.append(consumeEscape());
253			}
254			else emit() && switchto('data') && reconsume();
255			break;
256
257		case "ident":
258			if(code == 0x2d) {
259				if(namestartchar(next())) create(new IdentifierToken(code)) && switchto('ident-rest');
260				else if(next(1) == 0x5c && !badescape(next(2))) create(new IdentifierToken(code)) && switchto('ident-rest');
261				else emit(new DelimToken(0x2d)) && switchto('data');
262			}
263			else if(namestartchar(code)) create(new IdentifierToken(code)) && switchto('ident-rest');
264			else if(code == 0x5c) {
265				if(badescape(next())) parseerror() && switchto("data") && reconsume();
266				else create(new IdentifierToken(consumeEscape())) && switchto('ident-rest');
267			}
268			else catchfire("Hit the generic 'else' clause in ident state.") && switchto('data') && reconsume();
269			break;
270
271		case "ident-rest":
272			if(namechar(code)) currtoken.append(code);
273			else if(code == 0x5c) {
274				if(badescape(next())) parseerror() && emit() && switchto("data") && reconsume();
275				else currtoken.append(consumeEscape());
276			}
277			else if(code == 0x28) {
278				if(currtoken.ASCIImatch('url')) switchto('url');
279				else emit(new FunctionToken(currtoken)) && switchto('data');
280			} 
281			else if(whitespace(code) && options.transformFunctionWhitespace) switchto('transform-function-whitespace') && reconsume();
282			else emit() && switchto('data') && reconsume();
283			break;
284
285		case "transform-function-whitespace":
286			if(whitespace(next())) donothing();
287			else if(code == 0x28) emit(new FunctionToken(currtoken)) && switchto('data');
288			else emit() && switchto('data') && reconsume();
289			break;
290
291		case "number":
292			create(new NumberToken());
293
294			if(code == 0x2d) {
295				if(digit(next())) consume() && currtoken.append([0x2d,code]) && switchto('number-rest');
296				else if(next(1) == 0x2e && digit(next(2))) consume(2) && currtoken.append([0x2d,0x2e,code]) && switchto('number-fraction');
297				else switchto('data') && reconsume();
298			}
299			else if(code == 0x2b) {
300				if(digit(next())) consume() && currtoken.append([0x2b,code]) && switchto('number-rest');
301				else if(next(1) == 0x2e && digit(next(2))) consume(2) && currtoken.append([0x2b,0x2e,code]) && switchto('number-fraction');
302				else switchto('data') && reconsume();
303			}
304			else if(digit(code)) currtoken.append(code) && switchto('number-rest');
305			else if(code == 0x2e) {
306				if(digit(next())) consume() && currtoken.append([0x2e,code]) && switchto('number-fraction');
307				else switchto('data') && reconsume();
308			}
309			else switchto('data') && reconsume();
310			break;
311
312		case "number-rest":
313			if(digit(code)) currtoken.append(code);
314			else if(code == 0x2e) {
315				if(digit(next())) consume() && currtoken.append([0x2e,code]) && switchto('number-fraction');
316				else emit() && switchto('data') && reconsume();
317			}
318			else if(code == 0x25) emit(new PercentageToken(currtoken)) && switchto('data');
319			else if(code == 0x45 || code == 0x65) {
320				if(digit(next())) consume() && currtoken.append([0x25,code]) && switchto('sci-notation');
321				else if((next(1) == 0x2b || next(1) == 0x2d) && digit(next(2))) currtoken.append([0x25,next(1),next(2)]) && consume(2) && switchto('sci-notation');
322				else create(new DimensionToken(currtoken,code)) && switchto('dimension');
323			}
324			else if(code == 0x2d) {
325				if(namestartchar(next())) consume() && create(new DimensionToken(currtoken,[0x2d,code])) && switchto('dimension');
326				else if(next(1) == 0x5c && badescape(next(2))) parseerror() && emit() && switchto('data') && reconsume();
327				else if(next(1) == 0x5c) consume() && create(new DimensionToken(currtoken, [0x2d,consumeEscape()])) && switchto('dimension');
328				else emit() && switchto('data') && reconsume();
329			}
330			else if(namestartchar(code)) create(new DimensionToken(currtoken, code)) && switchto('dimension');
331			else if(code == 0x5c) {
332				if(badescape(next)) parseerror() && emit() && switchto('data') && reconsume();
333				else create(new DimensionToken(currtoken,consumeEscape)) && switchto('dimension');
334			}
335			else emit() && switchto('data') && reconsume();
336			break;
337
338		case "number-fraction":
339			currtoken.type = "number";
340
341			if(digit(code)) currtoken.append(code);
342			else if(code == 0x25) emit(new PercentageToken(currtoken)) && switchto('data');
343			else if(code == 0x45 || code == 0x65) {
344				if(digit(next())) consume() && currtoken.append([0x65,code]) && switchto('sci-notation');
345				else if((next(1) == 0x2b || next(1) == 0x2d) && digit(next(2))) currtoken.append([0x65,next(1),next(2)]) && consume(2) && switchto('sci-notation');
346				else create(new DimensionToken(currtoken,code)) && switchto('dimension');
347			}
348			else if(code == 0x2d) {
349				if(namestartchar(next())) consume() && create(new DimensionToken(currtoken,[0x2d,code])) && switchto('dimension');
350				else if(next(1) == 0x5c && badescape(next(2))) parseerror() && emit() && switchto('data') && reconsume();
351				else if(next(1) == 0x5c) consume() && create(new DimensionToken(currtoken, [0x2d,consumeEscape()])) && switchto('dimension');
352				else emit() && switchto('data') && reconsume();
353			}
354			else if(namestartchar(code)) create(new DimensionToken(currtoken, code)) && switchto('dimension');
355			else if(code == 0x5c) {
356				if(badescape(next)) parseerror() && emit() && switchto('data') && reconsume();
357				else create(new DimensionToken(currtoken,consumeEscape())) && switchto('dimension');
358			}
359			else emit() && switchto('data') && reconsume();
360			break;
361
362		case "dimension":
363			if(namechar(code)) currtoken.append(code);
364			else if(code == 0x5c) {
365				if(badescape(next())) parseerror() && emit() && switchto('data') && reconsume();
366				else currtoken.append(consumeEscape());
367			}
368			else emit() && switchto('data') && reconsume();
369			break;
370
371		case "sci-notation":
372			currtoken.type = "number";
373
374			if(digit(code)) currtoken.append(code);
375			else emit() && switchto('data') && reconsume();
376			break;
377
378		case "url":
379			if(eof()) parseerror() && emit(new BadURLToken) && switchto('data');
380			else if(code == 0x22) switchto('url-double-quote');
381			else if(code == 0x27) switchto('url-single-quote');
382			else if(code == 0x29) emit(new URLToken) && switchto('data');
383			else if(whitespace(code)) donothing();
384			else switchto('url-unquoted') && reconsume();
385			break;
386
387		case "url-double-quote":
388			if(! (currtoken instanceof URLToken)) create(new URLToken);
389
390			if(eof()) parseerror() && emit(new BadURLToken) && switchto('data');
391			else if(code == 0x22) switchto('url-end');
392			else if(newline(code)) parseerror() && switchto('bad-url');
393			else if(code == 0x5c) {
394				if(newline(next())) consume();
395				else if(badescape(next())) parseerror() && emit(new BadURLToken) && switchto('data') && reconsume();
396				else currtoken.append(consumeEscape());
397			}
398			else currtoken.append(code);
399			break;
400
401		case "url-single-quote":
402			if(! (currtoken instanceof URLToken)) create(new URLToken);
403
404			if(eof()) parseerror() && emit(new BadURLToken) && switchto('data');
405			else if(code == 0x27) switchto('url-end');
406			else if(newline(code)) parseerror() && switchto('bad-url');
407			else if(code == 0x5c) {
408				if(newline(next())) consume();
409				else if(badescape(next())) parseerror() && emit(new BadURLToken) && switchto('data') && reconsume();
410				else currtoken.append(consumeEscape());
411			}
412			else currtoken.append(code);
413			break;
414
415		case "url-end":
416			if(eof()) parseerror() && emit(new BadURLToken) && switchto('data');
417			else if(whitespace(code)) donothing();
418			else if(code == 0x29) emit() && switchto('data');
419			else parseerror() && switchto('bad-url') && reconsume();
420			break;
421
422		case "url-unquoted":
423			if(! (currtoken instanceof URLToken)) create(new URLToken);
424
425			if(eof()) parseerror() && emit(new BadURLToken) && switchto('data');
426			else if(whitespace(code)) switchto('url-end');
427			else if(code == 0x29) emit() && switchto('data');
428			else if(code == 0x22 || code == 0x27 || code == 0x28 || nonprintable(code)) parseerror() && switchto('bad-url');
429			else if(code == 0x5c) {
430				if(badescape(next())) parseerror() && switchto('bad-url');
431				else currtoken.append(consumeEscape());
432			}
433			else currtoken.append(code);
434			break;
435
436		case "bad-url":
437			if(eof()) parseerror() && emit(new BadURLToken) && switchto('data');
438			else if(code == 0x29) emit(new BadURLToken) && switchto('data');
439			else if(code == 0x5c) {
440				if(badescape(next())) donothing();
441				else consumeEscape();
442			}
443			else donothing();
444			break;
445
446		case "unicode-range":
447			// We already know that the current code is a hexdigit.
448
449			var start = [code], end = [code];
450
451			for(var total = 1; total < 6; total++) {
452				if(hexdigit(next())) {
453					consume();
454					start.push(code);
455					end.push(code);
456				}
457				else break;
458			}
459
460			if(next() == 0x3f) {
461				for(;total < 6; total++) {
462					if(next() == 0x3f) {
463						consume();
464						start.push("0".charCodeAt(0));
465						end.push("f".charCodeAt(0));
466					}
467					else break;
468				}
469				emit(new UnicodeRangeToken(start,end)) && switchto('data');
470			}
471			else if(next(1) == 0x2d && hexdigit(next(2))) {
472				consume();
473				consume();
474				end = [code];
475				for(var total = 1; total < 6; total++) {
476					if(hexdigit(next())) {
477						consume();
478						end.push(code);
479					}
480					else break;
481				}
482				emit(new UnicodeRangeToken(start,end)) && switchto('data');
483			}
484			else emit(new UnicodeRangeToken(start)) && switchto('data');
485			break;
486
487		default:
488			catchfire("Unknown state '" + state + "'");
489		}
490	}
491}
492
493function stringFromCodeArray(arr) {
494	return String.fromCharCode.apply(null,arr.filter(function(e){return e;}));
495}
496
497function CSSParserToken(options) { return this; }
498CSSParserToken.prototype.finish = function() { return this; }
499CSSParserToken.prototype.toString = function() { return this.tokenType; }
500CSSParserToken.prototype.toJSON = function() { return this.toString(); }
501
502function BadStringToken() { return this; }
503BadStringToken.prototype = new CSSParserToken;
504BadStringToken.prototype.tokenType = "BADSTRING";
505
506function BadURLToken() { return this; }
507BadURLToken.prototype = new CSSParserToken;
508BadURLToken.prototype.tokenType = "BADURL";
509
510function WhitespaceToken() { return this; }
511WhitespaceToken.prototype = new CSSParserToken;
512WhitespaceToken.prototype.tokenType = "WHITESPACE";
513WhitespaceToken.prototype.toString = function() { return "WS"; }
514
515function CDOToken() { return this; }
516CDOToken.prototype = new CSSParserToken;
517CDOToken.prototype.tokenType = "CDO";
518
519function CDCToken() { return this; }
520CDCToken.prototype = new CSSParserToken;
521CDCToken.prototype.tokenType = "CDC";
522
523function ColonToken() { return this; }
524ColonToken.prototype = new CSSParserToken;
525ColonToken.prototype.tokenType = ":";
526
527function SemicolonToken() { return this; }
528SemicolonToken.prototype = new CSSParserToken;
529SemicolonToken.prototype.tokenType = ";";
530
531function OpenCurlyToken() { return this; }
532OpenCurlyToken.prototype = new CSSParserToken;
533OpenCurlyToken.prototype.tokenType = "{";
534
535function CloseCurlyToken() { return this; }
536CloseCurlyToken.prototype = new CSSParserToken;
537CloseCurlyToken.prototype.tokenType = "}";
538
539function OpenSquareToken() { return this; }
540OpenSquareToken.prototype = new CSSParserToken;
541OpenSquareToken.prototype.tokenType = "[";
542
543function CloseSquareToken() { return this; }
544CloseSquareToken.prototype = new CSSParserToken;
545CloseSquareToken.prototype.tokenType = "]";
546
547function OpenParenToken() { return this; }
548OpenParenToken.prototype = new CSSParserToken;
549OpenParenToken.prototype.tokenType = "(";
550
551function CloseParenToken() { return this; }
552CloseParenToken.prototype = new CSSParserToken;
553CloseParenToken.prototype.tokenType = ")";
554
555function EOFToken() { return this; }
556EOFToken.prototype = new CSSParserToken;
557EOFToken.prototype.tokenType = "EOF";
558
559function DelimToken(code) {
560	this.value = String.fromCharCode(code);
561	return this;
562}
563DelimToken.prototype = new CSSParserToken;
564DelimToken.prototype.tokenType = "DELIM";
565DelimToken.prototype.toString = function() { return "DELIM("+this.value+")"; }
566
567function StringValuedToken() { return this; }
568StringValuedToken.prototype = new CSSParserToken;
569StringValuedToken.prototype.append = function(val) {
570	if(val instanceof Array) {
571		for(var i = 0; i < val.length; i++) {
572			this.value.push(val[i]);
573		}
574	} else {
575		this.value.push(val);
576	}
577	return true;
578}
579StringValuedToken.prototype.finish = function() {
580	this.value = this.valueAsString();
581	return this;
582}
583StringValuedToken.prototype.ASCIImatch = function(str) {
584	return this.valueAsString().toLowerCase() == str.toLowerCase();
585}
586StringValuedToken.prototype.valueAsString = function() {
587	if(typeof this.value == 'string') return this.value;
588	return stringFromCodeArray(this.value);
589}
590StringValuedToken.prototype.valueAsCodes = function() {
591	if(typeof this.value == 'string') {
592		var ret = [];
593		for(var i = 0; i < this.value.length; i++)
594			ret.push(this.value.charCodeAt(i));
595		return ret;
596	}
597	return this.value.filter(function(e){return e;});
598}
599
600function IdentifierToken(val) {
601	this.value = [];
602	this.append(val);
603}
604IdentifierToken.prototype = new StringValuedToken;
605IdentifierToken.prototype.tokenType = "IDENT";
606IdentifierToken.prototype.toString = function() { return "IDENT("+this.value+")"; }
607
608function FunctionToken(val) {
609	// These are always constructed by passing an IdentifierToken
610	this.value = val.finish().value;
611}
612FunctionToken.prototype = new StringValuedToken;
613FunctionToken.prototype.tokenType = "FUNCTION";
614FunctionToken.prototype.toString = function() { return "FUNCTION("+this.value+")"; }
615
616function AtKeywordToken(val) {
617	this.value = [];
618	this.append(val);
619}
620AtKeywordToken.prototype = new StringValuedToken;
621AtKeywordToken.prototype.tokenType = "AT-KEYWORD";
622AtKeywordToken.prototype.toString = function() { return "AT("+this.value+")"; }
623
624function HashToken(val) {
625	this.value = [];
626	this.append(val);
627}
628HashToken.prototype = new StringValuedToken;
629HashToken.prototype.tokenType = "HASH";
630HashToken.prototype.toString = function() { return "HASH("+this.value+")"; }
631
632function StringToken(val) {
633	this.value = [];
634	this.append(val);
635}
636StringToken.prototype = new StringValuedToken;
637StringToken.prototype.tokenType = "STRING";
638StringToken.prototype.toString = function() { return "\""+this.value+"\""; }
639
640function URLToken(val) {
641	this.value = [];
642	this.append(val);
643}
644URLToken.prototype = new StringValuedToken;
645URLToken.prototype.tokenType = "URL";
646URLToken.prototype.toString = function() { return "URL("+this.value+")"; }
647
648function NumberToken(val) {
649	this.value = [];
650	this.append(val);
651	this.type = "integer";
652}
653NumberToken.prototype = new StringValuedToken;
654NumberToken.prototype.tokenType = "NUMBER";
655NumberToken.prototype.toString = function() {
656	if(this.type == "integer")
657		return "INT("+this.value+")";
658	return "NUMBER("+this.value+")";
659}
660NumberToken.prototype.finish = function() {
661	this.repr = this.valueAsString();
662	this.value = this.repr * 1;
663	if(Math.abs(this.value) % 1 != 0) this.type = "number";
664	return this;
665}
666
667function PercentageToken(val) {
668	// These are always created by passing a NumberToken as val
669	val.finish();
670	this.value = val.value;
671	this.repr = val.repr;
672}
673PercentageToken.prototype = new CSSParserToken;
674PercentageToken.prototype.tokenType = "PERCENTAGE";
675PercentageToken.prototype.toString = function() { return "PERCENTAGE("+this.value+")"; }
676
677function DimensionToken(val,unit) {
678	// These are always created by passing a NumberToken as the val
679	val.finish();
680	this.num = val.value;
681	this.unit = [];
682	this.repr = val.repr;
683	this.append(unit);
684}
685DimensionToken.prototype = new CSSParserToken;
686DimensionToken.prototype.tokenType = "DIMENSION";
687DimensionToken.prototype.toString = function() { return "DIM("+this.num+","+this.unit+")"; }
688DimensionToken.prototype.append = function(val) {
689	if(val instanceof Array) {
690		for(var i = 0; i < val.length; i++) {
691			this.unit.push(val[i]);
692		}
693	} else {
694		this.unit.push(val);
695	}
696	return true;
697}
698DimensionToken.prototype.finish = function() {
699	this.unit = stringFromCodeArray(this.unit);
700	this.repr += this.unit;
701	return this;
702}
703
704function UnicodeRangeToken(start,end) {
705	// start and end are array of char codes, completely finished
706	start = parseInt(stringFromCodeArray(start),16);
707	if(end === undefined) end = start + 1;
708	else end = parseInt(stringFromCodeArray(end),16);
709
710	if(start > maximumallowedcodepoint) end = start;
711	if(end < start) end = start;
712	if(end > maximumallowedcodepoint) end = maximumallowedcodepoint;
713
714	this.start = start;
715	this.end = end;
716	return this;
717}
718UnicodeRangeToken.prototype = new CSSParserToken;
719UnicodeRangeToken.prototype.tokenType = "UNICODE-RANGE";
720UnicodeRangeToken.prototype.toString = function() {
721	if(this.start+1 == this.end)
722		return "UNICODE-RANGE("+this.start.toString(16).toUpperCase()+")";
723	if(this.start < this.end)
724		return "UNICODE-RANGE("+this.start.toString(16).toUpperCase()+"-"+this.end.toString(16).toUpperCase()+")";
725	return "UNICODE-RANGE()";
726}
727UnicodeRangeToken.prototype.contains = function(code) {
728	return code >= this.start && code < this.end;
729}
730
731
732// Exportation.
733// TODO: also export the various tokens objects?
734exports.tokenize = tokenize;
735
736}));
737
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Run JavaScript Tests on LambdaTest Cloud Grid

Execute automation tests with Playwright Internal on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)