How to use buildDynamicSlot 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.

vSlot.js

Source: vSlot.js Github

copy
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3var ast_1 = require("../ast");
4var errors_1 = require("../errors");
5var utils_1 = require("../utils");
6var runtimeHelpers_1 = require("../runtimeHelpers");
7var vFor_1 = require("./vFor");
8var isStaticExp = function (p) {
9    return p.type === 4 && p.isStatic;
10};
11var defaultFallback = ast_1.createSimpleExpression("undefined", false);
12exports.trackSlotScopes = function (node, context) {
13    if (node.type === 1 &&
14        (node.tagType === 1 ||
15            node.tagType === 3)) {
16        var vSlot = utils_1.findDir(node, 'slot');
17        if (vSlot) {
18            var slotProps_1 = vSlot.exp;
19            if (!__BROWSER__ && context.prefixIdentifiers) {
20                slotProps_1 && context.addIdentifiers(slotProps_1);
21            }
22            context.scopes.vSlot++;
23            return function () {
24                if (!__BROWSER__ && context.prefixIdentifiers) {
25                    slotProps_1 && context.removeIdentifiers(slotProps_1);
26                }
27                context.scopes.vSlot--;
28            };
29        }
30    }
31};
32exports.trackVForSlotScopes = function (node, context) {
33    var vFor;
34    if (utils_1.isTemplateNode(node) &&
35        node.props.some(utils_1.isVSlot) &&
36        (vFor = utils_1.findDir(node, 'for'))) {
37        var result = (vFor.parseResult = vFor_1.parseForExpression(vFor.exp, context));
38        if (result) {
39            var value_1 = result.value, key_1 = result.key, index_1 = result.index;
40            var addIdentifiers = context.addIdentifiers, removeIdentifiers_1 = context.removeIdentifiers;
41            value_1 && addIdentifiers(value_1);
42            key_1 && addIdentifiers(key_1);
43            index_1 && addIdentifiers(index_1);
44            return function () {
45                value_1 && removeIdentifiers_1(value_1);
46                key_1 && removeIdentifiers_1(key_1);
47                index_1 && removeIdentifiers_1(index_1);
48            };
49        }
50    }
51};
52function buildSlots(node, context) {
53    var children = node.children, loc = node.loc;
54    var slotsProperties = [];
55    var dynamicSlots = [];
56    var hasDynamicSlots = context.scopes.vSlot > 0 || context.scopes.vFor > 0;
57    if (!__BROWSER__ && context.prefixIdentifiers) {
58        hasDynamicSlots = utils_1.hasScopeRef(node, context.identifiers);
59    }
60    var explicitDefaultSlot = utils_1.findDir(node, 'slot', true);
61    if (explicitDefaultSlot) {
62        var arg = explicitDefaultSlot.arg, exp = explicitDefaultSlot.exp, loc_1 = explicitDefaultSlot.loc;
63        if (arg) {
64            context.onError(errors_1.createCompilerError(42, loc_1));
65        }
66        slotsProperties.push(buildDefaultSlot(exp, children, loc_1));
67    }
68    var hasTemplateSlots = false;
69    var extraneousChild = undefined;
70    var seenSlotNames = new Set();
71    for (var i = 0; i < children.length; i++) {
72        var slotElement = children[i];
73        var slotDir = void 0;
74        if (!utils_1.isTemplateNode(slotElement) ||
75            !(slotDir = utils_1.findDir(slotElement, 'slot', true))) {
76            if (slotElement.type !== 3 && !extraneousChild) {
77                extraneousChild = slotElement;
78            }
79            continue;
80        }
81        if (explicitDefaultSlot) {
82            context.onError(errors_1.createCompilerError(43, slotDir.loc));
83            break;
84        }
85        hasTemplateSlots = true;
86        var slotChildren = slotElement.children, slotLoc = slotElement.loc;
87        var _a = slotDir.arg, slotName = _a === void 0 ? ast_1.createSimpleExpression("default", true) : _a, slotProps = slotDir.exp, dirLoc = slotDir.loc;
88        var staticSlotName = void 0;
89        if (isStaticExp(slotName)) {
90            staticSlotName = slotName ? slotName.content : "default";
91        }
92        else {
93            hasDynamicSlots = true;
94        }
95        var slotFunction = ast_1.createFunctionExpression(slotProps, slotChildren, false, slotChildren.length ? slotChildren[0].loc : slotLoc);
96        var vIf = void 0;
97        var vElse = void 0;
98        var vFor = void 0;
99        if ((vIf = utils_1.findDir(slotElement, 'if'))) {
100            hasDynamicSlots = true;
101            dynamicSlots.push(ast_1.createConditionalExpression(vIf.exp, buildDynamicSlot(slotName, slotFunction), defaultFallback));
102        }
103        else if ((vElse = utils_1.findDir(slotElement, /^else(-if)?$/, true))) {
104            var j = i;
105            var prev = void 0;
106            while (j--) {
107                prev = children[j];
108                if (prev.type !== 3) {
109                    break;
110                }
111            }
112            if (prev && utils_1.isTemplateNode(prev) && utils_1.findDir(prev, 'if')) {
113                children.splice(i, 1);
114                i--;
115                __DEV__ && utils_1.assert(dynamicSlots.length > 0);
116                var conditional = dynamicSlots[dynamicSlots.length - 1];
117                while (conditional.alternate.type === 19) {
118                    conditional = conditional.alternate;
119                }
120                conditional.alternate = vElse.exp
121                    ? ast_1.createConditionalExpression(vElse.exp, buildDynamicSlot(slotName, slotFunction), defaultFallback)
122                    : buildDynamicSlot(slotName, slotFunction);
123            }
124            else {
125                context.onError(errors_1.createCompilerError(36, vElse.loc));
126            }
127        }
128        else if ((vFor = utils_1.findDir(slotElement, 'for'))) {
129            hasDynamicSlots = true;
130            var parseResult = vFor.parseResult ||
131                vFor_1.parseForExpression(vFor.exp, context);
132            if (parseResult) {
133                dynamicSlots.push(ast_1.createCallExpression(context.helper(runtimeHelpers_1.RENDER_LIST), [
134                    parseResult.source,
135                    ast_1.createFunctionExpression(vFor_1.createForLoopParams(parseResult), buildDynamicSlot(slotName, slotFunction), true)
136                ]));
137            }
138            else {
139                context.onError(errors_1.createCompilerError(38, vFor.loc));
140            }
141        }
142        else {
143            if (staticSlotName) {
144                if (seenSlotNames.has(staticSlotName)) {
145                    context.onError(errors_1.createCompilerError(44, dirLoc));
146                    continue;
147                }
148                seenSlotNames.add(staticSlotName);
149            }
150            slotsProperties.push(ast_1.createObjectProperty(slotName, slotFunction));
151        }
152    }
153    if (hasTemplateSlots && extraneousChild) {
154        context.onError(errors_1.createCompilerError(45, extraneousChild.loc));
155    }
156    if (!explicitDefaultSlot && !hasTemplateSlots) {
157        slotsProperties.push(buildDefaultSlot(undefined, children, loc));
158    }
159    var slots = ast_1.createObjectExpression(slotsProperties.concat(ast_1.createObjectProperty("_compiled", ast_1.createSimpleExpression("true", false))), loc);
160    if (dynamicSlots.length) {
161        slots = ast_1.createCallExpression(context.helper(runtimeHelpers_1.CREATE_SLOTS), [
162            slots,
163            ast_1.createArrayExpression(dynamicSlots)
164        ]);
165    }
166    return {
167        slots: slots,
168        hasDynamicSlots: hasDynamicSlots
169    };
170}
171exports.buildSlots = buildSlots;
172function buildDefaultSlot(slotProps, children, loc) {
173    return ast_1.createObjectProperty("default", ast_1.createFunctionExpression(slotProps, children, false, children.length ? children[0].loc : loc));
174}
175function buildDynamicSlot(name, fn) {
176    return ast_1.createObjectExpression([
177        ast_1.createObjectProperty("name", name),
178        ast_1.createObjectProperty("fn", fn)
179    ]);
180}
181
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)