From 7a4fd2ec014135746ea60948fd9fe3bfa843e0e5 Mon Sep 17 00:00:00 2001 From: Michael Ficarra Date: Fri, 6 May 2011 09:47:40 -0400 Subject: [PATCH] slightly improved fix for #1182 and #1313 --- lib/command.js | 2 +- lib/nodes.js | 13 ++++--------- src/nodes.coffee | 7 +------ 3 files changed, 6 insertions(+), 16 deletions(-) diff --git a/lib/command.js b/lib/command.js index bec08e73..fa2fe2e3 100644 --- a/lib/command.js +++ b/lib/command.js @@ -15,7 +15,7 @@ return process.binding('stdio').writeError(line + '\n'); }; BANNER = 'Usage: coffee [options] path/to/script.coffee'; - SWITCHES = [['-c', '--compile', 'compile to JavaScript and save as .js files'], ['-i', '--interactive', 'run an interactive CoffeeScript REPL'], ['-o', '--output [DIR]', 'set the directory for compiled JavaScript'], ['-j', '--join [FILE]', 'concatenate the scripts before compiling'], ['-w', '--watch', 'watch scripts for changes, and recompile'], ['-p', '--print', 'print the compiled JavaScript to stdout'], ['-l', '--lint', 'pipe the compiled JavaScript through JSLint'], ['-s', '--stdio', 'listen for and compile scripts over stdio'], ['-e', '--eval', 'compile a string from the command line'], ['-r', '--require [FILE*]', 'require a library before executing your script'], ['-b', '--bare', 'compile without the top-level function wrapper'], ['-t', '--tokens', 'print the tokens that the lexer produces'], ['-n', '--nodes', 'print the parse tree that Jison produces'], ['--nodejs [ARGS]', 'pass options through to the "node" binary'], ['-v', '--version', 'display CoffeeScript version'], ['-h', '--help', 'display this help message']]; + SWITCHES = [['-c', '--compile', 'compile to JavaScript and save as .js files'], ['-i', '--interactive', 'run an interactive CoffeeScript REPL'], ['-o', '--output [DIR]', 'set the directory for compiled JavaScript'], ['-j', '--join [FILE]', 'concatenate the scripts before compiling'], ['-w', '--watch', 'watch scripts for changes, and recompile'], ['-p', '--print', 'print the compiled JavaScript to stdout'], ['-l', '--lint', 'pipe the compiled JavaScript through JavaScript Lint'], ['-s', '--stdio', 'listen for and compile scripts over stdio'], ['-e', '--eval', 'compile a string from the command line'], ['-r', '--require [FILE*]', 'require a library before executing your script'], ['-b', '--bare', 'compile without the top-level function wrapper'], ['-t', '--tokens', 'print the tokens that the lexer produces'], ['-n', '--nodes', 'print the parse tree that Jison produces'], ['--nodejs [ARGS]', 'pass options through to the "node" binary'], ['-v', '--version', 'display CoffeeScript version'], ['-h', '--help', 'display this help message']]; opts = {}; sources = []; contents = []; diff --git a/lib/nodes.js b/lib/nodes.js index ebf6db1b..ab78fa9d 100644 --- a/lib/nodes.js +++ b/lib/nodes.js @@ -1096,24 +1096,19 @@ return this.ctor.noReturn = true; }; Class.prototype.compileNode = function(o) { - var decl, extension, klass, lname, name; + var decl, klass, lname, name; decl = this.determineName(); name = decl || this.name || '_Class'; lname = new Literal(name); this.setContext(name); this.walkBody(name); this.ensureConstructor(name); + if (this.parent) { + this.body.expressions.unshift(new Extends(lname, this.parent)); + } if (!(this.ctor instanceof Code)) { this.body.expressions.unshift(this.ctor); } - if (this.parent) { - extension = new Extends(lname, this.parent); - if (this.ctor instanceof Code) { - this.body.expressions.unshift(extension); - } else { - this.body.expressions.splice(1, 0, extension); - } - } this.body.expressions.push(lname); this.addBoundFunctions(o); klass = new Parens(Closure.wrap(this.body), true); diff --git a/src/nodes.coffee b/src/nodes.coffee index 18cb3fcf..55f493df 100644 --- a/src/nodes.coffee +++ b/src/nodes.coffee @@ -875,13 +875,8 @@ exports.Class = class Class extends Base @setContext name @walkBody name @ensureConstructor name + @body.expressions.unshift new Extends lname, @parent if @parent @body.expressions.unshift @ctor unless @ctor instanceof Code - if @parent - extension = new Extends lname, @parent - if @ctor instanceof Code - @body.expressions.unshift extension - else - @body.expressions.splice 1, 0, extension @body.expressions.push lname @addBoundFunctions o