How to use AstLiteral method in wpt

Best JavaScript code snippet using wpt

gen.ts

Source:gen.ts Github

copy

Full Screen

1import * as AST from "./ast"2const digitRegex = /\d+/3const lookAroundMap = {4 lookahead: ["(?=", "(?!"],5 lookbehind: ["(?<=", "(?<!"],6}7class CodeGen {8 ast: AST.Regex | AST.Node[]9 astLiteral = false10 isLiteral = false11 constructor(ast: AST.Regex | AST.Node[], isLiteral = false) {12 this.ast = ast13 this.isLiteral = isLiteral14 if (!Array.isArray(ast)) {15 this.astLiteral = ast.withSlash16 }17 }18 gen() {19 const nodes = Array.isArray(this.ast) ? this.ast : this.ast.body20 const regexBody = this.genNodes(nodes)21 if (this.astLiteral) {22 const f = (this.ast as AST.Regex).flags.map((flag) => flag).join("")23 return `/${regexBody}/${f}`24 }25 return regexBody26 }27 genNodes(nodes: AST.Node[]) {28 return nodes29 .map((node) => {30 let regex = ""31 switch (node.type) {32 case "choice":33 regex = this.genChoice(node)34 break35 case "group":36 regex += this.genGroup(node)37 break38 case "character":39 regex += this.genCharacter(node)40 break41 case "boundaryAssertion":42 regex += this.genBoundaryAssertionNode(node)43 break44 case "lookAroundAssertion":45 regex += this.genLookaroundAssertionNode(node)46 break47 case "backReference":48 regex += this.genBackReference(node)49 break50 default:51 break52 }53 if (node.type === "character" || node.type === "group") {54 regex += this.genQuantifier(node)55 }56 return regex57 })58 .join("")59 }60 genChoice(node: AST.ChoiceNode) {61 const { branches } = node62 return branches63 .map((branch) => {64 return this.genNodes(branch)65 })66 .join("|")67 }68 genGroup(node: AST.GroupNode) {69 const { children } = node70 const content = this.genNodes(children)71 switch (node.kind) {72 case "capturing":73 return "(" + content + ")"74 case "namedCapturing":75 return "(?<" + node.name + ">" + content + ")"76 case "nonCapturing":77 return "(?:" + content + ")"78 default:79 break80 }81 }82 prefix(value: string) {83 return value.replace(84 this.isLiteral || this.astLiteral85 ? /[|\\{}()[\]^$+*?./]/g86 : /[|\\{}()[\]^$+*?.]/g,87 "\\$&"88 )89 }90 genCharacter(node: AST.CharacterNode) {91 switch (node.kind) {92 case "ranges":93 const { negate, ranges } = node94 let str = ""95 ranges.forEach(({ from, to }, index) => {96 if (from === "]" || from === "\\") {97 from = "\\" + from98 }99 if (to === "]" || to === "\\") {100 to = "\\" + to101 }102 if (!(index === 0 || index === ranges.length - 1)) {103 if (from === "-") {104 from = "\\-"105 }106 if (to === "-") {107 to = "\\-"108 }109 }110 if (from !== to) {111 str += from + "-" + to112 } else {113 str += from114 }115 })116 return (negate ? "[^" : "[") + str + "]"117 case "string":118 return this.prefix(node.value)119 case "class":120 return node.value121 default:122 return ""123 }124 }125 genQuantifier(node: AST.CharacterNode | AST.GroupNode) {126 const { quantifier } = node127 if (!quantifier) {128 return ""129 }130 const { kind, min, max, greedy } = quantifier131 let result = ""132 switch (kind) {133 case "*":134 result = "*"135 break136 case "+":137 result = "+"138 break139 case "?":140 result = "?"141 break142 case "custom":143 if (min === max) {144 result = `{${min}}`145 } else if (max === Infinity) {146 result = `{${min},}`147 } else {148 result = `{${min},${max}}`149 }150 break151 default:152 break153 }154 return result + (greedy ? "" : "?")155 }156 genBoundaryAssertionNode(157 node:158 | AST.BeginningBoundaryAssertionNode159 | AST.EndBoundaryAssertionNode160 | AST.WordBoundaryAssertionNode161 ) {162 switch (node.kind) {163 case "beginning":164 return "^"165 case "end":166 return "$"167 case "word":168 return node.negate ? "\\B" : "\\b"169 default:170 return ""171 }172 }173 genLookaroundAssertionNode(node: AST.LookAroundAssertionNode) {174 const { children, kind, negate } = node175 return lookAroundMap[kind][negate ? 1 : 0] + this.genNodes(children) + ")"176 }177 genBackReference(node: AST.BackReferenceNode) {178 const { ref } = node179 if (digitRegex.test(ref)) {180 return `\\${ref}`181 }182 return `\\k<${ref}>`183 }184}185const gen = (ast: AST.Regex | AST.Node[], isLiteral = false) => {186 const codeGen = new CodeGen(ast, isLiteral)187 return codeGen.gen()188}...

Full Screen

Full Screen

index.ts

Source:index.ts Github

copy

Full Screen

1export type Position = Readonly<{ offset: number; line: number; column: number }>;2export type Location = Readonly<{3 source: unknown;4 start: Position;5 end: Position;6}>;7type ASTLiteral<TType extends string, TValue> = Readonly<{8 type: TType;9 value: TValue;10 location: Location;11}>;12export type ParsedUnsignedIntegerLiteral = ASTLiteral<'unsigned_integer', string>;13export type ParsedSignedIntegerLiteral = ASTLiteral<'signed_integer', string>;14export type ParsedFloatLiteral = ASTLiteral<'float', string>;15export type ParsedBooleanLiteral = ASTLiteral<'boolean', boolean>;16export type ParsedStringLiteral = ASTLiteral<'string', string>;17export type ParsedAST = ReadonlyArray<ParsedTypedefNode>;18type ASTNode<TType extends string, TPayload> = Readonly<{19 type: TType;20 payload: TPayload;21 location: Location;22}>;23export type ParsedIdentifierNode = ASTNode<24 'identifier',25 {26 name: string;27 }28>;29export type ParsedTypedefNode = ASTNode<30 'typedef',31 {32 modifiers: never[] | ['export'];33 identifier: ParsedIdentifierNode;34 type: ParsedTypeNode;35 }36>;37export type ParsedTypeNode =38 | ParsedIntersectionTypeNode39 | ParsedUnionTypeNode40 | ParsedArrayTypeNode41 | ParsedStringTypeNode42 | ParsedDateStringTypeNode43 | ParsedIntegerTypeNode44 | ParsedFloatTypeNode45 | ParsedBooleanTypeNode46 | ParsedNullTypeNode47 | ParsedIntegerLiteralTypeNode48 | ParsedFloatLiteralTypeNode49 | ParsedBooleanLiteralTypeNode50 | ParsedStringLiteralTypeNode51 | ParsedDictionaryTypeNode52 | ParsedNamedTupleTypeNode53 | ParsedTupleTypeNode54 | ParsedIdentifierNode;55export type ParsedStringTypeNode = ASTNode<56 'string_type',57 {58 min: ParsedUnsignedIntegerLiteral | null;59 max: ParsedUnsignedIntegerLiteral | null;60 }61>;62export type ParsedDateStringTypeNode = ASTNode<'date_string_type', null>;63export type ParsedIntegerTypeNode = ASTNode<64 'integer_type',65 {66 min: ParsedSignedIntegerLiteral | null;67 max: ParsedSignedIntegerLiteral | null;68 }69>;70export type ParsedFloatTypeNode = ASTNode<71 'float_type',72 {73 left: [ParsedSignedIntegerLiteral | ParsedFloatLiteral, 'open' | 'closed'] | null;74 right: [ParsedSignedIntegerLiteral | ParsedFloatLiteral, 'open' | 'closed'] | null;75 }76>;77export type ParsedBooleanTypeNode = ASTNode<'boolean_type', null>;78export type ParsedNullTypeNode = ASTNode<'null_type', null>;79export type ParsedIntegerLiteralTypeNode = ASTNode<'integer_literal_type', { value: ParsedSignedIntegerLiteral }>;80export type ParsedFloatLiteralTypeNode = ASTNode<'float_literal_type', { value: ParsedFloatLiteral }>;81export type ParsedBooleanLiteralTypeNode = ASTNode<'boolean_literal_type', { value: ParsedBooleanLiteral }>;82export type ParsedStringLiteralTypeNode = ASTNode<'string_literal_type', { value: ParsedStringLiteral }>;83export type ParsedDictionaryTypeNode = ASTNode<84 'dictionary_type',85 {86 properties: {87 identifier: ParsedIdentifierNode;88 optional: boolean;89 type: ParsedTypeNode;90 }[];91 }92>;93export type ParsedNamedTupleTypeNode = ASTNode<94 'named_tuple_type',95 {96 elements: {97 identifier: ParsedIdentifierNode;98 optional: boolean;99 type: ParsedTypeNode;100 }[];101 }102>;103export type ParsedTupleTypeNode = ASTNode<'tuple_type', { elements: ParsedTypeNode[] }>;104export type ParsedArrayTypeNode = ASTNode<105 'array_type',106 {107 type: ParsedTypeNode;108 min: ParsedUnsignedIntegerLiteral | null;109 max: ParsedUnsignedIntegerLiteral | null;110 }111>;112export type ParsedIntersectionTypeNode = ASTNode<113 'intersection_type',114 {115 types: ParsedTypeNode[];116 }117>;118export type ParsedUnionTypeNode = ASTNode<119 'union_type',120 {121 types: ParsedTypeNode[];122 }...

Full Screen

Full Screen

expression.ts

Source:expression.ts Github

copy

Full Screen

1import { ISrcLoc, SrcLoc } from '../../diagnostic'2import { Literal, ASTLiteralPattern, matchASTLiteral } from './literal'3import { Decl, IModule, IParam, IPort } from './declaration'4export type Expr = Literal | IRef<Decl> | ITuple | IRange | IBinOp | IInst5export interface ASTExprPattern<T> extends ASTLiteralPattern<T> {6 Ref: (ref: IRef<Decl>) => T7 Tuple: (tuple: ITuple) => T8 Range: (range: IRange) => T9 BinOp: (op: IBinOp) => T10 Inst: (inst: IInst) => T11}12export function matchASTExpr<T>(p: ASTExprPattern<T>): (expr: Expr) => T {13 return (expr: Expr): T => {14 switch(expr.tag) {15 case 'ref':16 return p.Ref(expr)17 case 'range':18 return p.Range(expr)19 case 'tuple':20 return p.Tuple(expr)21 case 'inst':22 return p.Inst(expr)23 case 'binop':24 return p.BinOp(expr)25 default:26 return matchASTLiteral(p)(expr)27 }28 }29}30/* Reference */31export interface IRef<T> {32 tag: 'ref'33 ref: T34 src: ISrcLoc35}36export function Ref<T>(ref: T, src?: ISrcLoc): IRef<T> {37 return {38 tag: 'ref',39 ref,40 src: src || SrcLoc.empty(),41 }42}43/* Reference */44/* Tuple */45export interface ITuple {46 tag: 'tuple'47 exprs: Expr[]48 src: ISrcLoc49}50export function Tuple(exprs: Expr[], src?: ISrcLoc): ITuple {51 return {52 tag: 'tuple',53 exprs,54 src: src || SrcLoc.empty(),55 }56}57/* Tuple */58/* Indexing */59export interface IRange {60 tag: 'range'61 expr: Expr62 start: Expr63 end: Expr64 src: ISrcLoc65}66export function Range(expr: Expr, start: Expr, end?: Expr,67 src?: ISrcLoc): IRange {68 return {69 tag: 'range',70 expr,71 start,72 end: end || start,73 src: src || SrcLoc.empty(),74 }75}76/* Indexing */77/* Operators */78export type BinOp = '+' | '-' | '*' | '<<' | '>>'79export interface IBinOp {80 tag: 'binop'81 op: BinOp82 lhs: Expr83 rhs: Expr84 src: ISrcLoc85}86export function BinOp(op: BinOp, lhs: Expr, rhs: Expr, src?: ISrcLoc): IBinOp {87 return {88 tag: 'binop',89 op,90 lhs,91 rhs,92 src: src || SrcLoc.empty(),93 }94}95/* Operators */96/* Instances */97export interface IInst {98 tag: 'inst'99 mod: IRef<IModule>100 params: [IRef<IParam>, Expr][]101 conns: [IRef<IPort>, Expr][]102 src: ISrcLoc103}104export function Inst(mod: IRef<IModule>,105 params: [IRef<IParam>, Expr][],106 conns: [IRef<IPort>, Expr][],107 src?: ISrcLoc): IInst {108 return {109 tag: 'inst',110 mod,111 params,112 conns,113 src: src || SrcLoc.empty(),114 }115}...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3var options = {4};5 if (err) return console.error(err);6 console.log('Test ID: %s', data.data.testId);7 console.log('User URL: %s', data.data.userUrl);8 console.log('Summary CSV: %s', data.data.summaryCSV);9 console.log('Detail CSV: %s', data.data.detailCSV);10});11var wpt = require('webpagetest');12var wpt = new WebPageTest('www.webpagetest.org');13var options = {14};15 if (err) return console.error(err);16 console.log('Test ID: %s', data.data.testId);17 console.log('User URL: %s', data.data.userUrl);18 console.log('Summary CSV: %s', data.data.summaryCSV);19 console.log('Detail CSV: %s', data.data.detailCSV);20});21var wpt = require('webpagetest');22var wpt = new WebPageTest('www.webpagetest.org');23var options = {24};25 if (err) return console.error(err);26 console.log('Test ID: %s', data.data.testId);27 console.log('User URL

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var options = {3};4var test = wpt(options);5 if (err) {6 console.log(err);7 } else {8 console.log(data);9 test.getTestStatus(data.data.testId, function(err, data) {10 if (err) {11 console.log(err);12 } else {13 console.log(data);14 }15 });16 }17});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt');2 if (!err) {3 console.log(data);4 }5});6- [All Contributors](../../contributors)

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpage').create();2 console.log(wpt.evaluate(function() {3 return document.getElementById('test').innerHTML;4 }));5 phantom.exit();6});

Full Screen

Using AI Code Generation

copy

Full Screen

1wpt.AstLiteral("foo");2wpt.AstLiteral("foo");3wpt.AstLiteral("foo");4wpt.AstLiteral("foo");5wpt.AstLiteral("foo");6wpt.AstLiteral("foo");7wpt.AstLiteral("foo");8wpt.AstLiteral("foo");9wpt.AstLiteral("foo");10wpt.AstLiteral("foo");11wpt.AstLiteral("foo");12wpt.AstLiteral("foo");13wpt.AstLiteral("foo");

Full Screen

Automation Testing Tutorials

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

LambdaTest Learning Hubs:

YouTube

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

Run wpt automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful