• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

magento / pwa-studio / #25290

13 Feb 2025 10:58AM UTC coverage: 85.778% (-0.1%) from 85.922%
#25290

Pull #4403

codebuild

glo82145
PWA remove gomage package
Pull Request #4403: PWA remove gomage package

5224 of 6494 branches covered (80.44%)

Branch coverage included in aggregate %.

13208 of 14994 relevant lines covered (88.09%)

29.57 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

90.7
/packages/pwa-buildpack/lib/WebpackTools/targetables/BabelModifyJSXPlugin/JSXModifier.js
1
const JSXSnippetParser = require('./JSXSnippetParser');
2✔
2
const Operation = require('./Operation');
2✔
3

4
/**
5
 * Processor for JSX nodes in an AST, which receives a list of instructions and
6
 * then a sequence of nodes from the plugin visitor.
7
 *
8
 * For every JSX node, JSXModifier will check its library of operations to see
9
 * if one matches, and if so, it will run the requested operation on the node.
10
 *
11
 * @class JSXModifier
12
 */
13
class JSXModifier {
14
    constructor(requests, babel, visitor) {
15
        this.parser = new JSXSnippetParser(babel, visitor.filename);
2✔
16
        this.visitor = visitor;
2✔
17
        this.operations = new Set(
2✔
18
            requests.map(request =>
19
                Operation.fromRequest(request, {
31✔
20
                    parser: this.parser,
21
                    file: this.visitor.file,
22
                    babel
23
                })
24
            )
25
        );
26
        this.unmatchedOperations = new Set(this.operations);
2✔
27
        this.visited = new WeakMap();
2✔
28
        this.visitor.file.metadata.warnings = [];
2✔
29
    }
30
    runMatchingOperations(openingPath) {
31
        const path = openingPath.parentPath;
40✔
32
        // detach node so that we preserve its identity, even if the operation
33
        // changes the value of path.node. Otherwise, we won't cache the node we
34
        // actually visited, and we may end up infinitely recurring.
35
        const originalNode = path.node;
40✔
36
        const hasAlreadyRun = this.visited.get(originalNode) || new Set();
40✔
37
        for (const operation of this.operations) {
40✔
38
            if (operation.match(path) && !hasAlreadyRun.has(operation)) {
89✔
39
                this.unmatchedOperations.delete(operation);
17✔
40
                operation.run(path);
17✔
41
                hasAlreadyRun.add(operation);
17✔
42
                if (!operation.global) {
17✔
43
                    this.operations.delete(operation);
15✔
44
                }
45
                this.visited.set(originalNode, hasAlreadyRun);
17✔
46
                if (path.removed || !path.node) {
17!
47
                    break;
×
48
                } else if (path.node !== originalNode) {
17✔
49
                    this.visited.set(path.node, hasAlreadyRun);
1✔
50
                }
51
            }
52
        }
53
    }
54

55
    parseJSXParam(params) {
56
        return this.parser.parseElement(
×
57
            this.parser.normalizeElement(params.jsx)
58
        );
59
    }
60

61
    warnUnmatchedOperations() {
62
        const { warnings } = this.visitor.file.metadata;
1✔
63
        for (const operation of this.unmatchedOperations) {
1✔
64
            warnings.push(
×
65
                `JSX operation:\n${operation}\nnever found an element matching '${
66
                    operation.element
67
                }'`
68
            );
69
        }
70
    }
71
}
72

73
module.exports = JSXModifier;
2✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc