Compare commits
45 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e01b7d288f | ||
|
|
98c0e185b8 | ||
|
|
bf66d78210 | ||
|
|
b60eca0a76 | ||
|
|
44f06c0b4c | ||
|
|
6c5606b7e8 | ||
|
|
07ddfbeb5d | ||
|
|
87b890c172 | ||
|
|
245fcfe110 | ||
|
|
4744719040 | ||
|
|
a3b814a897 | ||
|
|
f5f17f0ccb | ||
|
|
f6a2acdfb1 | ||
|
|
e8dba2ad1e | ||
|
|
8ce5c5b608 | ||
|
|
0dfea1a51b | ||
|
|
a4e528e2b3 | ||
|
|
99ca9b7e9a | ||
|
|
313e932e7c | ||
|
|
6a57a4e565 | ||
|
|
fc3a5f25fb | ||
|
|
e258b85420 | ||
|
|
6b836de306 | ||
|
|
fe6f53d471 | ||
|
|
3b259c6b1e | ||
|
|
2005df3fa2 | ||
|
|
4fdcf685d3 | ||
|
|
afd3af834d | ||
|
|
8afec8b12a | ||
|
|
f25ed0b5de | ||
|
|
4898770d60 | ||
|
|
bd2fa77446 | ||
|
|
1c2bafe0e1 | ||
|
|
f8915333b0 | ||
|
|
f8275adc6f | ||
|
|
2a97a4233d | ||
|
|
70eae9f6ce | ||
|
|
f560062d82 | ||
|
|
0f55a66f5b | ||
|
|
f14f72b635 | ||
|
|
9aa010d987 | ||
|
|
bd179ace86 | ||
|
|
4df6d6043e | ||
|
|
7ed7475c46 | ||
|
|
b2dc560a2d |
@@ -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,
|
||||
|
||||
|
||||
35
CHANGELOG.md
35
CHANGELOG.md
@@ -11,6 +11,41 @@
|
||||
|
||||
_Note: Gaps between patch versions are faulty/broken releases._
|
||||
|
||||
## 2.12.3
|
||||
|
||||
* **Spec Compliancy**
|
||||
* Optional `typeof` transformer checks for `undefined` before passing it to the helper.
|
||||
* Class methods are now named.
|
||||
|
||||
## 2.12.2
|
||||
|
||||
* **Internal**
|
||||
* Exclude nodes in function parameters and catch clauses from `isReferenced` check.
|
||||
|
||||
## 2.12.1
|
||||
|
||||
* **Internal**
|
||||
* Add `.jsx` to list of allowed extensions.
|
||||
|
||||
## 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**
|
||||
|
||||
4
Makefile
4
Makefile
@@ -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
|
||||
|
||||
2
NOTES.md
2
NOTES.md
@@ -10,4 +10,4 @@
|
||||
* Split up ES5 getter/setter transforming and ES6 property methods into separate transformers.
|
||||
* Add autoindentation.
|
||||
* Move `super` transformation from classes into a separate transformer that also supports object expressions.
|
||||
* Prefix all fast transformers with `fast`, make them declare that they're a fast transformer similar to optional transformers and add a `--fast` flag to enable them all.
|
||||
* Remove fast transformer backwards compatibility.
|
||||
|
||||
@@ -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))
|
||||
|
||||
@@ -96,8 +96,8 @@ function replEval(code, context, filename, callback) {
|
||||
var result;
|
||||
|
||||
try {
|
||||
if (/^\((.*?)\n\)$/.test(code)) {
|
||||
code = code.slice(1, -2); // remove "(" and "\n)"
|
||||
if (code[0] === "(" && code[code.length - 1] === ")") {
|
||||
code = code.slice(1, -1); // remove "(" and ")"
|
||||
}
|
||||
|
||||
result = _eval(code, filename);
|
||||
|
||||
@@ -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 = [];
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -123,7 +123,7 @@ var hookExtensions = function (_exts) {
|
||||
});
|
||||
};
|
||||
|
||||
hookExtensions([".es6", ".es", ".js"]);
|
||||
hookExtensions(util.canCompile.EXTENSIONS);
|
||||
|
||||
module.exports = function (opts) {
|
||||
// normalise options
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
(function () {
|
||||
if (SUPER_NAME != null) {
|
||||
SUPER_NAME.apply(this, arguments);
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,3 @@
|
||||
if (SUPER_NAME != null) {
|
||||
SUPER_NAME.apply(this, arguments);
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
(function (strings, raw) {
|
||||
strings.raw = raw;
|
||||
return strings;
|
||||
});
|
||||
@@ -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"),
|
||||
|
||||
@@ -65,7 +65,7 @@ Transformer.prototype.transform = function (file) {
|
||||
if (exit) fn = fns.exit;
|
||||
if (!fn) return;
|
||||
|
||||
return fn(node, parent, file, scope);
|
||||
return fn.call(this, node, parent, file, scope);
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -1,12 +1,24 @@
|
||||
var traverse = require("../../traverse");
|
||||
var util = require("../../util");
|
||||
var t = require("../../types");
|
||||
var propertyMethodAssignment = require("./es6-property-method-assignment");
|
||||
var traverse = require("../../traverse");
|
||||
var util = require("../../util");
|
||||
var t = require("../../types");
|
||||
|
||||
exports.ClassDeclaration = function (node, parent, file, scope) {
|
||||
return new Class(node, file, scope, true).run();
|
||||
};
|
||||
|
||||
exports.ClassExpression = function (node, parent, file, scope) {
|
||||
if (!node.id) {
|
||||
if (t.isProperty(parent) && parent.value === node && !parent.computed && t.isIdentifier(parent.key)) {
|
||||
// var o = { foo: class {} };
|
||||
node.id = parent.key;
|
||||
}
|
||||
|
||||
if (t.isVariableDeclarator(parent)) {
|
||||
node.id = parent.id;
|
||||
}
|
||||
}
|
||||
|
||||
return new Class(node, file, scope, false).run();
|
||||
};
|
||||
|
||||
@@ -33,6 +45,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 +130,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));
|
||||
}
|
||||
|
||||
@@ -174,6 +191,26 @@ Class.prototype.pushMethod = function (node) {
|
||||
var methodName = node.key;
|
||||
|
||||
var kind = node.kind;
|
||||
|
||||
if (kind === "") {
|
||||
propertyMethodAssignment._namedMethod(node, this.file, this.scope);
|
||||
|
||||
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";
|
||||
}
|
||||
|
||||
var mutatorMap = this.instanceMutatorMap;
|
||||
if (node.static) {
|
||||
this.hasStaticMutators = true;
|
||||
@@ -182,10 +219,6 @@ Class.prototype.pushMethod = function (node) {
|
||||
this.hasInstanceMutators = true;
|
||||
}
|
||||
|
||||
if (kind === "") {
|
||||
kind = "value";
|
||||
}
|
||||
|
||||
util.pushMutatorMap(mutatorMap, methodName, kind, node.computed, node);
|
||||
};
|
||||
|
||||
@@ -219,6 +252,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 +305,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 +313,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;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -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, []);
|
||||
};
|
||||
|
||||
@@ -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,25 +39,13 @@ 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);
|
||||
var has = scope.get(param.name, true);
|
||||
if (has && node.params.indexOf(has) < 0) {
|
||||
iife = true;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
};
|
||||
};
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -2,13 +2,9 @@ var traverse = require("../../traverse");
|
||||
var util = require("../../util");
|
||||
var t = require("../../types");
|
||||
|
||||
exports.Property = function (node, parent, file, scope) {
|
||||
if (!node.method) return;
|
||||
|
||||
node.method = false;
|
||||
|
||||
exports._namedMethod = function (node, file, scope) {
|
||||
var key = t.toComputedKey(node, node.key);
|
||||
if (!t.isLiteral(key)) return; // we can't set a function id with this
|
||||
if (!t.isLiteral(key)) return node; // we can't set a function id with this
|
||||
|
||||
var id = t.toIdentifier(key.value);
|
||||
key = t.identifier(id);
|
||||
@@ -46,6 +42,14 @@ exports.Property = function (node, parent, file, scope) {
|
||||
}
|
||||
};
|
||||
|
||||
exports.Property = function (node, parent, file, scope) {
|
||||
if (!node.method) return;
|
||||
|
||||
node.method = false;
|
||||
|
||||
exports._namedMethod(node, file, scope);
|
||||
};
|
||||
|
||||
exports.ObjectExpression = function (node) {
|
||||
var mutatorMap = {};
|
||||
var hasAny = false;
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
};
|
||||
@@ -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;
|
||||
};
|
||||
@@ -3,7 +3,19 @@ var t = require("../../types");
|
||||
exports.optional = true;
|
||||
|
||||
exports.UnaryExpression = function (node, parent, file) {
|
||||
this.skip();
|
||||
|
||||
if (node.operator === "typeof") {
|
||||
return t.callExpression(file.addHelper("typeof"), [node.argument]);
|
||||
var call = t.callExpression(file.addHelper("typeof"), [node.argument]);
|
||||
if (t.isIdentifier(node.argument)) {
|
||||
var undefLiteral = t.literal("undefined");
|
||||
return t.conditionalExpression(
|
||||
t.binaryExpression("===", t.unaryExpression("typeof", node.argument), undefLiteral),
|
||||
undefLiteral,
|
||||
call
|
||||
);
|
||||
} else {
|
||||
return call;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -193,6 +193,21 @@ t.isReferenced = function (node, parent) {
|
||||
// we're a property key and we aren't computed so we aren't referenced
|
||||
if (t.isProperty(parent) && parent.key === node && !parent.computed) return false;
|
||||
|
||||
if (t.isFunction(parent)) {
|
||||
// we're a function param
|
||||
if (_.contains(parent.params, node)) return false;
|
||||
|
||||
// we're a rest parameter
|
||||
if (_.contains(parent.params, node)) return false;
|
||||
}
|
||||
|
||||
if (t.isMethodDefinition(parent) && parent.key === node && !parent.computed) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// we're a catch clause param
|
||||
if (t.isCatchClause(parent) && parent.param === node) return false;
|
||||
|
||||
// we're a variable declarator id so we aren't referenced
|
||||
if (t.isVariableDeclarator(parent) && parent.id === node) return false;
|
||||
|
||||
|
||||
@@ -12,11 +12,13 @@ var _ = require("lodash");
|
||||
exports.inherits = util.inherits;
|
||||
|
||||
exports.canCompile = function (filename, altExts) {
|
||||
var exts = altExts || [".js", ".jsx", ".es6", ".es"];
|
||||
var exts = altExts || exports.canCompile.EXTENSIONS;
|
||||
var ext = path.extname(filename);
|
||||
return _.contains(exts, ext);
|
||||
};
|
||||
|
||||
exports.canCompile.EXTENSIONS = [".js", ".jsx", ".es6", ".es"];
|
||||
|
||||
exports.isInteger = function (i) {
|
||||
return _.isNumber(i) && i % 1 === 0;
|
||||
};
|
||||
|
||||
20
package.json
20
package.json
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "6to5",
|
||||
"description": "Turn ES6 code into readable vanilla ES5 with source maps",
|
||||
"version": "2.11.2",
|
||||
"version": "2.12.3",
|
||||
"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"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -1,11 +1,6 @@
|
||||
"use strict";
|
||||
|
||||
var _slice = Array.prototype.slice;
|
||||
var _prototypeProperties = function (child, staticProps, instanceProps) {
|
||||
if (staticProps) Object.defineProperties(child, staticProps);
|
||||
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
|
||||
};
|
||||
|
||||
var _inherits = function (subClass, superClass) {
|
||||
if (typeof superClass !== "function" && superClass !== null) {
|
||||
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
|
||||
@@ -37,31 +32,19 @@ 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 test() {
|
||||
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 foo() {
|
||||
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)));
|
||||
};
|
||||
|
||||
return Test;
|
||||
})(Foo);
|
||||
@@ -1,10 +1,5 @@
|
||||
"use strict";
|
||||
|
||||
var _prototypeProperties = function (child, staticProps, instanceProps) {
|
||||
if (staticProps) Object.defineProperties(child, staticProps);
|
||||
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
|
||||
};
|
||||
|
||||
var _inherits = function (subClass, superClass) {
|
||||
if (typeof superClass !== "function" && superClass !== null) {
|
||||
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
|
||||
@@ -28,16 +23,9 @@ 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 test() {
|
||||
return Foo.wow.call(this);
|
||||
};
|
||||
|
||||
return Test;
|
||||
})(Foo);
|
||||
3
test/fixtures/transformation/es6-classes-loose/options.json
vendored
Normal file
3
test/fixtures/transformation/es6-classes-loose/options.json
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"loose": ["classes"]
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ var Test = (function (Foo) {
|
||||
|
||||
_prototypeProperties(Test, {
|
||||
foo: {
|
||||
value: function () {
|
||||
value: function foo() {
|
||||
var _get4;
|
||||
_get(Object.getPrototypeOf(Test), "foo", this).call(this);
|
||||
_get(Object.getPrototypeOf(Test), "foo", this).apply(this, arguments);
|
||||
@@ -73,7 +73,7 @@ var Test = (function (Foo) {
|
||||
}
|
||||
}, {
|
||||
test: {
|
||||
value: function () {
|
||||
value: function test() {
|
||||
var _get5;
|
||||
_get(Object.getPrototypeOf(Test.prototype), "test", this).call(this);
|
||||
_get(Object.getPrototypeOf(Test.prototype), "test", this).apply(this, arguments);
|
||||
|
||||
@@ -52,7 +52,7 @@ var Test = (function (Foo) {
|
||||
|
||||
_prototypeProperties(Test, {
|
||||
test: {
|
||||
value: function () {
|
||||
value: function test() {
|
||||
return _get(Object.getPrototypeOf(Test), "wow", this).call(this);
|
||||
},
|
||||
writable: true,
|
||||
|
||||
@@ -10,7 +10,7 @@ var Test = (function () {
|
||||
|
||||
_prototypeProperties(Test, null, {
|
||||
test: {
|
||||
value: function () {
|
||||
value: function test() {
|
||||
return 5 + 5;
|
||||
},
|
||||
writable: true,
|
||||
|
||||
@@ -9,16 +9,16 @@ var BaseView = function BaseView() {
|
||||
this.autoRender = true;
|
||||
};
|
||||
|
||||
var BaseView = function () {
|
||||
var BaseView = function BaseView() {
|
||||
this.autoRender = true;
|
||||
};
|
||||
|
||||
var BaseView = (function () {
|
||||
var _class2 = function () {};
|
||||
function BaseView() {}
|
||||
|
||||
_prototypeProperties(_class2, null, {
|
||||
_prototypeProperties(BaseView, null, {
|
||||
foo: {
|
||||
value: function () {
|
||||
value: function foo() {
|
||||
this.autoRender = true;
|
||||
},
|
||||
writable: true,
|
||||
@@ -27,5 +27,5 @@ var BaseView = (function () {
|
||||
}
|
||||
});
|
||||
|
||||
return _class2;
|
||||
return BaseView;
|
||||
})();
|
||||
|
||||
@@ -10,7 +10,7 @@ var A = (function () {
|
||||
|
||||
_prototypeProperties(A, {
|
||||
a: {
|
||||
value: function () {},
|
||||
value: function a() {},
|
||||
writable: true,
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
|
||||
3
test/fixtures/transformation/es6-computed-property-names-loose/argument/actual.js
vendored
Normal file
3
test/fixtures/transformation/es6-computed-property-names-loose/argument/actual.js
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
foo({
|
||||
[bar]: "foobar"
|
||||
});
|
||||
8
test/fixtures/transformation/es6-computed-property-names-loose/argument/expected.js
vendored
Normal file
8
test/fixtures/transformation/es6-computed-property-names-loose/argument/expected.js
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
"use strict";
|
||||
|
||||
foo((function () {
|
||||
var _foo = {};
|
||||
|
||||
_foo[bar] = "foobar";
|
||||
return _foo;
|
||||
})());
|
||||
3
test/fixtures/transformation/es6-computed-property-names-loose/assignment/actual.js
vendored
Normal file
3
test/fixtures/transformation/es6-computed-property-names-loose/assignment/actual.js
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
foo = {
|
||||
[bar]: "foobar"
|
||||
};
|
||||
8
test/fixtures/transformation/es6-computed-property-names-loose/assignment/expected.js
vendored
Normal file
8
test/fixtures/transformation/es6-computed-property-names-loose/assignment/expected.js
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
"use strict";
|
||||
|
||||
foo = (function () {
|
||||
var _foo = {};
|
||||
|
||||
_foo[bar] = "foobar";
|
||||
return _foo;
|
||||
})();
|
||||
3
test/fixtures/transformation/es6-computed-property-names-loose/ignore-symbol/actual.js
vendored
Normal file
3
test/fixtures/transformation/es6-computed-property-names-loose/ignore-symbol/actual.js
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
var foo = {
|
||||
[Symbol.iterator]: "foobar"
|
||||
};
|
||||
8
test/fixtures/transformation/es6-computed-property-names-loose/ignore-symbol/expected.js
vendored
Normal file
8
test/fixtures/transformation/es6-computed-property-names-loose/ignore-symbol/expected.js
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
"use strict";
|
||||
|
||||
var foo = (function () {
|
||||
var _foo = {};
|
||||
|
||||
_foo[Symbol.iterator] = "foobar";
|
||||
return _foo;
|
||||
})();
|
||||
5
test/fixtures/transformation/es6-computed-property-names-loose/method/actual.js
vendored
Normal file
5
test/fixtures/transformation/es6-computed-property-names-loose/method/actual.js
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
var obj = {
|
||||
[foobar]() {
|
||||
return "foobar";
|
||||
}
|
||||
};
|
||||
11
test/fixtures/transformation/es6-computed-property-names-loose/method/expected.js
vendored
Normal file
11
test/fixtures/transformation/es6-computed-property-names-loose/method/expected.js
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
"use strict";
|
||||
|
||||
var obj = (function () {
|
||||
var _obj = {};
|
||||
|
||||
_obj[foobar] = function () {
|
||||
return "foobar";
|
||||
};
|
||||
|
||||
return _obj;
|
||||
})();
|
||||
6
test/fixtures/transformation/es6-computed-property-names-loose/mixed/actual.js
vendored
Normal file
6
test/fixtures/transformation/es6-computed-property-names-loose/mixed/actual.js
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
var obj = {
|
||||
["x" + foo]: "heh",
|
||||
["y" + bar]: "noo",
|
||||
foo: "foo",
|
||||
bar: "bar"
|
||||
};
|
||||
11
test/fixtures/transformation/es6-computed-property-names-loose/mixed/expected.js
vendored
Normal file
11
test/fixtures/transformation/es6-computed-property-names-loose/mixed/expected.js
vendored
Normal 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;
|
||||
})();
|
||||
4
test/fixtures/transformation/es6-computed-property-names-loose/multiple/actual.js
vendored
Normal file
4
test/fixtures/transformation/es6-computed-property-names-loose/multiple/actual.js
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
var obj = {
|
||||
["x" + foo]: "heh",
|
||||
["y" + bar]: "noo"
|
||||
};
|
||||
9
test/fixtures/transformation/es6-computed-property-names-loose/multiple/expected.js
vendored
Normal file
9
test/fixtures/transformation/es6-computed-property-names-loose/multiple/expected.js
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
"use strict";
|
||||
|
||||
var obj = (function () {
|
||||
var _obj = {};
|
||||
|
||||
_obj["x" + foo] = "heh";
|
||||
_obj["y" + bar] = "noo";
|
||||
return _obj;
|
||||
})();
|
||||
3
test/fixtures/transformation/es6-computed-property-names-loose/options.json
vendored
Normal file
3
test/fixtures/transformation/es6-computed-property-names-loose/options.json
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"loose": ["computedPropertyNames"]
|
||||
}
|
||||
3
test/fixtures/transformation/es6-computed-property-names-loose/single/actual.js
vendored
Normal file
3
test/fixtures/transformation/es6-computed-property-names-loose/single/actual.js
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
var obj = {
|
||||
["x" + foo]: "heh"
|
||||
};
|
||||
8
test/fixtures/transformation/es6-computed-property-names-loose/single/expected.js
vendored
Normal file
8
test/fixtures/transformation/es6-computed-property-names-loose/single/expected.js
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
"use strict";
|
||||
|
||||
var obj = (function () {
|
||||
var _obj = {};
|
||||
|
||||
_obj["x" + foo] = "heh";
|
||||
return _obj;
|
||||
})();
|
||||
3
test/fixtures/transformation/es6-computed-property-names-loose/this/actual.js
vendored
Normal file
3
test/fixtures/transformation/es6-computed-property-names-loose/this/actual.js
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
var obj = {
|
||||
["x" + this.foo]: "heh"
|
||||
};
|
||||
9
test/fixtures/transformation/es6-computed-property-names-loose/this/expected.js
vendored
Normal file
9
test/fixtures/transformation/es6-computed-property-names-loose/this/expected.js
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
"use strict";
|
||||
|
||||
var _this = this;
|
||||
var obj = (function () {
|
||||
var _obj = {};
|
||||
|
||||
_obj["x" + _this.foo] = "heh";
|
||||
return _obj;
|
||||
})();
|
||||
4
test/fixtures/transformation/es6-computed-property-names-loose/two/actual.js
vendored
Normal file
4
test/fixtures/transformation/es6-computed-property-names-loose/two/actual.js
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
var obj = {
|
||||
first: "first",
|
||||
["second"]: "second",
|
||||
};
|
||||
9
test/fixtures/transformation/es6-computed-property-names-loose/two/expected.js
vendored
Normal file
9
test/fixtures/transformation/es6-computed-property-names-loose/two/expected.js
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
"use strict";
|
||||
|
||||
var obj = (function () {
|
||||
var _obj = {};
|
||||
|
||||
_obj.first = "first";
|
||||
_obj.second = "second";
|
||||
return _obj;
|
||||
})();
|
||||
3
test/fixtures/transformation/es6-computed-property-names-loose/variable/actual.js
vendored
Normal file
3
test/fixtures/transformation/es6-computed-property-names-loose/variable/actual.js
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
var foo = {
|
||||
[bar]: "foobar"
|
||||
};
|
||||
8
test/fixtures/transformation/es6-computed-property-names-loose/variable/expected.js
vendored
Normal file
8
test/fixtures/transformation/es6-computed-property-names-loose/variable/expected.js
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
"use strict";
|
||||
|
||||
var foo = (function () {
|
||||
var _foo = {};
|
||||
|
||||
_foo[bar] = "foobar";
|
||||
return _foo;
|
||||
})();
|
||||
3
test/fixtures/transformation/es6-for-of-loose/identifier/actual.js
vendored
Normal file
3
test/fixtures/transformation/es6-for-of-loose/identifier/actual.js
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
for (i of arr) {
|
||||
|
||||
}
|
||||
15
test/fixtures/transformation/es6-for-of-loose/identifier/expected.js
vendored
Normal file
15
test/fixtures/transformation/es6-for-of-loose/identifier/expected.js
vendored
Normal 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;
|
||||
}
|
||||
}
|
||||
3
test/fixtures/transformation/es6-for-of-loose/let/actual.js
vendored
Normal file
3
test/fixtures/transformation/es6-for-of-loose/let/actual.js
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
for (let i of arr) {
|
||||
|
||||
}
|
||||
16
test/fixtures/transformation/es6-for-of-loose/let/expected.js
vendored
Normal file
16
test/fixtures/transformation/es6-for-of-loose/let/expected.js
vendored
Normal 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;
|
||||
}
|
||||
}
|
||||
7
test/fixtures/transformation/es6-for-of-loose/multiple/actual.js
vendored
Normal file
7
test/fixtures/transformation/es6-for-of-loose/multiple/actual.js
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
for (var i of arr) {
|
||||
|
||||
}
|
||||
|
||||
for (var i of numbers) {
|
||||
|
||||
}
|
||||
31
test/fixtures/transformation/es6-for-of-loose/multiple/expected.js
vendored
Normal file
31
test/fixtures/transformation/es6-for-of-loose/multiple/expected.js
vendored
Normal 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;
|
||||
}
|
||||
}
|
||||
3
test/fixtures/transformation/es6-for-of-loose/options.json
vendored
Normal file
3
test/fixtures/transformation/es6-for-of-loose/options.json
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"loose": ["forOf"]
|
||||
}
|
||||
3
test/fixtures/transformation/es6-for-of-loose/var/actual.js
vendored
Normal file
3
test/fixtures/transformation/es6-for-of-loose/var/actual.js
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
for (var i of arr) {
|
||||
|
||||
}
|
||||
16
test/fixtures/transformation/es6-for-of-loose/var/expected.js
vendored
Normal file
16
test/fixtures/transformation/es6-for-of-loose/var/expected.js
vendored
Normal 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;
|
||||
}
|
||||
}
|
||||
1
test/fixtures/transformation/es6-template-literals/tag-loose/actual.js
vendored
Normal file
1
test/fixtures/transformation/es6-template-literals/tag-loose/actual.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
var foo = bar`wow\na${ 42 }b ${_.foobar()}`;
|
||||
8
test/fixtures/transformation/es6-template-literals/tag-loose/expected.js
vendored
Normal file
8
test/fixtures/transformation/es6-template-literals/tag-loose/expected.js
vendored
Normal 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());
|
||||
3
test/fixtures/transformation/es6-template-literals/tag-loose/options.json
vendored
Normal file
3
test/fixtures/transformation/es6-template-literals/tag-loose/options.json
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"loose": ["templateLiterals"]
|
||||
}
|
||||
@@ -16,7 +16,7 @@ var H = (function () {
|
||||
var J = new WeakMap(),
|
||||
K = new WeakMap();
|
||||
var I = new WeakMap();
|
||||
var _class = function () {};
|
||||
function H() {}
|
||||
|
||||
return _class;
|
||||
return H;
|
||||
})();
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
{
|
||||
"optional": ["classesFastSuper"]
|
||||
}
|
||||
@@ -5,4 +5,4 @@ var _typeof = function (obj) {
|
||||
};
|
||||
|
||||
var s = Symbol("s");
|
||||
assert.equal(_typeof(s), "symbol");
|
||||
assert.equal(typeof s === "undefined" ? "undefined" : _typeof(s), "symbol");
|
||||
|
||||
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user