Compare commits

...

19 Commits

Author SHA1 Message Date
Sebastian McKenzie
b91997354c v4.5.2 2015-02-26 09:04:05 +11:00
Sebastian McKenzie
4b8039a00c add 4.5.2 changelog 2015-02-26 09:00:37 +11:00
Sebastian McKenzie
0a0931dc2e add access to helpers used by the current file and allow a helper whitelist to be passed to buildHelpers - closes #898 2015-02-26 08:59:07 +11:00
Sebastian McKenzie
372c06eb80 bump acorn-babel 2015-02-26 08:32:27 +11:00
Sebastian McKenzie
b8121ed4d0 Merge branch 'master' of github.com:6to5/6to5 2015-02-26 08:21:49 +11:00
Sebastian McKenzie
1f79445ee5 shim in function arity when proxying named functions - fixes #896 2015-02-26 08:21:37 +11:00
Sebastian McKenzie
cb46ca60af Merge pull request #894 from josh/travis-test-full-build
Test full `make build` on Travis
2015-02-26 08:05:24 +11:00
Joshua Peek
24c0c7679f Test full make build on travis 2015-02-25 10:23:42 -06:00
Sebastian McKenzie
d7ec337567 move spec.functionName transformer to below validation transformers 2015-02-26 01:00:35 +11:00
Sebastian McKenzie
845f1ce65e remove linting since we're too bleeding edge :'( 2015-02-26 01:00:24 +11:00
Sebastian McKenzie
88563a0c26 add additional newline to alias functions transformer 2015-02-26 00:05:33 +11:00
Sebastian McKenzie
ccd7a6560c simplify README 2015-02-26 00:05:21 +11:00
Sebastian McKenzie
c340597fdb remove docs directory 2015-02-26 00:04:59 +11:00
Sebastian McKenzie
e498358125 classes... i just... no words 2015-02-25 23:47:01 +11:00
Sebastian McKenzie
25232d3141 use the mallet operator this is actually amazing i think i'm going to cry 2015-02-25 23:34:04 +11:00
Sebastian McKenzie
5b9878451a use strict BE GONE 2015-02-25 23:07:49 +11:00
Sebastian McKenzie
23d6fb6bb1 concise methods oh my god this is so good 2015-02-25 23:06:57 +11:00
Sebastian McKenzie
8d1b5c8ccb BOLD TEXT ALL UP IN THIS 2015-02-25 23:06:48 +11:00
Sebastian McKenzie
10bd7d1b91 4.5.1 2015-02-25 22:57:59 +11:00
123 changed files with 1321 additions and 1521 deletions

View File

@@ -1 +0,0 @@
src/babel/transformation/templates

View File

@@ -1,27 +0,0 @@
{
"esnext": true,
"indent": 2,
"freeze": true,
"validthis": true,
"camelcase": true,
"unused": true,
"eqnull": true,
"newcap": true,
"supernew": true,
"noyield": true,
"evil": true,
"node": true,
"boss": true,
"expr": true,
"undef": true,
"maxparams": 5,
"maxdepth": 4,
"globals": {
"window": true,
"suite": true,
"set": true,
"before": true,
"bench": true
}
}

View File

@@ -13,6 +13,22 @@ _Note: Gaps between patch versions are faulty/broken releases._
See [CHANGELOG - 6to5](CHANGELOG-6to5.md) for the pre-4.0.0 version changelog.
## 4.5.2
* **New Feature**
* `returnUsedHelpers` option and add whitelist to `buildHelpers`.
* **Bug Fix**
* Fix function arity on self referencing inferred named functions.
* **Internal**
* Bump `acorn-babel`.
* Start converting source to ES6...
## 4.5.1
**Babel now compiles itself!**
![holy shit](http://gifsec.com/wp-content/uploads/GIF/2014/03/OMG-GIF_2.gif)
## 4.5.0
* **New Feature**

View File

@@ -8,7 +8,7 @@ BABEL_CMD = node_modules/babel/bin/babel
export NODE_ENV = test
.PHONY: clean test test-cov test-clean lint test-travis test-simple test-all test-browser publish build bootstrap publish-core publish-runtime build-core watch-core
.PHONY: clean test test-cov test-clean test-travis test-simple test-all test-browser publish build bootstrap publish-core publish-runtime build-core watch-core
build-core:
node $(BABEL_CMD) src --out-dir lib --copy-files
@@ -36,13 +36,10 @@ build:
clean:
rm -rf coverage templates.json test/tmp dist
lint:
$(JSHINT_CMD) --reporter node_modules/jshint-stylish/stylish.js src bin
test-clean:
rm -rf test/tmp
test: lint
test:
$(MOCHA_CMD)
make test-clean
@@ -60,7 +57,7 @@ test-cov:
export SIMPLE_BABEL_TESTS=1; \
node $(ISTANBUL_CMD) $(MOCHA_CMD) --
test-travis: build-core bootstrap
test-travis: bootstrap build
node $(ISTANBUL_CMD) $(MOCHA_CMD) --
if test -n "$$CODECLIMATE_REPO_TOKEN"; then codeclimate < coverage/lcov.info; fi

View File

@@ -9,9 +9,7 @@
</p>
<p align="center">
For more information view the <a href="https://babeljs.io/">documentation</a>. For questions
and support please visit the <a href="https://gitter.im/babel/babel">gitter room</a> before
creating an issue.
For questions and support please visit the <a href="https://gitter.im/babel/babel">gitter room</a> before creating an issue.
</p>
<p align="center">

View File

@@ -1 +0,0 @@
See [babel.github.io/docs](https://github.com/babel/babel.github.io/tree/master/docs).

View File

@@ -1,7 +1,7 @@
{
"name": "babel",
"description": "Turn ES6 code into readable vanilla ES5 with source maps",
"version": "4.5.1",
"version": "4.5.2",
"author": "Sebastian McKenzie <sebmck@gmail.com>",
"homepage": "https://babeljs.io/",
"repository": "babel/babel",
@@ -36,7 +36,7 @@
"test": "make test"
},
"dependencies": {
"acorn-babel": "0.11.1-34",
"acorn-babel": "0.11.1-35",
"ast-types": "~0.6.1",
"chalk": "^1.0.0",
"chokidar": "^0.12.6",
@@ -67,13 +67,11 @@
"trim-right": "^1.0.0"
},
"devDependencies": {
"babel": "4.5.0",
"babel": "4.5.1",
"browserify": "^8.1.3",
"chai": "^2.0.0",
"esvalid": "^1.1.0",
"istanbul": "^0.3.5",
"jshint": "^2.6.0",
"jshint-stylish": "^1.0.0",
"matcha": "^0.6.0",
"mocha": "^2.1.0",
"rimraf": "^2.2.8",

View File

@@ -1,7 +1,7 @@
{
"name": "babel-runtime",
"description": "babel selfContained runtime",
"version": "4.5.0",
"version": "4.5.1",
"repository": "babel/babel",
"author": "Sebastian McKenzie <sebmck@gmail.com>"
}

View File

@@ -1,5 +1,3 @@
"use strict";
var transform = module.exports = require("../transformation");
transform.version = require("../../../package").version;
@@ -7,14 +5,14 @@ transform.version = require("../../../package").version;
transform.transform = transform;
transform.run = function (code, opts) {
opts = opts || {};
opts ||= {};
opts.sourceMap = "inline";
return new Function(transform(code, opts).code)();
};
transform.load = function (url, callback, opts, hold) {
opts = opts || {};
opts.filename = opts.filename || url;
opts ||= {};
opts.filename ||= url;
var xhr = global.ActiveXObject ? new global.ActiveXObject("Microsoft.XMLHTTP") : new global.XMLHttpRequest();
xhr.open("GET", url, true);

View File

@@ -1,5 +1,3 @@
"use strict";
var isFunction = require("lodash/lang/isFunction");
var transform = require("../transformation");
var util = require("../util");
@@ -52,7 +50,7 @@ exports.transformFile = function (filename, opts, callback) {
};
exports.transformFileSync = function (filename, opts) {
opts = opts || {};
opts ||= {};
opts.filename = filename;
return transform(fs.readFileSync(filename), opts);
};

View File

@@ -1,5 +1,3 @@
"use strict";
// required to safely use babel/register within a browserify codebase
module.exports = function () {};

View File

@@ -1,5 +1,3 @@
"use strict";
var path = require("path");
var os = require("os");
var fs = require("fs");

View File

@@ -1,5 +1,3 @@
"use strict";
require("../../polyfill");
var sourceMapSupport = require("source-map-support");
@@ -12,7 +10,7 @@ var util = require("../../util");
var fs = require("fs");
sourceMapSupport.install({
retrieveSourceMap: function (source) {
retrieveSourceMap(source) {
var map = maps && maps[source];
if (map) {
return {
@@ -138,7 +136,7 @@ hookExtensions(util.canCompile.EXTENSIONS);
module.exports = function (opts) {
// normalize options
opts = opts || {};
opts ||= {};
if (opts.only != null) onlyRegex = util.regexify(opts.only);
if (opts.ignore != null) ignoreRegex = util.regexify(opts.ignore);

View File

@@ -1,5 +1,3 @@
"use strict";
var merge = require("lodash/object/merge");
var path = require("path");
var fs = require("fs");
@@ -14,7 +12,7 @@ function exists(filename) {
module.exports = function (loc, opts) {
var rel = ".babelrc";
opts = opts || {};
opts ||= {};
function find(start, rel) {
var file = path.join(start, rel);

View File

@@ -1,11 +1,9 @@
"use strict";
var buildHelpers = require("./build-helpers");
var generator = require("./generation");
var util = require("./util");
var t = require("./types");
module.exports = function () {
module.exports = function (whitelist) {
var namespace = t.identifier("babelHelpers");
var body = [];
@@ -19,7 +17,7 @@ module.exports = function () {
)
]));
buildHelpers(body, namespace);
buildHelpers(body, namespace, whitelist);
return generator(tree).code;
};

View File

@@ -3,9 +3,11 @@ var util = require("./util");
var each = require("lodash/collection/each");
var t = require("./types");
module.exports = function (body, namespace) {
module.exports = function (body, namespace, whitelist = []) {
each(File.helpers, function (name) {
var key = t.identifier(t.toIdentifier(name));
if (whitelist.length && whitelist.indexOf(key) >= 0) return;
body.push(t.expressionStatement(
t.assignmentExpression("=", t.memberExpression(namespace, key), util.template(name))
));

View File

@@ -15,7 +15,7 @@ function detect(ast) {
};
traverse(ast, {
enter: function (node, parent) {
enter(node, parent) {
if (SYNTAX_KEYS[node.type]) {
detectedSyntax(SYNTAX_KEYS[node.type]);
}

View File

@@ -1,5 +1,3 @@
"use strict";
module.exports = Buffer;
var repeating = require("repeating");
@@ -80,7 +78,7 @@ Buffer.prototype.newline = function (i, removeLast) {
return;
}
removeLast = removeLast || false;
removeLast ||= false;
if (isNumber(i)) {
i = Math.min(2, i);

View File

@@ -1,5 +1,3 @@
"use strict";
exports.File = function (node, print) {
print(node.program);
};

View File

@@ -1,5 +1,3 @@
"use strict";
exports.ClassExpression =
exports.ClassDeclaration = function (node, print) {
this.push("class");

View File

@@ -1,5 +1,3 @@
"use strict";
exports.ComprehensionBlock = function (node, print) {
this.keyword("for");
this.push("(");

View File

@@ -1,5 +1,3 @@
"use strict";
var isInteger = require("is-integer");
var isNumber = require("lodash/lang/isNumber");
var t = require("../../types");

View File

@@ -1,5 +1,3 @@
"use strict";
exports.AnyTypeAnnotation =
exports.ArrayTypeAnnotation =
exports.BooleanTypeAnnotation =

View File

@@ -1,5 +1,3 @@
"use strict";
var t = require("../../types");
var each = require("lodash/collection/each");

View File

@@ -1,5 +1,3 @@
"use strict";
var t = require("../../types");
exports._params = function (node, print) {

View File

@@ -1,5 +1,3 @@
"use strict";
var t = require("../../types");
var each = require("lodash/collection/each");

View File

@@ -1,5 +1,3 @@
"use strict";
var each = require("lodash/collection/each");
each(["BindMemberExpression", "BindFunctionExpression"], function (type) {

View File

@@ -1,5 +1,3 @@
"use strict";
var repeating = require("repeating");
var t = require("../../types");
@@ -151,7 +149,7 @@ exports.SwitchStatement = function (node, print) {
print.sequence(node.cases, {
indent: true,
addNewlines: function (leading, cas) {
addNewlines(leading, cas) {
if (!leading && node.cases[node.cases.length - 1] === cas) return -1;
}
});

View File

@@ -1,5 +1,3 @@
"use strict";
var each = require("lodash/collection/each");
exports.TaggedTemplateExpression = function (node, print) {

View File

@@ -1,5 +1,3 @@
"use strict";
var each = require("lodash/collection/each");
exports.Identifier = function (node) {

View File

@@ -1,5 +1,3 @@
"use strict";
module.exports = function (ast, opts, code) {
var gen = new CodeGenerator(ast, opts, code);
return gen.generate();
@@ -20,7 +18,7 @@ var n = require("./node");
var t = require("../types");
function CodeGenerator(ast, opts, code) {
opts = opts || {};
opts ||= {};
this.comments = ast.comments || [];
this.tokens = ast.tokens || [];
@@ -110,7 +108,7 @@ CodeGenerator.prototype.buildPrint = function (parent) {
};
print.sequence = (nodes, opts) => {
opts = opts || {};
opts ||= {};
opts.statement = true;
return this.printJoin(print, nodes, opts);
};
@@ -120,8 +118,8 @@ CodeGenerator.prototype.buildPrint = function (parent) {
};
print.list = function (items, opts) {
opts = opts || {};
opts.separator = opts.separator || ", ";
opts ||= {};
opts.separator ||= ", ";
print.join(items, opts);
};
@@ -148,7 +146,7 @@ CodeGenerator.prototype.print = function (node, parent, opts) {
this.format.concise = true;
}
opts = opts || {};
opts ||= {};
var newline = (leading) => {
if (!opts.statement && !n.isUserWhitespacable(node, parent)) {
@@ -218,7 +216,7 @@ CodeGenerator.prototype.print = function (node, parent, opts) {
CodeGenerator.prototype.printJoin = function (print, nodes, opts) {
if (!nodes || !nodes.length) return;
opts = opts || {};
opts ||= {};
var len = nodes.length;

View File

@@ -1,5 +1,3 @@
"use strict";
module.exports = Node;
var whitespace = require("./whitespace");

View File

@@ -1,5 +1,3 @@
"use strict";
var t = require("../../types");
var each = require("lodash/collection/each");

View File

@@ -1,12 +1,10 @@
"use strict";
var isBoolean = require("lodash/lang/isBoolean");
var each = require("lodash/collection/each");
var map = require("lodash/collection/map");
var t = require("../../types");
var crawl = function (node, state) {
state = state || {};
state ||= {};
if (t.isMemberExpression(node)) {
crawl(node.object, state);
@@ -20,7 +18,7 @@ var crawl = function (node, state) {
} else if (t.isFunction(node)) {
state.hasFunction = true;
} else if (t.isIdentifier(node)) {
state.hasHelper = state.hasHelper || isHelper(node.callee);
state.hasHelper ||= isHelper(node.callee);
}
return state;
@@ -46,7 +44,7 @@ var isType = function (node) {
};
exports.nodes = {
AssignmentExpression: function (node) {
AssignmentExpression(node) {
var state = crawl(node.right);
if ((state.hasCall && state.hasHelper) || state.hasFunction) {
return {
@@ -56,13 +54,13 @@ exports.nodes = {
}
},
SwitchCase: function (node, parent) {
SwitchCase(node, parent) {
return {
before: node.consequent.length || parent.cases[0] === node
};
},
LogicalExpression: function (node) {
LogicalExpression(node) {
if (t.isFunction(node.left) || t.isFunction(node.right)) {
return {
after: true
@@ -70,7 +68,7 @@ exports.nodes = {
}
},
Literal: function (node) {
Literal(node) {
if (node.value === "use strict") {
return {
after: true
@@ -78,7 +76,7 @@ exports.nodes = {
}
},
CallExpression: function (node) {
CallExpression(node) {
if (t.isFunction(node.callee) || isHelper(node)) {
return {
before: true,
@@ -87,7 +85,7 @@ exports.nodes = {
}
},
VariableDeclaration: function (node) {
VariableDeclaration(node) {
for (var i = 0; i < node.declarations.length; i++) {
var declar = node.declarations[i];
@@ -106,7 +104,7 @@ exports.nodes = {
}
},
IfStatement: function (node) {
IfStatement(node) {
if (t.isBlockStatement(node.consequent)) {
return {
before: true,
@@ -126,15 +124,15 @@ exports.nodes.SpreadProperty = function (node, parent) {
};
exports.list = {
VariableDeclaration: function (node) {
VariableDeclaration(node) {
return map(node.declarations, "init");
},
ArrayExpression: function (node) {
ArrayExpression(node) {
return node.elements;
},
ObjectExpression: function (node) {
ObjectExpression(node) {
return node.properties;
}
};

View File

@@ -1,5 +1,3 @@
"use strict";
module.exports = Position;
function Position() {

View File

@@ -1,5 +1,3 @@
"use strict";
module.exports = SourceMap;
var sourceMap = require("source-map");

View File

@@ -1,5 +1,3 @@
"use strict";
module.exports = Whitespace;
var sortBy = require("lodash/collection/sortBy");

View File

@@ -77,7 +77,7 @@ module.exports = function (lines, lineNumber, colNumber) {
start: start + 1,
before: " ",
after: " | ",
transform: function (params) {
transform(params) {
if (params.number !== lineNumber) {
return;
}

View File

@@ -1,5 +1,3 @@
"use strict";
module.exports = function () {
return Object.create(null);
};

View File

@@ -1,5 +1,3 @@
"use strict";
/**
* A trick from Bluebird to force V8 to use fast properties for an object.
* Read more: http://stackoverflow.com/questions/24987896/

View File

@@ -1,5 +1,3 @@
"use strict";
var extend = require("lodash/object/extend");
var t = require("./types");

View File

@@ -1,5 +1,3 @@
"use strict";
if (global._babelPolyfill) {
throw new Error("only one instance of babel/polyfill is allowed");
}

View File

@@ -1,5 +1,3 @@
"use strict";
module.exports = File;
var sourceMapToComment = require("source-map-to-comment");
@@ -24,12 +22,13 @@ function File(opts) {
this.dynamicImported = [];
this.dynamicImports = [];
this.dynamicData = {};
this.data = {};
this.usedHelpers = {};
this.dynamicData = {};
this.data = {};
this.lastStatements = [];
this.opts = this.normalizeOptions(opts);
this.ast = {};
this.lastStatements = [];
this.opts = this.normalizeOptions(opts);
this.ast = {};
this.buildTransformers();
}
@@ -87,6 +86,7 @@ File.validOptions = [
"externalHelpers",
"auxiliaryComment",
"compact",
"returnUsedHelpers",
"resolveModuleSource",
"moduleId",
@@ -113,6 +113,7 @@ File.prototype.normalizeOptions = function (opts) {
defaults(opts, {
keepModuleIdExtensions: false,
resolveModuleSource: null,
returnUsedHelpers: false,
externalHelpers: false,
auxilaryComment: "",
experimental: false,
@@ -288,7 +289,7 @@ File.prototype.get = function (key) {
};
File.prototype.addImport = function (source, name, noDefault) {
name = name || source;
name ||= source;
var id = this.dynamicImportIds[name];
if (!id) {
@@ -314,7 +315,7 @@ File.prototype.isConsequenceExpressionStatement = function (node) {
File.prototype.attachAuxiliaryComment = function (node) {
var comment = this.opts.auxiliaryComment;
if (comment) {
node.leadingComments = node.leadingComments || [];
node.leadingComments ||= [];
node.leadingComments.push({
type: "Line",
value: " " + comment
@@ -333,6 +334,8 @@ File.prototype.addHelper = function (name) {
var declar = program._declarations && program._declarations[name];
if (declar) return declar.id;
this.usedHelpers[name] = true;
var runtime = this.get("helpersNamespace");
if (runtime) {
name = t.identifier(t.toIdentifier(name));
@@ -355,7 +358,7 @@ File.prototype.logDeopt = function () {
};
File.prototype.errorWithNode = function (node, msg, Error) {
Error = Error || SyntaxError;
Error ||= SyntaxError;
var loc = node.loc.start;
var err = new Error("Line " + loc.line + ": " + msg);
@@ -417,7 +420,7 @@ File.prototype.call = function (key) {
};
var checkTransformerVisitor = {
enter: function (node, parent, scope, state) {
enter(node, parent, scope, state) {
checkNode(state.stack, node, scope);
}
};
@@ -431,7 +434,7 @@ var checkNode = function (stack, node, scope) {
File.prototype.checkNode = function (node, scope) {
var stack = this.transformerStack;
scope = scope || this.scope;
scope ||= this.scope;
checkNode(stack, node, scope);
@@ -450,6 +453,10 @@ File.prototype.generate = function () {
ast: null
};
if (this.opts.returnUsedHelpers) {
result.usedHelpers = Object.keys(this.usedHelpers);
}
if (opts.ast) result.ast = ast;
if (!opts.code) return result;

View File

@@ -1,5 +1,3 @@
"use strict";
var explode = require("./explode-assignable-expression");
var t = require("../../types");

View File

@@ -1,5 +1,3 @@
"use strict";
var t = require("../../types");
module.exports = function build(node, buildBody) {

View File

@@ -1,5 +1,3 @@
"use strict";
var explode = require("./explode-assignable-expression");
var t = require("../../types");

View File

@@ -1,5 +1,3 @@
"use strict";
// Based upon the excellent jsx-transpiler by Ingvar Stepanyan (RReverser)
// https://github.com/RReverser/jsx-transpiler
@@ -33,7 +31,7 @@ module.exports = function (exports, opts) {
};
exports.JSXMemberExpression = {
exit: function (node) {
exit(node) {
node.computed = t.isLiteral(node.property);
node.type = "MemberExpression";
}
@@ -44,21 +42,21 @@ module.exports = function (exports, opts) {
};
exports.JSXAttribute = {
enter: function (node) {
enter(node) {
var value = node.value;
if (t.isLiteral(value) && isString(value.value)) {
value.value = value.value.replace(/\n\s+/g, " ");
}
},
exit: function (node) {
exit(node) {
var value = node.value || t.literal(true);
return t.inherits(t.property("init", node.name, value), node);
}
};
exports.JSXOpeningElement = {
exit: function (node, parent, scope, file) {
exit(node, parent, scope, file) {
var tagExpr = node.name;
var args = [];
@@ -146,7 +144,7 @@ module.exports = function (exports, opts) {
};
exports.JSXElement = {
exit: function (node) {
exit(node) {
var callExpr = node.openingElement;
for (var i = 0; i < node.children.length; i++) {

View File

@@ -1,5 +1,3 @@
"use strict";
var t = require("../../types");
var getObjRef = function (node, nodes, file, scope) {

View File

@@ -0,0 +1,9 @@
var t = require("../../types");
module.exports = function (node) {
var lastNonDefault = 0;
for (var i = 0; i < node.params.length; i++) {
if (!t.isAssignmentPattern(node.params[i])) lastNonDefault = i + 1;
}
return lastNonDefault;
};

View File

@@ -1,10 +1,9 @@
"use strict";
var util = require("../../util");
var t = require("../../types");
var getFunctionArity = require("./get-function-arity");
var util = require("../../util");
var t = require("../../types");
var visitor = {
enter: function (node, parent, scope, state) {
enter(node, parent, scope, state) {
// check if this node is a referenced identifier that matches the same as our
// function id
if (!t.isReferencedIdentifier(node, parent, { name: state.name })) return;
@@ -23,12 +22,21 @@ var wrap = function (state, method, id, scope) {
if (state.selfReference) {
var templateName = "property-method-assignment-wrapper";
if (method.generator) templateName += "-generator";
return util.template(templateName, {
var template = util.template(templateName, {
FUNCTION: method,
FUNCTION_ID: id,
FUNCTION_KEY: scope.generateUidIdentifier(id.name),
WRAPPER_KEY: scope.generateUidIdentifier(id.name + "Wrapper")
});
// shim in dummy params to retain function arity, if you try to read the
// source then you'll get the original since it's proxied so it's all good
var params = template.callee.body.body[0].declarations[0].init.params;
for (var i = 0, len = getFunctionArity(method); i < len; i++) {
params.push(scope.generateUidIdentifier("x"));
}
return template;
} else {
method.id = id;
return method;
@@ -99,7 +107,7 @@ exports.bare = function (node, parent, scope) {
var id;
if (t.isProperty(parent) && parent.kind === "init" && !parent.computed) {
// { foo: function () {} };
// { foo() {} };
id = parent.key;
} else if (t.isVariableDeclarator(parent)) {
// var foo = function () {};

View File

@@ -1,9 +1,7 @@
"use strict";
var t = require("../../types");
var visitor = {
enter: function (node) {
enter(node) {
if (t.isFunction(node)) this.skip();
if (t.isAwaitExpression(node)) {

View File

@@ -1,5 +1,3 @@
"use strict";
module.exports = ReplaceSupers;
var messages = require("../../messages");
@@ -96,7 +94,7 @@ ReplaceSupers.prototype.replace = function () {
};
var visitor = {
enter: function (node, parent, scope, state) {
enter(node, parent, scope, state) {
var topLevel = state.topLevel;
var self = state.self;

View File

@@ -1,5 +1,3 @@
"use strict";
var t = require("../../types");
exports.has = function (node) {

View File

@@ -1,5 +1,3 @@
"use strict";
module.exports = transform;
var normalizeAst = require("../helpers/normalize-ast");
@@ -60,7 +58,7 @@ var rawTransformers = require("./transformers");
each(rawTransformers, function (transformer, key) {
var namespace = key.split(".")[0];
transform.namespaces[namespace] = transform.namespaces[namespace] || [];
transform.namespaces[namespace] ||= [];
transform.namespaces[namespace].push(key);
transform.transformerNamespaces[key] = namespace;

View File

@@ -1,5 +1,3 @@
"use strict";
module.exports = DefaultFormatter;
var messages = require("../../messages");
@@ -35,12 +33,12 @@ DefaultFormatter.prototype.doDefaultExportInterop = function (node) {
DefaultFormatter.prototype.bumpImportOccurences = function (node) {
var source = node.source.value;
var occurs = this.localImportOccurences;
occurs[source] = occurs[source] || 0;
occurs[source] ||= 0;
occurs[source] += node.specifiers.length;
};
var exportsVisitor = {
enter: function (node, parent, scope, formatter) {
enter(node, parent, scope, formatter) {
var declar = node && node.declaration;
if (t.isExportDeclaration(node)) {
formatter.hasLocalImports = true;
@@ -65,7 +63,7 @@ DefaultFormatter.prototype.getLocalExports = function () {
};
var importsVisitor = {
enter: function (node, parent, scope, formatter) {
enter(node, parent, scope, formatter) {
if (t.isImportDeclaration(node)) {
formatter.hasLocalImports = true;
extend(formatter.localImports, t.getBindingIdentifiers(node));
@@ -79,7 +77,7 @@ DefaultFormatter.prototype.getLocalImports = function () {
};
var remapVisitor = {
enter: function (node, parent, scope, formatter) {
enter(node, parent, scope, formatter) {
if (t.isUpdateExpression(node) && formatter.isLocalReference(node.argument, scope)) {
this.skip();

View File

@@ -1,5 +1,3 @@
"use strict";
var util = require("../../util");
module.exports = function (Parent) {

View File

@@ -1,3 +1 @@
"use strict";
module.exports = require("./_strict")(require("./amd"));

View File

@@ -1,5 +1,3 @@
"use strict";
module.exports = AMDFormatter;
var DefaultFormatter = require("./_default");

View File

@@ -1,3 +1 @@
"use strict";
module.exports = require("./_strict")(require("./common"));

View File

@@ -1,5 +1,3 @@
"use strict";
module.exports = CommonJSFormatter;
var DefaultFormatter = require("./_default");

View File

@@ -1,5 +1,3 @@
"use strict";
module.exports = IgnoreFormatter;
var t = require("../../types");

View File

@@ -1,5 +1,3 @@
"use strict";
module.exports = SystemFormatter;
var DefaultFormatter = require("./_default");
@@ -68,7 +66,7 @@ SystemFormatter.prototype.importSpecifier = function (specifier, node, nodes) {
};
var runnerSettersVisitor = {
enter: function (node, parent, scope, state) {
enter(node, parent, scope, state) {
if (node._importSource === state.source) {
if (t.isVariableDeclaration(node)) {
each(node.declarations, function (declar) {
@@ -103,7 +101,7 @@ SystemFormatter.prototype.buildRunnerSetters = function (block, hoistDeclarators
};
var hoistVariablesVisitor = {
enter: function (node, parent, scope, hoistDeclarators) {
enter(node, parent, scope, hoistDeclarators) {
if (t.isFunction(node)) {
// nothing inside is accessible
return this.skip();
@@ -148,7 +146,7 @@ var hoistVariablesVisitor = {
};
var hoistFunctionsVisitor = {
enter: function (node, parent, scope, handlerBody) {
enter(node, parent, scope, handlerBody) {
if (t.isFunction(node)) this.skip();
if (t.isFunctionDeclaration(node) || node._blockHoist) {

View File

@@ -1,3 +1 @@
"use strict";
module.exports = require("./_strict")(require("./umd"));

View File

@@ -1,5 +1,3 @@
"use strict";
module.exports = UMDFormatter;
var AMDFormatter = require("./amd");

View File

@@ -1,5 +1,3 @@
"use strict";
module.exports = Transformer;
var TransformerPass = require("./transformer-pass");
@@ -35,7 +33,7 @@ function Transformer(key, transformer, opts) {
this.optional = !!take("optional");
this.handlers = this.normalize(transformer);
this.opts = opts || {};
this.opts ||= {};
this.key = key;
}

View File

@@ -1,5 +1,3 @@
"use strict";
var t = require("../../../types");
exports.MemberExpression = function (node) {

View File

@@ -1,5 +1,3 @@
"use strict";
var t = require("../../../types");
exports.Property = function (node) {

View File

@@ -1,5 +1,3 @@
"use strict";
var defineMap = require("../../helpers/define-map");
var t = require("../../../types");

View File

@@ -1,5 +1,3 @@
"use strict";
var t = require("../../../types");
exports.check = t.isArrowFunctionExpression;

View File

@@ -1,9 +1,7 @@
"use strict";
var t = require("../../../types");
var visitor = {
enter: function (node, parent, scope, state) {
enter(node, parent, scope, state) {
if (!t.isReferencedIdentifier(node, parent)) return;
var declared = state.letRefs[node.name];

View File

@@ -1,5 +1,3 @@
"use strict";
var traverse = require("../../../traversal");
var object = require("../../../helpers/object");
var util = require("../../../util");
@@ -20,7 +18,7 @@ var isLet = function (node, parent) {
if (isLetInitable(node, parent)) {
for (var i = 0; i < node.declarations.length; i++) {
var declar = node.declarations[i];
declar.init = declar.init || t.identifier("undefined");
declar.init ||= t.identifier("undefined");
}
}
@@ -83,53 +81,6 @@ exports.BlockStatement = function (block, parent, scope, file) {
}
};
/**
* Description
*
* @param {Boolean|Node} loopParent
* @param {Node} block
* @param {Node} parent
* @param {Scope} scope
* @param {File} file
*/
function BlockScoping(loopParent, block, parent, scope, file) {
this.loopParent = loopParent;
this.parent = parent;
this.scope = scope;
this.block = block;
this.file = file;
this.outsideLetReferences = object();
this.hasLetReferences = false;
this.letReferences = block._letReferences = object();
this.body = [];
}
/**
* Start the ball rolling.
*/
BlockScoping.prototype.run = function () {
var block = this.block;
if (block._letDone) return;
block._letDone = true;
var needsClosure = this.getLetReferences();
// this is a block within a `Function/Program` so we can safely leave it be
if (t.isFunction(this.parent) || t.isProgram(this.block)) return;
// we can skip everything
if (!this.hasLetReferences) return;
if (needsClosure) {
this.wrapClosure();
} else {
this.remap();
}
};
function replace(node, parent, scope, remaps) {
if (!t.isReferencedIdentifier(node, parent)) return;
@@ -155,118 +106,17 @@ function traverseReplace(node, parent, scope, remaps) {
scope.traverse(node, replaceVisitor, remaps);
}
/**
* Description
*/
BlockScoping.prototype.remap = function () {
var hasRemaps = false;
var letRefs = this.letReferences;
var scope = this.scope;
// alright, so since we aren't wrapping this block in a closure
// we have to check if any of our let variables collide with
// those in upper scopes and then if they do, generate a uid
// for them and replace all references with it
var remaps = object();
for (var key in letRefs) {
// just an Identifier node we collected in `getLetReferences`
// this is the defining identifier of a declaration
var ref = letRefs[key];
if (scope.parentHasBinding(key) || scope.hasGlobal(key)) {
var uid = scope.generateUidIdentifier(ref.name).name;
ref.name = uid;
hasRemaps = true;
remaps[key] = remaps[uid] = {
binding: ref,
uid: uid
};
var letReferenceBlockVisitor = {
enter(node, parent, scope, state) {
if (t.isFunction(node)) {
scope.traverse(node, letReferenceFunctionVisitor, state);
return this.skip();
}
}
if (!hasRemaps) return;
//
var loopParent = this.loopParent;
if (loopParent) {
traverseReplace(loopParent.right, loopParent, scope, remaps);
traverseReplace(loopParent.test, loopParent, scope, remaps);
traverseReplace(loopParent.update, loopParent, scope, remaps);
}
scope.traverse(this.block, replaceVisitor, remaps);
};
/**
* Description
*/
BlockScoping.prototype.wrapClosure = function () {
var block = this.block;
var outsideRefs = this.outsideLetReferences;
// remap loop heads with colliding variables
if (this.loopParent) {
for (var name in outsideRefs) {
var id = outsideRefs[name];
if (this.scope.hasGlobal(id.name)) {
delete outsideRefs[id.name];
delete this.letReferences[id.name];
this.scope.rename(id.name);
this.letReferences[id.name] = id;
outsideRefs[id.name] = id;
}
}
}
// if we're inside of a for loop then we search to see if there are any
// `break`s, `continue`s, `return`s etc
this.has = this.checkLoop();
// hoist var references to retain scope
this.hoistVarDeclarations();
// turn outsideLetReferences into an array
var params = values(outsideRefs);
// build the closure that we're going to wrap the block with
var fn = t.functionExpression(null, params, t.blockStatement(block.body));
fn._aliasFunction = true;
// replace the current block body with the one we're going to build
block.body = this.body;
// build a call and a unique id that we can assign the return value to
var call = t.callExpression(fn, params);
var ret = this.scope.generateUidIdentifier("ret");
// handle generators
var hasYield = traverse.hasType(fn.body, this.scope, "YieldExpression", t.FUNCTION_TYPES);
if (hasYield) {
fn.generator = true;
call = t.yieldExpression(call, true);
}
// handlers async functions
var hasAsync = traverse.hasType(fn.body, this.scope, "AwaitExpression", t.FUNCTION_TYPES);
if (hasAsync) {
fn.async = true;
call = t.awaitExpression(call, true);
}
this.build(ret, call);
};
var letReferenceFunctionVisitor = {
enter: function (node, parent, scope, state) {
enter(node, parent, scope, state) {
// not a direct reference
if (!t.isReferencedIdentifier(node, parent)) return;
@@ -281,65 +131,30 @@ var letReferenceFunctionVisitor = {
}
};
var letReferenceBlockVisitor = {
enter: function (node, parent, scope, state) {
if (t.isFunction(node)) {
scope.traverse(node, letReferenceFunctionVisitor, state);
var hoistVarDeclarationsVisitor = {
enter(node, parent, scope, self) {
if (t.isForStatement(node)) {
if (isVar(node.init, node)) {
node.init = t.sequenceExpression(self.pushDeclar(node.init));
}
} else if (t.isFor(node)) {
if (isVar(node.left, node)) {
node.left = node.left.declarations[0].id;
}
} else if (isVar(node, parent)) {
return self.pushDeclar(node).map(t.expressionStatement);
} else if (t.isFunction(node)) {
return this.skip();
}
}
};
/**
* Description
*/
BlockScoping.prototype.getLetReferences = function () {
var block = this.block;
var declarators = block._letDeclarators || [];
var declar;
//
for (var i = 0; i < declarators.length; i++) {
declar = declarators[i];
extend(this.outsideLetReferences, t.getBindingIdentifiers(declar));
}
//
if (block.body) {
for (i = 0; i < block.body.length; i++) {
declar = block.body[i];
if (isLet(declar, block)) {
declarators = declarators.concat(declar.declarations);
}
var loopLabelVisitor = {
enter(node, parent, scope, state) {
if (t.isLabeledStatement(node)) {
state.innerLabels.push(node.label.name);
}
}
//
for (i = 0; i < declarators.length; i++) {
declar = declarators[i];
var keys = t.getBindingIdentifiers(declar);
extend(this.letReferences, keys);
this.hasLetReferences = true;
}
// no let references so we can just quit
if (!this.hasLetReferences) return;
// set let references to plain var references
standardizeLets(declarators);
var state = {
letReferences: this.letReferences,
closurify: false
};
// traverse through this block, stopping on functions and checking if they
// contain any local let references
this.scope.traverse(this.block, letReferenceBlockVisitor, state);
return state.closurify;
};
var loopNodeTo = function (node) {
@@ -351,7 +166,7 @@ var loopNodeTo = function (node) {
};
var loopVisitor = {
enter: function (node, parent, scope, state) {
enter(node, parent, scope, state) {
var replace;
if (t.isLoop(node)) {
@@ -402,160 +217,346 @@ var loopVisitor = {
}
};
var loopLabelVisitor = {
enter: function (node, parent, scope, state) {
if (t.isLabeledStatement(node)) {
state.innerLabels.push(node.label.name);
}
}
};
class BlockScoping {
/**
* If we're inside of a loop then traverse it and check if it has one of
* the following node types `ReturnStatement`, `BreakStatement`,
* `ContinueStatement` and replace it with a return value that we can track
* later on.
*
* @returns {Object}
*/
/**
* Description
*
* @param {Boolean|Node} loopParent
* @param {Node} block
* @param {Node} parent
* @param {Scope} scope
* @param {File} file
*/
BlockScoping.prototype.checkLoop = function () {
var state = {
hasBreakContinue: false,
ignoreLabeless: false,
innerLabels: [],
hasReturn: false,
isLoop: !!this.loopParent,
map: {}
};
constructor(loopParent, block, parent, scope, file) {
this.loopParent = loopParent;
this.parent = parent;
this.scope = scope;
this.block = block;
this.file = file;
this.scope.traverse(this.block, loopLabelVisitor, state);
this.scope.traverse(this.block, loopVisitor, state);
return state;
};
var hoistVarDeclarationsVisitor = {
enter: function (node, parent, scope, self) {
if (t.isForStatement(node)) {
if (isVar(node.init, node)) {
node.init = t.sequenceExpression(self.pushDeclar(node.init));
}
} else if (t.isFor(node)) {
if (isVar(node.left, node)) {
node.left = node.left.declarations[0].id;
}
} else if (isVar(node, parent)) {
return self.pushDeclar(node).map(t.expressionStatement);
} else if (t.isFunction(node)) {
return this.skip();
}
}
};
/**
* Hoist all var declarations in this block to before it so they retain scope
* once we wrap everything in a closure.
*/
BlockScoping.prototype.hoistVarDeclarations = function () {
traverse(this.block, hoistVarDeclarationsVisitor, this.scope, this);
};
/**
* Turn a `VariableDeclaration` into an array of `AssignmentExpressions` with
* their declarations hoisted to before the closure wrapper.
*
* @param {Node} node VariableDeclaration
* @returns {Array}
*/
BlockScoping.prototype.pushDeclar = function (node) {
this.body.push(t.variableDeclaration(node.kind, node.declarations.map(function (declar) {
return t.variableDeclarator(declar.id);
})));
var replace = [];
for (var i = 0; i < node.declarations.length; i++) {
var declar = node.declarations[i];
if (!declar.init) continue;
var expr = t.assignmentExpression("=", declar.id, declar.init);
replace.push(t.inherits(expr, declar));
this.outsideLetReferences = object();
this.hasLetReferences = false;
this.letReferences = block._letReferences = object();
this.body = [];
}
return replace;
};
/**
* Start the ball rolling.
*/
/**
* Push the closure to the body.
*
* @param {Node} ret Identifier
* @param {Node} call CallExpression
*/
run() {
var block = this.block;
if (block._letDone) return;
block._letDone = true;
BlockScoping.prototype.build = function (ret, call) {
var has = this.has;
if (has.hasReturn || has.hasBreakContinue) {
this.buildHas(ret, call);
} else {
this.body.push(t.expressionStatement(call));
}
};
var needsClosure = this.getLetReferences();
/**
* Description
*
* @param {Node} ret Identifier
* @param {Node} call CallExpression
*/
// this is a block within a `Function/Program` so we can safely leave it be
if (t.isFunction(this.parent) || t.isProgram(this.block)) return;
BlockScoping.prototype.buildHas = function (ret, call) {
var body = this.body;
// we can skip everything
if (!this.hasLetReferences) return;
body.push(t.variableDeclaration("var", [
t.variableDeclarator(ret, call)
]));
var loopParent = this.loopParent;
var retCheck;
var has = this.has;
var cases = [];
if (has.hasReturn) {
// typeof ret === "object"
retCheck = util.template("let-scoping-return", {
RETURN: ret
});
}
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.");
}
for (var key in has.map) {
cases.push(t.switchCase(t.literal(key), [has.map[key]]));
}
if (has.hasReturn) {
cases.push(t.switchCase(null, [retCheck]));
}
if (cases.length === 1) {
var single = cases[0];
body.push(this.file.attachAuxiliaryComment(t.ifStatement(
t.binaryExpression("===", ret, single.test),
single.consequent[0]
)));
if (needsClosure) {
this.wrapClosure();
} else {
body.push(this.file.attachAuxiliaryComment(t.switchStatement(ret, cases)));
}
} else {
if (has.hasReturn) {
body.push(this.file.attachAuxiliaryComment(retCheck));
this.remap();
}
}
};
/**
* Description
*/
remap() {
var hasRemaps = false;
var letRefs = this.letReferences;
var scope = this.scope;
// alright, so since we aren't wrapping this block in a closure
// we have to check if any of our let variables collide with
// those in upper scopes and then if they do, generate a uid
// for them and replace all references with it
var remaps = object();
for (var key in letRefs) {
// just an Identifier node we collected in `getLetReferences`
// this is the defining identifier of a declaration
var ref = letRefs[key];
if (scope.parentHasBinding(key) || scope.hasGlobal(key)) {
var uid = scope.generateUidIdentifier(ref.name).name;
ref.name = uid;
hasRemaps = true;
remaps[key] = remaps[uid] = {
binding: ref,
uid: uid
};
}
}
if (!hasRemaps) return;
//
var loopParent = this.loopParent;
if (loopParent) {
traverseReplace(loopParent.right, loopParent, scope, remaps);
traverseReplace(loopParent.test, loopParent, scope, remaps);
traverseReplace(loopParent.update, loopParent, scope, remaps);
}
scope.traverse(this.block, replaceVisitor, remaps);
}
/**
* Description
*/
wrapClosure() {
var block = this.block;
var outsideRefs = this.outsideLetReferences;
// remap loop heads with colliding variables
if (this.loopParent) {
for (var name in outsideRefs) {
var id = outsideRefs[name];
if (this.scope.hasGlobal(id.name)) {
delete outsideRefs[id.name];
delete this.letReferences[id.name];
this.scope.rename(id.name);
this.letReferences[id.name] = id;
outsideRefs[id.name] = id;
}
}
}
// if we're inside of a for loop then we search to see if there are any
// `break`s, `continue`s, `return`s etc
this.has = this.checkLoop();
// hoist var references to retain scope
this.hoistVarDeclarations();
// turn outsideLetReferences into an array
var params = values(outsideRefs);
// build the closure that we're going to wrap the block with
var fn = t.functionExpression(null, params, t.blockStatement(block.body));
fn._aliasFunction = true;
// replace the current block body with the one we're going to build
block.body = this.body;
// build a call and a unique id that we can assign the return value to
var call = t.callExpression(fn, params);
var ret = this.scope.generateUidIdentifier("ret");
// handle generators
var hasYield = traverse.hasType(fn.body, this.scope, "YieldExpression", t.FUNCTION_TYPES);
if (hasYield) {
fn.generator = true;
call = t.yieldExpression(call, true);
}
// handlers async functions
var hasAsync = traverse.hasType(fn.body, this.scope, "AwaitExpression", t.FUNCTION_TYPES);
if (hasAsync) {
fn.async = true;
call = t.awaitExpression(call, true);
}
this.build(ret, call);
}
/**
* Description
*/
getLetReferences() {
var block = this.block;
var declarators = block._letDeclarators || [];
var declar;
//
for (var i = 0; i < declarators.length; i++) {
declar = declarators[i];
extend(this.outsideLetReferences, t.getBindingIdentifiers(declar));
}
//
if (block.body) {
for (i = 0; i < block.body.length; i++) {
declar = block.body[i];
if (isLet(declar, block)) {
declarators = declarators.concat(declar.declarations);
}
}
}
//
for (i = 0; i < declarators.length; i++) {
declar = declarators[i];
var keys = t.getBindingIdentifiers(declar);
extend(this.letReferences, keys);
this.hasLetReferences = true;
}
// no let references so we can just quit
if (!this.hasLetReferences) return;
// set let references to plain var references
standardizeLets(declarators);
var state = {
letReferences: this.letReferences,
closurify: false
};
// traverse through this block, stopping on functions and checking if they
// contain any local let references
this.scope.traverse(this.block, letReferenceBlockVisitor, state);
return state.closurify;
}
/**
* If we're inside of a loop then traverse it and check if it has one of
* the following node types `ReturnStatement`, `BreakStatement`,
* `ContinueStatement` and replace it with a return value that we can track
* later on.
*
* @returns {Object}
*/
checkLoop() {
var state = {
hasBreakContinue: false,
ignoreLabeless: false,
innerLabels: [],
hasReturn: false,
isLoop: !!this.loopParent,
map: {}
};
this.scope.traverse(this.block, loopLabelVisitor, state);
this.scope.traverse(this.block, loopVisitor, state);
return state;
}
/**
* Hoist all var declarations in this block to before it so they retain scope
* once we wrap everything in a closure.
*/
hoistVarDeclarations() {
traverse(this.block, hoistVarDeclarationsVisitor, this.scope, this);
}
/**
* Turn a `VariableDeclaration` into an array of `AssignmentExpressions` with
* their declarations hoisted to before the closure wrapper.
*
* @param {Node} node VariableDeclaration
* @returns {Array}
*/
pushDeclar(node) {
this.body.push(t.variableDeclaration(node.kind, node.declarations.map(function (declar) {
return t.variableDeclarator(declar.id);
})));
var replace = [];
for (var i = 0; i < node.declarations.length; i++) {
var declar = node.declarations[i];
if (!declar.init) continue;
var expr = t.assignmentExpression("=", declar.id, declar.init);
replace.push(t.inherits(expr, declar));
}
return replace;
}
/**
* Push the closure to the body.
*
* @param {Node} ret Identifier
* @param {Node} call CallExpression
*/
build(ret, call) {
var has = this.has;
if (has.hasReturn || has.hasBreakContinue) {
this.buildHas(ret, call);
} else {
this.body.push(t.expressionStatement(call));
}
}
/**
* Description
*
* @param {Node} ret Identifier
* @param {Node} call CallExpression
*/
buildHas(ret, call) {
var body = this.body;
body.push(t.variableDeclaration("var", [
t.variableDeclarator(ret, call)
]));
var loopParent = this.loopParent;
var retCheck;
var has = this.has;
var cases = [];
if (has.hasReturn) {
// typeof ret === "object"
retCheck = util.template("let-scoping-return", {
RETURN: ret
});
}
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.");
}
for (var key in has.map) {
cases.push(t.switchCase(t.literal(key), [has.map[key]]));
}
if (has.hasReturn) {
cases.push(t.switchCase(null, [retCheck]));
}
if (cases.length === 1) {
var single = cases[0];
body.push(this.file.attachAuxiliaryComment(t.ifStatement(
t.binaryExpression("===", ret, single.test),
single.consequent[0]
)));
} else {
body.push(this.file.attachAuxiliaryComment(t.switchStatement(ret, cases)));
}
} else {
if (has.hasReturn) {
body.push(this.file.attachAuxiliaryComment(retCheck));
}
}
}
}

View File

@@ -1,5 +1,3 @@
"use strict";
var ReplaceSupers = require("../../helpers/replace-supers");
var nameMethod = require("../../helpers/name-method");
var defineMap = require("../../helpers/define-map");
@@ -29,277 +27,280 @@ exports.ClassExpression = function (node, parent, scope, file) {
return new ClassTransformer(node, file, scope, false).run();
};
/**
* Description
*
* @param {Node} node
* @param {File} file
* @param {Scope} scope
* @param {Boolean} isStatement
*/
class ClassTransformer {
function ClassTransformer(node, file, scope, isStatement) {
this.isStatement = isStatement;
this.scope = scope;
this.node = node;
this.file = file;
/**
* Description
*
* @param {Node} node
* @param {File} file
* @param {Scope} scope
* @param {Boolean} isStatement
*/
this.hasInstanceMutators = false;
this.hasStaticMutators = false;
constructor(node, file, scope, isStatement) {
this.isStatement = isStatement;
this.scope = scope;
this.node = node;
this.file = file;
this.instanceMutatorMap = {};
this.staticMutatorMap = {};
this.hasConstructor = false;
this.className = node.id || scope.generateUidIdentifier("class");
this.superName = node.superClass || t.identifier("Function");
this.hasSuper = !!node.superClass;
this.isLoose = file.isLoose("es6.classes");
}
this.hasInstanceMutators = false;
this.hasStaticMutators = false;
/**
* Description
*
* @returns {Array}
*/
ClassTransformer.prototype.run = function () {
var superName = this.superName;
var className = this.className;
var classBody = this.node.body.body;
var file = this.file;
//
var body = this.body = [];
var constructorBody = t.blockStatement([
t.expressionStatement(t.callExpression(file.addHelper("class-call-check"), [
t.thisExpression(),
className
]))
]);
var constructor;
if (this.node.id) {
constructor = t.functionDeclaration(className, [], constructorBody);
body.push(constructor);
} else {
var constructorName = null;
// when a class has no parent and there is only a constructor or no body
// then the constructor is not wrapped in a closure and needs to be named
var containsOnlyConstructor = classBody.length === 1 && classBody[0].key.name === "constructor";
if (!this.hasSuper && (classBody.length === 0 || containsOnlyConstructor)) {
constructorName = className;
}
constructor = t.functionExpression(constructorName, [], constructorBody);
body.push(t.variableDeclaration("var", [
t.variableDeclarator(className, constructor)
]));
}
this.constructor = constructor;
var closureParams = [];
var closureArgs = [];
//
if (this.hasSuper) {
closureArgs.push(superName);
if (!t.isIdentifier(superName)) {
superName = this.scope.generateUidBasedOnNode(superName, this.file);
}
closureParams.push(superName);
this.superName = superName;
body.push(t.expressionStatement(t.callExpression(file.addHelper("inherits"), [className, superName])));
this.instanceMutatorMap = {};
this.staticMutatorMap = {};
this.hasConstructor = false;
this.className = node.id || scope.generateUidIdentifier("class");
this.superName = node.superClass || t.identifier("Function");
this.hasSuper = !!node.superClass;
this.isLoose = file.isLoose("es6.classes");
}
this.buildBody();
/**
* Description
*
* @returns {Array}
*/
t.inheritsComments(body[0], this.node);
run() {
var superName = this.superName;
var className = this.className;
var classBody = this.node.body.body;
var file = this.file;
var init;
//
if (body.length === 1) {
// only a constructor so no need for a closure container
init = t.toExpression(constructor);
} else {
body.push(t.returnStatement(className));
init = t.callExpression(
t.functionExpression(null, closureParams, t.blockStatement(body)),
closureArgs
);
}
var body = this.body = [];
if (this.isStatement) {
return t.variableDeclaration("let", [
t.variableDeclarator(className, init)
var constructorBody = t.blockStatement([
t.expressionStatement(t.callExpression(file.addHelper("class-call-check"), [
t.thisExpression(),
className
]))
]);
} else {
return init;
}
};
/**
* Description
*/
ClassTransformer.prototype.buildBody = function () {
var constructor = this.constructor;
var className = this.className;
var superName = this.superName;
var classBody = this.node.body.body;
var body = this.body;
for (var i = 0; i < classBody.length; i++) {
var node = classBody[i];
if (t.isMethodDefinition(node)) {
var replaceSupers = new ReplaceSupers({
methodNode: node,
className: this.className,
superName: this.superName,
isStatic: node.static,
isLoose: this.isLoose,
scope: this.scope,
file: this.file
}, true);
replaceSupers.replace();
if ((!node.computed && t.isIdentifier(node.key, { name: "constructor" })) || t.isLiteral(node.key, { value: "constructor" })) {
this.pushConstructor(node);
} else {
this.pushMethod(node);
var constructor;
if (this.node.id) {
constructor = t.functionDeclaration(className, [], constructorBody);
body.push(constructor);
} else {
var constructorName = null;
// when a class has no parent and there is only a constructor or no body
// then the constructor is not wrapped in a closure and needs to be named
var containsOnlyConstructor = classBody.length === 1 && classBody[0].key.name === "constructor";
if (!this.hasSuper && (classBody.length === 0 || containsOnlyConstructor)) {
constructorName = className;
}
} else if (t.isPrivateDeclaration(node)) {
this.closure = true;
body.unshift(node);
} else if (t.isClassProperty(node)) {
this.pushProperty(node);
constructor = t.functionExpression(constructorName, [], constructorBody);
body.push(t.variableDeclaration("var", [
t.variableDeclarator(className, constructor)
]));
}
this.constructor = constructor;
var closureParams = [];
var closureArgs = [];
//
if (this.hasSuper) {
closureArgs.push(superName);
if (!t.isIdentifier(superName)) {
superName = this.scope.generateUidBasedOnNode(superName, this.file);
}
closureParams.push(superName);
this.superName = superName;
body.push(t.expressionStatement(t.callExpression(file.addHelper("inherits"), [className, superName])));
}
this.buildBody();
t.inheritsComments(body[0], this.node);
var init;
if (body.length === 1) {
// only a constructor so no need for a closure container
init = t.toExpression(constructor);
} else {
body.push(t.returnStatement(className));
init = t.callExpression(
t.functionExpression(null, closureParams, t.blockStatement(body)),
closureArgs
);
}
if (this.isStatement) {
return t.variableDeclaration("let", [
t.variableDeclarator(className, init)
]);
} else {
return init;
}
}
// we have no constructor, we have a super, and the super doesn't appear to be falsy
if (!this.hasConstructor && this.hasSuper && !t.isFalsyExpression(superName)) {
var helperName = "class-super-constructor-call";
if (this.isLoose) helperName += "-loose";
constructor.body.body.push(util.template(helperName, {
CLASS_NAME: className,
SUPER_NAME: this.superName
}, true));
}
/**
* Description
*/
var instanceProps;
var staticProps;
buildBody() {
var constructor = this.constructor;
var className = this.className;
var superName = this.superName;
var classBody = this.node.body.body;
var body = this.body;
if (this.hasInstanceMutators) {
instanceProps = defineMap.build(this.instanceMutatorMap);
}
for (var i = 0; i < classBody.length; i++) {
var node = classBody[i];
if (t.isMethodDefinition(node)) {
var replaceSupers = new ReplaceSupers({
methodNode: node,
className: this.className,
superName: this.superName,
isStatic: node.static,
isLoose: this.isLoose,
scope: this.scope,
file: this.file
}, true);
replaceSupers.replace();
if (this.hasStaticMutators) {
staticProps = defineMap.build(this.staticMutatorMap);
}
if (instanceProps || staticProps) {
staticProps = staticProps || t.literal(null);
var args = [className, staticProps];
if (instanceProps) args.push(instanceProps);
body.push(t.expressionStatement(
t.callExpression(this.file.addHelper("prototype-properties"), args)
));
}
};
/**
* Push a method to its respective mutatorMap.
*
* @param {Node} node MethodDefinition
*/
ClassTransformer.prototype.pushMethod = function (node) {
var methodName = node.key;
var kind = node.kind;
if (kind === "") {
nameMethod.property(node, this.file, this.scope);
if (this.isLoose) {
// use assignments instead of define properties for loose classes
var className = this.className;
if (!node.static) className = t.memberExpression(className, t.identifier("prototype"));
methodName = t.memberExpression(className, methodName, node.computed);
var expr = t.expressionStatement(t.assignmentExpression("=", methodName, node.value));
t.inheritsComments(expr, node);
this.body.push(expr);
return;
if ((!node.computed && t.isIdentifier(node.key, { name: "constructor" })) || t.isLiteral(node.key, { value: "constructor" })) {
this.pushConstructor(node);
} else {
this.pushMethod(node);
}
} else if (t.isPrivateDeclaration(node)) {
this.closure = true;
body.unshift(node);
} else if (t.isClassProperty(node)) {
this.pushProperty(node);
}
}
kind = "value";
// we have no constructor, we have a super, and the super doesn't appear to be falsy
if (!this.hasConstructor && this.hasSuper && !t.isFalsyExpression(superName)) {
var helperName = "class-super-constructor-call";
if (this.isLoose) helperName += "-loose";
constructor.body.body.push(util.template(helperName, {
CLASS_NAME: className,
SUPER_NAME: this.superName
}, true));
}
var instanceProps;
var staticProps;
if (this.hasInstanceMutators) {
instanceProps = defineMap.build(this.instanceMutatorMap);
}
if (this.hasStaticMutators) {
staticProps = defineMap.build(this.staticMutatorMap);
}
if (instanceProps || staticProps) {
staticProps ||= t.literal(null);
var args = [className, staticProps];
if (instanceProps) args.push(instanceProps);
body.push(t.expressionStatement(
t.callExpression(this.file.addHelper("prototype-properties"), args)
));
}
}
var mutatorMap = this.instanceMutatorMap;
if (node.static) {
this.hasStaticMutators = true;
mutatorMap = this.staticMutatorMap;
} else {
this.hasInstanceMutators = true;
/**
* Push a method to its respective mutatorMap.
*
* @param {Node} node MethodDefinition
*/
pushMethod(node) {
var methodName = node.key;
var kind = node.kind;
if (kind === "") {
nameMethod.property(node, this.file, this.scope);
if (this.isLoose) {
// use assignments instead of define properties for loose classes
var className = this.className;
if (!node.static) className = t.memberExpression(className, t.identifier("prototype"));
methodName = t.memberExpression(className, methodName, node.computed);
var expr = t.expressionStatement(t.assignmentExpression("=", methodName, node.value));
t.inheritsComments(expr, node);
this.body.push(expr);
return;
}
kind = "value";
}
var mutatorMap = this.instanceMutatorMap;
if (node.static) {
this.hasStaticMutators = true;
mutatorMap = this.staticMutatorMap;
} else {
this.hasInstanceMutators = true;
}
defineMap.push(mutatorMap, methodName, kind, node.computed, node);
defineMap.push(mutatorMap, methodName, "enumerable", node.computed, false);
}
defineMap.push(mutatorMap, methodName, kind, node.computed, node);
defineMap.push(mutatorMap, methodName, "enumerable", node.computed, false);
};
/**
* Description
*
* @param {Node} node
*/
/**
* Description
*
* @param {Node} node
*/
pushProperty(node) {
if (!node.value) return;
ClassTransformer.prototype.pushProperty = function (node) {
if (!node.value) return;
var key;
var key;
if (node.static) {
key = t.memberExpression(this.className, node.key);
this.body.push(
t.expressionStatement(t.assignmentExpression("=", key, node.value))
);
} else {
key = t.memberExpression(t.thisExpression(), node.key);
this.constructor.body.body.unshift(
t.expressionStatement(t.assignmentExpression("=", key, node.value))
);
}
};
/**
* Replace the constructor body of our class.
*
* @param {Node} method MethodDefinition
*/
ClassTransformer.prototype.pushConstructor = function (method) {
if (method.kind) {
throw this.file.errorWithNode(method, messages.get("classesIllegalConstructorKind"));
if (node.static) {
key = t.memberExpression(this.className, node.key);
this.body.push(
t.expressionStatement(t.assignmentExpression("=", key, node.value))
);
} else {
key = t.memberExpression(t.thisExpression(), node.key);
this.constructor.body.body.unshift(
t.expressionStatement(t.assignmentExpression("=", key, node.value))
);
}
}
var construct = this.constructor;
var fn = method.value;
/**
* Replace the constructor body of our class.
*
* @param {Node} method MethodDefinition
*/
this.hasConstructor = true;
pushConstructor(method) {
if (method.kind) {
throw this.file.errorWithNode(method, messages.get("classesIllegalConstructorKind"));
}
t.inherits(construct, fn);
t.inheritsComments(construct, method);
var construct = this.constructor;
var fn = method.value;
construct._ignoreUserWhitespace = true;
construct.params = fn.params;
construct.body.body = construct.body.body.concat(fn.body.body);
};
this.hasConstructor = true;
t.inherits(construct, fn);
t.inheritsComments(construct, method);
construct._ignoreUserWhitespace = true;
construct.params = fn.params;
construct.body.body = construct.body.body.concat(fn.body.body);
}
}

View File

@@ -1,5 +1,3 @@
"use strict";
var messages = require("../../../messages");
var t = require("../../../types");
@@ -8,7 +6,7 @@ exports.check = function (node) {
};
var visitor = {
enter: function (node, parent, scope, state) {
enter(node, parent, scope, state) {
if (t.isAssignmentExpression(node) || t.isUpdateExpression(node)) {
var ids = t.getBindingIdentifiers(node);

View File

@@ -1,273 +1,8 @@
"use strict";
var messages = require("../../../messages");
var t = require("../../../types");
exports.check = t.isPattern;
function DestructuringTransformer(opts) {
this.blockHoist = opts.blockHoist;
this.operator = opts.operator;
this.nodes = opts.nodes;
this.scope = opts.scope;
this.file = opts.file;
this.kind = opts.kind;
}
DestructuringTransformer.prototype.buildVariableAssignment = function (id, init) {
var op = this.operator;
if (t.isMemberExpression(id)) op = "=";
var node;
if (op) {
node = t.expressionStatement(t.assignmentExpression(op, id, init));
} else {
node = t.variableDeclaration(this.kind, [
t.variableDeclarator(id, init)
]);
}
node._blockHoist = this.blockHoist;
return node;
};
DestructuringTransformer.prototype.buildVariableDeclaration = function (id, init) {
var declar = t.variableDeclaration("var", [
t.variableDeclarator(id, init)
]);
declar._blockHoist = this.blockHoist;
return declar;
};
DestructuringTransformer.prototype.push = function (id, init) {
if (t.isObjectPattern(id)) {
this.pushObjectPattern(id, init);
} else if (t.isArrayPattern(id)) {
this.pushArrayPattern(id, init);
} else if (t.isAssignmentPattern(id)) {
this.pushAssignmentPattern(id, init);
} else {
this.nodes.push(this.buildVariableAssignment(id, init));
}
};
DestructuringTransformer.prototype.get = function () {
};
DestructuringTransformer.prototype.pushAssignmentPattern = function (pattern, valueRef) {
// we need to assign the current value of the assignment to avoid evaluating
// it more than once
var tempValueRef = this.scope.generateUidBasedOnNode(valueRef);
var declar = t.variableDeclaration("var", [
t.variableDeclarator(tempValueRef, valueRef)
]);
declar._blockHoist = this.blockHoist;
this.nodes.push(declar);
//
this.nodes.push(this.buildVariableAssignment(
pattern.left,
t.conditionalExpression(
t.binaryExpression("===", tempValueRef, t.identifier("undefined")),
pattern.right,
tempValueRef
)
));
};
DestructuringTransformer.prototype.pushObjectSpread = function (pattern, objRef, spreadProp, spreadPropIndex) {
// get all the keys that appear in this object before the current spread
var keys = [];
for (var i = 0; i < pattern.properties.length; i++) {
var prop = pattern.properties[i];
// we've exceeded the index of the spread property to all properties to the
// right need to be ignored
if (i >= spreadPropIndex) break;
// ignore other spread properties
if (t.isSpreadProperty(prop)) continue;
var key = prop.key;
if (t.isIdentifier(key)) key = t.literal(prop.key.name);
keys.push(key);
}
keys = t.arrayExpression(keys);
//
var value = t.callExpression(this.file.addHelper("object-without-properties"), [objRef, keys]);
this.nodes.push(this.buildVariableAssignment(spreadProp.argument, value));
};
DestructuringTransformer.prototype.pushObjectProperty = function (prop, propRef) {
if (t.isLiteral(prop.key)) prop.computed = true;
var pattern = prop.value;
var objRef = t.memberExpression(propRef, prop.key, prop.computed);
if (t.isPattern(pattern)) {
this.push(pattern, objRef);
} else {
this.nodes.push(this.buildVariableAssignment(pattern, objRef));
}
};
DestructuringTransformer.prototype.pushObjectPattern = function (pattern, objRef) {
// https://github.com/babel/babel/issues/681
if (!pattern.properties.length) {
this.nodes.push(t.expressionStatement(
t.callExpression(this.file.addHelper("object-destructuring-empty"), [objRef])
));
}
// if we have more than one properties in this pattern and the objectRef is a
// member expression then we need to assign it to a temporary variable so it's
// only evaluated once
if (pattern.properties.length > 1 && t.isMemberExpression(objRef)) {
var temp = this.scope.generateUidBasedOnNode(objRef, this.file);
this.nodes.push(this.buildVariableDeclaration(temp, objRef));
objRef = temp;
}
//
for (var i = 0; i < pattern.properties.length; i++) {
var prop = pattern.properties[i];
if (t.isSpreadProperty(prop)) {
this.pushObjectSpread(pattern, objRef, prop, i);
} else {
this.pushObjectProperty(prop, objRef);
}
}
};
var hasRest = function (pattern) {
for (var i = 0; i < pattern.elements.length; i++) {
if (t.isRestElement(pattern.elements[i])) {
return true;
}
}
return false;
};
DestructuringTransformer.prototype.canUnpackArrayPattern = function (pattern, arr) {
// not an array so there's no way we can deal with this
if (!t.isArrayExpression(arr)) return false;
// pattern has less elements than the array and doesn't have a rest so some
// elements wont be evaluated
if (pattern.elements.length > arr.elements.length) return;
if (pattern.elements.length < arr.elements.length && !hasRest(pattern)) return false;
// deopt on holes
for (var i = 0; i < pattern.elements.length; i++) {
if (!pattern.elements[i]) return false;
}
return true;
};
DestructuringTransformer.prototype.pushUnpackedArrayPattern = function (pattern, arr) {
for (var i = 0; i < pattern.elements.length; i++) {
var elem = pattern.elements[i];
if (t.isRestElement(elem)) {
this.push(elem.argument, t.arrayExpression(arr.elements.slice(i)));
} else {
this.push(elem, arr.elements[i]);
}
}
};
DestructuringTransformer.prototype.pushArrayPattern = function (pattern, arrayRef) {
if (!pattern.elements) return;
// optimise basic array destructuring of an array expression
//
// we can't do this to a pattern of unequal size to it's right hand
// array expression as then there will be values that wont be evaluated
//
// eg: var [a, b] = [1, 2];
if (this.canUnpackArrayPattern(pattern, arrayRef)) {
return this.pushUnpackedArrayPattern(pattern, arrayRef);
}
// if we have a rest then we need all the elements so don't tell
// `scope.toArray` to only get a certain amount
var count = !hasRest(pattern) && pattern.elements.length;
// so we need to ensure that the `arrayRef` is an array, `scope.toArray` will
// return a locally bound identifier if it's been inferred to be an array,
// otherwise it'll be a call to a helper that will ensure it's one
var toArray = this.scope.toArray(arrayRef, count);
if (t.isIdentifier(toArray)) {
// we've been given an identifier so it must have been inferred to be an
// array
arrayRef = toArray;
} else {
arrayRef = this.scope.generateUidBasedOnNode(arrayRef);
this.nodes.push(this.buildVariableDeclaration(arrayRef, toArray));
this.scope.assignTypeGeneric(arrayRef.name, "Array");
}
//
for (var i = 0; i < pattern.elements.length; i++) {
var elem = pattern.elements[i];
// hole
if (!elem) continue;
var elemRef;
if (t.isRestElement(elem)) {
elemRef = this.scope.toArray(arrayRef);
if (i > 0) {
elemRef = t.callExpression(t.memberExpression(elemRef, t.identifier("slice")), [t.literal(i)]);
}
// set the element to the rest element argument since we've dealt with it
// being a rest already
elem = elem.argument;
} else {
elemRef = t.memberExpression(arrayRef, t.literal(i), true);
}
this.push(elem, elemRef);
}
};
DestructuringTransformer.prototype.init = function (pattern, ref) {
// trying to destructure a value that we can't evaluate more than once so we
// need to save it to a variable
if (!t.isArrayExpression(ref) && !t.isMemberExpression(ref) && !t.isIdentifier(ref)) {
var key = this.scope.generateUidBasedOnNode(ref);
this.nodes.push(this.buildVariableDeclaration(key, ref));
ref = key;
}
//
this.push(pattern, ref);
};
exports.ForInStatement =
exports.ForOfStatement = function (node, parent, scope, file) {
var left = node.left;
@@ -469,7 +204,7 @@ exports.VariableDeclaration = function (node, parent, scope, file) {
for (i = 0; i < nodes.length; i++) {
node = nodes[i];
declar = declar || t.variableDeclaration(node.kind, []);
declar ||= t.variableDeclaration(node.kind, []);
if (!t.isVariableDeclaration(node) && declar.kind !== node.kind) {
throw file.errorWithNode(node, messages.get("invalidParentForThisNode"));
@@ -483,3 +218,264 @@ exports.VariableDeclaration = function (node, parent, scope, file) {
return nodes;
};
var hasRest = function (pattern) {
for (var i = 0; i < pattern.elements.length; i++) {
if (t.isRestElement(pattern.elements[i])) {
return true;
}
}
return false;
};
class DestructuringTransformer {
constructor(opts) {
this.blockHoist = opts.blockHoist;
this.operator = opts.operator;
this.nodes = opts.nodes;
this.scope = opts.scope;
this.file = opts.file;
this.kind = opts.kind;
}
buildVariableAssignment(id, init) {
var op = this.operator;
if (t.isMemberExpression(id)) op = "=";
var node;
if (op) {
node = t.expressionStatement(t.assignmentExpression(op, id, init));
} else {
node = t.variableDeclaration(this.kind, [
t.variableDeclarator(id, init)
]);
}
node._blockHoist = this.blockHoist;
return node;
}
buildVariableDeclaration(id, init) {
var declar = t.variableDeclaration("var", [
t.variableDeclarator(id, init)
]);
declar._blockHoist = this.blockHoist;
return declar;
}
push(id, init) {
if (t.isObjectPattern(id)) {
this.pushObjectPattern(id, init);
} else if (t.isArrayPattern(id)) {
this.pushArrayPattern(id, init);
} else if (t.isAssignmentPattern(id)) {
this.pushAssignmentPattern(id, init);
} else {
this.nodes.push(this.buildVariableAssignment(id, init));
}
}
pushAssignmentPattern(pattern, valueRef) {
// we need to assign the current value of the assignment to avoid evaluating
// it more than once
var tempValueRef = this.scope.generateUidBasedOnNode(valueRef);
var declar = t.variableDeclaration("var", [
t.variableDeclarator(tempValueRef, valueRef)
]);
declar._blockHoist = this.blockHoist;
this.nodes.push(declar);
//
this.nodes.push(this.buildVariableAssignment(
pattern.left,
t.conditionalExpression(
t.binaryExpression("===", tempValueRef, t.identifier("undefined")),
pattern.right,
tempValueRef
)
));
}
pushObjectSpread(pattern, objRef, spreadProp, spreadPropIndex) {
// get all the keys that appear in this object before the current spread
var keys = [];
for (var i = 0; i < pattern.properties.length; i++) {
var prop = pattern.properties[i];
// we've exceeded the index of the spread property to all properties to the
// right need to be ignored
if (i >= spreadPropIndex) break;
// ignore other spread properties
if (t.isSpreadProperty(prop)) continue;
var key = prop.key;
if (t.isIdentifier(key)) key = t.literal(prop.key.name);
keys.push(key);
}
keys = t.arrayExpression(keys);
//
var value = t.callExpression(this.file.addHelper("object-without-properties"), [objRef, keys]);
this.nodes.push(this.buildVariableAssignment(spreadProp.argument, value));
}
pushObjectProperty(prop, propRef) {
if (t.isLiteral(prop.key)) prop.computed = true;
var pattern = prop.value;
var objRef = t.memberExpression(propRef, prop.key, prop.computed);
if (t.isPattern(pattern)) {
this.push(pattern, objRef);
} else {
this.nodes.push(this.buildVariableAssignment(pattern, objRef));
}
}
pushObjectPattern(pattern, objRef) {
// https://github.com/babel/babel/issues/681
if (!pattern.properties.length) {
this.nodes.push(t.expressionStatement(
t.callExpression(this.file.addHelper("object-destructuring-empty"), [objRef])
));
}
// if we have more than one properties in this pattern and the objectRef is a
// member expression then we need to assign it to a temporary variable so it's
// only evaluated once
if (pattern.properties.length > 1 && t.isMemberExpression(objRef)) {
var temp = this.scope.generateUidBasedOnNode(objRef, this.file);
this.nodes.push(this.buildVariableDeclaration(temp, objRef));
objRef = temp;
}
//
for (var i = 0; i < pattern.properties.length; i++) {
var prop = pattern.properties[i];
if (t.isSpreadProperty(prop)) {
this.pushObjectSpread(pattern, objRef, prop, i);
} else {
this.pushObjectProperty(prop, objRef);
}
}
}
canUnpackArrayPattern(pattern, arr) {
// not an array so there's no way we can deal with this
if (!t.isArrayExpression(arr)) return false;
// pattern has less elements than the array and doesn't have a rest so some
// elements wont be evaluated
if (pattern.elements.length > arr.elements.length) return;
if (pattern.elements.length < arr.elements.length && !hasRest(pattern)) return false;
// deopt on holes
for (var i = 0; i < pattern.elements.length; i++) {
if (!pattern.elements[i]) return false;
}
return true;
}
pushUnpackedArrayPattern(pattern, arr) {
for (var i = 0; i < pattern.elements.length; i++) {
var elem = pattern.elements[i];
if (t.isRestElement(elem)) {
this.push(elem.argument, t.arrayExpression(arr.elements.slice(i)));
} else {
this.push(elem, arr.elements[i]);
}
}
}
pushArrayPattern(pattern, arrayRef) {
if (!pattern.elements) return;
// optimise basic array destructuring of an array expression
//
// we can't do this to a pattern of unequal size to it's right hand
// array expression as then there will be values that wont be evaluated
//
// eg: var [a, b] = [1, 2];
if (this.canUnpackArrayPattern(pattern, arrayRef)) {
return this.pushUnpackedArrayPattern(pattern, arrayRef);
}
// if we have a rest then we need all the elements so don't tell
// `scope.toArray` to only get a certain amount
var count = !hasRest(pattern) && pattern.elements.length;
// so we need to ensure that the `arrayRef` is an array, `scope.toArray` will
// return a locally bound identifier if it's been inferred to be an array,
// otherwise it'll be a call to a helper that will ensure it's one
var toArray = this.scope.toArray(arrayRef, count);
if (t.isIdentifier(toArray)) {
// we've been given an identifier so it must have been inferred to be an
// array
arrayRef = toArray;
} else {
arrayRef = this.scope.generateUidBasedOnNode(arrayRef);
this.nodes.push(this.buildVariableDeclaration(arrayRef, toArray));
this.scope.assignTypeGeneric(arrayRef.name, "Array");
}
//
for (var i = 0; i < pattern.elements.length; i++) {
var elem = pattern.elements[i];
// hole
if (!elem) continue;
var elemRef;
if (t.isRestElement(elem)) {
elemRef = this.scope.toArray(arrayRef);
if (i > 0) {
elemRef = t.callExpression(t.memberExpression(elemRef, t.identifier("slice")), [t.literal(i)]);
}
// set the element to the rest element argument since we've dealt with it
// being a rest already
elem = elem.argument;
} else {
elemRef = t.memberExpression(arrayRef, t.literal(i), true);
}
this.push(elem, elemRef);
}
}
init(pattern, ref) {
// trying to destructure a value that we can't evaluate more than once so we
// need to save it to a variable
if (!t.isArrayExpression(ref) && !t.isMemberExpression(ref) && !t.isIdentifier(ref)) {
var key = this.scope.generateUidBasedOnNode(ref);
this.nodes.push(this.buildVariableDeclaration(key, ref));
ref = key;
}
//
this.push(pattern, ref);
}
}

View File

@@ -1,5 +1,3 @@
"use strict";
var messages = require("../../../messages");
var util = require("../../../util");
var t = require("../../../types");
@@ -38,7 +36,7 @@ exports.ForOfStatement = function (node, parent, scope, file) {
};
var breakVisitor = {
enter: function (node, parent, scope, state) {
enter(node, parent, scope, state) {
if (t.isLoop(node)) {
state.ignoreLabeless = true;
scope.traverse(node, breakVisitor, state);

View File

@@ -1,5 +1,3 @@
"use strict";
var t = require("../../../types");
exports.check = require("../internal/modules").check;

View File

@@ -1,5 +1,3 @@
"use strict";
var ReplaceSupers = require("../../helpers/replace-supers");
var t = require("../../../types");

View File

@@ -1,5 +1,3 @@
"use strict";
var util = require("../../../util");
var t = require("../../../types");
@@ -15,7 +13,7 @@ var hasDefaults = function (node) {
};
var iifeVisitor = {
enter: function (node, parent, scope, state) {
enter(node, parent, scope, state) {
if (!t.isReferencedIdentifier(node, parent)) return;
if (!state.scope.hasOwnBinding(node.name)) return;
if (state.scope.bindingIdentifierEquals(node.name, node)) return;

View File

@@ -1,5 +1,3 @@
"use strict";
var util = require("../../../util");
var t = require("../../../types");

View File

@@ -1,5 +1,3 @@
"use strict";
var t = require("../../../types");
exports.check = function (node) {

View File

@@ -1,5 +1,3 @@
"use strict";
var clone = require("lodash/lang/clone");
var t = require("../../../types");

View File

@@ -1,5 +1,3 @@
"use strict";
var includes = require("lodash/collection/includes");
var t = require("../../../types");

View File

@@ -1,5 +1,3 @@
"use strict";
var reduceRight = require("lodash/collection/reduceRight");
var messages = require("../../../messages");
var flatten = require("lodash/array/flatten");
@@ -7,305 +5,18 @@ var util = require("../../../util");
var map = require("lodash/collection/map");
var t = require("../../../types");
exports.Function = function (node, parent, scope, file) {
var tailCall = new TailCallTransformer(node, scope, file);
tailCall.run();
};
function returnBlock(expr) {
return t.blockStatement([t.returnStatement(expr)]);
}
function TailCallTransformer(node, scope, file) {
this.hasTailRecursion = false;
this.needsArguments = false;
this.setsArguments = false;
this.needsThis = false;
this.ownerId = node.id;
this.vars = [];
this.scope = scope;
this.file = file;
this.node = node;
}
TailCallTransformer.prototype.getArgumentsId = function () {
return this.argumentsId = this.argumentsId || this.scope.generateUidIdentifier("arguments");
};
TailCallTransformer.prototype.getThisId = function () {
return this.thisId = this.thisId || this.scope.generateUidIdentifier("this");
};
TailCallTransformer.prototype.getLeftId = function () {
return this.leftId = this.leftId || this.scope.generateUidIdentifier("left");
};
TailCallTransformer.prototype.getFunctionId = function () {
return this.functionId = this.functionId || this.scope.generateUidIdentifier("function");
};
TailCallTransformer.prototype.getAgainId = function () {
return this.againId = this.againId || this.scope.generateUidIdentifier("again");
};
TailCallTransformer.prototype.getParams = function () {
var params = this.params;
if (!params) {
params = this.node.params;
this.paramDecls = [];
for (var i = 0; i < params.length; i++) {
var param = params[i];
if (!param._isDefaultPlaceholder) {
this.paramDecls.push(t.variableDeclarator(
param,
params[i] = this.scope.generateUidIdentifier("x")
));
}
}
}
return this.params = params;
};
TailCallTransformer.prototype.hasDeopt = function () {
// check if the ownerId has been reassigned, if it has then it's not safe to
// perform optimisations
var ownerIdInfo = this.scope.getBindingInfo(this.ownerId.name);
return ownerIdInfo && ownerIdInfo.reassigned;
};
TailCallTransformer.prototype.run = function () {
var scope = this.scope;
var node = this.node;
// only tail recursion can be optimized as for now, so we can skip anonymous
// functions entirely
var ownerId = this.ownerId;
if (!ownerId) return;
// traverse the function and look for tail recursion
scope.traverse(node, firstPass, this);
if (!this.hasTailRecursion) return;
if (this.hasDeopt()) {
this.file.logDeopt(node, messages.get("tailCallReassignmentDeopt"));
return;
}
//
scope.traverse(node, secondPass, this);
if (!this.needsThis || !this.needsArguments) {
scope.traverse(node, thirdPass, this);
}
var body = t.ensureBlock(node).body;
if (this.vars.length > 0) {
var declarations = flatten(map(this.vars, function (decl) {
return decl.declarations;
}, this));
var statement = reduceRight(declarations, function (expr, decl) {
return t.assignmentExpression("=", decl.id, expr);
}, t.identifier("undefined"));
body.unshift(t.expressionStatement(statement));
}
var paramDecls = this.paramDecls;
if (paramDecls.length > 0) {
body.unshift(t.variableDeclaration("var", paramDecls));
}
body.unshift(t.expressionStatement(
t.assignmentExpression("=", this.getAgainId(), t.literal(false)))
);
node.body = util.template("tail-call-body", {
AGAIN_ID: this.getAgainId(),
THIS_ID: this.thisId,
ARGUMENTS_ID: this.argumentsId,
FUNCTION_ID: this.getFunctionId(),
BLOCK: node.body
});
var topVars = [];
if (this.needsThis) {
topVars.push(t.variableDeclarator(this.getThisId(), t.thisExpression()));
}
if (this.needsArguments || this.setsArguments) {
var decl = t.variableDeclarator(this.getArgumentsId());
if (this.needsArguments) {
decl.init = t.identifier("arguments");
}
topVars.push(decl);
}
var leftId = this.leftId;
if (leftId) {
topVars.push(t.variableDeclarator(leftId));
}
if (topVars.length > 0) {
node.body.body.unshift(t.variableDeclaration("var", topVars));
}
};
TailCallTransformer.prototype.subTransform = function (node) {
if (!node) return;
var handler = this["subTransform" + node.type];
if (handler) return handler.call(this, node);
};
TailCallTransformer.prototype.subTransformConditionalExpression = function (node) {
var callConsequent = this.subTransform(node.consequent);
var callAlternate = this.subTransform(node.alternate);
if (!callConsequent && !callAlternate) {
return;
}
// if ternary operator had tail recursion in value, convert to optimized if-statement
node.type = "IfStatement";
node.consequent = callConsequent ? t.toBlock(callConsequent) : returnBlock(node.consequent);
if (callAlternate) {
node.alternate = t.isIfStatement(callAlternate) ? callAlternate : t.toBlock(callAlternate);
} else {
node.alternate = returnBlock(node.alternate);
}
return [node];
};
TailCallTransformer.prototype.subTransformLogicalExpression = function (node) {
// only call in right-value of can be optimized
var callRight = this.subTransform(node.right);
if (!callRight) return;
// cache left value as it might have side-effects
var leftId = this.getLeftId();
var testExpr = t.assignmentExpression(
"=",
leftId,
node.left
);
if (node.operator === "&&") {
testExpr = t.unaryExpression("!", testExpr);
}
return [t.ifStatement(testExpr, returnBlock(leftId))].concat(callRight);
};
TailCallTransformer.prototype.subTransformSequenceExpression = function (node) {
var seq = node.expressions;
// only last element can be optimized
var lastCall = this.subTransform(seq[seq.length - 1]);
if (!lastCall) {
return;
}
// remove converted expression from sequence
// and convert to regular expression if needed
if (--seq.length === 1) {
node = seq[0];
}
return [t.expressionStatement(node)].concat(lastCall);
};
TailCallTransformer.prototype.subTransformCallExpression = function (node) {
var callee = node.callee, thisBinding, args;
if (t.isMemberExpression(callee, { computed: false }) && t.isIdentifier(callee.property)) {
switch (callee.property.name) {
case "call":
args = t.arrayExpression(node.arguments.slice(1));
break;
case "apply":
args = node.arguments[1] || t.identifier("undefined");
break;
default:
return;
}
thisBinding = node.arguments[0];
callee = callee.object;
}
// only tail recursion can be optimized as for now
if (!t.isIdentifier(callee) || !this.scope.bindingIdentifierEquals(callee.name, this.ownerId)) {
return;
}
this.hasTailRecursion = true;
if (this.hasDeopt()) return;
var body = [];
if (!t.isThisExpression(thisBinding)) {
body.push(t.expressionStatement(t.assignmentExpression(
"=",
this.getThisId(),
thisBinding || t.identifier("undefined")
)));
}
if (!args) {
args = t.arrayExpression(node.arguments);
}
var argumentsId = this.getArgumentsId();
var params = this.getParams();
body.push(t.expressionStatement(t.assignmentExpression(
"=",
argumentsId,
args
)));
var i, param;
if (t.isArrayExpression(args)) {
var elems = args.elements;
for (i = 0; i < elems.length && i < params.length; i++) {
param = params[i];
var elem = elems[i] || (elems[i] = t.identifier("undefined"));
if (!param._isDefaultPlaceholder) {
elems[i] = t.assignmentExpression("=", param, elem);
}
}
} else {
this.setsArguments = true;
for (i = 0; i < params.length; i++) {
param = params[i];
if (!param._isDefaultPlaceholder) {
body.push(t.expressionStatement(t.assignmentExpression(
"=",
param,
t.memberExpression(argumentsId, t.literal(i), true)
)));
}
}
}
body.push(t.expressionStatement(
t.assignmentExpression("=", this.getAgainId(), t.literal(true))
));
body.push(t.continueStatement(this.getFunctionId()));
return body;
};
// looks for and replaces tail recursion calls
var firstPass = {
enter: function (node, parent, scope, state) {
enter(node, parent, scope, state) {
if (t.isIfStatement(node)) {
if (t.isReturnStatement(node.alternate)) {
t.ensureBlock(node, "alternate");
@@ -335,7 +46,7 @@ var firstPass = {
// hoists up function declarations, replaces `this` and `arguments` and marks
// them as needed
var secondPass = {
enter: function (node, parent, scope, state) {
enter(node, parent, scope, state) {
if (t.isThisExpression(node)) {
state.needsThis = true;
return state.getThisId();
@@ -357,7 +68,7 @@ var secondPass = {
// optimizes recursion by removing `this` and `arguments` if they aren't used
var thirdPass = {
enter: function (node, parent, scope, state) {
enter(node, parent, scope, state) {
if (!t.isExpressionStatement(node)) return;
var expr = node.expression;
@@ -373,7 +84,296 @@ var thirdPass = {
}
};
exports.Function = function (node, parent, scope, file) {
var tailCall = new TailCallTransformer(node, scope, file);
tailCall.run();
};
class TailCallTransformer {
constructor(node, scope, file) {
this.hasTailRecursion = false;
this.needsArguments = false;
this.setsArguments = false;
this.needsThis = false;
this.ownerId = node.id;
this.vars = [];
this.scope = scope;
this.file = file;
this.node = node;
}
getArgumentsId() {
return this.argumentsId ||= this.scope.generateUidIdentifier("arguments");
}
getThisId() {
return this.thisId ||= this.scope.generateUidIdentifier("this");
}
getLeftId() {
return this.leftId ||= this.scope.generateUidIdentifier("left");
}
getFunctionId() {
return this.functionId ||= this.scope.generateUidIdentifier("function");
}
getAgainId() {
return this.againId ||= this.scope.generateUidIdentifier("again");
}
getParams() {
var params = this.params;
if (!params) {
params = this.node.params;
this.paramDecls = [];
for (var i = 0; i < params.length; i++) {
var param = params[i];
if (!param._isDefaultPlaceholder) {
this.paramDecls.push(t.variableDeclarator(
param,
params[i] = this.scope.generateUidIdentifier("x")
));
}
}
}
return this.params = params;
}
hasDeopt() {
// check if the ownerId has been reassigned, if it has then it's not safe to
// perform optimisations
var ownerIdInfo = this.scope.getBindingInfo(this.ownerId.name);
return ownerIdInfo && ownerIdInfo.reassigned;
}
run() {
var scope = this.scope;
var node = this.node;
// only tail recursion can be optimized as for now, so we can skip anonymous
// functions entirely
var ownerId = this.ownerId;
if (!ownerId) return;
// traverse the function and look for tail recursion
scope.traverse(node, firstPass, this);
if (!this.hasTailRecursion) return;
if (this.hasDeopt()) {
this.file.logDeopt(node, messages.get("tailCallReassignmentDeopt"));
return;
}
//
scope.traverse(node, secondPass, this);
if (!this.needsThis || !this.needsArguments) {
scope.traverse(node, thirdPass, this);
}
var body = t.ensureBlock(node).body;
if (this.vars.length > 0) {
var declarations = flatten(map(this.vars, function (decl) {
return decl.declarations;
}, this));
var statement = reduceRight(declarations, function (expr, decl) {
return t.assignmentExpression("=", decl.id, expr);
}, t.identifier("undefined"));
body.unshift(t.expressionStatement(statement));
}
var paramDecls = this.paramDecls;
if (paramDecls.length > 0) {
body.unshift(t.variableDeclaration("var", paramDecls));
}
body.unshift(t.expressionStatement(
t.assignmentExpression("=", this.getAgainId(), t.literal(false)))
);
node.body = util.template("tail-call-body", {
AGAIN_ID: this.getAgainId(),
THIS_ID: this.thisId,
ARGUMENTS_ID: this.argumentsId,
FUNCTION_ID: this.getFunctionId(),
BLOCK: node.body
});
var topVars = [];
if (this.needsThis) {
topVars.push(t.variableDeclarator(this.getThisId(), t.thisExpression()));
}
if (this.needsArguments || this.setsArguments) {
var decl = t.variableDeclarator(this.getArgumentsId());
if (this.needsArguments) {
decl.init = t.identifier("arguments");
}
topVars.push(decl);
}
var leftId = this.leftId;
if (leftId) {
topVars.push(t.variableDeclarator(leftId));
}
if (topVars.length > 0) {
node.body.body.unshift(t.variableDeclaration("var", topVars));
}
}
subTransform(node) {
if (!node) return;
var handler = this["subTransform" + node.type];
if (handler) return handler.call(this, node);
}
subTransformConditionalExpression(node) {
var callConsequent = this.subTransform(node.consequent);
var callAlternate = this.subTransform(node.alternate);
if (!callConsequent && !callAlternate) {
return;
}
// if ternary operator had tail recursion in value, convert to optimized if-statement
node.type = "IfStatement";
node.consequent = callConsequent ? t.toBlock(callConsequent) : returnBlock(node.consequent);
if (callAlternate) {
node.alternate = t.isIfStatement(callAlternate) ? callAlternate : t.toBlock(callAlternate);
} else {
node.alternate = returnBlock(node.alternate);
}
return [node];
}
subTransformLogicalExpression(node) {
// only call in right-value of can be optimized
var callRight = this.subTransform(node.right);
if (!callRight) return;
// cache left value as it might have side-effects
var leftId = this.getLeftId();
var testExpr = t.assignmentExpression(
"=",
leftId,
node.left
);
if (node.operator === "&&") {
testExpr = t.unaryExpression("!", testExpr);
}
return [t.ifStatement(testExpr, returnBlock(leftId))].concat(callRight);
}
subTransformSequenceExpression(node) {
var seq = node.expressions;
// only last element can be optimized
var lastCall = this.subTransform(seq[seq.length - 1]);
if (!lastCall) {
return;
}
// remove converted expression from sequence
// and convert to regular expression if needed
if (--seq.length === 1) {
node = seq[0];
}
return [t.expressionStatement(node)].concat(lastCall);
}
subTransformCallExpression(node) {
var callee = node.callee, thisBinding, args;
if (t.isMemberExpression(callee, { computed: false }) && t.isIdentifier(callee.property)) {
switch (callee.property.name) {
case "call":
args = t.arrayExpression(node.arguments.slice(1));
break;
case "apply":
args = node.arguments[1] || t.identifier("undefined");
break;
default:
return;
}
thisBinding = node.arguments[0];
callee = callee.object;
}
// only tail recursion can be optimized as for now
if (!t.isIdentifier(callee) || !this.scope.bindingIdentifierEquals(callee.name, this.ownerId)) {
return;
}
this.hasTailRecursion = true;
if (this.hasDeopt()) return;
var body = [];
if (!t.isThisExpression(thisBinding)) {
body.push(t.expressionStatement(t.assignmentExpression(
"=",
this.getThisId(),
thisBinding || t.identifier("undefined")
)));
}
if (!args) {
args = t.arrayExpression(node.arguments);
}
var argumentsId = this.getArgumentsId();
var params = this.getParams();
body.push(t.expressionStatement(t.assignmentExpression(
"=",
argumentsId,
args
)));
var i, param;
if (t.isArrayExpression(args)) {
var elems = args.elements;
for (i = 0; i < elems.length && i < params.length; i++) {
param = params[i];
var elem = elems[i] || (elems[i] = t.identifier("undefined"));
if (!param._isDefaultPlaceholder) {
elems[i] = t.assignmentExpression("=", param, elem);
}
}
} else {
this.setsArguments = true;
for (i = 0; i < params.length; i++) {
param = params[i];
if (!param._isDefaultPlaceholder) {
body.push(t.expressionStatement(t.assignmentExpression(
"=",
param,
t.memberExpression(argumentsId, t.literal(i), true)
)));
}
}
}
body.push(t.expressionStatement(
t.assignmentExpression("=", this.getAgainId(), t.literal(true))
));
body.push(t.continueStatement(this.getFunctionId()));
return body;
}
}

View File

@@ -1,5 +1,3 @@
"use strict";
var t = require("../../../types");
var buildBinaryExpression = function (left, right) {

View File

@@ -1,5 +1,3 @@
"use strict";
var rewritePattern = require("regexpu/rewrite-pattern");
var pull = require("lodash/array/pull");
var t = require("../../../types");

View File

@@ -1,5 +1,3 @@
"use strict";
// https://github.com/zenparsing/es-abstract-refs
var util = require("../../../util");

View File

@@ -1,5 +1,3 @@
"use strict";
var buildComprehension = require("../../helpers/build-comprehension");
var traverse = require("../../../traversal");
var util = require("../../../util");

View File

@@ -1,5 +1,3 @@
"use strict";
// https://github.com/rwaldron/exponentiation-operator
exports.experimental = true;
@@ -12,7 +10,7 @@ var MATH_POW = t.memberExpression(t.identifier("Math"), t.identifier("pow"));
build(exports, {
operator: "**",
build: function (left, right) {
build(left, right) {
return t.callExpression(MATH_POW, [left, right]);
}
});

View File

@@ -1,5 +1,3 @@
"use strict";
// https://github.com/sebmarkbage/ecmascript-rest-spread
var t = require("../../../types");

View File

@@ -1,13 +1,14 @@
module.exports = {
useStrict: require("./other/use-strict"),
// this goes at the start so we only transform the original user code
"spec.functionName": require("./spec/function-name"),
"validation.undeclaredVariableCheck": require("./validation/undeclared-variable-check"),
"validation.noForInOfAssignment": require("./validation/no-for-in-of-assignment"),
"validation.setters": require("./validation/setters"),
"validation.react": require("./validation/react"),
// this goes at the start so we only transform the original user code
"spec.functionName": require("./spec/function-name"),
"spec.blockScopedFunctions": require("./spec/block-scoped-functions"),
// needs to be before `_aliasFunction`

View File

@@ -1,9 +1,7 @@
"use strict";
var t = require("../../../types");
var functionChildrenVisitor = {
enter: function (node, parent, scope, state) {
enter(node, parent, scope, state) {
if (t.isFunction(node) && !node._aliasFunction) {
return this.skip();
}
@@ -25,7 +23,7 @@ var functionChildrenVisitor = {
};
var functionVisitor = {
enter: function (node, parent, scope, state) {
enter(node, parent, scope, state) {
if (!node._aliasFunction) {
if (t.isFunction(node)) {
// stop traversal of this node as it'll be hit again by this transformer
@@ -47,11 +45,12 @@ var go = function (getBody, node, scope) {
var thisId;
var state = {
getArgumentsId: function () {
return argumentsId = argumentsId || scope.generateUidIdentifier("arguments");
getArgumentsId() {
return argumentsId ||= scope.generateUidIdentifier("arguments");
},
getThisId: function () {
return thisId = thisId || scope.generateUidIdentifier("this");
getThisId() {
return thisId ||= scope.generateUidIdentifier("this");
}
};
@@ -62,7 +61,7 @@ var go = function (getBody, node, scope) {
var body;
var pushDeclaration = function (id, init) {
body = body || getBody();
body ||= getBody();
body.unshift(t.variableDeclaration("var", [
t.variableDeclarator(id, init)
]));

View File

@@ -1,5 +1,3 @@
"use strict";
var groupBy = require("lodash/collection/groupBy");
var flatten = require("lodash/array/flatten");
var values = require("lodash/object/values");
@@ -13,7 +11,7 @@ var values = require("lodash/object/values");
exports.BlockStatement =
exports.Program = {
exit: function (node) {
exit(node) {
var hasChange = false;
for (var i = 0; i < node.body.length; i++) {
var bodyNode = node.body[i];

View File

@@ -1,5 +1,3 @@
"use strict";
var useStrict = require("../../helpers/use-strict");
var t = require("../../../types");
@@ -22,7 +20,7 @@ exports.Program = function (node, parent, scope, file) {
if (declar.init) {
node.body.unshift(file.attachAuxiliaryComment(t.variableDeclaration(kind, [declarNode])));
} else {
kinds[kind] = kinds[kind] || [];
kinds[kind] ||= [];
kinds[kind].push(declarNode);
}
}

View File

@@ -1,5 +1,3 @@
"use strict";
var useStrict = require("../../helpers/use-strict");
exports.Program = function (program, parent, scope, file) {

View File

@@ -1,5 +1,3 @@
"use strict";
// in this transformer we have to split up classes and function declarations
// from their exports. why? because sometimes we need to replace classes with
// nodes that aren't allowed in the same contexts. also, if you're exporting

View File

@@ -1,5 +1,3 @@
"use strict";
var t = require("../../../types");
exports.Program = function (program, parent, scope, file) {

View File

@@ -17,7 +17,7 @@ exports.ExpressionStatement = function (node) {
};
exports.IfStatement = {
exit: function (node) {
exit(node) {
// todo: in scenarios where we can just return the consequent or
// alternate we should drop the block statement if it contains no
// block scoped variables

View File

@@ -1,5 +1,3 @@
"use strict";
var t = require("../../../types");
var isConsole = t.buildMatchMemberExpression("console", true);

View File

@@ -1,5 +1,3 @@
"use strict";
var remapAsyncToGenerator = require("../../helpers/remap-async-to-generator");
var bluebirdCoroutines = require("./bluebird-coroutines");

View File

@@ -1,5 +1,3 @@
"use strict";
var remapAsyncToGenerator = require("../../helpers/remap-async-to-generator");
var t = require("../../../types");

Some files were not shown because too many files have changed in this diff Show More