coffee-script 0.3.1 → 0.3.2

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.
@@ -0,0 +1,11 @@
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
+ })();
@@ -0,0 +1,73 @@
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
+ })();
data/package.json CHANGED
@@ -1,9 +1,8 @@
1
1
  {
2
2
  "name": "coffee-script",
3
- "lib": "lib/coffee_script/narwhal/lib",
4
- "preload": ["coffee-script/loader"],
3
+ "lib": "lib/coffee_script/narwhal",
5
4
  "description": "Unfancy JavaScript",
6
5
  "keywords": ["javascript", "language"],
7
6
  "author": "Jeremy Ashkenas",
8
- "version": "0.3.1"
7
+ "version": "0.3.2"
9
8
  }
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.3.1
4
+ version: 0.3.2
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-27 00:00:00 -05:00
12
+ date: 2010-02-08 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -23,6 +23,7 @@ extra_rdoc_files: []
23
23
 
24
24
  files:
25
25
  - bin/coffee
26
+ - examples/blocks.coffee
26
27
  - examples/code.coffee
27
28
  - examples/poignant.coffee
28
29
  - examples/potion.coffee
@@ -33,17 +34,22 @@ files:
33
34
  - extras/CoffeeScript.tmbundle/Syntaxes/CoffeeScript.tmLanguage
34
35
  - extras/EXTRAS
35
36
  - lib/coffee-script.rb
37
+ - lib/coffee_script/coffee-script.js
36
38
  - lib/coffee_script/command_line.rb
37
39
  - lib/coffee_script/grammar.y
40
+ - lib/coffee_script/lexer.js
38
41
  - lib/coffee_script/lexer.rb
39
- - lib/coffee_script/narwhal/coffee-script.coffee
40
- - lib/coffee_script/narwhal/lib/coffee-script/loader.js
41
- - lib/coffee_script/narwhal/lib/coffee-script.js
42
- - lib/coffee_script/narwhal/loader.coffee
42
+ - lib/coffee_script/narwhal/coffee-script.js
43
+ - lib/coffee_script/nodes.js
43
44
  - lib/coffee_script/nodes.rb
44
45
  - lib/coffee_script/parse_error.rb
46
+ - lib/coffee_script/parser.js
45
47
  - lib/coffee_script/parser.rb
48
+ - lib/coffee_script/repl.js
49
+ - lib/coffee_script/rewriter.js
46
50
  - lib/coffee_script/rewriter.rb
51
+ - lib/coffee_script/runner.js
52
+ - lib/coffee_script/scope.js
47
53
  - lib/coffee_script/scope.rb
48
54
  - lib/coffee_script/value.rb
49
55
  - coffee-script.gemspec
@@ -1,62 +0,0 @@
1
- # This (javascript) file is generated from lib/coffee_script/narwhal/coffee-script.coffee
2
-
3
- # Executes the `coffee` Ruby program to convert from CoffeeScript
4
- # to Javascript. Eventually this will hopefully happen entirely within JS.
5
-
6
- # Require external dependencies.
7
- OS: require('os')
8
- File: require('file')
9
- Readline: require('readline')
10
-
11
- # The path to the CoffeeScript Compiler.
12
- coffeePath: File.path(module.path).dirname().dirname().dirname().dirname().dirname().join('bin', 'coffee')
13
-
14
- # Our general-purpose error handler.
15
- checkForErrors: (coffeeProcess) ->
16
- return true if coffeeProcess.wait() is 0
17
- system.stderr.print(coffeeProcess.stderr.read())
18
- throw new Error("CoffeeScript compile error")
19
-
20
- # Run a simple REPL, round-tripping to the CoffeeScript compiler for every
21
- # command.
22
- exports.run: (args) ->
23
- if args.length
24
- for path, i in args
25
- exports.evalCS(File.read(path))
26
- delete args[i]
27
- return true
28
-
29
- while true
30
- try
31
- system.stdout.write('coffee> ').flush()
32
- result: exports.evalCS(Readline.readline(), ['--globals'])
33
- print(result) if result isnt undefined
34
- catch e
35
- print(e)
36
-
37
- # Compile a given CoffeeScript file into JavaScript.
38
- exports.compileFile: (path) ->
39
- coffee: OS.popen([coffeePath, "--print", "--no-wrap", path])
40
- checkForErrors(coffee)
41
- coffee.stdout.read()
42
-
43
- # Compile a string of CoffeeScript into JavaScript.
44
- exports.compile: (source, flags) ->
45
- coffee: OS.popen([coffeePath, "--eval", "--no-wrap"].concat(flags or []))
46
- coffee.stdin.write(source).flush().close()
47
- checkForErrors(coffee)
48
- coffee.stdout.read()
49
-
50
- # Evaluating a string of CoffeeScript first compiles it externally.
51
- exports.evalCS: (source, flags) ->
52
- eval(exports.compile(source, flags))
53
-
54
- # Make a factory for the CoffeeScript environment.
55
- exports.makeNarwhalFactory: (path) ->
56
- code: exports.compileFile(path)
57
- factoryText: "function(require,exports,module,system,print){" + code + "/**/\n}"
58
- if system.engine is "rhino"
59
- Packages.org.mozilla.javascript.Context.getCurrentContext().compileFunction(global, factoryText, path, 0, null)
60
- else
61
- # eval requires parentheses, but parentheses break compileFunction.
62
- eval("(" + factoryText + ")")
@@ -1,21 +0,0 @@
1
- (function(){
2
- var coffeescript, factories, loader;
3
- // This (javascript) file is generated from lib/coffee_script/narwhal/loader.coffee
4
- coffeescript = null;
5
- factories = {
6
- };
7
- loader = {
8
- // Reload the coffee-script environment from source.
9
- reload: function reload(topId, path) {
10
- coffeescript = coffeescript || require('coffee-script');
11
- return factories[topId] = function() {
12
- return coffeescript.makeNarwhalFactory(path);
13
- };
14
- },
15
- // Ensure that the coffee-script environment is loaded.
16
- load: function load(topId, path) {
17
- return factories[topId] = factories[topId] || this.reload(topId, path);
18
- }
19
- };
20
- require.loader.loaders.unshift([".coffee", loader]);
21
- })();
@@ -1,19 +0,0 @@
1
- # This (javascript) file is generated from lib/coffee_script/narwhal/loader.coffee
2
-
3
- coffeescript: null
4
- factories: {}
5
-
6
- loader: {
7
-
8
- # Reload the coffee-script environment from source.
9
- reload: (topId, path) ->
10
- coffeescript ||= require('coffee-script')
11
- factories[topId]: -> coffeescript.makeNarwhalFactory(path)
12
-
13
- # Ensure that the coffee-script environment is loaded.
14
- load: (topId, path) ->
15
- factories[topId] ||= this.reload(topId, path)
16
-
17
- }
18
-
19
- require.loader.loaders.unshift([".coffee", loader])