Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(bundle): omit enum comments if name contains */ in bundle mode #2371

Merged
merged 2 commits into from
Jul 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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