Skip to content

[Bug]: <<<'JS' heredoc in blade file spoils syntax highlighting #82

@N1ebieski

Description

@N1ebieski
Contributor

Extension Version

0.1.12

PHP Binary

Docker

Operating System

Linux

What happened?

Before I used JS heredoc in blade file:

before

After I used JS heredoc in blade file:

after

Autocompletion also has stopped working in the lines below the place where I put the JS heredoc.

Mimimal Code Sample

No response

Activity

mikebronner

mikebronner commented on Dec 18, 2024

@mikebronner

what happens if you do the heredoc without quotes:

$test = <<<JS
    a = 5;
JS;
N1ebieski

N1ebieski commented on Dec 18, 2024

@N1ebieski
ContributorAuthor

The same:

without

N1ebieski

N1ebieski commented on Feb 24, 2025

@N1ebieski
ContributorAuthor

Heredocs are still not working in the "stable" 1.0.0 version :(

N1ebieski

N1ebieski commented on Mar 2, 2025

@N1ebieski
ContributorAuthor

Ok I found it. The problem is the end parameter for all of the heredoc_interior/nowdoc_interior patterns in the blade.tmLanguage.json.

There is a caret (start of string) in the regex:

"end": "^(\\2)\\b"

so any code in the heredoc/nowdoc in the blade files must have closing tag without any spaces/tabs before:

For example:

new ExampleClass(
    exampleParam: <<<'JS'
        console.log('test');
JS,
    nextParam: "some string"
)

instead:

new ExampleClass(
    exampleParam: <<<'JS'
        console.log('test');
    JS,
    nextParam: "some string"
)

In my optinion this is a bug because the PHP heredoc/nowdoc documentation says:

The closing identifier may be indented by space or tab, in which case the indentation will be stripped from all lines in the doc string. Prior to PHP 7.3.0, the closing identifier must begin in the first column of the line.

https://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc

I suggest changing the end parameter to:

"end": "^\\s*(\\2)\\b"

for all of the heredoc_interior/nowdoc_interior patterns

linked a pull request that will close this issue on Mar 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Development

    Participants

    @mikebronner@joetannenbaum@N1ebieski

    Issue actions

      [Bug]: <<<'JS' heredoc in blade file spoils syntax highlighting · Issue #82 · laravel/vs-code-extension