Stabilize comments inside of ternaries (#666)
Now, all the variations of comments in ternaries are printed the same way. Fixes #617master
parent
3464092cc4
commit
287db4a9b6
|
@ -157,9 +157,11 @@ function attach(comments, ast, text) {
|
|||
addDanglingComment(ast, comment);
|
||||
}
|
||||
} else if (util.hasNewline(text, locEnd(comment))) {
|
||||
// There is content before this comment on the same line, but
|
||||
// none after it, so prefer a trailing comment of the previous node.
|
||||
if (precedingNode) {
|
||||
if (handleConditionalExpressionComments(enclosingNode, followingNode, comment)) {
|
||||
// We're good
|
||||
} else if (precedingNode) {
|
||||
// There is content before this comment on the same line, but
|
||||
// none after it, so prefer a trailing comment of the previous node.
|
||||
addTrailingComment(precedingNode, comment);
|
||||
} else if (followingNode) {
|
||||
addLeadingComment(followingNode, comment);
|
||||
|
@ -369,6 +371,14 @@ function handleMemberExpressionComment(enclosingNode, followingNode, comment) {
|
|||
return false;
|
||||
}
|
||||
|
||||
function handleConditionalExpressionComments(enclosingNode, followingNode, comment) {
|
||||
if (enclosingNode && enclosingNode.type === 'ConditionalExpression' && followingNode) {
|
||||
addLeadingComment(followingNode, comment);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function printComment(commentPath) {
|
||||
const comment = commentPath.getValue();
|
||||
|
||||
|
|
|
@ -0,0 +1,71 @@
|
|||
exports[`test comments.js 1`] = `
|
||||
"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.
|
||||
? { publicPath: Array(cssFilename.split(\'/\').length).join(\'../\') } :
|
||||
{};
|
||||
|
||||
const extractTextPluginOptions = shouldUseRelativeAssetPaths
|
||||
? // Making sure that the publicPath goes back to to build folder.
|
||||
{ publicPath: Array(cssFilename.split(\"/\").length).join(\"../\") }
|
||||
: {};
|
||||
|
||||
const extractTextPluginOptions = shouldUseRelativeAssetPaths // Making sure that the publicPath goes back to to build folder.
|
||||
? { publicPath: Array(cssFilename.split(\"/\").length).join(\"../\") }
|
||||
: {};
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
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.
|
||||
{ publicPath: Array(cssFilename.split(\"/\").length).join(\"../\") }
|
||||
: {};
|
||||
|
||||
const extractTextPluginOptions = shouldUseRelativeAssetPaths
|
||||
? // Making sure that the publicPath goes back to to build folder.
|
||||
{ publicPath: Array(cssFilename.split(\"/\").length).join(\"../\") }
|
||||
: {};
|
||||
|
||||
const extractTextPluginOptions = shouldUseRelativeAssetPaths
|
||||
? // Making sure that the publicPath goes back to to build folder.
|
||||
{ publicPath: Array(cssFilename.split(\"/\").length).join(\"../\") }
|
||||
: {};
|
||||
"
|
||||
`;
|
|
@ -0,0 +1,33 @@
|
|||
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.
|
||||
? { publicPath: Array(cssFilename.split('/').length).join('../') } :
|
||||
{};
|
||||
|
||||
const extractTextPluginOptions = shouldUseRelativeAssetPaths
|
||||
? // Making sure that the publicPath goes back to to build folder.
|
||||
{ publicPath: Array(cssFilename.split("/").length).join("../") }
|
||||
: {};
|
||||
|
||||
const extractTextPluginOptions = shouldUseRelativeAssetPaths // Making sure that the publicPath goes back to to build folder.
|
||||
? { publicPath: Array(cssFilename.split("/").length).join("../") }
|
||||
: {};
|
|
@ -0,0 +1 @@
|
|||
run_spec(__dirname);
|
Loading…
Reference in New Issue