Permalink
Browse files

Perlito5 - js - exists with array index

  • Loading branch information...
1 parent 890d83b commit a3b2e64ea0a242c8b1a3b9b89b00797b39a502d2 @fglock committed Oct 15, 2013
Showing with 47 additions and 2 deletions.
  1. +14 −0 html/perlito5.js
  2. +8 −2 html/perlito5to6.html
  3. +11 −0 perlito5.pl
  4. +14 −0 src5/lib/Perlito5/Javascript2/Emitter.pm
View
@@ -14021,10 +14021,24 @@ return (p5call(p5pkg["Perlito5::AST::Apply"]["v__"], "emit_javascript2_set_list"
(function () { throw(p5context([('(' + p5str(p5call(v_v, "emit_javascript2", [], 0)) + ')._hash_.hasOwnProperty(' + p5str(p5call(p5call(v_arg, "autoquote", p5list_to_a((v_arg || (v_arg = new p5HashRef({})))._hash_.p5hget('index_exp')), 0), "emit_javascript2", [v_level], 0)) + ')')], p5want)) })();
})();
};
+ if ( p5bool(p5call(v_arg, "isa", ['Perlito5::AST::Index'], 0)) ) {
+ (function () {
+ var v_v;
+ v_v = (p5call(v_arg, "obj", [], 0));
+ if ( (p5bool(p5call(v_v, "isa", ['Perlito5::AST::Var'], 0)) && (p5str(p5call(v_v, "sigil", [], 0)) == '$')) ) {
+ v_v = (p5call(p5pkg["Perlito5::AST::Var"], "new", p5list_to_a('sigil', '@', 'namespace', p5call(v_v, "namespace", [], 1), 'name', p5call(v_v, "name", [], 1)), 0));
+ (function () { throw(p5context([('(' + p5str(p5call(v_v, "emit_javascript2", [], 0)) + ').hasOwnProperty(' + p5str(p5call((v_arg || (v_arg = new p5HashRef({})))._hash_.p5hget('index_exp'), "emit_javascript2", [v_level], 0)) + ')')], p5want)) })();
+ };
+ (function () { throw(p5context([('(' + p5str(p5call(v_v, "emit_javascript2", [], 0)) + ')._array_.hasOwnProperty(' + p5str(p5call((v_arg || (v_arg = new p5HashRef({})))._hash_.p5hget('index_exp'), "emit_javascript2", [v_level], 0)) + ')')], p5want)) })();
+ })();
+ };
if ( p5bool(p5call(v_arg, "isa", ['Perlito5::AST::Call'], 0)) ) {
if ( (p5str(p5call(v_arg, "method", [], 0)) == 'postcircumfix:<{ }>') ) {
(function () { throw(p5context([('(' + p5str(p5call(p5call(v_arg, "invocant", [], 0), "emit_javascript2", [], 0)) + ')._hash_.hasOwnProperty(' + p5str(p5call(p5call(p5pkg["Perlito5::AST::Lookup"], "autoquote", p5list_to_a((v_arg || (v_arg = new p5HashRef({})))._hash_.p5hget('arguments')), 0), "emit_javascript2", [v_level], 0)) + ')')], p5want)) })();
};
+ if ( (p5str(p5call(v_arg, "method", [], 0)) == 'postcircumfix:<[ ]>') ) {
+ (function () { throw(p5context([('(' + p5str(p5call(p5call(v_arg, "invocant", [], 0), "emit_javascript2", [], 0)) + ')._array_.hasOwnProperty(' + p5str(p5call((v_arg || (v_arg = new p5HashRef({})))._hash_.p5hget('arguments'), "emit_javascript2", [v_level], 0)) + ')')], p5want)) })();
+ };
};
if ( (p5bool(p5call(v_arg, "isa", ['Perlito5::AST::Var'], 0)) && (p5str(p5call(v_arg, "sigil", [], 0)) == '&')) ) {
(function () {
View
@@ -27,9 +27,15 @@
my @x = qw/ x y z /;
print $x[1], "\n";
-for my $x (reverse @x) { say $x }
+for my $x ( reverse @x ) { say $x }
-for (my $i=0; $i<10; $i++) { say $i }
+for ( my $i = 0 ; $i < 10 ; $i++ ) { say $i }
+
+sub mysub {
+ my $x = shift;
+ my $y = shift;
+ $x + $y;
+}
</textarea><br/>
<input type="button" value="Execute" onclick="execute()"/>
View
@@ -9791,10 +9791,21 @@ package Perlito5::AST::Apply;
}
return('(' . $v->emit_javascript2() . ')._hash_.hasOwnProperty(' . $arg->autoquote($arg->{'index_exp'})->emit_javascript2($level) . ')')
}
+ if ($arg->isa('Perlito5::AST::Index')) {
+ my $v = $arg->obj();
+ if ($v->isa('Perlito5::AST::Var') && $v->sigil() eq '$') {
+ $v = Perlito5::AST::Var->new('sigil' => '@', 'namespace' => $v->namespace(), 'name' => $v->name());
+ return('(' . $v->emit_javascript2() . ').hasOwnProperty(' . $arg->{'index_exp'}->emit_javascript2($level) . ')')
+ }
+ return('(' . $v->emit_javascript2() . ')._array_.hasOwnProperty(' . $arg->{'index_exp'}->emit_javascript2($level) . ')')
+ }
if ($arg->isa('Perlito5::AST::Call')) {
if ($arg->method() eq 'postcircumfix:<{ }>') {
return('(' . $arg->invocant()->emit_javascript2() . ')._hash_.hasOwnProperty(' . Perlito5::AST::Lookup->autoquote($arg->{'arguments'})->emit_javascript2($level) . ')')
}
+ if ($arg->method() eq 'postcircumfix:<[ ]>') {
+ return('(' . $arg->invocant()->emit_javascript2() . ')._array_.hasOwnProperty(' . $arg->{'arguments'}->emit_javascript2($level) . ')')
+ }
}
if ($arg->isa('Perlito5::AST::Var') && $arg->sigil() eq '&') {
my $name = $arg->{'name'};
@@ -2338,10 +2338,24 @@ package Perlito5::AST::Apply;
}
return '(' . $v->emit_javascript2() . ')._hash_.hasOwnProperty(' . $arg->autoquote($arg->{index_exp})->emit_javascript2($level) . ')';
}
+ if ($arg->isa( 'Perlito5::AST::Index' )) {
+ my $v = $arg->obj;
+ if ( $v->isa('Perlito5::AST::Var')
+ && $v->sigil eq '$'
+ )
+ {
+ $v = Perlito5::AST::Var->new( sigil => '@', namespace => $v->namespace, name => $v->name );
+ return '(' . $v->emit_javascript2() . ').hasOwnProperty(' . $arg->{index_exp}->emit_javascript2($level) . ')';
+ }
+ return '(' . $v->emit_javascript2() . ')._array_.hasOwnProperty(' . $arg->{index_exp}->emit_javascript2($level) . ')';
+ }
if ($arg->isa( 'Perlito5::AST::Call' )) {
if ( $arg->method eq 'postcircumfix:<{ }>' ) {
return '(' . $arg->invocant->emit_javascript2() . ')._hash_.hasOwnProperty(' . Perlito5::AST::Lookup->autoquote($arg->{arguments})->emit_javascript2($level) . ')';
}
+ if ( $arg->method eq 'postcircumfix:<[ ]>' ) {
+ return '(' . $arg->invocant->emit_javascript2() . ')._array_.hasOwnProperty(' . $arg->{arguments}->emit_javascript2($level) . ')';
+ }
}
if ( $arg->isa('Perlito5::AST::Var')
&& $arg->sigil eq '&'

0 comments on commit a3b2e64

Please sign in to comment.