ripple 0.3.44 → 0.3.45

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/utils/ast.js DELETED
@@ -1,273 +0,0 @@
1
- /** @import * as AST from '@tsrx/core/types/estree' */
2
-
3
- /**
4
- * Represents the path of a destructured assignment from either a declaration
5
- * or assignment expression. For example, given `const { foo: { bar: baz } } = quux`,
6
- * the path of `baz` is `foo.bar`
7
- * @typedef {{
8
- * node: AST.Identifier | AST.MemberExpression;
9
- * is_rest: boolean;
10
- * has_default_value: boolean;
11
- * expression: (object: AST.Identifier | AST.CallExpression) => AST.Expression;
12
- * update_expression: (object: AST.Identifier) => AST.Expression;
13
- * }} DestructuredAssignment
14
- * - `node`: The node the destructuring path ends in. Can be a member expression only for assignment expressions
15
- * - `is_rest`: `true` if this is a `...rest` destructuring
16
- * - `has_default_value`: `true` if this has a fallback value like `const { foo = 'bar' } = ..`
17
- * - `expression`: The value of the current path. Will be a call expression if a rest element or default is involved — e.g. `const { foo: { bar: baz = 42 }, ...rest } = quux` — since we can't represent `baz` or `rest` purely as a path. Will be an await expression in case of an async default value (`const { foo = await bar } = ...`)
18
- * - `update_expression`: Like `expression` but without default values.
19
- */
20
-
21
- import * as b from './builders.js';
22
-
23
- /**
24
- * Gets the left-most identifier of a member expression or identifier.
25
- * @param {AST.MemberExpression | AST.Identifier} expression
26
- * @returns {AST.Identifier | null}
27
- */
28
- export function object(expression) {
29
- while (expression.type === 'MemberExpression') {
30
- expression = /** @type {AST.MemberExpression | AST.Identifier} */ (expression.object);
31
- }
32
-
33
- if (expression.type !== 'Identifier') {
34
- return null;
35
- }
36
-
37
- return expression;
38
- }
39
-
40
- /**
41
- * Extracts all identifiers and member expressions from a pattern.
42
- * @param {AST.Pattern} pattern
43
- * @param {Array<AST.Identifier | AST.MemberExpression>} [nodes]
44
- * @returns {Array<AST.Identifier | AST.MemberExpression>}
45
- */
46
- export function unwrap_pattern(pattern, nodes = []) {
47
- switch (pattern.type) {
48
- case 'Identifier':
49
- nodes.push(pattern);
50
- break;
51
-
52
- case 'MemberExpression':
53
- // member expressions can be part of an assignment pattern, but not a binding pattern
54
- // see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment#binding_and_assignment
55
- nodes.push(pattern);
56
- break;
57
-
58
- case 'ObjectPattern':
59
- for (const prop of pattern.properties) {
60
- if (prop.type === 'RestElement') {
61
- unwrap_pattern(prop.argument, nodes);
62
- } else {
63
- unwrap_pattern(prop.value, nodes);
64
- }
65
- }
66
-
67
- break;
68
-
69
- case 'ArrayPattern':
70
- for (const element of pattern.elements) {
71
- if (element) unwrap_pattern(element, nodes);
72
- }
73
-
74
- break;
75
-
76
- case 'RestElement':
77
- unwrap_pattern(pattern.argument, nodes);
78
- break;
79
-
80
- case 'AssignmentPattern':
81
- unwrap_pattern(pattern.left, nodes);
82
- break;
83
- }
84
-
85
- return nodes;
86
- }
87
-
88
- /**
89
- * Extracts all identifiers from a pattern.
90
- * @param {AST.Pattern} pattern
91
- * @returns {AST.Identifier[]}
92
- */
93
- export function extract_identifiers(pattern) {
94
- return unwrap_pattern(pattern, []).filter((node) => node.type === 'Identifier');
95
- }
96
-
97
- /**
98
- * Extracts all destructured assignments from a pattern.
99
- * @param {AST.Node} param
100
- * @returns {DestructuredAssignment[]}
101
- */
102
- export function extract_paths(param) {
103
- return _extract_paths(
104
- [],
105
- param,
106
- /** @param {AST.Identifier | AST.MemberExpression | AST.CallExpression} node */
107
- (node) => node,
108
- /** @param {AST.Identifier | AST.MemberExpression} node */
109
- (node) => node,
110
- false,
111
- );
112
- }
113
-
114
- /**
115
- * @param {DestructuredAssignment[]} assignments
116
- * @param {AST.Node} param
117
- * @param {DestructuredAssignment['expression']} expression
118
- * @param {DestructuredAssignment['update_expression']} update_expression
119
- * @param {boolean} has_default_value
120
- * @returns {DestructuredAssignment[]}
121
- */
122
- function _extract_paths(assignments = [], param, expression, update_expression, has_default_value) {
123
- switch (param.type) {
124
- case 'Identifier':
125
- case 'MemberExpression':
126
- assignments.push({
127
- node: param,
128
- is_rest: false,
129
- has_default_value,
130
- expression,
131
- update_expression,
132
- });
133
- break;
134
-
135
- case 'ObjectPattern':
136
- for (const prop of param.properties) {
137
- if (prop.type === 'RestElement') {
138
- /** @type {DestructuredAssignment['expression']} */
139
- const rest_expression = (object) => {
140
- /** @type {AST.Expression[]} */
141
- const props = [];
142
-
143
- for (const p of param.properties) {
144
- if (p.type === 'Property' && p.key.type !== 'PrivateIdentifier') {
145
- if (p.key.type === 'Identifier' && !p.computed) {
146
- props.push(b.literal(p.key.name));
147
- } else if (p.key.type === 'Literal') {
148
- props.push(b.literal(String(p.key.value)));
149
- } else {
150
- props.push(b.call('String', p.key));
151
- }
152
- }
153
- }
154
-
155
- return b.call('_$_.exclude_from_object', expression(object), b.array(props));
156
- };
157
-
158
- if (prop.argument.type === 'Identifier') {
159
- assignments.push({
160
- node: prop.argument,
161
- is_rest: true,
162
- has_default_value,
163
- expression: rest_expression,
164
- update_expression: rest_expression,
165
- });
166
- } else {
167
- _extract_paths(
168
- assignments,
169
- prop.argument,
170
- rest_expression,
171
- rest_expression,
172
- has_default_value,
173
- );
174
- }
175
- } else {
176
- /** @type {DestructuredAssignment['expression']} */
177
- const object_expression = (object) =>
178
- b.member(expression(object), prop.key, prop.computed || prop.key.type !== 'Identifier');
179
- _extract_paths(
180
- assignments,
181
- prop.value,
182
- object_expression,
183
- object_expression,
184
- has_default_value,
185
- );
186
- }
187
- }
188
-
189
- break;
190
-
191
- case 'ArrayPattern':
192
- for (let i = 0; i < param.elements.length; i += 1) {
193
- const element = param.elements[i];
194
- if (element) {
195
- if (element.type === 'RestElement') {
196
- /** @type {DestructuredAssignment['expression']} */
197
- const rest_expression = (object) =>
198
- b.call('_$_.array_slice', expression(object), b.literal(i));
199
- if (element.argument.type === 'Identifier') {
200
- assignments.push({
201
- node: element.argument,
202
- is_rest: true,
203
- has_default_value,
204
- expression: rest_expression,
205
- update_expression: rest_expression,
206
- });
207
- } else {
208
- _extract_paths(
209
- assignments,
210
- element.argument,
211
- rest_expression,
212
- rest_expression,
213
- has_default_value,
214
- );
215
- }
216
- } else {
217
- /** @type {DestructuredAssignment['expression']} */
218
- const array_expression = (object) => b.member(expression(object), b.literal(i), true);
219
- _extract_paths(
220
- assignments,
221
- element,
222
- array_expression,
223
- array_expression,
224
- has_default_value,
225
- );
226
- }
227
- }
228
- }
229
-
230
- break;
231
-
232
- case 'AssignmentPattern': {
233
- /** @type {DestructuredAssignment['expression']} */
234
- const fallback_expression = (object) => build_fallback(expression(object), param.right);
235
-
236
- if (param.left.type === 'Identifier') {
237
- assignments.push({
238
- node: param.left,
239
- is_rest: false,
240
- has_default_value: true,
241
- expression: fallback_expression,
242
- update_expression,
243
- });
244
- } else {
245
- _extract_paths(assignments, param.left, fallback_expression, update_expression, true);
246
- }
247
-
248
- break;
249
- }
250
- }
251
-
252
- return assignments;
253
- }
254
-
255
- /**
256
- * @param {AST.Expression} expression
257
- * @param {AST.Expression} fallback
258
- */
259
- export function build_fallback(expression, fallback) {
260
- return b.call('_$_.fallback', expression, fallback);
261
- }
262
-
263
- /**
264
- * @param {AST.AssignmentOperator} operator
265
- * @param {AST.Identifier | AST.MemberExpression} left
266
- * @param {AST.Expression} right
267
- */
268
- export function build_assignment_value(operator, left, right) {
269
- return operator === '='
270
- ? right
271
- : // turn something like x += 1 into x = x + 1
272
- b.binary(/** @type {AST.BinaryOperator} */ (operator.slice(0, -1)), left, right);
273
- }
@@ -1,43 +0,0 @@
1
- /**
2
- * Attributes that are boolean, i.e. they are present or not present.
3
- */
4
- const DOM_BOOLEAN_ATTRIBUTES = [
5
- 'allowfullscreen',
6
- 'async',
7
- 'autofocus',
8
- 'autoplay',
9
- 'checked',
10
- 'controls',
11
- 'default',
12
- 'disabled',
13
- 'formnovalidate',
14
- 'hidden',
15
- 'indeterminate',
16
- 'inert',
17
- 'ismap',
18
- 'loop',
19
- 'multiple',
20
- 'muted',
21
- 'nomodule',
22
- 'novalidate',
23
- 'open',
24
- 'playsinline',
25
- 'readonly',
26
- 'required',
27
- 'reversed',
28
- 'seamless',
29
- 'selected',
30
- 'webkitdirectory',
31
- 'defer',
32
- 'disablepictureinpicture',
33
- 'disableremoteplayback',
34
- ];
35
-
36
- /**
37
- * Returns true if name is a boolean DOM attribute
38
- * @param {string} name
39
- * @returns {boolean}
40
- */
41
- export function is_boolean_attribute(name) {
42
- return DOM_BOOLEAN_ATTRIBUTES.includes(name);
43
- }