-
-
Notifications
You must be signed in to change notification settings - Fork 22
/
index.js
191 lines (162 loc) · 7.66 KB
/
index.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
'use strict';
/* globals Ember, define */
(function(global) {
var OWN_CLASSES = new WeakMap();
var HAS_CONSTRUCTOR = new WeakMap();
var IS_CLASSIC = new WeakMap();
var BASE_CLASSES = new WeakMap();
var IS_PERMA_CLASSIC = new WeakMap();
global.__CLASSIC_HAS_CONSTRUCTOR__ = HAS_CONSTRUCTOR;
global.__CLASSIC_OWN_CLASSES__ = OWN_CLASSES;
const _Ember = typeof require === 'function' && typeof require.has === 'function' && require.has('ember') ? require('ember').default : Ember;
IS_PERMA_CLASSIC.set(_Ember.Object, true);
IS_PERMA_CLASSIC.set(_Ember.Component, true);
IS_PERMA_CLASSIC.set(_Ember.ObjectProxy, false);
IS_PERMA_CLASSIC.set(_Ember.Application, false);
IS_PERMA_CLASSIC.set(_Ember.Controller, false);
IS_PERMA_CLASSIC.set(_Ember.Router, false);
IS_PERMA_CLASSIC.set(_Ember.Route, false);
IS_PERMA_CLASSIC.set(_Ember.Service, false);
IS_PERMA_CLASSIC.set(_Ember.Helper, false);
IS_PERMA_CLASSIC.set(_Ember.Location, false);
IS_PERMA_CLASSIC.set(_Ember.AutoLocation, false);
IS_PERMA_CLASSIC.set(_Ember.HashLocation, false);
IS_PERMA_CLASSIC.set(_Ember.HistoryLocation, false);
IS_PERMA_CLASSIC.set(_Ember.NoneLocation, false);
BASE_CLASSES.set(_Ember.ObjectProxy, true);
BASE_CLASSES.set(_Ember.CoreObject, true);
BASE_CLASSES.set(_Ember.Object, true);
BASE_CLASSES.set(_Ember.Application, true);
BASE_CLASSES.set(_Ember.Controller, true);
BASE_CLASSES.set(_Ember.Router, true);
BASE_CLASSES.set(_Ember.Route, true);
BASE_CLASSES.set(_Ember.Service, true);
BASE_CLASSES.set(_Ember.Helper, true);
BASE_CLASSES.set(_Ember.Location, true);
function getClassName(klass) {
var klassToString = klass.toString();
return klassToString.includes('(unknown)') ? klass.name : klassToString;
}
function findAncestor(klass, predicate) {
while (klass !== null && Boolean(klass.prototype)) {
if (predicate(klass)) {
return klass;
}
klass = Object.getPrototypeOf(klass);
}
return null;
}
_Ember.Object.reopenClass({
create: function create() {
// We can't actually use `new` as an alternative here, but most classes
// don't need to be created by users, so no reason to assert in the
// general case.
var ret = this._super.apply(this, arguments);
if (OWN_CLASSES.get(this) && !IS_CLASSIC.has(this)) {
var permaClassicAncestor = findAncestor(this, function(klass) {
return IS_PERMA_CLASSIC.has(klass);
});
if (
permaClassicAncestor &&
IS_PERMA_CLASSIC.get(permaClassicAncestor)
) {
throw new Error(
'You defined the class '
.concat(getClassName(this), ' that extends from ')
.concat(
getClassName(permaClassicAncestor),
" using native class syntax, but you didn't mark it with the @classic decorator. All user classes that extend from this class must be marked as @classic, since they use classic features. If you want to remove the @classic decorator, you must remove the base class. For components, you can do this by converting to Glimmer components. For plain classes that extend from EmberObject, you can convert them into plain native classes that do not extend from EmberObject.\n\n" +
"If this class is a base class provided by the framework that you should be allowed to remove @classic from, please open an issue on the classic decorators repo: https://github.com/emberjs/ember-classic-decorator"
)
);
}
if (HAS_CONSTRUCTOR.has(this)) {
var ancestorWithInit = findAncestor(this, function(klass) {
return (
klass.prototype.hasOwnProperty('init') || BASE_CLASSES.has(klass)
);
});
if (ancestorWithInit !== null && !BASE_CLASSES.has(ancestorWithInit)) {
throw new Error(
'You defined the class '
.concat(
getClassName(this),
" with a 'constructor' function, but one of its ancestors, "
)
.concat(
getClassName(ancestorWithInit),
", uses the 'init' method. Due to the timing of the constructor and init methods, its not generally safe to use 'constructor' for class setup if the parent class is using 'init'. You can mark "
)
.concat(
getClassName(this),
" with the @classic decorator and safely use 'init', or you can convert the parent class to use native classes, and switch from 'init' to 'constructor' there first.\n\n" +
"If this error message is not being triggered by your code or code from an addon, but from Ember itself, please file a bug report on the classic decorator repo: https://github.com/emberjs/ember-classic-decorator"
)
);
}
}
}
return ret;
},
reopen: function reopen() {
if (OWN_CLASSES.get(this) && !IS_CLASSIC.has(this)) {
throw new Error(
'You attempted to use the .reopen() method on the '.concat(
getClassName(this),
" class, but it's not a classic class! Redefining classes after they have been defined is generally considered an antipattern.\n\n" +
"If this error message is not being triggered by your code or code from an addon, but from Ember itself, please file a bug report on the classic decorator repo: https://github.com/emberjs/ember-classic-decorator"
)
);
}
var ret = this._super.apply(this, arguments);
return ret;
},
reopenClass: function reopenClass() {
if (OWN_CLASSES.get(this) && !IS_CLASSIC.has(this) && !_Ember.Application.detect(this) && !_Ember.Router.detect(this)) {
throw new Error(
'You attempted to use the .reopen() method on the '.concat(
getClassName(this),
" class, but it's not a classic class! Redefining classes after they have been defined is generally considered an antipattern. If you were reopening this class to add static class fields or methods, you can now define those with the 'static' keyword instead.\n\n" +
"If this error message is not being triggered by your code or code from an addon, but from Ember itself, please file a bug report on the classic decorator repo: https://github.com/emberjs/ember-classic-decorator"
)
);
}
var ret = this._super.apply(this, arguments);
return ret;
},
});
global.__EMBER_CLASSIC_DECORATOR = function classic(target) {
IS_CLASSIC.set(target, true);
return target;
}
let originalRequire = window.require;
let originalRequireEntries = Object.entries(window.require);
window.require = require = function patchData(moduleName) {
var DS, Resolver;
try {
Resolver = originalRequire('ember-resolver').default;
DS = originalRequire('ember-data').default;
} catch (e) {}
if (Resolver) {
BASE_CLASSES.set(Resolver, true);
IS_PERMA_CLASSIC.set(Resolver, false);
}
if (DS) {
BASE_CLASSES.set(DS.Store, true);
BASE_CLASSES.set(DS.Model, true);
BASE_CLASSES.set(DS.Adapter, true);
BASE_CLASSES.set(DS.Serializer, true);
BASE_CLASSES.set(DS.Transform, true);
IS_PERMA_CLASSIC.set(DS.Store, false);
IS_PERMA_CLASSIC.set(DS.Model, false);
IS_PERMA_CLASSIC.set(DS.Adapter, false);
IS_PERMA_CLASSIC.set(DS.Serializer, false);
IS_PERMA_CLASSIC.set(DS.Transform, false);
}
window.require = require = window.requirejs;
return window.requirejs(moduleName);
}
originalRequireEntries.forEach(
([key, value]) => (window.require[key] = value)
);
})(window);