Ensure directives get printed in block statements (#4873)
This commit is contained in:
parent
2bbc36d25e
commit
01bc43464e
@ -14,11 +14,14 @@ export function Program(node: Object) {
|
|||||||
export function BlockStatement(node: Object) {
|
export function BlockStatement(node: Object) {
|
||||||
this.token("{");
|
this.token("{");
|
||||||
this.printInnerComments(node);
|
this.printInnerComments(node);
|
||||||
if (node.body.length) {
|
|
||||||
|
let hasDirectives = node.directives && node.directives.length;
|
||||||
|
|
||||||
|
if (node.body.length || hasDirectives) {
|
||||||
this.newline();
|
this.newline();
|
||||||
|
|
||||||
this.printSequence(node.directives, node, { indent: true });
|
this.printSequence(node.directives, node, { indent: true });
|
||||||
if (node.directives && node.directives.length) this.newline();
|
if (hasDirectives) this.newline();
|
||||||
|
|
||||||
this.printSequence(node.body, node, { indent: true });
|
this.printSequence(node.body, node, { indent: true });
|
||||||
this.removeTrailingNewline();
|
this.removeTrailingNewline();
|
||||||
|
|||||||
@ -230,6 +230,20 @@ describe("programmatic generation", function() {
|
|||||||
assert.equal(ast.program.body[0].consequent.type, "BlockStatement");
|
assert.equal(ast.program.body[0].consequent.type, "BlockStatement");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("prints directives in block with empty body", function() {
|
||||||
|
let blockStatement = t.blockStatement(
|
||||||
|
[],
|
||||||
|
[t.directive(t.directiveLiteral("use strict"))]
|
||||||
|
);
|
||||||
|
|
||||||
|
let output = generate.default(blockStatement).code;
|
||||||
|
assert.equal(output, [
|
||||||
|
"{",
|
||||||
|
" \"use strict\";",
|
||||||
|
"}"
|
||||||
|
].join("\n"));
|
||||||
|
});
|
||||||
|
|
||||||
it("flow object indentation", function() {
|
it("flow object indentation", function() {
|
||||||
let objectStatement = t.objectTypeAnnotation(
|
let objectStatement = t.objectTypeAnnotation(
|
||||||
[
|
[
|
||||||
|
|||||||
@ -1 +1,3 @@
|
|||||||
define("my custom module name", [], function () {});
|
define("my custom module name", [], function () {
|
||||||
|
"use strict";
|
||||||
|
});
|
||||||
|
|||||||
@ -1 +1,3 @@
|
|||||||
define(["foo", "foo-bar", "./directory/foo-bar"], function () {});
|
define(["foo", "foo-bar", "./directory/foo-bar"], function () {
|
||||||
|
"use strict";
|
||||||
|
});
|
||||||
|
|||||||
@ -10,4 +10,6 @@
|
|||||||
factory();
|
factory();
|
||||||
global.myCustomModuleName = mod.exports;
|
global.myCustomModuleName = mod.exports;
|
||||||
}
|
}
|
||||||
})(this, function () {});
|
})(this, function () {
|
||||||
|
"use strict";
|
||||||
|
});
|
||||||
|
|||||||
@ -10,4 +10,6 @@
|
|||||||
factory(global.foo, global.fooBar, global.fooBar);
|
factory(global.foo, global.fooBar, global.fooBar);
|
||||||
global.actual = mod.exports;
|
global.actual = mod.exports;
|
||||||
}
|
}
|
||||||
})(this, function () {});
|
})(this, function () {
|
||||||
|
"use strict";
|
||||||
|
});
|
||||||
|
|||||||
@ -10,4 +10,6 @@
|
|||||||
factory(global.render);
|
factory(global.render);
|
||||||
global.actual = mod.exports;
|
global.actual = mod.exports;
|
||||||
}
|
}
|
||||||
})(this, function (_render) {});
|
})(this, function (_render) {
|
||||||
|
"use strict";
|
||||||
|
});
|
||||||
|
|||||||
@ -10,4 +10,6 @@
|
|||||||
factory(global.baz);
|
factory(global.baz);
|
||||||
global.actual = mod.exports;
|
global.actual = mod.exports;
|
||||||
}
|
}
|
||||||
})(this, function () {});
|
})(this, function () {
|
||||||
|
"use strict";
|
||||||
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user