private Statement staticsInitializer(MsgFallbackGroupNode node, Expression translationVar) {

    // All of these helper variables must have uniquely-suffixed names because {msg}s can be nested.

    // The mutable (tracking index of last match) regex to find the placeholder placeholders.
    VariableDeclaration regexVar =
        VariableDeclaration.builder("partRe_" + node.getId())
            .setRhs(Expression.regexLiteral(PLACEHOLDER_REGEX))
            .build();
    // The current placeholder from the regex.
    VariableDeclaration matchVar = VariableDeclaration.builder("match_" + node.getId()).build();
    // The index of the end of the previous placeholder, where the next raw text run starts.
    VariableDeclaration lastIndexVar =
        VariableDeclaration.builder("lastIndex_" + node.getId())
            .setRhs(Expression.number(0))
            .build();
    // A counter to increment and update the statics array.
    VariableDeclaration counter =
        VariableDeclaration.builder("counter_" + node.getId()).setRhs(Expression.number(0)).build();

    List<Statement> doBody = new ArrayList<>();
    // Execute the regex on the string to get the next matching pair.
    // match_XXX = partRe_XXX.exec(MSG_EXTERNAL_XXX) || undefined;
    doBody.add(
        matchVar
            .ref()
            .assign(
                regexVar
                    .ref()
                    .dotAccess("exec")
                    .call(translationVar)
                    // Replace null with undefined.  This is necessary to make substring() treat
                    // falsy as an omitted
                    // parameter, so that it goes until the end of the string.  Otherwise, the
                    // non-numeric parameter
                    // would be coerced to zero.
                    .or(Expression.id("undefined"), translationContext.codeGenerator()))
            .asStatement());

    // Emit the (possibly-empty) run of raw text since the last placeholder, until this placeholder,
    // or until the end of the source string.
    Expression endIndex =
        matchVar.ref().and(matchVar.ref().dotAccess("index"), translationContext.codeGenerator());
    // Incremental DOM usually unescapes all strings at compile time. However, for messages
    // we need to do so at runtime so that entities like `&lt`; becomes <
    Expression unescape =
        GOOG_STRING_UNESCAPE_ENTITIES.call(
            // This unescapes the string up from the beginning of the text content to the next
            // placeholder
            translationVar.dotAccess("substring").call(lastIndexVar.ref(), endIndex));

    // First start off by initializing the statics declaration array (it is undefined before)
    doBody.add(
        Expression.id(staticDecl)
            .bracketAccess(translationVar)
            .bracketAccess(counter.ref())
            .assign(
                Expression.arrayLiteral(
                    ImmutableList.of(
                        unescape,
                        matchVar
                            .ref()
                            .and(
                                matchVar.ref().bracketAccess(Expression.number(0)),
                                translationContext.codeGenerator()))))
            .asStatement());

    // counter++
    doBody.add(counter.ref().assign(counter.ref().plus(Expression.number(1))).asStatement());
    // Update the beginning of the string to parse to the end of the current one.
    doBody.add(lastIndexVar.ref().assign(regexVar.ref().dotAccess("lastIndex")).asStatement());

    Statement statement =
        Statement.of(
            Expression.id(staticDecl)
                .bracketAccess(translationVar)
                .assign(Expression.arrayLiteral(ImmutableList.of()))
                .asStatement(),
            Statement.of(translationVar.initialStatements()),
            regexVar,
            lastIndexVar,
            counter,
            matchVar,
            DoWhile.builder().setCondition(matchVar.ref()).setBody(Statement.of(doBody)).build());
    statement =
        Statement.ifStatement(
                Expression.not(Expression.id(staticDecl).bracketAccess(translationVar)), statement)
            .build();
    return statement;
  }
private Statement staticsInitializer ( MsgFallbackGroupNode node , Expression translationVar ) { VariableDeclaration regexVar = VariableDeclaration . builder ( "partRe_" + node . getId ( ) ) . setRhs ( Expression . regexLiteral ( PLACEHOLDER_REGEX ) ) . build ( ) ; VariableDeclaration matchVar = VariableDeclaration . builder ( "match_" + node . getId ( ) ) . build ( ) ; VariableDeclaration lastIndexVar = VariableDeclaration . builder ( "lastIndex_" + node . getId ( ) ) . setRhs ( Expression . number ( 0 ) ) . build ( ) ; VariableDeclaration counter = VariableDeclaration . builder ( "counter_" + node . getId ( ) ) . setRhs ( Expression . number ( 0 ) ) . build ( ) ; List < Statement > doBody = new ArrayList < > ( ) ; doBody . add ( matchVar . ref ( ) . assign ( regexVar . ref ( ) . dotAccess ( "exec" ) . call ( translationVar ) . or ( Expression . id ( "undefined" ) , translationContext . codeGenerator ( ) ) ) . asStatement ( ) ) ; Expression endIndex = matchVar . ref ( ) . and ( matchVar . ref ( ) . dotAccess ( "index" ) , translationContext . codeGenerator ( ) ) ; Expression unescape = GOOG_STRING_UNESCAPE_ENTITIES . call ( translationVar . dotAccess ( "substring" ) . call ( lastIndexVar . ref ( ) , endIndex ) ) ; doBody . add ( Expression . id ( staticDecl ) . bracketAccess ( translationVar ) . bracketAccess ( counter . ref ( ) ) . assign ( Expression . arrayLiteral ( ImmutableList . of ( unescape , matchVar . ref ( ) . and ( matchVar . ref ( ) . bracketAccess ( Expression . number ( 0 ) ) , translationContext . codeGenerator ( ) ) ) ) ) . asStatement ( ) ) ; doBody . add ( counter . ref ( ) . assign ( counter . ref ( ) . plus ( Expression . number ( 1 ) ) ) . asStatement ( ) ) ; doBody . add ( lastIndexVar . ref ( ) . assign ( regexVar . ref ( ) . dotAccess ( "lastIndex" ) ) . asStatement ( ) ) ; Statement statement = Statement . of ( Expression . id ( staticDecl ) . bracketAccess ( translationVar ) . assign ( Expression . arrayLiteral ( ImmutableList . of ( ) ) ) . asStatement ( ) , Statement . of ( translationVar . initialStatements ( ) ) , regexVar , lastIndexVar , counter , matchVar , DoWhile . builder ( ) . setCondition ( matchVar . ref ( ) ) . setBody ( Statement . of ( doBody ) ) . build ( ) ) ; statement = Statement . ifStatement ( Expression . not ( Expression . id ( staticDecl ) . bracketAccess ( translationVar ) ) , statement ) . build ( ) ; return statement ; }
In all cases, messages that are broken up into placeholders typically contain the same parts.
That is, a message that looks like <div>FooBar{$foo}</div> in all invocations will be broken up
into {DIV_PLACEHOLDER}{CONSTANT_MESSAGE}{PRINT $FOO}{END_DIV_PLACEHOLDER}. In order to avoid
parsing and splitting up this over and over again, we execute the splitting logic once and save
the results so that future usages are fast.

<p>Concretely speaking, this is basically an uninitialized array that lives in the module
scope. See staticsDecl.