add transformation logger

This commit is contained in:
Sebastian McKenzie 2015-03-10 17:19:51 +11:00
parent 212776e220
commit 0ca71f5e15
4 changed files with 30 additions and 13 deletions

View File

@ -7,6 +7,7 @@ import generate from "../generation";
import defaults from "lodash/object/defaults";
import includes from "lodash/collection/includes";
import assign from "lodash/object/assign";
import Logger from "./logger";
import parse from "../helpers/parse";
import Scope from "../traversal/scope";
import slash from "slash";
@ -23,7 +24,7 @@ var checkTransformerVisitor = {
function checkNode(stack, node, scope) {
each(stack, function (pass) {
if (pass.shouldRun) return;
if (pass.shouldRun || pass.ran) return;
pass.checkNode(node, scope);
});
}
@ -41,6 +42,7 @@ export default class File {
this.lastStatements = [];
this.opts = this.normalizeOptions(opts);
this.log = new Logger(this);
this.ast = {};
this.buildTransformers();
@ -260,12 +262,6 @@ export default class File {
this.transformers = transformers;
}
debug(msg?: string) {
var parts = this.opts.filename;
if (msg) parts += `: ${msg}`;
util.debug(parts);
}
getModuleFormatter(type: string) {
var ModuleFormatter = isFunction(type) ? type : transform.moduleFormatters[type];
@ -398,10 +394,6 @@ export default class File {
}
}
logDeopt() {
// todo, (node, msg)
}
errorWithNode(node, msg, Error = SyntaxError) {
var loc = node.loc.start;
var err = new Error(`Line ${loc.line}: ${msg}`);

View File

@ -0,0 +1,22 @@
import * as util from "../util";
export default class Logger {
constructor(file: File) {
this.filename = file.opts.filename;
this.file = file;
}
_buildMessage(msg: string): string {
var parts = this.filename;
if (msg) parts += `: ${msg}`;
return parts;
}
debug(msg: string) {
util.debug(this._buildMessage(msg));
}
deopt(node: Object, msg: string) {
util.debug(this._buildMessage(msg));
}
}

View File

@ -11,6 +11,7 @@ export default class TransformerPass {
this.shouldRun = !transformer.check;
this.handlers = transformer.handlers;
this.file = file;
this.ran = false;
}
canRun(): boolean {
@ -56,8 +57,10 @@ export default class TransformerPass {
var file = this.file;
file.debug(`Running transformer ${this.transformer.key}`);
file.log.debug(`Running transformer ${this.transformer.key}`);
file.scope.traverse(file.ast, this.handlers, file);
this.ran = true;
}
}

View File

@ -161,7 +161,7 @@ class TailCallTransformer {
if (!this.hasTailRecursion) return;
if (this.hasDeopt()) {
this.file.logDeopt(node, messages.get("tailCallReassignmentDeopt"));
this.file.log.deopt(node, messages.get("tailCallReassignmentDeopt"));
return;
}