fix corner case with yield (#4867)
This commit is contained in:
@@ -482,31 +482,37 @@ function OutputStream(options) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function should_merge_comments(node, parent) {
|
||||||
|
if (parent instanceof AST_Binary) return parent.left === node;
|
||||||
|
if (parent.TYPE == "Call") return parent.expression === node;
|
||||||
|
if (parent instanceof AST_Conditional) return parent.condition === node;
|
||||||
|
if (parent instanceof AST_Dot) return parent.expression === node;
|
||||||
|
if (parent instanceof AST_Exit) return true;
|
||||||
|
if (parent instanceof AST_Sequence) return parent.expressions[0] === node;
|
||||||
|
if (parent instanceof AST_Sub) return parent.expression === node;
|
||||||
|
if (parent instanceof AST_UnaryPostfix) return true;
|
||||||
|
if (parent instanceof AST_Yield) return true;
|
||||||
|
}
|
||||||
|
|
||||||
function prepend_comments(node) {
|
function prepend_comments(node) {
|
||||||
var self = this;
|
var self = this;
|
||||||
var scan = node instanceof AST_Exit && node.value;
|
var scan;
|
||||||
|
if (node instanceof AST_Exit) {
|
||||||
|
scan = node.value;
|
||||||
|
} else if (node instanceof AST_Yield) {
|
||||||
|
scan = node.expression;
|
||||||
|
}
|
||||||
var comments = dump(node);
|
var comments = dump(node);
|
||||||
if (!comments) comments = [];
|
if (!comments) comments = [];
|
||||||
|
|
||||||
if (scan) {
|
if (scan) {
|
||||||
var tw = new TreeWalker(function(node) {
|
var tw = new TreeWalker(function(node) {
|
||||||
var parent = tw.parent();
|
if (!should_merge_comments(node, tw.parent())) return true;
|
||||||
if (parent instanceof AST_Exit
|
var before = dump(node);
|
||||||
|| parent instanceof AST_Binary && parent.left === node
|
if (before) comments = comments.concat(before);
|
||||||
|| parent.TYPE == "Call" && parent.expression === node
|
|
||||||
|| parent instanceof AST_Conditional && parent.condition === node
|
|
||||||
|| parent instanceof AST_Dot && parent.expression === node
|
|
||||||
|| parent instanceof AST_Sequence && parent.expressions[0] === node
|
|
||||||
|| parent instanceof AST_Sub && parent.expression === node
|
|
||||||
|| parent instanceof AST_UnaryPostfix) {
|
|
||||||
var before = dump(node);
|
|
||||||
if (before) comments = comments.concat(before);
|
|
||||||
} else {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
tw.push(node);
|
tw.push(node);
|
||||||
node.value.walk(tw);
|
scan.walk(tw);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (current_pos == 0) {
|
if (current_pos == 0) {
|
||||||
|
|||||||
@@ -150,6 +150,27 @@ for_await_of: {
|
|||||||
node_version: ">=10"
|
node_version: ">=10"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
comment_newline: {
|
||||||
|
beautify = {
|
||||||
|
comments: "all",
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(function*() {
|
||||||
|
yield (
|
||||||
|
/* */
|
||||||
|
"PASS"
|
||||||
|
);
|
||||||
|
}().next().value);
|
||||||
|
}
|
||||||
|
expect_exact: [
|
||||||
|
"console.log(function*(){",
|
||||||
|
"/* */",
|
||||||
|
'yield"PASS"}().next().value);',
|
||||||
|
]
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
node_version: ">=4"
|
||||||
|
}
|
||||||
|
|
||||||
collapse_vars_1: {
|
collapse_vars_1: {
|
||||||
options = {
|
options = {
|
||||||
collapse_vars: true,
|
collapse_vars: true,
|
||||||
|
|||||||
Reference in New Issue
Block a user