opal 0.3.19 → 0.3.20
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/.gitignore +3 -1
- data/Gemfile +3 -2
- data/README.md +304 -48
- data/Rakefile +1 -2
- data/core/alpha.rb +2 -1
- data/core/array.rb +92 -96
- data/core/basic_object.rb +1 -10
- data/core/boolean.rb +6 -18
- data/core/class.rb +9 -10
- data/core/comparable.rb +1 -1
- data/core/enumerable.rb +11 -11
- data/core/enumerator.rb +2 -10
- data/core/error.rb +16 -31
- data/core/hash.rb +32 -36
- data/core/json.rb +50 -0
- data/core/kernel.rb +48 -57
- data/core/load_order +3 -5
- data/core/module.rb +37 -35
- data/core/nil_class.rb +4 -0
- data/core/numeric.rb +10 -30
- data/core/proc.rb +1 -1
- data/core/range.rb +3 -4
- data/core/regexp.rb +21 -6
- data/core/runtime.js +278 -370
- data/core/string.rb +21 -37
- data/core/struct.rb +11 -3
- data/core/time.rb +44 -37
- data/lib/opal.rb +3 -3
- data/lib/opal/builder.rb +48 -27
- data/lib/opal/builder_task.rb +3 -20
- data/lib/opal/grammar.rb +18 -13
- data/lib/opal/grammar.y +7 -4
- data/lib/opal/parser.rb +290 -199
- data/lib/opal/scope.rb +187 -176
- data/lib/opal/version.rb +1 -1
- data/test/core/kernel/define_singleton_method_spec.rb +21 -0
- data/test/core/time/at_spec.rb +7 -0
- data/test/core/time/day_spec.rb +5 -0
- data/test/core/time/friday_spec.rb +9 -0
- data/test/core/time/hour_spec.rb +5 -0
- data/test/core/time/min_spec.rb +5 -0
- data/test/core/time/monday_spec.rb +9 -0
- data/test/core/time/month_spec.rb +5 -0
- data/test/core/time/now_spec.rb +5 -0
- data/test/core/time/saturday_spec.rb +9 -0
- data/test/index.html +2 -1
- data/test/language/singleton_class_spec.rb +0 -16
- data/test/opal/array/to_json_spec.rb +7 -0
- data/test/opal/boolean/singleton_class_spec.rb +9 -0
- data/test/opal/boolean/to_json_spec.rb +9 -0
- data/test/opal/hash/to_json_spec.rb +9 -0
- data/test/opal/json/parse_spec.rb +31 -0
- data/test/opal/kernel/to_json_spec.rb +5 -0
- data/test/opal/nil/to_json_spec.rb +5 -0
- data/test/opal/numeric/to_json_spec.rb +6 -0
- data/test/opal/runtime/call_spec.rb +16 -0
- data/test/opal/runtime/defined_spec.rb +11 -0
- data/test/opal/runtime/super_spec.rb +16 -0
- data/test/opal/string/to_json_spec.rb +6 -0
- data/test/spec_helper.rb +1 -3
- metadata +48 -15
- data/core/dir.rb +0 -89
- data/core/file.rb +0 -85
- data/core/match_data.rb +0 -35
- data/core/rational.rb +0 -16
- data/test/core/file/expand_path_spec.rb +0 -20
data/core/file.rb
DELETED
@@ -1,85 +0,0 @@
|
|
1
|
-
class File
|
2
|
-
# Regexp to split path into dirname, basename and extname
|
3
|
-
PATH_RE = /^(.+\/(?!$)|\/)?((?:.+?)?(\.[^.]*)?)$/
|
4
|
-
|
5
|
-
def self.expand_path(path, base = undefined)
|
6
|
-
%x{
|
7
|
-
if (!base) {
|
8
|
-
base = '';
|
9
|
-
}
|
10
|
-
|
11
|
-
path = #{ join(base, path) };
|
12
|
-
|
13
|
-
var parts = path.split('/'), result = [], path;
|
14
|
-
|
15
|
-
for (var i = 0, ii = parts.length; i < ii; i++) {
|
16
|
-
part = parts[i];
|
17
|
-
|
18
|
-
if (part === '..') {
|
19
|
-
result.pop();
|
20
|
-
}
|
21
|
-
else if (part === '.' || part === '') {
|
22
|
-
// ignore?
|
23
|
-
}
|
24
|
-
else {
|
25
|
-
result.push(part);
|
26
|
-
}
|
27
|
-
}
|
28
|
-
|
29
|
-
return result.join('/');
|
30
|
-
}
|
31
|
-
end
|
32
|
-
|
33
|
-
def self.join(*paths)
|
34
|
-
%x{
|
35
|
-
var result = [];
|
36
|
-
|
37
|
-
for (var i = 0, length = paths.length; i < length; i++) {
|
38
|
-
var part = paths[i];
|
39
|
-
|
40
|
-
if (part != '') {
|
41
|
-
result.push(part);
|
42
|
-
}
|
43
|
-
}
|
44
|
-
|
45
|
-
return result.join('/');
|
46
|
-
}
|
47
|
-
end
|
48
|
-
|
49
|
-
def self.dirname(path)
|
50
|
-
%x{
|
51
|
-
var dirname = #{PATH_RE}.exec(path)[1];
|
52
|
-
|
53
|
-
if (!dirname) {
|
54
|
-
return '.';
|
55
|
-
}
|
56
|
-
else if (dirname === '/') {
|
57
|
-
return dirname;
|
58
|
-
}
|
59
|
-
else {
|
60
|
-
return dirname.substring(0, dirname.length - 1);
|
61
|
-
}
|
62
|
-
}
|
63
|
-
end
|
64
|
-
|
65
|
-
def self.extname(path)
|
66
|
-
%x{
|
67
|
-
var extname = #{PATH_RE}.exec(path)[3];
|
68
|
-
|
69
|
-
if (!extname || extname === '.') {
|
70
|
-
return '';
|
71
|
-
}
|
72
|
-
else {
|
73
|
-
return extname;
|
74
|
-
}
|
75
|
-
}
|
76
|
-
end
|
77
|
-
|
78
|
-
def self.basename(path, suffix)
|
79
|
-
""
|
80
|
-
end
|
81
|
-
|
82
|
-
def self.exist?(path)
|
83
|
-
`!!factories[#{ expand_path path }]`
|
84
|
-
end
|
85
|
-
end
|
data/core/match_data.rb
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
class MatchData
|
2
|
-
def [](index)
|
3
|
-
%x{
|
4
|
-
var length = this.$data.length;
|
5
|
-
|
6
|
-
if (index < 0) {
|
7
|
-
index += length;
|
8
|
-
}
|
9
|
-
|
10
|
-
if (index >= length || index < 0) {
|
11
|
-
return null;
|
12
|
-
}
|
13
|
-
|
14
|
-
return this.$data[index];
|
15
|
-
}
|
16
|
-
end
|
17
|
-
|
18
|
-
def length
|
19
|
-
`this.$data.length`
|
20
|
-
end
|
21
|
-
|
22
|
-
def inspect
|
23
|
-
"#<MatchData #{self[0].inspect}>"
|
24
|
-
end
|
25
|
-
|
26
|
-
alias size length
|
27
|
-
|
28
|
-
def to_a
|
29
|
-
`__slice.call(this.$data)`
|
30
|
-
end
|
31
|
-
|
32
|
-
def to_s
|
33
|
-
`this.$data[0]`
|
34
|
-
end
|
35
|
-
end
|
data/core/rational.rb
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
class Rational
|
2
|
-
attr_reader :numerator, :denominator
|
3
|
-
|
4
|
-
def initialize (numerator, denominator = 1)
|
5
|
-
@numerator = numerator
|
6
|
-
@denominator = denominator
|
7
|
-
end
|
8
|
-
|
9
|
-
def to_s
|
10
|
-
"#{numerator}#{"/#{denominator}" if denominator}"
|
11
|
-
end
|
12
|
-
|
13
|
-
def inspect
|
14
|
-
"(#{to_s})"
|
15
|
-
end
|
16
|
-
end
|
@@ -1,20 +0,0 @@
|
|
1
|
-
describe "File.expand_path" do
|
2
|
-
before :each do
|
3
|
-
@base = ""
|
4
|
-
@tmpdir = "tmp"
|
5
|
-
@rootdir = ""
|
6
|
-
end
|
7
|
-
|
8
|
-
it "converts a pathname to an absolute pathname" do
|
9
|
-
File.expand_path('').should == @base
|
10
|
-
File.expand_path('a').should == File.join(@base, "a")
|
11
|
-
File.expand_path('a', nil).should == File.join(@base, 'a')
|
12
|
-
end
|
13
|
-
|
14
|
-
it "converts a pathname to an absolute pathname, using a complete path" do
|
15
|
-
File.expand_path("", "#{@tmpdir}").should == "#{@tmpdir}"
|
16
|
-
File.expand_path("a", "#{@tmpdir}").should == "#{@tmpdir}/a"
|
17
|
-
File.expand_path("../a", "#{@tmpdir}/xxx").should == "#{@tmpdir}/a"
|
18
|
-
File.expand_path(".", "#{@rootdir}").should == "#{@rootdir}"
|
19
|
-
end
|
20
|
-
end
|