1 | var Ap = Array.prototype;
|
2 | var slice = Ap.slice;
|
3 | var map = Ap.map;
|
4 | var each = Ap.forEach;
|
5 | var Op = Object.prototype;
|
6 | var objToStr = Op.toString;
|
7 | var funObjStr = objToStr.call(function(){});
|
8 | var strObjStr = objToStr.call("");
|
9 | var hasOwn = Op.hasOwnProperty;
|
10 |
|
11 |
|
12 |
|
13 |
|
14 | function Type(check, name) {
|
15 | var self = this;
|
16 | if (!(self instanceof Type)) {
|
17 | throw new Error("Type constructor cannot be invoked without 'new'");
|
18 | }
|
19 |
|
20 |
|
21 |
|
22 | if (objToStr.call(check) !== funObjStr) {
|
23 | throw new Error(check + " is not a function");
|
24 | }
|
25 |
|
26 |
|
27 | var nameObjStr = objToStr.call(name);
|
28 | if (!(nameObjStr === funObjStr ||
|
29 | nameObjStr === strObjStr)) {
|
30 | throw new Error(name + " is neither a function nor a string");
|
31 | }
|
32 |
|
33 | Object.defineProperties(self, {
|
34 | name: { value: name },
|
35 | check: {
|
36 | value: function(value, deep) {
|
37 | var result = check.call(self, value, deep);
|
38 | if (!result && deep && objToStr.call(deep) === funObjStr)
|
39 | deep(self, value);
|
40 | return result;
|
41 | }
|
42 | }
|
43 | });
|
44 | }
|
45 |
|
46 | var Tp = Type.prototype;
|
47 |
|
48 |
|
49 |
|
50 | exports.Type = Type;
|
51 |
|
52 |
|
53 | Tp.assert = function(value, deep) {
|
54 | if (!this.check(value, deep)) {
|
55 | var str = shallowStringify(value);
|
56 | throw new Error(str + " does not match type " + this);
|
57 | }
|
58 | return true;
|
59 | };
|
60 |
|
61 | function shallowStringify(value) {
|
62 | if (isObject.check(value))
|
63 | return "{" + Object.keys(value).map(function(key) {
|
64 | return key + ": " + value[key];
|
65 | }).join(", ") + "}";
|
66 |
|
67 | if (isArray.check(value))
|
68 | return "[" + value.map(shallowStringify).join(", ") + "]";
|
69 |
|
70 | return JSON.stringify(value);
|
71 | }
|
72 |
|
73 | Tp.toString = function() {
|
74 | var name = this.name;
|
75 |
|
76 | if (isString.check(name))
|
77 | return name;
|
78 |
|
79 | if (isFunction.check(name))
|
80 | return name.call(this) + "";
|
81 |
|
82 | return name + " type";
|
83 | };
|
84 |
|
85 | var builtInCtorFns = [];
|
86 | var builtInCtorTypes = [];
|
87 | var builtInTypes = {};
|
88 | exports.builtInTypes = builtInTypes;
|
89 |
|
90 | function defBuiltInType(example, name) {
|
91 | var objStr = objToStr.call(example);
|
92 |
|
93 | var type = new Type(function(value) {
|
94 | return objToStr.call(value) === objStr;
|
95 | }, name);
|
96 |
|
97 | builtInTypes[name] = type;
|
98 |
|
99 | if (example && typeof example.constructor === "function") {
|
100 | builtInCtorFns.push(example.constructor);
|
101 | builtInCtorTypes.push(type);
|
102 | }
|
103 |
|
104 | return type;
|
105 | }
|
106 |
|
107 |
|
108 |
|
109 |
|
110 |
|
111 | var isString = defBuiltInType("truthy", "string");
|
112 | var isFunction = defBuiltInType(function(){}, "function");
|
113 | var isArray = defBuiltInType([], "array");
|
114 | var isObject = defBuiltInType({}, "object");
|
115 | var isRegExp = defBuiltInType(/./, "RegExp");
|
116 | var isDate = defBuiltInType(new Date, "Date");
|
117 | var isNumber = defBuiltInType(3, "number");
|
118 | var isBoolean = defBuiltInType(true, "boolean");
|
119 | var isNull = defBuiltInType(null, "null");
|
120 | var isUndefined = defBuiltInType(void 0, "undefined");
|
121 |
|
122 |
|
123 |
|
124 |
|
125 | function toType(from, name) {
|
126 |
|
127 | if (from instanceof Type)
|
128 | return from;
|
129 |
|
130 |
|
131 |
|
132 | if (from instanceof Def)
|
133 | return from.type;
|
134 |
|
135 |
|
136 | if (isArray.check(from))
|
137 | return Type.fromArray(from);
|
138 |
|
139 |
|
140 | if (isObject.check(from))
|
141 | return Type.fromObject(from);
|
142 |
|
143 | if (isFunction.check(from)) {
|
144 | var bicfIndex = builtInCtorFns.indexOf(from);
|
145 | if (bicfIndex >= 0) {
|
146 | return builtInCtorTypes[bicfIndex];
|
147 | }
|
148 |
|
149 |
|
150 |
|
151 |
|
152 | return new Type(from, name);
|
153 | }
|
154 |
|
155 |
|
156 |
|
157 |
|
158 |
|
159 | return new Type(function(value) {
|
160 | return value === from;
|
161 | }, isUndefined.check(name) ? function() {
|
162 | return from + "";
|
163 | } : name);
|
164 | }
|
165 |
|
166 |
|
167 |
|
168 | Type.or = function(/* type1, type2, ... */) {
|
169 | var types = [];
|
170 | var len = arguments.length;
|
171 | for (var i = 0; i < len; ++i)
|
172 | types.push(toType(arguments[i]));
|
173 |
|
174 | return new Type(function(value, deep) {
|
175 | for (var i = 0; i < len; ++i)
|
176 | if (types[i].check(value, deep))
|
177 | return true;
|
178 | return false;
|
179 | }, function() {
|
180 | return types.join(" | ");
|
181 | });
|
182 | };
|
183 |
|
184 | Type.fromArray = function(arr) {
|
185 | if (!isArray.check(arr)) {
|
186 | throw new Error("");
|
187 | }
|
188 | if (arr.length !== 1) {
|
189 | throw new Error("only one element type is permitted for typed arrays");
|
190 | }
|
191 | return toType(arr[0]).arrayOf();
|
192 | };
|
193 |
|
194 | Tp.arrayOf = function() {
|
195 | var elemType = this;
|
196 | return new Type(function(value, deep) {
|
197 | return isArray.check(value) && value.every(function(elem) {
|
198 | return elemType.check(elem, deep);
|
199 | });
|
200 | }, function() {
|
201 | return "[" + elemType + "]";
|
202 | });
|
203 | };
|
204 |
|
205 | Type.fromObject = function(obj) {
|
206 | var fields = Object.keys(obj).map(function(name) {
|
207 | return new Field(name, obj[name]);
|
208 | });
|
209 |
|
210 | return new Type(function(value, deep) {
|
211 | return isObject.check(value) && fields.every(function(field) {
|
212 | return field.type.check(value[field.name], deep);
|
213 | });
|
214 | }, function() {
|
215 | return "{ " + fields.join(", ") + " }";
|
216 | });
|
217 | };
|
218 |
|
219 | function Field(name, type, defaultFn, hidden) {
|
220 | var self = this;
|
221 |
|
222 | if (!(self instanceof Field)) {
|
223 | throw new Error("Field constructor cannot be invoked without 'new'");
|
224 | }
|
225 | isString.assert(name);
|
226 |
|
227 | type = toType(type);
|
228 |
|
229 | var properties = {
|
230 | name: { value: name },
|
231 | type: { value: type },
|
232 | hidden: { value: !!hidden }
|
233 | };
|
234 |
|
235 | if (isFunction.check(defaultFn)) {
|
236 | properties.defaultFn = { value: defaultFn };
|
237 | }
|
238 |
|
239 | Object.defineProperties(self, properties);
|
240 | }
|
241 |
|
242 | var Fp = Field.prototype;
|
243 |
|
244 | Fp.toString = function() {
|
245 | return JSON.stringify(this.name) + ": " + this.type;
|
246 | };
|
247 |
|
248 | Fp.getValue = function(obj) {
|
249 | var value = obj[this.name];
|
250 |
|
251 | if (!isUndefined.check(value))
|
252 | return value;
|
253 |
|
254 | if (this.defaultFn)
|
255 | value = this.defaultFn.call(obj);
|
256 |
|
257 | return value;
|
258 | };
|
259 |
|
260 |
|
261 |
|
262 |
|
263 |
|
264 |
|
265 | Type.def = function(typeName) {
|
266 | isString.assert(typeName);
|
267 | return hasOwn.call(defCache, typeName)
|
268 | ? defCache[typeName]
|
269 | : defCache[typeName] = new Def(typeName);
|
270 | };
|
271 |
|
272 |
|
273 |
|
274 | var defCache = Object.create(null);
|
275 |
|
276 | function Def(typeName) {
|
277 | var self = this;
|
278 | if (!(self instanceof Def)) {
|
279 | throw new Error("Def constructor cannot be invoked without 'new'");
|
280 | }
|
281 |
|
282 | Object.defineProperties(self, {
|
283 | typeName: { value: typeName },
|
284 | baseNames: { value: [] },
|
285 | ownFields: { value: Object.create(null) },
|
286 |
|
287 |
|
288 | allSupertypes: { value: Object.create(null) },
|
289 | supertypeList: { value: [] },
|
290 | allFields: { value: Object.create(null) },
|
291 | fieldNames: { value: [] },
|
292 |
|
293 | type: {
|
294 | value: new Type(function(value, deep) {
|
295 | return self.check(value, deep);
|
296 | }, typeName)
|
297 | }
|
298 | });
|
299 | }
|
300 |
|
301 | Def.fromValue = function(value) {
|
302 | if (value && typeof value === "object") {
|
303 | var type = value.type;
|
304 | if (typeof type === "string" &&
|
305 | hasOwn.call(defCache, type)) {
|
306 | var d = defCache[type];
|
307 | if (d.finalized) {
|
308 | return d;
|
309 | }
|
310 | }
|
311 | }
|
312 |
|
313 | return null;
|
314 | };
|
315 |
|
316 | var Dp = Def.prototype;
|
317 |
|
318 | Dp.isSupertypeOf = function(that) {
|
319 | if (that instanceof Def) {
|
320 | if (this.finalized !== true ||
|
321 | that.finalized !== true) {
|
322 | throw new Error("");
|
323 | }
|
324 | return hasOwn.call(that.allSupertypes, this.typeName);
|
325 | } else {
|
326 | throw new Error(that + " is not a Def");
|
327 | }
|
328 | };
|
329 |
|
330 |
|
331 |
|
332 | exports.getSupertypeNames = function(typeName) {
|
333 | if (!hasOwn.call(defCache, typeName)) {
|
334 | throw new Error("");
|
335 | }
|
336 | var d = defCache[typeName];
|
337 | if (d.finalized !== true) {
|
338 | throw new Error("");
|
339 | }
|
340 | return d.supertypeList.slice(1);
|
341 | };
|
342 |
|
343 |
|
344 |
|
345 |
|
346 | exports.computeSupertypeLookupTable = function(candidates) {
|
347 | var table = {};
|
348 | var typeNames = Object.keys(defCache);
|
349 | var typeNameCount = typeNames.length;
|
350 |
|
351 | for (var i = 0; i < typeNameCount; ++i) {
|
352 | var typeName = typeNames[i];
|
353 | var d = defCache[typeName];
|
354 | if (d.finalized !== true) {
|
355 | throw new Error("" + typeName);
|
356 | }
|
357 | for (var j = 0; j < d.supertypeList.length; ++j) {
|
358 | var superTypeName = d.supertypeList[j];
|
359 | if (hasOwn.call(candidates, superTypeName)) {
|
360 | table[typeName] = superTypeName;
|
361 | break;
|
362 | }
|
363 | }
|
364 | }
|
365 |
|
366 | return table;
|
367 | };
|
368 |
|
369 | Dp.checkAllFields = function(value, deep) {
|
370 | var allFields = this.allFields;
|
371 | if (this.finalized !== true) {
|
372 | throw new Error("" + this.typeName);
|
373 | }
|
374 |
|
375 | function checkFieldByName(name) {
|
376 | var field = allFields[name];
|
377 | var type = field.type;
|
378 | var child = field.getValue(value);
|
379 | return type.check(child, deep);
|
380 | }
|
381 |
|
382 | return isObject.check(value)
|
383 | && Object.keys(allFields).every(checkFieldByName);
|
384 | };
|
385 |
|
386 | Dp.check = function(value, deep) {
|
387 | if (this.finalized !== true) {
|
388 | throw new Error(
|
389 | "prematurely checking unfinalized type " + this.typeName
|
390 | );
|
391 | }
|
392 |
|
393 |
|
394 | if (!isObject.check(value))
|
395 | return false;
|
396 |
|
397 | var vDef = Def.fromValue(value);
|
398 | if (!vDef) {
|
399 |
|
400 |
|
401 |
|
402 |
|
403 |
|
404 | if (this.typeName === "SourceLocation" ||
|
405 | this.typeName === "Position") {
|
406 | return this.checkAllFields(value, deep);
|
407 | }
|
408 |
|
409 |
|
410 |
|
411 | return false;
|
412 | }
|
413 |
|
414 |
|
415 |
|
416 |
|
417 | if (deep && vDef === this)
|
418 | return this.checkAllFields(value, deep);
|
419 |
|
420 |
|
421 |
|
422 |
|
423 |
|
424 | if (!this.isSupertypeOf(vDef))
|
425 | return false;
|
426 |
|
427 |
|
428 |
|
429 | if (!deep)
|
430 | return true;
|
431 |
|
432 |
|
433 |
|
434 | return vDef.checkAllFields(value, deep)
|
435 | && this.checkAllFields(value, false);
|
436 | };
|
437 |
|
438 | Dp.bases = function() {
|
439 | var args = slice.call(arguments);
|
440 | var bases = this.baseNames;
|
441 |
|
442 | if (this.finalized) {
|
443 | if (args.length !== bases.length) {
|
444 | throw new Error("");
|
445 | }
|
446 | for (var i = 0; i < args.length; i++) {
|
447 | if (args[i] !== bases[i]) {
|
448 | throw new Error("");
|
449 | }
|
450 | }
|
451 | return this;
|
452 | }
|
453 |
|
454 | args.forEach(function(baseName) {
|
455 | isString.assert(baseName);
|
456 |
|
457 |
|
458 |
|
459 | if (bases.indexOf(baseName) < 0)
|
460 | bases.push(baseName);
|
461 | });
|
462 |
|
463 | return this;
|
464 | };
|
465 |
|
466 |
|
467 | Object.defineProperty(Dp, "buildable", { value: false });
|
468 |
|
469 | var builders = {};
|
470 | exports.builders = builders;
|
471 |
|
472 |
|
473 | var nodePrototype = {};
|
474 |
|
475 |
|
476 |
|
477 | exports.defineMethod = function(name, func) {
|
478 | var old = nodePrototype[name];
|
479 |
|
480 |
|
481 | if (isUndefined.check(func)) {
|
482 | delete nodePrototype[name];
|
483 |
|
484 | } else {
|
485 | isFunction.assert(func);
|
486 |
|
487 | Object.defineProperty(nodePrototype, name, {
|
488 | enumerable: true,
|
489 | configurable: true,
|
490 | value: func
|
491 | });
|
492 | }
|
493 |
|
494 | return old;
|
495 | };
|
496 |
|
497 | var isArrayOfString = isString.arrayOf();
|
498 |
|
499 |
|
500 |
|
501 |
|
502 |
|
503 | Dp.build = function(/* param1, param2, ... */) {
|
504 | var self = this;
|
505 |
|
506 | var newBuildParams = slice.call(arguments);
|
507 | isArrayOfString.assert(newBuildParams);
|
508 |
|
509 |
|
510 |
|
511 | Object.defineProperty(self, "buildParams", {
|
512 | value: newBuildParams,
|
513 | writable: false,
|
514 | enumerable: false,
|
515 | configurable: true
|
516 | });
|
517 |
|
518 | if (self.buildable) {
|
519 |
|
520 |
|
521 | return self;
|
522 | }
|
523 |
|
524 |
|
525 |
|
526 |
|
527 | self.field("type", String, function() { return self.typeName });
|
528 |
|
529 |
|
530 | Object.defineProperty(self, "buildable", { value: true });
|
531 |
|
532 | Object.defineProperty(builders, getBuilderName(self.typeName), {
|
533 | enumerable: true,
|
534 |
|
535 | value: function() {
|
536 | var args = arguments;
|
537 | var argc = args.length;
|
538 | var built = Object.create(nodePrototype);
|
539 |
|
540 | if (!self.finalized) {
|
541 | throw new Error(
|
542 | "attempting to instantiate unfinalized type " +
|
543 | self.typeName
|
544 | );
|
545 | }
|
546 |
|
547 | function add(param, i) {
|
548 | if (hasOwn.call(built, param))
|
549 | return;
|
550 |
|
551 | var all = self.allFields;
|
552 | if (!hasOwn.call(all, param)) {
|
553 | throw new Error("" + param);
|
554 | }
|
555 |
|
556 | var field = all[param];
|
557 | var type = field.type;
|
558 | var value;
|
559 |
|
560 | if (isNumber.check(i) && i < argc) {
|
561 | value = args[i];
|
562 | } else if (field.defaultFn) {
|
563 |
|
564 |
|
565 | value = field.defaultFn.call(built);
|
566 | } else {
|
567 | var message = "no value or default function given for field " +
|
568 | JSON.stringify(param) + " of " + self.typeName + "(" +
|
569 | self.buildParams.map(function(name) {
|
570 | return all[name];
|
571 | }).join(", ") + ")";
|
572 | throw new Error(message);
|
573 | }
|
574 |
|
575 | if (!type.check(value)) {
|
576 | throw new Error(
|
577 | shallowStringify(value) +
|
578 | " does not match field " + field +
|
579 | " of type " + self.typeName
|
580 | );
|
581 | }
|
582 |
|
583 |
|
584 |
|
585 | built[param] = value;
|
586 | }
|
587 |
|
588 | self.buildParams.forEach(function(param, i) {
|
589 | add(param, i);
|
590 | });
|
591 |
|
592 | Object.keys(self.allFields).forEach(function(param) {
|
593 | add(param);
|
594 | });
|
595 |
|
596 |
|
597 | if (built.type !== self.typeName) {
|
598 | throw new Error("");
|
599 | }
|
600 |
|
601 | return built;
|
602 | }
|
603 | });
|
604 |
|
605 | return self;
|
606 | };
|
607 |
|
608 | function getBuilderName(typeName) {
|
609 | return typeName.replace(/^[A-Z]+/, function(upperCasePrefix) {
|
610 | var len = upperCasePrefix.length;
|
611 | switch (len) {
|
612 | case 0: return "";
|
613 |
|
614 | case 1: return upperCasePrefix.toLowerCase();
|
615 | default:
|
616 |
|
617 |
|
618 |
|
619 | return upperCasePrefix.slice(
|
620 | 0, len - 1).toLowerCase() +
|
621 | upperCasePrefix.charAt(len - 1);
|
622 | }
|
623 | });
|
624 | }
|
625 | exports.getBuilderName = getBuilderName;
|
626 |
|
627 | function getStatementBuilderName(typeName) {
|
628 | typeName = getBuilderName(typeName);
|
629 | return typeName.replace(/(Expression)?$/, "Statement");
|
630 | }
|
631 | exports.getStatementBuilderName = getStatementBuilderName;
|
632 |
|
633 |
|
634 |
|
635 |
|
636 |
|
637 | Dp.field = function(name, type, defaultFn, hidden) {
|
638 | if (this.finalized) {
|
639 | console.error("Ignoring attempt to redefine field " +
|
640 | JSON.stringify(name) + " of finalized type " +
|
641 | JSON.stringify(this.typeName));
|
642 | return this;
|
643 | }
|
644 | this.ownFields[name] = new Field(name, type, defaultFn, hidden);
|
645 | return this;
|
646 | };
|
647 |
|
648 | var namedTypes = {};
|
649 | exports.namedTypes = namedTypes;
|
650 |
|
651 |
|
652 | function getFieldNames(object) {
|
653 | var d = Def.fromValue(object);
|
654 | if (d) {
|
655 | return d.fieldNames.slice(0);
|
656 | }
|
657 |
|
658 | if ("type" in object) {
|
659 | throw new Error(
|
660 | "did not recognize object of type " +
|
661 | JSON.stringify(object.type)
|
662 | );
|
663 | }
|
664 |
|
665 | return Object.keys(object);
|
666 | }
|
667 | exports.getFieldNames = getFieldNames;
|
668 |
|
669 |
|
670 |
|
671 | function getFieldValue(object, fieldName) {
|
672 | var d = Def.fromValue(object);
|
673 | if (d) {
|
674 | var field = d.allFields[fieldName];
|
675 | if (field) {
|
676 | return field.getValue(object);
|
677 | }
|
678 | }
|
679 |
|
680 | return object[fieldName];
|
681 | }
|
682 | exports.getFieldValue = getFieldValue;
|
683 |
|
684 |
|
685 |
|
686 |
|
687 |
|
688 | exports.eachField = function(object, callback, context) {
|
689 | getFieldNames(object).forEach(function(name) {
|
690 | callback.call(this, name, getFieldValue(object, name));
|
691 | }, context);
|
692 | };
|
693 |
|
694 |
|
695 |
|
696 |
|
697 |
|
698 | exports.someField = function(object, callback, context) {
|
699 | return getFieldNames(object).some(function(name) {
|
700 | return callback.call(this, name, getFieldValue(object, name));
|
701 | }, context);
|
702 | };
|
703 |
|
704 |
|
705 |
|
706 | Object.defineProperty(Dp, "finalized", { value: false });
|
707 |
|
708 | Dp.finalize = function() {
|
709 | var self = this;
|
710 |
|
711 |
|
712 |
|
713 | if (!self.finalized) {
|
714 | var allFields = self.allFields;
|
715 | var allSupertypes = self.allSupertypes;
|
716 |
|
717 | self.baseNames.forEach(function(name) {
|
718 | var def = defCache[name];
|
719 | if (def instanceof Def) {
|
720 | def.finalize();
|
721 | extend(allFields, def.allFields);
|
722 | extend(allSupertypes, def.allSupertypes);
|
723 | } else {
|
724 | var message = "unknown supertype name " +
|
725 | JSON.stringify(name) +
|
726 | " for subtype " +
|
727 | JSON.stringify(self.typeName);
|
728 | throw new Error(message);
|
729 | }
|
730 | });
|
731 |
|
732 |
|
733 | extend(allFields, self.ownFields);
|
734 | allSupertypes[self.typeName] = self;
|
735 |
|
736 | self.fieldNames.length = 0;
|
737 | for (var fieldName in allFields) {
|
738 | if (hasOwn.call(allFields, fieldName) &&
|
739 | !allFields[fieldName].hidden) {
|
740 | self.fieldNames.push(fieldName);
|
741 | }
|
742 | }
|
743 |
|
744 |
|
745 | Object.defineProperty(namedTypes, self.typeName, {
|
746 | enumerable: true,
|
747 | value: self.type
|
748 | });
|
749 |
|
750 | Object.defineProperty(self, "finalized", { value: true });
|
751 |
|
752 |
|
753 | populateSupertypeList(self.typeName, self.supertypeList);
|
754 |
|
755 | if (self.buildable && self.supertypeList.lastIndexOf("Expression") >= 0) {
|
756 | wrapExpressionBuilderWithStatement(self.typeName);
|
757 | }
|
758 | }
|
759 | };
|
760 |
|
761 |
|
762 |
|
763 | function wrapExpressionBuilderWithStatement(typeName) {
|
764 | var wrapperName = getStatementBuilderName(typeName);
|
765 |
|
766 |
|
767 | if (builders[wrapperName]) return;
|
768 |
|
769 |
|
770 | var wrapped = builders[getBuilderName(typeName)];
|
771 |
|
772 |
|
773 | if (!wrapped) return;
|
774 |
|
775 | builders[wrapperName] = function() {
|
776 | return builders.expressionStatement(wrapped.apply(builders, arguments));
|
777 | };
|
778 | }
|
779 |
|
780 | function populateSupertypeList(typeName, list) {
|
781 | list.length = 0;
|
782 | list.push(typeName);
|
783 |
|
784 | var lastSeen = Object.create(null);
|
785 |
|
786 | for (var pos = 0; pos < list.length; ++pos) {
|
787 | typeName = list[pos];
|
788 | var d = defCache[typeName];
|
789 | if (d.finalized !== true) {
|
790 | throw new Error("");
|
791 | }
|
792 |
|
793 |
|
794 |
|
795 | if (hasOwn.call(lastSeen, typeName)) {
|
796 | delete list[lastSeen[typeName]];
|
797 | }
|
798 |
|
799 |
|
800 | lastSeen[typeName] = pos;
|
801 |
|
802 |
|
803 | list.push.apply(list, d.baseNames);
|
804 | }
|
805 |
|
806 |
|
807 | for (var to = 0, from = to, len = list.length; from < len; ++from) {
|
808 | if (hasOwn.call(list, from)) {
|
809 | list[to++] = list[from];
|
810 | }
|
811 | }
|
812 |
|
813 | list.length = to;
|
814 | }
|
815 |
|
816 | function extend(into, from) {
|
817 | Object.keys(from).forEach(function(name) {
|
818 | into[name] = from[name];
|
819 | });
|
820 |
|
821 | return into;
|
822 | };
|
823 |
|
824 | exports.finalize = function() {
|
825 | Object.keys(defCache).forEach(function(name) {
|
826 | defCache[name].finalize();
|
827 | });
|
828 | };
|