bio-dts 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/post-transform.js +6 -0
- package/lib/pre-transform.js +29 -10
- package/package.json +1 -1
package/lib/post-transform.js
CHANGED
|
@@ -36,6 +36,12 @@ export default function transform(src) {
|
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
// TODO(nikku): transform illegal typescript methods into override calls
|
|
39
|
+
|
|
40
|
+
// TODO(nikku): remove annotations
|
|
41
|
+
//
|
|
42
|
+
// * @typedef
|
|
43
|
+
// * @class
|
|
44
|
+
// * @constructor
|
|
39
45
|
});
|
|
40
46
|
|
|
41
47
|
return print(ast).code;
|
package/lib/pre-transform.js
CHANGED
|
@@ -146,19 +146,31 @@ export default function transform(src) {
|
|
|
146
146
|
const ast = parse(src);
|
|
147
147
|
const body = path(ast).get('program', 'body');
|
|
148
148
|
|
|
149
|
+
const inheritsImports = findInheritsImports(body);
|
|
150
|
+
|
|
149
151
|
const classes = findConstructors(body);
|
|
150
152
|
|
|
153
|
+
// query
|
|
151
154
|
for (const cls of classes) {
|
|
152
|
-
|
|
155
|
+
cls.members = [
|
|
153
156
|
...findEmbeddedMethods(cls),
|
|
154
157
|
...findProtoMethods(cls, body)
|
|
155
158
|
];
|
|
156
159
|
|
|
157
|
-
|
|
160
|
+
cls.staticMembers = [
|
|
158
161
|
...findStaticMembers(cls, body)
|
|
159
162
|
];
|
|
160
163
|
|
|
161
|
-
|
|
164
|
+
cls.superDeclaration = findSuperDeclarations(cls, body, inheritsImports);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// transform
|
|
168
|
+
for (const cls of classes) {
|
|
169
|
+
const {
|
|
170
|
+
members,
|
|
171
|
+
staticMembers,
|
|
172
|
+
superDeclaration
|
|
173
|
+
} = cls;
|
|
162
174
|
|
|
163
175
|
if (superDeclaration) {
|
|
164
176
|
cls.ctor.get('body', 'body').unshift(superCall());
|
|
@@ -187,26 +199,34 @@ export default function transform(src) {
|
|
|
187
199
|
});
|
|
188
200
|
|
|
189
201
|
if (superDeclaration) {
|
|
190
|
-
superDeclaration.importDeclarations.forEach(m => m.node.replace());
|
|
191
202
|
superDeclaration.inheritsExpression.node.replace();
|
|
192
203
|
}
|
|
193
204
|
}
|
|
194
205
|
|
|
206
|
+
inheritsImports.forEach(m => m.node.replace());
|
|
207
|
+
|
|
195
208
|
return print(ast).code;
|
|
196
209
|
}
|
|
197
210
|
|
|
198
|
-
function
|
|
199
|
-
|
|
211
|
+
function findInheritsImports(nodes) {
|
|
200
212
|
const importsMatches = matcher`
|
|
201
213
|
import $1 from 'inherits-browser';
|
|
202
214
|
`;
|
|
203
215
|
|
|
204
|
-
|
|
216
|
+
return importsMatches(nodes).map(m => {
|
|
217
|
+
return {
|
|
218
|
+
node: m[0],
|
|
219
|
+
name: m[1].value.name
|
|
220
|
+
};
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
function findSuperDeclarations(cls, nodes, importDeclarations) {
|
|
205
225
|
|
|
206
|
-
for (const
|
|
226
|
+
for (const { name: inheritsName } of importDeclarations) {
|
|
207
227
|
|
|
208
228
|
const inheritsMatches = matcher`
|
|
209
|
-
${
|
|
229
|
+
${inheritsName}(${cls.name}, $1);
|
|
210
230
|
`;
|
|
211
231
|
|
|
212
232
|
const inheritsExpressions = inheritsMatches(nodes);
|
|
@@ -230,7 +250,6 @@ function findSuperDeclarations(cls, nodes) {
|
|
|
230
250
|
const superCalls = superCallMatches(cls.ctor.get('body', 'body'));
|
|
231
251
|
|
|
232
252
|
return {
|
|
233
|
-
importDeclarations: importDeclarations.map(m => ({ node: m[0] })),
|
|
234
253
|
superCalls: superCalls.map(m => ({ node: m[0] })),
|
|
235
254
|
clazz,
|
|
236
255
|
inheritsExpression
|