js2 0.0.8 → 0.0.9
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.
- data/Changelog +3 -0
- data/Manifest.txt +13 -28
- data/Rakefile +19 -19
- data/bin/js2 +48 -41
- data/lib/javascript/sel_marker.js2 +3 -3
- data/lib/js2/config.rb +6 -1
- data/lib/js2/{process/file_handler.rb → file_handler.rb} +15 -19
- data/lib/js2/foo.js2.haml +3 -0
- data/lib/js2/{process/haml_engine.rb → haml_engine.rb} +1 -1
- data/lib/js2/{parser/haml.rb → haml_parser.rb} +20 -7
- data/lib/js2/js2.js +108 -0
- data/lib/js2/js2bootstrap.js2 +455 -0
- data/lib/js2/parser.rb +3542 -0
- data/lib/js2/processor.rb +14 -65
- data/lib/js2/replace.rb +106 -0
- data/lib/js2/{decorator/test.rb → sel_decorator.rb} +11 -14
- data/{meta/c_tokenizer.rl.erb → lib/js2/tokenizer.rl.erb} +155 -123
- data/lib/js2/tree.rb +340 -0
- data/lib/js2/universe.rb +101 -0
- data/lib/js2.rb +31 -77
- data/lib/tasks/js2.rake +1 -1
- metadata +15 -29
- data/lib/js2/ast/class_node.rb +0 -105
- data/lib/js2/ast/comment_node.rb +0 -2
- data/lib/js2/ast/haml_node.rb +0 -22
- data/lib/js2/ast/include_node.rb +0 -11
- data/lib/js2/ast/inherited_node.rb +0 -7
- data/lib/js2/ast/member_node.rb +0 -18
- data/lib/js2/ast/method_node.rb +0 -29
- data/lib/js2/ast/module_node.rb +0 -6
- data/lib/js2/ast/node.rb +0 -14
- data/lib/js2/ast/nodes.rb +0 -123
- data/lib/js2/ast/stuff_node.rb +0 -6
- data/lib/js2/decorator/app.rb +0 -7
- data/lib/js2/decorator/cleanser.rb +0 -54
- data/lib/js2/decorator/standard.rb +0 -103
- data/lib/js2/parser/fast.rb +0 -3959
- data/lib/js2/process/universe.rb +0 -89
- data/lib/js2/test/selenium.rb +0 -109
- data/lib/js2/test/selenium_element.rb +0 -234
- data/lib/js2/test/selenium_helper.rb +0 -27
- data/lib/js2bootstrap.js2 +0 -274
- data/meta/replace.rb +0 -126
data/lib/js2bootstrap.js2
DELETED
@@ -1,274 +0,0 @@
|
|
1
|
-
var JS2 = {};
|
2
|
-
JS2.createClass = function (name) {
|
3
|
-
var splitName = name.split('.');
|
4
|
-
var namespace = window;
|
5
|
-
while (splitName.length) {
|
6
|
-
var subName = splitName.shift();
|
7
|
-
if (! namespace[subName]) {
|
8
|
-
namespace =
|
9
|
-
namespace[subName] =
|
10
|
-
function () { if (this.initialize) this.initialize.apply(this, arguments) };
|
11
|
-
} else {
|
12
|
-
namespace = namespace[subName];
|
13
|
-
}
|
14
|
-
}
|
15
|
-
}
|
16
|
-
|
17
|
-
JS2.getClass = function (name) {
|
18
|
-
var splitName = name.split('.');
|
19
|
-
var namespace = window;
|
20
|
-
|
21
|
-
while (splitName.length) {
|
22
|
-
var subName = splitName.shift();
|
23
|
-
if (namespace[subName]) {
|
24
|
-
namespace = namespace[subName];
|
25
|
-
} else {
|
26
|
-
return null;
|
27
|
-
}
|
28
|
-
}
|
29
|
-
|
30
|
-
return namespace;
|
31
|
-
}
|
32
|
-
|
33
|
-
function _super () {
|
34
|
-
var method = arguments.callee.caller._super;
|
35
|
-
if (! method) return;
|
36
|
-
var self = arguments[0];
|
37
|
-
var args = [];
|
38
|
-
for (var i=1,len=arguments.length;i<len;i++) {
|
39
|
-
args.push(arguments[i]);
|
40
|
-
}
|
41
|
-
return method.apply(self, args);
|
42
|
-
}
|
43
|
-
|
44
|
-
|
45
|
-
class JS2.Observer {
|
46
|
-
function initialize (owner) {
|
47
|
-
this.lookupBefore = {};
|
48
|
-
this.lookupAfter = {};
|
49
|
-
|
50
|
-
this.replaced = {};
|
51
|
-
this.replacedValues = {};
|
52
|
-
}
|
53
|
-
|
54
|
-
function replaceFunction (owner, eventName) {
|
55
|
-
if (this.replaced[eventName]) return;
|
56
|
-
|
57
|
-
this.replacedValues[eventName] = owner[eventName];
|
58
|
-
this.replaced[eventName] = true;
|
59
|
-
owner[eventName] = this.getTrigger(eventName);
|
60
|
-
}
|
61
|
-
|
62
|
-
function trigger (owner, eventName, args) {
|
63
|
-
var beforeChain = this.lookupBefore[eventName];
|
64
|
-
if (beforeChain) this.executeChain(beforeChain, args);
|
65
|
-
|
66
|
-
var funct = this.replacedValues[eventName];
|
67
|
-
if (funct) funct.apply(owner, args);
|
68
|
-
|
69
|
-
var afterChain = this.lookupAfter[eventName];
|
70
|
-
if (afterChain) this.executeChain(afterChain, args);
|
71
|
-
}
|
72
|
-
|
73
|
-
function addListener (eventName, funct, before) {
|
74
|
-
var lookup = before ? this.lookupBefore : this.lookupAfter;
|
75
|
-
|
76
|
-
var chain = lookup[eventName] = lookup[eventName] || [];
|
77
|
-
chain.push(funct);
|
78
|
-
}
|
79
|
-
|
80
|
-
private
|
81
|
-
|
82
|
-
function getTrigger (eventName) {
|
83
|
-
return function () { this.__observer.trigger(this, eventName, arguments); };
|
84
|
-
}
|
85
|
-
|
86
|
-
function executeChain (chain, args) {
|
87
|
-
foreach (var f:i in chain) if (f) f.apply(this, args);
|
88
|
-
}
|
89
|
-
}
|
90
|
-
|
91
|
-
module JS2.Observable {
|
92
|
-
function addListener (eventName, funct, before) {
|
93
|
-
if (! this.__observer) this.__observer = new Factual.Core.Observer();
|
94
|
-
|
95
|
-
var id = this.__observer.addListener(eventName, funct, before);
|
96
|
-
this.__observer.replaceFunction(this, eventName);
|
97
|
-
return id;
|
98
|
-
}
|
99
|
-
|
100
|
-
function triggerEvent (eventName, args) {
|
101
|
-
if (this.__observer) this.__observer.trigger(this, eventName, args);
|
102
|
-
}
|
103
|
-
}
|
104
|
-
|
105
|
-
|
106
|
-
class JS2.App.Notifier {
|
107
|
-
var autoInc = 1;
|
108
|
-
|
109
|
-
function initialize () {
|
110
|
-
this.chains = {};
|
111
|
-
this.autoInc = 1;
|
112
|
-
this.id = this['class'].prototype.autoInc;
|
113
|
-
this['class'].prototype.autoInc++;
|
114
|
-
}
|
115
|
-
|
116
|
-
function register (comp) {
|
117
|
-
if (! comp.__notifier_ids) {
|
118
|
-
comp.__notifier_ids = {};
|
119
|
-
}
|
120
|
-
|
121
|
-
if (! comp.__notifier_ids[this.id]) {
|
122
|
-
comp.__notifier_ids[this.id] = this.autoInc;
|
123
|
-
this.autoInc++;
|
124
|
-
}
|
125
|
-
|
126
|
-
for (var key in comp) {
|
127
|
-
if (key.indexOf('e_') == 0) {
|
128
|
-
var eventType = key.substr(2);
|
129
|
-
if (! this.chains[eventType]) this.chains[eventType] = [];
|
130
|
-
this.chains[eventType].push([ comp, comp[key] ]);
|
131
|
-
}
|
132
|
-
}
|
133
|
-
|
134
|
-
comp.notify = curry with (this) {
|
135
|
-
self.notify.apply(self, arguments);
|
136
|
-
};
|
137
|
-
}
|
138
|
-
|
139
|
-
function remove (comp) {
|
140
|
-
var id = comp.__notifier_id;
|
141
|
-
for (var key in this.chains) {
|
142
|
-
var newChain = [];
|
143
|
-
foreach (var ele:j in chain) {
|
144
|
-
if (ele[0].__notifier_id[this.id] != id) {
|
145
|
-
newChain.push(ele);
|
146
|
-
}
|
147
|
-
}
|
148
|
-
|
149
|
-
this.chains[key] = newChain;
|
150
|
-
}
|
151
|
-
}
|
152
|
-
|
153
|
-
function registerListener (listener) {
|
154
|
-
for (var key in listener) {
|
155
|
-
var funct = listener[key];
|
156
|
-
if (typeof funct != 'function') continue;
|
157
|
-
if (! this.chains[key]) this.chains[key] = [];
|
158
|
-
this.chains[key].push([ listener, funct ]);
|
159
|
-
}
|
160
|
-
}
|
161
|
-
|
162
|
-
function notify () {
|
163
|
-
var eventType = arguments[0];
|
164
|
-
var args;
|
165
|
-
|
166
|
-
// optimize for 1 argument
|
167
|
-
if (arguments.length == 2) {
|
168
|
-
args = [ arguments[1] ];
|
169
|
-
} else {
|
170
|
-
args = [];
|
171
|
-
for (var i=1; i<=arguments.length; i++) args.push(arguments[i]);
|
172
|
-
}
|
173
|
-
|
174
|
-
var chain = this.chains[eventType];
|
175
|
-
if (chain) {
|
176
|
-
for (var i=0,pair; pair=chain[i++];) {
|
177
|
-
pair[1].apply(pair[0], args);
|
178
|
-
}
|
179
|
-
}
|
180
|
-
}
|
181
|
-
}
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
class JS2.App {
|
186
|
-
include JS2.Observer;
|
187
|
-
|
188
|
-
function start () {
|
189
|
-
// hack to get notifier
|
190
|
-
this.getNotifier();
|
191
|
-
|
192
|
-
this.build();
|
193
|
-
this.notify('initHTML');
|
194
|
-
this.notify('registerEvents');
|
195
|
-
this.notify('finalize');
|
196
|
-
}
|
197
|
-
|
198
|
-
|
199
|
-
function register (comp) {
|
200
|
-
this.getNotifier().register(comp);
|
201
|
-
}
|
202
|
-
|
203
|
-
function getNotifier () {
|
204
|
-
if (! this._notifier) {
|
205
|
-
this._notifier = new JS2.App.Notifier();
|
206
|
-
this._notifier.register(this);
|
207
|
-
}
|
208
|
-
|
209
|
-
return this._notifier;
|
210
|
-
}
|
211
|
-
|
212
|
-
function build () {
|
213
|
-
var components = {};
|
214
|
-
var template = this.getTemplate();
|
215
|
-
|
216
|
-
// instantiate all components
|
217
|
-
foreach (var config:i in template) {
|
218
|
-
if (!config['class']) alert("Invalid class defined for " + name + ':' + config['class']);
|
219
|
-
var klass = JS2.getClass(config['class']);
|
220
|
-
|
221
|
-
components[config.name] = new klass();
|
222
|
-
this.register(components[config.name]);
|
223
|
-
}
|
224
|
-
|
225
|
-
foreach (var config:i in template) {
|
226
|
-
var name = config.name;
|
227
|
-
var comp = components[name];
|
228
|
-
|
229
|
-
// inject set dependencies as an array
|
230
|
-
if (config.dependencies instanceof Array) {
|
231
|
-
foreach (var dep:j in config.dependencies) {
|
232
|
-
comp[dep] = components[dep];
|
233
|
-
}
|
234
|
-
}
|
235
|
-
|
236
|
-
// as a hash... for use when nickname is not the dependency name
|
237
|
-
else if (config.dependencies instanceof Object) {
|
238
|
-
for (var key in config.dependencies) {
|
239
|
-
comp[key] = components[config.dependencies[key]];
|
240
|
-
}
|
241
|
-
}
|
242
|
-
}
|
243
|
-
|
244
|
-
this.notify('initBaseHTML');
|
245
|
-
|
246
|
-
// handle selectors as root elements
|
247
|
-
foreach (var config:i in template) {
|
248
|
-
var name = config.name;
|
249
|
-
var comp = components[name];
|
250
|
-
|
251
|
-
if (config.selector) comp.$root = this.htmlSelect(this.$root, config.selector);
|
252
|
-
if (config.globalSelector) comp.$root = this.htmlSelect(config.globalSelector);
|
253
|
-
}
|
254
|
-
}
|
255
|
-
|
256
|
-
function htmlSelect (root, text) {
|
257
|
-
alert('html selector not implemented');
|
258
|
-
}
|
259
|
-
|
260
|
-
function getTemplate () {
|
261
|
-
return {};
|
262
|
-
}
|
263
|
-
}
|
264
|
-
|
265
|
-
class JS2.App.JQuery extends JS2.App {
|
266
|
-
function htmlSelect ($root, text) {
|
267
|
-
if (text) {
|
268
|
-
return $root.find(text);
|
269
|
-
} else {
|
270
|
-
return $(root);
|
271
|
-
}
|
272
|
-
}
|
273
|
-
}
|
274
|
-
|
data/meta/replace.rb
DELETED
@@ -1,126 +0,0 @@
|
|
1
|
-
require 'erb'
|
2
|
-
|
3
|
-
LITERALS = [ '!=', '!==', '#', '%', '%=', '&&', '&&=', '&=', '*', '*=', '+', '+=', ',', '-', '-=', '->', '.', '/', '/=', ':', '::', '<', '<<', '<<=', '<=', '=', '==', '===', '>', '>=', '>>', '>>=', '>>>', '>>>=', '?', '@', '[', '^', '^=', '^^', '^^=', '|', '|=', '||', '||=', 'abstract', 'break', 'case', 'catch', 'class', 'const', 'continue', 'debugger', 'default', 'delete', 'do', 'else', 'enum', 'export', 'extends', 'field', 'final', 'finally', 'for', 'function', 'goto', 'if', 'implements', 'import', 'in', 'instanceof', 'native', 'new', 'package', 'private', 'protected', 'public', 'return', 'static', 'switch', 'synchronized', 'throw', 'throws', 'transient', 'try', 'typeof', 'var', 'volatile', 'while', 'with', 'foreach', 'module', 'include' ]
|
4
|
-
|
5
|
-
class Replacer
|
6
|
-
def initialize
|
7
|
-
@types = []
|
8
|
-
end
|
9
|
-
|
10
|
-
def start (type, start_idx = nil)
|
11
|
-
return <<-END
|
12
|
-
in_#{type} = 1;
|
13
|
-
start_#{type} = #{start_idx || 'curr'};
|
14
|
-
line_#{type} = line_number;
|
15
|
-
cb_lvl_#{type} = cb_count;
|
16
|
-
br_lvl_#{type} = br_count;
|
17
|
-
END
|
18
|
-
end
|
19
|
-
|
20
|
-
# directly in
|
21
|
-
def directly_in? (type)
|
22
|
-
return "(cb_lvl_#{type} == (cb_count - 1) && in_#{type} == 1)"
|
23
|
-
end
|
24
|
-
|
25
|
-
def set_static
|
26
|
-
return "rb_funcall2(self, set_static_sym, set_static_argc, set_static_argv);"
|
27
|
-
end
|
28
|
-
|
29
|
-
def def_literals
|
30
|
-
ret = []
|
31
|
-
LITERALS.each do |literal|
|
32
|
-
ret << "'#{literal}' whitespacecharacter* regexpliteral => { };"
|
33
|
-
end
|
34
|
-
ret.join("\n") + "\n"
|
35
|
-
end
|
36
|
-
|
37
|
-
def is? (type)
|
38
|
-
return "strcmp(word, \"#{type.to_s.downcase}\") == 0"
|
39
|
-
end
|
40
|
-
|
41
|
-
def handle_stops (types)
|
42
|
-
ret = ''
|
43
|
-
types.each do |type|
|
44
|
-
ret += <<-END
|
45
|
-
if (in_#{type} && cb_lvl_#{type} == cb_count) {
|
46
|
-
#{self.stop type}
|
47
|
-
}
|
48
|
-
END
|
49
|
-
end
|
50
|
-
|
51
|
-
return ret
|
52
|
-
end
|
53
|
-
|
54
|
-
def handle_semicolon_stops (types)
|
55
|
-
ret = ''
|
56
|
-
types.each do |type|
|
57
|
-
ret += <<-END
|
58
|
-
if (in_#{type} == 1) {
|
59
|
-
#{self.stop type}
|
60
|
-
}
|
61
|
-
END
|
62
|
-
end
|
63
|
-
return ret
|
64
|
-
end
|
65
|
-
|
66
|
-
def declare_vars (types)
|
67
|
-
ret = ''
|
68
|
-
types.each do |type|
|
69
|
-
ret += self.declare(type)
|
70
|
-
end
|
71
|
-
|
72
|
-
return ret
|
73
|
-
end
|
74
|
-
|
75
|
-
def do_next (type, start, stop)
|
76
|
-
return <<-END
|
77
|
-
do_next_argv[0] = sym_#{type};
|
78
|
-
do_next_argv[1] = INT2FIX(#{start});
|
79
|
-
do_next_argv[2] = INT2FIX(#{stop});
|
80
|
-
do_next_argv[3] = INT2FIX(0);
|
81
|
-
rb_funcall2(self, do_next_sym, do_next_argc, do_next_argv);
|
82
|
-
END
|
83
|
-
end
|
84
|
-
|
85
|
-
def stop (type, stop = nil)
|
86
|
-
return <<-END
|
87
|
-
in_#{type} = 0;
|
88
|
-
cb_lvl_#{type} = -1;
|
89
|
-
do_next_argv[0] = sym_#{type};
|
90
|
-
do_next_argv[1] = INT2FIX(start_#{type});
|
91
|
-
do_next_argv[2] = INT2FIX(#{stop || 'curr'});
|
92
|
-
do_next_argv[3] = INT2FIX(0);
|
93
|
-
rb_funcall2(self, do_next_sym, do_next_argc, do_next_argv);
|
94
|
-
END
|
95
|
-
end
|
96
|
-
|
97
|
-
|
98
|
-
def declare (type)
|
99
|
-
return <<-END
|
100
|
-
// #{type}
|
101
|
-
int in_#{type} = 0;
|
102
|
-
int start_#{type} = -1;
|
103
|
-
int line_#{type} = 0;
|
104
|
-
int cb_lvl_#{type} = -1;
|
105
|
-
int br_lvl_#{type} = 0;
|
106
|
-
ID sym_#{type} = ID2SYM(rb_intern("#{type}"));
|
107
|
-
END
|
108
|
-
end
|
109
|
-
|
110
|
-
def set_keyword
|
111
|
-
<<-END
|
112
|
-
for (j=0, i=ts-data; i<te-data; i++) {
|
113
|
-
word[j] = data[i];
|
114
|
-
++j;
|
115
|
-
}
|
116
|
-
word[j] = 0;
|
117
|
-
END
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
replacer = Replacer.new
|
122
|
-
template = ERB.new(File.read('c_tokenizer.rl.erb'), 0, "%<>")
|
123
|
-
|
124
|
-
File.open('final_tokenizer.rl', 'w') do |f|
|
125
|
-
f << template.result(binding)
|
126
|
-
end
|