-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
23 lines (23 loc) · 905 Bytes
/
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
/**
* Adds a class property '_name' to Arva Controller and Model classes containing their unmangled class names.
*
* @param t
* @returns {{visitor: {Class: (function(*=))}}}
*/
module.exports = function({ types: t }) {
return {
visitor: {
Class(path) {
let superClassName = path.node.superClass && path.node.superClass.name;
if(superClassName === 'Controller' || superClassName === 'Model' || superClassName === 'PrioritisedArray') {
let name = path.node.id.name;
let nameMethod = t.classMethod('get', t.Identifier('_name'), [], t.blockStatement([
t.returnStatement(t.stringLiteral(name))
]), false, true);
path.node.body.body.push(nameMethod);
path.replaceWith(path);
}
}
}
};
}