Search in sources :

Example 1 with VariableMap

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);
        }
    }
}
Also used : VariableMap(com.google.javascript.jscomp.VariableMap) Node(com.google.javascript.rhino.Node)

Example 2 with VariableMap

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");
}
Also used : Compiler(com.google.javascript.jscomp.Compiler) VariableMap(com.google.javascript.jscomp.VariableMap) CompilerOptions(com.google.javascript.jscomp.CompilerOptions) Test(org.junit.Test)

Example 3 with VariableMap

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>\"]");
}
Also used : Compiler(com.google.javascript.jscomp.Compiler) VariableMap(com.google.javascript.jscomp.VariableMap) CompilerOptions(com.google.javascript.jscomp.CompilerOptions) Test(org.junit.Test)

Aggregations

VariableMap (com.google.javascript.jscomp.VariableMap)3 Compiler (com.google.javascript.jscomp.Compiler)2 CompilerOptions (com.google.javascript.jscomp.CompilerOptions)2 Test (org.junit.Test)2 Node (com.google.javascript.rhino.Node)1