Skip to content

Commit 2ea3ff0

Browse files
authored
Preserve trailing comma when rewriting shorthand assignment (microsoft#533)
1 parent 101d98a commit 2ea3ff0

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

internal/transformers/commonjsmodule.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1880,6 +1880,7 @@ func (tx *CommonJSModuleTransformer) visitShorthandPropertyAssignment(node *ast.
18801880
)
18811881
}
18821882
assignment := tx.factory.NewPropertyAssignment(nil /*modifiers*/, name, nil /*postfixToken*/, expression)
1883+
assignment.Loc = node.Loc
18831884
tx.emitContext.AssignCommentAndSourceMapRanges(assignment, node.AsNode())
18841885
return assignment
18851886
}

internal/transformers/commonjsmodule_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -810,6 +810,19 @@ Object.defineProperty(exports, "__esModule", { value: true });
810810
const other_1 = require("other");
811811
({ a: other_1.a });`,
812812
},
813+
{
814+
title: "ShorthandPropertyAssignment#2",
815+
input: `import { a } from "other"
816+
({
817+
a,
818+
})`,
819+
output: `"use strict";
820+
Object.defineProperty(exports, "__esModule", { value: true });
821+
const other_1 = require("other");
822+
({
823+
a: other_1.a,
824+
});`,
825+
},
813826

814827
// CallExpression
815828
{

0 commit comments

Comments
 (0)