Skip to content

Add condition for fully-qualified global functions#4

Open
LuigiPulcini wants to merge 1 commit intotimelsass:masterfrom
LuigiPulcini:tweak/fully-qualified-functions
Open

Add condition for fully-qualified global functions#4
LuigiPulcini wants to merge 1 commit intotimelsass:masterfrom
LuigiPulcini:tweak/fully-qualified-functions

Conversation

@LuigiPulcini
Copy link

The current implementation doesn't cover the case of a WordPress i18n global function written with a leading backslash (e.g. \__()) because the PHP parser does not identify \__() as a T_STRING but rather as a T_NAME_FULLY_QUALIFIED.

The proposed change takes that case into account by adding a new condition that is satisfied when the current token is T_NAME_FULLY_QUALIFIED and its text, starting from the second character (i.e. text.slice(1)), is one of the i18n functions.

This case is necessary when a WordPress component uses external libraries that are automatically namespaced by a processor such as PHP Scoper, which transforms the name of every global function into a fully-qualified name (e.g. esc_html__() becomes \esc_html__()).

When a global function is written as a fully-qualified name (e.g. `\__()`), the PHP parser lists them as `T_NAME_FULLY_QUALIFIED` tokens. This change takes that scenario into account.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant