Skip to content
Open
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
15 changes: 15 additions & 0 deletions internal/bundler_tests/bundler_default_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1400,6 +1400,21 @@ func TestHashbangNoBundle(t *testing.T) {
})
}

func TestHashbangUnsupported(t *testing.T) {
default_suite.expectBundled(t, bundled{
files: map[string]string{
"/entry.js": `#!/usr/bin/env node
process.exit(0);
`,
},
entryPaths: []string{"/entry.js"},
options: config.Options{
AbsOutputFile: "/out.js",
UnsupportedJSFeatures: compat.Hashbang,
},
})
}

func TestHashbangBannerUseStrictOrder(t *testing.T) {
default_suite.expectBundled(t, bundled{
files: map[string]string{
Expand Down
5 changes: 5 additions & 0 deletions internal/bundler_tests/snapshots/snapshots_default.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1795,6 +1795,11 @@ TestHashbangNoBundle
#!/usr/bin/env node
process.exit(0);

================================================================================
TestHashbangUnsupported
---------- /out.js ----------
process.exit(0);

================================================================================
TestIIFE_ES5
---------- /out.js ----------
Expand Down
2 changes: 1 addition & 1 deletion internal/linker/linker.go
Original file line number Diff line number Diff line change
Expand Up @@ -5678,7 +5678,7 @@ func (c *linkerContext) generateChunkJS(chunkIndex int, chunkWaitGroup *sync.Wai

// Start with the hashbang if there is one. This must be done before the
// banner because it only works if it's literally the first character.
if chunk.isEntryPoint {
if chunk.isEntryPoint && !c.options.UnsupportedJSFeatures.Has(compat.Hashbang) {
if repr := c.graph.Files[chunk.sourceIndex].InputFile.Repr.(*graph.JSRepr); repr.AST.Hashbang != "" {
hashbang := repr.AST.Hashbang + "\n"
prevOffset.AdvanceString(hashbang)
Expand Down