How to use advanceSpaces method in Playwright Internal

Best JavaScript code snippet using playwright-internal

index.umd.js

Source:index.umd.js Github

copy

Full Screen

...115 var source = context.source;116 advancePositionWithMutation(context, source, numberOfCharacters);117 context.source = source.slice(numberOfCharacters);118 }119 function advanceSpaces(context) {120 var match = /^[\t\r\n\f ]+/.exec(context.source);121 if (match && match[0]) {122 advanceBy(context, match[0].length);123 }124 }125 function parseData(context, keyName) {126 advanceSpaces(context);127 var start = getCursor(context);128 var key = keyName || parseKey(context);129 var _parseValue = parseValue(context),130 value = _parseValue.value,131 type = _parseValue.type;132 var loc = getLoc(context, start);133 advanceSpaces(context);134 if (context.source[0] === ",") {135 advanceBy(context, 1);136 advanceSpaces(context);137 }138 return {139 key: key,140 value: value,141 type: type,142 loc: loc143 };144 }145 function parseChildren(context) {146 var nodes = [];147 while (!isEnd(context)) {148 advanceSpaces(context);149 var s = context.source;150 if (s[0] === "{") {151 advanceBy(context, 1);152 } else if (s[0] === "}") {153 advanceBy(context, 1);154 advanceSpaces(context);155 return nodes;156 } else if (s[0] === "/") {157 if (s[1] === "/") {158 var lastNode = nodes[nodes.length - 1];159 var lastLine = -1;160 if (lastNode) {161 lastLine = lastNode.loc.end.line;162 }163 nodes.push(parseComment(context, lastLine));164 advanceSpaces(context);165 } else {166 throw new Error(COMMENT_ERROR_MESSAGE);167 }168 } else {169 nodes.push(parseData(context));170 }171 }172 return nodes;173 }174 function parseKey(context) {175 var s = context.source[0];176 var match = [];177 if (s === '"') {178 match = /^"(.[^"]*)/i.exec(context.source);179 } else if (s === "'") {180 match = /^'(.[^']*)/i.exec(context.source);181 } else {182 match = /(.[^:]*)/i.exec(context.source);183 match[1] = match[1].trim();184 }185 advanceBy(context, match[0].length + 1);186 advanceSpaces(context);187 if (context.source[0] === ":") {188 advanceBy(context, 1);189 advanceSpaces(context);190 }191 return match[1];192 }193 function parseNumber(context) {194 var match = /^([0-9]*)/i.exec(context.source);195 advanceBy(context, match[0].length);196 return match[1];197 }198 function parseString(context) {199 var match = /^["|']([^"|']*)/i.exec(context.source);200 advanceBy(context, match[0].length + 1);201 return match[1];202 }203 function parseNull(context) {204 advanceBy(context, 4);205 return "null";206 }207 function parseBoolean(context) {208 var match = /^(true|false)/i.exec(context.source);209 advanceBy(context, match[0].length);210 return match[1];211 }212 function parseUndefined(context) {213 advanceBy(context, 9);214 return "undefined";215 }216 function parseValue(context) {217 var value = null;218 var type = null;219 var code = context.source[0];220 if (/^[0-9]/.test(code)) {221 value = parseNumber(context);222 type = NUMBER_TYPE;223 } else if (code === '"' || code === "'") {224 value = parseString(context);225 type = STRING_TYPE;226 } else if (code === "[") {227 advanceBy(context, 1);228 value = parseArray(context);229 type = ARRAY_TYPE;230 } else if (code === "{") {231 value = parseChildren(context);232 type = OBJECT_TYPE;233 } else if (context.source.indexOf("null") === 0) {234 value = parseNull(context);235 type = NULL_TYPE;236 } else if (context.source.indexOf("true") === 0 || context.source.indexOf("false") === 0) {237 value = parseBoolean(context);238 type = BOOLEAN_TYPE;239 } else if (context.source.indexOf("undefined") === 0) {240 value = parseUndefined(context);241 type = UNDEFINED_TYPE;242 } else {243 throw new Error(VALUE_ILLEGAL_ERROR_MESSAGE);244 }245 return {246 value: value,247 type: type248 };249 }250 function parseArray(context) {251 var nodes = [];252 var lastLine = getCursor(context).line;253 advanceSpaces(context);254 while (!isEnd(context)) {255 if (context.source.indexOf("//") === 0) {256 var cv = parseComment(context, lastLine);257 nodes.push(cv);258 advanceSpaces(context);259 } else {260 var itemValue = parseData(context, ARRAY_ITEM);261 lastLine = itemValue.loc.end.line;262 nodes.push(itemValue);263 }264 var s = context.source[0];265 if (s === "]") {266 advanceBy(context, 1);267 return nodes;268 }269 if (s === "}" || s === ":") {270 throw new Error(ARRAY_ERROR_MESSAGE);271 }272 }...

Full Screen

Full Screen

index.cjs

Source:index.cjs Github

copy

Full Screen

...82 var source = context.source;83 advancePositionWithMutation(context, source, numberOfCharacters);84 context.source = source.slice(numberOfCharacters);85}86function advanceSpaces(context) {87 var match = /^[\t\r\n\f ]+/.exec(context.source);88 if (match && match[0]) {89 advanceBy(context, match[0].length);90 }91}92function parseData(context, keyName) {93 advanceSpaces(context);94 var start = getCursor(context);95 var key = keyName || parseKey(context);96 var _parseValue = parseValue(context),97 value = _parseValue.value,98 type = _parseValue.type;99 var loc = getLoc(context, start);100 advanceSpaces(context);101 if (context.source[0] === ",") {102 advanceBy(context, 1);103 advanceSpaces(context);104 }105 return {106 key: key,107 value: value,108 type: type,109 loc: loc110 };111}112function parseChildren(context) {113 var nodes = [];114 while (!isEnd(context)) {115 advanceSpaces(context);116 var s = context.source;117 if (s[0] === "{") {118 advanceBy(context, 1);119 } else if (s[0] === "}") {120 advanceBy(context, 1);121 advanceSpaces(context);122 return nodes;123 } else if (s[0] === "/") {124 if (s[1] === "/") {125 var lastNode = nodes[nodes.length - 1];126 var lastLine = -1;127 if (lastNode) {128 lastLine = lastNode.loc.end.line;129 }130 nodes.push(parseComment(context, lastLine));131 advanceSpaces(context);132 } else {133 throw new Error(COMMENT_ERROR_MESSAGE);134 }135 } else {136 nodes.push(parseData(context));137 }138 }139 return nodes;140}141function parseKey(context) {142 var s = context.source[0];143 var match = [];144 if (s === '"') {145 match = /^"(.[^"]*)/i.exec(context.source);146 } else if (s === "'") {147 match = /^'(.[^']*)/i.exec(context.source);148 } else {149 match = /(.[^:]*)/i.exec(context.source);150 match[1] = match[1].trim();151 }152 advanceBy(context, match[0].length + 1);153 advanceSpaces(context);154 if (context.source[0] === ":") {155 advanceBy(context, 1);156 advanceSpaces(context);157 }158 return match[1];159}160function parseNumber(context) {161 var match = /^([0-9]*)/i.exec(context.source);162 advanceBy(context, match[0].length);163 return match[1];164}165function parseString(context) {166 var match = /^["|']([^"|']*)/i.exec(context.source);167 advanceBy(context, match[0].length + 1);168 return match[1];169}170function parseNull(context) {171 advanceBy(context, 4);172 return "null";173}174function parseBoolean(context) {175 var match = /^(true|false)/i.exec(context.source);176 advanceBy(context, match[0].length);177 return match[1];178}179function parseUndefined(context) {180 advanceBy(context, 9);181 return "undefined";182}183function parseValue(context) {184 var value = null;185 var type = null;186 var code = context.source[0];187 if (/^[0-9]/.test(code)) {188 value = parseNumber(context);189 type = NUMBER_TYPE;190 } else if (code === '"' || code === "'") {191 value = parseString(context);192 type = STRING_TYPE;193 } else if (code === "[") {194 advanceBy(context, 1);195 value = parseArray(context);196 type = ARRAY_TYPE;197 } else if (code === "{") {198 value = parseChildren(context);199 type = OBJECT_TYPE;200 } else if (context.source.indexOf("null") === 0) {201 value = parseNull(context);202 type = NULL_TYPE;203 } else if (context.source.indexOf("true") === 0 || context.source.indexOf("false") === 0) {204 value = parseBoolean(context);205 type = BOOLEAN_TYPE;206 } else if (context.source.indexOf("undefined") === 0) {207 value = parseUndefined(context);208 type = UNDEFINED_TYPE;209 } else {210 throw new Error(VALUE_ILLEGAL_ERROR_MESSAGE);211 }212 return {213 value: value,214 type: type215 };216}217function parseArray(context) {218 var nodes = [];219 var lastLine = getCursor(context).line;220 advanceSpaces(context);221 while (!isEnd(context)) {222 if (context.source.indexOf("//") === 0) {223 var cv = parseComment(context, lastLine);224 nodes.push(cv);225 advanceSpaces(context);226 } else {227 var itemValue = parseData(context, ARRAY_ITEM);228 lastLine = itemValue.loc.end.line;229 nodes.push(itemValue);230 }231 var s = context.source[0];232 if (s === "]") {233 advanceBy(context, 1);234 return nodes;235 }236 if (s === "}" || s === ":") {237 throw new Error(ARRAY_ERROR_MESSAGE);238 }239 }...

Full Screen

Full Screen

parser.js

Source:parser.js Github

copy

Full Screen

...51 advanceBy(num) {52 // 消费指定长度的字符串53 context.source = context.source.slice(num);54 },55 advanceSpaces() {56 // 匹配空白字符串,然后消费57 const match = /^[\t\r\n\f ]+/.exec(context.source);58 if (match) {59 context.advanceBy(match[0].length);60 }61 },62 };63 const nodes = parseChildren(context, []);64 return {65 type: "Root",66 children: nodes,67 };68}69function parseChildren(context, ancestors) {70 let nodes = [];71 const { mode, advanceSpaces } = context;72 // 每次运行前清除空白字符73 advanceSpaces();74 // 开启while循环,如果没有结束,一直循环下去75 while (!isEnd(context, ancestors)) {76 let node;77 // 只有DATA和RCDATA支持对插值节点的解析78 if (mode === TextModes.DATA || mode === TextModes.RCDATA) {79 // 只有DATA模式才支持标签节点的解析80 if (mode === TextModes.DATA && context.source[0] === "<") {81 if (context.source[1] === "!") {82 if (context.source.startsWith("<!--")) {83 // 解析注释84 node = parseComment(context);85 } else if (context.source.startsWith("<![CDATA[")) {86 // 解析CDATA87 node = parseCDATA(context);88 }89 } else if (context.source[1] === "/") {90 // 由于解析子节点会开启新的状态机,在新的状态机中会将结束标签处理掉91 // 如果此时遇到了结束标签标志,则认为该结束标签没有对应的开始标签,抛出错误92 console.error("出错了");93 continue;94 } else if (/[a-z]/i.test(context.source[1])) {95 // 解析标签96 node = parseElement(context, ancestors);97 }98 } else if (context.source.startsWith("{{")) {99 // 解析插值100 node = parseInterpolation(context);101 }102 }103 // 上一轮下来都没有节点被解析,解析为文本104 if (!node) {105 node = parseText(context);106 }107 nodes.push(node);108 }109 return nodes;110}111function parseCDATA(context) {112 context.advanceBy("<![CDATA[".length); // 消费CDATA开始字符113 let endIndex = context.source.indexOf("]]>"); // 寻找CDATA结束标志114 if (endIndex === -1) {115 endIndex = context.source.length;116 }117 let content = context.source.slice(0, endIndex); // CDATA之间的所有内容将会识别为普通文本118 return {119 type: "CDATA",120 content,121 };122}123function parseText(context) {124 let endIndex = context.source.length; // endIndex默认为字符串长度125 const ltIndex = context.source.indexOf("<"); // 寻找<位置126 const delimiterIndex = context.source.indexOf("{{"); // 寻找定界符{{的位置127 // ltIndex存在,且小于字符串长度,则endIndex为ltIndex128 if (ltIndex > -1 && ltIndex <= endIndex) {129 endIndex = ltIndex;130 }131 // delimiterIndex存在且小于endIndex,则endIndex为delimiterIndex132 if (delimiterIndex > -1 && delimiterIndex < endIndex) {133 endIndex = delimiterIndex;134 }135 // 取得content136 const content = context.source.slice(0, endIndex);137 // 消费content长度的字符串138 context.advanceBy(content.length);139 return {140 type: "Text",141 content: decodeHtml(content),142 };143}144// 第一个参数是要解码的字符串145// 第二个参数代表文本内容是否作为属性值146function decodeHtml(rawText, asAttr = false) {147 let offset = 0;148 const end = rawText.length;149 let decodedText = ""; // 最终解码的字符串150 let maxCRNameLength = 0; // 引用表中实体名称的最大长度151 // 消费指定长度的字符串152 function advance(length) {153 offset += length;154 rawText = rawText.slice(length);155 }156 while (offset < end) {157 // 匹配字符引用的开始部分;158 // 有三种情况:head[0]='&'、head[0]='&#'、head[0]='&#x'159 const head = /&(?:#x?)?/i.exec(rawText);160 // 如果没有匹配161 if (!head) {162 // 计算剩余内容长度163 const remaining = end - offset;164 // 将剩余内容追加到decodedText165 decodedText += rawText.slice(0, remaining);166 // 消费剩余内容长度的字符167 advance(remaining);168 break;169 }170 // 如果找到了字符引用,截取&之前的字符,追加到decoidedText171 decodedText += rawText.slice(0, head.index);172 // 消费字符&之前的内容173 advance(head.index);174 // 如果匹配到的head第一个字符是&,说明是命名字符引用,否则为数字字符引用175 if (head[0] === "&") {176 let name = "";177 let value;178 // 如果match到了&,且下一个字符是ASCII字母或数字,需要进一步查找字符引用表179 if (/[0-9a-z]/i.test(rawText[1])) {180 // 找出字符引用表中名称最长的字符长度181 if (!maxCRNameLength) {182 maxCRNameLength = Object.keys(namedChararacterReferences).reduce(183 (max, name) => Math.max(max, name.length),184 0185 );186 }187 // 从当前文本进行截取指定长度的字符串,尝试去字符引用表中查找对应的项188 for (let length = maxCRNameLength; !value && length > 0; --length) {189 name = rawText.substr(1, length);190 value = namedChararacterReferences[name];191 }192 // 如果找到了,看他有没有以;结尾193 if (value) {194 const semi = name.endsWith(";");195 // 如果没有以;结尾且解码的文本作为属性值,并且最后一个字符是=、ASCII字母或数字196 // 由于历史原因,将字符&和实体名称name一起作为普通文本197 if (198 asAttr &&199 !semi &&200 /[=a-z0-9]/i.test(rawText[name.length + 1] || "")201 ) {202 decodedText += "&" + name;203 advance(1 + name.length);204 } else {205 // 其他情况,正常拼接其值到decodedText,并消费name长度的字符串206 decodedText += value;207 advance(1 + name.length);208 }209 } else {210 // 如果没找到,则直接拼接&和name作为普通文本到decodedText,并消费211 decodedText += "&" + name;212 advance(1 + name.length);213 }214 } else {215 // 如果match到了&,但是下一个字符不是ASCII字母或数字,则将字符&作为普通文本216 decodedText += "&";217 advance(1);218 }219 } else {220 // 如果匹配到的head以&#x或&#开头,说明是数字字符引用,而数字字符引用分为10进制和16进制221 // 根据进制不同,匹配的正则也不同222 const hex = head[0] === "&#x";223 const pattern = hex ? /^&#x([0-9a-f]+);?/i : /^&#([0-9]+);?/i;224 const body = pattern.exec(rawText);225 // 如果能匹配上对应的进制226 if (body) {227 // 通过parseInt拿到其十进制的码点,通过码点拿到对应的字符228 const codePoint = parseInt(bdoy[1], hex ? 16 : 10);229 // 检查得到的码点合法性230 if (codePoint === 0) {231 // 如果码点值为0x00,替换为0xfffd232 codePoint = 0xfffd;233 } else if (codePoint > 0x10ffff) {234 // 如果码点值超过了Unicode最大值,替换为0xfffd235 codePoint = 0xfffd;236 } else if (codePoint >= 0xd800 && codePoint <= 0xdfff) {237 // 如果码点值处于代理对范围内,替换为0xfffd238 codePoint = 0xfffd;239 } else if (240 (codePoint >= 0xfdd0 && codePoint <= 0xfdef) ||241 (codePoint & 0xfffe) === 0xfffe242 ) {243 // 如果码点值处于noncharacter范围内,啥都不处理244 } else if (245 (codePoint >= 0x01 && codePoint <= 0x08) ||246 codePoint === 0x0b ||247 (codePoint >= 0x0d && codePoint <= 0x1f) ||248 (codePoint >= 0x7f && codePoint <= 0x9f)249 ) {250 // 如果码点值在控制字符集范围([0x01, 0x1f]+[0x7f, 0x9f])内251 // 去掉ASCII空白字符:0x09(TAB),0x0A(LF)、0x0C(FF)、0x0D(CR)252 // 去CCR_REPLACEMENTS寻找替换的码点,如果找不到则使用原码点253 codePoint = CCR_REPLACEMENTS[codePoint] || codePoint;254 }255 const char = String.fromCodePoint(codePoint);256 decodedText += char;257 advance(body[0].length); // 消费匹配到的body长度258 } else {259 // 如果没有匹配到数字字符引用,则不进行解码操作,只是追加head[0]到decodedText,并消费head[0]260 decodedText += head[0];261 advance(head[0].length);262 }263 }264 }265 return decodedText;266}267function parseInterpolation(context) {268 const { advanceBy } = context;269 advanceBy("{{".length); // 消费插值表达式开头的{{270 let closeIndex = context.source.indexOf("}}");271 if (closeIndex < 0) {272 console.error("插值缺少结束界定符");273 }274 // 从开始到插值结束界定符之间的内容作为content275 const content = context.source.slice(0, closeIndex);276 advanceBy(content.length); // 消费内容长度277 advanceBy("}}".length); // 消费插值结束界定符278 return {279 type: "Interpolation",280 // 插值节点的类型是一个表达式节点281 content: {282 type: "Expression",283 content: decodeHtml(content), // 对插值表达式的内容做一次解码,其结果作为真正的内容返回284 },285 };286}287function parseComment(context) {288 const { advanceBy } = context;289 advanceBy("<!--".length);290 let closeIndex = context.source.indexOf("-->");291 const content = context.source.slice(0, closeIndex);292 advanceBy(content.length);293 advanceBy("-->".length);294 return {295 type: "Comment",296 content,297 };298}299function parseElement(context, ancestors) {300 const element = parseTag(context); // 解析开始标签301 // 标签是一个自闭合标签,直接返回302 if (element.isSelfClosing) {303 return element;304 }305 // 如果tag是textarea和title的话,切换到RCDATA模式306 if (element.tag === "textarea" || element.tag === "title") {307 context.mode = TextModes.RCDATA;308 } else if (/style|xmp|iframe|noembed|noframes|noscript/.test(element.tag)) {309 // 切换到RAWTEXT模式310 context.mode = TextModes.RAWTEXT;311 } else {312 // 其他切换到DATA模式313 context.mode === TextModes.DATA;314 }315 ancestors.push(element);316 element.children = parseChildren(context, ancestors); // 解析子节点317 ancestors.pop(); // 遍历完了子节点,将当前节点从祖先节点弹出318 // 解析完子节点之后,如果当前字符串以element.tag作为结束标签,则认为已结束。否则认为没有与之对应的闭合标签319 if (context.source.startsWith(`</${element.tag}>`)) {320 parseTag(context, "end");321 } else {322 console.error(`${element.tag}标签缺少闭合标签`);323 }324 return element;325}326function parseTag(context, type = "start") {327 const { advanceBy, advanceSpaces } = context;328 const match =329 type === "start"330 ? /^<([a-z][^\t\r\n\f />]*)/i.exec(context.source) // 匹配开始标签331 : /^<\/([a-z][^\t\r\n\f />]*)/i.exec(context.source); // 匹配结束标签332 // 消费匹配组的第一个(exec能匹配的话,第一个是能匹配的字符串,之后是捕获组)的长度333 const tag = match[1];334 advanceBy(match[0].length);335 advanceSpaces(); // 消费空白字符串336 const props = parseAttribute(context);337 const isSelfClosing = context.source.startsWith("/"); // 是否是自闭合标签,如果是的话则消费两个字符串(/>),否则只消费一个(>)338 advanceBy(isSelfClosing ? 2 : 1);339 return {340 type: "Element",341 tag,342 props: props,343 children: [],344 isSelfClosing,345 };346}347function parseAttribute(context) {348 const { advanceBy, advanceSpaces } = context;349 const props = [];350 // 开启while循环,只要没遇到结束标志,就一直运行351 while (!context.source.startsWith(">") && !context.source.startsWith("/>")) {352 // 解析指令和属性353 // 读取属性名354 const match = /^[^\t\r\n\f />][^\t\r\n\f />=]*/.exec(context.source);355 const name = match[0];356 advanceBy(name.length);357 advanceSpaces();358 advanceBy(1); // 消费等号359 advanceSpaces(); // 消费等号和属性值之间的空白字符串360 let value = "";361 const quote = context.source[0];362 const isQuote = quote === '"' || quote === "'";363 if (isQuote) {364 advanceBy(1); // 消费开始引号365 const endQuoteIndex = context.source.indexOf(quote); // 在字符串里去找结束引号366 if (endQuoteIndex > -1) {367 // 找到了结束引号,得到中间的属性值368 value = context.source.slice(0, endQuoteIndex);369 advanceBy(value.length); // 消费属性值370 advanceBy(1); // 消费结束引号371 } else {372 console.error("缺少引号");373 }374 } else {375 // 如果属性值没有被引号引用,那么到结束前的下一个空白字符之前的内容作为其属性值376 const match = /^[^\t\r\n\f >]+/.exec(context.source);377 value = match[0];378 advanceBy(value.length);379 }380 advanceSpaces(); // 消费完属性值之后,消费属性值后的空白组付出按381 // 添加props382 props.push({383 type: "Attribute",384 name,385 value,386 });387 }388 return props;389}390function isEnd(context, ancestors) {391 // 模板解析完毕=>结束392 if (!context.source) {393 return true;394 }...

Full Screen

Full Screen

index.mjs

Source:index.mjs Github

copy

Full Screen

...78 var source = context.source;79 advancePositionWithMutation(context, source, numberOfCharacters);80 context.source = source.slice(numberOfCharacters);81}82function advanceSpaces(context) {83 var match = /^[\t\r\n\f ]+/.exec(context.source);84 if (match && match[0]) {85 advanceBy(context, match[0].length);86 }87}88function parseData(context, keyName) {89 advanceSpaces(context);90 var start = getCursor(context);91 var key = keyName || parseKey(context);92 var _parseValue = parseValue(context),93 value = _parseValue.value,94 type = _parseValue.type;95 var loc = getLoc(context, start);96 advanceSpaces(context);97 if (context.source[0] === ",") {98 advanceBy(context, 1);99 advanceSpaces(context);100 }101 return {102 key: key,103 value: value,104 type: type,105 loc: loc106 };107}108function parseChildren(context) {109 var nodes = [];110 while (!isEnd(context)) {111 advanceSpaces(context);112 var s = context.source;113 if (s[0] === "{") {114 advanceBy(context, 1);115 } else if (s[0] === "}") {116 advanceBy(context, 1);117 advanceSpaces(context);118 return nodes;119 } else if (s[0] === "/") {120 if (s[1] === "/") {121 var lastNode = nodes[nodes.length - 1];122 var lastLine = -1;123 if (lastNode) {124 lastLine = lastNode.loc.end.line;125 }126 nodes.push(parseComment(context, lastLine));127 advanceSpaces(context);128 } else {129 throw new Error(COMMENT_ERROR_MESSAGE);130 }131 } else {132 nodes.push(parseData(context));133 }134 }135 return nodes;136}137function parseKey(context) {138 var s = context.source[0];139 var match = [];140 if (s === '"') {141 match = /^"(.[^"]*)/i.exec(context.source);142 } else if (s === "'") {143 match = /^'(.[^']*)/i.exec(context.source);144 } else {145 match = /(.[^:]*)/i.exec(context.source);146 match[1] = match[1].trim();147 }148 advanceBy(context, match[0].length + 1);149 advanceSpaces(context);150 if (context.source[0] === ":") {151 advanceBy(context, 1);152 advanceSpaces(context);153 }154 return match[1];155}156function parseNumber(context) {157 var match = /^([0-9]*)/i.exec(context.source);158 advanceBy(context, match[0].length);159 return match[1];160}161function parseString(context) {162 var match = /^["|']([^"|']*)/i.exec(context.source);163 advanceBy(context, match[0].length + 1);164 return match[1];165}166function parseNull(context) {167 advanceBy(context, 4);168 return "null";169}170function parseBoolean(context) {171 var match = /^(true|false)/i.exec(context.source);172 advanceBy(context, match[0].length);173 return match[1];174}175function parseUndefined(context) {176 advanceBy(context, 9);177 return "undefined";178}179function parseValue(context) {180 var value = null;181 var type = null;182 var code = context.source[0];183 if (/^[0-9]/.test(code)) {184 value = parseNumber(context);185 type = NUMBER_TYPE;186 } else if (code === '"' || code === "'") {187 value = parseString(context);188 type = STRING_TYPE;189 } else if (code === "[") {190 advanceBy(context, 1);191 value = parseArray(context);192 type = ARRAY_TYPE;193 } else if (code === "{") {194 value = parseChildren(context);195 type = OBJECT_TYPE;196 } else if (context.source.indexOf("null") === 0) {197 value = parseNull(context);198 type = NULL_TYPE;199 } else if (context.source.indexOf("true") === 0 || context.source.indexOf("false") === 0) {200 value = parseBoolean(context);201 type = BOOLEAN_TYPE;202 } else if (context.source.indexOf("undefined") === 0) {203 value = parseUndefined(context);204 type = UNDEFINED_TYPE;205 } else {206 throw new Error(VALUE_ILLEGAL_ERROR_MESSAGE);207 }208 return {209 value: value,210 type: type211 };212}213function parseArray(context) {214 var nodes = [];215 var lastLine = getCursor(context).line;216 advanceSpaces(context);217 while (!isEnd(context)) {218 if (context.source.indexOf("//") === 0) {219 var cv = parseComment(context, lastLine);220 nodes.push(cv);221 advanceSpaces(context);222 } else {223 var itemValue = parseData(context, ARRAY_ITEM);224 lastLine = itemValue.loc.end.line;225 nodes.push(itemValue);226 }227 var s = context.source[0];228 if (s === "]") {229 advanceBy(context, 1);230 return nodes;231 }232 if (s === "}" || s === ":") {233 throw new Error(ARRAY_ERROR_MESSAGE);234 }235 }...

Full Screen

Full Screen

index.js

Source:index.js Github

copy

Full Screen

...16 advanceBy(num) {17 context.source = context.source.slice(num);18 },19 // 前进连续的 n 个空格20 advanceSpaces() {21 const match = /^[\t\r\n\f ]+/.exec(context.source);22 if (match) {23 context.advanceBy(match[0].length);24 }25 },26 };27 // 开始解析节点28 const nodes = parseChildren(context, []);29 return {30 type: "Root",31 children: nodes,32 };33}34/**35 * 解析子节点36 * @param {*} context 上下文37 * @param {*} ancestors 父节点栈38 */39function parseChildren(context, ancestors) {40 let nodes = [];41 while (!isEnd(context, ancestors)) {42 let node = null;43 if (context.source[0] === "<") {44 // 标签 < 开头 // <div...45 node = parseElement(context, ancestors);46 } else if (context.source.startsWith("{{")) {47 // 解析插值 `{{title}}</div>`48 node = parseInterpolation(context);49 }50 // 不存在匹配的类型解析为文本51 if (!node) {52 // `Hello {{title}}</div>`53 node = parseText(context);54 }55 nodes.push(node);56 }57 return nodes;58}59/**60 * 解析元素61 */62function parseElement(context, ancestors) {63 // 解析标签64 const element = parseTag(context);65 ancestors.push(element);66 // 递归子节点67 element.children = parseChildren(context, ancestors);68 ancestors.pop();69 // 子节点解析结束70 if (context.source.startsWith(`</${element.tag}`)) {71 // 消费对应的闭合标签72 parseTag(context, "end");73 }74 return element;75}76/**77 * 解析标签名称78 */79function parseTag(context, type = "start") {80 const { advanceBy, advanceSpaces } = context;81 // 匹配标签名称82 let match = null;83 if (type === "start") {84 // /^<([a-z][^\t\r\n\f />]*)/i.exec(`<div class="home">Hello {{title}}</div>`) ==> ['<div', 'div']85 match = /^<([a-z][^\t\r\n\f />]*)/i.exec(context.source);86 } else {87 // /^<([a-z][^\t\r\n\f />]*)/i.exec(`</div>`) ==> ['</div', 'div']88 match = /^<\/([a-z][^\t\r\n\f />]*)/i.exec(context.source);89 }90 // 消费标签91 advanceBy(match[0].length);92 // 消费空格93 advanceSpaces();94 // 剩余 ==> `class="home">Hello {{title}}</div>`95 // 解析属性96 const props = parseAttributes(context);97 // 消费解析属性之后的 ">"98 advanceBy(1);99 // 剩余 ==> `Hello {{title}}</div>`100 // 返回节点信息101 return {102 type: "Element",103 tag: match[1],104 props,105 children: [],106 };107}108/**109 * 解析标签属性110 */111function parseAttributes(context) {112 const { advanceBy, advanceSpaces } = context;113 const props = [];114 // 标签 "<div" 开始之后 “>” 之前的都是属性115 while (!context.source.startsWith(">")) {116 // 解析属性 key117 // /^[^\t\r\n\f />][^\t\r\n\f />=]*/.exec(`class="home">Hello {{title}}</div>`) ==> ['class']118 const match = /^[^\t\r\n\f />][^\t\r\n\f />=]*/.exec(context.source);119 const name = match[0];120 // 消费 name121 advanceBy(name.length);122 // 消费空格123 advanceSpaces();124 // 消费 = 号125 advanceBy(1);126 // 消费空格127 advanceSpaces();128 // 剩余 ==> `"home">Hello {{title}}</div>`129 // 解析属性 value130 // 消费引号 "131 advanceBy(1);132 // 截取到下一个引号之前为 value133 const value = context.source.slice(0, context.source.indexOf('"'));134 // 消费 value135 advanceBy(value.length);136 // 消费引号 "137 advanceBy(1);138 // 消费空格139 advanceSpaces();140 // 解析一个 value141 props.push({142 type: "Attribute",143 name,144 value,145 });146 // 剩余 ==> `>Hello {{title}}</、div>`147 }148 // 返回属性信息149 return props;150}151/**152 * 解析文本153 */...

Full Screen

Full Screen

parse.js

Source:parse.js Github

copy

Full Screen

...119function parseTag(context) {120 const match = /^<\/?([a-z][^\t\r\n\f />]*)/i.exec(context.source);121 const tag = match[1];122 advanceBy(context, match[0].length);123 advanceSpaces(context);124 const { props, directives } = parseAttributes(context);125 const isSelfClosing = context.source.startsWith('/>');126 advanceBy(context, isSelfClosing ? 2 : 1);127 const tagType = isComponent(tag, context) ?128 ElementTypes.COMPONENT :129 ElementTypes.ELEMENT;130 return {131 type: NodeTypes.ELEMENT,132 tag, // 标签名,133 tagType, // 是组件还是原生元素,134 props, // 属性节点数组,135 directives, // 指令数组136 isSelfClosing, // 是否是自闭合标签,137 children: [],138 };139}140//判断是component组件吗141function isComponent(tag, context) {142 return !context.options.isNativeTag(tag);143}144//解析element节点的属性和指令145function parseAttributes(context) {146 const props = [];147 const directives = [];148 while (149 context.source.length &&150 !context.source.startsWith('>') &&151 !context.source.startsWith('/>')152 ) {153 let attr = parseAttribute(context);154 if (attr.type === NodeTypes.DIRECTIVE) {155 directives.push(attr);156 } else {157 props.push(attr);158 }159 }160 return { props, directives };161}162//解析例如:id='foo',拿到name->id,value->foo163function parseAttribute(context) {164 const match = /^[^\t\r\n\f />][^\t\r\n\f />=]*/.exec(context.source);165 const name = match[0];166 advanceBy(context, name.length);167 advanceSpaces(context);168 let value;169 if (context.source[0] === '=') {170 advanceBy(context, 1);171 advanceSpaces(context);172 value = parseAttributeValue(context);173 advanceSpaces(context);174 }175 // 指令 v-bind @click176 if (/^(:|@|v-)/.test(name)) {177 let dirName, argContent;178 if (name[0] === ':') {179 dirName = 'bind';180 argContent = name.slice(1);181 } else if (name[0] === '@') {182 dirName = 'on';183 argContent = name.slice(1);184 } else if (name.startsWith('v-')) {185 [dirName, argContent] = name.slice(2).split(':');186 }187 return {188 type: NodeTypes.DIRECTIVE,189 name: dirName,190 exp: value && {191 type: NodeTypes.SIMPLE_EXPRESSION,192 content: value.content,193 isStatic: false,194 }, // 表达式节点195 arg: argContent && {196 type: NodeTypes.SIMPLE_EXPRESSION,197 content: camelize(argContent),198 isStatic: true,199 }, // 表达式节点200 };201 }202 // 属性203 return {204 type: NodeTypes.ATTRIBUTE,205 name,206 value: value && {207 type: NodeTypes.TEXT,208 content: value.content,209 },210 };211}212function parseAttributeValue(context) {213 const quote = context.source[0];214 advanceBy(context, 1);215 const endIndex = context.source.indexOf(quote);216 const content = parseTextData(context, endIndex);217 advanceBy(context, 1);218 return { content };219}220function isEnd(context) {221 const s = context.source;222 return s.startsWith('</') || !s;223}224//工具,去掉前面的字符225function advanceBy(context, numberOfCharacters) {226 context.source = context.source.slice(numberOfCharacters);227}228//工具,去掉空格229function advanceSpaces(context) {230 const match = /^[\t\r\n\f ]+/.exec(context.source);231 if (match) {232 advanceBy(context, match[0].length);233 }...

Full Screen

Full Screen

compiler-dom.js

Source:compiler-dom.js Github

copy

Full Screen

...17 return true;18 }19 return !source;20}21function advanceSpaces(context) {22 const match = /^[ \t\r\n]+/.exec(context.source);23 if (match) {24 advanceBy(context, match[0].length);25 }26}27function parseTag(context) {28 const start = getCursor(context); //<div/>29 // 最基本的元字符30 const match = /^<\/?([a-z][^ \t\r\n/>]*)/.exec(context.source); // igm31 const tag = match[1];32 advanceBy(context, match[0].length);33 advanceSpaces(context);34 const isSelfClosing = context.source.startsWith("/>");35 advanceBy(context, isSelfClosing ? 2 : 1);36 return {37 type: NodeTypes.ElEMENT,38 tag,39 isSelfClosing,40 loc: getSelection(context, start),41 };42}43function parseElement(context) {44 // 1.解析标签名45 let ele = parseTag(context); // <div></div>46 // 这里可能有儿子?47 const children = parseChildren(context); // 这里处理儿子的时候 有可能没有儿子,那就直接跳出? 如果遇到结束标签就直接跳出就好了...

Full Screen

Full Screen

03-parseTag.js

Source:03-parseTag.js Github

copy

Full Screen

...11 const tag = match[1]12 const ns = context.options.getNamespace(tag, parent)13 // 向前遍历代码14 advanceBy(context, match[0].length)15 advanceSpaces(context)16 17 // save current state in case we need to re-parse attributes with v-pre18 const cursor = getCursor(context)19 const currentSource = context.source20 21 // check <pre> tag 22 if (context.options.isPreTag(tag)) {23 context.inPre = true24 }25 // Attributes.26 // 解析属性27 let props = parseAttributes(context, type)28 // check v-pre29 if (){...}...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const { chromium } = require('playwright');2const path = require('path');3(async () => {4 const browser = await chromium.launch();5 const page = await browser.newPage();6 await page.click('text=Docs');7 await page.click('text=API');8 await page.click('text=class: Page');9 await page.waitForSelector('text=Page');10 const pageElement = await page.$('text=Page');11 await pageElement.evaluate(element => element.scrollIntoViewIfNeeded());

Full Screen

Using AI Code Generation

copy

Full Screen

1const { advanceTo } = require('@playwright/test');2const { advanceTime } = require('@playwright/test');3const { clear } = require('@playwright/test');4const { click } = require('@playwright/test');5const { close } = require('@playwright/test');6const { doubleClick } = require('@playwright/test');7const { dragAndDrop } = require('@playwright/test');8const { evalOnSelector } = require('@playwright/test');9const { evalOnSelectorAll } = require('@playwright/test');10const { evalOnSelectorAll } = require('@playwright/test');11const { fill } = require('@playwright/test');12const { focus } = require('@playwright/test');13const { frame } = require('@playwright/test');14const { goto } = require('@playwright/test');15const { hover } = require('@playwright/test');16const { innerHTML } = require('@playwright/test');17const { innerText } = require('@playwright/test');18const { inputValue } = require('@playwright/test');19const { isVisible } = require('@playwright/test');20const { isHidden } = require('@playwright/test');21const { isChecked } =

Full Screen

Using AI Code Generation

copy

Full Screen

1const { advanceSpaces } = require('@playwright/test/lib/page');2const { test, expect } = require('@playwright/test');3test('should advance spaces', async ({ page }) => {4 await advanceSpaces(page, 2);5 await advanceSpaces(page, 2);6 await advanceSpaces(page, -1);7});8const { test, expect } = require('@playwright/test');9test('should advance spaces', async ({ page }) => {10 await page.keyboard.press('Tab');11 await page.keyboard.press('Tab');12 await page.keyboard.press('Shift+Tab');13});14Your name to display (optional):

Full Screen

Using AI Code Generation

copy

Full Screen

1const { advanceSpaces } = require('@playwright/test/lib/utils/keyboardLayout');2const { test } = require('@playwright/test');3test('test', async ({ page }) => {4 await page.click('input[name="q"]');5 await page.keyboard.press('Shift+Tab');6 await page.keyboard.type(advanceSpaces(5));7 await page.keyboard.type('Hello');8});

Full Screen

Using AI Code Generation

copy

Full Screen

1const { advanceSpaces } = require('playwright/lib/server/keyboardLayouts.js');2const text = advanceSpaces('hello world', 6);3const { advanceSpaces } = require('playwright/lib/server/keyboardLayouts.js');4const text = advanceSpaces('hello world', 6);5const { advanceSpaces } = require('playwright/lib/server/keyboardLayouts.js');6const text = advanceSpaces('hello world', 6);7const { advanceSpaces } = require('playwright/lib/server/keyboardLayouts.js');8const text = advanceSpaces('hello world', 6);9In the above code, we are importing the advanceSpaces method from the keyboardLayouts.js file of Playwright internal library. This method is used to advance the string by the given

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