1
0
Fork 0
mirror of https://github.com/jashkenas/coffeescript.git synced 2022-11-09 12:23:24 -05:00

fixes #1380: super with reserved names

This commit is contained in:
Michael Ficarra 2011-05-25 03:22:26 -04:00
parent 8e5eff5e1e
commit bbf1c6a8df
2 changed files with 26 additions and 10 deletions

View file

@ -1,5 +1,5 @@
(function() {
var Access, Arr, Assign, Base, Block, Call, Class, Closure, Code, Comment, Existence, Extends, For, IDENTIFIER, IS_STRING, If, In, Index, LEVEL_ACCESS, LEVEL_COND, LEVEL_LIST, LEVEL_OP, LEVEL_PAREN, LEVEL_TOP, Literal, METHOD_DEF, NEGATE, NO, Obj, Op, Param, Parens, Push, Range, Return, SIMPLENUM, Scope, Slice, Splat, Switch, TAB, THIS, Throw, Try, UTILITIES, Value, While, YES, compact, del, ends, extend, flatten, last, merge, multident, starts, unfoldSoak, utility, _ref;
var Access, Arr, Assign, Base, Block, Call, Class, Closure, Code, Comment, Existence, Extends, For, IDENTIFIER, IDENTIFIER_STR, IS_STRING, If, In, Index, LEVEL_ACCESS, LEVEL_COND, LEVEL_LIST, LEVEL_OP, LEVEL_PAREN, LEVEL_TOP, Literal, METHOD_DEF, NEGATE, NO, Obj, Op, Param, Parens, Push, Range, Return, SIMPLENUM, Scope, Slice, Splat, Switch, TAB, THIS, Throw, Try, UTILITIES, Value, While, YES, compact, del, ends, extend, flatten, last, merge, multident, starts, unfoldSoak, utility, _ref;
var __hasProp = Object.prototype.hasOwnProperty, __extends = function(child, parent) {
for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; }
function ctor() { this.constructor = child; }
@ -593,7 +593,7 @@
throw SyntaxError('cannot call super on an anonymous function.');
}
if (method.klass) {
return "" + method.klass + ".__super__." + name;
return (new Value(new Literal(method.klass), [new Access(new Literal("__super__")), new Access(new Literal(name))])).compile(o);
} else {
return "" + name + ".__super__.constructor";
}
@ -1140,7 +1140,7 @@
return unfoldSoak(o, this, 'variable');
};
Assign.prototype.compileNode = function(o) {
var isValue, match, name, val, _ref2;
var isValue, match, name, val, _ref2, _ref3, _ref4;
if (isValue = this.variable instanceof Value) {
if (this.variable.isArray() || this.variable.isObject()) {
return this.compilePatternMatch(o);
@ -1164,10 +1164,10 @@
}
}
if (this.value instanceof Code && (match = METHOD_DEF.exec(name))) {
this.value.name = match[2];
if (match[1]) {
this.value.klass = match[1];
}
this.value.name = (_ref3 = (_ref4 = match[2]) != null ? _ref4 : match[3]) != null ? _ref3 : match[4];
}
val = this.value.compile(o, LEVEL_LIST);
if (this.context === 'object') {
@ -2260,9 +2260,10 @@
LEVEL_OP = 5;
LEVEL_ACCESS = 6;
TAB = ' ';
IDENTIFIER = /^[$A-Za-z_\x7f-\uffff][$\w\x7f-\uffff]*$/;
IDENTIFIER_STR = "[$A-Za-z_\\x7f-\\uffff][$\\w\\x7f-\\uffff]*";
IDENTIFIER = RegExp("^" + IDENTIFIER_STR + "$");
SIMPLENUM = /^[+-]?\d+$/;
METHOD_DEF = /^(?:([$A-Za-z_][$\w\x7f-\uffff]*)\.prototype\.)?([$A-Za-z_][$\w\x7f-\uffff]*)$/;
METHOD_DEF = RegExp("^(?:(" + IDENTIFIER_STR + ")\\.prototype(?:\\.(" + IDENTIFIER_STR + ")|\\[(\"(?:[^\"\\r\\n]|\\\\\")*\"|'(?:[^'\\r\\n]|\\\\')*')\\]))|(" + IDENTIFIER_STR + ")$");
IS_STRING = /^['"]/;
utility = function(name) {
var ref;

View file

@ -469,7 +469,7 @@ exports.Call = class Call extends Base
{name} = method
throw SyntaxError 'cannot call super on an anonymous function.' unless name
if method.klass
"#{method.klass}.__super__.#{name}"
(new Value (new Literal method.klass), [new Access(new Literal "__super__"), new Access new Literal name]).compile o
else
"#{name}.__super__.constructor"
@ -933,8 +933,8 @@ exports.Assign = class Assign extends Base
else
o.scope.find name
if @value instanceof Code and match = METHOD_DEF.exec name
@value.name = match[2]
@value.klass = match[1] if match[1]
@value.name = match[2] ? match[3] ? match[4]
val = @value.compile o, LEVEL_LIST
return "#{name}: #{val}" if @context is 'object'
val = name + " #{ @context or '=' } " + val
@ -1798,9 +1798,24 @@ LEVEL_ACCESS = 6 # ...[0]
# Tabs are two spaces for pretty printing.
TAB = ' '
IDENTIFIER = /^[$A-Za-z_\x7f-\uffff][$\w\x7f-\uffff]*$/
IDENTIFIER_STR = "[$A-Za-z_\\x7f-\\uffff][$\\w\\x7f-\\uffff]*"
IDENTIFIER = /// ^ #{IDENTIFIER_STR} $ ///
SIMPLENUM = /^[+-]?\d+$/
METHOD_DEF = /^(?:([$A-Za-z_][$\w\x7f-\uffff]*)\.prototype\.)?([$A-Za-z_][$\w\x7f-\uffff]*)$/
METHOD_DEF = ///
^
(?:
(#{IDENTIFIER_STR})
\.prototype
(?:
\.(#{IDENTIFIER_STR})
|
\[("(?:[^"\r\n]|\\")*"|'(?:[^'\r\n]|\\')*')\]
)
)
|
(#{IDENTIFIER_STR})
$
///
# Is a literal value a string?
IS_STRING = /^['"]/