1.1.0
This fixes a regression from 0.22 around member expressions breaking and fixes no-semi placement around leading comments, plus some other minor fixes.master
parent
17051ece2c
commit
ad637d0744
20
CHANGELOG.md
20
CHANGELOG.md
|
@ -1,3 +1,23 @@
|
|||
# 1.1.0
|
||||
|
||||
[link](https://github.com/jlongster/prettier/compare/1.0.0...1.1.0)
|
||||
|
||||
* Prettier 1.0 is the stabler release we've been waiting for (#1242)
|
||||
* fix small typo (#1255)
|
||||
* Fix : ReferenceError: err is not defined (#1254)
|
||||
* Document debugging strategies (#1253)
|
||||
* Do not inline member expressions as part of assignments (#1256)
|
||||
* Fix flow union params (#1251)
|
||||
* Use a whitelist instead of blacklist for member breaking (#1261)
|
||||
* Remove trailing whitespace (#1259)
|
||||
* Get rid of fixFaultyLocations code (#1252)
|
||||
* Fixing n.comments check in printer (#1239)
|
||||
* [WIP] no-semi comments (#1257)
|
||||
|
||||
# 1.0.1
|
||||
|
||||
* change semi default
|
||||
|
||||
# 1.0.0
|
||||
|
||||
[link](https://github.com/jlongster/prettier/compare/0.22.0...1.0.0)
|
||||
|
|
|
@ -8728,60 +8728,6 @@ var docBuilders$1 = {
|
|||
align: align$1
|
||||
};
|
||||
|
||||
var types$3 = main;
|
||||
var n$1 = types$3.namedTypes;
|
||||
|
||||
function comparePos$1(pos1, pos2) {
|
||||
return pos1.line - pos2.line || pos1.column - pos2.column;
|
||||
}
|
||||
|
||||
function expandLoc(parentNode, childNode) {
|
||||
if (locStart$1(childNode) - locStart$1(parentNode) < 0) {
|
||||
setLocStart(parentNode, locStart$1(childNode));
|
||||
}
|
||||
|
||||
if (locEnd$1(parentNode) - locEnd$1(childNode) < 0) {
|
||||
setLocEnd(parentNode, locEnd$1(childNode));
|
||||
}
|
||||
}
|
||||
|
||||
function fixFaultyLocations(node, text) {
|
||||
if (node.decorators) {
|
||||
// Expand the loc of the node responsible for printing the decorators
|
||||
// (here, the decorated node) so that it includes node.decorators.
|
||||
node.decorators.forEach(function(decorator) {
|
||||
expandLoc(node, decorator);
|
||||
});
|
||||
} else if (node.declaration && isExportDeclaration(node)) {
|
||||
// Expand the loc of the node responsible for printing the decorators
|
||||
// (here, the export declaration) so that it includes node.decorators.
|
||||
var decorators = node.declaration.decorators;
|
||||
if (decorators) {
|
||||
decorators.forEach(function(decorator) {
|
||||
expandLoc(node, decorator);
|
||||
});
|
||||
}
|
||||
} else if (
|
||||
(n$1.MethodDefinition && n$1.MethodDefinition.check(node)) ||
|
||||
(n$1.Property.check(node) && (node.method || node.shorthand))
|
||||
) {
|
||||
if (n$1.FunctionExpression.check(node.value)) {
|
||||
// FunctionExpression method values should be anonymous,
|
||||
// because their .id fields are ignored anyway.
|
||||
node.value.id = null;
|
||||
}
|
||||
} else if (node.type === "ObjectTypeProperty") {
|
||||
var end = skipSpaces(text, locEnd$1(node), true);
|
||||
if (end !== false && text.charAt(end) === ",") {
|
||||
// Some parsers accidentally include trailing commas in the
|
||||
// end information for ObjectTypeProperty nodes.
|
||||
if ((end = skipSpaces(text, end - 1, true)) !== false) {
|
||||
setLocEnd(node, end);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function isExportDeclaration(node) {
|
||||
if (node)
|
||||
switch (node.type) {
|
||||
|
@ -9050,9 +8996,7 @@ function getPrecedence(op) {
|
|||
}
|
||||
|
||||
var util$2 = {
|
||||
comparePos: comparePos$1,
|
||||
getPrecedence,
|
||||
fixFaultyLocations,
|
||||
isExportDeclaration,
|
||||
getParentExportDeclaration,
|
||||
getPenultimate,
|
||||
|
@ -9101,10 +9045,6 @@ function getSortedChildNodes(node, text, resultArray) {
|
|||
return;
|
||||
}
|
||||
|
||||
// The loc checks below are sensitive to some of the problems that
|
||||
// are fixed by this utility function.
|
||||
util.fixFaultyLocations(node, text);
|
||||
|
||||
if (resultArray) {
|
||||
if (n.Node.check(node) && node.type !== "EmptyStatement") {
|
||||
// This reverse insertion sort almost always takes constant
|
||||
|
@ -9968,7 +9908,7 @@ function printDanglingComments(path, options, sameIndent) {
|
|||
return indent(concat([hardline, join(hardline, parts)]));
|
||||
}
|
||||
|
||||
function printComments(path, print, options) {
|
||||
function printComments(path, print, options, needsSemi) {
|
||||
var value = path.getValue();
|
||||
var parent = path.getParentNode();
|
||||
var printed = print(path);
|
||||
|
@ -9979,7 +9919,7 @@ function printComments(path, print, options) {
|
|||
}
|
||||
|
||||
var leadingParts = [];
|
||||
var trailingParts = [printed];
|
||||
var trailingParts = [needsSemi ? ";" : "", printed];
|
||||
|
||||
path.each(function(commentPath) {
|
||||
var comment = commentPath.getValue();
|
||||
|
@ -10006,7 +9946,7 @@ function printComments(path, print, options) {
|
|||
var comments$1 = { attach, printComments, printDanglingComments };
|
||||
|
||||
var name = "prettier";
|
||||
var version$2 = "1.0.0";
|
||||
var version$2 = "1.1.0";
|
||||
var description = "Prettier is an opinionated JavaScript formatter";
|
||||
var bin = {"prettier":"./bin/prettier.js"};
|
||||
var repository = "prettier/prettier";
|
||||
|
@ -10840,6 +10780,7 @@ function genericPrintNoParens(path, options, print, args) {
|
|||
return concat$2(["(", path.call(print, "expression"), ")"]);
|
||||
case "AssignmentExpression":
|
||||
return printAssignment(
|
||||
n.left,
|
||||
path.call(print, "left"),
|
||||
n.operator,
|
||||
n.right,
|
||||
|
@ -10887,7 +10828,22 @@ function genericPrintNoParens(path, options, print, args) {
|
|||
]);
|
||||
case "MemberExpression": {
|
||||
const parent = path.getParentNode();
|
||||
let firstNonMemberParent;
|
||||
let i = 0;
|
||||
do {
|
||||
firstNonMemberParent = path.getParentNode(i);
|
||||
i++;
|
||||
} while (
|
||||
firstNonMemberParent &&
|
||||
firstNonMemberParent.type === "MemberExpression"
|
||||
);
|
||||
|
||||
const shouldInline =
|
||||
firstNonMemberParent && (
|
||||
(firstNonMemberParent.type === "VariableDeclarator" &&
|
||||
firstNonMemberParent.id.type !== "Identifier") ||
|
||||
(firstNonMemberParent.type === "AssignmentExpression" &&
|
||||
firstNonMemberParent.left.type !== "Identifier")) ||
|
||||
n.computed ||
|
||||
(n.object.type === "Identifier" &&
|
||||
n.property.type === "Identifier" &&
|
||||
|
@ -11619,6 +11575,7 @@ function genericPrintNoParens(path, options, print, args) {
|
|||
return group$1(concat$2(parts));
|
||||
case "VariableDeclarator":
|
||||
return printAssignment(
|
||||
n.id,
|
||||
path.call(print, "id"),
|
||||
"=",
|
||||
n.init,
|
||||
|
@ -11989,7 +11946,7 @@ function genericPrintNoParens(path, options, print, args) {
|
|||
case "JSXText":
|
||||
throw new Error("JSXTest should be handled by JSXElement");
|
||||
case "JSXEmptyExpression":
|
||||
const requiresHardline = n.comments.some(
|
||||
const requiresHardline = n.comments && n.comments.some(
|
||||
comment => comment.type === "Line" || comment.type === "CommentLine"
|
||||
);
|
||||
|
||||
|
@ -12644,10 +12601,20 @@ function printStatementSequence(path, options, print) {
|
|||
|
||||
// in no-semi mode, prepend statement with semicolon if it might break ASI
|
||||
if (!options.semi && !isClass && stmtNeedsASIProtection(stmtPath)) {
|
||||
parts.push(";");
|
||||
if (
|
||||
stmt.comments &&
|
||||
stmt.comments.some(comment => comment.leading)
|
||||
) {
|
||||
// Note: stmtNeedsASIProtection requires stmtPath to already be printed
|
||||
// as it reads needsParens which is mutated on the instance
|
||||
parts.push(print(stmtPath, { needsSemi: true }));
|
||||
} else {
|
||||
parts.push(";", stmtPrinted);
|
||||
}
|
||||
} else {
|
||||
parts.push(stmtPrinted);
|
||||
}
|
||||
|
||||
parts.push(stmtPrinted);
|
||||
|
||||
if (!options.semi && isClass) {
|
||||
if (classPropMayCauseASIProblems(stmtPath)) {
|
||||
|
@ -12940,12 +12907,32 @@ function printFunctionParams(path, print, options, expandArg) {
|
|||
}
|
||||
|
||||
const parent = path.getParentNode();
|
||||
|
||||
const flowTypeAnnotations = [
|
||||
"AnyTypeAnnotation",
|
||||
"NullLiteralTypeAnnotation",
|
||||
"NullableTypeAnnotation",
|
||||
"GenericTypeAnnotation",
|
||||
"ThisTypeAnnotation",
|
||||
"NumberTypeAnnotation",
|
||||
"VoidTypeAnnotation",
|
||||
"NullTypeAnnotation",
|
||||
"EmptyTypeAnnotation",
|
||||
"MixedTypeAnnotation",
|
||||
"BooleanTypeAnnotation",
|
||||
"BooleanLiteralTypeAnnotation",
|
||||
"StringLiteralTypeAnnotation",
|
||||
"StringTypeAnnotation"
|
||||
];
|
||||
|
||||
const isFlowShorthandWithOneArg =
|
||||
(isObjectTypePropertyAFunction(parent) ||
|
||||
isTypeAnnotationAFunction(parent) ||
|
||||
parent.type === "TypeAlias") &&
|
||||
fun[paramsField].length === 1 &&
|
||||
fun[paramsField][0].name === null &&
|
||||
fun[paramsField][0].typeAnnotation &&
|
||||
flowTypeAnnotations.indexOf(fun[paramsField][0].typeAnnotation.type) !== -1 &&
|
||||
!fun.rest;
|
||||
|
||||
return concat$2([
|
||||
|
@ -13808,6 +13795,7 @@ function printBinaryishExpressions(path, print, options, isNested) {
|
|||
}
|
||||
|
||||
function printAssignment(
|
||||
leftNode,
|
||||
printedLeft,
|
||||
operator,
|
||||
rightNode,
|
||||
|
@ -13823,9 +13811,10 @@ function printAssignment(
|
|||
printed = indent$2(concat$2([hardline$2, printedRight]));
|
||||
} else if (
|
||||
(isBinaryish(rightNode) && !shouldInlineLogicalExpression(rightNode)) ||
|
||||
rightNode.type === "StringLiteral" ||
|
||||
(rightNode.type === "Literal" && typeof rightNode.value === "string") ||
|
||||
isMemberExpressionChain(rightNode)
|
||||
(leftNode.type === "Identifier" || leftNode.type === "MemberExpression") &&
|
||||
(rightNode.type === "StringLiteral" ||
|
||||
(rightNode.type === "Literal" && typeof rightNode.value === "string") ||
|
||||
isMemberExpressionChain(rightNode))
|
||||
) {
|
||||
printed = indent$2(concat$2([line$1, printedRight]));
|
||||
} else {
|
||||
|
@ -14173,7 +14162,8 @@ function printAstToDoc$1(ast, options) {
|
|||
return comments$3.printComments(
|
||||
path,
|
||||
p => genericPrint(p, options, printGenerically, args),
|
||||
options
|
||||
options,
|
||||
args && args.needsSemi
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -14451,6 +14441,13 @@ function printDocToString$1(doc, options) {
|
|||
} else {
|
||||
if (out.length > 0) {
|
||||
// Trim whitespace at the end of line
|
||||
while (
|
||||
out.length > 0 &&
|
||||
out[out.length - 1].match(/^[^\S\n]*$/)
|
||||
) {
|
||||
out.pop();
|
||||
}
|
||||
|
||||
out[out.length - 1] = out[out.length - 1].replace(
|
||||
/[^\S\n]*$/,
|
||||
""
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "prettier",
|
||||
"version": "1.0.2",
|
||||
"version": "1.1.0",
|
||||
"description": "Prettier is an opinionated JavaScript formatter",
|
||||
"bin": {
|
||||
"prettier": "./bin/prettier.js"
|
||||
|
|
Loading…
Reference in New Issue