liquidscript 0.4.1 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/lib/liquidscript/buffer.rb +2 -2
  3. data/lib/liquidscript/compiler/icr.rb +1 -0
  4. data/lib/liquidscript/compiler/icr/classes.rb +11 -3
  5. data/lib/liquidscript/compiler/icr/expressions.rb +56 -10
  6. data/lib/liquidscript/compiler/icr/functions.rb +7 -6
  7. data/lib/liquidscript/compiler/icr/heredoc.rb +28 -0
  8. data/lib/liquidscript/compiler/icr/literals.rb +102 -9
  9. data/lib/liquidscript/errors.rb +6 -0
  10. data/lib/liquidscript/generator/base.rb +1 -1
  11. data/lib/liquidscript/generator/base/replacements.rb +2 -2
  12. data/lib/liquidscript/generator/javascript.rb +21 -0
  13. data/lib/liquidscript/generator/javascript/exceptions.rb +42 -0
  14. data/lib/liquidscript/generator/javascript/literals.rb +71 -9
  15. data/lib/liquidscript/generator/javascript/metas.rb +14 -13
  16. data/lib/liquidscript/generator/javascript/objects.rb +21 -16
  17. data/lib/liquidscript/icr/set.rb +8 -0
  18. data/lib/liquidscript/scanner/base/lexer.rb +13 -10
  19. data/lib/liquidscript/scanner/liquidscript.rb +95 -17
  20. data/lib/liquidscript/template.rb +1 -2
  21. data/lib/liquidscript/version.rb +1 -1
  22. data/liquidscript.gemspec +1 -0
  23. data/spec/fixtures/class.compile.yml +12 -1
  24. data/spec/fixtures/class.generate.yml +4 -4
  25. data/spec/fixtures/combination.generate.yml +4 -4
  26. data/spec/fixtures/complex.generate.yml +5 -5
  27. data/spec/fixtures/expression.generate.yml +1 -1
  28. data/spec/fixtures/heredoc.generate.yml +9 -0
  29. data/spec/fixtures/literals.generate.yml +9 -1
  30. data/spec/fixtures/loop.generate.yml +16 -0
  31. data/spec/fixtures/main.compile.yml +19 -15
  32. data/spec/fixtures/operator.generate.yml +10 -2
  33. data/spec/fixtures/string.compile.yml +20 -1
  34. data/spec/fixtures/string.generate.yml +1 -1
  35. data/spec/fixtures/underscore.js +28 -0
  36. data/spec/fixtures/underscore.ls +2 -1
  37. data/spec/liquidscript/compiler/icr_spec.rb +2 -0
  38. data/spec/liquidscript/node_spec.rb +21 -0
  39. data/spec/liquidscript/scanner/lexer_spec.rb +23 -2
  40. data/spec/support/matchers/compile.rb +1 -1
  41. data/spec/support/matchers/generate.rb +6 -3
  42. data/spec/support/matchers/run.rb +12 -0
  43. metadata +28 -2
@@ -9,9 +9,8 @@ module Liquidscript
9
9
 
10
10
  def render
11
11
  @_render ||= begin
12
- compiler = Compiler::ICR.new(Scanner::Liquidscript.new(@data))
12
+ compiler = Compiler::ICR.new(s = Scanner::Liquidscript.new(@data))
13
13
  compiler.compile
14
- puts ICR::Sexp.new(compiler.top).output
15
14
  Generator::Javascript.new(compiler.top).generate
16
15
  end
17
16
  end
@@ -1,5 +1,5 @@
1
1
  module Liquidscript
2
2
 
3
3
  # The current version of liquidscript.
4
- VERSION = "0.4.1".freeze
4
+ VERSION = "0.5.0".freeze
5
5
  end
@@ -22,6 +22,7 @@ Gem::Specification.new do |spec|
22
22
  spec.add_development_dependency "rake"
23
23
  spec.add_development_dependency "rspec"
24
24
  spec.add_development_dependency "yard"
25
+ spec.add_development_dependency "command-runner"
25
26
 
26
27
  spec.add_dependency "hashie", "~> 2.0"
27
28
  end
@@ -3,6 +3,10 @@ data: |
3
3
  class SomeClass {
4
4
  test: -> {}
5
5
  }
6
+
7
+ class AnotherClass : SomeClass {
8
+
9
+ }
6
10
  }
7
11
 
8
12
  compiled:
@@ -10,12 +14,14 @@ compiled:
10
14
  - - :_context
11
15
  - - :Something
12
16
  - :SomeClass
17
+ - :AnotherClass
13
18
  - - :module
14
19
  - - :identifier
15
20
  - Something
16
21
  - - - :class
17
22
  - - :identifier
18
23
  - SomeClass
24
+ - ~
19
25
  - - - - :identifier
20
26
  - test
21
27
  - - :function
@@ -24,4 +30,9 @@ compiled:
24
30
  - []
25
31
  - - :_arguments
26
32
  - []
27
- - - :newline
33
+ - - :class
34
+ - - :identifier
35
+ - AnotherClass
36
+ - - :identifier
37
+ - SomeClass
38
+ - []
@@ -23,17 +23,17 @@ compiled: |
23
23
  if(this.initialize) {
24
24
  this.initialize.apply(this, arguments);
25
25
  }
26
- };
26
+ }
27
27
 
28
28
  Test.prototype.wee = function() {
29
- console.log(2)
29
+ console.log(2);
30
30
  };
31
31
 
32
32
  Test.prototype.initialize = function() {
33
- "this should be init"
33
+ "this should be init";
34
34
  };
35
35
 
36
36
  Test.test = function() {
37
- "class method!"
37
+ "class method!";
38
38
  };
39
39
  Something.Test = Test;
@@ -1,5 +1,5 @@
1
1
  data: |
2
- Test = require("some_module/test")
2
+ Test = require("assert")
3
3
 
4
4
  module SomeModule {
5
5
  class Thing {
@@ -15,19 +15,19 @@ data: |
15
15
 
16
16
  compiled: |
17
17
  var Test, SomeModule, Thing;
18
- Test = require("some_module/test");
18
+ Test = require("assert");
19
19
  SomeModule = SomeModule || {};
20
20
  Thing = Thing || function Thing() {
21
21
  if(this.initialize) {
22
22
  this.initialize.apply(this, arguments);
23
23
  }
24
- };
24
+ }
25
25
 
26
26
  Thing.prototype.initialize = function() {
27
27
  this.test = new Test();
28
28
  };
29
29
 
30
30
  Thing.prototype.do = function(thing) {
31
- return this.test.do(thing)
31
+ return this.test.do(thing);
32
32
  };
33
33
  SomeModule.Thing = Thing;
@@ -20,14 +20,14 @@ compiled: |
20
20
  thing = {
21
21
  "test": function() {
22
22
  if(undefined) {
23
- "test"
23
+ "test";
24
24
  } else if(null) {
25
- "um"
25
+ "um";
26
26
  } else {
27
- "hello"
28
- }
27
+ "hello";
28
+ };
29
29
  }
30
30
  };
31
31
 
32
- thing.test()
32
+ thing.test();
33
33
 
@@ -1,4 +1,4 @@
1
1
  data: |
2
2
  (2)
3
3
 
4
- compiled: "(2)"
4
+ compiled: "(2);"
@@ -0,0 +1,9 @@
1
+ data: |
2
+ console.log(<<TEST, <<-MAYBE)
3
+ hello world
4
+ TEST
5
+ hello #{console}
6
+ MAYBE
7
+
8
+ compiled: |
9
+ console.log("hello world", "hello " + console + "");
@@ -1,8 +1,16 @@
1
1
  data: |
2
2
  object = { hello: "world" }
3
3
  test = [1, 2]
4
+ regex = /^test/
5
+ block = ///
6
+ ^test # comment
7
+ ///
8
+ regex == block
4
9
 
5
10
  compiled: |
6
- var object, test;
11
+ var object, test, regex, block;
7
12
  object = { "hello": "world" };
8
13
  test = [1, 2];
14
+ regex = /^test/;
15
+ block = /^test/;
16
+ regex === block;
@@ -0,0 +1,16 @@
1
+ data: |
2
+ t = 5
3
+
4
+ while(t > 0) {
5
+ t--
6
+ }
7
+
8
+ for(t = 0, t < 5, t++) {
9
+ console.log(t)
10
+ }
11
+
12
+ compiled: |
13
+ var t;
14
+ t = 5;
15
+ while(t > 0) { t--; };
16
+ for(t = 0; t < 5; t++) { console.log(t); };
@@ -1,36 +1,40 @@
1
1
  data: |
2
- console = 2
3
2
  func = ()-> {
3
+ for(v in console) {
4
+ console.log(v)
5
+ }
4
6
  console.log("hello world")
5
7
  }
6
8
  compiled:
7
9
  - :exec
8
10
  - - :_context
9
- - - :console
10
- - :func
11
- - - :set
12
- - - :_variable
13
- - :console
14
- - - :number
15
- - "2"
16
- - - :newline
11
+ - - :func
17
12
  - - :set
18
13
  - - :_variable
19
14
  - :func
20
15
  - - :function
21
16
  - - :exec
22
17
  - - :_context
23
- - []
18
+ - - :v
24
19
  - - :_arguments
25
20
  - []
26
- - - :newline
21
+ - - :for_in
22
+ - - :identifier
23
+ - v
24
+ - - :_variable
25
+ - :console
26
+ - - - :call
27
+ - - :property
28
+ - - :identifier
29
+ - console
30
+ - log
31
+ - - :get
32
+ - - :_variable
33
+ - :v
27
34
  - - :call
28
35
  - - :property
29
36
  - - :identifier
30
37
  - console
31
- - - :identifier
32
- - log
38
+ - log
33
39
  - - :istring
34
40
  - hello world
35
- - - :newline
36
- - - :newline
@@ -6,6 +6,10 @@ data: |
6
6
  out = true
7
7
  }
8
8
 
9
+ try {
10
+ console.ummm()
11
+ } catch(e) {}
12
+
9
13
  return out
10
14
  }
11
15
 
@@ -17,7 +21,11 @@ compiled: |
17
21
  out = false;
18
22
  if(typeof global !== 'undefined') {
19
23
  out = true;
20
- }
24
+ };
21
25
 
22
- return out
26
+ try {
27
+ console.ummm();
28
+ } catch(e) {};
29
+
30
+ return out;
23
31
  };
@@ -1,9 +1,29 @@
1
1
  data: |
2
+ console.log(<<TEST)
3
+ hello world
4
+ TEST
5
+
2
6
  "hello #{console}"
7
+
3
8
  compiled:
4
9
  - :exec
5
10
  - - :_context
6
11
  - []
12
+ - - :_heredocs
13
+ - - &heredoc
14
+ - :heredoc
15
+ - TEST
16
+ - - - :heredoc
17
+ - hello world
18
+ - - :_herenum
19
+ - 1
20
+ - - :call
21
+ - - :property
22
+ - - :identifier
23
+ - console
24
+ - log
25
+ - - :href
26
+ - *heredoc
7
27
  - - :interop
8
28
  - - :istring_begin
9
29
  - "hello "
@@ -12,4 +32,3 @@ compiled:
12
32
  - :console
13
33
  - - :istring
14
34
  - ""
15
- - - :newline
@@ -10,4 +10,4 @@ compiled: |
10
10
  test = "hello";
11
11
  foo = 'world';
12
12
  thing = "hello \" test \n world";
13
- interop = ["hello ", foo, ""].join('');
13
+ interop = "hello" + (foo) + "";
@@ -0,0 +1,28 @@
1
+ (function() {
2
+ var root,previousUnderscore,breaker,ArrayProto,ObjProto,FuncProto,push,slice,concat,toString,hasOwnProperty,_;
3
+ root = this;
4
+ previousUnderscore = root._;
5
+ breaker = {};
6
+ ArrayProto = root.Array.prototype;
7
+ ObjProto = root.Object.prototype;
8
+ FuncProto = root.Function.prototype;
9
+ push = ArrayProto.push;
10
+ slice = ArrayProto.slice;
11
+ concat = ArrayProto.concat;
12
+ toString = ObjProto.toString;
13
+ hasOwnProperty = ObjProto.hasOwnProperty;
14
+ _ = _ || function _() {
15
+ if(this.initialize) {
16
+ this.initialize.apply(this, arguments);
17
+ }
18
+ };
19
+ if( typeof exports !== 'undefined') {
20
+ if( typeof root.module !== 'undefined' && root.module.exports) {
21
+ exports = root.module.exports = _;
22
+ };
23
+ exports._ = _;
24
+ } else {
25
+ root._ = _;
26
+ };
27
+ _.VERSION = "1.6.0";
28
+ }).call();
@@ -17,7 +17,7 @@
17
17
  }
18
18
 
19
19
  if(typeof exports != 'undefined) {
20
- if(typeof root.module !== 'undefined && root.module.exports) {
20
+ if(typeof root.module != 'undefined && root.module.exports) {
21
21
  exports = root.module.exports = _
22
22
  }
23
23
 
@@ -25,5 +25,6 @@
25
25
  } else {
26
26
  root._ = _
27
27
  }
28
+
28
29
  _.VERSION = "1.6.0"
29
30
  }).call()
@@ -119,11 +119,13 @@ describe Compiler::ICR do
119
119
  ]])
120
120
  }
121
121
 
122
+
122
123
  specify { expect("(2)").to compile }
123
124
  specify { expect("(2)->").to_not compile }
124
125
  specify { expect("()-> {}").to compile }
125
126
  specify { expect("(test)-> {}").to compile }
126
127
  specify { expect("(test, foo)-> {}").to compile }
128
+ specify { expect("class Test : Variant {}").to_not compile }
127
129
  end
128
130
 
129
131
  describe "with fixtures" do
@@ -0,0 +1,21 @@
1
+ require "spec_helper"
2
+ require "command/runner"
3
+
4
+ which_node = Command::Runner.new("which", "node")
5
+
6
+ if which_node.backend.class != Command::Runner::Backends::Backticks &&
7
+ which_node.run.successful?
8
+ describe "Node support" do
9
+ describe "with fixtures" do
10
+
11
+ Dir.glob("spec/fixtures/*.yml") do |file|
12
+ content = YAML.load_file file
13
+ file =~ /spec\/fixtures\/(.*)\.yml/
14
+
15
+ it "generates #{$1}" do
16
+ expect(content["data"]).to run
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -35,11 +35,11 @@ describe Liquidscript::Scanner::Liquidscript, :lexer_helper do
35
35
 
36
36
  it "scans brackets" do
37
37
  scan("{ test = 3 }").should eq [
38
- [:lbrack, nil],
38
+ [:lbrace, nil],
39
39
  [:identifier, "test"],
40
40
  [:equal, nil],
41
41
  [:number, "3"],
42
- [:rbrack, nil]
42
+ [:rbrace, nil]
43
43
  ]
44
44
  end
45
45
 
@@ -52,5 +52,26 @@ describe Liquidscript::Scanner::Liquidscript, :lexer_helper do
52
52
  [:identifier, "foo"]
53
53
  ]
54
54
  end
55
+
56
+ it "scans heredocs" do
57
+ scan("<<TEST\nhello\nTEST\n").should eq [
58
+ [:heredoc_ref, "TEST"],
59
+ [:heredoc, "hello"]
60
+ ]
61
+
62
+ scan("<<-TEST\nhello \#{world}\nTEST\n").should eq [
63
+ [:iheredoc_ref, "TEST"],
64
+ [:iheredoc_begin, "hello "],
65
+ [:identifier, "world"],
66
+ [:iheredoc, ""]
67
+ ]
68
+
69
+ scan("hello <<TEST world\nin heredoc\nTEST\n").should eq [
70
+ [:identifier, "hello"],
71
+ [:heredoc_ref, "TEST"],
72
+ [:identifier, "world"],
73
+ [:heredoc, "in heredoc"]
74
+ ]
75
+ end
55
76
  end
56
77
  end
@@ -14,7 +14,7 @@ RSpec::Matchers.define :compile do
14
14
  end
15
15
 
16
16
  failure_message_for_should do |data|
17
- "expected #{data} to compile correctly"
17
+ "expected #{data} to compile correctly\nexpected: #{expected}\n got: #{actual}"
18
18
  end
19
19
 
20
20
  failure_message_for_should_not do |data|