coffee-script 0.3.2 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,11 +0,0 @@
1
- (function(){
2
- var coffee, paths;
3
- // Quickie script to compile and run all the files given as arguments.
4
- process.mixin(require('sys'));
5
- coffee = require('./coffee-script');
6
- paths = process.ARGV;
7
- paths = paths.slice(2, paths.length);
8
- paths.length ? coffee.compile_files(paths, function(js) {
9
- return eval(js);
10
- }) : require('./repl');
11
- })();
@@ -1,73 +0,0 @@
1
- (function(){
2
- var dup;
3
- var __hasProp = Object.prototype.hasOwnProperty;
4
- dup = function dup(input) {
5
- var __a, __b, __c, key, output, val;
6
- output = null;
7
- if (input instanceof Array) {
8
- output = [];
9
- __a = input;
10
- for (__b = 0; __b < __a.length; __b++) {
11
- val = __a[__b];
12
- output.push(val);
13
- }
14
- } else {
15
- output = {
16
- };
17
- __c = input;
18
- for (key in __c) {
19
- val = __c[key];
20
- if (__hasProp.call(__c, key)) {
21
- output.key = val;
22
- }
23
- }
24
- output;
25
- }
26
- return output;
27
- };
28
- // scope objects form a tree corresponding to the shape of the function
29
- // definitions present in the script. They provide lexical scope, to determine
30
- // whether a variable has been seen before or if it needs to be declared.
31
- exports.Scope = function Scope(parent, expressions, func) {
32
- var __a;
33
- // Initialize a scope with its parent, for lookups up the chain,
34
- // as well as the Expressions body where it should declare its variables,
35
- // and the function that it wraps.
36
- this.parent = parent;
37
- this.expressions = expressions;
38
- this.function = func;
39
- this.variables = {
40
- };
41
- __a = this.temp_variable = this.parent ? dup(this.parent.temp_variable) : '__a';
42
- return Scope === this.constructor ? this : __a;
43
- };
44
- // Look up a variable in lexical scope, or declare it if not found.
45
- exports.Scope.prototype.find = function find(name, rem) {
46
- var found, remote;
47
- remote = (typeof rem !== "undefined" && rem !== null) ? rem : false;
48
- found = this.check(name);
49
- if (found || remote) {
50
- return found;
51
- }
52
- this.variables[name] = 'var';
53
- return found;
54
- };
55
- // Define a local variable as originating from a parameter in current scope
56
- // -- no var required.
57
- exports.Scope.prototype.parameter = function parameter(name) {
58
- return this.variables[name] = 'param';
59
- };
60
- // Just check to see if a variable has already been declared.
61
- exports.Scope.prototype.check = function check(name) {
62
- if ((typeof this.variables[name] !== "undefined" && this.variables[name] !== null)) {
63
- return true;
64
- }
65
- // TODO: what does that ruby !! mean..? need to follow up
66
- // .. this next line is prolly wrong ..
67
- return !!(this.parent && this.parent.check(name));
68
- };
69
- // You can reset a found variable on the immediate scope.
70
- exports.Scope.prototype.reset = function reset(name) {
71
- return this.variables[name] = undefined;
72
- };
73
- })();
@@ -1,91 +0,0 @@
1
- module CoffeeScript
2
-
3
- # Scope objects form a tree corresponding to the shape of the function
4
- # definitions present in the script. They provide lexical scope, to determine
5
- # whether a variable has been seen before or if it needs to be declared.
6
- class Scope
7
-
8
- attr_reader :parent, :expressions, :function, :variables, :temp_variable
9
-
10
- # Initialize a scope with its parent, for lookups up the chain,
11
- # as well as the Expressions body where it should declare its variables,
12
- # and the function that it wraps.
13
- def initialize(parent, expressions, function)
14
- @parent, @expressions, @function = parent, expressions, function
15
- @variables = {}
16
- @temp_variable = @parent ? @parent.temp_variable.dup : '__a'
17
- end
18
-
19
- # Look up a variable in lexical scope, or declare it if not found.
20
- def find(name, remote=false)
21
- found = check(name)
22
- return found if found || remote
23
- @variables[name.to_sym] = :var
24
- found
25
- end
26
-
27
- # Define a local variable as originating from a parameter in current scope
28
- # -- no var required.
29
- def parameter(name)
30
- @variables[name.to_sym] = :param
31
- end
32
-
33
- # Just check to see if a variable has already been declared.
34
- def check(name)
35
- return true if @variables[name.to_sym]
36
- !!(@parent && @parent.check(name))
37
- end
38
-
39
- # You can reset a found variable on the immediate scope.
40
- def reset(name)
41
- @variables[name.to_sym] = false
42
- end
43
-
44
- # Find an available, short, name for a compiler-generated variable.
45
- def free_variable
46
- @temp_variable.succ! while check(@temp_variable)
47
- @variables[@temp_variable.to_sym] = :var
48
- Value.new(@temp_variable.dup)
49
- end
50
-
51
- # Ensure that an assignment is made at the top of scope (or top-level
52
- # scope, if requested).
53
- def assign(name, value, top=false)
54
- return @parent.assign(name, value, top) if top && @parent
55
- @variables[name.to_sym] = Value.new(value)
56
- end
57
-
58
- def declarations?(body)
59
- !declared_variables.empty? && body == @expressions
60
- end
61
-
62
- def assignments?(body)
63
- !assigned_variables.empty? && body == @expressions
64
- end
65
-
66
- # Return the list of variables first declared in current scope.
67
- def declared_variables
68
- @variables.select {|k, v| v == :var }.map {|pair| pair[0].to_s }.sort
69
- end
70
-
71
- # Return the list of variables that are supposed to be assigned at the top
72
- # of scope.
73
- def assigned_variables
74
- @variables.select {|k, v| v.is_a?(Value) }.sort_by {|pair| pair[0].to_s }
75
- end
76
-
77
- def compiled_declarations
78
- declared_variables.join(', ')
79
- end
80
-
81
- def compiled_assignments
82
- assigned_variables.map {|name, val| "#{name} = #{val}"}.join(', ')
83
- end
84
-
85
- def inspect
86
- "<Scope:#{__id__} #{@variables.inspect}>"
87
- end
88
-
89
- end
90
-
91
- end
@@ -1,64 +0,0 @@
1
- module CoffeeScript
2
-
3
- # Instead of producing raw Ruby objects, the Lexer produces values of this
4
- # class, wrapping native objects tagged with line number information.
5
- # Values masquerade as both strings and nodes -- being used both as nodes in
6
- # the AST, and as literally-interpolated values in the generated code.
7
- class Value
8
- attr_reader :value, :line
9
-
10
- def initialize(value, line=nil)
11
- @value, @line = value, line
12
- end
13
-
14
- def to_str
15
- @value.to_s
16
- end
17
- alias_method :to_s, :to_str
18
-
19
- def to_sym
20
- to_str.to_sym
21
- end
22
-
23
- def compile(o={})
24
- to_s
25
- end
26
-
27
- def inspect
28
- @value.inspect
29
- end
30
-
31
- def ==(other)
32
- @value == other
33
- end
34
-
35
- def [](index)
36
- @value[index]
37
- end
38
-
39
- def eql?(other)
40
- @value.eql?(other)
41
- end
42
-
43
- def hash
44
- @value.hash
45
- end
46
-
47
- def match(regex)
48
- @value.match(regex)
49
- end
50
-
51
- def children
52
- []
53
- end
54
-
55
- def statement_only?
56
- false
57
- end
58
-
59
- def contains?
60
- false
61
- end
62
- end
63
-
64
- end
@@ -1,8 +0,0 @@
1
- {
2
- "name": "coffee-script",
3
- "lib": "lib/coffee_script/narwhal",
4
- "description": "Unfancy JavaScript",
5
- "keywords": ["javascript", "language"],
6
- "author": "Jeremy Ashkenas",
7
- "version": "0.3.2"
8
- }