/**
* Test for one of the bugs causing issue 8284. JsObfuscateNamer was reassigning the same names
* across different fragments.
*/
public void testDuplicateNamesWithCodeSplitterError() throws Exception {
JsProgram program = new JsProgram();
// Reference to a in .b is to the top level scope a function where the one in _.c is to the
// local a definition.
//
// After deduping _.b and _.c the identifier a in the deduped function points to the top level
// scope a function and runing a namer afterwards makes the deduping invalid.
String fragment0js = "_.a=function (){return _.a;}; _.b=function (){return _.a}; _.a();_.b();";
String fragment1js = "_.c=function (){return _.c;}; _.d=function (){return _.c}; _.c();_.d();";
List<JsStatement> fragment0 = JsParser.parse(SourceOrigin.UNKNOWN,
program.getScope(), new StringReader(fragment0js));
List<JsStatement> fragment1 = JsParser.parse(SourceOrigin.UNKNOWN,
program.getScope(), new StringReader(fragment1js));
program.setFragmentCount(2);
program.getFragmentBlock(0).getStatements().addAll(fragment0);
program.getFragmentBlock(1).getStatements().addAll(fragment1);
// Mark all functions as if they were translated from Java sources.
setAllFromJava(program);
optimize(program, JsSymbolResolver.class, JsDuplicateFunctionRemoverProxy.class);
// There should be two distinct dedupped functions here.
MockNameGenerator tempFreshNameGenerator = new MockNameGenerator();
String firstName = tempFreshNameGenerator.getFreshName();
String secondName = tempFreshNameGenerator.getFreshName();
assertNotNull(program.getScope().findExistingName(secondName));
}