mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-05-03 03:00:14 -04:00
fix to #2333 greatly improved, but still depends on eval :(
This commit is contained in:
@@ -1184,10 +1184,28 @@
|
||||
if (prop != null) {
|
||||
propName = prop.unwrapAll().value.toString();
|
||||
isDuplicate = function(x) {
|
||||
var p0, x0;
|
||||
p0 = propName[0];
|
||||
x0 = x[0];
|
||||
return propName === x || +propName === +x || (p0 === "'" && x0 === '"' || p0 === '"' && x0 === "'" ? eval(x) === eval(propName) : p0 === "'" ? propName === ("'" + x + "'") : p0 === '"' ? propName === ("\"" + x + "\"") : x0 === "'" ? x === ("'" + propName + "'") : x0 === '"' ? x === ("\"" + propName + "\"") : void 0);
|
||||
return propName === x || +propName === +x || (function() {
|
||||
var ep, ex;
|
||||
ex = ep = null;
|
||||
if (!/^[a-z$_]/i.test(x)) {
|
||||
ex = eval(x);
|
||||
if (propName === ex) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (!/^[a-z$_]/i.test(propName)) {
|
||||
ep = eval(propName);
|
||||
if (x === ep) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if ((ex != null) && (ep != null)) {
|
||||
if (ex === ep) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
})();
|
||||
};
|
||||
if (any(propNames, isDuplicate)) {
|
||||
throw SyntaxError("multiple object literal properties named \"" + propName + "\"");
|
||||
|
||||
@@ -807,15 +807,18 @@ exports.Obj = class Obj extends Base
|
||||
if prop?
|
||||
propName = prop.unwrapAll().value.toString()
|
||||
isDuplicate = (x) ->
|
||||
p0 = propName[0]
|
||||
x0 = x[0]
|
||||
propName is x or +propName is +x or
|
||||
if p0 is "'" and x0 is '"' or p0 is '"' and x0 is "'"
|
||||
eval(x) is eval(propName)
|
||||
else if p0 is "'" then propName is "'#{x}'"
|
||||
else if p0 is '"' then propName is "\"#{x}\""
|
||||
else if x0 is "'" then x is "'#{propName}'"
|
||||
else if x0 is '"' then x is "\"#{propName}\""
|
||||
do ->
|
||||
ex = ep = null
|
||||
unless /^[a-z$_]/i.test x
|
||||
ex = eval x
|
||||
return true if propName is ex
|
||||
unless /^[a-z$_]/i.test propName
|
||||
ep = eval propName
|
||||
return true if x is ep
|
||||
if ex? and ep?
|
||||
return true if ex is ep
|
||||
false
|
||||
if any propNames, isDuplicate
|
||||
throw SyntaxError "multiple object literal properties named \"#{propName}\""
|
||||
propNames.push propName
|
||||
|
||||
@@ -65,7 +65,10 @@ test "#2333: more duplicate property prohibitions", ->
|
||||
strict "{'a':0, a:0}"
|
||||
strict '{\'a\':0, "a":0}'
|
||||
strict '{0:0, 0x0:0}'
|
||||
strict '{0:0, "\x30":0}'
|
||||
strict '{"\0":0, "\x00":0}'
|
||||
strict 'a = 0; {a, "a":0}'
|
||||
strictOk '{0:0, "0x0":0}'
|
||||
strictOk '{"a":0, "\'a\'":0}'
|
||||
|
||||
test "duplicate formal parameters are prohibited", ->
|
||||
|
||||
Reference in New Issue
Block a user