How to use compileIllegal method in Playwright Internal

Best JavaScript code snippet using playwright-internal

highlight.js

Source:highlight.js Github

copy

Full Screen

...713 /**714 * Allow `illegal` to contain an array of illegal values715 * @type {CompilerExt}716 */717 function compileIllegal(mode, _parent) {718 if (!Array.isArray(mode.illegal)) return;719 mode.illegal = either(...mode.illegal);720 }721 /**722 * `match` to match a single expression for readability723 * @type {CompilerExt}724 */725 function compileMatch(mode, _parent) {726 if (!mode.match) return;727 if (mode.begin || mode.end) throw new Error("begin & end are not supported with match");728 mode.begin = mode.match;729 delete mode.match;730 }731 /**...

Full Screen

Full Screen

highlight.js_v11.3.1-0C5csJSkMVgQyOMzmIlU_dist_es2020_mode_imports_optimized_common_core-da5e7eef_1b12fcb113193245855a.js

Source:highlight.js_v11.3.1-0C5csJSkMVgQyOMzmIlU_dist_es2020_mode_imports_optimized_common_core-da5e7eef_1b12fcb113193245855a.js Github

copy

Full Screen

...429 delete mode.beginKeywords;430 if (mode.relevance === void 0)431 mode.relevance = 0;432}433function compileIllegal(mode, _parent) {434 if (!Array.isArray(mode.illegal))435 return;436 mode.illegal = either(...mode.illegal);437}438function compileMatch(mode, _parent) {439 if (!mode.match)440 return;441 if (mode.begin || mode.end)442 throw new Error("begin & end are not supported with match");443 mode.begin = mode.match;444 delete mode.match;445}446function compileRelevance(mode, _parent) {447 if (mode.relevance === void 0)...

Full Screen

Full Screen

coder.js

Source:coder.js Github

copy

Full Screen

...432 mode.__beforeBegin = skipIfhasPrecedingDot;433 mode.keywords = mode.keywords || mode.beginKeywords;434 delete mode.beginKeywords;435}436function compileIllegal(mode, _parent) {437 if (!Array.isArray(mode.illegal)) return;438 439 mode.illegal = either(...mode.illegal);440}441function compileMatch(mode, _parent) {442 if (!mode.match) return;443 if (mode.begin || mode.end) throw new Error("begin & end are not supported with match");444 445 mode.begin = mode.match;446 delete mode.match;447}448function compileRelevance(mode, _parent) {449 // eslint-disable-next-line no-undefined450 if (mode.relevance === undefined) mode.relevance = 1;...

Full Screen

Full Screen

core.js

Source:core.js Github

copy

Full Screen

...444 mode.keywords = mode.keywords || mode.beginKeywords;445 delete mode.beginKeywords;446 if (mode.relevance === undefined) mode.relevance = 0;447}448function compileIllegal(mode, _parent) {449 if (!Array.isArray(mode.illegal)) return;450 mode.illegal = either(...mode.illegal);451}452function compileMatch(mode, _parent) {453 if (!mode.match) return;454 if (mode.begin || mode.end) throw new Error("begin & end are not supported with match");455 mode.begin = mode.match;456 delete mode.match;457}458function compileRelevance(mode, _parent) {459 // eslint-disable-next-line no-undefined460 if (mode.relevance === undefined) mode.relevance = 1;461}462const beforeMatchExt = (mode, parent) => {...

Full Screen

Full Screen

mode_compiler_20210105153356.js

Source:mode_compiler_20210105153356.js Github

copy

Full Screen

1import * as regex from './regex.js';2import { inherit } from './utils.js';3import * as EXT from "./compiler_extensions.js";4import { compileKeywords } from "./compile_keywords.js";5// compilation6/**7 * Compiles a language definition result8 *9 * Given the raw result of a language definition (Language), compiles this so10 * that it is ready for highlighting code.11 * @param {Language} language12 * @param {{plugins: HLJSPlugin[]}} opts13 * @returns {CompiledLanguage}14 */15export function compileLanguage(language, { plugins }) {16 /**17 * Builds a regex with the case sensativility of the current language18 *19 * @param {RegExp | string} value20 * @param {boolean} [global]21 */22 function langRe(value, global) {23 return new RegExp(24 regex.source(value),25 'm' + (language.case_insensitive ? 'i' : '') + (global ? 'g' : '')26 );27 }28 /**29 Stores multiple regular expressions and allows you to quickly search for30 them all in a string simultaneously - returning the first match. It does31 this by creating a huge (a|b|c) regex - each individual item wrapped with ()32 and joined by `|` - using match groups to track position. When a match is33 found checking which position in the array has content allows us to figure34 out which of the original regexes / match groups triggered the match.35 The match object itself (the result of `Regex.exec`) is returned but also36 enhanced by merging in any meta-data that was registered with the regex.37 This is how we keep track of which mode matched, and what type of rule38 (`illegal`, `begin`, end, etc).39 */40 class MultiRegex {41 constructor() {42 this.matchIndexes = {};43 // @ts-ignore44 this.regexes = [];45 this.matchAt = 1;46 this.position = 0;47 }48 // @ts-ignore49 addRule(re, opts) {50 opts.position = this.position++;51 // @ts-ignore52 this.matchIndexes[this.matchAt] = opts;53 this.regexes.push([opts, re]);54 this.matchAt += regex.countMatchGroups(re) + 1;55 }56 compile() {57 if (this.regexes.length === 0) {58 // avoids the need to check length every time exec is called59 // @ts-ignore60 this.exec = () => null;61 }62 const terminators = this.regexes.map(el => el[1]);63 this.matcherRe = langRe(regex.join(terminators), true);64 this.lastIndex = 0;65 }66 /** @param {string} s */67 exec(s) {68 this.matcherRe.lastIndex = this.lastIndex;69 const match = this.matcherRe.exec(s);70 if (!match) { return null; }71 // eslint-disable-next-line no-undefined72 const i = match.findIndex((el, i) => i > 0 && el !== undefined);73 // @ts-ignore74 const matchData = this.matchIndexes[i];75 // trim off any earlier non-relevant match groups (ie, the other regex76 // match groups that make up the multi-matcher)77 match.splice(0, i);78 return Object.assign(match, matchData);79 }80 }81 /*82 Created to solve the key deficiently with MultiRegex - there is no way to83 test for multiple matches at a single location. Why would we need to do84 that? In the future a more dynamic engine will allow certain matches to be85 ignored. An example: if we matched say the 3rd regex in a large group but86 decided to ignore it - we'd need to started testing again at the 4th87 regex... but MultiRegex itself gives us no real way to do that.88 So what this class creates MultiRegexs on the fly for whatever search89 position they are needed.90 NOTE: These additional MultiRegex objects are created dynamically. For most91 grammars most of the time we will never actually need anything more than the92 first MultiRegex - so this shouldn't have too much overhead.93 Say this is our search group, and we match regex3, but wish to ignore it.94 regex1 | regex2 | regex3 | regex4 | regex5 ' ie, startAt = 095 What we need is a new MultiRegex that only includes the remaining96 possibilities:97 regex4 | regex5 ' ie, startAt = 398 This class wraps all that complexity up in a simple API... `startAt` decides99 where in the array of expressions to start doing the matching. It100 auto-increments, so if a match is found at position 2, then startAt will be101 set to 3. If the end is reached startAt will return to 0.102 MOST of the time the parser will be setting startAt manually to 0.103 */104 class ResumableMultiRegex {105 constructor() {106 // @ts-ignore107 this.rules = [];108 // @ts-ignore109 this.multiRegexes = [];110 this.count = 0;111 this.lastIndex = 0;112 this.regexIndex = 0;113 }114 // @ts-ignore115 getMatcher(index) {116 if (this.multiRegexes[index]) return this.multiRegexes[index];117 const matcher = new MultiRegex();118 this.rules.slice(index).forEach(([re, opts]) => matcher.addRule(re, opts));119 matcher.compile();120 this.multiRegexes[index] = matcher;121 return matcher;122 }123 resumingScanAtSamePosition() {124 return this.regexIndex !== 0;125 }126 considerAll() {127 this.regexIndex = 0;128 }129 // @ts-ignore130 addRule(re, opts) {131 this.rules.push([re, opts]);132 if (opts.type === "begin") this.count++;133 }134 /** @param {string} s */135 exec(s) {136 const m = this.getMatcher(this.regexIndex);137 m.lastIndex = this.lastIndex;138 let result = m.exec(s);139 // The following is because we have no easy way to say "resume scanning at the140 // existing position but also skip the current rule ONLY". What happens is141 // all prior rules are also skipped which can result in matching the wrong142 // thing. Example of matching "booger":143 // our matcher is [string, "booger", number]144 //145 // ....booger....146 // if "booger" is ignored then we'd really need a regex to scan from the147 // SAME position for only: [string, number] but ignoring "booger" (if it148 // was the first match), a simple resume would scan ahead who knows how149 // far looking only for "number", ignoring potential string matches (or150 // future "booger" matches that might be valid.)151 // So what we do: We execute two matchers, one resuming at the same152 // position, but the second full matcher starting at the position after:153 // /--- resume first regex match here (for [number])154 // |/---- full match here for [string, "booger", number]155 // vv156 // ....booger....157 // Which ever results in a match first is then used. So this 3-4 step158 // process essentially allows us to say "match at this position, excluding159 // a prior rule that was ignored".160 //161 // 1. Match "booger" first, ignore. Also proves that [string] does non match.162 // 2. Resume matching for [number]163 // 3. Match at index + 1 for [string, "booger", number]164 // 4. If #2 and #3 result in matches, which came first?165 if (this.resumingScanAtSamePosition()) {166 if (result && result.index === this.lastIndex) {167 // result is position +0 and therefore a valid168 // "resume" match so result stays result169 } else { // use the second matcher result170 const m2 = this.getMatcher(0);171 m2.lastIndex = this.lastIndex + 1;172 result = m2.exec(s);173 }174 }175 if (result) {176 this.regexIndex += result.position + 1;177 if (this.regexIndex === this.count) {178 // wrap-around to considering all matches again179 this.considerAll();180 }181 }182 return result;183 }184 }185 /**186 * Given a mode, builds a huge ResumableMultiRegex that can be used to walk187 * the content and find matches.188 *189 * @param {CompiledMode} mode190 * @returns {ResumableMultiRegex}191 */192 function buildModeRegex(mode) {193 const mm = new ResumableMultiRegex();194 mode.contains.forEach(term => mm.addRule(term.begin, { rule: term, type: "begin" }));195 if (mode.terminatorEnd) {196 mm.addRule(mode.terminatorEnd, { type: "end" });197 }198 if (mode.illegal) {199 mm.addRule(mode.illegal, { type: "illegal" });200 }201 return mm;202 }203 /** skip vs abort vs ignore204 *205 * @skip - The mode is still entered and exited normally (and contains rules apply),206 * but all content is held and added to the parent buffer rather than being207 * output when the mode ends. Mostly used with `sublanguage` to build up208 * a single large buffer than can be parsed by sublanguage.209 *210 * - The mode begin ands ends normally.211 * - Content matched is added to the parent mode buffer.212 * - The parser cursor is moved forward normally.213 *214 * @abort - A hack placeholder until we have ignore. Aborts the mode (as if it215 * never matched) but DOES NOT continue to match subsequent `contains`216 * modes. Abort is bad/suboptimal because it can result in modes217 * farther down not getting applied because an earlier rule eats the218 * content but then aborts.219 *220 * - The mode does not begin.221 * - Content matched by `begin` is added to the mode buffer.222 * - The parser cursor is moved forward accordingly.223 *224 * @ignore - Ignores the mode (as if it never matched) and continues to match any225 * subsequent `contains` modes. Ignore isn't technically possible with226 * the current parser implementation.227 *228 * - The mode does not begin.229 * - Content matched by `begin` is ignored.230 * - The parser cursor is not moved forward.231 */232 /**233 * Compiles an individual mode234 *235 * This can raise an error if the mode contains certain detectable known logic236 * issues.237 * @param {Mode} mode238 * @param {CompiledMode | null} [parent]239 * @returns {CompiledMode | never}240 */241 function compileMode(mode, parent) {242 const cmode = /** @type CompiledMode */ (mode);243 if (mode.compiled) return cmode;244 [245 // do this early so compiler extensions generally don't have to worry about246 // the distinction between match/begin247 EXT.compileMatch248 ].forEach(ext => ext(mode, parent));249 language.compilerExtensions.forEach(ext => ext(mode, parent));250 // __beforeBegin is considered private API, internal use only251 mode.__beforeBegin = null;252 [253 EXT.beginKeywords,254 // do this later so compiler extensions that come earlier have access to the255 // raw array if they wanted to perhaps manipulate it, etc.256 EXT.compileIllegal,257 // default to 1 relevance if not specified258 EXT.compileRelevance259 ].forEach(ext => ext(mode, parent));260 mode.compiled = true;261 let keywordPattern = null;262 if (typeof mode.keywords === "object") {263 keywordPattern = mode.keywords.$pattern;264 delete mode.keywords.$pattern;265 }266 if (mode.keywords) {267 mode.keywords = compileKeywords(mode.keywords, language.case_insensitive);268 }269 // both are not allowed270 if (mode.lexemes && keywordPattern) {271 throw new Error("ERR: Prefer `keywords.$pattern` to `mode.lexemes`, BOTH are not allowed. (see mode reference) ");272 }273 // `mode.lexemes` was the old standard before we added and now recommend274 // using `keywords.$pattern` to pass the keyword pattern275 keywordPattern = keywordPattern || mode.lexemes || /\w+/;276 cmode.keywordPatternRe = langRe(keywordPattern, true);277 if (parent) {278 if (!mode.begin) mode.begin = /\B|\b/;279 cmode.beginRe = langRe(mode.begin);280 if (mode.endSameAsBegin) mode.end = mode.begin;281 if (!mode.end && !mode.endsWithParent) mode.end = /\B|\b/;282 if (mode.end) cmode.endRe = langRe(mode.end);283 cmode.terminatorEnd = regex.source(mode.end) || '';284 if (mode.endsWithParent && parent.terminatorEnd) {285 cmode.terminatorEnd += (mode.end ? '|' : '') + parent.terminatorEnd;286 }287 }288 if (mode.illegal) cmode.illegalRe = langRe(/** @type {RegExp | string} */ (mode.illegal));289 if (!mode.contains) mode.contains = [];290 mode.contains = [].concat(...mode.contains.map(function(c) {291 return expandOrCloneMode(c === 'self' ? mode : c);292 }));293 mode.contains.forEach(function(c) { compileMode(/** @type Mode */ (c), cmode); });294 if (mode.starts) {295 compileMode(mode.starts, parent);296 }297 cmode.matcher = buildModeRegex(cmode);298 return cmode;299 }300 if (!language.compilerExtensions) language.compilerExtensions = [];301 // self is not valid at the top-level302 if (language.contains && language.contains.includes('self')) {303 throw new Error("ERR: contains `self` is not supported at the top-level of a language. See documentation.");304 }305 // we need a null object, which inherit will guarantee306 language.classNameAliases = inherit(language.classNameAliases || {});307 return compileMode(/** @type Mode */ (language));308}309/**310 * Determines if a mode has a dependency on it's parent or not311 *312 * If a mode does have a parent dependency then often we need to clone it if313 * it's used in multiple places so that each copy points to the correct parent,314 * where-as modes without a parent can often safely be re-used at the bottom of315 * a mode chain.316 *317 * @param {Mode | null} mode318 * @returns {boolean} - is there a dependency on the parent?319 * */320function dependencyOnParent(mode) {321 if (!mode) return false;322 return mode.endsWithParent || dependencyOnParent(mode.starts);323}324/**325 * Expands a mode or clones it if necessary326 *327 * This is necessary for modes with parental dependenceis (see notes on328 * `dependencyOnParent`) and for nodes that have `variants` - which must then be329 * exploded into their own individual modes at compile time.330 *331 * @param {Mode} mode332 * @returns {Mode | Mode[]}333 * */334function expandOrCloneMode(mode) {335 if (mode.variants && !mode.cachedVariants) {336 mode.cachedVariants = mode.variants.map(function(variant) {337 return inherit(mode, { variants: null }, variant);338 });339 }340 // EXPAND341 // if we have variants then essentially "replace" the mode with the variants342 // this happens in compileMode, where this function is called from343 if (mode.cachedVariants) {344 return mode.cachedVariants;345 }346 // CLONE347 // if we have dependencies on parents then we need a unique348 // instance of ourselves, so we can be reused with many349 // different parents without issue350 if (dependencyOnParent(mode)) {351 return inherit(mode, { starts: mode.starts ? inherit(mode.starts) : null });352 }353 if (Object.isFrozen(mode)) {354 return inherit(mode);355 }356 // no special dependency issues, just return ourselves357 return mode;...

Full Screen

Full Screen

mode_compiler.js

Source:mode_compiler.js Github

copy

Full Screen

1import * as regex from './regex.js';2import { inherit } from './utils.js';3import * as EXT from "./compiler_extensions.js";4import { compileKeywords } from "./compile_keywords.js";5// compilation6/**7 * Compiles a language definition result8 *9 * Given the raw result of a language definition (Language), compiles this so10 * that it is ready for highlighting code.11 * @param {Language} language12 * @param {{plugins: HLJSPlugin[]}} opts13 * @returns {CompiledLanguage}14 */15export function compileLanguage(language, { plugins }) {16 /**17 * Builds a regex with the case sensativility of the current language18 *19 * @param {RegExp | string} value20 * @param {boolean} [global]21 */22 function langRe(value, global) {23 return new RegExp(24 regex.source(value),25 'm' + (language.case_insensitive ? 'i' : '') + (global ? 'g' : '')26 );27 }28 /**29 Stores multiple regular expressions and allows you to quickly search for30 them all in a string simultaneously - returning the first match. It does31 this by creating a huge (a|b|c) regex - each individual item wrapped with ()32 and joined by `|` - using match groups to track position. When a match is33 found checking which position in the array has content allows us to figure34 out which of the original regexes / match groups triggered the match.35 The match object itself (the result of `Regex.exec`) is returned but also36 enhanced by merging in any meta-data that was registered with the regex.37 This is how we keep track of which mode matched, and what type of rule38 (`illegal`, `begin`, end, etc).39 */40 class MultiRegex {41 constructor() {42 this.matchIndexes = {};43 // @ts-ignore44 this.regexes = [];45 this.matchAt = 1;46 this.position = 0;47 }48 // @ts-ignore49 addRule(re, opts) {50 opts.position = this.position++;51 // @ts-ignore52 this.matchIndexes[this.matchAt] = opts;53 this.regexes.push([opts, re]);54 this.matchAt += regex.countMatchGroups(re) + 1;55 }56 compile() {57 if (this.regexes.length === 0) {58 // avoids the need to check length every time exec is called59 // @ts-ignore60 this.exec = () => null;61 }62 const terminators = this.regexes.map(el => el[1]);63 this.matcherRe = langRe(regex.join(terminators), true);64 this.lastIndex = 0;65 }66 /** @param {string} s */67 exec(s) {68 this.matcherRe.lastIndex = this.lastIndex;69 const match = this.matcherRe.exec(s);70 if (!match) { return null; }71 // eslint-disable-next-line no-undefined72 const i = match.findIndex((el, i) => i > 0 && el !== undefined);73 // @ts-ignore74 const matchData = this.matchIndexes[i];75 // trim off any earlier non-relevant match groups (ie, the other regex76 // match groups that make up the multi-matcher)77 match.splice(0, i);78 return Object.assign(match, matchData);79 }80 }81 /*82 Created to solve the key deficiently with MultiRegex - there is no way to83 test for multiple matches at a single location. Why would we need to do84 that? In the future a more dynamic engine will allow certain matches to be85 ignored. An example: if we matched say the 3rd regex in a large group but86 decided to ignore it - we'd need to started testing again at the 4th87 regex... but MultiRegex itself gives us no real way to do that.88 So what this class creates MultiRegexs on the fly for whatever search89 position they are needed.90 NOTE: These additional MultiRegex objects are created dynamically. For most91 grammars most of the time we will never actually need anything more than the92 first MultiRegex - so this shouldn't have too much overhead.93 Say this is our search group, and we match regex3, but wish to ignore it.94 regex1 | regex2 | regex3 | regex4 | regex5 ' ie, startAt = 095 What we need is a new MultiRegex that only includes the remaining96 possibilities:97 regex4 | regex5 ' ie, startAt = 398 This class wraps all that complexity up in a simple API... `startAt` decides99 where in the array of expressions to start doing the matching. It100 auto-increments, so if a match is found at position 2, then startAt will be101 set to 3. If the end is reached startAt will return to 0.102 MOST of the time the parser will be setting startAt manually to 0.103 */104 class ResumableMultiRegex {105 constructor() {106 // @ts-ignore107 this.rules = [];108 // @ts-ignore109 this.multiRegexes = [];110 this.count = 0;111 this.lastIndex = 0;112 this.regexIndex = 0;113 }114 // @ts-ignore115 getMatcher(index) {116 if (this.multiRegexes[index]) return this.multiRegexes[index];117 const matcher = new MultiRegex();118 this.rules.slice(index).forEach(([re, opts]) => matcher.addRule(re, opts));119 matcher.compile();120 this.multiRegexes[index] = matcher;121 return matcher;122 }123 resumingScanAtSamePosition() {124 return this.regexIndex !== 0;125 }126 considerAll() {127 this.regexIndex = 0;128 }129 // @ts-ignore130 addRule(re, opts) {131 this.rules.push([re, opts]);132 if (opts.type === "begin") this.count++;133 }134 /** @param {string} s */135 exec(s) {136 const m = this.getMatcher(this.regexIndex);137 m.lastIndex = this.lastIndex;138 let result = m.exec(s);139 // The following is because we have no easy way to say "resume scanning at the140 // existing position but also skip the current rule ONLY". What happens is141 // all prior rules are also skipped which can result in matching the wrong142 // thing. Example of matching "booger":143 // our matcher is [string, "booger", number]144 //145 // ....booger....146 // if "booger" is ignored then we'd really need a regex to scan from the147 // SAME position for only: [string, number] but ignoring "booger" (if it148 // was the first match), a simple resume would scan ahead who knows how149 // far looking only for "number", ignoring potential string matches (or150 // future "booger" matches that might be valid.)151 // So what we do: We execute two matchers, one resuming at the same152 // position, but the second full matcher starting at the position after:153 // /--- resume first regex match here (for [number])154 // |/---- full match here for [string, "booger", number]155 // vv156 // ....booger....157 // Which ever results in a match first is then used. So this 3-4 step158 // process essentially allows us to say "match at this position, excluding159 // a prior rule that was ignored".160 //161 // 1. Match "booger" first, ignore. Also proves that [string] does non match.162 // 2. Resume matching for [number]163 // 3. Match at index + 1 for [string, "booger", number]164 // 4. If #2 and #3 result in matches, which came first?165 if (this.resumingScanAtSamePosition()) {166 if (result && result.index === this.lastIndex) {167 // result is position +0 and therefore a valid168 // "resume" match so result stays result169 } else { // use the second matcher result170 const m2 = this.getMatcher(0);171 m2.lastIndex = this.lastIndex + 1;172 result = m2.exec(s);173 }174 }175 if (result) {176 this.regexIndex += result.position + 1;177 if (this.regexIndex === this.count) {178 // wrap-around to considering all matches again179 this.considerAll();180 }181 }182 return result;183 }184 }185 /**186 * Given a mode, builds a huge ResumableMultiRegex that can be used to walk187 * the content and find matches.188 *189 * @param {CompiledMode} mode190 * @returns {ResumableMultiRegex}191 */192 function buildModeRegex(mode) {193 const mm = new ResumableMultiRegex();194 mode.contains.forEach(term => mm.addRule(term.begin, { rule: term, type: "begin" }));195 if (mode.terminatorEnd) {196 mm.addRule(mode.terminatorEnd, { type: "end" });197 }198 if (mode.illegal) {199 mm.addRule(mode.illegal, { type: "illegal" });200 }201 return mm;202 }203 /** skip vs abort vs ignore204 *205 * @skip - The mode is still entered and exited normally (and contains rules apply),206 * but all content is held and added to the parent buffer rather than being207 * output when the mode ends. Mostly used with `sublanguage` to build up208 * a single large buffer than can be parsed by sublanguage.209 *210 * - The mode begin ands ends normally.211 * - Content matched is added to the parent mode buffer.212 * - The parser cursor is moved forward normally.213 *214 * @abort - A hack placeholder until we have ignore. Aborts the mode (as if it215 * never matched) but DOES NOT continue to match subsequent `contains`216 * modes. Abort is bad/suboptimal because it can result in modes217 * farther down not getting applied because an earlier rule eats the218 * content but then aborts.219 *220 * - The mode does not begin.221 * - Content matched by `begin` is added to the mode buffer.222 * - The parser cursor is moved forward accordingly.223 *224 * @ignore - Ignores the mode (as if it never matched) and continues to match any225 * subsequent `contains` modes. Ignore isn't technically possible with226 * the current parser implementation.227 *228 * - The mode does not begin.229 * - Content matched by `begin` is ignored.230 * - The parser cursor is not moved forward.231 */232 /**233 * Compiles an individual mode234 *235 * This can raise an error if the mode contains certain detectable known logic236 * issues.237 * @param {Mode} mode238 * @param {CompiledMode | null} [parent]239 * @returns {CompiledMode | never}240 */241 function compileMode(mode, parent) {242 const cmode = /** @type CompiledMode */ (mode);243 if (mode.compiled) return cmode;244 [245 // do this early so compiler extensions generally don't have to worry about246 // the distinction between match/begin247 EXT.compileMatch248 ].forEach(ext => ext(mode, parent));249 language.compilerExtensions.forEach(ext => ext(mode, parent));250 // __beforeBegin is considered public API, internal use only251 mode.__beforeBegin = null;252 [253 EXT.beginKeywords,254 // do this later so compiler extensions that come earlier have access to the255 // raw array if they wanted to perhaps manipulate it, etc.256 EXT.compileIllegal,257 // default to 1 relevance if not specified258 EXT.compileRelevance259 ].forEach(ext => ext(mode, parent));260 mode.compiled = true;261 let keywordPattern = null;262 if (typeof mode.keywords === "object") {263 keywordPattern = mode.keywords.$pattern;264 delete mode.keywords.$pattern;265 }266 if (mode.keywords) {267 mode.keywords = compileKeywords(mode.keywords, language.case_insensitive);268 }269 // both are not allowed270 if (mode.lexemes && keywordPattern) {271 throw new Error("ERR: Prefer `keywords.$pattern` to `mode.lexemes`, BOTH are not allowed. (see mode reference) ");272 }273 // `mode.lexemes` was the old standard before we added and now recommend274 // using `keywords.$pattern` to pass the keyword pattern275 keywordPattern = keywordPattern || mode.lexemes || /\w+/;276 cmode.keywordPatternRe = langRe(keywordPattern, true);277 if (parent) {278 if (!mode.begin) mode.begin = /\B|\b/;279 cmode.beginRe = langRe(mode.begin);280 if (mode.endSameAsBegin) mode.end = mode.begin;281 if (!mode.end && !mode.endsWithParent) mode.end = /\B|\b/;282 if (mode.end) cmode.endRe = langRe(mode.end);283 cmode.terminatorEnd = regex.source(mode.end) || '';284 if (mode.endsWithParent && parent.terminatorEnd) {285 cmode.terminatorEnd += (mode.end ? '|' : '') + parent.terminatorEnd;286 }287 }288 if (mode.illegal) cmode.illegalRe = langRe(/** @type {RegExp | string} */ (mode.illegal));289 if (!mode.contains) mode.contains = [];290 mode.contains = [].concat(...mode.contains.map(function(c) {291 return expandOrCloneMode(c === 'self' ? mode : c);292 }));293 mode.contains.forEach(function(c) { compileMode(/** @type Mode */ (c), cmode); });294 if (mode.starts) {295 compileMode(mode.starts, parent);296 }297 cmode.matcher = buildModeRegex(cmode);298 return cmode;299 }300 if (!language.compilerExtensions) language.compilerExtensions = [];301 // self is not valid at the top-level302 if (language.contains && language.contains.includes('self')) {303 throw new Error("ERR: contains `self` is not supported at the top-level of a language. See documentation.");304 }305 // we need a null object, which inherit will guarantee306 language.classNameAliases = inherit(language.classNameAliases || {});307 return compileMode(/** @type Mode */ (language));308}309/**310 * Determines if a mode has a dependency on it's parent or not311 *312 * If a mode does have a parent dependency then often we need to clone it if313 * it's used in multiple places so that each copy points to the correct parent,314 * where-as modes without a parent can often safely be re-used at the bottom of315 * a mode chain.316 *317 * @param {Mode | null} mode318 * @returns {boolean} - is there a dependency on the parent?319 * */320function dependencyOnParent(mode) {321 if (!mode) return false;322 return mode.endsWithParent || dependencyOnParent(mode.starts);323}324/**325 * Expands a mode or clones it if necessary326 *327 * This is necessary for modes with parental dependenceis (see notes on328 * `dependencyOnParent`) and for nodes that have `variants` - which must then be329 * exploded into their own individual modes at compile time.330 *331 * @param {Mode} mode332 * @returns {Mode | Mode[]}333 * */334function expandOrCloneMode(mode) {335 if (mode.variants && !mode.cachedVariants) {336 mode.cachedVariants = mode.variants.map(function(variant) {337 return inherit(mode, { variants: null }, variant);338 });339 }340 // EXPAND341 // if we have variants then essentially "replace" the mode with the variants342 // this happens in compileMode, where this function is called from343 if (mode.cachedVariants) {344 return mode.cachedVariants;345 }346 // CLONE347 // if we have dependencies on parents then we need a unique348 // instance of ourselves, so we can be reused with many349 // different parents without issue350 if (dependencyOnParent(mode)) {351 return inherit(mode, { starts: mode.starts ? inherit(mode.starts) : null });352 }353 if (Object.isFrozen(mode)) {354 return inherit(mode);355 }356 // no special dependency issues, just return ourselves357 return mode;...

Full Screen

Full Screen

compiler_extensions.js

Source:compiler_extensions.js Github

copy

Full Screen

...45/**46 * Allow `illegal` to contain an array of illegal values47 * @type {CompilerExt}48 */49export function compileIllegal(mode, _parent) {50 if (!Array.isArray(mode.illegal)) return;51 mode.illegal = regex.either(...mode.illegal);52}53/**54 * `match` to match a single expression for readability55 * @type {CompilerExt}56 */57export function compileMatch(mode, _parent) {58 if (!mode.match) return;59 if (mode.begin || mode.end) throw new Error("begin & end are not supported with match");60 mode.begin = mode.match;61 delete mode.match;62}63/**...

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 page = await browser.newPage();5 await page.screenshot({ path: `example.png` });6 await browser.close();7})();

Full Screen

Using AI Code Generation

copy

Full Screen

1const playwright = require('playwright');2(async () => {3 const browser = await playwright.chromium.launch();4 const page = await browser.newPage();5 await page.$eval('input[type="text"]', (el) => {6 el.value = "test";7 });8 await page.$eval('input[type="text"]', (el) => {9 el.value = "test";10 });11 await browser.close();12})();

Full Screen

Using AI Code Generation

copy

Full Screen

1const { chromium } = require('playwright');2const { compileIllegal } = require('playwright/lib/utils/regexps');3(async () => {4 const browser = await chromium.launch();5 const context = await browser.newContext();6 const page = await context.newPage();7 await page.screenshot({ path: 'google.png' });8 await browser.close();9})();10When I try to import it from the playwright package, I get the following error:11const { compileIllegal } = require('playwright/lib/utils/regexps');12I can't seem to find the regexps.js file anywhere in the Playwright package. I'm not sure how to get this file to import. Does anyone know how to do this?

Full Screen

Using AI Code Generation

copy

Full Screen

1const { Playwright } = require('playwright');2const playwright = new Playwright();3const { internal } = playwright;4const { compileIllegal } = internal;5const { Playwright } = require('playwright');6const playwright = new Playwright();7const { internal } = playwright;8const { compileIllegal } = internal;9const { Playwright } = require('playwright');10const playwright = new Playwright();11const { internal } = playwright;12const { compileIllegal } = internal;13const { Playwright } = require('playwright');14const playwright = new Playwright();15const { internal } = playwright;16const { compileIllegal } = internal;17const { Playwright } = require('playwright');18const playwright = new Playwright();19const { internal } = playwright;20const { compileIllegal } = internal;21const { Playwright } = require('playwright');22const playwright = new Playwright();23const { internal } = playwright;24const { compileIllegal } = internal;25const { Playwright } = require('playwright');26const playwright = new Playwright();27const { internal } = playwright;28const { compileIllegal } = internal;29const { Playwright } = require('playwright');

Full Screen

Using AI Code Generation

copy

Full Screen

1const { compileIllegal } = require('playwright/lib/server/supplements/recorder/recorderApp');2const illegal = compileIllegal();3console.log(illegal);4const { compileIllegal } = require('playwright/lib/server/supplements/recorder/recorderApp');5const illegal = compileIllegal();6console.log(illegal);7const { compileIllegal } = require('playwright/lib/server/supplements/recorder/recorderApp');8const illegal = compileIllegal();9console.log(illegal);10const { compileIllegal } = require('playwright/lib/server/supplements/recorder/recorderApp');11const illegal = compileIllegal();12console.log(illegal);13const { compileIllegal } = require('playwright/lib/server/supplements/recorder/recorderApp');14const illegal = compileIllegal();15console.log(illegal);16const { compileIllegal } = require('playwright/lib/server/supplements/recorder/recorderApp');17const illegal = compileIllegal();18console.log(illegal);19const { compileIllegal } = require('playwright/lib/server/supplements/recorder/recorderApp');20const illegal = compileIllegal();21console.log(illegal);22const { compileIllegal } = require('playwright/lib/server/supplements/recorder/recorderApp');23const illegal = compileIllegal();24console.log(illegal);25const { compileIllegal } = require('playwright/lib/server/supplements/recorder/recorderApp');26const illegal = compileIllegal();27console.log(illegal);28const { compileIllegal } = require('playwright/lib/server/supplements/recorder/recorderApp');29const illegal = compileIllegal();30console.log(illegal);31const { compileIllegal } = require('playwright/lib/server/supplements/recorder

Full Screen

Using AI Code Generation

copy

Full Screen

1const { compileIllegal } = require('playwright/lib/server/supplements/recorder/recorderSupplement');2const code = compileIllegal('click', 'button');3console.log(code);4const { compileLegal } = require('playwright/lib/server/supplements/recorder/recorderSupplement');5const code = compileLegal('click', 'button');6console.log(code);7const { RecorderSupplement } = require('playwright/lib/server/supplements/recorder/recorderSupplement');8const recorder = new RecorderSupplement();9const code = recorder.compile('click', 'button');10console.log(code);11const { RecorderSupplement } = require('playwright/lib/server/supplements/recorder/recorderSupplement');12const recorder = new RecorderSupplement();13const code = recorder.compile('click', 'button');14console.log(code);15const { RecorderSupplement } = require('playwright/lib/server/supplements/recorder/recorderSupplement');16const recorder = new RecorderSupplement();17const code = recorder.compile('click', 'button');18console.log(code);19const { RecorderSupplement } = require('playwright/lib/server/supplements/recorder/recorderSupplement');20const recorder = new RecorderSupplement();21const code = recorder.compile('click', 'button');22console.log(code);23const { RecorderSupplement } = require('playwright/lib/server/supplements/recorder/recorderSupplement');24const recorder = new RecorderSupplement();25const code = recorder.compile('click', 'button');26console.log(code);27const { RecorderSupplement } = require('playwright/lib/server/supplements/recorder/recorderSupplement');28const recorder = new RecorderSupplement();29const code = recorder.compile('click', 'button');30console.log(code);31const { RecorderSupplement } = require('playwright/lib/server/supplements/recorder/recorderSupplement');32const recorder = new RecorderSupplement();33const code = recorder.compile('click', 'button');34console.log(code);35const { RecorderSupplement } = require('playwright/lib/server/supplements/recorder/recorderSupplement');36const recorder = new RecorderSupplement();37const code = recorder.compile('click', '

Full Screen

Using AI Code Generation

copy

Full Screen

1const { PlaywrightInternal } = require('playwright-core/lib/server/playwright');2const playwright = new PlaywrightInternal();3const { compileIllegal } = playwright;4console.log(compileIllegal('test.js', 'const x = 1;'));5const { PlaywrightInternal } = require('playwright-core/lib/server/playwright');6const playwright = new PlaywrightInternal();7const { compileIllegal } = playwright;8console.log(compileIllegal('test.js', 'const x = 1;'));9const { PlaywrightInternal } = require('playwright-core/lib/server/playwright');10const playwright = new PlaywrightInternal();11const { compileIllegal } = playwright;12const { PlaywrightInternal } = require('playwright-core/lib/server/playwright');13const { compileIllegal } = new PlaywrightInternal();14const { PlaywrightInternal } = require('playwright-core/lib/server/playwright');15const { compileIllegal } = new PlaywrightInternal();16const { PlaywrightInternal } = require('playwright-core/lib/server/playwright');17const playwright = new PlaywrightInternal();18const { compileIllegal } = playwright;19const { PlaywrightInternal } = require('playwright-core/lib/server/playwright');20const { compileIllegal } = new PlaywrightInternal();21const { PlaywrightInternal } = require('playwright-core/lib/server/playwright');22const { compileIllegal } = new PlaywrightInternal();

Full Screen

Using AI Code Generation

copy

Full Screen

1const playwright = require('playwright');2const { compileIllegal } = require('playwright/lib/utils/utils');3const code = compileIllegal('console.log("Hello World")');4console.log(code);5(async () => {6 const browser = await playwright.chromium.launch();7 const context = await browser.newContext();8 const page = await context.newPage();9 await page.evaluate(code);10 await browser.close();11})();12function() {13 console.log("Hello World")14}

Full Screen

Using AI Code Generation

copy

Full Screen

1const { compileIllegal } = require('playwright/lib/utils/regexps');2console.log(compileIllegal('test'));3const { compileIllegal } = require('puppeteer/lib/USKeyboardLayout');4console.log(compileIllegal('test'));5const { compileIllegal } = require('puppeteer/lib/USKeyboardLayout');6console.log(compileIllegal('test'));7const { compileIllegal } = require('puppeteer/lib/USKeyboardLayout');8console.log(compileIllegal('test'));9const { compileIllegal } = require('puppeteer/lib/USKeyboardLayout');10console.log(compileIllegal('test'));11const { compileIllegal } = require('puppeteer/lib/USKeyboardLayout');12console.log(compileIllegal('test'));13const { compileIllegal } = require('puppeteer/lib/USKeyboardLayout');14console.log(compileIllegal('test'));15const { compileIllegal } = require('p

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