Skip to content

Commit

Permalink
Merge pull request #204 from matzeeable/fix/#203/webpack-mangle
Browse files Browse the repository at this point in the history
fix(make-pot): parses mangled webpack statements (closes #203)
  • Loading branch information
swissspidy authored Mar 2, 2020
2 parents 2804c52 + cbe2aaf commit 3acd67f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
5 changes: 5 additions & 0 deletions features/makepot.feature
Original file line number Diff line number Diff line change
Expand Up @@ -1592,6 +1592,7 @@ Feature: Generate a POT file of a WordPress project
translate.__( 'translate.__', 'foo-plugin' );
Object(_wordpress_i18n__WEBPACK_IMPORTED_MODULE_7__["__"])( 'webpack.__', 'foo-plugin' );
Object(_wordpress_i18n__WEBPACK_IMPORTED_MODULE_7__[/* __ */ "a"])( 'webpack.mangle.__', 'foo-plugin' );
Object(u.__)( 'minified.__', 'foo-plugin' );
Object(j._x)( 'minified._x', 'minified._x_context', 'foo-plugin' );
Expand Down Expand Up @@ -1660,6 +1661,10 @@ Feature: Generate a POT file of a WordPress project
"""
msgid "webpack.__"
"""
And the foo-plugin/foo-plugin.pot file should contain:
"""
msgid "webpack.mangle.__"
"""
And the foo-plugin/foo-plugin.pot file should contain:
"""
msgid "minified.__"
Expand Down
11 changes: 10 additions & 1 deletion src/JsFunctionsScanner.php
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,17 @@ private function resolveExpressionCallee( Node\CallExpression $node ) {
// Matches unminified webpack statements:
// Object(_wordpress_i18n__WEBPACK_IMPORTED_MODULE_7__["__"])( "translation" );
if ( 'Literal' === $property->getType() ) {
$name = $property->getValue();

// Matches mangled webpack statement:
// Object(_wordpress_i18n__WEBPACK_IMPORTED_MODULE_7__[/* __ */ "a"])( "translation" );
$leading_property_comments = $property->getLeadingComments();
if ( count( $leading_property_comments ) === 1 && $leading_property_comments[0]->getKind() === 'multiline' ) {
$name = trim( $leading_property_comments[0]->getText() );
}

return [
'name' => $property->getValue(),
'name' => $name,
'comments' => $callee->getCallee()->getLeadingComments(),
];
}
Expand Down

0 comments on commit 3acd67f

Please sign in to comment.