Skip to content

Instantly share code, notes, and snippets.

@mikechau
Created March 19, 2015 19:55
Show Gist options
  • Save mikechau/b8b2eed60292d12fb809 to your computer and use it in GitHub Desktop.
Save mikechau/b8b2eed60292d12fb809 to your computer and use it in GitHub Desktop.
{
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