test/com/google/javascript/jscomp/MustBeReachingVariableDefTest.java
/**
   * Computes reaching definition on given source.
   */
Computes reaching definition on given source.
Computes reaching definition on given source .
private void computeDefUse(String src) {
    Compiler compiler = new Compiler();
    compiler.setLifeCycleStage(LifeCycleStage.NORMALIZED);
    CompilerOptions options = new CompilerOptions();
    options.setCodingConvention(new GoogleCodingConvention());
    compiler.init(ImmutableList.<SourceFile>of(), ImmutableList.<SourceFile>of(), options);
    compiler.getOptions().setLanguageIn(LanguageMode.ECMASCRIPT_2017);
    compiler.getOptions().setLanguageOut(LanguageMode.ECMASCRIPT_2017);
    Es6SyntacticScopeCreator scopeCreator = new Es6SyntacticScopeCreator(compiler);
    src = "function _FUNCTION(param1, param2){" + src + "}";
    Node script = compiler.parseTestCode(src);
    Node root = script.getFirstChild();
    Node functionBlock = root.getLastChild();
    assertThat(compiler.getErrorCount()).isEqualTo(0);
    Scope globalScope = scopeCreator.createScope(script, null);
    Scope functionScope = scopeCreator.createScope(root, globalScope);
    Scope funcBlockScope = scopeCreator.createScope(functionBlock, functionScope);
    ControlFlowAnalysis cfa = new ControlFlowAnalysis(compiler, false, true);
    cfa.process(null, root);
    ControlFlowGraph<Node> cfg = cfa.getCfg();
    defUse = new MustBeReachingVariableDef(cfg, funcBlockScope, compiler, scopeCreator);
    defUse.analyze();
    def = null;
    use = null;
    NodeTraversal.traverse(compiler, root, new LabelFinder());
    assertWithMessage("Code should have an instruction labeled D").that(def).isNotNull();
    assertWithMessage("Code should have an instruction labeled U").that(use).isNotNull();
  }
private void computeDefUse ( String src ) { Compiler compiler = new Compiler ( ) ; compiler . setLifeCycleStage ( LifeCycleStage . NORMALIZED ) ; CompilerOptions options = new CompilerOptions ( ) ; options . setCodingConvention ( new GoogleCodingConvention ( ) ) ; compiler . init ( ImmutableList . < SourceFile > of ( ) , ImmutableList . < SourceFile > of ( ) , options ) ; compiler . getOptions ( ) . setLanguageIn ( LanguageMode . ECMASCRIPT_2017 ) ; compiler . getOptions ( ) . setLanguageOut ( LanguageMode . ECMASCRIPT_2017 ) ; Es6SyntacticScopeCreator scopeCreator = new Es6SyntacticScopeCreator ( compiler ) ; src = "function _FUNCTION(param1, param2){" + src + "}" ; Node script = compiler . parseTestCode ( src ) ; Node root = script . getFirstChild ( ) ; Node functionBlock = root . getLastChild ( ) ; assertThat ( compiler . getErrorCount ( ) ) . isEqualTo ( 0 ) ; Scope globalScope = scopeCreator . createScope ( script , null ) ; Scope functionScope = scopeCreator . createScope ( root , globalScope ) ; Scope funcBlockScope = scopeCreator . createScope ( functionBlock , functionScope ) ; ControlFlowAnalysis cfa = new ControlFlowAnalysis ( compiler , false , true ) ; cfa . process ( null , root ) ; ControlFlowGraph < Node > cfg = cfa . getCfg ( ) ; defUse = new MustBeReachingVariableDef ( cfg , funcBlockScope , compiler , scopeCreator ) ; defUse . analyze ( ) ; def = null ; use = null ; NodeTraversal . traverse ( compiler , root , new LabelFinder ( ) ) ; assertWithMessage ( "Code should have an instruction labeled D" ) . that ( def ) . isNotNull ( ) ; assertWithMessage ( "Code should have an instruction labeled U" ) . that ( use ) . isNotNull ( ) ; }
Computes reaching definition on given source.
Computes reaching definition on given source .