mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-04-11 03:00:13 -04:00
lexer: fixed a regression where assignmentError wasn't fired
This commit is contained in:
57
lib/lexer.js
57
lib/lexer.js
@@ -29,17 +29,17 @@
|
||||
return (new Rewriter).rewrite(this.tokens);
|
||||
};
|
||||
Lexer.prototype.identifierToken = function() {
|
||||
var forcedIdentifier, id, match, tag;
|
||||
var _ref2, colon, forcedIdentifier, id, input, match, tag;
|
||||
if (!(match = IDENTIFIER.exec(this.chunk))) {
|
||||
return false;
|
||||
}
|
||||
id = match[0];
|
||||
this.i += id.length;
|
||||
_ref2 = match, input = _ref2[0], id = _ref2[1], colon = _ref2[2];
|
||||
this.i += input.length;
|
||||
if (id === 'all' && this.tag() === 'FOR') {
|
||||
this.token('ALL', id);
|
||||
return true;
|
||||
}
|
||||
forcedIdentifier = this.tagAccessor() || ASSIGNED.test(this.chunk);
|
||||
forcedIdentifier = colon || this.tagAccessor();
|
||||
tag = 'IDENTIFIER';
|
||||
if (include(JS_KEYWORDS, id) || !forcedIdentifier && include(COFFEE_KEYWORDS, id)) {
|
||||
tag = id.toUpperCase();
|
||||
@@ -85,6 +85,9 @@
|
||||
}
|
||||
}
|
||||
this.token(tag, id);
|
||||
if (colon) {
|
||||
this.token(':', ':');
|
||||
}
|
||||
return true;
|
||||
};
|
||||
Lexer.prototype.numberToken = function() {
|
||||
@@ -241,7 +244,7 @@
|
||||
prev = last(this.tokens, 1);
|
||||
size = indent.length - 1 - indent.lastIndexOf('\n');
|
||||
nextCharacter = NEXT_CHARACTER.exec(this.chunk)[1];
|
||||
noNewlines = (('.' === nextCharacter || ',' === nextCharacter)) || this.unfinished();
|
||||
noNewlines = ('.' === nextCharacter || ',' === nextCharacter) || this.unfinished();
|
||||
if (size - this.indebt === this.indent) {
|
||||
if (noNewlines) {
|
||||
return this.suppressNewlines();
|
||||
@@ -332,9 +335,9 @@
|
||||
if (!prev[1].reserved && include(JS_FORBIDDEN, prev[1])) {
|
||||
this.assignmentError();
|
||||
}
|
||||
if (('or' === (_ref2 = prev[1]) || 'and' === _ref2)) {
|
||||
if (('||' === (_ref2 = prev[1]) || '&&' === _ref2)) {
|
||||
prev[0] = 'COMPOUND_ASSIGN';
|
||||
prev[1] = COFFEE_ALIASES[prev[1]] + '=';
|
||||
prev[1] += '=';
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -376,25 +379,23 @@
|
||||
return true;
|
||||
};
|
||||
Lexer.prototype.tagAccessor = function() {
|
||||
var accessor, prev;
|
||||
var prev;
|
||||
if (!(prev = last(this.tokens)) || prev.spaced) {
|
||||
return false;
|
||||
}
|
||||
accessor = (function() {
|
||||
if (prev[1] === '::') {
|
||||
return this.tag(0, 'PROTOTYPE_ACCESS');
|
||||
} else if (prev[1] === '.' && this.value(1) !== '.') {
|
||||
if (this.tag(1) === '?') {
|
||||
this.tag(0, 'SOAK_ACCESS');
|
||||
return this.tokens.splice(-2, 1);
|
||||
} else {
|
||||
return this.tag(0, 'PROPERTY_ACCESS');
|
||||
}
|
||||
if (prev[1] === '::') {
|
||||
this.tag(0, 'PROTOTYPE_ACCESS');
|
||||
} else if (prev[1] === '.' && this.value(1) !== '.') {
|
||||
if (this.tag(1) === '?') {
|
||||
this.tag(0, 'SOAK_ACCESS');
|
||||
this.tokens.splice(-2, 1);
|
||||
} else {
|
||||
return prev[0] === '@';
|
||||
this.tag(0, 'PROPERTY_ACCESS');
|
||||
}
|
||||
}).call(this);
|
||||
return accessor ? 'accessor' : false;
|
||||
} else {
|
||||
return prev[0] === '@';
|
||||
}
|
||||
return true;
|
||||
};
|
||||
Lexer.prototype.sanitizeHeredoc = function(doc, options) {
|
||||
var _ref2, _ref3, attempt, herecomment, indent, match;
|
||||
@@ -424,10 +425,7 @@
|
||||
return;
|
||||
}
|
||||
i = this.tokens.length;
|
||||
while (true) {
|
||||
if (!(tok = this.tokens[--i])) {
|
||||
return;
|
||||
}
|
||||
while (tok = this.tokens[--i]) {
|
||||
switch (tok[0]) {
|
||||
case 'IDENTIFIER':
|
||||
tok[0] = 'PARAM';
|
||||
@@ -437,7 +435,8 @@
|
||||
break;
|
||||
case '(':
|
||||
case 'CALL_START':
|
||||
return (tok[0] = 'PARAM_START');
|
||||
tok[0] = 'PARAM_START';
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
@@ -446,10 +445,10 @@
|
||||
return this.outdentToken(this.indent);
|
||||
};
|
||||
Lexer.prototype.identifierError = function(word) {
|
||||
throw new Error("SyntaxError: Reserved word \"" + word + "\" on line " + (this.line + 1));
|
||||
throw SyntaxError("Reserved word \"" + word + "\" on line " + (this.line + 1));
|
||||
};
|
||||
Lexer.prototype.assignmentError = function() {
|
||||
throw new Error("SyntaxError: Reserved word \"" + (this.value()) + "\" on line " + (this.line + 1) + " can't be assigned");
|
||||
throw SyntaxError("Reserved word \"" + (this.value()) + "\" on line " + (this.line + 1) + " can't be assigned");
|
||||
};
|
||||
Lexer.prototype.balancedString = function(str, delimited, options) {
|
||||
var _i, _len, _ref2, close, i, levels, open, pair, slen;
|
||||
@@ -598,7 +597,7 @@
|
||||
COFFEE_ALIASES['==='] = '==';
|
||||
RESERVED = ['case', 'default', 'do', 'function', 'var', 'void', 'with', 'const', 'let', 'enum', 'export', 'import', 'native', '__hasProp', '__extends', '__slice'];
|
||||
JS_FORBIDDEN = JS_KEYWORDS.concat(RESERVED);
|
||||
IDENTIFIER = /^[a-zA-Z_$][\w$]*/;
|
||||
IDENTIFIER = /^([$A-Za-z_][$\w]*)([^\n\S]*:(?!:))?/;
|
||||
NUMBER = /^0x[\da-f]+|^(?:\d+(\.\d+)?|\.\d+)(?:e[+-]?\d+)?/i;
|
||||
HEREDOC = /^("""|''')([\s\S]*?)(?:\n[ \t]*)?\1/;
|
||||
OPERATOR = /^(?:-[-=>]?|\+[+=]?|[*&|\/%=<>^:!?]+)/;
|
||||
|
||||
Reference in New Issue
Block a user