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

View File

@ -130,26 +130,26 @@ void init_consts();
js_headers = ' js_headers = '
class array_string {} var array_string = function() {}
class array_byte {} var array_byte = function() {}
class array_int {} var array_int = function() {}
class byte {} var byte = function() {}
class double {} var double = function() {}
class int {} var int = function() {}
class f64 {} var f64 = function() {}
class f32 {} var f32 = function() {}
class i64 {} var i64 = function() {}
class i32 {} var i32 = function() {}
class i16 {} var i16 = function() {}
class u64 {} var u64 = function() {}
class u32 {} var u32 = function() {}
class u16 {} var u16 = function() {}
class i8 {} var i8 = function() {}
class u8 {} var u8 = function() {}
class bool {} var bool = function() {}
class rune {} var rune = function() {}
class map_string {} var map_string = function() {}
class map_int {} var map_int = function() {}
function init_consts() { 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) { fn (p mut Parser) gen_fn_decl(f Fn, typ, _str_args string) {
mut str_args := '' mut str_args := ''
for i, arg in f.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 { if i < f.args.len - 1 {
str_args += ', ' str_args += ', '
} }
} }
name := p.table.fn_gen_name(f) name := p.table.fn_gen_name(f)
if f.is_method { 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 { } 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_ { if t.cat != .union_ && t.cat != .struct_ {
continue continue
} }
sb.writeln('class $t.name {') sb.write('\n/**\n')
sb.write('* @typedef { object } $t.name' + 'Type\n')
for field in t.fields { for field in t.fields {
sb.write('\t') sb.writeln('* @property { $field.typ' + '= } $field.name')
sb.write(field.name)
sb.writeln('; // $field.typ')
} }
sb.writeln(' sb.writeln('**/\n')
constructor(obj) { sb.writeln('/** @type { function & $t.name' + 'Type } **/')
obj && Object.assign(this, obj); sb.writeln('var $t.name = function() {}')
}
')
sb.writeln('}\n')
} }
return sb.str() return sb.str()
} }