From 0e7fd0741d58a34993a503e5e94bce14b4287099 Mon Sep 17 00:00:00 2001 From: Sebastian McKenzie Date: Tue, 17 Mar 2015 11:26:06 +1100 Subject: [PATCH] inject transformer parser plugins --- src/babel/transformation/file/index.js | 8 +++++++- src/babel/transformation/transformer.js | 6 ++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/babel/transformation/file/index.js b/src/babel/transformation/file/index.js index a4db9cad11..a322eee31e 100644 --- a/src/babel/transformation/file/index.js +++ b/src/babel/transformation/file/index.js @@ -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"); diff --git a/src/babel/transformation/transformer.js b/src/babel/transformation/transformer.js index 552b160116..dced834a83 100644 --- a/src/babel/transformation/transformer.js +++ b/src/babel/transformation/transformer.js @@ -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 {