From 682c2b985d6cc2d430dc24f6c9ac30208505e74b Mon Sep 17 00:00:00 2001 From: magic-akari Date: Sun, 3 Jul 2022 20:35:09 +0800 Subject: [PATCH 1/2] chore: add test case --- internal/bundler/bundler_ts_test.go | 22 +++++++++++++++++++++ internal/bundler/snapshots/snapshots_ts.txt | 6 ++++++ 2 files changed, 28 insertions(+) diff --git a/internal/bundler/bundler_ts_test.go b/internal/bundler/bundler_ts_test.go index bcdde9bf862..2d730302ac9 100644 --- a/internal/bundler/bundler_ts_test.go +++ b/internal/bundler/bundler_ts_test.go @@ -223,6 +223,28 @@ func TestTSDeclareConstEnum(t *testing.T) { }) } +func TestConstEnumComments(t *testing.T) { + ts_suite.expectBundled(t, bundled{ + files: map[string]string{ + "/bar.ts": ` + export const enum PRCD { + "*/%" = 14, + } + `, + "/foo.ts": ` + import { PRCD } from "./bar"; + + console.log(PRCD["*/%"]); + `, + }, + entryPaths: []string{"/foo.ts"}, + options: config.Options{ + Mode: config.ModeBundle, + AbsOutputFile: "/out.js", + }, + }) +} + func TestTSImportEmptyNamespace(t *testing.T) { ts_suite.expectBundled(t, bundled{ files: map[string]string{ diff --git a/internal/bundler/snapshots/snapshots_ts.txt b/internal/bundler/snapshots/snapshots_ts.txt index a0bf09178c9..49ff10f6b79 100644 --- a/internal/bundler/snapshots/snapshots_ts.txt +++ b/internal/bundler/snapshots/snapshots_ts.txt @@ -1,3 +1,9 @@ +TestConstEnumComments +---------- /out.js ---------- +// foo.ts +console.log(14); + +================================================================================ TestExportTypeIssue379 ---------- /out.js ---------- // a.ts From 10ea4f885875d5f35a327c5464a85e7c4453a913 Mon Sep 17 00:00:00 2001 From: magic-akari Date: Sun, 3 Jul 2022 20:37:39 +0800 Subject: [PATCH 2/2] fix(bundle): omit enum comments if name contains `*/` in bundle mode --- internal/js_printer/js_printer.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/js_printer/js_printer.go b/internal/js_printer/js_printer.go index c28d1be42ce..cb9e2d6f0e2 100644 --- a/internal/js_printer/js_printer.go +++ b/internal/js_printer/js_printer.go @@ -2001,7 +2001,7 @@ func (p *printer) printExpr(expr js_ast.Expr, level js_ast.L, flags printExprFla } else { p.printNumber(value.Number, level) } - if !p.options.MinifyWhitespace && !p.options.MinifyIdentifiers { + if !p.options.MinifyWhitespace && !p.options.MinifyIdentifiers && !strings.Contains(name, "*/") { p.print(" /* ") p.print(name) p.print(" */")