use of com.google.javascript.jscomp.VariableMap in project closure-compiler by google.
the class CoverageInstrumentationPass method process.
@Override
public void process(Node externsNode, Node rootNode) {
if (rootNode.hasChildren()) {
if (instrumentOption == InstrumentOption.BRANCH_ONLY) {
NodeTraversal.traverse(compiler, rootNode, new BranchCoverageInstrumentationCallback(compiler, instrumentationData));
} else if (instrumentOption == InstrumentOption.PRODUCTION) {
ProductionCoverageInstrumentationCallback productionCoverageInstrumentationCallback = new ProductionCoverageInstrumentationCallback(compiler, productionInstrumentationArrayName);
NodeTraversal.traverse(compiler, rootNode, productionCoverageInstrumentationCallback);
checkIfArrayNameExternDeclared(externsNode, productionInstrumentationArrayName);
VariableMap instrumentationMapping = productionCoverageInstrumentationCallback.getInstrumentationMapping();
compiler.setInstrumentationMapping(instrumentationMapping);
} else {
NodeTraversal.traverse(compiler, rootNode, new CoverageInstrumentationCallback(instrumentationData, reach));
}
Node firstScript = rootNode.getFirstChild();
checkState(firstScript.isScript());
// just add to a script if it is a module.
if (firstScript.hasChildren() && firstScript.getFirstChild().isModuleBody()) {
firstScript = firstScript.getFirstChild();
}
if (instrumentOption == InstrumentOption.PRODUCTION) {
addProductionHeaderCode(firstScript, productionInstrumentationArrayName);
} else {
addHeaderCode(firstScript);
}
}
}
use of com.google.javascript.jscomp.VariableMap in project closure-compiler by google.
the class ProductionCoverageInstrumentationPassIntegrationTest method testInstrumentationMappingIsCreated.
@Test
public void testInstrumentationMappingIsCreated() {
CompilerOptions options = createCompilerOptions();
declareIstArrExtern();
String source = lines(//
"function foo() { ", " console.log('Hello');", "}");
Compiler compiledSourceCode = compile(options, source);
VariableMap variableParamMap = compiledSourceCode.getInstrumentationMapping();
ImmutableMap<String, String> paramMap = variableParamMap.getOriginalNameToNewNameMap();
assertThat(paramMap).hasSize(4);
assertWithMessage("FunctionNames in the parameter mapping are not properly set").that(paramMap.get(" FunctionNames")).isEqualTo("[\"foo\"]");
assertWithMessage("FileNames in the parameter mapping are not properly set").that(paramMap.get(" FileNames")).isEqualTo("[\"i0.js\"]");
assertWithMessage("Types in the parameter mapping are not properly set").that(paramMap.get(" Types")).isEqualTo("[\"FUNCTION\"]");
assertWithMessage("Array index encoding is not performed properly").that(paramMap.get("C")).isEqualTo("AAACA");
}
use of com.google.javascript.jscomp.VariableMap in project closure-compiler by google.
the class ProductionCoverageInstrumentationPassIntegrationTest method testNoNameFunctionsAreNamedProperly.
@Test
public void testNoNameFunctionsAreNamedProperly() {
CompilerOptions options = createCompilerOptions();
declareIstArrExtern();
String source = lines("tempObj.a || tempObj.b;");
Compiler compiledSourceCode = compile(options, source);
VariableMap variableParamMap = compiledSourceCode.getInstrumentationMapping();
ImmutableMap<String, String> paramMap = variableParamMap.getOriginalNameToNewNameMap();
assertWithMessage("Function name is not converted properly when it has no name").that(paramMap.get(" FunctionNames")).isEqualTo("[\"<Anonymous>\"]");
}
Aggregations