Compare commits
14 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
833e8b091b | ||
|
|
23ebb23944 | ||
|
|
778cab33d5 | ||
|
|
5849c6af17 | ||
|
|
bb0655d8f6 | ||
|
|
9977a5f614 | ||
|
|
9318d63b5c | ||
|
|
b2ab0dbedc | ||
|
|
e0d3e18865 | ||
|
|
3a3ad4775b | ||
|
|
40fdd2a828 | ||
|
|
12f66e852a | ||
|
|
c61c9aab56 | ||
|
|
7adc919bb6 |
@@ -9,3 +9,11 @@ branches:
|
||||
|
||||
before_script: "npm install -g codeclimate-test-reporter"
|
||||
script: "make test-travis"
|
||||
|
||||
notifications:
|
||||
webhooks:
|
||||
urls:
|
||||
- https://webhooks.gitter.im/e/acf1870e9d223c65e8d5
|
||||
on_success: always
|
||||
on_failure: always
|
||||
on_start: false
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
var transform = require("./transformation/transform");
|
||||
var util = require("./util");
|
||||
var fs = require("fs");
|
||||
var _ = require("lodash");
|
||||
|
||||
@@ -14,6 +15,8 @@ exports.polyfill = function () {
|
||||
require("./polyfill");
|
||||
};
|
||||
|
||||
exports.canCompile = util.canCompile;
|
||||
|
||||
exports.transform = transform;
|
||||
|
||||
exports.transformFile = function (filename, opts, callback) {
|
||||
|
||||
@@ -11,16 +11,7 @@ module.exports = function (namespace) {
|
||||
var container = t.functionExpression(null, [], t.blockStatement(body));
|
||||
var tree = t.program([t.expressionStatement(t.callExpression(container, []))]);
|
||||
|
||||
body.push(t.variableDeclaration("var", [
|
||||
t.variableDeclarator(t.identifier("self"), t.conditionalExpression(
|
||||
t.binaryExpression("===",
|
||||
t.unaryExpression("typeof", t.identifier("global"), true),
|
||||
t.literal("undefined")
|
||||
),
|
||||
t.identifier("window"),
|
||||
t.identifier("global"))
|
||||
)
|
||||
]));
|
||||
body.push(util.template("self-global", true));
|
||||
|
||||
body.push(t.variableDeclaration("var", [
|
||||
t.variableDeclarator(
|
||||
|
||||
1
lib/6to5/templates/let-scoping-return.js
Normal file
1
lib/6to5/templates/let-scoping-return.js
Normal file
@@ -0,0 +1 @@
|
||||
if (typeof RETURN === "object") return RETURN.v;
|
||||
1
lib/6to5/templates/self-global.js
Normal file
1
lib/6to5/templates/self-global.js
Normal file
@@ -0,0 +1 @@
|
||||
var self = typeof global === "undefined" ? window : global;
|
||||
@@ -20,7 +20,16 @@ transform._ensureTransformerNames = function (type, keys) {
|
||||
});
|
||||
};
|
||||
|
||||
transform.transformers = {
|
||||
transform.transformers = {};
|
||||
|
||||
transform.moduleFormatters = {
|
||||
common: require("./modules/common"),
|
||||
ignore: require("./modules/ignore"),
|
||||
amd: require("./modules/amd"),
|
||||
umd: require("./modules/umd")
|
||||
};
|
||||
|
||||
_.each({
|
||||
modules: require("./transformers/modules"),
|
||||
propertyNameShorthand: require("./transformers/property-name-shorthand"),
|
||||
constants: require("./transformers/constants"),
|
||||
@@ -53,15 +62,6 @@ transform.transformers = {
|
||||
useStrict: require("./transformers/use-strict"),
|
||||
|
||||
_moduleFormatter: require("./transformers/_module-formatter")
|
||||
};
|
||||
|
||||
transform.moduleFormatters = {
|
||||
common: require("./modules/common"),
|
||||
ignore: require("./modules/ignore"),
|
||||
amd: require("./modules/amd"),
|
||||
umd: require("./modules/umd")
|
||||
};
|
||||
|
||||
_.each(transform.transformers, function (transformer, key) {
|
||||
}, function (transformer, key) {
|
||||
transform.transformers[key] = new Transformer(key, transformer);
|
||||
});
|
||||
|
||||
@@ -11,21 +11,7 @@ var buildVariableAssign = function (kind, id, init) {
|
||||
}
|
||||
};
|
||||
|
||||
var normalise = function (node) {
|
||||
if (t.isParenthesizedExpression(node)) {
|
||||
return node.expression;
|
||||
} else {
|
||||
return node;
|
||||
}
|
||||
};
|
||||
|
||||
var isPattern = function (node) {
|
||||
return t.isPattern(normalise(node));
|
||||
};
|
||||
|
||||
var push = function (kind, nodes, elem, parentId) {
|
||||
elem = normalise(elem);
|
||||
|
||||
if (t.isObjectPattern(elem)) {
|
||||
pushObjectPattern(kind, nodes, elem, parentId);
|
||||
} else if (t.isArrayPattern(elem)) {
|
||||
@@ -42,7 +28,7 @@ var pushObjectPattern = function (kind, nodes, pattern, parentId) {
|
||||
var pattern2 = prop.value;
|
||||
var patternId2 = t.memberExpression(parentId, prop.key);
|
||||
|
||||
if (isPattern(pattern2)) {
|
||||
if (t.isPattern(pattern2)) {
|
||||
push(kind, nodes, pattern2, patternId2);
|
||||
} else {
|
||||
nodes.push(buildVariableAssign(kind, pattern2, patternId2));
|
||||
@@ -94,7 +80,7 @@ exports.ForOfStatement = function (node, parent, file, scope) {
|
||||
if (!t.isVariableDeclaration(declar)) return;
|
||||
|
||||
var pattern = declar.declarations[0].id;
|
||||
if (!isPattern(pattern)) return;
|
||||
if (!t.isPattern(pattern)) return;
|
||||
|
||||
var key = t.identifier(file.generateUid("ref", scope));
|
||||
node.left = t.variableDeclaration(declar.kind, [
|
||||
@@ -117,7 +103,7 @@ exports.Function = function (node, parent, file, scope) {
|
||||
var hasDestructuring = false;
|
||||
|
||||
node.params = node.params.map(function (pattern) {
|
||||
if (!isPattern(pattern)) return pattern;
|
||||
if (!t.isPattern(pattern)) return pattern;
|
||||
|
||||
hasDestructuring = true;
|
||||
var parentId = t.identifier(file.generateUid("ref", scope));
|
||||
@@ -146,7 +132,7 @@ exports.ExpressionStatement = function (node, parent, file, scope) {
|
||||
var expr = node.expression;
|
||||
if (expr.type !== "AssignmentExpression") return;
|
||||
|
||||
if (!isPattern(expr.left)) return;
|
||||
if (!t.isPattern(expr.left)) return;
|
||||
|
||||
var nodes = [];
|
||||
|
||||
@@ -167,7 +153,7 @@ exports.VariableDeclaration = function (node, parent, file, scope) {
|
||||
|
||||
var hasPattern = false;
|
||||
_.each(node.declarations, function (declar) {
|
||||
if (isPattern(declar.id)) {
|
||||
if (t.isPattern(declar.id)) {
|
||||
hasPattern = true;
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
var traverse = require("../../traverse");
|
||||
var util = require("../../util");
|
||||
var t = require("../../types");
|
||||
var _ = require("lodash");
|
||||
|
||||
@@ -287,10 +288,9 @@ var run = function (forParent, block, parent, file, scope) {
|
||||
|
||||
if (has.hasReturn) {
|
||||
// typeof ret === "object"
|
||||
retCheck = t.ifStatement(
|
||||
t.binaryExpression("===", t.unaryExpression("typeof", ret, true), t.literal("object")),
|
||||
t.returnStatement(t.memberExpression(ret, t.identifier("v")))
|
||||
);
|
||||
retCheck = util.template("let-scoping-return", {
|
||||
RETURN: ret,
|
||||
});
|
||||
|
||||
// there's no `break` or `continue` so we can just push in the `if`
|
||||
if (!has.hasBreak && !has.hasContinue) {
|
||||
|
||||
@@ -162,31 +162,17 @@ t.getIds = function (node, map) {
|
||||
|
||||
while (search.length) {
|
||||
var id = search.shift();
|
||||
if (!id) continue;
|
||||
|
||||
var nodeKey = t.getIds.nodes[id.type];
|
||||
var arrKey = t.getIds.arrays[id.type];
|
||||
|
||||
if (t.isIdentifier(id)) {
|
||||
ids[id.name] = id;
|
||||
} else if (t.isArrayPattern(id)) {
|
||||
_.each(id.elements, function (elem) {
|
||||
search.push(elem);
|
||||
});
|
||||
} else if (t.isAssignmentExpression(id)) {
|
||||
search.push(id.left);
|
||||
} else if (t.isObjectPattern(id)) {
|
||||
_.each(id.properties, function (prop) {
|
||||
search.push(prop.value);
|
||||
});
|
||||
} else if (t.isVariableDeclaration(id)) {
|
||||
search = search.concat(id.declarations);
|
||||
} else if (t.isImportSpecifier(id) || t.isExportSpecifier(id) || t.isVariableDeclarator(id) || t.isFunctionDeclaration(id) || t.isClassDeclaration(id)) {
|
||||
search.push(id.id);
|
||||
} else if (t.isSpreadElement(id)) {
|
||||
search.push(id.argument);
|
||||
} else if (t.isExportDeclaration(id) || t.isImportDeclaration(id)) {
|
||||
search = search.concat(id.specifiers);
|
||||
} else if (t.isMemberExpression(id)) {
|
||||
search.push(id.object);
|
||||
} else if (t.isParenthesizedExpression(id)) {
|
||||
search.push(id.expression);
|
||||
} else if (nodeKey) {
|
||||
if (id[nodeKey]) search.push(id[nodeKey]);
|
||||
} else if (arrKey) {
|
||||
search = search.concat(id[arrKey] || []);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -194,6 +180,27 @@ t.getIds = function (node, map) {
|
||||
return ids;
|
||||
};
|
||||
|
||||
t.getIds.nodes = {
|
||||
AssignmentExpression: "left",
|
||||
ImportSpecifier: "id",
|
||||
ExportSpecifier: "id",
|
||||
VariableDeclarator: "id",
|
||||
FunctionDeclaration: "id",
|
||||
ClassDeclaration: "id",
|
||||
ParenthesizedExpression: "expression",
|
||||
MemeberExpression: "object",
|
||||
SpreadElement: "argument",
|
||||
Property: "value"
|
||||
};
|
||||
|
||||
t.getIds.arrays = {
|
||||
ExportDeclaration: "specifiers",
|
||||
ImportDeclaration: "specifiers",
|
||||
VariableDeclaration: "declarations",
|
||||
ArrayPattern: "elements",
|
||||
ObjectPattern: "properties"
|
||||
};
|
||||
|
||||
t.inherits = function (child, parent) {
|
||||
child.loc = parent.loc;
|
||||
child.end = parent.end;
|
||||
|
||||
@@ -11,6 +11,12 @@ var _ = require("lodash");
|
||||
|
||||
exports.inherits = util.inherits;
|
||||
|
||||
exports.canCompile = function (filename, altExts) {
|
||||
var exts = altExts || [".js", ".jsx", ".es6"];
|
||||
var ext = path.extname(filename);
|
||||
return _.contains(exts, ext);
|
||||
};
|
||||
|
||||
exports.resolve = function (loc) {
|
||||
try {
|
||||
return require.resolve(loc);
|
||||
@@ -111,6 +117,11 @@ exports.template = function (name, nodes, keepExpression) {
|
||||
var template = exports.templates[name];
|
||||
if (!template) throw new ReferenceError("unknown template " + name);
|
||||
|
||||
if (nodes === true) {
|
||||
keepExpression = true;
|
||||
nodes = null;
|
||||
}
|
||||
|
||||
template = _.cloneDeep(template);
|
||||
|
||||
var inherits = false;
|
||||
@@ -192,13 +203,14 @@ exports.parse = function (opts, code, callback) {
|
||||
var tokens = [];
|
||||
|
||||
var ast = acorn.parse(code, {
|
||||
preserveParens: true,
|
||||
ecmaVersion: Infinity,
|
||||
strictMode: true,
|
||||
onComment: comments,
|
||||
locations: true,
|
||||
onToken: tokens,
|
||||
ranges: true
|
||||
allowReturnOutsideFunction: true,
|
||||
preserveParens: true,
|
||||
ecmaVersion: Infinity,
|
||||
strictMode: true,
|
||||
onComment: comments,
|
||||
locations: true,
|
||||
onToken: tokens,
|
||||
ranges: true
|
||||
});
|
||||
|
||||
estraverse.attachComments(ast, comments, tokens);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "6to5",
|
||||
"description": "Turn ES6 code into readable vanilla ES5 with source maps",
|
||||
"version": "1.11.2",
|
||||
"version": "1.11.4",
|
||||
"author": "Sebastian McKenzie <sebmck@gmail.com>",
|
||||
"homepage": "https://github.com/6to5/6to5",
|
||||
"repository": {
|
||||
@@ -48,7 +48,7 @@
|
||||
"chokidar": "0.10.5",
|
||||
"source-map-support": "0.2.8",
|
||||
"esutils": "1.1.4",
|
||||
"acorn-6to5": "https://github.com/6to5/acorn-6to5/archive/f5110383517eef0bea78c2da2a1fb01fbed74e4e.tar.gz",
|
||||
"acorn-6to5": "https://github.com/6to5/acorn-6to5/archive/49e421660af161af0e75c2fa066ea356d6650e69.tar.gz",
|
||||
"estraverse": "^1.7.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
({ t: t }) = obj;
|
||||
({
|
||||
t: { C: C }
|
||||
}) = obj;
|
||||
({ a, b, c }) = obj;
|
||||
@@ -1,5 +0,0 @@
|
||||
({ t: t }) = obj;
|
||||
({
|
||||
t: { C: C }
|
||||
}) = obj;
|
||||
({ a, b, c }) = obj;
|
||||
@@ -1,2 +1 @@
|
||||
[a, b] = f();
|
||||
({ x }) = e();
|
||||
|
||||
@@ -4,6 +4,3 @@ var _ref = f();
|
||||
|
||||
a = _ref[0];
|
||||
b = _ref[1];
|
||||
var _ref2 = e();
|
||||
|
||||
x = _ref2.x;
|
||||
|
||||
Reference in New Issue
Block a user