coffee-script 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,7 +5,7 @@ module CoffeeScript
5
5
  # whether a variable has been seen before or if it needs to be declared.
6
6
  class Scope
7
7
 
8
- attr_reader :parent, :temp_variable
8
+ attr_reader :parent, :variables, :temp_variable
9
9
 
10
10
  # Initialize a scope with its parent, for lookups up the chain.
11
11
  def initialize(parent=nil)
@@ -18,10 +18,16 @@ module CoffeeScript
18
18
  def find(name, remote=false)
19
19
  found = check(name, remote)
20
20
  return found if found || remote
21
- @variables[name.to_sym] = true
21
+ @variables[name.to_sym] = :var
22
22
  found
23
23
  end
24
24
 
25
+ # Define a local variable as originating from a parameter in current scope
26
+ # -- no var required.
27
+ def parameter(name)
28
+ @variables[name.to_sym] = :param
29
+ end
30
+
25
31
  # Just check to see if a variable has already been declared.
26
32
  def check(name, remote=false)
27
33
  return true if @variables[name.to_sym]
@@ -36,10 +42,19 @@ module CoffeeScript
36
42
  # Find an available, short, name for a compiler-generated variable.
37
43
  def free_variable
38
44
  @temp_variable.succ! while check(@temp_variable)
39
- @variables[@temp_variable.to_sym] = true
45
+ @variables[@temp_variable.to_sym] = :var
40
46
  @temp_variable.dup
41
47
  end
42
48
 
49
+ def any_declared?
50
+ !declared_variables.empty?
51
+ end
52
+
53
+ # Return the list of variables first declared in current scope.
54
+ def declared_variables
55
+ @variables.select {|k, v| v == :var }.map {|pair| pair[0].to_s }.sort
56
+ end
57
+
43
58
  end
44
59
 
45
60
  end
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.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Ashkenas
@@ -9,20 +9,20 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-12-25 00:00:00 -08:00
12
+ date: 2009-12-26 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
16
16
  description: " CoffeeScript is a little language that compiles into JavaScript. Think\n of it as JavaScript's less ostentatious kid brother -- the same genes,\n roughly the same height, but a different sense of style. Apart from a\n handful of bonus goodies, statements in CoffeeScript correspond\n one-to-one with their equivalent in JavaScript, it's just another\n way of saying it.\n"
17
17
  email: jashkenas@gmail.com
18
18
  executables:
19
- - coffee-script
19
+ - coffee
20
20
  extensions: []
21
21
 
22
22
  extra_rdoc_files: []
23
23
 
24
24
  files:
25
- - bin/coffee-script
25
+ - bin/coffee
26
26
  - examples/code.coffee
27
27
  - examples/documents.coffee
28
28
  - examples/poignant.coffee
@@ -43,6 +43,7 @@ files:
43
43
  - lib/coffee_script/narwhal/loader.coffee
44
44
  - lib/coffee_script/nodes.rb
45
45
  - lib/coffee_script/parse_error.rb
46
+ - lib/coffee_script/parser.output
46
47
  - lib/coffee_script/parser.rb
47
48
  - lib/coffee_script/scope.rb
48
49
  - lib/coffee_script/value.rb