Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

javascript fails to format when <?php > is first text inside <script> tag #1687

Closed
bmewburn opened this issue Jul 12, 2019 · 1 comment · Fixed by #1690
Closed

javascript fails to format when <?php > is first text inside <script> tag #1687

bmewburn opened this issue Jul 12, 2019 · 1 comment · Fixed by #1690

Comments

@bmewburn
Copy link

Description

When templating is set to php, and a php tag immediately follows a script tag, then the javascript inside the block will fail to format. Placing a comment or any other js expression before the php tag will cause it to format correctly.

Input

The code looked like this before beautification:

<script>
    <?php ?>
    function
    _test(myVar)
    {
    $('.selector').picker({
    "a":
    true,
    "b":
    myVar
    });
    }
</script>

<script>
    // a comment
    <?php ?>
    function
    _test(myVar)
    {
    $('.selector').picker({
    "a":
    true,
    "b":
    myVar
    });
    }
</script>

Actual Output

The code actually looked like this after beautification:

<script>
    <?php ?>
    function
    _test(myVar)
    {
    $('.selector').picker({
    "a":
    true,
    "b":
    myVar
    });
    }
</script>

<script>
    // a comment
    <?php ?>

    function
    _test(myVar) {
        $('.selector').picker({
            "a": true,
            "b": myVar
        });
    }
</script>

Steps to Reproduce

var format = require('js-beautify');
var fs = require('fs');
var src = fs.readFileSync('./test.php').toString();
fs.writeFileSync('./formatted.php', format.html(src, { js: { templating: ['php'] } }));

Environment

OS: Linux

@bmewburn bmewburn changed the title If a php tag follows a script tag then the following javascript will fail to format If a php tag follows a script tag then javascript will fail to format Jul 12, 2019
@bitwiseman bitwiseman changed the title If a php tag follows a script tag then javascript will fail to format javascript will fails to format when <?php > is first text inside <script> tag Jul 16, 2019
@bitwiseman bitwiseman changed the title javascript will fails to format when <?php > is first text inside <script> tag javascript fails to format when <?php > is first text inside <script> tag Jul 16, 2019
@bitwiseman
Copy link
Member

Good catch, thank you.

Probably caused by the fix to #1641 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants