Compare commits
36 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
026fd7eddb | ||
|
|
456b2d3910 | ||
|
|
4208bf3f4b | ||
|
|
a81678d327 | ||
|
|
be55f42f80 | ||
|
|
b1b326cf9c | ||
|
|
a9ff73b4f6 | ||
|
|
f5ccb9c0ba | ||
|
|
1cbbe00b7a | ||
|
|
055dd5d2c3 | ||
|
|
0fea437536 | ||
|
|
f325d3b065 | ||
|
|
e514660fbd | ||
|
|
a5d8144cce | ||
|
|
8145840264 | ||
|
|
a02eafedfd | ||
|
|
3f3cd2bb3a | ||
|
|
503a3f2e3a | ||
|
|
48a8723fdb | ||
|
|
92c297b1be | ||
|
|
56e26378ff | ||
|
|
f3f69ab4fa | ||
|
|
2a488b951d | ||
|
|
ac01caacd3 | ||
|
|
cbdf746474 | ||
|
|
ad0a1ae66d | ||
|
|
3b783979d8 | ||
|
|
b2ec15accc | ||
|
|
3b7cfc908e | ||
|
|
010ca83d0d | ||
|
|
161c895a90 | ||
|
|
47a45f3731 | ||
|
|
7bb3cfd932 | ||
|
|
d87b70b57e | ||
|
|
bbfb297d73 | ||
|
|
9b68d08604 |
3
.gitmodules
vendored
3
.gitmodules
vendored
@@ -7,3 +7,6 @@
|
||||
[submodule "vendor/test262"]
|
||||
path = vendor/test262
|
||||
url = https://github.com/tc39/test262
|
||||
[submodule "vendor/compat-table"]
|
||||
path = vendor/compat-table
|
||||
url = https://github.com/kangax/compat-table
|
||||
|
||||
2
.istanbul.yml
Normal file
2
.istanbul.yml
Normal file
@@ -0,0 +1,2 @@
|
||||
instrumentation:
|
||||
root: lib
|
||||
10
CHANGELOG.md
10
CHANGELOG.md
@@ -11,6 +11,16 @@
|
||||
|
||||
_Note: Gaps between patch versions are faulty/broken releases._
|
||||
|
||||
## 3.2.0
|
||||
|
||||
* **Bug Fix**
|
||||
* Fixed scope tracking for default parameters IIFE.
|
||||
* Fixed block scoped functions.
|
||||
* **New Feature**
|
||||
* You can now trigger super setters in classes. Thanks [@kruppel](https://github.com/kruppel)!
|
||||
* Add `resolveSourceMap` option.
|
||||
* Better support and output for block scoping loops with labels.
|
||||
|
||||
## 3.1.1
|
||||
|
||||
* **Polish**
|
||||
|
||||
1
Makefile
1
Makefile
@@ -110,3 +110,4 @@ bootstrap:
|
||||
npm install
|
||||
git submodule update --init
|
||||
cd vendor/regenerator; npm install
|
||||
cd vendor/compat-table; npm install object-assign
|
||||
|
||||
@@ -53,10 +53,7 @@ module.exports = function (commander, filenames, opts) {
|
||||
|
||||
_.each(["add", "change"], function (type) {
|
||||
watcher.on(type, function (filename) {
|
||||
// chop off the dirname plus the path separator
|
||||
var relative = filename.slice(dirname.length + 1);
|
||||
|
||||
console.log(type, filename);
|
||||
var relative = path.relative(dirname, filename) || filename;
|
||||
write(filename, relative);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -49,7 +49,8 @@ File.helpers = [
|
||||
"interop-require-wildcard",
|
||||
"typeof",
|
||||
"extends",
|
||||
"get"
|
||||
"get",
|
||||
"set"
|
||||
];
|
||||
|
||||
File.validOptions = [
|
||||
@@ -74,11 +75,13 @@ File.validOptions = [
|
||||
"format",
|
||||
"playground",
|
||||
"experimental",
|
||||
"resolveModuleSource",
|
||||
|
||||
// these are used by plugins
|
||||
"ignore",
|
||||
"only",
|
||||
"extensions"
|
||||
"extensions",
|
||||
"accept"
|
||||
];
|
||||
|
||||
File.normaliseOptions = function (opts) {
|
||||
@@ -92,6 +95,7 @@ File.normaliseOptions = function (opts) {
|
||||
|
||||
defaults(opts, {
|
||||
keepModuleIdExtensions: false,
|
||||
resolveModuleSource: null,
|
||||
experimental: false,
|
||||
reactCompat: false,
|
||||
playground: false,
|
||||
@@ -332,7 +336,11 @@ File.prototype.transform = function (ast) {
|
||||
this.ast = ast;
|
||||
this.lastStatements = t.getLastStatements(ast.program);
|
||||
this.scope = new Scope(ast.program, ast, null, this);
|
||||
this.moduleFormatter = this.getModuleFormatter(this.opts.modules);
|
||||
|
||||
var modFormatter = this.moduleFormatter = this.getModuleFormatter(this.opts.modules);
|
||||
if (modFormatter.init && this.transformers["es6.modules"].canRun()) {
|
||||
modFormatter.init();
|
||||
}
|
||||
|
||||
var astRun = function (key) {
|
||||
each(self.transformerStack, function (pass) {
|
||||
|
||||
@@ -21,6 +21,36 @@ function ReplaceSupers(opts) {
|
||||
this.file = opts.file;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a super class value of the named property.
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* _set(Object.getPrototypeOf(CLASS.prototype), "METHOD", "VALUE", this)
|
||||
*
|
||||
* @param {Node} property
|
||||
* @param {boolean} isStatic
|
||||
* @param {boolean} isComputed
|
||||
*
|
||||
* @returns {Node}
|
||||
*/
|
||||
ReplaceSupers.prototype.setSuperProperty = function (property, value, isStatic, isComputed, thisExpression) {
|
||||
return t.callExpression(
|
||||
this.file.addHelper("set"),
|
||||
[
|
||||
t.callExpression(
|
||||
t.memberExpression(t.identifier("Object"), t.identifier("getPrototypeOf")),
|
||||
[
|
||||
isStatic ? this.className : t.memberExpression(this.className, t.identifier("prototype"))
|
||||
]
|
||||
),
|
||||
isComputed ? property : t.literal(property.name),
|
||||
value,
|
||||
thisExpression
|
||||
]
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Gets a node representing the super class value of the named property.
|
||||
*
|
||||
@@ -191,6 +221,7 @@ ReplaceSupers.prototype.specHandle = function (getThisReference, node, parent) {
|
||||
var property;
|
||||
var computed;
|
||||
var args;
|
||||
var thisReference;
|
||||
|
||||
if (t.isIdentifier(node, { name: "super" })) {
|
||||
if (!(t.isMemberExpression(parent) && !parent.computed && parent.property === node)) {
|
||||
@@ -226,11 +257,18 @@ ReplaceSupers.prototype.specHandle = function (getThisReference, node, parent) {
|
||||
// super.name; -> _get(Object.getPrototypeOf(ClassName.prototype), "name", this);
|
||||
property = node.property;
|
||||
computed = node.computed;
|
||||
} else if (t.isAssignmentExpression(node)) {
|
||||
if (!t.isIdentifier(node.left.object, { name: "super" })) return;
|
||||
if (methodNode.kind !== "set") return;
|
||||
|
||||
thisReference = getThisReference();
|
||||
// super.name = "val"; -> _set(Object.getPrototypeOf(ClassName.prototype), "name", this);
|
||||
return this.setSuperProperty(node.left.property, node.right, methodNode.static, node.left.computed, thisReference);
|
||||
}
|
||||
|
||||
if (!property) return;
|
||||
|
||||
var thisReference = getThisReference();
|
||||
thisReference = getThisReference();
|
||||
var superProperty = this.superProperty(property, methodNode.static, computed, thisReference);
|
||||
if (args) {
|
||||
if (args.length === 1 && t.isSpreadElement(args[0])) {
|
||||
|
||||
@@ -45,7 +45,7 @@ var exportsVisitor = {
|
||||
formatter.hasLocalImports = true;
|
||||
|
||||
if (declar && t.isStatement(declar)) {
|
||||
extend(formatter.localExports, t.getIds(declar, true));
|
||||
extend(formatter.localExports, t.getDeclarations(declar));
|
||||
}
|
||||
|
||||
if (!node.default) {
|
||||
@@ -67,7 +67,7 @@ var importsVisitor = {
|
||||
enter: function (node, parent, scope, context, formatter) {
|
||||
if (t.isImportDeclaration(node)) {
|
||||
formatter.hasLocalImports = true;
|
||||
extend(formatter.localImports, t.getIds(node, true));
|
||||
extend(formatter.localImports, t.getDeclarations(node));
|
||||
formatter.bumpImportOccurences(node);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,8 @@ function AMDFormatter() {
|
||||
|
||||
util.inherits(AMDFormatter, DefaultFormatter);
|
||||
|
||||
AMDFormatter.prototype.init = CommonFormatter.prototype.init;
|
||||
|
||||
AMDFormatter.prototype.buildDependencyLiterals = function () {
|
||||
var names = [];
|
||||
for (var name in this.ids) {
|
||||
|
||||
@@ -7,16 +7,18 @@ var util = require("../../util");
|
||||
var t = require("../../types");
|
||||
var contains = require("lodash/collection/contains");
|
||||
|
||||
function CommonJSFormatter(file) {
|
||||
function CommonJSFormatter() {
|
||||
DefaultFormatter.apply(this, arguments);
|
||||
|
||||
if (this.hasNonDefaultExports) {
|
||||
file.ast.program.body.push(util.template("exports-module-declaration", true));
|
||||
}
|
||||
}
|
||||
|
||||
util.inherits(CommonJSFormatter, DefaultFormatter);
|
||||
|
||||
CommonJSFormatter.prototype.init = function () {
|
||||
if (this.hasNonDefaultExports) {
|
||||
this.file.ast.program.body.push(util.template("exports-module-declaration", true));
|
||||
}
|
||||
};
|
||||
|
||||
CommonJSFormatter.prototype.importSpecifier = function (specifier, node, nodes) {
|
||||
var variableName = t.getSpecifierName(specifier);
|
||||
|
||||
|
||||
@@ -21,6 +21,8 @@ function SystemFormatter(file) {
|
||||
|
||||
util.inherits(SystemFormatter, AMDFormatter);
|
||||
|
||||
SystemFormatter.prototype.init = function () {};
|
||||
|
||||
SystemFormatter.prototype._addImportSource = function (node, exportNode) {
|
||||
node._importSource = exportNode.source && exportNode.source.value;
|
||||
return node;
|
||||
|
||||
24
lib/6to5/transformation/templates/set.js
Normal file
24
lib/6to5/transformation/templates/set.js
Normal file
@@ -0,0 +1,24 @@
|
||||
(function set(object, property, value, receiver) {
|
||||
var desc = Object.getOwnPropertyDescriptor(object, property);
|
||||
|
||||
if (desc === undefined) {
|
||||
var parent = Object.getPrototypeOf(object);
|
||||
|
||||
if (parent === null) {
|
||||
return;
|
||||
} else {
|
||||
return set(parent, property, value, receiver);
|
||||
}
|
||||
} else if ("value" in desc && desc.writable) {
|
||||
desc.value = value;
|
||||
return;
|
||||
} else {
|
||||
var setter = desc.set;
|
||||
|
||||
if (setter === undefined) {
|
||||
return;
|
||||
}
|
||||
|
||||
return setter.call(receiver, value);
|
||||
}
|
||||
});
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
var traverse = require("../../../traverse");
|
||||
var object = require("../../../helpers/object");
|
||||
var clone = require("lodash/lang/clone");
|
||||
var util = require("../../../util");
|
||||
var t = require("../../../types");
|
||||
var values = require("lodash/object/values");
|
||||
@@ -45,19 +46,8 @@ exports.Loop = function (node, parent, scope, context, file) {
|
||||
t.ensureBlock(node);
|
||||
node.body._letDeclarators = [init];
|
||||
}
|
||||
|
||||
if (t.isLabeledStatement(parent)) {
|
||||
// set label so `run` has access to it
|
||||
node.label = parent.label;
|
||||
}
|
||||
|
||||
var letScoping = new LetScoping(node, node.body, parent, scope, file);
|
||||
letScoping.run();
|
||||
|
||||
if (node.label && !t.isLabeledStatement(parent)) {
|
||||
// we've been given a label so let's wrap ourselves
|
||||
return t.labeledStatement(node.label, node);
|
||||
}
|
||||
};
|
||||
|
||||
exports.Program =
|
||||
@@ -269,7 +259,7 @@ LetScoping.prototype.getLetReferences = function () {
|
||||
//
|
||||
for (var i = 0; i < declarators.length; i++) {
|
||||
declar = declarators[i];
|
||||
extend(this.outsideLetReferences, t.getIds(declar, true));
|
||||
extend(this.outsideLetReferences, t.getDeclarations(declar));
|
||||
}
|
||||
|
||||
//
|
||||
@@ -285,7 +275,7 @@ LetScoping.prototype.getLetReferences = function () {
|
||||
//
|
||||
for (i = 0; i < declarators.length; i++) {
|
||||
declar = declarators[i];
|
||||
var keys = t.getIds(declar, true);
|
||||
var keys = t.getDeclarations(declar);
|
||||
extend(this.letReferences, keys);
|
||||
this.hasLetReferences = true;
|
||||
}
|
||||
@@ -308,34 +298,57 @@ LetScoping.prototype.getLetReferences = function () {
|
||||
return state.closurify;
|
||||
};
|
||||
|
||||
var loopNodeTo = function (node) {
|
||||
if (t.isBreakStatement(node)) {
|
||||
return "break";
|
||||
} else if (t.isContinueStatement(node)) {
|
||||
return "continue";
|
||||
}
|
||||
};
|
||||
|
||||
var loopVisitor = {
|
||||
enter: function (node, parent, scope, context, state) {
|
||||
var replace;
|
||||
|
||||
if (t.isLoop(node)) {
|
||||
state = clone(state);
|
||||
state.ignoreLabeless = true;
|
||||
traverse(node, loopVisitor, scope, state);
|
||||
}
|
||||
|
||||
if (t.isFunction(node) || t.isLoop(node)) {
|
||||
return context.skip();
|
||||
}
|
||||
|
||||
if (node && !node.label && state.isLoop) {
|
||||
if (t.isBreakStatement(node)) {
|
||||
if (t.isSwitchCase(parent)) return;
|
||||
var loopText = loopNodeTo(node);
|
||||
|
||||
state.hasBreak = true;
|
||||
replace = t.returnStatement(t.literal("break"));
|
||||
} else if (t.isContinueStatement(node)) {
|
||||
state.hasContinue = true;
|
||||
replace = t.returnStatement(t.literal("continue"));
|
||||
if (loopText) {
|
||||
if (node.label) {
|
||||
loopText = loopText + "|" + node.label.name;
|
||||
} else {
|
||||
// we shouldn't be dealing with this
|
||||
if (state.ignoreLabeless) return;
|
||||
|
||||
// break statements mean something different in this context
|
||||
if (t.isBreakStatement(node) && t.isSwitchCase(parent)) return;
|
||||
}
|
||||
|
||||
state.hasBreakContinue = true;
|
||||
state.map[loopText] = node;
|
||||
replace = t.literal(loopText);
|
||||
}
|
||||
|
||||
if (t.isReturnStatement(node)) {
|
||||
state.hasReturn = true;
|
||||
replace = t.returnStatement(t.objectExpression([
|
||||
replace = t.objectExpression([
|
||||
t.property("init", t.identifier("v"), node.argument || t.identifier("undefined"))
|
||||
]));
|
||||
]);
|
||||
}
|
||||
|
||||
if (replace) return t.inherits(replace, node);
|
||||
if (replace) {
|
||||
replace = t.returnStatement(replace);
|
||||
return t.inherits(replace, node);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -350,10 +363,11 @@ var loopVisitor = {
|
||||
|
||||
LetScoping.prototype.checkLoop = function () {
|
||||
var state = {
|
||||
hasContinue: false,
|
||||
hasReturn: false,
|
||||
hasBreak: false,
|
||||
isLoop: !!this.loopParent
|
||||
hasBreakContinue: false,
|
||||
ignoreLabeless: false,
|
||||
hasReturn: false,
|
||||
isLoop: !!this.loopParent,
|
||||
map: {}
|
||||
};
|
||||
|
||||
traverse(this.block, loopVisitor, this.scope, state);
|
||||
@@ -422,7 +436,7 @@ LetScoping.prototype.pushDeclar = function (node) {
|
||||
|
||||
LetScoping.prototype.build = function (ret, call) {
|
||||
var has = this.has;
|
||||
if (has.hasReturn || has.hasBreak || has.hasContinue) {
|
||||
if (has.hasReturn || has.hasBreakContinue) {
|
||||
this.buildHas(ret, call);
|
||||
} else {
|
||||
this.body.push(t.expressionStatement(call));
|
||||
@@ -455,22 +469,14 @@ LetScoping.prototype.buildHas = function (ret, call) {
|
||||
});
|
||||
}
|
||||
|
||||
if (has.hasBreak || has.hasContinue) {
|
||||
if (has.hasBreakContinue) {
|
||||
if (!loopParent) {
|
||||
throw new Error("Has no loop parent but we're trying to reassign breaks " +
|
||||
"and continues, something is going wrong here.");
|
||||
}
|
||||
|
||||
// ensure that the parent has a label as we're building a switch and we
|
||||
// need to be able to access it
|
||||
var label = loopParent.label = loopParent.label || this.scope.generateUidIdentifier("loop");
|
||||
|
||||
if (has.hasBreak) {
|
||||
cases.push(t.switchCase(t.literal("break"), [t.breakStatement(label)]));
|
||||
}
|
||||
|
||||
if (has.hasContinue) {
|
||||
cases.push(t.switchCase(t.literal("continue"), [t.continueStatement(label)]));
|
||||
for (var key in has.map) {
|
||||
cases.push(t.switchCase(t.literal(key), [has.map[key]]));
|
||||
}
|
||||
|
||||
if (has.hasReturn) {
|
||||
|
||||
@@ -6,7 +6,7 @@ var t = require("../../../types");
|
||||
var visitor = {
|
||||
enter: function (node, parent, scope, context, state) {
|
||||
if (t.isDeclaration(node) || t.isAssignmentExpression(node)) {
|
||||
var ids = t.getIds(node, true);
|
||||
var ids = t.getDeclarations(node);
|
||||
|
||||
for (var key in ids) {
|
||||
var id = ids[key];
|
||||
|
||||
@@ -13,7 +13,7 @@ var hasDefaults = function (node) {
|
||||
|
||||
var iifeVisitor = {
|
||||
enter: function (node, parent, scope, context, state) {
|
||||
if (t.isReferencedIdentifier(node, parent) && scope.hasOwn(node.name)) {
|
||||
if (t.isReferencedIdentifier(node, parent) && state.scope.hasOwn(node.name)) {
|
||||
state.iife = true;
|
||||
context.stop();
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ module.exports = {
|
||||
|
||||
react: require("./other/react"),
|
||||
|
||||
_modulesSplit: require("./internal/modules-split"),
|
||||
_modules: require("./internal/modules"),
|
||||
|
||||
// needs to be before `regenerator` due to generator comprehensions
|
||||
// needs to be before `_aliasFunction`
|
||||
|
||||
@@ -8,7 +8,18 @@
|
||||
|
||||
var t = require("../../../types");
|
||||
|
||||
var resolveModuleSource = function (node, parent, scope, context, file) {
|
||||
var resolveModuleSource = file.opts.resolveModuleSource;
|
||||
if (node.source && resolveModuleSource) {
|
||||
node.source.value = resolveModuleSource(node.source.value);
|
||||
}
|
||||
};
|
||||
|
||||
exports.ImportDeclaration = resolveModuleSource;
|
||||
|
||||
exports.ExportDeclaration = function (node, parent, scope) {
|
||||
resolveModuleSource.apply(null, arguments);
|
||||
|
||||
var declar = node.declaration;
|
||||
|
||||
if (node.default) {
|
||||
@@ -17,5 +17,5 @@ exports.FunctionExpression = function (node, parent, scope, context) {
|
||||
};
|
||||
|
||||
exports.ThisExpression = function (node, parent, scope, context, file) {
|
||||
throw file.errorWithNode(node, "Top level `this` is not allowed", ReferenceError);
|
||||
throw file.errorWithNode(node, "Top level `this` is `undefined` in strict mode", ReferenceError);
|
||||
};
|
||||
|
||||
@@ -3,13 +3,13 @@
|
||||
var t = require("../../../types");
|
||||
|
||||
exports.BlockStatement = function (node, parent) {
|
||||
if (t.isFunction(parent) || t.isExportDeclaration(parent)) {
|
||||
if ((t.isFunction(parent) && parent.body === node) || t.isExportDeclaration(parent)) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (var i = 0; i < node.body.length; i++) {
|
||||
var func = node.body[i];
|
||||
if (!t.isFunctionDeclaration(i)) continue;
|
||||
if (!t.isFunctionDeclaration(func)) continue;
|
||||
|
||||
var declar = t.variableDeclaration("let", [
|
||||
t.variableDeclarator(func.id, t.toExpression(func))
|
||||
@@ -21,6 +21,6 @@ exports.BlockStatement = function (node, parent) {
|
||||
// todo: name this
|
||||
func.id = null;
|
||||
|
||||
func.body[i] = declar;
|
||||
node.body[i] = declar;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,64 +0,0 @@
|
||||
[
|
||||
"Set",
|
||||
"Map",
|
||||
"WeakMap",
|
||||
"WeakSet",
|
||||
"Proxy",
|
||||
"Promise",
|
||||
"Reflect",
|
||||
"Symbol",
|
||||
"System",
|
||||
"__filename",
|
||||
"__dirname",
|
||||
"GLOBAL",
|
||||
"global",
|
||||
"module",
|
||||
"require",
|
||||
"Buffer",
|
||||
"console",
|
||||
"exports",
|
||||
"process",
|
||||
"setTimeout",
|
||||
"clearTimeout",
|
||||
"setInterval",
|
||||
"clearInterval",
|
||||
"setImmediate",
|
||||
"clearImmediate",
|
||||
"Array",
|
||||
"Boolean",
|
||||
"Date",
|
||||
"decodeURI",
|
||||
"decodeURIComponent",
|
||||
"encodeURI",
|
||||
"encodeURIComponent",
|
||||
"Error",
|
||||
"eval",
|
||||
"EvalError",
|
||||
"Function",
|
||||
"hasOwnProperty",
|
||||
"isFinite",
|
||||
"isNaN",
|
||||
"JSON",
|
||||
"Map",
|
||||
"Math",
|
||||
"Number",
|
||||
"Object",
|
||||
"Proxy",
|
||||
"Promise",
|
||||
"parseInt",
|
||||
"parseFloat",
|
||||
"RangeError",
|
||||
"ReferenceError",
|
||||
"RegExp",
|
||||
"Set",
|
||||
"String",
|
||||
"SyntaxError",
|
||||
"TypeError",
|
||||
"URIError",
|
||||
"WeakMap",
|
||||
"WeakSet",
|
||||
"arguments",
|
||||
"NaN",
|
||||
"window",
|
||||
"self"
|
||||
]
|
||||
@@ -3,11 +3,13 @@
|
||||
module.exports = Scope;
|
||||
|
||||
var traverse = require("./index");
|
||||
var globals = require("globals");
|
||||
var object = require("../helpers/object");
|
||||
var t = require("../types");
|
||||
var each = require("lodash/collection/each");
|
||||
var has = require("lodash/object/has");
|
||||
var contains = require("lodash/collection/contains");
|
||||
var flatten = require("lodash/array/flatten");
|
||||
var defaults = require("lodash/object/defaults");
|
||||
|
||||
var FOR_KEYS = ["left", "init"];
|
||||
@@ -35,12 +37,12 @@ function Scope(block, parentBlock, parent, file) {
|
||||
this.declarationKinds = info.declarationKinds;
|
||||
}
|
||||
|
||||
Scope.defaultDeclarations = require("./global-keys");
|
||||
Scope.defaultDeclarations = flatten([globals.builtin, globals.browser, globals.node].map(Object.keys));
|
||||
|
||||
Scope.prototype._add = function (node, references, throwOnDuplicate) {
|
||||
if (!node) return;
|
||||
|
||||
var ids = t.getIds(node, true);
|
||||
var ids = t.getDeclarations(node);
|
||||
|
||||
for (var key in ids) {
|
||||
var id = ids[key];
|
||||
@@ -385,8 +387,11 @@ Scope.prototype.parentGet = function (id, decl) {
|
||||
*/
|
||||
|
||||
Scope.prototype.has = function (id, decl) {
|
||||
return (id && (this.hasOwn(id, decl) || this.parentHas(id, decl))) ||
|
||||
contains(Scope.defaultDeclarations, id);
|
||||
if (!id) return false;
|
||||
if (this.hasOwn(id, decl)) return true;
|
||||
if (this.parentHas(id, decl)) return true;
|
||||
if (contains(Scope.defaultDeclarations, id)) return true;
|
||||
return false;
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -8,15 +8,10 @@ var each = require("lodash/collection/each");
|
||||
var uniq = require("lodash/array/uniq");
|
||||
var compact = require("lodash/array/compact");
|
||||
var defaults = require("lodash/object/defaults");
|
||||
var keys = require("lodash/object/keys");
|
||||
var isString = require("lodash/lang/isString");
|
||||
|
||||
var t = exports;
|
||||
|
||||
t.NATIVE_TYPE_NAMES = ["Array", "Object", "Number", "Boolean", "Date", "Array", "String"];
|
||||
|
||||
//
|
||||
|
||||
/**
|
||||
* Registers `is[Type]` and `assert[Type]` generated functions for a given `type`.
|
||||
* Pass `skipAliasCheck` to force it to directly compare `node.type` with `type`.
|
||||
@@ -39,8 +34,7 @@ function registerType(type, skipAliasCheck) {
|
||||
}
|
||||
|
||||
t.STATEMENT_OR_BLOCK_KEYS = ["consequent", "body"];
|
||||
|
||||
//
|
||||
t.NATIVE_TYPE_NAMES = ["Array", "Object", "Number", "Boolean", "Date", "Array", "String"];
|
||||
|
||||
t.VISITOR_KEYS = require("./visitor-keys");
|
||||
|
||||
@@ -66,6 +60,7 @@ each(t.FLIPPED_ALIAS_KEYS, function (types, type) {
|
||||
|
||||
/**
|
||||
* Returns whether `node` is of given `type`.
|
||||
*
|
||||
* For better performance, use this instead of `is[Type]` when `type` is unknown.
|
||||
* Optionally, pass `skipAliasCheck` to directly compare `node.type` with `type`.
|
||||
*
|
||||
@@ -156,6 +151,9 @@ t.isFalsyExpression = function (node) {
|
||||
* declarations hoisted to the top of the current scope.
|
||||
*
|
||||
* Expression statements are just resolved to their standard expression.
|
||||
*
|
||||
* @param {Array} nodes
|
||||
* @param {Scope} scope
|
||||
*/
|
||||
|
||||
t.toSequenceExpression = function (nodes, scope) {
|
||||
@@ -185,17 +183,23 @@ t.toSequenceExpression = function (nodes, scope) {
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
/*
|
||||
* Description
|
||||
*
|
||||
* @param {Object} actual
|
||||
* @param {Object} expected
|
||||
* @returns {Boolean}
|
||||
*/
|
||||
|
||||
t.shallowEqual = function (actual, expected) {
|
||||
var keys = Object.keys(expected);
|
||||
var key;
|
||||
|
||||
for (var i = 0; i < keys.length; i++) {
|
||||
key = keys[i];
|
||||
var key = keys[i];
|
||||
|
||||
if (actual[key] !== expected[key])
|
||||
if (actual[key] !== expected[key]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -330,7 +334,7 @@ t.isReferenced = function (node, parent) {
|
||||
};
|
||||
|
||||
/**
|
||||
* Description
|
||||
* Check if the input `node` is an `Identifier` and `isReferenced`.
|
||||
*
|
||||
* @param {Object} node
|
||||
* @param {Object} parent
|
||||
@@ -342,7 +346,8 @@ t.isReferencedIdentifier = function (node, parent) {
|
||||
};
|
||||
|
||||
/**
|
||||
* Description
|
||||
* Check if the input `name` is a valid identifier name
|
||||
* and isn't a reserved word.
|
||||
*
|
||||
* @param {String} name
|
||||
* @returns {Boolean}
|
||||
@@ -502,12 +507,10 @@ t.toBlock = function (node, parent) {
|
||||
* declaration then it's assumed to be an assignable.
|
||||
*
|
||||
* @param {Object} node
|
||||
* @param {Boolean} [map]
|
||||
* @param {Array} [ignoreTypes]
|
||||
* @returns {Array|Object}
|
||||
*/
|
||||
|
||||
t.getIds = function (node, map, ignoreTypes) {
|
||||
t.getDeclarations = function (node) {
|
||||
var search = [].concat(node);
|
||||
var ids = object();
|
||||
|
||||
@@ -515,13 +518,7 @@ t.getIds = function (node, map, ignoreTypes) {
|
||||
var id = search.shift();
|
||||
if (!id) continue;
|
||||
|
||||
// blacklist types
|
||||
if (ignoreTypes && ignoreTypes.indexOf(id.type) >= 0) continue;
|
||||
|
||||
var nodeKeys = t.getIds.nodes[id.type];
|
||||
var arrKeys = t.getIds.arrays[id.type];
|
||||
|
||||
var i, key;
|
||||
var keys = t.getDeclarations.keys[id.type];
|
||||
|
||||
if (t.isIdentifier(id)) {
|
||||
ids[id.name] = id;
|
||||
@@ -529,27 +526,18 @@ t.getIds = function (node, map, ignoreTypes) {
|
||||
if (t.isDeclaration(node.declaration)) {
|
||||
search.push(node.declaration);
|
||||
}
|
||||
} else if (nodeKeys) {
|
||||
for (i = 0; i < nodeKeys.length; i++) {
|
||||
key = nodeKeys[i];
|
||||
if (id[key]) {
|
||||
search.push(id[key]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else if (arrKeys) {
|
||||
for (i = 0; i < arrKeys.length; i++) {
|
||||
key = arrKeys[i];
|
||||
} else if (keys) {
|
||||
for (var i = 0; i < keys.length; i++) {
|
||||
var key = keys[i];
|
||||
search = search.concat(id[key] || []);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!map) ids = keys(ids);
|
||||
return ids;
|
||||
};
|
||||
|
||||
t.getIds.nodes = {
|
||||
t.getDeclarations.keys = {
|
||||
AssignmentExpression: ["left"],
|
||||
ImportBatchSpecifier: ["name"],
|
||||
ImportSpecifier: ["name", "id"],
|
||||
@@ -562,10 +550,7 @@ t.getIds.nodes = {
|
||||
RestElement: ["argument"],
|
||||
Property: ["value"],
|
||||
ComprehensionBlock: ["left"],
|
||||
AssignmentPattern: ["left"]
|
||||
};
|
||||
|
||||
t.getIds.arrays = {
|
||||
AssignmentPattern: ["left"],
|
||||
PrivateDeclaration: ["declarations"],
|
||||
ComprehensionExpression: ["blocks"],
|
||||
ImportDeclaration: ["specifiers"],
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "6to5",
|
||||
"description": "Turn ES6 code into readable vanilla ES5 with source maps",
|
||||
"version": "3.1.1",
|
||||
"version": "3.2.0",
|
||||
"author": "Sebastian McKenzie <sebmck@gmail.com>",
|
||||
"homepage": "https://6to5.org/",
|
||||
"repository": "6to5/6to5",
|
||||
@@ -42,8 +42,8 @@
|
||||
"detect-indent": "3.0.0",
|
||||
"estraverse": "1.9.1",
|
||||
"esutils": "1.1.6",
|
||||
"esvalid": "1.1.0",
|
||||
"fs-readdir-recursive": "0.1.0",
|
||||
"globals": "^5.1.0",
|
||||
"js-tokenizer": "1.3.3",
|
||||
"lodash": "3.0.0",
|
||||
"output-file-sync": "1.1.0",
|
||||
@@ -59,6 +59,7 @@
|
||||
"devDependencies": {
|
||||
"browserify": "8.1.1",
|
||||
"chai": "1.10.0",
|
||||
"esvalid": "1.1.0",
|
||||
"istanbul": "0.3.5",
|
||||
"jscs": "1.10.0",
|
||||
"jshint": "2.6.0",
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "6to5-runtime",
|
||||
"description": "6to5 selfContained runtime",
|
||||
"version": "3.1.0",
|
||||
"version": "3.1.1",
|
||||
"repository": "6to5/6to5",
|
||||
"author": "Sebastian McKenzie <sebmck@gmail.com>"
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
var util = require("../lib/6to5/util");
|
||||
var path = require("path");
|
||||
var fs = require("fs");
|
||||
var _ = require("lodash");
|
||||
@@ -17,6 +18,13 @@ var readFile = exports.readFile = function (filename) {
|
||||
}
|
||||
};
|
||||
|
||||
exports.assertVendor = function (name) {
|
||||
if (!fs.existsSync(__dirname + "/../vendor/" + name)) {
|
||||
console.error("No vendor/" + name + " - run `make bootstrap`");
|
||||
process.exit(1);
|
||||
}
|
||||
};
|
||||
|
||||
exports.get = function (entryName, entryLoc) {
|
||||
if (exports.cache[entryName]) return exports.cache[entryName];
|
||||
|
||||
@@ -34,8 +42,8 @@ exports.get = function (entryName, entryLoc) {
|
||||
};
|
||||
suites.push(suite);
|
||||
|
||||
var suiteOptsLoc = suite.filename + "/options.json";
|
||||
if (fs.existsSync(suiteOptsLoc)) suite.options = require(suiteOptsLoc);
|
||||
var suiteOptsLoc = util.resolve(suite.filename + "/options");
|
||||
if (suiteOptsLoc) suite.options = require(suiteOptsLoc);
|
||||
|
||||
if (fs.statSync(suite.filename).isFile()) {
|
||||
push(suiteName, suite.filename);
|
||||
@@ -71,8 +79,8 @@ exports.get = function (entryName, entryLoc) {
|
||||
sourceMapName: expectLocAlias
|
||||
}, _.cloneDeep(suite.options));
|
||||
|
||||
var taskOptsLoc = taskDir + "/options.json";
|
||||
if (fs.existsSync(taskOptsLoc)) _.merge(taskOpts, require(taskOptsLoc));
|
||||
var taskOptsLoc = util.resolve(taskDir + "/options");
|
||||
if (taskOptsLoc) _.merge(taskOpts, require(taskOptsLoc));
|
||||
|
||||
var test = {
|
||||
title: humanise(taskName, true),
|
||||
|
||||
@@ -125,12 +125,14 @@ var run = function (task, done) {
|
||||
module.exports = function (suiteOpts, taskOpts, dynamicOpts) {
|
||||
taskOpts = taskOpts || {};
|
||||
|
||||
require("../register")(taskOpts);
|
||||
|
||||
_.each(helper.get(suiteOpts.name, suiteOpts.loc), function (testSuite) {
|
||||
if (_.contains(suiteOpts.ignoreSuites, testSuite.title)) return;
|
||||
|
||||
suite(suiteOpts.name + "/" + testSuite.title, function () {
|
||||
setup(function () {
|
||||
require("../register")(taskOpts);
|
||||
});
|
||||
|
||||
_.each(testSuite.tests, function (task) {
|
||||
if (_.contains(suiteOpts.ignoreTasks, task.title) || _.contains(suiteOpts.ignoreTasks, testSuite.title + "/" + task.title)) return;
|
||||
|
||||
|
||||
@@ -2,6 +2,14 @@ class Base {
|
||||
get sound() {
|
||||
return 'I am a ' + this.type + '.';
|
||||
}
|
||||
|
||||
get name() {
|
||||
return this._name;
|
||||
}
|
||||
|
||||
set name(val) {
|
||||
this._name = val;
|
||||
}
|
||||
}
|
||||
|
||||
class Animal extends Base {}
|
||||
@@ -12,6 +20,18 @@ class Cat extends Animal {
|
||||
get sound() {
|
||||
return super.sound + ' MEOW!';
|
||||
}
|
||||
|
||||
get name() {
|
||||
return super.name;
|
||||
}
|
||||
|
||||
set name(val) {
|
||||
super.name = val + ' Cat';
|
||||
}
|
||||
}
|
||||
|
||||
assert.equal(new Cat().sound, 'I am a cat. MEOW!');
|
||||
var cat = new Cat();
|
||||
|
||||
assert.equal(cat.sound, 'I am a cat. MEOW!');
|
||||
cat.name = 'Nyan';
|
||||
assert.equal(cat.name, 'Nyan Cat');
|
||||
|
||||
3
test/fixtures/transformation/api/resolve-module-source/actual.js
vendored
Normal file
3
test/fixtures/transformation/api/resolve-module-source/actual.js
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
export { foo } from "foo-export-named";
|
||||
import foo from "foo-import-default";
|
||||
import "foo-import-bare";
|
||||
5
test/fixtures/transformation/api/resolve-module-source/expected.js
vendored
Normal file
5
test/fixtures/transformation/api/resolve-module-source/expected.js
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
"use strict";
|
||||
|
||||
export { foo } from "resolved/foo-export-named";
|
||||
import foo from "resolved/foo-import-default";
|
||||
import "resolved/foo-import-bare";
|
||||
5
test/fixtures/transformation/api/resolve-module-source/options.js
vendored
Normal file
5
test/fixtures/transformation/api/resolve-module-source/options.js
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
exports.blacklist = ["es6.modules"];
|
||||
|
||||
exports.resolveModuleSource = function (originalSource) {
|
||||
return "resolved/" + originalSource;
|
||||
};
|
||||
15
test/fixtures/transformation/es6-block-scoping-exec/label.js
vendored
Normal file
15
test/fixtures/transformation/es6-block-scoping-exec/label.js
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
var heh = [];
|
||||
var nums = [1, 2, 3];
|
||||
|
||||
loop1:
|
||||
for (let i in nums) {
|
||||
let num = nums[i];
|
||||
heh.push(x => x * num);
|
||||
if (num >= 2) {
|
||||
break loop1;
|
||||
}
|
||||
}
|
||||
|
||||
assert.equal(heh.length, 2);
|
||||
assert.equal(heh[0](2), 2);
|
||||
assert.equal(heh[1](4), 8);
|
||||
4
test/fixtures/transformation/es6-block-scoping-exec/multiple.js
vendored
Normal file
4
test/fixtures/transformation/es6-block-scoping-exec/multiple.js
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
for (let i = 0, x = 2; i < 5; i++);
|
||||
|
||||
assert.ok(typeof i === "undefined");
|
||||
assert.ok(typeof x === "undefined");
|
||||
22
test/fixtures/transformation/es6-block-scoping-exec/nested-labels-2.js
vendored
Normal file
22
test/fixtures/transformation/es6-block-scoping-exec/nested-labels-2.js
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
(function () {
|
||||
var stack = [];
|
||||
|
||||
loop1:
|
||||
for (let j = 0; j < 10; j++) {
|
||||
for (let i = 0; i < 10; i++) {
|
||||
stack.push(() => [i, j]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
assert.deepEqual(stack[0](), [0, 0]);
|
||||
assert.deepEqual(stack[1](), [0, 1]);
|
||||
assert.deepEqual(stack[2](), [0, 2]);
|
||||
assert.deepEqual(stack[3](), [0, 3]);
|
||||
assert.deepEqual(stack[4](), [0, 4]);
|
||||
assert.deepEqual(stack[5](), [0, 5]);
|
||||
assert.deepEqual(stack[6](), [0, 6]);
|
||||
assert.deepEqual(stack[7](), [0, 7]);
|
||||
assert.deepEqual(stack[8](), [0, 8]);
|
||||
assert.deepEqual(stack[9](), [0, 9]);
|
||||
})();
|
||||
25
test/fixtures/transformation/es6-block-scoping-exec/nested-labels-3.js
vendored
Normal file
25
test/fixtures/transformation/es6-block-scoping-exec/nested-labels-3.js
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
(function () {
|
||||
var stack = [];
|
||||
|
||||
loop1:
|
||||
for (let j = 0; j < 10; j++) {
|
||||
loop2:
|
||||
for (let i = 0; i < 10; i++) {
|
||||
for (let x = 0; x < 10; x++) {
|
||||
stack.push(() => [j, i, x]);
|
||||
continue loop2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
assert.deepEqual(stack[0](), [0, 0, 0]);
|
||||
assert.deepEqual(stack[1](), [0, 1, 0]);
|
||||
assert.deepEqual(stack[2](), [0, 2, 0]);
|
||||
assert.deepEqual(stack[3](), [0, 3, 0]);
|
||||
assert.deepEqual(stack[4](), [0, 4, 0]);
|
||||
assert.deepEqual(stack[5](), [0, 5, 0]);
|
||||
assert.deepEqual(stack[6](), [0, 6, 0]);
|
||||
assert.deepEqual(stack[7](), [0, 7, 0]);
|
||||
assert.deepEqual(stack[8](), [0, 8, 0]);
|
||||
assert.deepEqual(stack[9](), [0, 9, 0]);
|
||||
})();
|
||||
22
test/fixtures/transformation/es6-block-scoping-exec/nested-labels.js
vendored
Normal file
22
test/fixtures/transformation/es6-block-scoping-exec/nested-labels.js
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
(function () {
|
||||
var stack = [];
|
||||
|
||||
loop1:
|
||||
for (let j = 0; j < 10; j++) {
|
||||
for (let i = 0; i < 10; i++) {
|
||||
stack.push(() => [i, j]);
|
||||
continue loop1;
|
||||
}
|
||||
}
|
||||
|
||||
assert.deepEqual(stack[0](), [0, 0]);
|
||||
assert.deepEqual(stack[1](), [0, 1]);
|
||||
assert.deepEqual(stack[2](), [0, 2]);
|
||||
assert.deepEqual(stack[3](), [0, 3]);
|
||||
assert.deepEqual(stack[4](), [0, 4]);
|
||||
assert.deepEqual(stack[5](), [0, 5]);
|
||||
assert.deepEqual(stack[6](), [0, 6]);
|
||||
assert.deepEqual(stack[7](), [0, 7]);
|
||||
assert.deepEqual(stack[8](), [0, 8]);
|
||||
assert.deepEqual(stack[9](), [0, 9]);
|
||||
})();
|
||||
@@ -1,7 +1,7 @@
|
||||
"use strict";
|
||||
|
||||
(function () {
|
||||
_loop: for (var i in nums) {
|
||||
for (var i in nums) {
|
||||
var _ret = (function (i) {
|
||||
fns.push(function () {
|
||||
return i;
|
||||
@@ -18,10 +18,10 @@
|
||||
})(i);
|
||||
|
||||
switch (_ret) {
|
||||
case "break":
|
||||
break _loop;
|
||||
case "continue":
|
||||
continue _loop;
|
||||
continue;
|
||||
case "break":
|
||||
break;
|
||||
default:
|
||||
if (typeof _ret === "object") return _ret.v;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
"use strict";
|
||||
|
||||
_loop: for (var i in nums) {
|
||||
for (var i in nums) {
|
||||
var _ret = (function (i) {
|
||||
fns.push(function () {
|
||||
return i;
|
||||
@@ -8,5 +8,5 @@ _loop: for (var i in nums) {
|
||||
return "break";
|
||||
})(i);
|
||||
|
||||
if (_ret === "break") break _loop;
|
||||
if (_ret === "break") break;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
"use strict";
|
||||
|
||||
_loop: for (var i in nums) {
|
||||
for (var i in nums) {
|
||||
var _ret = (function (i) {
|
||||
fns.push(function () {
|
||||
return i;
|
||||
@@ -8,5 +8,5 @@ _loop: for (var i in nums) {
|
||||
return "continue";
|
||||
})(i);
|
||||
|
||||
if (_ret === "continue") continue _loop;
|
||||
if (_ret === "continue") continue;
|
||||
}
|
||||
|
||||
3
test/fixtures/transformation/es6-parameters.rest/pattern/actual.js
vendored
Normal file
3
test/fixtures/transformation/es6-parameters.rest/pattern/actual.js
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
var foo = function (...[a, b]) {
|
||||
|
||||
};
|
||||
14
test/fixtures/transformation/es6-parameters.rest/pattern/expected.js
vendored
Normal file
14
test/fixtures/transformation/es6-parameters.rest/pattern/expected.js
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
"use strict";
|
||||
|
||||
var _slicedToArray = function (arr, i) { if (Array.isArray(arr)) { return arr; } else { var _arr = []; for (var _iterator = arr[Symbol.iterator](), _step; !(_step = _iterator.next()).done;) { _arr.push(_step.value); if (i && _arr.length === i) break; } return _arr; } };
|
||||
|
||||
var foo = function () {
|
||||
for (var _len = arguments.length, _ref = Array(_len), _key = 0; _key < _len; _key++) {
|
||||
_ref[_key] = arguments[_key];
|
||||
}
|
||||
|
||||
var _ref2 = _slicedToArray(_ref, 2);
|
||||
|
||||
var a = _ref2[0];
|
||||
var b = _ref2[1];
|
||||
};
|
||||
@@ -1,3 +1,7 @@
|
||||
var foo = function () {
|
||||
return () => <this />;
|
||||
};
|
||||
|
||||
var bar = function () {
|
||||
return () => <this.foo />;
|
||||
};
|
||||
|
||||
@@ -4,3 +4,10 @@ var foo = function () {
|
||||
return React.createElement(_this, null);
|
||||
};
|
||||
};
|
||||
|
||||
var bar = function () {
|
||||
var _this = this;
|
||||
return function () {
|
||||
return React.createElement(_this.foo, null);
|
||||
};
|
||||
};
|
||||
|
||||
1
test/fixtures/transformation/self-contained/modules-amd/actual.js
vendored
Normal file
1
test/fixtures/transformation/self-contained/modules-amd/actual.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
import foo from "foo";
|
||||
6
test/fixtures/transformation/self-contained/modules-amd/expected.js
vendored
Normal file
6
test/fixtures/transformation/self-contained/modules-amd/expected.js
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
define(["exports", "foo", "6to5-runtime/helpers"], function (exports, _foo, _to5RuntimeHelpers) {
|
||||
"use strict";
|
||||
|
||||
var _to5Helpers = _to5RuntimeHelpers;
|
||||
var foo = _to5Helpers.interopRequire(_foo);
|
||||
});
|
||||
1
test/fixtures/transformation/self-contained/modules-common/actual.js
vendored
Normal file
1
test/fixtures/transformation/self-contained/modules-common/actual.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
import foo from "foo";
|
||||
5
test/fixtures/transformation/self-contained/modules-common/expected.js
vendored
Normal file
5
test/fixtures/transformation/self-contained/modules-common/expected.js
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
"use strict";
|
||||
|
||||
var _to5Helpers = require("6to5-runtime/helpers");
|
||||
|
||||
var foo = _to5Helpers.interopRequire(require("foo"));
|
||||
1
test/fixtures/transformation/self-contained/modules-system/actual.js
vendored
Normal file
1
test/fixtures/transformation/self-contained/modules-system/actual.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
foo(...bar);
|
||||
13
test/fixtures/transformation/self-contained/modules-system/expected.js
vendored
Normal file
13
test/fixtures/transformation/self-contained/modules-system/expected.js
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
System.register(["6to5-runtime/helpers"], function (_export) {
|
||||
"use strict";
|
||||
|
||||
var _to5Helpers;
|
||||
return {
|
||||
setters: [function (_to5RuntimeHelpers) {
|
||||
_to5Helpers = _to5RuntimeHelpers;
|
||||
}],
|
||||
execute: function () {
|
||||
foo.apply(undefined, _to5Helpers.toArray(bar));
|
||||
}
|
||||
};
|
||||
});
|
||||
3
test/fixtures/transformation/self-contained/modules-system/options.json
vendored
Normal file
3
test/fixtures/transformation/self-contained/modules-system/options.json
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"modules": "system"
|
||||
}
|
||||
1
test/fixtures/transformation/self-contained/modules-umd/actual.js
vendored
Normal file
1
test/fixtures/transformation/self-contained/modules-umd/actual.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
import foo from "foo";
|
||||
12
test/fixtures/transformation/self-contained/modules-umd/expected.js
vendored
Normal file
12
test/fixtures/transformation/self-contained/modules-umd/expected.js
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
(function (factory) {
|
||||
if (typeof define === "function" && define.amd) {
|
||||
define(["exports", "foo", "6to5-runtime/helpers"], factory);
|
||||
} else if (typeof exports !== "undefined") {
|
||||
factory(exports, require("foo"), require("6to5-runtime/helpers"));
|
||||
}
|
||||
})(function (exports, _foo, _to5RuntimeHelpers) {
|
||||
"use strict";
|
||||
|
||||
var _to5Helpers = _to5RuntimeHelpers;
|
||||
var foo = _to5Helpers.interopRequire(_foo);
|
||||
});
|
||||
3
test/fixtures/transformation/self-contained/modules-umd/options.json
vendored
Normal file
3
test/fixtures/transformation/self-contained/modules-umd/options.json
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"modules": "umd"
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
import foo from "someModule";
|
||||
@@ -1,6 +0,0 @@
|
||||
define(["exports", "someModule", "6to5-runtime/helpers"], function (exports, _someModule, _to5RuntimeHelpers) {
|
||||
"use strict";
|
||||
|
||||
var _to5Helpers = _to5RuntimeHelpers;
|
||||
var foo = _to5Helpers.interopRequire(_someModule);
|
||||
});
|
||||
@@ -1 +0,0 @@
|
||||
import * as foo from "someModule";
|
||||
@@ -1,5 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
var _to5Helpers = require("6to5-runtime/helpers");
|
||||
|
||||
var foo = _to5Helpers.interopRequireWildcard(require("someModule"));
|
||||
@@ -1,3 +1,3 @@
|
||||
{
|
||||
"throws": "Top level `this` is not allowed"
|
||||
"throws": "Top level `this` is `undefined` in strict mode"
|
||||
}
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
{
|
||||
"throws": "Top level `this` is not allowed"
|
||||
"throws": "Top level `this` is `undefined` in strict mode"
|
||||
}
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
{
|
||||
"throws": "Top level `this` is not allowed"
|
||||
"throws": "Top level `this` is `undefined` in strict mode"
|
||||
}
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
{
|
||||
"throws": "Top level `this` is not allowed"
|
||||
"throws": "Top level `this` is `undefined` in strict mode"
|
||||
}
|
||||
|
||||
75
test/kangax.js
Normal file
75
test/kangax.js
Normal file
@@ -0,0 +1,75 @@
|
||||
require("./_helper").assertVendor("compat-table");
|
||||
|
||||
require("../polyfill");
|
||||
|
||||
var transform = require("../lib/6to5/transformation/transform");
|
||||
var assert = require("assert");
|
||||
var data = require("../vendor/compat-table/data-es6");
|
||||
var _ = require("lodash");
|
||||
|
||||
|
||||
global.__createIterableObject = function (a, b, c) {
|
||||
var arr = [a, b, c, ,];
|
||||
var iterable = {
|
||||
next: function() {
|
||||
return { value: arr.shift(), done: arr.length <= 0 };
|
||||
},
|
||||
};
|
||||
iterable[Symbol.iterator] = function(){ return iterable; }
|
||||
return iterable;
|
||||
};
|
||||
|
||||
var tests = {};
|
||||
|
||||
_.each(data.tests, function (test, key) {
|
||||
if (test.subtests) {
|
||||
_.extend(tests, test.subtests);
|
||||
} else {
|
||||
tests[test.name] = test;
|
||||
}
|
||||
});
|
||||
|
||||
suite("kangax/compat-table", function () {
|
||||
for (var key in tests) {
|
||||
var data = tests[key];
|
||||
|
||||
if (data.res._6to5 !== true) continue;
|
||||
|
||||
var exec = data.exec;
|
||||
var code = exec.toString().match(/[^]*\/\*([^]*)\*\/\}$/)[1];
|
||||
|
||||
// eval test
|
||||
if (_.contains(code, "eval") || _.contains(code, "Function")) continue;
|
||||
|
||||
// async test
|
||||
if (_.contains(code, "function check() {")) continue;
|
||||
|
||||
test(key, function () {
|
||||
code = transform(code, {
|
||||
filename: key,
|
||||
blacklist: ["useStrict"],
|
||||
optional: ["spec.typeofSymbol", "es6.blockScopingTDZ"]
|
||||
}).code;
|
||||
|
||||
code = '"use strict";\n' + code;
|
||||
|
||||
var fn;
|
||||
try {
|
||||
fn = new Function(code);
|
||||
} catch (err) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
var fn = new Function(code);
|
||||
assert.ok(fn.call(undefined));
|
||||
} catch (err) {
|
||||
if (err.message === "Cannot redefine property: name") {
|
||||
return;
|
||||
} else {
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -1,9 +1,6 @@
|
||||
if (!process.env.ALL_6TO5_TESTS) return;
|
||||
|
||||
require("../register")({
|
||||
blacklist: ["useStrict"],
|
||||
experimental: true
|
||||
});
|
||||
require("./_helper").assertVendor("regenerator");
|
||||
|
||||
var transform = require("../lib/6to5/transformation/transform");
|
||||
var fs = require("fs");
|
||||
@@ -11,13 +8,17 @@ var _ = require("lodash");
|
||||
|
||||
var regeneratorLoc = __dirname + "/../vendor/regenerator";
|
||||
|
||||
if (!fs.existsSync(regeneratorLoc)) {
|
||||
console.error("No vendor/regenerator - run `make bootstrap`");
|
||||
process.exit(1);
|
||||
}
|
||||
suite("regenerator", function () {
|
||||
setup(function () {
|
||||
require("../register")({
|
||||
blacklist: ["useStrict"],
|
||||
experimental: true
|
||||
});
|
||||
});
|
||||
|
||||
_.each(["tests", "async"], function (filename) {
|
||||
var loc = regeneratorLoc + "/test/" + filename + ".es6.js";
|
||||
var code = fs.readFileSync(loc, "utf8");
|
||||
require(loc);
|
||||
_.each(["tests", "async"], function (filename) {
|
||||
var loc = regeneratorLoc + "/test/" + filename + ".es6.js";
|
||||
var code = fs.readFileSync(loc, "utf8");
|
||||
require(loc);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
if (process.env.SIMPLE_6TO5_TESTS) return;
|
||||
|
||||
require("./_helper").assertVendor("test262");
|
||||
|
||||
var transform = require("../lib/6to5/transformation/transform");
|
||||
var readdir = require("fs-readdir-recursive");
|
||||
var path = require("path");
|
||||
@@ -7,10 +9,6 @@ var fs = require("fs");
|
||||
var _ = require("lodash");
|
||||
|
||||
var test262Loc = __dirname + "/../vendor/test262";
|
||||
if (!fs.existsSync(test262Loc)) {
|
||||
console.error("No vendor/test262 - run `make bootstrap`");
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
var read = function (loc) {
|
||||
return readdir(loc).map(function (filename) {
|
||||
|
||||
@@ -1,17 +1,13 @@
|
||||
if (!process.env.ALL_6TO5_TESTS) return;
|
||||
|
||||
require("./_helper").assertVendor("traceur");
|
||||
|
||||
var fs = require("fs");
|
||||
var _ = require("lodash");
|
||||
|
||||
var traceurLoc = __dirname + "/../vendor/traceur";
|
||||
if (!fs.existsSync(traceurLoc)) {
|
||||
console.error("No vendor/traceur - run `make bootstrap`");
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
require("./_transformation-helper")({
|
||||
name: "traceur",
|
||||
loc: traceurLoc + "/test/feature",
|
||||
loc: __dirname + "/../vendor/traceur/test/feature",
|
||||
|
||||
ignoreSuites: [
|
||||
// these are all internal traceur tests or non-standard features
|
||||
|
||||
1
vendor/compat-table
vendored
Submodule
1
vendor/compat-table
vendored
Submodule
Submodule vendor/compat-table added at 40499d421f
Reference in New Issue
Block a user