move runtime helpers to separate modules - babel/ember-cli-babel#24
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
import buildHelpers from "./build-helpers";
|
||||
import generator from "./generation";
|
||||
import * as messages from "./messages";
|
||||
import * as util from "./util";
|
||||
import File from "./transformation/file";
|
||||
import each from "lodash/collection/each";
|
||||
import t from "./types";
|
||||
|
||||
function buildGlobal(namespace, builder) {
|
||||
@@ -49,8 +50,20 @@ function buildVar(namespace, builder) {
|
||||
return t.program(body);
|
||||
}
|
||||
|
||||
function buildHelpers(body, namespace, whitelist = []) {
|
||||
each(File.helpers, function (name) {
|
||||
if (whitelist.length && whitelist.indexOf(name) === -1) return;
|
||||
|
||||
var key = t.identifier(t.toIdentifier(name));
|
||||
body.push(t.expressionStatement(
|
||||
t.assignmentExpression("=", t.memberExpression(namespace, key), util.template(name))
|
||||
));
|
||||
});
|
||||
}
|
||||
|
||||
export default function (whitelist, outputType = "global") {
|
||||
var namespace = t.identifier("babelHelpers");
|
||||
|
||||
var builder = function (body) {
|
||||
return buildHelpers(body, namespace, whitelist);
|
||||
};
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
import File from "./transformation/file";
|
||||
import * as util from "./util";
|
||||
import each from "lodash/collection/each";
|
||||
import t from "./types";
|
||||
|
||||
export default function (body, namespace, whitelist = []) {
|
||||
each(File.helpers, function (name) {
|
||||
if (whitelist.length && whitelist.indexOf(name) === -1) return;
|
||||
|
||||
var key = t.identifier(t.toIdentifier(name));
|
||||
body.push(t.expressionStatement(
|
||||
t.assignmentExpression("=", t.memberExpression(namespace, key), util.template(name))
|
||||
));
|
||||
});
|
||||
};
|
||||
@@ -377,10 +377,15 @@ export default class File {
|
||||
|
||||
this.usedHelpers[name] = true;
|
||||
|
||||
var generator = this.get("helperGenerator");
|
||||
var runtime = this.get("helpersNamespace");
|
||||
if (runtime) {
|
||||
name = t.identifier(t.toIdentifier(name));
|
||||
return t.memberExpression(runtime, name);
|
||||
if (runtime || generator) {
|
||||
var id = t.identifier(t.toIdentifier(name));
|
||||
if (generator) {
|
||||
return generator(name, id);
|
||||
} else {
|
||||
return t.memberExpression(runtime, id);
|
||||
}
|
||||
} else {
|
||||
var ref = util.template(name);
|
||||
ref._compact = true;
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
var helpers = exports.default = {};
|
||||
exports.default = HELPER;
|
||||
exports.__esModule = true;
|
||||
|
||||
@@ -81,8 +81,8 @@ export function Program(node, parent, scope, file) {
|
||||
}
|
||||
|
||||
export function pre(file) {
|
||||
file.setDynamic("helpersNamespace", function () {
|
||||
return file.addImport("babel-runtime/helpers", "babelHelpers");
|
||||
file.set("helperGenerator", function (name, id) {
|
||||
return file.addImport("babel-runtime/helpers/" + name, id);
|
||||
});
|
||||
|
||||
file.setDynamic("coreIdentifier", function () {
|
||||
|
||||
Reference in New Issue
Block a user