Compare commits
41 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a0befe349d | ||
|
|
04992effb3 | ||
|
|
9ae54d2a50 | ||
|
|
fe72a40159 | ||
|
|
ea510d09d0 | ||
|
|
375689a1ff | ||
|
|
9908e331b7 | ||
|
|
cd8655708d | ||
|
|
62b94f297a | ||
|
|
01d399ee3c | ||
|
|
30e3908484 | ||
|
|
ff12046009 | ||
|
|
1a058b4a6e | ||
|
|
02dfd18023 | ||
|
|
9ab7df5f47 | ||
|
|
7a5b140f92 | ||
|
|
6f83111c55 | ||
|
|
f3f60368da | ||
|
|
7a09640b20 | ||
|
|
2916d1262b | ||
|
|
741abb73d2 | ||
|
|
2e46755260 | ||
|
|
2cff9519e1 | ||
|
|
f9c2c6e988 | ||
|
|
5ae3dc01f1 | ||
|
|
af4fd69dd0 | ||
|
|
4d4493f325 | ||
|
|
e70d474b39 | ||
|
|
1b45f64858 | ||
|
|
b89cf6768f | ||
|
|
36ad1108b4 | ||
|
|
4c04371ea4 | ||
|
|
d3e385c554 | ||
|
|
6afcef9805 | ||
|
|
ed861e230b | ||
|
|
e15ced2922 | ||
|
|
93052e532f | ||
|
|
198d51ddaa | ||
|
|
8730b24def | ||
|
|
f09c0d5998 | ||
|
|
21e4481ab7 |
22
CHANGELOG.md
22
CHANGELOG.md
@@ -13,6 +13,28 @@ _Note: Gaps between patch versions are faulty/broken releases._
|
||||
|
||||
See [CHANGELOG - 6to5](CHANGELOG-6to5.md) for the pre-4.0.0 version changelog.
|
||||
|
||||
## 5.4.3
|
||||
|
||||
* **Bug Fix**
|
||||
* Fix `module` being incorrectly rewritten when used as in an export declaration.
|
||||
* When performing single-reference inlining, ensure that the single reference isn't a child of the binding itself.
|
||||
* Fix a bug in `minification.deadCodeElimination` where a new binding instance was being created for local class bindings instead of just inheriting the parent one.
|
||||
* Fix bug with paren printing in `compact` and `retainLines` mode where a left paren was already printed before catching up.
|
||||
* **Internal**
|
||||
* Handle contexts for paths much better. This will ensure that the path node location info is in sync.
|
||||
|
||||
## 5.4.2
|
||||
|
||||
* **Polish**
|
||||
* `ignore` and `only` patterns are now **very** liberal. The pattern can now exist anywhere in the path.
|
||||
|
||||
## 5.4.1
|
||||
|
||||
* **Bug Fix**
|
||||
* Add missing `slash` dependency. Thanks [@browncolyn](https://github.com/browncolyn)!
|
||||
* **Polish**
|
||||
* Clean up `shouldIgnore` algorithm to work how you'd expect rather than being a hacky piece of shit. It now crawls the entire path, checking each section of it against the input ignore/only patterns. This means that the pattern `foo` will ignore the paths `foo/bar.js`, `bar/foo` etc.
|
||||
|
||||
## 5.4.0
|
||||
|
||||
* **New Feature**
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "babel-core",
|
||||
"description": "Turn ES6 code into readable vanilla ES5 with source maps",
|
||||
"version": "5.4.0",
|
||||
"version": "5.4.3",
|
||||
"author": "Sebastian McKenzie <sebmck@gmail.com>",
|
||||
"homepage": "https://babeljs.io/",
|
||||
"license": "MIT",
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
{
|
||||
"name": "babel",
|
||||
"description": "Turn ES6 code into readable vanilla ES5 with source maps",
|
||||
"version": "5.3.3",
|
||||
"version": "5.4.2",
|
||||
"author": "Sebastian McKenzie <sebmck@gmail.com>",
|
||||
"homepage": "https://babeljs.io/",
|
||||
"license": "MIT",
|
||||
"repository": "babel/babel",
|
||||
"preferGlobal": true,
|
||||
"dependencies": {
|
||||
"babel-core": "^5.3.3",
|
||||
"babel-core": "^5.4.2",
|
||||
"chokidar": "^1.0.0",
|
||||
"commander": "^2.6.0",
|
||||
"convert-source-map": "^1.1.0",
|
||||
@@ -17,7 +17,8 @@
|
||||
"lodash": "^3.2.0",
|
||||
"output-file-sync": "^1.1.0",
|
||||
"path-is-absolute": "^1.0.0",
|
||||
"source-map": "^0.4.0"
|
||||
"source-map": "^0.4.0",
|
||||
"slash": "^1.0.0"
|
||||
},
|
||||
"bin": {
|
||||
"babel": "./bin/babel/index.js",
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "babel-runtime",
|
||||
"description": "babel selfContained runtime",
|
||||
"version": "5.3.3",
|
||||
"version": "5.4.2",
|
||||
"license": "MIT",
|
||||
"repository": "babel/babel",
|
||||
"author": "Sebastian McKenzie <sebmck@gmail.com>",
|
||||
|
||||
@@ -53,6 +53,9 @@ var compile = function (filename) {
|
||||
|
||||
var cacheKey = `${filename}:${JSON.stringify(opts)}:${babel.version}`;
|
||||
|
||||
var env = process.env.BABEL_ENV || process.env.NODE_ENV;
|
||||
if (env) cacheKey += `:${env}`;
|
||||
|
||||
if (cache) {
|
||||
var cached = cache[cacheKey];
|
||||
if (cached && cached.mtime === mtime(filename)) {
|
||||
|
||||
@@ -117,8 +117,9 @@ export default class Buffer {
|
||||
|
||||
_removeSpacesAfterLastNewline() {
|
||||
var lastNewlineIndex = this.buf.lastIndexOf("\n");
|
||||
if (lastNewlineIndex === -1)
|
||||
if (lastNewlineIndex === -1) {
|
||||
return;
|
||||
}
|
||||
|
||||
var index = this.buf.length - 1;
|
||||
while (index > lastNewlineIndex) {
|
||||
|
||||
@@ -149,11 +149,12 @@ class CodeGenerator {
|
||||
return print;
|
||||
}
|
||||
|
||||
catchUp(node, parent) {
|
||||
catchUp(node, parent, leftParenPrinted) {
|
||||
// catch up to this nodes newline if we're behind
|
||||
if (node.loc && this.format.retainLines && this.buffer.buf) {
|
||||
var needsParens = false;
|
||||
if (parent && this.position.line < node.loc.start.line && t.isTerminatorless(parent)) {
|
||||
if (!leftParenPrinted && parent &&
|
||||
this.position.line < node.loc.start.line && t.isTerminatorless(parent)) {
|
||||
needsParens = true;
|
||||
this._push("(");
|
||||
}
|
||||
@@ -216,7 +217,7 @@ class CodeGenerator {
|
||||
|
||||
this.printLeadingComments(node, parent);
|
||||
|
||||
var needsParensFromCatchup = this.catchUp(node, parent);
|
||||
var needsParensFromCatchup = this.catchUp(node, parent, needsParens);
|
||||
|
||||
newline(true);
|
||||
|
||||
@@ -330,7 +331,6 @@ class CodeGenerator {
|
||||
|
||||
_printComments(comments) {
|
||||
if (this.format.compact) return;
|
||||
|
||||
if (!this.format.comments) return;
|
||||
if (!comments || !comments.length) return;
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ export const MESSAGES = {
|
||||
missingTemplatesDirectory: "no templates directory - this is most likely the result of a broken `npm publish`. Please report to https://github.com/babel/babel/issues",
|
||||
unsupportedOutputType: "Unsupported output type $1",
|
||||
illegalMethodName: "Illegal method name $1",
|
||||
lostTrackNodePath: "We lost track of this nodes position, likely because the AST was directly manipulated",
|
||||
|
||||
traverseNeedsParent: "Must pass a scope and parentPath unless traversing a Program/File got a $1 node",
|
||||
traverseVerifyRootFunction: "You passed `traverse()` a function when it expected a visitor object, are you sure you didn't mean `{ enter: Function }`?",
|
||||
|
||||
@@ -463,7 +463,7 @@ export default class File {
|
||||
}
|
||||
|
||||
_addAst(ast) {
|
||||
this.path = TraversalPath.get(null, null, ast, ast, "program", this);
|
||||
this.path = TraversalPath.get(null, ast, ast, "program", this).setContext(null, this);
|
||||
this.scope = this.path.scope;
|
||||
this.ast = ast;
|
||||
}
|
||||
|
||||
@@ -6,8 +6,8 @@ import * as util from "../../util";
|
||||
import * as t from "../../types";
|
||||
|
||||
export default class AMDFormatter extends DefaultFormatter {
|
||||
init() {
|
||||
CommonFormatter.prototype._init.call(this, this.hasNonDefaultExports);
|
||||
setup() {
|
||||
CommonFormatter.prototype._setup.call(this, this.hasNonDefaultExports);
|
||||
}
|
||||
|
||||
buildDependencyLiterals() {
|
||||
|
||||
@@ -4,11 +4,11 @@ import * as util from "../../util";
|
||||
import * as t from "../../types";
|
||||
|
||||
export default class CommonJSFormatter extends DefaultFormatter {
|
||||
init() {
|
||||
this._init(this.hasLocalExports);
|
||||
setup() {
|
||||
this._setup(this.hasLocalExports);
|
||||
}
|
||||
|
||||
_init(conditional) {
|
||||
_setup(conditional) {
|
||||
var file = this.file;
|
||||
var scope = file.scope;
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ export function ForOfStatement(node, parent, scope, file) {
|
||||
this.parentPath.replaceWithMultiple(build.node);
|
||||
this.remove();
|
||||
} else {
|
||||
this.replaceWithMultiple(build.node);
|
||||
return build.node;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -85,18 +85,28 @@ export function ExportNamedDeclaration(node, parent, scope) {
|
||||
}
|
||||
}
|
||||
|
||||
export function Program(node) {
|
||||
var imports = [];
|
||||
var rest = [];
|
||||
export var Program = {
|
||||
enter(node) {
|
||||
var imports = [];
|
||||
var rest = [];
|
||||
|
||||
for (var i = 0; i < node.body.length; i++) {
|
||||
var bodyNode = node.body[i];
|
||||
if (t.isImportDeclaration(bodyNode)) {
|
||||
imports.push(bodyNode);
|
||||
} else {
|
||||
rest.push(bodyNode);
|
||||
for (var i = 0; i < node.body.length; i++) {
|
||||
var bodyNode = node.body[i];
|
||||
if (t.isImportDeclaration(bodyNode)) {
|
||||
imports.push(bodyNode);
|
||||
} else {
|
||||
rest.push(bodyNode);
|
||||
}
|
||||
}
|
||||
|
||||
node.body = imports.concat(rest);
|
||||
},
|
||||
|
||||
exit(node, parent, scope, file) {
|
||||
if (!file.transformers["es6.modules"].canTransform()) return;
|
||||
|
||||
if (file.moduleFormatter.setup) {
|
||||
file.moduleFormatter.setup();
|
||||
}
|
||||
}
|
||||
|
||||
node.body = imports.concat(rest);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -33,6 +33,10 @@ export function ReferencedIdentifier(node, parent, scope) {
|
||||
}
|
||||
if (!replacement) return;
|
||||
|
||||
if (this.findParent((node) => replacement)) {
|
||||
return;
|
||||
}
|
||||
|
||||
t.toExpression(replacement);
|
||||
scope.removeBinding(node.name);
|
||||
binding.path.remove();
|
||||
|
||||
@@ -35,7 +35,7 @@ export function JSXElement(node, parent, scope, file) {
|
||||
this.traverse(immutabilityVisitor, state);
|
||||
|
||||
if (state.isImmutable) {
|
||||
return this.hoist();
|
||||
this.hoist();
|
||||
} else {
|
||||
node._hoisted = true;
|
||||
}
|
||||
|
||||
@@ -16,7 +16,9 @@ export default class TraversalContext {
|
||||
}
|
||||
|
||||
create(node, obj, key) {
|
||||
return TraversalPath.get(this.parentPath, this, node, obj, key);
|
||||
var path = TraversalPath.get(this.parentPath, node, obj, key);
|
||||
path.unshiftContext(this);
|
||||
return path;
|
||||
}
|
||||
|
||||
visitMultiple(nodes, node, key) {
|
||||
@@ -37,25 +39,32 @@ export default class TraversalContext {
|
||||
}
|
||||
|
||||
// visit the queue
|
||||
for (let i = 0; i < queue.length; i++) {
|
||||
var path = queue[i];
|
||||
for (let path of (queue: Array)) {
|
||||
path.update();
|
||||
|
||||
if (visited.indexOf(path.node) >= 0) continue;
|
||||
visited.push(path.node);
|
||||
|
||||
path.setContext(this.parentPath, this, path.key);
|
||||
|
||||
if (path.visit()) {
|
||||
stop = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for (let path of (queue: Array)) {
|
||||
path.shiftContext();
|
||||
}
|
||||
|
||||
this.queue = null;
|
||||
|
||||
return stop;
|
||||
}
|
||||
|
||||
visitSingle(node, key) {
|
||||
if (this.shouldVisit(node[key])) {
|
||||
return this.create(node, node, key).visit();
|
||||
var path = this.create(node, node, key);
|
||||
path.visit();
|
||||
path.shiftContext();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -125,6 +125,6 @@ export default class PathHoister {
|
||||
uid = t.jSXExpressionContainer(uid);
|
||||
}
|
||||
|
||||
return uid;
|
||||
this.path.replaceWith(uid);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import PathHoister from "./hoister";
|
||||
import * as virtualTypes from "./virtual-types";
|
||||
import * as messages from "../../messages";
|
||||
import isBoolean from "lodash/lang/isBoolean";
|
||||
import isNumber from "lodash/lang/isNumber";
|
||||
import isRegExp from "lodash/lang/isRegExp";
|
||||
@@ -45,6 +46,7 @@ var hoistVariablesVisitor = explode({
|
||||
export default class TraversalPath {
|
||||
constructor(parent, container) {
|
||||
this.container = container;
|
||||
this.contexts = [];
|
||||
this.parent = parent;
|
||||
this.data = {};
|
||||
}
|
||||
@@ -53,7 +55,7 @@ export default class TraversalPath {
|
||||
* Description
|
||||
*/
|
||||
|
||||
static get(parentPath: TraversalPath, context?: TraversalContext, parent, container, key, file?: File) {
|
||||
static get(parentPath: TraversalPath, parent, container, key) {
|
||||
var targetNode = container[key];
|
||||
var paths = container._paths = container._paths || [];
|
||||
var path;
|
||||
@@ -71,7 +73,7 @@ export default class TraversalPath {
|
||||
paths.push(path);
|
||||
}
|
||||
|
||||
path.setContext(parentPath, context, key, file);
|
||||
path.setup(parentPath, key);
|
||||
|
||||
return path;
|
||||
}
|
||||
@@ -178,8 +180,10 @@ export default class TraversalPath {
|
||||
*/
|
||||
|
||||
queueNode(path) {
|
||||
if (this.context && this.context.queue) {
|
||||
this.context.queue.push(path);
|
||||
for (var context of (this.contexts: Array)) {
|
||||
if (context.queue) {
|
||||
context.queue.push(path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -201,7 +205,7 @@ export default class TraversalPath {
|
||||
this._containerInsertBefore(nodes);
|
||||
} else if (this.isStatementOrBlock()) {
|
||||
if (this.node) nodes.push(this.node);
|
||||
this.container[this.key] = t.blockStatement(nodes);
|
||||
this.node = this.container[this.key] = t.blockStatement(nodes);
|
||||
} else {
|
||||
throw new Error("We don't know what to do with this node type. We were previously a Statement but we can't fit in here?");
|
||||
}
|
||||
@@ -225,7 +229,7 @@ export default class TraversalPath {
|
||||
paths.push(path);
|
||||
this.queueNode(path);
|
||||
} else {
|
||||
paths.push(TraversalPath.get(this, null, node, this.container, to));
|
||||
paths.push(TraversalPath.get(this, node, this.container, to));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -298,7 +302,7 @@ export default class TraversalPath {
|
||||
this._containerInsertAfter(nodes);
|
||||
} else if (this.isStatementOrBlock()) {
|
||||
if (this.node) nodes.unshift(this.node);
|
||||
this.container[this.key] = t.blockStatement(nodes);
|
||||
this.node = this.container[this.key] = t.blockStatement(nodes);
|
||||
} else {
|
||||
throw new Error("We don't know what to do with this node type. We were previously a Statement but we can't fit in here?");
|
||||
}
|
||||
@@ -344,6 +348,8 @@ export default class TraversalPath {
|
||||
*/
|
||||
|
||||
setScope(file?) {
|
||||
if (this.opts && this.opts.noScope) return;
|
||||
|
||||
var target = this.context || this.parentPath;
|
||||
this.scope = TraversalPath.getScope(this, target && target.scope, file);
|
||||
}
|
||||
@@ -352,34 +358,87 @@ export default class TraversalPath {
|
||||
* Description
|
||||
*/
|
||||
|
||||
clearContext() {
|
||||
this.context = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Description
|
||||
*/
|
||||
|
||||
setContext(parentPath, context, key, file?) {
|
||||
setContext(context, file) {
|
||||
this.shouldSkip = false;
|
||||
this.shouldStop = false;
|
||||
this.removed = false;
|
||||
|
||||
this.parentPath = parentPath || this.parentPath;
|
||||
this.key = key;
|
||||
|
||||
if (context) {
|
||||
this.context = context;
|
||||
this.state = context.state;
|
||||
this.opts = context.opts;
|
||||
}
|
||||
|
||||
this.type = this.node && this.node.type;
|
||||
|
||||
var log = file && this.type === "Program";
|
||||
if (log) file.log.debug("Start scope building");
|
||||
this.setScope(file);
|
||||
if (log) file.log.debug("End scope building");
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Description
|
||||
*/
|
||||
|
||||
update() {
|
||||
if (this.node === this.container[this.key]) return;
|
||||
|
||||
// grrr, path key is out of sync. this is likely due to a modification to the AST
|
||||
// not through our path APIs
|
||||
|
||||
if (Array.isArray(this.container)) {
|
||||
for (var i = 0; i < this.container.length; i++) {
|
||||
if (this.container[i] === this.node) {
|
||||
return this.setKey(i);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (var key in this.container) {
|
||||
if (this.container[key] === this.node) {
|
||||
return this.setKey(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
throw new Error(messages.get("lostTrackNodePath"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Description
|
||||
*/
|
||||
|
||||
shiftContext() {
|
||||
this.contexts.shift();
|
||||
this.setContext(this.contexts[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Description
|
||||
*/
|
||||
|
||||
unshiftContext(context) {
|
||||
this.contexts.unshift(context);
|
||||
this.setContext(context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Description
|
||||
*/
|
||||
|
||||
setup(parentPath, key) {
|
||||
this.parentPath = parentPath || this.parentPath;
|
||||
this.setKey(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Description
|
||||
*/
|
||||
|
||||
setKey(key) {
|
||||
this.key = key;
|
||||
this.node = this.container[this.key];
|
||||
this.type = this.node && this.node.type;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -470,6 +529,7 @@ export default class TraversalPath {
|
||||
} else {
|
||||
this.container[this.key] = null;
|
||||
}
|
||||
this.node = null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -500,18 +560,6 @@ export default class TraversalPath {
|
||||
return err;
|
||||
}
|
||||
|
||||
get node() {
|
||||
if (this.removed) {
|
||||
return null;
|
||||
} else {
|
||||
return this.container[this.key];
|
||||
}
|
||||
}
|
||||
|
||||
set node(replacement) {
|
||||
throw new Error("Don't use `path.node = newNode;`, use `path.replaceWith(newNode)` or `path.replaceWithMultiple([newNode])`");
|
||||
}
|
||||
|
||||
/**
|
||||
* Description
|
||||
*/
|
||||
@@ -564,7 +612,7 @@ export default class TraversalPath {
|
||||
// doesn't matter, our nodes will be inserted anyway
|
||||
|
||||
var container = this.node[containerKey];
|
||||
var path = TraversalPath.get(this, null, this.node, container, 0);
|
||||
var path = TraversalPath.get(this, this.node, container, 0);
|
||||
|
||||
return path.insertBefore(nodes);
|
||||
}
|
||||
@@ -581,7 +629,7 @@ export default class TraversalPath {
|
||||
|
||||
var container = this.node[containerKey];
|
||||
var i = container.length;
|
||||
var path = TraversalPath.get(this, null, this.node, container, i);
|
||||
var path = TraversalPath.get(this, this.node, container, i);
|
||||
|
||||
return path.replaceWith(nodes, true);
|
||||
}
|
||||
@@ -593,7 +641,7 @@ export default class TraversalPath {
|
||||
replaceWithMultiple(nodes: Array<Object>) {
|
||||
nodes = this._verifyNodeList(nodes);
|
||||
t.inheritsComments(nodes[0], this.node);
|
||||
this.container[this.key] = null;
|
||||
this.node = this.container[this.key] = null;
|
||||
this.insertAfter(nodes);
|
||||
if (!this.node) this.remove();
|
||||
}
|
||||
@@ -673,7 +721,7 @@ export default class TraversalPath {
|
||||
if (oldNode) t.inheritsComments(replacement, oldNode);
|
||||
|
||||
// replace the node
|
||||
this.container[this.key] = replacement;
|
||||
this.node = this.container[this.key] = replacement;
|
||||
this.type = replacement.type;
|
||||
|
||||
// potentially create new scope
|
||||
@@ -777,9 +825,10 @@ export default class TraversalPath {
|
||||
var node = this.node;
|
||||
if (!node) return;
|
||||
|
||||
var previousType = this.type;
|
||||
|
||||
// call the function with the params (node, parent, scope, state)
|
||||
var replacement = fn.call(this, node, this.parent, this.scope, this.state);
|
||||
var previousType = this.type;
|
||||
|
||||
if (replacement) {
|
||||
this.replaceWith(replacement, true);
|
||||
@@ -787,7 +836,7 @@ export default class TraversalPath {
|
||||
|
||||
if (this.shouldStop || this.shouldSkip || this.removed) return;
|
||||
|
||||
if (replacement && previousType !== this.type) {
|
||||
if (previousType !== this.type) {
|
||||
this.queueNode(this);
|
||||
return;
|
||||
}
|
||||
@@ -841,7 +890,7 @@ export default class TraversalPath {
|
||||
*/
|
||||
|
||||
getSibling(key) {
|
||||
return TraversalPath.get(this.parentPath, null, this.parent, this.container, key, this.file);
|
||||
return TraversalPath.get(this.parentPath, this.parent, this.container, key, this.file);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -868,10 +917,10 @@ export default class TraversalPath {
|
||||
if (Array.isArray(container)) {
|
||||
// requested a container so give them all the paths
|
||||
return container.map((_, i) => {
|
||||
return TraversalPath.get(this, null, node, container, i);
|
||||
return TraversalPath.get(this, node, container, i).setContext();
|
||||
});
|
||||
} else {
|
||||
return TraversalPath.get(this, null, node, node, key);
|
||||
return TraversalPath.get(this, node, node, key).setContext();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1105,6 +1154,7 @@ export default class TraversalPath {
|
||||
*/
|
||||
|
||||
traverse(visitor, state) {
|
||||
if (!this.scope) console.log(this.contexts);
|
||||
traverse(this.node, visitor, this.scope, state, this);
|
||||
}
|
||||
|
||||
|
||||
@@ -553,7 +553,7 @@ export default class Scope {
|
||||
isPure(node) {
|
||||
if (t.isIdentifier(node)) {
|
||||
var bindingInfo = this.getBinding(node.name);
|
||||
return bindingInfo.constant;
|
||||
return bindingInfo && bindingInfo.constant;
|
||||
} else {
|
||||
return t.isPure(node);
|
||||
}
|
||||
@@ -599,8 +599,13 @@ export default class Scope {
|
||||
|
||||
// Class
|
||||
|
||||
if (path.isClass() && path.has("id")) {
|
||||
this.registerBinding("var", path.get("id"));
|
||||
if (path.isClassDeclaration()) {
|
||||
var name = path.node.id.name;
|
||||
this.bindings[name] = this.parent.bindings[name];
|
||||
}
|
||||
|
||||
if (path.isClassExpression() && path.has("id")) {
|
||||
this.registerBinding("var", path);
|
||||
}
|
||||
|
||||
// Function - params, rest
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import "./patch";
|
||||
|
||||
import escapeRegExp from "lodash/string/escapeRegExp";
|
||||
|
||||
import startsWith from "lodash/string/startsWith";
|
||||
import cloneDeep from "lodash/lang/cloneDeep";
|
||||
import isBoolean from "lodash/lang/isBoolean";
|
||||
import * as messages from "./messages";
|
||||
@@ -69,9 +69,23 @@ export function list(val: string): Array<string> {
|
||||
|
||||
export function regexify(val: any): RegExp {
|
||||
if (!val) return new RegExp(/.^/);
|
||||
|
||||
if (Array.isArray(val)) val = new RegExp(val.map(escapeRegExp).join("|"), "i");
|
||||
if (isString(val)) return minimatch.makeRe(val, { nocase: true });
|
||||
|
||||
if (isString(val)) {
|
||||
// normalise path separators
|
||||
val = slash(val);
|
||||
|
||||
// remove starting wildcards or relative separator if present
|
||||
if (startsWith(val, "./") || startsWith(val, "*/")) val = val.slice(2);
|
||||
if (startsWith(val, "**/")) val = val.slice(3);
|
||||
|
||||
var regex = minimatch.makeRe(val, { nocase: true });
|
||||
return new RegExp(regex.source.slice(1, -1), "i");
|
||||
}
|
||||
|
||||
if (isRegExp(val)) return val;
|
||||
|
||||
throw new TypeError("illegal type for regexify");
|
||||
}
|
||||
|
||||
@@ -96,6 +110,7 @@ export function booleanify(val: any): boolean {
|
||||
|
||||
export function shouldIgnore(filename, ignore, only) {
|
||||
filename = slash(filename);
|
||||
|
||||
if (only.length) {
|
||||
for (var pattern of (only: Array)) {
|
||||
if (pattern.test(filename)) return false;
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
function foo(l) {
|
||||
return (
|
||||
// hi
|
||||
l
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
function foo(l){
|
||||
return (
|
||||
|
||||
l);}
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"retainLines": true,
|
||||
"compact": true
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
export function module() {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.module = _module;
|
||||
|
||||
function _module() {}
|
||||
@@ -0,0 +1,4 @@
|
||||
class A {
|
||||
constructor() { this.value = 12345; }
|
||||
}
|
||||
export default new A();
|
||||
@@ -0,0 +1,3 @@
|
||||
import aInstance from './imported';
|
||||
|
||||
assert.equal(aInstance.value, 12345);
|
||||
@@ -0,0 +1,14 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
|
||||
var A = function A() {
|
||||
babelHelpers.classCallCheck(this, A);
|
||||
this.value = 12345;
|
||||
};
|
||||
|
||||
exports["default"] = new A();
|
||||
module.exports = exports["default"];
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
class A {
|
||||
constructor() { this.value = 12345; }
|
||||
}
|
||||
export default new A();
|
||||
@@ -0,0 +1,5 @@
|
||||
class A {
|
||||
f() { return 1235; }
|
||||
}
|
||||
|
||||
let a = new A();
|
||||
@@ -0,0 +1,5 @@
|
||||
class A {
|
||||
k() { return 12345; }
|
||||
}
|
||||
|
||||
assert.equal((new A()).k(), 12345);
|
||||
@@ -0,0 +1,17 @@
|
||||
"use strict";
|
||||
|
||||
var A = (function () {
|
||||
function A() {
|
||||
babelHelpers.classCallCheck(this, A);
|
||||
}
|
||||
|
||||
babelHelpers.createClass(A, [{
|
||||
key: "f",
|
||||
value: function f() {
|
||||
return 1235;
|
||||
}
|
||||
}]);
|
||||
return A;
|
||||
})();
|
||||
|
||||
var a = new A();
|
||||
@@ -0,0 +1 @@
|
||||
import x from 'y';
|
||||
@@ -0,0 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
var _y = require('y');
|
||||
|
||||
var _y2 = babelHelpers.interopRequireDefault(_y);
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
import x from 'y';
|
||||
|
||||
x.foo = function (err) {};
|
||||
@@ -0,0 +1,5 @@
|
||||
import x from 'y';
|
||||
|
||||
x.z = function (a) { return 1 + a; };
|
||||
|
||||
assert(x.z(x.value), 43);
|
||||
@@ -0,0 +1,8 @@
|
||||
'use strict';
|
||||
|
||||
var _y = require('y');
|
||||
|
||||
var _y2 = babelHelpers.interopRequireDefault(_y);
|
||||
|
||||
_y2['default'].foo = function (err) {};
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
let y = { value: 42 };
|
||||
export default y;
|
||||
@@ -0,0 +1,5 @@
|
||||
function f(a) {
|
||||
return !a;
|
||||
}
|
||||
|
||||
export { f };
|
||||
@@ -0,0 +1,11 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
function f(a) {
|
||||
return !a;
|
||||
}
|
||||
|
||||
exports.f = f;
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
function* x() {
|
||||
for (let a of []) {
|
||||
for (let b of a) {
|
||||
yield 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function y() {
|
||||
return [...x()];
|
||||
}
|
||||
|
||||
export { y };
|
||||
@@ -0,0 +1,42 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
function* x() {
|
||||
var _arr = [];
|
||||
|
||||
for (var _i = 0; _i < _arr.length; _i++) {
|
||||
var a = _arr[_i];var _iteratorNormalCompletion = true;
|
||||
var _didIteratorError = false;
|
||||
var _iteratorError = undefined;
|
||||
|
||||
try {
|
||||
for (var _iterator = a[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
||||
var b = _step.value;
|
||||
|
||||
yield 1;
|
||||
}
|
||||
} catch (err) {
|
||||
_didIteratorError = true;
|
||||
_iteratorError = err;
|
||||
} finally {
|
||||
try {
|
||||
if (!_iteratorNormalCompletion && _iterator["return"]) {
|
||||
_iterator["return"]();
|
||||
}
|
||||
} finally {
|
||||
if (_didIteratorError) {
|
||||
throw _iteratorError;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function y() {
|
||||
return [].concat(babelHelpers.toConsumableArray(x()));
|
||||
}
|
||||
|
||||
exports.y = y;
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
class X {
|
||||
Y() {
|
||||
return new X();
|
||||
}
|
||||
}
|
||||
|
||||
export { X };
|
||||
@@ -0,0 +1,22 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
|
||||
var X = (function () {
|
||||
function X() {
|
||||
babelHelpers.classCallCheck(this, X);
|
||||
}
|
||||
|
||||
babelHelpers.createClass(X, [{
|
||||
key: "Y",
|
||||
value: function Y() {
|
||||
return new X();
|
||||
}
|
||||
}]);
|
||||
return X;
|
||||
})();
|
||||
|
||||
exports.X = X;
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"externalHelpers": true,
|
||||
"noCheckAst": true,
|
||||
"blacklist": ["regenerator"],
|
||||
"optional": ["minification.deadCodeElimination"]
|
||||
}
|
||||
@@ -52,6 +52,22 @@ suite("traverse", function () {
|
||||
|
||||
var body = ast.body;
|
||||
|
||||
test("traverse replace", function () {
|
||||
var replacement = {
|
||||
type: "Literal",
|
||||
value: "foo"
|
||||
};
|
||||
var ast2 = _.cloneDeep(ast);
|
||||
|
||||
traverse(ast2, {
|
||||
enter: function (node) {
|
||||
if (node.type === "ThisExpression") return replacement;
|
||||
}
|
||||
});
|
||||
|
||||
assert.equal(ast2.body[1].expression.left.object, replacement);
|
||||
});
|
||||
|
||||
test("traverse", function () {
|
||||
var expect = [
|
||||
body[0], body[0].declarations[0], body[0].declarations[0].id, body[0].declarations[0].init,
|
||||
@@ -95,22 +111,6 @@ suite("traverse", function () {
|
||||
assert.deepEqual(actual, expect);
|
||||
});
|
||||
|
||||
test("traverse replace", function () {
|
||||
var replacement = {
|
||||
type: "Literal",
|
||||
value: "foo"
|
||||
};
|
||||
var ast2 = _.cloneDeep(ast);
|
||||
|
||||
traverse(ast2, {
|
||||
enter: function (node) {
|
||||
if (node.type === "ThisExpression") return replacement;
|
||||
}
|
||||
});
|
||||
|
||||
assert.equal(ast2.body[1].expression.left.object, replacement);
|
||||
});
|
||||
|
||||
test("hasType", function () {
|
||||
assert.ok(traverse.hasType(ast, null, "ThisExpression"));
|
||||
assert.ok(!traverse.hasType(ast, null, "ThisExpression", ["AssignmentExpression"]));
|
||||
|
||||
@@ -80,9 +80,16 @@ suite("util", function () {
|
||||
assert.deepEqual(util.regexify(null), /.^/);
|
||||
assert.deepEqual(util.regexify(""), /.^/);
|
||||
assert.deepEqual(util.regexify(["foo", "bar"]), /foo|bar/i);
|
||||
assert.deepEqual(util.regexify("foobar"), /^(?:(?=.)foobar)$/i);
|
||||
assert.deepEqual(util.regexify("foobar"), /(?:(?=.)foobar)/i);
|
||||
assert.deepEqual(util.regexify(/foobar/), /foobar/);
|
||||
|
||||
assert.ok(util.regexify("foo/bar").test("bar/foo/bar"));
|
||||
assert.ok(util.regexify("foo/*").test("foo/bar.js"));
|
||||
assert.ok(util.regexify("*.js").test("bar.js"));
|
||||
assert.ok(util.regexify("./foo").test("foo"));
|
||||
assert.ok(util.regexify("./foo/bar.js").test("foo/bar.js"));
|
||||
assert.ok(util.regexify("foobar").test("foobar"));
|
||||
|
||||
assert.throws(function () {
|
||||
util.regexify({});
|
||||
}, /illegal type for regexify/);
|
||||
|
||||
Reference in New Issue
Block a user