js2 0.3.9 → 0.3.12
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 +15 -0
- data/lib/js2/browser.js +2 -2
- data/lib/js2/js2.js +50 -14
- data/lib/js2/rack.rb +17 -10
- metadata +2 -2
data/CHANGELOG
CHANGED
@@ -1,3 +1,18 @@
|
|
1
|
+
0.3.12
|
2
|
+
* fixed parse error in JSMLElement
|
3
|
+
* Yanking 0.3.11
|
4
|
+
|
5
|
+
0.3.11
|
6
|
+
* fixed minor issue finding Rails.root in rack
|
7
|
+
* Yanking 0.3.10
|
8
|
+
|
9
|
+
0.3.10
|
10
|
+
* fixed foreach boolean
|
11
|
+
* fixed https://github.com/jeffsu/js2/issues#issue/1
|
12
|
+
* Rack to try and use Rails.root otherwise, use cwd
|
13
|
+
* put boundaries in lexer for js2 keywords
|
14
|
+
* made regex/divide solution more robust
|
15
|
+
|
1
16
|
0.3.9
|
2
17
|
* fixed regex/divide issue
|
3
18
|
|
data/lib/js2/browser.js
CHANGED
@@ -19,7 +19,7 @@ function mainFunction (arg) {
|
|
19
19
|
|
20
20
|
var JS2 = root.JS2 = mainFunction;
|
21
21
|
var js2 = root.js2 = JS2;
|
22
|
-
js2.VERSION = "0.3.
|
22
|
+
js2.VERSION = "0.3.12";
|
23
23
|
|
24
24
|
JS2.ROOT = JS2;
|
25
25
|
|
@@ -168,7 +168,7 @@ function mainFunction (arg) {
|
|
168
168
|
|
169
169
|
var assert = {
|
170
170
|
'eq': function(expected, actual) { if (expected != actual) console.log("Expected "+expected+", but got "+actual+".") },
|
171
|
-
'isFalse': function(val) { if (val) console.log("Expected false, but got "+val+".") },
|
171
|
+
'isFalse': function(val) { if (val) console.log("Expected false, but got "+JSON.stringify(val)+".") },
|
172
172
|
'isTrue': function(val) { if (!val) console.log("Expected true, but got " +val+".") }
|
173
173
|
};
|
174
174
|
|
data/lib/js2/js2.js
CHANGED
@@ -14,7 +14,7 @@ function mainFunction (arg) {
|
|
14
14
|
|
15
15
|
var JS2 = root.JS2 = mainFunction;
|
16
16
|
var js2 = root.js2 = JS2;
|
17
|
-
js2.VERSION = "0.3.
|
17
|
+
js2.VERSION = "0.3.12";
|
18
18
|
|
19
19
|
JS2.ROOT = JS2;
|
20
20
|
|
@@ -162,7 +162,7 @@ function mainFunction (arg) {
|
|
162
162
|
|
163
163
|
var assert = {
|
164
164
|
'eq': function(expected, actual) { if (expected != actual) console.log("Expected "+expected+", but got "+actual+".") },
|
165
|
-
'isFalse': function(val) { if (val) console.log("Expected false, but got "+val+".") },
|
165
|
+
'isFalse': function(val) { if (val) console.log("Expected false, but got "+JSON.stringify(val)+".") },
|
166
166
|
'isTrue': function(val) { if (!val) console.log("Expected true, but got " +val+".") }
|
167
167
|
};
|
168
168
|
|
@@ -180,19 +180,19 @@ function mainFunction (arg) {
|
|
180
180
|
[ 'COMMENT', "\\/\\/|/\\*" ],
|
181
181
|
[ 'SPACE', "\\s+" ],
|
182
182
|
[ 'REGEX', "\\/" ],
|
183
|
-
[ 'CLASS', "
|
184
|
-
[ 'MODULE', "
|
185
|
-
[ 'STATIC', "
|
186
|
-
[ 'include', "
|
183
|
+
[ 'CLASS', "\\bclass\\b" ],
|
184
|
+
[ 'MODULE', "\\bmodule\\b" ],
|
185
|
+
[ 'STATIC', "\\bstatic\\b" ],
|
186
|
+
[ 'include', "\\binclude\\b" ],
|
187
187
|
[ 'SHORT_FUNCT', "#\\{|#\\(" ],
|
188
|
-
[ 'FOREACH', "
|
189
|
-
[ 'CURRY', "
|
188
|
+
[ 'FOREACH', "\\bforeach\\b" ],
|
189
|
+
[ 'CURRY', "\\bcurry\\b" ],
|
190
190
|
[ 'IDENT', "[\\w$]+" ],
|
191
191
|
[ 'DSTRING', '"' ],
|
192
192
|
[ 'SSTRING', "'" ],
|
193
193
|
[ 'ISTRING', "%\\{" ],
|
194
194
|
[ 'HEREDOC', "<<-?\\w+" ],
|
195
|
-
[ 'OPERATOR', "[^\\w]" ]
|
195
|
+
[ 'OPERATOR', "(?:\\+\\+|\\-\\-|[^\\w])" ]
|
196
196
|
];
|
197
197
|
|
198
198
|
var IDS = {};
|
@@ -343,7 +343,7 @@ function mainFunction (arg) {
|
|
343
343
|
|
344
344
|
JS2.Lexer.ISTRING.extend('Lexer.HEREDOC', {
|
345
345
|
REGEX_NEXT: /^((\\#|[^#])*?)(#{|\r?\n)/,
|
346
|
-
REGEX: /^<<\-?(\w+)\r?\n/m,
|
346
|
+
REGEX: /^<<\-?(\w+)(?::(\w+))?\s*\r?\n/m,
|
347
347
|
ID: IDS.HEREDOC,
|
348
348
|
consume: function() {
|
349
349
|
var m = this.tokens.match(this.REGEX);
|
@@ -376,10 +376,13 @@ function mainFunction (arg) {
|
|
376
376
|
|
377
377
|
var next = this.tokens.match(this.REGEX_NEXT);
|
378
378
|
if (next) {
|
379
|
+
var str = next[1];
|
380
|
+
var ending = next[2];
|
381
|
+
|
379
382
|
if (next[1]) {
|
380
383
|
this.tokens.chomp(next[1].length);
|
381
384
|
this.tokens.push([ (first ? '' : '+') + '"' + this.sanitize(next[1]) + '\\\\n"', IDS.DSTRING ]);
|
382
|
-
}
|
385
|
+
}
|
383
386
|
|
384
387
|
if (next[3] == '#{') {
|
385
388
|
this.tokens.chomp(1);
|
@@ -474,7 +477,7 @@ function mainFunction (arg) {
|
|
474
477
|
|
475
478
|
divideCompatible: function() {
|
476
479
|
var last = this.lastNonSpace();
|
477
|
-
return (last[0].match(/(\}|\))
|
480
|
+
return (last[0].match(/(\}|\)|\+\+|\-\-)$/) || last[1] == IDS.IDENT);
|
478
481
|
},
|
479
482
|
|
480
483
|
lastNonSpace: function() {
|
@@ -1242,7 +1245,7 @@ JS2.Class.extend('Updater', function(KLASS, OO){
|
|
1242
1245
|
|
1243
1246
|
OO.addMember("matchDirs",function (dir) {
|
1244
1247
|
var subs = this.fs.readdir(dir);
|
1245
|
-
for(var
|
1248
|
+
for(var _i1=0,_c1=subs,_l1=_c1.length,sub;(sub=_c1[_i1])||(_i1<_l1);_i1++){
|
1246
1249
|
var path = dir + '/' + sub;
|
1247
1250
|
if (this.fs.isDirectory(path)) {
|
1248
1251
|
this.fs.mkdir(path.replace(this.inDir, this.outDir));
|
@@ -1484,7 +1487,7 @@ JS2.Class.extend('JSML', function(KLASS, OO){
|
|
1484
1487
|
this.current = this.root;
|
1485
1488
|
this.stack = [ this.root ];
|
1486
1489
|
|
1487
|
-
for(var
|
1490
|
+
for(var _i1=0,_c1=lines,_l1=_c1.length,l;(l=_c1[_i1])||(_i1<_l1);_i1++){
|
1488
1491
|
if (l.match(/^\s*$/)) continue;
|
1489
1492
|
this.processLine(l);
|
1490
1493
|
}
|
@@ -1525,6 +1528,39 @@ JS2.Class.extend('JSML', function(KLASS, OO){
|
|
1525
1528
|
});
|
1526
1529
|
|
1527
1530
|
JS2.Class.extend('JSMLElement', function(KLASS, OO){
|
1531
|
+
OO.addMember("SCOPE_REGEX",/(\s+)(.*)/);
|
1532
|
+
OO.addMember("TOKEN_REGEX",/^(%|#|\.)([\w-]+)/);
|
1533
|
+
OO.addMember("JS_REGEX",/^(-|=)(.*)$/);
|
1534
|
+
|
1535
|
+
OO.addMember("initialize",function (line) {
|
1536
|
+
var spaceMatch = line.match(this.SCOPE_REGEX);
|
1537
|
+
this.scope = spaceMatch[1].length / 2;
|
1538
|
+
|
1539
|
+
this.classes = [];
|
1540
|
+
this.nodeID = null;
|
1541
|
+
|
1542
|
+
this.parse(spaceMatch[2]);
|
1543
|
+
});
|
1544
|
+
|
1545
|
+
OO.addMember("parse",function (line) {
|
1546
|
+
var self = this;
|
1547
|
+
line = line.replace(this.TOKEN_REGEX, function(match, type, name){
|
1548
|
+
switch(type) {
|
1549
|
+
case '%': this.nodeType = name; break;
|
1550
|
+
case '#': this.classes.push(name); break;
|
1551
|
+
case '.': this.nodeID = name; break;
|
1552
|
+
}
|
1553
|
+
return '';
|
1554
|
+
});
|
1555
|
+
|
1556
|
+
line = line.replace(this.JS_OUT_REGEX, function(match, type, content){
|
1557
|
+
switch(type) {
|
1558
|
+
case '=': this.jsEQ = content; break;
|
1559
|
+
case '-': this.jsExec = content; break;
|
1560
|
+
}
|
1561
|
+
return '';
|
1562
|
+
});
|
1563
|
+
});
|
1528
1564
|
});
|
1529
1565
|
|
1530
1566
|
|
data/lib/js2/rack.rb
CHANGED
@@ -3,19 +3,24 @@ require 'yaml'
|
|
3
3
|
module JS2
|
4
4
|
# this is a hack for now until I can get v8 stable
|
5
5
|
class Rack
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
'bin' => (`which js2`.chomp rescue nil),
|
12
|
-
'copy_js2' => true
|
13
|
-
}
|
6
|
+
def get_root
|
7
|
+
@root ||= defined?(Rails) ? Rails.root : File.expand_path(Dir.getwd)
|
8
|
+
puts "ROOT:#{@root}"
|
9
|
+
return @root
|
10
|
+
end
|
14
11
|
|
15
12
|
def initialize(app)
|
16
13
|
@app = app
|
17
14
|
|
18
|
-
|
15
|
+
default = {
|
16
|
+
'source_dir' => "#{get_root}/app/js2",
|
17
|
+
'target_dir' => "#{get_root}/public/javascripts",
|
18
|
+
'bin' => (`which js2`.chomp rescue nil),
|
19
|
+
'copy_js2' => true
|
20
|
+
}
|
21
|
+
|
22
|
+
|
23
|
+
config = YAML.load_file(get_root + '/config/js2.yml') rescue default
|
19
24
|
|
20
25
|
@source_dir = config['source_dir'] || './app/js2'
|
21
26
|
@target_dir = config['target_dir'] || './public/javascripts'
|
@@ -31,9 +36,11 @@ module JS2
|
|
31
36
|
|
32
37
|
def call(env)
|
33
38
|
if @copy_js2
|
34
|
-
to_file =
|
39
|
+
to_file = "#{get_root}/public/javascripts/js2.js"
|
35
40
|
unless File.exists?(to_file)
|
36
41
|
from_file = JS2::ROOT + '/js2/browser.js'
|
42
|
+
puts "--- #{get_root}"
|
43
|
+
puts "#{from_file} #{to_file}"
|
37
44
|
File.open(to_file, 'w') { |f| f << File.read(from_file) }
|
38
45
|
end
|
39
46
|
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: js2
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.3.
|
5
|
+
version: 0.3.12
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Jeff Su
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-03-
|
13
|
+
date: 2011-03-31 00:00:00 +08:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|