Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

removing code that restricts duplicate key names and associated tests

  • Loading branch information...
commit 7c29ea4d38928f829315ea4bd630219fb1e3ac30 1 parent 6c6c8bd
@michaelficarra michaelficarra authored
Showing with 5 additions and 71 deletions.
  1. +5 −28 lib/coffee-script/nodes.js
  2. +0 −10 src/nodes.coffee
  3. +0 −33 test/strict.coffee
View
33 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;
View
10 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
View
33 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

3 comments on commit 7c29ea4

Please sign in to comment.
Something went wrong with that request. Please try again.