diff --git a/src/babel/transformation/file/index.js b/src/babel/transformation/file/index.js index 8abc0cf98d..80c38d4f4f 100644 --- a/src/babel/transformation/file/index.js +++ b/src/babel/transformation/file/index.js @@ -341,14 +341,24 @@ export default class File { } attachAuxiliaryComment(node: Object): Object { - var comment = this.opts.auxiliaryComment; - if (comment) { + var beforeComment = this.opts.auxiliaryCommentBefore; + if (beforeComment) { node.leadingComments = node.leadingComments || []; node.leadingComments.push({ type: "CommentLine", - value: " " + comment + value: " " + beforeComment }); } + + var afterComment = this.opts.auxiliaryCommentAfter; + if (afterComment) { + node.trailingComments = node.trailingComments || []; + node.trailingComments.push({ + type: "CommentLine", + value: " " + afterComment + }); + } + return node; } diff --git a/src/babel/transformation/file/options.json b/src/babel/transformation/file/options.json index e127a69a48..892baa0cfd 100644 --- a/src/babel/transformation/file/options.json +++ b/src/babel/transformation/file/options.json @@ -173,12 +173,23 @@ }, "auxiliaryComment": { + "deprecated": "renamed to auxiliaryCommentBefore", + "shorthand": "a", + "alias": "auxiliaryCommentBefore" + }, + + "auxiliaryCommentBefore": { "type": "string", "default": "", - "shorthand": "a", "description": "attach a comment before all helper declarations and auxiliary code" }, + "auxiliaryCommentAfter": { + "type": "string", + "default": "", + "description": "attach a comment after all helper declarations and auxiliary code" + }, + "externalHelpers": { "type": "boolean", "default": false, diff --git a/test/core/api.js b/test/core/api.js index e2c3c16ee0..1bc6366d7f 100644 --- a/test/core/api.js +++ b/test/core/api.js @@ -18,13 +18,23 @@ suite("api", function () { assert.ok(!result.ast); }); - test("auxiliaryComment option", function () { + test("auxiliaryCommentBefore option", function () { assert.ok(transform("class Foo {}", { - auxiliaryComment: "foobar" + auxiliaryCommentBefore: "foobar" }).code.indexOf("foobar") >= 0); assert.ok(transform("for (let i in bar) { foo(function () { i; }); break; continue; }", { - auxiliaryComment: "foobar" + auxiliaryCommentBefore: "foobar" + }).code.indexOf("foobar") >= 0); + }); + + test("auxiliaryCommentAfter option", function () { + assert.ok(transform("class Foo {}", { + auxiliaryCommentAfter: "foobar" + }).code.indexOf("foobar") >= 0); + + assert.ok(transform("for (let i in bar) { foo(function () { i; }); break; continue; }", { + auxiliaryCommentAfter: "foobar" }).code.indexOf("foobar") >= 0); });