inject transformer parser plugins

This commit is contained in:
Sebastian McKenzie 2015-03-17 11:26:06 +11:00
parent 276cafaae1
commit 0e7fd0741d
2 changed files with 13 additions and 1 deletions

View File

@ -392,7 +392,13 @@ export default class File {
var transformers = parseOpts.transformers = {};
for (var key in this.transformers) {
transformers[key] = this.transformers[key].canParse;
var transformer = this.transformers[key];
transformers[key] = transformer.canTransform;
if (transformer.parser) {
parseOpts.plugins[key] = true;
}
}
parseOpts.looseModules = this.isLoose("es6.modules");

View File

@ -3,6 +3,7 @@ import isFunction from "lodash/lang/isFunction";
import traverse from "../traversal";
import isObject from "lodash/lang/isObject";
import assign from "lodash/object/assign";
import acorn from "../../../../acorn";
import File from "./file";
import each from "lodash/collection/each";
@ -24,6 +25,7 @@ export default class Transformer {
this.manipulateOptions = take("manipulateOptions");
this.metadata = take("metadata") || {};
this.parser = take("parser");
this.check = take("check");
this.post = take("post");
this.pre = take("pre");
@ -31,6 +33,10 @@ export default class Transformer {
this.handlers = this.normalize(transformer);
this.opts ||= {};
this.key = transformerKey;
if (this.parser) {
acorn.plugins[key] = this.parser(acorn.Parser.prototype, acorn.tokTypes);
}
}
normalize(transformer: Object): Object {