Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also .

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also .
...
  • 4 commits
  • 10 files changed
  • 0 commit comments
  • 1 contributor
@@ -1,12 +1,17 @@
Gem::Specification.new do |s|
s.name = 'coffee-script'
- s.version = '0.1.0' # Keep version in sync with coffee-script.rb
+ s.version = '0.1.1' # Keep version in sync with coffee-script.rb
s.date = '2009-12-24'
s.homepage = "http://jashkenas.github.com/coffee-script/"
s.summary = "The CoffeeScript Compiler"
s.description = <<-EOS
- CoffeeScript is a little language that compiles into JavaScript.
+ CoffeeScript is a little language that compiles into JavaScript. Think
+ of it as JavaScript's less ostentatious kid brother -- the same genes,
+ roughly the same height, but a different sense of style. Apart from a
+ handful of bonus goodies, statements in CoffeeScript correspond
+ one-to-one with their equivalent in JavaScript, it's just another
+ way of saying it.
EOS
s.authors = ['Jeremy Ashkenas']
@@ -405,6 +405,11 @@ coffee-script --print app/scripts/*.cs > concatenation.js</pre>
Integration with Processing.js's JavaScript API (this would depend on
having a JavaScript version of the compiler).
</li>
+ <li>
+ A lot of the code generation in <tt>nodes.rb</tt> gets into messy
+ string manipulation. Techniques for cleaning this up across the board
+ would be appreciated.
+ </li>
</ul>
<h2 id="change_log">Change Log</h2>
View
@@ -784,6 +784,11 @@ <h2 id="contributing">Contributing</h2>
Integration with Processing.js's JavaScript API (this would depend on
having a JavaScript version of the compiler).
</li>
+ <li>
+ A lot of the code generation in <tt>nodes.rb</tt> gets into messy
+ string manipulation. Techniques for cleaning this up across the board
+ would be appreciated.
+ </li>
</ul>
<h2 id="change_log">Change Log</h2>
@@ -9,7 +9,7 @@
# Namespace for all CoffeeScript internal classes.
module CoffeeScript
- VERSION = '0.1.0' # Keep in sync with the gemspec.
+ VERSION = '0.1.1' # Keep in sync with the gemspec.
# Compile a script (String or IO) to JavaScript.
def self.compile(script)
@@ -10,8 +10,8 @@ token TRY CATCH FINALLY THROW
token BREAK CONTINUE
token FOR IN WHILE
token SWITCH WHEN
+token DELETE INSTANCEOF TYPEOF
token SUPER
-token DELETE
token NEWLINE
token COMMENT
token JS
@@ -27,7 +27,7 @@ prechigh
right '==' '!=' IS AINT
left '&&' '||' AND OR
right '-=' '+=' '/=' '*='
- right DELETE
+ right DELETE INSTANCEOF TYPEOF
left "."
right THROW FOR IN WHILE NEW
left UNLESS IF ELSE
@@ -185,6 +185,8 @@ rule
| Expression '&&:' Expression { result = OpNode.new(val[1], val[0], val[2]) }
| DELETE Expression { result = OpNode.new(val[0], val[1]) }
+ | TYPEOF Expression { result = OpNode.new(val[0], val[1]) }
+ | Expression INSTANCEOF Expression { result = OpNode.new(val[1], val[0], val[2]) }
;
# Function definition.
@@ -15,7 +15,7 @@ class Lexer
"for", "in", "while",
"switch", "when",
"super",
- "delete"]
+ "delete", "instanceof", "typeof"]
# Token matching regexes.
IDENTIFIER = /\A([a-zA-Z$_]\w*)/
@@ -342,7 +342,8 @@ class OpNode < Node
"aint" => "!==",
'not' => '!',
}
- CONDITIONALS = ['||:', '&&:']
+ CONDITIONALS = ['||:', '&&:']
+ PREFIX_OPERATORS = ['typeof', 'delete']
attr_reader :operator, :first, :second
@@ -369,7 +370,7 @@ def compile_conditional(o)
end
def compile_unary(o)
- space = @operator.to_s == 'delete' ? ' ' : ''
+ space = PREFIX_OPERATORS.include?(@operator.to_s) ? ' ' : ''
parts = [@operator.to_s, space, @first.compile(o)]
parts.reverse! if @flip
parts.join('')
Oops, something went wrong.
@@ -0,0 +1,10 @@
+a: 5
+atype: typeof a
+
+b: "hello"
+btype: typeof b
+
+Klass: => .
+k: new Klass()
+
+print(atype is 'number' and btype is 'string' and k instanceof Klass)
@@ -0,0 +1,10 @@
+(function(){
+ var a = 5;
+ var atype = typeof a;
+ var b = "hello";
+ var btype = typeof b;
+ var Klass = function() {
+ };
+ var k = new Klass();
+ print(atype === 'number' && btype === 'string' && k instanceof Klass);
+})();

No commit comments for this range