Compare commits

...

29 Commits

Author SHA1 Message Date
Sebastian McKenzie
a4e528e2b3 v2.12.0 2015-01-14 10:14:14 +11:00
Sebastian McKenzie
99ca9b7e9a fix linting errors 2015-01-14 10:12:11 +11:00
Sebastian McKenzie
313e932e7c fix linting errors 2015-01-14 10:11:41 +11:00
Sebastian McKenzie
6a57a4e565 fix linting errors 2015-01-14 10:11:07 +11:00
Sebastian McKenzie
fc3a5f25fb add 2.12.0 changelog 2015-01-14 10:09:47 +11:00
Sebastian McKenzie
e258b85420 clean up loose template literals 2015-01-14 08:55:24 +11:00
Sebastian McKenzie
6b836de306 add #480 test 2015-01-14 07:56:45 +11:00
Sebastian McKenzie
fe6f53d471 Merge pull request #480 from monsanto/loose-templates
Add loose transform for tagged template literals
2015-01-14 07:54:19 +11:00
Sebastian McKenzie
3b259c6b1e clean up 6to5 register-browser 2015-01-14 07:31:51 +11:00
Sebastian McKenzie
2005df3fa2 support non-string jsx literals - fixes #479 2015-01-14 07:31:28 +11:00
Christopher Monsanto
4fdcf685d3 add loose transform for tagged template literals 2015-01-13 14:48:31 -05:00
Sebastian McKenzie
afd3af834d add loose option to computed property names 2015-01-14 00:35:45 +11:00
Sebastian McKenzie
8afec8b12a rename fast mode to loose #465 2015-01-14 00:24:34 +11:00
Sebastian McKenzie
f25ed0b5de add minimum of 1 newline after line comments - fixes #442 and fixes #477 2015-01-13 23:27:52 +11:00
Sebastian McKenzie
4898770d60 ignore test262 in istanbul 2015-01-13 23:27:26 +11:00
Sebastian McKenzie
bd2fa77446 fix fast forOf and add tests 2015-01-13 23:18:46 +11:00
Sebastian McKenzie
1c2bafe0e1 use assignment instead of define for fast classes 2015-01-13 23:18:38 +11:00
Sebastian McKenzie
f8915333b0 remove double spaces in version read in makefile 2015-01-13 22:44:26 +11:00
Sebastian McKenzie
f8275adc6f upgrade acorn-6to5 2015-01-13 22:44:06 +11:00
Sebastian McKenzie
2a97a4233d remove invalid jshint options 2015-01-13 22:26:33 +11:00
Sebastian McKenzie
70eae9f6ce remove functions inside of loops 2015-01-13 22:18:58 +11:00
Sebastian McKenzie
f560062d82 remove loopfunc: false from jshint - thanks @dcousens... 2015-01-13 22:02:30 +11:00
Sebastian McKenzie
0f55a66f5b add "fast" option for transformers 2015-01-13 22:02:04 +11:00
Sebastian McKenzie
f14f72b635 add --mangle option to uglify 2015-01-13 22:01:37 +11:00
Sebastian McKenzie
9aa010d987 v2.11.4 2015-01-13 20:15:35 +11:00
Sebastian McKenzie
bd179ace86 add 2.11.4 changelog 2015-01-13 20:08:38 +11:00
Sebastian McKenzie
4df6d6043e make dependency versions static - fixes #475 2015-01-13 20:07:34 +11:00
Sebastian McKenzie
7ed7475c46 v2.11.3 2015-01-13 14:35:14 +11:00
Sebastian McKenzie
b2dc560a2d allow a string to be passed as the optional option 2015-01-13 14:33:18 +11:00
71 changed files with 628 additions and 295 deletions

View File

@@ -5,7 +5,6 @@
"camelcase": true,
"unused": true,
"eqnull": true,
"proto": true,
"newcap": true,
"supernew": true,
"noyield": true,
@@ -14,8 +13,6 @@
"boss": true,
"expr": true,
"undef": true,
"loopfunc": true,
"white": true,
"maxparams": 5,
"maxdepth": 4,

View File

@@ -11,6 +11,25 @@
_Note: Gaps between patch versions are faulty/broken releases._
## 2.12.0
* **Bug Fix**
* Support non-string JSX literals.
* **New Feature**
* Loose mode for some transformers that enables non-spec behaviour.
* **Internal**
* Uglify `--mangle sort` has been added to the build script, cutting minified scripts in half.
## 2.11.4
* **Internal**
* Make all dependency versions fixed.
## 2.11.3
* **Bug Fix**
* Allow a string to be passed as the `optional` option.
## 2.11.2
* **Bug Fix**

View File

@@ -1,6 +1,6 @@
BROWSERIFY_CMD = node_modules/browserify/bin/cmd.js
ISTANBUL_CMD = node_modules/istanbul/lib/cli.js cover
UGLIFY_CMD = node_modules/uglify-js/bin/uglifyjs
UGLIFY_CMD = node_modules/uglify-js/bin/uglifyjs --mangle sort
JSHINT_CMD = node_modules/jshint/bin/jshint
MOCHA_CMD = node_modules/mocha/bin/_mocha
@@ -71,7 +71,7 @@ publish:
make test
read -p "Version: " version; \
read -p "Version: " version; \
npm version $$version --message "v%s"
make build

View File

@@ -18,6 +18,7 @@ commander.option("-m, --modules [modules]", "Module formatter type to use [commo
commander.option("-l, --whitelist [whitelist]", "Whitelist of transformers to ONLY use", util.list);
commander.option("-b, --blacklist [blacklist]", "Blacklist of transformers to NOT use", util.list);
commander.option("-i, --optional [list]", "List of optional transformers to enable", util.list);
commander.option("--loose [list]", "List of transformers to enable their loose mode", util.list);
commander.option("-o, --out-file [out]", "Compile all input files into a single file");
commander.option("-d, --out-dir [out]", "Compile an input directory of modules into an output directory");
commander.option("-c, --remove-comments", "Remove comments from the compiled code", false);
@@ -116,6 +117,7 @@ exports.opts = {
comments: !commander.removeComments,
runtime: commander.runtime,
modules: commander.modules,
loose: commander.loose,
format: {
indent: {
style: util.repeat(parseInt(commander.indent))

View File

@@ -24,6 +24,7 @@ File.helpers = [
"prototype-properties",
"apply-constructor",
"tagged-template-literal",
"tagged-template-literal-loose",
"interop-require",
"to-array",
"sliced-to-array",
@@ -41,7 +42,8 @@ File.helpers = [
File.excludeHelpersFromRuntime = [
"async-to-generator",
"typeof"
"typeof",
"tagged-template-literal-loose"
];
File.normaliseOptions = function (opts) {
@@ -63,6 +65,7 @@ File.normaliseOptions = function (opts) {
filename: "unknown",
modules: "common",
runtime: false,
loose: [],
code: true,
ast: true
});
@@ -72,6 +75,19 @@ File.normaliseOptions = function (opts) {
opts.blacklist = util.arrayify(opts.blacklist);
opts.whitelist = util.arrayify(opts.whitelist);
opts.optional = util.arrayify(opts.optional);
opts.loose = util.arrayify(opts.loose);
// todo: remove in 3.0.0
_.each({
fastForOf: "forOf",
classesFastSuper: "classes"
}, function (newTransformer, oldTransformer) {
if (_.contains(opts.optional, oldTransformer)) {
_.pull(opts.optional, oldTransformer);
opts.loose.push(newTransformer);
}
});
_.defaults(opts, {
moduleRoot: opts.sourceRoot
@@ -101,10 +117,15 @@ File.normaliseOptions = function (opts) {
transform._ensureTransformerNames("blacklist", opts.blacklist);
transform._ensureTransformerNames("whitelist", opts.whitelist);
transform._ensureTransformerNames("optional", opts.optional);
transform._ensureTransformerNames("loose", opts.loose);
return opts;
};
File.prototype.isLoose = function (key) {
return _.contains(this.opts.loose, key);
};
File.prototype.getTransformers = function () {
var file = this;
var transformers = [];

View File

@@ -47,7 +47,13 @@ Whitespace.prototype.getNewlinesAfter = function (node) {
if (endToken.type.type === "eof") {
return 1;
} else {
return this.getNewlinesBetween(startToken, endToken);
var lines = this.getNewlinesBetween(startToken, endToken);
if (node.type === "Line" && !lines) {
// line comment
return 1;
} else {
return lines;
}
}
};

View File

@@ -1,4 +1,5 @@
// Required to safely use 6to5/register within a browserify codebase.
// required to safely use 6to5/register within a browserify codebase
module.exports = function () {};
require("./polyfill");

View File

@@ -1,5 +0,0 @@
(function () {
if (SUPER_NAME != null) {
SUPER_NAME.apply(this, arguments);
}
});

View File

@@ -0,0 +1,3 @@
if (SUPER_NAME != null) {
SUPER_NAME.apply(this, arguments);
}

View File

@@ -0,0 +1,4 @@
(function (strings, raw) {
strings.raw = raw;
return strings;
});

View File

@@ -59,7 +59,6 @@ _.each({
arrayComprehension: require("./transformers/es7-array-comprehension"),
generatorComprehension: require("./transformers/es7-generator-comprehension"),
arrowFunctions: require("./transformers/es6-arrow-functions"),
classesFastSuper: require("./transformers/optional-classes-fast-super"),
classes: require("./transformers/es6-classes"),
objectSpread: require("./transformers/es7-object-spread"),
@@ -70,7 +69,6 @@ _.each({
computedPropertyNames: require("./transformers/es6-computed-property-names"),
destructuring: require("./transformers/es6-destructuring"),
defaultParameters: require("./transformers/es6-default-parameters"),
forOfFast: require("./transformers/optional-for-of-fast"),
forOf: require("./transformers/es6-for-of"),
unicodeRegex: require("./transformers/es6-unicode-regex"),
abstractReferences: require("./transformers/es7-abstract-references"),

View File

@@ -33,6 +33,7 @@ function Class(node, file, scope, isStatement) {
this.hasConstructor = false;
this.className = node.id || file.generateUidIdentifier("class", scope);
this.superName = node.superClass;
this.isLoose = file.isLoose("classes");
}
/**
@@ -117,27 +118,31 @@ Class.prototype.buildBody = function () {
var superName = this.superName;
var classBody = this.node.body.body;
var body = this.body;
var self = this;
for (var i in classBody) {
var node = classBody[i];
if (t.isMethodDefinition(node)) {
self.replaceInstanceSuperReferences(node);
this.replaceInstanceSuperReferences(node);
if (node.key.name === "constructor") {
self.pushConstructor(node);
this.pushConstructor(node);
} else {
self.pushMethod(node);
this.pushMethod(node);
}
} else if (t.isPrivateDeclaration(node)) {
self.closure = true;
this.closure = true;
body.unshift(node);
}
}
// we have no constructor, we have a super, and the super doesn't appear to be falsy
if (!this.hasConstructor && superName && !t.isFalsyExpression(superName)) {
constructor.body.body.push(util.template("class-super-constructor-call", {
CLASS_NAME: className
var defaultConstructorTemplate = "class-super-constructor-call";
if (this.isLoose) defaultConstructorTemplate += "-loose";
constructor.body.body.push(util.template(defaultConstructorTemplate, {
CLASS_NAME: className,
SUPER_NAME: this.superName
}, true));
}
@@ -183,6 +188,19 @@ Class.prototype.pushMethod = function (node) {
}
if (kind === "") {
if (this.isLoose) {
// use assignments instead of define properties for loose classes
var className = this.className;
if (!node.static) className = t.memberExpression(className, t.identifier("prototype"));
methodName = t.memberExpression(className, methodName, node.computed);
var expr = t.expressionStatement(t.assignmentExpression("=", methodName, node.value));
t.inheritsComments(expr, node);
this.body.push(expr);
return;
}
kind = "value";
}
@@ -219,6 +237,47 @@ Class.prototype.superProperty = function (property, isStatic, isComputed, thisEx
);
};
/**
* Description
*
* @param {Object} node
* @param {Object} id
* @param {Object} parent
* @returns {Object}
*/
Class.prototype.looseSuperProperty = function (methodNode, id, parent) {
var methodName = methodNode.key;
var superName = this.superName || t.identifier("Function");
if (parent.property === id) {
return;
} else if (t.isCallExpression(parent, { callee: id })) {
// super(); -> ClassName.prototype.MethodName.call(this);
parent.arguments.unshift(t.thisExpression());
if (methodName.name === "constructor") {
// constructor() { super(); }
return t.memberExpression(superName, t.identifier("call"));
} else {
id = superName;
// foo() { super(); }
if (!methodNode.static) {
id = t.memberExpression(id, t.identifier("prototype"));
}
id = t.memberExpression(id, methodName, methodNode.computed);
return t.memberExpression(id, t.identifier("call"));
}
} else if (t.isMemberExpression(parent) && !methodNode.static) {
// super.test -> ClassName.prototype.test
return t.memberExpression(superName, t.identifier("prototype"));
} else {
return superName;
}
};
/**
* Replace all `super` references with a reference to our `superClass`.
*
@@ -231,7 +290,7 @@ Class.prototype.replaceInstanceSuperReferences = function (methodNode) {
var topLevelThisReference;
traverse2(method, true);
traverseLevel(method, true);
if (topLevelThisReference) {
method.body.body.unshift(t.variableDeclaration("var", [
@@ -239,75 +298,100 @@ Class.prototype.replaceInstanceSuperReferences = function (methodNode) {
]));
}
function traverse2(node, topLevel) {
function traverseLevel(node, topLevel) {
traverse(node, {
enter: function (node, parent) {
if (t.isFunction(node) && !t.isArrowFunctionExpression(node)) {
traverse2(node, false);
// we need to call traverseLevel again so we're context aware
traverseLevel(node, false);
return this.skip();
}
var property;
var computed;
var args;
if (t.isIdentifier(node, { name: "super" })) {
if (!(t.isMemberExpression(parent) && !parent.computed && parent.property === node)) {
throw self.file.errorWithNode(node, "illegal use of bare super");
}
} else if (t.isCallExpression(node)) {
var callee = node.callee;
if (t.isIdentifier(callee, { name: "super" })) {
// super(); -> _get(Object.getPrototypeOf(ClassName), "MethodName", this).call(this);
property = methodNode.key;
computed = methodNode.computed;
args = node.arguments;
} else {
if (!t.isMemberExpression(callee)) return;
if (callee.object.name !== "super") return;
// super.test(); -> _get(Object.getPrototypeOf(ClassName.prototype), "test", this).call(this);
property = callee.property;
computed = callee.computed;
args = node.arguments;
}
} else if (t.isMemberExpression(node)) {
if (!t.isIdentifier(node.object, { name: "super" })) return;
// super.name; -> _get(Object.getPrototypeOf(ClassName.prototype), "name", this);
property = node.property;
computed = node.computed;
}
if (property) {
var thisReference;
var getThisReference = function () {
if (topLevel) {
thisReference = t.thisExpression();
// top level so `this` is the instance
return t.thisExpression();
} else {
topLevelThisReference = thisReference = topLevelThisReference || self.file.generateUidIdentifier("this");
// not in the top level so we need to create a reference
return topLevelThisReference = topLevelThisReference || self.file.generateUidIdentifier("this");
}
};
var superProperty = self.superProperty(property, methodNode.static, computed, thisReference);
if (args) {
if (args.length === 1 && t.isSpreadElement(args[0])) {
// super(...arguments);
return t.callExpression(
t.memberExpression(superProperty, t.identifier("apply"), false),
[thisReference, args[0].argument]
);
} else {
return t.callExpression(
t.memberExpression(superProperty, t.identifier("call"), false),
[thisReference].concat(args)
);
}
} else {
return superProperty;
}
}
var callback = specHandle;
if (self.isLoose) callback = looseHandle;
return callback(getThisReference, node, parent);
}
});
}
function looseHandle(getThisReference, node, parent) {
if (t.isIdentifier(node, { name: "super" })) {
return self.looseSuperProperty(methodNode, node, parent);
} else if (t.isCallExpression(node)) {
var callee = node.callee;
if (!t.isMemberExpression(callee)) return;
if (callee.object.name !== "super") return;
// super.test(); -> ClassName.prototype.MethodName.call(this);
t.appendToMemberExpression(callee, t.identifier("call"));
node.arguments.unshift(getThisReference());
}
}
function specHandle(getThisReference, node, parent) {
var property;
var computed;
var args;
if (t.isIdentifier(node, { name: "super" })) {
if (!(t.isMemberExpression(parent) && !parent.computed && parent.property === node)) {
throw self.file.errorWithNode(node, "illegal use of bare super");
}
} else if (t.isCallExpression(node)) {
var callee = node.callee;
if (t.isIdentifier(callee, { name: "super" })) {
// super(); -> _get(Object.getPrototypeOf(ClassName), "MethodName", this).call(this);
property = methodNode.key;
computed = methodNode.computed;
args = node.arguments;
} else {
if (!t.isMemberExpression(callee)) return;
if (callee.object.name !== "super") return;
// super.test(); -> _get(Object.getPrototypeOf(ClassName.prototype), "test", this).call(this);
property = callee.property;
computed = callee.computed;
args = node.arguments;
}
} else if (t.isMemberExpression(node)) {
if (!t.isIdentifier(node.object, { name: "super" })) return;
// super.name; -> _get(Object.getPrototypeOf(ClassName.prototype), "name", this);
property = node.property;
computed = node.computed;
}
if (!property) return;
var thisReference = getThisReference();
var superProperty = self.superProperty(property, methodNode.static, computed, thisReference);
if (args) {
if (args.length === 1 && t.isSpreadElement(args[0])) {
// super(...arguments);
return t.callExpression(
t.memberExpression(superProperty, t.identifier("apply")),
[thisReference, args[0].argument]
);
} else {
return t.callExpression(
t.memberExpression(superProperty, t.identifier("call")),
[thisReference].concat(args)
);
}
} else {
return superProperty;
}
}
};
/**

View File

@@ -2,28 +2,63 @@ var t = require("../../types");
exports.ObjectExpression = function (node, parent, file, scope) {
var hasComputed = false;
var prop;
var key;
var i;
for (i in node.properties) {
for (var i in node.properties) {
hasComputed = t.isProperty(node.properties[i], { computed: true, kind: "init" });
if (hasComputed) break;
}
if (!hasComputed) return;
var initProps = [];
var objId = scope.generateUidBasedOnNode(parent, file);
//
var body = [];
var container = t.functionExpression(null, [], t.blockStatement(body));
container._aliasFunction = true;
//
var callback = spec;
if (file.isLoose("computedPropertyNames")) callback = loose;
var result = callback(node, body, objId, initProps, file);
if (result) return result;
//
body.unshift(t.variableDeclaration("var", [
t.variableDeclarator(objId, t.objectExpression(initProps))
]));
body.push(t.returnStatement(objId));
return t.callExpression(container, []);
};
var loose = function (node, body, objId) {
for (var i in node.properties) {
var prop = node.properties[i];
body.push(t.expressionStatement(
t.assignmentExpression(
"=",
t.memberExpression(objId, prop.key, prop.computed),
prop.value
)
));
}
};
var spec = function (node, body, objId, initProps, file) {
var props = node.properties;
var prop, key;
// normalise key
for (i in props) {
for (var i in props) {
prop = props[i];
if (prop.kind !== "init") continue;
@@ -36,7 +71,6 @@ exports.ObjectExpression = function (node, parent, file, scope) {
// add all non-computed properties and `__proto__` properties to the initializer
var initProps = [];
var broken = false;
for (i in props) {
@@ -86,14 +120,4 @@ exports.ObjectExpression = function (node, parent, file, scope) {
return first;
}
}
//
body.unshift(t.variableDeclaration("var", [
t.variableDeclarator(objId, t.objectExpression(initProps))
]));
body.push(t.returnStatement(objId));
return t.callExpression(container, []);
};

View File

@@ -1,7 +1,6 @@
var traverse = require("../../traverse");
var util = require("../../util");
var t = require("../../types");
var _ = require("lodash");
exports.Function = function (node, parent, file, scope) {
if (!node.defaults || !node.defaults.length) return;
@@ -15,6 +14,23 @@ exports.Function = function (node, parent, file, scope) {
var i;
var def;
var checkTDZ = function (ids) {
var check = function (node, parent) {
if (!t.isIdentifier(node) || !t.isReferenced(node, parent)) return;
if (ids.indexOf(node.name) >= 0) {
throw file.errorWithNode(node, "Temporal dead zone - accessing a variable before it's initialized");
}
if (scope.has(node.name, true)) {
iife = true;
}
};
check(def, node);
traverse(def, { enter: check });
};
for (i in node.defaults) {
def = node.defaults[i];
if (!def) continue;
@@ -23,22 +39,10 @@ exports.Function = function (node, parent, file, scope) {
// temporal dead zone check - here we prevent accessing of params that
// are to the right - ie. uninitialized parameters
_.each(ids.slice(i), function (ids) {
var check = function (node, parent) {
if (!t.isIdentifier(node) || !t.isReferenced(node, parent)) return;
if (ids.indexOf(node.name) >= 0) {
throw file.errorWithNode(node, "Temporal dead zone - accessing a variable before it's initialized");
}
if (scope.has(node.name, true)) {
iife = true;
}
};
check(def, node);
traverse(def, { enter: check });
});
var rightIds = ids.slice(i);
for (i in rightIds) {
checkTDZ(rightIds[i]);
}
// we're accessing a variable that's already defined within this function
var has = scope.get(param.name);

View File

@@ -2,6 +2,68 @@ var util = require("../../util");
var t = require("../../types");
exports.ForOfStatement = function (node, parent, file, scope) {
var callback = spec;
if (file.isLoose("forOf")) callback = loose;
var build = callback(node, parent, file, scope);
var declar = build.declar;
var loop = build.loop;
var block = loop.body;
// inherit comments from the original loop
t.inheritsComments(loop, node);
// ensure that it's a block so we can take all it's statemetns
t.ensureBlock(node);
// add the value declaration to the new loop body
if (declar){
if (build.shouldUnshift) {
block.body.unshift(declar);
} else {
block.body.push(declar);
}
}
// push the rest of the original loop body onto our new body
block.body = block.body.concat(node.body.body);
return loop;
};
var loose = function (node, parent, file, scope) {
var left = node.left;
var declar, id;
if (t.isIdentifier(left) || t.isPattern(left)) {
// for (i of test), for ({ i } of test)
id = left;
} else if (t.isVariableDeclaration(left)) {
// for (var i of test)
id = left.declarations[0].id;
declar = t.variableDeclaration(left.kind, [
t.variableDeclarator(id)
]);
} else {
throw file.errorWithNode(left, "Unknown node type " + left.type + " in ForOfStatement");
}
var loop = util.template("for-of-loose", {
LOOP_OBJECT: file.generateUidIdentifier("iterator", scope),
IS_ARRAY: file.generateUidIdentifier("isArray", scope),
OBJECT: node.right,
INDEX: file.generateUidIdentifier("i", scope),
ID: id
});
return {
shouldUnshift: true,
declar: declar,
loop: loop
};
};
var spec = function (node, parent, file, scope) {
var left = node.left;
var declar;
@@ -9,8 +71,10 @@ exports.ForOfStatement = function (node, parent, file, scope) {
var stepValue = t.memberExpression(stepKey, t.identifier("value"));
if (t.isIdentifier(left) || t.isPattern(left)) {
// for (i of test), for ({ i } of test)
declar = t.expressionStatement(t.assignmentExpression("=", left, stepValue));
} else if (t.isVariableDeclaration(left)) {
// for (var i of test)
declar = t.variableDeclaration(left.kind, [
t.variableDeclarator(left.declarations[0].id, stepValue)
]);
@@ -18,18 +82,14 @@ exports.ForOfStatement = function (node, parent, file, scope) {
throw file.errorWithNode(left, "Unknown node type " + left.type + " in ForOfStatement");
}
var node2 = util.template("for-of", {
var loop = util.template("for-of", {
ITERATOR_KEY: file.generateUidIdentifier("iterator", scope),
STEP_KEY: stepKey,
OBJECT: node.right
});
t.inheritsComments(node2, node);
t.ensureBlock(node);
var block = node2.body;
block.body.push(declar);
block.body = block.body.concat(node.body.body);
return node2;
return {
declar: declar,
loop: loop
};
};

View File

@@ -250,10 +250,11 @@ LetScoping.prototype.getInfo = function () {
declar = block.body[i];
if (!isLet(declar, block)) continue;
_.each(t.getIds(declar, true), function (id, key) {
duplicates(id, key);
var declars = t.getIds(declar, true);
for (var key in declars) {
duplicates(declars[key], key);
opts.keys.push(key);
});
}
}
return opts;

View File

@@ -17,10 +17,12 @@ exports.TaggedTemplateExpression = function (node, parent, file) {
raw.push(t.literal(elem.value.raw));
}
args.push(t.callExpression(file.addHelper("tagged-template-literal"), [
t.arrayExpression(strings),
t.arrayExpression(raw)
]));
strings = t.arrayExpression(strings);
raw = t.arrayExpression(raw);
var templateName = "tagged-template-literal";
if (file.isLoose("templateLiterals")) templateName += "-loose";
args.push(t.callExpression(file.addHelper(templateName), [strings, raw]));
args = args.concat(quasi.expressions);

View File

@@ -1,74 +0,0 @@
var traverse = require("../../traverse");
var util = require("../../util");
var t = require("../../types");
exports.optional = true;
exports.Class = function (node) {
var superClass = node.superClass || t.identifier("Function");
var hasConstructor = false;
var body = node.body.body;
for (var i in body) {
var methodNode = body[i];
hasConstructor = hasConstructor || methodNode.key.name === "constructor";
traverse(methodNode, {
enter: function (node, parent) {
if (t.isIdentifier(node, { name: "super" })) {
return superIdentifier(superClass, methodNode, node, parent);
} else if (t.isCallExpression(node)) {
var callee = node.callee;
if (!t.isMemberExpression(callee)) return;
if (callee.object.name !== "super") return;
// super.test(); -> ClassName.prototype.MethodName.call(this);
t.appendToMemberExpression(callee, t.identifier("call"));
node.arguments.unshift(t.thisExpression());
}
}
});
}
if (node.superClass && !hasConstructor) {
body.unshift(t.methodDefinition(
t.identifier("constructor"),
util.template("class-super-constructor-call-fast", {
SUPER_NAME: superClass
})
));
}
};
var superIdentifier = function (superClass, methodNode, id, parent) {
var methodName = methodNode.key;
if (parent.property === id) {
return;
} else if (t.isCallExpression(parent, { callee: id })) {
// super(); -> ClassName.prototype.MethodName.call(this);
parent.arguments.unshift(t.thisExpression());
if (methodName.name === "constructor") {
// constructor() { super(); }
return t.memberExpression(superClass, t.identifier("call"));
} else {
id = superClass;
// foo() { super(); }
if (!methodNode.static) {
id = t.memberExpression(id, t.identifier("prototype"));
}
id = t.memberExpression(id, methodName, methodNode.computed);
return t.memberExpression(id, t.identifier("call"));
}
} else if (t.isMemberExpression(parent) && !methodNode.static) {
// super.test -> ClassName.prototype.test
return t.memberExpression(superClass, t.identifier("prototype"));
} else {
return superClass;
}
};

View File

@@ -1,37 +0,0 @@
var util = require("../../util");
var t = require("../../types");
exports.optional = true;
exports.ForOfStatement = function (node, parent, file, scope) {
var left = node.left;
var declar, id;
if (t.isIdentifier(left) || t.isPattern(left)) {
id = left;
} else if (t.isVariableDeclaration(left)) {
id = left.declarations[0].id;
declar = t.variableDeclaration(left.kind, [
t.variableDeclarator(id)
]);
} else {
throw file.errorWithNode(left, "Unknown node type " + left.type + " in ForOfStatement");
}
var node2 = util.template("for-of-fast", {
LOOP_OBJECT: file.generateUidIdentifier("loopObject", scope),
IS_ARRAY: file.generateUidIdentifier("isArray", scope),
OBJECT: node.right,
INDEX: file.generateUidIdentifier("i", scope),
ID: id
});
t.inheritsComments(node2, node);
t.ensureBlock(node);
var block = node2.body;
if (declar) block.body.unshift(declar);
block.body = block.body.concat(node.body.body);
return node2;
};

View File

@@ -5,6 +5,7 @@
var esutils = require("esutils");
var t = require("../../types");
var _ = require("lodash");
exports.XJSIdentifier = function (node) {
if (esutils.keyword.isIdentifierName(node.name)) {
@@ -138,7 +139,7 @@ exports.XJSElement = {
for (i in node.children) {
var child = node.children[i];
if (t.isLiteral(child)) {
if (t.isLiteral(child) && _.isString(child.value)) {
var lines = child.value.split(/\r\n|\n|\r/);
for (i in lines) {

View File

@@ -1,7 +1,7 @@
{
"name": "6to5",
"description": "Turn ES6 code into readable vanilla ES5 with source maps",
"version": "2.11.2",
"version": "2.12.0",
"author": "Sebastian McKenzie <sebmck@gmail.com>",
"homepage": "https://github.com/6to5/6to5",
"repository": {
@@ -39,36 +39,36 @@
"test": "make test"
},
"dependencies": {
"acorn-6to5": "0.11.1-13",
"acorn-6to5": "0.11.1-14",
"ast-types": "~0.6.1",
"chokidar": "0.11.1",
"commander": "2.5.0",
"core-js": "^0.4.4",
"core-js": "0.4.4",
"estraverse": "1.8.0",
"esutils": "1.1.6",
"esvalid": "^1.1.0",
"esvalid": "1.1.0",
"fs-readdir-recursive": "0.1.0",
"jshint": "^2.5.10",
"jshint": "2.5.10",
"lodash": "2.4.1",
"mkdirp": "0.5.0",
"private": "0.1.6",
"regenerator": "^0.8.3",
"regenerator": "0.8.3",
"regexpu": "0.3.0",
"roadrunner": "^1.0.4",
"roadrunner": "1.0.4",
"source-map": "0.1.40",
"source-map-support": "0.2.8"
},
"devDependencies": {
"browserify": "6.3.2",
"chai": "^1.9.2",
"chai": "1.9.2",
"istanbul": "0.3.2",
"jshint-stylish": "^1.0.0",
"jshint-stylish": "1.0.0",
"matcha": "0.6.0",
"mocha": "1.21.4",
"rimraf": "2.2.8",
"uglify-js": "2.4.15"
},
"optionalDependencies": {
"kexec": "^0.2.0"
"kexec": "0.2.0"
}
}

View File

@@ -1,5 +1,4 @@
// skip these tests under instanbul since they're useless
if (process.env.running_under_istanbul === '1') return;
if (process.env.running_under_istanbul) return;
var readdir = require("fs-readdir-recursive");
var helper = require("./_helper");

View File

@@ -37,31 +37,21 @@ var Test = (function (Foo) {
_inherits(Test, Foo);
_prototypeProperties(Test, {
foo: {
value: function () {
var _Foo$foo, _Foo$foo2;
Foo.foo.call(this);
(_Foo$foo = Foo.foo).call.apply(_Foo$foo, [this].concat(_slice.call(arguments)));
(_Foo$foo2 = Foo.foo).call.apply(_Foo$foo2, [this, "test"].concat(_slice.call(arguments)));
},
writable: true,
enumerable: true,
configurable: true
}
}, {
test: {
value: function () {
var _Foo$prototype$test3, _Foo$prototype$test4;
Foo.prototype.test.call(this);
(_Foo$prototype$test3 = Foo.prototype.test).call.apply(_Foo$prototype$test3, [this].concat(_slice.call(arguments)));
(_Foo$prototype$test4 = Foo.prototype.test).call.apply(_Foo$prototype$test4, [this, "test"].concat(_slice.call(arguments)));
},
writable: true,
enumerable: true,
configurable: true
}
});
Test.prototype.test = function () {
var _Foo$prototype$test3, _Foo$prototype$test4;
Foo.prototype.test.call(this);
(_Foo$prototype$test3 = Foo.prototype.test).call.apply(_Foo$prototype$test3, [this].concat(_slice.call(arguments)));
(_Foo$prototype$test4 = Foo.prototype.test).call.apply(_Foo$prototype$test4, [this, "test"].concat(_slice.call(arguments)));
};
Test.foo = function () {
var _Foo$foo, _Foo$foo2;
Foo.foo.call(this);
(_Foo$foo = Foo.foo).call.apply(_Foo$foo, [this].concat(_slice.call(arguments)));
(_Foo$foo2 = Foo.foo).call.apply(_Foo$foo2, [this, "test"].concat(_slice.call(arguments)));
};
_prototypeProperties(Test, {}, {});
return Test;
})(Foo);

View File

@@ -28,16 +28,11 @@ var Test = (function (Foo) {
_inherits(Test, Foo);
_prototypeProperties(Test, {
test: {
value: function () {
return Foo.wow.call(this);
},
writable: true,
enumerable: true,
configurable: true
}
});
Test.test = function () {
return Foo.wow.call(this);
};
_prototypeProperties(Test, {});
return Test;
})(Foo);

View File

@@ -0,0 +1,3 @@
{
"loose": ["classes"]
}

View File

@@ -17,8 +17,8 @@ var _inherits = function (subClass, superClass) {
var BaseController = (function (_Chaplin$Controller) {
function BaseController() {
if (Chaplin.Controller != null) {
Chaplin.Controller.apply(this, arguments);
if (_Chaplin$Controller != null) {
_Chaplin$Controller.apply(this, arguments);
}
}
@@ -29,8 +29,8 @@ var BaseController = (function (_Chaplin$Controller) {
var BaseController2 = (function (_Chaplin$Controller$Another) {
function BaseController2() {
if (Chaplin.Controller.Another != null) {
Chaplin.Controller.Another.apply(this, arguments);
if (_Chaplin$Controller$Another != null) {
_Chaplin$Controller$Another.apply(this, arguments);
}
}

View File

@@ -0,0 +1,3 @@
foo({
[bar]: "foobar"
});

View File

@@ -0,0 +1,8 @@
"use strict";
foo((function () {
var _foo = {};
_foo[bar] = "foobar";
return _foo;
})());

View File

@@ -0,0 +1,3 @@
foo = {
[bar]: "foobar"
};

View File

@@ -0,0 +1,8 @@
"use strict";
foo = (function () {
var _foo = {};
_foo[bar] = "foobar";
return _foo;
})();

View File

@@ -0,0 +1,3 @@
var foo = {
[Symbol.iterator]: "foobar"
};

View File

@@ -0,0 +1,8 @@
"use strict";
var foo = (function () {
var _foo = {};
_foo[Symbol.iterator] = "foobar";
return _foo;
})();

View File

@@ -0,0 +1,5 @@
var obj = {
[foobar]() {
return "foobar";
}
};

View File

@@ -0,0 +1,11 @@
"use strict";
var obj = (function () {
var _obj = {};
_obj[foobar] = function () {
return "foobar";
};
return _obj;
})();

View File

@@ -0,0 +1,6 @@
var obj = {
["x" + foo]: "heh",
["y" + bar]: "noo",
foo: "foo",
bar: "bar"
};

View File

@@ -0,0 +1,11 @@
"use strict";
var obj = (function () {
var _obj = {};
_obj["x" + foo] = "heh";
_obj["y" + bar] = "noo";
_obj.foo = "foo";
_obj.bar = "bar";
return _obj;
})();

View File

@@ -0,0 +1,4 @@
var obj = {
["x" + foo]: "heh",
["y" + bar]: "noo"
};

View File

@@ -0,0 +1,9 @@
"use strict";
var obj = (function () {
var _obj = {};
_obj["x" + foo] = "heh";
_obj["y" + bar] = "noo";
return _obj;
})();

View File

@@ -0,0 +1,3 @@
{
"loose": ["computedPropertyNames"]
}

View File

@@ -0,0 +1,3 @@
var obj = {
["x" + foo]: "heh"
};

View File

@@ -0,0 +1,8 @@
"use strict";
var obj = (function () {
var _obj = {};
_obj["x" + foo] = "heh";
return _obj;
})();

View File

@@ -0,0 +1,3 @@
var obj = {
["x" + this.foo]: "heh"
};

View File

@@ -0,0 +1,9 @@
"use strict";
var _this = this;
var obj = (function () {
var _obj = {};
_obj["x" + _this.foo] = "heh";
return _obj;
})();

View File

@@ -0,0 +1,4 @@
var obj = {
first: "first",
["second"]: "second",
};

View File

@@ -0,0 +1,9 @@
"use strict";
var obj = (function () {
var _obj = {};
_obj.first = "first";
_obj.second = "second";
return _obj;
})();

View File

@@ -0,0 +1,3 @@
var foo = {
[bar]: "foobar"
};

View File

@@ -0,0 +1,8 @@
"use strict";
var foo = (function () {
var _foo = {};
_foo[bar] = "foobar";
return _foo;
})();

View File

@@ -0,0 +1,3 @@
for (i of arr) {
}

View File

@@ -0,0 +1,15 @@
"use strict";
for (var _iterator = arr,
_isArray = Array.isArray(_iterator),
_i = 0,
_iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
if (_isArray) {
if (_i >= _iterator.length) break;
i = _iterator[_i++];
} else {
_i = _iterator.next();
if (_i.done) break;
i = _i.value;
}
}

View File

@@ -0,0 +1,3 @@
for (let i of arr) {
}

View File

@@ -0,0 +1,16 @@
"use strict";
for (var _iterator = arr,
_isArray = Array.isArray(_iterator),
_i = 0,
_iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
var i = undefined;
if (_isArray) {
if (_i >= _iterator.length) break;
i = _iterator[_i++];
} else {
_i = _iterator.next();
if (_i.done) break;
i = _i.value;
}
}

View File

@@ -0,0 +1,7 @@
for (var i of arr) {
}
for (var i of numbers) {
}

View File

@@ -0,0 +1,31 @@
"use strict";
for (var _iterator = arr,
_isArray = Array.isArray(_iterator),
_i = 0,
_iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
var i;
if (_isArray) {
if (_i >= _iterator.length) break;
i = _iterator[_i++];
} else {
_i = _iterator.next();
if (_i.done) break;
i = _i.value;
}
}
for (var _iterator2 = numbers,
_isArray2 = Array.isArray(_iterator2),
_i2 = 0,
_iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) {
var i;
if (_isArray2) {
if (_i2 >= _iterator2.length) break;
i = _iterator2[_i2++];
} else {
_i2 = _iterator2.next();
if (_i2.done) break;
i = _i2.value;
}
}

View File

@@ -0,0 +1,3 @@
{
"loose": ["forOf"]
}

View File

@@ -0,0 +1,3 @@
for (var i of arr) {
}

View File

@@ -0,0 +1,16 @@
"use strict";
for (var _iterator = arr,
_isArray = Array.isArray(_iterator),
_i = 0,
_iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
var i;
if (_isArray) {
if (_i >= _iterator.length) break;
i = _iterator[_i++];
} else {
_i = _iterator.next();
if (_i.done) break;
i = _i.value;
}
}

View File

@@ -0,0 +1 @@
var foo = bar`wow\na${ 42 }b ${_.foobar()}`;

View File

@@ -0,0 +1,8 @@
"use strict";
var _taggedTemplateLiteralLoose = function (strings, raw) {
strings.raw = raw;
return strings;
};
var foo = bar(_taggedTemplateLiteralLoose(["wow\na", "b ", ""], ["wow\\na", "b ", ""]), 42, _.foobar());

View File

@@ -0,0 +1,3 @@
{
"loose": ["templateLiterals"]
}

View File

@@ -1,3 +0,0 @@
{
"optional": ["classesFastSuper"]
}

View File

@@ -1,4 +1,4 @@
if (process.env.SIMPLE_6TO5_TESTS) return;
if (process.env.SIMPLE_6TO5_TESTS || process.env.running_under_istanbul) return;
var transform = require("../lib/6to5/transformation/transform");
var readdir = require("fs-readdir-recursive");