js2 0.0.10 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. data/Manifest +42 -0
  2. data/README.md +65 -0
  3. data/Rakefile +19 -35
  4. data/bin/js2 +80 -66
  5. data/config/js2.yml +2 -0
  6. data/js2.gemspec +33 -0
  7. data/lib/js2/{haml_parser.rb → parser/haml.rb} +2 -2
  8. data/lib/js2/{haml_engine.rb → parser/haml_engine.rb} +1 -1
  9. data/lib/js2/parser/lexer.rb +37 -0
  10. data/lib/js2/{parser.rb → parser/tokenizer.rb} +157 -143
  11. data/lib/js2/{replace.rb → ragel/helper.rb} +16 -5
  12. data/lib/js2/ragel/tokenizer.rl +561 -0
  13. data/lib/js2/{tokenizer.rl.erb → ragel/tokenizer.rl.erb} +12 -19
  14. data/lib/js2/standard/factory.rb +289 -0
  15. data/lib/js2/standard/node.rb +75 -0
  16. data/lib/js2/util/compilation.rb +77 -0
  17. data/lib/js2/util/config.rb +84 -0
  18. data/lib/js2/util/exec.rb +34 -0
  19. data/lib/js2/util/file_handler.rb +73 -0
  20. data/lib/js2/{js2bootstrap.js2 → util/js2bootstrap.js2} +12 -68
  21. data/lib/js2/util/processor.rb +88 -0
  22. data/lib/js2/util/rdoc.rb +35 -0
  23. data/lib/js2/{sel_decorator.rb → util/sel_decorator.rb} +11 -1
  24. data/lib/js2.rb +22 -45
  25. data/test/compiled/bar.js +3 -0
  26. data/test/compiled/basic.comp.js +31 -0
  27. data/test/compiled/basic.js +27 -0
  28. data/test/compiled/foo.js +3 -0
  29. data/test/fixtures/bar.js2 +3 -0
  30. data/test/fixtures/basic.js2 +27 -0
  31. data/test/fixtures/basic.js2.haml +4 -0
  32. data/test/fixtures/basic.js2.yml +5 -0
  33. data/test/fixtures/curry.js2 +5 -0
  34. data/test/fixtures/foo.js2 +3 -0
  35. data/test/fixtures/member.js2 +14 -0
  36. data/test/fixtures/private.js2 +5 -0
  37. data/test/fixtures/property.js2 +4 -0
  38. data/test/test_helper.rb +25 -0
  39. data/test/test_js2.rb +43 -0
  40. data/wiki/features.md +106 -0
  41. data/wiki/installation.md +53 -0
  42. metadata +89 -83
  43. data/Changelog +0 -33
  44. data/History.txt +0 -4
  45. data/Manifest.txt +0 -35
  46. data/PostInstall.txt +0 -7
  47. data/README +0 -69
  48. data/README.rdoc +0 -69
  49. data/README.txt +0 -69
  50. data/examples/js2.yml +0 -8
  51. data/examples/test.yml +0 -5
  52. data/lib/javascript/sel_marker.js2 +0 -150
  53. data/lib/javascript/test.js2 +0 -73
  54. data/lib/js2/config.rb +0 -39
  55. data/lib/js2/daemon.rb +0 -35
  56. data/lib/js2/file_handler.rb +0 -91
  57. data/lib/js2/foo.js2.haml +0 -3
  58. data/lib/js2/js2.js +0 -110
  59. data/lib/js2/processor.rb +0 -112
  60. data/lib/js2/test/selenium.rb +0 -119
  61. data/lib/js2/test/selenium_element.rb +0 -234
  62. data/lib/js2/test/selenium_helper.rb +0 -27
  63. data/lib/js2/tree.rb +0 -351
  64. data/lib/js2/universe.rb +0 -123
  65. data/lib/tasks/js2.rake +0 -9
  66. data/website/index.txt +0 -86
  67. /data/{LICENSE → lib/js2/standard/class_node.rb} +0 -0
@@ -1,119 +0,0 @@
1
- begin
2
- require 'rubygems'
3
- gem "selenium-client", ">=1.2.16"
4
- require "selenium/client"
5
- require "yaml"
6
- require "json"
7
-
8
-
9
- class JS2::Test::Selenium < Selenium::Client::Driver
10
- attr_accessor :reference_dir, :child_selector
11
-
12
- RESET_SEL_MARKER = "if (window.JS2) { window.USE_SEL_MARKER = window.JS2.SEL_MARKER; }"
13
-
14
- class << self
15
-
16
- def logger
17
- return @logger || nil
18
- end
19
-
20
- def logger= (a_logger)
21
- @logger = a_logger
22
- end
23
-
24
- def connect (config_file, env = nil)
25
- config = YAML.load_file(config_file)
26
- config = config[env] if env
27
-
28
- reference_dir = config['reference_dir'] || './spec/js2refs'
29
- config = config['selenium']
30
- ret = self.new( :host => config['host'] || 'localhost',
31
- :port => config['port'] || 4444,
32
- :browser => config['browser'] || '*firefox',
33
- :url => config['url'] || 'http://www.factual.com',
34
-
35
- :timeout_in_second => config[:timeout] || 60,
36
- :highlight_located_element => config['highlight'] || false,
37
- :javascript_framework => config['framework'] || 'jquery' )
38
-
39
- # hack to get an instance var in.
40
- ret.reference_dir = reference_dir
41
- ret.child_selector = nil
42
- return ret
43
- end
44
- end
45
-
46
- def get_sel_markers ()
47
- json = self.execute("JS2.SEL_MARKER.toJson()")
48
- struct = JSON.parse(json)
49
- puts YAML::dump(struct)
50
- end
51
-
52
- def open!(uri)
53
- ret = self.open(uri)
54
- self.wait_for_page
55
- self.set_sel_marker!
56
- return ret
57
- end
58
-
59
- def execute (js)
60
- puts js
61
- return self.js_eval("window.eval(#{js.to_json});")
62
- end
63
-
64
- def wait_for_html(html, timeout=15000)
65
- js = %{window.document.body.innerHTML.toLowerCase().replace(/[\"\']/g, '').indexOf(#{html.to_json.downcase}) >= 0;}
66
- begin
67
- self.wait_for_condition(js, timeout)
68
- return true
69
- rescue Selenium::CommandError
70
- return false
71
- end
72
- end
73
-
74
- def uri
75
- return self.location.sub(%r|^https?://(.*)?/|, '/')
76
- end
77
-
78
- def get_helper (klass_name)
79
- klass = klass_name
80
- ref_file = %|#{@reference_dir}/#{klass_name}.yml|
81
- lookup = if File.exist? ref_file
82
- YAML.load_file(ref_file)
83
- else
84
- Hash.new
85
- end
86
-
87
- return JS2::Test::SeleniumHelper.new(klass_name, lookup, self)
88
- end
89
-
90
- def child_scope (selector)
91
- js = "if (window.JS2) { window.USE_SEL_MARKER = window.JS2.SEL_MARKER."
92
- js << selector.split('>').collect { |s| "children.#{s}" }.join('.')
93
- js << '};'
94
- @keep_selector = js
95
- self.set_sel_marker!
96
- yield()
97
- @keep_selector = nil
98
- self.set_sel_marker!
99
- end
100
-
101
- def set_sel_marker!
102
- self.execute(@keep_selector || RESET_SEL_MARKER)
103
- end
104
-
105
- def scope(klass_name)
106
- self.set_sel_marker!
107
- helper = get_helper(klass_name)
108
- if block_given?
109
- yield(helper)
110
- else
111
- return helper
112
- end
113
- end
114
-
115
- end
116
-
117
- rescue Exception => e
118
- warn "No support for selenium"
119
- end
@@ -1,234 +0,0 @@
1
- class JS2::Test::SeleniumElement
2
- attr_accessor :options
3
- QUICK_WAIT_FOR = 5
4
- AJAX_TIME_OUT = 60
5
- def initialize (sel, klass, key, selector = nil)
6
- @sel = sel
7
- @key = key
8
- @klass = klass
9
- @selector = selector
10
- end
11
-
12
- def log (str)
13
- if JS2::Test::Selenium.logger
14
- JS2::Test::Selenium.logger.info(str)
15
- end
16
- end
17
-
18
- def raw
19
- ret = self.class.new(@sel, @klass, @key, @selector)
20
- ret.options[:raw] = true
21
- return ret
22
- end
23
-
24
- def check
25
- return execute('checked=true')
26
- end
27
-
28
- def uncheck
29
- return execute('checked=false')
30
- end
31
-
32
- def checked?
33
- return execute('checked')
34
- end
35
-
36
- def execute (str)
37
- wait_for_ajax
38
- return @sel.execute(get_js_locator() + '.' + str)
39
- end
40
-
41
- def visible?(wait_for = nil)
42
- return self.check_attribute(':visible', true, wait_for);
43
- end
44
-
45
- def sel_visible?()
46
- return @sel.visible?(get_ele())
47
- end
48
-
49
- def hidden?(wait_for = nil)
50
- return self.check_attribute(':visible', false, wait_for);
51
- end
52
-
53
- def find (str, idx = 0)
54
- selector = "window.$(#{get_js_locator()}).find(#{str.to_json})[#{idx}]"
55
- return self.class.new(@sel, @klass, @key, selector)
56
- end
57
-
58
- def filter (str, idx = 0)
59
- selector = "window.$(#{get_js_locator()}).filter(#{str.to_json})[#{idx}]"
60
- return self.class.new(@sel, @klass, @key, selector)
61
- end
62
-
63
- def get (idx)
64
- # when jqObjects in //@+
65
- selector = "#{get_js_locator()}[#{idx}][0]"
66
- return self.class.new(@sel, @klass, @key, selector)
67
- end
68
-
69
- def [] (idx)
70
- selector = "#{get_js_locator()}[#{idx}]"
71
- return self.class.new(@sel, @klass, @key, selector)
72
- end
73
-
74
- def attr (attr)
75
- get_ele()
76
- js = %{window.$(#{get_js_locator()}).attr(#{attr.to_json});}
77
- return @sel.js_eval(js)
78
- end
79
-
80
- def jq_attr (attr)
81
- return @sel.execute("window.$(#{get_js_locator()}).#{attr};")
82
- end
83
-
84
- def check_attribute (attr, val, wait_for = nil)
85
- wait_for ||= QUICK_WAIT_FOR
86
- get_ele()
87
- js = %{window.$(#{get_js_locator()}).is('#{attr}') == #{val.to_json};}
88
- begin
89
- log "Waiting for #{@key}.#{attr} to be #{val.to_json}... Waiting #{wait_for} secs."
90
- @sel.wait_for_condition(js, wait_for)
91
- rescue Selenium::CommandError
92
- return false
93
- end
94
-
95
- return true
96
- end
97
-
98
- def containsp? (str, timeout=QUICK_WAIT_FOR)
99
- wait_for_ajax
100
- js = %{window.$(#{get_js_locator()}).html().toLowerCase().replace(/[\"\']/g, '').indexOf(#{str.to_json.downcase}) >= 0;}
101
- begin
102
- @sel.wait_for_condition(js, timeout)
103
- return true
104
- rescue Selenium::CommandError
105
- return false
106
- end
107
- end
108
-
109
- def contains? (str,timeout=QUICK_WAIT_FOR)
110
- wait_for_ajax
111
- js = %{window.$(#{get_js_locator()}).html().indexOf(#{str.to_json}) >= 0;}
112
- begin
113
- @sel.wait_for_condition(js, timeout)
114
- return true
115
- rescue Selenium::CommandError
116
- return false
117
- end
118
- end
119
-
120
- def click (options = {})
121
- @sel.click(get_ele(), options)
122
- end
123
-
124
- def text
125
- return @sel.text(get_ele())
126
- end
127
-
128
- def get_value
129
- return @sel.get_value(get_ele())
130
- end
131
-
132
- def click! (options = {})
133
- @sel.click(get_ele(), options)
134
- @sel.wait_for_page
135
- end
136
-
137
- def mouse_up ()
138
- trigger("LEFT_MOUSE_UP")
139
- end
140
-
141
- def mouse_down ()
142
- trigger("LEFT_MOUSE_DOWN")
143
- end
144
-
145
- def mouse_over
146
- @sel.mouse_over(get_ele())
147
- end
148
-
149
- def mouse_out
150
- @sel.mouse_out(get_ele())
151
- end
152
-
153
- def key_down(value)
154
- @sel.key_down(get_ele(), value)
155
- end
156
-
157
- def type (*params)
158
- elem = get_ele()
159
- @sel.type(elem, *params)
160
- @sel.fire_event(elem, 'blur')
161
- end
162
-
163
- def select(params)
164
- elem = get_ele()
165
- @sel.select(elem, params)
166
- @sel.fire_event(elem, 'blur')
167
- end
168
-
169
- def html ()
170
- wait_for_ajax
171
- js = get_js_locator()
172
- return @sel.js_eval("#{js}.innerHTML;")
173
- end
174
-
175
- private
176
-
177
- def get_locator
178
- js = get_js_locator()
179
- dom_locator = "dom=#{js};"
180
- return dom_locator
181
- end
182
-
183
- def get_ele
184
- real_locator = get_locator()
185
- wait_for_ele()
186
-
187
- return real_locator
188
- end
189
-
190
- def get_js_locator
191
- if @selector
192
- return @selector
193
- end
194
-
195
- filtered_locator = @key.to_s
196
- int = ''
197
-
198
- if m = filtered_locator.match(/([^\[\]]+)(\[([^\]]*)\])/)
199
- log "filtered: #{filtered_locator} #{m.inspect}"
200
- filtered_locator = m[1]
201
- int = ', ' + m[3] if m[3]
202
- end
203
-
204
- funct = 'getVal'
205
- get_val = "window.USE_SEL_MARKER.#{funct}('#{@klass}', '#{filtered_locator}'#{int})"
206
-
207
- return get_val
208
- end
209
-
210
- def wait_for_ele ()
211
- real_locator = get_locator
212
- puts "waiting for #{real_locator}"
213
- wait_for_ajax
214
- @sel.wait_for_condition real_locator, QUICK_WAIT_FOR
215
- puts "found #{real_locator}"
216
- end
217
-
218
- def wait_for_ajax
219
- @sel.wait_for_condition('selenium.browserbot.getCurrentWindow().jQuery.active == 0', AJAX_TIME_OUT)
220
- end
221
-
222
- def trigger (event)
223
- get_ele()
224
- @sel.execute("window.$(#{get_js_locator}).trigger(JS2.SEL_EVENTS.#{event})")
225
- end
226
-
227
- def method_missing (method, *arg)
228
- if @sel.respond_to?(method)
229
- return @sel.send(method, get_js_locator, *arg)
230
- else
231
- raise "Method missing: #{method}"
232
- end
233
- end
234
- end
@@ -1,27 +0,0 @@
1
- class JS2::Test::SeleniumHelper
2
- attr_accessor :klass, :lookup
3
-
4
- def initialize (klass, lookup, sel)
5
- @klass = klass
6
- @lookup = lookup
7
- @sel = sel
8
- @all_eles = Hash.new
9
- end
10
-
11
- def [] (key, tail = nil)
12
- key = key.to_s
13
-
14
- return @all_eles[key] if @all_eles[key]
15
-
16
- # TODO: support inheritence
17
- #raise "invalid key #{key}" unless @lookup[key]
18
-
19
- return @all_eles[key] = JS2::Test::SeleniumElement.new(@sel, @klass, key, tail)
20
- end
21
-
22
- def type_form (params = {})
23
- params.each_pair do |k,v|
24
- self[k].type(v)
25
- end
26
- end
27
- end
data/lib/js2/tree.rb DELETED
@@ -1,351 +0,0 @@
1
- class JS2::Node < Array
2
- attr_accessor :start_idx, :static
3
- SEL = JS2::SelDecorator.new
4
-
5
- def initialize (start_idx, string, static = false)
6
- @static = static
7
- @stack = []
8
- @start_idx = start_idx
9
- @current_idx = @start_idx
10
- @string = string
11
- end
12
-
13
- def set_child (node)
14
- len = node.start_idx - @current_idx
15
- if len > 0
16
- self << @string[@current_idx, len]
17
- end
18
-
19
- self << node
20
- end
21
-
22
-
23
- def stop_child (idx)
24
- @current_idx = idx
25
- end
26
-
27
- def to_s
28
- ret = []
29
- last_idx = self.length - 1
30
-
31
- self.each_with_index do |s, i|
32
- if i == 0
33
- ret << self.first_string(s)
34
- elsif i == last_idx
35
- ret << self.last_string(s)
36
- else
37
- ret << s.to_s
38
- end
39
- end
40
-
41
- if last_idx == 0
42
- ret << self.last_string('')
43
- end
44
-
45
- return ret.join('')
46
- end
47
-
48
- def first_string (s)
49
- return s.to_s
50
- end
51
-
52
- def last_string (s)
53
- return s.to_s
54
- end
55
-
56
- def mark (idx)
57
- len = idx - @current_idx
58
- if len > 0
59
- self << @string[@current_idx, len]
60
- end
61
-
62
- @current_idx = idx
63
- end
64
-
65
- def stop (idx)
66
- len = idx - @current_idx
67
- if len > 0
68
- self << @string[@current_idx, len]
69
- end
70
- self.setup!
71
- end
72
-
73
- def setup!
74
- end
75
-
76
- def reset
77
- end
78
- end
79
-
80
- class JS2::Stuff < JS2::Node
81
- def to_s
82
- str = super
83
- str = SEL.translate(str, nil, false)
84
- return str
85
- end
86
- end
87
-
88
- class JS2::Class < JS2::Node
89
- REGEX = /^(\s*class|module)\s+([\w\.]+)\s+(extends\s+([\w\.]+))?\s*\{(.*)/m
90
- attr_accessor :name, :extends
91
-
92
- def setup!
93
- m = self[0].match(REGEX)
94
- @name = m[2]
95
- @extends = m[4]
96
- @start = m[5]
97
- end
98
-
99
- def createName
100
- return 'createClass'
101
- end
102
-
103
- def first_string (s)
104
- extends = nil
105
- if @extends
106
- extends = "#{@name}.oo('extends', #{@extends});"
107
- end
108
-
109
-
110
- return %|JS2.OO.#{createName}("#{@name}"); #{extends} (function (K,Package) {var self=K; var _super=JS2.OO['super']; #{@start}|
111
- end
112
-
113
- def last_string (s)
114
- pkg = @name.split(/\./)
115
- pkg.pop()
116
-
117
- if pkg.empty?
118
- pkg = 'null'
119
- else
120
- pkg = pkg.join('.')
121
- end
122
-
123
- #pkg = pkg.length > 0 ? pkg : 'null'
124
- return s.to_s + ")(#{@name}, #{pkg});"
125
- end
126
-
127
- def to_s
128
- str = super
129
- str = SEL.translate(str, @name, true)
130
- return str
131
- end
132
- end
133
-
134
- class JS2::Property < JS2::Node
135
- REGEX = /(\s*)property(\s+)([\w+,\s]+\w)(\s*)/
136
- def setup!
137
- m = first.match(REGEX)
138
- @space = m[1]
139
- @mid_space = m[2]
140
- @list = m[3].split(/,/).collect { |i| i.strip }
141
- @end_space = m[4]
142
- end
143
-
144
- def to_s
145
- return %|#{@space}K.oo('property',#{@mid_space}[ #{@list.collect { |i| "'#{i}'" }.join(',')} ]);|
146
- end
147
- end
148
-
149
- class JS2::Accessor < JS2::Node
150
- REGEX = /(\s*)accessor(\s+)([\w+,\s]+\w)(\s*)/
151
- def setup!
152
- m = first.match(REGEX)
153
- @space = m[1]
154
- @mid_space = m[2]
155
- @list = m[3].split(/,/).collect { |i| i.strip }
156
- @end_space = m[4]
157
- end
158
-
159
- def to_s
160
- return %|#{@space}K.oo('accessor',#{@mid_space}[ #{@list.collect { |i| "'#{i}'" }.join(',')} ]);|
161
- end
162
-
163
- end
164
-
165
-
166
- class JS2::Foreach < JS2::Node
167
- # start var iterator array
168
- REGEX = /(\s*)foreach\s*\(\s*var\s*([\$\w]+)(\s*:\s*([\$\w]))?\s*in\s*([^\s]+)\s*\)/
169
- attr_accessor :iterator, :item, :array
170
- @@inc = 0
171
-
172
- def setup!
173
- m = first.match(REGEX)
174
- @start = m[1]
175
- @item = m[2]
176
- @iterator = m[4]
177
- @array = m[5]
178
- end
179
-
180
- def first_string (s)
181
- it = iterator
182
-
183
- unless iterator
184
- it = 'it' + @@inc.to_s
185
- @@inc += 1
186
- end
187
-
188
- len = it + '__len'
189
- arr = it + '__arr'
190
-
191
- return %(#{@start}for (var #{it}=0,#{@item},#{arr}=#{@array},#{len}=#{arr}.length; (#{@item}=#{arr}[#{it}]) || #{it}<#{len}; #{it}++))
192
- end
193
-
194
- def self.reset
195
- @@inc = 0
196
- end
197
-
198
- end
199
-
200
- class JS2::Module < JS2::Class
201
- def createName
202
- return 'createModule'
203
- end
204
- end
205
-
206
- class JS2::Private < JS2::Node
207
- def to_s
208
- return first.sub(/private/m, '// private')
209
- end
210
- end
211
-
212
-
213
-
214
- class JS2::Include < JS2::Node
215
- def first_string (s)
216
- return s.sub(/include\s*/, "K.oo('include', ").sub(/;$/, ');');
217
- end
218
- end
219
-
220
- class JS2::Member < JS2::Node
221
- def first_string (s)
222
- method = 'member'
223
-
224
- if s.match(/^(\s*)(static)\s*/)
225
- method = 'staticMember'
226
- s = s.sub(/static\s*/, '')
227
- end
228
-
229
- return s.sub(/var\s*([\$\w]+)/) { "K.oo('#{method}', '" + $1 + "'" }.sub(/;$/, ');').sub(/\s*=/, ', ');
230
- end
231
- end
232
-
233
- class JS2::Curry < JS2::Node
234
- REGEX = %r|^curry\s*([^\{]*)?\{(.*)$|m
235
- REGEX_WITH = %r|with\s+\(([^)]*)\)|
236
- REGEX_ARGS = %r|^\s*\(([^)]*)\)|
237
-
238
- def setup!
239
- m = first.match(REGEX)
240
- @decl = m[1].strip
241
- @stop = m[2]
242
-
243
- @args = ''
244
- @in_scoped = ''
245
- @scoped = ''
246
-
247
- if m = @decl.match(REGEX_WITH)
248
- in_scoped = m[1].split(',').collect { |v| v.strip }
249
- scoped = in_scoped.collect { |v| v == 'this' ? 'self' : v }
250
- if in_scoped.length
251
- @scoped = scoped.join(', ')
252
- @in_scoped = in_scoped.join(', ')
253
- end
254
- end
255
-
256
- if m = @decl.match(%r|^\s*\(([^)]*)\)|)
257
- @args = m[1].strip
258
- end
259
- end
260
-
261
- def first_string (s)
262
- return %|(function (#{@scoped}) { return function (#{@args}) {#{@stop}|
263
- end
264
-
265
- def last_string (s)
266
- return s + %|})(#{@in_scoped})|
267
- end
268
- end
269
-
270
- class JS2::Method < JS2::Node
271
- REGEX = /^(\s*)(static\s+)?function\s+([\$\w\.]+)\s*\(([^)]*)\)\s*\{(.*)/m
272
- attr_accessor :name, :args
273
-
274
- def setup!
275
- m = self[0].match(REGEX)
276
- @space = m[1]
277
- @static = m[2]
278
- @name = m[3]
279
- @args = m[4]
280
- @start = m[5]
281
- end
282
-
283
- def first_string (s)
284
- m = static ? 'staticMember' : 'method'
285
- return %|#{@space}K.oo('#{m}', "#{@name}", function (#{args}) {#{@start}|
286
- end
287
-
288
- def last_string (s)
289
- return %|#{s});|
290
- end
291
- end
292
-
293
- class JS2::Ignore < JS2::Node
294
- def to_s
295
- return ''
296
- end
297
- end
298
-
299
-
300
-
301
- class JS2::ParserHelper
302
- attr_accessor :filename, :classes, :extra
303
-
304
- TYPES = {
305
- :CLASS => JS2::Class,
306
- :FOREACH => JS2::Foreach,
307
- :INCLUDE => JS2::Include,
308
- :METHOD => JS2::Method,
309
- :MEMBER => JS2::Member,
310
- :MODULE => JS2::Module,
311
- :STUFF => JS2::Stuff,
312
- :STATIC => JS2::Ignore,
313
- :PRIVATE => JS2::Private,
314
- :CURRY => JS2::Curry,
315
- :PROPERTY => JS2::Property,
316
- :ACCESSOR => JS2::Accessor
317
- }
318
-
319
- def initialize (code)
320
- @code = code
321
- @stack = [ JS2::Stuff.new(0, @code) ]
322
- @classes = []
323
- @extra = []
324
- end
325
-
326
- def mark_node (idx)
327
- @stack.last.mark(idx)
328
- end
329
-
330
- def start_node (type, start_idx, static = false)
331
- klass = TYPES[type] || JS2::Node
332
- new_node = klass.new(start_idx, @code, static)
333
- if type == :CLASS || type == :MODULE
334
- @classes.push(new_node)
335
- end
336
-
337
- @stack.last.set_child(new_node) if @stack.last
338
- @stack.push << new_node
339
- end
340
-
341
- def stop_node (stop_idx)
342
- last = @stack.pop
343
- last.stop(stop_idx) if last
344
- @stack.last.stop_child(stop_idx) if @stack.last
345
- end
346
-
347
- def to_s
348
- return @stack.collect { |i| i.to_s }.join('') + (extra.empty? ? '' : ("\n" + extra.join("\n")))
349
- end
350
- end
351
-