HoriSun / closure-compiler

Automatically exported from code.google.com/p/closure-compiler
0 stars 0 forks source link

@idGenerator not generating ids properly #1188

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1.  Go to http://closure-compiler.appspot.com/home
2.  Try to compile the following code:
// ==ClosureCompiler==
// @compilation_level ADVANCED_OPTIMIZATIONS
// @output_file_name default.js
// ==/ClosureCompiler==

goog.provide('foo');

/**
* @idGenerator
* @param {string} str
* @return {string}
*/
foo.getId = function(str){return str};

var x = {
x: [foo.getId('xxx1'),foo.getId('xxx2'),foo.getId('xxx3')]
}

var y = {};
y[foo.getId('xxx1')]=123;

console.log(foo.getId('xxx1'),y[foo.getId('xxx1')],foo.getId('xxx1'),foo.getId('
xxx1'))

What is the expected output? What do you see instead?
Should compile to:
console.log("a",123,"a","a");
Compiles to:
console.log("e",{d:123}.f,"g","h");

What version of the product are you using? On what operating system?
http://closure-compiler.appspot.com/home

Please provide any additional information below.

Original issue reported on code.google.com by jhiswin on 30 Dec 2013 at 11:36

GoogleCodeExporter commented 9 years ago
I think you're looking for the @consistentIdGenerator annotation.

Original comment by dim...@google.com on 30 Dec 2013 at 6:29

GoogleCodeExporter commented 9 years ago
Hi, either the example on this page is wrong:
https://code.google.com/p/closure-compiler/wiki/IdGeneratorAnnotations

Or there is a problem with the compiler, as even the example on the wiki fails 
to give the same results.
Additionally, I was under the impression @idGenerator and 
@consistentIdGenerator difference is only that the consistent generator will 
try to use a provided mapping file.

Original comment by jhiswin on 1 Jan 2014 at 9:58

GoogleCodeExporter commented 9 years ago
Although I do submit that @idGenerator creating a new id on every invocation 
makes sense and matches other implementations (such as Closure Library's 
idGenerator), but the specs on the wiki do not match this.

Additionally, I do think a distinction needs to be made between an 
"idGenerator" that uses a predefined map, and one that just returns the same id 
for the same string, so perhaps another annotation for a different type of id 
generator should be provided.

Original comment by jhiswin on 1 Jan 2014 at 10:06

GoogleCodeExporter commented 9 years ago
Good point, I didn't realize the docs said otherwise. I answered by looking at 
the behavior of the tests here.
https://code.google.com/p/closure-compiler/source/browse/test/com/google/javascr
ipt/jscomp/ReplaceIdGeneratorsTest.java

Nick, John (or whoever wrote the wiki page), can you take a look and fix the 
mismatch between the code and the doc?

Original comment by dim...@google.com on 2 Jan 2014 at 6:15

GoogleCodeExporter commented 9 years ago
Issue tracking has been migrated to github. Please make any further comments on 
this issue through https://github.com/google/closure-compiler/issues

Original comment by blic...@google.com on 1 May 2014 at 6:31

GoogleCodeExporter commented 9 years ago

Original comment by blic...@google.com on 1 May 2014 at 6:34