Skip to content

Commit

Permalink
Remove unused f expression from jscode gen. (#5573)
Browse files Browse the repository at this point in the history
Varadic assignment in javascript where the right hand expression is an
object yields a single set assignment with the right most lefthand variable,
while leaving the other left side expressions undefined.

For example:
var a,b = {}

will only initialize a to undefined. But will set b to the {} value.

--

For this code since f is never used, it is a safe operation to remove
it.
  • Loading branch information
samccone authored and TeBoring committed Jan 14, 2019
1 parent a2a0afb commit 94a1819
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/google/protobuf/compiler/js/js_generator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2272,7 +2272,7 @@ void Generator::GenerateClassToObject(const GeneratorOptions& options,
" * @suppress {unusedLocalVariables} f is only used for nested messages\n"
" */\n"
"$classname$.toObject = function(includeInstance, msg) {\n"
" var f, obj = {",
" var obj = {",
"classname", GetMessagePath(options, desc));

bool first = true;
Expand Down

3 comments on commit 94a1819

@dankurka
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Turns out that variable is actually used and this broke protobuf/js externally. Reverting this.

@TeBoring
Copy link
Contributor

@TeBoring TeBoring commented on 94a1819 Mar 21, 2019 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dankurka
Copy link
Contributor

@dankurka dankurka commented on 94a1819 Mar 21, 2019 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.