-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy paththallium-migrate.js
8918 lines (7498 loc) · 728 KB
/
thallium-migrate.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
"use strict"
module.exports = require("clean-assert")
},{"clean-assert":34}],2:[function(require,module,exports){
"use strict"
module.exports = require("./lib/dom")
},{"./lib/dom":12}],3:[function(require,module,exports){
"use strict"
/**
* Main entry point, for those wanting to use this framework with the core
* assertions.
*/
var Thallium = require("./lib/api/thallium")
module.exports = new Thallium()
},{"./lib/api/thallium":7}],4:[function(require,module,exports){
"use strict"
var Thallium = require("./lib/api/thallium")
var Reports = require("./lib/core/reports")
var HookStage = Reports.HookStage
exports.root = function () {
return new Thallium()
}
function d(duration) {
if (duration == null) return 10
if (typeof duration === "number") return duration|0
throw new TypeError("Expected `duration` to be a number if it exists")
}
function s(slow) {
if (slow == null) return 75
if (typeof slow === "number") return slow|0
throw new TypeError("Expected `slow` to be a number if it exists")
}
function p(path) {
if (Array.isArray(path)) return path
throw new TypeError("Expected `path` to be an array of locations")
}
function h(value) {
if (value != null && typeof value._ === "number") return value
throw new TypeError("Expected `value` to be a hook error")
}
/**
* Create a new report, mainly for testing reporters.
*/
exports.reports = {
start: function () {
return new Reports.Start()
},
enter: function (path, duration, slow) {
return new Reports.Enter(p(path), d(duration), s(slow))
},
leave: function (path) {
return new Reports.Leave(p(path))
},
pass: function (path, duration, slow) {
return new Reports.Pass(p(path), d(duration), s(slow))
},
fail: function (path, value, duration, slow, isFailable) { // eslint-disable-line max-params, max-len
return new Reports.Fail(
p(path), value, d(duration), s(slow),
!!isFailable)
},
skip: function (path) {
return new Reports.Skip(p(path))
},
end: function () {
return new Reports.End()
},
error: function (value) {
return new Reports.Error(value)
},
hook: function (path, rootPath, value) {
return new Reports.Hook(p(path), p(rootPath), h(value))
},
}
/**
* Create a new hook error, mainly for testing reporters.
*/
exports.hookErrors = {
beforeAll: function (func, value) {
return new Reports.HookError(HookStage.BeforeAll, func, value)
},
beforeEach: function (func, value) {
return new Reports.HookError(HookStage.BeforeEach, func, value)
},
afterEach: function (func, value) {
return new Reports.HookError(HookStage.AfterEach, func, value)
},
afterAll: function (func, value) {
return new Reports.HookError(HookStage.AfterAll, func, value)
},
}
/**
* Creates a new location, mainly for testing reporters.
*/
exports.location = function (name, index) {
if (typeof name !== "string") {
throw new TypeError("Expected `name` to be a string")
}
if (typeof index !== "number") {
throw new TypeError("Expected `index` to be a number")
}
return {name: name, index: index|0}
}
},{"./lib/api/thallium":7,"./lib/core/reports":10}],5:[function(require,module,exports){
"use strict"
var assert = require("../util").assert
exports.addHook = function (list, callback) {
assert(list == null || Array.isArray(list))
assert(typeof callback === "function")
if (list != null) {
list.push(callback)
return list
} else {
return [callback]
}
}
exports.removeHook = function (list, callback) {
assert(list == null || Array.isArray(list))
assert(typeof callback === "function")
if (list == null) return undefined
if (list.length === 1) {
if (list[0] === callback) return undefined
} else {
var index = list.indexOf(callback)
if (index >= 0) list.splice(index, 1)
}
return list
}
exports.hasHook = function (list, callback) {
assert(list == null || Array.isArray(list))
assert(typeof callback === "function")
if (list == null) return false
if (list.length > 1) return list.indexOf(callback) >= 0
return list[0] === callback
}
},{"../util":24}],6:[function(require,module,exports){
"use strict"
var assert = require("../util").assert
var methods = require("../methods")
var Tests = require("../core/tests")
var Common = require("./common")
/**
* This contains the low level, more arcane things that are generally not
* interesting to anyone other than plugin developers.
*/
module.exports = Reflect
function Reflect(test) {
assert(test != null && typeof test === "object")
var reflect = test.reflect
if (reflect != null) return reflect
test.reflect = this
this._ = test
}
methods(Reflect, {
/**
* Whether a reporter was registered.
*/
hasReporter: function (reporter) {
if (typeof reporter !== "function") {
throw new TypeError("Expected `reporter` to be a reporter")
}
return this._.root.reporters.indexOf(reporter) >= 0
},
/**
* Add a reporter.
*/
addReporter: function (reporter) {
if (typeof reporter !== "function") {
throw new TypeError("Expected `reporter` to be a function")
}
var root = this._.root
if (root.current !== root) {
throw new Error("Reporters may only be added to the root")
}
if (root.reporters.indexOf(reporter) < 0) root.reporters.push(reporter)
},
/**
* Remove a reporter.
*/
removeReporter: function (reporter) {
if (typeof reporter !== "function") {
throw new TypeError("Expected `reporter` to be a reporter")
}
var root = this._.root
if (root.current !== root) {
throw new Error("Reporters may only be added to the root")
}
var index = root.reporters.indexOf(reporter)
if (index >= 0) root.reporters.splice(index, 1)
},
/**
* Get the currently executing test.
*/
get current() {
return new Reflect(this._.root.current)
},
/**
* Get the root test.
*/
get root() {
return new Reflect(this._.root)
},
/**
* Get the current total test count.
*/
get count() {
return this._.tests == null ? 0 : this._.tests.length
},
/**
* Get a copy of the current test list, as a Reflect collection. This is
* intentionally a slice, so you can't mutate the real children.
*/
get children() {
var children = []
if (this._.tests != null) {
for (var i = 0; i < this._.tests.length; i++) {
children[i] = new Reflect(this._.tests[i])
}
}
return children
},
/**
* Is this test the root, i.e. top level?
*/
get isRoot() {
return this._.parent == null
},
/**
* Is this locked (i.e. unsafe to modify)?
*/
get isLocked() {
return !!this._.locked
},
/**
* Get the active timeout in milliseconds, not necessarily own, or the
* framework default of 2000, if none was set.
*/
get timeout() {
return this._.timeout || Tests.defaultTimeout
},
/**
* Get the active slow threshold in milliseconds, not necessarily own, or
* the framework default of 75, if none was set.
*/
get slow() {
return this._.slow || Tests.defaultSlow
},
/**
* Get the test's own max attempt count. Note that this is parasitically
* inherited from its parent, not delegated.
*/
get attempts() {
return this._.attempts
},
/**
* Get whether this test is failable. Note that this is parasitically
* inherited from its parent, not delegated.
*/
get isFailable() {
return this._.isFailable
},
/**
* Get the test name, or `undefined` if it's the root test.
*/
get name() {
if (this._.parent == null) return undefined
return this._.name
},
/**
* Get the test index, or `undefined` if it's the root test.
*/
get index() {
if (this._.parent == null) return undefined
return this._.index
},
/**
* Get the test's parent as a Reflect, or `undefined` if it's the root test.
*/
get parent() {
if (this._.parent == null) return undefined
return new Reflect(this._.parent)
},
/**
* Add a hook to be run before each subtest, including their subtests and so
* on.
*/
before: function (callback) {
if (typeof callback !== "function") {
throw new TypeError("Expected callback to be a function if passed")
}
this._.beforeEach = Common.addHook(this._.beforeEach, callback)
},
/**
* Add a hook to be run once before all subtests are run.
*/
beforeAll: function (callback) {
if (typeof callback !== "function") {
throw new TypeError("Expected callback to be a function if passed")
}
this._.beforeAll = Common.addHook(this._.beforeAll, callback)
},
/**
* Add a hook to be run after each subtest, including their subtests and so
* on.
*/
after: function (callback) {
if (typeof callback !== "function") {
throw new TypeError("Expected callback to be a function if passed")
}
this._.afterEach = Common.addHook(this._.afterEach, callback)
},
/**
* Add a hook to be run once after all subtests are run.
*/
afterAll: function (callback) {
if (typeof callback !== "function") {
throw new TypeError("Expected callback to be a function if passed")
}
this._.afterAll = Common.addHook(this._.afterAll, callback)
},
/**
* Remove a hook previously added with `t.before` or `reflect.before`.
*/
hasBefore: function (callback) {
if (typeof callback !== "function") {
throw new TypeError("Expected callback to be a function if passed")
}
return Common.hasHook(this._.beforeEach, callback)
},
/**
* Remove a hook previously added with `t.beforeAll` or `reflect.beforeAll`.
*/
hasBeforeAll: function (callback) {
if (typeof callback !== "function") {
throw new TypeError("Expected callback to be a function if passed")
}
return Common.hasHook(this._.beforeAll, callback)
},
/**
* Remove a hook previously added with `t.after` or`reflect.after`.
*/
hasAfter: function (callback) {
if (typeof callback !== "function") {
throw new TypeError("Expected callback to be a function if passed")
}
return Common.hasHook(this._.afterEach, callback)
},
/**
* Remove a hook previously added with `t.afterAll` or `reflect.afterAll`.
*/
hasAfterAll: function (callback) {
if (typeof callback !== "function") {
throw new TypeError("Expected callback to be a function if passed")
}
return Common.hasHook(this._.afterAll, callback)
},
/**
* Remove a hook previously added with `t.before` or `reflect.before`.
*/
removeBefore: function (callback) {
if (typeof callback !== "function") {
throw new TypeError("Expected callback to be a function if passed")
}
this._.beforeEach = Common.removeHook(this._.beforeEach, callback)
},
/**
* Remove a hook previously added with `t.beforeAll` or `reflect.beforeAll`.
*/
removeBeforeAll: function (callback) {
if (typeof callback !== "function") {
throw new TypeError("Expected callback to be a function if passed")
}
this._.beforeAll = Common.removeHook(this._.beforeAll, callback)
},
/**
* Remove a hook previously added with `t.after` or`reflect.after`.
*/
removeAfter: function (callback) {
if (typeof callback !== "function") {
throw new TypeError("Expected callback to be a function if passed")
}
this._.afterEach = Common.removeHook(this._.afterEach, callback)
},
/**
* Remove a hook previously added with `t.afterAll` or `reflect.afterAll`.
*/
removeAfterAll: function (callback) {
if (typeof callback !== "function") {
throw new TypeError("Expected callback to be a function if passed")
}
this._.afterAll = Common.removeHook(this._.afterAll, callback)
},
/**
* Add a block or inline test.
*/
test: function (name, callback) {
if (typeof name !== "string") {
throw new TypeError("Expected `name` to be a string")
}
if (typeof callback !== "function") {
throw new TypeError("Expected callback to be a function if passed")
}
Tests.addTest(this._.root.current, name, callback)
},
/**
* Skip the current test dynamically
*/
skip: function () {
if (this._.root.current === this._.root) {
throw new TypeError("This should only be called within tests.")
}
throw Tests.Skip
},
})
},{"../core/tests":11,"../methods":17,"../util":24,"./common":5}],7:[function(require,module,exports){
"use strict"
var methods = require("../methods")
var Util = require("../util")
var Tests = require("../core/tests")
var Filter = require("../core/filter")
var Reporters = require("../../r/index")
var Common = require("./common")
var Reflect = require("./reflect")
module.exports = Thallium
function Thallium() {
this._ = Tests.createRoot()
}
methods(Thallium, {
/**
* Get a Reflect instance directly.
*/
get reflect() {
return new Reflect(this._.root.current)
},
/**
* Call a plugin and return the result. The plugin is called with a Reflect
* instance for access to plenty of potentially useful internal details.
*/
call: function (plugin) {
if (typeof plugin !== "function") {
throw new TypeError("Expected `plugin` to be a function")
}
return plugin.call(this.reflect, this.reflect)
},
/**
* Whitelist specific tests, using array-based selectors where each entry
* is either a string or regular expression.
*/
set only(selectors) {
var root = this._.root
if (root.current !== root) {
throw new Error("Reporters may only be added to the root.")
}
Filter.validate(selectors)
root.only = Filter.create(selectors)
},
/**
* Add a reporter.
*/
set reporter(reporter) {
if (Array.isArray(reporter)
? typeof reporter[0] !== "string"
: typeof reporter !== "function"
) {
throw new TypeError(
"Expected `reporter` to be a `[string, opts?]` pair or a " +
"function.")
}
var root = this._.root
if (root.current !== root) {
throw new Error("Reporters may only be added to the root.")
}
if (typeof reporter === "function") {
root.reporter = reporter
} else {
var mod = Reporters[reporter]
if (mod == null) {
throw new TypeError("Built-in reporter " +
JSON.stringify(reporter) + " not found")
}
root.reporter = mod(reporter[1])
}
},
/**
* Check if this has a reporter.
*/
get hasReporter() {
return this._.root.reporter != null
},
/**
* Get the current file set.
*/
get files() {
return this._.files
},
/**
* Set the current file set.
*/
set files(files) {
var root = this._.root
if (root.current !== root) {
throw new Error("Files may only be set in the root.")
}
if (files == null) {
root.files = undefined
} else {
if (!Array.isArray(files)) {
throw new TypeError(
"Expected files to be an array if it exists, but found " +
"a(n) " + Util.getType(files))
}
for (var i = 0; i < files.length; i++) {
var glob = files[i]
if (typeof glob !== "string") {
throw new TypeError(
"Expected t.files[" + i + "] to be a string, but " +
"found a(n) " + Util.getType(glob))
}
}
root.files = files
}
},
/**
* Set the current file set.
*/
set options(opts) {
if (opts != null) {
if (typeof opts !== "object") {
throw new Error("Options must be an object if given.")
}
if (opts.only != null) Filter.validate(opts.only)
if (opts.skip != null) Filter.validate(opts.skip)
}
this._.options = opts
},
/**
* Get the current timeout. 0 means inherit the parent's, and `Infinity`
* means it's disabled.
*/
get timeout() {
return this._.root.current.timeout || Tests.defaultTimeout
},
/**
* Set the timeout in milliseconds, rounding negatives to 0. Setting the
* timeout to 0 means to inherit the parent timeout, and setting it to
* `Infinity` disables it.
*/
set timeout(timeout) {
this._.root.current.timeout = Math.floor(Math.max(+timeout, 0))
},
/**
* Get the current slow threshold. 0 means inherit the parent's, and
* `Infinity` means it's disabled.
*/
get slow() {
return this._.root.current.slow || Tests.defaultSlow
},
/**
* Set the slow threshold in milliseconds, rounding negatives to 0. Setting
* the timeout to 0 means to inherit the parent threshold, and setting it to
* `Infinity` disables it.
*/
set slow(slow) {
this._.root.current.slow = Math.floor(Math.max(+slow, 0))
},
/**
* Get the current attempt count. `0` means inherit the parent's.
*/
get attempts() {
return this._.root.current.attempts
},
/**
* Set the number of attempts allowed, rounding negatives to 0. Setting the
* count to `0` means to inherit the parent retry count.
*/
set attempts(attempts) {
// This is done differently to avoid a massive performance penalty.
var calculated = Math.floor(Math.max(attempts, 0))
var test = this._.root.current
test.attempts = calculated || test.parent.attempts
},
/**
* Get whether this test is failable.
*/
get isFailable() {
return this._.root.current.isFailable
},
/**
* Get whether this test is failable.
*/
set isFailable(isFailable) {
this._.root.current.isFailable = !!isFailable
},
/**
* Run the tests (or the test's tests if it's not a base instance).
*/
run: function (opts) {
var root = this._.root
if (root.current !== root) {
throw new Error(
"Only the root test can be run - If you only want to run a " +
"subtest, use `t.only = [[\"test\", ...]]` instead.")
}
if (root.locked) {
throw new Error("Can't run while tests are already running.")
}
if (opts != null) {
if (typeof opts !== "object") {
throw new Error("Options must be an object if given.")
}
if (opts.only != null) Filter.validate(opts.only)
if (opts.skip != null) Filter.validate(opts.skip)
}
var restore = root.reporter == null
if (restore) root.reporter = Reporters.spec()
return Tests.runTest(root, opts).then(
function (v) { if (restore) root.reporter = undefined; return v },
function (e) { if (restore) root.reporter = undefined; throw e }
)
},
/**
* Add a test.
*/
test: function (name, callback) {
if (typeof name !== "string") {
throw new TypeError("Expected `name` to be a string")
}
if (typeof callback !== "function") {
throw new TypeError("Expected callback to be a function if passed")
}
Tests.addTest(this._.root.current, name, callback)
},
/**
* Skip the current test dynamically
*/
skip: function () {
if (this._.root.current === this._.root) {
throw new TypeError("This should only be called within tests.")
}
throw Tests.Skip
},
/**
* Clear all existing tests.
*/
clearTests: function () {
if (this._.root !== this._) {
throw new Error("Tests may only be cleared at the root.")
}
if (this._.locked) {
throw new Error("Can't clear tests while they are running.")
}
Tests.clearTests(this._)
},
before: function (callback) {
if (typeof callback !== "function") {
throw new TypeError("Expected callback to be a function if passed")
}
var test = this._.root.current
test.beforeEach = Common.addHook(test.beforeEach, callback)
},
beforeAll: function (callback) {
if (typeof callback !== "function") {
throw new TypeError("Expected callback to be a function if passed")
}
var test = this._.root.current
test.beforeAll = Common.addHook(test.beforeAll, callback)
},
after: function (callback) {
if (typeof callback !== "function") {
throw new TypeError("Expected callback to be a function if passed")
}
var test = this._.root.current
test.afterEach = Common.addHook(test.afterEach, callback)
},
afterAll: function (callback) {
if (typeof callback !== "function") {
throw new TypeError("Expected callback to be a function if passed")
}
var test = this._.root.current
test.afterAll = Common.addHook(test.afterAll, callback)
},
})
},{"../../r/index":69,"../core/filter":9,"../core/tests":11,"../methods":17,"../util":24,"./common":5,"./reflect":6}],8:[function(require,module,exports){
(function (global){
"use strict"
/**
* This is the entry point for the Browserify bundle. Note that it *also* will
* run as part of the tests in Node (unbundled), and it theoretically could be
* run in Node or a runtime limited to only ES5 support (e.g. Rhino, Nashorn, or
* embedded V8), so do *not* assume browser globals are present.
*/
var t = require("../index")
var dom = require("../dom")
global.t = t
global.assert = require("../assert")
t.r = require("../r")
t.dom = dom
t.internal = require("../internal")
function autoload(script) {
if (!script.hasAttribute("data-files")) return
function set(opts, attr, transform) {
var value = script.getAttribute("data-" + attr)
if (value) opts[attr] = transform(value)
}
var files = script.getAttribute("data-files").trim()
var opts = {files: files ? files.split(/\s+/g) : []}
set(opts, "onready", Function)
set(opts, "timeout", Number)
set(opts, "preload", Function)
set(opts, "prerun", Function)
set(opts, "postrun", Function)
set(opts, "onerror", function (attr) {
return new Function("err", attr) // eslint-disable-line
})
if (global.document.readyState !== "loading") {
dom(opts).run()
} else {
global.document.addEventListener("DOMContentLoaded", function () {
dom(opts).run()
})
}
}
if (global.document != null && global.document.currentScript != null) {
autoload(global.document.currentScript)
}
// In case the user needs to adjust these (e.g. Nashorn + console output).
t.console = require("./replaced/console")
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
},{"../assert":1,"../dom":2,"../index":3,"../internal":4,"../r":69,"./replaced/console":18}],9:[function(require,module,exports){
"use strict"
var assert = require("../util").assert
/**
* The filter is actually stored as a tree for faster lookup times when there
* are multiple selectors. Objects can't be used for the nodes, where keys
* represent values and values represent children, because regular expressions
* aren't possible to use.
*/
function isEquivalent(entry, item) {
if (typeof entry === "string" && typeof item === "string") {
return entry === item
} else if (entry instanceof RegExp && item instanceof RegExp) {
return entry.toString() === item.toString()
} else {
return false
}
}
function matches(value, entry) {
if (typeof value === "string") {
return value === entry.name
} else {
return value.test(entry.name)
}
}
function Filter(value) {
assert(
value == null || typeof value === "string" || value instanceof RegExp
)
this.value = value
this.length = 0
}
function findEquivalent(node, entry) {
assert(node != null && typeof node === "object")
assert(typeof entry === "string" || entry instanceof RegExp)
for (var i = 0; i < node.length; i++) {
if (isEquivalent(node[i].value, entry)) return node[i]
}
return undefined
}
/**
* Validate a selector at the API level.
*/
exports.validate = function (list) {
for (var i = 0; i < list.length; i++) {
var selector = list[i]
if (!Array.isArray(selector)) {
throw new TypeError("Expected selector " + i + " to be an array")
}
for (var j = 0; j < selector.length; j++) {
// Strings and regular expressions are the only things allowed.
if (typeof selector[j] !== "string" &&
!(selector[j] instanceof RegExp)) {
throw new TypeError(
"Selector " + i + " may only consist of strings and " +
"regular expressions")
}
}
}
}
/**
* Create a filter from a list of selectors
*/
exports.create = function (list) {
assert(Array.isArray(list))
var filter = new Filter()
for (var i = 0; i < list.length; i++) {
var selector = list[i]
var node = filter
for (var j = 0; j < selector.length; j++) {
var entry = selector[j]
var child = findEquivalent(node, entry)
if (child == null) {
child = new Filter(entry)
node[node.length++] = child
}
node = child
}
}