mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
254 lines
4.5 KiB
JavaScript
254 lines
4.5 KiB
JavaScript
// V_COMMIT_HASH 74686d0
|
|
// V_CURRENT_COMMIT_HASH 577d252
|
|
// Generated by the V compiler
|
|
|
|
"use strict";
|
|
|
|
const _CONSTS = Object.freeze({
|
|
/** @type {number} - i_am_a_const */
|
|
i_am_a_const: 21214,
|
|
/** @type {string} - v_super */
|
|
v_super: "amazing keyword"
|
|
});
|
|
|
|
/* namespace: hello */
|
|
const hello = (function () {
|
|
class A {
|
|
/**
|
|
* @param {{foo?: string}} values - values for this class fields
|
|
* @constructor
|
|
*/
|
|
constructor(values) {
|
|
this.foo = values.foo
|
|
}
|
|
|
|
/**
|
|
* @param {string} s
|
|
* @returns {void}
|
|
*/
|
|
update(s) {
|
|
const a = this;
|
|
a.foo = s;
|
|
}
|
|
}
|
|
|
|
|
|
class B {
|
|
/**
|
|
* @param {{}} values - values for this class fields
|
|
* @constructor
|
|
*/
|
|
constructor(values) {
|
|
}
|
|
}
|
|
|
|
const C = Object.freeze({
|
|
});
|
|
|
|
/**
|
|
* @returns {string}
|
|
*/
|
|
function v_debugger() {
|
|
const v = new B({
|
|
});
|
|
return "Hello";
|
|
}
|
|
|
|
/**
|
|
* @returns {string}
|
|
*/
|
|
function excited() {
|
|
return v_debugger() + "!";
|
|
}
|
|
|
|
/* module exports */
|
|
return {
|
|
A,
|
|
C,
|
|
v_debugger,
|
|
excited,
|
|
};
|
|
})();
|
|
|
|
/* namespace: main */
|
|
const main = (function (hl) {
|
|
class Foo {
|
|
/**
|
|
* @param {{a?: hello["A"]["prototype"]}} values - values for this class fields
|
|
* @constructor
|
|
*/
|
|
constructor(values) {
|
|
this.a = values.a
|
|
}
|
|
}
|
|
|
|
class Companies {
|
|
/**
|
|
* @param {{google?: number, amazon?: boolean, yahoo?: string}} values - values for this class fields
|
|
* @constructor
|
|
*/
|
|
constructor(values) {
|
|
this.google = values.google
|
|
this.amazon = values.amazon
|
|
this.yahoo = values.yahoo
|
|
}
|
|
|
|
/**
|
|
* @returns {number}
|
|
*/
|
|
method() {
|
|
const it = this;
|
|
const ss = new Companies({
|
|
google: 2,
|
|
amazon: true,
|
|
yahoo: "hello"
|
|
});
|
|
/** @type {[number, number]} */
|
|
const [a, b] = hello(2, "google", "not google");
|
|
/** @type {string} - glue */
|
|
const glue = (a > 2 ? "more_glue" : a > 5 ? "more glueee" : "less glue");
|
|
if (a !== 2) {
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
const POSITION = Object.freeze({
|
|
go_back: 0,
|
|
dont_go_back: 1,
|
|
});
|
|
|
|
/**
|
|
* @param {string} v_extends
|
|
* @param {number} v_instanceof
|
|
* @returns {void}
|
|
*/
|
|
function v_class(v_extends, v_instanceof) {
|
|
/** @type {number} - v_delete */
|
|
const v_delete = v_instanceof;
|
|
}
|
|
|
|
/* program entry point */
|
|
(async function() {
|
|
console.log("Hello from V.js!");
|
|
/** @type {number} - a */
|
|
let a = 1;
|
|
a *= 2;
|
|
a += 3;
|
|
console.log(a, " == 5");
|
|
const b = new hl.A({
|
|
});
|
|
b.update("an update");
|
|
console.log(b);
|
|
const c = new Foo({
|
|
a: new hl.A({
|
|
})
|
|
});
|
|
c.a.update("another update");
|
|
console.log(c);
|
|
/** @type {string} - v */
|
|
const v = "done";
|
|
{
|
|
/** @type {string} - _ */
|
|
const _ = "block";
|
|
}
|
|
|
|
/** @type {number} - pos */
|
|
const pos = POSITION.go_back;
|
|
/** @type {string} - v_debugger */
|
|
const v_debugger = "JS keywords";
|
|
/** @type {string} - v_await */
|
|
const v_await = _CONSTS.v_super + ": " + v_debugger;
|
|
/** @type {string} - v_finally */
|
|
let v_finally = "implemented";
|
|
console.log(v_await, v_finally);
|
|
/** @type {number} - dun */
|
|
const dun = _CONSTS.i_am_a_const * 20;
|
|
for (let i = 0; i < 10; i++) {
|
|
}
|
|
|
|
for (let i = 0; i < "hello".length; ++i) {
|
|
let x = "hello"[i];
|
|
}
|
|
|
|
for (let x = 1; x < 10; ++x) {
|
|
}
|
|
|
|
/** @type {number[]} - arr */
|
|
const arr = [1, 2, 3, 4, 5];
|
|
for (let _tmp1 = 0; _tmp1 < arr.length; ++_tmp1) {
|
|
let i = arr[_tmp1];
|
|
}
|
|
|
|
/** @type {Map<string, string>} - ma */
|
|
const ma = new Map([
|
|
["str", "done"],
|
|
["ddo", "baba"]
|
|
]);
|
|
for (let [m, n] of ma) {
|
|
/** @type {string} - iss */
|
|
const iss = m;
|
|
}
|
|
|
|
await new Promise(function(resolve){
|
|
async(0, "hello");
|
|
resolve();
|
|
});
|
|
|
|
/** @type {(number: number) => void} - fn_in_var */
|
|
const fn_in_var = function (number) {
|
|
console.log(tos3(`number: ${number}`));
|
|
};
|
|
hl.v_debugger();
|
|
anon_consumer(hl.excited(), function (message) {
|
|
console.log(message);
|
|
});
|
|
})();
|
|
|
|
/**
|
|
* @param {string} greeting
|
|
* @param {(message: string) => void} anon
|
|
* @returns {void}
|
|
*/
|
|
function anon_consumer(greeting, anon) {
|
|
anon(greeting);
|
|
}
|
|
|
|
/**
|
|
* @param {number} num
|
|
* @param {string} def
|
|
* @returns {void}
|
|
*/
|
|
function async(num, def) {
|
|
}
|
|
|
|
/* [inline] */
|
|
/* [deprecated] */
|
|
/**
|
|
* @deprecated
|
|
* @param {number} game_on
|
|
* @param {...string} dummy
|
|
* @returns {[number, number]}
|
|
*/
|
|
function hello(game_on, ...dummy) {
|
|
for (let _tmp2 = 0; _tmp2 < dummy.length; ++_tmp2) {
|
|
let dd = dummy[_tmp2];
|
|
/** @type {string} - l */
|
|
const l = dd;
|
|
}
|
|
|
|
(function defer() {
|
|
/** @type {string} - v_do */
|
|
const v_do = "not";
|
|
})();
|
|
return [game_on + 2, 221];
|
|
}
|
|
|
|
/* module exports */
|
|
return {
|
|
};
|
|
})(hello);
|
|
|
|
|