fixes #1724: regular expressions beginning with `*`

also normalised capitalisation in a few error messages
This commit is contained in:
Michael Ficarra 2011-09-22 04:09:58 -04:00
parent 08762a101c
commit f4c1b20ec2
3 changed files with 15 additions and 6 deletions

View File

@ -72,7 +72,7 @@
id = new String(id);
id.reserved = true;
} else if (__indexOf.call(RESERVED, id) >= 0) {
this.error("Reserved word \"" + word + "\"");
this.error("reserved word \"" + word + "\"");
}
}
if (!forcedIdentifier) {
@ -194,7 +194,11 @@
}
if (!(match = REGEX.exec(this.chunk))) return 0;
regex = match[0];
this.token('REGEX', regex === '//' ? '/(?:)/' : regex);
if (regex.match(/^\/\*/)) {
this.error('regular expressions cannot begin with `*`');
}
if (regex === '//') regex = '/(?:)/';
this.token('REGEX', regex);
return regex.length;
};
@ -338,7 +342,7 @@
prev = last(this.tokens);
if (value === '=' && prev) {
if (!prev[1].reserved && (_ref3 = prev[1], __indexOf.call(JS_FORBIDDEN, _ref3) >= 0)) {
this.error("Reserved word \"" + (this.value()) + "\" can't be assigned");
this.error("reserved word \"" + (this.value()) + "\" can't be assigned");
}
if ((_ref4 = prev[1]) === '||' || _ref4 === '&&') {
prev[0] = 'COMPOUND_ASSIGN';

View File

@ -112,7 +112,7 @@ exports.Lexer = class Lexer
id = new String id
id.reserved = yes
else if id in RESERVED
@error "Reserved word \"#{word}\""
@error "reserved word \"#{word}\""
unless forcedIdentifier
id = COFFEE_ALIAS_MAP[id] if id in COFFEE_ALIASES
@ -199,7 +199,9 @@ exports.Lexer = class Lexer
return 0 if prev and (prev[0] in (if prev.spaced then NOT_REGEX else NOT_SPACED_REGEX))
return 0 unless match = REGEX.exec @chunk
[regex] = match
@token 'REGEX', if regex is '//' then '/(?:)/' else regex
if regex.match /^\/\*/ then @error 'regular expressions cannot begin with `*`'
if regex is '//' then regex = '/(?:)/'
@token 'REGEX', regex
regex.length
# Matches multiline extended regular expressions.
@ -324,7 +326,7 @@ exports.Lexer = class Lexer
prev = last @tokens
if value is '=' and prev
if not prev[1].reserved and prev[1] in JS_FORBIDDEN
@error "Reserved word \"#{@value()}\" can't be assigned"
@error "reserved word \"#{@value()}\" can't be assigned"
if prev[1] in ['||', '&&']
prev[0] = 'COMPOUND_ASSIGN'
prev[1] += '='

View File

@ -38,6 +38,9 @@ test "#764: regular expressions should be indexable", ->
test "#584: slashes are allowed unescaped in character classes", ->
ok /^a\/[/]b$/.test 'a//b'
test "#1724: regular expressions beginning with `*`", ->
throws -> CoffeeScript.compile '/*/'
# Heregexe(n|s)