File tree 2 files changed +37
-1
lines changed
2 files changed +37
-1
lines changed Original file line number Diff line number Diff line change @@ -144,7 +144,15 @@ def compile_keyword_args
144
144
line " throw new Error('expecting keyword arg: #{ arg_name } ')"
145
145
line "}"
146
146
when :kwrestarg
147
- nil
147
+ arg_name = kwarg [ 1 ]
148
+ var_name = variable ( arg_name . to_s )
149
+
150
+ kwarg_names = @kwargs . select do |kw |
151
+ [ :kwoptarg , :kwarg ] . include? kw . first
152
+ end . map { |kw | "#{ kw [ 1 ] . to_s . inspect } : true" }
153
+
154
+ used_args = "{#{ kwarg_names . join ',' } }"
155
+ line "#{ var_name } = Opal.kwrestargs($kwargs, #{ used_args } );"
148
156
else
149
157
raise "unknown kwarg type #{ kwarg . first } "
150
158
end
Original file line number Diff line number Diff line change 890
890
return [ value ] ;
891
891
} ;
892
892
893
+ /**
894
+ Used to get a list of rest keyword arguments. Method takes the given
895
+ keyword args, i.e. the hash literal passed to the method containing all
896
+ keyword arguemnts passed to method, as well as the used args which are
897
+ the names of required and optional arguments defined. This method then
898
+ just returns all key/value pairs which have not been used, in a new
899
+ hash literal.
900
+
901
+ @param given_args [Hash] all kwargs given to method
902
+ @param used_args [Object<String: true>] all keys used as named kwargs
903
+ @return [Hash]
904
+ */
905
+ Opal . kwrestargs = function ( given_args , used_args ) {
906
+ var keys = [ ] ,
907
+ map = { } ,
908
+ key = null ,
909
+ given_map = given_args . smap ;
910
+
911
+ for ( key in given_map ) {
912
+ if ( ! used_args [ key ] ) {
913
+ keys . push ( key ) ;
914
+ map [ key ] = given_map [ key ] ;
915
+ }
916
+ }
917
+
918
+ return Opal . hash2 ( keys , map ) ;
919
+ } ;
920
+
893
921
/*
894
922
* Call a ruby method on a ruby object with some arguments:
895
923
*
You can’t perform that action at this time.
0 commit comments