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

Ignore hashhbang comments #4676

Merged
merged 2 commits into from Oct 16, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/ast/nodes/Program.ts
Expand Up @@ -32,8 +32,13 @@ export default class Program extends NodeBase {
}

render(code: MagicString, options: RenderOptions): void {
let start = this.start;
if (code.original.startsWith('#!')) {
start = Math.min(code.original.indexOf('\n') + 1, this.end);
code.remove(0, start);
}
if (this.body.length > 0) {
renderStatementList(this.body, code, this.start, this.end, options);
renderStatementList(this.body, code, start, this.end, options);
} else {
super.render(code, options);
}
Expand Down
3 changes: 3 additions & 0 deletions test/form/samples/hashbang/_config.js
@@ -0,0 +1,3 @@
module.exports = {
description: 'supports input files with leading hashbang comment'
};
3 changes: 3 additions & 0 deletions test/form/samples/hashbang/_expected.js
@@ -0,0 +1,3 @@
console.log('other');

console.log('main');
3 changes: 3 additions & 0 deletions test/form/samples/hashbang/main.js
@@ -0,0 +1,3 @@
#!/usr/bin/env node
import './other';
console.log('main');
2 changes: 2 additions & 0 deletions test/form/samples/hashbang/other.js
@@ -0,0 +1,2 @@
#!/usr/bin/env node
console.log('other');