abstract away astRun from transformer

This commit is contained in:
Sebastian McKenzie
2014-12-11 10:14:08 +11:00
parent 2537768772
commit c26ce1c114

View File

@@ -23,19 +23,22 @@ Transformer.normalise = function (transformer) {
return transformer;
};
Transformer.prototype.astRun = function (file, key) {
var transformer = this.transformer;
var ast = file.ast;
if (transformer.ast && transformer.ast[key]) {
transformer.ast[key](ast, file);
}
};
Transformer.prototype.transform = function (file) {
if (!this.canRun(file)) return;
var transformer = this.transformer;
var ast = file.ast;
var astRun = function (key) {
if (transformer.ast && transformer.ast[key]) {
transformer.ast[key](ast, file);
}
};
astRun("enter");
this.astRun(file, "enter");
var build = function (exit) {
return function (node, parent, scope) {
@@ -64,7 +67,7 @@ Transformer.prototype.transform = function (file) {
exit: build(true)
});
astRun("exit");
this.astRun(file, "exit");
};
Transformer.prototype.canRun = function (file) {