1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

fmt: keep the shebang header in vsh files (#7893)

This commit is contained in:
Lukas Neubert 2021-01-05 15:14:16 +01:00 committed by GitHub
parent 2aea11e607
commit eaba21d81a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 2 deletions

View File

@ -1355,6 +1355,10 @@ struct CommentsOptions {
}
pub fn (mut f Fmt) comment(node ast.Comment, options CommentsOptions) {
if node.text.starts_with('#!') {
f.writeln(node.text)
return
}
if options.iembed {
x := node.text.trim_left('\x01')
if x.contains('\n') {

View File

@ -0,0 +1,4 @@
#!/usr/local/bin/v run
x := 5
println(x)

View File

@ -820,9 +820,9 @@ fn (mut s Scanner) text_scan() token.Token {
s.ignore_line()
if nextc == `!` {
// treat shebang line (#!) as a comment
s.line_comment = s.text[start + 1..s.pos].trim_space()
comment := s.text[start - 1..s.pos].trim_space()
// s.fgenln('// shebang line "$s.line_comment"')
continue
return s.new_token(.comment, comment, comment.len + 2)
}
hash := s.text[start..s.pos].trim_space()
return s.new_token(.hash, hash, hash.len)