From 7c29ea4d38928f829315ea4bd630219fb1e3ac30 Mon Sep 17 00:00:00 2001 From: Michael Ficarra Date: Mon, 21 May 2012 13:49:00 -0400 Subject: [PATCH] removing code that restricts duplicate key names and associated tests --- lib/coffee-script/nodes.js | 33 +++++---------------------------- src/nodes.coffee | 10 ---------- test/strict.coffee | 33 --------------------------------- 3 files changed, 5 insertions(+), 71 deletions(-) diff --git a/lib/coffee-script/nodes.js b/lib/coffee-script/nodes.js index 15619579..90e6f764 100644 --- a/lib/coffee-script/nodes.js +++ b/lib/coffee-script/nodes.js @@ -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; diff --git a/src/nodes.coffee b/src/nodes.coffee index 804f2984..c6cdfad6 100644 --- a/src/nodes.coffee +++ b/src/nodes.coffee @@ -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 diff --git a/test/strict.coffee b/test/strict.coffee index b2aba705..45c11a99 100644 --- a/test/strict.coffee +++ b/test/strict.coffee @@ -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