less 2.2.0 → 2.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -30,9 +30,12 @@ module Less
30
30
  end
31
31
 
32
32
  # function LessError(e, env) { ... }
33
- %w{ type filename index line stack column extract }.each do |key|
33
+ %w{ type filename stack extract }.each do |key|
34
34
  class_eval "def #{key}; @value && @value['#{key}']; end"
35
35
  end
36
+ %w{ index line column }.each do |key|
37
+ class_eval "def #{key}; @value && @value['#{key}'].to_i; end"
38
+ end
36
39
 
37
40
  end
38
41
 
@@ -71,8 +71,8 @@ module Less
71
71
  private
72
72
 
73
73
  def handle_js_error(e)
74
- if e.value && e.value['type'] # LessError
75
- raise Less::ParseError.new(e, e.value)
74
+ if e.value && ( e.value['message'] || e.value['type'].is_a?(String) )
75
+ raise Less::ParseError.new(e, e.value) # LessError
76
76
  end
77
77
  if e.unwrap.to_s == "missing closing `}`"
78
78
  raise Less::ParseError.new(e.unwrap.to_s)
@@ -59,11 +59,28 @@ module Less
59
59
  def lock(&block)
60
60
  do_lock(&block)
61
61
  rescue V8::JSError => e
62
- if e.value["name"] == "SyntaxError" || e.in_javascript?
63
- raise Less::ParseError.new(e)
64
- else
65
- raise Less::Error.new(e)
62
+ if e.in_javascript?
63
+ js_value = e.value.respond_to?(:'[]')
64
+ name = js_value && e.value["name"]
65
+ constructor = js_value && e.value['constructor']
66
+ if name == "SyntaxError" ||
67
+ ( constructor && constructor.name == "LessError" )
68
+ raise Less::ParseError.new(e, js_value ? e.value : nil)
69
+ end
70
+ # NOTE: less/parser.js :
71
+ #
72
+ # error = new(LessError)({
73
+ # index: i,
74
+ # type: 'Parse',
75
+ # message: "missing closing `}`",
76
+ # filename: env.filename
77
+ # }, env);
78
+ #
79
+ # comes back as value: RuntimeError !
80
+ elsif e.value.to_s == "missing closing `}`"
81
+ raise Less::ParseError.new(e.value.to_s)
66
82
  end
83
+ raise Less::Error.new(e)
67
84
  end
68
85
 
69
86
  def do_lock
@@ -26,6 +26,9 @@ module Less
26
26
  # v8 >= 0.10 passes this as first arg :
27
27
  if args.size > 2
28
28
  error, tree = args[-2], args[-1]
29
+ elsif args.last.respond_to?(:message) && args.last.message
30
+ # might get invoked as callback(error)
31
+ error = args.last
29
32
  else
30
33
  error, tree = *args
31
34
  end
@@ -1,3 +1,3 @@
1
1
  module Less
2
- VERSION = '2.2.0'
2
+ VERSION = '2.2.1'
3
3
  end
@@ -19,6 +19,10 @@ describe Less::Parser do
19
19
  end
20
20
  end
21
21
 
22
+ it "throws a ParseError if the lesscss is bogus" do
23
+ expect { subject.parse('{^)') }.should raise_error(Less::ParseError, /missing closing `\}`/)
24
+ end
25
+
22
26
  it "passes exceptions from the less compiler" do
23
27
  expect { subject.parse('body { color: @a; }').to_css }.should raise_error(Less::ParseError, /variable @a is undefined/)
24
28
  end
@@ -35,6 +39,19 @@ describe Less::Parser do
35
39
  expect { subject.parse('@import "faulty.less";').to_css }.should raise_error(Less::ParseError, /variable @a is undefined/)
36
40
  end
37
41
 
42
+ it "reports type, line, column and filename of (parse) error" do
43
+ begin
44
+ subject.parse('@import "faulty.less";').to_css
45
+ rescue Less::ParseError => e
46
+ e.type.should == 'Name'
47
+ e.filename.should == cwd.join('faulty/faulty.less').to_s
48
+ e.line.should == 1
49
+ e.column.should == 16
50
+ else
51
+ fail "parse error not raised"
52
+ end
53
+ end
54
+
38
55
  end
39
56
 
40
57
  describe "when load paths are specified in as default options" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: less
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.0
4
+ version: 2.2.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-04-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: commonjs
16
- requirement: &2151889720 !ruby/object:Gem::Requirement
16
+ requirement: &2152447520 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 0.2.6
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2151889720
24
+ version_requirements: *2152447520
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rake
27
- requirement: &2151888660 !ruby/object:Gem::Requirement
27
+ requirement: &2160076840 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *2151888660
35
+ version_requirements: *2160076840
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rspec
38
- requirement: &2151887500 !ruby/object:Gem::Requirement
38
+ requirement: &2160074640 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,7 +43,7 @@ dependencies:
43
43
  version: '2.0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *2151887500
46
+ version_requirements: *2160074640
47
47
  description: Invoke the Less CSS compiler from Ruby
48
48
  email:
49
49
  - cowboyd@thefrontside.net
@@ -349,7 +349,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
349
349
  version: '0'
350
350
  segments:
351
351
  - 0
352
- hash: 2145882749298948818
352
+ hash: 1291247618380618562
353
353
  required_rubygems_version: !ruby/object:Gem::Requirement
354
354
  none: false
355
355
  requirements:
@@ -358,7 +358,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
358
358
  version: '0'
359
359
  segments:
360
360
  - 0
361
- hash: 2145882749298948818
361
+ hash: 1291247618380618562
362
362
  requirements: []
363
363
  rubyforge_project: less
364
364
  rubygems_version: 1.8.17