Handle conditions inside of a ternary (#2228)

Fixes #2122
master
Christopher Chedeau 2017-06-21 18:17:30 -07:00 committed by GitHub
parent ec1b672bbf
commit 39954f7951
5 changed files with 115 additions and 25 deletions

View File

@ -306,7 +306,8 @@ function genericPrintNoParens(path, options, print, args) {
(n === parent.body && parent.type === "ArrowFunctionExpression") ||
(n !== parent.body && parent.type === "ForStatement") ||
parent.type === "ObjectProperty" ||
parent.type === "Property"
parent.type === "Property" ||
parent.type === "ConditionalExpression"
) {
return group(concat(parts));
}
@ -4090,6 +4091,9 @@ function printAssignment(
const canBreak =
(isBinaryish(rightNode) && !shouldInlineLogicalExpression(rightNode)) ||
(rightNode.type === "ConditionalExpression" &&
isBinaryish(rightNode.test) &&
!shouldInlineLogicalExpression(rightNode.test)) ||
((leftNode.type === "Identifier" ||
isStringLiteral(leftNode) ||
leftNode.type === "MemberExpression") &&

View File

@ -39,25 +39,27 @@ const { configureStore } = process.env.NODE_ENV === "production"
? require("./configureProdStore") // a
: require("./configureDevStore"); // b
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
var inspect = 4 === util.inspect.length
? // node <= 0.8.x
function(v, colors) {
return util.inspect(v, void 0, void 0, colors);
}
: // node > 0.8.x
function(v, colors) {
return util.inspect(v, { colors: colors });
};
var inspect =
4 === util.inspect.length
? // node <= 0.8.x
function(v, colors) {
return util.inspect(v, void 0, void 0, colors);
}
: // node > 0.8.x
function(v, colors) {
return util.inspect(v, { colors: colors });
};
var inspect = 4 === util.inspect.length
? // node <= 0.8.x
function(v, colors) {
return util.inspect(v, void 0, void 0, colors);
}
: // node > 0.8.x
function(v, colors) {
return util.inspect(v, { colors: colors });
};
var inspect =
4 === util.inspect.length
? // node <= 0.8.x
function(v, colors) {
return util.inspect(v, void 0, void 0, colors);
}
: // node > 0.8.x
function(v, colors) {
return util.inspect(v, { colors: colors });
};
const extractTextPluginOptions = shouldUseRelativeAssetPaths
? // Making sure that the publicPath goes back to to build folder.
@ -73,9 +75,10 @@ const extractTextPluginOptions = shouldUseRelativeAssetPaths // Making sure that
? { publicPath: Array(cssFilename.split("/").length).join("../") }
: {};
const { configureStore } = process.env.NODE_ENV === "production"
? require("./configureProdStore") // a
: require("./configureDevStore"); // b
const { configureStore } =
process.env.NODE_ENV === "production"
? require("./configureProdStore") // a
: require("./configureDevStore"); // b
`;

View File

@ -1,5 +1,75 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`binary.js 1`] = `
const funnelSnapshotCard = (report === MY_OVERVIEW &&
!ReportGK.xar_metrics_active_capitol_v2) ||
(report === COMPANY_OVERVIEW &&
!ReportGK.xar_metrics_active_capitol_v2_company_metrics)
? <ReportMetricsFunnelSnapshotCard metrics={metrics} />
: null;
room = room.map((row, rowIndex) => (
row.map((col, colIndex) => (
(rowIndex === 0 || colIndex === 0 || rowIndex === height || colIndex === width) ? 1 : 0
))
))
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
const funnelSnapshotCard =
(report === MY_OVERVIEW && !ReportGK.xar_metrics_active_capitol_v2) ||
(report === COMPANY_OVERVIEW &&
!ReportGK.xar_metrics_active_capitol_v2_company_metrics)
? <ReportMetricsFunnelSnapshotCard metrics={metrics} />
: null;
room = room.map((row, rowIndex) =>
row.map(
(col, colIndex) =>
rowIndex === 0 ||
colIndex === 0 ||
rowIndex === height ||
colIndex === width
? 1
: 0
)
);
`;
exports[`binary.js 2`] = `
const funnelSnapshotCard = (report === MY_OVERVIEW &&
!ReportGK.xar_metrics_active_capitol_v2) ||
(report === COMPANY_OVERVIEW &&
!ReportGK.xar_metrics_active_capitol_v2_company_metrics)
? <ReportMetricsFunnelSnapshotCard metrics={metrics} />
: null;
room = room.map((row, rowIndex) => (
row.map((col, colIndex) => (
(rowIndex === 0 || colIndex === 0 || rowIndex === height || colIndex === width) ? 1 : 0
))
))
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
const funnelSnapshotCard =
(report === MY_OVERVIEW && !ReportGK.xar_metrics_active_capitol_v2) ||
(report === COMPANY_OVERVIEW &&
!ReportGK.xar_metrics_active_capitol_v2_company_metrics)
? <ReportMetricsFunnelSnapshotCard metrics={metrics} />
: null;
room = room.map((row, rowIndex) =>
row.map(
(col, colIndex) =>
rowIndex === 0 ||
colIndex === 0 ||
rowIndex === height ||
colIndex === width
? 1
: 0
)
);
`;
exports[`indent.js 1`] = `
aaaaaaaaaaaaaaa ? bbbbbbbbbbbbbbbbbb : ccccccccccccccc ? ddddddddddddddd : eeeeeeeeeeeeeee ? fffffffffffffff : gggggggggggggggg
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

12
tests/ternaries/binary.js Normal file
View File

@ -0,0 +1,12 @@
const funnelSnapshotCard = (report === MY_OVERVIEW &&
!ReportGK.xar_metrics_active_capitol_v2) ||
(report === COMPANY_OVERVIEW &&
!ReportGK.xar_metrics_active_capitol_v2_company_metrics)
? <ReportMetricsFunnelSnapshotCard metrics={metrics} />
: null;
room = room.map((row, rowIndex) => (
row.map((col, colIndex) => (
(rowIndex === 0 || colIndex === 0 || rowIndex === height || colIndex === width) ? 1 : 0
))
))

View File

@ -147,11 +147,12 @@ namespace TypeScript.WebTsc {
// Position must be at 0 before encoding can be changed
fileStream.Position = 0;
// [0xFF,0xFE] and [0xFE,0xFF] mean utf-16 (little or big endian), otherwise default to utf-8
fileStream.Charset = bom.length >= 2 &&
fileStream.Charset =
bom.length >= 2 &&
((bom.charCodeAt(0) === 0xff && bom.charCodeAt(1) === 0xfe) ||
(bom.charCodeAt(0) === 0xfe && bom.charCodeAt(1) === 0xff))
? "unicode"
: "utf-8";
? "unicode"
: "utf-8";
}
// ReadText method always strips byte order mark from resulting string
return fileStream.ReadText();