liquidscript 0.6.1 → 0.6.2
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.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/bin/lscript +9 -3
- data/lib/liquidscript/compiler/base.rb +6 -5
- data/lib/liquidscript/compiler/icr.rb +23 -0
- data/lib/liquidscript/compiler/icr/expressions.rb +30 -4
- data/lib/liquidscript/compiler/icr/functions.rb +3 -0
- data/lib/liquidscript/errors.rb +6 -0
- data/lib/liquidscript/generator/javascript/literals.rb +16 -9
- data/lib/liquidscript/generator/javascript/metas.rb +1 -6
- data/lib/liquidscript/generator/javascript/objects.rb +1 -8
- data/lib/liquidscript/icr/context.rb +11 -0
- data/lib/liquidscript/scanner/base.rb +7 -4
- data/lib/liquidscript/scanner/liquidscript.rb +16 -8
- data/lib/liquidscript/version.rb +1 -1
- data/spec/fixtures/underscore.js +70 -11
- data/spec/fixtures/underscore.liq +100 -0
- data/spec/liquidscript/compiler/icr_spec.rb +37 -0
- data/spec/liquidscript/scanner/lexer_spec.rb +5 -0
- metadata +3 -3
- data/spec/fixtures/underscore.ls +0 -30
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 294e4c6a0c4f14b51aa48ac555de488b94308ac7
|
4
|
+
data.tar.gz: 412b48e5603ee3871ebc7889c25dfafac288f473
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2f0c008c716700c45618878f3a34dd56fa9d656e52bdff254be77513795e2271bf51757ed67afa1fa34b81adb8e4ac5229f42fcaa761b9141020e909b50c5a0a
|
7
|
+
data.tar.gz: 9b9c4341ec21542b483356a592f85664a40dd607a7f3987561ca407cf31b7d5e0b9b4300466cbf9b929a2956bcbfbfeae59d4e445a6185f86ebbf08c21424f6b
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# 
|
2
2
|
|
3
|
-
[](https://travis-ci.org/redjazz96/liquidscript) [](https://coveralls.io/r/redjazz96/liquidscript?branch=master) [](https://codeclimate.com/github/redjazz96/liquidscript) [](http://badge.fury.io/rb/liquidscript) [](https://gemnasium.com/redjazz96/liquidscript) [](http://choosealicense.com/licenses/mit/)
|
4
4
|
|
5
5
|
A javascript-based language that compiles to javascript.
|
6
6
|
|
data/bin/lscript
CHANGED
@@ -8,10 +8,16 @@ if ARGV.length < 1
|
|
8
8
|
end
|
9
9
|
|
10
10
|
infile = ARGV.shift
|
11
|
-
outfile = ARGV.shift || infile.gsub(/\.
|
11
|
+
outfile = ARGV.shift || infile.gsub(/\.liq\Z/, ".js")
|
12
12
|
|
13
13
|
File.open(infile, "r") do |f|
|
14
|
-
out = Liquidscript::Template.new(f.read).render
|
15
14
|
|
16
|
-
|
15
|
+
begin
|
16
|
+
out = Liquidscript::Template.new(f.read).render
|
17
|
+
File.open(outfile, "w") { |o| o.write out }
|
18
|
+
rescue StandardError => e
|
19
|
+
$stderr.puts "ERROR: #{e.class}: #{e.message}"
|
20
|
+
$stderr.puts e.backtrace[0..5].map { |s| "\t#{s.gsub(/^.*?\/lib\/liquidscript\//, "")}" }.join("\n")
|
21
|
+
end
|
22
|
+
|
17
23
|
end
|
@@ -17,8 +17,9 @@ module Liquidscript
|
|
17
17
|
# the #each function returns an Enumerator, which yields
|
18
18
|
# {Scanner::Token}s.
|
19
19
|
def initialize(scanner)
|
20
|
-
@scanner
|
21
|
-
@
|
20
|
+
@scanner = scanner
|
21
|
+
@iterator = scanner.each
|
22
|
+
@action = Action.new
|
22
23
|
reset!
|
23
24
|
end
|
24
25
|
|
@@ -71,7 +72,7 @@ module Liquidscript
|
|
71
72
|
#
|
72
73
|
# @return [#type?, Blank]
|
73
74
|
def pop
|
74
|
-
@
|
75
|
+
@iterator.next
|
75
76
|
rescue StopIteration
|
76
77
|
scanner_nil
|
77
78
|
end
|
@@ -82,7 +83,7 @@ module Liquidscript
|
|
82
83
|
#
|
83
84
|
# @return [#type, Blank]
|
84
85
|
def peek
|
85
|
-
@
|
86
|
+
@iterator.peek
|
86
87
|
rescue StopIteration
|
87
88
|
scanner_nil
|
88
89
|
end
|
@@ -91,7 +92,7 @@ module Liquidscript
|
|
91
92
|
#
|
92
93
|
# @return [void]
|
93
94
|
def reset!
|
94
|
-
@
|
95
|
+
@iterator.rewind
|
95
96
|
end
|
96
97
|
|
97
98
|
alias_method :rewind, :reset!
|
@@ -15,6 +15,13 @@ module Liquidscript
|
|
15
15
|
include Classes
|
16
16
|
include Helpers
|
17
17
|
|
18
|
+
# (see Base#initialize)
|
19
|
+
def initialize(*)
|
20
|
+
super
|
21
|
+
|
22
|
+
handle_directives
|
23
|
+
end
|
24
|
+
|
18
25
|
# (see Base#reset!)
|
19
26
|
def reset!
|
20
27
|
@top = Liquidscript::ICR::Set.new
|
@@ -34,6 +41,22 @@ module Liquidscript
|
|
34
41
|
def compile_start
|
35
42
|
compile_expression
|
36
43
|
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def handle_directives
|
48
|
+
return unless @scanner.metadata[:directives]
|
49
|
+
|
50
|
+
@scanner.metadata[:directives].each do |meta|
|
51
|
+
case meta[:command]
|
52
|
+
when "allow"
|
53
|
+
variables = meta[:args].split(' ')
|
54
|
+
variables.each { |v| top.context.allow(v.intern) }
|
55
|
+
else
|
56
|
+
raise UnknownDirectiveError.new(meta[:command])
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
37
60
|
end
|
38
61
|
end
|
39
62
|
end
|
@@ -24,6 +24,7 @@ module Liquidscript
|
|
24
24
|
:newline,
|
25
25
|
:istring_begin,
|
26
26
|
:iheredoc_begin,
|
27
|
+
:plus, :minus,
|
27
28
|
:lbrace => :object,
|
28
29
|
:lbrack => :array,
|
29
30
|
:arrow => :function,
|
@@ -34,7 +35,7 @@ module Liquidscript
|
|
34
35
|
:heredoc, :iheredoc
|
35
36
|
] => :heredoc
|
36
37
|
|
37
|
-
if peek? :binop
|
38
|
+
if peek? :binop, :minus, :plus
|
38
39
|
compile_binop(out)
|
39
40
|
elsif peek? :prop
|
40
41
|
compile_property(out)
|
@@ -43,8 +44,21 @@ module Liquidscript
|
|
43
44
|
end
|
44
45
|
end
|
45
46
|
|
47
|
+
def compile_minus
|
48
|
+
shift :minus
|
49
|
+
|
50
|
+
code :neg, compile_vexpression
|
51
|
+
end
|
52
|
+
|
53
|
+
def compile_plus
|
54
|
+
shift :plus
|
55
|
+
|
56
|
+
code :pos, compile_vexpression
|
57
|
+
end
|
58
|
+
|
46
59
|
def compile_binop(left)
|
47
|
-
code :binop, shift(:binop), left,
|
60
|
+
code :binop, shift(:binop, :minus, :plus), left,
|
61
|
+
compile_vexpression
|
48
62
|
end
|
49
63
|
|
50
64
|
def compile_unop
|
@@ -58,12 +72,13 @@ module Liquidscript
|
|
58
72
|
# @return [ICR::Code]
|
59
73
|
def compile_assignment(identifier)
|
60
74
|
shift :equal
|
61
|
-
value = compile_vexpression
|
62
75
|
|
63
76
|
if identifier.type == :identifier
|
64
77
|
variable = set(identifier)
|
78
|
+
value = compile_vexpression
|
65
79
|
variable.value = value
|
66
80
|
else
|
81
|
+
value = compile_vexpression
|
67
82
|
variable = identifier
|
68
83
|
end
|
69
84
|
|
@@ -90,6 +105,17 @@ module Liquidscript
|
|
90
105
|
components << compile_vexpression
|
91
106
|
end
|
92
107
|
|
108
|
+
ident = action do |i|
|
109
|
+
if peek?(:comma)
|
110
|
+
maybe_func = 2
|
111
|
+
components << i
|
112
|
+
elsif peek?(:rparen)
|
113
|
+
components << i
|
114
|
+
else
|
115
|
+
components << compile_identifier(i)
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
93
119
|
loop do
|
94
120
|
case maybe_func
|
95
121
|
when 0
|
@@ -98,7 +124,7 @@ module Liquidscript
|
|
98
124
|
when 1
|
99
125
|
expect :rparen => action.end_loop,
|
100
126
|
:comma => action { maybe_func = 2 },
|
101
|
-
:identifier =>
|
127
|
+
:identifier => ident,
|
102
128
|
:_ => expression
|
103
129
|
when 2
|
104
130
|
expect :rparen => action.end_loop,
|
@@ -42,6 +42,9 @@ module Liquidscript
|
|
42
42
|
:equal => action { compile_assignment(v) },
|
43
43
|
:prop => action { compile_property(v) },
|
44
44
|
:lbrack => action { compile_access(v) },
|
45
|
+
[:binop,
|
46
|
+
:minus,
|
47
|
+
:plus] => action { compile_binop(v) },
|
45
48
|
:unop => action { |o| code :op, v, o },
|
46
49
|
:_ => default || action { v }
|
47
50
|
end
|
data/lib/liquidscript/errors.rb
CHANGED
@@ -14,6 +14,12 @@ module Liquidscript
|
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
+
class UnknownDirectiveError < CompileError
|
18
|
+
def initialize(directive)
|
19
|
+
super "Unkown directive: #{directive}"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
17
23
|
class UnexpectedError < CompileError
|
18
24
|
def initialize(expected, got)
|
19
25
|
@expected = expected
|
@@ -21,11 +21,15 @@ module Liquidscript
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def generate_op(code)
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
24
|
+
"#{replace(code[1])}#{code[2].value}"
|
25
|
+
end
|
26
|
+
|
27
|
+
def generate_neg(code)
|
28
|
+
"-#{replace(code[1])}"
|
29
|
+
end
|
30
|
+
|
31
|
+
def generate_pos(code)
|
32
|
+
"+#{replace(code[1])}"
|
29
33
|
end
|
30
34
|
|
31
35
|
def generate_while(code)
|
@@ -110,6 +114,10 @@ module Liquidscript
|
|
110
114
|
" #{replace(code[2])} #{op} #{replace(code[3])}"
|
111
115
|
end
|
112
116
|
|
117
|
+
def generate_identifier(code)
|
118
|
+
code.value
|
119
|
+
end
|
120
|
+
|
113
121
|
def generate_keyword(code)
|
114
122
|
" #{code[1].value} "
|
115
123
|
end
|
@@ -153,11 +161,10 @@ module Liquidscript
|
|
153
161
|
"function(" <<
|
154
162
|
code[1].parameters.join(',') <<
|
155
163
|
") {\n" <<
|
156
|
-
replace(code[1])
|
157
|
-
'}'
|
158
|
-
|
164
|
+
replace(code[1])
|
159
165
|
unindent!
|
160
|
-
|
166
|
+
|
167
|
+
function << indent_level << "}"
|
161
168
|
end
|
162
169
|
end
|
163
170
|
end
|
@@ -20,12 +20,7 @@ module Liquidscript
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def generate_access(code)
|
23
|
-
|
24
|
-
when :identifier
|
25
|
-
"#{code[1].value}[#{replace code[2]}]"
|
26
|
-
else
|
27
|
-
"#{replace code[1]}[#{replace code[2]}]"
|
28
|
-
end
|
23
|
+
"#{replace code[1]}[#{replace code[2]}]"
|
29
24
|
end
|
30
25
|
|
31
26
|
def generate_get(code)
|
@@ -12,12 +12,7 @@
|
|
12
12
|
args = buffer
|
13
13
|
args.set_join! ','
|
14
14
|
|
15
|
-
|
16
|
-
when :identifier
|
17
|
-
call << "#{code[1].value}"
|
18
|
-
else
|
19
|
-
call << "#{replace(code[1])}"
|
20
|
-
end
|
15
|
+
call << "#{replace(code[1])}"
|
21
16
|
|
22
17
|
code[2..-1].inject(args) do |b, arg|
|
23
18
|
b << replace(arg)
|
@@ -30,8 +25,6 @@
|
|
30
25
|
prop = buffer
|
31
26
|
|
32
27
|
case code[1].type
|
33
|
-
when :identifier
|
34
|
-
prop << code[1].value
|
35
28
|
when :variable
|
36
29
|
prop << code[1].name
|
37
30
|
else
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require "hashie"
|
2
|
+
|
1
3
|
module Liquidscript
|
2
4
|
module ICR
|
3
5
|
|
@@ -64,6 +66,15 @@ module Liquidscript
|
|
64
66
|
end
|
65
67
|
end
|
66
68
|
|
69
|
+
# Allows a specific variable to be used - but doesn't define it
|
70
|
+
# in the current context.
|
71
|
+
#
|
72
|
+
# @param name [Symbol]
|
73
|
+
# @return [void]
|
74
|
+
def allow(name)
|
75
|
+
allowed_variables << name
|
76
|
+
end
|
77
|
+
|
67
78
|
# All of the parameter variables.
|
68
79
|
#
|
69
80
|
# @return [Array<Variable>]
|
@@ -25,11 +25,14 @@ module Liquidscript
|
|
25
25
|
|
26
26
|
end
|
27
27
|
|
28
|
+
attr_accessor :metadata
|
29
|
+
|
28
30
|
def initialize(source)
|
29
|
-
@source
|
30
|
-
@scanner
|
31
|
-
@tokens
|
32
|
-
@_scan
|
31
|
+
@source = source
|
32
|
+
@scanner = StringScanner.new(@source)
|
33
|
+
@tokens = []
|
34
|
+
@_scan = nil
|
35
|
+
@metadata = {}
|
33
36
|
end
|
34
37
|
|
35
38
|
def contexts
|
@@ -11,9 +11,9 @@ module Liquidscript
|
|
11
11
|
|
12
12
|
context :main do
|
13
13
|
set :number, %r{
|
14
|
-
-? [1-9][0-9]*
|
15
|
-
(\.[0-9]+)?
|
16
|
-
([eE][+-]?[0-9]+)?
|
14
|
+
-? ([1-9][0-9]* | 0) # the base of the number
|
15
|
+
(\.[0-9]+)? # decmial portion, if needed
|
16
|
+
([eE][+-]?[0-9]+)? # scientific notation
|
17
17
|
}x
|
18
18
|
|
19
19
|
set :string, %r{
|
@@ -39,12 +39,12 @@ module Liquidscript
|
|
39
39
|
)
|
40
40
|
|
41
41
|
set :binops, %w(
|
42
|
-
|
42
|
+
* / ^
|
43
43
|
<< >> >>>
|
44
|
-
==
|
45
|
-
!=
|
46
|
-
>
|
47
|
-
<
|
44
|
+
=== ==
|
45
|
+
!== !=
|
46
|
+
>= >
|
47
|
+
<= <
|
48
48
|
&& ||
|
49
49
|
& |
|
50
50
|
instanceof
|
@@ -86,6 +86,8 @@ module Liquidscript
|
|
86
86
|
on(":") { emit :colon }
|
87
87
|
on(".") { emit :prop }
|
88
88
|
on(",") { emit :comma }
|
89
|
+
on("-") { emit :minus }
|
90
|
+
on("+") { emit :plus }
|
89
91
|
on("\n") { line! }
|
90
92
|
on(%r{"} => :istring)
|
91
93
|
on(%r{<<([A-Z]+)}) do |_, s|
|
@@ -104,6 +106,12 @@ module Liquidscript
|
|
104
106
|
on(:unops) { |m| emit :unop, m }
|
105
107
|
on(:identifier) { |m| emit :identifier, m }
|
106
108
|
|
109
|
+
on(%r{#! ([A-Za-z]+) ?(.*?)\n}) do |_, c, a|
|
110
|
+
metadata[:directives] ||= []
|
111
|
+
metadata[:directives].push :command => c,
|
112
|
+
:args => a
|
113
|
+
end
|
114
|
+
|
107
115
|
on(%r{#.*?\n}) { }
|
108
116
|
on(%r{\s}) { }
|
109
117
|
on(:_) { |m| error }
|
data/lib/liquidscript/version.rb
CHANGED
data/spec/fixtures/underscore.js
CHANGED
@@ -1,22 +1,39 @@
|
|
1
1
|
(function() {
|
2
|
-
|
2
|
+
|
3
|
+
var root,breaker,previousUnderscore,ArrayProto,ObjProto,FuncProto,push,slice,concat,toString,hasOwnProperty,nativeForEach,nativeMap,nativeReduce,nativeReduceRight,nativeFilter,nativeEvery,nativeSome,nativeIndexOf,nativeLastIndexOf,nativeIsArray,nativeKeys,nativeBind,_,each;
|
3
4
|
root = this;
|
4
|
-
previousUnderscore = root._;
|
5
5
|
breaker = {};
|
6
|
-
|
7
|
-
|
8
|
-
|
6
|
+
previousUnderscore = root._;
|
7
|
+
console = root;
|
8
|
+
ArrayProto = Array.prototype;
|
9
|
+
ObjProto = Object.prototype;
|
10
|
+
FuncProto = Function.prototype;
|
9
11
|
push = ArrayProto.push;
|
10
12
|
slice = ArrayProto.slice;
|
11
13
|
concat = ArrayProto.concat;
|
12
14
|
toString = ObjProto.toString;
|
13
15
|
hasOwnProperty = ObjProto.hasOwnProperty;
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
;
|
16
|
+
nativeForEach = ArrayProto.forEach;
|
17
|
+
nativeMap = ArrayProto.map;
|
18
|
+
nativeReduce = ArrayProto.reduce;
|
19
|
+
nativeReduceRight = ArrayProto.reduceRight;
|
20
|
+
nativeFilter = ArrayProto.filter;
|
21
|
+
nativeEvery = ArrayProto.every;
|
22
|
+
nativeSome = ArrayProto.some;
|
23
|
+
nativeIndexOf = ArrayProto.indexOf;
|
24
|
+
nativeLastIndexOf = arrayProto.lastIndexOf;
|
25
|
+
nativeIsArray = Array.isArray;
|
26
|
+
nativeKeys = Object.keys;
|
27
|
+
nativeBind = FuncProto.bind;
|
28
|
+
_ = function(obj) {
|
29
|
+
if( obj instanceof _) {
|
30
|
+
return obj;
|
31
|
+
};
|
32
|
+
if( ! ( this instanceof _)) {
|
33
|
+
return new _(obj);
|
34
|
+
};
|
35
|
+
this._wrapped = obj;
|
36
|
+
};
|
20
37
|
if( typeof exports !== 'undefined') {
|
21
38
|
if( typeof root.module !== 'undefined' && root.module.exports) {
|
22
39
|
exports = root.module.exports = _;
|
@@ -26,4 +43,46 @@
|
|
26
43
|
root._ = _;
|
27
44
|
};
|
28
45
|
_.VERSION = "1.6.0";
|
46
|
+
each = _.each = _.forEach = function(obj,iterator,context) {
|
47
|
+
|
48
|
+
var i,length,keys;
|
49
|
+
if( obj === null ) {
|
50
|
+
return obj;
|
51
|
+
};
|
52
|
+
if( nativeForEach && obj.forEach === nativeForEach) {
|
53
|
+
obj.forEach(iterator,context);
|
54
|
+
}else if( obj.length === (+obj.length)) {
|
55
|
+
i = 0;
|
56
|
+
length = obj.length;
|
57
|
+
for(i = 0; i < length;i++) {
|
58
|
+
if( iterator.call(context,obj[i],i,obj) === breaker) {
|
59
|
+
return null ;
|
60
|
+
};
|
61
|
+
};
|
62
|
+
} else {
|
63
|
+
keys = _.keys(obj);
|
64
|
+
length = keys.length;
|
65
|
+
for(i = 0; i < length;i++) {
|
66
|
+
if( iterator.call(context,obj[keys[i]],keys[i],obj) === breaker) {
|
67
|
+
return null ;
|
68
|
+
};
|
69
|
+
};
|
70
|
+
};
|
71
|
+
return obj;
|
72
|
+
};
|
73
|
+
_.map = _.collect = function(obj,iterator,context) {
|
74
|
+
|
75
|
+
var results;
|
76
|
+
results = [];
|
77
|
+
if( obj == null ) {
|
78
|
+
return results;
|
79
|
+
};
|
80
|
+
if( nativeMap && obj.map === nativeMap) {
|
81
|
+
return obj.map(iterator,context);
|
82
|
+
};
|
83
|
+
each(obj,function(value,index,list) {
|
84
|
+
results.push(iterator.call(context,value,index,list));
|
85
|
+
});
|
86
|
+
return results;
|
87
|
+
};
|
29
88
|
}).call();
|
@@ -0,0 +1,100 @@
|
|
1
|
+
(-> {
|
2
|
+
|
3
|
+
#! allow Array Object Function
|
4
|
+
|
5
|
+
root = this
|
6
|
+
breaker = {}
|
7
|
+
previousUnderscore = root._
|
8
|
+
console = root
|
9
|
+
|
10
|
+
ArrayProto = Array.prototype
|
11
|
+
ObjProto = Object.prototype
|
12
|
+
FuncProto = Function.prototype
|
13
|
+
|
14
|
+
push = ArrayProto.push
|
15
|
+
slice = ArrayProto.slice
|
16
|
+
concat = ArrayProto.concat
|
17
|
+
toString = ObjProto.toString
|
18
|
+
hasOwnProperty = ObjProto.hasOwnProperty
|
19
|
+
|
20
|
+
nativeForEach = ArrayProto.forEach
|
21
|
+
nativeMap = ArrayProto.map
|
22
|
+
nativeReduce = ArrayProto.reduce
|
23
|
+
nativeReduceRight = ArrayProto.reduceRight
|
24
|
+
nativeFilter = ArrayProto.filter
|
25
|
+
nativeEvery = ArrayProto.every
|
26
|
+
nativeSome = ArrayProto.some
|
27
|
+
nativeIndexOf = ArrayProto.indexOf
|
28
|
+
nativeLastIndexOf = arrayProto.lastIndexOf
|
29
|
+
nativeIsArray = Array.isArray
|
30
|
+
nativeKeys = Object.keys
|
31
|
+
nativeBind = FuncProto.bind
|
32
|
+
|
33
|
+
_ = (obj)-> {
|
34
|
+
if(obj instanceof _) {
|
35
|
+
return obj
|
36
|
+
}
|
37
|
+
if(!(this instanceof _)) {
|
38
|
+
return new _(obj)
|
39
|
+
}
|
40
|
+
|
41
|
+
this._wrapped = obj
|
42
|
+
}
|
43
|
+
|
44
|
+
if(typeof exports != 'undefined) {
|
45
|
+
if(typeof root.module != 'undefined && root.module.exports) {
|
46
|
+
exports = root.module.exports = _
|
47
|
+
}
|
48
|
+
|
49
|
+
exports._ = _
|
50
|
+
} else {
|
51
|
+
root._ = _
|
52
|
+
}
|
53
|
+
|
54
|
+
_.VERSION = "1.6.0"
|
55
|
+
|
56
|
+
each = _.each = _.forEach = (obj, iterator, context)-> {
|
57
|
+
if(obj == null) {
|
58
|
+
return obj
|
59
|
+
}
|
60
|
+
if(nativeForEach && obj.forEach == nativeForEach) {
|
61
|
+
obj.forEach(iterator, context)
|
62
|
+
} elsif(obj.length == (+obj.length)) {
|
63
|
+
i = 0
|
64
|
+
length = obj.length
|
65
|
+
for(i = 0, i < length, i++) {
|
66
|
+
if(iterator.call(context, obj[i], i, obj) == breaker) {
|
67
|
+
return null
|
68
|
+
}
|
69
|
+
}
|
70
|
+
} else {
|
71
|
+
keys = _.keys(obj)
|
72
|
+
length = keys.length
|
73
|
+
for(i = 0, i < length, i++) {
|
74
|
+
if(iterator.call(context, obj[keys[i]], keys[i], obj) == breaker) {
|
75
|
+
return null
|
76
|
+
}
|
77
|
+
}
|
78
|
+
}
|
79
|
+
|
80
|
+
return obj
|
81
|
+
}
|
82
|
+
|
83
|
+
_.map = _.collect = (obj, iterator, context)-> {
|
84
|
+
results = []
|
85
|
+
if(obj === null) {
|
86
|
+
return results
|
87
|
+
}
|
88
|
+
|
89
|
+
if(nativeMap && obj.map == nativeMap) {
|
90
|
+
return obj.map(iterator, context)
|
91
|
+
}
|
92
|
+
|
93
|
+
each(obj, (value, index, list)-> {
|
94
|
+
results.push(iterator.call(context, value, index, list))
|
95
|
+
})
|
96
|
+
|
97
|
+
return results
|
98
|
+
}
|
99
|
+
|
100
|
+
}).call()
|
@@ -7,6 +7,7 @@ describe Compiler::ICR do
|
|
7
7
|
iterator = double("iterator")
|
8
8
|
scanner = double("scanner")
|
9
9
|
|
10
|
+
allow(scanner).to receive(:metadata).and_return({})
|
10
11
|
expect(scanner).to receive(:each).once.and_return(iterator)
|
11
12
|
allow(iterator).to receive(:next).and_return([
|
12
13
|
Scanner::Token.new(:number, "32", 0, 0),
|
@@ -138,4 +139,40 @@ describe Compiler::ICR do
|
|
138
139
|
end
|
139
140
|
end
|
140
141
|
end
|
142
|
+
|
143
|
+
describe "invalid directives" do
|
144
|
+
let(:scanner) do
|
145
|
+
scanner = double("scanner")
|
146
|
+
iterator = double("iterator")
|
147
|
+
allow(iterator).to receive(:rewind)
|
148
|
+
|
149
|
+
expect(scanner).to receive(:each).once.and_return(iterator)
|
150
|
+
expect(scanner).to receive(:metadata).twice.and_return(
|
151
|
+
{:directives =>
|
152
|
+
[{:command => "test", :args => ""},
|
153
|
+
{:command => "allow", :args => "test"}]})
|
154
|
+
scanner
|
155
|
+
end
|
156
|
+
|
157
|
+
it "raises an error" do
|
158
|
+
expect { subject }.to raise_error(Liquidscript::UnknownDirectiveError)
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
describe "directives" do
|
163
|
+
let(:scanner) do
|
164
|
+
scanner = double("scanner")
|
165
|
+
iterator = double("iterator")
|
166
|
+
allow(iterator).to receive(:rewind)
|
167
|
+
|
168
|
+
expect(scanner).to receive(:each).once.and_return(iterator)
|
169
|
+
expect(scanner).to receive(:metadata).twice.and_return(
|
170
|
+
{:directives => [{:command => "allow", :args => "test"}]})
|
171
|
+
scanner
|
172
|
+
end
|
173
|
+
|
174
|
+
it "raises an error" do
|
175
|
+
subject.top.context.get(:test)
|
176
|
+
end
|
177
|
+
end
|
141
178
|
end
|
@@ -73,5 +73,10 @@ describe Liquidscript::Scanner::Liquidscript, :lexer_helper do
|
|
73
73
|
[:heredoc, "in heredoc"]
|
74
74
|
]
|
75
75
|
end
|
76
|
+
|
77
|
+
describe "scanning directives" do
|
78
|
+
subject { c = described_class.new("#! test thing\n"); c.scan; c }
|
79
|
+
its(:metadata) { should eq :directives => [{:command => "test", :args => "thing"}] }
|
80
|
+
end
|
76
81
|
end
|
77
82
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: liquidscript
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeremy Rodi
|
@@ -174,7 +174,7 @@ files:
|
|
174
174
|
- spec/fixtures/string.compile.yml
|
175
175
|
- spec/fixtures/string.generate.yml
|
176
176
|
- spec/fixtures/underscore.js
|
177
|
-
- spec/fixtures/underscore.
|
177
|
+
- spec/fixtures/underscore.liq
|
178
178
|
- spec/liquidscript/buffer_spec.rb
|
179
179
|
- spec/liquidscript/compiler/icr_spec.rb
|
180
180
|
- spec/liquidscript/generator/javascript_spec.rb
|
@@ -233,7 +233,7 @@ test_files:
|
|
233
233
|
- spec/fixtures/string.compile.yml
|
234
234
|
- spec/fixtures/string.generate.yml
|
235
235
|
- spec/fixtures/underscore.js
|
236
|
-
- spec/fixtures/underscore.
|
236
|
+
- spec/fixtures/underscore.liq
|
237
237
|
- spec/liquidscript/buffer_spec.rb
|
238
238
|
- spec/liquidscript/compiler/icr_spec.rb
|
239
239
|
- spec/liquidscript/generator/javascript_spec.rb
|
data/spec/fixtures/underscore.ls
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
(-> {
|
2
|
-
root = this
|
3
|
-
previousUnderscore = root._
|
4
|
-
breaker = {}
|
5
|
-
ArrayProto = root.Array.prototype
|
6
|
-
ObjProto = root.Object.prototype
|
7
|
-
FuncProto = root.Function.prototype
|
8
|
-
|
9
|
-
push = ArrayProto.push
|
10
|
-
slice = ArrayProto.slice
|
11
|
-
concat = ArrayProto.concat
|
12
|
-
toString = ObjProto.toString
|
13
|
-
hasOwnProperty = ObjProto.hasOwnProperty
|
14
|
-
|
15
|
-
class _ {
|
16
|
-
|
17
|
-
}
|
18
|
-
|
19
|
-
if(typeof exports != 'undefined) {
|
20
|
-
if(typeof root.module != 'undefined && root.module.exports) {
|
21
|
-
exports = root.module.exports = _
|
22
|
-
}
|
23
|
-
|
24
|
-
exports._ = _
|
25
|
-
} else {
|
26
|
-
root._ = _
|
27
|
-
}
|
28
|
-
|
29
|
-
_.VERSION = "1.6.0"
|
30
|
-
}).call()
|