@player-tools/xlr-utils 0.4.2-next.0 → 0.4.2-next.1

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/dist/index.cjs.js CHANGED
@@ -270,6 +270,9 @@ function computeExtends(a, b) {
270
270
  return true;
271
271
  }
272
272
  }
273
+ if (a.type === "ref" && b.type === "ref") {
274
+ return a.ref === b.ref;
275
+ }
273
276
  if (a.type === "object" && b.type === "object") {
274
277
  for (const property in b.properties) {
275
278
  const propertyNode = b.properties[property];
@@ -280,6 +283,15 @@ function computeExtends(a, b) {
280
283
  return true;
281
284
  }
282
285
  }
286
+ if (isPrimitiveTypeNode(a) && b.type === "or") {
287
+ return b.or.every((member) => computeExtends(a, member));
288
+ }
289
+ if (isPrimitiveTypeNode(b) && a.type === "or") {
290
+ return a.or.every((member) => computeExtends(b, member));
291
+ }
292
+ if (a.type === "or" && b.type === "or") {
293
+ return a.or.every((x) => b.or.some((y) => computeExtends(x, y)));
294
+ }
283
295
  return false;
284
296
  }
285
297
  function resolveConditional(conditional) {
@@ -325,7 +337,7 @@ function computeEffectiveObject(base, operand, errorOnOverlap = true) {
325
337
  var _a, _b, _c, _d;
326
338
  const baseObjectName = (_b = (_a = base.name) != null ? _a : base.title) != null ? _b : "object literal";
327
339
  const operandObjectName = (_d = (_c = operand.name) != null ? _c : operand.title) != null ? _d : "object literal";
328
- const newObject = __spreadProps$1(__spreadValues$1({}, base), {
340
+ const newObject = __spreadProps$1(__spreadValues$1({}, JSON.parse(JSON.stringify(base))), {
329
341
  name: `${baseObjectName} & ${operandObjectName}`,
330
342
  description: `Effective type combining ${baseObjectName} and ${operandObjectName}`,
331
343
  genericTokens: [
@@ -334,8 +346,10 @@ function computeEffectiveObject(base, operand, errorOnOverlap = true) {
334
346
  ]
335
347
  });
336
348
  for (const property in operand.properties) {
337
- if (newObject.properties[property] !== void 0 && newObject.properties[property].node.type !== operand.properties[property].node.type && errorOnOverlap) {
338
- throw new Error(`Can't compute effective type for ${baseObjectName} and ${operandObjectName} because of conflicting properties ${property}`);
349
+ if (newObject.properties[property] !== void 0 && errorOnOverlap) {
350
+ if (!computeExtends(newObject.properties[property].node, operand.properties[property].node)) {
351
+ throw new Error(`Can't compute effective type for ${baseObjectName} and ${operandObjectName} because of conflicting properties ${property}`);
352
+ }
339
353
  }
340
354
  newObject.properties[property] = operand.properties[property];
341
355
  }
@@ -566,7 +580,7 @@ function applyPartialOrRequiredToNodeType(baseObject, modifier) {
566
580
  function applyExcludeToNodeType(baseObject, filters) {
567
581
  const remainingMembers = baseObject.or.filter((type) => {
568
582
  if (filters.type === "or") {
569
- return !filters.or.some((filter) => !computeExtends(type, filter));
583
+ return !filters.or.some((filter) => computeExtends(type, filter));
570
584
  }
571
585
  return !computeExtends(type, filters);
572
586
  });
package/dist/index.esm.js CHANGED
@@ -243,6 +243,9 @@ function computeExtends(a, b) {
243
243
  return true;
244
244
  }
245
245
  }
246
+ if (a.type === "ref" && b.type === "ref") {
247
+ return a.ref === b.ref;
248
+ }
246
249
  if (a.type === "object" && b.type === "object") {
247
250
  for (const property in b.properties) {
248
251
  const propertyNode = b.properties[property];
@@ -253,6 +256,15 @@ function computeExtends(a, b) {
253
256
  return true;
254
257
  }
255
258
  }
259
+ if (isPrimitiveTypeNode(a) && b.type === "or") {
260
+ return b.or.every((member) => computeExtends(a, member));
261
+ }
262
+ if (isPrimitiveTypeNode(b) && a.type === "or") {
263
+ return a.or.every((member) => computeExtends(b, member));
264
+ }
265
+ if (a.type === "or" && b.type === "or") {
266
+ return a.or.every((x) => b.or.some((y) => computeExtends(x, y)));
267
+ }
256
268
  return false;
257
269
  }
258
270
  function resolveConditional(conditional) {
@@ -298,7 +310,7 @@ function computeEffectiveObject(base, operand, errorOnOverlap = true) {
298
310
  var _a, _b, _c, _d;
299
311
  const baseObjectName = (_b = (_a = base.name) != null ? _a : base.title) != null ? _b : "object literal";
300
312
  const operandObjectName = (_d = (_c = operand.name) != null ? _c : operand.title) != null ? _d : "object literal";
301
- const newObject = __spreadProps$1(__spreadValues$1({}, base), {
313
+ const newObject = __spreadProps$1(__spreadValues$1({}, JSON.parse(JSON.stringify(base))), {
302
314
  name: `${baseObjectName} & ${operandObjectName}`,
303
315
  description: `Effective type combining ${baseObjectName} and ${operandObjectName}`,
304
316
  genericTokens: [
@@ -307,8 +319,10 @@ function computeEffectiveObject(base, operand, errorOnOverlap = true) {
307
319
  ]
308
320
  });
309
321
  for (const property in operand.properties) {
310
- if (newObject.properties[property] !== void 0 && newObject.properties[property].node.type !== operand.properties[property].node.type && errorOnOverlap) {
311
- throw new Error(`Can't compute effective type for ${baseObjectName} and ${operandObjectName} because of conflicting properties ${property}`);
322
+ if (newObject.properties[property] !== void 0 && errorOnOverlap) {
323
+ if (!computeExtends(newObject.properties[property].node, operand.properties[property].node)) {
324
+ throw new Error(`Can't compute effective type for ${baseObjectName} and ${operandObjectName} because of conflicting properties ${property}`);
325
+ }
312
326
  }
313
327
  newObject.properties[property] = operand.properties[property];
314
328
  }
@@ -539,7 +553,7 @@ function applyPartialOrRequiredToNodeType(baseObject, modifier) {
539
553
  function applyExcludeToNodeType(baseObject, filters) {
540
554
  const remainingMembers = baseObject.or.filter((type) => {
541
555
  if (filters.type === "or") {
542
- return !filters.or.some((filter) => !computeExtends(type, filter));
556
+ return !filters.or.some((filter) => computeExtends(type, filter));
543
557
  }
544
558
  return !computeExtends(type, filters);
545
559
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@player-tools/xlr-utils",
3
- "version": "0.4.2-next.0",
3
+ "version": "0.4.2-next.1",
4
4
  "private": false,
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org"
@@ -10,7 +10,7 @@
10
10
  "jsonc-parser": "^2.3.1"
11
11
  },
12
12
  "dependencies": {
13
- "@player-tools/xlr": "0.4.2-next.0",
13
+ "@player-tools/xlr": "0.4.2-next.1",
14
14
  "@typescript/vfs": "^1.4.0",
15
15
  "@babel/runtime": "7.15.4"
16
16
  },
package/src/ts-helpers.ts CHANGED
@@ -368,7 +368,7 @@ export function applyExcludeToNodeType(
368
368
  ): NodeType {
369
369
  const remainingMembers = baseObject.or.filter((type) => {
370
370
  if (filters.type === 'or') {
371
- return !filters.or.some((filter) => !computeExtends(type, filter));
371
+ return !filters.or.some((filter) => computeExtends(type, filter));
372
372
  }
373
373
 
374
374
  return !computeExtends(type, filters);
@@ -76,6 +76,7 @@ export function computeExtends(a: NodeType, b: NodeType): boolean {
76
76
  return true;
77
77
  }
78
78
 
79
+ // check simple case of equal types
79
80
  if (a.type === b.type) {
80
81
  if (isPrimitiveTypeNode(a) && isPrimitiveTypeNode(b)) {
81
82
  if (a.const && b.const) {
@@ -87,6 +88,10 @@ export function computeExtends(a: NodeType, b: NodeType): boolean {
87
88
  }
88
89
  }
89
90
 
91
+ if (a.type === 'ref' && b.type === 'ref') {
92
+ return a.ref === b.ref;
93
+ }
94
+
90
95
  if (a.type === 'object' && b.type === 'object') {
91
96
  for (const property in b.properties) {
92
97
  const propertyNode = b.properties[property];
@@ -102,6 +107,18 @@ export function computeExtends(a: NodeType, b: NodeType): boolean {
102
107
  }
103
108
  }
104
109
 
110
+ if (isPrimitiveTypeNode(a) && b.type === 'or') {
111
+ return b.or.every((member) => computeExtends(a, member));
112
+ }
113
+
114
+ if (isPrimitiveTypeNode(b) && a.type === 'or') {
115
+ return a.or.every((member) => computeExtends(b, member));
116
+ }
117
+
118
+ if (a.type === 'or' && b.type === 'or') {
119
+ return a.or.every((x) => b.or.some((y) => computeExtends(x, y)));
120
+ }
121
+
105
122
  return false;
106
123
  }
107
124
 
@@ -193,7 +210,7 @@ export function computeEffectiveObject(
193
210
  const baseObjectName = base.name ?? base.title ?? 'object literal';
194
211
  const operandObjectName = operand.name ?? operand.title ?? 'object literal';
195
212
  const newObject = {
196
- ...base,
213
+ ...JSON.parse(JSON.stringify(base)),
197
214
  name: `${baseObjectName} & ${operandObjectName}`,
198
215
  description: `Effective type combining ${baseObjectName} and ${operandObjectName}`,
199
216
  genericTokens: [
@@ -201,18 +218,20 @@ export function computeEffectiveObject(
201
218
  ...(isGenericNodeType(operand) ? operand.genericTokens : []),
202
219
  ],
203
220
  };
221
+ // TODO this check needs to account for primitive -> primitive generic overlap
204
222
 
205
- // eslint-disable-next-line no-restricted-syntax, guard-for-in
206
223
  for (const property in operand.properties) {
207
- if (
208
- newObject.properties[property] !== undefined &&
209
- newObject.properties[property].node.type !==
210
- operand.properties[property].node.type &&
211
- errorOnOverlap
212
- ) {
213
- throw new Error(
214
- `Can't compute effective type for ${baseObjectName} and ${operandObjectName} because of conflicting properties ${property}`
215
- );
224
+ if (newObject.properties[property] !== undefined && errorOnOverlap) {
225
+ if (
226
+ !computeExtends(
227
+ newObject.properties[property].node,
228
+ operand.properties[property].node
229
+ )
230
+ ) {
231
+ throw new Error(
232
+ `Can't compute effective type for ${baseObjectName} and ${operandObjectName} because of conflicting properties ${property}`
233
+ );
234
+ }
216
235
  }
217
236
 
218
237
  newObject.properties[property] = operand.properties[property];