add plugin modes
This commit is contained in:
@@ -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";
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -25,6 +25,11 @@
|
||||
"default": {}
|
||||
},
|
||||
|
||||
"mode": {
|
||||
"description": "",
|
||||
"hidden": true
|
||||
},
|
||||
|
||||
"moduleId": {
|
||||
"description": "specify a custom name for module ids",
|
||||
"type": "string"
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -18,7 +18,8 @@ const VALID_METADATA_PROPERTES = [
|
||||
"stage",
|
||||
"group",
|
||||
"experimental",
|
||||
"secondPass"
|
||||
"secondPass",
|
||||
"mode"
|
||||
];
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user