add back runtime - fixes #651
This commit is contained in:
4
Makefile
4
Makefile
@@ -21,6 +21,9 @@ build:
|
||||
node $(BROWSERIFY_CMD) lib/6to5/browser.js -s to5 >dist/6to5.js
|
||||
node $(UGLIFY_CMD) dist/6to5.js >dist/6to5.min.js
|
||||
|
||||
node bin/6to5-runtime >dist/runtime.js
|
||||
node $(UGLIFY_CMD) dist/runtime.js >dist/runtime.min.js
|
||||
|
||||
rm -rf templates.json
|
||||
|
||||
clean:
|
||||
@@ -77,6 +80,7 @@ publish:
|
||||
make build
|
||||
cp dist/6to5.min.js browser.js
|
||||
cp dist/polyfill.min.js browser-polyfill.js
|
||||
cp dist/runtime.min.js runtime.js
|
||||
|
||||
node tools/cache-templates
|
||||
test -f templates.json
|
||||
|
||||
4
bin/6to5-runtime
Executable file
4
bin/6to5-runtime
Executable file
@@ -0,0 +1,4 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
var runtime = require("../lib/6to5/build-runtime");
|
||||
console.log(runtime());
|
||||
@@ -11,6 +11,7 @@ commander.option("-t, --source-maps-inline", "Append sourceMappingURL comment to
|
||||
commander.option("-s, --source-maps", "Save source map alongside the compiled code");
|
||||
commander.option("-f, --filename [filename]", "Filename to use when reading from stdin - this will be used in source-maps, errors etc [stdin]", "stdin");
|
||||
commander.option("-w, --watch", "Recompile files on changes");
|
||||
commander.option("-r, --runtime", "Replace 6to5 declarations with references to a runtime");
|
||||
commander.option("-e, --experimental", "Enable experimental support for proposed ES7 features");
|
||||
commander.option("-p, --playground", "Enable playground support");
|
||||
|
||||
@@ -108,6 +109,7 @@ exports.opts = {
|
||||
sourceMap: commander.sourceMaps || commander.sourceMapsInline,
|
||||
optional: commander.optional,
|
||||
comments: !commander.removeComments,
|
||||
runtime: commander.runtime,
|
||||
modules: commander.modules,
|
||||
loose: commander.loose
|
||||
};
|
||||
|
||||
13
lib/6to5/build-helpers.js
Normal file
13
lib/6to5/build-helpers.js
Normal file
@@ -0,0 +1,13 @@
|
||||
var File = require("./file");
|
||||
var util = require("./util");
|
||||
var each = require("lodash/collection/each");
|
||||
var t = require("./types");
|
||||
|
||||
module.exports = function (body, namespace) {
|
||||
each(File.helpers, function (name) {
|
||||
var key = t.identifier(t.toIdentifier(name));
|
||||
body.push(t.expressionStatement(
|
||||
t.assignmentExpression("=", t.memberExpression(namespace, key), util.template(name))
|
||||
));
|
||||
});
|
||||
};
|
||||
26
lib/6to5/build-runtime.js
Normal file
26
lib/6to5/build-runtime.js
Normal file
@@ -0,0 +1,26 @@
|
||||
"use strict";
|
||||
|
||||
var buildHelpers = require("./build-helpers");
|
||||
var generator = require("./generation");
|
||||
var util = require("./util");
|
||||
var t = require("./types");
|
||||
var _ = require("lodash");
|
||||
|
||||
module.exports = function () {
|
||||
var namespace = t.identifier("to5Runtime");
|
||||
|
||||
var body = [];
|
||||
var container = t.functionExpression(null, [t.identifier("global")], t.blockStatement(body));
|
||||
var tree = t.program([t.expressionStatement(t.callExpression(container, [util.template("self-global")]))]);
|
||||
|
||||
body.push(t.variableDeclaration("var", [
|
||||
t.variableDeclarator(
|
||||
namespace,
|
||||
t.assignmentExpression("=", t.memberExpression(t.identifier("global"), namespace), t.objectExpression([]))
|
||||
)
|
||||
]));
|
||||
|
||||
buildHelpers(body, namespace);
|
||||
|
||||
return generator(tree).code;
|
||||
};
|
||||
@@ -24,7 +24,7 @@ function File(opts) {
|
||||
this.data = {};
|
||||
|
||||
this.lastStatements = [];
|
||||
this.opts = File.normaliseOptions(opts);
|
||||
this.opts = this.normaliseOptions(opts);
|
||||
this.ast = {};
|
||||
|
||||
this.buildTransformers();
|
||||
@@ -76,6 +76,7 @@ File.validOptions = [
|
||||
"playground",
|
||||
"experimental",
|
||||
"resolveModuleSource",
|
||||
"runtime",
|
||||
|
||||
// these are used by plugins
|
||||
"ignore",
|
||||
@@ -84,7 +85,7 @@ File.validOptions = [
|
||||
"accept"
|
||||
];
|
||||
|
||||
File.normaliseOptions = function (opts) {
|
||||
File.prototype.normaliseOptions = function (opts) {
|
||||
opts = clone(opts);
|
||||
|
||||
for (var key in opts) {
|
||||
@@ -108,6 +109,7 @@ File.normaliseOptions = function (opts) {
|
||||
comments: true,
|
||||
filename: "unknown",
|
||||
modules: "common",
|
||||
runtime: false,
|
||||
loose: [],
|
||||
code: true,
|
||||
ast: true
|
||||
@@ -146,6 +148,10 @@ File.normaliseOptions = function (opts) {
|
||||
opts.experimental = true;
|
||||
}
|
||||
|
||||
if (opts.runtime) {
|
||||
this.set("runtimeIdentifier", t.identifier("to5Runtime"));
|
||||
}
|
||||
|
||||
opts.blacklist = transform._ensureTransformerNames("blacklist", opts.blacklist);
|
||||
opts.whitelist = transform._ensureTransformerNames("whitelist", opts.whitelist);
|
||||
opts.optional = transform._ensureTransformerNames("optional", opts.optional);
|
||||
|
||||
@@ -40,9 +40,11 @@ each(Buffer.prototype, function (fn, key) {
|
||||
});
|
||||
|
||||
CodeGenerator.normaliseOptions = function (code, opts) {
|
||||
var indent = detectIndent(code);
|
||||
var style = indent.indent;
|
||||
if (!style || style === " ") style = " ";
|
||||
var style = " ";
|
||||
if (code) {
|
||||
var style = detectIndent(code).indent;
|
||||
if (style && style !== " ") style = " ";
|
||||
}
|
||||
|
||||
return merge({
|
||||
parentheses: true,
|
||||
|
||||
@@ -7,6 +7,8 @@ var isFunction = require("lodash/lang/isFunction");
|
||||
|
||||
exports.version = require("../../package").version;
|
||||
|
||||
exports.runtime = require("./build-runtime");
|
||||
|
||||
exports.types = require("./types");
|
||||
|
||||
exports.register = function (opts) {
|
||||
|
||||
@@ -9,7 +9,8 @@
|
||||
"main": "lib/6to5/index.js",
|
||||
"bin": {
|
||||
"6to5": "./bin/6to5/index.js",
|
||||
"6to5-node": "./bin/6to5-node"
|
||||
"6to5-node": "./bin/6to5-node",
|
||||
"6to5-runtime": "./bin/6to5-runtime"
|
||||
},
|
||||
"browser": {
|
||||
"./lib/6to5/index.js": "./lib/6to5/browser.js",
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
"use strict";
|
||||
|
||||
var transform = require("../lib/6to5/transformation");
|
||||
var File = require("../lib/6to5/file");
|
||||
var util = require("../lib/6to5/util");
|
||||
var fs = require("fs");
|
||||
var t = require("../lib/6to5/types");
|
||||
var _ = require("lodash");
|
||||
var buildHelpers = require("../lib/6to5/build-helpers");
|
||||
var transform = require("../lib/6to5/transformation");
|
||||
var fs = require("fs");
|
||||
var t = require("../lib/6to5/types");
|
||||
var _ = require("lodash");
|
||||
|
||||
var relative = function (filename) {
|
||||
return __dirname + "/6to5-runtime/" + filename;
|
||||
@@ -35,12 +34,7 @@ var buildHelpers = function () {
|
||||
var body = [];
|
||||
var tree = t.program(body);
|
||||
|
||||
_.each(File.helpers, function (name) {
|
||||
var key = t.identifier(t.toIdentifier(name));
|
||||
body.push(t.expressionStatement(
|
||||
t.assignmentExpression("=", t.memberExpression(t.identifier("exports"), key), util.template(name))
|
||||
));
|
||||
});
|
||||
buildHelpers(body, t.identifier("exports"));
|
||||
|
||||
return transform.fromAst(tree, null, {
|
||||
optional: ["selfContained"]
|
||||
|
||||
Reference in New Issue
Block a user