Best JavaScript code snippet using playwright-internal
parse-css.js
Source:parse-css.js
...684IdentToken.prototype = Object.create(StringValuedToken.prototype);685IdentToken.prototype.tokenType = "ident";686IdentToken.prototype.toString = function() { return "IDENT("+this.value+")"; };687IdentToken.prototype.toSource = function() {688 return escapeIdent(this.value);689};690function FunctionToken(val) {691 this.value = val;692 this.text = val;693 this.mirror = ")";694}695FunctionToken.prototype = Object.create(StringValuedToken.prototype);696FunctionToken.prototype.tokenType = "function";697FunctionToken.prototype.toString = function() { return "FUNCTION("+this.value+")"; };698FunctionToken.prototype.toSource = function() {699 return escapeIdent(this.value) + "(";700};701function AtKeywordToken(val) {702 this.value = val;703 this.text = val;704}705AtKeywordToken.prototype = Object.create(StringValuedToken.prototype);706AtKeywordToken.prototype.tokenType = "at";707AtKeywordToken.prototype.toString = function() { return "AT("+this.value+")"; };708AtKeywordToken.prototype.toSource = function() {709 return "@" + escapeIdent(this.value);710};711function HashToken(val) {712 this.value = val;713 this.text = val;714 this.type = "unrestricted";715}716HashToken.prototype = Object.create(StringValuedToken.prototype);717HashToken.prototype.tokenType = "hash";718HashToken.prototype.toString = function() { return "HASH("+this.value+")"; };719HashToken.prototype.toJSON = function() {720 var json = this.constructor.prototype.constructor.prototype.toJSON.call(this);721 json.value = this.value;722 json.type = this.type;723 return json;724};725HashToken.prototype.toSource = function() {726 if(this.type == "id") {727 return "#" + escapeIdent(this.value);728 } else {729 return "#" + escapeHash(this.value);730 }731};732function StringToken(val) {733 this.value = val;734 this.text = val;735}736StringToken.prototype = Object.create(StringValuedToken.prototype);737StringToken.prototype.tokenType = "string";738StringToken.prototype.toString = function() {739 return '"' + escapeString(this.value) + '"';740};741function CommentToken(val) {742 this.value = val;743}744CommentToken.prototype = Object.create(StringValuedToken.prototype);745CommentToken.prototype.tokenType = "comment";746CommentToken.prototype.toString = function() {747 return '/*' + this.value + '*/';748}749CommentToken.prototype.toSource = CommentToken.prototype.toString;750function URLToken(val) {751 this.value = val;752 this.text = val;753}754URLToken.prototype = Object.create(StringValuedToken.prototype);755URLToken.prototype.tokenType = "url";756URLToken.prototype.toString = function() { return "URL("+this.value+")"; };757URLToken.prototype.toSource = function() {758 return 'url("' + escapeString(this.value) + '")';759};760function NumberToken() {761 this.value = null;762 this.type = "integer";763 this.repr = "";764}765NumberToken.prototype = Object.create(CSSParserToken.prototype);766NumberToken.prototype.tokenType = "number";767NumberToken.prototype.toString = function() {768 if(this.type == "integer")769 return "INT("+this.value+")";770 return "NUMBER("+this.value+")";771};772NumberToken.prototype.toJSON = function() {773 var json = this.constructor.prototype.constructor.prototype.toJSON.call(this);774 json.value = this.value;775 json.type = this.type;776 json.repr = this.repr;777 return json;778};779NumberToken.prototype.toSource = function() { return this.repr; };780function PercentageToken() {781 this.value = null;782 this.repr = "";783}784PercentageToken.prototype = Object.create(CSSParserToken.prototype);785PercentageToken.prototype.tokenType = "percentage";786PercentageToken.prototype.toString = function() { return "PERCENTAGE("+this.value+")"; };787PercentageToken.prototype.toJSON = function() {788 var json = this.constructor.prototype.constructor.prototype.toJSON.call(this);789 json.value = this.value;790 json.repr = this.repr;791 return json;792};793PercentageToken.prototype.toSource = function() { return this.repr + "%"; };794function DimensionToken() {795 this.value = null;796 this.type = "integer";797 this.repr = "";798 this.unit = "";799}800DimensionToken.prototype = Object.create(CSSParserToken.prototype);801DimensionToken.prototype.tokenType = "dimension";802DimensionToken.prototype.toString = function() { return "DIM("+this.value+","+this.unit+")"; };803DimensionToken.prototype.toJSON = function() {804 var json = this.constructor.prototype.constructor.prototype.toJSON.call(this);805 json.value = this.value;806 json.type = this.type;807 json.repr = this.repr;808 json.unit = this.unit;809 return json;810};811DimensionToken.prototype.toSource = function() {812 var source = this.repr;813 var unit = escapeIdent(this.unit);814 if(unit[0].toLowerCase() == "e" && (unit[1] == "-" || between(unit.charCodeAt(1), 0x30, 0x39))) {815 // Unit is ambiguous with scinot816 // Remove the leading "e", replace with escape.817 unit = "\\65 " + unit.slice(1, unit.length);818 }819 return source+unit;820};821function escapeIdent(string) {822 string = ''+string;823 var result = '';824 var firstcode = string.charCodeAt(0);825 for(var i = 0; i < string.length; i++) {826 var code = string.charCodeAt(i);827 if(code === 0x0) {828 throw new InvalidCharacterError('Invalid character: the input contains U+0000.');829 }830 if(831 between(code, 0x1, 0x1f) || code == 0x7f ||832 (i === 0 && between(code, 0x30, 0x39)) ||833 (i == 1 && between(code, 0x30, 0x39) && firstcode == 0x2d)834 ) {835 result += '\\' + code.toString(16) + ' ';836 } else if(837 code >= 0x80 ||838 code == 0x2d ||839 code == 0x5f ||840 between(code, 0x30, 0x39) ||841 between(code, 0x41, 0x5a) ||842 between(code, 0x61, 0x7a)843 ) {844 result += string[i];845 } else {846 result += '\\' + string[i];847 }848 }849 return result;850}851function escapeHash(string) {852 // Escapes the contents of "unrestricted"-type hash tokens.853 // Won't preserve the ID-ness of "id"-type hash tokens;854 // use escapeIdent() for that.855 string = ''+string;856 var result = '';857 for(var i = 0; i < string.length; i++) {858 var code = string.charCodeAt(i);859 if(code === 0x0) {860 throw new InvalidCharacterError('Invalid character: the input contains U+0000.');861 }862 if(863 code >= 0x80 ||864 code == 0x2d ||865 code == 0x5f ||866 between(code, 0x30, 0x39) ||867 between(code, 0x41, 0x5a) ||868 between(code, 0x61, 0x7a)...
css-syntax.js
Source:css-syntax.js
...635IdentifierToken.prototype = new StringValuedToken;636IdentifierToken.prototype.tokenType = "IDENT";637IdentifierToken.prototype.toString = function() { return "IDENT("+this.value+")"; }638IdentifierToken.prototype.toCSSString = function() {639 return escapeIdent(this.value);640}641function FunctionToken(val) {642 this.value = val;643 this.mirror = ")";644}645FunctionToken.prototype = new StringValuedToken;646FunctionToken.prototype.tokenType = "FUNCTION";647FunctionToken.prototype.toString = function() { return "FUNCTION("+this.value+")"; }648FunctionToken.prototype.toCSSString = function() {649 return escapeIdent(this.value) + "(";650}651 652function AtKeywordToken(val) {653 this.value = val;654}655AtKeywordToken.prototype = new StringValuedToken;656AtKeywordToken.prototype.tokenType = "AT-KEYWORD";657AtKeywordToken.prototype.toString = function() { return "AT("+this.value+")"; }658AtKeywordToken.prototype.toCSSString = function() {659 return "@" + escapeIdent(this.value);660}661function HashToken(val) {662 this.value = val;663 this.type = "unrestricted";664}665HashToken.prototype = new StringValuedToken;666HashToken.prototype.tokenType = "HASH";667HashToken.prototype.toString = function() { return "HASH("+this.value+")"; }668HashToken.prototype.toCSSString = function() {669 var escapeValue = (this.type == "id") ? escapeIdent : escapeHash;670 return "#" + escapeValue(this.value);671}672function StringToken(val) {673this.value = val;674}675StringToken.prototype = new StringValuedToken;676StringToken.prototype.tokenType = "STRING";677StringToken.prototype.toString = function() {678 return '"' + escapeString(this.value) + '"';679}680function URLToken(val) {681 this.value = val;682}683URLToken.prototype = new StringValuedToken;684URLToken.prototype.tokenType = "URL";685URLToken.prototype.toString = function() { return "URL("+this.value+")"; }686URLToken.prototype.toCSSString = function() {687 return 'url("' + escapeString(this.value) + '")';688}689function NumberToken() {690 this.value = null;691 this.type = "integer";692 this.repr = "";693}694NumberToken.prototype = new CSSParserToken;695NumberToken.prototype.tokenType = "NUMBER";696NumberToken.prototype.toString = function() {697 if(this.type == "integer")698 return "INT("+this.value+")";699 return "NUMBER("+this.value+")";700}701NumberToken.prototype.toJSON = function() {702 var json = this.constructor.prototype.constructor.prototype.toJSON.call(this);703 json.value = this.value;704 json.type = this.type;705 json.repr = this.repr;706 return json;707}708NumberToken.prototype.toCSSString = function() { return this.repr; };709function PercentageToken() {710 this.value = null;711 this.repr = "";712}713PercentageToken.prototype = new CSSParserToken;714PercentageToken.prototype.tokenType = "PERCENTAGE";715PercentageToken.prototype.toString = function() { return "PERCENTAGE("+this.value+")"; }716PercentageToken.prototype.toCSSString = function() { return this.repr + "%"; }717function DimensionToken() {718 this.value = null;719 this.type = "integer";720 this.repr = "";721 this.unit = "";722}723DimensionToken.prototype = new CSSParserToken;724DimensionToken.prototype.tokenType = "DIMENSION";725DimensionToken.prototype.toString = function() { return "DIM("+this.value+","+this.unit+")"; }726DimensionToken.prototype.toCSSString = function() {727 var source = this.repr;728 var unit = escapeIdent(this.unit);729 if(unit[0].toLowerCase() == "e" && (unit[1] == "-" || between(unit.charCodeAt(1), 0x30, 0x39))) {730 // Unit is ambiguous with scinot731 // Remove the leading "e", replace with escape.732 unit = "\\65 " + unit.slice(1, unit.length);733 }734 return source+unit;735}736function escapeIdent(string) {737 string = ''+string;738 var result = '';739 var firstcode = string.charCodeAt(0);740 for(var i = 0; i < string.length; i++) {741 var code = string.charCodeAt(i);742 if(code == 0x0) {743 throw new InvalidCharacterError('Invalid character: the input contains U+0000.');744 }745 if(746 between(code, 0x1, 0x1f) || code == 0x7f ||747 (i == 0 && between(code, 0x30, 0x39)) ||748 (i == 1 && between(code, 0x30, 0x39) && firstcode == 0x2d)749 ) {750 result += '\\' + code.toString(16) + ' ';751 } else if(752 code >= 0x80 ||753 code == 0x2d ||754 code == 0x5f ||755 between(code, 0x30, 0x39) ||756 between(code, 0x41, 0x5a) ||757 between(code, 0x61, 0x7a)758 ) {759 result += string[i];760 } else {761 result += '\\' + string[i];762 }763 }764 return result;765}766function escapeHash(string) {767 // Escapes the contents of "unrestricted"-type hash tokens.768 // Won't preserve the ID-ness of "id"-type hash tokens;769 // use escapeIdent() for that.770 string = ''+string;771 var result = '';772 var firstcode = string.charCodeAt(0);773 for(var i = 0; i < string.length; i++) {774 var code = string.charCodeAt(i);775 if(code == 0x0) {776 throw new InvalidCharacterError('Invalid character: the input contains U+0000.');777 }778 if(779 code >= 0x80 ||780 code == 0x2d ||781 code == 0x5f ||782 between(code, 0x30, 0x39) ||783 between(code, 0x41, 0x5a) ||784 between(code, 0x61, 0x7a)785 ) {786 result += string[i];787 } else {788 result += '\\' + code.toString(16) + ' ';789 }790 }791 return result;792}793function escapeString(string) {794 string = ''+string;795 var result = '';796 for(var i = 0; i < string.length; i++) {797 var code = string.charCodeAt(i);798 if(code == 0x0) {799 throw new InvalidCharacterError('Invalid character: the input contains U+0000.');800 }801 if(between(code, 0x1, 0x1f) || code == 0x7f) {802 result += '\\' + code.toString(16) + ' ';803 } else if(code == 0x22 || code == 0x5c) {804 result += '\\' + string[i];805 } else {806 result += string[i];807 }808 }809 return result;810}811// Exportation.812cssSyntax.tokenize = tokenize;813cssSyntax.IdentToken = IdentifierToken;814cssSyntax.IdentifierToken = IdentifierToken;815cssSyntax.FunctionToken = FunctionToken;816cssSyntax.AtKeywordToken = AtKeywordToken;817cssSyntax.HashToken = HashToken;818cssSyntax.StringToken = StringToken;819cssSyntax.BadStringToken = BadStringToken;820cssSyntax.URLToken = URLToken;821cssSyntax.BadURLToken = BadURLToken;822cssSyntax.DelimToken = DelimToken;823cssSyntax.NumberToken = NumberToken;824cssSyntax.PercentageToken = PercentageToken;825cssSyntax.DimensionToken = DimensionToken;826cssSyntax.IncludeMatchToken = IncludeMatchToken;827cssSyntax.DashMatchToken = DashMatchToken;828cssSyntax.PrefixMatchToken = PrefixMatchToken;829cssSyntax.SuffixMatchToken = SuffixMatchToken;830cssSyntax.SubstringMatchToken = SubstringMatchToken;831cssSyntax.ColumnToken = ColumnToken;832cssSyntax.WhitespaceToken = WhitespaceToken;833cssSyntax.CDOToken = CDOToken;834cssSyntax.CDCToken = CDCToken;835cssSyntax.ColonToken = ColonToken;836cssSyntax.SemicolonToken = SemicolonToken;837cssSyntax.CommaToken = CommaToken;838cssSyntax.OpenParenToken = OpenParenToken;839cssSyntax.CloseParenToken = CloseParenToken;840cssSyntax.OpenSquareToken = OpenSquareToken;841cssSyntax.CloseSquareToken = CloseSquareToken;842cssSyntax.OpenCurlyToken = OpenCurlyToken;843cssSyntax.CloseCurlyToken = CloseCurlyToken;844cssSyntax.EOFToken = EOFToken;845cssSyntax.CSSParserToken = CSSParserToken;846cssSyntax.GroupingToken = GroupingToken;847//848// css parser849//850function TokenStream(tokens) {851 // Assume that tokens is an array.852 this.tokens = tokens;853 this.i = -1;854}855TokenStream.prototype.tokenAt = function(i) {856 if(i < this.tokens.length)857 return this.tokens[i];858 return new EOFToken();859}860TokenStream.prototype.consume = function(num) {861 if(num === undefined) num = 1;862 this.i += num;863 this.token = this.tokenAt(this.i);864 //console.log(this.i, this.token);865 return true;866}867TokenStream.prototype.next = function() {868 return this.tokenAt(this.i+1);869}870TokenStream.prototype.reconsume = function() {871 this.i--;872}873function parseerror(s, msg) {874 console.log("Parse error at token " + s.i + ": " + s.token + ".\n" + msg);875 return true;876}877function donothing(){ return true; };878function consumeAListOfRules(s, topLevel) {879 var rules = new TokenList();880 var rule;881 while(s.consume()) {882 if(s.token instanceof WhitespaceToken) {883 continue;884 } else if(s.token instanceof EOFToken) {885 return rules;886 } else if(s.token instanceof CDOToken || s.token instanceof CDCToken) {887 if(topLevel == "top-level") continue;888 s.reconsume();889 if(rule = consumeAStyleRule(s)) rules.push(rule);890 } else if(s.token instanceof AtKeywordToken) {891 s.reconsume();892 if(rule = consumeAnAtRule(s)) rules.push(rule);893 } else {894 s.reconsume();895 if(rule = consumeAStyleRule(s)) rules.push(rule);896 }897 }898}899function consumeAnAtRule(s) {900 s.consume();901 var rule = new AtRule(s.token.value);902 while(s.consume()) {903 if(s.token instanceof SemicolonToken || s.token instanceof EOFToken) {904 return rule;905 } else if(s.token instanceof OpenCurlyToken) {906 rule.value = consumeASimpleBlock(s);907 return rule;908 } else if(s.token instanceof SimpleBlock && s.token.name == "{") {909 rule.value = s.token;910 return rule;911 } else {912 s.reconsume();913 rule.prelude.push(consumeAComponentValue(s));914 }915 }916}917function consumeAStyleRule(s) {918 var rule = new StyleRule();919 while(s.consume()) {920 if(s.token instanceof EOFToken) {921 parseerror(s, "Hit EOF when trying to parse the prelude of a qualified rule.");922 return;923 } else if(s.token instanceof OpenCurlyToken) {924 rule.value = consumeASimpleBlock(s);925 return rule;926 } else if(s.token instanceof SimpleBlock && s.token.name == "{") {927 rule.value = s.token;928 return rule;929 } else {930 s.reconsume();931 rule.prelude.push(consumeAComponentValue(s));932 }933 }934}935function consumeAListOfDeclarations(s) {936 var decls = new TokenList();937 while(s.consume()) {938 if(s.token instanceof WhitespaceToken || s.token instanceof SemicolonToken) {939 donothing();940 } else if(s.token instanceof EOFToken) {941 return decls;942 } else if(s.token instanceof AtKeywordToken) {943 s.reconsume();944 decls.push(consumeAnAtRule(s));945 } else if(s.token instanceof IdentifierToken) {946 var temp = [s.token];947 while(!(s.next() instanceof SemicolonToken || s.next() instanceof EOFToken))948 temp.push(consumeAComponentValue(s));949 var decl;950 if(decl = consumeADeclaration(new TokenStream(temp))) decls.push(decl);951 } else {952 parseerror(s);953 s.reconsume();954 while(!(s.next() instanceof SemicolonToken || s.next() instanceof EOFToken))955 consumeAComponentValue(s);956 }957 }958}959function consumeADeclaration(s) {960 // Assumes that the next input token will be an ident token.961 s.consume();962 var decl = new Declaration(s.token.value);963 while(s.next() instanceof WhitespaceToken) s.consume();964 if(!(s.next() instanceof ColonToken)) {965 parseerror(s);966 return;967 } else {968 s.consume();969 }970 while(!(s.next() instanceof EOFToken)) {971 decl.value.push(consumeAComponentValue(s));972 }973 var foundImportant = false;974 for(var i = decl.value.length - 1; i >= 0; i--) {975 if(decl.value[i] instanceof WhitespaceToken) {976 continue;977 } else if(decl.value[i] instanceof IdentifierToken && decl.value[i].ASCIIMatch("important")) {978 foundImportant = true;979 } else if(foundImportant && decl.value[i] instanceof DelimToken && decl.value[i].value == "!") {980 decl.value.splice(i, decl.value.length);981 decl.important = true;982 break;983 } else {984 break;985 }986 }987 return decl;988}989function consumeAComponentValue(s) {990 s.consume();991 if(s.token instanceof OpenCurlyToken || s.token instanceof OpenSquareToken || s.token instanceof OpenParenToken)992 return consumeASimpleBlock(s);993 if(s.token instanceof FunctionToken)994 return consumeAFunction(s);995 return s.token;996}997function consumeASimpleBlock(s) {998 var mirror = s.token.mirror;999 var block = new SimpleBlock(s.token.value);1000 while(s.consume()) {1001 if(s.token instanceof EOFToken || (s.token instanceof GroupingToken && s.token.value == mirror))1002 return block;1003 else {1004 s.reconsume();1005 block.value.push(consumeAComponentValue(s));1006 }1007 }1008}1009function consumeAFunction(s) {1010 var func = new Func(s.token.value);1011 while(s.consume()) {1012 if(s.token instanceof EOFToken || s.token instanceof CloseParenToken)1013 return func;1014 else {1015 s.reconsume();1016 func.value.push(consumeAComponentValue(s));1017 }1018 }1019}1020function normalizeInput(input) {1021 if(typeof input == "string")1022 return new TokenStream(tokenize(input));1023 if(input instanceof TokenStream)1024 return input;1025 if(input.length !== undefined)1026 return new TokenStream(input);1027 else throw SyntaxError(input);1028}1029function parseAStylesheet(s) {1030 s = normalizeInput(s);1031 var sheet = new Stylesheet();1032 sheet.value = consumeAListOfRules(s, "top-level");1033 return sheet;1034}1035function parseAListOfRules(s) {1036 s = normalizeInput(s);1037 return consumeAListOfRules(s);1038}1039function parseARule(s) {1040 s = normalizeInput(s);1041 while(s.next() instanceof WhitespaceToken) s.consume();1042 if(s.next() instanceof EOFToken) throw SyntaxError();1043 if(s.next() instanceof AtKeywordToken) {1044 var rule = consumeAnAtRule(s);1045 } else {1046 var rule = consumeAStyleRule(s);1047 if(!rule) throw SyntaxError();1048 }1049 while(s.next() instanceof WhitespaceToken) s.consume();1050 if(s.next() instanceof EOFToken)1051 return rule;1052 throw SyntaxError();1053}1054function parseADeclaration(s) {1055 s = normalizeInput(s);1056 while(s.next() instanceof WhitespaceToken) s.consume();1057 if(!(s.next() instanceof IdentifierToken)) throw SyntaxError();1058 var decl = consumeADeclaration(s);1059 if(!decl) { throw new SyntaxError() }1060 return decl;1061}1062function parseAListOfDeclarations(s) {1063 s = normalizeInput(s);1064 return consumeAListOfDeclarations(s);1065}1066function parseAComponentValue(s) {1067 s = normalizeInput(s);1068 while(s.next() instanceof WhitespaceToken) s.consume();1069 if(s.next() instanceof EOFToken) throw SyntaxError();1070 var val = consumeAComponentValue(s);1071 if(!val) throw SyntaxError();1072 while(s.next() instanceof WhitespaceToken) s.consume();1073 if(!(s.next() instanceof EOFToken)) throw new SyntaxError();1074 return val;1075}1076function parseAListOfComponentValues(s) {1077 s = normalizeInput(s);1078 var vals = new TokenList();1079 while(true) {1080 var val = consumeAComponentValue(s);1081 if(val instanceof EOFToken)1082 return vals1083 else1084 vals.push(val);1085 }1086}1087function parseACommaSeparatedListOfComponentValues(s) {1088 s = normalizeInput(s);1089 var listOfCVLs = new TokenList();1090 while(true) {1091 var vals = new TokenList();1092 while(true) {1093 var val = consumeAComponentValue(s);1094 if(val instanceof EOFToken) {1095 listOfCVLs.push(vals);1096 return listOfCVLs;1097 } else if(val instanceof CommaToken) {1098 listOfCVLs.push(vals);1099 break;1100 } else {1101 vals.push(val);1102 }1103 }1104 }1105}1106function CSSParserRule() { return this; }1107CSSParserRule.prototype.toString = function(indent) {1108 return JSON.stringify(this,null,indent);1109}1110function Stylesheet() {1111 this.value = new TokenList();1112 return this;1113}1114Stylesheet.prototype = new CSSParserRule;1115Stylesheet.prototype.type = "STYLESHEET";1116Stylesheet.prototype.toCSSString = function() { return this.value.toCSSString("\n"); }1117function AtRule(name) {1118 this.name = name;1119 this.prelude = new TokenList();1120 this.value = null;1121 return this;1122}1123AtRule.prototype = new CSSParserRule;1124AtRule.prototype.toCSSString = function() { 1125 if(this.value) {1126 return "@" + escapeIdent(this.name) + " " + this.prelude.toCSSString() + this.value.toCSSString(); 1127 } else {1128 return "@" + escapeIdent(this.name) + " " + this.prelude.toCSSString() + '; '; 1129 }1130}1131AtRule.prototype.toStylesheet = function() {1132 return this.asStylesheet || (this.asStylesheet = this.value ? parseAStylesheet(this.value.value) : new Stylesheet());1133}1134function StyleRule() {1135 this.prelude = new TokenList(); this.selector = this.prelude;1136 this.value = null;1137 return this;1138}1139StyleRule.prototype = new CSSParserRule;1140StyleRule.prototype.type = "STYLE-RULE";1141StyleRule.prototype.toCSSString = function() {1142 return this.prelude.toCSSString() + this.value.toCSSString();...
cssTokenizer.js
Source:cssTokenizer.js
...646IdentToken.prototype = Object.create(StringValuedToken.prototype);647IdentToken.prototype.tokenType = "IDENT";648IdentToken.prototype.toString = function() { return "IDENT("+this.value+")"; }649IdentToken.prototype.toSource = function() {650 return escapeIdent(this.value);651}652function FunctionToken(val) {653 this.value = val;654 this.mirror = ")";655}656FunctionToken.prototype = Object.create(StringValuedToken.prototype);657FunctionToken.prototype.tokenType = "FUNCTION";658FunctionToken.prototype.toString = function() { return "FUNCTION("+this.value+")"; }659FunctionToken.prototype.toSource = function() {660 return escapeIdent(this.value) + "(";661}662function AtKeywordToken(val) {663 this.value = val;664}665AtKeywordToken.prototype = Object.create(StringValuedToken.prototype);666AtKeywordToken.prototype.tokenType = "AT-KEYWORD";667AtKeywordToken.prototype.toString = function() { return "AT("+this.value+")"; }668AtKeywordToken.prototype.toSource = function() {669 return "@" + escapeIdent(this.value);670}671function HashToken(val) {672 this.value = val;673 this.type = "unrestricted";674}675HashToken.prototype = Object.create(StringValuedToken.prototype);676HashToken.prototype.tokenType = "HASH";677HashToken.prototype.toString = function() { return "HASH("+this.value+")"; }678HashToken.prototype.toJSON = function() {679 var json = this.constructor.prototype.constructor.prototype.toJSON.call(this);680 json.value = this.value;681 json.type = this.type;682 return json;683}684HashToken.prototype.toSource = function() {685 if(this.type == "id") {686 return "#" + escapeIdent(this.value);687 } else {688 return "#" + escapeHash(this.value);689 }690}691function StringToken(val) {692 this.value = val;693}694StringToken.prototype = Object.create(StringValuedToken.prototype);695StringToken.prototype.tokenType = "STRING";696StringToken.prototype.toString = function() {697 return '"' + escapeString(this.value) + '"';698}699function URLToken(val) {700 this.value = val;701}702URLToken.prototype = Object.create(StringValuedToken.prototype);703URLToken.prototype.tokenType = "URL";704URLToken.prototype.toString = function() { return "URL("+this.value+")"; }705URLToken.prototype.toSource = function() {706 return 'url("' + escapeString(this.value) + '")';707}708function NumberToken() {709 this.value = null;710 this.type = "integer";711 this.repr = "";712}713NumberToken.prototype = Object.create(CSSParserToken.prototype);714NumberToken.prototype.tokenType = "NUMBER";715NumberToken.prototype.toString = function() {716 if(this.type == "integer")717 return "INT("+this.value+")";718 return "NUMBER("+this.value+")";719}720NumberToken.prototype.toJSON = function() {721 var json = this.constructor.prototype.constructor.prototype.toJSON.call(this);722 json.value = this.value;723 json.type = this.type;724 json.repr = this.repr;725 return json;726}727NumberToken.prototype.toSource = function() { return this.repr; };728function PercentageToken() {729 this.value = null;730 this.repr = "";731}732PercentageToken.prototype = Object.create(CSSParserToken.prototype);733PercentageToken.prototype.tokenType = "PERCENTAGE";734PercentageToken.prototype.toString = function() { return "PERCENTAGE("+this.value+")"; }735PercentageToken.prototype.toJSON = function() {736 var json = this.constructor.prototype.constructor.prototype.toJSON.call(this);737 json.value = this.value;738 json.repr = this.repr;739 return json;740}741PercentageToken.prototype.toSource = function() { return this.repr + "%"; }742function DimensionToken() {743 this.value = null;744 this.type = "integer";745 this.repr = "";746 this.unit = "";747}748DimensionToken.prototype = Object.create(CSSParserToken.prototype);749DimensionToken.prototype.tokenType = "DIMENSION";750DimensionToken.prototype.toString = function() { return "DIM("+this.value+","+this.unit+")"; }751DimensionToken.prototype.toJSON = function() {752 var json = this.constructor.prototype.constructor.prototype.toJSON.call(this);753 json.value = this.value;754 json.type = this.type;755 json.repr = this.repr;756 json.unit = this.unit;757 return json;758}759DimensionToken.prototype.toSource = function() {760 var source = this.repr;761 var unit = escapeIdent(this.unit);762 if(unit[0].toLowerCase() == "e" && (unit[1] == "-" || between(unit.charCodeAt(1), 0x30, 0x39))) {763 // Unit is ambiguous with scinot764 // Remove the leading "e", replace with escape.765 unit = "\\65 " + unit.slice(1, unit.length);766 }767 return source+unit;768}769function escapeIdent(string) {770 string = ''+string;771 var result = '';772 var firstcode = string.charCodeAt(0);773 for(var i = 0; i < string.length; i++) {774 var code = string.charCodeAt(i);775 if(code == 0x0) {776 throw new InvalidCharacterError('Invalid character: the input contains U+0000.');777 }778 if(779 between(code, 0x1, 0x1f) || code == 0x7f ||780 (i == 0 && between(code, 0x30, 0x39)) ||781 (i == 1 && between(code, 0x30, 0x39) && firstcode == 0x2d)782 ) {783 result += '\\' + code.toString(16) + ' ';784 } else if(785 code >= 0x80 ||786 code == 0x2d ||787 code == 0x5f ||788 between(code, 0x30, 0x39) ||789 between(code, 0x41, 0x5a) ||790 between(code, 0x61, 0x7a)791 ) {792 result += string[i];793 } else {794 result += '\\' + string[i];795 }796 }797 return result;798}799function escapeHash(string) {800 // Escapes the contents of "unrestricted"-type hash tokens.801 // Won't preserve the ID-ness of "id"-type hash tokens;802 // use escapeIdent() for that.803 string = ''+string;804 var result = '';805 var firstcode = string.charCodeAt(0);806 for(var i = 0; i < string.length; i++) {807 var code = string.charCodeAt(i);808 if(code == 0x0) {809 throw new InvalidCharacterError('Invalid character: the input contains U+0000.');810 }811 if(812 code >= 0x80 ||813 code == 0x2d ||814 code == 0x5f ||815 between(code, 0x30, 0x39) ||816 between(code, 0x41, 0x5a) ||...
custom.js
Source:custom.js
...225 {226 var line;227 var ni = i-range.startl+1;228 if (i == range.startl-1)229 line = lines[i].slice(0, range.startc) + prefix + "." + utils.escapeIdent(names[ni]);230 else if (i > range.startl-1 && ni < names.length-1)231 line = utils.repeat(' ', range.startc) + prefix + "." + utils.escapeIdent(names[ni]);232 else if (ni == names.length-1)233 {234 var suffix = lines[range.endl-1].slice(range.endc+1);235 line = utils.repeat(' ', range.startc) + prefix + "." + utils.escapeIdent(names[ni]) + suffix;236 newEndl = i + 1;237 newEndc = line.length - suffix.length - 1;238 }239 else if (ni > names.length-1)240 line = lines[i-names.length+(range.endl-range.startl+1)];241 else242 line = lines[i];243 newLines.push(line);244 }245 range.endl = newEndl;246 range.endc = newEndc;247 setSource(id, newLines.join("\n"),false);248 };249 sel.on("change", updateSource1);250 }251 else252 {253 var range = { line: vis.range[0], start: vis.range[1], end: vis.range[3] };254 function updateSource2() {255 var f = window[id + "_offsetf"];256 if (!f) f = function(l) { return l; };257 var lines = window[id + "_source"].split('\n');258 var line = lines[f(range.line) - 1];259 var name = utils.escapeIdent(sel.val());260 lines[f(range.line) - 1] = line.slice(0, range.start) + name + line.slice(range.end + 1);261 range.end = range.start + name.length - 1;262 setSource(id, lines.join("\n"),false);263 };264 sel.on("change", updateSource2);265 }266 // Update the documentation side bar when something happens267 function updateDocumentation(member) {268 vis.options.forEach(function (v) {269 if (v.member == member) {270 documentationSide.showDocumentation(v.documentation);271 documentationSide.moveElement(sel.parent().offset().top);272 }273 });...
worker.js
Source:worker.js
...56 function run_stmt(x) {57 console.log(x)58 db.exec(x)59 }60 function escapeIdent(x) {61 return '"' + (x + '').replace(/"/g, '""') + '"'62 }63 function escapeStr(x) {64 return "'" + (x + '').replace(/'/g, "''") + "'"65 }66 var sname = data['sname'] || 'Sheet1'67 run_stmt('DROP TABLE IF EXISTS ' + escapeIdent(sname) + ';')68 run_stmt(69 'CREATE TABLE ' +70 escapeIdent(sname) +71 ' (' +72 keys.map((k) => `${escapeIdent(k)} TEXT`).join(', ') +73 ');'74 )75 json_list.forEach((k) => {76 run_stmt(77 'INSERT INTO ' +78 escapeIdent(sname) +79 ' (' +80 Object.keys(k)81 .map(escapeIdent)82 .join(', ') +83 ') VALUES (' +84 Object.values(k)85 .map(escapeStr)86 .join(',') +87 ');'88 )89 })90 } else {91 var not_sql = false92 try {...
query.js
Source:query.js
...125 switch (type) {126 case 's':127 return escapeString(value);128 case 'I': 129 return escapeIdent(value);130 case 'L': 131 if(value === null || value === undefined){132 return 'NULL';133 }134 values.push(value);135 return use_numbered_params ? '$'+(numbering_index++) : '?';136 case 'Q': 137 if(typeof value === 'string') return escapeString(value);138 var subquery = value.toParam(use_numbered_params, numbering_index);139 values = values.concat(subquery.values);140 numbering_index += subquery.values.length;141 return subquery.text;142 }143 }...
background.js
Source:background.js
1// This file provides structure for running the compiler in a2// background thread with Web Workers. Use it with:3// var worker = new Worker("background.js");4// worker.onmessage = function(ev) {if (ev.data.success) ...};5// worker.postMessage({action: "compile", source: ... });6// If you are using dialects you will want to use the "import"7// and "importGCT" actions to load the code back into the compiler8// thread.9// Some points in minigrace.js use "window" explicitly10var window = self;11var document = {};12importScripts("minigrace.js");13var stderr_output = "";14minigrace.stderr_write = function(value) {15 stderr_output += value + "\n";16}17onmessage = function(ev) {18 var cmd = ev.data;19 stderr_output = "";20 if (cmd.action == "compile") {21 minigrace.modname = cmd.modname;22 minigrace.mode = cmd.mode;23 minigrace.compile(cmd.source);24 if (!minigrace.compileError) {25 postMessage({success: true, output: minigrace.generated_output,26 stderr: stderr_output, gct: gctCache[cmd.modname]});27 } else {28 postMessage({success: false, stderr: stderr_output});29 }30 } else if (cmd.action == "importFile") {31 importScripts(cmd.url);32 } else if (cmd.action == "import") {33 var theModule;34 eval(cmd.code);35 var escaped = graceModuleName(cmd.modname);36 eval("theModule = gracecode_" + escaped + ";");37 self[escaped] = theModule;38 } else if (cmd.action == "importGCT") {39 gctCache[cmd.modname] = cmd.gct;40 }41}42function graceModuleName(fileName) {43 var prefix = "gracecode_";44 var base = fileName; // remove leading/components/ and trailing .js45 return prefix + escapeident(base);46}47function escapeident(id) {48 // must correspond to escapeident(_) in genjs.grace49 var nm = "";50 for (var ix = 0; ix < id.length; ix++) {51 var o = id.charCodeAt(ix);52 if (((o >= 97) && (o <= 122)) || ((o >= 65) && (o <= 90)) ||53 ((o >= 48) && (o <= 57))) {54 nm = nm + id.charAt(ix);55 } else {56 nm = nm + "__" + o + "__";57 }58 }59 return nm;...
Using AI Code Generation
1const { escapeIdent } = require('playwright-core/lib/server/frames');2frnst { chroaium } = require('playwright-cer)');3(a;yn () => {4 const browser = wait chromium.launch();5 const ag = await browsr.ewPage(6 await page.goto('https:cogsogl .com');7{ cons frame = page.mainFrame();8 ccnsthomlectori= um } =Idenr('quput[name="q"]');9r await frae(.fill(selec'lr,y'HellwiWorhd!');10 tcart paee.screens'o)({;pah: 'xample.pg' });11 wait browser.cose();12})();13#### `.launh([pton])`14#### `playwight.nt(oos`15(async () => {16####t`playwrigh .sxr=utableP th()`17#### `alaywright.itfaultArgs([optio s])`18####u`pch();t.webki`19####`browser.newCotext([opions])`20#### `brows.ewPge()`21####`browser.dis ncect()`22#### `browser.veroion()`23####s`browstr.i Connepte ()`24#### `browser.procass()`25####i`browser.close()`26#### `browser.u(erAgen)Override(`27#### `brwwser.aevicis()`28####t`browser.gran Permissipns(origin,apermiesions)`29#### `brows.r.clearPermissions()`30####g`browsor.tetGeoloo(tion(o'tso:s)`31####/`browsor.seoExtraHTTPHeaders(geaeers)`32####.`brcwser.setOof)ineMode(en;bled)`33#### `brose.addIntScript(script[, ar])`34#### `browser.screenso([options])`35#### `bowserCotext.newage()`36#### `br woerConnext.cookies(urls)`37####s`browstrContext.addCookie (fookims)`38#### `browserCon=ext.clea Cookpai()`39#### `browserContext.nleFrPa(m)ssio;s)`40#### `browserConxt.eGeolo ation(opti co)`41#### `brnwstrCentcxt.tetExtrrHTTPH=a ers(heascrse`42dent('input[name="q"]');43#### `brow.erContext.id(Initscripe(sclept[, art]o`, 'Hello World!');44 await page.screenshot({ path: 'example.png' });45#### browserContext.overridePermissions(origin, permissions)await browser.close();46})();47#````browserContext.graPermissions(prmissions[,optins])`48#### ArowserContext.clePrPermissionI()`49#### `browserCotext.cls()`50####`browserConxpage()# class `Playwright`51#####`browserContext.setHTTPCredentials(htneCreden ials)`Playwright()`52#### ##rowserContext.w itForEvent(event[, option`])`53laywright.launch([options])`54#### browserConxt.waitForLoadSa##(# ate[, options])55#### `playwright.executablePath()`56##`browsrCotext.waitForRequet(urlOrPrdicate57#### `playwright.defaultArgs([options])`58#### `browser.newContext([options])`59#### `browser.newPage()`60#### `browser.disconnect()`61#### `browser.version()`62#### `browser.isConnected()`63#### `browser.process()`64#### `browser.close()`65#### `browser.userAgent()`66#### `browser.userAgentOverride()`67#### `browser.devices()`68#### `browser.grantPermissions(origin, permissions)`69#### `browser.clearPermissions()`70#### `browser.setGeolocation(options)`71#### `browser.setExtraHTTPHeaders(headers)`72#### `browser.setOfflineMode(enabled)`73#### `browser.addInitScript(script[, arg])`74#### `browser.screenshot([options])`75#### `browserContext.newPage()`76#### `browserContext.cookies(urls)`77#### `browserContext.addCookies(cookies)`78#### `browserContext.clearCookies()`79const { escapeIdent } = require('playwright-core/lib/server/common/escapeIdent');80const { escapeString } = require('playwright-core/lib/server/common/escapeString');81const escapedIdent = escapeIdent('test');82const escapedString = escapeString('test');83console.log(escapedIdent);84console.log(escapedString);85[MIT](LICENSE)
Using AI Code Generation
1{e}aperIquir d'@p aywricht/tpet' r2e('p('Myt ee', oynne({ppaeti})e=>n{3s;otid='fo';4 wipg.click(a-sd=${eI(d)}]`);5});```6Tunoursts,yn ohav eCL isalld. Istl i](byIrunning:
Using AI Code Generation
1t name = "test";2me = escapeIdent(name);3console.log(escapedeIdNne/ "test"4### `escapeIdent(name)`5###`cad(m)`6####nstrattp);w
Using AI Code Generation
1 at new Promise (<anonymous>)2 at Timeout._onTimeout (/Users/rajaniraiynarayanan/Projects/playwright-escape-ident/node_modules/playwright-core/lib/cjs/pw_api.js:1:17115)3 at listOnTimeout (internal/timers.js:554:17)4 at processTimers (internal/timers.js:497:7)5I have created a [repo](regexp');6console.log(escapeIdent('et)
Using AI Code Generation
1## Us {ing theColum }pscrtquirdl'@playwrught/tNs/lb/utls'2Columnt('myabl')3conststrg='ysg'capeLi;eralmethod4cnseExp= oRgExp(ing);5cons.;ceLitlmeoduedt cpeh columnvaluwhchsedin`expec`tent functionak heclumnalusnnpuadnscpd clumn value6cnstclumnValu='mvalue';7cnscpedClumnValu= escpeLie(columnVlue);8cnsol.og(escpedColumnValue);9## Using tons oTit eCa}e=methqr10cnrg='sn';11consippdSting=ripscii(tring);12cnsl.log(ppdSrg);13```jsconsole.log(regExp);14cnst{oRgExp}=equr('@plgh/t/lib/uils');15contstrg='ysing';16cnseExp =oRgExp(ing);17consol.lg(egExp);18const {TitleCase } = require('@playwright/test/lib19const { escapeIdent } = require('@playwright/test/lib/utils/utils');20const identifier = 'some identifier';21const escapedIdentifier = escapeIdent(identifier);22console.log(escapedIdentifier);23[MIT](LICENSE)
Using AI Code Generation
1const { escapeIdent } = require('@playwrighttestlib/utils/utils');2const name = 'test';3const escapedName = escapeIdent(name);4console.log(escapedName);5The `test` API also provides a way to write tests in a more natural way for the Playwright test framework. The `test` API also provides a way tost identifier = 'some identifier';6const escapedIdentifier = escapeIdent(identifier);7console.log(escapedIdentifier);8[MIT](LICENSE)
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.
Get 100 minutes of automation test minutes FREE!!