How to use badescape method in Playwright Internal

Best JavaScript code snippet using playwright-internal

vimtokenizer.js

Source:vimtokenizer.js Github

copy

Full Screen

...62 }63 function whitespace(code) {64 return newline(code) || code == 9 || code == 0x20;65 }66 function badescape(code) {67 return newline(code) || isNaN(code);68 }69 // Note: I'm not yet acting smart enough to actually handle astral characters.70 var maximumallowedcodepoint = 0x10ffff;71 function tokenize(str, options) {72 if (options == undefined)73 options = {74 transformFunctionWhitespace : false,75 scientificNotation : false76 };77 var i = -1;78 var tokens = [];79 var state = "data";80 var code;81 var currtoken;82 // Line number information.83 var line = 0;84 var column = 0;85 // The only use of lastLineLength is in reconsume().86 var lastLineLength = 0;87 var incrLineno = function() {88 line += 1;89 lastLineLength = column;90 column = 0;91 };92 var locStart = {93 line : line,94 column : column95 };96 var next = function(num) {97 if (num === undefined)98 num = 1;99 return str.charCodeAt(i + num);100 };101 var consume = function(num) {102 if (num === undefined)103 num = 1;104 i += num;105 code = str.charCodeAt(i);106 if (newline(code))107 incrLineno();108 else109 column += num;110 //console.log('Consume '+i+' '+String.fromCharCode(code) + ' 0x' + code.toString(16));111 return true;112 };113 var reconsume = function() {114 i -= 1;115 if (newline(code)) {116 line -= 1;117 column = lastLineLength;118 } else {119 column -= 1;120 }121 locStart.line = line;122 locStart.column = column;123 return true;124 };125 var eof = function() {126 return i >= str.length;127 };128 var donothing = function() {129 };130 var emit = function(token) {131 if (token) {132 token.finish();133 } else {134 token = currtoken.finish();135 }136 if (options.loc === true) {137 token.loc = {};138 token.loc.start = {139 line : locStart.line,140 column : locStart.column141 };142 locStart = {143 line : line,144 column : column145 };146 token.loc.end = locStart;147 }148 tokens.push(token);149 //console.log('Emitting ' + token);150 currtoken = undefined;151 return true;152 };153 var create = function(token) {154 currtoken = token;155 return true;156 };157 var parseerror = function() {158 console.log("Parse error at index " + i + ", processing codepoint 0x" + code.toString(16) + " in state " + state + ".");159 return true;160 };161 var catchfire = function(msg) {162 console.log("MAJOR SPEC ERROR: " + msg);163 return true;164 }165 var switchto = function(newstate) {166 state = newstate;167 //console.log('Switching to ' + state);168 return true;169 };170 var consumeEscape = function() {171 // Assume the the current character is the \172 consume();173 if (hexdigit(code)) {174 // Consume 1-6 hex digits175 var digits = [];176 for (var total = 0; total < 6; total++) {177 if (hexdigit(code)) {178 digits.push(code);179 consume();180 } else {181 break;182 }183 }184 var value = parseInt(digits.map(String.fromCharCode).join(''), 16);185 if (value > maximumallowedcodepoint)186 value = 0xfffd;187 // If the current char is whitespace, cool, we'll just eat it.188 // Otherwise, put it back.189 if (!whitespace(code))190 reconsume();191 return value;192 } else {193 return code;194 }195 };196 for (; ; ) {197 if (i > str.length * 2)198 return "I'm infinite-looping!";199 consume();200 switch(state) {201 case "data":202 if (whitespace(code)) {203 emit(new WhitespaceToken);204 while (whitespace(next()))consume();205 } else if (code == 0x22)206 switchto("double-quote-string");207 else if (code == 0x23)208 switchto("hash");209 else if (code == 0x27)210 switchto("single-quote-string");211 else if (code == 0x28)212 emit(new OpenParenToken);213 else if (code == 0x29)214 emit(new CloseParenToken);215 else if (code == 0x2b) {216 if (digit(next()) || (next() == 0x2e && digit(next(2))))217 switchto("number") && reconsume();218 else219 emit(new DelimToken(code));220 } else if (code == 0x2d) {221 if (next(1) == 0x2d && next(2) == 0x3e)222 consume(2) && emit(new CDCToken);223 else if (digit(next()) || (next(1) == 0x2e && digit(next(2))))224 switchto("number") && reconsume();225 else226 switchto('ident') && reconsume();227 } else if (code == 0x2e) {228 if (digit(next()))229 switchto("number") && reconsume();230 else231 emit(new DelimToken(code));232 } else if (code == 0x2f) {233 if (next() == 0x2a)234 consume() && switchto("comment");235 else236 emit(new DelimToken(code));237 } else if (code == 0x3a)238 emit(new ColonToken);239 else if (code == 0x3b)240 emit(new SemicolonToken);241 else if (code == 0x3c) {242 if (next(1) == 0x21 && next(2) == 0x2d && next(3) == 0x2d)243 consume(3) && emit(new CDOToken);244 else245 emit(new DelimToken(code));246 } else if (code == 0x40)247 switchto("at-keyword");248 else if (code == 0x5b)249 emit(new OpenSquareToken);250 else if (code == 0x5c) {251 if (badescape(next()))252 parseerror() && emit(new DelimToken(code));253 else254 switchto('ident') && reconsume();255 } else if (code == 0x5d)256 emit(new CloseSquareToken);257 else if (code == 0x7b)258 emit(new OpenCurlyToken);259 else if (code == 0x7d)260 emit(new CloseCurlyToken);261 else if (digit(code))262 switchto("number") && reconsume();263 else if (code == 0x55 || code == 0x75) {264 if (next(1) == 0x2b && hexdigit(next(2)))265 consume() && switchto("unicode-range");266 else267 switchto('ident') && reconsume();268 } else if (namestartchar(code))269 switchto('ident') && reconsume();270 else if (eof()) {271 emit(new EOFToken);272 return tokens;273 } else274 emit(new DelimToken(code));275 break;276 case "double-quote-string":277 if (currtoken == undefined)278 create(new StringToken);279 if (code == 0x22)280 emit() && switchto("data");281 else if (eof())282 parseerror() && emit() && switchto("data") && reconsume();283 else if (newline(code))284 parseerror() && emit(new BadStringToken) && switchto("data") && reconsume();285 else if (code == 0x5c) {286 if (badescape(next()))287 parseerror() && emit(new BadStringToken) && switchto("data");288 else if (newline(next()))289 consume();290 else291 currtoken.append(consumeEscape());292 } else293 currtoken.append(code);294 break;295 case "single-quote-string":296 if (currtoken == undefined)297 create(new StringToken);298 if (code == 0x27)299 emit() && switchto("data");300 else if (eof())301 parseerror() && emit() && switchto("data");302 else if (newline(code))303 parseerror() && emit(new BadStringToken) && switchto("data") && reconsume();304 else if (code == 0x5c) {305 if (badescape(next()))306 parseerror() && emit(new BadStringToken) && switchto("data");307 else if (newline(next()))308 consume();309 else310 currtoken.append(consumeEscape());311 } else312 currtoken.append(code);313 break;314 case "hash":315 if (namechar(code))316 create(new HashToken(code)) && switchto("hash-rest");317 else if (code == 0x5c) {318 if (badescape(next()))319 parseerror() && emit(new DelimToken(0x23)) && switchto("data") && reconsume();320 else321 create(new HashToken(consumeEscape())) && switchto('hash-rest');322 } else323 emit(new DelimToken(0x23)) && switchto('data') && reconsume();324 break;325 case "hash-rest":326 if (namechar(code))327 currtoken.append(code);328 else if (code == 0x5c) {329 if (badescape(next()))330 parseerror() && emit() && switchto("data") && reconsume();331 else332 currtoken.append(consumeEscape());333 } else334 emit() && switchto('data') && reconsume();335 break;336 case "comment":337 if (code == 0x2a) {338 if (next() == 0x2f)339 consume() && switchto('data');340 else341 donothing();342 } else if (eof())343 parseerror() && switchto('data') && reconsume();344 else345 donothing();346 break;347 case "at-keyword":348 if (code == 0x2d) {349 if (namestartchar(next()))350 create(new AtKeywordToken(0x2d)) && switchto('at-keyword-rest');351 else if (next(1) == 0x5c && !badescape(next(2)))352 create(new AtKeywordtoken(0x2d)) && switchto('at-keyword-rest');353 else354 parseerror() && emit(new DelimToken(0x40)) && switchto('data') && reconsume();355 } else if (namestartchar(code))356 create(new AtKeywordToken(code)) && switchto('at-keyword-rest');357 else if (code == 0x5c) {358 if (badescape(next()))359 parseerror() && emit(new DelimToken(0x23)) && switchto("data") && reconsume();360 else361 create(new AtKeywordToken(consumeEscape())) && switchto('at-keyword-rest');362 } else363 emit(new DelimToken(0x40)) && switchto('data') && reconsume();364 break;365 case "at-keyword-rest":366 if (namechar(code))367 currtoken.append(code);368 else if (code == 0x5c) {369 if (badescape(next()))370 parseerror() && emit() && switchto("data") && reconsume();371 else372 currtoken.append(consumeEscape());373 } else374 emit() && switchto('data') && reconsume();375 break;376 case "ident":377 if (code == 0x2d) {378 if (namestartchar(next()))379 create(new IdentifierToken(code)) && switchto('ident-rest');380 else if (next(1) == 0x5c && !badescape(next(2)))381 create(new IdentifierToken(code)) && switchto('ident-rest');382 else383 emit(new DelimToken(0x2d)) && switchto('data');384 } else if (namestartchar(code))385 create(new IdentifierToken(code)) && switchto('ident-rest');386 else if (code == 0x5c) {387 if (badescape(next()))388 parseerror() && switchto("data") && reconsume();389 else390 create(new IdentifierToken(consumeEscape())) && switchto('ident-rest');391 } else392 catchfire("Hit the generic 'else' clause in ident state.") && switchto('data') && reconsume();393 break;394 case "ident-rest":395 if (namechar(code))396 currtoken.append(code);397 else if (code == 0x5c) {398 if (badescape(next()))399 parseerror() && emit() && switchto("data") && reconsume();400 else401 currtoken.append(consumeEscape());402 } else if (code == 0x28) {403 if (currtoken.ASCIImatch('url'))404 switchto('url');405 else406 emit(new FunctionToken(currtoken)) && switchto('data');407 } else if (whitespace(code) && options.transformFunctionWhitespace)408 switchto('transform-function-whitespace') && reconsume();409 else410 emit() && switchto('data') && reconsume();411 break;412 case "transform-function-whitespace":413 if (whitespace(next()))414 donothing();415 else if (code == 0x28)416 emit(new FunctionToken(currtoken)) && switchto('data');417 else418 emit() && switchto('data') && reconsume();419 break;420 case "number":421 create(new NumberToken());422 if (code == 0x2d) {423 if (digit(next()))424 consume() && currtoken.append([0x2d, code]) && switchto('number-rest');425 else if (next(1) == 0x2e && digit(next(2)))426 consume(2) && currtoken.append([0x2d, 0x2e, code]) && switchto('number-fraction');427 else428 switchto('data') && reconsume();429 } else if (code == 0x2b) {430 if (digit(next()))431 consume() && currtoken.append([0x2b, code]) && switchto('number-rest');432 else if (next(1) == 0x2e && digit(next(2)))433 consume(2) && currtoken.append([0x2b, 0x2e, code]) && switchto('number-fraction');434 else435 switchto('data') && reconsume();436 } else if (digit(code))437 currtoken.append(code) && switchto('number-rest');438 else if (code == 0x2e) {439 if (digit(next()))440 consume() && currtoken.append([0x2e, code]) && switchto('number-fraction');441 else442 switchto('data') && reconsume();443 } else444 switchto('data') && reconsume();445 break;446 case "number-rest":447 if (digit(code))448 currtoken.append(code);449 else if (code == 0x2e) {450 if (digit(next()))451 consume() && currtoken.append([0x2e, code]) && switchto('number-fraction');452 else453 emit() && switchto('data') && reconsume();454 } else if (code == 0x25)455 emit(new PercentageToken(currtoken)) && switchto('data');456 else if (code == 0x45 || code == 0x65) {457 if (digit(next()))458 consume() && currtoken.append([0x25, code]) && switchto('sci-notation');459 else if ((next(1) == 0x2b || next(1) == 0x2d) && digit(next(2)))460 currtoken.append([0x25, next(1), next(2)]) && consume(2) && switchto('sci-notation');461 else462 create(new DimensionToken(currtoken, code)) && switchto('dimension');463 } else if (code == 0x2d) {464 if (namestartchar(next()))465 consume() && create(new DimensionToken(currtoken, [0x2d, code])) && switchto('dimension');466 else if (next(1) == 0x5c && badescape(next(2)))467 parseerror() && emit() && switchto('data') && reconsume();468 else if (next(1) == 0x5c)469 consume() && create(new DimensionToken(currtoken, [0x2d, consumeEscape()])) && switchto('dimension');470 else471 emit() && switchto('data') && reconsume();472 } else if (namestartchar(code))473 create(new DimensionToken(currtoken, code)) && switchto('dimension');474 else if (code == 0x5c) {475 if (badescape(next))476 parseerror() && emit() && switchto('data') && reconsume();477 else478 create(new DimensionToken(currtoken, consumeEscape)) && switchto('dimension');479 } else480 emit() && switchto('data') && reconsume();481 break;482 case "number-fraction":483 currtoken.type = "number";484 if (digit(code))485 currtoken.append(code);486 else if (code == 0x25)487 emit(new PercentageToken(currtoken)) && switchto('data');488 else if (code == 0x45 || code == 0x65) {489 if (digit(next()))490 consume() && currtoken.append([0x65, code]) && switchto('sci-notation');491 else if ((next(1) == 0x2b || next(1) == 0x2d) && digit(next(2)))492 currtoken.append([0x65, next(1), next(2)]) && consume(2) && switchto('sci-notation');493 else494 create(new DimensionToken(currtoken, code)) && switchto('dimension');495 } else if (code == 0x2d) {496 if (namestartchar(next()))497 consume() && create(new DimensionToken(currtoken, [0x2d, code])) && switchto('dimension');498 else if (next(1) == 0x5c && badescape(next(2)))499 parseerror() && emit() && switchto('data') && reconsume();500 else if (next(1) == 0x5c)501 consume() && create(new DimensionToken(currtoken, [0x2d, consumeEscape()])) && switchto('dimension');502 else503 emit() && switchto('data') && reconsume();504 } else if (namestartchar(code))505 create(new DimensionToken(currtoken, code)) && switchto('dimension');506 else if (code == 0x5c) {507 if (badescape(next))508 parseerror() && emit() && switchto('data') && reconsume();509 else510 create(new DimensionToken(currtoken, consumeEscape())) && switchto('dimension');511 } else512 emit() && switchto('data') && reconsume();513 break;514 case "dimension":515 if (namechar(code))516 currtoken.append(code);517 else if (code == 0x5c) {518 if (badescape(next()))519 parseerror() && emit() && switchto('data') && reconsume();520 else521 currtoken.append(consumeEscape());522 } else523 emit() && switchto('data') && reconsume();524 break;525 case "sci-notation":526 currtoken.type = "number";527 if (digit(code))528 currtoken.append(code);529 else530 emit() && switchto('data') && reconsume();531 break;532 case "url":533 if (eof())534 parseerror() && emit(new BadURLToken) && switchto('data');535 else if (code == 0x22)536 switchto('url-double-quote');537 else if (code == 0x27)538 switchto('url-single-quote');539 else if (code == 0x29)540 emit(new URLToken) && switchto('data');541 else if (whitespace(code))542 donothing();543 else544 switchto('url-unquoted') && reconsume();545 break;546 case "url-double-quote":547 if (!( currtoken instanceof URLToken))548 create(new URLToken);549 if (eof())550 parseerror() && emit(new BadURLToken) && switchto('data');551 else if (code == 0x22)552 switchto('url-end');553 else if (newline(code))554 parseerror() && switchto('bad-url');555 else if (code == 0x5c) {556 if (newline(next()))557 consume();558 else if (badescape(next()))559 parseerror() && emit(new BadURLToken) && switchto('data') && reconsume();560 else561 currtoken.append(consumeEscape());562 } else563 currtoken.append(code);564 break;565 case "url-single-quote":566 if (!( currtoken instanceof URLToken))567 create(new URLToken);568 if (eof())569 parseerror() && emit(new BadURLToken) && switchto('data');570 else if (code == 0x27)571 switchto('url-end');572 else if (newline(code))573 parseerror() && switchto('bad-url');574 else if (code == 0x5c) {575 if (newline(next()))576 consume();577 else if (badescape(next()))578 parseerror() && emit(new BadURLToken) && switchto('data') && reconsume();579 else580 currtoken.append(consumeEscape());581 } else582 currtoken.append(code);583 break;584 case "url-end":585 if (eof())586 parseerror() && emit(new BadURLToken) && switchto('data');587 else if (whitespace(code))588 donothing();589 else if (code == 0x29)590 emit() && switchto('data');591 else592 parseerror() && switchto('bad-url') && reconsume();593 break;594 case "url-unquoted":595 if (!( currtoken instanceof URLToken))596 create(new URLToken);597 if (eof())598 parseerror() && emit(new BadURLToken) && switchto('data');599 else if (whitespace(code))600 switchto('url-end');601 else if (code == 0x29)602 emit() && switchto('data');603 else if (code == 0x22 || code == 0x27 || code == 0x28 || nonprintable(code))604 parseerror() && switchto('bad-url');605 else if (code == 0x5c) {606 if (badescape(next()))607 parseerror() && switchto('bad-url');608 else609 currtoken.append(consumeEscape());610 } else611 currtoken.append(code);612 break;613 case "bad-url":614 if (eof())615 parseerror() && emit(new BadURLToken) && switchto('data');616 else if (code == 0x29)617 emit(new BadURLToken) && switchto('data');618 else if (code == 0x5c) {619 if (badescape(next()))620 donothing();621 else622 consumeEscape();623 } else624 donothing();625 break;626 case "unicode-range":627 // We already know that the current code is a hexdigit.628 var start = [code], end = [code];629 for (var total = 1; total < 6; total++) {630 if (hexdigit(next())) {631 consume();632 start.push(code);633 end.push(code);...

Full Screen

Full Screen

tokenizer.js

Source:tokenizer.js Github

copy

Full Screen

...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); }2627// Note: I'm not yet acting smart enough to actually handle astral characters.28var maximumallowedcodepoint = 0x10ffff;2930function 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;3738 // 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};4950 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, idx: locStart.idx};84 locStart = {line: line, column: column, idx: i};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 // mozmod: disable console.log94 var parseerror = function() { /* console.log("Parse error at index " + i + ", processing codepoint 0x" + code.toString(16) + " in state " + state + "."); */ return true; };95 // mozmod: disable console.log96 var catchfire = function(msg) { /* console.log("MAJOR SPEC ERROR: " + msg); */ return true;}97 var switchto = function(newstate) {98 state = newstate;99 //console.log('Switching to ' + state);100 return true;101 };102 var consumeEscape = function() {103 // Assume the the current character is the \104 consume();105 if(hexdigit(code)) {106 // Consume 1-6 hex digits107 var digits = [];108 for(var total = 0; total < 6; total++) {109 if(hexdigit(code)) {110 digits.push(code);111 consume();112 } else { break; }113 }114 var value = parseInt(digits.map(String.fromCharCode).join(''), 16);115 if( value > maximumallowedcodepoint ) value = 0xfffd;116 // If the current char is whitespace, cool, we'll just eat it.117 // Otherwise, put it back.118 if(!whitespace(code)) reconsume();119 return value;120 } else {121 return code;122 }123 };124125 for(;;) {126 if(i > str.length*2) return "I'm infinite-looping!";127 consume();128 switch(state) {129 case "data":130 if(whitespace(code)) {131 emit(new WhitespaceToken);132 while(whitespace(next())) consume();133 }134 else if(code == 0x22) switchto("double-quote-string");135 else if(code == 0x23) switchto("hash");136 else if(code == 0x27) switchto("single-quote-string");137 else if(code == 0x28) emit(new OpenParenToken);138 else if(code == 0x29) emit(new CloseParenToken);139 else if(code == 0x2b) {140 if(digit(next()) || (next() == 0x2e && digit(next(2)))) switchto("number") && reconsume();141 else emit(new DelimToken(code));142 }143 else if(code == 0x2d) {144 if(next(1) == 0x2d && next(2) == 0x3e) consume(2) && emit(new CDCToken);145 else if(digit(next()) || (next(1) == 0x2e && digit(next(2)))) switchto("number") && reconsume();146 else switchto('ident') && reconsume();147 }148 else if(code == 0x2e) {149 if(digit(next())) switchto("number") && reconsume();150 else emit(new DelimToken(code));151 }152 else if(code == 0x2f) {153 if(next() == 0x2a) consume() && switchto("comment");154 else emit(new DelimToken(code));155 }156 else if(code == 0x3a) emit(new ColonToken);157 else if(code == 0x3b) emit(new SemicolonToken);158 else if(code == 0x3c) {159 if(next(1) == 0x21 && next(2) == 0x2d && next(3) == 0x2d) consume(3) && emit(new CDOToken);160 else emit(new DelimToken(code));161 }162 else if(code == 0x40) switchto("at-keyword");163 else if(code == 0x5b) emit(new OpenSquareToken);164 else if(code == 0x5c) {165 if(badescape(next())) parseerror() && emit(new DelimToken(code));166 else switchto('ident') && reconsume();167 }168 else if(code == 0x5d) emit(new CloseSquareToken);169 else if(code == 0x7b) emit(new OpenCurlyToken);170 else if(code == 0x7d) emit(new CloseCurlyToken);171 else if(digit(code)) switchto("number") && reconsume();172 else if(code == 0x55 || code == 0x75) {173 if(next(1) == 0x2b && hexdigit(next(2))) consume() && switchto("unicode-range");174 else switchto('ident') && reconsume();175 }176 else if(namestartchar(code)) switchto('ident') && reconsume();177 else if(eof()) { emit(new EOFToken); return tokens; }178 else emit(new DelimToken(code));179 break;180181 case "double-quote-string":182 if(currtoken == undefined) create(new StringToken);183184 if(code == 0x22) emit() && switchto("data");185 else if(eof()) parseerror() && emit() && switchto("data") && reconsume();186 else if(newline(code)) parseerror() && emit(new BadStringToken) && switchto("data") && reconsume();187 else if(code == 0x5c) {188 if(badescape(next())) parseerror() && emit(new BadStringToken) && switchto("data");189 else if(newline(next())) consume();190 else currtoken.append(consumeEscape());191 }192 else currtoken.append(code);193 break;194195 case "single-quote-string":196 if(currtoken == undefined) create(new StringToken);197198 if(code == 0x27) emit() && switchto("data");199 else if(eof()) parseerror() && emit() && switchto("data");200 else if(newline(code)) parseerror() && emit(new BadStringToken) && switchto("data") && reconsume();201 else if(code == 0x5c) {202 if(badescape(next())) parseerror() && emit(new BadStringToken) && switchto("data");203 else if(newline(next())) consume();204 else currtoken.append(consumeEscape());205 }206 else currtoken.append(code);207 break;208209 case "hash":210 if(namechar(code)) create(new HashToken(code)) && switchto("hash-rest");211 else if(code == 0x5c) {212 if(badescape(next())) parseerror() && emit(new DelimToken(0x23)) && switchto("data") && reconsume();213 else create(new HashToken(consumeEscape())) && switchto('hash-rest');214 }215 else emit(new DelimToken(0x23)) && switchto('data') && reconsume();216 break;217218 case "hash-rest":219 if(namechar(code)) currtoken.append(code);220 else if(code == 0x5c) {221 if(badescape(next())) parseerror() && emit() && switchto("data") && reconsume();222 else currtoken.append(consumeEscape());223 }224 else emit() && switchto('data') && reconsume();225 break;226227 case "comment":228 if(code == 0x2a) {229 if(next() == 0x2f) consume() && switchto('data');230 else donothing();231 }232 else if(eof()) parseerror() && switchto('data') && reconsume();233 else donothing();234 break;235236 case "at-keyword":237 if(code == 0x2d) {238 if(namestartchar(next())) create(new AtKeywordToken(0x2d)) && switchto('at-keyword-rest');239 else if(next(1) == 0x5c && !badescape(next(2))) create(new AtKeywordtoken(0x2d)) && switchto('at-keyword-rest');240 else parseerror() && emit(new DelimToken(0x40)) && switchto('data') && reconsume();241 }242 else if(namestartchar(code)) create(new AtKeywordToken(code)) && switchto('at-keyword-rest');243 else if(code == 0x5c) {244 if(badescape(next())) parseerror() && emit(new DelimToken(0x23)) && switchto("data") && reconsume();245 else create(new AtKeywordToken(consumeEscape())) && switchto('at-keyword-rest');246 }247 else emit(new DelimToken(0x40)) && switchto('data') && reconsume();248 break;249250 case "at-keyword-rest":251 if(namechar(code)) currtoken.append(code);252 else if(code == 0x5c) {253 if(badescape(next())) parseerror() && emit() && switchto("data") && reconsume();254 else currtoken.append(consumeEscape());255 }256 else emit() && switchto('data') && reconsume();257 break;258259 case "ident":260 if(code == 0x2d) {261 if(namestartchar(next())) create(new IdentifierToken(code)) && switchto('ident-rest');262 else if(next(1) == 0x5c && !badescape(next(2))) create(new IdentifierToken(code)) && switchto('ident-rest');263 else emit(new DelimToken(0x2d)) && switchto('data');264 }265 else if(namestartchar(code)) create(new IdentifierToken(code)) && switchto('ident-rest');266 else if(code == 0x5c) {267 if(badescape(next())) parseerror() && switchto("data") && reconsume();268 else create(new IdentifierToken(consumeEscape())) && switchto('ident-rest');269 }270 else catchfire("Hit the generic 'else' clause in ident state.") && switchto('data') && reconsume();271 break;272273 case "ident-rest":274 if(namechar(code)) currtoken.append(code);275 else if(code == 0x5c) {276 if(badescape(next())) parseerror() && emit() && switchto("data") && reconsume();277 else currtoken.append(consumeEscape());278 }279 else if(code == 0x28) {280 if(currtoken.ASCIImatch('url')) switchto('url');281 else emit(new FunctionToken(currtoken)) && switchto('data');282 }283 else if(whitespace(code) && options.transformFunctionWhitespace) switchto('transform-function-whitespace') && reconsume();284 else emit() && switchto('data') && reconsume();285 break;286287 case "transform-function-whitespace":288 if(whitespace(next())) donothing();289 else if(code == 0x28) emit(new FunctionToken(currtoken)) && switchto('data');290 else emit() && switchto('data') && reconsume();291 break;292293 case "number":294 create(new NumberToken());295296 if(code == 0x2d) {297 if(digit(next())) consume() && currtoken.append([0x2d,code]) && switchto('number-rest');298 else if(next(1) == 0x2e && digit(next(2))) consume(2) && currtoken.append([0x2d,0x2e,code]) && switchto('number-fraction');299 else switchto('data') && reconsume();300 }301 else if(code == 0x2b) {302 if(digit(next())) consume() && currtoken.append([0x2b,code]) && switchto('number-rest');303 else if(next(1) == 0x2e && digit(next(2))) consume(2) && currtoken.append([0x2b,0x2e,code]) && switchto('number-fraction');304 else switchto('data') && reconsume();305 }306 else if(digit(code)) currtoken.append(code) && switchto('number-rest');307 else if(code == 0x2e) {308 if(digit(next())) consume() && currtoken.append([0x2e,code]) && switchto('number-fraction');309 else switchto('data') && reconsume();310 }311 else switchto('data') && reconsume();312 break;313314 case "number-rest":315 if(digit(code)) currtoken.append(code);316 else if(code == 0x2e) {317 if(digit(next())) consume() && currtoken.append([0x2e,code]) && switchto('number-fraction');318 else emit() && switchto('data') && reconsume();319 }320 else if(code == 0x25) emit(new PercentageToken(currtoken)) && switchto('data');321 else if(code == 0x45 || code == 0x65) {322 if(digit(next())) consume() && currtoken.append([0x25,code]) && switchto('sci-notation');323 else if((next(1) == 0x2b || next(1) == 0x2d) && digit(next(2))) currtoken.append([0x25,next(1),next(2)]) && consume(2) && switchto('sci-notation');324 else create(new DimensionToken(currtoken,code)) && switchto('dimension');325 }326 else if(code == 0x2d) {327 if(namestartchar(next())) consume() && create(new DimensionToken(currtoken,[0x2d,code])) && switchto('dimension');328 else if(next(1) == 0x5c && badescape(next(2))) parseerror() && emit() && switchto('data') && reconsume();329 else if(next(1) == 0x5c) consume() && create(new DimensionToken(currtoken, [0x2d,consumeEscape()])) && switchto('dimension');330 else emit() && switchto('data') && reconsume();331 }332 else if(namestartchar(code)) create(new DimensionToken(currtoken, code)) && switchto('dimension');333 else if(code == 0x5c) {334 if(badescape(next)) parseerror() && emit() && switchto('data') && reconsume();335 else create(new DimensionToken(currtoken,consumeEscape)) && switchto('dimension');336 }337 else emit() && switchto('data') && reconsume();338 break;339340 case "number-fraction":341 currtoken.type = "number";342343 if(digit(code)) currtoken.append(code);344 else if(code == 0x25) emit(new PercentageToken(currtoken)) && switchto('data');345 else if(code == 0x45 || code == 0x65) {346 if(digit(next())) consume() && currtoken.append([0x65,code]) && switchto('sci-notation');347 else if((next(1) == 0x2b || next(1) == 0x2d) && digit(next(2))) currtoken.append([0x65,next(1),next(2)]) && consume(2) && switchto('sci-notation');348 else create(new DimensionToken(currtoken,code)) && switchto('dimension');349 }350 else if(code == 0x2d) {351 if(namestartchar(next())) consume() && create(new DimensionToken(currtoken,[0x2d,code])) && switchto('dimension');352 else if(next(1) == 0x5c && badescape(next(2))) parseerror() && emit() && switchto('data') && reconsume();353 else if(next(1) == 0x5c) consume() && create(new DimensionToken(currtoken, [0x2d,consumeEscape()])) && switchto('dimension');354 else emit() && switchto('data') && reconsume();355 }356 else if(namestartchar(code)) create(new DimensionToken(currtoken, code)) && switchto('dimension');357 else if(code == 0x5c) {358 if(badescape(next)) parseerror() && emit() && switchto('data') && reconsume();359 else create(new DimensionToken(currtoken,consumeEscape())) && switchto('dimension');360 }361 else emit() && switchto('data') && reconsume();362 break;363364 case "dimension":365 if(namechar(code)) currtoken.append(code);366 else if(code == 0x5c) {367 if(badescape(next())) parseerror() && emit() && switchto('data') && reconsume();368 else currtoken.append(consumeEscape());369 }370 else emit() && switchto('data') && reconsume();371 break;372373 case "sci-notation":374 currtoken.type = "number";375376 if(digit(code)) currtoken.append(code);377 else emit() && switchto('data') && reconsume();378 break;379380 case "url":381 if(eof()) parseerror() && emit(new BadURLToken) && switchto('data');382 else if(code == 0x22) switchto('url-double-quote');383 else if(code == 0x27) switchto('url-single-quote');384 else if(code == 0x29) emit(new URLToken) && switchto('data');385 else if(whitespace(code)) donothing();386 else switchto('url-unquoted') && reconsume();387 break;388389 case "url-double-quote":390 if(! (currtoken instanceof URLToken)) create(new URLToken);391392 if(eof()) parseerror() && emit(new BadURLToken) && switchto('data');393 else if(code == 0x22) switchto('url-end');394 else if(newline(code)) parseerror() && switchto('bad-url');395 else if(code == 0x5c) {396 if(newline(next())) consume();397 else if(badescape(next())) parseerror() && emit(new BadURLToken) && switchto('data') && reconsume();398 else currtoken.append(consumeEscape());399 }400 else currtoken.append(code);401 break;402403 case "url-single-quote":404 if(! (currtoken instanceof URLToken)) create(new URLToken);405406 if(eof()) parseerror() && emit(new BadURLToken) && switchto('data');407 else if(code == 0x27) switchto('url-end');408 else if(newline(code)) parseerror() && switchto('bad-url');409 else if(code == 0x5c) {410 if(newline(next())) consume();411 else if(badescape(next())) parseerror() && emit(new BadURLToken) && switchto('data') && reconsume();412 else currtoken.append(consumeEscape());413 }414 else currtoken.append(code);415 break;416417 case "url-end":418 if(eof()) parseerror() && emit(new BadURLToken) && switchto('data');419 else if(whitespace(code)) donothing();420 else if(code == 0x29) emit() && switchto('data');421 else parseerror() && switchto('bad-url') && reconsume();422 break;423424 case "url-unquoted":425 if(! (currtoken instanceof URLToken)) create(new URLToken);426427 if(eof()) parseerror() && emit(new BadURLToken) && switchto('data');428 else if(whitespace(code)) switchto('url-end');429 else if(code == 0x29) emit() && switchto('data');430 else if(code == 0x22 || code == 0x27 || code == 0x28 || nonprintable(code)) parseerror() && switchto('bad-url');431 else if(code == 0x5c) {432 if(badescape(next())) parseerror() && switchto('bad-url');433 else currtoken.append(consumeEscape());434 }435 else currtoken.append(code);436 break;437438 case "bad-url":439 if(eof()) parseerror() && emit(new BadURLToken) && switchto('data');440 else if(code == 0x29) emit(new BadURLToken) && switchto('data');441 else if(code == 0x5c) {442 if(badescape(next())) donothing();443 else consumeEscape();444 }445 else donothing();446 break;447448 case "unicode-range":449 // We already know that the current code is a hexdigit.450451 var start = [code], end = [code];452453 for(var total = 1; total < 6; total++) {454 if(hexdigit(next())) {455 consume();456 start.push(code); ...

Full Screen

Full Screen

css-tokenizer.js

Source:css-tokenizer.js Github

copy

Full Screen

...34}35function whitespace(e) {36 return newline(e) || 9 == e || 32 == e;37}38function badescape(e) {39 return newline(e) || isNaN(e);40}41var maximumallowedcodepoint = 1114111;42export default function cssTokenizer(e, n) {43 null == n && (n = {44 transformFunctionWhitespace: !1,45 scientificNotation: !146 });47 for (var t, o, r = -1, i = [], a = 'data', s = 0, p = 0, u = 0, d = {48 line: s,49 column: p50 }, next = function(n) {51 return void 0 === n && (n = 1), e.charCodeAt(r + n);52 }, consume = function(n) {53 return void 0 === n && (n = 1), r += n, newline(t = e.charCodeAt(r)) ? (s += 1, 54 u = p, p = 0) : p += n, !0;55 }, reconsume = function() {56 return r -= 1, newline(t) ? (s -= 1, p = u) : p -= 1, d.line = s, d.column = p, 57 !0;58 }, eof = function() {59 return r >= e.length;60 }, emit = function(e) {61 return e ? e.finish() : e = o.finish(), !0 === n.loc && (e.loc = {}, e.loc.start = {62 line: d.line,63 column: d.column64 }, d = {65 line: s,66 column: p67 }, e.loc.end = d), i.push(e), o = void 0, !0;68 }, create = function(e) {69 return o = e, !0;70 }, parseerror = function() {71 return console.log('Parse error at index ' + r + ', processing codepoint 0x' + t.toString(16) + ' in state ' + a + '.'), 72 !0;73 }, catchfire = function(e) {74 return console.log('MAJOR SPEC ERROR: ' + e), !0;75 }, switchto = function(e) {76 return a = e, !0;77 }, consumeEscape = function() {78 if (consume(), hexdigit(t)) {79 for (var e = [], n = 0; n < 6 && hexdigit(t); n++) e.push(t), consume();80 var o = parseInt(e.map(String.fromCharCode).join(''), 16);81 return o > maximumallowedcodepoint && (o = 65533), whitespace(t) || reconsume(), 82 o;83 }84 return t;85 }; ;) {86 if (r > 2 * e.length) return 'I\'m infinite-looping!';87 switch (consume(), a) {88 case 'data':89 if (whitespace(t)) for (emit(new WhitespaceToken); whitespace(next()); ) consume(); else if (34 == t) switchto('double-quote-string'); else if (35 == t) switchto('hash'); else if (39 == t) switchto('single-quote-string'); else if (40 == t) emit(new OpenParenToken); else if (41 == t) emit(new CloseParenToken); else if (43 == t) digit(next()) || 46 == next() && digit(next(2)) ? switchto('number') && reconsume() : emit(new DelimToken(t)); else if (45 == t) 45 == next(1) && 62 == next(2) ? consume(2) && emit(new CDCToken) : digit(next()) || 46 == next(1) && digit(next(2)) ? switchto('number') && reconsume() : switchto('ident') && reconsume(); else if (46 == t) digit(next()) ? switchto('number') && reconsume() : emit(new DelimToken(t)); else if (47 == t) 42 == next() ? consume() && switchto('comment') : emit(new DelimToken(t)); else if (58 == t) emit(new ColonToken); else if (59 == t) emit(new SemicolonToken); else if (60 == t) 33 == next(1) && 45 == next(2) && 45 == next(3) ? consume(3) && emit(new CDOToken) : emit(new DelimToken(t)); else if (64 == t) switchto('at-keyword'); else if (91 == t) emit(new OpenSquareToken); else if (92 == t) badescape(next()) ? parseerror() && emit(new DelimToken(t)) : switchto('ident') && reconsume(); else if (93 == t) emit(new CloseSquareToken); else if (123 == t) emit(new OpenCurlyToken); else if (125 == t) emit(new CloseCurlyToken); else if (digit(t)) switchto('number') && reconsume(); else if (85 == t || 117 == t) 43 == next(1) && hexdigit(next(2)) ? consume() && switchto('unicode-range') : switchto('ident') && reconsume(); else if (namestartchar(t)) switchto('ident') && reconsume(); else {90 if (eof()) return emit(new EOFToken), i;91 emit(new DelimToken(t));92 }93 break;94 case 'double-quote-string':95 null == o && create(new StringToken), 34 == t ? emit() && switchto('data') : eof() ? parseerror() && emit() && switchto('data') && reconsume() : newline(t) ? parseerror() && emit(new BadStringToken) && switchto('data') && reconsume() : 92 == t ? badescape(next()) ? parseerror() && emit(new BadStringToken) && switchto('data') : newline(next()) ? consume() : o.append(consumeEscape()) : o.append(t);96 break;97 case 'single-quote-string':98 null == o && create(new StringToken), 39 == t ? emit() && switchto('data') : eof() ? parseerror() && emit() && switchto('data') : newline(t) ? parseerror() && emit(new BadStringToken) && switchto('data') && reconsume() : 92 == t ? badescape(next()) ? parseerror() && emit(new BadStringToken) && switchto('data') : newline(next()) ? consume() : o.append(consumeEscape()) : o.append(t);99 break;100 case 'hash':101 namechar(t) ? create(new HashToken(t)) && switchto('hash-rest') : 92 == t ? badescape(next()) ? parseerror() && emit(new DelimToken(35)) && switchto('data') && reconsume() : create(new HashToken(consumeEscape())) && switchto('hash-rest') : emit(new DelimToken(35)) && switchto('data') && reconsume();102 break;103 case 'hash-rest':104 namechar(t) ? o.append(t) : 92 == t ? badescape(next()) ? parseerror() && emit() && switchto('data') && reconsume() : o.append(consumeEscape()) : emit() && switchto('data') && reconsume();105 break;106 case 'comment':107 42 == t ? 47 == next() && consume() && switchto('data') : eof() && parseerror() && switchto('data') && reconsume();108 break;109 case 'at-keyword':110 45 == t ? namestartchar(next()) ? create(new AtKeywordToken(45)) && switchto('at-keyword-rest') : 92 != next(1) || badescape(next(2)) ? parseerror() && emit(new DelimToken(64)) && switchto('data') && reconsume() : create(new AtKeywordtoken(45)) && switchto('at-keyword-rest') : namestartchar(t) ? create(new AtKeywordToken(t)) && switchto('at-keyword-rest') : 92 == t ? badescape(next()) ? parseerror() && emit(new DelimToken(35)) && switchto('data') && reconsume() : create(new AtKeywordToken(consumeEscape())) && switchto('at-keyword-rest') : emit(new DelimToken(64)) && switchto('data') && reconsume();111 break;112 case 'at-keyword-rest':113 namechar(t) ? o.append(t) : 92 == t ? badescape(next()) ? parseerror() && emit() && switchto('data') && reconsume() : o.append(consumeEscape()) : emit() && switchto('data') && reconsume();114 break;115 case 'ident':116 45 == t ? namestartchar(next()) ? create(new IdentifierToken(t)) && switchto('ident-rest') : 92 != next(1) || badescape(next(2)) ? emit(new DelimToken(45)) && switchto('data') : create(new IdentifierToken(t)) && switchto('ident-rest') : namestartchar(t) ? create(new IdentifierToken(t)) && switchto('ident-rest') : 92 == t ? badescape(next()) ? parseerror() && switchto('data') && reconsume() : create(new IdentifierToken(consumeEscape())) && switchto('ident-rest') : catchfire('Hit the generic \'else\' clause in ident state.') && switchto('data') && reconsume();117 break;118 case 'ident-rest':119 namechar(t) ? o.append(t) : 92 == t ? badescape(next()) ? parseerror() && emit() && switchto('data') && reconsume() : o.append(consumeEscape()) : 40 == t ? o.ASCIImatch('url') ? switchto('url') : emit(new FunctionToken(o)) && switchto('data') : whitespace(t) && n.transformFunctionWhitespace ? switchto('transform-function-whitespace') && reconsume() : emit() && switchto('data') && reconsume();120 break;121 case 'transform-function-whitespace':122 whitespace(next()) || (40 == t ? emit(new FunctionToken(o)) && switchto('data') : emit() && switchto('data') && reconsume());123 break;124 case 'number':125 create(new NumberToken), 45 == t ? digit(next()) ? consume() && o.append([ 45, t ]) && switchto('number-rest') : 46 == next(1) && digit(next(2)) ? consume(2) && o.append([ 45, 46, t ]) && switchto('number-fraction') : switchto('data') && reconsume() : 43 == t ? digit(next()) ? consume() && o.append([ 43, t ]) && switchto('number-rest') : 46 == next(1) && digit(next(2)) ? consume(2) && o.append([ 43, 46, t ]) && switchto('number-fraction') : switchto('data') && reconsume() : digit(t) ? o.append(t) && switchto('number-rest') : 46 == t && digit(next()) ? consume() && o.append([ 46, t ]) && switchto('number-fraction') : switchto('data') && reconsume();126 break;127 case 'number-rest':128 digit(t) ? o.append(t) : 46 == t ? digit(next()) ? consume() && o.append([ 46, t ]) && switchto('number-fraction') : emit() && switchto('data') && reconsume() : 37 == t ? emit(new PercentageToken(o)) && switchto('data') : 69 == t || 101 == t ? digit(next()) ? consume() && o.append([ 37, t ]) && switchto('sci-notation') : 43 != next(1) && 45 != next(1) || !digit(next(2)) ? create(new DimensionToken(o, t)) && switchto('dimension') : o.append([ 37, next(1), next(2) ]) && consume(2) && switchto('sci-notation') : 45 == t ? namestartchar(next()) ? consume() && create(new DimensionToken(o, [ 45, t ])) && switchto('dimension') : 92 == next(1) && badescape(next(2)) ? parseerror() && emit() && switchto('data') && reconsume() : 92 == next(1) ? consume() && create(new DimensionToken(o, [ 45, consumeEscape() ])) && switchto('dimension') : emit() && switchto('data') && reconsume() : namestartchar(t) ? create(new DimensionToken(o, t)) && switchto('dimension') : 92 == t ? badescape(next) ? parseerror() && emit() && switchto('data') && reconsume() : create(new DimensionToken(o, consumeEscape)) && switchto('dimension') : emit() && switchto('data') && reconsume();129 break;130 case 'number-fraction':131 o.type = 'number', digit(t) ? o.append(t) : 37 == t ? emit(new PercentageToken(o)) && switchto('data') : 69 == t || 101 == t ? digit(next()) ? consume() && o.append([ 101, t ]) && switchto('sci-notation') : 43 != next(1) && 45 != next(1) || !digit(next(2)) ? create(new DimensionToken(o, t)) && switchto('dimension') : o.append([ 101, next(1), next(2) ]) && consume(2) && switchto('sci-notation') : 45 == t ? namestartchar(next()) ? consume() && create(new DimensionToken(o, [ 45, t ])) && switchto('dimension') : 92 == next(1) && badescape(next(2)) ? parseerror() && emit() && switchto('data') && reconsume() : 92 == next(1) ? consume() && create(new DimensionToken(o, [ 45, consumeEscape() ])) && switchto('dimension') : emit() && switchto('data') && reconsume() : namestartchar(t) ? create(new DimensionToken(o, t)) && switchto('dimension') : 92 == t ? badescape(next) ? parseerror() && emit() && switchto('data') && reconsume() : create(new DimensionToken(o, consumeEscape())) && switchto('dimension') : emit() && switchto('data') && reconsume();132 break;133 case 'dimension':134 namechar(t) ? o.append(t) : 92 == t ? badescape(next()) ? parseerror() && emit() && switchto('data') && reconsume() : o.append(consumeEscape()) : emit() && switchto('data') && reconsume();135 break;136 case 'sci-notation':137 o.type = 'number', digit(t) ? o.append(t) : emit() && switchto('data') && reconsume();138 break;139 case 'url':140 eof() ? parseerror() && emit(new BadURLToken) && switchto('data') : 34 == t ? switchto('url-double-quote') : 39 == t ? switchto('url-single-quote') : 41 == t ? emit(new URLToken) && switchto('data') : whitespace(t) || switchto('url-unquoted') && reconsume();141 break;142 case 'url-double-quote':143 o instanceof URLToken || create(new URLToken), eof() ? parseerror() && emit(new BadURLToken) && switchto('data') : 34 == t ? switchto('url-end') : newline(t) ? parseerror() && switchto('bad-url') : 92 == t ? newline(next()) ? consume() : badescape(next()) ? parseerror() && emit(new BadURLToken) && switchto('data') && reconsume() : o.append(consumeEscape()) : o.append(t);144 break;145 case 'url-single-quote':146 o instanceof URLToken || create(new URLToken), eof() ? parseerror() && emit(new BadURLToken) && switchto('data') : 39 == t ? switchto('url-end') : newline(t) ? parseerror() && switchto('bad-url') : 92 == t ? newline(next()) ? consume() : badescape(next()) ? parseerror() && emit(new BadURLToken) && switchto('data') && reconsume() : o.append(consumeEscape()) : o.append(t);147 break;148 case 'url-end':149 eof() ? parseerror() && emit(new BadURLToken) && switchto('data') : whitespace(t) || (41 == t ? emit() && switchto('data') : parseerror() && switchto('bad-url') && reconsume());150 break;151 case 'url-unquoted':152 o instanceof URLToken || create(new URLToken), eof() ? parseerror() && emit(new BadURLToken) && switchto('data') : whitespace(t) ? switchto('url-end') : 41 == t ? emit() && switchto('data') : 34 == t || 39 == t || 40 == t || nonprintable(t) ? parseerror() && switchto('bad-url') : 92 == t ? badescape(next()) ? parseerror() && switchto('bad-url') : o.append(consumeEscape()) : o.append(t);153 break;154 case 'bad-url':155 eof() ? parseerror() && emit(new BadURLToken) && switchto('data') : 41 == t ? emit(new BadURLToken) && switchto('data') : 92 == t && (badescape(next()) || consumeEscape());156 break;157 case 'unicode-range':158 for (var k = [ t ], c = [ t ], T = 1; T < 6 && hexdigit(next()); T++) consume(), 159 k.push(t), c.push(t);160 if (63 == next()) {161 for (;T < 6 && 63 == next(); T++) consume(), k.push('0'.charCodeAt(0)), c.push('f'.charCodeAt(0));162 emit(new UnicodeRangeToken(k, c)) && switchto('data');163 } else if (45 == next(1) && hexdigit(next(2))) {164 consume(), consume(), c = [ t ];165 for (T = 1; T < 6 && hexdigit(next()); T++) consume(), c.push(t);166 emit(new UnicodeRangeToken(k, c)) && switchto('data');167 } else emit(new UnicodeRangeToken(k)) && switchto('data');168 break;169 default:...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const context = await browser.newContext();5 const page = await context.newPage();6 await page.screenshot({ path: 'google.png' });7 await browser.close();8})();

Full Screen

Using AI Code Generation

copy

Full Screen

1const { test, expect } = require('@playwright/test');2test('test', async ({ page }) => {3 const title = page.locator('.navbar__inner .navbar__title');4 expect(await title.textContent()).toBe('Playwright');5});6- Use the page.waitForNavigation()

Full Screen

Using AI Code Generation

copy

Full Screen

1const { chromium } = require('playwright');2const { badescape } = require('playwright/lib/internal/utils');3(async () => {4 const browser = await chromium.launch();5 const page = await browser.newPage();6 await browser.close();7})();

Full Screen

Using AI Code Generation

copy

Full Screen

1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const page = await browser.newPage();5 await page.goto(url);6 const title = await page.title();7 console.log(title);8 await browser.close();9})();

Full Screen

Using AI Code Generation

copy

Full Screen

1const { test, expect } = require('@playwright/test');2const { badescape } = require('@playwright/test/internal');3test('my test', async ({ page }) => {4 await page.goto(url);5 expect(await page.textContent('h1')).toBe('Hello John!');6});7const { test, expect } = require('@playwright/test');8const { badescape } = require('@playwright/test/internal');9test('my test', async ({ page }) => {10 await page.goto(url);11 expect(await page.textContent('h1')).toBe('Hello John!');12});13const { test, expect } = require('@playwright/test');14const { badescape } = require('@playwright/test/internal');15test('my test', async ({ page }) => {16 await page.goto(url);17 expect(await page.textContent('h1')).toBe('Hello John!');18});19const { test, expect } = require('@playwright/test');20const { badescape } = require('@playwright/test/internal');21test('my test', async ({ page }) => {22 await page.goto(url);23 expect(await page.textContent('h1')).toBe('Hello John!');24});25const { test, expect } = require('@playwright/test');26const { badescape } = require('@playwright/test/internal');27test('my test', async ({ page }) => {28 await page.goto(url);29 expect(await page.textContent('h1')).toBe('Hello John!');30});31const { test, expect } = require('@playwright/test');

Full Screen

Using AI Code Generation

copy

Full Screen

1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const context = await browser.newContext();5 const page = await context.newPage();6 await page.fill('[name="q"]', 'playwright');7 await page.keyboard.press('Enter');8 await page.waitForNavigation();9 await page.screenshot({ path: `example.png` });10 await browser.close();11})();

Full Screen

Using AI Code Generation

copy

Full Screen

1const {badescape} = require('playwright/lib/utils/utils');2const escaped = badescape(url);3console.log(escaped);4const {badescape} = require('playwright');5const escaped = badescape(url);6console.log(escaped);7const {badescape} = require('playwright/lib/utils/utils');8const escaped = badescape(url);9console.log(escaped);10const {badescape} = require('playwright');11const escaped = badescape(url);12console.log(escaped);13const {badescape} = require('playwright/lib/utils/utils');14const escaped = badescape(url);15console.log(escaped);16const {badescape} = require('playwright');17const escaped = badescape(url);18console.log(escaped);19const {badescape} = require('playwright/lib/utils/utils');20const escaped = badescape(url);21console.log(escaped);

Full Screen

Playwright tutorial

LambdaTest’s Playwright tutorial will give you a broader idea about the Playwright automation framework, its unique features, and use cases with examples to exceed your understanding of Playwright testing. This tutorial will give A to Z guidance, from installing the Playwright framework to some best practices and advanced concepts.

Chapters:

  1. What is Playwright : Playwright is comparatively new but has gained good popularity. Get to know some history of the Playwright with some interesting facts connected with it.
  2. How To Install Playwright : Learn in detail about what basic configuration and dependencies are required for installing Playwright and run a test. Get a step-by-step direction for installing the Playwright automation framework.
  3. Playwright Futuristic Features: Launched in 2020, Playwright gained huge popularity quickly because of some obliging features such as Playwright Test Generator and Inspector, Playwright Reporter, Playwright auto-waiting mechanism and etc. Read up on those features to master Playwright testing.
  4. What is Component Testing: Component testing in Playwright is a unique feature that allows a tester to test a single component of a web application without integrating them with other elements. Learn how to perform Component testing on the Playwright automation framework.
  5. Inputs And Buttons In Playwright: Every website has Input boxes and buttons; learn about testing inputs and buttons with different scenarios and examples.
  6. Functions and Selectors in Playwright: Learn how to launch the Chromium browser with Playwright. Also, gain a better understanding of some important functions like “BrowserContext,” which allows you to run multiple browser sessions, and “newPage” which interacts with a page.
  7. Handling Alerts and Dropdowns in Playwright : Playwright interact with different types of alerts and pop-ups, such as simple, confirmation, and prompt, and different types of dropdowns, such as single selector and multi-selector get your hands-on with handling alerts and dropdown in Playright testing.
  8. Playwright vs Puppeteer: Get to know about the difference between two testing frameworks and how they are different than one another, which browsers they support, and what features they provide.
  9. Run Playwright Tests on LambdaTest: Playwright testing with LambdaTest leverages test performance to the utmost. You can run multiple Playwright tests in Parallel with the LammbdaTest test cloud. Get a step-by-step guide to run your Playwright test on the LambdaTest platform.
  10. Playwright Python Tutorial: Playwright automation framework support all major languages such as Python, JavaScript, TypeScript, .NET and etc. However, there are various advantages to Python end-to-end testing with Playwright because of its versatile utility. Get the hang of Playwright python testing with this chapter.
  11. Playwright End To End Testing Tutorial: Get your hands on with Playwright end-to-end testing and learn to use some exciting features such as TraceViewer, Debugging, Networking, Component testing, Visual testing, and many more.
  12. Playwright Video Tutorial: Watch the video tutorials on Playwright testing from experts and get a consecutive in-depth explanation of Playwright automation testing.

Run Playwright Internal automation tests on LambdaTest cloud grid

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

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful