Skip to content

Commit 68dd26a

Browse files
committed
Build tools: Fix the grunt format:php build.
Re-add variable that was removed on accident by [44359]. Also run `grunt format:php` to adjust the code style. .--This line, and those below, will be ignored-- M Gruntfile.js M src/index.php M src/wp-admin/index.php M src/wp-includes/class-wp-block-parser.php git-svn-id: https://develop.svn.wordpress.org/trunk@44360 602fd350-edb4-49c9-b593-d223f7449a82
1 parent d2d7243 commit 68dd26a

4 files changed

Lines changed: 72 additions & 62 deletions

File tree

Gruntfile.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ module.exports = function(grunt) {
2525
'wp-content/plugins/index.php',
2626
'wp-content/plugins/hello.php',
2727
'wp-content/plugins/akismet/**'
28-
];
28+
],
29+
changedFiles = {
30+
php: []
31+
};
2932

3033
if ( 'watch:phpunit' === grunt.cli.tasks[ 0 ] && ! phpUnitWatchGroup ) {
3134
grunt.log.writeln();

src/index.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,25 +36,25 @@
3636
'WordPress'
3737
) . '</p>';
3838

39-
$die .= '<p>' . __( 'Before running any grunt tasks you need to make sure the dependencies are installed. You can install these by running ');
39+
$die .= '<p>' . __( 'Before running any grunt tasks you need to make sure the dependencies are installed. You can install these by running ' );
4040
$die .= '<code style="color: green;">npm install</code>.</p>';
4141

4242
$die .= '<ul>';
4343
$die .= '<li>' . sprintf(
4444
/* translators: %s: WordPress */
4545
__( 'To build %s while developing run:' ),
46-
'WordPress'
47-
) . '<br /><br />';
46+
'WordPress'
47+
) . '<br /><br />';
4848
$die .= '<code style="color: green;">grunt build --dev</code></li>';
4949
$die .= '<li>' . sprintf(
50-
__( 'To build files automatically when changing the source files run:' ),
51-
'WordPress'
52-
) . '<br /><br />';
50+
__( 'To build files automatically when changing the source files run:' ),
51+
'WordPress'
52+
) . '<br /><br />';
5353
$die .= '<code style="color: green;">grunt watch</code></li>';
5454
$die .= '<li>' . sprintf(
55-
__( 'To create a production build of %s run:' ),
56-
'WordPress'
57-
) . '<br /><br />';
55+
__( 'To create a production build of %s run:' ),
56+
'WordPress'
57+
) . '<br /><br />';
5858
$die .= '<code style="color: green;">grunt build</code></li>';
5959
$die .= '</ul>';
6060

src/wp-admin/index.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,35 +36,35 @@
3636
'WordPress'
3737
) . '</p>';
3838

39-
$die .= '<p>' . __( 'Before running any grunt tasks you need to make sure the dependencies are installed. You can install these by running ');
39+
$die .= '<p>' . __( 'Before running any grunt tasks you need to make sure the dependencies are installed. You can install these by running ' );
4040
$die .= '<code style="color: green;">npm install</code>.</p>';
4141

4242
$die .= '<ul>';
4343
$die .= '<li>' . sprintf(
4444
/* translators: %s: WordPress */
4545
__( 'To build %s while developing run:' ),
46-
'WordPress'
47-
) . '<br /><br />';
46+
'WordPress'
47+
) . '<br /><br />';
4848
$die .= '<code style="color: green;">grunt build --dev</code></li>';
4949
$die .= '<li>' . sprintf(
50-
__( 'To build files automatically when changing the source files run:' ),
51-
'WordPress'
52-
) . '<br /><br />';
50+
__( 'To build files automatically when changing the source files run:' ),
51+
'WordPress'
52+
) . '<br /><br />';
5353
$die .= '<code style="color: green;">grunt watch</code></li>';
5454
$die .= '<li>' . sprintf(
55-
__( 'To create a production build of %s run:' ),
56-
'WordPress'
57-
) . '<br /><br />';
55+
__( 'To create a production build of %s run:' ),
56+
'WordPress'
57+
) . '<br /><br />';
5858
$die .= '<code style="color: green;">grunt build</code></li>';
5959
$die .= '</ul>';
6060

6161

6262
$die .= '<p>' . sprintf(
6363
/* translators: %1$s: NPM URL, %2$s: Grunt URL */
6464
__( 'This requires <a href="%1$s">NPM</a> and <a href="%2$s">Grunt</a>. <a href="%3$s">Read more about setting up your local development environment</a>.' ),
65-
'https://www.npmjs.com/',
66-
'https://gruntjs.com/',
67-
__( 'https://make.wordpress.org/core/handbook/tutorials/installing-wordpress-locally/' )
68-
) . '</p>';
65+
'https://www.npmjs.com/',
66+
'https://gruntjs.com/',
67+
__( 'https://make.wordpress.org/core/handbook/tutorials/installing-wordpress-locally/' )
68+
) . '</p>';
6969

7070
wp_die( $die, __( 'WordPress &rsaquo; Error' ) );

src/wp-includes/class-wp-block-parser.php

Lines changed: 46 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,10 @@ class WP_Block_Parser_Block {
6363
public $innerContent;
6464

6565
function __construct( $name, $attrs, $innerBlocks, $innerHTML, $innerContent ) {
66-
$this->blockName = $name;
67-
$this->attrs = $attrs;
68-
$this->innerBlocks = $innerBlocks;
69-
$this->innerHTML = $innerHTML;
66+
$this->blockName = $name;
67+
$this->attrs = $attrs;
68+
$this->innerBlocks = $innerBlocks;
69+
$this->innerHTML = $innerHTML;
7070
$this->innerContent = $innerContent;
7171
}
7272
}
@@ -269,15 +269,17 @@ function proceed() {
269269
*/
270270
if ( 0 === $stack_depth ) {
271271
if ( isset( $leading_html_start ) ) {
272-
$this->output[] = (array) self::freeform( substr(
273-
$this->document,
274-
$leading_html_start,
275-
$start_offset - $leading_html_start
276-
) );
272+
$this->output[] = (array) self::freeform(
273+
substr(
274+
$this->document,
275+
$leading_html_start,
276+
$start_offset - $leading_html_start
277+
)
278+
);
277279
}
278280

279281
$this->output[] = (array) new WP_Block_Parser_Block( $block_name, $attrs, array(), '', array() );
280-
$this->offset = $start_offset + $token_length;
282+
$this->offset = $start_offset + $token_length;
281283
return true;
282284
}
283285

@@ -292,13 +294,16 @@ function proceed() {
292294

293295
case 'block-opener':
294296
// track all newly-opened blocks on the stack
295-
array_push( $this->stack, new WP_Block_Parser_Frame(
296-
new WP_Block_Parser_Block( $block_name, $attrs, array(), '', array() ),
297-
$start_offset,
298-
$token_length,
299-
$start_offset + $token_length,
300-
$leading_html_start
301-
) );
297+
array_push(
298+
$this->stack,
299+
new WP_Block_Parser_Frame(
300+
new WP_Block_Parser_Block( $block_name, $attrs, array(), '', array() ),
301+
$start_offset,
302+
$token_length,
303+
$start_offset + $token_length,
304+
$leading_html_start
305+
)
306+
);
302307
$this->offset = $start_offset + $token_length;
303308
return true;
304309

@@ -329,11 +334,11 @@ function proceed() {
329334
* otherwise we're nested and we have to close out the current
330335
* block and add it as a new innerBlock to the parent
331336
*/
332-
$stack_top = array_pop( $this->stack );
333-
$html = substr( $this->document, $stack_top->prev_offset, $start_offset - $stack_top->prev_offset );
334-
$stack_top->block->innerHTML .= $html;
337+
$stack_top = array_pop( $this->stack );
338+
$html = substr( $this->document, $stack_top->prev_offset, $start_offset - $stack_top->prev_offset );
339+
$stack_top->block->innerHTML .= $html;
335340
$stack_top->block->innerContent[] = $html;
336-
$stack_top->prev_offset = $start_offset + $token_length;
341+
$stack_top->prev_offset = $start_offset + $token_length;
337342

338343
$this->add_inner_block(
339344
$stack_top->block,
@@ -391,22 +396,22 @@ function next_token() {
391396
return array( 'no-more-tokens', null, null, null, null );
392397
}
393398

394-
list( $match, $started_at ) = $matches[ 0 ];
399+
list( $match, $started_at ) = $matches[0];
395400

396401
$length = strlen( $match );
397-
$is_closer = isset( $matches[ 'closer' ] ) && -1 !== $matches[ 'closer' ][ 1 ];
398-
$is_void = isset( $matches[ 'void' ] ) && -1 !== $matches[ 'void' ][ 1 ];
399-
$namespace = $matches[ 'namespace' ];
400-
$namespace = ( isset( $namespace ) && -1 !== $namespace[ 1 ] ) ? $namespace[ 0 ] : 'core/';
401-
$name = $namespace . $matches[ 'name' ][ 0 ];
402-
$has_attrs = isset( $matches[ 'attrs' ] ) && -1 !== $matches[ 'attrs' ][ 1 ];
402+
$is_closer = isset( $matches['closer'] ) && -1 !== $matches['closer'][1];
403+
$is_void = isset( $matches['void'] ) && -1 !== $matches['void'][1];
404+
$namespace = $matches['namespace'];
405+
$namespace = ( isset( $namespace ) && -1 !== $namespace[1] ) ? $namespace[0] : 'core/';
406+
$name = $namespace . $matches['name'][0];
407+
$has_attrs = isset( $matches['attrs'] ) && -1 !== $matches['attrs'][1];
403408

404409
/*
405410
* Fun fact! It's not trivial in PHP to create "an empty associative array" since all arrays
406411
* are associative arrays. If we use `array()` we get a JSON `[]`
407412
*/
408413
$attrs = $has_attrs
409-
? json_decode( $matches[ 'attrs' ][ 0 ], /* as-associative */ true )
414+
? json_decode( $matches['attrs'][0], /* as-associative */ true )
410415
: $this->empty_attrs;
411416

412417
/*
@@ -471,17 +476,17 @@ function add_freeform( $length = null ) {
471476
* @param int|null $last_offset last byte offset into document if continuing form earlier output
472477
*/
473478
function add_inner_block( WP_Block_Parser_Block $block, $token_start, $token_length, $last_offset = null ) {
474-
$parent = $this->stack[ count( $this->stack ) - 1 ];
479+
$parent = $this->stack[ count( $this->stack ) - 1 ];
475480
$parent->block->innerBlocks[] = (array) $block;
476-
$html = substr( $this->document, $parent->prev_offset, $token_start - $parent->prev_offset );
481+
$html = substr( $this->document, $parent->prev_offset, $token_start - $parent->prev_offset );
477482

478483
if ( ! empty( $html ) ) {
479-
$parent->block->innerHTML .= $html;
484+
$parent->block->innerHTML .= $html;
480485
$parent->block->innerContent[] = $html;
481486
}
482487

483488
$parent->block->innerContent[] = null;
484-
$parent->prev_offset = $last_offset ? $last_offset : $token_start + $token_length;
489+
$parent->prev_offset = $last_offset ? $last_offset : $token_start + $token_length;
485490
}
486491

487492
/**
@@ -500,16 +505,18 @@ function add_block_from_stack( $end_offset = null ) {
500505
: substr( $this->document, $prev_offset );
501506

502507
if ( ! empty( $html ) ) {
503-
$stack_top->block->innerHTML .= $html;
508+
$stack_top->block->innerHTML .= $html;
504509
$stack_top->block->innerContent[] = $html;
505510
}
506511

507512
if ( isset( $stack_top->leading_html_start ) ) {
508-
$this->output[] = (array) self::freeform( substr(
509-
$this->document,
510-
$stack_top->leading_html_start,
511-
$stack_top->token_start - $stack_top->leading_html_start
512-
) );
513+
$this->output[] = (array) self::freeform(
514+
substr(
515+
$this->document,
516+
$stack_top->leading_html_start,
517+
$stack_top->token_start - $stack_top->leading_html_start
518+
)
519+
);
513520
}
514521

515522
$this->output[] = (array) $stack_top->block;

0 commit comments

Comments
 (0)