Created
March 19, 2015 19:55
-
-
Save mikechau/b8b2eed60292d12fb809 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
esprima: { | |
transforms: [ | |
{ | |
type: 'replace', | |
enter: function(node, parent) { | |
if (node.type === 'VariableDeclaration') { | |
var declarations = node.declarations; | |
var newDeclarations = declarations.map(function(declaration) { | |
if (declaration.type === 'VariableDeclarator') { | |
if (declaration.init && declaration.init.type === 'CallExpression' && declaration.init.callee && declaration.init.callee.type === 'MemberExpression' && declaration.init.callee.object && declaration.init.callee.object.name === 'React' && declaration.init.callee.property && declaration.init.callee.property.name === 'createClass') { | |
var newDeclaration = declaration.init.arguments.map(function(argument) { | |
if (argument.type === 'ObjectExpression') { | |
var newPropertyArgs = argument.properties.map(function(property) { | |
if (property.type === 'Property' && property.value.type === 'ArrayExpression' && property.key.name === 'mixins') { | |
property.value.elements.push({ type: "Identifier", name: "LifecycleLogMixin" }); | |
return property; | |
} else { | |
return property; | |
} | |
}); | |
return newPropertyArgs; | |
} else { | |
return argument; | |
} | |
}); | |
return newDeclaration; | |
} else { | |
return declaration; | |
} | |
} else { | |
return declaration; | |
} | |
}); | |
} | |
} | |
} | |
] | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment