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

js: no need to generate ES6 classes

This commit is contained in:
vitalyster 2019-09-19 00:03:54 +03:00 committed by Alexander Medvednikov
parent 74b82b688c
commit 377956e969
3 changed files with 33 additions and 50 deletions

View File

@ -6,17 +6,9 @@ matrix:
dist: xenial
sudo: required
addons:
snaps:
- name: node
channel: latest/edge
confinement: classic
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- gcc-5
- g++-5
- make
- build-essential
- libglfw3
- libglfw3-dev
- libfreetype6-dev
@ -39,10 +31,6 @@ matrix:
- glfw
- openssl
script:
- |
if [[ "${TRAVIS_OS_NAME}" == "linux" ]]; then
sudo unlink /usr/bin/gcc && sudo ln -s /usr/bin/gcc-5 /usr/bin/gcc
fi
- |
if [[ "${TRAVIS_OS_NAME}" == "osx" ]]; then
export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/opt/openssl/lib/
@ -82,11 +70,11 @@ script:
if [[ "${TRAVIS_OS_NAME}" == "linux" ]]; then
## aliases do not work for some reason in travis, just use full commands :-|
echo "Nodejs version:"
snap run node --version
node --version
# Build hi.js
echo "fn main(){ println('Hello from V.js') }" > hi.v
./v -o hi.js hi.v
snap run node hi.js
node hi.js
fi
- |
if [[ "${TRAVIS_OS_NAME}" == "osx" ]]; then
@ -95,8 +83,7 @@ script:
# Build hi.js
echo "fn main(){ println('Hello from V.js') }" > hi.v
./v -o hi.js hi.v
## the node on osx requires --harmony-class-fields for now
node --harmony-class-fields hi.js
node hi.js
fi
- |
if [[ "${TRAVIS_OS_NAME}" == "osx" ]]; then

View File

@ -130,26 +130,26 @@ void init_consts();
js_headers = '
class array_string {}
class array_byte {}
class array_int {}
class byte {}
class double {}
class int {}
class f64 {}
class f32 {}
class i64 {}
class i32 {}
class i16 {}
class u64 {}
class u32 {}
class u16 {}
class i8 {}
class u8 {}
class bool {}
class rune {}
class map_string {}
class map_int {}
var array_string = function() {}
var array_byte = function() {}
var array_int = function() {}
var byte = function() {}
var double = function() {}
var int = function() {}
var f64 = function() {}
var f32 = function() {}
var i64 = function() {}
var i32 = function() {}
var i16 = function() {}
var u64 = function() {}
var u32 = function() {}
var u16 = function() {}
var i8 = function() {}
var u8 = function() {}
var bool = function() {}
var rune = function() {}
var map_string = function() {}
var map_int = function() {}
function init_consts() {

View File

@ -20,16 +20,16 @@ fn (p mut Parser) gen_var_decl(name string, is_static bool) string {
fn (p mut Parser) gen_fn_decl(f Fn, typ, _str_args string) {
mut str_args := ''
for i, arg in f.args {
str_args += arg.name + ' /* $arg.typ */ '
str_args += ' /** @type { $arg.typ } **/ ' + arg.name
if i < f.args.len - 1 {
str_args += ', '
}
}
name := p.table.fn_gen_name(f)
if f.is_method {
p.genln('\n${f.receiver_typ}.prototype.${name} = function($str_args)/* $typ */ {')
p.genln('\n${f.receiver_typ}.prototype.${name} = function($str_args) {')
} else {
p.genln('\nfunction $name($str_args) /* $typ */ {')
p.genln('/** @return { $typ } **/\nfunction $name($str_args) {')
}
}
@ -39,18 +39,14 @@ fn types_to_c(types []Type, table &Table) string {
if t.cat != .union_ && t.cat != .struct_ {
continue
}
sb.writeln('class $t.name {')
sb.write('\n/**\n')
sb.write('* @typedef { object } $t.name' + 'Type\n')
for field in t.fields {
sb.write('\t')
sb.write(field.name)
sb.writeln('; // $field.typ')
sb.writeln('* @property { $field.typ' + '= } $field.name')
}
sb.writeln('
constructor(obj) {
obj && Object.assign(this, obj);
}
')
sb.writeln('}\n')
sb.writeln('**/\n')
sb.writeln('/** @type { function & $t.name' + 'Type } **/')
sb.writeln('var $t.name = function() {}')
}
return sb.str()
}