Break on Property with long value and Literal key (#1786)
* fix(object-expression): break on object literal with long value * fix(object-expression): add isStringLiteral checkmaster
parent
920ceea77e
commit
c9159f7862
|
@ -1486,10 +1486,7 @@ function genericPrintNoParens(path, options, print, args) {
|
||||||
|
|
||||||
if (n.value) {
|
if (n.value) {
|
||||||
let res;
|
let res;
|
||||||
if (
|
if (isStringLiteral(n.value)) {
|
||||||
(n.value.type === "StringLiteral" || n.value.type === "Literal") &&
|
|
||||||
typeof n.value.value === "string"
|
|
||||||
) {
|
|
||||||
const value = n.value.extra ? n.value.extra.raw : n.value.raw;
|
const value = n.value.extra ? n.value.extra.raw : n.value.raw;
|
||||||
res = '"' + value.slice(1, -1).replace(/"/g, """) + '"';
|
res = '"' + value.slice(1, -1).replace(/"/g, """) + '"';
|
||||||
} else {
|
} else {
|
||||||
|
@ -1570,9 +1567,7 @@ function genericPrintNoParens(path, options, print, args) {
|
||||||
if (
|
if (
|
||||||
n.attributes.length === 1 &&
|
n.attributes.length === 1 &&
|
||||||
n.attributes[0].value &&
|
n.attributes[0].value &&
|
||||||
(n.attributes[0].value.type === "Literal" ||
|
isStringLiteral(n.attributes[0].value)
|
||||||
n.attributes[0].value.type === "StringLiteral") &&
|
|
||||||
typeof n.attributes[0].value.value === "string"
|
|
||||||
) {
|
) {
|
||||||
return group(
|
return group(
|
||||||
concat([
|
concat([
|
||||||
|
@ -2893,12 +2888,7 @@ function printPropertyKey(path, options, print) {
|
||||||
const node = path.getNode();
|
const node = path.getNode();
|
||||||
const key = node.key;
|
const key = node.key;
|
||||||
|
|
||||||
if (
|
if (isStringLiteral(key) && isIdentifierName(key.value) && !node.computed) {
|
||||||
(key.type === "StringLiteral" ||
|
|
||||||
(key.type === "Literal" && typeof key.value === "string")) &&
|
|
||||||
isIdentifierName(key.value) &&
|
|
||||||
!node.computed
|
|
||||||
) {
|
|
||||||
// 'a' -> a
|
// 'a' -> a
|
||||||
return path.call(
|
return path.call(
|
||||||
keyPath => comments.printComments(keyPath, () => key.value, options),
|
keyPath => comments.printComments(keyPath, () => key.value, options),
|
||||||
|
@ -4229,10 +4219,10 @@ function printAssignment(
|
||||||
|
|
||||||
const canBreak =
|
const canBreak =
|
||||||
(isBinaryish(rightNode) && !shouldInlineLogicalExpression(rightNode)) ||
|
(isBinaryish(rightNode) && !shouldInlineLogicalExpression(rightNode)) ||
|
||||||
((leftNode.type === "Identifier" || leftNode.type === "MemberExpression") &&
|
((leftNode.type === "Identifier" ||
|
||||||
(rightNode.type === "StringLiteral" ||
|
isStringLiteral(leftNode) ||
|
||||||
(rightNode.type === "Literal" && typeof rightNode.value === "string") ||
|
leftNode.type === "MemberExpression") &&
|
||||||
isMemberExpressionChain(rightNode)));
|
(isStringLiteral(rightNode) || isMemberExpressionChain(rightNode)));
|
||||||
|
|
||||||
const printed = printAssignmentRight(
|
const printed = printAssignmentRight(
|
||||||
rightNode,
|
rightNode,
|
||||||
|
@ -4706,6 +4696,13 @@ function isLiteral(node) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isStringLiteral(node) {
|
||||||
|
return (
|
||||||
|
node.type === "StringLiteral" ||
|
||||||
|
(node.type === "Literal" && typeof node.value === "string")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
function removeLines(doc) {
|
function removeLines(doc) {
|
||||||
// Force this doc into flat mode by statically converting all
|
// Force this doc into flat mode by statically converting all
|
||||||
// lines into spaces (or soft lines into nothing). Hard lines
|
// lines into spaces (or soft lines into nothing). Hard lines
|
||||||
|
|
|
@ -17,6 +17,18 @@ function foo() {
|
||||||
|
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
exports[`long-value.js 1`] = `
|
||||||
|
const x = {
|
||||||
|
"ABC": "12345678901234567890123456789012345678901234567890123456789012345678901234567890"
|
||||||
|
};
|
||||||
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
const x = {
|
||||||
|
ABC:
|
||||||
|
"12345678901234567890123456789012345678901234567890123456789012345678901234567890"
|
||||||
|
};
|
||||||
|
|
||||||
|
`;
|
||||||
|
|
||||||
exports[`test.js 1`] = `
|
exports[`test.js 1`] = `
|
||||||
const a = classnames({
|
const a = classnames({
|
||||||
"some-prop": this.state.longLongLongLongLongLongLongLongLongTooLongProp
|
"some-prop": this.state.longLongLongLongLongLongLongLongLongTooLongProp
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
run_spec(__dirname, null, ["typescript"]);
|
run_spec(__dirname, null, ["babylon", "typescript"]);
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
const x = {
|
||||||
|
"ABC": "12345678901234567890123456789012345678901234567890123456789012345678901234567890"
|
||||||
|
};
|
Loading…
Reference in New Issue