How to use consume method in wpt

Best JavaScript code snippet using wpt

WebIDLParser.js

Source:WebIDLParser.js Github

copy

Full Screen

...119 120 var integer_type = function () {121 var ret = "";122 all_ws();123 if (consume(ID, "unsigned")) ret = "unsigned ";124 all_ws();125 if (consume(ID, "short")) return ret + "short";126 if (consume(ID, "long")) {127 ret += "long";128 all_ws();129 if (consume(ID, "long")) return ret + " long";130 return ret;131 }132 if (ret) error("Failed to parse integer type");133 };134 135 var float_type = function () {136 var ret = "";137 all_ws();138 if (consume(ID, "unrestricted")) ret = "unrestricted ";139 all_ws();140 if (consume(ID, "float")) return ret + "float";141 if (consume(ID, "double")) return ret + "double";142 if (ret) error("Failed to parse float type");143 };144 145 var primitive_type = function () {146 var num_type = integer_type() || float_type();147 if (num_type) return num_type;148 all_ws();149 if (consume(ID, "boolean")) return "boolean";150 if (consume(ID, "byte")) return "byte";151 if (consume(ID, "octet")) return "octet";152 };153 154 var const_value = function () {155 if (consume(ID, "true")) return { type: "boolean", value: true };156 if (consume(ID, "false")) return { type: "boolean", value: false };157 if (consume(ID, "null")) return { type: "null" };158 if (consume(ID, "Infinity")) return { type: "Infinity", negative: false };159 if (consume(ID, "NaN")) return { type: "NaN" };160 var ret = consume(FLOAT) || consume(INT);161 if (ret) return { type: "number", value: 1 * ret.value };162 var tok = consume(OTHER, "-");163 if (tok) {164 if (consume(ID, "Infinity")) return { type: "Infinity", negative: true };165 else tokens.unshift(tok);166 }167 };168 169 var type_suffix = function (obj) {170 while (true) {171 all_ws();172 if (consume(OTHER, "?")) {173 if (obj.nullable) error("Can't nullable more than once");174 obj.nullable = true;175 }176 else if (consume(OTHER, "[")) {177 all_ws();178 consume(OTHER, "]") || error("Unterminated array type");179 if (!obj.array) {180 obj.array = 1;181 obj.nullableArray = [obj.nullable];182 }183 else {184 obj.array++;185 obj.nullableArray.push(obj.nullable);186 }187 obj.nullable = false;188 }189 else return;190 }191 };192 193 var single_type = function () {194 var prim = primitive_type()195 , ret = { sequence: false, generic: null, nullable: false, array: false, union: false }196 , name197 , value198 ;199 if (prim) {200 ret.idlType = prim;201 }202 else if (name = consume(ID)) {203 value = name.value;204 all_ws();205 // Generic types206 if (consume(OTHER, "<")) {207 // backwards compat208 if (value === "sequence") {209 ret.sequence = true;210 }211 ret.generic = value;212 ret.idlType = type() || error("Error parsing generic type " + value);213 all_ws();214 if (!consume(OTHER, ">")) error("Unterminated generic type " + value);215 all_ws();216 if (consume(OTHER, "?")) ret.nullable = true;217 return ret;218 }219 else {220 ret.idlType = value;221 }222 }223 else {224 return;225 }226 type_suffix(ret);227 if (ret.nullable && !ret.array && ret.idlType === "any") error("Type any cannot be made nullable");228 return ret;229 };230 231 var union_type = function () {232 all_ws();233 if (!consume(OTHER, "(")) return;234 var ret = { sequence: false, generic: null, nullable: false, array: false, union: true, idlType: [] };235 var fst = type() || error("Union type with no content");236 ret.idlType.push(fst);237 while (true) {238 all_ws();239 if (!consume(ID, "or")) break;240 var typ = type() || error("No type after 'or' in union type");241 ret.idlType.push(typ);242 }243 if (!consume(OTHER, ")")) error("Unterminated union type");244 type_suffix(ret);245 return ret;246 };247 248 var type = function () {249 return single_type() || union_type();250 };251 252 var argument = function (store) {253 var ret = { optional: false, variadic: false };254 ret.extAttrs = extended_attrs(store);255 all_ws(store, "pea");256 var opt_token = consume(ID, "optional");257 if (opt_token) {258 ret.optional = true;259 all_ws();260 }261 ret.idlType = type();262 if (!ret.idlType) {263 if (opt_token) tokens.unshift(opt_token);264 return;265 }266 var type_token = last_token;267 if (!ret.optional) {268 all_ws();269 if (tokens.length >= 3 &&270 tokens[0].type === "other" && tokens[0].value === "." &&271 tokens[1].type === "other" && tokens[1].value === "." &&272 tokens[2].type === "other" && tokens[2].value === "."273 ) {274 tokens.shift();275 tokens.shift();276 tokens.shift();277 ret.variadic = true;278 }279 }280 all_ws();281 var name = consume(ID);282 if (!name) {283 if (opt_token) tokens.unshift(opt_token);284 tokens.unshift(type_token);285 return;286 }287 ret.name = name.value;288 if (ret.optional) {289 all_ws();290 ret["default"] = default_();291 }292 return ret;293 };294 295 var argument_list = function (store) {296 var ret = []297 , arg = argument(store ? ret : null)298 ;299 if (!arg) return;300 ret.push(arg);301 while (true) {302 all_ws(store ? ret : null);303 if (!consume(OTHER, ",")) return ret;304 var nxt = argument(store ? ret : null) || error("Trailing comma in arguments list");305 ret.push(nxt);306 }307 };308 309 var type_pair = function () {310 all_ws();311 var k = type();312 if (!k) return;313 all_ws()314 if (!consume(OTHER, ",")) return;315 all_ws();316 var v = type();317 if (!v) return;318 return [k, v];319 };320 321 var simple_extended_attr = function (store) {322 all_ws();323 var name = consume(ID);324 if (!name) return;325 var ret = {326 name: name.value327 , "arguments": null328 };329 all_ws();330 var eq = consume(OTHER, "=");331 if (eq) {332 all_ws();333 ret.rhs = consume(ID);334 if (!ret.rhs) return error("No right hand side to extended attribute assignment");335 }336 all_ws();337 if (consume(OTHER, "(")) {338 var args, pair;339 // [Constructor(DOMString str)]340 if (args = argument_list(store)) {341 ret["arguments"] = args;342 }343 // [MapClass(DOMString, DOMString)]344 else if (pair = type_pair()) {345 ret.typePair = pair;346 }347 // [Constructor()]348 else {349 ret["arguments"] = [];350 }351 all_ws();352 consume(OTHER, ")") || error("Unexpected token in extended attribute argument list or type pair");353 }354 return ret;355 };356 357 // Note: we parse something simpler than the official syntax. It's all that ever358 // seems to be used359 var extended_attrs = function (store) {360 var eas = [];361 all_ws(store);362 if (!consume(OTHER, "[")) return eas;363 eas[0] = simple_extended_attr(store) || error("Extended attribute with not content");364 all_ws();365 while (consume(OTHER, ",")) {366 eas.push(simple_extended_attr(store) || error("Trailing comma in extended attribute"));367 all_ws();368 }369 consume(OTHER, "]") || error("No end of extended attribute");370 return eas;371 };372 373 var default_ = function () {374 all_ws();375 if (consume(OTHER, "=")) {376 all_ws();377 var def = const_value();378 if (def) {379 return def;380 }381 else {382 var str = consume(STR) || error("No value for default");383 str.value = str.value.replace(/^"/, "").replace(/"$/, "");384 return str;385 }386 }387 };388 389 var const_ = function (store) {390 all_ws(store, "pea");391 if (!consume(ID, "const")) return;392 var ret = { type: "const", nullable: false };393 all_ws();394 var typ = primitive_type();395 if (!typ) {396 typ = consume(ID) || error("No type for const");397 typ = typ.value;398 }399 ret.idlType = typ;400 all_ws();401 if (consume(OTHER, "?")) {402 ret.nullable = true;403 all_ws();404 }405 var name = consume(ID) || error("No name for const");406 ret.name = name.value;407 all_ws();408 consume(OTHER, "=") || error("No value assignment for const");409 all_ws();410 var cnt = const_value();411 if (cnt) ret.value = cnt;412 else error("No value for const");413 all_ws();414 consume(OTHER, ";") || error("Unterminated const");415 return ret;416 };417 418 var inheritance = function () {419 all_ws();420 if (consume(OTHER, ":")) {421 all_ws();422 var inh = consume(ID) || error ("No type in inheritance");423 return inh.value;424 }425 };426 427 var operation_rest = function (ret, store) {428 all_ws();429 if (!ret) ret = {};430 var name = consume(ID);431 ret.name = name ? name.value : null;432 all_ws();433 consume(OTHER, "(") || error("Invalid operation");434 ret["arguments"] = argument_list(store) || [];435 all_ws();436 consume(OTHER, ")") || error("Unterminated operation");437 all_ws();438 consume(OTHER, ";") || error("Unterminated operation");439 return ret;440 };441 442 var callback = function (store) {443 all_ws(store, "pea");444 var ret;445 if (!consume(ID, "callback")) return;446 all_ws();447 var tok = consume(ID, "interface");448 if (tok) {449 tokens.unshift(tok);450 ret = interface_();451 ret.type = "callback interface";452 return ret;453 }454 var name = consume(ID) || error("No name for callback");455 ret = { type: "callback", name: name.value };456 all_ws();457 consume(OTHER, "=") || error("No assignment in callback");458 all_ws();459 ret.idlType = return_type();460 all_ws();461 consume(OTHER, "(") || error("No arguments in callback");462 ret["arguments"] = argument_list(store) || [];463 all_ws();464 consume(OTHER, ")") || error("Unterminated callback");465 all_ws();466 consume(OTHER, ";") || error("Unterminated callback");467 return ret;468 };469 var attribute = function (store) {470 all_ws(store, "pea");471 var grabbed = []472 , ret = {473 type: "attribute"474 , "static": false475 , stringifier: false476 , inherit: false477 , readonly: false478 };479 if (consume(ID, "static")) {480 ret["static"] = true;481 grabbed.push(last_token);482 }483 else if (consume(ID, "stringifier")) {484 ret.stringifier = true;485 grabbed.push(last_token);486 }487 var w = all_ws();488 if (w) grabbed.push(w);489 if (consume(ID, "inherit")) {490 if (ret["static"] || ret.stringifier) error("Cannot have a static or stringifier inherit");491 ret.inherit = true;492 grabbed.push(last_token);493 var w = all_ws();494 if (w) grabbed.push(w);495 }496 if (consume(ID, "readonly")) {497 ret.readonly = true;498 grabbed.push(last_token);499 var w = all_ws();500 if (w) grabbed.push(w);501 }502 if (!consume(ID, "attribute")) {503 tokens = grabbed.concat(tokens);504 return;505 }506 all_ws();507 ret.idlType = type() || error("No type in attribute");508 if (ret.idlType.sequence) error("Attributes cannot accept sequence types");509 all_ws();510 var name = consume(ID) || error("No name in attribute");511 ret.name = name.value;512 all_ws();513 consume(OTHER, ";") || error("Unterminated attribute");514 return ret;515 };516 517 var return_type = function () {518 var typ = type();519 if (!typ) {520 if (consume(ID, "void")) {521 return "void";522 }523 else error("No return type");524 }525 return typ;526 };527 528 var operation = function (store) {529 all_ws(store, "pea");530 var ret = {531 type: "operation"532 , getter: false533 , setter: false534 , creator: false535 , deleter: false536 , legacycaller: false537 , "static": false538 , stringifier: false539 };540 while (true) {541 all_ws();542 if (consume(ID, "getter")) ret.getter = true;543 else if (consume(ID, "setter")) ret.setter = true;544 else if (consume(ID, "creator")) ret.creator = true;545 else if (consume(ID, "deleter")) ret.deleter = true;546 else if (consume(ID, "legacycaller")) ret.legacycaller = true;547 else break;548 }549 if (ret.getter || ret.setter || ret.creator || ret.deleter || ret.legacycaller) {550 all_ws();551 ret.idlType = return_type();552 operation_rest(ret, store);553 return ret;554 }555 if (consume(ID, "static")) {556 ret["static"] = true;557 ret.idlType = return_type();558 operation_rest(ret, store);559 return ret;560 }561 else if (consume(ID, "stringifier")) {562 ret.stringifier = true;563 all_ws();564 if (consume(OTHER, ";")) return ret;565 ret.idlType = return_type();566 operation_rest(ret, store);567 return ret;568 }569 ret.idlType = return_type();570 all_ws();571 if (consume(ID, "iterator")) {572 all_ws();573 ret.type = "iterator";574 if (consume(ID, "object")) {575 ret.iteratorObject = "object";576 }577 else if (consume(OTHER, "=")) {578 all_ws();579 var name = consume(ID) || error("No right hand side in iterator");580 ret.iteratorObject = name.value;581 }582 all_ws();583 consume(OTHER, ";") || error("Unterminated iterator");584 return ret;585 }586 else {587 operation_rest(ret, store);588 return ret;589 }590 };591 592 var identifiers = function (arr) {593 while (true) {594 all_ws();595 if (consume(OTHER, ",")) {596 all_ws();597 var name = consume(ID) || error("Trailing comma in identifiers list");598 arr.push(name.value);599 }600 else break;601 }602 };603 604 var serialiser = function (store) {605 all_ws(store, "pea");606 if (!consume(ID, "serializer")) return;607 var ret = { type: "serializer" };608 all_ws();609 if (consume(OTHER, "=")) {610 all_ws();611 if (consume(OTHER, "{")) {612 ret.patternMap = true;613 all_ws();614 var id = consume(ID);615 if (id && id.value === "getter") {616 ret.names = ["getter"];617 }618 else if (id && id.value === "inherit") {619 ret.names = ["inherit"];620 identifiers(ret.names);621 }622 else if (id) {623 ret.names = [id.value];624 identifiers(ret.names);625 }626 else {627 ret.names = [];628 }629 all_ws();630 consume(OTHER, "}") || error("Unterminated serializer pattern map");631 }632 else if (consume(OTHER, "[")) {633 ret.patternList = true;634 all_ws();635 var id = consume(ID);636 if (id && id.value === "getter") {637 ret.names = ["getter"];638 }639 else if (id) {640 ret.names = [id.value];641 identifiers(ret.names);642 }643 else {644 ret.names = [];645 }646 all_ws();647 consume(OTHER, "]") || error("Unterminated serializer pattern list");648 }649 else {650 var name = consume(ID) || error("Invalid serializer");651 ret.name = name.value;652 }653 all_ws();654 consume(OTHER, ";") || error("Unterminated serializer");655 return ret;656 }657 else if (consume(OTHER, ";")) {658 // noop, just parsing659 }660 else {661 ret.idlType = return_type();662 all_ws();663 ret.operation = operation_rest(null, store);664 }665 return ret;666 };667 668 var interface_ = function (isPartial, store) {669 all_ws(isPartial ? null : store, "pea");670 if (!consume(ID, "interface")) return;671 all_ws();672 var name = consume(ID) || error("No name for interface");673 var mems = []674 , ret = {675 type: "interface"676 , name: name.value677 , partial: false678 , members: mems679 };680 if (!isPartial) ret.inheritance = inheritance() || null;681 all_ws();682 consume(OTHER, "{") || error("Bodyless interface");683 while (true) {684 all_ws(store ? mems : null);685 if (consume(OTHER, "}")) {686 all_ws();687 consume(OTHER, ";") || error("Missing semicolon after interface");688 return ret;689 }690 var ea = extended_attrs(store ? mems : null);691 all_ws();692 var cnt = const_(store ? mems : null);693 if (cnt) {694 cnt.extAttrs = ea;695 ret.members.push(cnt);696 continue;697 }698 var mem = serialiser(store ? mems : null) ||699 attribute(store ? mems : null) ||700 operation(store ? mems : null) ||701 error("Unknown member");702 mem.extAttrs = ea;703 ret.members.push(mem);704 }705 };706 707 var partial = function (store) {708 all_ws(store, "pea");709 if (!consume(ID, "partial")) return;710 var thing = dictionary(true, store) ||711 interface_(true, store) ||712 error("Partial doesn't apply to anything");713 thing.partial = true;714 return thing;715 };716 717 var dictionary = function (isPartial, store) {718 all_ws(isPartial ? null : store, "pea");719 if (!consume(ID, "dictionary")) return;720 all_ws();721 var name = consume(ID) || error("No name for dictionary");722 var mems = []723 , ret = {724 type: "dictionary"725 , name: name.value726 , partial: false727 , members: mems728 };729 if (!isPartial) ret.inheritance = inheritance() || null;730 all_ws();731 consume(OTHER, "{") || error("Bodyless dictionary");732 while (true) {733 all_ws(store ? mems : null);734 if (consume(OTHER, "}")) {735 all_ws();736 consume(OTHER, ";") || error("Missing semicolon after dictionary");737 return ret;738 }739 var ea = extended_attrs(store ? mems : null);740 all_ws(store ? mems : null, "pea");741 var typ = type() || error("No type for dictionary member");742 all_ws();743 var name = consume(ID) || error("No name for dictionary member");744 ret.members.push({745 type: "field"746 , name: name.value747 , idlType: typ748 , extAttrs: ea749 , "default": default_()750 });751 all_ws();752 consume(OTHER, ";") || error("Unterminated dictionary member");753 }754 };755 756 var exception = function (store) {757 all_ws(store, "pea");758 if (!consume(ID, "exception")) return;759 all_ws();760 var name = consume(ID) || error("No name for exception");761 var mems = []762 , ret = {763 type: "exception"764 , name: name.value765 , members: mems766 };767 ret.inheritance = inheritance() || null;768 all_ws();769 consume(OTHER, "{") || error("Bodyless exception");770 while (true) {771 all_ws(store ? mems : null);772 if (consume(OTHER, "}")) {773 all_ws();774 consume(OTHER, ";") || error("Missing semicolon after exception");775 return ret;776 }777 var ea = extended_attrs(store ? mems : null);778 all_ws(store ? mems : null, "pea");779 var cnt = const_();780 if (cnt) {781 cnt.extAttrs = ea;782 ret.members.push(cnt);783 }784 else {785 var typ = type();786 all_ws();787 var name = consume(ID);788 all_ws();789 if (!typ || !name || !consume(OTHER, ";")) error("Unknown member in exception body");790 ret.members.push({791 type: "field"792 , name: name.value793 , idlType: typ794 , extAttrs: ea795 });796 }797 }798 };799 800 var enum_ = function (store) {801 all_ws(store, "pea");802 if (!consume(ID, "enum")) return;803 all_ws();804 var name = consume(ID) || error("No name for enum");805 var vals = []806 , ret = {807 type: "enum"808 , name: name.value809 , values: vals810 };811 all_ws();812 consume(OTHER, "{") || error("No curly for enum");813 var saw_comma = false;814 while (true) {815 all_ws(store ? vals : null);816 if (consume(OTHER, "}")) {817 all_ws();818 if (saw_comma) error("Trailing comma in enum");819 consume(OTHER, ";") || error("No semicolon after enum");820 return ret;821 }822 var val = consume(STR) || error("Unexpected value in enum");823 ret.values.push(val.value.replace(/"/g, ""));824 all_ws(store ? vals : null);825 if (consume(OTHER, ",")) {826 if (store) vals.push({ type: "," });827 all_ws(store ? vals : null);828 saw_comma = true;829 }830 else {831 saw_comma = false;832 }833 }834 };835 836 var typedef = function (store) {837 all_ws(store, "pea");838 if (!consume(ID, "typedef")) return;839 var ret = {840 type: "typedef"841 };842 all_ws();843 ret.typeExtAttrs = extended_attrs();844 all_ws(store, "tpea");845 ret.idlType = type() || error("No type in typedef");846 all_ws();847 var name = consume(ID) || error("No name in typedef");848 ret.name = name.value;849 all_ws();850 consume(OTHER, ";") || error("Unterminated typedef");851 return ret;852 };853 854 var implements_ = function (store) {855 all_ws(store, "pea");856 var target = consume(ID);857 if (!target) return;858 var w = all_ws();859 if (consume(ID, "implements")) {860 var ret = {861 type: "implements"862 , target: target.value863 };864 all_ws();865 var imp = consume(ID) || error("Incomplete implements statement");866 ret["implements"] = imp.value;867 all_ws();868 consume(OTHER, ";") || error("No terminating ; for implements statement");869 return ret;870 }871 else {872 // rollback873 tokens.unshift(w);874 tokens.unshift(target);875 }876 };877 878 var definition = function (store) {879 return callback(store) ||880 interface_(false, store) ||881 partial(store) ||882 dictionary(false, store) ||...

Full Screen

Full Screen

webidl2.js

Source:webidl2.js Github

copy

Full Screen

...109 };110 var integer_type = function() {111 var ret = "";112 all_ws();113 if (consume(ID, "unsigned")) ret = "unsigned ";114 all_ws();115 if (consume(ID, "short")) return ret + "short";116 if (consume(ID, "long")) {117 ret += "long";118 all_ws();119 if (consume(ID, "long")) return ret + " long";120 return ret;121 }122 if (ret) error("Failed to parse integer type");123 };124 var float_type = function() {125 var ret = "";126 all_ws();127 if (consume(ID, "unrestricted")) ret = "unrestricted ";128 all_ws();129 if (consume(ID, "float")) return ret + "float";130 if (consume(ID, "double")) return ret + "double";131 if (ret) error("Failed to parse float type");132 };133 var primitive_type = function() {134 var num_type = integer_type() || float_type();135 if (num_type) return num_type;136 all_ws();137 if (consume(ID, "boolean")) return "boolean";138 if (consume(ID, "byte")) return "byte";139 if (consume(ID, "octet")) return "octet";140 };141 var const_value = function() {142 if (consume(ID, "true")) return { type: "boolean", value: true };143 if (consume(ID, "false")) return { type: "boolean", value: false };144 if (consume(ID, "null")) return { type: "null" };145 if (consume(ID, "Infinity")) return { type: "Infinity", negative: false };146 if (consume(ID, "NaN")) return { type: "NaN" };147 var ret = consume(FLOAT) || consume(INT);148 if (ret) return { type: "number", value: 1 * ret.value };149 var tok = consume(OTHER, "-");150 if (tok) {151 if (consume(ID, "Infinity")) return { type: "Infinity", negative: true };152 else tokens.unshift(tok);153 }154 };155 var type_suffix = function(obj) {156 while (true) {157 all_ws();158 if (consume(OTHER, "?")) {159 if (obj.nullable) error("Can't nullable more than once");160 obj.nullable = true;161 } else if (consume(OTHER, "[")) {162 all_ws();163 consume(OTHER, "]") || error("Unterminated array type");164 if (!obj.array) {165 obj.array = 1;166 obj.nullableArray = [obj.nullable];167 } else {168 obj.array++;169 obj.nullableArray.push(obj.nullable);170 }171 obj.nullable = false;172 } else return;173 }174 };175 var single_type = function() {176 var prim = primitive_type(),177 ret = { sequence: false, generic: null, nullable: false, array: false, union: false },178 name, value;179 if (prim) {180 ret.idlType = prim;181 } else if (name = consume(ID)) {182 value = name.value;183 all_ws();184 // Generic types185 if (consume(OTHER, "<")) {186 // backwards compat187 if (value === "sequence") {188 ret.sequence = true;189 }190 ret.generic = value;191 var types = [];192 do {193 all_ws();194 types.push(type() || error("Error parsing generic type " + value));195 all_ws();196 }197 while (consume(OTHER, ","));198 if (value === "sequence") {199 if (types.length !== 1) error("A sequence must have exactly one subtype");200 } else if (value === "record") {201 if (types.length !== 2) error("A record must have exactly two subtypes");202 if (!/^(DOMString|USVString|ByteString)$/.test(types[0].idlType)) {203 error("Record key must be DOMString, USVString, or ByteString");204 }205 }206 ret.idlType = types.length === 1 ? types[0] : types;207 all_ws();208 if (!consume(OTHER, ">")) error("Unterminated generic type " + value);209 type_suffix(ret);210 return ret;211 } else {212 ret.idlType = value;213 }214 } else {215 return;216 }217 type_suffix(ret);218 if (ret.nullable && !ret.array && ret.idlType === "any") error("Type any cannot be made nullable");219 return ret;220 };221 var union_type = function() {222 all_ws();223 if (!consume(OTHER, "(")) return;224 var ret = { sequence: false, generic: null, nullable: false, array: false, union: true, idlType: [] };225 var fst = type_with_extended_attributes() || error("Union type with no content");226 ret.idlType.push(fst);227 while (true) {228 all_ws();229 if (!consume(ID, "or")) break;230 var typ = type_with_extended_attributes() || error("No type after 'or' in union type");231 ret.idlType.push(typ);232 }233 if (!consume(OTHER, ")")) error("Unterminated union type");234 type_suffix(ret);235 return ret;236 };237 var type = function() {238 return single_type() || union_type();239 };240 var type_with_extended_attributes = function() {241 var extAttrs = extended_attrs();242 var ret = single_type() || union_type();243 if (extAttrs.length && ret) ret.extAttrs = extAttrs;244 return ret;245 };246 var argument = function(store) {247 var ret = { optional: false, variadic: false };248 ret.extAttrs = extended_attrs(store);249 all_ws(store, "pea");250 var opt_token = consume(ID, "optional");251 if (opt_token) {252 ret.optional = true;253 all_ws();254 }255 ret.idlType = type_with_extended_attributes();256 if (!ret.idlType) {257 if (opt_token) tokens.unshift(opt_token);258 return;259 }260 var type_token = last_token;261 if (!ret.optional) {262 all_ws();263 if (tokens.length >= 3 &&264 tokens[0].type === "other" && tokens[0].value === "." &&265 tokens[1].type === "other" && tokens[1].value === "." &&266 tokens[2].type === "other" && tokens[2].value === "."267 ) {268 tokens.shift();269 tokens.shift();270 tokens.shift();271 ret.variadic = true;272 }273 }274 all_ws();275 var name = consume(ID);276 if (!name) {277 if (opt_token) tokens.unshift(opt_token);278 tokens.unshift(type_token);279 return;280 }281 ret.name = name.value;282 if (ret.optional) {283 all_ws();284 var dflt = default_();285 if (typeof dflt !== "undefined") {286 ret["default"] = dflt;287 }288 }289 return ret;290 };291 var argument_list = function(store) {292 var ret = [],293 arg = argument(store ? ret : null);294 if (!arg) return;295 ret.push(arg);296 while (true) {297 all_ws(store ? ret : null);298 if (!consume(OTHER, ",")) return ret;299 var nxt = argument(store ? ret : null) || error("Trailing comma in arguments list");300 ret.push(nxt);301 }302 };303 var simple_extended_attr = function(store) {304 all_ws();305 var name = consume(ID);306 if (!name) return;307 var ret = {308 name: name.value,309 "arguments": null310 };311 all_ws();312 var eq = consume(OTHER, "=");313 if (eq) {314 var rhs;315 all_ws();316 if (rhs = consume(ID)) {317 ret.rhs = rhs;318 } else if (rhs = consume(FLOAT)) {319 ret.rhs = rhs;320 } else if (rhs = consume(INT)) {321 ret.rhs = rhs;322 } else if (rhs = consume(STR)) {323 ret.rhs = rhs;324 } else if (consume(OTHER, "(")) {325 // [Exposed=(Window,Worker)]326 rhs = [];327 var id = consume(ID);328 if (id) {329 rhs = [id.value];330 }331 identifiers(rhs);332 consume(OTHER, ")") || error("Unexpected token in extended attribute argument list or type pair");333 ret.rhs = {334 type: "identifier-list",335 value: rhs336 };337 }338 if (!ret.rhs) return error("No right hand side to extended attribute assignment");339 }340 all_ws();341 if (consume(OTHER, "(")) {342 var args, pair;343 // [Constructor(DOMString str)]344 if (args = argument_list(store)) {345 ret["arguments"] = args;346 }347 // [Constructor()]348 else {349 ret["arguments"] = [];350 }351 all_ws();352 consume(OTHER, ")") || error("Unexpected token in extended attribute argument list");353 }354 return ret;355 };356 // Note: we parse something simpler than the official syntax. It's all that ever357 // seems to be used358 var extended_attrs = function(store) {359 var eas = [];360 all_ws(store);361 if (!consume(OTHER, "[")) return eas;362 eas[0] = simple_extended_attr(store) || error("Extended attribute with not content");363 all_ws();364 while (consume(OTHER, ",")) {365 if (eas.length) {366 eas.push(simple_extended_attr(store));367 } else {368 eas.push(simple_extended_attr(store) || error("Trailing comma in extended attribute"));369 }370 }371 consume(OTHER, "]") || error("No end of extended attribute");372 return eas;373 };374 var default_ = function() {375 all_ws();376 if (consume(OTHER, "=")) {377 all_ws();378 var def = const_value();379 if (def) {380 return def;381 } else if (consume(OTHER, "[")) {382 if (!consume(OTHER, "]")) error("Default sequence value must be empty");383 return { type: "sequence", value: [] };384 } else {385 var str = consume(STR) || error("No value for default");386 str.value = str.value.replace(/^"/, "").replace(/"$/, "");387 return str;388 }389 }390 };391 var const_ = function(store) {392 all_ws(store, "pea");393 if (!consume(ID, "const")) return;394 var ret = { type: "const", nullable: false };395 all_ws();396 var typ = primitive_type();397 if (!typ) {398 typ = consume(ID) || error("No type for const");399 typ = typ.value;400 }401 ret.idlType = typ;402 all_ws();403 if (consume(OTHER, "?")) {404 ret.nullable = true;405 all_ws();406 }407 var name = consume(ID) || error("No name for const");408 ret.name = name.value;409 all_ws();410 consume(OTHER, "=") || error("No value assignment for const");411 all_ws();412 var cnt = const_value();413 if (cnt) ret.value = cnt;414 else error("No value for const");415 all_ws();416 consume(OTHER, ";") || error("Unterminated const");417 return ret;418 };419 var inheritance = function() {420 all_ws();421 if (consume(OTHER, ":")) {422 all_ws();423 var inh = consume(ID) || error("No type in inheritance");424 return inh.value;425 }426 };427 var operation_rest = function(ret, store) {428 all_ws();429 if (!ret) ret = {};430 var name = consume(ID);431 ret.name = name ? name.value : null;432 all_ws();433 consume(OTHER, "(") || error("Invalid operation");434 ret["arguments"] = argument_list(store) || [];435 all_ws();436 consume(OTHER, ")") || error("Unterminated operation");437 all_ws();438 consume(OTHER, ";") || error("Unterminated operation");439 return ret;440 };441 var callback = function(store) {442 all_ws(store, "pea");443 var ret;444 if (!consume(ID, "callback")) return;445 all_ws();446 var tok = consume(ID, "interface");447 if (tok) {448 tokens.unshift(tok);449 ret = interface_();450 ret.type = "callback interface";451 return ret;452 }453 var name = consume(ID) || error("No name for callback");454 ret = { type: "callback", name: name.value };455 all_ws();456 consume(OTHER, "=") || error("No assignment in callback");457 all_ws();458 ret.idlType = return_type();459 all_ws();460 consume(OTHER, "(") || error("No arguments in callback");461 ret["arguments"] = argument_list(store) || [];462 all_ws();463 consume(OTHER, ")") || error("Unterminated callback");464 all_ws();465 consume(OTHER, ";") || error("Unterminated callback");466 return ret;467 };468 var attribute = function(store) {469 all_ws(store, "pea");470 var grabbed = [],471 ret = {472 type: "attribute",473 "static": false,474 stringifier: false,475 inherit: false,476 readonly: false477 };478 if (consume(ID, "static")) {479 ret["static"] = true;480 grabbed.push(last_token);481 } else if (consume(ID, "stringifier")) {482 ret.stringifier = true;483 grabbed.push(last_token);484 }485 var w = all_ws();486 if (w) grabbed.push(w);487 if (consume(ID, "inherit")) {488 if (ret["static"] || ret.stringifier) error("Cannot have a static or stringifier inherit");489 ret.inherit = true;490 grabbed.push(last_token);491 var w = all_ws();492 if (w) grabbed.push(w);493 }494 if (consume(ID, "readonly")) {495 ret.readonly = true;496 grabbed.push(last_token);497 var w = all_ws();498 if (w) grabbed.push(w);499 }500 var rest = attribute_rest(ret);501 if (!rest) {502 tokens = grabbed.concat(tokens);503 }504 return rest;505 };506 var attribute_rest = function(ret) {507 if (!consume(ID, "attribute")) {508 return;509 }510 all_ws();511 ret.idlType = type_with_extended_attributes() || error("No type in attribute");512 if (ret.idlType.sequence) error("Attributes cannot accept sequence types");513 if (ret.idlType.generic === "record") error("Attributes cannot accept record types");514 all_ws();515 var name = consume(ID) || error("No name in attribute");516 ret.name = name.value;517 all_ws();518 consume(OTHER, ";") || error("Unterminated attribute");519 return ret;520 };521 var return_type = function() {522 var typ = type();523 if (!typ) {524 if (consume(ID, "void")) {525 return "void";526 } else error("No return type");527 }528 return typ;529 };530 var operation = function(store) {531 all_ws(store, "pea");532 var ret = {533 type: "operation",534 getter: false,535 setter: false,536 creator: false,537 deleter: false,538 legacycaller: false,539 "static": false,540 stringifier: false541 };542 while (true) {543 all_ws();544 if (consume(ID, "getter")) ret.getter = true;545 else if (consume(ID, "setter")) ret.setter = true;546 else if (consume(ID, "creator")) ret.creator = true;547 else if (consume(ID, "deleter")) ret.deleter = true;548 else if (consume(ID, "legacycaller")) ret.legacycaller = true;549 else break;550 }551 if (ret.getter || ret.setter || ret.creator || ret.deleter || ret.legacycaller) {552 all_ws();553 ret.idlType = return_type();554 operation_rest(ret, store);555 return ret;556 }557 if (consume(ID, "static")) {558 ret["static"] = true;559 ret.idlType = return_type();560 operation_rest(ret, store);561 return ret;562 } else if (consume(ID, "stringifier")) {563 ret.stringifier = true; -564 all_ws();565 if (consume(OTHER, ";")) return ret;566 ret.idlType = return_type();567 operation_rest(ret, store);568 return ret;569 }570 ret.idlType = return_type();571 all_ws();572 if (consume(ID, "iterator")) {573 all_ws();574 ret.type = "iterator";575 if (consume(ID, "object")) {576 ret.iteratorObject = "object";577 } else if (consume(OTHER, "=")) {578 all_ws();579 var name = consume(ID) || error("No right hand side in iterator");580 ret.iteratorObject = name.value;581 }582 all_ws();583 consume(OTHER, ";") || error("Unterminated iterator");584 return ret;585 } else {586 operation_rest(ret, store);587 return ret;588 }589 };590 var identifiers = function(arr) {591 while (true) {592 all_ws();593 if (consume(OTHER, ",")) {594 all_ws();595 var name = consume(ID) || error("Trailing comma in identifiers list");596 arr.push(name.value);597 } else break;598 }599 };600 var serialiser = function(store) {601 all_ws(store, "pea");602 if (!consume(ID, "serializer")) return;603 var ret = { type: "serializer" };604 all_ws();605 if (consume(OTHER, "=")) {606 all_ws();607 if (consume(OTHER, "{")) {608 ret.patternMap = true;609 all_ws();610 var id = consume(ID);611 if (id && id.value === "getter") {612 ret.names = ["getter"];613 } else if (id && id.value === "inherit") {614 ret.names = ["inherit"];615 identifiers(ret.names);616 } else if (id) {617 ret.names = [id.value];618 identifiers(ret.names);619 } else {620 ret.names = [];621 }622 all_ws();623 consume(OTHER, "}") || error("Unterminated serializer pattern map");624 } else if (consume(OTHER, "[")) {625 ret.patternList = true;626 all_ws();627 var id = consume(ID);628 if (id && id.value === "getter") {629 ret.names = ["getter"];630 } else if (id) {631 ret.names = [id.value];632 identifiers(ret.names);633 } else {634 ret.names = [];635 }636 all_ws();637 consume(OTHER, "]") || error("Unterminated serializer pattern list");638 } else {639 var name = consume(ID) || error("Invalid serializer");640 ret.name = name.value;641 }642 all_ws();643 consume(OTHER, ";") || error("Unterminated serializer");644 return ret;645 } else if (consume(OTHER, ";")) {646 // noop, just parsing647 } else {648 ret.idlType = return_type();649 all_ws();650 ret.operation = operation_rest(null, store);651 }652 return ret;653 };654 var iterable_type = function() {655 if (consume(ID, "iterable")) return "iterable";656 else if (consume(ID, "legacyiterable")) return "legacyiterable";657 else if (consume(ID, "maplike")) return "maplike";658 else if (consume(ID, "setlike")) return "setlike";659 else return;660 };661 var readonly_iterable_type = function() {662 if (consume(ID, "maplike")) return "maplike";663 else if (consume(ID, "setlike")) return "setlike";664 else return;665 };666 var iterable = function(store) {667 all_ws(store, "pea");668 var grabbed = [],669 ret = { type: null, idlType: null, readonly: false };670 if (consume(ID, "readonly")) {671 ret.readonly = true;672 grabbed.push(last_token);673 var w = all_ws();674 if (w) grabbed.push(w);675 }676 var consumeItType = ret.readonly ? readonly_iterable_type : iterable_type;677 var ittype = consumeItType();678 if (!ittype) {679 tokens = grabbed.concat(tokens);680 return;681 }682 var secondTypeRequired = ittype === "maplike";683 var secondTypeAllowed = secondTypeRequired || ittype === "iterable";684 ret.type = ittype;685 if (ret.type !== 'maplike' && ret.type !== 'setlike')686 delete ret.readonly;687 all_ws();688 if (consume(OTHER, "<")) {689 ret.idlType = type_with_extended_attributes() || error("Error parsing " + ittype + " declaration");690 all_ws();691 if (secondTypeAllowed) {692 var type2 = null;693 if (consume(OTHER, ",")) {694 all_ws();695 type2 = type_with_extended_attributes();696 all_ws();697 }698 if (type2)699 ret.idlType = [ret.idlType, type2];700 else if (secondTypeRequired)701 error("Missing second type argument in " + ittype + " declaration");702 }703 if (!consume(OTHER, ">")) error("Unterminated " + ittype + " declaration");704 all_ws();705 if (!consume(OTHER, ";")) error("Missing semicolon after " + ittype + " declaration");706 } else707 error("Error parsing " + ittype + " declaration");708 return ret;709 };710 var interface_ = function(isPartial, store) {711 all_ws(isPartial ? null : store, "pea");712 if (!consume(ID, "interface")) return;713 all_ws();714 var name = consume(ID) || error("No name for interface");715 var mems = [],716 ret = {717 type: "interface",718 name: name.value,719 partial: false,720 members: mems721 };722 if (!isPartial) ret.inheritance = inheritance() || null;723 all_ws();724 consume(OTHER, "{") || error("Bodyless interface");725 while (true) {726 all_ws(store ? mems : null);727 if (consume(OTHER, "}")) {728 all_ws();729 consume(OTHER, ";") || error("Missing semicolon after interface");730 return ret;731 }732 var ea = extended_attrs(store ? mems : null);733 all_ws();734 var cnt = const_(store ? mems : null);735 if (cnt) {736 cnt.extAttrs = ea;737 ret.members.push(cnt);738 continue;739 }740 var mem = (opt.allowNestedTypedefs && typedef(store ? mems : null)) ||741 iterable(store ? mems : null) ||742 serialiser(store ? mems : null) ||743 attribute(store ? mems : null) ||744 operation(store ? mems : null) ||745 error("Unknown member");746 mem.extAttrs = ea;747 ret.members.push(mem);748 }749 };750 var namespace = function(isPartial, store) {751 all_ws(isPartial ? null : store, "pea");752 if (!consume(ID, "namespace")) return;753 all_ws();754 var name = consume(ID) || error("No name for namespace");755 var mems = [],756 ret = {757 type: "namespace",758 name: name.value,759 partial: isPartial,760 members: mems761 };762 all_ws();763 consume(OTHER, "{") || error("Bodyless namespace");764 while (true) {765 all_ws(store ? mems : null);766 if (consume(OTHER, "}")) {767 all_ws();768 consume(OTHER, ";") || error("Missing semicolon after namespace");769 return ret;770 }771 var ea = extended_attrs(store ? mems : null);772 all_ws();773 var mem = noninherited_attribute(store ? mems : null) ||774 nonspecial_operation(store ? mems : null) ||775 error("Unknown member");776 mem.extAttrs = ea;777 ret.members.push(mem);778 }779 }780 var noninherited_attribute = function(store) {781 var w = all_ws(store, "pea"), 782 grabbed = [],783 ret = {784 type: "attribute",785 "static": false,786 stringifier: false,787 inherit: false,788 readonly: false789 };790 if (w) grabbed.push(w);791 if (consume(ID, "readonly")) {792 ret.readonly = true;793 grabbed.push(last_token);794 var w = all_ws();795 if (w) grabbed.push(w);796 }797 var rest = attribute_rest(ret);798 if (!rest) {799 tokens = grabbed.concat(tokens);800 }801 return rest;802 }803 804 var nonspecial_operation = function(store) {805 all_ws(store, "pea");806 var ret = {807 type: "operation",808 getter: false,809 setter: false,810 creator: false,811 deleter: false,812 legacycaller: false,813 "static": false,814 stringifier: false815 };816 ret.idlType = return_type();817 return operation_rest(ret, store);818 }819 var partial = function(store) {820 all_ws(store, "pea");821 if (!consume(ID, "partial")) return;822 var thing = dictionary(true, store) ||823 interface_(true, store) ||824 namespace(true, store) ||825 error("Partial doesn't apply to anything");826 thing.partial = true;827 return thing;828 };829 var dictionary = function(isPartial, store) {830 all_ws(isPartial ? null : store, "pea");831 if (!consume(ID, "dictionary")) return;832 all_ws();833 var name = consume(ID) || error("No name for dictionary");834 var mems = [],835 ret = {836 type: "dictionary",837 name: name.value,838 partial: false,839 members: mems840 };841 if (!isPartial) ret.inheritance = inheritance() || null;842 all_ws();843 consume(OTHER, "{") || error("Bodyless dictionary");844 while (true) {845 all_ws(store ? mems : null);846 if (consume(OTHER, "}")) {847 all_ws();848 consume(OTHER, ";") || error("Missing semicolon after dictionary");849 return ret;850 }851 var ea = extended_attrs(store ? mems : null);852 all_ws(store ? mems : null, "pea");853 var required = consume(ID, "required");854 var typ = type_with_extended_attributes() || error("No type for dictionary member");855 all_ws();856 var name = consume(ID) || error("No name for dictionary member");857 var dflt = default_();858 if (required && dflt) error("Required member must not have a default");859 var member = {860 type: "field",861 name: name.value,862 required: !!required,863 idlType: typ,864 extAttrs: ea865 };866 if (typeof dflt !== "undefined") {867 member["default"] = dflt;868 }869 ret.members.push(member);870 all_ws();871 consume(OTHER, ";") || error("Unterminated dictionary member");872 }873 };874 var exception = function(store) {875 all_ws(store, "pea");876 if (!consume(ID, "exception")) return;877 all_ws();878 var name = consume(ID) || error("No name for exception");879 var mems = [],880 ret = {881 type: "exception",882 name: name.value,883 members: mems884 };885 ret.inheritance = inheritance() || null;886 all_ws();887 consume(OTHER, "{") || error("Bodyless exception");888 while (true) {889 all_ws(store ? mems : null);890 if (consume(OTHER, "}")) {891 all_ws();892 consume(OTHER, ";") || error("Missing semicolon after exception");893 return ret;894 }895 var ea = extended_attrs(store ? mems : null);896 all_ws(store ? mems : null, "pea");897 var cnt = const_();898 if (cnt) {899 cnt.extAttrs = ea;900 ret.members.push(cnt);901 } else {902 var typ = type();903 all_ws();904 var name = consume(ID);905 all_ws();906 if (!typ || !name || !consume(OTHER, ";")) error("Unknown member in exception body");907 ret.members.push({908 type: "field",909 name: name.value,910 idlType: typ,911 extAttrs: ea912 });913 }914 }915 };916 var enum_ = function(store) {917 all_ws(store, "pea");918 if (!consume(ID, "enum")) return;919 all_ws();920 var name = consume(ID) || error("No name for enum");921 var vals = [],922 ret = {923 type: "enum",924 name: name.value,925 values: vals926 };927 all_ws();928 consume(OTHER, "{") || error("No curly for enum");929 var saw_comma = false;930 while (true) {931 all_ws(store ? vals : null);932 if (consume(OTHER, "}")) {933 all_ws();934 consume(OTHER, ";") || error("No semicolon after enum");935 return ret;936 }937 var val = consume(STR) || error("Unexpected value in enum");938 ret.values.push(val.value.replace(/"/g, ""));939 all_ws(store ? vals : null);940 if (consume(OTHER, ",")) {941 if (store) vals.push({ type: "," });942 all_ws(store ? vals : null);943 saw_comma = true;944 } else {945 saw_comma = false;946 }947 }948 };949 var typedef = function(store) {950 all_ws(store, "pea");951 if (!consume(ID, "typedef")) return;952 var ret = {953 type: "typedef"954 };955 all_ws();956 ret.idlType = type_with_extended_attributes() || error("No type in typedef");957 all_ws();958 var name = consume(ID) || error("No name in typedef");959 ret.name = name.value;960 all_ws();961 consume(OTHER, ";") || error("Unterminated typedef");962 return ret;963 };964 var implements_ = function(store) {965 all_ws(store, "pea");966 var target = consume(ID);967 if (!target) return;968 var w = all_ws();969 if (consume(ID, "implements")) {970 var ret = {971 type: "implements",972 target: target.value973 };974 all_ws();975 var imp = consume(ID) || error("Incomplete implements statement");976 ret["implements"] = imp.value;977 all_ws();978 consume(OTHER, ";") || error("No terminating ; for implements statement");979 return ret;980 } else {981 // rollback982 tokens.unshift(w);983 tokens.unshift(target);984 }985 };986 var definition = function(store) {987 return callback(store) ||988 interface_(false, store) ||989 partial(store) ||990 dictionary(false, store) ||991 exception(store) ||992 enum_(store) ||...

Full Screen

Full Screen

tokenizer.js

Source:tokenizer.js Github

copy

Full Screen

1// https://www.w3.org/TR/css-syntax-32import { fromCodePoint, toCodePoints } from 'css-line-break';3export var TokenType;4(function (TokenType) {5 TokenType[TokenType["STRING_TOKEN"] = 0] = "STRING_TOKEN";6 TokenType[TokenType["BAD_STRING_TOKEN"] = 1] = "BAD_STRING_TOKEN";7 TokenType[TokenType["LEFT_PARENTHESIS_TOKEN"] = 2] = "LEFT_PARENTHESIS_TOKEN";8 TokenType[TokenType["RIGHT_PARENTHESIS_TOKEN"] = 3] = "RIGHT_PARENTHESIS_TOKEN";9 TokenType[TokenType["COMMA_TOKEN"] = 4] = "COMMA_TOKEN";10 TokenType[TokenType["HASH_TOKEN"] = 5] = "HASH_TOKEN";11 TokenType[TokenType["DELIM_TOKEN"] = 6] = "DELIM_TOKEN";12 TokenType[TokenType["AT_KEYWORD_TOKEN"] = 7] = "AT_KEYWORD_TOKEN";13 TokenType[TokenType["PREFIX_MATCH_TOKEN"] = 8] = "PREFIX_MATCH_TOKEN";14 TokenType[TokenType["DASH_MATCH_TOKEN"] = 9] = "DASH_MATCH_TOKEN";15 TokenType[TokenType["INCLUDE_MATCH_TOKEN"] = 10] = "INCLUDE_MATCH_TOKEN";16 TokenType[TokenType["LEFT_CURLY_BRACKET_TOKEN"] = 11] = "LEFT_CURLY_BRACKET_TOKEN";17 TokenType[TokenType["RIGHT_CURLY_BRACKET_TOKEN"] = 12] = "RIGHT_CURLY_BRACKET_TOKEN";18 TokenType[TokenType["SUFFIX_MATCH_TOKEN"] = 13] = "SUFFIX_MATCH_TOKEN";19 TokenType[TokenType["SUBSTRING_MATCH_TOKEN"] = 14] = "SUBSTRING_MATCH_TOKEN";20 TokenType[TokenType["DIMENSION_TOKEN"] = 15] = "DIMENSION_TOKEN";21 TokenType[TokenType["PERCENTAGE_TOKEN"] = 16] = "PERCENTAGE_TOKEN";22 TokenType[TokenType["NUMBER_TOKEN"] = 17] = "NUMBER_TOKEN";23 TokenType[TokenType["FUNCTION"] = 18] = "FUNCTION";24 TokenType[TokenType["FUNCTION_TOKEN"] = 19] = "FUNCTION_TOKEN";25 TokenType[TokenType["IDENT_TOKEN"] = 20] = "IDENT_TOKEN";26 TokenType[TokenType["COLUMN_TOKEN"] = 21] = "COLUMN_TOKEN";27 TokenType[TokenType["URL_TOKEN"] = 22] = "URL_TOKEN";28 TokenType[TokenType["BAD_URL_TOKEN"] = 23] = "BAD_URL_TOKEN";29 TokenType[TokenType["CDC_TOKEN"] = 24] = "CDC_TOKEN";30 TokenType[TokenType["CDO_TOKEN"] = 25] = "CDO_TOKEN";31 TokenType[TokenType["COLON_TOKEN"] = 26] = "COLON_TOKEN";32 TokenType[TokenType["SEMICOLON_TOKEN"] = 27] = "SEMICOLON_TOKEN";33 TokenType[TokenType["LEFT_SQUARE_BRACKET_TOKEN"] = 28] = "LEFT_SQUARE_BRACKET_TOKEN";34 TokenType[TokenType["RIGHT_SQUARE_BRACKET_TOKEN"] = 29] = "RIGHT_SQUARE_BRACKET_TOKEN";35 TokenType[TokenType["UNICODE_RANGE_TOKEN"] = 30] = "UNICODE_RANGE_TOKEN";36 TokenType[TokenType["WHITESPACE_TOKEN"] = 31] = "WHITESPACE_TOKEN";37 TokenType[TokenType["EOF_TOKEN"] = 32] = "EOF_TOKEN";38})(TokenType || (TokenType = {}));39export const FLAG_UNRESTRICTED = 1 << 0;40export const FLAG_ID = 1 << 1;41export const FLAG_INTEGER = 1 << 2;42export const FLAG_NUMBER = 1 << 3;43const LINE_FEED = 0x000a;44const SOLIDUS = 0x002f;45const REVERSE_SOLIDUS = 0x005c;46const CHARACTER_TABULATION = 0x0009;47const SPACE = 0x0020;48const QUOTATION_MARK = 0x0022;49const EQUALS_SIGN = 0x003d;50const NUMBER_SIGN = 0x0023;51const DOLLAR_SIGN = 0x0024;52const PERCENTAGE_SIGN = 0x0025;53const APOSTROPHE = 0x0027;54const LEFT_PARENTHESIS = 0x0028;55const RIGHT_PARENTHESIS = 0x0029;56const LOW_LINE = 0x005f;57const HYPHEN_MINUS = 0x002d;58const EXCLAMATION_MARK = 0x0021;59const LESS_THAN_SIGN = 0x003c;60const GREATER_THAN_SIGN = 0x003e;61const COMMERCIAL_AT = 0x0040;62const LEFT_SQUARE_BRACKET = 0x005b;63const RIGHT_SQUARE_BRACKET = 0x005d;64const CIRCUMFLEX_ACCENT = 0x003d;65const LEFT_CURLY_BRACKET = 0x007b;66const QUESTION_MARK = 0x003f;67const RIGHT_CURLY_BRACKET = 0x007d;68const VERTICAL_LINE = 0x007c;69const TILDE = 0x007e;70const CONTROL = 0x0080;71const REPLACEMENT_CHARACTER = 0xfffd;72const ASTERISK = 0x002a;73const PLUS_SIGN = 0x002b;74const COMMA = 0x002c;75const COLON = 0x003a;76const SEMICOLON = 0x003b;77const FULL_STOP = 0x002e;78const NULL = 0x0000;79const BACKSPACE = 0x0008;80const LINE_TABULATION = 0x000b;81const SHIFT_OUT = 0x000e;82const INFORMATION_SEPARATOR_ONE = 0x001f;83const DELETE = 0x007f;84const EOF = -1;85const ZERO = 0x0030;86const a = 0x0061;87const e = 0x0065;88const f = 0x0066;89const u = 0x0075;90const z = 0x007a;91const A = 0x0041;92const E = 0x0045;93const F = 0x0046;94const U = 0x0055;95const Z = 0x005a;96const isDigit = (codePoint) => codePoint >= ZERO && codePoint <= 0x0039;97const isSurrogateCodePoint = (codePoint) => codePoint >= 0xd800 && codePoint <= 0xdfff;98const isHex = (codePoint) => isDigit(codePoint) || (codePoint >= A && codePoint <= F) || (codePoint >= a && codePoint <= f);99const isLowerCaseLetter = (codePoint) => codePoint >= a && codePoint <= z;100const isUpperCaseLetter = (codePoint) => codePoint >= A && codePoint <= Z;101const isLetter = (codePoint) => isLowerCaseLetter(codePoint) || isUpperCaseLetter(codePoint);102const isNonASCIICodePoint = (codePoint) => codePoint >= CONTROL;103const isWhiteSpace = (codePoint) => codePoint === LINE_FEED || codePoint === CHARACTER_TABULATION || codePoint === SPACE;104const isNameStartCodePoint = (codePoint) => isLetter(codePoint) || isNonASCIICodePoint(codePoint) || codePoint === LOW_LINE;105const isNameCodePoint = (codePoint) => isNameStartCodePoint(codePoint) || isDigit(codePoint) || codePoint === HYPHEN_MINUS;106const isNonPrintableCodePoint = (codePoint) => {107 return ((codePoint >= NULL && codePoint <= BACKSPACE) ||108 codePoint === LINE_TABULATION ||109 (codePoint >= SHIFT_OUT && codePoint <= INFORMATION_SEPARATOR_ONE) ||110 codePoint === DELETE);111};112const isValidEscape = (c1, c2) => {113 if (c1 !== REVERSE_SOLIDUS) {114 return false;115 }116 return c2 !== LINE_FEED;117};118const isIdentifierStart = (c1, c2, c3) => {119 if (c1 === HYPHEN_MINUS) {120 return isNameStartCodePoint(c2) || isValidEscape(c2, c3);121 }122 else if (isNameStartCodePoint(c1)) {123 return true;124 }125 else if (c1 === REVERSE_SOLIDUS && isValidEscape(c1, c2)) {126 return true;127 }128 return false;129};130const isNumberStart = (c1, c2, c3) => {131 if (c1 === PLUS_SIGN || c1 === HYPHEN_MINUS) {132 if (isDigit(c2)) {133 return true;134 }135 return c2 === FULL_STOP && isDigit(c3);136 }137 if (c1 === FULL_STOP) {138 return isDigit(c2);139 }140 return isDigit(c1);141};142const stringToNumber = (codePoints) => {143 let c = 0;144 let sign = 1;145 if (codePoints[c] === PLUS_SIGN || codePoints[c] === HYPHEN_MINUS) {146 if (codePoints[c] === HYPHEN_MINUS) {147 sign = -1;148 }149 c++;150 }151 const integers = [];152 while (isDigit(codePoints[c])) {153 integers.push(codePoints[c++]);154 }155 const int = integers.length ? parseInt(fromCodePoint(...integers), 10) : 0;156 if (codePoints[c] === FULL_STOP) {157 c++;158 }159 const fraction = [];160 while (isDigit(codePoints[c])) {161 fraction.push(codePoints[c++]);162 }163 const fracd = fraction.length;164 const frac = fracd ? parseInt(fromCodePoint(...fraction), 10) : 0;165 if (codePoints[c] === E || codePoints[c] === e) {166 c++;167 }168 let expsign = 1;169 if (codePoints[c] === PLUS_SIGN || codePoints[c] === HYPHEN_MINUS) {170 if (codePoints[c] === HYPHEN_MINUS) {171 expsign = -1;172 }173 c++;174 }175 const exponent = [];176 while (isDigit(codePoints[c])) {177 exponent.push(codePoints[c++]);178 }179 const exp = exponent.length ? parseInt(fromCodePoint(...exponent), 10) : 0;180 return sign * (int + frac * Math.pow(10, -fracd)) * Math.pow(10, expsign * exp);181};182const LEFT_PARENTHESIS_TOKEN = {183 type: TokenType.LEFT_PARENTHESIS_TOKEN184};185const RIGHT_PARENTHESIS_TOKEN = {186 type: TokenType.RIGHT_PARENTHESIS_TOKEN187};188const COMMA_TOKEN = { type: TokenType.COMMA_TOKEN };189const SUFFIX_MATCH_TOKEN = { type: TokenType.SUFFIX_MATCH_TOKEN };190const PREFIX_MATCH_TOKEN = { type: TokenType.PREFIX_MATCH_TOKEN };191const COLUMN_TOKEN = { type: TokenType.COLUMN_TOKEN };192const DASH_MATCH_TOKEN = { type: TokenType.DASH_MATCH_TOKEN };193const INCLUDE_MATCH_TOKEN = { type: TokenType.INCLUDE_MATCH_TOKEN };194const LEFT_CURLY_BRACKET_TOKEN = {195 type: TokenType.LEFT_CURLY_BRACKET_TOKEN196};197const RIGHT_CURLY_BRACKET_TOKEN = {198 type: TokenType.RIGHT_CURLY_BRACKET_TOKEN199};200const SUBSTRING_MATCH_TOKEN = { type: TokenType.SUBSTRING_MATCH_TOKEN };201const BAD_URL_TOKEN = { type: TokenType.BAD_URL_TOKEN };202const BAD_STRING_TOKEN = { type: TokenType.BAD_STRING_TOKEN };203const CDO_TOKEN = { type: TokenType.CDO_TOKEN };204const CDC_TOKEN = { type: TokenType.CDC_TOKEN };205const COLON_TOKEN = { type: TokenType.COLON_TOKEN };206const SEMICOLON_TOKEN = { type: TokenType.SEMICOLON_TOKEN };207const LEFT_SQUARE_BRACKET_TOKEN = {208 type: TokenType.LEFT_SQUARE_BRACKET_TOKEN209};210const RIGHT_SQUARE_BRACKET_TOKEN = {211 type: TokenType.RIGHT_SQUARE_BRACKET_TOKEN212};213const WHITESPACE_TOKEN = { type: TokenType.WHITESPACE_TOKEN };214export const EOF_TOKEN = { type: TokenType.EOF_TOKEN };215export class Tokenizer {216 constructor() {217 this._value = [];218 }219 write(chunk) {220 this._value = this._value.concat(toCodePoints(chunk));221 }222 read() {223 const tokens = [];224 let token = this.consumeToken();225 while (token !== EOF_TOKEN) {226 tokens.push(token);227 token = this.consumeToken();228 }229 return tokens;230 }231 consumeToken() {232 const codePoint = this.consumeCodePoint();233 switch (codePoint) {234 case QUOTATION_MARK:235 return this.consumeStringToken(QUOTATION_MARK);236 case NUMBER_SIGN:237 const c1 = this.peekCodePoint(0);238 const c2 = this.peekCodePoint(1);239 const c3 = this.peekCodePoint(2);240 if (isNameCodePoint(c1) || isValidEscape(c2, c3)) {241 const flags = isIdentifierStart(c1, c2, c3) ? FLAG_ID : FLAG_UNRESTRICTED;242 const value = this.consumeName();243 return { type: TokenType.HASH_TOKEN, value, flags };244 }245 break;246 case DOLLAR_SIGN:247 if (this.peekCodePoint(0) === EQUALS_SIGN) {248 this.consumeCodePoint();249 return SUFFIX_MATCH_TOKEN;250 }251 break;252 case APOSTROPHE:253 return this.consumeStringToken(APOSTROPHE);254 case LEFT_PARENTHESIS:255 return LEFT_PARENTHESIS_TOKEN;256 case RIGHT_PARENTHESIS:257 return RIGHT_PARENTHESIS_TOKEN;258 case ASTERISK:259 if (this.peekCodePoint(0) === EQUALS_SIGN) {260 this.consumeCodePoint();261 return SUBSTRING_MATCH_TOKEN;262 }263 break;264 case PLUS_SIGN:265 if (isNumberStart(codePoint, this.peekCodePoint(0), this.peekCodePoint(1))) {266 this.reconsumeCodePoint(codePoint);267 return this.consumeNumericToken();268 }269 break;270 case COMMA:271 return COMMA_TOKEN;272 case HYPHEN_MINUS:273 const e1 = codePoint;274 const e2 = this.peekCodePoint(0);275 const e3 = this.peekCodePoint(1);276 if (isNumberStart(e1, e2, e3)) {277 this.reconsumeCodePoint(codePoint);278 return this.consumeNumericToken();279 }280 if (isIdentifierStart(e1, e2, e3)) {281 this.reconsumeCodePoint(codePoint);282 return this.consumeIdentLikeToken();283 }284 if (e2 === HYPHEN_MINUS && e3 === GREATER_THAN_SIGN) {285 this.consumeCodePoint();286 this.consumeCodePoint();287 return CDC_TOKEN;288 }289 break;290 case FULL_STOP:291 if (isNumberStart(codePoint, this.peekCodePoint(0), this.peekCodePoint(1))) {292 this.reconsumeCodePoint(codePoint);293 return this.consumeNumericToken();294 }295 break;296 case SOLIDUS:297 if (this.peekCodePoint(0) === ASTERISK) {298 this.consumeCodePoint();299 while (true) {300 let c = this.consumeCodePoint();301 if (c === ASTERISK) {302 c = this.consumeCodePoint();303 if (c === SOLIDUS) {304 return this.consumeToken();305 }306 }307 if (c === EOF) {308 return this.consumeToken();309 }310 }311 }312 break;313 case COLON:314 return COLON_TOKEN;315 case SEMICOLON:316 return SEMICOLON_TOKEN;317 case LESS_THAN_SIGN:318 if (this.peekCodePoint(0) === EXCLAMATION_MARK &&319 this.peekCodePoint(1) === HYPHEN_MINUS &&320 this.peekCodePoint(2) === HYPHEN_MINUS) {321 this.consumeCodePoint();322 this.consumeCodePoint();323 return CDO_TOKEN;324 }325 break;326 case COMMERCIAL_AT:327 const a1 = this.peekCodePoint(0);328 const a2 = this.peekCodePoint(1);329 const a3 = this.peekCodePoint(2);330 if (isIdentifierStart(a1, a2, a3)) {331 const value = this.consumeName();332 return { type: TokenType.AT_KEYWORD_TOKEN, value };333 }334 break;335 case LEFT_SQUARE_BRACKET:336 return LEFT_SQUARE_BRACKET_TOKEN;337 case REVERSE_SOLIDUS:338 if (isValidEscape(codePoint, this.peekCodePoint(0))) {339 this.reconsumeCodePoint(codePoint);340 return this.consumeIdentLikeToken();341 }342 break;343 case RIGHT_SQUARE_BRACKET:344 return RIGHT_SQUARE_BRACKET_TOKEN;345 case CIRCUMFLEX_ACCENT:346 if (this.peekCodePoint(0) === EQUALS_SIGN) {347 this.consumeCodePoint();348 return PREFIX_MATCH_TOKEN;349 }350 break;351 case LEFT_CURLY_BRACKET:352 return LEFT_CURLY_BRACKET_TOKEN;353 case RIGHT_CURLY_BRACKET:354 return RIGHT_CURLY_BRACKET_TOKEN;355 case u:356 case U:357 const u1 = this.peekCodePoint(0);358 const u2 = this.peekCodePoint(1);359 if (u1 === PLUS_SIGN && (isHex(u2) || u2 === QUESTION_MARK)) {360 this.consumeCodePoint();361 this.consumeUnicodeRangeToken();362 }363 this.reconsumeCodePoint(codePoint);364 return this.consumeIdentLikeToken();365 case VERTICAL_LINE:366 if (this.peekCodePoint(0) === EQUALS_SIGN) {367 this.consumeCodePoint();368 return DASH_MATCH_TOKEN;369 }370 if (this.peekCodePoint(0) === VERTICAL_LINE) {371 this.consumeCodePoint();372 return COLUMN_TOKEN;373 }374 break;375 case TILDE:376 if (this.peekCodePoint(0) === EQUALS_SIGN) {377 this.consumeCodePoint();378 return INCLUDE_MATCH_TOKEN;379 }380 break;381 case EOF:382 return EOF_TOKEN;383 }384 if (isWhiteSpace(codePoint)) {385 this.consumeWhiteSpace();386 return WHITESPACE_TOKEN;387 }388 if (isDigit(codePoint)) {389 this.reconsumeCodePoint(codePoint);390 return this.consumeNumericToken();391 }392 if (isNameStartCodePoint(codePoint)) {393 this.reconsumeCodePoint(codePoint);394 return this.consumeIdentLikeToken();395 }396 return { type: TokenType.DELIM_TOKEN, value: fromCodePoint(codePoint) };397 }398 consumeCodePoint() {399 const value = this._value.shift();400 return typeof value === 'undefined' ? -1 : value;401 }402 reconsumeCodePoint(codePoint) {403 this._value.unshift(codePoint);404 }405 peekCodePoint(delta) {406 if (delta >= this._value.length) {407 return -1;408 }409 return this._value[delta];410 }411 consumeUnicodeRangeToken() {412 const digits = [];413 let codePoint = this.consumeCodePoint();414 while (isHex(codePoint) && digits.length < 6) {415 digits.push(codePoint);416 codePoint = this.consumeCodePoint();417 }418 let questionMarks = false;419 while (codePoint === QUESTION_MARK && digits.length < 6) {420 digits.push(codePoint);421 codePoint = this.consumeCodePoint();422 questionMarks = true;423 }424 if (questionMarks) {425 const start = parseInt(fromCodePoint(...digits.map(digit => (digit === QUESTION_MARK ? ZERO : digit))), 16);426 const end = parseInt(fromCodePoint(...digits.map(digit => (digit === QUESTION_MARK ? F : digit))), 16);427 return { type: TokenType.UNICODE_RANGE_TOKEN, start, end };428 }429 const start = parseInt(fromCodePoint(...digits), 16);430 if (this.peekCodePoint(0) === HYPHEN_MINUS && isHex(this.peekCodePoint(1))) {431 this.consumeCodePoint();432 codePoint = this.consumeCodePoint();433 const endDigits = [];434 while (isHex(codePoint) && endDigits.length < 6) {435 endDigits.push(codePoint);436 codePoint = this.consumeCodePoint();437 }438 const end = parseInt(fromCodePoint(...endDigits), 16);439 return { type: TokenType.UNICODE_RANGE_TOKEN, start, end };440 }441 else {442 return { type: TokenType.UNICODE_RANGE_TOKEN, start, end: start };443 }444 }445 consumeIdentLikeToken() {446 const value = this.consumeName();447 if (value.toLowerCase() === 'url' && this.peekCodePoint(0) === LEFT_PARENTHESIS) {448 this.consumeCodePoint();449 return this.consumeUrlToken();450 }451 else if (this.peekCodePoint(0) === LEFT_PARENTHESIS) {452 this.consumeCodePoint();453 return { type: TokenType.FUNCTION_TOKEN, value };454 }455 return { type: TokenType.IDENT_TOKEN, value };456 }457 consumeUrlToken() {458 const value = [];459 this.consumeWhiteSpace();460 if (this.peekCodePoint(0) === EOF) {461 return { type: TokenType.URL_TOKEN, value: '' };462 }463 const next = this.peekCodePoint(0);464 if (next === APOSTROPHE || next === QUOTATION_MARK) {465 const stringToken = this.consumeStringToken(this.consumeCodePoint());466 if (stringToken.type === TokenType.STRING_TOKEN) {467 this.consumeWhiteSpace();468 if (this.peekCodePoint(0) === EOF || this.peekCodePoint(0) === RIGHT_PARENTHESIS) {469 this.consumeCodePoint();470 return { type: TokenType.URL_TOKEN, value: stringToken.value };471 }472 }473 this.consumeBadUrlRemnants();474 return BAD_URL_TOKEN;475 }476 while (true) {477 const codePoint = this.consumeCodePoint();478 if (codePoint === EOF || codePoint === RIGHT_PARENTHESIS) {479 return { type: TokenType.URL_TOKEN, value: fromCodePoint(...value) };480 }481 else if (isWhiteSpace(codePoint)) {482 this.consumeWhiteSpace();483 if (this.peekCodePoint(0) === EOF || this.peekCodePoint(0) === RIGHT_PARENTHESIS) {484 this.consumeCodePoint();485 return { type: TokenType.URL_TOKEN, value: fromCodePoint(...value) };486 }487 this.consumeBadUrlRemnants();488 return BAD_URL_TOKEN;489 }490 else if (codePoint === QUOTATION_MARK ||491 codePoint === APOSTROPHE ||492 codePoint === LEFT_PARENTHESIS ||493 isNonPrintableCodePoint(codePoint)) {494 this.consumeBadUrlRemnants();495 return BAD_URL_TOKEN;496 }497 else if (codePoint === REVERSE_SOLIDUS) {498 if (isValidEscape(codePoint, this.peekCodePoint(0))) {499 value.push(this.consumeEscapedCodePoint());500 }501 else {502 this.consumeBadUrlRemnants();503 return BAD_URL_TOKEN;504 }505 }506 else {507 value.push(codePoint);508 }509 }510 }511 consumeWhiteSpace() {512 while (isWhiteSpace(this.peekCodePoint(0))) {513 this.consumeCodePoint();514 }515 }516 consumeBadUrlRemnants() {517 while (true) {518 let codePoint = this.consumeCodePoint();519 if (codePoint === RIGHT_PARENTHESIS || codePoint === EOF) {520 return;521 }522 if (isValidEscape(codePoint, this.peekCodePoint(0))) {523 this.consumeEscapedCodePoint();524 }525 }526 }527 consumeStringSlice(count) {528 const SLICE_STACK_SIZE = 60000;529 let value = '';530 while (count > 0) {531 const amount = Math.min(SLICE_STACK_SIZE, count);532 value += fromCodePoint(...this._value.splice(0, amount));533 count -= amount;534 }535 this._value.shift();536 return value;537 }538 consumeStringToken(endingCodePoint) {539 let value = '';540 let i = 0;541 do {542 const codePoint = this._value[i];543 if (codePoint === EOF || codePoint === undefined || codePoint === endingCodePoint) {544 value += this.consumeStringSlice(i);545 return { type: TokenType.STRING_TOKEN, value };546 }547 if (codePoint === LINE_FEED) {548 this._value.splice(0, i);549 return BAD_STRING_TOKEN;550 }551 if (codePoint === REVERSE_SOLIDUS) {552 const next = this._value[i + 1];553 if (next !== EOF && next !== undefined) {554 if (next === LINE_FEED) {555 value += this.consumeStringSlice(i);556 i = -1;557 this._value.shift();558 }559 else if (isValidEscape(codePoint, next)) {560 value += this.consumeStringSlice(i);561 value += fromCodePoint(this.consumeEscapedCodePoint());562 i = -1;563 }564 }565 }566 i++;567 } while (true);568 }569 consumeNumber() {570 let repr = [];571 let type = FLAG_INTEGER;572 let c1 = this.peekCodePoint(0);573 if (c1 === PLUS_SIGN || c1 === HYPHEN_MINUS) {574 repr.push(this.consumeCodePoint());575 }576 while (isDigit(this.peekCodePoint(0))) {577 repr.push(this.consumeCodePoint());578 }579 c1 = this.peekCodePoint(0);580 let c2 = this.peekCodePoint(1);581 if (c1 === FULL_STOP && isDigit(c2)) {582 repr.push(this.consumeCodePoint(), this.consumeCodePoint());583 type = FLAG_NUMBER;584 while (isDigit(this.peekCodePoint(0))) {585 repr.push(this.consumeCodePoint());586 }587 }588 c1 = this.peekCodePoint(0);589 c2 = this.peekCodePoint(1);590 let c3 = this.peekCodePoint(2);591 if ((c1 === E || c1 === e) && (((c2 === PLUS_SIGN || c2 === HYPHEN_MINUS) && isDigit(c3)) || isDigit(c2))) {592 repr.push(this.consumeCodePoint(), this.consumeCodePoint());593 type = FLAG_NUMBER;594 while (isDigit(this.peekCodePoint(0))) {595 repr.push(this.consumeCodePoint());596 }597 }598 return [stringToNumber(repr), type];599 }600 consumeNumericToken() {601 const [number, flags] = this.consumeNumber();602 const c1 = this.peekCodePoint(0);603 const c2 = this.peekCodePoint(1);604 const c3 = this.peekCodePoint(2);605 if (isIdentifierStart(c1, c2, c3)) {606 let unit = this.consumeName();607 return { type: TokenType.DIMENSION_TOKEN, number, flags, unit };608 }609 if (c1 === PERCENTAGE_SIGN) {610 this.consumeCodePoint();611 return { type: TokenType.PERCENTAGE_TOKEN, number, flags };612 }613 return { type: TokenType.NUMBER_TOKEN, number, flags };614 }615 consumeEscapedCodePoint() {616 const codePoint = this.consumeCodePoint();617 if (isHex(codePoint)) {618 let hex = fromCodePoint(codePoint);619 while (isHex(this.peekCodePoint(0)) && hex.length < 6) {620 hex += fromCodePoint(this.consumeCodePoint());621 }622 if (isWhiteSpace(this.peekCodePoint(0))) {623 this.consumeCodePoint();624 }625 const hexCodePoint = parseInt(hex, 16);626 if (hexCodePoint === 0 || isSurrogateCodePoint(hexCodePoint) || hexCodePoint > 0x10ffff) {627 return REPLACEMENT_CHARACTER;628 }629 return hexCodePoint;630 }631 if (codePoint === EOF) {632 return REPLACEMENT_CHARACTER;633 }634 return codePoint;635 }636 consumeName() {637 let result = '';638 while (true) {639 const codePoint = this.consumeCodePoint();640 if (isNameCodePoint(codePoint)) {641 result += fromCodePoint(codePoint);642 }643 else if (isValidEscape(codePoint, this.peekCodePoint(0))) {644 result += fromCodePoint(this.consumeEscapedCodePoint());645 }646 else {647 this.reconsumeCodePoint(codePoint);648 return result;649 }650 }651 }...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt');2var options = {3};4wpt.consume(options, function(err, data) {5 if (err) {6 console.log(err);7 } else {8 console.log(data);9 }10});11var wpt = require('wpt');12var options = {13};14wpt.consume(options, function(err, data) {15 if (err) {16 console.log(err);17 } else {18 console.log(data);19 }20});21var wpt = require('wpt');22var options = {23};24wpt.consume(options, function(err, data) {25 if (err) {26 console.log(err);27 } else {28 console.log(data);29 }30});31var wpt = require('wpt');32var options = {33};34wpt.consume(options, function(err, data) {35 if (err) {36 console.log(err);37 } else {38 console.log(data);39 }40});41var wpt = require('wpt');42var options = {43};44wpt.consume(options, function(err, data) {45 if (err) {46 console.log(err);47 } else {48 console.log(data);49 }50});51var wpt = require('wpt');52var options = {53};54wpt.consume(options, function(err, data) {55 if (err) {56 console.log(err);57 } else {58 console.log(data);59 }60});61var wpt = require('wpt');

Full Screen

Using AI Code Generation

copy

Full Screen

1const wpt = require('webpagetest');2const util = require('util');3const fs = require('fs');4const path = require('path');5const csv = require('csvtojson');6const csvFilePath = path.join(__dirname, 'urls.csv');7const csvFilePath2 = path.join(__dirname, 'urls2.csv');8const csvFilePath3 = path.join(__dirname, 'urls3.csv');9const csvFilePath4 = path.join(__dirname, 'urls4.csv');10const csvFilePath5 = path.join(__dirname, 'urls5.csv');11const csvFilePath6 = path.join(__dirname, 'urls6.csv');12const csvFilePath7 = path.join(__dirname, 'urls7.csv');13const csvFilePath8 = path.join(__dirname, 'urls8.csv');14const csvFilePath9 = path.join(__dirname, 'urls9.csv');15const csvFilePath10 = path.join(__dirname, 'urls10.csv');16const csvFilePath11 = path.join(__dirname, 'urls11.csv');17const csvFilePath12 = path.join(__dirname, 'urls12.csv');18const csvFilePath13 = path.join(__dirname, 'urls13.csv');19const csvFilePath14 = path.join(__dirname, 'urls14.csv');20const csvFilePath15 = path.join(__dirname, 'urls15.csv');21const csvFilePath16 = path.join(__dirname, 'urls16.csv');22const csvFilePath17 = path.join(__dirname, 'urls17.csv');23const csvFilePath18 = path.join(__dirname, 'urls18.csv');24const csvFilePath19 = path.join(__dirname, 'urls19.csv');25const csvFilePath20 = path.join(__dirname, 'urls20.csv');26const csvFilePath21 = path.join(__dirname, 'urls21.csv');27const csvFilePath22 = path.join(__dirname, 'urls22.csv');28const csvFilePath23 = path.join(__dirname, 'urls23.csv');29const csvFilePath24 = path.join(__dirname, 'urls24.csv');30const csvFilePath25 = path.join(__dirname, 'urls25.csv');31const csvFilePath26 = path.join(__dirname, 'urls26.csv');32const csvFilePath27 = path.join(__dirname, 'urls27.csv');33const csvFilePath28 = path.join(__dirname, 'urls28.csv');34const csvFilePath29 = path.join(__dirname, 'urls29.csv');35const csvFilePath30 = path.join(__dirname, 'urls30.csv');36const csvFilePath31 = path.join(__dirname

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run wpt 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