Socket
Socket
Sign inDemoInstall

recast

Package Overview
Dependencies
Maintainers
2
Versions
266
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

recast - npm Package Compare versions

Comparing version 0.19.1 to 0.20.0

.eslintrc.js

33

lib/comments.js

@@ -34,8 +34,8 @@ "use strict";

if (resultArray) {
if (n.Node.check(node) &&
n.SourceLocation.check(node.loc)) {
if (n.Node.check(node) && n.SourceLocation.check(node.loc)) {
// This reverse insertion sort almost always takes constant
// time because we almost always (maybe always?) append the
// nodes in order anyway.
for (var i = resultArray.length - 1; i >= 0; --i) {
var i = resultArray.length - 1;
for (; i >= 0; --i) {
if (util_1.comparePos(resultArray[i].loc.end, node.loc.start) <= 0) {

@@ -65,3 +65,3 @@ break;

value: resultArray = [],
enumerable: false
enumerable: false,
});

@@ -80,3 +80,3 @@ }

// Time to dust off the old binary search robes and wizard hat.
var left = 0, right = childNodes.length;
var left = 0, right = childNodes.length, precedingNode, followingNode;
while (left < right) {

@@ -88,3 +88,3 @@ var middle = (left + right) >> 1;

// The comment is completely contained by this child node.
decorateComment(comment.enclosingNode = child, comment, lines);
decorateComment((comment.enclosingNode = child), comment, lines);
return; // Abandon the binary search at this level.

@@ -97,3 +97,3 @@ }

// node we have encountered so far.
var precedingNode = child;
precedingNode = child;
left = middle + 1;

@@ -107,3 +107,3 @@ continue;

// have encountered so far.
var followingNode = child;
followingNode = child;
right = middle;

@@ -174,3 +174,2 @@ continue;

exports.attach = attach;
;
function breakTies(tiesToBreak, lines) {

@@ -188,4 +187,6 @@ var tieCount = tiesToBreak.length;

// whitespace-only gaps (or other comments).
for (var indexOfFirstLeadingComment = tieCount; indexOfFirstLeadingComment > 0; --indexOfFirstLeadingComment) {
var comment = tiesToBreak[indexOfFirstLeadingComment - 1];
var indexOfFirstLeadingComment = tieCount;
var comment;
for (; indexOfFirstLeadingComment > 0; --indexOfFirstLeadingComment) {
comment = tiesToBreak[indexOfFirstLeadingComment - 1];
assert_1.default.strictEqual(comment.precedingNode, pn);

@@ -292,4 +293,3 @@ assert_1.default.strictEqual(comment.followingNode, fn);

var innerLines = print(path);
var comments = n.Node.check(value) &&
types.getFieldValue(value, "comments");
var comments = n.Node.check(value) && types.getFieldValue(value, "comments");
if (!comments || comments.length === 0) {

@@ -304,5 +304,5 @@ return innerLines;

var trailing = types.getFieldValue(comment, "trailing");
if (leading || (trailing && !(n.Statement.check(value) ||
comment.type === "Block" ||
comment.type === "CommentBlock"))) {
if (leading ||
(trailing &&
!(n.Statement.check(value) || comment.type === "Block" || comment.type === "CommentBlock"))) {
leadingParts.push(printLeadingComment(commentPath, print));

@@ -318,2 +318,1 @@ }

exports.printComments = printComments;
;

@@ -15,6 +15,24 @@ "use strict";

var types = __importStar(require("ast-types"));
var util = __importStar(require("./util"));
var n = types.namedTypes;
var isArray = types.builtInTypes.array;
var isNumber = types.builtInTypes.number;
var util = __importStar(require("./util"));
var PRECEDENCE = {};
[
["||"],
["&&"],
["|"],
["^"],
["&"],
["==", "===", "!=", "!=="],
["<", ">", "<=", ">=", "in", "instanceof"],
[">>", "<<", ">>>"],
["+", "-"],
["*", "/", "%"],
["**"],
].forEach(function (tier, i) {
tier.forEach(function (op) {
PRECEDENCE[op] = i;
});
});
var FastPath = function FastPath(value) {

@@ -36,3 +54,3 @@ assert_1.default.ok(this instanceof FastPath);

var stack = [obj.value];
for (var pp; (pp = obj.parentPath); obj = pp)
for (var pp = void 0; (pp = obj.parentPath); obj = pp)
stack.push(obj.name, pp.value);

@@ -204,5 +222,3 @@ copy.stack = stack.reverse();

// the parsing ambiguity that made it appear to need parentheses.
var justNeedsOpeningParen = !this.canBeFirstInStatement() &&
this.firstInStatement() &&
!this.needsParens(true);
var justNeedsOpeningParen = !this.canBeFirstInStatement() && this.firstInStatement() && !this.needsParens(true);
if (justNeedsOpeningParen) {

@@ -253,3 +269,3 @@ return true;

// correctness even when it's the topmost expression.
if (node.type === "AssignmentExpression" && node.left.type === 'ObjectPattern') {
if (node.type === "AssignmentExpression" && node.left.type === "ObjectPattern") {
return true;

@@ -276,3 +292,4 @@ }

}
if (parent.type === "ParenthesizedExpression") {
if (parent.type === "ParenthesizedExpression" ||
(node.extra && node.extra.parenthesized)) {
return false;

@@ -284,5 +301,3 @@ }

case "SpreadProperty":
return parent.type === "MemberExpression"
&& name === "object"
&& parent.object === node;
return parent.type === "MemberExpression" && name === "object" && parent.object === node;
case "BinaryExpression":

@@ -292,4 +307,3 @@ case "LogicalExpression":

case "CallExpression":
return name === "callee"
&& parent.callee === node;
return name === "callee" && parent.callee === node;
case "UnaryExpression":

@@ -300,6 +314,5 @@ case "SpreadElement":

case "MemberExpression":
return name === "object"
&& parent.object === node;
return name === "object" && parent.object === node;
case "BinaryExpression":
case "LogicalExpression":
case "LogicalExpression": {
var po = parent.operator;

@@ -316,5 +329,8 @@ var pp = PRECEDENCE[po];

}
break;
}
default:
return false;
}
break;
case "SequenceExpression":

@@ -336,18 +352,2 @@ switch (parent.type) {

}
case "YieldExpression":
switch (parent.type) {
case "BinaryExpression":
case "LogicalExpression":
case "UnaryExpression":
case "SpreadElement":
case "SpreadProperty":
case "CallExpression":
case "MemberExpression":
case "NewExpression":
case "ConditionalExpression":
case "YieldExpression":
return true;
default:
return false;
}
case "IntersectionTypeAnnotation":

@@ -357,11 +357,11 @@ case "UnionTypeAnnotation":

case "Literal":
return parent.type === "MemberExpression"
&& isNumber.check(node.value)
&& name === "object"
&& parent.object === node;
return (parent.type === "MemberExpression" &&
isNumber.check(node.value) &&
name === "object" &&
parent.object === node);
// Babel 6 Literal split
case "NumericLiteral":
return parent.type === "MemberExpression"
&& name === "object"
&& parent.object === node;
return parent.type === "MemberExpression" && name === "object" && parent.object === node;
case "YieldExpression":
case "AwaitExpression":
case "AssignmentExpression":

@@ -378,10 +378,7 @@ case "ConditionalExpression":

case "NewExpression":
return name === "callee"
&& parent.callee === node;
return name === "callee" && parent.callee === node;
case "ConditionalExpression":
return name === "test"
&& parent.test === node;
return name === "test" && parent.test === node;
case "MemberExpression":
return name === "object"
&& parent.object === node;
return name === "object" && parent.object === node;
default:

@@ -392,20 +389,30 @@ return false;

if (n.CallExpression.check(parent) &&
name === 'callee') {
name === "callee" &&
parent.callee === node) {
return true;
}
if (n.MemberExpression.check(parent) &&
name === 'object') {
name === "object" &&
parent.object === node) {
return true;
}
if (n.TSAsExpression &&
n.TSAsExpression.check(parent) &&
name === "expression" &&
parent.expression === node) {
return true;
}
return isBinary(parent);
case "ObjectExpression":
if (parent.type === "ArrowFunctionExpression" &&
name === "body") {
name === "body" &&
parent.body === node) {
return true;
}
break;
case 'TSAsExpression':
if (parent.type === 'ArrowFunctionExpression' &&
name === 'body' &&
node.expression.type === 'ObjectExpression') {
case "TSAsExpression":
if (parent.type === "ArrowFunctionExpression" &&
name === "body" &&
parent.body === node &&
node.expression.type === "ObjectExpression") {
return true;

@@ -434,30 +441,12 @@ }

function isBinary(node) {
return n.BinaryExpression.check(node)
|| n.LogicalExpression.check(node);
return n.BinaryExpression.check(node) || n.LogicalExpression.check(node);
}
// @ts-ignore 'isUnaryLike' is declared but its value is never read. [6133]
function isUnaryLike(node) {
return n.UnaryExpression.check(node)
return (n.UnaryExpression.check(node) ||
// I considered making SpreadElement and SpreadProperty subtypes of
// UnaryExpression, but they're not really Expression nodes.
|| (n.SpreadElement && n.SpreadElement.check(node))
|| (n.SpreadProperty && n.SpreadProperty.check(node));
(n.SpreadElement && n.SpreadElement.check(node)) ||
(n.SpreadProperty && n.SpreadProperty.check(node)));
}
var PRECEDENCE = {};
[["||"],
["&&"],
["|"],
["^"],
["&"],
["==", "===", "!=", "!=="],
["<", ">", "<=", ">=", "in", "instanceof"],
[">>", "<<", ">>>"],
["+", "-"],
["*", "/", "%"],
["**"]
].forEach(function (tier, i) {
tier.forEach(function (op) {
PRECEDENCE[op] = i;
});
});
function containsCallExpression(node) {

@@ -502,52 +491,39 @@ if (n.CallExpression.check(node)) {

}
if (n.BlockStatement.check(parent) &&
parentName === "body" &&
childName === 0) {
if (n.BlockStatement.check(parent) && parentName === "body" && childName === 0) {
assert_1.default.strictEqual(parent.body[0], child);
return true;
}
if (n.ExpressionStatement.check(parent) &&
childName === "expression") {
if (n.ExpressionStatement.check(parent) && childName === "expression") {
assert_1.default.strictEqual(parent.expression, child);
return true;
}
if (n.AssignmentExpression.check(parent) &&
childName === "left") {
if (n.AssignmentExpression.check(parent) && childName === "left") {
assert_1.default.strictEqual(parent.left, child);
return true;
}
if (n.ArrowFunctionExpression.check(parent) &&
childName === "body") {
if (n.ArrowFunctionExpression.check(parent) && childName === "body") {
assert_1.default.strictEqual(parent.body, child);
return true;
}
if (n.SequenceExpression.check(parent) &&
parentName === "expressions" &&
childName === 0) {
if (n.SequenceExpression.check(parent) && parentName === "expressions" && childName === 0) {
assert_1.default.strictEqual(parent.expressions[0], child);
continue;
}
if (n.CallExpression.check(parent) &&
childName === "callee") {
if (n.CallExpression.check(parent) && childName === "callee") {
assert_1.default.strictEqual(parent.callee, child);
continue;
}
if (n.MemberExpression.check(parent) &&
childName === "object") {
if (n.MemberExpression.check(parent) && childName === "object") {
assert_1.default.strictEqual(parent.object, child);
continue;
}
if (n.ConditionalExpression.check(parent) &&
childName === "test") {
if (n.ConditionalExpression.check(parent) && childName === "test") {
assert_1.default.strictEqual(parent.test, child);
continue;
}
if (isBinary(parent) &&
childName === "left") {
if (isBinary(parent) && childName === "left") {
assert_1.default.strictEqual(parent.left, child);
continue;
}
if (n.UnaryExpression.check(parent) &&
!parent.prefix &&
childName === "argument") {
if (n.UnaryExpression.check(parent) && !parent.prefix && childName === "argument") {
assert_1.default.strictEqual(parent.argument, child);

@@ -554,0 +530,0 @@ continue;

@@ -79,6 +79,4 @@ "use strict";

source: sourceName,
original: { line: sourceCursor.line,
column: sourceCursor.column },
generated: { line: targetCursor.line,
column: targetCursor.column }
original: { line: sourceCursor.line, column: sourceCursor.column },
generated: { line: targetCursor.line, column: targetCursor.column },
});

@@ -104,4 +102,3 @@ if (!hasOwn.call(sourcesToContents, sourceName)) {

return "";
if (column === string.length &&
line < strings.length)
if (column === string.length && line < strings.length)
return "\n";

@@ -123,4 +120,3 @@ if (column >= string.length)

c += info.sliceStart - indent;
if (c === info.sliceEnd &&
line < this.length)
if (c === info.sliceEnd && line < this.length)
return "\n";

@@ -224,4 +220,3 @@ if (c >= info.sliceEnd)

for (var tabWidth = 1; tabWidth < counts.length; tabWidth += 1) {
if (hasOwn.call(counts, tabWidth) &&
counts[tabWidth] > maxCount) {
if (hasOwn.call(counts, tabWidth) && counts[tabWidth] > maxCount) {
maxCount = counts[tabWidth];

@@ -231,3 +226,3 @@ result = tabWidth;

}
return this.cachedTabWidth = result;
return (this.cachedTabWidth = result);
};

@@ -242,5 +237,3 @@ // Determine if the list of lines has a first line that starts with a //

var firstLineInfo = this.infos[0], sliceStart = firstLineInfo.sliceStart, sliceEnd = firstLineInfo.sliceEnd, firstLine = firstLineInfo.line.slice(sliceStart, sliceEnd).trim();
return firstLine.length === 0 ||
firstLine.slice(0, 2) === "//" ||
firstLine.slice(0, 2) === "/*";
return (firstLine.length === 0 || firstLine.slice(0, 2) === "//" || firstLine.slice(0, 2) === "/*");
};

@@ -273,5 +266,3 @@ Lines.prototype.isOnlyWhitespace = function () {

pos.column += 1;
return skipSpaces
? !!this.skipSpaces(pos, false, true)
: true;
return skipSpaces ? !!this.skipSpaces(pos, false, true) : true;
}

@@ -281,5 +272,3 @@ if (l < this.length) {

pos.column = 0;
return skipSpaces
? !!this.skipSpaces(pos, false, true)
: true;
return skipSpaces ? !!this.skipSpaces(pos, false, true) : true;
}

@@ -302,5 +291,3 @@ return false;

pos.column = c;
return skipSpaces
? !!this.skipSpaces(pos, true, true)
: true;
return skipSpaces ? !!this.skipSpaces(pos, true, true) : true;
};

@@ -314,3 +301,3 @@ Lines.prototype.firstPos = function () {

line: this.length,
column: this.getLineLength(this.length)
column: this.getLineLength(this.length),
};

@@ -322,6 +309,8 @@ };

if (pos) {
pos = modifyInPlace ? pos : {
line: pos.line,
column: pos.column
};
pos = modifyInPlace
? pos
: {
line: pos.line,
column: pos.column,
};
}

@@ -336,4 +325,3 @@ else if (backward) {

while (this.prevPos(pos)) {
if (!isOnlyWhitespace(this.charAt(pos)) &&
this.nextPos(pos)) {
if (!isOnlyWhitespace(this.charAt(pos)) && this.nextPos(pos)) {
return pos;

@@ -377,4 +365,3 @@ }

if (startPos) {
pos.line = startPos.line,
pos.column = startPos.column;
(pos.line = startPos.line), (pos.column = startPos.column);
}

@@ -389,3 +376,5 @@ if (skipSpaces && !this.skipSpaces(pos, false, true)) {

Lines.prototype.bootstrapSlice = function (start, end) {
var strings = this.toString().split(lineTerminatorSeqExp).slice(start.line - 1, end.line);
var strings = this.toString()
.split(lineTerminatorSeqExp)
.slice(start.line - 1, end.line);
if (strings.length > 0) {

@@ -439,5 +428,4 @@ strings.push(strings.pop().slice(0, end.column));

if (end === void 0) { end = this.lastPos(); }
options = options_1.normalize(options);
var _a = options_1.normalize(options), tabWidth = _a.tabWidth, useTabs = _a.useTabs, reuseWhitespace = _a.reuseWhitespace, lineTerminator = _a.lineTerminator;
var parts = [];
var _a = options.tabWidth, tabWidth = _a === void 0 ? 2 : _a;
for (var line = start.line; line <= end.line; ++line) {

@@ -458,5 +446,3 @@ var info = this.infos[line - 1];

var before_1 = info.line.slice(0, info.sliceStart);
if (options.reuseWhitespace &&
isOnlyWhitespace(before_1) &&
countSpaces(before_1, options.tabWidth) === indent) {
if (reuseWhitespace && isOnlyWhitespace(before_1) && countSpaces(before_1, tabWidth) === indent) {
// Reuse original spaces if the indentation is correct.

@@ -468,3 +454,3 @@ parts.push(info.line.slice(0, info.sliceEnd));

var spaces = indent;
if (options.useTabs) {
if (useTabs) {
tabs = Math.floor(indent / tabWidth);

@@ -483,3 +469,3 @@ spaces -= tabs * tabWidth;

}
return parts.join(options.lineTerminator);
return parts.join(lineTerminator);
};

@@ -502,5 +488,7 @@ Lines.prototype.isEmpty = function () {

var prevLine_1 = infos.length;
var prevColumn_1 = Math.max(prevInfo.indent, 0) +
prevInfo.sliceEnd - prevInfo.sliceStart;
prevInfo.line = prevInfo.line.slice(0, prevInfo.sliceEnd) + indent + info.line.slice(info.sliceStart, info.sliceEnd);
var prevColumn_1 = Math.max(prevInfo.indent, 0) + prevInfo.sliceEnd - prevInfo.sliceStart;
prevInfo.line =
prevInfo.line.slice(0, prevInfo.sliceEnd) +
indent +
info.line.slice(info.sliceStart, info.sliceEnd);
// If any part of a line is indentation-locked, the whole line

@@ -531,3 +519,4 @@ // will be indentation-locked.

}
elements.map(function (elem) {
elements
.map(function (elem) {
var lines = fromString(elem);

@@ -537,3 +526,4 @@ if (lines.isEmpty())

return lines;
}).forEach(function (linesOrNull, i) {
})
.forEach(function (linesOrNull, i) {
if (separator.isEmpty()) {

@@ -573,3 +563,4 @@ appendLines(linesOrNull);

switch (spaces.charCodeAt(i)) {
case 9: // '\t'
case 9: {
// '\t'
assert_1.default.strictEqual(typeof tabWidth, "number");

@@ -585,2 +576,3 @@ assert_1.default.ok(tabWidth > 0);

break;
}
case 11: // '\v'

@@ -593,3 +585,4 @@ case 12: // '\f'

case 32: // ' '
default: // Treat all other whitespace like ' '.
default:
// Treat all other whitespace like ' '.
count += 1;

@@ -614,3 +607,3 @@ break;

var tabless = string.indexOf("\t") < 0;
var cacheable = !options && tabless && (string.length <= maxCacheKeyLen);
var cacheable = !options && tabless && string.length <= maxCacheKeyLen;
assert_1.default.ok(tabWidth || tabless, "No tab width specified but encountered tabs in string\n" + string);

@@ -628,3 +621,3 @@ if (cacheable && hasOwn.call(fromStringCache, string))

sliceStart: spaces.length,
sliceEnd: line.length
sliceEnd: line.length,
};

@@ -671,5 +664,3 @@ }), options_1.normalize(options).sourceFileName);

assert_1.default.strictEqual(lineLength, indent + sliceEnd - sliceStart);
if (info.indent === indent &&
info.sliceStart === sliceStart &&
info.sliceEnd === sliceEnd) {
if (info.indent === indent && info.sliceStart === sliceStart && info.sliceEnd === sliceEnd) {
return info;

@@ -683,3 +674,3 @@ }

sliceStart: sliceStart,
sliceEnd: sliceEnd
sliceEnd: sliceEnd,
};

@@ -691,5 +682,4 @@ }

exports.concat = concat;
;
// The emptyLines object needs to be created all the way down here so that
// Lines.prototype will be fully populated.
var emptyLines = fromString("");

@@ -36,3 +36,3 @@ "use strict";

start: subtractPos(targetLoc.start, start.line, start.column),
end: subtractPos(targetLoc.end, start.line, start.column)
end: subtractPos(targetLoc.end, start.line, start.column),
};

@@ -48,7 +48,7 @@ // The sourceLoc can stay the same because the contents of the

start: sourceLoc.start,
end: skip("end")
end: skip("end"),
};
targetLoc = {
start: subtractPos(targetLoc.start, start.line, start.column),
end: subtractPos(end, start.line, start.column)
end: subtractPos(end, start.line, start.column),
};

@@ -64,3 +64,3 @@ }

start: skip("start"),
end: sourceLoc.end
end: sourceLoc.end,
};

@@ -70,3 +70,3 @@ targetLoc = {

start: { line: 1, column: 0 },
end: subtractPos(targetLoc.end, start.line, start.column)
end: subtractPos(targetLoc.end, start.line, start.column),
};

@@ -77,3 +77,3 @@ }

start: skip("start"),
end: skip("end")
end: skip("end"),
};

@@ -83,3 +83,3 @@ targetLoc = {

start: { line: 1, column: 0 },
end: subtractPos(end, start.line, start.column)
end: subtractPos(end, start.line, start.column),
};

@@ -93,3 +93,3 @@ }

start: addPos(this.targetLoc.start, line, column),
end: addPos(this.targetLoc.end, line, column)
end: addPos(this.targetLoc.end, line, column),
});

@@ -100,3 +100,3 @@ };

start: subtractPos(this.targetLoc.start, line, column),
end: subtractPos(this.targetLoc.end, line, column)
end: subtractPos(this.targetLoc.end, line, column),
});

@@ -118,3 +118,3 @@ };

start: targetLoc.start,
end: targetLoc.end
end: targetLoc.end,
};

@@ -125,5 +125,3 @@ if (!skipFirstLine || startLine > 1) {

line: startLine,
column: noNegativeColumns
? Math.max(0, startColumn)
: startColumn
column: noNegativeColumns ? Math.max(0, startColumn) : startColumn,
};

@@ -135,5 +133,3 @@ }

line: endLine,
column: noNegativeColumns
? Math.max(0, endColumn)
: endColumn
column: noNegativeColumns ? Math.max(0, endColumn) : endColumn,
};

@@ -149,5 +145,3 @@ }

line: toPos.line + line - 1,
column: (toPos.line === 1)
? toPos.column + column
: toPos.column
column: toPos.line === 1 ? toPos.column + column : toPos.column,
};

@@ -158,5 +152,3 @@ }

line: fromPos.line - line + 1,
column: (fromPos.line === line)
? fromPos.column - column
: fromPos.column
column: fromPos.line === line ? fromPos.column - column : fromPos.column,
};

@@ -170,6 +162,7 @@ }

}
var sourceCursor, targetCursor;
if (targetComparison < 0) {
// Skipping forward.
var sourceCursor = sourceLines.skipSpaces(sourceFromPos) || sourceLines.lastPos();
var targetCursor = targetLines.skipSpaces(targetFromPos) || targetLines.lastPos();
sourceCursor = sourceLines.skipSpaces(sourceFromPos) || sourceLines.lastPos();
targetCursor = targetLines.skipSpaces(targetFromPos) || targetLines.lastPos();
var lineDiff = targetToPos.line - targetCursor.line;

@@ -187,4 +180,3 @@ sourceCursor.line += lineDiff;

}
while (util_1.comparePos(targetCursor, targetToPos) < 0 &&
targetLines.nextPos(targetCursor, true)) {
while (util_1.comparePos(targetCursor, targetToPos) < 0 && targetLines.nextPos(targetCursor, true)) {
assert_1.default.ok(sourceLines.nextPos(sourceCursor, true));

@@ -196,4 +188,4 @@ assert_1.default.strictEqual(sourceLines.charAt(sourceCursor), targetLines.charAt(targetCursor));

// Skipping backward.
var sourceCursor = sourceLines.skipSpaces(sourceFromPos, true) || sourceLines.firstPos();
var targetCursor = targetLines.skipSpaces(targetFromPos, true) || targetLines.firstPos();
sourceCursor = sourceLines.skipSpaces(sourceFromPos, true) || sourceLines.firstPos();
targetCursor = targetLines.skipSpaces(targetFromPos, true) || targetLines.firstPos();
var lineDiff = targetToPos.line - targetCursor.line;

@@ -211,4 +203,3 @@ sourceCursor.line += lineDiff;

}
while (util_1.comparePos(targetToPos, targetCursor) < 0 &&
targetLines.prevPos(targetCursor, true)) {
while (util_1.comparePos(targetToPos, targetCursor) < 0 && targetLines.prevPos(targetCursor, true)) {
assert_1.default.ok(sourceLines.prevPos(sourceCursor, true));

@@ -215,0 +206,0 @@ assert_1.default.strictEqual(sourceLines.charAt(sourceCursor), targetLines.charAt(targetCursor));

@@ -91,3 +91,3 @@ import { Omit } from "ast-types/types";

*/
quote?: 'single' | 'double' | 'auto' | null;
quote?: "single" | "double" | "auto" | null;
/**

@@ -94,0 +94,0 @@ * Controls the printing of trailing commas in object literals, array

@@ -22,3 +22,3 @@ "use strict";

flowObjectCommas: true,
tokens: true
tokens: true,
};

@@ -30,5 +30,3 @@ var hasOwn = defaults.hasOwnProperty;

function get(key) {
return hasOwn.call(options, key)
? options[key]
: defaults[key];
return hasOwn.call(options, key) ? options[key] : defaults[key];
}

@@ -54,6 +52,5 @@ return {

flowObjectCommas: get("flowObjectCommas"),
tokens: !!get("tokens")
tokens: !!get("tokens"),
};
}
exports.normalize = normalize;
;

@@ -28,3 +28,3 @@ "use strict";

reuseWhitespace: false,
useTabs: false
useTabs: false,
});

@@ -41,3 +41,3 @@ var comments = [];

ecmaVersion: 6,
sourceType: util.getOption(options, "sourceType", "module")
sourceType: util.getOption(options, "sourceType", "module"),
});

@@ -51,3 +51,3 @@ // Use ast.tokens if possible, and otherwise fall back to the Esprima

: require("esprima").tokenize(sourceWithoutTabs, {
loc: true
loc: true,
});

@@ -74,3 +74,3 @@ // We will reattach the tokens array to the file object below.

start: lines.firstPos(),
end: lines.lastPos()
end: lines.lastPos(),
};

@@ -93,3 +93,3 @@ }

lines: lines,
indent: 0
indent: 0,
};

@@ -114,3 +114,3 @@ }

body: [],
comments: comments
comments: comments,
}, lines);

@@ -127,3 +127,2 @@ program.loc.start = trueProgramLoc.start;

exports.parse = parse;
;
var TreeCopier = function TreeCopier(lines, tokens) {

@@ -136,3 +135,3 @@ assert_1.default.ok(this instanceof TreeCopier);

this.indent = 0;
this.seen = new Map;
this.seen = new Map();
};

@@ -145,8 +144,8 @@ var TCp = TreeCopier.prototype;

if (isArray.check(node)) {
var copy = new Array(node.length);
this.seen.set(node, copy);
var copy_1 = new Array(node.length);
this.seen.set(node, copy_1);
node.forEach(function (item, i) {
copy[i] = this.copy(item);
copy_1[i] = this.copy(item);
}, this);
return copy;
return copy_1;
}

@@ -159,7 +158,8 @@ if (!isObject.check(node)) {

original: {
// Provide a link from the copy to the original.
value: node,
configurable: false,
enumerable: false,
writable: true
}
writable: true,
},
});

@@ -178,4 +178,6 @@ this.seen.set(node, copy);

// but it doesn't hurt for Line comments.
if (node.type === "Block" || node.type === "Line" ||
node.type === "CommentBlock" || node.type === "CommentLine" ||
if (node.type === "Block" ||
node.type === "Line" ||
node.type === "CommentBlock" ||
node.type === "CommentLine" ||
this.lines.isPrecededOnlyByWhitespace(loc.start)) {

@@ -201,4 +203,3 @@ newIndent = this.indent = loc.start.column;

}
else if (key === "tokens" &&
node.type === "File") {
else if (key === "tokens" && node.type === "File") {
// Preserve file.tokens (uncopied) in case client code cares about

@@ -205,0 +206,0 @@ // it, even though Recast ignores it when reprinting.

@@ -36,3 +36,3 @@ "use strict";

start: loc.start,
end: loc.end
end: loc.end,
});

@@ -44,4 +44,3 @@ };

start: { line: 1, column: 0 },
end: { line: lines.length,
column: lines.getLineLength(lines.length) }
end: { line: lines.length, column: lines.getLineLength(lines.length) },
};

@@ -53,3 +52,5 @@ var sliceFrom = loc.start, toConcat = [];

}
replacements.sort(function (a, b) { return util_1.comparePos(a.start, b.start); }).forEach(function (rep) {
replacements
.sort(function (a, b) { return util_1.comparePos(a.start, b.start); })
.forEach(function (rep) {
if (util_1.comparePos(sliceFrom, rep.start) > 0) {

@@ -72,4 +73,3 @@ // Ignore nested replacement ranges.

var patcher = this;
if (!newNode.comments &&
!oldNode.comments) {
if (!newNode.comments && !oldNode.comments) {
// We were (vacuously) able to reprint all the comments!

@@ -103,4 +103,3 @@ return true;

var result = [];
if (node.comments &&
node.comments.length > 0) {
if (node.comments && node.comments.length > 0) {
node.comments.forEach(function (comment) {

@@ -125,3 +124,3 @@ if (comment.leading || comment.trailing) {

start: comment.loc.start,
end: node.loc.lines.skipSpaces(comment.loc.end, false, false)
end: node.loc.lines.skipSpaces(comment.loc.end, false, false),
}, "");

@@ -134,3 +133,3 @@ }

start: node.loc.lines.skipSpaces(comment.loc.start, true, false),
end: comment.loc.end
end: comment.loc.end,
}, "");

@@ -174,4 +173,3 @@ }

// decide if reprint.newPath needs parentheses, as usual.
avoidRootParens: (oldNode.type === newNode.type &&
reprint.oldPath.hasParens())
avoidRootParens: oldNode.type === newNode.type && reprint.oldPath.hasParens(),
}).indentTail(oldNode.loc.indent);

@@ -204,3 +202,2 @@ var nls = needsLeadingSpace(lines, oldNode.loc, newLines);

exports.getReprinter = getReprinter;
;
// If the last character before oldLoc and the first character of newLines

@@ -212,10 +209,9 @@ // are both identifier characters, they must be separated by a space,

// The character just before the location occupied by oldNode.
var charBeforeOldLoc = oldLines.prevPos(posBeforeOldLoc) &&
oldLines.charAt(posBeforeOldLoc);
var charBeforeOldLoc = oldLines.prevPos(posBeforeOldLoc) && oldLines.charAt(posBeforeOldLoc);
// First character of the reprinted node.
var newFirstChar = newLines.charAt(newLines.firstPos());
return charBeforeOldLoc &&
return (charBeforeOldLoc &&
riskyAdjoiningCharExp.test(charBeforeOldLoc) &&
newFirstChar &&
riskyAdjoiningCharExp.test(newFirstChar);
riskyAdjoiningCharExp.test(newFirstChar));
}

@@ -230,8 +226,7 @@ // If the last character of newLines and the first character after oldLoc

// Last character of the reprinted node.
var newLastChar = newLines.prevPos(newLastPos) &&
newLines.charAt(newLastPos);
return newLastChar &&
var newLastChar = newLines.prevPos(newLastPos) && newLines.charAt(newLastPos);
return (newLastChar &&
riskyAdjoiningCharExp.test(newLastChar) &&
charAfterOldLoc &&
riskyAdjoiningCharExp.test(charAfterOldLoc);
riskyAdjoiningCharExp.test(charAfterOldLoc));
}

@@ -270,5 +265,3 @@ function findReprints(newPath, reprints) {

var oldNode = oldPath.getValue();
if (newNode === oldNode ||
newPath.valueIsDuplicate() ||
oldPath.valueIsDuplicate()) {
if (newNode === oldNode || newPath.valueIsDuplicate() || oldPath.valueIsDuplicate()) {
return true;

@@ -278,4 +271,3 @@ }

var len = newNode.length;
if (!(isArray.check(oldNode) &&
oldNode.length === len))
if (!(isArray.check(oldNode) && oldNode.length === len))
return false;

@@ -304,5 +296,3 @@ for (var i = 0; i < len; ++i) {

return false;
if (newNode === oldNode ||
newPath.valueIsDuplicate() ||
oldPath.valueIsDuplicate()) {
if (newNode === oldNode || newPath.valueIsDuplicate() || oldPath.valueIsDuplicate()) {
return true;

@@ -316,4 +306,6 @@ }

var oldParentNode = oldPath.getParentNode();
if (oldParentNode !== null && oldParentNode.type === 'FunctionTypeAnnotation'
&& newParentNode !== null && newParentNode.type === 'FunctionTypeAnnotation') {
if (oldParentNode !== null &&
oldParentNode.type === "FunctionTypeAnnotation" &&
newParentNode !== null &&
newParentNode.type === "FunctionTypeAnnotation") {
var oldNeedsParens = oldParentNode.params.length !== 1 || !!oldParentNode.params[0].name;

@@ -337,3 +329,3 @@ var newNeedParens = newParentNode.params.length !== 1 || !!newParentNode.params[0].name;

oldPath: oldPath.copy(),
newPath: newPath.copy()
newPath: newPath.copy(),
});

@@ -356,3 +348,3 @@ }

oldPath: oldPath.copy(),
newPath: newPath.copy()
newPath: newPath.copy(),
});

@@ -380,9 +372,7 @@ return true;

// let it be printed generically.
if (newPath.needsParens() &&
!oldPath.hasParens()) {
if (newPath.needsParens() && !oldPath.hasParens()) {
return false;
}
var keys = util_1.getUnionOfKeys(oldNode, newNode);
if (oldNode.type === "File" ||
newNode.type === "File") {
if (oldNode.type === "File" || newNode.type === "File") {
// Don't bother traversing file.tokens, an often very large array

@@ -413,4 +403,3 @@ // returned by Babylon, and useless for our purposes.

// changed within them.
if (ReturnStatement.check(newPath.getNode()) &&
reprints.length > originalReprintCount) {
if (ReturnStatement.check(newPath.getNode()) && reprints.length > originalReprintCount) {
return false;

@@ -417,0 +406,0 @@ }

@@ -45,3 +45,3 @@ "use strict";

function comparePos(pos1, pos2) {
return (pos1.line - pos2.line) || (pos1.column - pos2.column);
return pos1.line - pos2.line || pos1.column - pos2.column;
}

@@ -52,3 +52,3 @@ exports.comparePos = comparePos;

line: pos.line,
column: pos.column
column: pos.column,
};

@@ -70,3 +70,3 @@ }

file: latterMap.file,
sourceRoot: latterMap.sourceRoot
sourceRoot: latterMap.sourceRoot,
});

@@ -77,3 +77,3 @@ var sourcesToContents = {};

line: mapping.originalLine,
column: mapping.originalColumn
column: mapping.originalColumn,
});

@@ -89,5 +89,5 @@ var sourceName = origPos.source;

line: mapping.generatedLine,
column: mapping.generatedColumn
column: mapping.generatedColumn,
},
name: mapping.name
name: mapping.name,
});

@@ -103,3 +103,2 @@ var sourceContent = smcFormer.sourceContentFor(sourceName);

exports.composeSourceMaps = composeSourceMaps;
;
function getTrueLoc(node, lines) {

@@ -115,3 +114,3 @@ // It's possible that node is newly-created (not parsed by Esprima),

start: node.loc.start,
end: node.loc.end
end: node.loc.end,
};

@@ -124,5 +123,3 @@ function include(node) {

// positions of the export declaration node.
if (node.declaration &&
node.declaration.decorators &&
isExportDeclaration(node)) {
if (node.declaration && node.declaration.decorators && isExportDeclaration(node)) {
node.declaration.decorators.forEach(include);

@@ -149,3 +146,2 @@ }

exports.getTrueLoc = getTrueLoc;
;
function expandLoc(parentLoc, childLoc) {

@@ -215,12 +211,11 @@ if (parentLoc && childLoc) {

else if (node.type === "ObjectTypeProperty") {
var loc = node.loc;
var end = loc && loc.end;
var loc_1 = node.loc;
var end = loc_1 && loc_1.end;
if (end) {
end = copyPos(end);
if (lines.prevPos(end) &&
lines.charAt(end) === ",") {
if (lines.prevPos(end) && lines.charAt(end) === ",") {
// Some parsers accidentally include trailing commas in the
// .loc.end information for ObjectTypeProperty nodes.
if ((end = lines.skipSpaces(end, true, true))) {
loc.end = end;
loc_1.end = end;
}

@@ -232,3 +227,2 @@ }

exports.fixFaultyLocations = fixFaultyLocations;
;
function fixForLoopHead(node, lines) {

@@ -331,7 +325,5 @@ if (node.type !== "ForStatement") {

exports.isExportDeclaration = isExportDeclaration;
;
function getParentExportDeclaration(path) {
var parentNode = path.getParentNode();
if (path.getName() === "declaration" &&
isExportDeclaration(parentNode)) {
if (path.getName() === "declaration" && isExportDeclaration(parentNode)) {
return parentNode;

@@ -342,3 +334,2 @@ }

exports.getParentExportDeclaration = getParentExportDeclaration;
;
function isTrailingCommaEnabled(options, context) {

@@ -352,2 +343,1 @@ var trailingComma = options.trailingComma;

exports.isTrailingCommaEnabled = isTrailingCommaEnabled;
;
{
"author": "Ben Newman <bn@cs.stanford.edu>",
"name": "recast",
"version": "0.19.1",
"version": "0.20.0",
"description": "JavaScript syntax tree transformer, nondestructive pretty-printer, and automatic source map generator",

@@ -27,4 +27,6 @@ "keywords": [

"debug": "test/run.sh --inspect-brk",
"test": "npm run build && npm run mocha",
"test": "npm run lint && npm run build && npm run mocha",
"build": "npm run clean && tsc",
"lint": "eslint --ext .ts .",
"format": "prettier --write '{lib,test}/**.ts' '*rc.js'",
"clean": "ts-emit-clean",

@@ -34,2 +36,8 @@ "prepack": "npm run build",

},
"lint-staged": {
"*.ts": [
"eslint",
"prettier -c"
]
},
"browser": {

@@ -52,6 +60,10 @@ "fs": false

"@types/node": "13.1.1",
"@typescript-eslint/parser": "^3.0.1",
"eslint": "^7.1.0",
"esprima-fb": "15001.1001.0-dev-harmony-fb",
"flow-parser": "0.119.1",
"glob": "7.1.5",
"lint-staged": "^10.2.6",
"mocha": "6.2.2",
"prettier": "^2.0.5",
"reify": "0.20.12",

@@ -58,0 +70,0 @@ "ts-emit-clean": "1.0.0",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc