coffee-script 0.2.4 → 0.2.5

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.
@@ -26,7 +26,7 @@ module CoffeeScript
26
26
 
27
27
  # Single-line flavors of block expressions that have unclosed endings.
28
28
  # The grammar can't disambiguate them, so we insert the implicit indentation.
29
- SINGLE_LINERS = [:ELSE, "=>", :TRY, :FINALLY, :THEN]
29
+ SINGLE_LINERS = [:ELSE, "=>", "==>", :TRY, :FINALLY, :THEN]
30
30
  SINGLE_CLOSERS = ["\n", :CATCH, :FINALLY, :ELSE, :OUTDENT, :LEADING_WHEN]
31
31
 
32
32
  # Rewrite the token stream in multiple passes, one logical filter at
@@ -35,6 +35,7 @@ module CoffeeScript
35
35
  def rewrite(tokens)
36
36
  @tokens = tokens
37
37
  adjust_comments
38
+ remove_leading_newlines
38
39
  remove_mid_expression_newlines
39
40
  move_commas_outside_outdents
40
41
  add_implicit_indentation
@@ -82,6 +83,12 @@ module CoffeeScript
82
83
  end
83
84
  end
84
85
 
86
+ # Leading newlines would introduce an ambiguity in the grammar, so we
87
+ # dispatch them here.
88
+ def remove_leading_newlines
89
+ @tokens.shift if @tokens[0][0] == "\n"
90
+ end
91
+
85
92
  # Some blocks occur in the middle of expressions -- when we're expecting
86
93
  # this, remove their trailing newlines.
87
94
  def remove_mid_expression_newlines
@@ -47,15 +47,40 @@ module CoffeeScript
47
47
  @temp_variable.dup
48
48
  end
49
49
 
50
+ # Ensure that an assignment is made at the top of scope (or top-level
51
+ # scope, if requested).
52
+ def assign(name, value, top=false)
53
+ return @parent.assign(name, value, top) if top && @parent
54
+ @variables[name.to_sym] = Value.new(value)
55
+ end
56
+
50
57
  def declarations?(body)
51
58
  !declared_variables.empty? && body == @expressions
52
59
  end
53
60
 
61
+ def assignments?(body)
62
+ !assigned_variables.empty? && body == @expressions
63
+ end
64
+
54
65
  # Return the list of variables first declared in current scope.
55
66
  def declared_variables
56
67
  @variables.select {|k, v| v == :var }.map {|pair| pair[0].to_s }.sort
57
68
  end
58
69
 
70
+ # Return the list of variables that are supposed to be assigned at the top
71
+ # of scope.
72
+ def assigned_variables
73
+ @variables.select {|k, v| v.is_a?(Value) }.sort_by {|pair| pair[0].to_s }
74
+ end
75
+
76
+ def compiled_declarations
77
+ declared_variables.join(', ')
78
+ end
79
+
80
+ def compiled_assignments
81
+ assigned_variables.map {|name, val| "#{name} = #{val}"}.join(', ')
82
+ end
83
+
59
84
  def inspect
60
85
  "<Scope:#{__id__} #{@variables.inspect}>"
61
86
  end
@@ -41,6 +41,10 @@ module CoffeeScript
41
41
  def hash
42
42
  @value.hash
43
43
  end
44
+
45
+ def match(regex)
46
+ @value.match(regex)
47
+ end
44
48
  end
45
49
 
46
50
  end
data/package.json CHANGED
@@ -5,5 +5,5 @@
5
5
  "description": "Unfancy JavaScript",
6
6
  "keywords": ["javascript", "language"],
7
7
  "author": "Jeremy Ashkenas",
8
- "version": "0.2.4"
8
+ "version": "0.2.5"
9
9
  }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: coffee-script
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Ashkenas
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-01-12 00:00:00 -05:00
12
+ date: 2010-01-13 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies: []
15
15