aboutsummaryrefslogtreecommitdiff
path: root/node_modules/babylon/lib/index.js
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/babylon/lib/index.js')
-rw-r--r--node_modules/babylon/lib/index.js118
1 files changed, 92 insertions, 26 deletions
diff --git a/node_modules/babylon/lib/index.js b/node_modules/babylon/lib/index.js
index 8df2642bf..29febfed7 100644
--- a/node_modules/babylon/lib/index.js
+++ b/node_modules/babylon/lib/index.js
@@ -2668,7 +2668,7 @@ pp$1.parseExportDeclaration = function () {
pp$1.isExportDefaultSpecifier = function () {
if (this.match(types.name)) {
- return this.state.value !== "type" && this.state.value !== "async" && this.state.value !== "interface";
+ return this.state.value !== "async";
}
if (!this.match(types._default)) {
@@ -2981,6 +2981,8 @@ pp$2.toAssignable = function (node, isBinding, contextDescription) {
case "SpreadProperty":
node.type = "RestProperty";
+ var arg = node.argument;
+ this.toAssignable(arg, isBinding, contextDescription);
break;
case "ArrayExpression":
@@ -4498,7 +4500,8 @@ pp$6.processComment = function (node) {
var stack = this.state.commentStack;
- var lastChild = void 0,
+ var firstChild = void 0,
+ lastChild = void 0,
trailingComments = void 0,
i = void 0,
j = void 0;
@@ -4529,10 +4532,52 @@ pp$6.processComment = function (node) {
}
// Eating the stack.
+ if (stack.length > 0 && last(stack).start >= node.start) {
+ firstChild = stack.pop();
+ }
+
while (stack.length > 0 && last(stack).start >= node.start) {
lastChild = stack.pop();
}
+ if (!lastChild && firstChild) lastChild = firstChild;
+
+ // Attach comments that follow a trailing comma on the last
+ // property in an object literal or a trailing comma in function arguments
+ // as trailing comments
+ if (firstChild && this.state.leadingComments.length > 0) {
+ var lastComment = last(this.state.leadingComments);
+
+ if (firstChild.type === "ObjectProperty") {
+ if (lastComment.start >= node.start) {
+ if (this.state.commentPreviousNode) {
+ for (j = 0; j < this.state.leadingComments.length; j++) {
+ if (this.state.leadingComments[j].end < this.state.commentPreviousNode.end) {
+ this.state.leadingComments.splice(j, 1);
+ j--;
+ }
+ }
+
+ if (this.state.leadingComments.length > 0) {
+ firstChild.trailingComments = this.state.leadingComments;
+ this.state.leadingComments = [];
+ }
+ }
+ }
+ } else if (node.type === "CallExpression" && node.arguments && node.arguments.length) {
+ var lastArg = last(node.arguments);
+
+ if (lastArg && lastComment.start >= lastArg.start && lastComment.end <= node.end) {
+ if (this.state.commentPreviousNode) {
+ if (this.state.leadingComments.length > 0) {
+ lastArg.trailingComments = this.state.leadingComments;
+ this.state.leadingComments = [];
+ }
+ }
+ }
+ }
+ }
+
if (lastChild) {
if (lastChild.leadingComments) {
if (lastChild !== node && last(lastChild.leadingComments).end <= node.start) {
@@ -4751,6 +4796,19 @@ var estreePlugin = function (instance) {
};
});
+ instance.extend("stmtToDirective", function (inner) {
+ return function (stmt) {
+ var directive = inner.call(this, stmt);
+ var value = stmt.expression.value;
+
+ // Reset value to the actual value as in estree mode we want
+ // the stmt to have the real value and not the raw value
+ directive.value.value = value;
+
+ return directive;
+ };
+ });
+
instance.extend("parseBlockBody", function (inner) {
return function (node) {
var _this2 = this;
@@ -4768,16 +4826,14 @@ var estreePlugin = function (instance) {
};
});
- instance.extend("parseClassMethod", function (inner) {
- return function (classBody) {
- for (var _len3 = arguments.length, args = Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {
- args[_key3 - 1] = arguments[_key3];
+ instance.extend("parseClassMethod", function () {
+ return function (classBody, method, isGenerator, isAsync) {
+ this.parseMethod(method, isGenerator, isAsync);
+ if (method.typeParameters) {
+ method.value.typeParameters = method.typeParameters;
+ delete method.typeParameters;
}
-
- inner.call.apply(inner, [this, classBody].concat(args));
-
- var body = classBody.body;
- body[body.length - 1].type = "MethodDefinition";
+ classBody.body.push(this.finishNode(method, "MethodDefinition"));
};
});
@@ -4801,8 +4857,8 @@ var estreePlugin = function (instance) {
return this.estreeParseLiteral(false);
default:
- for (var _len4 = arguments.length, args = Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
- args[_key4] = arguments[_key4];
+ for (var _len3 = arguments.length, args = Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
+ args[_key3] = arguments[_key3];
}
return inner.call.apply(inner, [this].concat(args));
@@ -4812,8 +4868,8 @@ var estreePlugin = function (instance) {
instance.extend("parseLiteral", function (inner) {
return function () {
- for (var _len5 = arguments.length, args = Array(_len5), _key5 = 0; _key5 < _len5; _key5++) {
- args[_key5] = arguments[_key5];
+ for (var _len4 = arguments.length, args = Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
+ args[_key4] = arguments[_key4];
}
var node = inner.call.apply(inner, [this].concat(args));
@@ -4829,8 +4885,8 @@ var estreePlugin = function (instance) {
var funcNode = this.startNode();
funcNode.kind = node.kind; // provide kind, so inner method correctly sets state
- for (var _len6 = arguments.length, args = Array(_len6 > 1 ? _len6 - 1 : 0), _key6 = 1; _key6 < _len6; _key6++) {
- args[_key6 - 1] = arguments[_key6];
+ for (var _len5 = arguments.length, args = Array(_len5 > 1 ? _len5 - 1 : 0), _key5 = 1; _key5 < _len5; _key5++) {
+ args[_key5 - 1] = arguments[_key5];
}
funcNode = inner.call.apply(inner, [this, funcNode].concat(args));
@@ -4843,8 +4899,8 @@ var estreePlugin = function (instance) {
instance.extend("parseObjectMethod", function (inner) {
return function () {
- for (var _len7 = arguments.length, args = Array(_len7), _key7 = 0; _key7 < _len7; _key7++) {
- args[_key7] = arguments[_key7];
+ for (var _len6 = arguments.length, args = Array(_len6), _key6 = 0; _key6 < _len6; _key6++) {
+ args[_key6] = arguments[_key6];
}
var node = inner.call.apply(inner, [this].concat(args));
@@ -4860,8 +4916,8 @@ var estreePlugin = function (instance) {
instance.extend("parseObjectProperty", function (inner) {
return function () {
- for (var _len8 = arguments.length, args = Array(_len8), _key8 = 0; _key8 < _len8; _key8++) {
- args[_key8] = arguments[_key8];
+ for (var _len7 = arguments.length, args = Array(_len7), _key7 = 0; _key7 < _len7; _key7++) {
+ args[_key7] = arguments[_key7];
}
var node = inner.call.apply(inner, [this].concat(args));
@@ -4877,8 +4933,8 @@ var estreePlugin = function (instance) {
instance.extend("toAssignable", function (inner) {
return function (node, isBinding) {
- for (var _len9 = arguments.length, args = Array(_len9 > 2 ? _len9 - 2 : 0), _key9 = 2; _key9 < _len9; _key9++) {
- args[_key9 - 2] = arguments[_key9];
+ for (var _len8 = arguments.length, args = Array(_len8 > 2 ? _len8 - 2 : 0), _key8 = 2; _key8 < _len8; _key8++) {
+ args[_key8 - 2] = arguments[_key8];
}
if (isSimpleProperty(node)) {
@@ -5277,7 +5333,7 @@ pp$8.flowParseObjectTypeMethodish = function (node) {
}
this.expect(types.parenL);
- while (this.match(types.name)) {
+ while (!this.match(types.parenR) && !this.match(types.ellipsis)) {
node.params.push(this.flowParseFunctionTypeParam());
if (!this.match(types.parenR)) {
this.expect(types.comma);
@@ -5482,7 +5538,7 @@ pp$8.flowParseFunctionTypeParam = function () {
};
pp$8.reinterpretTypeAsFunctionTypeParam = function (type) {
- var node = this.startNodeAt(type.start, type.loc);
+ var node = this.startNodeAt(type.start, type.loc.start);
node.name = null;
node.optional = false;
node.typeAnnotation = type;
@@ -5693,7 +5749,7 @@ pp$8.flowParsePrefixType = function () {
pp$8.flowParseAnonFunctionWithoutParens = function () {
var param = this.flowParsePrefixType();
if (!this.state.noAnonFunctionType && this.eat(types.arrow)) {
- var node = this.startNodeAt(param.start, param.loc);
+ var node = this.startNodeAt(param.start, param.loc.start);
node.params = [this.reinterpretTypeAsFunctionTypeParam(param)];
node.rest = null;
node.returnType = this.flowParseType();
@@ -5834,6 +5890,16 @@ var flowPlugin = function (instance) {
};
});
+ instance.extend("isExportDefaultSpecifier", function (inner) {
+ return function () {
+ if (this.match(types.name) && (this.state.value === "type" || this.state.value === "interface")) {
+ return false;
+ }
+
+ return inner.call(this);
+ };
+ });
+
instance.extend("parseConditional", function (inner) {
return function (expr, noIn, startPos, startLoc, refNeedsArrowPos) {
// only do the expensive clone if there is a question mark