How to use DelimToken method in Playwright Internal

Best JavaScript code snippet using playwright-internal

cssTokenizer.js

Source:cssTokenizer.js Github

copy

Full Screen

...151 if(wouldStartAnIdentifier(next(1), next(2), next(3))) token.type = "id";152 token.value = consumeAName();153 return token;154 } else {155 return new DelimToken(code);156 }157 }158 else if(code == 0x24) {159 if(next() == 0x3d) {160 consume();161 return new SuffixMatchToken();162 } else {163 return new DelimToken(code);164 }165 }166 else if(code == 0x27) return consumeAStringToken();167 else if(code == 0x28) return new OpenParenToken();168 else if(code == 0x29) return new CloseParenToken();169 else if(code == 0x2a) {170 if(next() == 0x3d) {171 consume();172 return new SubstringMatchToken();173 } else {174 return new DelimToken(code);175 }176 }177 else if(code == 0x2b) {178 if(startsWithANumber()) {179 reconsume();180 return consumeANumericToken();181 } else {182 return new DelimToken(code);183 }184 }185 else if(code == 0x2c) return new CommaToken();186 else if(code == 0x2d) {187 if(startsWithANumber()) {188 reconsume();189 return consumeANumericToken();190 } else if(next(1) == 0x2d && next(2) == 0x3e) {191 consume(2);192 return new CDCToken();193 } else if(startsWithAnIdentifier()) {194 reconsume();195 return consumeAnIdentlikeToken();196 } else {197 return new DelimToken(code);198 }199 }200 else if(code == 0x2e) {201 if(startsWithANumber()) {202 reconsume();203 return consumeANumericToken();204 } else {205 return new DelimToken(code);206 }207 }208 else if(code == 0x3a) return new ColonToken;209 else if(code == 0x3b) return new SemicolonToken;210 else if(code == 0x3c) {211 if(next(1) == 0x21 && next(2) == 0x2d && next(3) == 0x2d) {212 consume(3);213 return new CDOToken();214 } else {215 return new DelimToken(code);216 }217 }218 else if(code == 0x40) {219 if(wouldStartAnIdentifier(next(1), next(2), next(3))) {220 return new AtKeywordToken(consumeAName());221 } else {222 return new DelimToken(code);223 }224 }225 else if(code == 0x5b) return new OpenSquareToken();226 else if(code == 0x5c) {227 if(startsWithAValidEscape()) {228 reconsume();229 return consumeAnIdentlikeToken();230 } else {231 parseerror();232 return new DelimToken(code);233 }234 }235 else if(code == 0x5d) return new CloseSquareToken();236 else if(code == 0x5e) {237 if(next() == 0x3d) {238 consume();239 return new PrefixMatchToken();240 } else {241 return new DelimToken(code);242 }243 }244 else if(code == 0x7b) return new OpenCurlyToken();245 else if(code == 0x7c) {246 if(next() == 0x3d) {247 consume();248 return new DashMatchToken();249 } else if(next() == 0x7c) {250 consume();251 return new ColumnToken();252 } else {253 return new DelimToken(code);254 }255 }256 else if(code == 0x7d) return new CloseCurlyToken();257 else if(code == 0x7e) {258 if(next() == 0x3d) {259 consume();260 return new IncludeMatchToken();261 } else {262 return new DelimToken(code);263 }264 }265 else if(digit(code)) {266 reconsume();267 return consumeANumericToken();268 }269 else if(namestartchar(code)) {270 reconsume();271 return consumeAnIdentlikeToken();272 }273 else if(eof()) return new EOFToken();274 else return new DelimToken(code);275 };276 var consumeComments = function() {277 while(next(1) == 0x2f && next(2) == 0x2a) {278 consume(2);279 while(true) {280 consume();281 if(code == 0x2a && next() == 0x2f) {282 consume();283 break;284 } else if(eof()) {285 parseerror();286 return;287 }288 }289 }290 };291 var consumeANumericToken = function() {292 var num = consumeANumber();293 if(wouldStartAnIdentifier(next(1), next(2), next(3))) {294 var token = new DimensionToken();295 token.value = num.value;296 token.repr = num.repr;297 token.type = num.type;298 token.unit = consumeAName();299 return token;300 } else if(next() == 0x25) {301 consume();302 var token = new PercentageToken();303 token.value = num.value;304 token.repr = num.repr;305 return token;306 } else {307 var token = new NumberToken();308 token.value = num.value;309 token.repr = num.repr;310 token.type = num.type;311 return token;312 }313 };314 var consumeAnIdentlikeToken = function() {315 var str = consumeAName();316 if(str.toLowerCase() == "url" && next() == 0x28) {317 consume();318 while(whitespace(next(1)) && whitespace(next(2))) consume();319 if(next() == 0x22 || next() == 0x27) {320 return new FunctionToken(str);321 } else if(whitespace(next()) && (next(2) == 0x22 || next(2) == 0x27)) {322 return new FunctionToken(str);323 } else {324 return consumeAURLToken();325 }326 } else if(next() == 0x28) {327 consume();328 return new FunctionToken(str);329 } else {330 return new IdentToken(str);331 }332 };333 var consumeAStringToken = function(endingCodePoint) {334 if(endingCodePoint === undefined) endingCodePoint = code;335 var string = "";336 while(consume()) {337 if(code == endingCodePoint || eof()) {338 return new StringToken(string);339 } else if(newline(code)) {340 parseerror();341 reconsume();342 return new BadStringToken();343 } else if(code == 0x5c) {344 if(eof(next())) {345 donothing();346 } else if(newline(next())) {347 consume();348 } else {349 string += stringFromCode(consumeEscape())350 }351 } else {352 string += stringFromCode(code);353 }354 }355 };356 var consumeAURLToken = function() {357 var token = new URLToken("");358 while(whitespace(next())) consume();359 if(eof(next())) return token;360 while(consume()) {361 if(code == 0x29 || eof()) {362 return token;363 } else if(whitespace(code)) {364 while(whitespace(next())) consume();365 if(next() == 0x29 || eof(next())) {366 consume();367 return token;368 } else {369 consumeTheRemnantsOfABadURL();370 return new BadURLToken();371 }372 } else if(code == 0x22 || code == 0x27 || code == 0x28 || nonprintable(code)) {373 parseerror();374 consumeTheRemnantsOfABadURL();375 return new BadURLToken();376 } else if(code == 0x5c) {377 if(startsWithAValidEscape()) {378 token.value += stringFromCode(consumeEscape());379 } else {380 parseerror();381 consumeTheRemnantsOfABadURL();382 return new BadURLToken();383 }384 } else {385 token.value += stringFromCode(code);386 }387 }388 };389 var consumeEscape = function() {390 // Assume the the current character is the \391 // and the next code point is not a newline.392 consume();393 if(hexdigit(code)) {394 // Consume 1-6 hex digits395 var digits = [code];396 for(var total = 0; total < 5; total++) {397 if(hexdigit(next())) {398 consume();399 digits.push(code);400 } else {401 break;402 }403 }404 if(whitespace(next())) consume();405 var value = parseInt(digits.map(function(x){return String.fromCharCode(x);}).join(''), 16);406 if( value > maximumallowedcodepoint ) value = 0xfffd;407 return value;408 } else if(eof()) {409 return 0xfffd;410 } else {411 return code;412 }413 };414 var areAValidEscape = function(c1, c2) {415 if(c1 != 0x5c) return false;416 if(newline(c2)) return false;417 return true;418 };419 var startsWithAValidEscape = function() {420 return areAValidEscape(code, next());421 };422 var wouldStartAnIdentifier = function(c1, c2, c3) {423 if(c1 == 0x2d) {424 return namestartchar(c2) || c2 == 0x2d || areAValidEscape(c2, c3);425 } else if(namestartchar(c1)) {426 return true;427 } else if(c1 == 0x5c) {428 return areAValidEscape(c1, c2);429 } else {430 return false;431 }432 };433 var startsWithAnIdentifier = function() {434 return wouldStartAnIdentifier(code, next(1), next(2));435 };436 var wouldStartANumber = function(c1, c2, c3) {437 if(c1 == 0x2b || c1 == 0x2d) {438 if(digit(c2)) return true;439 if(c2 == 0x2e && digit(c3)) return true;440 return false;441 } else if(c1 == 0x2e) {442 if(digit(c2)) return true;443 return false;444 } else if(digit(c1)) {445 return true;446 } else {447 return false;448 }449 };450 var startsWithANumber = function() {451 return wouldStartANumber(code, next(1), next(2));452 };453 var consumeAName = function() {454 var result = "";455 while(consume()) {456 if(namechar(code)) {457 result += stringFromCode(code);458 } else if(startsWithAValidEscape()) {459 result += stringFromCode(consumeEscape());460 } else {461 reconsume();462 return result;463 }464 }465 };466 var consumeANumber = function() {467 var repr = [];468 var type = "integer";469 if(next() == 0x2b || next() == 0x2d) {470 consume();471 repr += stringFromCode(code);472 }473 while(digit(next())) {474 consume();475 repr += stringFromCode(code);476 }477 if(next(1) == 0x2e && digit(next(2))) {478 consume();479 repr += stringFromCode(code);480 consume();481 repr += stringFromCode(code);482 type = "number";483 while(digit(next())) {484 consume();485 repr += stringFromCode(code);486 }487 }488 var c1 = next(1), c2 = next(2), c3 = next(3);489 if((c1 == 0x45 || c1 == 0x65) && digit(c2)) {490 consume();491 repr += stringFromCode(code);492 consume();493 repr += stringFromCode(code);494 type = "number";495 while(digit(next())) {496 consume();497 repr += stringFromCode(code);498 }499 } else if((c1 == 0x45 || c1 == 0x65) && (c2 == 0x2b || c2 == 0x2d) && digit(c3)) {500 consume();501 repr += stringFromCode(code);502 consume();503 repr += stringFromCode(code);504 consume();505 repr += stringFromCode(code);506 type = "number";507 while(digit(next())) {508 consume();509 repr += stringFromCode(code);510 }511 }512 var value = convertAStringToANumber(repr);513 return {type:type, value:value, repr:repr};514 };515 var convertAStringToANumber = function(string) {516 // CSS's number rules are identical to JS, afaik.517 return +string;518 };519 var consumeTheRemnantsOfABadURL = function() {520 while(consume()) {521 if(code == 0x29 || eof()) {522 return;523 } else if(startsWithAValidEscape()) {524 consumeEscape();525 donothing();526 } else {527 donothing();528 }529 }530 };531 var iterationCount = 0;532 while(!eof(next())) {533 tokens.push(consumeAToken());534 iterationCount++;535 if(iterationCount > str.length*2) return "I'm infinite-looping!";536 }537 return tokens;538}539function CSSParserToken() { throw "Abstract Base Class"; }540CSSParserToken.prototype.toJSON = function() {541 return {token: this.tokenType};542}543CSSParserToken.prototype.toString = function() { return this.tokenType; }544CSSParserToken.prototype.toSource = function() { return ''+this; }545function BadStringToken() { return this; }546BadStringToken.prototype = Object.create(CSSParserToken.prototype);547BadStringToken.prototype.tokenType = "BADSTRING";548function BadURLToken() { return this; }549BadURLToken.prototype = Object.create(CSSParserToken.prototype);550BadURLToken.prototype.tokenType = "BADURL";551function WhitespaceToken() { return this; }552WhitespaceToken.prototype = Object.create(CSSParserToken.prototype);553WhitespaceToken.prototype.tokenType = "WHITESPACE";554WhitespaceToken.prototype.toString = function() { return "WS"; }555WhitespaceToken.prototype.toSource = function() { return " "; }556function CDOToken() { return this; }557CDOToken.prototype = Object.create(CSSParserToken.prototype);558CDOToken.prototype.tokenType = "CDO";559CDOToken.prototype.toSource = function() { return "<!--"; }560function CDCToken() { return this; }561CDCToken.prototype = Object.create(CSSParserToken.prototype);562CDCToken.prototype.tokenType = "CDC";563CDCToken.prototype.toSource = function() { return "-->"; }564function ColonToken() { return this; }565ColonToken.prototype = Object.create(CSSParserToken.prototype);566ColonToken.prototype.tokenType = ":";567function SemicolonToken() { return this; }568SemicolonToken.prototype = Object.create(CSSParserToken.prototype);569SemicolonToken.prototype.tokenType = ";";570function CommaToken() { return this; }571CommaToken.prototype = Object.create(CSSParserToken.prototype);572CommaToken.prototype.tokenType = ",";573function GroupingToken() { throw "Abstract Base Class"; }574GroupingToken.prototype = Object.create(CSSParserToken.prototype);575function OpenCurlyToken() { this.value = "{"; this.mirror = "}"; return this; }576OpenCurlyToken.prototype = Object.create(GroupingToken.prototype);577OpenCurlyToken.prototype.tokenType = "{";578function CloseCurlyToken() { this.value = "}"; this.mirror = "{"; return this; }579CloseCurlyToken.prototype = Object.create(GroupingToken.prototype);580CloseCurlyToken.prototype.tokenType = "}";581function OpenSquareToken() { this.value = "["; this.mirror = "]"; return this; }582OpenSquareToken.prototype = Object.create(GroupingToken.prototype);583OpenSquareToken.prototype.tokenType = "[";584function CloseSquareToken() { this.value = "]"; this.mirror = "["; return this; }585CloseSquareToken.prototype = Object.create(GroupingToken.prototype);586CloseSquareToken.prototype.tokenType = "]";587function OpenParenToken() { this.value = "("; this.mirror = ")"; return this; }588OpenParenToken.prototype = Object.create(GroupingToken.prototype);589OpenParenToken.prototype.tokenType = "(";590function CloseParenToken() { this.value = ")"; this.mirror = "("; return this; }591CloseParenToken.prototype = Object.create(GroupingToken.prototype);592CloseParenToken.prototype.tokenType = ")";593function IncludeMatchToken() { return this; }594IncludeMatchToken.prototype = Object.create(CSSParserToken.prototype);595IncludeMatchToken.prototype.tokenType = "~=";596function DashMatchToken() { return this; }597DashMatchToken.prototype = Object.create(CSSParserToken.prototype);598DashMatchToken.prototype.tokenType = "|=";599function PrefixMatchToken() { return this; }600PrefixMatchToken.prototype = Object.create(CSSParserToken.prototype);601PrefixMatchToken.prototype.tokenType = "^=";602function SuffixMatchToken() { return this; }603SuffixMatchToken.prototype = Object.create(CSSParserToken.prototype);604SuffixMatchToken.prototype.tokenType = "$=";605function SubstringMatchToken() { return this; }606SubstringMatchToken.prototype = Object.create(CSSParserToken.prototype);607SubstringMatchToken.prototype.tokenType = "*=";608function ColumnToken() { return this; }609ColumnToken.prototype = Object.create(CSSParserToken.prototype);610ColumnToken.prototype.tokenType = "||";611function EOFToken() { return this; }612EOFToken.prototype = Object.create(CSSParserToken.prototype);613EOFToken.prototype.tokenType = "EOF";614EOFToken.prototype.toSource = function() { return ""; }615function DelimToken(code) {616 this.value = stringFromCode(code);617 return this;618}619DelimToken.prototype = Object.create(CSSParserToken.prototype);620DelimToken.prototype.tokenType = "DELIM";621DelimToken.prototype.toString = function() { return "DELIM("+this.value+")"; }622DelimToken.prototype.toJSON = function() {623 var json = this.constructor.prototype.constructor.prototype.toJSON.call(this);624 json.value = this.value;625 return json;626}627DelimToken.prototype.toSource = function() {628 if(this.value == "\\")629 return "\\\n";...

Full Screen

Full Screen

tokenizer.js

Source:tokenizer.js Github

copy

Full Screen

...136 else if(code == 0x28) emit(new OpenParenToken);137 else if(code == 0x29) emit(new CloseParenToken);138 else if(code == 0x2b) {139 if(digit(next()) || (next() == 0x2e && digit(next(2)))) switchto("number") && reconsume();140 else emit(new DelimToken(code));141 }142 else if(code == 0x2d) {143 if(next(1) == 0x2d && next(2) == 0x3e) consume(2) && emit(new CDCToken);144 else if(digit(next()) || (next(1) == 0x2e && digit(next(2)))) switchto("number") && reconsume();145 else switchto('ident') && reconsume();146 }147 else if(code == 0x2e) {148 if(digit(next())) switchto("number") && reconsume();149 else emit(new DelimToken(code));150 }151 else if(code == 0x2f) {152 if(next() == 0x2a) consume() && switchto("comment");153 else emit(new DelimToken(code));154 }155 else if(code == 0x3a) emit(new ColonToken);156 else if(code == 0x3b) emit(new SemicolonToken);157 else if(code == 0x3c) {158 if(next(1) == 0x21 && next(2) == 0x2d && next(3) == 0x2d) consume(3) && emit(new CDOToken);159 else emit(new DelimToken(code));160 }161 else if(code == 0x40) switchto("at-keyword");162 else if(code == 0x5b) emit(new OpenSquareToken);163 else if(code == 0x5c) {164 if(badescape(next())) parseerror() && emit(new DelimToken(code));165 else switchto('ident') && reconsume();166 }167 else if(code == 0x5d) emit(new CloseSquareToken);168 else if(code == 0x7b) emit(new OpenCurlyToken);169 else if(code == 0x7d) emit(new CloseCurlyToken);170 else if(digit(code)) switchto("number") && reconsume();171 else if(code == 0x55 || code == 0x75) {172 if(next(1) == 0x2b && hexdigit(next(2))) consume() && switchto("unicode-range");173 else switchto('ident') && reconsume();174 }175 else if(namestartchar(code)) switchto('ident') && reconsume();176 else if(eof()) { emit(new EOFToken); return tokens; }177 else emit(new DelimToken(code));178 break;179 case "double-quote-string":180 if(currtoken == undefined) create(new StringToken);181 if(code == 0x22) emit() && switchto("data");182 else if(eof()) parseerror() && emit() && switchto("data") && reconsume();183 else if(newline(code)) parseerror() && emit(new BadStringToken) && switchto("data") && reconsume();184 else if(code == 0x5c) {185 if(badescape(next())) parseerror() && emit(new BadStringToken) && switchto("data");186 else if(newline(next())) consume();187 else currtoken.append(consumeEscape());188 }189 else currtoken.append(code);190 break;191 case "single-quote-string":192 if(currtoken == undefined) create(new StringToken);193 if(code == 0x27) emit() && switchto("data");194 else if(eof()) parseerror() && emit() && switchto("data");195 else if(newline(code)) parseerror() && emit(new BadStringToken) && switchto("data") && reconsume();196 else if(code == 0x5c) {197 if(badescape(next())) parseerror() && emit(new BadStringToken) && switchto("data");198 else if(newline(next())) consume();199 else currtoken.append(consumeEscape());200 }201 else currtoken.append(code);202 break;203 case "hash":204 if(namechar(code)) create(new HashToken(code)) && switchto("hash-rest");205 else if(code == 0x5c) {206 if(badescape(next())) parseerror() && emit(new DelimToken(0x23)) && switchto("data") && reconsume();207 else create(new HashToken(consumeEscape())) && switchto('hash-rest');208 }209 else emit(new DelimToken(0x23)) && switchto('data') && reconsume();210 break;211 case "hash-rest":212 if(namechar(code)) currtoken.append(code);213 else if(code == 0x5c) {214 if(badescape(next())) parseerror() && emit() && switchto("data") && reconsume();215 else currtoken.append(consumeEscape());216 }217 else emit() && switchto('data') && reconsume();218 break;219 case "comment":220 if(code == 0x2a) {221 if(next() == 0x2f) consume() && switchto('data');222 else donothing();223 }224 else if(eof()) parseerror() && switchto('data') && reconsume();225 else donothing();226 break;227 case "at-keyword":228 if(code == 0x2d) {229 if(namestartchar(next())) create(new AtKeywordToken(0x2d)) && switchto('at-keyword-rest');230 else if(next(1) == 0x5c && !badescape(next(2))) create(new AtKeywordtoken(0x2d)) && switchto('at-keyword-rest');231 else parseerror() && emit(new DelimToken(0x40)) && switchto('data') && reconsume();232 }233 else if(namestartchar(code)) create(new AtKeywordToken(code)) && switchto('at-keyword-rest');234 else if(code == 0x5c) {235 if(badescape(next())) parseerror() && emit(new DelimToken(0x23)) && switchto("data") && reconsume();236 else create(new AtKeywordToken(consumeEscape())) && switchto('at-keyword-rest');237 }238 else emit(new DelimToken(0x40)) && switchto('data') && reconsume();239 break;240 case "at-keyword-rest":241 if(namechar(code)) currtoken.append(code);242 else if(code == 0x5c) {243 if(badescape(next())) parseerror() && emit() && switchto("data") && reconsume();244 else currtoken.append(consumeEscape());245 }246 else emit() && switchto('data') && reconsume();247 break;248 case "ident":249 if(code == 0x2d) {250 if(namestartchar(next())) create(new IdentifierToken(code)) && switchto('ident-rest');251 else if(next(1) == 0x5c && !badescape(next(2))) create(new IdentifierToken(code)) && switchto('ident-rest');252 else emit(new DelimToken(0x2d)) && switchto('data');253 }254 else if(namestartchar(code)) create(new IdentifierToken(code)) && switchto('ident-rest');255 else if(code == 0x5c) {256 if(badescape(next())) parseerror() && switchto("data") && reconsume();257 else create(new IdentifierToken(consumeEscape())) && switchto('ident-rest');258 }259 else catchfire("Hit the generic 'else' clause in ident state.") && switchto('data') && reconsume();260 break;261 case "ident-rest":262 if(namechar(code)) currtoken.append(code);263 else if(code == 0x5c) {264 if(badescape(next())) parseerror() && emit() && switchto("data") && reconsume();265 else currtoken.append(consumeEscape());266 }267 else if(code == 0x28) {268 if(currtoken.ASCIImatch('url')) switchto('url');269 else emit(new FunctionToken(currtoken)) && switchto('data');270 } 271 else if(whitespace(code) && options.transformFunctionWhitespace) switchto('transform-function-whitespace') && reconsume();272 else emit() && switchto('data') && reconsume();273 break;274 case "transform-function-whitespace":275 if(whitespace(next())) donothing();276 else if(code == 0x28) emit(new FunctionToken(currtoken)) && switchto('data');277 else emit() && switchto('data') && reconsume();278 break;279 case "number":280 create(new NumberToken());281 if(code == 0x2d) {282 if(digit(next())) consume() && currtoken.append([0x2d,code]) && switchto('number-rest');283 else if(next(1) == 0x2e && digit(next(2))) consume(2) && currtoken.append([0x2d,0x2e,code]) && switchto('number-fraction');284 else switchto('data') && reconsume();285 }286 else if(code == 0x2b) {287 if(digit(next())) consume() && currtoken.append([0x2b,code]) && switchto('number-rest');288 else if(next(1) == 0x2e && digit(next(2))) consume(2) && currtoken.append([0x2b,0x2e,code]) && switchto('number-fraction');289 else switchto('data') && reconsume();290 }291 else if(digit(code)) currtoken.append(code) && switchto('number-rest');292 else if(code == 0x2e) {293 if(digit(next())) consume() && currtoken.append([0x2e,code]) && switchto('number-fraction');294 else switchto('data') && reconsume();295 }296 else switchto('data') && reconsume();297 break;298 case "number-rest":299 if(digit(code)) currtoken.append(code);300 else if(code == 0x2e) {301 if(digit(next())) consume() && currtoken.append([0x2e,code]) && switchto('number-fraction');302 else emit() && switchto('data') && reconsume();303 }304 else if(code == 0x25) emit(new PercentageToken(currtoken)) && switchto('data');305 else if(code == 0x45 || code == 0x65) {306 if(digit(next())) consume() && currtoken.append([0x25,code]) && switchto('sci-notation');307 else if((next(1) == 0x2b || next(1) == 0x2d) && digit(next(2))) currtoken.append([0x25,next(1),next(2)]) && consume(2) && switchto('sci-notation');308 else create(new DimensionToken(currtoken,code)) && switchto('dimension');309 }310 else if(code == 0x2d) {311 if(namestartchar(next())) consume() && create(new DimensionToken(currtoken,[0x2d,code])) && switchto('dimension');312 else if(next(1) == 0x5c && badescape(next(2))) parseerror() && emit() && switchto('data') && reconsume();313 else if(next(1) == 0x5c) consume() && create(new DimensionToken(currtoken, [0x2d,consumeEscape()])) && switchto('dimension');314 else emit() && switchto('data') && reconsume();315 }316 else if(namestartchar(code)) create(new DimensionToken(currtoken, code)) && switchto('dimension');317 else if(code == 0x5c) {318 if(badescape(next)) parseerror() && emit() && switchto('data') && reconsume();319 else create(new DimensionToken(currtoken,consumeEscape)) && switchto('dimension');320 }321 else emit() && switchto('data') && reconsume();322 break;323 case "number-fraction":324 currtoken.type = "number";325 if(digit(code)) currtoken.append(code);326 else if(code == 0x25) emit(new PercentageToken(currtoken)) && switchto('data');327 else if(code == 0x45 || code == 0x65) {328 if(digit(next())) consume() && currtoken.append([0x65,code]) && switchto('sci-notation');329 else if((next(1) == 0x2b || next(1) == 0x2d) && digit(next(2))) currtoken.append([0x65,next(1),next(2)]) && consume(2) && switchto('sci-notation');330 else create(new DimensionToken(currtoken,code)) && switchto('dimension');331 }332 else if(code == 0x2d) {333 if(namestartchar(next())) consume() && create(new DimensionToken(currtoken,[0x2d,code])) && switchto('dimension');334 else if(next(1) == 0x5c && badescape(next(2))) parseerror() && emit() && switchto('data') && reconsume();335 else if(next(1) == 0x5c) consume() && create(new DimensionToken(currtoken, [0x2d,consumeEscape()])) && switchto('dimension');336 else emit() && switchto('data') && reconsume();337 }338 else if(namestartchar(code)) create(new DimensionToken(currtoken, code)) && switchto('dimension');339 else if(code == 0x5c) {340 if(badescape(next)) parseerror() && emit() && switchto('data') && reconsume();341 else create(new DimensionToken(currtoken,consumeEscape())) && switchto('dimension');342 }343 else emit() && switchto('data') && reconsume();344 break;345 case "dimension":346 if(namechar(code)) currtoken.append(code);347 else if(code == 0x5c) {348 if(badescape(next())) parseerror() && emit() && switchto('data') && reconsume();349 else currtoken.append(consumeEscape());350 }351 else emit() && switchto('data') && reconsume();352 break;353 case "sci-notation":354 currtoken.type = "number";355 if(digit(code)) currtoken.append(code);356 else emit() && switchto('data') && reconsume();357 break;358 case "url":359 if(eof()) parseerror() && emit(new BadURLToken) && switchto('data');360 else if(code == 0x22) switchto('url-double-quote');361 else if(code == 0x27) switchto('url-single-quote');362 else if(code == 0x29) emit(new URLToken) && switchto('data');363 else if(whitespace(code)) donothing();364 else switchto('url-unquoted') && reconsume();365 break;366 case "url-double-quote":367 if(! (currtoken instanceof URLToken)) create(new URLToken);368 if(eof()) parseerror() && emit(new BadURLToken) && switchto('data');369 else if(code == 0x22) switchto('url-end');370 else if(newline(code)) parseerror() && switchto('bad-url');371 else if(code == 0x5c) {372 if(newline(next())) consume();373 else if(badescape(next())) parseerror() && emit(new BadURLToken) && switchto('data') && reconsume();374 else currtoken.append(consumeEscape());375 }376 else currtoken.append(code);377 break;378 case "url-single-quote":379 if(! (currtoken instanceof URLToken)) create(new URLToken);380 if(eof()) parseerror() && emit(new BadURLToken) && switchto('data');381 else if(code == 0x27) switchto('url-end');382 else if(newline(code)) parseerror() && switchto('bad-url');383 else if(code == 0x5c) {384 if(newline(next())) consume();385 else if(badescape(next())) parseerror() && emit(new BadURLToken) && switchto('data') && reconsume();386 else currtoken.append(consumeEscape());387 }388 else currtoken.append(code);389 break;390 case "url-end":391 if(eof()) parseerror() && emit(new BadURLToken) && switchto('data');392 else if(whitespace(code)) donothing();393 else if(code == 0x29) emit() && switchto('data');394 else parseerror() && switchto('bad-url') && reconsume();395 break;396 case "url-unquoted":397 if(! (currtoken instanceof URLToken)) create(new URLToken);398 if(eof()) parseerror() && emit(new BadURLToken) && switchto('data');399 else if(whitespace(code)) switchto('url-end');400 else if(code == 0x29) emit() && switchto('data');401 else if(code == 0x22 || code == 0x27 || code == 0x28 || nonprintable(code)) parseerror() && switchto('bad-url');402 else if(code == 0x5c) {403 if(badescape(next())) parseerror() && switchto('bad-url');404 else currtoken.append(consumeEscape());405 }406 else currtoken.append(code);407 break;408 case "bad-url":409 if(eof()) parseerror() && emit(new BadURLToken) && switchto('data');410 else if(code == 0x29) emit(new BadURLToken) && switchto('data');411 else if(code == 0x5c) {412 if(badescape(next())) donothing();413 else consumeEscape();414 }415 else donothing();416 break;417 case "unicode-range":418 // We already know that the current code is a hexdigit.419 var start = [code], end = [code];420 for(var total = 1; total < 6; total++) {421 if(hexdigit(next())) {422 consume();423 start.push(code);424 end.push(code);425 }426 else break;427 }428 if(next() == 0x3f) {429 for(;total < 6; total++) {430 if(next() == 0x3f) {431 consume();432 start.push("0".charCodeAt(0));433 end.push("f".charCodeAt(0));434 }435 else break;436 }437 emit(new UnicodeRangeToken(start,end)) && switchto('data');438 }439 else if(next(1) == 0x2d && hexdigit(next(2))) {440 consume();441 consume();442 end = [code];443 for(var total = 1; total < 6; total++) {444 if(hexdigit(next())) {445 consume();446 end.push(code);447 }448 else break;449 }450 emit(new UnicodeRangeToken(start,end)) && switchto('data');451 }452 else emit(new UnicodeRangeToken(start)) && switchto('data');453 break;454 default:455 catchfire("Unknown state '" + state + "'");456 }457 }458}459function stringFromCodeArray(arr) {460 return String.fromCharCode.apply(null,arr.filter(function(e){return e;}));461}462function CSSParserToken(options) { return this; }463CSSParserToken.prototype.finish = function() { return this; }464CSSParserToken.prototype.toString = function() { return this.tokenType; }465CSSParserToken.prototype.toSourceString = CSSParserToken.prototype.toString;466CSSParserToken.prototype.toJSON = function() { return this.toString(); }467function BadStringToken() { return this; }468BadStringToken.prototype = new CSSParserToken;469BadStringToken.prototype.tokenType = "BADSTRING";470function BadURLToken() { return this; }471BadURLToken.prototype = new CSSParserToken;472BadURLToken.prototype.tokenType = "BADURL";473function WhitespaceToken() { return this; }474WhitespaceToken.prototype = new CSSParserToken;475WhitespaceToken.prototype.tokenType = "WHITESPACE";476WhitespaceToken.prototype.toString = function() { return "WS"; }477WhitespaceToken.prototype.toSourceString = function() { return " "; }478function CDOToken() { return this; }479CDOToken.prototype = new CSSParserToken;480CDOToken.prototype.tokenType = "CDO";481function CDCToken() { return this; }482CDCToken.prototype = new CSSParserToken;483CDCToken.prototype.tokenType = "CDC";484function ColonToken() { return this; }485ColonToken.prototype = new CSSParserToken;486ColonToken.prototype.tokenType = ":";487function SemicolonToken() { return this; }488SemicolonToken.prototype = new CSSParserToken;489SemicolonToken.prototype.tokenType = ";";490function OpenCurlyToken() { return this; }491OpenCurlyToken.prototype = new CSSParserToken;492OpenCurlyToken.prototype.tokenType = "{";493function CloseCurlyToken() { return this; }494CloseCurlyToken.prototype = new CSSParserToken;495CloseCurlyToken.prototype.tokenType = "}";496function OpenSquareToken() { return this; }497OpenSquareToken.prototype = new CSSParserToken;498OpenSquareToken.prototype.tokenType = "[";499function CloseSquareToken() { return this; }500CloseSquareToken.prototype = new CSSParserToken;501CloseSquareToken.prototype.tokenType = "]";502function OpenParenToken() { return this; }503OpenParenToken.prototype = new CSSParserToken;504OpenParenToken.prototype.tokenType = "(";505function CloseParenToken() { return this; }506CloseParenToken.prototype = new CSSParserToken;507CloseParenToken.prototype.tokenType = ")";508function EOFToken() { return this; }509EOFToken.prototype = new CSSParserToken;510EOFToken.prototype.tokenType = "EOF";511function DelimToken(code) {512 this.value = String.fromCharCode(code);513 return this;514}515DelimToken.prototype = new CSSParserToken;516DelimToken.prototype.tokenType = "DELIM";517DelimToken.prototype.toString = function() { return "DELIM("+this.value+")"; }518DelimToken.prototype.toSourceString = function() { return this.value; }519function StringValuedToken() { return this; }520StringValuedToken.prototype = new CSSParserToken;521StringValuedToken.prototype.append = function(val) {522 if(val instanceof Array) {523 for(var i = 0; i < val.length; i++) {524 this.value.push(val[i]);525 }...

Full Screen

Full Screen

css-tokenizer.js

Source:css-tokenizer.js Github

copy

Full Screen

...133 else if(code == 0x28) emit(new OpenParenToken);134 else if(code == 0x29) emit(new CloseParenToken);135 else if(code == 0x2b) {136 if(digit(next()) || (next() == 0x2e && digit(next(2)))) switchto("number") && reconsume();137 else emit(new DelimToken(code));138 }139 else if(code == 0x2d) {140 if(next(1) == 0x2d && next(2) == 0x3e) consume(2) && emit(new CDCToken);141 else if(digit(next()) || (next(1) == 0x2e && digit(next(2)))) switchto("number") && reconsume();142 else if(namestartchar(next())) switchto("identifier") && reconsume();143 else emit(new DelimToken(code));144 }145 else if(code == 0x2e) {146 if(digit(next())) switchto("number") && reconsume();147 else emit(new DelimToken(code));148 }149 else if(code == 0x2f) {150 if(next() == 0x2a) switchto("comment");151 else emit(new DelimToken(code));152 }153 else if(code == 0x3a) emit(new ColonToken);154 else if(code == 0x3b) emit(new SemicolonToken);155 else if(code == 0x3c) {156 if(next(1) == 0x21 && next(2) == 0x2d && next(3) == 0x2d) consume(3) && emit(new CDOToken);157 else emit(new DelimToken(code));158 }159 else if(code == 0x40) switchto("at-keyword");160 else if(code == 0x5b) emit(new OpenSquareToken);161 else if(code == 0x5c) {162 if(badescape(next())) parseerror() && emit(new DelimToken(code));163 else switchto("identifier") && reconsume();164 }165 else if(code == 0x5d) emit(new CloseSquareToken);166 else if(code == 0x7b) emit(new OpenCurlyToken);167 else if(code == 0x7d) emit(new CloseCurlyToken);168 else if(digit(code)) switchto("number") && reconsume();169 else if(code == 0x55 || code == 0x75) {170 if(next(1) == 0x2b && hexdigit(next(2))) consume() && switchto("unicode-range");171 else if((next(1) == 0x52 || next(1) == 0x72) && (next(2) == 0x4c || next(2) == 0x6c) && (next(3) == 0x28)) consume(3) && switchto("url");172 else switchto("identifier") && reconsume();173 }174 else if(namestartchar(code)) switchto("identifier") && reconsume();175 else if(eof()) { emit(new EOFToken); return tokens; }176 else emit(new DelimToken(code));177 break;178 case "double-quote-string":179 if(currtoken == undefined) create(new StringToken);180 if(code == 0x22) emit() && switchto("data");181 else if(eof()) parseerror() && emit() && switchto("data");182 else if(newline(code)) parseerror() && emit(new BadStringToken) && switchto("data") && reconsume();183 else if(code == 0x5c) {184 if(badescape(next())) parseerror() && emit(new BadStringToken) && switchto("data");185 else if(newline(next())) consume();186 else currtoken.append(consumeEscape());187 }188 else currtoken.append(code);189 break;190 case "single-quote-string":191 if(currtoken == undefined) create(new StringToken);192 if(code == 0x27) emit() && switchto("data");193 else if(eof()) parseerror() && emit() && switchto("data");194 else if(newline(code)) parseerror() && emit(new BadStringToken) && switchto("data") && reconsume();195 else if(code == 0x5c) {196 if(badescape(next())) parseerror() && emit(new BadStringToken) && switchto("data");197 else if(newline(next())) consume();198 else currtoken.append(consumeEscape());199 }200 else currtoken.append(code);201 break;202 case "hash":203 if(namechar(code)) create(new HashToken(code)) && switchto("hash-rest");204 else if(code == 0x5c) {205 if(badescape(next())) parseerror() && emit(new DelimToken(0x23)) && switchto("data") && reconsume();206 else create(new HashToken(consumeEscape())) && switchto('hash-rest');207 }208 else emit(new DelimToken(0x23)) && switchto('data') && reconsume();209 break;210 case "hash-rest":211 if(namechar(code)) currtoken.append(code);212 else if(code == 0x5c) {213 if(badescape(next())) parseerror() && emit(new DelimToken(0x23)) && switchto("data") && reconsume();214 else currtoken.append(consumeEscape());215 }216 else emit() && switchto('data') && reconsume();217 break;218 case "comment":219 if(code == 0x2a) {220 if(next() == 0x2f) consume() && switchto('data');221 else donothing();222 }223 else if(eof()) parseerror() && switchto('data') && reconsume();224 else donothing();225 break;226 case "at-keyword":227 if(code == 0x2d) {228 if(namestartchar(next())) consume() && create(new AtKeywordToken([0x40,code])) && switchto('at-keyword-rest');229 else emit(new DelimToken(0x40)) && switchto('data') && reconsume();230 }231 else if(namestartchar(code)) create(new AtKeywordToken(code)) && switchto('at-keyword-rest');232 else if(code == 0x5c) {233 if(badescape(next())) parseerror() && emit(new DelimToken(0x23)) && switchto("data") && reconsume();234 else create(new AtKeywordToken(consumeEscape())) && switchto('at-keyword-rest');235 }236 else emit(new DelimToken(0x40)) && switchto('data') && reconsume();237 break;238 case "at-keyword-rest":239 if(namechar(code)) currtoken.append(code);240 else if(code == 0x5c) {241 if(badescape(next())) parseerror() && emit() && switchto("data") && reconsume();242 else currtoken.append(consumeEscape());243 }244 else emit() && switchto('data') && reconsume();245 break;246 case "identifier":247 if(code == 0x2d) {248 if(namestartchar(next())) create(new IdentifierToken(code)) && switchto('identifier-rest');249 else switchto('data') && reconsume();250 }251 else if(namestartchar(code)) create(new IdentifierToken(code)) && switchto('identifier-rest');252 else if(code == 0x5c) {253 if(badescape(next())) parseerror() && switchto("data") && reconsume();254 else create(new IdentifierToken(consumeEscape())) && switchto('identifier-rest');255 }256 else switchto('data') && reconsume();257 break;258 case "identifier-rest":259 if(namechar(code)) currtoken.append(code);260 else if(code == 0x5c) {261 if(badescape(next())) parseerror() && emit() && switchto("data") && reconsume();262 else currtoken.append(consumeEscape());263 }264 else if(code == 0x28) emit(new FunctionToken(currtoken)) && switchto('data');265 else if(whitespace(code) && options.transformFunctionWhitespace) switchto('transform-function-whitespace');266 else emit() && switchto('data') && reconsume();267 break;268 case "transform-function-whitespace":269 if(whitespace(code)) donothing();270 else if(code == 0x28) emit(new FunctionToken(currtoken)) && switchto('data');271 else emit() && switchto('data') && reconsume();272 break;273 case "number":274 create(new NumberToken());275 if(code == 0x2d) {276 if(digit(next())) consume() && currtoken.append([0x2d,code]) && switchto('number-rest');277 else if(next(1) == 0x2e && digit(next(2))) consume(2) && currtoken.append([0x2d,0x2e,code]) && switchto('number-fraction');278 else switchto('data') && reconsume();279 }280 else if(code == 0x2b) {281 if(digit(next())) consume() && currtoken.append([0x2b,code]) && switchto('number-rest');282 else if(next(1) == 0x2e && digit(next(2))) consume(2) && currtoken.append([0x2b,0x2e,code]) && switchto('number-fraction');283 else switchto('data') && reconsume();284 }285 else if(digit(code)) currtoken.append(code) && switchto('number-rest');286 else if(code == 0x2e) {287 if(digit(next())) consume() && currtoken.append([0x2e,code]) && switchto('number-fraction');288 else switchto('data') && reconsume();289 }290 else switchto('data') && reconsume();291 break;292 case "number-rest":293 if(digit(code)) currtoken.append(code);294 else if(code == 0x2e) {295 if(digit(next())) consume() && currtoken.append([0x2e,code]) && switchto('number-fraction');296 else emit() && switchto('data') && reconsume();297 }298 else if(code == 0x25) emit(new PercentageToken(currtoken)) && switchto('data') && reconsume();299 else if(code == 0x45 || code == 0x65) {300 if(!options.scientificNotation) create(new DimensionToken(currtoken,code)) && switchto('dimension');301 else if(digit(next())) consume() && currtoken.append([0x25,code]) && switchto('sci-notation');302 else if((next(1) == 0x2b || next(1) == 0x2d) && digit(next(2))) currtoken.append([0x25,next(1),next(2)]) && consume(2) && switchto('sci-notation');303 else create(new DimensionToken(currtoken,code)) && switchto('dimension');304 }305 else if(code == 0x2d) {306 if(namestartchar(next())) consume() && create(new DimensionToken(currtoken,[0x2d,code])) && switchto('dimension');307 else if(next(1) == 0x5c && badescape(next(2))) parseerror() && emit() && switchto('data') && reconsume();308 else if(next(1) == 0x5c) consume() && create(new DimensionToken(currtoken, [0x2d,consumeEscape()])) && switchto('dimension');309 else emit() && switchto('data') && reconsume();310 }311 else if(namestartchar(code)) create(new DimensionToken(currtoken, code)) && switchto('dimension');312 else if(code == 0x5c) {313 if(badescape(next)) emit() && switchto('data') && reconsume();314 else create(new DimensionToken(currtoken,consumeEscape)) && switchto('dimension');315 }316 else emit() && switchto('data') && reconsume();317 break;318 case "number-fraction":319 currtoken.type = "number";320 if(digit(code)) currtoken.append(code);321 else if(code == 0x2e) emit() && switchto('data') && reconsume();322 else if(code == 0x25) emit(new PercentageToken(currtoken)) && switchto('data') && reconsume();323 else if(code == 0x45 || code == 0x65) {324 if(!options.scientificNotation) create(new DimensionToken(currtoken,code)) && switchto('dimension');325 else if(digit(next())) consume() && currtoken.append([0x25,code]) && switchto('sci-notation');326 else if((next(1) == 0x2b || next(1) == 0x2d) && digit(next(2))) currtoken.append([0x25,next(1),next(2)]) && consume(2) && switchto('sci-notation');327 else create(new DimensionToken(currtoken,code)) && switchto('dimension');328 }329 else if(code == 0x2d) {330 if(namestartchar(next())) consume() && create(new DimensionToken(currtoken,[0x2d,code])) && switchto('dimension');331 else if(next(1) == 0x5c && badescape(next(2))) parseerror() && emit() && switchto('data') && reconsume();332 else if(next(1) == 0x5c) consume() && create(new DimensionToken(currtoken, [0x2d,consumeEscape()])) && switchto('dimension');333 else emit() && switchto('data') && reconsume();334 }335 else if(namestartchar(code)) create(new DimensionToken(currtoken, code)) && switchto('dimension');336 else if(code == 0x5c) {337 if(badescape(next)) emit() && switchto('data') && reconsume();338 else create(new DimensionToken(currtoken,consumeEscape)) && switchto('dimension');339 }340 else emit() && switchto('data') && reconsume();341 break;342 case "dimension":343 if(namechar(code)) currtoken.append(code);344 else if(code == 0x5c) {345 if(badescape(next())) parseerror() && emit() && switchto('data') && reconsume();346 else currtoken.append(consumeEscape());347 }348 else emit() && switchto('data') && reconsume();349 break;350 case "sci-notation":351 if(digit(code)) currtoken.append(code);352 else emit() && switchto('data') && reconsume();353 break;354 case "url":355 if(code == 0x22) switchto('url-double-quote');356 else if(code == 0x27) switchto('url-single-quote');357 else if(code == 0x29) emit(new URLToken) && switchto('data');358 else if(whitespace(code)) donothing();359 else switchto('url-unquoted') && reconsume();360 break;361 case "url-double-quote":362 if(currtoken == undefined) create(new URLToken);363 if(code == 0x22) switchto('url-end');364 else if(newline(code)) parseerror() && switchto('bad-url');365 else if(code == 0x5c) {366 if(newline(next())) consume();367 else if(badescape(next())) parseerror() && emit(new BadURLToken) && switchto('data') && reconsume();368 else currtoken.append(consumeEscape());369 }370 else currtoken.append(code);371 break;372 case "url-single-quote":373 if(currtoken == undefined) create(new URLToken);374 if(code == 0x27) switchto('url-end');375 else if(newline(code)) parseerror() && switchto('bad-url');376 else if(code == 0x5c) {377 if(newline(next())) consume();378 else if(badescape(next())) parseerror() && emit(new BadURLToken) && switchto('data') && reconsume();379 else currtoken.append(consumeEscape());380 }381 else currtoken.append(code);382 break;383 case "url-end":384 if(whitespace(code)) donothing();385 else if(code == 0x29) emit() && switchto('data');386 else parseerror() && switchto('bad-url') && reconsume();387 break;388 case "url-unquoted":389 if(currtoken == undefined) create(new URLToken);390 if(whitespace(code)) switchto('url-end');391 else if(code == 0x29) emit() && switchto('data');392 else if(code == 0x22 || code == 0x27 || code == 0x28 || nonprintable(code)) parseerror() && switchto('bad-url');393 else if(code == 0x5c) {394 if(badescape(next())) parseerror() && switchto('bad-url');395 else currtoken.append(consumeEscape());396 }397 else currtoken.append(code);398 break;399 case "bad-url":400 if(code == 0x29) emit(new BadURLToken) && switchto('data');401 else if(code == 0x5c) {402 if(badescape(next())) donothing();403 else consumeEscape()404 }405 else donothing();406 break;407 case "unicode-range":408 // We already know that the current code is a hexdigit.409 var start = [code], end = [code];410 for(var total = 1; total < 6; total++) {411 if(hexdigit(next())) {412 consume();413 start.push(code);414 end.push(code);415 }416 else break;417 }418 if(next() == 0x3f) {419 for(;total < 6; total++) {420 if(next() == 0x3f) {421 consume();422 start.push("0".charCodeAt(0));423 end.push("f".charCodeAt(0));424 }425 else break;426 }427 emit(new UnicodeRangeToken(start,end)) && switchto('data');428 }429 else if(next(1) == 0x2d && hexdigit(next(2))) {430 consume();431 consume();432 end = [code];433 for(var total = 1; total < 6; total++) {434 if(hexdigit(next())) {435 consume();436 end.push(code);437 }438 else break;439 }440 emit(new UnicodeRangeToken(start,end)) && switchto('data');441 }442 else emit(new UnicodeRangeToken(start)) && switchto('data');443 break;444 default:445 console.log("Unknown state '" + state + "'");446 }447 }448}449function stringFromCodeArray(arr) {450 return String.fromCharCode.apply(null,arr.filter(function(e){return e;}));451}452function CSSParserToken(options) { return this; }453CSSParserToken.prototype.finish = function() { return this; }454CSSParserToken.prototype.toString = function() { return this.tokenType; }455CSSParserToken.prototype.toJSON = function() { return this.toString(); }456function BadStringToken() { return this; }457BadStringToken.prototype = new CSSParserToken;458BadStringToken.prototype.tokenType = "BADSTRING";459function BadURLToken() { return this; }460BadURLToken.prototype = new CSSParserToken;461BadURLToken.prototype.tokenType = "BADURL";462function WhitespaceToken() { return this; }463WhitespaceToken.prototype = new CSSParserToken;464WhitespaceToken.prototype.tokenType = "WHITESPACE";465WhitespaceToken.prototype.toString = function() { return "WS"; }466function CDOToken() { return this; }467CDOToken.prototype = new CSSParserToken;468CDOToken.prototype.tokenType = "CDO";469function CDCToken() { return this; }470CDCToken.prototype = new CSSParserToken;471CDCToken.prototype.tokenType = "CDC";472function ColonToken() { return this; }473ColonToken.prototype = new CSSParserToken;474ColonToken.prototype.tokenType = ":";475function SemicolonToken() { return this; }476SemicolonToken.prototype = new CSSParserToken;477SemicolonToken.prototype.tokenType = ";";478function OpenCurlyToken() { return this; }479OpenCurlyToken.prototype = new CSSParserToken;480OpenCurlyToken.prototype.tokenType = "{";481function CloseCurlyToken() { return this; }482CloseCurlyToken.prototype = new CSSParserToken;483CloseCurlyToken.prototype.tokenType = "}";484function OpenSquareToken() { return this; }485OpenSquareToken.prototype = new CSSParserToken;486OpenSquareToken.prototype.tokenType = "[";487function CloseSquareToken() { return this; }488CloseSquareToken.prototype = new CSSParserToken;489CloseSquareToken.prototype.tokenType = "]";490function OpenParenToken() { return this; }491OpenParenToken.prototype = new CSSParserToken;492OpenParenToken.prototype.tokenType = "(";493function CloseParenToken() { return this; }494CloseParenToken.prototype = new CSSParserToken;495CloseParenToken.prototype.tokenType = ")";496function EOFToken() { return this; }497EOFToken.prototype = new CSSParserToken;498EOFToken.prototype.tokenType = "EOF";499function DelimToken(code) {500 this.value = String.fromCharCode(code);501 return this;502}503DelimToken.prototype = new CSSParserToken;504DelimToken.prototype.tokenType = "DELIM";505DelimToken.prototype.toString = function() { return "DELIM("+this.value+")"; }506function StringValuedToken() { return this; }507StringValuedToken.prototype = new CSSParserToken;508StringValuedToken.prototype.append = function(val) {509 if(val instanceof Array) {510 for(var i = 0; i < val.length; i++) {511 this.value.push(val[i]);512 }513 } else {...

Full Screen

Full Screen

DelimToken.js

Source:DelimToken.js Github

copy

Full Screen

...35 return null;36 }37 let tok = DelimToken.m_onto.try_parse(t, TerminParseAttr.NO);38 if (tok !== null) {39 let res = new DelimToken(t, tok.end_token);40 res.typ = DelimType.of(tok.termin.tag);41 res.doublt = tok.termin.tag2 !== null;42 let res2 = DelimToken.try_parse(res.end_token.next);43 if (res2 !== null) {44 if (res2.typ === res.typ) {45 res.end_token = res2.end_token;46 res.doublt = false;47 }48 }49 if (t.morph.class0.is_pronoun) {50 let npt = NounPhraseHelper.try_parse(t, NounPhraseParseAttr.PARSEADVERBS, 0, null);51 if (npt !== null && npt.end_char > res.end_char) 52 return null;53 }...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

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

Full Screen

Using AI Code Generation

copy

Full Screen

1const { DelimToken } = require("@playwright/test/lib/internal/tokenizer/delimToken");2const { Token } = require("@playwright/test/lib/internal/tokenizer/token");3const { Tokenizer } = require("@playwright/test/lib/internal/tokenizer/tokenizer");4const tokenizer = new Tokenizer();5const token = new Token();6token.type = Token.Type.STRING;7token.value = "test";8const delimToken = new DelimToken();9delimToken.token = token;10delimToken.delim = " ";11console.log(delimToken.value());12const { DelimToken } = require("./test");13const { Token } = require("./test");14const { Tokenizer } = require("./test");15const tokenizer = new Tokenizer();16const token = new Token();17token.type = Token.Type.STRING;18token.value = "test";19const delimToken = new DelimToken();20delimToken.token = token;21delimToken.delim = " ";22console.log(delimToken.value());23const { DelimToken } = require("./test");24const { Token } = require("./test");25const { Tokenizer } = require("./test");26const tokenizer = new Tokenizer();27const token = new Token();28token.type = Token.Type.STRING;29token.value = "test";30const delimToken = new DelimToken();31delimToken.token = token;32delimToken.delim = " ";33console.log(delimToken.value());34const { DelimToken } = require("./test");35const { Token } = require("./test");36const { Tokenizer } = require("./test");37const tokenizer = new Tokenizer();38const token = new Token();39token.type = Token.Type.STRING;40token.value = "test";41const delimToken = new DelimToken();42delimToken.token = token;43delimToken.delim = " ";44console.log(delimToken.value());45const { DelimToken } = require("./test");46const { Token } = require("./test");47const { Tokenizer } = require("./test");48const tokenizer = new Tokenizer();49const token = new Token();50token.type = Token.Type.STRING;51token.value = "test";52const delimToken = new DelimToken();53delimToken.token = token;54delimToken.delim = " ";55console.log(delimToken.value());56const { Delim

Full Screen

Using AI Code Generation

copy

Full Screen

1const { DelimToken } = require('playwright/lib/internal/test/test');2const { test } = require('@playwright/test');3test('test', async ({ page }) => {4 await page.fill('input[title="Search"]', 'test');5 await page.keyboard.press(DelimToken.Enter);6});7const { DelimToken } = require('playwright/lib/internal/test/test');8const { test } = require('@playwright/test');9test('test', async ({ page }) => {10 await page.fill('input[title="Search"]', 'test');11 await page.keyboard.press(DelimToken.Enter);12});13const { DelimToken } = require('playwright/lib/internal/test/test');14const { test } = require('@playwright/test');15test('test', async ({ page }) => {16 await page.fill('input[title="Search"]', 'test');17 await page.keyboard.press(DelimToken.Enter);18});19const { DelimToken } = require('playwright/lib/internal/test/test');20const { test } = require('@playwright/test');21test('test', async ({ page }) => {22 await page.fill('input[title="Search"]', 'test');23 await page.keyboard.press(DelimToken.Enter);24});

Full Screen

Using AI Code Generation

copy

Full Screen

1const { DelimToken } = require('playwright/lib/internal/protocol/driver');2const { Playwright } = require('playwright/lib/server/playwright');3const playwright = new Playwright(__dirname);4const { BrowserServer } = require('playwright/lib/server/browserServer');5const { BrowserType } = require('playwright/lib/server/browserType');6const { Browser } = require('playwright/lib/server/browser');7const { Page } = require('playwright/lib/server/page');8const { Frame } = require('playwright/lib/server/frame');9const { ElementHandle } = require('playwright/lib/server/elementHandler');10const { JSHandle } = require('playwright/lib/server/jsHandle');11const { Worker } = require('playwright/lib/server/worker');12const { BrowserContext } = require('playwright/lib/server/browserContext');13const { CDPSession } = require('playwright/lib/server/cdpsession');14const { Selectors } = require('playwright/lib/server/selectors');15const { FileChooser } = require('playwright/lib/server/fileChooser');16const { Download } = require('playwright/lib/server/download');17const { ConsoleMessage } = require('playwright/lib/server/consoleMessage');18const { Dialog } = require('playwright/lib/server/dialog');19const { WebSocketTransport } = require('playwright/lib/server/webSocketTransport');20const { PipeTransport } = require('playwright/lib/server/pipeTransport');21const { StreamTransport } = require('playwright/lib/server/streamTransport');22const { HttpServer } = require('playwright/lib/server/httpServer');23const { ProgressController } = require('playwright/lib/server/progress');24const { Progress } = require('playwright/lib/server/progress');25const { ConnectionTransport } = require('playwright/lib/server/webSocketTransport');26const { Connection } = require('playwright/lib/server/connection');27const { TimeoutError } = require('playwright/lib/errors');28const { helper } = require('playwright/lib/helper');29const { debugLogger } = require('playwright/lib/utils/debugLogger');30const { debugError } = require('playwright/lib/utils/debugLogger');31const { helper } = require('playwright/lib/helper');32const { TimeoutSettings } = require('playwright/lib/server/timeouts');33const { Events } = require('playwright/lib/server/events');34const { BrowserContextDispatcher } = require('playwright/lib/server/browserContextDispatcher');35const { BrowserTypeDispatcher

Full Screen

Using AI Code Generation

copy

Full Screen

1const { DelimToken } = require('playwright/lib/utils/selectorParser');2const selector = new DelimToken('>>');3console.log(selector);4DelimToken { value: '>>' }5const { SelectorParser } = require('playwright/lib/utils/selectorParser');6const parser = new SelectorParser(selector, { visibility: 'visible' });7const tokens = parser.parse();8console.log(tokens);9const { SelectorParser } = require('playwright/lib/utils/selectorParser');10const parser = new SelectorParser('>>');11const tokens = parser.parse();12console.log(tokens);13SelectorParser { tokens: [ DelimToken { value: '>>' } ] }14const { SelectorTokenizer } = require('playwright/lib/utils/selectorParser');15const tokenizer = new SelectorTokenizer(selector);16const tokens = tokenizer.tokenize();17console.log(tokens);18const { SelectorTokenizer } = require('playwright/lib/utils/selectorParser');19const tokenizer = new SelectorTokenizer('>>');20const tokens = tokenizer.tokenize();21console.log(tokens);22SelectorTokenizer { tokens: [ DelimToken { value: '>>' } ] }

Full Screen

Using AI Code Generation

copy

Full Screen

1const { DelimToken } = require('playwright');2const text = "This is a test text";3const delim = "test";4const delimToken = new DelimToken(delim);5console.log(text.includes(delimToken));6const { DelimToken } = require('playwright');7const text = "This is a test text";8const delim = "test";9const delimToken = new DelimToken(delim);10console.log(text.includes(delimToken));11const { DelimToken } = require('playwright');12const text = "This is a test text";13const delim = "test";14const delimToken = new DelimToken(delim);15console.log(text.includes(delimToken));16const { DelimToken } = require('playwright');17const text = "This is a test text";18const delim = "test";19const delimToken = new DelimToken(delim);20console.log(text.includes(delimToken));21const { DelimToken } = require('playwright');22const text = "This is a test text";23const delim = "test";24const delimToken = new DelimToken(delim);25console.log(text.includes(delimToken));26const { DelimToken } = require('playwright');27const text = "This is a test text";28const delim = "test";29const delimToken = new DelimToken(delim);30console.log(text.includes(delimToken));

Full Screen

Using AI Code Generation

copy

Full Screen

1const { DelimToken } = require('playwright/lib/utils/utils');2console.log(DelimToken(`"a b c"`, ' ', '"'));3const { DelimToken } = require('playwright/lib/utils/utils');4console.log(DelimToken(`a b c`, ' ', '"'));5const { DelimToken } = require('playwright/lib/utils/utils');6console.log(DelimToken(`"a b c`, ' ', '"'));7const { DelimToken } = require('playwright/lib/utils/utils');8console.log(DelimToken(`a b c"`, ' ', '"'));9const { DelimToken } = require('playwright/lib/utils/utils');10console.log(DelimToken(`"a b c"`, ' ', '"', true));11const { DelimToken } = require('playwright/lib/utils/utils');12console.log(DelimToken(`a b c`, ' ', '"', true));13const { DelimToken } = require('playwright/lib/utils/utils');14console.log(DelimToken(`"a b c`, ' ', '"', true));

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