fmt: do not insert a newline before returned $vweb.html() (#9063)
parent
97f9abcf82
commit
460e06b9ff
|
@ -1142,6 +1142,7 @@ pub:
|
||||||
has_parens bool // if $() is used, for vfmt
|
has_parens bool // if $() is used, for vfmt
|
||||||
left Expr
|
left Expr
|
||||||
field_expr Expr
|
field_expr Expr
|
||||||
|
pos token.Position
|
||||||
pub mut:
|
pub mut:
|
||||||
left_type table.Type
|
left_type table.Type
|
||||||
typ table.Type
|
typ table.Type
|
||||||
|
@ -1149,6 +1150,7 @@ pub mut:
|
||||||
|
|
||||||
pub struct ComptimeCall {
|
pub struct ComptimeCall {
|
||||||
pub:
|
pub:
|
||||||
|
pos token.Position
|
||||||
has_parens bool // if $() is used, for vfmt
|
has_parens bool // if $() is used, for vfmt
|
||||||
method_name string
|
method_name string
|
||||||
method_pos token.Position
|
method_pos token.Position
|
||||||
|
@ -1235,18 +1237,16 @@ pub fn (expr Expr) position() token.Position {
|
||||||
return expr.decl.pos
|
return expr.decl.pos
|
||||||
}
|
}
|
||||||
ArrayDecompose, ArrayInit, AsCast, Assoc, AtExpr, BoolLiteral, CallExpr, CastExpr, ChanInit,
|
ArrayDecompose, ArrayInit, AsCast, Assoc, AtExpr, BoolLiteral, CallExpr, CastExpr, ChanInit,
|
||||||
CharLiteral, ConcatExpr, Comment, EnumVal, FloatLiteral, GoExpr, Ident, IfExpr, IndexExpr,
|
CharLiteral, ConcatExpr, Comment, ComptimeCall, ComptimeSelector, EnumVal, FloatLiteral,
|
||||||
IntegerLiteral, Likely, LockExpr, MapInit, MatchExpr, None, OffsetOf, OrExpr, ParExpr,
|
GoExpr, Ident, IfExpr, IndexExpr, IntegerLiteral, Likely, LockExpr, MapInit, MatchExpr,
|
||||||
PostfixExpr, PrefixExpr, RangeExpr, SelectExpr, SelectorExpr, SizeOf, SqlExpr, StringInterLiteral,
|
None, OffsetOf, OrExpr, ParExpr, PostfixExpr, PrefixExpr, RangeExpr, SelectExpr, SelectorExpr,
|
||||||
StringLiteral, StructInit, Type, TypeOf, UnsafeExpr {
|
SizeOf, SqlExpr, StringInterLiteral, StringLiteral, StructInit, Type, TypeOf, UnsafeExpr
|
||||||
|
{
|
||||||
return expr.pos
|
return expr.pos
|
||||||
}
|
}
|
||||||
IfGuardExpr {
|
IfGuardExpr {
|
||||||
return expr.expr.position()
|
return expr.expr.position()
|
||||||
}
|
}
|
||||||
ComptimeCall, ComptimeSelector {
|
|
||||||
return expr.left.position()
|
|
||||||
}
|
|
||||||
InfixExpr {
|
InfixExpr {
|
||||||
left_pos := expr.left.position()
|
left_pos := expr.left.position()
|
||||||
right_pos := expr.right.position()
|
right_pos := expr.right.position()
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
import vweb
|
||||||
|
|
||||||
struct App {
|
struct App {
|
||||||
a string
|
a string
|
||||||
b string
|
b string
|
||||||
|
@ -57,8 +59,7 @@ fn comptime_for_fields() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Result {
|
struct Result {}
|
||||||
}
|
|
||||||
|
|
||||||
fn (mut a App) my_method(p string) Result {
|
fn (mut a App) my_method(p string) Result {
|
||||||
println('>>>> ${@FN} | p: $p')
|
println('>>>> ${@FN} | p: $p')
|
||||||
|
@ -81,6 +82,10 @@ fn comptime_call_dollar_method() {
|
||||||
handle_conn<App>(mut app)
|
handle_conn<App>(mut app)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn (mut app App) create() vweb.Result {
|
||||||
|
return $vweb.html()
|
||||||
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
comptime_for()
|
comptime_for()
|
||||||
comptime_for_with_if()
|
comptime_for_with_if()
|
||||||
|
|
|
@ -47,6 +47,7 @@ fn (mut p Parser) comp_call() ast.ComptimeCall {
|
||||||
scope: 0
|
scope: 0
|
||||||
}
|
}
|
||||||
p.check(.dollar)
|
p.check(.dollar)
|
||||||
|
start_pos := p.prev_tok.position()
|
||||||
error_msg := 'only `\$tmpl()`, `\$env()`, `\$embed_file()` and `\$vweb.html()` comptime functions are supported right now'
|
error_msg := 'only `\$tmpl()`, `\$env()`, `\$embed_file()` and `\$vweb.html()` comptime functions are supported right now'
|
||||||
if p.peek_tok.kind == .dot {
|
if p.peek_tok.kind == .dot {
|
||||||
n := p.check_name() // skip `vweb.html()` TODO
|
n := p.check_name() // skip `vweb.html()` TODO
|
||||||
|
@ -146,6 +147,14 @@ fn (mut p Parser) comp_call() ast.ComptimeCall {
|
||||||
path += '.html'
|
path += '.html'
|
||||||
}
|
}
|
||||||
if !os.exists(path) {
|
if !os.exists(path) {
|
||||||
|
if p.pref.is_fmt {
|
||||||
|
return ast.ComptimeCall{
|
||||||
|
scope: 0
|
||||||
|
is_vweb: true
|
||||||
|
method_name: n
|
||||||
|
pos: start_pos.extend(p.prev_tok.position())
|
||||||
|
}
|
||||||
|
}
|
||||||
if is_html {
|
if is_html {
|
||||||
p.error('vweb HTML template "$path" not found')
|
p.error('vweb HTML template "$path" not found')
|
||||||
} else {
|
} else {
|
||||||
|
@ -211,6 +220,7 @@ fn (mut p Parser) comp_call() ast.ComptimeCall {
|
||||||
vweb_tmpl: file
|
vweb_tmpl: file
|
||||||
method_name: n
|
method_name: n
|
||||||
args_var: literal_string_param
|
args_var: literal_string_param
|
||||||
|
pos: start_pos.extend(p.prev_tok.position())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -288,6 +298,7 @@ fn (mut p Parser) at() ast.AtExpr {
|
||||||
|
|
||||||
fn (mut p Parser) comptime_selector(left ast.Expr) ast.Expr {
|
fn (mut p Parser) comptime_selector(left ast.Expr) ast.Expr {
|
||||||
p.check(.dollar)
|
p.check(.dollar)
|
||||||
|
start_pos := p.prev_tok.position()
|
||||||
if p.peek_tok.kind == .lpar {
|
if p.peek_tok.kind == .lpar {
|
||||||
method_pos := p.tok.position()
|
method_pos := p.tok.position()
|
||||||
method_name := p.check_name()
|
method_name := p.check_name()
|
||||||
|
@ -311,6 +322,7 @@ fn (mut p Parser) comptime_selector(left ast.Expr) ast.Expr {
|
||||||
method_pos: method_pos
|
method_pos: method_pos
|
||||||
scope: p.scope
|
scope: p.scope
|
||||||
args_var: args_var
|
args_var: args_var
|
||||||
|
pos: start_pos.extend(p.prev_tok.position())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mut has_parens := false
|
mut has_parens := false
|
||||||
|
@ -328,5 +340,6 @@ fn (mut p Parser) comptime_selector(left ast.Expr) ast.Expr {
|
||||||
has_parens: has_parens
|
has_parens: has_parens
|
||||||
left: left
|
left: left
|
||||||
field_expr: expr
|
field_expr: expr
|
||||||
|
pos: start_pos.extend(p.prev_tok.position())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue