coffeescript
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -42,3 +42,3 @@ (function() { | ||
CoffeeScript.run(fs.readFileSync('Cakefile').toString(), { | ||
fileName: 'Cakefile' | ||
filename: 'Cakefile' | ||
}); | ||
@@ -45,0 +45,0 @@ oparse = new optparse.OptionParser(switches); |
@@ -18,3 +18,3 @@ (function() { | ||
} | ||
exports.VERSION = '1.0.0'; | ||
exports.VERSION = '1.0.1'; | ||
exports.RESERVED = RESERVED; | ||
@@ -29,4 +29,4 @@ exports.helpers = require('./helpers'); | ||
} catch (err) { | ||
if (options.fileName) { | ||
err.message = "In " + options.fileName + ", " + err.message; | ||
if (options.filename) { | ||
err.message = "In " + options.filename + ", " + err.message; | ||
} | ||
@@ -52,3 +52,3 @@ throw err; | ||
} | ||
root.filename = fs.realpathSync(options.fileName || '.'); | ||
root.filename = options.filename ? fs.realpathSync(options.filename) : '.'; | ||
if (root.moduleCache) { | ||
@@ -65,3 +65,3 @@ root.moduleCache = {}; | ||
var __dirname, __filename; | ||
__filename = options.fileName; | ||
__filename = module.filename = options.filename; | ||
__dirname = path.dirname(__filename); | ||
@@ -68,0 +68,0 @@ return eval(compile(code, options)); |
(function() { | ||
var BANNER, CoffeeScript, EventEmitter, SWITCHES, compileJoin, compileOptions, compileScript, compileScripts, compileStdio, contents, exec, forkNode, fs, helpers, lint, optionParser, optparse, opts, parseOptions, path, printLine, printTokens, printWarn, sources, spawn, usage, util, version, watch, writeJs, _ref; | ||
var BANNER, CoffeeScript, EventEmitter, SWITCHES, compileJoin, compileOptions, compileScript, compileScripts, compileStdio, contents, exec, forkNode, fs, helpers, lint, loadRequires, optionParser, optparse, opts, parseOptions, path, printLine, printTokens, printWarn, sources, spawn, usage, version, watch, writeJs, _ref; | ||
fs = require('fs'); | ||
path = require('path'); | ||
util = require('util'); | ||
helpers = require('./helpers'); | ||
@@ -35,2 +34,5 @@ optparse = require('./optparse'); | ||
} | ||
if (opts.require) { | ||
loadRequires(); | ||
} | ||
if (opts.interactive) { | ||
@@ -62,3 +64,3 @@ return require('./repl'); | ||
return path.exists(source, function(exists) { | ||
if (!exists) { | ||
if (topLevel && !exists) { | ||
throw new Error("File not found: " + source); | ||
@@ -100,12 +102,5 @@ } | ||
compileScript = function(file, input, base) { | ||
var o, options, req, t, task, _i, _len, _ref; | ||
var o, options, t, task; | ||
o = opts; | ||
options = compileOptions(file); | ||
if (o.require) { | ||
_ref = o.require; | ||
for (_i = 0, _len = _ref.length; _i < _len; _i++) { | ||
req = _ref[_i]; | ||
require(helpers.starts(req, '.') ? fs.realpathSync(req) : req); | ||
} | ||
} | ||
try { | ||
@@ -165,2 +160,13 @@ t = task = { | ||
}; | ||
loadRequires = function() { | ||
var realFilename, req, _i, _len, _ref; | ||
realFilename = module.filename; | ||
module.filename = '.'; | ||
_ref = opts.require; | ||
for (_i = 0, _len = _ref.length; _i < _len; _i++) { | ||
req = _ref[_i]; | ||
require(req); | ||
} | ||
return module.filename = realFilename; | ||
}; | ||
watch = function(source, base) { | ||
@@ -197,3 +203,3 @@ return fs.watchFile(source, { | ||
} else if (opts.compile && opts.watch) { | ||
return util.log("compiled " + source); | ||
return console.log("" + ((new Date).toTimeString()) + " - compiled " + source); | ||
} | ||
@@ -245,5 +251,5 @@ }); | ||
}; | ||
compileOptions = function(fileName) { | ||
compileOptions = function(filename) { | ||
return { | ||
fileName: fileName, | ||
filename: filename, | ||
bare: opts.bare | ||
@@ -264,9 +270,7 @@ }; | ||
usage = function() { | ||
printLine((new optparse.OptionParser(SWITCHES, BANNER)).help()); | ||
return process.exit(0); | ||
return printLine((new optparse.OptionParser(SWITCHES, BANNER)).help()); | ||
}; | ||
version = function() { | ||
printLine("CoffeeScript version " + CoffeeScript.VERSION); | ||
return process.exit(0); | ||
return printLine("CoffeeScript version " + CoffeeScript.VERSION); | ||
}; | ||
}).call(this); |
@@ -13,3 +13,3 @@ (function() { | ||
action = action.replace(/\bnew /g, '$&yy.'); | ||
action = action.replace(/\b(?:Expressions\.wrap|extend)\b/g, 'yy.$&'); | ||
action = action.replace(/\b(?:Block\.wrap|extend)\b/g, 'yy.$&'); | ||
return [patternString, "$$ = " + action + ";", options]; | ||
@@ -20,3 +20,3 @@ }; | ||
o('', function() { | ||
return new Expressions; | ||
return new Block; | ||
}), o('Body'), o('Block TERMINATOR') | ||
@@ -26,3 +26,3 @@ ], | ||
o('Line', function() { | ||
return Expressions.wrap([$1]); | ||
return Block.wrap([$1]); | ||
}), o('Body TERMINATOR Line', function() { | ||
@@ -41,3 +41,3 @@ return $1.push($3); | ||
o('INDENT OUTDENT', function() { | ||
return new Expressions; | ||
return new Block; | ||
}), o('INDENT Body OUTDENT', function() { | ||
@@ -65,3 +65,8 @@ return $2; | ||
}), o('BOOL', function() { | ||
return new Literal($1 === 'undefined' ? 'void 0' : $1); | ||
var val; | ||
val = new Literal($1); | ||
if ($1 === 'undefined') { | ||
val.isUndefined = true; | ||
} | ||
return val; | ||
}) | ||
@@ -360,5 +365,5 @@ ], | ||
}), o('Statement WhileSource', function() { | ||
return $2.addBody(Expressions.wrap([$1])); | ||
return $2.addBody(Block.wrap([$1])); | ||
}), o('Expression WhileSource', function() { | ||
return $2.addBody(Expressions.wrap([$1])); | ||
return $2.addBody(Block.wrap([$1])); | ||
}), o('Loop', function() { | ||
@@ -372,3 +377,3 @@ return $1; | ||
}), o('LOOP Expression', function() { | ||
return new While(new Literal('true')).addBody(Expressions.wrap([$2])); | ||
return new While(new Literal('true')).addBody(Block.wrap([$2])); | ||
}) | ||
@@ -491,9 +496,9 @@ ], | ||
})); | ||
}), o('IfBlock ELSE Block', function() { | ||
return $1.addElse($3); | ||
}) | ||
], | ||
If: [ | ||
o('IfBlock'), o('Statement POST_IF Expression', function() { | ||
return new If($3, Expressions.wrap([$1]), { | ||
o('IfBlock'), o('IfBlock ELSE Block', function() { | ||
return $1.addElse($3); | ||
}), o('Statement POST_IF Expression', function() { | ||
return new If($3, Block.wrap([$1]), { | ||
type: $2, | ||
@@ -503,3 +508,3 @@ statement: true | ||
}), o('Expression POST_IF Expression', function() { | ||
return new If($3, Expressions.wrap([$1]), { | ||
return new If($3, Block.wrap([$1]), { | ||
type: $2, | ||
@@ -506,0 +511,0 @@ statement: true |
@@ -18,2 +18,5 @@ (function() { | ||
} | ||
if (WHITESPACE.test(code)) { | ||
code = "\n" + code; | ||
} | ||
code = code.replace(/\r/g, '').replace(TRAILING_SPACES, ''); | ||
@@ -481,3 +484,3 @@ this.code = code; | ||
Lexer.prototype.interpolateString = function(str, options) { | ||
var expr, heredoc, i, inner, interpolated, letter, nested, pi, regex, tag, tokens, value, _len, _ref, _ref2, _ref3; | ||
var expr, heredoc, i, inner, interpolated, len, letter, nested, pi, regex, tag, tokens, value, _len, _ref, _ref2, _ref3; | ||
if (options == null) { | ||
@@ -511,7 +514,9 @@ options = {}; | ||
} | ||
if (nested.length > 1) { | ||
nested.unshift(['(', '(']); | ||
nested.push([')', ')']); | ||
if (len = nested.length) { | ||
if (len > 1) { | ||
nested.unshift(['(', '(']); | ||
nested.push([')', ')']); | ||
} | ||
tokens.push(['TOKENS', nested]); | ||
} | ||
tokens.push(['TOKENS', nested]); | ||
} | ||
@@ -604,3 +609,3 @@ i += expr.length; | ||
exports.RESERVED = RESERVED.concat(JS_KEYWORDS).concat(COFFEE_KEYWORDS); | ||
IDENTIFIER = /^([$A-Za-z_][$\w]*)([^\n\S]*:(?!:))?/; | ||
IDENTIFIER = /^([$A-Za-z_\x7f-\uffff][$\w\x7f-\uffff]*)([^\n\S]*:(?!:))?/; | ||
NUMBER = /^0x[\da-f]+|^(?:\d+(\.\d+)?|\.\d+)(?:e[+-]?\d+)?/i; | ||
@@ -620,3 +625,3 @@ HEREDOC = /^("""|''')([\s\S]*?)(?:\n[^\n\S]*)?\1/; | ||
HEREDOC_INDENT = /\n+([^\n\S]*)/g; | ||
ASSIGNED = /^\s*@?([$A-Za-z_][$\w]*|['"].*['"])[^\n\S]*?[:=][^:=>]/; | ||
ASSIGNED = /^\s*@?([$A-Za-z_][$\w\x7f-\uffff]*|['"].*['"])[^\n\S]*?[:=][^:=>]/; | ||
LINE_CONTINUER = /^\s*(?:,|\??\.(?!\.)|::)/; | ||
@@ -623,0 +628,0 @@ TRAILING_SPACES = /\s+$/; |
@@ -45,3 +45,3 @@ (function() { | ||
var letPart, lines, rule, spaces, _i, _len, _ref; | ||
lines = ['Available options:']; | ||
lines = []; | ||
if (this.banner) { | ||
@@ -48,0 +48,0 @@ lines.unshift("" + this.banner + "\n"); |
(function() { | ||
var CoffeeScript, error, helpers, readline, repl, run, stdio; | ||
var CoffeeScript, error, helpers, readline, repl, run, stdin, stdout; | ||
CoffeeScript = require('./coffee-script'); | ||
helpers = require('./helpers'); | ||
readline = require('readline'); | ||
stdio = process.openStdin(); | ||
stdin = process.openStdin(); | ||
stdout = process.stdout; | ||
error = function(err) { | ||
return stdio.write((err.stack || err.toString()) + '\n\n'); | ||
return stdout.write((err.stack || err.toString()) + '\n\n'); | ||
}; | ||
@@ -21,6 +22,6 @@ helpers.extend(global, { | ||
globals: true, | ||
fileName: 'repl' | ||
filename: 'repl' | ||
}); | ||
if (val !== void 0) { | ||
console.log(val); | ||
process.stdout.write(val + '\n'); | ||
} | ||
@@ -33,9 +34,13 @@ } catch (err) { | ||
process.on('uncaughtException', error); | ||
repl = readline.createInterface(stdio); | ||
if (readline.createInterface.length < 3) { | ||
repl = readline.createInterface(stdin); | ||
stdin.on('data', function(buffer) { | ||
return repl.write(buffer); | ||
}); | ||
} else { | ||
repl = readline.createInterface(stdin, stdout); | ||
} | ||
repl.setPrompt('coffee> '); | ||
stdio.on('data', function(buffer) { | ||
return repl.write(buffer); | ||
}); | ||
repl.on('close', function() { | ||
return stdio.destroy(); | ||
return stdin.destroy(); | ||
}); | ||
@@ -42,0 +47,0 @@ repl.on('line', run); |
@@ -6,3 +6,3 @@ { | ||
"author": "Jeremy Ashkenas", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"licenses": [{ | ||
@@ -9,0 +9,0 @@ "type": "MIT", |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
268236
5575