fixes #1724: regular expressions beginning with `*`
also normalised capitalisation in a few error messages
This commit is contained in:
parent
08762a101c
commit
f4c1b20ec2
|
@ -72,7 +72,7 @@
|
||||||
id = new String(id);
|
id = new String(id);
|
||||||
id.reserved = true;
|
id.reserved = true;
|
||||||
} else if (__indexOf.call(RESERVED, id) >= 0) {
|
} else if (__indexOf.call(RESERVED, id) >= 0) {
|
||||||
this.error("Reserved word \"" + word + "\"");
|
this.error("reserved word \"" + word + "\"");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!forcedIdentifier) {
|
if (!forcedIdentifier) {
|
||||||
|
@ -194,7 +194,11 @@
|
||||||
}
|
}
|
||||||
if (!(match = REGEX.exec(this.chunk))) return 0;
|
if (!(match = REGEX.exec(this.chunk))) return 0;
|
||||||
regex = match[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;
|
return regex.length;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -338,7 +342,7 @@
|
||||||
prev = last(this.tokens);
|
prev = last(this.tokens);
|
||||||
if (value === '=' && prev) {
|
if (value === '=' && prev) {
|
||||||
if (!prev[1].reserved && (_ref3 = prev[1], __indexOf.call(JS_FORBIDDEN, _ref3) >= 0)) {
|
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 === '&&') {
|
if ((_ref4 = prev[1]) === '||' || _ref4 === '&&') {
|
||||||
prev[0] = 'COMPOUND_ASSIGN';
|
prev[0] = 'COMPOUND_ASSIGN';
|
||||||
|
|
|
@ -112,7 +112,7 @@ exports.Lexer = class Lexer
|
||||||
id = new String id
|
id = new String id
|
||||||
id.reserved = yes
|
id.reserved = yes
|
||||||
else if id in RESERVED
|
else if id in RESERVED
|
||||||
@error "Reserved word \"#{word}\""
|
@error "reserved word \"#{word}\""
|
||||||
|
|
||||||
unless forcedIdentifier
|
unless forcedIdentifier
|
||||||
id = COFFEE_ALIAS_MAP[id] if id in COFFEE_ALIASES
|
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 if prev and (prev[0] in (if prev.spaced then NOT_REGEX else NOT_SPACED_REGEX))
|
||||||
return 0 unless match = REGEX.exec @chunk
|
return 0 unless match = REGEX.exec @chunk
|
||||||
[regex] = match
|
[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
|
regex.length
|
||||||
|
|
||||||
# Matches multiline extended regular expressions.
|
# Matches multiline extended regular expressions.
|
||||||
|
@ -324,7 +326,7 @@ exports.Lexer = class Lexer
|
||||||
prev = last @tokens
|
prev = last @tokens
|
||||||
if value is '=' and prev
|
if value is '=' and prev
|
||||||
if not prev[1].reserved and prev[1] in JS_FORBIDDEN
|
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 ['||', '&&']
|
if prev[1] in ['||', '&&']
|
||||||
prev[0] = 'COMPOUND_ASSIGN'
|
prev[0] = 'COMPOUND_ASSIGN'
|
||||||
prev[1] += '='
|
prev[1] += '='
|
||||||
|
|
|
@ -38,6 +38,9 @@ test "#764: regular expressions should be indexable", ->
|
||||||
test "#584: slashes are allowed unescaped in character classes", ->
|
test "#584: slashes are allowed unescaped in character classes", ->
|
||||||
ok /^a\/[/]b$/.test 'a//b'
|
ok /^a\/[/]b$/.test 'a//b'
|
||||||
|
|
||||||
|
test "#1724: regular expressions beginning with `*`", ->
|
||||||
|
throws -> CoffeeScript.compile '/*/'
|
||||||
|
|
||||||
|
|
||||||
# Heregexe(n|s)
|
# Heregexe(n|s)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue