Skip to content

JS extractor chokes on IIFEs #122

@lxg

Description

@lxg

Considering the following test code:

(function(){
    var foo = ["string1", "string2", "string3"];
})();

This is something the JS parser should ignore. Instead it somehow tries to interpret the array members as function arguments, which causes an exception in vendor/gettext/gettext/src/Utils/FunctionsScanner.php in line 29 “Notice: Undefined offset: 1”.

What helps is to check if the function definition is complete before adding it to the list. For example, one could replace lines 129-131 of Utils/JsFunctionsScanner.php with something like

if (!empty($bufferFunctions)) {
    $function = array_shift($bufferFunctions);

    if (isset($function[0]) && isset($function[1]) && isset($function[2]))
        $functions[] = $function;
}

Though this doesn’t solve the underlying problem with the parser.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions