git.fiddlerwoaroof.com
Browse code

disable eslint, reformat

Ed Langley authored on 29/05/2019 07:15:53
Showing 3 changed files
... ...
@@ -1,10 +1,11 @@
1
+/* eslint-disable */
1 2
 
2 3
 window.devtoolsFormatters = [
3 4
     {
4 5
         header(obj, config) {
5 6
             if (config && config.genfunFormatter) {
6 7
                 return ["div", {}, config.key];
7
-            } else if (! (obj.gf || obj instanceof GenericFunction) ) {
8
+            } else if (!(obj.gf || obj instanceof GenericFunction)) {
8 9
                 return null;
9 10
             } else if (obj.gf) {
10 11
                 const args = obj.gf.lambda_list.join(', ');
... ...
@@ -12,7 +13,7 @@ window.devtoolsFormatters = [
12 13
                 return [
13 14
                     'div', {},
14 15
                     `GenericFunction lambda: ${obj.gf.name}(${args}) `
15
-                        + `[${method_count} methods]`
16
+                    + `[${method_count} methods]`
16 17
                 ];
17 18
             } else {
18 19
                 const args = obj.lambda_list.join(', ');
... ...
@@ -1,10 +1,10 @@
1
-export function NoNextMethodError() {}
1
+export function NoNextMethodError() { }
2 2
 NoNextMethodError.prototype = Object.create(Error);
3 3
 
4
-export function NoApplicableMethodError() {}
4
+export function NoApplicableMethodError() { }
5 5
 NoApplicableMethodError.prototype = Object.create(Error);
6 6
 
7
-export function NoPrimaryMethodError() {}
7
+export function NoPrimaryMethodError() { }
8 8
 NoPrimaryMethodError.prototype = Object.create(NoApplicableMethodError);
9 9
 
10 10
 const before_qualifier = Symbol.for('before');
... ...
@@ -33,19 +33,19 @@ let genfun_prototype = {
33 33
     },
34 34
     get fn() {
35 35
         const gf = this;
36
-        const lambda = (function() {
36
+        const lambda = (function () {
37 37
             return apply_generic_function(gf, [].slice.call(arguments));
38 38
         }).bind(gf);
39 39
         return Object.defineProperties(lambda, {
40
-            'name': {value: gf.name},
41
-            'lambda_list': {value: gf.lambda_list},
42
-            'gf': {value: gf},
40
+            'name': { value: gf.name },
41
+            'lambda_list': { value: gf.lambda_list },
42
+            'gf': { value: gf },
43 43
         });
44 44
     }
45 45
 };
46 46
 
47 47
 function GenericFunction(name, lambda_list) {
48
-    if (! (this instanceof GenericFunction) ) {
48
+    if (!(this instanceof GenericFunction)) {
49 49
         return new GenericFunction(...arguments);
50 50
     }
51 51
 
... ...
@@ -72,7 +72,7 @@ export function defgeneric(name, ...argument_names) {
72 72
 export function StandardMethod(
73 73
     lambda_list, qualifiers, specializers, body
74 74
 ) {
75
-    if (! (this instanceof StandardMethod) ) {
75
+    if (!(this instanceof StandardMethod)) {
76 76
         return new StandardMethod(...arguments);
77 77
     }
78 78
 
... ...
@@ -139,7 +139,7 @@ export function sub_specializer_p(c1, c2) {
139 139
 const idS = Symbol.for('id');
140 140
 Object.prototype[idS] = function () { return this };
141 141
 
142
-export function Specializer() {}
142
+export function Specializer() { }
143 143
 Specializer.prototype = {
144 144
     matches(_obj) { return false; },
145 145
     super_of(_obj) { return false; },
... ...
@@ -153,17 +153,17 @@ function isSuperset(superset, subset) {
153 153
 }
154 154
 
155 155
 const matchShape = defgeneric("matchShape", "shape", "value")
156
-      .primary([Array], ([name, dflt], v) => dflt!==undefined && v[name] === dflt)
157
-      .primary([String], (name, v) => v[name] !== undefined)
158
-      .fn;
156
+    .primary([Array], ([name, dflt], v) => dflt !== undefined && v[name] === dflt)
157
+    .primary([String], (name, v) => v[name] !== undefined)
158
+    .fn;
159 159
 
160 160
 export const extractKey = defgeneric("extractKey", "key")
161
-      .primary([Array], ([name, _]) => name)
162
-      .primary([String], (name) => name)
163
-      .fn;
161
+    .primary([Array], ([name, _]) => name)
162
+    .primary([String], (name) => name)
163
+    .fn;
164 164
 
165 165
 export function Shape(...keys) {
166
-    if (! (this instanceof Shape) ) {
166
+    if (!(this instanceof Shape)) {
167 167
         return new Shape(...keys);
168 168
     }
169 169
     this.keys = new Set(keys);
... ...
@@ -221,15 +221,15 @@ export function matches_specializer(obj, specializer) {
221 221
 function compute_applicable_methods_using_classes(gf, required_classes) {
222 222
     const applicable_methods = gf.methods.filter(
223 223
         method => method.specializers.every((specializer, idx) => matches_specializer(required_classes[idx], specializer))
224
-        
224
+
225 225
     );
226 226
 
227
-    applicable_methods.sort((a,b) => {
227
+    applicable_methods.sort((a, b) => {
228 228
         let result = 0;
229
-        if (method_more_specific_p(a,b)) {
229
+        if (method_more_specific_p(a, b)) {
230 230
             result = 1;
231 231
         }
232
-        if (method_more_specific_p(b,a)) {
232
+        if (method_more_specific_p(b, a)) {
233 233
             result = -1;
234 234
         }
235 235
 
... ...
@@ -271,13 +271,13 @@ function arr_eq(a1, a2) {
271 271
 // }
272 272
 
273 273
 const primary_method_p =
274
-      method => method instanceof WrappedMethod || method.qualifiers.length === 0;
274
+    method => method instanceof WrappedMethod || method.qualifiers.length === 0;
275 275
 const before_method_p =
276
-      method => !(method instanceof WrappedMethod) && arr_eq(method.qualifiers, [before_qualifier]);
276
+    method => !(method instanceof WrappedMethod) && arr_eq(method.qualifiers, [before_qualifier]);
277 277
 const after_method_p =
278
-      method => !(method instanceof WrappedMethod) && arr_eq(method.qualifiers, [after_qualifier]);
278
+    method => !(method instanceof WrappedMethod) && arr_eq(method.qualifiers, [after_qualifier]);
279 279
 const around_method_p =
280
-      method => !(method instanceof WrappedMethod) && arr_eq(method.qualifiers, [around_qualifier]);
280
+    method => !(method instanceof WrappedMethod) && arr_eq(method.qualifiers, [around_qualifier]);
281 281
 
282 282
 function WrappedMethod(continuation) {
283 283
     this.continuation = continuation;
... ...
@@ -291,7 +291,7 @@ function apply_methods(gf, args, applicable_methods) {
291 291
     afters.reverse();
292 292
 
293 293
     const main_call = Object.defineProperty(
294
-        function() {
294
+        function () {
295 295
             if (primaries.length === 0) {
296 296
                 throw new NoPrimaryMethodError(`No primary method for ${gf.name}`);
297 297
             }
... ...
@@ -308,7 +308,7 @@ function apply_methods(gf, args, applicable_methods) {
308 308
                 }
309 309
             }
310 310
         },
311
-        'name', {value: `main_call_${gf.name}`}, 
311
+        'name', { value: `main_call_${gf.name}` },
312 312
     );
313 313
 
314 314
     if (arounds.length === 0) {
... ...
@@ -14,21 +14,21 @@ describe('matches_specializer', () => {
14 14
         expect(uut.matches_specializer([], Object)).toBeTruthy();
15 15
         expect(uut.matches_specializer([], Number)).toBeFalsy();
16 16
 
17
-        function Foo() {}
17
+        function Foo() { }
18 18
         Foo.prototype = Object.create(null);
19 19
         const inst = new Foo();
20 20
         expect(uut.matches_specializer(inst, Foo)).toBeTruthy();
21 21
         expect(uut.matches_specializer(inst, Object)).toBeFalsy();
22 22
 
23
-        expect(uut.matches_specializer({a:1}, uut.Shape('a'))).toBeTruthy();
24
-        expect(uut.matches_specializer({a:1, b:2}, uut.Shape('a'))).toBeTruthy();
25
-        expect(uut.matches_specializer({b:2}, uut.Shape('a'))).toBeFalsy();
23
+        expect(uut.matches_specializer({ a: 1 }, uut.Shape('a'))).toBeTruthy();
24
+        expect(uut.matches_specializer({ a: 1, b: 2 }, uut.Shape('a'))).toBeTruthy();
25
+        expect(uut.matches_specializer({ b: 2 }, uut.Shape('a'))).toBeFalsy();
26 26
 
27
-        expect(uut.matches_specializer({a:1, b:2, c:3}, uut.Shape('a', 'b', 'c'))).toBeTruthy();
28
-        expect(uut.matches_specializer({a:1, b:2, c:3, d:4}, uut.Shape('a', 'b', 'c'))).toBeTruthy();
29
-        expect(uut.matches_specializer({a:1, c:3}, uut.Shape('a', 'b', 'c'))).toBeFalsy();
30
-        expect(uut.matches_specializer({c:3}, uut.Shape('a', 'b', 'c'))).toBeFalsy();
31
-        expect(uut.matches_specializer({d:3}, uut.Shape('a', 'b', 'c'))).toBeFalsy();
27
+        expect(uut.matches_specializer({ a: 1, b: 2, c: 3 }, uut.Shape('a', 'b', 'c'))).toBeTruthy();
28
+        expect(uut.matches_specializer({ a: 1, b: 2, c: 3, d: 4 }, uut.Shape('a', 'b', 'c'))).toBeTruthy();
29
+        expect(uut.matches_specializer({ a: 1, c: 3 }, uut.Shape('a', 'b', 'c'))).toBeFalsy();
30
+        expect(uut.matches_specializer({ c: 3 }, uut.Shape('a', 'b', 'c'))).toBeFalsy();
31
+        expect(uut.matches_specializer({ d: 3 }, uut.Shape('a', 'b', 'c'))).toBeFalsy();
32 32
     });
33 33
 
34 34
     test('null behavior', () => {
... ...
@@ -70,7 +70,7 @@ describe('defgeneric', () => {
70 70
         expect(
71 71
             uut.defgeneric("testing1", "a", "b")
72 72
                 .primary([Object, Object], (_, __) => 1)
73
-                .fn(1,2)
73
+                .fn(1, 2)
74 74
         ).toEqual(1);
75 75
 
76 76
         try {
... ...
@@ -85,14 +85,14 @@ describe('defgeneric', () => {
85 85
         expect(
86 86
             uut.defgeneric("testing1", "a", "b")
87 87
                 .primary([Number, Number], (_, __) => 1)
88
-                .fn(1,2)
88
+                .fn(1, 2)
89 89
         ).toEqual(1);
90 90
 
91 91
         expect(
92 92
             uut.defgeneric("testing1", "a", "b")
93 93
                 .primary([Number, Number], (_, __) => 2)
94 94
                 .primary([String, String], (_, __) => 1)
95
-                .fn("1","2")
95
+                .fn("1", "2")
96 96
         ).toEqual(1);
97 97
 
98 98
         let firstCounts = 0;
... ...
@@ -100,7 +100,7 @@ describe('defgeneric', () => {
100 100
             uut.defgeneric("testing1", "a", "b")
101 101
                 .primary([Number, Number], (_, __) => firstCounts += 1)
102 102
                 .primary([String, String], (_, __) => firstCounts += 1)
103
-                .fn("1","2")
103
+                .fn("1", "2")
104 104
         ).toEqual(1);
105 105
         expect(firstCounts).toEqual(1);
106 106
 
... ...
@@ -109,7 +109,7 @@ describe('defgeneric', () => {
109 109
             uut.defgeneric("testing1", "a", "b")
110 110
                 .primary([Object, Object], (_, __) => secondCounts += 1)
111 111
                 .primary([String, String], (_, __) => secondCounts += 1)
112
-                .fn("1","2")
112
+                .fn("1", "2")
113 113
         ).toEqual(1);
114 114
         expect(secondCounts).toEqual(1);
115 115
 
... ...
@@ -119,7 +119,7 @@ describe('defgeneric', () => {
119 119
                 .before([Object, Object], (_, __) => thirdCounts += 1)
120 120
                 .primary([String, String], (_, __) => 'hi')
121 121
                 .after([Object, String], (_, __) => thirdCounts += 1)
122
-                .fn("1","2")
122
+                .fn("1", "2")
123 123
         ).toEqual('hi');
124 124
         expect(thirdCounts).toEqual(2);
125 125
 
... ...
@@ -189,19 +189,19 @@ describe('defgeneric', () => {
189 189
                 })
190 190
                 .fn("foobar")
191 191
         ).toEqual(1);
192
-        
192
+
193 193
         expect(
194 194
             uut.defgeneric("foobar", "a", "b")
195
-                .primary ([String, String], function (a,b) {
195
+                .primary([String, String], function (a, b) {
196 196
                     return `1${this.call_next_method()}`;
197 197
                 })
198
-                .primary ([Object, String], function (a,b) {
198
+                .primary([Object, String], function (a, b) {
199 199
                     return `3${this.call_next_method()}`;
200 200
                 })
201
-                .primary ([String, Object], function (a,b) {
201
+                .primary([String, Object], function (a, b) {
202 202
                     return `2${this.call_next_method()}`;
203 203
                 })
204
-                .primary ([Object, Object], function (a,b) {
204
+                .primary([Object, Object], function (a, b) {
205 205
                     return `4`;
206 206
                 }).fn("a", "b")
207 207
         ).toEqual("1234");
... ...
@@ -223,33 +223,33 @@ describe('defgeneric', () => {
223 223
 describe('custom specializers', () => {
224 224
     test('Shape works', () => {
225 225
         expect(uut.defgeneric("foobar", "a")
226
-               .primary([uut.Shape('a', 'b')], ({a,b}) => a+b)
227
-               .primary([Object], _ => null)
228
-               .fn({a:1,b:2}))
226
+            .primary([uut.Shape('a', 'b')], ({ a, b }) => a + b)
227
+            .primary([Object], _ => null)
228
+            .fn({ a: 1, b: 2 }))
229 229
             .toEqual(3);
230 230
 
231 231
         expect(uut.defgeneric("foobar", "a")
232
-               .primary([uut.Shape('a', 'b')], ({a,b}) => a+b)
233
-               .primary([Object], _ => null)
234
-               .fn({a:1,b:2,c:3}))
232
+            .primary([uut.Shape('a', 'b')], ({ a, b }) => a + b)
233
+            .primary([Object], _ => null)
234
+            .fn({ a: 1, b: 2, c: 3 }))
235 235
             .toEqual(3);
236 236
 
237 237
         expect(uut.defgeneric("foobar", "a")
238
-               .primary([uut.Shape('a', 'b')], ({a,b}) => a+b)
239
-               .primary([Object], _ => null)
240
-               .fn({a:1}))
238
+            .primary([uut.Shape('a', 'b')], ({ a, b }) => a + b)
239
+            .primary([Object], _ => null)
240
+            .fn({ a: 1 }))
241 241
             .toEqual(null);
242 242
 
243 243
         expect(uut.defgeneric("foobar", "a")
244
-               .primary([uut.Shape(['a', 1], 'b')], ({a,b}) => a+b)
245
-               .primary([Object], _ => null)
246
-               .fn({a:1, b: 3}))
244
+            .primary([uut.Shape(['a', 1], 'b')], ({ a, b }) => a + b)
245
+            .primary([Object], _ => null)
246
+            .fn({ a: 1, b: 3 }))
247 247
             .toEqual(4);
248 248
 
249 249
         expect(uut.defgeneric("foobar", "a")
250
-               .primary([uut.Shape(['a', null], 'b')], ({a,b}) => b)
251
-               .primary([Object], _ => null)
252
-               .fn({a:null, b: 3}))
250
+            .primary([uut.Shape(['a', null], 'b')], ({ a, b }) => b)
251
+            .primary([Object], _ => null)
252
+            .fn({ a: null, b: 3 }))
253 253
             .toEqual(3);
254 254
 
255 255
         expect(uut.defgeneric("foobar", "a")
... ...
@@ -259,34 +259,34 @@ describe('custom specializers', () => {
259 259
             .toEqual(null); //undefined is not a permissible default: treated as if the key is missing
260 260
 
261 261
         expect(uut.defgeneric("foobar", "a")
262
-               .primary([uut.Shape(['a', 1], 'b')], ({a,b}) => a+b)
263
-               .primary([Object], _ => null)
264
-               .fn({a:2, b: 3}))
262
+            .primary([uut.Shape(['a', 1], 'b')], ({ a, b }) => a + b)
263
+            .primary([Object], _ => null)
264
+            .fn({ a: 2, b: 3 }))
265 265
             .toEqual(null);
266 266
     });
267 267
 
268 268
     test('Shape, prototype precedence', () => {
269 269
         expect(uut.defgeneric("foobar4", "a")
270
-               .primary([uut.Shape('a')], ({a}) => a)
271
-               .primary([uut.Shape('a', 'b')], ({a,b}) => {return a+b})
272
-               .primary([Object], _ => null).fn({a:1,b:3}))
270
+            .primary([uut.Shape('a')], ({ a }) => a)
271
+            .primary([uut.Shape('a', 'b')], ({ a, b }) => { return a + b })
272
+            .primary([Object], _ => null).fn({ a: 1, b: 3 }))
273 273
             .toEqual(4);
274 274
 
275 275
         expect(uut.defgeneric("foobar", "a")
276
-               .primary([uut.Shape('a', 'b')], ({a,b}) => a+b)
277
-               .primary([uut.Shape('b')], ({b}) => b)
278
-               .primary([Object], _ => null)
279
-               .fn({a:1,b:2}))
276
+            .primary([uut.Shape('a', 'b')], ({ a, b }) => a + b)
277
+            .primary([uut.Shape('b')], ({ b }) => b)
278
+            .primary([Object], _ => null)
279
+            .fn({ a: 1, b: 2 }))
280 280
             .toEqual(3);
281 281
 
282
-        const Foo = function () {}
283
-        Foo.prototype = {a: true, b: null};
282
+        const Foo = function () { }
283
+        Foo.prototype = { a: true, b: null };
284 284
         expect(uut.defgeneric("foobar", "a")
285
-               .primary([uut.Shape('a')], function ({a}) { return `a${this.call_next_method()}`; })
286
-               .primary([uut.Shape('a', 'b', 'c')], function ({a,b,c}) { return `c${this.call_next_method()}`; })
287
-               .primary([uut.Shape('a', 'b')], function ({a,b}) { return `b${this.call_next_method()}`; })
288
-               .primary([Object], _ => 'd')
289
-               .fn(Object.assign(new Foo(), {c: 3})))
285
+            .primary([uut.Shape('a')], function ({ a }) { return `a${this.call_next_method()}`; })
286
+            .primary([uut.Shape('a', 'b', 'c')], function ({ a, b, c }) { return `c${this.call_next_method()}`; })
287
+            .primary([uut.Shape('a', 'b')], function ({ a, b }) { return `b${this.call_next_method()}`; })
288
+            .primary([Object], _ => 'd')
289
+            .fn(Object.assign(new Foo(), { c: 3 })))
290 290
             .toEqual('cbad');
291 291
     });
292 292
 });