diff --git a/internal/printer/printer.go b/internal/printer/printer.go index d3a0657cb3..2a212b6be3 100644 --- a/internal/printer/printer.go +++ b/internal/printer/printer.go @@ -3802,8 +3802,12 @@ func (p *Printer) emitImportAttribute(node *ast.ImportAttribute) { p.emitImportAttributeName(node.Name()) p.writePunctuation(":") p.writeSpace() - /// !!! emit trailing comments of value - p.emitExpression(node.Value, ast.OperatorPrecedenceDisallowComma) + value := node.Value + if p.emitContext.EmitFlags(node.Value)&EFNoLeadingComments == 0 { + commentRange := getCommentRange(value) + p.emitTrailingComments(commentRange.Pos(), commentSeparatorAfter) + } + p.emitExpression(value, ast.OperatorPrecedenceDisallowComma) p.exitNode(node.AsNode(), state) } diff --git a/testdata/baselines/reference/compiler/importAttributesWithValueComments.js b/testdata/baselines/reference/compiler/importAttributesWithValueComments.js new file mode 100644 index 0000000000..8cb0310784 --- /dev/null +++ b/testdata/baselines/reference/compiler/importAttributesWithValueComments.js @@ -0,0 +1,23 @@ +//// [tests/cases/compiler/importAttributesWithValueComments.ts] //// + +//// [a.ts] +export default { + a: "a", + b: "b", + 1: "1", +} + +//// [b.ts] +import a from "./a" with { a: /* a */ "a", "b": /* b */ "b" }; +a; + + +//// [a.js] +export default { + a: "a", + b: "b", + 1: "1", +}; +//// [b.js] +import a from "./a" with { a: /* a */ "a", "b": /* b */ "b" }; +a; diff --git a/testdata/baselines/reference/compiler/importAttributesWithValueComments.symbols b/testdata/baselines/reference/compiler/importAttributesWithValueComments.symbols new file mode 100644 index 0000000000..a70fa74cf7 --- /dev/null +++ b/testdata/baselines/reference/compiler/importAttributesWithValueComments.symbols @@ -0,0 +1,21 @@ +//// [tests/cases/compiler/importAttributesWithValueComments.ts] //// + +=== /a.ts === +export default { + a: "a", +>a : Symbol(a, Decl(a.ts, 0, 16)) + + b: "b", +>b : Symbol(b, Decl(a.ts, 1, 11)) + + 1: "1", +>1 : Symbol(1, Decl(a.ts, 2, 11)) +} + +=== /b.ts === +import a from "./a" with { a: /* a */ "a", "b": /* b */ "b" }; +>a : Symbol(a, Decl(b.ts, 0, 6)) + +a; +>a : Symbol(a, Decl(b.ts, 0, 6)) + diff --git a/testdata/baselines/reference/compiler/importAttributesWithValueComments.types b/testdata/baselines/reference/compiler/importAttributesWithValueComments.types new file mode 100644 index 0000000000..a9ea0943a4 --- /dev/null +++ b/testdata/baselines/reference/compiler/importAttributesWithValueComments.types @@ -0,0 +1,27 @@ +//// [tests/cases/compiler/importAttributesWithValueComments.ts] //// + +=== /a.ts === +export default { +>{ a: "a", b: "b", 1: "1",} : { a: string; b: string; 1: string; } + + a: "a", +>a : string +>"a" : "a" + + b: "b", +>b : string +>"b" : "b" + + 1: "1", +>1 : string +>"1" : "1" +} + +=== /b.ts === +import a from "./a" with { a: /* a */ "a", "b": /* b */ "b" }; +>a : { a: string; b: string; 1: string; } +>a : any + +a; +>a : { a: string; b: string; 1: string; } + diff --git a/testdata/tests/cases/compiler/importAttributesWithValueComments.ts b/testdata/tests/cases/compiler/importAttributesWithValueComments.ts new file mode 100644 index 0000000000..77a7a6ebf7 --- /dev/null +++ b/testdata/tests/cases/compiler/importAttributesWithValueComments.ts @@ -0,0 +1,13 @@ +// @target: esnext +// @module: esnext + +// @filename: /a.ts +export default { + a: "a", + b: "b", + 1: "1", +} + +// @filename: /b.ts +import a from "./a" with { a: /* a */ "a", "b": /* b */ "b" }; +a;