Make WordPress Core

Changeset 60685


Ignore:
Timestamp:
08/28/2025 07:54:21 AM (14 months ago)
Author:
jonsurrell
Message:

Script Loader: Add sourceURL to inline scripts and styles.

Improve the source locations referenced by developer tooling in supporting browsers. Inline source locations are named like inline:handle-js-after and appear in the developer tools "sources" panel.

Developed in ​https://github.com/WordPress/wordpress-develop/pull/9628.

Props jonsurrell, swissspidy, alshakero, westonruter.
Fixes #63887.

Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-scripts.php

    r60681 r60685  
    222222                        return;
    223223                }
     224
     225                $output .= sprintf(
     226                        "\n//# sourceURL=inline:%s",
     227                        rawurlencode( "{$handle}-js-extra" )
     228                );
    224229
    225230                if ( ! $display ) {
    … …  
    521526                        return '';
    522527                }
     528
     529                $data[] = sprintf(
     530                        '//# sourceURL=inline:%s',
     531                        rawurlencode( "{$handle}-js-{$position}" )
     532                );
    523533
    524534                return trim( implode( "\n", $data ), "\n" );
  • trunk/src/wp-includes/class-wp-styles.php

    r58878 r60685  
    337337                        return false;
    338338                }
     339
     340                $output[] = sprintf(
     341                        '/*# sourceURL=inline:%s */',
     342                        rawurlencode( "{$handle}-inline-css" )
     343                );
    339344
    340345                $output = implode( "\n", $output );
  • trunk/tests/phpunit/tests/blocks/editor.php

    r60648 r60685  
    763763<script id="wp-api-fetch-js-after">
    764764wp.apiFetch.use( wp.apiFetch.createPreloadingMiddleware( {"/test/v0/test-62797":{"body":["Unclosed comment and a script open tag \\u003C!--\\u003Cscript\\u003E"],"headers":{"Allow":"GET"}}} ) );
     765//# sourceURL=inline:wp-api-fetch-js-after
    765766</script>
    766767
  • trunk/tests/phpunit/tests/dependencies/scripts.php

    r60666 r60685  
    117117        public function test_after_inline_script_with_delayed_main_script( $strategy ) {
    118118                wp_enqueue_script( 'ms-isa-1', 'http://example.org/ms-isa-1.js', array(), null, compact( 'strategy' ) );
    119                 wp_add_inline_script( 'ms-isa-1', 'console.log("after one");', 'after' );
     119                wp_add_inline_script( 'ms-isa-1', 'console.log(\'after one\');', 'after' );
    120120                $output    = get_echo( 'wp_print_scripts' );
    121121                $expected  = "<script type='text/javascript' src='http://example.org/ms-isa-1.js' id='ms-isa-1-js' data-wp-strategy='{$strategy}'></script>\n";
    122122                $expected .= wp_get_inline_script_tag(
    123                         'console.log("after one");',
     123                        "console.log('after one');\n//# sourceURL=inline:ms-isa-1-js-after",
    124124                        array(
    125125                                'id' => 'ms-isa-1-js-after',
    … …  
    144144        public function test_after_inline_script_with_blocking_main_script() {
    145145                wp_enqueue_script( 'ms-insa-3', 'http://example.org/ms-insa-3.js', array(), null );
    146                 wp_add_inline_script( 'ms-insa-3', 'console.log("after one");', 'after' );
     146                wp_add_inline_script( 'ms-insa-3', 'console.log(\'after one\');', 'after' );
    147147                $output = get_echo( 'wp_print_scripts' );
    148148
    149149                $expected  = "<script type='text/javascript' src='http://example.org/ms-insa-3.js' id='ms-insa-3-js'></script>\n";
    150150                $expected .= wp_get_inline_script_tag(
    151                         'console.log("after one");',
     151                        "console.log('after one');\n//# sourceURL=inline:ms-insa-3-js-after",
    152152                        array(
    153153                                'id' => 'ms-insa-3-js-after',
    … …  
    175175        public function test_before_inline_scripts_with_delayed_main_script( $strategy ) {
    176176                wp_enqueue_script( 'ds-i1-1', 'http://example.org/ds-i1-1.js', array(), null, compact( 'strategy' ) );
    177                 wp_add_inline_script( 'ds-i1-1', 'console.log("before first");', 'before' );
     177                wp_add_inline_script( 'ds-i1-1', 'console.log(\'before first\');', 'before' );
    178178                wp_enqueue_script( 'ds-i1-2', 'http://example.org/ds-i1-2.js', array(), null, compact( 'strategy' ) );
    179179                wp_enqueue_script( 'ds-i1-3', 'http://example.org/ds-i1-3.js', array(), null, compact( 'strategy' ) );
    180180                wp_enqueue_script( 'ms-i1-1', 'http://example.org/ms-i1-1.js', array( 'ds-i1-1', 'ds-i1-2', 'ds-i1-3' ), null, compact( 'strategy' ) );
    181                 wp_add_inline_script( 'ms-i1-1', 'console.log("before last");', 'before' );
     181                wp_add_inline_script( 'ms-i1-1', 'console.log(\'before last\');', 'before' );
    182182                $output = get_echo( 'wp_print_scripts' );
    183183
    184184                $expected  = wp_get_inline_script_tag(
    185                         'console.log("before first");',
     185                        "console.log('before first');\n//# sourceURL=inline:ds-i1-1-js-before",
    186186                        array(
    187187                                'id' => 'ds-i1-1-js-before',
    … …  
    192192                $expected .= "<script type='text/javascript' src='http://example.org/ds-i1-3.js' id='ds-i1-3-js' {$strategy}='{$strategy}' data-wp-strategy='{$strategy}'></script>\n";
    193193                $expected .= wp_get_inline_script_tag(
    194                         'console.log("before last");',
     194                        "console.log('before last');\n//# sourceURL=inline:ms-i1-1-js-before",
    195195                        array(
    196196                                'id'   => 'ms-i1-1-js-before',
    … …  
    514514/* <![CDATA[ */
    515515scriptEventLog.push( "blocking-not-async-without-dependency: before inline" )
     516//# sourceURL=inline:blocking-not-async-without-dependency-js-before
    516517/* ]]> */
    517518</script>
    … …  
    520521/* <![CDATA[ */
    521522scriptEventLog.push( "blocking-not-async-without-dependency: after inline" )
     523//# sourceURL=inline:blocking-not-async-without-dependency-js-after
    522524/* ]]> */
    523525</script>
    … …  
    525527/* <![CDATA[ */
    526528scriptEventLog.push( "async-with-blocking-dependency: before inline" )
     529//# sourceURL=inline:async-with-blocking-dependency-js-before
    527530/* ]]> */
    528531</script>
    … …  
    531534/* <![CDATA[ */
    532535scriptEventLog.push( "async-with-blocking-dependency: after inline" )
     536//# sourceURL=inline:async-with-blocking-dependency-js-after
    533537/* ]]> */
    534538</script>
    … …  
    559563/* <![CDATA[ */
    560564scriptEventLog.push( "async-no-dependency: before inline" )
     565//# sourceURL=inline:async-no-dependency-js-before
    561566/* ]]> */
    562567</script>
    … …  
    565570/* <![CDATA[ */
    566571scriptEventLog.push( "async-no-dependency: after inline" )
     572//# sourceURL=inline:async-no-dependency-js-after
    567573/* ]]> */
    568574</script>
    … …  
    570576/* <![CDATA[ */
    571577scriptEventLog.push( "async-one-async-dependency: before inline" )
     578//# sourceURL=inline:async-one-async-dependency-js-before
    572579/* ]]> */
    573580</script>
    … …  
    576583/* <![CDATA[ */
    577584scriptEventLog.push( "async-one-async-dependency: after inline" )
     585//# sourceURL=inline:async-one-async-dependency-js-after
    578586/* ]]> */
    579587</script>
    … …  
    581589/* <![CDATA[ */
    582590scriptEventLog.push( "async-two-async-dependencies: before inline" )
     591//# sourceURL=inline:async-two-async-dependencies-js-before
    583592/* ]]> */
    584593</script>
    … …  
    587596/* <![CDATA[ */
    588597scriptEventLog.push( "async-two-async-dependencies: after inline" )
     598//# sourceURL=inline:async-two-async-dependencies-js-after
    589599/* ]]> */
    590600</script>
    … …  
    607617/* <![CDATA[ */
    608618scriptEventLog.push( "async-with-blocking-dependent: before inline" )
     619//# sourceURL=inline:async-with-blocking-dependent-js-before
    609620/* ]]> */
    610621</script>
    … …  
    613624/* <![CDATA[ */
    614625scriptEventLog.push( "async-with-blocking-dependent: after inline" )
     626//# sourceURL=inline:async-with-blocking-dependent-js-after
    615627/* ]]> */
    616628</script>
    … …  
    618630/* <![CDATA[ */
    619631scriptEventLog.push( "blocking-dependent-of-async: before inline" )
     632//# sourceURL=inline:blocking-dependent-of-async-js-before
    620633/* ]]> */
    621634</script>
    … …  
    624637/* <![CDATA[ */
    625638scriptEventLog.push( "blocking-dependent-of-async: after inline" )
     639//# sourceURL=inline:blocking-dependent-of-async-js-after
    626640/* ]]> */
    627641</script>
    … …  
    644658/* <![CDATA[ */
    645659scriptEventLog.push( "async-with-defer-dependent: before inline" )
     660//# sourceURL=inline:async-with-defer-dependent-js-before
    646661/* ]]> */
    647662</script>
    … …  
    650665/* <![CDATA[ */
    651666scriptEventLog.push( "async-with-defer-dependent: after inline" )
     667//# sourceURL=inline:async-with-defer-dependent-js-after
    652668/* ]]> */
    653669</script>
    … …  
    655671/* <![CDATA[ */
    656672scriptEventLog.push( "defer-dependent-of-async: before inline" )
     673//# sourceURL=inline:defer-dependent-of-async-js-before
    657674/* ]]> */
    658675</script>
    … …  
    661678/* <![CDATA[ */
    662679scriptEventLog.push( "defer-dependent-of-async: after inline" )
     680//# sourceURL=inline:defer-dependent-of-async-js-after
    663681/* ]]> */
    664682</script>
    … …  
    684702/* <![CDATA[ */
    685703scriptEventLog.push( "blocking-bundle-of-none: before inline" )
     704//# sourceURL=inline:blocking-bundle-of-none-js-before
    686705/* ]]> */
    687706</script>
    … …  
    689708/* <![CDATA[ */
    690709scriptEventLog.push( "blocking-bundle-of-none: after inline" )
     710//# sourceURL=inline:blocking-bundle-of-none-js-after
    691711/* ]]> */
    692712</script>
    … …  
    694714/* <![CDATA[ */
    695715scriptEventLog.push( "defer-dependent-of-blocking-bundle-of-none: before inline" )
     716//# sourceURL=inline:defer-dependent-of-blocking-bundle-of-none-js-before
    696717/* ]]> */
    697718</script>
    … …  
    700721/* <![CDATA[ */
    701722scriptEventLog.push( "defer-dependent-of-blocking-bundle-of-none: after inline" )
     723//# sourceURL=inline:defer-dependent-of-blocking-bundle-of-none-js-after
    702724/* ]]> */
    703725</script>
    … …  
    726748/* <![CDATA[ */
    727749scriptEventLog.push( "blocking-bundle-member-one: before inline" )
     750//# sourceURL=inline:blocking-bundle-member-one-js-before
    728751/* ]]> */
    729752</script>
    … …  
    732755/* <![CDATA[ */
    733756scriptEventLog.push( "blocking-bundle-member-one: after inline" )
     757//# sourceURL=inline:blocking-bundle-member-one-js-after
    734758/* ]]> */
    735759</script>
    … …  
    737761/* <![CDATA[ */
    738762scriptEventLog.push( "blocking-bundle-member-two: before inline" )
     763//# sourceURL=inline:blocking-bundle-member-two-js-before
    739764/* ]]> */
    740765</script>
    … …  
    743768/* <![CDATA[ */
    744769scriptEventLog.push( "blocking-bundle-member-two: after inline" )
     770//# sourceURL=inline:blocking-bundle-member-two-js-after
    745771/* ]]> */
    746772</script>
    … …  
    748774/* <![CDATA[ */
    749775scriptEventLog.push( "defer-dependent-of-blocking-bundle-of-two: before inline" )
     776//# sourceURL=inline:defer-dependent-of-blocking-bundle-of-two-js-before
    750777/* ]]> */
    751778</script>
    … …  
    754781/* <![CDATA[ */
    755782scriptEventLog.push( "defer-dependent-of-blocking-bundle-of-two: after inline" )
     783//# sourceURL=inline:defer-dependent-of-blocking-bundle-of-two-js-after
    756784/* ]]> */
    757785</script>
    … …  
    779807/* <![CDATA[ */
    780808scriptEventLog.push( "defer-bundle-of-none: before inline" )
     809//# sourceURL=inline:defer-bundle-of-none-js-before
    781810/* ]]> */
    782811</script>
    … …  
    784813/* <![CDATA[ */
    785814scriptEventLog.push( "defer-bundle-of-none: after inline" )
     815//# sourceURL=inline:defer-bundle-of-none-js-after
    786816/* ]]> */
    787817</script>
    … …  
    789819/* <![CDATA[ */
    790820scriptEventLog.push( "defer-dependent-of-defer-bundle-of-none: before inline" )
     821//# sourceURL=inline:defer-dependent-of-defer-bundle-of-none-js-before
    791822/* ]]> */
    792823</script>
    … …  
    795826/* <![CDATA[ */
    796827scriptEventLog.push( "defer-dependent-of-defer-bundle-of-none: after inline" )
     828//# sourceURL=inline:defer-dependent-of-defer-bundle-of-none-js-after
    797829/* ]]> */
    798830</script>
    … …  
    818850/* <![CDATA[ */
    819851scriptEventLog.push( "blocking-dependency-with-defer-following-dependency: before inline" )
     852//# sourceURL=inline:blocking-dependency-with-defer-following-dependency-js-before
    820853/* ]]> */
    821854</script>
    … …  
    824857/* <![CDATA[ */
    825858scriptEventLog.push( "blocking-dependency-with-defer-following-dependency: after inline" )
     859//# sourceURL=inline:blocking-dependency-with-defer-following-dependency-js-after
    826860/* ]]> */
    827861</script>
    … …  
    829863/* <![CDATA[ */
    830864scriptEventLog.push( "defer-dependency-with-blocking-preceding-dependency: before inline" )
     865//# sourceURL=inline:defer-dependency-with-blocking-preceding-dependency-js-before
    831866/* ]]> */
    832867</script>
    … …  
    835870/* <![CDATA[ */
    836871scriptEventLog.push( "defer-dependency-with-blocking-preceding-dependency: after inline" )
     872//# sourceURL=inline:defer-dependency-with-blocking-preceding-dependency-js-after
    837873/* ]]> */
    838874</script>
    … …  
    840876/* <![CDATA[ */
    841877scriptEventLog.push( "defer-dependent-of-blocking-and-defer-dependencies: before inline" )
     878//# sourceURL=inline:defer-dependent-of-blocking-and-defer-dependencies-js-before
    842879/* ]]> */
    843880</script>
    … …  
    846883/* <![CDATA[ */
    847884scriptEventLog.push( "defer-dependent-of-blocking-and-defer-dependencies: after inline" )
     885//# sourceURL=inline:defer-dependent-of-blocking-and-defer-dependencies-js-after
    848886/* ]]> */
    849887</script>
    … …  
    869907/* <![CDATA[ */
    870908scriptEventLog.push( "defer-dependency-with-blocking-following-dependency: before inline" )
     909//# sourceURL=inline:defer-dependency-with-blocking-following-dependency-js-before
    871910/* ]]> */
    872911</script>
    … …  
    875914/* <![CDATA[ */
    876915scriptEventLog.push( "defer-dependency-with-blocking-following-dependency: after inline" )
     916//# sourceURL=inline:defer-dependency-with-blocking-following-dependency-js-after
    877917/* ]]> */
    878918</script>
    … …  
    880920/* <![CDATA[ */
    881921scriptEventLog.push( "blocking-dependency-with-defer-preceding-dependency: before inline" )
     922//# sourceURL=inline:blocking-dependency-with-defer-preceding-dependency-js-before
    882923/* ]]> */
    883924</script>
    … …  
    886927/* <![CDATA[ */
    887928scriptEventLog.push( "blocking-dependency-with-defer-preceding-dependency: after inline" )
     929//# sourceURL=inline:blocking-dependency-with-defer-preceding-dependency-js-after
    888930/* ]]> */
    889931</script>
    … …  
    891933/* <![CDATA[ */
    892934scriptEventLog.push( "defer-dependent-of-defer-and-blocking-dependencies: before inline" )
     935//# sourceURL=inline:defer-dependent-of-defer-and-blocking-dependencies-js-before
    893936/* ]]> */
    894937</script>
    … …  
    897940/* <![CDATA[ */
    898941scriptEventLog.push( "defer-dependent-of-defer-and-blocking-dependencies: after inline" )
     942//# sourceURL=inline:defer-dependent-of-defer-and-blocking-dependencies-js-after
    899943/* ]]> */
    900944</script>
    … …  
    917961/* <![CDATA[ */
    918962scriptEventLog.push( "defer-with-async-dependent: before inline" )
     963//# sourceURL=inline:defer-with-async-dependent-js-before
    919964/* ]]> */
    920965</script>
    … …  
    923968/* <![CDATA[ */
    924969scriptEventLog.push( "defer-with-async-dependent: after inline" )
     970//# sourceURL=inline:defer-with-async-dependent-js-after
    925971/* ]]> */
    926972</script>
    … …  
    928974/* <![CDATA[ */
    929975scriptEventLog.push( "async-dependent-of-defer: before inline" )
     976//# sourceURL=inline:async-dependent-of-defer-js-before
    930977/* ]]> */
    931978</script>
    … …  
    934981/* <![CDATA[ */
    935982scriptEventLog.push( "async-dependent-of-defer: after inline" )
     983//# sourceURL=inline:async-dependent-of-defer-js-after
    936984/* ]]> */
    937985</script>
    … …  
    950998/* <![CDATA[ */
    951999scriptEventLog.push( "defer-with-before-inline: before inline" )
     1000//# sourceURL=inline:defer-with-before-inline-js-before
    9521001/* ]]> */
    9531002</script>
    … …  
    9681017/* <![CDATA[ */
    9691018scriptEventLog.push( "defer-with-after-inline: after inline" )
     1019//# sourceURL=inline:defer-with-after-inline-js-after
    9701020/* ]]> */
    9711021</script>
    … …  
    10151065/* <![CDATA[ */
    10161066scriptEventLog.push( "defer-dependent-of-nested-aliases: before inline" )
     1067//# sourceURL=inline:defer-dependent-of-nested-aliases-js-before
    10171068/* ]]> */
    10181069</script>
    … …  
    10211072/* <![CDATA[ */
    10221073scriptEventLog.push( "defer-dependent-of-nested-aliases: after inline" )
     1074//# sourceURL=inline:defer-dependent-of-nested-aliases-js-after
    10231075/* ]]> */
    10241076</script>
    … …  
    16191671                wp_enqueue_script( 'test-only-data', 'example.com', array(), null );
    16201672                wp_script_add_data( 'test-only-data', 'data', 'testing' );
    1621                 $expected  = "<script type='text/javascript' id='test-only-data-js-extra'>\n/* <![CDATA[ */\ntesting\n/* ]]> */\n</script>\n";
     1673                $expected  = "<script type='text/javascript' id='test-only-data-js-extra'>\n/* <![CDATA[ */\ntesting\n//# sourceURL=inline:test-only-data-js-extra\n/* ]]> */\n</script>\n";
    16221674                $expected .= "<script type='text/javascript' src='http://example.com' id='test-only-data-js'></script>\n";
    16231675
    … …  
    16571709                wp_script_add_data( 'test-conditional-with-data', 'data', 'testing' );
    16581710                wp_script_add_data( 'test-conditional-with-data', 'conditional', 'lt IE 9' );
    1659                 $expected  = "<!--[if lt IE 9]>\n<script type='text/javascript' id='test-conditional-with-data-js-extra'>\n/* <![CDATA[ */\ntesting\n/* ]]> */\n</script>\n<![endif]-->\n";
     1711                $expected  = "<!--[if lt IE 9]>\n<script type='text/javascript' id='test-conditional-with-data-js-extra'>\n/* <![CDATA[ */\ntesting\n//# sourceURL=inline:test-conditional-with-data-js-extra\n/* ]]> */\n</script>\n<![endif]-->\n";
    16601712                $expected .= "<!--[if lt IE 9]>\n<script type='text/javascript' src='http://example.com' id='test-conditional-with-data-js'></script>\n<![endif]-->\n";
    16611713                $expected  = str_replace( "'", '"', $expected );
    … …  
    18811933/* <![CDATA[ */
    18821934console.log("before");
     1935//# sourceURL=inline:test-example-js-before
    18831936/* ]]> */
    18841937</script>
    … …  
    19011954/* <![CDATA[ */
    19021955console.log("after");
     1956//# sourceURL=inline:test-example-js-after
    19031957/* ]]> */
    19041958</script>
    … …  
    19161970                wp_add_inline_script( 'test-example', 'console.log("after");' );
    19171971
    1918                 $expected  = "<script type='text/javascript' id='test-example-js-before'>\n/* <![CDATA[ */\nconsole.log(\"before\");\n/* ]]> */\n</script>\n";
     1972                $expected  = "<script type='text/javascript' id='test-example-js-before'>\n/* <![CDATA[ */\nconsole.log(\"before\");\n//# sourceURL=inline:test-example-js-before\n/* ]]> */\n</script>\n";
    19191973                $expected .= "<script type='text/javascript' src='http://example.com' id='test-example-js'></script>\n";
    1920                 $expected .= "<script type='text/javascript' id='test-example-js-after'>\n/* <![CDATA[ */\nconsole.log(\"after\");\n/* ]]> */\n</script>\n";
     1974                $expected .= "<script type='text/javascript' id='test-example-js-after'>\n/* <![CDATA[ */\nconsole.log(\"after\");\n//# sourceURL=inline:test-example-js-after\n/* ]]> */\n</script>\n";
    19211975
    19221976                $this->assertEqualHTML( $expected, get_echo( 'wp_print_scripts' ) );
    … …  
    19311985                wp_add_inline_script( 'test-example', 'console.log("before");', 'before' );
    19321986
    1933                 $expected = "<script type='text/javascript' id='test-example-js-before'>\n/* <![CDATA[ */\nconsole.log(\"before\");\n/* ]]> */\n</script>\n";
     1987                $expected = "<script type='text/javascript' id='test-example-js-before'>\n/* <![CDATA[ */\nconsole.log(\"before\");\n//# sourceURL=inline:test-example-js-before\n/* ]]> */\n</script>\n";
    19341988
    19351989                $this->assertEqualHTML( $expected, get_echo( 'wp_print_scripts' ) );
    … …  
    19441998                wp_add_inline_script( 'test-example', 'console.log("after");' );
    19451999
    1946                 $expected = "<script type='text/javascript' id='test-example-js-after'>\n/* <![CDATA[ */\nconsole.log(\"after\");\n/* ]]> */\n</script>\n";
     2000                $expected = "<script type='text/javascript' id='test-example-js-after'>\n/* <![CDATA[ */\nconsole.log(\"after\");\n//# sourceURL=inline:test-example-js-after\n/* ]]> */\n</script>\n";
    19472001
    19482002                $this->assertEqualHTML( $expected, get_echo( 'wp_print_scripts' ) );
    … …  
    19582012                wp_add_inline_script( 'test-example', 'console.log("after");' );
    19592013
    1960                 $expected  = "<script type='text/javascript' id='test-example-js-before'>\n/* <![CDATA[ */\nconsole.log(\"before\");\n/* ]]> */\n</script>\n";
    1961                 $expected .= "<script type='text/javascript' id='test-example-js-after'>\n/* <![CDATA[ */\nconsole.log(\"after\");\n/* ]]> */\n</script>\n";
     2014                $expected  = "<script type='text/javascript' id='test-example-js-before'>\n/* <![CDATA[ */\nconsole.log(\"before\");\n//# sourceURL=inline:test-example-js-before\n/* ]]> */\n</script>\n";
     2015                $expected .= "<script type='text/javascript' id='test-example-js-after'>\n/* <![CDATA[ */\nconsole.log(\"after\");\n//# sourceURL=inline:test-example-js-after\n/* ]]> */\n</script>\n";
    19622016
    19632017                $this->assertEqualHTML( $expected, get_echo( 'wp_print_scripts' ) );
    … …  
    19742028                wp_add_inline_script( 'test-example', 'console.log("after");' );
    19752029
    1976                 $expected  = "<script type='text/javascript' id='test-example-js-before'>\n/* <![CDATA[ */\nconsole.log(\"before\");\nconsole.log(\"before\");\n/* ]]> */\n</script>\n";
     2030                $expected  = "<script type='text/javascript' id='test-example-js-before'>\n/* <![CDATA[ */\nconsole.log(\"before\");\nconsole.log(\"before\");\n//# sourceURL=inline:test-example-js-before\n/* ]]> */\n</script>\n";
    19772031                $expected .= "<script type='text/javascript' src='http://example.com' id='test-example-js'></script>\n";
    1978                 $expected .= "<script type='text/javascript' id='test-example-js-after'>\n/* <![CDATA[ */\nconsole.log(\"after\");\nconsole.log(\"after\");\n/* ]]> */\n</script>\n";
     2032                $expected .= "<script type='text/javascript' id='test-example-js-after'>\n/* <![CDATA[ */\nconsole.log(\"after\");\nconsole.log(\"after\");\n//# sourceURL=inline:test-example-js-after\n/* ]]> */\n</script>\n";
    19792033
    19802034                $this->assertEqualHTML( $expected, get_echo( 'wp_print_scripts' ) );
    … …  
    19902044                wp_add_inline_script( 'test-example', 'console.log("after");' );
    19912045
    1992                 $expected  = "<script type='text/javascript' id='test-example-js-extra'>\n/* <![CDATA[ */\nvar testExample = {\"foo\":\"bar\"};\n/* ]]> */\n</script>\n";
    1993                 $expected .= "<script type='text/javascript' id='test-example-js-before'>\n/* <![CDATA[ */\nconsole.log(\"before\");\n/* ]]> */\n</script>\n";
     2046                $expected  = "<script type='text/javascript' id='test-example-js-extra'>\n/* <![CDATA[ */\nvar testExample = {\"foo\":\"bar\"};\n//# sourceURL=inline:test-example-js-extra\n/* ]]> */\n</script>\n";
     2047                $expected .= "<script type='text/javascript' id='test-example-js-before'>\n/* <![CDATA[ */\nconsole.log(\"before\");\n//# sourceURL=inline:test-example-js-before\n/* ]]> */\n</script>\n";
    19942048                $expected .= "<script type='text/javascript' src='http://example.com' id='test-example-js'></script>\n";
    1995                 $expected .= "<script type='text/javascript' id='test-example-js-after'>\n/* <![CDATA[ */\nconsole.log(\"after\");\n/* ]]> */\n</script>\n";
     2049                $expected .= "<script type='text/javascript' id='test-example-js-after'>\n/* <![CDATA[ */\nconsole.log(\"after\");\n//# sourceURL=inline:test-example-js-after\n/* ]]> */\n</script>\n";
    19962050
    19972051                $this->assertEqualHTML( $expected, get_echo( 'wp_print_scripts' ) );
    … …  
    20142068                wp_add_inline_script( 'two', 'console.log("before two");', 'before' );
    20152069
    2016                 $expected  = "<script type='text/javascript' id='one-js-before'>\n/* <![CDATA[ */\nconsole.log(\"before one\");\n/* ]]> */\n</script>\n";
     2070                $expected  = "<script type='text/javascript' id='one-js-before'>\n/* <![CDATA[ */\nconsole.log(\"before one\");\n//# sourceURL=inline:one-js-before\n/* ]]> */\n</script>\n";
    20172071                $expected .= "<script type='text/javascript' src='{$this->default_scripts_dir}one.js?ver={$wp_version}' id='one-js'></script>\n";
    2018                 $expected .= "<script type='text/javascript' id='two-js-before'>\n/* <![CDATA[ */\nconsole.log(\"before two\");\n/* ]]> */\n</script>\n";
     2072                $expected .= "<script type='text/javascript' id='two-js-before'>\n/* <![CDATA[ */\nconsole.log(\"before two\");\n//# sourceURL=inline:two-js-before\n/* ]]> */\n</script>\n";
    20192073                $expected .= "<script type='text/javascript' src='{$this->default_scripts_dir}two.js?ver={$wp_version}' id='two-js'></script>\n";
    20202074                $expected .= "<script type='text/javascript' src='{$this->default_scripts_dir}three.js?ver={$wp_version}' id='three-js'></script>\n";
    … …  
    20382092                wp_add_inline_script( 'one', 'console.log("before one");', 'before' );
    20392093
    2040                 $expected  = "<script type='text/javascript' id='one-js-before'>\n/* <![CDATA[ */\nconsole.log(\"before one\");\n/* ]]> */\n</script>\n";
     2094                $expected  = "<script type='text/javascript' id='one-js-before'>\n/* <![CDATA[ */\nconsole.log(\"before one\");\n//# sourceURL=inline:one-js-before\n/* ]]> */\n</script>\n";
    20412095                $expected .= "<script type='text/javascript' src='{$this->default_scripts_dir}one.js?ver={$wp_version}' id='one-js'></script>\n";
    20422096                $expected .= "<script type='text/javascript' src='{$this->default_scripts_dir}two.js?ver={$wp_version}' id='two-js'></script>\n";
    … …  
    20652119                $expected  = "<script type='text/javascript' src='/wp-admin/load-scripts.php?c=0&amp;load%5Bchunk_0%5D=one&amp;ver={$wp_version}'></script>\n";
    20662120                $expected .= "<script type='text/javascript' src='{$this->default_scripts_dir}two.js?ver={$wp_version}' id='two-js'></script>\n";
    2067                 $expected .= "<script type='text/javascript' id='two-js-after'>\n/* <![CDATA[ */\nconsole.log(\"after two\");\n/* ]]> */\n</script>\n";
     2121                $expected .= "<script type='text/javascript' id='two-js-after'>\n/* <![CDATA[ */\nconsole.log(\"after two\");\n//# sourceURL=inline:two-js-after\n/* ]]> */\n</script>\n";
    20682122                $expected .= "<script type='text/javascript' src='{$this->default_scripts_dir}three.js?ver={$wp_version}' id='three-js'></script>\n";
    2069                 $expected .= "<script type='text/javascript' id='three-js-after'>\n/* <![CDATA[ */\nconsole.log(\"after three\");\n/* ]]> */\n</script>\n";
     2123                $expected .= "<script type='text/javascript' id='three-js-after'>\n/* <![CDATA[ */\nconsole.log(\"after three\");\n//# sourceURL=inline:three-js-after\n/* ]]> */\n</script>\n";
    20702124                $expected .= "<script type='text/javascript' src='{$this->default_scripts_dir}four.js?ver={$wp_version}' id='four-js'></script>\n";
    20712125
    … …  
    20832137
    20842138                $expected_localized  = "<!--[if gte IE 9]>\n";
    2085                 $expected_localized .= "<script type='text/javascript' id='test-example-js-extra'>\n/* <![CDATA[ */\nvar testExample = {\"foo\":\"bar\"};\n/* ]]> */\n</script>\n";
     2139                $expected_localized .= "<script type='text/javascript' id='test-example-js-extra'>\n/* <![CDATA[ */\nvar testExample = {\"foo\":\"bar\"};\n//# sourceURL=inline:test-example-js-extra\n/* ]]> */\n</script>\n";
    20862140                $expected_localized .= "<![endif]-->\n";
    20872141                $expected_localized  = str_replace( "'", '"', $expected_localized );
    20882142
    20892143                $expected  = "<!--[if gte IE 9]>\n";
    2090                 $expected .= "<script type='text/javascript' id='test-example-js-before'>\n/* <![CDATA[ */\nconsole.log(\"before\");\n/* ]]> */\n</script>\n";
     2144                $expected .= "<script type='text/javascript' id='test-example-js-before'>\n/* <![CDATA[ */\nconsole.log(\"before\");\n//# sourceURL=inline:test-example-js-before\n/* ]]> */\n</script>\n";
    20912145                $expected .= "<script type='text/javascript' src='http://example.com' id='test-example-js'></script>\n";
    2092                 $expected .= "<script type='text/javascript' id='test-example-js-after'>\n/* <![CDATA[ */\nconsole.log(\"after\");\n/* ]]> */\n</script>\n";
     2146                $expected .= "<script type='text/javascript' id='test-example-js-after'>\n/* <![CDATA[ */\nconsole.log(\"after\");\n//# sourceURL=inline:test-example-js-after\n/* ]]> */\n</script>\n";
    20932147                $expected .= "<![endif]-->\n";
    20942148                $expected  = str_replace( "'", '"', $expected );
    … …  
    21182172                $expected  = "<script type='text/javascript' src='/wp-admin/load-scripts.php?c=0&amp;load%5Bchunk_0%5D=jquery-core,jquery-migrate&amp;ver={$wp_version}'></script>\n";
    21192173                $expected .= "<script type='text/javascript' src='http://example.com' id='test-example-js'></script>\n";
    2120                 $expected .= "<script type='text/javascript' id='test-example-js-after'>\n/* <![CDATA[ */\nconsole.log(\"after\");\n/* ]]> */\n</script>\n";
     2174                $expected .= "<script type='text/javascript' id='test-example-js-after'>\n/* <![CDATA[ */\nconsole.log(\"after\");\n//# sourceURL=inline:test-example-js-after\n/* ]]> */\n</script>\n";
    21212175
    21222176                wp_enqueue_script( 'test-example', 'http://example.com', array( 'jquery' ), null );
    … …  
    21432197                $expected .= "<!--[if gte IE 9]>\n";
    21442198                $expected .= "<script type=\"text/javascript\" src=\"http://example.com\" id=\"test-example-js\"></script>\n";
    2145                 $expected .= "<script type=\"text/javascript\" id=\"test-example-js-after\">\n/* <![CDATA[ */\nconsole.log(\"after\");\n/* ]]> */\n</script>\n";
     2199                $expected .= "<script type=\"text/javascript\" id=\"test-example-js-after\">\n/* <![CDATA[ */\nconsole.log(\"after\");\n//# sourceURL=inline:test-example-js-after\n/* ]]> */\n</script>\n";
    21462200                $expected .= "<![endif]-->\n";
    21472201
    … …  
    21692223
    21702224                $expected  = "<script type='text/javascript' src='/wp-admin/load-scripts.php?c=0&amp;load%5Bchunk_0%5D=jquery-core,jquery-migrate&amp;ver={$wp_version}'></script>\n";
    2171                 $expected .= "<script type='text/javascript' id='test-example-js-before'>\n/* <![CDATA[ */\nconsole.log(\"before\");\n/* ]]> */\n</script>\n";
     2225                $expected .= "<script type='text/javascript' id='test-example-js-before'>\n/* <![CDATA[ */\nconsole.log(\"before\");\n//# sourceURL=inline:test-example-js-before\n/* ]]> */\n</script>\n";
    21722226                $expected .= "<script type='text/javascript' src='http://example.com' id='test-example-js'></script>\n";
    21732227
    … …  
    21942248
    21952249                $expected  = "<script type='text/javascript' src='/wp-admin/load-scripts.php?c=0&amp;load%5Bchunk_0%5D=jquery-core,jquery-migrate,wp-dom-ready,wp-hooks&amp;ver={$wp_version}'></script>\n";
    2196                 $expected .= "<script type='text/javascript' id='test-example-js-before'>\n/* <![CDATA[ */\nconsole.log(\"before\");\n/* ]]> */\n</script>\n";
     2250                $expected .= "<script type='text/javascript' id='test-example-js-before'>\n/* <![CDATA[ */\nconsole.log(\"before\");\n//# sourceURL=inline:test-example-js-before\n/* ]]> */\n</script>\n";
    21972251                $expected .= "<script type='text/javascript' src='http://example.com' id='test-example-js'></script>\n";
    21982252                $expected .= "<script type='text/javascript' src='/wp-includes/js/dist/i18n.min.js' id='wp-i18n-js'></script>\n";
    … …  
    22002254                $expected .= "/* <![CDATA[ */\n";
    22012255                $expected .= "wp.i18n.setLocaleData( { 'text direction\u0004ltr': [ 'ltr' ] } );\n";
     2256                $expected .= "//# sourceURL=inline:wp-i18n-js-after\n";
    22022257                $expected .= "/* ]]> */\n";
    22032258                $expected .= "</script>\n";
    22042259                $expected .= "<script type='text/javascript' src='/wp-includes/js/dist/a11y.min.js' id='wp-a11y-js'></script>\n";
    22052260                $expected .= "<script type='text/javascript' src='http://example2.com' id='test-example2-js'></script>\n";
    2206                 $expected .= "<script type='text/javascript' id='test-example2-js-after'>\n/* <![CDATA[ */\nconsole.log(\"after\");\n/* ]]> */\n</script>\n";
    2207 
     2261                $expected .= "<script type='text/javascript' id='test-example2-js-after'>\n/* <![CDATA[ */\nconsole.log(\"after\");\n//# sourceURL=inline:test-example2-js-after\n/* ]]> */\n</script>\n";
    22082262                wp_enqueue_script( 'test-example', 'http://example.com', array( 'jquery' ), null );
    22092263                wp_add_inline_script( 'test-example', 'console.log("before");', 'before' );
    … …  
    22492303                $expected_tail .= "/* <![CDATA[ */\n";
    22502304                $expected_tail .= "tryCustomizeDependency()\n";
     2305                $expected_tail .= "//# sourceURL=inline:customize-dependency-js-after\n";
    22512306                $expected_tail .= "/* ]]> */\n";
    22522307                $expected_tail .= "</script>\n";
    … …  
    22842339
    22852340                $expected  = "<script type='text/javascript' src='/wp-includes/js/script.js?ver={$wp_version}' id='one-js'></script>\n";
    2286                 $expected .= "<script type='text/javascript' id='one-js-after'>\n/* <![CDATA[ */\nconsole.log(\"after one\");\n/* ]]> */\n</script>\n";
     2341                $expected .= "<script type='text/javascript' id='one-js-after'>\n/* <![CDATA[ */\nconsole.log(\"after one\");\n//# sourceURL=inline:one-js-after\n/* ]]> */\n</script>\n";
    22872342                $expected .= "<script type='text/javascript' src='/wp-includes/js/script2.js?ver={$wp_version}' id='two-js'></script>\n";
    22882343                $expected .= "<script type='text/javascript' src='/wp-includes/js/script3.js?ver={$wp_version}' id='three-js'></script>\n";
    … …  
    23082363
    23092364                $expected  = "<script type='text/javascript' src='/wp-admin/load-scripts.php?c=0&amp;load%5Bchunk_0%5D=one,two&amp;ver={$wp_version}'></script>\n";
    2310                 $expected .= "<script type='text/javascript' id='three-js-before'>\n/* <![CDATA[ */\nconsole.log(\"before three\");\n/* ]]> */\n</script>\n";
     2365                $expected .= "<script type='text/javascript' id='three-js-before'>\n/* <![CDATA[ */\nconsole.log(\"before three\");\n//# sourceURL=inline:three-js-before\n/* ]]> */\n</script>\n";
    23112366                $expected .= "<script type='text/javascript' src='/wp-includes/js/script3.js?ver={$wp_version}' id='three-js'></script>\n";
    23122367                $expected .= "<script type='text/javascript' src='/wp-includes/js/script4.js?ver={$wp_version}' id='four-js'></script>\n";
    … …  
    23282383                                ),
    23292384                                'delayed'        => false,
    2330                                 'expected_data'  => '/*before foo 1*/',
    2331                                 'expected_tag'   => "<script id='foo-js-before' type='text/javascript'>\n/* <![CDATA[ */\n/*before foo 1*/\n/* ]]> */\n</script>\n",
     2385                                'expected_data'  => "/*before foo 1*/\n//# sourceURL=inline:foo-js-before",
     2386                                'expected_tag'   => "<script id='foo-js-before' type='text/javascript'>\n/* <![CDATA[ */\n/*before foo 1*/\n//# sourceURL=inline:foo-js-before\n/* ]]> */\n</script>\n",
    23322387                        ),
    23332388                        'after-blocking'  => array(
    … …  
    23382393                                ),
    23392394                                'delayed'        => false,
    2340                                 'expected_data'  => "/*after foo 1*/\n/*after foo 2*/",
    2341                                 'expected_tag'   => "<script id='foo-js-after' type='text/javascript'>\n/* <![CDATA[ */\n/*after foo 1*/\n/*after foo 2*/\n/* ]]> */\n</script>\n",
     2395                                'expected_data'  => "/*after foo 1*/\n/*after foo 2*/\n//# sourceURL=inline:foo-js-after",
     2396                                'expected_tag'   => "<script id='foo-js-after' type='text/javascript'>\n/* <![CDATA[ */\n/*after foo 1*/\n/*after foo 2*/\n//# sourceURL=inline:foo-js-after\n/* ]]> */\n</script>\n",
    23422397                        ),
    23432398                        'before-delayed'  => array(
    … …  
    23472402                                ),
    23482403                                'delayed'        => true,
    2349                                 'expected_data'  => '/*before foo 1*/',
    2350                                 'expected_tag'   => "<script id='foo-js-before' type='text/javascript'>\n/* <![CDATA[ */\n/*before foo 1*/\n/* ]]> */\n</script>\n",
     2404                                'expected_data'  => "/*before foo 1*/\n//# sourceURL=inline:foo-js-before",
     2405                                'expected_tag'   => "<script id='foo-js-before' type='text/javascript'>\n/* <![CDATA[ */\n/*before foo 1*/\n//# sourceURL=inline:foo-js-before\n/* ]]> */\n</script>\n",
    23512406                        ),
    23522407                        'after-delayed'   => array(
    … …  
    23572412                                ),
    23582413                                'delayed'        => true,
    2359                                 'expected_data'  => "/*after foo 1*/\n/*after foo 2*/",
    2360                                 'expected_tag'   => "<script id='foo-js-after' type='text/javascript'>\n/* <![CDATA[ */\n/*after foo 1*/\n/*after foo 2*/\n/* ]]> */\n</script>\n",
     2414                                'expected_data'  => "/*after foo 1*/\n/*after foo 2*/\n//# sourceURL=inline:foo-js-after",
     2415                                'expected_tag'   => "<script id='foo-js-after' type='text/javascript'>\n/* <![CDATA[ */\n/*after foo 1*/\n/*after foo 2*/\n//# sourceURL=inline:foo-js-after\n/* ]]> */\n</script>\n",
    23612416                        ),
    23622417                );
    … …  
    30003055                wp_localize_script( 'test-example', 'testExample', $l10n_data );
    30013056
    3002                 $expected  = "<script type='text/javascript' id='test-example-js-extra'>\n/* <![CDATA[ */\nvar testExample = {$expected};\n/* ]]> */\n</script>\n";
     3057                $expected  = "<script type='text/javascript' id='test-example-js-extra'>\n/* <![CDATA[ */\nvar testExample = {$expected};\n//# sourceURL=inline:test-example-js-extra\n/* ]]> */\n</script>\n";
    30033058                $expected .= "<script type='text/javascript' src='http://example.com' id='test-example-js'></script>\n";
    30043059
    … …  
    35693624                return $data['dependencies'];
    35703625        }
     3626
     3627        /**
     3628         * @ticket 63887
     3629         */
     3630        public function test_source_url_encoding() {
     3631                $this->add_html5_script_theme_support();
     3632
     3633                $handle = '# test/</script> #';
     3634                wp_enqueue_script( $handle, '/example.js', array(), '0.0' );
     3635                wp_add_inline_script( $handle, '"ok";' );
     3636
     3637                $expected = <<<HTML
     3638<script src="/example.js?ver=0.0" id="# test/</script> #-js"></script>
     3639<script id="# test/</script> #-js-after">
     3640"ok";
     3641//# sourceURL=inline:%23%20test%2F%3C%2Fscript%3E%20%23-js-after
     3642</script>
     3643
     3644HTML;
     3645
     3646                $this->assertEqualHTML( $expected, get_echo( 'wp_print_scripts' ) );
     3647        }
    35713648}
  • trunk/tests/phpunit/tests/dependencies/styles.php

    r58932 r60685  
    151151                $expected .= "<style id='handle-inline-css' type='text/css'>\n";
    152152                $expected .= "$style\n";
     153                $expected .= "/*# sourceURL=inline:handle-inline-css */\n";
    153154                $expected .= "</style>\n";
    154155
    … …  
    180181                $expected .= "<style id='handle-inline-css' type='text/css'>\n";
    181182                $expected .= "$style\n";
     183                $expected .= "/*# sourceURL=inline:handle-inline-css */\n";
    182184                $expected .= "</style>\n";
    183185
    … …  
    275277                $expected .= "$style1\n";
    276278                $expected .= "$style2\n";
     279                $expected .= "/*# sourceURL=inline:handle-inline-css */\n";
    277280                $expected .= "</style>\n";
    278281
    … …  
    293296        public function test_plugin_doing_inline_styles_wrong() {
    294297
    295                 $style  = "<style id='handle-inline-css' type='text/css'>\n";
    296                 $style .= ".thing {\n";
     298                $style  = ".thing {\n";
    297299                $style .= "\tbackground: red;\n";
    298                 $style .= "}\n";
    299                 $style .= '</style>';
     300                $style .= '}';
    300301
    301302                $expected  = "<link rel='stylesheet' id='handle-css' href='http://example.com?ver=1' type='text/css' media='all' />\n";
     303                $expected .= "<style id='handle-inline-css' type='text/css'>\n";
    302304                $expected .= "$style\n";
     305                $expected .= "/*# sourceURL=inline:handle-inline-css */\n";
     306                $expected .= "</style>\n";
    303307
    304308                wp_enqueue_style( 'handle', 'http://example.com', array(), 1 );
    305309
    306                 wp_add_inline_style( 'handle', $style );
     310                wp_add_inline_style( 'handle', "<style>{$style}</style>" );
    307311
    308312                $this->assertSame( $expected, get_echo( 'wp_print_styles' ) );
    … …  
    333337<style id='handle-inline-css' type='text/css'>
    334338a { color: blue; }
     339/*# sourceURL=inline:handle-inline-css */
    335340</style>
    336341<![endif]-->
    … …  
    364369                $expected .= "<style id='handle-three-inline-css' type='text/css'>\n";
    365370                $expected .= "$style\n";
     371                $expected .= "/*# sourceURL=inline:handle-three-inline-css */\n";
    366372                $expected .= "</style>\n";
    367373
    … …  
    633639                $this->assertSame( $GLOBALS['wp_styles']->registered['test-handle']->src, $url );
    634640        }
     641
     642        /**
     643         * @ticket 63887
     644         */
     645        public function test_source_url_encoding() {
     646                $handle = '# test/</style> #';
     647                wp_enqueue_style( $handle, '/example.css', array(), '0.0' );
     648                wp_add_inline_style( $handle, 'custom-el { content: "ok"; }' );
     649
     650                $expected = <<<HTML
     651<link rel='stylesheet' href="/example.css?ver=0.0" id="# test/</style> #-css" media="all" type="text/css">
     652<style id="# test/</style> #-inline-css" type="text/css">
     653custom-el { content: "ok"; }
     654/*# sourceURL=inline:%23%20test%2F%3C%2Fstyle%3E%20%23-inline-css */
     655</style>
     656
     657HTML;
     658
     659                $this->assertEqualHTML( $expected, get_echo( 'wp_print_styles' ) );
     660        }
    635661}
  • trunk/tests/phpunit/tests/dependencies/wpLocalizeScript.php

    r60681 r60685  
    5757                $output = get_echo( 'wp_print_scripts' );
    5858
    59                 $expected  = "<script id=\"test-script-js-extra\">\nvar testData = {\"\\u003C!--\":\"\\u003Cscript\\u003E\"};\n</script>\n";
     59                $expected  = "<script id=\"test-script-js-extra\">\nvar testData = {\"\\u003C!--\":\"\\u003Cscript\\u003E\"};\n//# sourceURL=inline:test-script-js-extra\n</script>\n";
    6060                $expected .= "<script src=\"{$base_url}\" id=\"test-script-js\"></script>\n";
    6161
Note: See TracChangeset for help on using the changeset viewer.