|
2 | 2 | 'use strict'; |
3 | 3 | var _undefined; |
4 | 4 |
|
5 | | - var var1 = 'roperties'; |
6 | | - var var2 = 'ropertyDescriptors'; |
7 | | - var var3 = 'static'; |
8 | | - var var4 = 'onfiguration'; |
9 | | - var _properties = 'p' + var1; |
10 | | - var _deepProperties = 'deepP' + var1; |
11 | | - var _propertyDescriptors = 'p' + var2; |
12 | | - var _staticProperties = var3 + 'P' + var1; |
13 | | - var _staticDeepProperties = var3 + 'DeepP' + var1; |
14 | | - var _staticPropertyDescriptors = var3 + 'P' + var2; |
15 | | - var _configuration = 'c' + var4; |
16 | | - var _deepConfiguration = 'deepC' + var4; |
| 5 | + var var1, var2, var3; |
| 6 | + var _properties = 'properties'; |
| 7 | + var _deepProperties = 'deepProperties'; |
| 8 | + var _propertyDescriptors = 'propertyDescriptors'; |
| 9 | + var _staticProperties = 'staticProperties'; |
| 10 | + var _staticDeepProperties = 'staticDeepProperties'; |
| 11 | + var _staticPropertyDescriptors = 'staticPropertyDescriptors'; |
| 12 | + var _configuration = 'configuration'; |
| 13 | + var _deepConfiguration = 'deepConfiguration'; |
17 | 14 | var _deepProps = 'deepProps'; |
18 | 15 | var _deepStatics = 'deepStatics'; |
19 | 16 | var _deepConf = 'deepConf'; |
20 | 17 | var _initializers = 'initializers'; |
21 | 18 | var _methods = 'methods'; |
22 | 19 | var _composers = 'composers'; |
23 | 20 | var _compose = 'compose'; |
24 | | - var _object = 'object'; |
25 | | - var _length = 'length'; |
26 | | - var _create = 'create'; |
27 | | - var _Object = Object; |
28 | | - var isArray = Array.isArray; |
29 | | - var defineProperties = _Object.defineProperties; |
30 | | - var defineProperty = _Object.defineProperty; |
31 | | - var getOwnPropertyDescriptor = _Object.getOwnPropertyDescriptor; |
32 | | - var getOwnPropertySymbols = _Object.getOwnPropertySymbols; |
33 | | - var baseStampit = Array.prototype; // temporary reusing the variable |
34 | | - var concat = baseStampit.concat; |
35 | | - var slice = baseStampit.slice; |
| 21 | + var baseStampit; |
36 | 22 |
|
37 | 23 | function getOwnPropertyKeys(obj) { |
38 | | - return _Object.getOwnPropertyNames(obj).concat(getOwnPropertySymbols ? getOwnPropertySymbols(obj) : []); |
| 24 | + return Object.getOwnPropertyNames(obj).concat(Object.getOwnPropertySymbols ? Object.getOwnPropertySymbols(obj) : []); |
39 | 25 | } |
40 | 26 |
|
41 | 27 | function _mergeOrAssign(action, dst) { |
42 | | - return slice.call(arguments, 2).reduce(action, dst); |
| 28 | + return Array.prototype.slice.call(arguments, 2).reduce(action, dst); |
43 | 29 | } |
44 | 30 |
|
45 | 31 | function assignOne(dst, src) { |
46 | 32 | if (src) { |
47 | 33 | // We need to copy regular props, symbols, getters and setters. |
48 | 34 | var keys = getOwnPropertyKeys(src), i = 0, desc; |
49 | 35 | for (; i < keys.length; i += 1) { |
50 | | - desc = getOwnPropertyDescriptor(src, keys[i]); |
| 36 | + desc = Object.getOwnPropertyDescriptor(src, keys[i]); |
51 | 37 | // Make it rewritable because two stamps can have same named getter/setter |
52 | | - defineProperty(dst, keys[i], desc); |
| 38 | + Object.defineProperty(dst, keys[i], desc); |
53 | 39 | } |
54 | 40 | } |
55 | 41 | return dst; |
|
62 | 48 | } |
63 | 49 |
|
64 | 50 | function isObject(obj) { |
65 | | - return obj && typeof obj == _object || isFunction(obj); |
| 51 | + return obj && typeof obj == 'object' || isFunction(obj); |
66 | 52 | } |
67 | 53 |
|
68 | 54 | function isPlainObject(value) { |
69 | | - return value && typeof value == _object && |
70 | | - value.__proto__ == _Object.prototype; |
| 55 | + return value && typeof value == 'object' && |
| 56 | + value.__proto__ == Object.prototype; |
71 | 57 | } |
72 | 58 |
|
73 | 59 | /** |
|
82 | 68 |
|
83 | 69 | // According to specification arrays must be concatenated. |
84 | 70 | // Also, the '.concat' creates a new array instance. Overrides the 'dst'. |
85 | | - if (isArray(src)) return (isArray(dst) ? dst : []).concat(src); |
| 71 | + if (Array.isArray(src)) return (Array.isArray(dst) ? dst : []).concat(src); |
86 | 72 |
|
87 | 73 | // Now deal with non plain 'src' object. 'src' overrides 'dst' |
88 | 74 | // Note that functions are also assigned! We do not deep merge functions. |
89 | 75 | if (!isPlainObject(src)) return src; |
90 | 76 |
|
91 | 77 | var keys = getOwnPropertyKeys(src), i = 0, key, desc; |
92 | | - for (; i < keys[_length];) { |
| 78 | + for (; i < keys.length;) { |
93 | 79 | key = keys[i++]; |
94 | | - desc = getOwnPropertyDescriptor(src, key); |
| 80 | + desc = Object.getOwnPropertyDescriptor(src, key); |
95 | 81 | if (desc.hasOwnProperty('value')) { // is this a regular property? |
96 | 82 | // Do not merge properties with the 'undefined' value. |
97 | 83 | if (desc.value !== _undefined) { |
98 | 84 | // deep merge each property. Recursion! |
99 | | - dst[key] = mergeOne(isPlainObject(dst[key]) || isArray(src[key]) ? dst[key] : {}, src[key]); |
| 85 | + dst[key] = mergeOne(isPlainObject(dst[key]) || Array.isArray(src[key]) ? dst[key] : {}, src[key]); |
100 | 86 | } |
101 | 87 | } else { // nope, it looks like a getter/setter |
102 | 88 | // Make it rewritable because two stamps can have same named getter/setter |
103 | | - defineProperty(dst, key, desc); |
| 89 | + Object.defineProperty(dst, key, desc); |
104 | 90 | } |
105 | 91 | } |
106 | 92 |
|
|
110 | 96 | var merge = _mergeOrAssign.bind(0, mergeOne); |
111 | 97 |
|
112 | 98 | function extractUniqueFunctions() { |
113 | | - var1 = concat.apply([], arguments).filter(function(elem, index, array) { |
| 99 | + var1 = Array.prototype.concat.apply([], arguments).filter(function(elem, index, array) { |
114 | 100 | return isFunction(elem) && array.indexOf(elem) === index; |
115 | 101 | }); |
116 | | - return var1[_length] ? var1 : _undefined; |
| 102 | + return var1.length ? var1 : _undefined; |
117 | 103 | } |
118 | 104 |
|
119 | 105 |
|
|
141 | 127 | * @returns {Descriptor} Standardised descriptor |
142 | 128 | */ |
143 | 129 | function standardiseDescriptor(descr) { |
144 | | - var4 = {}; |
| 130 | + var3 = {}; |
145 | 131 |
|
146 | | - var4[_methods] = descr[_methods] || _undefined; |
| 132 | + var3[_methods] = descr[_methods] || _undefined; |
147 | 133 |
|
148 | 134 | var1 = descr[_properties]; |
149 | 135 | var2 = descr.props; |
150 | | - var4[_properties] = isObject(var1 || var2) ? assign({}, var2, var1) : _undefined; |
| 136 | + var3[_properties] = isObject(var1 || var2) ? assign({}, var2, var1) : _undefined; |
151 | 137 |
|
152 | | - var4[_initializers] = extractUniqueFunctions(descr.init, descr[_initializers]); |
| 138 | + var3[_initializers] = extractUniqueFunctions(descr.init, descr[_initializers]); |
153 | 139 |
|
154 | | - var4[_composers] = extractUniqueFunctions(descr[_composers]); |
| 140 | + var3[_composers] = extractUniqueFunctions(descr[_composers]); |
155 | 141 |
|
156 | 142 | var1 = descr[_deepProperties]; |
157 | 143 | var2 = descr[_deepProps]; |
158 | | - var4[_deepProperties] = isObject(var1 || var2) ? merge({}, var2, var1) : _undefined; |
| 144 | + var3[_deepProperties] = isObject(var1 || var2) ? merge({}, var2, var1) : _undefined; |
159 | 145 |
|
160 | | - var4[_propertyDescriptors] = descr[_propertyDescriptors]; |
| 146 | + var3[_propertyDescriptors] = descr[_propertyDescriptors]; |
161 | 147 |
|
162 | 148 | var1 = descr[_staticProperties]; |
163 | 149 | var2 = descr.statics; |
164 | | - var4[_staticProperties] = isObject(var1 || var2) ? assign({}, var2, var1) : _undefined; |
| 150 | + var3[_staticProperties] = isObject(var1 || var2) ? assign({}, var2, var1) : _undefined; |
165 | 151 |
|
166 | 152 | var1 = descr[_staticDeepProperties]; |
167 | 153 | var2 = descr[_deepStatics]; |
168 | | - var4[_staticDeepProperties] = isObject(var1 || var2) ? merge({}, var2, var1) : _undefined; |
| 154 | + var3[_staticDeepProperties] = isObject(var1 || var2) ? merge({}, var2, var1) : _undefined; |
169 | 155 |
|
170 | 156 | var1 = descr[_staticPropertyDescriptors]; |
171 | 157 | var2 = descr.name && {name: {value: descr.name}}; |
172 | | - var4[_staticPropertyDescriptors] = isObject(var2 || var1) ? assign({}, var1, var2) : _undefined; |
| 158 | + var3[_staticPropertyDescriptors] = isObject(var2 || var1) ? assign({}, var1, var2) : _undefined; |
173 | 159 |
|
174 | 160 | var1 = descr[_configuration]; |
175 | 161 | var2 = descr.conf; |
176 | | - var4[_configuration] = isObject(var1 || var2) ? assign({}, var2, var1) : _undefined; |
| 162 | + var3[_configuration] = isObject(var1 || var2) ? assign({}, var2, var1) : _undefined; |
177 | 163 |
|
178 | 164 | var1 = descr[_deepConfiguration]; |
179 | 165 | var2 = descr[_deepConf]; |
180 | | - var4[_deepConfiguration] = isObject(var1 || var2) ? merge({}, var2, var1) : _undefined; |
| 166 | + var3[_deepConfiguration] = isObject(var1 || var2) ? merge({}, var2, var1) : _undefined; |
181 | 167 |
|
182 | | - return var4; |
| 168 | + return var3; |
183 | 169 | } |
184 | 170 |
|
185 | 171 | /** |
|
192 | 178 | // Next line was optimized for most JS VMs. Please, be careful here! |
193 | 179 | var obj = {__proto__: i[_methods]}; |
194 | 180 |
|
195 | | - var inits = i[_initializers], args = slice.apply(arguments); |
| 181 | + var inits = i[_initializers], args = Array.prototype.slice.apply(arguments); |
196 | 182 | var initializer, returnedValue; |
197 | 183 |
|
198 | 184 | var tmp = i[_deepProperties]; |
199 | 185 | if (tmp) merge(obj, tmp); |
200 | 186 | tmp = i[_properties]; |
201 | 187 | if (tmp) assign(obj, tmp); |
202 | 188 | tmp = i[_propertyDescriptors]; |
203 | | - if (tmp) defineProperties(obj, tmp); |
| 189 | + if (tmp) Object.defineProperties(obj, tmp); |
204 | 190 |
|
205 | | - if (!inits || !inits[_length]) return obj; |
| 191 | + if (!inits || !inits.length) return obj; |
206 | 192 |
|
207 | 193 | if (options === _undefined) options = {}; |
208 | | - for (i = 0; i < inits[_length];) { |
| 194 | + for (i = 0; i < inits.length;) { |
209 | 195 | initializer = inits[i++]; |
210 | 196 | if (isFunction(initializer)) { |
211 | 197 | returnedValue = initializer.call(obj, options, |
|
233 | 219 | if (var2) assign(var1, var2); |
234 | 220 |
|
235 | 221 | var2 = descriptor[_staticPropertyDescriptors]; |
236 | | - if (var2) defineProperties(var1, var2); |
| 222 | + if (var2) Object.defineProperties(var1, var2); |
237 | 223 |
|
238 | 224 | var2 = isFunction(var1[_compose]) ? var1[_compose] : compose; |
239 | 225 | assign(var1[_compose] = function() { |
|
291 | 277 | * @returns {Stamp} A new stamp (aka composable factory function) |
292 | 278 | */ |
293 | 279 | function compose() { |
294 | | - var descriptor = concat.apply([this], arguments) |
| 280 | + var descriptor = Array.prototype.concat.apply([this], arguments) |
295 | 281 | .reduce(mergeComposable, {}); |
296 | 282 | return createStamp(descriptor); |
297 | 283 | } |
|
367 | 353 |
|
368 | 354 | function createUtilityFunction(propName, action) { |
369 | 355 | return function() { |
370 | | - var4 = {}; |
371 | | - var4[propName] = action.apply(_undefined, concat.apply([{}], arguments)); |
| 356 | + var3 = {}; |
| 357 | + var3[propName] = action.apply(_undefined, Array.prototype.concat.apply([{}], arguments)); |
372 | 358 | var1 = this; |
373 | 359 |
|
374 | | - return ((var1 && var1[_compose]) || var2).call(var1, var4); |
| 360 | + return ((var1 && var1[_compose]) || var2).call(var1, var3); |
375 | 361 | }; |
376 | 362 | } |
377 | 363 |
|
|
382 | 368 | */ |
383 | 369 | var2 = allUtilities[_compose] = assign(function stampit() { |
384 | 370 | var i = 0, composable, composables = [], array = arguments, composerResult = this; |
385 | | - for (; i < array[_length];) { |
| 371 | + for (; i < array.length;) { |
386 | 372 | composable = array[i++]; |
387 | 373 | if (isObject(composable)) { |
388 | 374 | composables.push(isStamp(composable) ? composable : standardiseDescriptor(composable)); |
|
394 | 380 | if (composerResult) composables.unshift(composerResult); |
395 | 381 |
|
396 | 382 | array = composable[_compose][_composers]; |
397 | | - if (isArray(array)) { |
398 | | - for (i = 0; i < array[_length];) { |
| 383 | + if (Array.isArray(array)) { |
| 384 | + for (i = 0; i < array.length;) { |
399 | 385 | composerResult = array[i++]({stamp: composable, composables: composables}); |
400 | 386 | composable = isStamp(composerResult) ? composerResult : composable; |
401 | 387 | } |
|
404 | 390 | return composable; |
405 | 391 | }, allUtilities); // Setting up the shortcut functions |
406 | 392 |
|
407 | | - allUtilities[_create] = function() { |
| 393 | + allUtilities.create = function() { |
408 | 394 | return this.apply(_undefined, arguments); |
409 | 395 | }; |
410 | 396 |
|
411 | | - var4 = {}; |
412 | | - var4[_staticProperties] = allUtilities; |
| 397 | + var3 = {}; |
| 398 | + var3[_staticProperties] = allUtilities; |
413 | 399 |
|
414 | 400 | /** |
415 | 401 | * Infected stamp. Used as a storage of the infection metadata |
416 | 402 | * @type {Function} |
417 | 403 | * @return {Stamp} |
418 | 404 | */ |
419 | | - baseStampit = compose(var4); |
| 405 | + baseStampit = compose(var3); |
420 | 406 |
|
421 | 407 | var2[_compose] = var2.bind(); // bind to undefined |
422 | 408 | var2.version = 'VERSION'; |
|
0 commit comments