6.0.0
I'm extremely stupid and didn't commit as I go. To anyone reading this I'm extremely sorry. A lot of these changes are very broad and I plan on releasing Babel 6.0.0 today live on stage at Ember Camp London so I'm afraid I couldn't wait. If you're ever in London I'll buy you a beer (or assorted beverage!) to make up for it, also I'll kiss your feet and give you a back massage, maybe.
This commit is contained in:
@@ -1,33 +1,79 @@
|
||||
/* @flow */
|
||||
|
||||
import OptionManager from "./file/options/option-manager"
|
||||
import * as messages from "babel-messages";
|
||||
import Store from "../store";
|
||||
import traverse from "babel-traverse";
|
||||
import assign from "lodash/object/assign";
|
||||
import clone from "lodash/lang/clone";
|
||||
|
||||
export default class Plugin {
|
||||
export default class Plugin extends Store {
|
||||
constructor(plugin: Object) {
|
||||
plugin = this.raw = assign({}, plugin);
|
||||
super();
|
||||
|
||||
function take(key) {
|
||||
let val = plugin[key];
|
||||
delete plugin[key];
|
||||
return val;
|
||||
}
|
||||
this.initialized = false;
|
||||
this.raw = assign({}, plugin);
|
||||
|
||||
this.manipulateOptions = take("manipulateOptions");
|
||||
this.post = take("post");
|
||||
this.pre = take("pre");
|
||||
this.visitor = this.normalize(clone(take("visitor")) || {});
|
||||
this.manipulateOptions = this.take("manipulateOptions");
|
||||
this.post = this.take("post");
|
||||
this.pre = this.take("pre");
|
||||
this.visitor = this.normalize(clone(this.take("visitor")) || {});
|
||||
}
|
||||
|
||||
initialized: boolean;
|
||||
raw: Object;
|
||||
manipulateOptions: ?Function;
|
||||
post: ?Function;
|
||||
pre: ?Function;
|
||||
visitor: Object;
|
||||
|
||||
validate(loc: string, i: number) {
|
||||
take(key) {
|
||||
let val = this.raw[key];
|
||||
delete this.raw[key];
|
||||
return val;
|
||||
}
|
||||
|
||||
chain(target, key) {
|
||||
if (!target[key]) return this[key];
|
||||
if (!this[key]) return target[key];
|
||||
|
||||
let fns: Array<?Function> = [target[key], this[key]];
|
||||
|
||||
return function (...args) {
|
||||
let val;
|
||||
for (let fn of fns) {
|
||||
if (fn) {
|
||||
let ret = fn.apply(this, args);
|
||||
if (ret != null) val = ret;
|
||||
}
|
||||
}
|
||||
return val;
|
||||
};
|
||||
}
|
||||
|
||||
maybeInherit(loc: string) {
|
||||
let inherits = this.take("inherits");
|
||||
if (!inherits) return;
|
||||
|
||||
inherits = OptionManager.normalisePlugin(inherits, loc, "inherits");
|
||||
|
||||
this.manipulateOptions = this.chain(inherits, "manipulateOptions");
|
||||
this.post = this.chain(inherits, "post");
|
||||
this.pre = this.chain(inherits, "pre");
|
||||
this.visitor = traverse.visitors.merge([inherits.visitor, this.visitor]);
|
||||
}
|
||||
|
||||
/**
|
||||
* We lazy initialise parts of a plugin that rely on contextual information such as
|
||||
* position on disk and how it was specified.
|
||||
*/
|
||||
|
||||
init(loc: string, i: number) {
|
||||
if (this.initialized) return;
|
||||
this.initialized = true;
|
||||
|
||||
this.maybeInherit(loc);
|
||||
|
||||
for (let key in this.raw) {
|
||||
throw new Error(messages.get("pluginInvalidProperty", loc, i, key));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user