Skip to content

Commit

Permalink
Fix tabs in multiline comments
Browse files Browse the repository at this point in the history
Co-authored-by: Jon Surrell <[email protected]>
  • Loading branch information
luisherranz and sirreal authored Jan 31, 2024
1 parent f9cd9c0 commit c12b9ab
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 69 deletions.
117 changes: 57 additions & 60 deletions src/wp-includes/interactivity-api/class-wp-interactivity-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,23 +192,20 @@ public function process_directives( string $html ): string {
if ( 0 === count( $tag_stack ) || $opening_tag_name !== $tag_name ) {

/*
* If the tag stack is empty or the matching opening tag is not the
* same than the closing tag, it means the HTML is unbalanced and it
* stops processing it.
*/
* If the tag stack is empty or the matching opening tag is not the
* same than the closing tag, it means the HTML is unbalanced and it
* stops processing it.
*/
$unbalanced = true;
continue;
} else {

/*
* It removes the last tag from the stack.
*/
// Remove the last tag from the stack.
array_pop( $tag_stack );

/*
* If the matching opening tag didn't have any directives, it can skip
* the processing.
*/
* If the matching opening tag didn't have any directives, it can skip
* the processing.
*/
if ( 0 === count( $directives_prefixes ) ) {
continue;
}
Expand All @@ -219,29 +216,29 @@ public function process_directives( string $html ): string {
foreach ( $p->get_attribute_names_with_prefix( 'data-wp-' ) as $attribute_name ) {

/*
* Extracts the directive prefix to see if there is a server directive
* processor registered for that directive.
*/
* Extracts the directive prefix to see if there is a server directive
* processor registered for that directive.
*/
list( $directive_prefix ) = $this->extract_prefix_and_suffix( $attribute_name );
if ( array_key_exists( $directive_prefix, self::$directive_processors ) ) {
$directives_prefixes[] = $directive_prefix;
}
}

/*
* If this is not a void element, it adds it to the tag stack so it can
* process its closing tag and check for unbalanced tags.
*/
* If this is not a void element, it adds it to the tag stack so it can
* process its closing tag and check for unbalanced tags.
*/
if ( ! $p->is_void() ) {
$tag_stack[] = array( $tag_name, $directives_prefixes );
}
}

/*
* Sorts the attributes by the order of the `directives_processor` array
* and checks what directives are present in this element. The processing
* order is reversed for tag closers.
*/
* Sorts the attributes by the order of the `directives_processor` array
* and checks what directives are present in this element. The processing
* order is reversed for tag closers.
*/
$directives_prefixes = array_intersect(
$p->is_tag_closer()
? $directive_processor_prefixes_reversed
Expand All @@ -262,10 +259,10 @@ public function process_directives( string $html ): string {
}

/*
* It returns the original content if the HTML is unbalanced because
* unbalanced HTML is not safe to process. In that case, the Interactivity
* API runtime will update the HTML on the client side during the hydration.
*/
* It returns the original content if the HTML is unbalanced because
* unbalanced HTML is not safe to process. In that case, the Interactivity
* API runtime will update the HTML on the client side during the hydration.
*/
return $unbalanced || 0 < count( $tag_stack ) ? $html : $p->get_updated_html();
}

Expand Down Expand Up @@ -371,10 +368,10 @@ private function extract_directive_value( $directive_value, $default_namespace =
}

/*
* Tries to decode the value as a JSON object. If it fails and the value
* isn't `null`, it returns the value as it is. Otherwise, it returns the
* decoded JSON or null for the string `null`.
*/
* Tries to decode the value as a JSON object. If it fails and the value
* isn't `null`, it returns the value as it is. Otherwise, it returns the
* decoded JSON or null for the string `null`.
*/
$decoded_json = json_decode( $directive_value, true );
if ( null !== $decoded_json || 'null' === $directive_value ) {
$directive_value = $decoded_json;
Expand Down Expand Up @@ -409,13 +406,13 @@ private function data_wp_interactive_processor( WP_Interactivity_API_Directives_
: null;

/*
* Pushes the newly defined namespace or the current one if the
* `data-wp-interactive` definition was invalid or does not contain a
* namespace. It does so because the function pops out the current namespace
* from the stack whenever it finds a `data-wp-interactive`'s closing tag,
* independently of whether the previous `data-wp-interactive` definition
* contained a valid namespace.
*/
* Pushes the newly defined namespace or the current one if the
* `data-wp-interactive` definition was invalid or does not contain a
* namespace. It does so because the function pops out the current namespace
* from the stack whenever it finds a `data-wp-interactive`'s closing tag,
* independently of whether the previous `data-wp-interactive` definition
* contained a valid namespace.
*/
$namespace_stack[] = isset( $decoded_json['namespace'] )
? $decoded_json['namespace']
: end( $namespace_stack );
Expand Down Expand Up @@ -448,9 +445,9 @@ private function data_wp_context_processor( WP_Interactivity_API_Directives_Proc
: array( $namespace_value, null );

/*
* If there is a namespace, it adds a new context to the stack merging the
* previous context with the new one.
*/
* If there is a namespace, it adds a new context to the stack merging the
* previous context with the new one.
*/
if ( is_string( $namespace_value ) ) {
array_push(
$context_stack,
Expand All @@ -461,10 +458,10 @@ private function data_wp_context_processor( WP_Interactivity_API_Directives_Proc
);
} else {
/*
* If there is no namespace, it pushes the current context to the stack.
* It needs to do so because the function pops out the current context
* from the stack whenever it finds a `data-wp-context`'s closing tag.
*/
* If there is no namespace, it pushes the current context to the stack.
* It needs to do so because the function pops out the current context
* from the stack whenever it finds a `data-wp-context`'s closing tag.
*/
array_push( $context_stack, end( $context_stack ) );
}
}
Expand Down Expand Up @@ -496,12 +493,12 @@ private function data_wp_bind_processor( WP_Interactivity_API_Directives_Process

if ( null !== $result && ( false !== $result || '-' === $bound_attribute[4] ) ) {
/*
* If the result of the evaluation is a boolean and the attribute is
* `aria-` or `data-, convert it to a string "true" or "false". It
* follows the exact same logic as Preact because it needs to
* replicate what Preact will later do in the client:
* https://github.com/preactjs/preact/blob/ea49f7a0f9d1ff2c98c0bdd66aa0cbc583055246/src/diff/props.js#L131C24-L136
*/
* If the result of the evaluation is a boolean and the attribute is
* `aria-` or `data-, convert it to a string "true" or "false". It
* follows the exact same logic as Preact because it needs to
* replicate what Preact will later do in the client:
* https://github.com/preactjs/preact/blob/ea49f7a0f9d1ff2c98c0bdd66aa0cbc583055246/src/diff/props.js#L131C24-L136
*/
if ( is_bool( $result ) && '-' === $bound_attribute[4] ) {
$result = $result ? 'true' : 'false';
}
Expand Down Expand Up @@ -576,16 +573,16 @@ private function data_wp_style_processor( WP_Interactivity_API_Directives_Proces
$style_attribute_value = ( $style_attribute_value && ! is_bool( $style_attribute_value ) ) ? $style_attribute_value : '';

/*
* Checks first if the style property is not falsy and the style
* attribute value is not empty because if it is, it doesn't need to
* update the attribute value.
*/
* Checks first if the style property is not falsy and the style
* attribute value is not empty because if it is, it doesn't need to
* update the attribute value.
*/
if ( $style_property_value || ( ! $style_property_value && $style_attribute_value ) ) {
$style_attribute_value = $this->set_style_property( $style_attribute_value, $style_property, $style_property_value );
/*
* If the style attribute value is not empty, it sets it. Otherwise,
* it removes it.
*/
* If the style attribute value is not empty, it sets it. Otherwise,
* it removes it.
*/
if ( ! empty( $style_attribute_value ) ) {
$p->set_attribute( 'style', $style_attribute_value );
} else {
Expand Down Expand Up @@ -658,10 +655,10 @@ private function data_wp_text_processor( WP_Interactivity_API_Directives_Process
$result = $this->evaluate( $attribute_value, end( $namespace_stack ), end( $context_stack ) );

/*
* Follows the same logic as Preact in the client and only changes the
* content if the value is a string or a number. Otherwise, it removes the
* content.
*/
* Follows the same logic as Preact in the client and only changes the
* content if the value is a string or a number. Otherwise, it removes the
* content.
*/
if ( is_string( $result ) || is_numeric( $result ) ) {
$p->set_content_between_balanced_tags( esc_html( $result ) );
} else {
Expand Down
18 changes: 9 additions & 9 deletions src/wp-includes/interactivity-api/interactivity-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ function wp_interactivity_process_directives_of_interactive_blocks( $parsed_bloc
static $root_interactive_block = null;

/*
* Checks whether a root interactive block is already annotated for
* processing, and if it is, it ignores the subsequent ones.
*/
* Checks whether a root interactive block is already annotated for
* processing, and if it is, it ignores the subsequent ones.
*/
if ( null === $root_interactive_block ) {
$block_name = $parsed_block['blockName'];
$block_type = WP_Block_Type_Registry::get_instance()->get_registered( $block_name );
Expand All @@ -35,9 +35,9 @@ function wp_interactivity_process_directives_of_interactive_blocks( $parsed_bloc
$root_interactive_block = array( $block_name, md5( serialize( $parsed_block ) ) );

/*
* Adds a filter to process the root interactive block once it has
* finished rendering.
*/
* Adds a filter to process the root interactive block once it has
* finished rendering.
*/
$process_interactive_blocks = static function ( $content, $parsed_block ) use ( &$root_interactive_block, &$process_interactive_blocks ) {
// Checks whether the current block is the root interactive block.
list($root_block_name, $root_block_md5) = $root_interactive_block;
Expand All @@ -52,9 +52,9 @@ function wp_interactivity_process_directives_of_interactive_blocks( $parsed_bloc
};

/*
* Uses a priority of 20 to ensure that other filters can add additional
* directives before the processing starts.
*/
* Uses a priority of 20 to ensure that other filters can add additional
* directives before the processing starts.
*/
add_filter( 'render_block', $process_interactive_blocks, 20, 2 );
}
}
Expand Down

0 comments on commit c12b9ab

Please sign in to comment.