From 8a60174932d15198883ac3f07000ab4e7179a695 Mon Sep 17 00:00:00 2001 From: dcodeIO Date: Fri, 24 Mar 2017 18:34:16 +0100 Subject: [PATCH] CLI: Fixed computed array indexes not being renamed in static code, see #726 --- cli/targets/static.js | 2 +- tests/data/package.js | 10 +++++----- tests/data/test.js | 20 ++++++++++---------- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/cli/targets/static.js b/cli/targets/static.js index e8c2973bf..87e0cbb0e 100644 --- a/cli/targets/static.js +++ b/cli/targets/static.js @@ -170,7 +170,7 @@ function beautifyCode(code) { estraverse.replace(ast, { enter: function(node, parent) { // rename short vars - if (node.type === "Identifier" && parent.property !== node && shortVars[node.name]) + if (node.type === "Identifier" && (parent.property !== node || parent.computed) && shortVars[node.name]) return { "type": "Identifier", "name": shortVars[node.name] diff --git a/tests/data/package.js b/tests/data/package.js index 0cd2221ef..b2c7691b6 100644 --- a/tests/data/package.js +++ b/tests/data/package.js @@ -275,7 +275,7 @@ $root.Package = (function() { message.bin = {}; key = reader.string(); reader.pos++; - message.bin[k] = reader.string(); + message.bin[key] = reader.string(); break; case 12: reader.skip().pos++; @@ -283,7 +283,7 @@ $root.Package = (function() { message.scripts = {}; key = reader.string(); reader.pos++; - message.scripts[k] = reader.string(); + message.scripts[key] = reader.string(); break; case 13: reader.skip().pos++; @@ -291,7 +291,7 @@ $root.Package = (function() { message.dependencies = {}; key = reader.string(); reader.pos++; - message.dependencies[k] = reader.string(); + message.dependencies[key] = reader.string(); break; case 14: reader.skip().pos++; @@ -299,7 +299,7 @@ $root.Package = (function() { message.optionalDependencies = {}; key = reader.string(); reader.pos++; - message.optionalDependencies[k] = reader.string(); + message.optionalDependencies[key] = reader.string(); break; case 15: reader.skip().pos++; @@ -307,7 +307,7 @@ $root.Package = (function() { message.devDependencies = {}; key = reader.string(); reader.pos++; - message.devDependencies[k] = reader.string(); + message.devDependencies[key] = reader.string(); break; case 17: message.types = reader.string(); diff --git a/tests/data/test.js b/tests/data/test.js index 4da40765e..564f7bd47 100644 --- a/tests/data/test.js +++ b/tests/data/test.js @@ -6385,7 +6385,7 @@ $root.jspb = (function() { message.mapStringString = {}; key = reader.string(); reader.pos++; - message.mapStringString[k] = reader.string(); + message.mapStringString[key] = reader.string(); break; case 2: reader.skip().pos++; @@ -6393,7 +6393,7 @@ $root.jspb = (function() { message.mapStringInt32 = {}; key = reader.string(); reader.pos++; - message.mapStringInt32[k] = reader.int32(); + message.mapStringInt32[key] = reader.int32(); break; case 3: reader.skip().pos++; @@ -6409,7 +6409,7 @@ $root.jspb = (function() { message.mapStringBool = {}; key = reader.string(); reader.pos++; - message.mapStringBool[k] = reader.bool(); + message.mapStringBool[key] = reader.bool(); break; case 5: reader.skip().pos++; @@ -6417,7 +6417,7 @@ $root.jspb = (function() { message.mapStringDouble = {}; key = reader.string(); reader.pos++; - message.mapStringDouble[k] = reader.double(); + message.mapStringDouble[key] = reader.double(); break; case 6: reader.skip().pos++; @@ -6425,7 +6425,7 @@ $root.jspb = (function() { message.mapStringEnum = {}; key = reader.string(); reader.pos++; - message.mapStringEnum[k] = reader.uint32(); + message.mapStringEnum[key] = reader.uint32(); break; case 7: reader.skip().pos++; @@ -6433,7 +6433,7 @@ $root.jspb = (function() { message.mapStringMsg = {}; key = reader.string(); reader.pos++; - message.mapStringMsg[k] = $root.jspb.test.MapValueMessageNoBinary.decode(reader, reader.uint32()); + message.mapStringMsg[key] = $root.jspb.test.MapValueMessageNoBinary.decode(reader, reader.uint32()); break; case 8: reader.skip().pos++; @@ -6441,7 +6441,7 @@ $root.jspb = (function() { message.mapInt32String = {}; key = reader.int32(); reader.pos++; - message.mapInt32String[k] = reader.string(); + message.mapInt32String[key] = reader.string(); break; case 9: reader.skip().pos++; @@ -6449,7 +6449,7 @@ $root.jspb = (function() { message.mapInt64String = {}; key = reader.int64(); reader.pos++; - message.mapInt64String[k] = reader.string(); + message.mapInt64String[key] = reader.string(); break; case 10: reader.skip().pos++; @@ -6457,7 +6457,7 @@ $root.jspb = (function() { message.mapBoolString = {}; key = reader.bool(); reader.pos++; - message.mapBoolString[k] = reader.string(); + message.mapBoolString[key] = reader.string(); break; case 11: message.testMapFields = $root.jspb.test.TestMapFieldsNoBinary.decode(reader, reader.uint32()); @@ -6468,7 +6468,7 @@ $root.jspb = (function() { message.mapStringTestmapfields = {}; key = reader.string(); reader.pos++; - message.mapStringTestmapfields[k] = $root.jspb.test.TestMapFieldsNoBinary.decode(reader, reader.uint32()); + message.mapStringTestmapfields[key] = $root.jspb.test.TestMapFieldsNoBinary.decode(reader, reader.uint32()); break; default: reader.skipType(tag & 7);