From ab134d09195ebb87d7b944c7f8dd06ca70b28ca6 Mon Sep 17 00:00:00 2001 From: Sebastian McKenzie Date: Tue, 20 Jan 2015 01:36:00 +1100 Subject: [PATCH] add data abstraction layer to File --- lib/6to5/file.js | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/lib/6to5/file.js b/lib/6to5/file.js index 153af36cd7..894f7ca869 100644 --- a/lib/6to5/file.js +++ b/lib/6to5/file.js @@ -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) {