|
1 | | -(function() { |
| 1 | +(function () { |
2 | 2 |
|
3 | 3 | var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { |
4 | 4 | var c = arguments.length; |
|
18 | 18 | }; |
19 | 19 |
|
20 | 20 | // For backward compatibility. |
21 | | - var __native = function(thiz) { |
22 | | - // we are setting the __container__ property to the base class when the super method is called |
23 | | - // if the constructor returns the __native(this) call we will use the old implementation |
24 | | - // copying all the properties to the result |
25 | | - // otherwise if we are using the result from the super() method call we won't need such logic |
26 | | - // as thiz already contains the parent properties |
27 | | - // this way we now support both implementations in typescript generated constructors: |
28 | | - // 1: super(); return __native(this); |
29 | | - // 2: return super() || this; |
30 | | - if(thiz.__container__) { |
31 | | - var result = thiz.__proto__; |
32 | | - |
33 | | - for (var prop in thiz) |
34 | | - { |
35 | | - if (thiz.hasOwnProperty(prop)) |
36 | | - { |
37 | | - thiz.__proto__[prop] = thiz[prop]; |
38 | | - delete thiz[prop]; |
39 | | - } |
40 | | - } |
41 | | - |
42 | | - thiz.constructor = undefined; |
43 | | - thiz.__proto__ = undefined; |
44 | | - Object.freeze(thiz); |
45 | | - Object.preventExtensions(thiz); |
46 | | - return result; |
| 21 | + var __native = function (thiz) { |
| 22 | + // we are setting the __container__ property to the base class when the super method is called |
| 23 | + // if the constructor returns the __native(this) call we will use the old implementation |
| 24 | + // copying all the properties to the result |
| 25 | + // otherwise if we are using the result from the super() method call we won't need such logic |
| 26 | + // as thiz already contains the parent properties |
| 27 | + // this way we now support both implementations in typescript generated constructors: |
| 28 | + // 1: super(); return __native(this); |
| 29 | + // 2: return super() || this; |
| 30 | + if (thiz.__container__) { |
| 31 | + var result = thiz.__proto__; |
| 32 | + |
| 33 | + for (var prop in thiz) { |
| 34 | + if (thiz.hasOwnProperty(prop)) { |
| 35 | + thiz.__proto__[prop] = thiz[prop]; |
| 36 | + delete thiz[prop]; |
| 37 | + } |
| 38 | + } |
| 39 | + |
| 40 | + thiz.constructor = undefined; |
| 41 | + thiz.__proto__ = undefined; |
| 42 | + Object.freeze(thiz); |
| 43 | + Object.preventExtensions(thiz); |
| 44 | + return result; |
47 | 45 | } else { |
48 | | - return thiz; |
| 46 | + return thiz; |
49 | 47 | } |
50 | 48 | }; |
51 | 49 |
|
52 | | - var __extends = function(Child, Parent) { |
| 50 | + var __extends = function (Child, Parent) { |
53 | 51 | const NATIVE_CODE_REGEX = /\{\s*\[native code\]\s*\}/g; |
54 | 52 | var extendNativeClass = !!Parent.extend && NATIVE_CODE_REGEX.test(Parent.extend.toString()); |
55 | | - if (!extendNativeClass) { |
| 53 | + if (!extendNativeClass) { |
56 | 54 | __extends_ts(Child, Parent); |
57 | 55 | return; |
58 | 56 | } |
59 | | - if (Parent.__isPrototypeImplementationObject) { |
| 57 | + if (Parent.__isPrototypeImplementationObject) { |
60 | 58 | throw new Error("Can not extend an already extended native object."); |
61 | 59 | } |
62 | 60 |
|
|
66 | 64 | var parent = thiz.__proto__.__parent; |
67 | 65 | child.__extended = parent.extend(child.name, child.prototype, true); |
68 | 66 | // This will deal with "i instanceof child" |
69 | | - child[Symbol.hasInstance] = function(instance) { |
| 67 | + child[Symbol.hasInstance] = function (instance) { |
70 | 68 | return instance instanceof this.__extended; |
71 | 69 | } |
72 | 70 | } |
73 | 71 | return child.__extended; |
74 | 72 | }; |
75 | 73 |
|
76 | | - Parent.__activityExtend = function(parent, name, implementationObject) { |
| 74 | + Parent.__activityExtend = function (parent, name, implementationObject) { |
77 | 75 | __log("__activityExtend called"); |
78 | 76 | return parent.extend(name, implementationObject); |
79 | 77 | }; |
80 | 78 |
|
81 | | - Parent.call = function(thiz) { |
| 79 | + Parent.call = function (thiz) { |
82 | 80 | var Extended = extend(thiz); |
83 | 81 | thiz.__container__ = true; |
84 | | - if (arguments.length > 1) |
85 | | - { |
| 82 | + if (arguments.length > 1) { |
86 | 83 | thiz.__proto__ = new (Function.prototype.bind.apply(Extended, [null].concat(Array.prototype.slice.call(arguments, 1)))); |
87 | 84 | } |
88 | | - else |
89 | | - { |
| 85 | + else { |
90 | 86 | thiz.__proto__ = new Extended() |
91 | 87 | } |
92 | 88 | return thiz.__proto__; |
93 | 89 | }; |
94 | 90 |
|
95 | | - Parent.apply = function(thiz, args) { |
| 91 | + Parent.apply = function (thiz, args) { |
96 | 92 | var Extended = extend(thiz); |
97 | 93 | thiz.__container__ = true; |
98 | | - if (args && args.length > 0) |
99 | | - { |
| 94 | + if (args && args.length > 0) { |
100 | 95 | thiz.__proto__ = new (Function.prototype.bind.apply(Extended, [null].concat(args))); |
101 | 96 | } |
102 | | - else |
103 | | - { |
| 97 | + else { |
104 | 98 | thiz.__proto__ = new Extended(); |
105 | 99 | } |
106 | 100 | return thiz.__proto__; |
|
126 | 120 | }; |
127 | 121 |
|
128 | 122 | var extendStaticFunctions = |
129 | | - Object.setPrototypeOf |
130 | | - || (hasInternalProtoProperty() && function (child, parent) { child.__proto__ = parent; }) |
131 | | - || assignPropertiesFromParentToChild; |
| 123 | + Object.setPrototypeOf |
| 124 | + || (hasInternalProtoProperty() && function (child, parent) { child.__proto__ = parent; }) |
| 125 | + || assignPropertiesFromParentToChild; |
132 | 126 |
|
133 | | - function hasInternalProtoProperty(){ |
| 127 | + function hasInternalProtoProperty() { |
134 | 128 | return { __proto__: [] } instanceof Array; |
135 | 129 | } |
136 | 130 |
|
137 | | - function assignPropertiesFromParentToChild(parent, child){ |
138 | | - for (var property in parent){ |
| 131 | + function assignPropertiesFromParentToChild(parent, child) { |
| 132 | + for (var property in parent) { |
139 | 133 | if (parent.hasOwnProperty(property)) { |
140 | 134 | child[property] = parent[property]; |
141 | 135 | } |
142 | 136 | } |
143 | 137 | } |
144 | 138 |
|
145 | | - function assignPrototypeFromParentToChild(parent, child){ |
| 139 | + function assignPrototypeFromParentToChild(parent, child) { |
146 | 140 | function __() { |
147 | 141 | this.constructor = child; |
148 | 142 | } |
149 | 143 |
|
150 | | - if(parent === null){ |
| 144 | + if (parent === null) { |
151 | 145 | child.prototype = Object.create(null); |
152 | 146 | } else { |
153 | 147 | __.prototype = parent.prototype; |
154 | | - child.prototype = new __(); |
| 148 | + child.prototype = new __(); |
155 | 149 | } |
156 | 150 | } |
157 | 151 |
|
|
166 | 160 |
|
167 | 161 | function Interfaces(interfacesArr) { |
168 | 162 | return function (target) { |
169 | | - if(interfacesArr instanceof Array) { |
| 163 | + if (interfacesArr instanceof Array) { |
170 | 164 | // attach interfaces: [] to the object |
171 | 165 | target.prototype.interfaces = interfacesArr; |
172 | 166 | } |
|
0 commit comments