Skip to content

Commit

Permalink
fix(bundle): omit enum comments if name contains */ in bundle mode (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
magic-akari authored Jul 6, 2022
1 parent 71be8bc commit 46d352e
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
22 changes: 22 additions & 0 deletions internal/bundler/bundler_ts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
6 changes: 6 additions & 0 deletions internal/bundler/snapshots/snapshots_ts.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
TestConstEnumComments
---------- /out.js ----------
// foo.ts
console.log(14);

================================================================================
TestExportTypeIssue379
---------- /out.js ----------
// a.ts
Expand Down
2 changes: 1 addition & 1 deletion internal/js_printer/js_printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(" */")
Expand Down

0 comments on commit 46d352e

Please sign in to comment.