diff --git a/CHANGELOG.md b/CHANGELOG.md index 76a09da17b..5aad5189fd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # 1.14.18 * Fix files only containg comments not being output. + * Fix duplicate comments on property key shorthands. # 1.14.17 diff --git a/lib/6to5/transformation/transformers/es6-property-name-shorthand.js b/lib/6to5/transformation/transformers/es6-property-name-shorthand.js index 747cbbd9ec..8614d69c84 100644 --- a/lib/6to5/transformation/transformers/es6-property-name-shorthand.js +++ b/lib/6to5/transformation/transformers/es6-property-name-shorthand.js @@ -1,4 +1,8 @@ +var t = require("../../types"); +var _ = require("lodash"); + exports.Property = function (node) { if (!node.shorthand) return; node.shorthand = false; + node.key = t.removeComments(_.clone(node.key)); }; diff --git a/lib/6to5/types/index.js b/lib/6to5/types/index.js index f741debaff..96cceddb6b 100644 --- a/lib/6to5/types/index.js +++ b/lib/6to5/types/index.js @@ -295,11 +295,6 @@ t.inheritsComments = function (child, parent) { return child; }; -t.removeComments = function (node) { - delete node.leadingComments; - delete node.trailingComments; -}; - t.inherits = function (child, parent) { child.loc = parent.loc; child.end = parent.end; diff --git a/test/fixtures/transformation/es6-property-name-shorthand/comments/actual.js b/test/fixtures/transformation/es6-property-name-shorthand/comments/actual.js new file mode 100644 index 0000000000..a6a10d4689 --- /dev/null +++ b/test/fixtures/transformation/es6-property-name-shorthand/comments/actual.js @@ -0,0 +1,4 @@ +const A = 'a'; +const o = { + A // comment +}; diff --git a/test/fixtures/transformation/es6-property-name-shorthand/comments/expected.js b/test/fixtures/transformation/es6-property-name-shorthand/comments/expected.js new file mode 100644 index 0000000000..1368b53247 --- /dev/null +++ b/test/fixtures/transformation/es6-property-name-shorthand/comments/expected.js @@ -0,0 +1,4 @@ +const A = 'a'; +const o = { + A: A // comment +};