Make WordPress Core

Changeset 60719


Ignore:
Timestamp:
09/08/2025 11:25:40 AM (6 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.

This is the second attempt to add sourceURL comments. The first attempt in [60685] was reverted due to an issue with script concatenation that has been addressed.

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

Follow-up to [60685], [60690].

Props jonsurrell, westonruter, wildworks, peterwilsoncc, johnbillion, tobiasbg.
Fixes #63887.

Location:
trunk
Files:
7 edited

Legend:

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

    r60704 r60719  
    221221        if ( ! $output ) {
    222222            return;
     223        }
     224
     225        /*
     226         * Do not print a sourceURL comment if concatenation is enabled.
     227         *
     228         * Extra scripts may be concatenated into a single script.
     229         * The line-based sourceURL comments may a concatenated script and
     230         * do not make sense when multiple are joined together.
     231         */
     232        if ( ! $this->do_concat ) {
     233            $output .= sprintf(
     234                "\n//# sourceURL=%s",
     235                rawurlencode( "{$handle}-js-extra" )
     236            );
    223237        }
    224238
     
    525539        }
    526540
     541        /*
     542         * Print sourceURL comment regardless of concatenation.
     543         *
     544         * Inline scripts prevent scripts from being concatenated, so
     545         * sourceURL comments are safe to print for inline scripts.
     546         */
     547        $data[] = sprintf(
     548            '//# sourceURL=%s',
     549            rawurlencode( "{$handle}-js-{$position}" )
     550        );
     551
    527552        return trim( implode( "\n", $data ), "\n" );
    528553    }
     
    697722        }
    698723
     724        $source_url = rawurlencode( "{$handle}-js-translations" );
     725
    699726        $output = <<<JS
    700727( function( domain, translations ) {
     
    703730    wp.i18n.setLocaleData( localeData, domain );
    704731} )( "{$domain}", {$json_translations} );
     732//# sourceURL={$source_url}
    705733JS;
    706734
  • trunk/src/wp-includes/class-wp-styles.php

    r60690 r60719  
    336336        if ( empty( $output ) ) {
    337337            return false;
     338        }
     339
     340        if ( ! $this->do_concat ) {
     341            $output[] = sprintf(
     342                '/*# sourceURL=%s */',
     343                rawurlencode( "{$handle}-inline-css" )
     344            );
    338345        }
    339346
  • trunk/src/wp-includes/script-loader.php

    r60704 r60719  
    22132213            echo "/* <![CDATA[ */\n"; // Not needed in HTML 5.
    22142214            echo $wp_scripts->print_code;
     2215            echo sprintf( "\n//# sourceURL=%s\n", rawurlencode( 'js-inline-concat-' . $concat ) );
    22152216            echo "/* ]]> */\n";
    22162217            echo "</script>\n";
     
    23952396        $ver = $wp_styles->default_version;
    23962397
    2397         $concat       = str_split( $concat, 128 );
    2398         $concatenated = '';
     2398        $concat_source_url = 'css-inline-concat-' . $concat;
     2399        $concat            = str_split( $concat, 128 );
     2400        $concatenated      = '';
    23992401
    24002402        foreach ( $concat as $key => $chunk ) {
     
    24082410            echo "<style{$type_attr}>\n";
    24092411            echo $wp_styles->print_code;
     2412            echo sprintf( "\n/*# sourceURL=%s */", rawurlencode( $concat_source_url ) );
    24102413            echo "\n</style>\n";
    24112414        }
  • trunk/tests/phpunit/tests/blocks/editor.php

    r60690 r60719  
    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=wp-api-fetch-js-after
    765766</script>
    766767
  • trunk/tests/phpunit/tests/dependencies/scripts.php

    r60704 r60719  
    1818
    1919    /**
     20     * @var bool
     21     */
     22    protected $old_concatenate_scripts;
     23
     24    /**
    2025     * @var WP_Styles
    2126     */
     
    3338    public function set_up() {
    3439        parent::set_up();
    35         $this->old_wp_scripts = isset( $GLOBALS['wp_scripts'] ) ? $GLOBALS['wp_scripts'] : null;
    36         $this->old_wp_styles  = isset( $GLOBALS['wp_styles'] ) ? $GLOBALS['wp_styles'] : null;
     40        $this->old_wp_scripts          = isset( $GLOBALS['wp_scripts'] ) ? $GLOBALS['wp_scripts'] : null;
     41        $this->old_wp_styles           = isset( $GLOBALS['wp_styles'] ) ? $GLOBALS['wp_styles'] : null;
     42        $this->old_concatenate_scripts = isset( $GLOBALS['concatenate_scripts'] ) ? $GLOBALS['concatenate_scripts'] : null;
    3743        remove_action( 'wp_default_scripts', 'wp_default_scripts' );
    3844        remove_action( 'wp_default_scripts', 'wp_default_packages' );
     
    4955    wp.i18n.setLocaleData( localeData, domain );
    5056} )( "__DOMAIN__", __JSON_TRANSLATIONS__ );
     57//# sourceURL=__HANDLE__-js-translations
    5158/* ]]> */
    5259</script>
     
    5663
    5764    public function tear_down() {
    58         $GLOBALS['wp_scripts'] = $this->old_wp_scripts;
    59         $GLOBALS['wp_styles']  = $this->old_wp_styles;
     65        $GLOBALS['wp_scripts']          = $this->old_wp_scripts;
     66        $GLOBALS['wp_styles']           = $this->old_wp_styles;
     67        $GLOBALS['concatenate_scripts'] = $this->old_concatenate_scripts;
    6068        add_action( 'wp_default_scripts', 'wp_default_scripts' );
    6169        parent::tear_down();
     
    117125    public function test_after_inline_script_with_delayed_main_script( $strategy ) {
    118126        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' );
     127        wp_add_inline_script( 'ms-isa-1', 'console.log(\'after one\');', 'after' );
    120128        $output    = get_echo( 'wp_print_scripts' );
    121129        $expected  = "<script type='text/javascript' src='http://example.org/ms-isa-1.js' id='ms-isa-1-js' data-wp-strategy='{$strategy}'></script>\n";
    122130        $expected .= wp_get_inline_script_tag(
    123             'console.log("after one");',
     131            "console.log('after one');\n//# sourceURL=ms-isa-1-js-after",
    124132            array(
    125133                'id' => 'ms-isa-1-js-after',
     
    144152    public function test_after_inline_script_with_blocking_main_script() {
    145153        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' );
     154        wp_add_inline_script( 'ms-insa-3', 'console.log(\'after one\');', 'after' );
    147155        $output = get_echo( 'wp_print_scripts' );
    148156
    149157        $expected  = "<script type='text/javascript' src='http://example.org/ms-insa-3.js' id='ms-insa-3-js'></script>\n";
    150158        $expected .= wp_get_inline_script_tag(
    151             'console.log("after one");',
     159            "console.log('after one');\n//# sourceURL=ms-insa-3-js-after",
    152160            array(
    153161                'id' => 'ms-insa-3-js-after',
     
    175183    public function test_before_inline_scripts_with_delayed_main_script( $strategy ) {
    176184        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' );
     185        wp_add_inline_script( 'ds-i1-1', 'console.log(\'before first\');', 'before' );
    178186        wp_enqueue_script( 'ds-i1-2', 'http://example.org/ds-i1-2.js', array(), null, compact( 'strategy' ) );
    179187        wp_enqueue_script( 'ds-i1-3', 'http://example.org/ds-i1-3.js', array(), null, compact( 'strategy' ) );
    180188        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' );
     189        wp_add_inline_script( 'ms-i1-1', 'console.log(\'before last\');', 'before' );
    182190        $output = get_echo( 'wp_print_scripts' );
    183191
    184192        $expected  = wp_get_inline_script_tag(
    185             'console.log("before first");',
     193            "console.log('before first');\n//# sourceURL=ds-i1-1-js-before",
    186194            array(
    187195                'id' => 'ds-i1-1-js-before',
     
    192200        $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";
    193201        $expected .= wp_get_inline_script_tag(
    194             'console.log("before last");',
     202            "console.log('before last');\n//# sourceURL=ms-i1-1-js-before",
    195203            array(
    196204                'id'   => 'ms-i1-1-js-before',
     
    514522/* <![CDATA[ */
    515523scriptEventLog.push( "blocking-not-async-without-dependency: before inline" )
     524//# sourceURL=blocking-not-async-without-dependency-js-before
    516525/* ]]> */
    517526</script>
     
    520529/* <![CDATA[ */
    521530scriptEventLog.push( "blocking-not-async-without-dependency: after inline" )
     531//# sourceURL=blocking-not-async-without-dependency-js-after
    522532/* ]]> */
    523533</script>
     
    525535/* <![CDATA[ */
    526536scriptEventLog.push( "async-with-blocking-dependency: before inline" )
     537//# sourceURL=async-with-blocking-dependency-js-before
    527538/* ]]> */
    528539</script>
     
    531542/* <![CDATA[ */
    532543scriptEventLog.push( "async-with-blocking-dependency: after inline" )
     544//# sourceURL=async-with-blocking-dependency-js-after
    533545/* ]]> */
    534546</script>
     
    559571/* <![CDATA[ */
    560572scriptEventLog.push( "async-no-dependency: before inline" )
     573//# sourceURL=async-no-dependency-js-before
    561574/* ]]> */
    562575</script>
     
    565578/* <![CDATA[ */
    566579scriptEventLog.push( "async-no-dependency: after inline" )
     580//# sourceURL=async-no-dependency-js-after
    567581/* ]]> */
    568582</script>
     
    570584/* <![CDATA[ */
    571585scriptEventLog.push( "async-one-async-dependency: before inline" )
     586//# sourceURL=async-one-async-dependency-js-before
    572587/* ]]> */
    573588</script>
     
    576591/* <![CDATA[ */
    577592scriptEventLog.push( "async-one-async-dependency: after inline" )
     593//# sourceURL=async-one-async-dependency-js-after
    578594/* ]]> */
    579595</script>
     
    581597/* <![CDATA[ */
    582598scriptEventLog.push( "async-two-async-dependencies: before inline" )
     599//# sourceURL=async-two-async-dependencies-js-before
    583600/* ]]> */
    584601</script>
     
    587604/* <![CDATA[ */
    588605scriptEventLog.push( "async-two-async-dependencies: after inline" )
     606//# sourceURL=async-two-async-dependencies-js-after
    589607/* ]]> */
    590608</script>
     
    607625/* <![CDATA[ */
    608626scriptEventLog.push( "async-with-blocking-dependent: before inline" )
     627//# sourceURL=async-with-blocking-dependent-js-before
    609628/* ]]> */
    610629</script>
     
    613632/* <![CDATA[ */
    614633scriptEventLog.push( "async-with-blocking-dependent: after inline" )
     634//# sourceURL=async-with-blocking-dependent-js-after
    615635/* ]]> */
    616636</script>
     
    618638/* <![CDATA[ */
    619639scriptEventLog.push( "blocking-dependent-of-async: before inline" )
     640//# sourceURL=blocking-dependent-of-async-js-before
    620641/* ]]> */
    621642</script>
     
    624645/* <![CDATA[ */
    625646scriptEventLog.push( "blocking-dependent-of-async: after inline" )
     647//# sourceURL=blocking-dependent-of-async-js-after
    626648/* ]]> */
    627649</script>
     
    644666/* <![CDATA[ */
    645667scriptEventLog.push( "async-with-defer-dependent: before inline" )
     668//# sourceURL=async-with-defer-dependent-js-before
    646669/* ]]> */
    647670</script>
     
    650673/* <![CDATA[ */
    651674scriptEventLog.push( "async-with-defer-dependent: after inline" )
     675//# sourceURL=async-with-defer-dependent-js-after
    652676/* ]]> */
    653677</script>
     
    655679/* <![CDATA[ */
    656680scriptEventLog.push( "defer-dependent-of-async: before inline" )
     681//# sourceURL=defer-dependent-of-async-js-before
    657682/* ]]> */
    658683</script>
     
    661686/* <![CDATA[ */
    662687scriptEventLog.push( "defer-dependent-of-async: after inline" )
     688//# sourceURL=defer-dependent-of-async-js-after
    663689/* ]]> */
    664690</script>
     
    684710/* <![CDATA[ */
    685711scriptEventLog.push( "blocking-bundle-of-none: before inline" )
     712//# sourceURL=blocking-bundle-of-none-js-before
    686713/* ]]> */
    687714</script>
     
    689716/* <![CDATA[ */
    690717scriptEventLog.push( "blocking-bundle-of-none: after inline" )
     718//# sourceURL=blocking-bundle-of-none-js-after
    691719/* ]]> */
    692720</script>
     
    694722/* <![CDATA[ */
    695723scriptEventLog.push( "defer-dependent-of-blocking-bundle-of-none: before inline" )
     724//# sourceURL=defer-dependent-of-blocking-bundle-of-none-js-before
    696725/* ]]> */
    697726</script>
     
    700729/* <![CDATA[ */
    701730scriptEventLog.push( "defer-dependent-of-blocking-bundle-of-none: after inline" )
     731//# sourceURL=defer-dependent-of-blocking-bundle-of-none-js-after
    702732/* ]]> */
    703733</script>
     
    726756/* <![CDATA[ */
    727757scriptEventLog.push( "blocking-bundle-member-one: before inline" )
     758//# sourceURL=blocking-bundle-member-one-js-before
    728759/* ]]> */
    729760</script>
     
    732763/* <![CDATA[ */
    733764scriptEventLog.push( "blocking-bundle-member-one: after inline" )
     765//# sourceURL=blocking-bundle-member-one-js-after
    734766/* ]]> */
    735767</script>
     
    737769/* <![CDATA[ */
    738770scriptEventLog.push( "blocking-bundle-member-two: before inline" )
     771//# sourceURL=blocking-bundle-member-two-js-before
    739772/* ]]> */
    740773</script>
     
    743776/* <![CDATA[ */
    744777scriptEventLog.push( "blocking-bundle-member-two: after inline" )
     778//# sourceURL=blocking-bundle-member-two-js-after
    745779/* ]]> */
    746780</script>
     
    748782/* <![CDATA[ */
    749783scriptEventLog.push( "defer-dependent-of-blocking-bundle-of-two: before inline" )
     784//# sourceURL=defer-dependent-of-blocking-bundle-of-two-js-before
    750785/* ]]> */
    751786</script>
     
    754789/* <![CDATA[ */
    755790scriptEventLog.push( "defer-dependent-of-blocking-bundle-of-two: after inline" )
     791//# sourceURL=defer-dependent-of-blocking-bundle-of-two-js-after
    756792/* ]]> */
    757793</script>
     
    779815/* <![CDATA[ */
    780816scriptEventLog.push( "defer-bundle-of-none: before inline" )
     817//# sourceURL=defer-bundle-of-none-js-before
    781818/* ]]> */
    782819</script>
     
    784821/* <![CDATA[ */
    785822scriptEventLog.push( "defer-bundle-of-none: after inline" )
     823//# sourceURL=defer-bundle-of-none-js-after
    786824/* ]]> */
    787825</script>
     
    789827/* <![CDATA[ */
    790828scriptEventLog.push( "defer-dependent-of-defer-bundle-of-none: before inline" )
     829//# sourceURL=defer-dependent-of-defer-bundle-of-none-js-before
    791830/* ]]> */
    792831</script>
     
    795834/* <![CDATA[ */
    796835scriptEventLog.push( "defer-dependent-of-defer-bundle-of-none: after inline" )
     836//# sourceURL=defer-dependent-of-defer-bundle-of-none-js-after
    797837/* ]]> */
    798838</script>
     
    818858/* <![CDATA[ */
    819859scriptEventLog.push( "blocking-dependency-with-defer-following-dependency: before inline" )
     860//# sourceURL=blocking-dependency-with-defer-following-dependency-js-before
    820861/* ]]> */
    821862</script>
     
    824865/* <![CDATA[ */
    825866scriptEventLog.push( "blocking-dependency-with-defer-following-dependency: after inline" )
     867//# sourceURL=blocking-dependency-with-defer-following-dependency-js-after
    826868/* ]]> */
    827869</script>
     
    829871/* <![CDATA[ */
    830872scriptEventLog.push( "defer-dependency-with-blocking-preceding-dependency: before inline" )
     873//# sourceURL=defer-dependency-with-blocking-preceding-dependency-js-before
    831874/* ]]> */
    832875</script>
     
    835878/* <![CDATA[ */
    836879scriptEventLog.push( "defer-dependency-with-blocking-preceding-dependency: after inline" )
     880//# sourceURL=defer-dependency-with-blocking-preceding-dependency-js-after
    837881/* ]]> */
    838882</script>
     
    840884/* <![CDATA[ */
    841885scriptEventLog.push( "defer-dependent-of-blocking-and-defer-dependencies: before inline" )
     886//# sourceURL=defer-dependent-of-blocking-and-defer-dependencies-js-before
    842887/* ]]> */
    843888</script>
     
    846891/* <![CDATA[ */
    847892scriptEventLog.push( "defer-dependent-of-blocking-and-defer-dependencies: after inline" )
     893//# sourceURL=defer-dependent-of-blocking-and-defer-dependencies-js-after
    848894/* ]]> */
    849895</script>
     
    869915/* <![CDATA[ */
    870916scriptEventLog.push( "defer-dependency-with-blocking-following-dependency: before inline" )
     917//# sourceURL=defer-dependency-with-blocking-following-dependency-js-before
    871918/* ]]> */
    872919</script>
     
    875922/* <![CDATA[ */
    876923scriptEventLog.push( "defer-dependency-with-blocking-following-dependency: after inline" )
     924//# sourceURL=defer-dependency-with-blocking-following-dependency-js-after
    877925/* ]]> */
    878926</script>
     
    880928/* <![CDATA[ */
    881929scriptEventLog.push( "blocking-dependency-with-defer-preceding-dependency: before inline" )
     930//# sourceURL=blocking-dependency-with-defer-preceding-dependency-js-before
    882931/* ]]> */
    883932</script>
     
    886935/* <![CDATA[ */
    887936scriptEventLog.push( "blocking-dependency-with-defer-preceding-dependency: after inline" )
     937//# sourceURL=blocking-dependency-with-defer-preceding-dependency-js-after
    888938/* ]]> */
    889939</script>
     
    891941/* <![CDATA[ */
    892942scriptEventLog.push( "defer-dependent-of-defer-and-blocking-dependencies: before inline" )
     943//# sourceURL=defer-dependent-of-defer-and-blocking-dependencies-js-before
    893944/* ]]> */
    894945</script>
     
    897948/* <![CDATA[ */
    898949scriptEventLog.push( "defer-dependent-of-defer-and-blocking-dependencies: after inline" )
     950//# sourceURL=defer-dependent-of-defer-and-blocking-dependencies-js-after
    899951/* ]]> */
    900952</script>
     
    917969/* <![CDATA[ */
    918970scriptEventLog.push( "defer-with-async-dependent: before inline" )
     971//# sourceURL=defer-with-async-dependent-js-before
    919972/* ]]> */
    920973</script>
     
    923976/* <![CDATA[ */
    924977scriptEventLog.push( "defer-with-async-dependent: after inline" )
     978//# sourceURL=defer-with-async-dependent-js-after
    925979/* ]]> */
    926980</script>
     
    928982/* <![CDATA[ */
    929983scriptEventLog.push( "async-dependent-of-defer: before inline" )
     984//# sourceURL=async-dependent-of-defer-js-before
    930985/* ]]> */
    931986</script>
     
    934989/* <![CDATA[ */
    935990scriptEventLog.push( "async-dependent-of-defer: after inline" )
     991//# sourceURL=async-dependent-of-defer-js-after
    936992/* ]]> */
    937993</script>
     
    9501006/* <![CDATA[ */
    9511007scriptEventLog.push( "defer-with-before-inline: before inline" )
     1008//# sourceURL=defer-with-before-inline-js-before
    9521009/* ]]> */
    9531010</script>
     
    9681025/* <![CDATA[ */
    9691026scriptEventLog.push( "defer-with-after-inline: after inline" )
     1027//# sourceURL=defer-with-after-inline-js-after
    9701028/* ]]> */
    9711029</script>
     
    10151073/* <![CDATA[ */
    10161074scriptEventLog.push( "defer-dependent-of-nested-aliases: before inline" )
     1075//# sourceURL=defer-dependent-of-nested-aliases-js-before
    10171076/* ]]> */
    10181077</script>
     
    10211080/* <![CDATA[ */
    10221081scriptEventLog.push( "defer-dependent-of-nested-aliases: after inline" )
     1082//# sourceURL=defer-dependent-of-nested-aliases-js-after
    10231083/* ]]> */
    10241084</script>
     
    15621622        global $wp_scripts, $concatenate_scripts, $wp_version;
    15631623
    1564         $old_value           = $concatenate_scripts;
    15651624        $concatenate_scripts = true;
    15661625
     
    15761635        $print_scripts = get_echo( '_print_scripts' );
    15771636
    1578         // Reset global before asserting.
    1579         $concatenate_scripts = $old_value;
    1580 
    15811637        $expected  = "<script type='text/javascript' src='/wp-admin/load-scripts.php?c=0&amp;load%5Bchunk_0%5D=one-concat-dep,two-concat-dep,three-concat-dep&amp;ver={$wp_version}'></script>\n";
    15821638        $expected .= "<script type='text/javascript' src='/main-script.js' id='main-defer-script-js' defer='defer' data-wp-strategy='defer'></script>\n";
     
    15971653        global $wp_scripts, $concatenate_scripts, $wp_version;
    15981654
    1599         $old_value           = $concatenate_scripts;
    16001655        $concatenate_scripts = true;
    16011656
     
    16111666        $print_scripts = get_echo( '_print_scripts' );
    16121667
    1613         // Reset global before asserting.
    1614         $concatenate_scripts = $old_value;
    1615 
    16161668        $expected  = "<script type='text/javascript' src='/wp-admin/load-scripts.php?c=0&amp;load%5Bchunk_0%5D=one-concat-dep-1,two-concat-dep-1,three-concat-dep-1&amp;ver={$wp_version}'></script>\n";
    16171669        $expected .= "<script type='text/javascript' src='/main-script.js' id='main-async-script-1-js' async='async' data-wp-strategy='async'></script>\n";
     
    16331685        global $wp_scripts, $concatenate_scripts, $wp_version;
    16341686
    1635         $old_value           = $concatenate_scripts;
    16361687        $concatenate_scripts = true;
    16371688
     
    16501701        $print_scripts = get_echo( '_print_scripts' );
    16511702
    1652         // Reset global before asserting.
    1653         $concatenate_scripts = $old_value;
    1654 
    16551703        $expected  = "<script type='text/javascript' src='/wp-admin/load-scripts.php?c=0&amp;load%5Bchunk_0%5D=one-concat-dep-2,two-concat-dep-2,three-concat-dep-2,four-concat-dep-2,five-concat-dep-2,six-concat-dep-2&amp;ver={$wp_version}'></script>\n";
    16561704        $expected .= "<script type='text/javascript' src='/main-script.js' id='deferred-script-2-js' defer='defer' data-wp-strategy='defer'></script>\n";
     
    17521800        wp_enqueue_script( 'test-only-data', 'example.com', array(), null );
    17531801        wp_script_add_data( 'test-only-data', 'data', 'testing' );
    1754         $expected  = "<script type='text/javascript' id='test-only-data-js-extra'>\n/* <![CDATA[ */\ntesting\n/* ]]> */\n</script>\n";
     1802        $expected  = "<script type='text/javascript' id='test-only-data-js-extra'>\n/* <![CDATA[ */\ntesting\n//# sourceURL=test-only-data-js-extra\n/* ]]> */\n</script>\n";
    17551803        $expected .= "<script type='text/javascript' src='http://example.com' id='test-only-data-js'></script>\n";
    17561804
     
    17901838        wp_script_add_data( 'test-conditional-with-data', 'data', 'testing' );
    17911839        wp_script_add_data( 'test-conditional-with-data', 'conditional', 'lt IE 9' );
    1792         $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";
     1840        $expected  = "<!--[if lt IE 9]>\n<script type='text/javascript' id='test-conditional-with-data-js-extra'>\n/* <![CDATA[ */\ntesting\n//# sourceURL=test-conditional-with-data-js-extra\n/* ]]> */\n</script>\n<![endif]-->\n";
    17931841        $expected .= "<!--[if lt IE 9]>\n<script type='text/javascript' src='http://example.com' id='test-conditional-with-data-js'></script>\n<![endif]-->\n";
    17941842        $expected  = str_replace( "'", '"', $expected );
     
    20142062/* <![CDATA[ */
    20152063console.log("before");
     2064//# sourceURL=test-example-js-before
    20162065/* ]]> */
    20172066</script>
     
    20342083/* <![CDATA[ */
    20352084console.log("after");
     2085//# sourceURL=test-example-js-after
    20362086/* ]]> */
    20372087</script>
     
    20492099        wp_add_inline_script( 'test-example', 'console.log("after");' );
    20502100
    2051         $expected  = "<script type='text/javascript' id='test-example-js-before'>\n/* <![CDATA[ */\nconsole.log(\"before\");\n/* ]]> */\n</script>\n";
     2101        $expected  = "<script type='text/javascript' id='test-example-js-before'>\n/* <![CDATA[ */\nconsole.log(\"before\");\n//# sourceURL=test-example-js-before\n/* ]]> */\n</script>\n";
    20522102        $expected .= "<script type='text/javascript' src='http://example.com' id='test-example-js'></script>\n";
    2053         $expected .= "<script type='text/javascript' id='test-example-js-after'>\n/* <![CDATA[ */\nconsole.log(\"after\");\n/* ]]> */\n</script>\n";
     2103        $expected .= "<script type='text/javascript' id='test-example-js-after'>\n/* <![CDATA[ */\nconsole.log(\"after\");\n//# sourceURL=test-example-js-after\n/* ]]> */\n</script>\n";
    20542104
    20552105        $this->assertEqualHTML( $expected, get_echo( 'wp_print_scripts' ) );
     
    20642114        wp_add_inline_script( 'test-example', 'console.log("before");', 'before' );
    20652115
    2066         $expected = "<script type='text/javascript' id='test-example-js-before'>\n/* <![CDATA[ */\nconsole.log(\"before\");\n/* ]]> */\n</script>\n";
     2116        $expected = "<script type='text/javascript' id='test-example-js-before'>\n/* <![CDATA[ */\nconsole.log(\"before\");\n//# sourceURL=test-example-js-before\n/* ]]> */\n</script>\n";
    20672117
    20682118        $this->assertEqualHTML( $expected, get_echo( 'wp_print_scripts' ) );
     
    20772127        wp_add_inline_script( 'test-example', 'console.log("after");' );
    20782128
    2079         $expected = "<script type='text/javascript' id='test-example-js-after'>\n/* <![CDATA[ */\nconsole.log(\"after\");\n/* ]]> */\n</script>\n";
     2129        $expected = "<script type='text/javascript' id='test-example-js-after'>\n/* <![CDATA[ */\nconsole.log(\"after\");\n//# sourceURL=test-example-js-after\n/* ]]> */\n</script>\n";
    20802130
    20812131        $this->assertEqualHTML( $expected, get_echo( 'wp_print_scripts' ) );
     
    20912141        wp_add_inline_script( 'test-example', 'console.log("after");' );
    20922142
    2093         $expected  = "<script type='text/javascript' id='test-example-js-before'>\n/* <![CDATA[ */\nconsole.log(\"before\");\n/* ]]> */\n</script>\n";
    2094         $expected .= "<script type='text/javascript' id='test-example-js-after'>\n/* <![CDATA[ */\nconsole.log(\"after\");\n/* ]]> */\n</script>\n";
     2143        $expected  = "<script type='text/javascript' id='test-example-js-before'>\n/* <![CDATA[ */\nconsole.log(\"before\");\n//# sourceURL=test-example-js-before\n/* ]]> */\n</script>\n";
     2144        $expected .= "<script type='text/javascript' id='test-example-js-after'>\n/* <![CDATA[ */\nconsole.log(\"after\");\n//# sourceURL=test-example-js-after\n/* ]]> */\n</script>\n";
    20952145
    20962146        $this->assertEqualHTML( $expected, get_echo( 'wp_print_scripts' ) );
     
    21072157        wp_add_inline_script( 'test-example', 'console.log("after");' );
    21082158
    2109         $expected  = "<script type='text/javascript' id='test-example-js-before'>\n/* <![CDATA[ */\nconsole.log(\"before\");\nconsole.log(\"before\");\n/* ]]> */\n</script>\n";
     2159        $expected  = "<script type='text/javascript' id='test-example-js-before'>\n/* <![CDATA[ */\nconsole.log(\"before\");\nconsole.log(\"before\");\n//# sourceURL=test-example-js-before\n/* ]]> */\n</script>\n";
    21102160        $expected .= "<script type='text/javascript' src='http://example.com' id='test-example-js'></script>\n";
    2111         $expected .= "<script type='text/javascript' id='test-example-js-after'>\n/* <![CDATA[ */\nconsole.log(\"after\");\nconsole.log(\"after\");\n/* ]]> */\n</script>\n";
     2161        $expected .= "<script type='text/javascript' id='test-example-js-after'>\n/* <![CDATA[ */\nconsole.log(\"after\");\nconsole.log(\"after\");\n//# sourceURL=test-example-js-after\n/* ]]> */\n</script>\n";
    21122162
    21132163        $this->assertEqualHTML( $expected, get_echo( 'wp_print_scripts' ) );
     
    21232173        wp_add_inline_script( 'test-example', 'console.log("after");' );
    21242174
    2125         $expected  = "<script type='text/javascript' id='test-example-js-extra'>\n/* <![CDATA[ */\nvar testExample = {\"foo\":\"bar\"};\n/* ]]> */\n</script>\n";
    2126         $expected .= "<script type='text/javascript' id='test-example-js-before'>\n/* <![CDATA[ */\nconsole.log(\"before\");\n/* ]]> */\n</script>\n";
     2175        $expected  = "<script type='text/javascript' id='test-example-js-extra'>\n/* <![CDATA[ */\nvar testExample = {\"foo\":\"bar\"};\n//# sourceURL=test-example-js-extra\n/* ]]> */\n</script>\n";
     2176        $expected .= "<script type='text/javascript' id='test-example-js-before'>\n/* <![CDATA[ */\nconsole.log(\"before\");\n//# sourceURL=test-example-js-before\n/* ]]> */\n</script>\n";
    21272177        $expected .= "<script type='text/javascript' src='http://example.com' id='test-example-js'></script>\n";
    2128         $expected .= "<script type='text/javascript' id='test-example-js-after'>\n/* <![CDATA[ */\nconsole.log(\"after\");\n/* ]]> */\n</script>\n";
     2178        $expected .= "<script type='text/javascript' id='test-example-js-after'>\n/* <![CDATA[ */\nconsole.log(\"after\");\n//# sourceURL=test-example-js-after\n/* ]]> */\n</script>\n";
    21292179
    21302180        $this->assertEqualHTML( $expected, get_echo( 'wp_print_scripts' ) );
     
    21472197        wp_add_inline_script( 'two', 'console.log("before two");', 'before' );
    21482198
    2149         $expected  = "<script type='text/javascript' id='one-js-before'>\n/* <![CDATA[ */\nconsole.log(\"before one\");\n/* ]]> */\n</script>\n";
     2199        $expected  = "<script type='text/javascript' id='one-js-before'>\n/* <![CDATA[ */\nconsole.log(\"before one\");\n//# sourceURL=one-js-before\n/* ]]> */\n</script>\n";
    21502200        $expected .= "<script type='text/javascript' src='{$this->default_scripts_dir}one.js?ver={$wp_version}' id='one-js'></script>\n";
    2151         $expected .= "<script type='text/javascript' id='two-js-before'>\n/* <![CDATA[ */\nconsole.log(\"before two\");\n/* ]]> */\n</script>\n";
     2201        $expected .= "<script type='text/javascript' id='two-js-before'>\n/* <![CDATA[ */\nconsole.log(\"before two\");\n//# sourceURL=two-js-before\n/* ]]> */\n</script>\n";
    21522202        $expected .= "<script type='text/javascript' src='{$this->default_scripts_dir}two.js?ver={$wp_version}' id='two-js'></script>\n";
    21532203        $expected .= "<script type='text/javascript' src='{$this->default_scripts_dir}three.js?ver={$wp_version}' id='three-js'></script>\n";
     
    21712221        wp_add_inline_script( 'one', 'console.log("before one");', 'before' );
    21722222
    2173         $expected  = "<script type='text/javascript' id='one-js-before'>\n/* <![CDATA[ */\nconsole.log(\"before one\");\n/* ]]> */\n</script>\n";
     2223        $expected  = "<script type='text/javascript' id='one-js-before'>\n/* <![CDATA[ */\nconsole.log(\"before one\");\n//# sourceURL=one-js-before\n/* ]]> */\n</script>\n";
    21742224        $expected .= "<script type='text/javascript' src='{$this->default_scripts_dir}one.js?ver={$wp_version}' id='one-js'></script>\n";
    21752225        $expected .= "<script type='text/javascript' src='{$this->default_scripts_dir}two.js?ver={$wp_version}' id='two-js'></script>\n";
     
    21982248        $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";
    21992249        $expected .= "<script type='text/javascript' src='{$this->default_scripts_dir}two.js?ver={$wp_version}' id='two-js'></script>\n";
    2200         $expected .= "<script type='text/javascript' id='two-js-after'>\n/* <![CDATA[ */\nconsole.log(\"after two\");\n/* ]]> */\n</script>\n";
     2250        $expected .= "<script type='text/javascript' id='two-js-after'>\n/* <![CDATA[ */\nconsole.log(\"after two\");\n//# sourceURL=two-js-after\n/* ]]> */\n</script>\n";
    22012251        $expected .= "<script type='text/javascript' src='{$this->default_scripts_dir}three.js?ver={$wp_version}' id='three-js'></script>\n";
    2202         $expected .= "<script type='text/javascript' id='three-js-after'>\n/* <![CDATA[ */\nconsole.log(\"after three\");\n/* ]]> */\n</script>\n";
     2252        $expected .= "<script type='text/javascript' id='three-js-after'>\n/* <![CDATA[ */\nconsole.log(\"after three\");\n//# sourceURL=three-js-after\n/* ]]> */\n</script>\n";
    22032253        $expected .= "<script type='text/javascript' src='{$this->default_scripts_dir}four.js?ver={$wp_version}' id='four-js'></script>\n";
    22042254
     
    22212271
    22222272        $expected  = "<!--[if gte IE 9]>\n";
    2223         $expected .= "<script type='text/javascript' id='test-example-js-before'>\n/* <![CDATA[ */\nconsole.log(\"before\");\n/* ]]> */\n</script>\n";
     2273        $expected .= "<script type='text/javascript' id='test-example-js-before'>\n/* <![CDATA[ */\nconsole.log(\"before\");\n//# sourceURL=test-example-js-before\n/* ]]> */\n</script>\n";
    22242274        $expected .= "<script type='text/javascript' src='http://example.com' id='test-example-js'></script>\n";
    2225         $expected .= "<script type='text/javascript' id='test-example-js-after'>\n/* <![CDATA[ */\nconsole.log(\"after\");\n/* ]]> */\n</script>\n";
     2275        $expected .= "<script type='text/javascript' id='test-example-js-after'>\n/* <![CDATA[ */\nconsole.log(\"after\");\n//# sourceURL=test-example-js-after\n/* ]]> */\n</script>\n";
    22262276        $expected .= "<![endif]-->\n";
    22272277        $expected  = str_replace( "'", '"', $expected );
     
    22512301        $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";
    22522302        $expected .= "<script type='text/javascript' src='http://example.com' id='test-example-js'></script>\n";
    2253         $expected .= "<script type='text/javascript' id='test-example-js-after'>\n/* <![CDATA[ */\nconsole.log(\"after\");\n/* ]]> */\n</script>\n";
     2303        $expected .= "<script type='text/javascript' id='test-example-js-after'>\n/* <![CDATA[ */\nconsole.log(\"after\");\n//# sourceURL=test-example-js-after\n/* ]]> */\n</script>\n";
    22542304
    22552305        wp_enqueue_script( 'test-example', 'http://example.com', array( 'jquery' ), null );
     
    22762326        $expected .= "<!--[if gte IE 9]>\n";
    22772327        $expected .= "<script type=\"text/javascript\" src=\"http://example.com\" id=\"test-example-js\"></script>\n";
    2278         $expected .= "<script type=\"text/javascript\" id=\"test-example-js-after\">\n/* <![CDATA[ */\nconsole.log(\"after\");\n/* ]]> */\n</script>\n";
     2328        $expected .= "<script type=\"text/javascript\" id=\"test-example-js-after\">\n/* <![CDATA[ */\nconsole.log(\"after\");\n//# sourceURL=test-example-js-after\n/* ]]> */\n</script>\n";
    22792329        $expected .= "<![endif]-->\n";
    22802330
     
    23022352
    23032353        $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";
    2304         $expected .= "<script type='text/javascript' id='test-example-js-before'>\n/* <![CDATA[ */\nconsole.log(\"before\");\n/* ]]> */\n</script>\n";
     2354        $expected .= "<script type='text/javascript' id='test-example-js-before'>\n/* <![CDATA[ */\nconsole.log(\"before\");\n//# sourceURL=test-example-js-before\n/* ]]> */\n</script>\n";
    23052355        $expected .= "<script type='text/javascript' src='http://example.com' id='test-example-js'></script>\n";
    23062356
     
    23272377
    23282378        $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";
    2329         $expected .= "<script type='text/javascript' id='test-example-js-before'>\n/* <![CDATA[ */\nconsole.log(\"before\");\n/* ]]> */\n</script>\n";
     2379        $expected .= "<script type='text/javascript' id='test-example-js-before'>\n";
     2380        $expected .= "/* <![CDATA[ */\nconsole.log(\"before\");\n//# sourceURL=test-example-js-before\n/* ]]> */\n";
     2381        $expected .= "</script>\n";
    23302382        $expected .= "<script type='text/javascript' src='http://example.com' id='test-example-js'></script>\n";
    23312383        $expected .= "<script type='text/javascript' src='/wp-includes/js/dist/i18n.min.js' id='wp-i18n-js'></script>\n";
     
    23332385        $expected .= "/* <![CDATA[ */\n";
    23342386        $expected .= "wp.i18n.setLocaleData( { 'text direction\u0004ltr': [ 'ltr' ] } );\n";
     2387        $expected .= "//# sourceURL=wp-i18n-js-after\n";
    23352388        $expected .= "/* ]]> */\n";
    23362389        $expected .= "</script>\n";
    23372390        $expected .= "<script type='text/javascript' src='/wp-includes/js/dist/a11y.min.js' id='wp-a11y-js'></script>\n";
    23382391        $expected .= "<script type='text/javascript' src='http://example2.com' id='test-example2-js'></script>\n";
    2339         $expected .= "<script type='text/javascript' id='test-example2-js-after'>\n/* <![CDATA[ */\nconsole.log(\"after\");\n/* ]]> */\n</script>\n";
    2340 
     2392        $expected .= "<script type='text/javascript' id='test-example2-js-after'>\n/* <![CDATA[ */\nconsole.log(\"after\");\n//# sourceURL=test-example2-js-after\n/* ]]> */\n</script>\n";
    23412393        wp_enqueue_script( 'test-example', 'http://example.com', array( 'jquery' ), null );
    23422394        wp_add_inline_script( 'test-example', 'console.log("before");', 'before' );
     
    23822434        $expected_tail .= "/* <![CDATA[ */\n";
    23832435        $expected_tail .= "tryCustomizeDependency()\n";
     2436        $expected_tail .= "//# sourceURL=customize-dependency-js-after\n";
    23842437        $expected_tail .= "/* ]]> */\n";
    23852438        $expected_tail .= "</script>\n";
     
    24172470
    24182471        $expected  = "<script type='text/javascript' src='/wp-includes/js/script.js?ver={$wp_version}' id='one-js'></script>\n";
    2419         $expected .= "<script type='text/javascript' id='one-js-after'>\n/* <![CDATA[ */\nconsole.log(\"after one\");\n/* ]]> */\n</script>\n";
     2472        $expected .= "<script type='text/javascript' id='one-js-after'>\n/* <![CDATA[ */\nconsole.log(\"after one\");\n//# sourceURL=one-js-after\n/* ]]> */\n</script>\n";
    24202473        $expected .= "<script type='text/javascript' src='/wp-includes/js/script2.js?ver={$wp_version}' id='two-js'></script>\n";
    24212474        $expected .= "<script type='text/javascript' src='/wp-includes/js/script3.js?ver={$wp_version}' id='three-js'></script>\n";
     
    24412494
    24422495        $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";
    2443         $expected .= "<script type='text/javascript' id='three-js-before'>\n/* <![CDATA[ */\nconsole.log(\"before three\");\n/* ]]> */\n</script>\n";
     2496        $expected .= "<script type='text/javascript' id='three-js-before'>\n/* <![CDATA[ */\nconsole.log(\"before three\");\n//# sourceURL=three-js-before\n/* ]]> */\n</script>\n";
    24442497        $expected .= "<script type='text/javascript' src='/wp-includes/js/script3.js?ver={$wp_version}' id='three-js'></script>\n";
    24452498        $expected .= "<script type='text/javascript' src='/wp-includes/js/script4.js?ver={$wp_version}' id='four-js'></script>\n";
     
    24612514                ),
    24622515                'delayed'        => false,
    2463                 'expected_data'  => '/*before foo 1*/',
    2464                 'expected_tag'   => "<script id='foo-js-before' type='text/javascript'>\n/* <![CDATA[ */\n/*before foo 1*/\n/* ]]> */\n</script>\n",
     2516                'expected_data'  => "/*before foo 1*/\n//# sourceURL=foo-js-before",
     2517                'expected_tag'   => "<script id='foo-js-before' type='text/javascript'>\n/* <![CDATA[ */\n/*before foo 1*/\n//# sourceURL=foo-js-before\n/* ]]> */\n</script>\n",
    24652518            ),
    24662519            'after-blocking'  => array(
     
    24712524                ),
    24722525                'delayed'        => false,
    2473                 'expected_data'  => "/*after foo 1*/\n/*after foo 2*/",
    2474                 'expected_tag'   => "<script id='foo-js-after' type='text/javascript'>\n/* <![CDATA[ */\n/*after foo 1*/\n/*after foo 2*/\n/* ]]> */\n</script>\n",
     2526                'expected_data'  => "/*after foo 1*/\n/*after foo 2*/\n//# sourceURL=foo-js-after",
     2527                'expected_tag'   => "<script id='foo-js-after' type='text/javascript'>\n/* <![CDATA[ */\n/*after foo 1*/\n/*after foo 2*/\n//# sourceURL=foo-js-after\n/* ]]> */\n</script>\n",
    24752528            ),
    24762529            'before-delayed'  => array(
     
    24802533                ),
    24812534                'delayed'        => true,
    2482                 'expected_data'  => '/*before foo 1*/',
    2483                 'expected_tag'   => "<script id='foo-js-before' type='text/javascript'>\n/* <![CDATA[ */\n/*before foo 1*/\n/* ]]> */\n</script>\n",
     2535                'expected_data'  => "/*before foo 1*/\n//# sourceURL=foo-js-before",
     2536                'expected_tag'   => "<script id='foo-js-before' type='text/javascript'>\n/* <![CDATA[ */\n/*before foo 1*/\n//# sourceURL=foo-js-before\n/* ]]> */\n</script>\n",
    24842537            ),
    24852538            'after-delayed'   => array(
     
    24902543                ),
    24912544                'delayed'        => true,
    2492                 'expected_data'  => "/*after foo 1*/\n/*after foo 2*/",
    2493                 'expected_tag'   => "<script id='foo-js-after' type='text/javascript'>\n/* <![CDATA[ */\n/*after foo 1*/\n/*after foo 2*/\n/* ]]> */\n</script>\n",
     2545                'expected_data'  => "/*after foo 1*/\n/*after foo 2*/\n//# sourceURL=foo-js-after",
     2546                'expected_tag'   => "<script id='foo-js-after' type='text/javascript'>\n/* <![CDATA[ */\n/*after foo 1*/\n/*after foo 2*/\n//# sourceURL=foo-js-after\n/* ]]> */\n</script>\n",
    24942547            ),
    24952548        );
     
    31333186        wp_localize_script( 'test-example', 'testExample', $l10n_data );
    31343187
    3135         $expected  = "<script type='text/javascript' id='test-example-js-extra'>\n/* <![CDATA[ */\nvar testExample = {$expected};\n/* ]]> */\n</script>\n";
     3188        $expected  = "<script type='text/javascript' id='test-example-js-extra'>\n/* <![CDATA[ */\nvar testExample = {$expected};\n//# sourceURL=test-example-js-extra\n/* ]]> */\n</script>\n";
    31363189        $expected .= "<script type='text/javascript' src='http://example.com' id='test-example-js'></script>\n";
    31373190
     
    37023755        return $data['dependencies'];
    37033756    }
     3757
     3758    /**
     3759     * @ticket 63887
     3760     */
     3761    public function test_source_url_encoding() {
     3762        $this->add_html5_script_theme_support();
     3763
     3764        $handle = '# test/</script> #';
     3765
     3766        wp_enqueue_script( $handle, '/example.js', array(), '0.0' );
     3767        wp_add_inline_script( $handle, '"before";', 'before' );
     3768        wp_add_inline_script( $handle, '"after";' );
     3769        wp_localize_script( $handle, 'test', array() );
     3770
     3771        $expected = <<<HTML
     3772<script id="# test/</script> #-js-extra">
     3773var test = [];
     3774//# sourceURL=%23%20test%2F%3C%2Fscript%3E%20%23-js-extra
     3775</script>
     3776<script id="# test/</script> #-js-before">
     3777"before";
     3778//# sourceURL=%23%20test%2F%3C%2Fscript%3E%20%23-js-before
     3779</script>
     3780<script src="/example.js?ver=0.0" id="# test/</script> #-js"></script>
     3781<script id="# test/</script> #-js-after">
     3782"after";
     3783//# sourceURL=%23%20test%2F%3C%2Fscript%3E%20%23-js-after
     3784</script>
     3785
     3786HTML;
     3787
     3788        $this->assertEqualHTML( $expected, get_echo( 'wp_print_scripts' ) );
     3789    }
     3790
     3791    /**
     3792     * @ticket 63887
     3793     */
     3794    public function test_source_url_with_concat() {
     3795        global $wp_scripts, $concatenate_scripts, $wp_version;
     3796        $this->add_html5_script_theme_support();
     3797
     3798        $concatenate_scripts = true;
     3799
     3800        $wp_scripts->do_concat    = true;
     3801        $wp_scripts->default_dirs = array( $this->default_scripts_dir );
     3802
     3803        wp_enqueue_script( 'one', $this->default_scripts_dir . '1.js' );
     3804        wp_enqueue_script( 'two', $this->default_scripts_dir . '2.js' );
     3805        wp_localize_script( 'one', 'one', array( 'key' => 'val' ) );
     3806        wp_localize_script( 'two', 'two', array( 'key' => 'val' ) );
     3807
     3808        wp_print_scripts();
     3809        $print_scripts = get_echo( '_print_scripts' );
     3810
     3811        $expected = <<<HTML
     3812<script>
     3813/* <![CDATA[ */
     3814var one = {"key":"val"};var two = {"key":"val"};
     3815//# sourceURL=js-inline-concat-one%2Ctwo
     3816/* ]]> */
     3817</script>
     3818<script src="/wp-admin/load-scripts.php?c=0&load%5Bchunk_0%5D=one,two&ver={$wp_version}"></script>
     3819
     3820HTML;
     3821
     3822        $this->assertEqualHTML( $expected, $print_scripts );
     3823    }
    37043824}
  • trunk/tests/phpunit/tests/dependencies/styles.php

    r60690 r60719  
    151151        $expected .= "<style id='handle-inline-css' type='text/css'>\n";
    152152        $expected .= "$style\n";
     153        $expected .= "/*# sourceURL=handle-inline-css */\n";
    153154        $expected .= "</style>\n";
    154155
     
    167168     */
    168169    public function test_inline_styles_concat() {
    169 
    170170        global $wp_styles;
    171171
     
    275275        $expected .= "$style1\n";
    276276        $expected .= "$style2\n";
     277        $expected .= "/*# sourceURL=handle-inline-css */\n";
    277278        $expected .= "</style>\n";
    278279
     
    293294    public function test_plugin_doing_inline_styles_wrong() {
    294295
    295         $style  = "<style id='handle-inline-css' type='text/css'>\n";
    296         $style .= ".thing {\n";
     296        $style  = ".thing {\n";
    297297        $style .= "\tbackground: red;\n";
    298         $style .= "}\n";
    299         $style .= '</style>';
     298        $style .= '}';
    300299
    301300        $expected  = "<link rel='stylesheet' id='handle-css' href='http://example.com?ver=1' type='text/css' media='all' />\n";
     301        $expected .= "<style id='handle-inline-css' type='text/css'>\n";
    302302        $expected .= "$style\n";
     303        $expected .= "/*# sourceURL=handle-inline-css */\n";
     304        $expected .= "</style>\n";
    303305
    304306        wp_enqueue_style( 'handle', 'http://example.com', array(), 1 );
    305307
    306         wp_add_inline_style( 'handle', $style );
     308        wp_add_inline_style( 'handle', "<style>{$style}</style>" );
    307309
    308310        $this->assertSame( $expected, get_echo( 'wp_print_styles' ) );
     
    333335<style id='handle-inline-css' type='text/css'>
    334336a { color: blue; }
     337/*# sourceURL=handle-inline-css */
    335338</style>
    336339<![endif]-->
     
    364367        $expected .= "<style id='handle-three-inline-css' type='text/css'>\n";
    365368        $expected .= "$style\n";
     369        $expected .= "/*# sourceURL=handle-three-inline-css */\n";
    366370        $expected .= "</style>\n";
    367371
     
    633637        $this->assertSame( $GLOBALS['wp_styles']->registered['test-handle']->src, $url );
    634638    }
     639
     640    /**
     641     * @ticket 63887
     642     */
     643    public function test_source_url_encoding() {
     644        $handle = '# test/</style> #';
     645        wp_enqueue_style( $handle, '/example.css', array(), '0.0' );
     646        wp_add_inline_style( $handle, 'custom-el { content: "ok"; }' );
     647
     648        $expected = <<<HTML
     649<link rel='stylesheet' href="/example.css?ver=0.0" id="# test/</style> #-css" media="all" type="text/css">
     650<style id="# test/</style> #-inline-css" type="text/css">
     651custom-el { content: "ok"; }
     652/*# sourceURL=%23%20test%2F%3C%2Fstyle%3E%20%23-inline-css */
     653</style>
     654
     655HTML;
     656
     657        $this->assertEqualHTML( $expected, get_echo( 'wp_print_styles' ) );
     658    }
     659
     660    /**
     661     * @ticket 63887
     662     */
     663    public function test_source_url_with_concat() {
     664        global $wp_styles, $wp_version;
     665        add_theme_support( 'html5', array( 'style' ) );
     666
     667        $wp_styles->do_concat    = true;
     668        $wp_styles->default_dirs = array( '/wp-admin/' );
     669
     670        wp_enqueue_style( 'one', '/wp-admin/1.css' );
     671        wp_enqueue_style( 'two', '/wp-admin/2.css' );
     672        wp_add_inline_style( 'one', 'h1 { background: blue; }' );
     673        wp_add_inline_style( 'two', 'h2 { color: green; }' );
     674
     675        wp_print_styles();
     676        $printed = get_echo( '_print_styles' );
     677
     678        $expected = <<<HTML
     679<link
     680    rel="stylesheet"
     681    href="/wp-admin/load-styles.php?c=0&dir=ltr&load%5Bchunk_0%5D=one,two&ver={$wp_version}"
     682    media="all"
     683>
     684<style>
     685h1 { background: blue; }h2 { color: green; }
     686/*# sourceURL=css-inline-concat-one%2Ctwo */
     687</style>
     688HTML;
     689
     690        $this->assertEqualHTML( $expected, $printed );
     691    }
    635692}
  • trunk/tests/phpunit/tests/dependencies/wpLocalizeScript.php

    r60690 r60719  
    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=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.