Compare commits
33 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4763b95a0d | ||
|
|
9fe1e37ca7 | ||
|
|
8a9aac3e68 | ||
|
|
27138abd29 | ||
|
|
dcf91db475 | ||
|
|
ab63345764 | ||
|
|
a35e63fb29 | ||
|
|
3fe7df9a48 | ||
|
|
5288f3afda | ||
|
|
25566a24f6 | ||
|
|
2ff6dee0ec | ||
|
|
491d1238c2 | ||
|
|
234414c2f2 | ||
|
|
3ff544bbab | ||
|
|
416c4cbb84 | ||
|
|
db5bf1749b | ||
|
|
41349afea3 | ||
|
|
27da6de723 | ||
|
|
2cdb4e3343 | ||
|
|
981d3e40f8 | ||
|
|
c7a616730c | ||
|
|
5aa8ece242 | ||
|
|
8c7ba20f86 | ||
|
|
1cc9027fcf | ||
|
|
e63dbaa646 | ||
|
|
4a720625d9 | ||
|
|
ad428b107a | ||
|
|
c0299320f0 | ||
|
|
efaee3d5d9 | ||
|
|
12bee73070 | ||
|
|
82c18a837d | ||
|
|
fed51e8246 | ||
|
|
71f17e464f |
18
CHANGELOG.md
18
CHANGELOG.md
@@ -11,11 +11,29 @@
|
||||
|
||||
_Note: Gaps between patch versions are faulty/broken releases._
|
||||
|
||||
## 3.3.1
|
||||
|
||||
* **Bug Fix**
|
||||
* Block hoist assignment pattern destructuring.
|
||||
|
||||
## 3.3.0
|
||||
|
||||
* **Bug Fix**
|
||||
* Do all transforms before the regenerator transform is ran.
|
||||
* **New Feature**
|
||||
* Added back the 2.x optional runtime.
|
||||
|
||||
## 3.2.1
|
||||
|
||||
* **Bug Fix**
|
||||
* Fix block scoping transformer rewriting breaks and continues to inner labels.
|
||||
|
||||
## 3.2.0
|
||||
|
||||
* **Bug Fix**
|
||||
* Fixed scope tracking for default parameters IIFE.
|
||||
* Fixed block scoped functions.
|
||||
* Improved `bin/6to5` path resolution.
|
||||
* **New Feature**
|
||||
* You can now trigger super setters in classes. Thanks [@kruppel](https://github.com/kruppel)!
|
||||
* Add `resolveSourceMap` option.
|
||||
|
||||
4
Makefile
4
Makefile
@@ -21,6 +21,9 @@ build:
|
||||
node $(BROWSERIFY_CMD) lib/6to5/browser.js -s to5 >dist/6to5.js
|
||||
node $(UGLIFY_CMD) dist/6to5.js >dist/6to5.min.js
|
||||
|
||||
node bin/6to5-runtime >dist/runtime.js
|
||||
node $(UGLIFY_CMD) dist/runtime.js >dist/runtime.min.js
|
||||
|
||||
rm -rf templates.json
|
||||
|
||||
clean:
|
||||
@@ -77,6 +80,7 @@ publish:
|
||||
make build
|
||||
cp dist/6to5.min.js browser.js
|
||||
cp dist/polyfill.min.js browser-polyfill.js
|
||||
cp dist/runtime.min.js runtime.js
|
||||
|
||||
node tools/cache-templates
|
||||
test -f templates.json
|
||||
|
||||
4
bin/6to5-runtime
Executable file
4
bin/6to5-runtime
Executable file
@@ -0,0 +1,4 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
var runtime = require("../lib/6to5/build-runtime");
|
||||
console.log(runtime());
|
||||
@@ -1,7 +1,7 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
var commander = require("commander");
|
||||
var transform = require("../../lib/6to5/transformation/transform");
|
||||
var transform = require("../../lib/6to5/transformation");
|
||||
var util = require("../../lib/6to5/util");
|
||||
var fs = require("fs");
|
||||
var each = require("lodash/collection/each");
|
||||
@@ -11,6 +11,7 @@ commander.option("-t, --source-maps-inline", "Append sourceMappingURL comment to
|
||||
commander.option("-s, --source-maps", "Save source map alongside the compiled code");
|
||||
commander.option("-f, --filename [filename]", "Filename to use when reading from stdin - this will be used in source-maps, errors etc [stdin]", "stdin");
|
||||
commander.option("-w, --watch", "Recompile files on changes");
|
||||
commander.option("-r, --runtime", "Replace 6to5 declarations with references to a runtime");
|
||||
commander.option("-e, --experimental", "Enable experimental support for proposed ES7 features");
|
||||
commander.option("-p, --playground", "Enable playground support");
|
||||
|
||||
@@ -108,6 +109,7 @@ exports.opts = {
|
||||
sourceMap: commander.sourceMaps || commander.sourceMapsInline,
|
||||
optional: commander.optional,
|
||||
comments: !commander.removeComments,
|
||||
runtime: commander.runtime,
|
||||
modules: commander.modules,
|
||||
loose: commander.loose
|
||||
};
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
"use strict";
|
||||
|
||||
var transform = module.exports = require("./transformation/transform");
|
||||
var transform = module.exports = require("./transformation");
|
||||
|
||||
transform.version = require("../../package").version;
|
||||
|
||||
|
||||
13
lib/6to5/build-helpers.js
Normal file
13
lib/6to5/build-helpers.js
Normal file
@@ -0,0 +1,13 @@
|
||||
var File = require("./file");
|
||||
var util = require("./util");
|
||||
var each = require("lodash/collection/each");
|
||||
var t = require("./types");
|
||||
|
||||
module.exports = function (body, namespace) {
|
||||
each(File.helpers, function (name) {
|
||||
var key = t.identifier(t.toIdentifier(name));
|
||||
body.push(t.expressionStatement(
|
||||
t.assignmentExpression("=", t.memberExpression(namespace, key), util.template(name))
|
||||
));
|
||||
});
|
||||
};
|
||||
25
lib/6to5/build-runtime.js
Normal file
25
lib/6to5/build-runtime.js
Normal file
@@ -0,0 +1,25 @@
|
||||
"use strict";
|
||||
|
||||
var buildHelpers = require("./build-helpers");
|
||||
var generator = require("./generation");
|
||||
var util = require("./util");
|
||||
var t = require("./types");
|
||||
|
||||
module.exports = function () {
|
||||
var namespace = t.identifier("to5Runtime");
|
||||
|
||||
var body = [];
|
||||
var container = t.functionExpression(null, [t.identifier("global")], t.blockStatement(body));
|
||||
var tree = t.program([t.expressionStatement(t.callExpression(container, [util.template("self-global")]))]);
|
||||
|
||||
body.push(t.variableDeclaration("var", [
|
||||
t.variableDeclarator(
|
||||
namespace,
|
||||
t.assignmentExpression("=", t.memberExpression(t.identifier("global"), namespace), t.objectExpression([]))
|
||||
)
|
||||
]));
|
||||
|
||||
buildHelpers(body, namespace);
|
||||
|
||||
return generator(tree).code;
|
||||
};
|
||||
@@ -1,7 +1,29 @@
|
||||
//exports.canRun = function (ast, userAgent) {
|
||||
module.exports = detect;
|
||||
|
||||
//};
|
||||
var SYNTAX_KEYS = require("./syntax-keys");
|
||||
var traverse = require("../traverse");
|
||||
var visitors = traverse.explode(require("./visitors"));
|
||||
|
||||
//exports.whoCanRun = function (ast, userAgent) {
|
||||
function detect(ast) {
|
||||
var stats = {
|
||||
syntax: {},
|
||||
builtins: {}
|
||||
};
|
||||
|
||||
//};
|
||||
var detectedSyntax = function (name) {
|
||||
stats.syntax[name] = true;
|
||||
};
|
||||
|
||||
traverse(ast, {
|
||||
enter: function (node, parent) {
|
||||
if (SYNTAX_KEYS[node.type]) {
|
||||
detectedSyntax(SYNTAX_KEYS[node.type]);
|
||||
}
|
||||
|
||||
var visitor = visitors[node.type];
|
||||
if (visitor) visitor(node, parent, detectedSyntax);
|
||||
}
|
||||
});
|
||||
|
||||
return stats;
|
||||
}
|
||||
|
||||
84
lib/6to5/detection/syntax-keys.json
Normal file
84
lib/6to5/detection/syntax-keys.json
Normal file
@@ -0,0 +1,84 @@
|
||||
{
|
||||
"ArrowFunctionExpression": "es6.arrowFunctions",
|
||||
|
||||
"AwaitExpression": "es7.asyncFunctions",
|
||||
|
||||
"ClassBody": "es6.classes",
|
||||
"ClassDeclaration": "es6.classes",
|
||||
"ClassExpression": "es6.classes",
|
||||
"MethodDefinition": "es6.classes",
|
||||
|
||||
"ComprehensionBlock": "es7.comprehensions",
|
||||
"ComprehensionExpression": "es7.comprehensions",
|
||||
|
||||
"ForOfStatement": "es6.forOf",
|
||||
|
||||
"ExportBatchSpecifier": "es6.modules",
|
||||
"ExportDeclaration": "es6.modules",
|
||||
"ExportSpecifier": "es6.modules",
|
||||
"ImportBatchSpecifier": "es6.modules",
|
||||
"ImportDeclaration": "es6.modules",
|
||||
"ImportSpecifier": "es6.modules",
|
||||
|
||||
"ArrayPattern": "es6.destructuring",
|
||||
"AssignmentPattern": "es6.destructuring",
|
||||
"ObjectPattern": "es6.destructuring",
|
||||
|
||||
"RestElement": "es6.parameters.rest",
|
||||
|
||||
"SpreadElement": "es6.spread",
|
||||
|
||||
"SpreadProperty": "es7.objectSpread",
|
||||
|
||||
"TaggedTemplateExpression": "es6.templateLiterals",
|
||||
"TemplateElement": "es6.templateLiterals",
|
||||
"TemplateLiteral": "es6.templateLiterals",
|
||||
|
||||
"VirtualPropertyExpression": "es7.abstractReferences",
|
||||
"PrivateDeclaration": "es7.abstractReferences",
|
||||
|
||||
"YieldExpression": "es6.generators",
|
||||
|
||||
"AnyTypeAnnotation": "flow",
|
||||
"ArrayTypeAnnotation": "flow",
|
||||
"BooleanTypeAnnotation": "flow",
|
||||
"ClassProperty": "flow",
|
||||
"DeclareClass": "flow",
|
||||
"DeclareFunction": "flow",
|
||||
"DeclareModule": "flow",
|
||||
"DeclareVariable": "flow",
|
||||
"FunctionTypeAnnotation": "flow",
|
||||
"FunctionTypeParam": "flow",
|
||||
"GenericTypeAnnotation": "flow",
|
||||
"InterfaceExtends": "flow",
|
||||
"InterfaceDeclaration": "flow",
|
||||
"IntersectionTypeAnnotation": "flow",
|
||||
"NullableTypeAnnotation": "flow",
|
||||
"NumberTypeAnnotation": "flow",
|
||||
"StringLiteralTypeAnnotation": "flow",
|
||||
"StringTypeAnnotation": "flow",
|
||||
"TupleTypeAnnotation": "flow",
|
||||
"TypeofTypeAnnotation": "flow",
|
||||
"TypeAlias": "flow",
|
||||
"TypeAnnotation": "flow",
|
||||
"TypeParameterDeclaration": "flow",
|
||||
"TypeParameterInstantiation": "flow",
|
||||
"ObjectTypeAnnotation": "flow",
|
||||
"ObjectTypeCallProperty": "flow",
|
||||
"ObjectTypeIndexer": "flow",
|
||||
"ObjectTypeProperty": "flow",
|
||||
"QualifiedTypeIdentifier": "flow",
|
||||
"UnionTypeAnnotation": "flow",
|
||||
"VoidTypeAnnotation": "flow",
|
||||
|
||||
"JSXAttribute": "jsx",
|
||||
"JSXClosingElement": "jsx",
|
||||
"JSXElement": "jsx",
|
||||
"JSXEmptyExpression": "jsx",
|
||||
"JSXExpressionContainer": "jsx",
|
||||
"JSXIdentifier": "jsx",
|
||||
"JSXMemberExpression": "jsx",
|
||||
"JSXNamespacedName": "jsx",
|
||||
"JSXOpeningElement": "jsx",
|
||||
"JSXSpreadAttribute": "jsx"
|
||||
}
|
||||
54
lib/6to5/detection/visitors.js
Normal file
54
lib/6to5/detection/visitors.js
Normal file
@@ -0,0 +1,54 @@
|
||||
var t = require("../types");
|
||||
var _ = require("lodash");
|
||||
|
||||
exports.AssignmentExpression = function (node, parent, detected) {
|
||||
if (node.operator === "**=") {
|
||||
detected("es6.exponentation");
|
||||
}
|
||||
};
|
||||
|
||||
exports.BinaryExpression = function (node, parent, detected) {
|
||||
if (node.operator === "**") {
|
||||
detected("es6.exponentation");
|
||||
}
|
||||
};
|
||||
|
||||
exports.VariableDeclaration = function (node, parent, detected) {
|
||||
if (node.kind === "let" || node.kind === "const") {
|
||||
detected("es6.blockScoping");
|
||||
}
|
||||
|
||||
if (node.kind === "const") {
|
||||
detected("es6.constants");
|
||||
}
|
||||
};
|
||||
|
||||
exports.Property = function (node, parent, detected) {
|
||||
if (node.shorthand || node.method) {
|
||||
detected("es6.properties.shorthand");
|
||||
}
|
||||
|
||||
if (node.kind === "set" || node.kind === "get") {
|
||||
detected("es5.properties.mutators");
|
||||
}
|
||||
|
||||
if (node.computed) {
|
||||
detected("es6.properties.computed");
|
||||
}
|
||||
};
|
||||
|
||||
exports.AssignmentPattern = function (node, parent, detected) {
|
||||
if (t.isFunction(parent) && _.contains(parent.params, node)) {
|
||||
detected("es6.parameters.default");
|
||||
}
|
||||
};
|
||||
|
||||
exports.Function = function (node, parent, detected) {
|
||||
if (node.generator) {
|
||||
detected("es6.generators");
|
||||
}
|
||||
|
||||
if (node.async) {
|
||||
detected("es7.asyncFunctions");
|
||||
}
|
||||
};
|
||||
@@ -4,8 +4,8 @@ module.exports = File;
|
||||
|
||||
var SHEBANG_REGEX = /^\#\!.*/;
|
||||
|
||||
var transform = require("./transformation/transform");
|
||||
var generate = require("./generation/generator");
|
||||
var transform = require("./transformation");
|
||||
var generate = require("./generation");
|
||||
var clone = require("./helpers/clone");
|
||||
var Scope = require("./traverse/scope");
|
||||
var util = require("./util");
|
||||
@@ -24,7 +24,7 @@ function File(opts) {
|
||||
this.data = {};
|
||||
|
||||
this.lastStatements = [];
|
||||
this.opts = File.normaliseOptions(opts);
|
||||
this.opts = this.normaliseOptions(opts);
|
||||
this.ast = {};
|
||||
|
||||
this.buildTransformers();
|
||||
@@ -76,6 +76,7 @@ File.validOptions = [
|
||||
"playground",
|
||||
"experimental",
|
||||
"resolveModuleSource",
|
||||
"runtime",
|
||||
|
||||
// these are used by plugins
|
||||
"ignore",
|
||||
@@ -84,7 +85,7 @@ File.validOptions = [
|
||||
"accept"
|
||||
];
|
||||
|
||||
File.normaliseOptions = function (opts) {
|
||||
File.prototype.normaliseOptions = function (opts) {
|
||||
opts = clone(opts);
|
||||
|
||||
for (var key in opts) {
|
||||
@@ -108,6 +109,7 @@ File.normaliseOptions = function (opts) {
|
||||
comments: true,
|
||||
filename: "unknown",
|
||||
modules: "common",
|
||||
runtime: false,
|
||||
loose: [],
|
||||
code: true,
|
||||
ast: true
|
||||
@@ -146,6 +148,10 @@ File.normaliseOptions = function (opts) {
|
||||
opts.experimental = true;
|
||||
}
|
||||
|
||||
if (opts.runtime) {
|
||||
this.set("runtimeIdentifier", t.identifier("to5Runtime"));
|
||||
}
|
||||
|
||||
opts.blacklist = transform._ensureTransformerNames("blacklist", opts.blacklist);
|
||||
opts.whitelist = transform._ensureTransformerNames("whitelist", opts.whitelist);
|
||||
opts.optional = transform._ensureTransformerNames("optional", opts.optional);
|
||||
|
||||
@@ -40,9 +40,11 @@ each(Buffer.prototype, function (fn, key) {
|
||||
});
|
||||
|
||||
CodeGenerator.normaliseOptions = function (code, opts) {
|
||||
var indent = detectIndent(code);
|
||||
var style = indent.indent;
|
||||
if (!style || style === " ") style = " ";
|
||||
var style = " ";
|
||||
if (code) {
|
||||
var indent = detectIndent(code).indent;
|
||||
if (indent && indent !== " ") style = indent;
|
||||
}
|
||||
|
||||
return merge({
|
||||
parentheses: true,
|
||||
38
lib/6to5/helpers/levenshtein.js
Normal file
38
lib/6to5/helpers/levenshtein.js
Normal file
@@ -0,0 +1,38 @@
|
||||
// taken from stackoverflow, it's crap i know.
|
||||
|
||||
module.exports = function (a, b) {
|
||||
if (a.length === 0) return b.length;
|
||||
if (b.length === 0) return a.length;
|
||||
|
||||
var matrix = [];
|
||||
|
||||
// increment along the first column of each row
|
||||
var i;
|
||||
for (i = 0; i <= b.length; i++) {
|
||||
matrix[i] = [i];
|
||||
}
|
||||
|
||||
// increment each column in the first row
|
||||
var j;
|
||||
for (j = 0; j <= a.length; j++) {
|
||||
matrix[0][j] = j;
|
||||
}
|
||||
|
||||
// Fill in the rest of the matrix
|
||||
for (i = 1; i <= b.length; i++) {
|
||||
for (j = 1; j <= a.length; j++) {
|
||||
if (b.charAt(i - 1) == a.charAt(j - 1)) {
|
||||
matrix[i][j] = matrix[i - 1][j - 1];
|
||||
} else {
|
||||
matrix[i][j] = Math.min(
|
||||
matrix[i - 1][j - 1] + 1, // substitution
|
||||
Math.min(
|
||||
matrix[i][j - 1] + 1, // insertion
|
||||
matrix[i - 1][j] + 1) // deletion
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return matrix[b.length][a.length];
|
||||
};
|
||||
@@ -1,12 +1,14 @@
|
||||
"use strict";
|
||||
|
||||
var transform = require("./transformation/transform");
|
||||
var transform = require("./transformation");
|
||||
var util = require("./util");
|
||||
var fs = require("fs");
|
||||
var isFunction = require("lodash/lang/isFunction");
|
||||
|
||||
exports.version = require("../../package").version;
|
||||
|
||||
exports.runtime = require("./build-runtime");
|
||||
|
||||
exports.types = require("./types");
|
||||
|
||||
exports.register = function (opts) {
|
||||
|
||||
22
lib/6to5/transformation/helpers/react.js
vendored
Normal file
22
lib/6to5/transformation/helpers/react.js
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
var t = require("../../types");
|
||||
|
||||
var isCreateClassCallExpression = t.buildMatchMemberExpression("React.createClass");
|
||||
|
||||
exports.isCreateClass = function (node) {
|
||||
if (!node || !t.isCallExpression(node)) return false;
|
||||
|
||||
// not React.createClass call member object
|
||||
if (!isCreateClassCallExpression(node.callee)) return false;
|
||||
|
||||
// no call arguments
|
||||
var args = node.arguments;
|
||||
if (args.length !== 1) return false;
|
||||
|
||||
// first node arg is not an object
|
||||
var first = args[0];
|
||||
if (!t.isObjectExpression(first)) return false;
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
exports.isReactComponent = t.buildMatchMemberExpression("React.Component");
|
||||
@@ -3,9 +3,9 @@
|
||||
module.exports = CommonJSFormatter;
|
||||
|
||||
var DefaultFormatter = require("./_default");
|
||||
var contains = require("lodash/collection/contains");
|
||||
var util = require("../../util");
|
||||
var t = require("../../types");
|
||||
var contains = require("lodash/collection/contains");
|
||||
|
||||
function CommonJSFormatter() {
|
||||
DefaultFormatter.apply(this, arguments);
|
||||
|
||||
@@ -41,6 +41,8 @@ TransformerPass.prototype.canRun = function () {
|
||||
|
||||
if (transformer.experimental && !opts.experimental) return false;
|
||||
|
||||
if (transformer.playground && !opts.playground) return false;
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
module.exports = Transformer;
|
||||
|
||||
var TransformerPass = require("./transformer-pass");
|
||||
var t = require("../types");
|
||||
var isFunction = require("lodash/lang/isFunction");
|
||||
var traverse = require("../traverse");
|
||||
var isObject = require("lodash/lang/isObject");
|
||||
var each = require("lodash/collection/each");
|
||||
|
||||
@@ -17,6 +17,7 @@ var each = require("lodash/collection/each");
|
||||
function Transformer(key, transformer, opts) {
|
||||
this.manipulateOptions = transformer.manipulateOptions;
|
||||
this.experimental = !!transformer.experimental;
|
||||
this.playground = !!transformer.playground;
|
||||
this.secondPass = !!transformer.secondPass;
|
||||
this.optional = !!transformer.optional;
|
||||
this.handlers = this.normalise(transformer);
|
||||
@@ -31,6 +32,8 @@ Transformer.prototype.normalise = function (transformer) {
|
||||
transformer = { ast: transformer };
|
||||
}
|
||||
|
||||
traverse.explode(transformer);
|
||||
|
||||
each(transformer, function (fns, type) {
|
||||
// hidden property
|
||||
if (type[0] === "_") {
|
||||
@@ -46,13 +49,6 @@ Transformer.prototype.normalise = function (transformer) {
|
||||
if (!fns.exit) fns.exit = function () { };
|
||||
|
||||
transformer[type] = fns;
|
||||
|
||||
var aliases = t.FLIPPED_ALIAS_KEYS[type];
|
||||
if (aliases) {
|
||||
each(aliases, function (alias) {
|
||||
transformer[alias] = fns;
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
return transformer;
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
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");
|
||||
@@ -311,9 +310,9 @@ var loopVisitor = {
|
||||
var replace;
|
||||
|
||||
if (t.isLoop(node)) {
|
||||
state = clone(state);
|
||||
state.ignoreLabeless = true;
|
||||
traverse(node, loopVisitor, scope, state);
|
||||
state.ignoreLabeless = false;
|
||||
}
|
||||
|
||||
if (t.isFunction(node) || t.isLoop(node)) {
|
||||
@@ -324,9 +323,15 @@ var loopVisitor = {
|
||||
|
||||
if (loopText) {
|
||||
if (node.label) {
|
||||
// we shouldn't be transforming this because it exists somewhere inside
|
||||
if (state.innerLabels.indexOf(node.label.name) >= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
loopText = loopText + "|" + node.label.name;
|
||||
} else {
|
||||
// we shouldn't be dealing with this
|
||||
// we shouldn't be transforming these statements because
|
||||
// they don't refer to the actual loop we're scopifying
|
||||
if (state.ignoreLabeless) return;
|
||||
|
||||
// break statements mean something different in this context
|
||||
@@ -352,6 +357,14 @@ var loopVisitor = {
|
||||
}
|
||||
};
|
||||
|
||||
var loopLabelVisitor = {
|
||||
enter: function (node, parent, scope, context, state) {
|
||||
if (t.isLabeledStatement(node)) {
|
||||
state.innerLabels.push(node.label.name);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* If we're inside of a loop then traverse it and check if it has one of
|
||||
* the following node types `ReturnStatement`, `BreakStatement`,
|
||||
@@ -365,12 +378,15 @@ LetScoping.prototype.checkLoop = function () {
|
||||
var state = {
|
||||
hasBreakContinue: false,
|
||||
ignoreLabeless: false,
|
||||
innerLabels: [],
|
||||
hasReturn: false,
|
||||
isLoop: !!this.loopParent,
|
||||
map: {}
|
||||
};
|
||||
|
||||
traverse(this.block, loopLabelVisitor, this.scope, state);
|
||||
traverse(this.block, loopVisitor, this.scope, state);
|
||||
|
||||
return state;
|
||||
};
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ var visitor = {
|
||||
|
||||
exports.Scope = function (node, parent, scope, context, file) {
|
||||
traverse(node, visitor, scope, {
|
||||
constants: scope.getAllOfKind("const"),
|
||||
constants: scope.getAllDeclarationsOfKind("const"),
|
||||
file: file
|
||||
});
|
||||
};
|
||||
|
||||
@@ -46,9 +46,11 @@ var push = function (opts, nodes, elem, parentId) {
|
||||
var pushAssignmentPattern = function (opts, nodes, pattern, parentId) {
|
||||
var tempParentId = opts.scope.generateUidBasedOnNode(parentId, opts.file);
|
||||
|
||||
nodes.push(t.variableDeclaration("var", [
|
||||
var declar = t.variableDeclaration("var", [
|
||||
t.variableDeclarator(tempParentId, parentId)
|
||||
]));
|
||||
]);
|
||||
declar._blockHoist = opts.blockHoist;
|
||||
nodes.push(declar);
|
||||
|
||||
nodes.push(buildVariableAssign(
|
||||
opts,
|
||||
|
||||
@@ -58,15 +58,15 @@ exports.Function = function (node, parent, scope) {
|
||||
node.body.body.unshift(restDeclar);
|
||||
}
|
||||
|
||||
node.body.body.unshift(
|
||||
util.template("rest", {
|
||||
ARGUMENTS: argsId,
|
||||
ARRAY_KEY: arrKey,
|
||||
ARRAY_LEN: arrLen,
|
||||
START: start,
|
||||
ARRAY: rest,
|
||||
KEY: key,
|
||||
LEN: len,
|
||||
})
|
||||
);
|
||||
var loop = util.template("rest", {
|
||||
ARGUMENTS: argsId,
|
||||
ARRAY_KEY: arrKey,
|
||||
ARRAY_LEN: arrLen,
|
||||
START: start,
|
||||
ARRAY: rest,
|
||||
KEY: key,
|
||||
LEN: len,
|
||||
});
|
||||
loop._blockHoist = node.params.length + 1;
|
||||
node.body.body.unshift(loop);
|
||||
};
|
||||
|
||||
@@ -12,6 +12,7 @@ module.exports = {
|
||||
"playground.objectGetterMemoization": require("./playground/object-getter-memoization"),
|
||||
|
||||
react: require("./other/react"),
|
||||
"optimisation.react": require("./optimisation/react"),
|
||||
|
||||
_modules: require("./internal/modules"),
|
||||
|
||||
@@ -52,14 +53,13 @@ module.exports = {
|
||||
// needs to be after `es6.blockScoping` due to needing `letReferences` set on blocks
|
||||
"es6.blockScopingTDZ": require("./es6/block-scoping-tdz"),
|
||||
|
||||
// needs to be after block scoping since regenerator doesn't support it
|
||||
regenerator: require("./other/regenerator"),
|
||||
|
||||
"es6.parameters.default": require("./es6/parameters.default"),
|
||||
"es6.parameters.rest": require("./es6/parameters.rest"),
|
||||
|
||||
"es6.destructuring": require("./es6/destructuring"),
|
||||
|
||||
regenerator: require("./other/regenerator"),
|
||||
|
||||
// needs to be after `regenerator` due to needing `regeneratorRuntime` references
|
||||
// needs to be after `es6.forOf` due to needing `Symbol.iterator` references
|
||||
// needs to be before `es6.modules` due to dynamic imports
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
module.exports = BaseOptimiser;
|
||||
|
||||
var object = require("../../../../helpers/object");
|
||||
|
||||
/**
|
||||
* Description
|
||||
*
|
||||
* @param {Node} node
|
||||
*/
|
||||
|
||||
function BaseOptimiser(node) {
|
||||
this.methods = object();
|
||||
this.types = object();
|
||||
|
||||
this.node = node;
|
||||
}
|
||||
|
||||
/**
|
||||
* Description
|
||||
*/
|
||||
|
||||
BaseOptimiser.prototype.run = function () {
|
||||
this.getMethods();
|
||||
this.getTypes();
|
||||
};
|
||||
|
||||
/**
|
||||
* Add an `ObjectExpression` `node` that contains `propTypes`.
|
||||
*
|
||||
* Search it and match it against the types that we can optimise
|
||||
* and register it for consumption later.
|
||||
*
|
||||
* @param {Node} node
|
||||
*/
|
||||
|
||||
BaseOptimiser.prototype.addPropTypes = function (node) {
|
||||
var props = node.properties;
|
||||
|
||||
for (var i = 0; i < props.length; i++) {
|
||||
this.addPropType(props[i]);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Register a `Property` node as a prop type.
|
||||
*
|
||||
* We'll try and resolve it to a known type if we can and normalise
|
||||
* it for consumption later.
|
||||
*
|
||||
* @param {Node} prop
|
||||
*/
|
||||
|
||||
BaseOptimiser.prototype.addPropType = function () {
|
||||
|
||||
};
|
||||
@@ -0,0 +1,51 @@
|
||||
module.exports = CreateClassOptimiser;
|
||||
|
||||
var BaseOptimiser = require("./base");
|
||||
var util = require("../../../../util");
|
||||
var t = require("../../../../types");
|
||||
|
||||
function CreateClassOptimiser() {
|
||||
BaseOptimiser.apply(this, arguments);
|
||||
}
|
||||
|
||||
util.inherits(CreateClassOptimiser, BaseOptimiser);
|
||||
|
||||
/**
|
||||
* Get all function expressions.
|
||||
*/
|
||||
|
||||
CreateClassOptimiser.prototype.getMethods = function () {
|
||||
var props = this.node.properties;
|
||||
|
||||
for (var i = 0; i < props.length; i++) {
|
||||
var prop = props[i];
|
||||
|
||||
// irrelevant
|
||||
if (!t.isFunctionExpression(prop.value)) continue;
|
||||
|
||||
// deopt
|
||||
if (prop.computed) continue;
|
||||
|
||||
this.methods[prop.key.name] = prop;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Find a `propTypes` property.
|
||||
*/
|
||||
|
||||
CreateClassOptimiser.prototype.getTypes = function () {
|
||||
var props = this.node.properties;
|
||||
|
||||
for (var i = 0; i < props.length; i++) {
|
||||
var prop = props[i];
|
||||
var key = t.toComputedKey(prop, prop.key);
|
||||
|
||||
if (t.isLiteral(key, { value: "propTypes" }) && t.isObjectExpression(prop.value)) {
|
||||
this.addPropTypes(prop.value);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// not found
|
||||
};
|
||||
@@ -0,0 +1,17 @@
|
||||
var CreateClassOptimiser = require("./create-class");
|
||||
var NativeClassOptimiser = require("./native-class");
|
||||
var react = require("../../../helpers/react");
|
||||
|
||||
exports.optional = true;
|
||||
|
||||
exports.CallExpression = function (node) {
|
||||
if (react.isCreateClass(node)) {
|
||||
new CreateClassOptimiser(node.arguments[0]).run();
|
||||
}
|
||||
};
|
||||
|
||||
exports.CallExpression = function (node) {
|
||||
if (react.isReactComponent(node.superClass)) {
|
||||
new NativeClassOptimiser(node).run();
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,42 @@
|
||||
module.exports = NativeClassOptimiser;
|
||||
|
||||
var BaseOptimiser = require("./base");
|
||||
var util = require("../../../../util");
|
||||
var t = require("../../../../types");
|
||||
|
||||
function NativeClassOptimiser() {
|
||||
BaseOptimiser.apply(this, arguments);
|
||||
}
|
||||
|
||||
util.inherits(NativeClassOptimiser, BaseOptimiser);
|
||||
|
||||
/**
|
||||
* Get all instance methods.
|
||||
*/
|
||||
|
||||
NativeClassOptimiser.prototype.getMethods = function () {
|
||||
var body = this.node.body;
|
||||
|
||||
for (var i = 0; i < body.length; i++) {
|
||||
var node = body[i];
|
||||
|
||||
// PrivateDeclaration etc
|
||||
if (!t.isMethodDefinition(node)) continue;
|
||||
|
||||
// deopt
|
||||
if (node.computed) continue;
|
||||
|
||||
// irrelevant
|
||||
if (node.static) continue;
|
||||
|
||||
this.methods[node.key.name] = node;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Description
|
||||
*/
|
||||
|
||||
NativeClassOptimiser.prototype.getTypes = function () {
|
||||
|
||||
};
|
||||
@@ -6,6 +6,7 @@
|
||||
// jsx
|
||||
|
||||
var esutils = require("esutils");
|
||||
var react = require("../../helpers/react");
|
||||
var t = require("../../../types");
|
||||
|
||||
exports.JSXIdentifier = function (node, parent) {
|
||||
@@ -197,33 +198,8 @@ var cleanJSXElementLiteralChild = function (child, args) {
|
||||
|
||||
// display names
|
||||
|
||||
var isCreateClass = function (call) {
|
||||
if (!call || !t.isCallExpression(call)) return false;
|
||||
|
||||
var callee = call.callee;
|
||||
if (!t.isMemberExpression(callee)) return false;
|
||||
|
||||
// not React call member object
|
||||
var obj = callee.object;
|
||||
if (!t.isIdentifier(obj, { name: "React" })) return false;
|
||||
|
||||
// not createClass call member property
|
||||
var prop = callee.property;
|
||||
if (!t.isIdentifier(prop, { name: "createClass" })) return false;
|
||||
|
||||
// no call arguments
|
||||
var args = call.arguments;
|
||||
if (args.length !== 1) return false;
|
||||
|
||||
// first call arg is not an object
|
||||
var first = args[0];
|
||||
if (!t.isObjectExpression(first)) return;
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
var addDisplayName = function (id, call) {
|
||||
if (!isCreateClass(call)) return;
|
||||
if (!react.isCreateClass(call)) return;
|
||||
|
||||
var props = call.arguments[0].properties;
|
||||
var safe = true;
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
"use strict";
|
||||
|
||||
var build = require("../../helpers/build-conditional-assignment-operator-transformer");
|
||||
var t = require("../../../types");
|
||||
var t = require("../../../types");
|
||||
|
||||
exports.playground = true;
|
||||
|
||||
build(exports, {
|
||||
is: function (node, file) {
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
var build = require("../../helpers/build-conditional-assignment-operator-transformer");
|
||||
var t = require("../../../types");
|
||||
|
||||
exports.playground = true;
|
||||
|
||||
build(exports, {
|
||||
is: function (node) {
|
||||
var is = t.isAssignmentExpression(node) && node.operator === "?=";
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
var t = require("../../../types");
|
||||
|
||||
exports.playground = true;
|
||||
|
||||
exports.BindMemberExpression = function (node, parent, scope) {
|
||||
var object = node.object;
|
||||
var prop = node.property;
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
var traverse = require("../../../traverse");
|
||||
var t = require("../../../types");
|
||||
|
||||
exports.playground = true;
|
||||
|
||||
var visitor = {
|
||||
enter: function (node, parent, scope, context, state) {
|
||||
if (t.isFunction(node)) return;
|
||||
|
||||
@@ -1,9 +1,38 @@
|
||||
"use strict";
|
||||
|
||||
var levenshtein = require("../../../helpers/levenshtein");
|
||||
var t = require("../../../types");
|
||||
|
||||
exports.optional = true;
|
||||
|
||||
exports.Identifier = function (node, parent, scope, context, file) {
|
||||
if (!scope.has(node.name, true)) {
|
||||
throw file.errorWithNode(node, "Reference to undeclared variable", ReferenceError);
|
||||
if (!t.isReferenced(node, parent)) return;
|
||||
if (scope.has(node.name, true)) return;
|
||||
|
||||
var msg = "Reference to undeclared variable";
|
||||
|
||||
// get the closest declaration to offer as a suggestion
|
||||
// the variable name may have just been mistyped
|
||||
|
||||
var declarations = scope.getAllDeclarations();
|
||||
|
||||
var closest;
|
||||
var shortest = -1;
|
||||
|
||||
for (var name in declarations) {
|
||||
var distance = levenshtein(node.name, name);
|
||||
if (distance <= 0 || distance > 3) continue;
|
||||
if (distance <= shortest) continue;
|
||||
|
||||
closest = name;
|
||||
shortest = distance;
|
||||
}
|
||||
|
||||
if (closest) {
|
||||
msg += " - Did you mean " + closest + "?";
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
throw file.errorWithNode(node, msg, ReferenceError);
|
||||
};
|
||||
|
||||
@@ -237,6 +237,20 @@ traverse.removeProperties = function (tree) {
|
||||
return tree;
|
||||
};
|
||||
|
||||
traverse.explode = function (obj) {
|
||||
for (var type in obj) {
|
||||
var fns = obj[type];
|
||||
|
||||
var aliases = t.FLIPPED_ALIAS_KEYS[type];
|
||||
if (aliases) {
|
||||
for (var i = 0; i < aliases.length; i++) {
|
||||
obj[aliases[i]] = fns;
|
||||
}
|
||||
}
|
||||
}
|
||||
return obj;
|
||||
};
|
||||
|
||||
function hasBlacklistedType(node, parent, scope, context, state) {
|
||||
if (node.type === state.type) {
|
||||
state.has = true;
|
||||
|
||||
@@ -326,12 +326,31 @@ Scope.prototype.getFunctionParent = function () {
|
||||
};
|
||||
|
||||
/**
|
||||
* Walks the scope tree and gathers all declarations of `kind`.
|
||||
* Walks the scope tree and gathers **all** declarations.
|
||||
*
|
||||
* @returns {Object}
|
||||
*/
|
||||
|
||||
Scope.prototype.getAllOfKind = function (kind) {
|
||||
Scope.prototype.getAllDeclarations = function () {
|
||||
var ids = object();
|
||||
|
||||
var scope = this;
|
||||
do {
|
||||
defaults(ids, scope.declarations);
|
||||
scope = scope.parent;
|
||||
} while (scope);
|
||||
|
||||
return ids;
|
||||
};
|
||||
|
||||
/**
|
||||
* Walks the scope tree and gathers all declarations of `kind`.
|
||||
*
|
||||
* @param {String} kind
|
||||
* @returns {Object}
|
||||
*/
|
||||
|
||||
Scope.prototype.getAllDeclarationsOfKind = function (kind) {
|
||||
var ids = object();
|
||||
|
||||
var scope = this;
|
||||
|
||||
@@ -399,6 +399,60 @@ t.ensureBlock = function (node, key) {
|
||||
node[key] = t.toBlock(node[key], node);
|
||||
};
|
||||
|
||||
/**
|
||||
* Build a function that when called will return whether or not the
|
||||
* input `node` `MemberExpression` matches the input `match`.
|
||||
*
|
||||
* For example, given the match `React.createClass` it would match the
|
||||
* parsed nodes of `React.createClass` and `React["createClass"]`.
|
||||
*
|
||||
* @param {String} match Dot delimetered string
|
||||
* @returns {Function}
|
||||
*/
|
||||
|
||||
t.buildMatchMemberExpression = function (match) {
|
||||
var parts = match.split(".");
|
||||
|
||||
return function (member) {
|
||||
// not a member expression
|
||||
if (!t.isMemberExpression(member)) return false;
|
||||
|
||||
var search = [member];
|
||||
var i = 0;
|
||||
|
||||
while (search.length) {
|
||||
var node = search.shift();
|
||||
|
||||
if (t.isIdentifier(node)) {
|
||||
// this part doesn't match
|
||||
if (parts[i] !== node.name) return false;
|
||||
} else if (t.isLiteral(node)) {
|
||||
// this part doesn't match
|
||||
if (parts[i] !== node.value) return false;
|
||||
} else if (t.isMemberExpression(node)) {
|
||||
if (node.computed && !t.isLiteral(node.property)) {
|
||||
// we can't deal with this
|
||||
return false;
|
||||
} else {
|
||||
search.push(node.object);
|
||||
search.push(node.property);
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
// we can't deal with this
|
||||
return false;
|
||||
}
|
||||
|
||||
// too many parts
|
||||
if (++i > parts.length) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Description
|
||||
*
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "6to5",
|
||||
"description": "Turn ES6 code into readable vanilla ES5 with source maps",
|
||||
"version": "3.2.0",
|
||||
"version": "3.3.2",
|
||||
"author": "Sebastian McKenzie <sebmck@gmail.com>",
|
||||
"homepage": "https://6to5.org/",
|
||||
"repository": "6to5/6to5",
|
||||
@@ -9,7 +9,8 @@
|
||||
"main": "lib/6to5/index.js",
|
||||
"bin": {
|
||||
"6to5": "./bin/6to5/index.js",
|
||||
"6to5-node": "./bin/6to5-node"
|
||||
"6to5-node": "./bin/6to5-node",
|
||||
"6to5-runtime": "./bin/6to5-runtime"
|
||||
},
|
||||
"browser": {
|
||||
"./lib/6to5/index.js": "./lib/6to5/browser.js",
|
||||
@@ -48,7 +49,7 @@
|
||||
"lodash": "3.0.0",
|
||||
"output-file-sync": "1.1.0",
|
||||
"private": "0.1.6",
|
||||
"regenerator-6to5": "0.8.9-7",
|
||||
"regenerator-6to5": "0.8.9-8",
|
||||
"regexpu": "1.1.0",
|
||||
"roadrunner": "1.0.4",
|
||||
"source-map": "0.1.43",
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "6to5-runtime",
|
||||
"description": "6to5 selfContained runtime",
|
||||
"version": "3.1.1",
|
||||
"version": "3.3.1",
|
||||
"repository": "6to5/6to5",
|
||||
"author": "Sebastian McKenzie <sebmck@gmail.com>"
|
||||
}
|
||||
@@ -1,11 +1,10 @@
|
||||
"use strict";
|
||||
|
||||
var transform = require("../lib/6to5/transformation/transform");
|
||||
var File = require("../lib/6to5/file");
|
||||
var util = require("../lib/6to5/util");
|
||||
var fs = require("fs");
|
||||
var t = require("../lib/6to5/types");
|
||||
var _ = require("lodash");
|
||||
var buildHelpers = require("../lib/6to5/build-helpers");
|
||||
var transform = require("../lib/6to5/transformation");
|
||||
var fs = require("fs");
|
||||
var t = require("../lib/6to5/types");
|
||||
var _ = require("lodash");
|
||||
|
||||
var relative = function (filename) {
|
||||
return __dirname + "/6to5-runtime/" + filename;
|
||||
@@ -31,23 +30,18 @@ var updatePackage = function () {
|
||||
writeFile("package.json", JSON.stringify(pkg, null, 2));
|
||||
};
|
||||
|
||||
var buildHelpers = function () {
|
||||
var buildHelpers2 = function () {
|
||||
var body = [];
|
||||
var tree = t.program(body);
|
||||
|
||||
_.each(File.helpers, function (name) {
|
||||
var key = t.identifier(t.toIdentifier(name));
|
||||
body.push(t.expressionStatement(
|
||||
t.assignmentExpression("=", t.memberExpression(t.identifier("exports"), key), util.template(name))
|
||||
));
|
||||
});
|
||||
buildHelpers(body, t.identifier("exports"));
|
||||
|
||||
return transform.fromAst(tree, null, {
|
||||
optional: ["selfContained"]
|
||||
}).code;
|
||||
};
|
||||
|
||||
writeFile("helpers.js", buildHelpers());
|
||||
writeFile("helpers.js", buildHelpers2());
|
||||
writeFile("core-js.js", readFile("core-js/library"));
|
||||
writeFile("regenerator/index.js", readFile("regenerator-6to5/runtime-module"));
|
||||
writeFile("regenerator/runtime.js", readFile("regenerator-6to5/runtime"));
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
var genHelpers = require("./_generator-helpers");
|
||||
var transform = require("../lib/6to5/transformation/transform");
|
||||
var transform = require("../lib/6to5/transformation");
|
||||
var sourceMap = require("source-map");
|
||||
var codeFrame = require("../lib/6to5/helpers/code-frame");
|
||||
var esvalid = require("esvalid");
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
var transform = require("../lib/6to5/transformation/transform");
|
||||
var transform = require("../lib/6to5/transformation");
|
||||
var assert = require("assert");
|
||||
var File = require("../lib/6to5/file");
|
||||
|
||||
|
||||
140
test/detection.js
Normal file
140
test/detection.js
Normal file
@@ -0,0 +1,140 @@
|
||||
var detect = require("../lib/6to5/detection");
|
||||
var assert = require("assert");
|
||||
var util = require("../lib/6to5/util");
|
||||
|
||||
suite("detection", function () {
|
||||
var checkSyntax = function (code, name) {
|
||||
var ast = util.parse({
|
||||
experimental: true
|
||||
}, code);
|
||||
|
||||
assert.ok(detect(ast).syntax[name]);
|
||||
};
|
||||
|
||||
test("es5.properties.mutators", function () {
|
||||
checkSyntax("var obj = { get foo() {} };", "es5.properties.mutators");
|
||||
checkSyntax("var obj = { set foo() {} };", "es5.properties.mutators");
|
||||
});
|
||||
|
||||
test("es6.exponentation", function () {
|
||||
checkSyntax("x ** 2;", "es6.exponentation");
|
||||
checkSyntax("x **= 2;", "es6.exponentation");
|
||||
});
|
||||
|
||||
test("es6.blockScoping", function () {
|
||||
checkSyntax("let foo;", "es6.blockScoping");
|
||||
checkSyntax("let foo = bar;", "es6.blockScoping");
|
||||
checkSyntax("const foo = bar;", "es6.blockScoping");
|
||||
});
|
||||
|
||||
test("es6.constants", function () {
|
||||
checkSyntax("const foo = bar;", "es6.constants");
|
||||
});
|
||||
|
||||
test("es6.properties.shorthand", function () {
|
||||
checkSyntax("var obj = { foo };", "es6.properties.shorthand");
|
||||
checkSyntax("var obj = { foo };", "es6.properties.shorthand");
|
||||
});
|
||||
|
||||
test("es6.properties.computed", function () {
|
||||
checkSyntax("var obj = { [foo]: bar };", "es6.properties.computed");
|
||||
checkSyntax("var obj = { ['foo']: bar };", "es6.properties.computed");
|
||||
});
|
||||
|
||||
test("es6.parameters.default", function () {
|
||||
checkSyntax("var obj = (foo = bar) => {};", "es6.parameters.default");
|
||||
checkSyntax("var obj = function (foo = bar) {};", "es6.parameters.default");
|
||||
checkSyntax("function foo(foo = bar) {}", "es6.parameters.default");
|
||||
});
|
||||
|
||||
test("es6.arrowFunctions", function () {
|
||||
checkSyntax("var foo = x => x;", "es6.arrowFunctions");
|
||||
checkSyntax("var foo = x => { return x * x };", "es6.arrowFunctions");
|
||||
checkSyntax("var foo = (x) => x;", "es6.arrowFunctions");
|
||||
checkSyntax("var foo = (a, b) => { return a * b };", "es6.arrowFunctions");
|
||||
});
|
||||
|
||||
test("es6.classes", function () {
|
||||
checkSyntax("class Foo {}", "es6.classes");
|
||||
checkSyntax("var Foo = class {};", "es6.classes");
|
||||
});
|
||||
|
||||
test("es6.forOf", function () {
|
||||
checkSyntax("for (var val of foo);", "es6.forOf");
|
||||
checkSyntax("for (val of foo);", "es6.forOf");
|
||||
});
|
||||
|
||||
test("es6.modules", function () {
|
||||
checkSyntax("import 'foo';", "es6.modules");
|
||||
checkSyntax("import foo from 'foo';", "es6.modules");
|
||||
checkSyntax("import * as foo from 'foo';", "es6.modules");
|
||||
checkSyntax("import { foo } from 'foo';", "es6.modules");
|
||||
checkSyntax("export { foo } from 'foo';", "es6.modules");
|
||||
checkSyntax("export var foo = 5;", "es6.modules");
|
||||
checkSyntax("export class Foo {}", "es6.modules");
|
||||
checkSyntax("export function foo() {}", "es6.modules");
|
||||
checkSyntax("export default class Foo {}", "es6.modules");
|
||||
checkSyntax("export default function foo() {}", "es6.modules");
|
||||
});
|
||||
|
||||
test("es6.destructuring", function () {
|
||||
checkSyntax("[a, b] = [];", "es6.destructuring");
|
||||
checkSyntax("var [a, b] = [];", "es6.destructuring");
|
||||
checkSyntax("({ a, b }) = {};", "es6.destructuring");
|
||||
checkSyntax("var { a, b } = {};", "es6.destructuring");
|
||||
checkSyntax("function foo(foo = bar) {}", "es6.destructuring");
|
||||
});
|
||||
|
||||
test("es6.parameters.rest", function () {
|
||||
checkSyntax("function foo(...items) {}", "es6.parameters.rest");
|
||||
checkSyntax("var foo = (...items) => {}", "es6.parameters.rest");
|
||||
});
|
||||
|
||||
test("es6.spread", function () {
|
||||
checkSyntax("new Foo(...items);", "es6.spread");
|
||||
checkSyntax("foo(...items);", "es6.spread");
|
||||
checkSyntax("[...items];", "es6.spread");
|
||||
});
|
||||
|
||||
test("es6.templateLiterals", function () {
|
||||
checkSyntax("`foobar`;", "es6.templateLiterals");
|
||||
checkSyntax("foobar`foobar`;", "es6.templateLiterals");
|
||||
});
|
||||
|
||||
test("es6.generators", function () {
|
||||
checkSyntax("function* foo() {}", "es6.generators");
|
||||
checkSyntax("var foo = function* () {};", "es6.generators");
|
||||
});
|
||||
|
||||
test("es7.asyncFunctions", function () {
|
||||
checkSyntax("async function foo() {}", "es7.asyncFunctions");
|
||||
checkSyntax("var foo = async function() {};", "es7.asyncFunctions");
|
||||
checkSyntax("var foo = async () => {};", "es7.asyncFunctions");
|
||||
});
|
||||
|
||||
test("es7.comprehensions", function () {
|
||||
checkSyntax("[for (i of test) i]", "es7.comprehensions");
|
||||
checkSyntax("(for (i of test) i)", "es7.comprehensions");
|
||||
});
|
||||
|
||||
test("es7.objectSpread", function () {
|
||||
checkSyntax("var foo = { ...bar };", "es7.objectSpread");
|
||||
});
|
||||
|
||||
test("es7.abstractReferences", function () {
|
||||
checkSyntax("class Foo { private A; }", "es7.abstractReferences");
|
||||
checkSyntax("foo::bar();", "es7.abstractReferences");
|
||||
checkSyntax("delete foo::bar;", "es7.abstractReferences");
|
||||
checkSyntax("foo::bar;", "es7.abstractReferences");
|
||||
checkSyntax("foo::bar = baz;", "es7.abstractReferences");
|
||||
});
|
||||
|
||||
test("flow", function () {
|
||||
|
||||
});
|
||||
|
||||
test("jsx", function () {
|
||||
checkSyntax("<div />", "jsx");
|
||||
checkSyntax("<Element />", "jsx");
|
||||
});
|
||||
});
|
||||
14
test/fixtures/transformation/es6-block-scoping-exec/nested-labels-4.js
vendored
Normal file
14
test/fixtures/transformation/es6-block-scoping-exec/nested-labels-4.js
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
(function () {
|
||||
var stack = [];
|
||||
|
||||
loop1:
|
||||
for (let j = 0; j < 10; j++) {
|
||||
for (let i = 0; i < 10; i++) {
|
||||
stack.push(() => [i, j]);
|
||||
break loop1;
|
||||
}
|
||||
}
|
||||
|
||||
assert.deepEqual(stack.length, 1);
|
||||
assert.deepEqual(stack[0](), [0, 0]);
|
||||
})();
|
||||
@@ -1,11 +0,0 @@
|
||||
if (true) {
|
||||
const x = 1;
|
||||
switch (x) {
|
||||
case 1: {
|
||||
function y() {
|
||||
assert(x, 1);
|
||||
};
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
5
test/fixtures/transformation/regenerator/destructuring-parameters/exec.js
vendored
Normal file
5
test/fixtures/transformation/regenerator/destructuring-parameters/exec.js
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
function* foo({ bar }) {
|
||||
return bar;
|
||||
}
|
||||
|
||||
assert(foo({ bar: "bar" }).next().value, "bar");
|
||||
@@ -1,5 +1,13 @@
|
||||
function* foo({ bar }) {
|
||||
function* foo() {
|
||||
var { bar } = { bar: "bar" };
|
||||
return bar;
|
||||
}
|
||||
|
||||
assert(foo({ bar: "bar" }).next().value, "bar");
|
||||
assert.equal(foo().next().value, "bar");
|
||||
|
||||
function* foo2({ bar = 0 }) {
|
||||
return bar;
|
||||
}
|
||||
|
||||
assert.equal(foo2({ bar: undefined }).next().value, 0);
|
||||
assert.equal(foo2({ bar: 3 }).next().value, 3);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
var generate = require("../lib/6to5/generation/generator");
|
||||
var generate = require("../lib/6to5/generation");
|
||||
var assert = require("assert");
|
||||
var helper = require("./_helper");
|
||||
var util = require("../lib/6to5/util");
|
||||
|
||||
@@ -2,7 +2,7 @@ require("./_helper").assertVendor("compat-table");
|
||||
|
||||
require("../polyfill");
|
||||
|
||||
var transform = require("../lib/6to5/transformation/transform");
|
||||
var transform = require("../lib/6to5/transformation");
|
||||
var assert = require("assert");
|
||||
var data = require("../vendor/compat-table/data-es6");
|
||||
var _ = require("lodash");
|
||||
|
||||
@@ -2,7 +2,7 @@ if (!process.env.ALL_6TO5_TESTS) return;
|
||||
|
||||
require("./_helper").assertVendor("regenerator");
|
||||
|
||||
var transform = require("../lib/6to5/transformation/transform");
|
||||
var transform = require("../lib/6to5/transformation");
|
||||
var fs = require("fs");
|
||||
var _ = require("lodash");
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ if (process.env.SIMPLE_6TO5_TESTS) return;
|
||||
|
||||
require("./_helper").assertVendor("test262");
|
||||
|
||||
var transform = require("../lib/6to5/transformation/transform");
|
||||
var transform = require("../lib/6to5/transformation");
|
||||
var readdir = require("fs-readdir-recursive");
|
||||
var path = require("path");
|
||||
var fs = require("fs");
|
||||
|
||||
@@ -12,44 +12,4 @@ suite("types", function () {
|
||||
assert.ok(!t.isFalsyExpression(t.literal(5)));
|
||||
assert.ok(!t.isFalsyExpression(t.identifier("foobar")));
|
||||
});
|
||||
|
||||
test("toSequenceExpression");
|
||||
|
||||
test("shallowEqual");
|
||||
|
||||
test("appendToMemberExpression");
|
||||
|
||||
test("prependToMemberExpression");
|
||||
|
||||
test("isDynamic");
|
||||
|
||||
test("isReferenced");
|
||||
|
||||
test("isValidIdentifier");
|
||||
|
||||
test("toIdentifier");
|
||||
|
||||
test("ensureBlock");
|
||||
|
||||
test("toStatement");
|
||||
|
||||
test("toBlock");
|
||||
|
||||
test("getUid");
|
||||
|
||||
test("getIds");
|
||||
|
||||
test("isLet");
|
||||
|
||||
test("isVar");
|
||||
|
||||
test("removeComments");
|
||||
|
||||
test("inheritsComments");
|
||||
|
||||
test("inherits");
|
||||
|
||||
test("getSpecifierName");
|
||||
|
||||
test("isSpecifierDefault");
|
||||
});
|
||||
|
||||
20
test/util.js
20
test/util.js
@@ -22,6 +22,10 @@ suite("util", function () {
|
||||
assert.ok(util.canCompile("/test.es"));
|
||||
assert.ok(util.canCompile("/scripts/test.es"));
|
||||
|
||||
assert.ok(util.canCompile("test.jsx"));
|
||||
assert.ok(util.canCompile("/test.jsx"));
|
||||
assert.ok(util.canCompile("/scripts/test.jsx"));
|
||||
|
||||
assert.ok(!util.canCompile("test"));
|
||||
assert.ok(!util.canCompile("test.css"));
|
||||
assert.ok(!util.canCompile("/test.css"));
|
||||
@@ -75,24 +79,8 @@ suite("util", function () {
|
||||
}, /illegal type for regexify/);
|
||||
});
|
||||
|
||||
test("getIds");
|
||||
|
||||
test("toStatement");
|
||||
|
||||
test("toBlock");
|
||||
|
||||
test("toIdentifier", function () {
|
||||
assert.equal(t.toIdentifier(t.identifier("swag")), "swag");
|
||||
assert.equal(t.toIdentifier("swag-lord"), "swagLord");
|
||||
});
|
||||
|
||||
test("isDynamic");
|
||||
|
||||
test("isReferenced");
|
||||
|
||||
test("removeProperties");
|
||||
|
||||
test("ensureBlock");
|
||||
|
||||
test("pushMutatorMap");
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user