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) {
|
||||
let res;
|
||||
if (
|
||||
(n.value.type === "StringLiteral" || n.value.type === "Literal") &&
|
||||
typeof n.value.value === "string"
|
||||
) {
|
||||
if (isStringLiteral(n.value)) {
|
||||
const value = n.value.extra ? n.value.extra.raw : n.value.raw;
|
||||
res = '"' + value.slice(1, -1).replace(/"/g, """) + '"';
|
||||
} else {
|
||||
|
@ -1570,9 +1567,7 @@ function genericPrintNoParens(path, options, print, args) {
|
|||
if (
|
||||
n.attributes.length === 1 &&
|
||||
n.attributes[0].value &&
|
||||
(n.attributes[0].value.type === "Literal" ||
|
||||
n.attributes[0].value.type === "StringLiteral") &&
|
||||
typeof n.attributes[0].value.value === "string"
|
||||
isStringLiteral(n.attributes[0].value)
|
||||
) {
|
||||
return group(
|
||||
concat([
|
||||
|
@ -2893,12 +2888,7 @@ function printPropertyKey(path, options, print) {
|
|||
const node = path.getNode();
|
||||
const key = node.key;
|
||||
|
||||
if (
|
||||
(key.type === "StringLiteral" ||
|
||||
(key.type === "Literal" && typeof key.value === "string")) &&
|
||||
isIdentifierName(key.value) &&
|
||||
!node.computed
|
||||
) {
|
||||
if (isStringLiteral(key) && isIdentifierName(key.value) && !node.computed) {
|
||||
// 'a' -> a
|
||||
return path.call(
|
||||
keyPath => comments.printComments(keyPath, () => key.value, options),
|
||||
|
@ -4229,10 +4219,10 @@ function printAssignment(
|
|||
|
||||
const canBreak =
|
||||
(isBinaryish(rightNode) && !shouldInlineLogicalExpression(rightNode)) ||
|
||||
((leftNode.type === "Identifier" || leftNode.type === "MemberExpression") &&
|
||||
(rightNode.type === "StringLiteral" ||
|
||||
(rightNode.type === "Literal" && typeof rightNode.value === "string") ||
|
||||
isMemberExpressionChain(rightNode)));
|
||||
((leftNode.type === "Identifier" ||
|
||||
isStringLiteral(leftNode) ||
|
||||
leftNode.type === "MemberExpression") &&
|
||||
(isStringLiteral(rightNode) || isMemberExpressionChain(rightNode)));
|
||||
|
||||
const printed = printAssignmentRight(
|
||||
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) {
|
||||
// Force this doc into flat mode by statically converting all
|
||||
// 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`] = `
|
||||
const a = classnames({
|
||||
"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