highlightjs / highlight.js

JavaScript syntax highlighter with language auto-detection and zero dependencies.
https://highlightjs.org/
BSD 3-Clause "New" or "Revised" License
23.3k stars 3.52k forks source link

(php) Semicolon inside string parsed as end of statement #4006

Open pkaminski opened 4 months ago

pkaminski commented 4 months ago

Describe the issue It looks like a semicolon inside a string is parsed as terminating the statement, at least sometimes.

Which language seems to have the issue? php

Are you using highlight or highlightAuto? highlight

Sample Code to Reproduce Fiddle here: https://jsfiddle.net/c3sLm2ga/. See how the highlighting gets messed up halfway through the string in the throw statement. Oddly, double-quoted strings are also affected but in a slightly different way.

Expected behavior

public static function mutate() {
  $result = null;
  DB::transaction(function () use (): void {
    if (static::$currentMutator !== null) {
      throw new LoggingMutatorException('LoggingMutator::mutate called while already in a mutation; nested mutations are not supported.');
    }
    $operationLogger = new OperationLogger($user);
  })
}
joshgoebel commented 4 months ago

Nothing to do with strings, this is broken from use because we're expecting that has special meaning and must be terminated by a ;:

Screen Shot 2024-03-01 at 6 05 45 PM
pkaminski commented 4 months ago

Interesting — is the PHP code's syntax incorrect then? (I know nothing about PHP, this was reported by a user.)

pkaminski commented 4 months ago

Oh, I see — the use token is dual-use (hah!) in PHP, and HighlightJS is assuming the import/aliasing meaning, right?