mirror of
https://github.com/jashkenas/coffeescript.git
synced 2022-11-09 12:23:24 -05:00
removing code that restricts duplicate key names and associated tests
This commit is contained in:
parent
6c6c8bd454
commit
7c29ea4d38
3 changed files with 5 additions and 71 deletions
|
@ -1172,37 +1172,14 @@
|
|||
Obj.prototype.children = ['properties'];
|
||||
|
||||
Obj.prototype.compileNode = function(o) {
|
||||
var i, idt, indent, join, lastNoncom, node, normalise, normalisedPropName, obj, prop, propName, propNames, props, _i, _j, _len, _len1, _ref2;
|
||||
var i, idt, indent, join, lastNoncom, node, obj, prop, props, _i, _len;
|
||||
props = this.properties;
|
||||
propNames = [];
|
||||
normalise = function(v) {
|
||||
if (IDENTIFIER.test(v)) {
|
||||
return v;
|
||||
} else {
|
||||
return "" + Function("return " + v)();
|
||||
}
|
||||
};
|
||||
_ref2 = this.properties;
|
||||
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
|
||||
prop = _ref2[_i];
|
||||
if (prop.isComplex()) {
|
||||
prop = prop.variable;
|
||||
}
|
||||
if (prop != null) {
|
||||
propName = prop.unwrapAll().value.toString();
|
||||
normalisedPropName = normalise(propName);
|
||||
if (__indexOf.call(propNames, normalisedPropName) >= 0) {
|
||||
throw SyntaxError("multiple object literal properties named \"" + propName + "\"");
|
||||
}
|
||||
propNames.push(normalisedPropName);
|
||||
}
|
||||
}
|
||||
if (!props.length) {
|
||||
return (this.front ? '({})' : '{}');
|
||||
}
|
||||
if (this.generated) {
|
||||
for (_j = 0, _len1 = props.length; _j < _len1; _j++) {
|
||||
node = props[_j];
|
||||
for (_i = 0, _len = props.length; _i < _len; _i++) {
|
||||
node = props[_i];
|
||||
if (node instanceof Value) {
|
||||
throw new Error('cannot have an implicit value in an implicit object');
|
||||
}
|
||||
|
@ -1211,9 +1188,9 @@
|
|||
idt = o.indent += TAB;
|
||||
lastNoncom = this.lastNonComment(this.properties);
|
||||
props = (function() {
|
||||
var _k, _len2, _results;
|
||||
var _j, _len1, _results;
|
||||
_results = [];
|
||||
for (i = _k = 0, _len2 = props.length; _k < _len2; i = ++_k) {
|
||||
for (i = _j = 0, _len1 = props.length; _j < _len1; i = ++_j) {
|
||||
prop = props[i];
|
||||
join = i === props.length - 1 ? '' : prop === lastNoncom || prop instanceof Comment ? '\n' : ',\n';
|
||||
indent = prop instanceof Comment ? '' : idt;
|
||||
|
|
|
@ -801,16 +801,6 @@ exports.Obj = class Obj extends Base
|
|||
|
||||
compileNode: (o) ->
|
||||
props = @properties
|
||||
propNames = []
|
||||
normalise = (v) -> if IDENTIFIER.test v then v else "" + do Function "return #{v}"
|
||||
for prop in @properties
|
||||
prop = prop.variable if prop.isComplex()
|
||||
if prop?
|
||||
propName = prop.unwrapAll().value.toString()
|
||||
normalisedPropName = normalise propName
|
||||
if normalisedPropName in propNames
|
||||
throw SyntaxError "multiple object literal properties named \"#{propName}\""
|
||||
propNames.push normalisedPropName
|
||||
return (if @front then '({})' else '{}') unless props.length
|
||||
if @generated
|
||||
for node in props when node instanceof Value
|
||||
|
|
|
@ -55,41 +55,8 @@ test "octal escape sequences prohibited", ->
|
|||
strictOk "`'\\1'`"
|
||||
eq "\\" + "1", `"\\1"`
|
||||
|
||||
|
||||
test "duplicate property definitions in object literals are prohibited", ->
|
||||
strict 'o = {x:1, x:1}'
|
||||
strict 'x = 1; o = {x, x: 2}'
|
||||
|
||||
test "#2333: more duplicate property prohibitions", ->
|
||||
usingKeys = (a, b) -> "{#{a}:0, #{b}:0}"
|
||||
strict '{a, "a":0}'
|
||||
strict usingKeys "a", '"a"'
|
||||
strict usingKeys "'a'", "a"
|
||||
strict usingKeys "'a'", '"a"'
|
||||
strict usingKeys "'a'", "'a'"
|
||||
strict usingKeys "0", "0x0"
|
||||
strict usingKeys "0", "'\\x30'"
|
||||
strict usingKeys ".1", "0.1"
|
||||
strict usingKeys ".1", "1e-1"
|
||||
strict usingKeys "100", "1e2"
|
||||
strict usingKeys "'\\0'", "'\\x00'"
|
||||
strict usingKeys "'\\t'", "'\\x09'"
|
||||
strict usingKeys "'\\\\x00'", "'\\\\\\x7800'"
|
||||
strict usingKeys "'c'", "'\\c'"
|
||||
strict usingKeys "'\\\\'", "'\\x5c'"
|
||||
strict usingKeys "'\\\n0'", "0"
|
||||
strict usingKeys "'\\\n0'", "'\\x00'"
|
||||
strict usingKeys "'\\'a'", "\"'a\""
|
||||
strict usingKeys "'\\\\a'", "'\\\\a'"
|
||||
strictOk usingKeys "a", "b"
|
||||
strictOk usingKeys "'\"a\"'", "'a'"
|
||||
strictOk usingKeys "'\"a\"'", '"\'a\'"'
|
||||
strictOk usingKeys "0", '"0x0"'
|
||||
strictOk usingKeys "0", '"\\\\x30"'
|
||||
|
||||
test "duplicate formal parameters are prohibited", ->
|
||||
nonce = {}
|
||||
|
||||
# a Param can be an Identifier, ThisProperty( @-param ), Array, or Object
|
||||
# a Param can also be a splat (...) or an assignment (param=value)
|
||||
# the following function expressions should throw errors
|
||||
|
|
Loading…
Add table
Reference in a new issue