add data abstraction layer to File

This commit is contained in:
Sebastian McKenzie 2015-01-20 01:36:00 +11:00
parent d6412d0a1b
commit ab134d0919

View File

@ -14,6 +14,7 @@ var _ = require("lodash");
function File(opts) {
this.dynamicImports = [];
this.dynamicImportIds = {};
this.data = {};
this.opts = File.normaliseOptions(opts);
this.transformers = this.getTransformers();
this.uids = {};
@ -175,6 +176,14 @@ File.prototype.parseShebang = function (code) {
return code;
};
File.prototype.set = function (key, val) {
this.data[key] = val;
};
File.prototype.get = function (key) {
return this.data[key];
};
File.prototype.addImport = function (source, name) {
name = name || source;
var id = this.dynamicImportIds[name];
@ -201,20 +210,19 @@ File.prototype.addHelper = function (name) {
var declar = program._declarations && program._declarations[name];
if (declar) return declar.id;
var ref;
if (this._runtime) {
return t.memberExpression(this._runtime, name);
var runtime = this.get("runtimeIdentifier");
if (runtime) {
return t.memberExpression(runtime, name);
} else {
ref = util.template(name);
var ref = util.template(name);
var uid = this.generateUidIdentifier(name);
this.scope.push({
key: name,
id: uid,
init: ref
});
return uid;
}
var uid = this.generateUidIdentifier(name);
this.scope.push({
key: name,
id: uid,
init: ref
});
return uid;
};
File.prototype.errorWithNode = function (node, msg, Error) {