How to use baseParse method in Playwright Internal

Best JavaScript code snippet using playwright-internal

Run Playwright Internal automation tests on LambdaTest cloud grid

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

index.cjs

Source: index.cjs Github

copy
1const {
2  normalizeESLintConfig
3} = require("./configuration.cjs");
4
5const analyzeScope = require("./analyze-scope.cjs");
6
7const baseParse = require("./parse.cjs");
8
9const {
10  LocalClient,
11  WorkerClient
12} = require("./client.cjs");
13
14const client = new LocalClient();
15
16exports.parse = function (code, options = {}) {
17  return baseParse(code, normalizeESLintConfig(options), client);
18};
19
20exports.parseForESLint = function (code, options = {}) {
21  const normalizedOptions = normalizeESLintConfig(options);
22  const ast = baseParse(code, normalizedOptions, client);
23  const scopeManager = analyzeScope(ast, normalizedOptions, client);
24  return {
25    ast,
26    scopeManager,
27    visitorKeys: client.getVisitorKeys()
28  };
29};
Full Screen

parse.js

Source: parse.js Github

copy
1/*jslint plusplus: false, strict: false */
2/*global define: false */
3
4/**
5 * An override for the jslib/parse.js to convert stealjs calls into
6 * require/define calls.
7 */
8
9define(['../../jslib/parse'], function (baseParse) {
10
11    var parse = baseParse,
12        allowedCalls = {
13            plugins: true,
14            views: true
15        },
16        viewStringRegExp = /^\/\//;
17
18    /**
19     * Finds a steal node in a nested, backwards AST tree structure.
20     */
21    function getStealCall(node) {
22        if (!baseParse.isArray(node)) {
23            return false;
24        }
25
26        if (node[0] === 'name' && node[1] === 'steal' && !node.isRequireJSParsed) {
27            return node;
28        } else if (node[0] === 'call') {
29            if (node[1][0] === 'name' && node[1][1] === 'steal') {
30                return getStealCall(node[1]);
31            } else if (node[1][0] === 'dot') {
32                return getStealCall(node[1][1]);
33            }
34        }
35
36        return null;
37    }
38
39    /**
40     * Mark the steal node tree as processed. Need to do this given the
41     * backwards structure of the AST.
42     */
43    function markStealTreeProcessed(node) {
44        getStealCall(node).isRequireJSParsed = true;
45    }
46
47    /**
48     * Transform a .views depdencency to an ejs! plugin loaded depdendency
49     * @param {String} value the .views string name.
50     * @returns {String} an 'ejs!' string
51     */
52    function viewTransform(value) {
53        return 'ejs!' + value.replace(viewStringRegExp, '');
54    }
55
56    function addStringsToArray(node, array, transform) {
57        var i, item, matches = [];
58        for (i = 0; i < node.length; i++) {
59            item = node[i];
60            if (item && baseParse.isArray(item) && item[0] === 'string') {
61                matches.push((transform ? transform(item[1]) : item[1]));
62            }
63        }
64
65        if (matches.length) {
66            //Build up arguments to splice, since we need to put these
67            //matches before other matches, given the backwards nature of
68            //the call traversal in the AST.
69            matches.unshift(0);
70            matches.unshift(0);
71            array.splice.apply(array, matches);
72        }
73    }
74
75    function generateRequireCall(node, array) {
76        if (!baseParse.isArray(node)) {
77            return;
78        }
79
80        var args, previous, call;
81
82        if (node[0] === 'call' && node[1][0] === 'name' && node[1][1] === 'steal') {
83            //A simple steal() call.
84            addStringsToArray(node[2], array);
85        } else {
86            //A chained call
87            //Need to unwind the call since the dot access shows up "backwards"
88            //in the AST.
89            args = node[node.length - 1];
90            previous = node[node.length - 2];
91            call = previous[previous.length - 1];
92
93            if (typeof call === 'string' && allowedCalls[call]) {
94                if (call === 'plugins') {
95                    addStringsToArray(args, array);
96                } else if (call === 'views') {
97                    addStringsToArray(args, array, viewTransform);
98                }
99
100                //Find out if there are any other chained calls.
101                previous = previous[previous.length - 2];
102
103                generateRequireCall(previous, array);
104            }
105        }
106    }
107
108    parse.oldParseNode = parse.parseNode;
109
110    parse.parseNode = function (node) {
111        var value;
112
113        if (!this.isArray(node)) {
114            return null;
115        }
116
117        //Allow files with regular define/require calls to be co-mingled
118        //with StealJS APIs.
119        value = this.oldParseNode(node);
120        if (value) {
121            return value;
122        }
123
124        if (getStealCall(node)) {
125            value = [];
126            generateRequireCall(node, value);
127            if (value.length) {
128                markStealTreeProcessed(node);
129                return "require(" + JSON.stringify(value) + ");";
130            } else {
131                return '';
132            }
133        }
134
135        return null;
136    };
137
138/*
139 use console.log(JSON.stringify(node, null, '  ')) to print out AST
140
141 Using this:
142 steal.plugins('foo','bar').views('//abc/init.ejs').then(function(){})
143
144 Has this for one of the nodes.
145
146[
147  "call",
148  [
149    "dot",
150    [
151      "call",
152      [
153        "dot",
154        [
155          "name",
156          "steal"
157        ],
158        "plugins"
159      ],
160      [
161        [
162          "string",
163          "foo"
164        ],
165        [
166          "string",
167          "bar"
168        ]
169      ]
170    ],
171    "views"
172  ],
173  [
174    [
175      "string",
176      "//abc/init.ejs"
177    ]
178  ]
179]
180
181**************************
182
183steal('one', 'two')
184
185[
186  "toplevel",
187  [
188    [
189      "stat",
190      [
191        "call",
192        [
193          "name",
194          "steal"
195        ],
196        [
197          [
198            "string",
199            "one"
200          ],
201          [
202            "string",
203            "two"
204          ]
205        ]
206      ]
207    ]
208  ]
209]
210
211*/
212
213    return parse;
214});
215
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Run JavaScript Tests on LambdaTest Cloud Grid

Execute automation tests with Playwright Internal on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)