diff --git a/packages/babel-core/src/api/node.js b/packages/babel-core/src/api/node.js index 1fedfd9b11..1f3e4b7c61 100644 --- a/packages/babel-core/src/api/node.js +++ b/packages/babel-core/src/api/node.js @@ -5,7 +5,7 @@ import * as util from "../util"; import fs from "fs"; export { util, babylon as acorn, transform }; -export { pipeline } from "../transformation"; +export { pipeline, lint } from "../transformation"; export { canCompile } from "../util"; export { default as File } from "../transformation/file"; diff --git a/packages/babel-core/src/transformation/file/index.js b/packages/babel-core/src/transformation/file/index.js index 6c617656ec..819d61c262 100644 --- a/packages/babel-core/src/transformation/file/index.js +++ b/packages/babel-core/src/transformation/file/index.js @@ -44,6 +44,8 @@ export default class File { ast = {}; metadata = { + marked: [], + modules: { imports: [], exports: { @@ -518,7 +520,7 @@ export default class File { var features = parseOpts.features = {}; for (var key in this.transformers) { var transformer = this.transformers[key]; - features[key] = transformer.canTransform(); + features[key] = transformer.canRun(); } parseOpts.looseModules = this.isLoose("es6.modules"); @@ -660,7 +662,7 @@ export default class File { call(key: string) { for (var pass of (this.uncollapsedTransformerStack: Array)) { var fn = pass.plugin[key]; - if (fn) fn(this); + if (fn) fn.call(pass, this); } } diff --git a/packages/babel-core/src/transformation/file/options/config.json b/packages/babel-core/src/transformation/file/options/config.json index 205b06eefb..5a363712ec 100644 --- a/packages/babel-core/src/transformation/file/options/config.json +++ b/packages/babel-core/src/transformation/file/options/config.json @@ -25,6 +25,11 @@ "default": {} }, + "mode": { + "description": "", + "hidden": true + }, + "moduleId": { "description": "specify a custom name for module ids", "type": "string" diff --git a/packages/babel-core/src/transformation/index.js b/packages/babel-core/src/transformation/index.js index cd62db85a1..ace35aa71c 100644 --- a/packages/babel-core/src/transformation/index.js +++ b/packages/babel-core/src/transformation/index.js @@ -54,5 +54,6 @@ pipeline.addFilter(filters.optional); var transform = pipeline.transform.bind(pipeline); transform.fromAst = pipeline.transformFromAst.bind(pipeline); +transform.lint = pipeline.lint.bind(pipeline); transform.pipeline = pipeline; export default transform; diff --git a/packages/babel-core/src/transformation/pipeline.js b/packages/babel-core/src/transformation/pipeline.js index b541aa6c23..0e72a5325c 100644 --- a/packages/babel-core/src/transformation/pipeline.js +++ b/packages/babel-core/src/transformation/pipeline.js @@ -84,7 +84,7 @@ export default class Pipeline { * [Please add a description.] */ - canTransform(plugin, fileOpts) { + canRun(plugin, fileOpts) { if (plugin.metadata.plugin) { return true; } @@ -101,8 +101,9 @@ export default class Pipeline { * [Please add a description.] */ - analyze(code: string, opts?: Object = {}) { + lint(code: string, opts?: Object = {}) { opts.code = false; + opts.mode = "lint"; return this.transform(code, opts); } diff --git a/packages/babel-core/src/transformation/plugin-pass.js b/packages/babel-core/src/transformation/plugin-pass.js index 1cc7bf2c2f..02488d9755 100644 --- a/packages/babel-core/src/transformation/plugin-pass.js +++ b/packages/babel-core/src/transformation/plugin-pass.js @@ -21,12 +21,24 @@ export default class PluginPass { } /** - * [Please add a description.] - */ + * [Please add a description.] + */ canTransform(): boolean { + if (this.plugin.metadata.mode !== this.file.opts.mode) { + return false; + } else { + return this.canRun(); + } + } + + /** + * [Please add a description.] + */ + + canRun() { return this.file.transformerDependencies[this.key] || - this.file.pipeline.canTransform(this.plugin, this.file.opts); + this.file.pipeline.canRun(this.plugin, this.file.opts); } /** diff --git a/packages/babel-core/src/transformation/plugin.js b/packages/babel-core/src/transformation/plugin.js index 1a8ff2ffc6..e0724d5df6 100644 --- a/packages/babel-core/src/transformation/plugin.js +++ b/packages/babel-core/src/transformation/plugin.js @@ -18,7 +18,8 @@ const VALID_METADATA_PROPERTES = [ "stage", "group", "experimental", - "secondPass" + "secondPass", + "mode" ]; /**