How to use CloseSquareToken method in Playwright Internal

Best JavaScript code snippet using playwright-internal

tokenize-css.js

Source:tokenize-css.js Github

copy

Full Screen

...498 .CSS_SYNTAX_STRAY_TRAILING_BACKSLASH,499 ['style']));500 }501 } else if (this.code_ === /* ']' */ 0x5d) {502 return mark.copyPosTo(new parse_css.CloseSquareToken());503 } else if (this.code_ === /* '^' */ 0x5e) {504 if (this.next() === /* '=' */ 0x3d) {505 this.consume();506 return mark.copyPosTo(new parse_css.PrefixMatchToken());507 } else {508 return mark.copyPosTo(new parse_css.DelimToken(this.code_));509 }510 } else if (this.code_ === /* '{' */ 0x7b) {511 return mark.copyPosTo(new parse_css.OpenCurlyToken());512 } else if (this.code_ === /* '|' */ 0x7c) {513 if (this.next() === /* '=' */ 0x3d) {514 this.consume();515 return mark.copyPosTo(new parse_css.DashMatchToken());516 } else if (this.next() === /* '|' */ 0x7c) {517 this.consume();518 return mark.copyPosTo(new parse_css.ColumnToken());519 } else {520 return mark.copyPosTo(new parse_css.DelimToken(this.code_));521 }522 } else if (this.code_ === /* '}' */ 0x7d) {523 return mark.copyPosTo(new parse_css.CloseCurlyToken());524 } else if (this.code_ === /* '~' */ 0x7e) {525 if (this.next() === /* '=' */ 0x3d) {526 this.consume();527 return mark.copyPosTo(new parse_css.IncludeMatchToken());528 } else {529 return mark.copyPosTo(new parse_css.DelimToken(this.code_));530 }531 } else if (digit(this.code_)) {532 this.reconsume();533 return mark.copyPosTo(this.consumeANumericToken());534 } else if (nameStartChar(this.code_)) {535 this.reconsume();536 return mark.copyPosTo(this.consumeAnIdentlikeToken());537 } else if (this.eof()) {538 return mark.copyPosTo(new parse_css.EOFToken());539 } else {540 const token = new parse_css.DelimToken(this.code_);541 return mark.copyPosTo(token);542 }543 }544 /**545 * Consume everything starting with /* and ending at * / (ignore the space),546 * emitting a parse error if we hit the end of the file. Returns nothing.547 */548 consumeComments() {549 const mark = new parse_css.Token();550 mark.line = this.getLine();551 mark.col = this.getCol();552 while (this.next(1) === /* '/' */ 0x2f && this.next(2) === /* '*' */ 0x2a) {553 this.consume(2);554 while (true) {555 this.consume();556 if (this.code_ === /* '*' */ 0x2a && this.next() === /* '/' */ 0x2f) {557 this.consume();558 break;559 } else if (this.eof()) {560 // For example "h1 { color: red; } \* " would emit this parse error561 // at the end of the string.562 this.errors_.push(mark.copyPosTo(new parse_css.ErrorToken(563 amp.validator.ValidationError.Code564 .CSS_SYNTAX_UNTERMINATED_COMMENT,565 ['style'])));566 return;567 }568 }569 }570 }571 /**572 * Consumes a token that starts with a number.573 * The specific type is one of:574 * NumberToken, DimensionToken, PercentageToken575 * @return {!parse_css.Token} */576 consumeANumericToken() {577 goog.asserts.assert(578 this.wouldStartANumber(this.next(1), this.next(2), this.next(3)),579 'Internal Error: consumeANumericToken precondition not met');580 /** @type {!parse_css.NumberToken} */581 const num = this.consumeANumber();582 if (this.wouldStartAnIdentifier(this.next(1), this.next(2), this.next(3))) {583 const token = new parse_css.DimensionToken();584 token.value = num.value;585 token.repr = num.repr;586 token.type = num.type;587 token.unit = this.consumeAName();588 return token;589 } else if (this.next() === /* '%' */ 0x25) {590 this.consume();591 const token = new parse_css.PercentageToken();592 token.value = num.value;593 token.repr = num.repr;594 return token;595 }596 return num;597 }598 /**599 * Consume an identifier-like token.600 * The specific type is one of:601 * FunctionToken, URLToken, ErrorToken, IdentToken602 * @return {!parse_css.Token}603 */604 consumeAnIdentlikeToken() {605 const name = this.consumeAName();606 if (name.toLowerCase() === 'url' && this.next() === /* '(' */ 0x28) {607 this.consume();608 while (whitespace(this.next(1)) && whitespace(this.next(2))) {609 this.consume();610 }611 if (this.next() === /* '"' */ 0x22 || this.next() === /* ''' */ 0x27) {612 const token = new parse_css.FunctionToken();613 token.value = name;614 return token;615 } else if (616 whitespace(this.next()) &&617 (this.next(2) === /* '"' */ 0x22 ||618 this.next(2) === /* ''' */ 0x27)) {619 const token = new parse_css.FunctionToken();620 token.value = name;621 return token;622 } else {623 return this.consumeAURLToken();624 }625 } else if (this.next() === /* '(' */ 0x28) {626 this.consume();627 const token = new parse_css.FunctionToken();628 token.value = name;629 return token;630 } else {631 const token = new parse_css.IdentToken();632 token.value = name;633 return token;634 }635 }636 /**637 * Consume a string token.638 * The specific type is one of:639 * StringToken, ErrorToken640 * @return {!parse_css.Token}641 */642 consumeAStringToken() {643 goog.asserts.assert(644 (this.code_ === /* '"' */ 0x22) || (this.code_ === /* ''' */ 0x27),645 'Internal Error: consumeAStringToken precondition not met');646 const endingCodePoint = this.code_;647 let string = '';648 while (true) {649 this.consume();650 if (this.code_ === endingCodePoint || this.eof()) {651 const token = new parse_css.StringToken();652 token.value = string;653 return token;654 } else if (newline(this.code_)) {655 this.reconsume();656 return new parse_css.ErrorToken(657 amp.validator.ValidationError.Code.CSS_SYNTAX_UNTERMINATED_STRING,658 ['style']);659 } else if (this.code_ === /* '\' */ 0x5c) {660 if (this.eof(this.next())) {661 continue;662 } else if (newline(this.next())) {663 this.consume();664 } else {665 string += stringFromCode(this.consumeEscape());666 }667 } else {668 string += stringFromCode(this.code_);669 }670 }671 }672 /**673 * Consume an URL token.674 * The specific type is one of:675 * URLToken, ErrorToken676 * @return {!parse_css.Token}677 */678 consumeAURLToken() {679 const token = new parse_css.URLToken();680 while (whitespace(this.next())) {681 this.consume();682 }683 if (this.eof(this.next())) {684 return token;685 }686 while (true) {687 this.consume();688 if (this.code_ === /* ')' */ 0x29 || this.eof()) {689 return token;690 } else if (whitespace(this.code_)) {691 while (whitespace(this.next())) {692 this.consume();693 }694 if (this.next() === /* ')' */ 0x29 || this.eof(this.next())) {695 this.consume();696 return token;697 } else {698 this.consumeTheRemnantsOfABadURL();699 return new parse_css.ErrorToken(700 amp.validator.ValidationError.Code.CSS_SYNTAX_BAD_URL, ['style']);701 }702 } else if (703 this.code_ === /* '"' */ 0x22 || this.code_ === /* ''' */ 0x27 ||704 this.code_ === /* '(' */ 0x28 || nonPrintable(this.code_)) {705 this.consumeTheRemnantsOfABadURL();706 return new parse_css.ErrorToken(707 amp.validator.ValidationError.Code.CSS_SYNTAX_BAD_URL, ['style']);708 } else if (this.code_ === /* '\' */ 0x5c) {709 if (this./*OK*/ startsWithAValidEscape()) {710 token.value += stringFromCode(this.consumeEscape());711 } else {712 this.consumeTheRemnantsOfABadURL();713 return new parse_css.ErrorToken(714 amp.validator.ValidationError.Code.CSS_SYNTAX_BAD_URL, ['style']);715 }716 } else {717 token.value += stringFromCode(this.code_);718 }719 }720 }721 /**722 * Consume an escaped character, ex: \a212f3, followed by any whitespace.723 * Returns the numerical value of the character. If the codepoint following724 * the '\' character is not a hex code and not EOF, returns that codepoint.725 * @return {number}726 */727 consumeEscape() {728 // Assume the the current character is the \729 // and the next code point is not a newline.730 this.consume(); // '\'731 if (hexDigit(this.code_)) {732 // Consume 1-6 hex digits733 const digits = [this.code_];734 for (let total = 0; total < 5; total++) {735 if (hexDigit(this.next())) {736 this.consume();737 digits.push(this.code_);738 } else {739 break;740 }741 }742 if (whitespace(this.next())) {743 this.consume();744 }745 let value = parseInt(746 digits747 .map(function(x) {748 return String.fromCharCode(x);749 })750 .join(''),751 16);752 if (value > maxAllowedCodepoint) {753 value = 0xfffd;754 }755 return value;756 } else if (this.eof()) {757 return 0xfffd;758 } else {759 return this.code_;760 }761 }762 /**763 * Returns true if the codepoint sequence c1, c2 are the start764 * of an escape token.765 * @param {number} c1 codepoint at pos x766 * @param {number} c2 codepoint at pos x + 1767 * @return {boolean}768 */769 areAValidEscape(c1, c2) {770 if (c1 != /* '\' */ 0x5c) {771 return false;772 }773 if (newline(c2)) {774 return false;775 }776 return true;777 }778 /**779 * Returns true if the next two codepoints are the start of an escape token.780 * @return {boolean} */781 /*OK*/ startsWithAValidEscape() {782 return this.areAValidEscape(this.code_, this.next());783 }784 /**785 * Returns true if the codepoint sequence c1, c2, c3 are the786 * start of an identifier.787 * @param {number} c1 codepoint at pos x788 * @param {number} c2 codepoint at pos x + 1789 * @param {number} c3 codepoint at pos x + 2790 * @return {boolean}791 */792 wouldStartAnIdentifier(c1, c2, c3) {793 if (c1 === /* '-' */ 0x2d) {794 return nameStartChar(c2) || c2 === /* '-' */ 0x2d ||795 this.areAValidEscape(c2, c3);796 } else if (nameStartChar(c1)) {797 return true;798 } else if (c1 === /* '\' */ 0x5c) {799 return this.areAValidEscape(c1, c2);800 } else {801 return false;802 }803 }804 /**805 * Returns true if the next three codepoints are the start of an identifier.806 * @return {boolean}807 */808 /*OK*/ startsWithAnIdentifier() {809 return this.wouldStartAnIdentifier(this.code_, this.next(1), this.next(2));810 }811 /**812 * Returns true if the codepoint sequence c1, c2, c3 are the813 * start of a number.814 * @param {number} c1 codepoint at pos x815 * @param {number} c2 codepoint at pos x + 1816 * @param {number} c3 codepoint at pos x + 2817 * @return {boolean}818 */819 wouldStartANumber(c1, c2, c3) {820 if (c1 === /* '+' */ 0x2b || c1 === /* '-' */ 0x2d) {821 if (digit(c2)) {822 return true;823 }824 if (c2 === /* '.' */ 0x2e && digit(c3)) {825 return true;826 }827 return false;828 } else if (c1 === /* '.' */ 0x2e) {829 if (digit(c2)) {830 return true;831 }832 return false;833 } else if (digit(c1)) {834 return true;835 } else {836 return false;837 }838 }839 /**840 * Returns true if the next three codepoints are the start of a number.841 * @return {boolean}842 */843 /*OK*/ startsWithANumber() {844 return this.wouldStartANumber(this.code_, this.next(1), this.next(2));845 }846 /** @return {string} */847 consumeAName() {848 let result = '';849 while (true) {850 this.consume();851 if (nameChar(this.code_)) {852 result += stringFromCode(this.code_);853 } else if (this./*OK*/ startsWithAValidEscape()) {854 result += stringFromCode(this.consumeEscape());855 } else {856 this.reconsume();857 return result;858 }859 }860 }861 /**862 * Consumes a number, returning it as a string representation. Numbers863 * may include +/- prefixes, ./e/E delimiters, etc. The type string will864 * be either 'integer' or 'number'. A number may be an integer.865 * @return {!parse_css.NumberToken}866 */867 consumeANumber() {868 goog.asserts.assert(869 this.wouldStartANumber(this.next(1), this.next(2), this.next(3)),870 'Internal Error: consumeANumber precondition not met');871 /** @type {string} */872 let repr = '';873 /** @type {string} */874 let type = 'integer';875 if (this.next() === /* '+' */ 0x2b || this.next() === /* '-' */ 0x2d) {876 this.consume();877 repr += stringFromCode(this.code_); // + or -878 }879 while (digit(this.next())) {880 this.consume();881 repr += stringFromCode(this.code_); // 0-9882 }883 if (this.next(1) === /* '.' */ 0x2e && digit(this.next(2))) {884 this.consume();885 repr += stringFromCode(this.code_); // '.'886 type = 'number';887 while (digit(this.next())) {888 this.consume();889 repr += stringFromCode(this.code_); // 0-9890 }891 }892 const c1 = this.next(1);893 const c2 = this.next(2);894 const c3 = this.next(3);895 if ((c1 === /* 'E' */ 0x45 || c1 === /* 'e' */ 0x65) && digit(c2)) {896 this.consume();897 repr += stringFromCode(this.code_); // E or e898 type = 'number';899 while (digit(this.next())) {900 this.consume();901 repr += stringFromCode(this.code_); // 0-9902 }903 } else if (904 (c1 === /* 'E' */ 0x45 || c1 === /* 'e' */ 0x65) &&905 (c2 === /* '+' */ 0x2b || c2 === /* '-' */ 0x2d) && digit(c3)) {906 this.consume();907 repr += stringFromCode(this.code_); // E or e908 this.consume();909 repr += stringFromCode(this.code_); // + or -910 type = 'number';911 while (digit(this.next())) {912 this.consume();913 repr += stringFromCode(this.code_); // 0-9914 }915 }916 const numberToken = new parse_css.NumberToken();917 numberToken.type = type;918 numberToken.value = this.convertAStringToANumber(repr);919 numberToken.repr = repr;920 return numberToken;921 }922 /**923 * Converts a numerical representation of a string to a number.924 * @param {string} string925 * @return {number}926 */927 convertAStringToANumber(string) {928 // CSS's number rules are identical to JS, afaik.929 return Number(string);930 }931 /**932 * Consumes ?. Returns nothing.933 */934 consumeTheRemnantsOfABadURL() {935 while (true) {936 this.consume();937 if (this.code_ === /* '-' */ 0x2d || this.eof()) {938 return;939 } else if (this./*OK*/ startsWithAValidEscape()) {940 this.consumeEscape();941 }942 }943 }944}945/**946 * NOTE: When adding to this enum, you must update TokenType_NamesById below.947 * @enum {number}948 */949parse_css.TokenType = {950 UNKNOWN: 0,951 AT_KEYWORD: 1,952 CDC: 2, // -->953 CDO: 3, // <!--954 CLOSE_CURLY: 4,955 CLOSE_PAREN: 5,956 CLOSE_SQUARE: 6,957 COLON: 7,958 COLUMN: 8, // ||959 COMMA: 9,960 DASH_MATCH: 10, // |=961 DELIM: 11,962 DIMENSION: 12,963 EOF_TOKEN: 13, // Can't call this EOF due to symbol conflict in C.964 ERROR: 14,965 FUNCTION_TOKEN: 15,966 HASH: 16, // #967 IDENT: 17,968 INCLUDE_MATCH: 18, // ~=969 NUMBER: 19,970 OPEN_CURLY: 20,971 OPEN_PAREN: 21,972 OPEN_SQUARE: 22,973 PERCENTAGE: 23,974 PREFIX_MATCH: 24, // ^=975 SEMICOLON: 25,976 STRING: 26,977 SUBSTRING_MATCH: 27, // *=978 SUFFIX_MATCH: 28, // $=979 WHITESPACE: 29,980 URL: 30,981 // AST nodes produced by the parsing routines.982 STYLESHEET: 31,983 AT_RULE: 32,984 QUALIFIED_RULE: 33,985 DECLARATION: 34,986 BLOCK: 35,987 FUNCTION: 36,988 // For ExtractUrls989 PARSED_CSS_URL: 37,990 // For css-selectors.js.991 TYPE_SELECTOR: 38,992 ID_SELECTOR: 39,993 ATTR_SELECTOR: 40,994 PSEUDO_SELECTOR: 41,995 CLASS_SELECTOR: 42,996 SIMPLE_SELECTOR_SEQUENCE: 43,997 COMBINATOR: 44,998 SELECTORS_GROUP: 45,999};1000/** @type {!Array<string>} */1001const TokenType_NamesById = [1002 'UNKNOWN',1003 'AT_KEYWORD',1004 'CDC',1005 'CDO',1006 'CLOSE_CURLY',1007 'CLOSE_PAREN',1008 'CLOSE_SQUARE',1009 'COLON',1010 'COLUMN',1011 'COMMA',1012 'DASH_MATCH',1013 'DELIM',1014 'DIMENSION',1015 'EOF_TOKEN',1016 'ERROR',1017 'FUNCTION_TOKEN',1018 'HASH',1019 'IDENT',1020 'INCLUDE_MATCH',1021 'NUMBER',1022 'OPEN_CURLY',1023 'OPEN_PAREN',1024 'OPEN_SQUARE',1025 'PERCENTAGE',1026 'PREFIX_MATCH',1027 'SEMICOLON',1028 'STRING',1029 'SUBSTRING_MATCH',1030 'SUFFIX_MATCH',1031 'WHITESPACE',1032 'URL',1033 'STYLESHEET',1034 'AT_RULE',1035 'QUALIFIED_RULE',1036 'DECLARATION',1037 'BLOCK',1038 'FUNCTION',1039 'PARSED_CSS_URL',1040 'TYPE_SELECTOR',1041 'ID_SELECTOR',1042 'ATTR_SELECTOR',1043 'PSEUDO_SELECTOR',1044 'CLASS_SELECTOR',1045 'SIMPLE_SELECTOR_SEQUENCE',1046 'COMBINATOR',1047 'SELECTORS_GROUP',1048];1049/**1050 * The abstract superclass for all tokens.1051 */1052parse_css.Token = class {1053 constructor() {1054 /** @type {number} */1055 this.line = 1;1056 /** @type {number} */1057 this.col = 0;1058 }1059 /**1060 * Copies the line / col values of |this| to |other|.1061 * @param {!T} other1062 * @return {!T}1063 * @template T1064 */1065 copyPosTo(other) {1066 other.line = this.line;1067 other.col = this.col;1068 return other;1069 }1070};1071/** @type {!parse_css.TokenType} */1072parse_css.Token.prototype.tokenType = parse_css.TokenType.UNKNOWN;1073/** @return {!Object} */1074parse_css.Token.prototype.toJSON = function() {1075 return {1076 'tokenType': TokenType_NamesById[this.tokenType],1077 'line': this.line,1078 'col': this.col,1079 };1080};1081/**1082 * Error tokens carry an error code and parameters, which can be1083 * formatted into an error message via the format strings in1084 * validator.protoascii.1085 */1086parse_css.ErrorToken = class extends parse_css.Token {1087 /**1088 * @param {amp.validator.ValidationError.Code=} opt_code1089 * @param {!Array<string>=} opt_params1090 */1091 constructor(opt_code, opt_params) {1092 super();1093 goog.asserts.assert(opt_code !== undefined);1094 goog.asserts.assert(opt_params !== undefined);1095 /** @type {!amp.validator.ValidationError.Code} */1096 this.code = opt_code;1097 /** @type {!Array<string>} */1098 this.params = opt_params;1099 }1100};1101/** @type {!parse_css.TokenType} */1102parse_css.ErrorToken.prototype.tokenType = parse_css.TokenType.ERROR;1103/** @inheritDoc */1104parse_css.ErrorToken.prototype.toJSON = function() {1105 const json = parse_css.Token.prototype.toJSON.call(this);1106 json['code'] = this.code;1107 json['params'] = this.params;1108 return json;1109};1110parse_css.WhitespaceToken = class extends parse_css.Token {};1111/** @type {!parse_css.TokenType} */1112parse_css.WhitespaceToken.prototype.tokenType = parse_css.TokenType.WHITESPACE;1113const TRIVIAL_WHITESPACE_TOKEN = new parse_css.WhitespaceToken();1114parse_css.CDOToken = class extends parse_css.Token {};1115/** @type {!parse_css.TokenType} */1116parse_css.CDOToken.prototype.tokenType = parse_css.TokenType.CDO;1117const TRIVIAL_CDO_TOKEN = new parse_css.CDOToken();1118parse_css.CDCToken = class extends parse_css.Token {};1119/** @type {!parse_css.TokenType} */1120parse_css.CDCToken.prototype.tokenType = parse_css.TokenType.CDC;1121const TRIVIAL_CDC_TOKEN = new parse_css.CDCToken();1122parse_css.ColonToken = class extends parse_css.Token {};1123/** @type {!parse_css.TokenType} */1124parse_css.ColonToken.prototype.tokenType = parse_css.TokenType.COLON;1125const TRIVIAL_COLON_TOKEN = new parse_css.ColonToken();1126parse_css.SemicolonToken = class extends parse_css.Token {};1127/** @type {!parse_css.TokenType} */1128parse_css.SemicolonToken.prototype.tokenType = parse_css.TokenType.SEMICOLON;1129const TRIVIAL_SEMICOLON_TOKEN = new parse_css.SemicolonToken();1130parse_css.CommaToken = class extends parse_css.Token {};1131/** @type {!parse_css.TokenType} */1132parse_css.CommaToken.prototype.tokenType = parse_css.TokenType.COMMA;1133const TRIVIAL_COMMA_TOKEN = new parse_css.CommaToken();1134parse_css.GroupingToken = class extends parse_css.Token {};1135/** @type {string} */1136parse_css.GroupingToken.prototype.value = 'abstract';1137/** @type {string} */1138parse_css.GroupingToken.prototype.mirror = 'abstract';1139parse_css.OpenCurlyToken = class extends parse_css.GroupingToken {};1140/** @type {!parse_css.TokenType} */1141parse_css.OpenCurlyToken.prototype.tokenType = parse_css.TokenType.OPEN_CURLY;1142/** @type {string} */1143parse_css.OpenCurlyToken.prototype.value = '{';1144/** @type {string} */1145parse_css.OpenCurlyToken.prototype.mirror = '}';1146const TRIVIAL_OPEN_CURLY_TOKEN = new parse_css.OpenCurlyToken();1147parse_css.CloseCurlyToken = class extends parse_css.GroupingToken {};1148/** @type {!parse_css.TokenType} */1149parse_css.CloseCurlyToken.prototype.tokenType = parse_css.TokenType.CLOSE_CURLY;1150/** @type {string} */1151parse_css.CloseCurlyToken.prototype.value = '}';1152/** @type {string} */1153parse_css.CloseCurlyToken.prototype.mirror = '{';1154const TRIVIAL_CLOSE_CURLY_TOKEN = new parse_css.CloseCurlyToken();1155parse_css.OpenSquareToken = class extends parse_css.GroupingToken {};1156/** @type {!parse_css.TokenType} */1157parse_css.OpenSquareToken.prototype.tokenType = parse_css.TokenType.OPEN_SQUARE;1158/** @type {string} */1159parse_css.OpenSquareToken.prototype.value = '[';1160/** @type {string} */1161parse_css.OpenSquareToken.prototype.mirror = ']';1162const TRIVIAL_OPEN_SQUARE_TOKEN = new parse_css.OpenSquareToken();1163parse_css.CloseSquareToken = class extends parse_css.GroupingToken {};1164/** @type {!parse_css.TokenType} */1165parse_css.CloseSquareToken.prototype.tokenType =1166 parse_css.TokenType.CLOSE_SQUARE;1167/** @type {string} */1168parse_css.CloseSquareToken.prototype.value = ']';1169/** @type {string} */1170parse_css.CloseSquareToken.prototype.mirror = '[';1171const TRIVIAL_CLOSE_SQUARE_TOKEN = new parse_css.CloseSquareToken();1172parse_css.OpenParenToken = class extends parse_css.GroupingToken {};1173/** @type {!parse_css.TokenType} */1174parse_css.OpenParenToken.prototype.tokenType = parse_css.TokenType.OPEN_PAREN;1175/** @type {string} */1176parse_css.OpenParenToken.prototype.value = '(';1177/** @type {string} */1178parse_css.OpenParenToken.prototype.mirror = ')';1179const TRIVIAL_OPEN_PAREN_TOKEN = new parse_css.OpenParenToken();1180parse_css.CloseParenToken = class extends parse_css.GroupingToken {};1181/** @type {!parse_css.TokenType} */1182parse_css.CloseParenToken.prototype.tokenType = parse_css.TokenType.CLOSE_PAREN;1183/** @type {string} */1184parse_css.CloseParenToken.prototype.value = ')';1185/** @type {string} */...

Full Screen

Full Screen

parse-css.js

Source:parse-css.js Github

copy

Full Screen

...233 parseerror();234 return new DelimToken(code);235 }236 }237 else if(code == 0x5d) return new CloseSquareToken();238 else if(code == 0x5e) {239 if(next() == 0x3d) {240 consume();241 return new PrefixMatchToken();242 } else {243 return new DelimToken(code);244 }245 }246 else if(code == 0x7b) return new OpenCurlyToken();247 else if(code == 0x7c) {248 if(next() == 0x3d) {249 consume();250 return new DashMatchToken();251 // } else if(next() == 0x7c) {252 // consume();253 // return new ColumnToken();254 } else {255 return new DelimToken(code);256 }257 }258 else if(code == 0x7d) return new CloseCurlyToken();259 else if(code == 0x7e) {260 if(next() == 0x3d) {261 consume();262 return new IncludeMatchToken();263 } else {264 return new DelimToken(code);265 }266 }267 else if(digit(code)) {268 reconsume();269 return consumeANumericToken();270 }271 else if(namestartchar(code)) {272 reconsume();273 return consumeAnIdentlikeToken();274 }275 else if(eof()) return new EOFToken();276 else return new DelimToken(code);277 };278 var consumeAComment = function() {279 consume();280 var comment = "";281 while(true) {282 consume();283 if(code == 0x2a && next() == 0x2f) {284 consume();285 break;286 } else if(eof()) {287 break;288 }289 comment += stringFromCode(code);290 }291 return new CommentToken(comment);292 };293 var consumeANumericToken = function() {294 var num = consumeANumber();295 var token;296 if(wouldStartAnIdentifier(next(1), next(2), next(3))) {297 token = new DimensionToken();298 token.value = num.value;299 token.repr = num.repr;300 token.type = num.type;301 token.unit = consumeAName();302 token.text = token.unit;303 } else if(next() == 0x25) {304 consume();305 token = new PercentageToken();306 token.value = num.value;307 token.repr = num.repr;308 } else {309 var token = new NumberToken();310 token.value = num.value;311 token.repr = num.repr;312 token.type = num.type;313 }314 token.number = token.value;315 token.isInteger = token.type === "integer";316 // FIXME hasSign317 return token;318 };319 var consumeAnIdentlikeToken = function() {320 var str = consumeAName();321 if(str.toLowerCase() == "url" && next() == 0x28) {322 consume();323 while(whitespace(next(1)) && whitespace(next(2)))324 consume();325 if((next() == 0x22 || next() == 0x27) ||326 (whitespace(next()) && (next(2) == 0x22 || next(2) == 0x27))) {327 while(whitespace(next()))328 consume();329 consume();330 let str = consumeAStringToken();331 while(whitespace(next()))332 consume();333 // The closing paren.334 consume();335 return new URLToken(str.text);336 } else {337 return consumeAURLToken();338 }339 } else if(next() == 0x28) {340 consume();341 return new FunctionToken(str);342 } else {343 return new IdentToken(str);344 }345 };346 var consumeAStringToken = function(endingCodePoint) {347 if(endingCodePoint === undefined) endingCodePoint = code;348 var string = "";349 while(consume()) {350 if(code == endingCodePoint || eof()) {351 return new StringToken(string);352 } else if(newline(code)) {353 reconsume();354 return new BadStringToken(string);355 } else if(code == 0x5c) {356 if(eof(next())) {357 donothing();358 } else if(newline(next())) {359 consume();360 } else {361 string += stringFromCode(consumeEscape());362 }363 } else {364 string += stringFromCode(code);365 }366 }367 };368 var consumeAURLToken = function() {369 var token = new URLToken("");370 while(whitespace(next())) consume();371 if(eof(next())) return token;372 while(consume()) {373 if(code == 0x29 || eof()) {374 break;375 } else if(whitespace(code)) {376 while(whitespace(next()))377 consume();378 if(next() == 0x29 || eof(next())) {379 consume();380 break;381 } else {382 consumeTheRemnantsOfABadURL();383 return new BadURLToken();384 }385 } else if(code == 0x22 || code == 0x27 || code == 0x28 || nonprintable(code)) {386 parseerror();387 consumeTheRemnantsOfABadURL();388 return new BadURLToken();389 } else if(code == 0x5c) {390 if(startsWithAValidEscape()) {391 token.value += stringFromCode(consumeEscape());392 } else {393 parseerror();394 consumeTheRemnantsOfABadURL();395 return new BadURLToken();396 }397 } else {398 token.value += stringFromCode(code);399 }400 }401 token.text = token.value;402 return token;403 };404 var consumeEscape = function() {405 // Assume the the current character is the \406 // and the next code point is not a newline.407 consume();408 if(hexdigit(code)) {409 // Consume 1-6 hex digits410 var digits = [code];411 for(var total = 0; total < 5; total++) {412 if(hexdigit(next())) {413 consume();414 digits.push(code);415 } else {416 break;417 }418 }419 if(whitespace(next())) consume();420 var value = parseInt(digits.map(function(x){return String.fromCharCode(x);}).join(''), 16);421 if( value > maximumallowedcodepoint ) value = 0xfffd;422 return value;423 } else if(eof()) {424 return 0xfffd;425 } else {426 return code;427 }428 };429 var areAValidEscape = function(c1, c2) {430 if(c1 != 0x5c) return false;431 if(newline(c2)) return false;432 return true;433 };434 var startsWithAValidEscape = function() {435 return areAValidEscape(code, next());436 };437 var wouldStartAnIdentifier = function(c1, c2, c3) {438 if(c1 == 0x2d) {439 return namestartchar(c2) || c2 == 0x2d || areAValidEscape(c2, c3);440 } else if(namestartchar(c1)) {441 return true;442 } else if(c1 == 0x5c) {443 return areAValidEscape(c1, c2);444 } else {445 return false;446 }447 };448 var startsWithAnIdentifier = function() {449 return wouldStartAnIdentifier(code, next(1), next(2));450 };451 var wouldStartANumber = function(c1, c2, c3) {452 if(c1 == 0x2b || c1 == 0x2d) {453 if(digit(c2)) return true;454 if(c2 == 0x2e && digit(c3)) return true;455 return false;456 } else if(c1 == 0x2e) {457 if(digit(c2)) return true;458 return false;459 } else if(digit(c1)) {460 return true;461 } else {462 return false;463 }464 };465 var startsWithANumber = function() {466 return wouldStartANumber(code, next(1), next(2));467 };468 var consumeAName = function() {469 var result = "";470 while(consume()) {471 if(namechar(code)) {472 result += stringFromCode(code);473 } else if(startsWithAValidEscape()) {474 result += stringFromCode(consumeEscape());475 } else {476 reconsume();477 return result;478 }479 }480 };481 var consumeANumber = function() {482 var repr = [];483 var type = "integer";484 if(next() == 0x2b || next() == 0x2d) {485 consume();486 repr += stringFromCode(code);487 }488 while(digit(next())) {489 consume();490 repr += stringFromCode(code);491 }492 if(next(1) == 0x2e && digit(next(2))) {493 consume();494 repr += stringFromCode(code);495 consume();496 repr += stringFromCode(code);497 type = "number";498 while(digit(next())) {499 consume();500 repr += stringFromCode(code);501 }502 }503 var c1 = next(1), c2 = next(2), c3 = next(3);504 if((c1 == 0x45 || c1 == 0x65) && digit(c2)) {505 consume();506 repr += stringFromCode(code);507 consume();508 repr += stringFromCode(code);509 type = "number";510 while(digit(next())) {511 consume();512 repr += stringFromCode(code);513 }514 } else if((c1 == 0x45 || c1 == 0x65) && (c2 == 0x2b || c2 == 0x2d) && digit(c3)) {515 consume();516 repr += stringFromCode(code);517 consume();518 repr += stringFromCode(code);519 consume();520 repr += stringFromCode(code);521 type = "number";522 while(digit(next())) {523 consume();524 repr += stringFromCode(code);525 }526 }527 var value = convertAStringToANumber(repr);528 return {type:type, value:value, repr:repr};529 };530 var convertAStringToANumber = function(string) {531 // CSS's number rules are identical to JS, afaik.532 return +string;533 };534 var consumeTheRemnantsOfABadURL = function() {535 while(consume()) {536 if(code == 0x2d || eof()) {537 return;538 } else if(startsWithAValidEscape()) {539 consumeEscape();540 donothing();541 } else {542 donothing();543 }544 }545 };546 var iterationCount = 0;547 while(!eof(next())) {548 var token = consumeAToken();549 if (options.loc) {550 token.loc = {};551 token.loc.start = {line:locStart.line, column:locStart.column};552 token.loc.end = {line:line, column:column};553 }554 if (options.offsets) {555 token.startOffset = offsetStart;556 token.endOffset = i + 1;557 }558 yield token;559 iterationCount++;560 if(iterationCount > str.length*2) return "I'm infinite-looping!";561 }562}563function CSSParserToken() { throw "Abstract Base Class"; }564CSSParserToken.prototype.toJSON = function() {565 return {token: this.tokenType};566};567CSSParserToken.prototype.toString = function() { return this.tokenType; };568CSSParserToken.prototype.toSource = function() { return ''+this; };569function BadStringToken(text) {570 this.text = text;571 return this;572}573BadStringToken.prototype = Object.create(CSSParserToken.prototype);574BadStringToken.prototype.tokenType = "bad_string";575function BadURLToken() { return this; }576BadURLToken.prototype = Object.create(CSSParserToken.prototype);577BadURLToken.prototype.tokenType = "bad_url";578function WhitespaceToken() { return this; }579WhitespaceToken.prototype = Object.create(CSSParserToken.prototype);580WhitespaceToken.prototype.tokenType = "whitespace";581WhitespaceToken.prototype.toString = function() { return "WS"; };582WhitespaceToken.prototype.toSource = function() { return " "; };583function CDOToken() { return this; }584CDOToken.prototype = Object.create(CSSParserToken.prototype);585CDOToken.prototype.tokenType = "htmlcomment";586CDOToken.prototype.toSource = function() { return "<!--"; };587function CDCToken() { return this; }588CDCToken.prototype = Object.create(CSSParserToken.prototype);589CDCToken.prototype.tokenType = "htmlcomment";590CDCToken.prototype.toSource = function() { return "-->"; };591function ColonToken() { return this; }592ColonToken.prototype = Object.create(CSSParserToken.prototype);593ColonToken.prototype.tokenType = "symbol";594ColonToken.prototype.text = ":";595function SemicolonToken() { return this; }596SemicolonToken.prototype = Object.create(CSSParserToken.prototype);597SemicolonToken.prototype.tokenType = "symbol";598SemicolonToken.prototype.text = ";";599function CommaToken() { return this; }600CommaToken.prototype = Object.create(CSSParserToken.prototype);601CommaToken.prototype.tokenType = "symbol";602CommaToken.prototype.text = ",";603function GroupingToken() { throw "Abstract Base Class"; }604GroupingToken.prototype = Object.create(CSSParserToken.prototype);605function OpenCurlyToken() { this.value = "{"; this.mirror = "}"; return this; }606OpenCurlyToken.prototype = Object.create(GroupingToken.prototype);607OpenCurlyToken.prototype.tokenType = "symbol";608OpenCurlyToken.prototype.text = "{";609function CloseCurlyToken() { this.value = "}"; this.mirror = "{"; return this; }610CloseCurlyToken.prototype = Object.create(GroupingToken.prototype);611CloseCurlyToken.prototype.tokenType = "symbol";612CloseCurlyToken.prototype.text = "}";613function OpenSquareToken() { this.value = "["; this.mirror = "]"; return this; }614OpenSquareToken.prototype = Object.create(GroupingToken.prototype);615OpenSquareToken.prototype.tokenType = "symbol";616OpenSquareToken.prototype.text = "[";617function CloseSquareToken() { this.value = "]"; this.mirror = "["; return this; }618CloseSquareToken.prototype = Object.create(GroupingToken.prototype);619CloseSquareToken.prototype.tokenType = "symbol";620CloseSquareToken.prototype.text = "]";621function OpenParenToken() { this.value = "("; this.mirror = ")"; return this; }622OpenParenToken.prototype = Object.create(GroupingToken.prototype);623OpenParenToken.prototype.tokenType = "symbol";624OpenParenToken.prototype.text = "(";625function CloseParenToken() { this.value = ")"; this.mirror = "("; return this; }626CloseParenToken.prototype = Object.create(GroupingToken.prototype);627CloseParenToken.prototype.tokenType = "symbol";628CloseParenToken.prototype.text = ")";629function IncludeMatchToken() { return this; }630IncludeMatchToken.prototype = Object.create(CSSParserToken.prototype);631IncludeMatchToken.prototype.tokenType = "includes";...

Full Screen

Full Screen

css-syntax.js

Source:css-syntax.js Github

copy

Full Screen

...231 tokenizeerror();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 tokenizeerror();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 IdentifierToken(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 tokenizeerror();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 tokenizeerror();374 consumeTheRemnantsOfABadURL();375 return new BadURLToken();376 } else if(code == 0x5c) {377 if(startsWithAValidEscape()) {378 token.value += stringFromCode(consumeEscape());379 } else {380 tokenizeerror();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 == 0x2d || 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 if(iterationCount++ > str.length*2) throw new Error("The CSS Tokenizer is infinite-looping");535 }536 return tokens;537}538function CSSParserToken() { return this; }539CSSParserToken.prototype.toJSON = function() {540 return {token: this.tokenType};541}542CSSParserToken.prototype.toString = function() { return this.tokenType; }543CSSParserToken.prototype.toCSSString = function() { return ''+this; }544function BadStringToken() { return this; }545BadStringToken.prototype = new CSSParserToken;546BadStringToken.prototype.tokenType = "BADSTRING";547BadStringToken.prototype.toCSSString = function() { return "'"; }548function BadURLToken() { return this; }549BadURLToken.prototype = new CSSParserToken;550BadURLToken.prototype.tokenType = "BADURL";551BadURLToken.prototype.toCSSString = function() { return "url("; }552function WhitespaceToken() { return this; }553WhitespaceToken.prototype = new CSSParserToken;554WhitespaceToken.prototype.tokenType = "WHITESPACE";555WhitespaceToken.prototype.toString = function() { return "WS"; }556WhitespaceToken.prototype.toCSSString = function() { return " "; }557function CDOToken() { return this; }558CDOToken.prototype = new CSSParserToken;559CDOToken.prototype.tokenType = "CDO";560CDOToken.prototype.toCSSString = function() { return "<!--"; }561function CDCToken() { return this; }562CDCToken.prototype = new CSSParserToken;563CDCToken.prototype.tokenType = "CDC";564CDCToken.prototype.toCSSString = function() { return "-->"; }565function ColonToken() { return this; }566ColonToken.prototype = new CSSParserToken;567ColonToken.prototype.tokenType = ":";568function SemicolonToken() { return this; }569SemicolonToken.prototype = new CSSParserToken;570SemicolonToken.prototype.tokenType = ";";571function CommaToken() { return this; }572CommaToken.prototype = new CSSParserToken;573CommaToken.prototype.tokenType = ",";574CommaToken.prototype.value = ";"; // backwards-compat with DELIM token575function GroupingToken() { return this; }576GroupingToken.prototype = new CSSParserToken;577function OpenCurlyToken() { this.value = "{"; this.mirror = "}"; return this; }578OpenCurlyToken.prototype = new GroupingToken;579OpenCurlyToken.prototype.tokenType = "{";580function CloseCurlyToken() { this.value = "}"; this.mirror = "{"; return this; }581CloseCurlyToken.prototype = new GroupingToken;582CloseCurlyToken.prototype.tokenType = "}";583function OpenSquareToken() { this.value = "["; this.mirror = "]"; return this; }584OpenSquareToken.prototype = new GroupingToken;585OpenSquareToken.prototype.tokenType = "[";586function CloseSquareToken() { this.value = "]"; this.mirror = "["; return this; }587CloseSquareToken.prototype = new GroupingToken;588CloseSquareToken.prototype.tokenType = "]";589function OpenParenToken() { this.value = "("; this.mirror = ")"; return this; }590OpenParenToken.prototype = new GroupingToken;591OpenParenToken.prototype.tokenType = "(";592function CloseParenToken() { this.value = ")"; this.mirror = "("; return this; }593CloseParenToken.prototype = new GroupingToken;594CloseParenToken.prototype.tokenType = ")";595function IncludeMatchToken() { return this; }596IncludeMatchToken.prototype = new CSSParserToken;597IncludeMatchToken.prototype.tokenType = "~=";598function DashMatchToken() { return this; }599DashMatchToken.prototype = new CSSParserToken;600DashMatchToken.prototype.tokenType = "|=";...

Full Screen

Full Screen

cssTokenizer.js

Source:cssTokenizer.js Github

copy

Full Screen

...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 = "|=";...

Full Screen

Full Screen

tokenizer.js

Source:tokenizer.js Github

copy

Full Screen

...539function OpenSquareToken() { return this; }540OpenSquareToken.prototype = new CSSParserToken;541OpenSquareToken.prototype.tokenType = "[";542543function CloseSquareToken() { return this; }544CloseSquareToken.prototype = new CSSParserToken;545CloseSquareToken.prototype.tokenType = "]";546547function OpenParenToken() { return this; }548OpenParenToken.prototype = new CSSParserToken;549OpenParenToken.prototype.tokenType = "(";550551function CloseParenToken() { return this; }552CloseParenToken.prototype = new CSSParserToken;553CloseParenToken.prototype.tokenType = ")";554555function EOFToken() { return this; }556EOFToken.prototype = new CSSParserToken;557EOFToken.prototype.tokenType = "EOF"; ...

Full Screen

Full Screen

css-tokenizer.js

Source:css-tokenizer.js Github

copy

Full Screen

...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;...

Full Screen

Full Screen

cssParser.js

Source:cssParser.js Github

copy

Full Screen

1"use strict";2Object.defineProperty(exports, "__esModule", {3 value: true4});5exports.parseCSS = parseCSS;6exports.serializeSelector = serializeSelector;7var _selectorErrors = require("./selectorErrors");8var css = _interopRequireWildcard(require("./cssTokenizer"));9function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }10function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }11/**12 * Copyright (c) Microsoft Corporation.13 *14 * Licensed under the Apache License, Version 2.0 (the "License");15 * you may not use this file except in compliance with the License.16 * You may obtain a copy of the License at17 *18 * http://www.apache.org/licenses/LICENSE-2.019 *20 * Unless required by applicable law or agreed to in writing, software21 * distributed under the License is distributed on an "AS IS" BASIS,22 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.23 * See the License for the specific language governing permissions and24 * limitations under the License.25 */26function parseCSS(selector, customNames) {27 let tokens;28 try {29 tokens = css.tokenize(selector);30 if (!(tokens[tokens.length - 1] instanceof css.EOFToken)) tokens.push(new css.EOFToken());31 } catch (e) {32 const newMessage = e.message + ` while parsing selector "${selector}"`;33 const index = (e.stack || '').indexOf(e.message);34 if (index !== -1) e.stack = e.stack.substring(0, index) + newMessage + e.stack.substring(index + e.message.length);35 e.message = newMessage;36 throw e;37 }38 const unsupportedToken = tokens.find(token => {39 return token instanceof css.AtKeywordToken || token instanceof css.BadStringToken || token instanceof css.BadURLToken || token instanceof css.ColumnToken || token instanceof css.CDOToken || token instanceof css.CDCToken || token instanceof css.SemicolonToken || // TODO: Consider using these for something, e.g. to escape complex strings.40 // For example :xpath{ (//div/bar[@attr="foo"])[2]/baz }41 // Or this way :xpath( {complex-xpath-goes-here("hello")} )42 token instanceof css.OpenCurlyToken || token instanceof css.CloseCurlyToken || // TODO: Consider treating these as strings?43 token instanceof css.URLToken || token instanceof css.PercentageToken;44 });45 if (unsupportedToken) throw new _selectorErrors.InvalidSelectorError(`Unsupported token "${unsupportedToken.toSource()}" while parsing selector "${selector}"`);46 let pos = 0;47 const names = new Set();48 function unexpected() {49 return new _selectorErrors.InvalidSelectorError(`Unexpected token "${tokens[pos].toSource()}" while parsing selector "${selector}"`);50 }51 function skipWhitespace() {52 while (tokens[pos] instanceof css.WhitespaceToken) pos++;53 }54 function isIdent(p = pos) {55 return tokens[p] instanceof css.IdentToken;56 }57 function isString(p = pos) {58 return tokens[p] instanceof css.StringToken;59 }60 function isNumber(p = pos) {61 return tokens[p] instanceof css.NumberToken;62 }63 function isComma(p = pos) {64 return tokens[p] instanceof css.CommaToken;65 }66 function isCloseParen(p = pos) {67 return tokens[p] instanceof css.CloseParenToken;68 }69 function isStar(p = pos) {70 return tokens[p] instanceof css.DelimToken && tokens[p].value === '*';71 }72 function isEOF(p = pos) {73 return tokens[p] instanceof css.EOFToken;74 }75 function isClauseCombinator(p = pos) {76 return tokens[p] instanceof css.DelimToken && ['>', '+', '~'].includes(tokens[p].value);77 }78 function isSelectorClauseEnd(p = pos) {79 return isComma(p) || isCloseParen(p) || isEOF(p) || isClauseCombinator(p) || tokens[p] instanceof css.WhitespaceToken;80 }81 function consumeFunctionArguments() {82 const result = [consumeArgument()];83 while (true) {84 skipWhitespace();85 if (!isComma()) break;86 pos++;87 result.push(consumeArgument());88 }89 return result;90 }91 function consumeArgument() {92 skipWhitespace();93 if (isNumber()) return tokens[pos++].value;94 if (isString()) return tokens[pos++].value;95 return consumeComplexSelector();96 }97 function consumeComplexSelector() {98 const result = {99 simples: []100 };101 skipWhitespace();102 if (isClauseCombinator()) {103 // Put implicit ":scope" at the start. https://drafts.csswg.org/selectors-4/#absolutize104 result.simples.push({105 selector: {106 functions: [{107 name: 'scope',108 args: []109 }]110 },111 combinator: ''112 });113 } else {114 result.simples.push({115 selector: consumeSimpleSelector(),116 combinator: ''117 });118 }119 while (true) {120 skipWhitespace();121 if (isClauseCombinator()) {122 result.simples[result.simples.length - 1].combinator = tokens[pos++].value;123 skipWhitespace();124 } else if (isSelectorClauseEnd()) {125 break;126 }127 result.simples.push({128 combinator: '',129 selector: consumeSimpleSelector()130 });131 }132 return result;133 }134 function consumeSimpleSelector() {135 let rawCSSString = '';136 const functions = [];137 while (!isSelectorClauseEnd()) {138 if (isIdent() || isStar()) {139 rawCSSString += tokens[pos++].toSource();140 } else if (tokens[pos] instanceof css.HashToken) {141 rawCSSString += tokens[pos++].toSource();142 } else if (tokens[pos] instanceof css.DelimToken && tokens[pos].value === '.') {143 pos++;144 if (isIdent()) rawCSSString += '.' + tokens[pos++].toSource();else throw unexpected();145 } else if (tokens[pos] instanceof css.ColonToken) {146 pos++;147 if (isIdent()) {148 if (!customNames.has(tokens[pos].value.toLowerCase())) {149 rawCSSString += ':' + tokens[pos++].toSource();150 } else {151 const name = tokens[pos++].value.toLowerCase();152 functions.push({153 name,154 args: []155 });156 names.add(name);157 }158 } else if (tokens[pos] instanceof css.FunctionToken) {159 const name = tokens[pos++].value.toLowerCase();160 if (!customNames.has(name)) {161 rawCSSString += `:${name}(${consumeBuiltinFunctionArguments()})`;162 } else {163 functions.push({164 name,165 args: consumeFunctionArguments()166 });167 names.add(name);168 }169 skipWhitespace();170 if (!isCloseParen()) throw unexpected();171 pos++;172 } else {173 throw unexpected();174 }175 } else if (tokens[pos] instanceof css.OpenSquareToken) {176 rawCSSString += '[';177 pos++;178 while (!(tokens[pos] instanceof css.CloseSquareToken) && !isEOF()) rawCSSString += tokens[pos++].toSource();179 if (!(tokens[pos] instanceof css.CloseSquareToken)) throw unexpected();180 rawCSSString += ']';181 pos++;182 } else {183 throw unexpected();184 }185 }186 if (!rawCSSString && !functions.length) throw unexpected();187 return {188 css: rawCSSString || undefined,189 functions190 };191 }192 function consumeBuiltinFunctionArguments() {193 let s = '';194 while (!isCloseParen() && !isEOF()) s += tokens[pos++].toSource();195 return s;196 }197 const result = consumeFunctionArguments();198 if (!isEOF()) throw new _selectorErrors.InvalidSelectorError(`Error while parsing selector "${selector}"`);199 if (result.some(arg => typeof arg !== 'object' || !('simples' in arg))) throw new _selectorErrors.InvalidSelectorError(`Error while parsing selector "${selector}"`);200 return {201 selector: result,202 names: Array.from(names)203 };204}205function serializeSelector(args) {206 return args.map(arg => {207 if (typeof arg === 'string') return `"${arg}"`;208 if (typeof arg === 'number') return String(arg);209 return arg.simples.map(({210 selector,211 combinator212 }) => {213 let s = selector.css || '';214 s = s + selector.functions.map(func => `:${func.name}(${serializeSelector(func.args)})`).join('');215 if (combinator) s += ' ' + combinator;216 return s;217 }).join(' ');218 }).join(', ');...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const context = await browser.newContext();5 const page = await context.newPage();6 await page.keyboard.press('Enter');7 await page.keyboard.press('Escape');8 await browser.close();9})();

Full Screen

Using AI Code Generation

copy

Full Screen

1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch({4 });5 const context = await browser.newContext();6 const page = await context.newPage();7 await page.click('input[title="Search"]');8 await page.keyboard.type('Hello World');9 await page.keyboard.press('Enter');

Full Screen

Using AI Code Generation

copy

Full Screen

1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const page = await browser.newPage();5 await page.keyboard.press('Escape');6 await browser.close();7})();8await page.keyboard.press(']');9await page.keyboard.press(']');

Full Screen

Using AI Code Generation

copy

Full Screen

1const { chromium } = require('playwright');2const { CloseSquareToken } = require('playwright/lib/internal/keyboard');3(async () => {4 const browser = await chromium.launch();5 const context = await browser.newContext();6 const page = await context.newPage();7 await page.click('text=Get started');8 await page.waitForSelector('text=Playwright is a Node library to automate Chromium, Firefox and WebKit with a single API');9 await page.keyboard.press('Escape');10 await page.keyboard.press(CloseSquareToken);11 await browser.close();12})();

Full Screen

Using AI Code Generation

copy

Full Screen

1const { chromium } = require('playwright');2const { CloseSquareToken } = require('playwright/lib/server/chromium');3(async () => {4 const browser = await chromium.launch();5 const context = await browser.newContext();6 const page = await context.newPage();7 await page.click('text=Google apps'

Full Screen

Using AI Code Generation

copy

Full Screen

1const {chromium} = require('playwright');2const fs = require('fs');3(async () => {4 const browser = await chromium.launch({ headless: false});5 const context = await browser.newContext();6 const page = await context.newPage();7 await page.waitForTimeout(5000);8 await page.evaluate(() => {9 const token = window['Playwright'].CloseSquareToken;10 fs.writeFileSync('token.txt', token);11 });12 await browser.close();13})();14const {chromium} = require('playwright');15const fs = require('fs');16(async () => {17 const browser = await chromium.launch({ headless: false});18 const context = await browser.newContext();19 const page = await context.newPage();20 await page.waitForTimeout(5000);21 const token = fs.readFileSync('token.txt', 'utf8');22 await page.evaluate(token => {23 window['Playwright'].CloseSquareToken(token);24 }, token);25 await browser.close();26})();

Full Screen

Using AI Code Generation

copy

Full Screen

1const { webkit } = require('playwright');2const { CloseSquareToken } = require('playwright/lib/server/webkit/wkPage');3(async () => {4 const browser = await webkit.launch();5 const page = await browser.newPage();6 await page.waitForSelector('input[name="q"]');7 await page.type('input[name="q"]', 'Playwright');8 await page.keyboard.press('Enter');9 await page.waitForSelector('text=Playwright');10 await page.click('text=Playwright');11 const token = new CloseSquareToken();12 await page.evaluate((token) => {13 window.close = token;14 }, token);15 await page.click('text=Playwright');16 await page.waitForTimeout(5000);17 await browser.close();18})();19const { helper } = require('../helper');20const { assert } = require('../helper');21const { WKSession } = require('./wkConnection');22const { WKExecutionContext } = require('./wkExecutionContext');23const { WKInterceptableRequest } = require('./wkInterceptableRequest');24const { WKInterceptableResponse } = require('./wkInterceptableResponse');25const { WKSessionDelegate } = require('./wkSessionDelegate');26const { WKTransport } = require('./wkTransport');27const { WKWebSocketTransport } = require('./wkWebSocketTransport');28const { Page } = require('../page');29const { Events: PageEvents } = Page;30const { Events: FrameManagerEvents } = require('../frameManager');31const { Events: NetworkManagerEvents } = require('../networkManager');32const { Events: DialogEvents } = require('../dialog');33const { Events: DownloadEvents } = require('../download');34const { Events: ConsoleMessageEvents } = require('../consoleMessage');35const { Events: WorkerEvents } = require('../worker');36const { Events: BrowserContextEvents } = require('../browserContext');37const { Events: CRBrowserEvents } = require('../chromium/crBrowser');38const { Events: CRPageEvents } = require('../chromium/crPage');39const { Events: CRSessionEvents } = require('../chromium/crConnection');40const { assertMaxArgs } = require('../utils/utils');41const { TimeoutError } = require('../../utils/errors');42const { Close

Full Screen

Using AI Code Generation

copy

Full Screen

1var pw = require('playwright');2(async () => {3 const browser = await pw.chromium.launch();4 const context = await browser.newContext();5 const page = await context.newPage();6 await page.keyboard.press('Shift+Enter');7 await page.keyboard.closeSquareToken();8 await browser.close();9})();

Full Screen

Using AI Code Generation

copy

Full Screen

1const { CloseSquareToken } = require('@playwright/test');2const { test } = require('@playwright/test');3test('test', async ({ page }) => {4 const token = new CloseSquareToken(page);5 await token.click();6});

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