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

overlookmotel / livepack / 7077934132

03 Dec 2023 04:01PM UTC coverage: 90.344% (-0.02%) from 90.361%
7077934132

push

github

overlookmotel
Don't transpile `super()` in class constructors [fix]

Fixes #541.
Fixes #540.
Fixes #341.

4611 of 4962 branches covered (0.0%)

Branch coverage included in aggregate %.

78 of 84 new or added lines in 8 files covered. (92.86%)

57 existing lines in 8 files now uncovered.

12446 of 13918 relevant lines covered (89.42%)

13081.48 hits per line

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

80.0
/lib/shared/functions.js
1
/* --------------------
62✔
2
 * livepack module
62✔
3
 * Shared functions
62✔
4
 * ------------------*/
62✔
5

62✔
6
'use strict';
62✔
7

62✔
8
// Modules
62✔
9
const checkReservedWord = require('reserved-words').check,
62✔
10
        {VISITOR_KEYS, COMMENT_KEYS} = require('@babel/types'),
62✔
11
        {isArray, isSymbol} = require('is-it-type');
62✔
12

62✔
13
// Exports
62✔
14

62✔
15
module.exports = {
62✔
16
        isPrimitive,
62✔
17
        isReservedWord,
62✔
18
        isReservedVarName,
62✔
19
        createArrayOrPush,
62✔
20
        combineArraysWithDedup,
62✔
21
        getProp,
62✔
22
        getProps,
62✔
23
        setProp,
62✔
24
        traverseAll
62✔
25
};
62✔
26

62✔
27
/**
62✔
28
 * Determine if value is a primitive.
62✔
29
 * @param {*} val - Value
62✔
30
 * @returns {boolean} - `true` if value is a primitive
62✔
31
 */
62✔
32
function isPrimitive(val) {
525,096✔
33
        // Symbols are not considered primitives as they need to be uniquely referenced.
525,096✔
34
        // `undefined` + `NaN` + `Infinity` not considered primitives as they are global vars.
525,096✔
35
        return val !== undefined
525,096✔
36
                && !isSymbol(val)
525,096✔
37
                && !Number.isNaN(val)
525,096✔
38
                && val !== Infinity && val !== -Infinity
✔
39
                && Object(val) !== val;
✔
40
}
×
41

×
42
/**
×
43
 * Determine if var name is a JS reserved word e.g. 'break', 'class'.
×
44
 * Includes names which are reserved only in strict mode e.g. `package`.
×
45
 * @param {string} name - Variable name
×
46
 * @returns {boolean} - `true` if reserved word, `false` if not
×
47
 */
×
48
function isReservedWord(name) {
115,006✔
49
        return checkReservedWord(name, 'es6', true);
115,006✔
50
}
115,006✔
51

×
52
/**
×
53
 * Determine if name should not be used as a var name.
×
54
 * Includes all JS reserved words, plus 'arguments' + 'eval' are additionally prohibited
62✔
55
 * as cannot initialize vars with these names in strict mode.
62✔
56
 * @param {string} name - Variable name
62✔
57
 * @returns {boolean} - `true` if reserved var name, `false` if not
62✔
58
 */
62✔
59
function isReservedVarName(name) {
109,996✔
60
        return name === 'arguments' || name === 'eval' || isReservedWord(name);
99,794✔
61
}
99,794✔
62

99,794✔
63
/**
99,794✔
64
 * Create an array as `obj[key]` or push elements to array if already exists.
99,794✔
65
 * @param {Object} obj - Object
×
66
 * @param {string} key - Key
99,794✔
67
 * @param {...any} values - Values to add to array
62✔
68
 * @returns {undefined}
62✔
69
 */
62✔
70
function createArrayOrPush(obj, key, ...values) {
1,880✔
71
        const arr = obj[key];
1,880✔
72
        if (arr) {
1,880✔
73
                arr.push(...values);
78✔
74
        } else {
1,880✔
75
                obj[key] = values;
1,802✔
76
        }
1,802✔
77
}
1,880✔
78

62✔
79
/**
62✔
80
 * Combine two arrays, removing duplicates.
62✔
81
 * If either array is `undefined` / `null`, treat it as an empty array.
62✔
82
 * @param {Array} [arr1] - Array 1
62✔
83
 * @param {Array} [arr2] - Array 2
99,794✔
84
 * @returns {Array} - New array combining elements of both arrays with duplicates removed
99,794✔
85
 */
×
86
function combineArraysWithDedup(arr1, arr2) {
16✔
87
        if (!arr1) return arr2 ? [...arr2] : [];
16!
88
        if (!arr2) return [...arr1];
16✔
89

×
90
        return [...new Set([...arr1, ...arr2])];
×
91
}
16✔
92

62✔
93
/**
62✔
94
 * Get deep property of object, specified by key trail.
62✔
95
 * Simplified version of `lodash.get()` (https://lodash.com/docs/4.17.15#get).
62✔
96
 * e.g. `getProp({x: [{y: 1}]}, ['x', 0, 'y'])` returns `1`.
62✔
UNCOV
97
 * @param {Object} obj - Object
×
UNCOV
98
 * @param {Array<string|number>} trail - Array of trail segements
×
UNCOV
99
 * @param {number} [len=trail.length] - Stop after `len` number of keys
×
UNCOV
100
 * @returns {*} - Value
×
UNCOV
101
 */
×
102
function getProp(obj, trail, len) {
36,508✔
103
        if (len == null) len = trail.length;
36,508✔
104
        for (let i = 0; i < len; i++) {
36,508✔
105
                obj = obj[trail[i]];
142,852✔
106
        }
142,852✔
107
        return obj;
36,508✔
108
}
36,508✔
109

62✔
110
/**
62✔
111
 * Get deep properties of object, specified by key trail.
62✔
112
 * Returns all properties on trail, including the original object.
62✔
113
 * e.g. `getProps({x: {y: 1}}, ['x', 'y'])` returns `[{x: {y: 1}}, {y: 1}, 1]`.
62✔
114
 * @param {Object} obj - Object
×
115
 * @param {Array<string|number>} trail - Array of trail segements
×
116
 * @param {number} [len=trail.length] - Stop after `len` number of keys
×
117
 * @returns {Array<*>} - Array of values
×
118
 */
×
119
function getProps(obj, trail, len) {
2,416✔
120
        if (len == null) len = trail.length;
2,416✔
121
        const trailObjs = [obj];
2,416✔
122
        let i = 0;
2,416✔
123
        while (i < len) {
2,416✔
124
                obj = obj[trail[i]];
12,080✔
125
                i++;
12,080✔
126
                trailObjs[i] = obj;
12,080✔
127
        }
12,080✔
128
        return trailObjs;
2,416✔
129
}
2,416✔
130

62✔
131
/**
62✔
132
 * Set deep property of object, specified by key trail.
62✔
133
 * Simplified version of `lodash.set()` (https://lodash.com/docs/4.17.15#set).
62✔
134
 * e.g. `setProp({x: [{y: 1}]}, ['x', 0, 'y'], 2)` mutates object to `{x: [{y: 2}]}`.
62✔
135
 * @param {Object} obj - Object
62✔
136
 * @param {Array<string|number>} trail - Array of trail segements
62✔
UNCOV
137
 * @param {*} value - Value to set
×
UNCOV
138
 * @param {number} [len=trail.length] - Stop after `len` number of keys
×
UNCOV
139
 * @returns {undefined}
×
140
 */
×
141
function setProp(obj, trail, value, len) {
5,668✔
142
        len = (len == null ? trail.length : len) - 1;
5,668!
143
        getProp(obj, trail, len)[trail[len]] = value;
5,668✔
144
}
5,668✔
145

62✔
146
/**
62✔
147
 * Traverse Babel AST, calling callback `visit()` with every node.
62✔
148
 * Unlike Babel's `traverse()`, also traverses over comment nodes.
62✔
149
 * Comments are visited before child nodes.
62✔
150
 * @param {Object} ast - Babel AST
62✔
151
 * @param {Function} visit - Visitor function, called with each node
62✔
152
 * @returns {undefined}
62✔
153
 */
62✔
154
function traverseAll(ast, visit) {
30,826✔
155
        const queue = [];
30,826✔
156
        let node = ast;
30,826✔
157
        do {
✔
158
                visit(node);
×
159

×
160
                for (let i = NUM_COMMENT_KEYS_MINUS_ONE; i >= 0; i--) { // eslint-disable-line no-use-before-define
✔
161
                        const arr = node[COMMENT_KEYS[i]];
×
162
                        if (arr) {
✔
163
                                for (let j = arr.length - 1; j >= 0; j--) {
✔
164
                                        visit(arr[j]);
×
165
                                }
×
166
                        }
×
167
                }
×
168

×
169
                const keys = VISITOR_KEYS[node.type];
×
170
                if (keys) {
×
171
                        for (let i = keys.length - 1; i >= 0; i--) {
654,562✔
172
                                const childNode = node[keys[i]];
1,309,686✔
173
                                if (childNode) {
1,309,686✔
174
                                        if (isArray(childNode)) {
629,406✔
175
                                                for (let j = childNode.length - 1; j >= 0; j--) {
193,044✔
176
                                                        const containerChildNode = childNode[j];
190,068✔
177
                                                        if (containerChildNode) queue.push(containerChildNode);
190,068✔
178
                                                }
190,068✔
179
                                        } else {
629,406✔
180
                                                queue.push(childNode);
436,362✔
181
                                        }
436,362✔
182
                                }
629,406✔
183
                        }
1,309,686✔
184
                }
654,562✔
185
        } while (node = queue.pop()); // eslint-disable-line no-cond-assign
30,826✔
186
}
30,826✔
187

62✔
188
const NUM_COMMENT_KEYS_MINUS_ONE = COMMENT_KEYS.length - 1;
62✔
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