builtin: vfmt every .v file, except vlib/builtin/int_test.v (#9448)

This commit is contained in:
zakuro 2021-03-25 03:39:59 +09:00 committed by GitHub
parent 5d8b9b0151
commit 6bc9ef7373
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
19 changed files with 259 additions and 272 deletions

View file

@ -15,7 +15,7 @@ pub fn println(s any) {
pub fn print(s any) {
// TODO
// $if js.node {
JS.process.stdout.write(s.toString())
JS.process.stdout.write(s.toString())
// } $else {
// panic('Cannot `print` in a browser, use `println` instead')
// }
@ -28,7 +28,7 @@ pub fn eprintln(s any) {
pub fn eprint(s any) {
// TODO
// $if js.node {
JS.process.stderr.write(s.toString())
JS.process.stderr.write(s.toString())
// } $else {
// panic('Cannot `eprint` in a browser, use `eprintln` instead')
// }
@ -68,13 +68,13 @@ pub:
}
pub fn (o Option) str() string {
if o.state == 0 {
return 'Option{ ok }'
}
if o.state == 1 {
return 'Option{ none }'
}
return 'Option{ error: "${o.err}" }'
if o.state == 0 {
return 'Option{ ok }'
}
if o.state == 1 {
return 'Option{ none }'
}
return 'Option{ error: "$o.err" }'
}
pub fn error(s string) Option {
@ -94,5 +94,4 @@ pub fn error_with_code(s string, code int) Option {
code: code
}
}
}

View file

@ -8,13 +8,17 @@
module builtin
pub struct JS.Number {}
pub struct JS.String {
length JS.Number
}
pub struct JS.Boolean {}
pub struct JS.Array {
length JS.Number
}
pub struct JS.Map {}
// Type prototype functions
@ -29,6 +33,7 @@ fn (v JS.Map) toString() JS.String
fn native_str_arr_len(arr []JS.String) int {
len := 0
#len = arr.length
return len
}
@ -41,7 +46,9 @@ fn JS.isFinite(f64) bool
fn JS.decodeURI(string) string
fn JS.decodeURIComponent(string) string
fn JS.encodeURI(string) string
type EncodeURIComponentArg = string | f64 | bool
type EncodeURIComponentArg = bool | f64 | string
fn JS.encodeURIComponent(EncodeURIComponentArg) string
fn JS.escape(string) string
fn JS.unescape(string) string

View file

@ -19,7 +19,7 @@ fn JS.clearTimeout(int)
// TODO: js async attribute
// [js_async]
// fn JS.fetch(RequestInfo, RequestInit) Promise<Response>
fn JS.queueMicrotask(fn())
fn JS.queueMicrotask(fn ())
fn JS.setInterval(any, int, ...any) int
fn JS.setTimeout(any, int, ...any) int
@ -28,8 +28,10 @@ fn JS.blur()
fn JS.captureEvents()
fn JS.close()
fn JS.confirm(string) bool
// fn JS.departFocus(NavigationReason, FocusNavigationOrigin)
fn JS.focus()
// fn JS.getComputedStyle(Element, string | null) CSSStyleDeclaration
// fn JS.getMatchedCSSRules(Element, string | null) CSSRuleList
// fn JS.getSelection() Selection | null
@ -37,6 +39,7 @@ fn JS.focus()
fn JS.moveBy(int, int)
fn JS.moveTo(int, int)
fn JS.msWriteProfilerMark(string)
// fn JS.open(string, string, string, bool) ?Window
// fn JS.postMessage(any, string, []Transferable)
fn JS.print()
@ -44,10 +47,13 @@ fn JS.prompt(string, string) ?string
fn JS.releaseEvents()
fn JS.resizeBy(int, int)
fn JS.resizeTo(int, int)
// fn JS.scroll(ScrollToOptions)
fn JS.scroll(int, int)
//fn JS.scrollBy(ScrollToOptions)
// fn JS.scrollBy(ScrollToOptions)
fn JS.scrollBy(int, int)
// fn JS.scrollTo(ScrollToOptions)
fn JS.scrollTo(int, int)
fn JS.stop()

View file

@ -14,7 +14,6 @@ pub fn (s string) after(dot string) string {
return string(s.str.slice(s.str.lastIndexOf(dot.str) + 1, int(s.str.length)))
}
pub fn (s string) after_char(dot byte) string {
// TODO: Implement after byte
return s
@ -97,7 +96,7 @@ pub fn (s string) starts_with(p string) bool {
}
pub fn (s string) fields() []string {
return []// s.str.split()
return [] // s.str.split()
}
pub fn (s string) find_between(start string, end string) string {
@ -105,9 +104,9 @@ pub fn (s string) find_between(start string, end string) string {
}
// unnecessary in the JS backend, implemented for api parity.
pub fn (s string) free () {}
pub fn (s string) free() {}
pub fn (s string) hash () int {
pub fn (s string) hash() int {
mut h := u32(0)
if h == 0 && s.len > 0 {
for c in s {
@ -161,4 +160,4 @@ pub fn (s string) u32() u32 {
// u64 returns the value of the string as u64 `'1'.u64() == u64(1)`.
pub fn (s string) u64() u64 {
return u64(JS.parseInt(s))
}
}