Merge branch 'master' of github.com:jashkenas/coffee-script

This commit is contained in:
Jeremy Ashkenas 2010-10-10 11:29:29 -04:00
commit 9c54291d04
10 changed files with 26 additions and 23 deletions

View File

@ -27,11 +27,11 @@
throw err;
}
});
exports.tokens = function(code) {
return lexer.tokenize(code);
exports.tokens = function(code, options) {
return lexer.tokenize(code, options);
};
exports.nodes = function(code) {
return parser.parse(lexer.tokenize(code));
exports.nodes = function(code, options) {
return parser.parse(lexer.tokenize(code, options));
};
exports.run = function(code, options) {
var root;

View File

@ -605,7 +605,7 @@
MULTI_DENT = /^(?:\n[ \t]*)+/;
SIMPLESTR = /^'[^\\']*(?:\\.[^\\']*)*'/;
JSTOKEN = /^`[^\\`]*(?:\\.[^\\`]*)*`/;
REGEX = /^\/(?!\s)(?:[^[\/\n\\]+|\\.|\[([^\\\]]+|\\.)*])+\/[imgy]{0,4}(?![A-Za-z])/;
REGEX = /^\/(?!\s)(?:[^[\/\n\\]+|\\[\s\S]|\[([^\]\n\\]+|\\[\s\S])*])+\/[imgy]{0,4}(?![A-Za-z])/;
HEREGEX = /^\/{3}([\s\S]+?)\/{3}([imgy]{0,4})(?![A-Za-z])/;
HEREGEX_OMIT = /\s+(?:#.*)?/g;
MULTILINER = /\n/g;

View File

@ -1382,10 +1382,6 @@
return Op.__super__.toString.call(this, idt, this.constructor.name + ' ' + this.operator);
};
Op.prototype.compileNode = function(o) {
var node;
if (node = Value.unfoldSoak(o, this, 'first')) {
return node.compile(o);
}
if (this.isChainable() && this.first.unwrap() instanceof Op && this.first.unwrap().isChainable()) {
return this.compileChain(o);
}

View File

@ -29,10 +29,10 @@
return true;
};
exports.Rewriter.prototype.detectEnd = function(i, condition, action) {
var levels, token;
var levels, token, tokens;
tokens = this.tokens;
levels = 0;
while (true) {
token = this.tokens[i];
while (token = tokens[i]) {
if (levels === 0 && condition.call(this, token, i)) {
return action.call(this, token, i);
}

View File

@ -33,14 +33,14 @@ exports.compile = compile = (code, options) ->
throw err
# Tokenize a string of CoffeeScript code, and return the array of tokens.
exports.tokens = (code) ->
lexer.tokenize code
exports.tokens = (code, options) ->
lexer.tokenize code, options
# Tokenize and parse a string of CoffeeScript code, and return the AST. You can
# then compile it by calling `.compile()` on the root, or traverse it by using
# `.traverse()` with a callback.
exports.nodes = (code) ->
parser.parse lexer.tokenize code
exports.nodes = (code, options) ->
parser.parse lexer.tokenize code, options
# Compile and execute a string of CoffeeScript (on the server), correctly
# setting `__filename`, `__dirname`, and relative `require()`.

View File

@ -557,10 +557,10 @@ JSTOKEN = /^`[^\\`]*(?:\\.[^\\`]*)*`/
# Regex-matching-regexes.
REGEX = /// ^
/ (?!\s) # disallow leading whitespace
(?: [^ [ / \n \\ ]+ # every other thing
| \\. # anything escaped
| \[ ( [^\\\]]+ | \\. )* ] # character class
/ (?!\s) # disallow leading whitespace
(?: [^ [ / \n \\ ]+ # every other thing
| \\[\s\S] # anything escaped
| \[ ( [^ \] \n \\ ]+ | \\[\s\S] )* ] # character class
)+
/ [imgy]{0,4} (?![A-Za-z])
///

View File

@ -1201,7 +1201,6 @@ exports.Op = class Op extends Base
super(idt, @constructor.name + ' ' + @operator)
compileNode: (o) ->
return node.compile o if node = Value.unfoldSoak o, this, 'first'
return @compileChain(o) if @isChainable() and @first.unwrap() instanceof Op and @first.unwrap().isChainable()
return @compileAssignment(o) if indexOf(@ASSIGNMENT, @operator) >= 0
return @compileUnary(o) if @isUnary()

View File

@ -46,9 +46,9 @@ class exports.Rewriter
true
detectEnd: (i, condition, action) ->
{tokens} = this
levels = 0
loop
token = @tokens[i]
while token = tokens[i]
return action.call this, token, i if levels is 0 and condition.call this, token, i
return action.call this, token, i - 1 if not token or levels < 0
if include EXPRESSION_START, token[0]

View File

@ -13,3 +13,10 @@ CoffeeScript.run("resultArray.push i for i of global", {noWrap: on, globals: on,
ok 'setInterval' in global.resultArray
ok 'passed' is CoffeeScript.eval '"passed"', noWrap: on, globals: on, fileName: 'tests'
#750
try
CoffeeScript.nodes 'f(->'
ok no
catch e
eq e.message, 'unclosed CALL_START on line 1'

View File

@ -92,6 +92,7 @@ ok not value?.property?, 'safely checks existence on soaks'
eq nothing?.value, undefined, 'safely calls values off of non-existent variables'
eq !nothing?.value and 1, 1, 'corresponding operators work as expected'
# Assign to the result of an exsitential operation with a minus.