Bug#1144876: highlight.js: Rollup change breaks hljs.registerLanguage calls

"Blair Noctis" <[email protected]>
Newsgroups gmane.linux.debian.devel.bugs.rc
Message-ID <DKT1XLR7D0A0.1KDDOCDFZVGDP__26734.4804525905$1787156116$gmane$org@debian.org>
Source: highlight.js
Version: 10.7.3+dfsg-1
Severity: grave
Justification: renders package unusable
Tags: patch
X-Debbugs-Cc: [email protected], [email protected]

Dear Maintainer,

Due to a breaking change in behavior from Rollup 2 to 3, IIFE regex replacement
for `hljs.registerLanguage` calls breaks.

Rollup 2, which this version of hljs targeted, generates this:

var dummyName = (function () { /* ... */ }());

which is replaced by hljs to:

hljs.registerLanguage('${language.name}', function () { /* ... */ }());

while Rollup 3 generates this:

var dummyName = (function () { /* ... */ })();

which is replaced by hljs to:

hljs.registerLanguage('${language.name}', function () { /* ... */ })();

You can see that while the previous replacement calls the function *inside*,
current replacement calls the "result" of the `hljs.registerLanguage` call.

The following patch fixes it by calling `hljs.registerLanguage` in a separate
statement.

Note, it's intended to be in the debian/patches series, not a debdiff.

--- a/tools/lib/language.js
+++ b/tools/lib/language.js
@@ -86,14 +86,14 @@

 async function compileLanguage (language, options) {
   const EXPORT_REGEX = /export default (.*);/;
-  const IIFE_HEADER_REGEX = /^(var dummyName = )?\(function \(\)/;
+  //const IIFE_HEADER_REGEX = /^(var dummyName = )?\(function \(\)/;
 
   // TODO: cant we use the source we already have?
   const input = { ...build_config.rollup.browser.input, input: language.path };
   const output = { ...build_config.rollup.browser.output,  name: `dummyName`, file: "out.js" };
   var data = await rollupCode(input, output)
 
-  data = data.replace(IIFE_HEADER_REGEX, `hljs.registerLanguage('${language.name}', function ()`)
+  data = `(function() {\n${data}\nhljs.registerLanguage('${language.name}', dummyName);\n})();` //data = data.replace(IIFE_HEADER_REGEX, `hljs.registerLanguage('${language.name}', function ()`)
 
   var original = data;
   language.module = data;

-- 
    ,Sdrager
Blair Noctis

🇵🇸
signature.asc (application/pgp-signature, 252 B)
-----BEGIN PGP SIGNATURE-----

iIYEABYKAC4WIQSkiHwhuQf2oVaWacxWG2M00EUuRAUCaoXWLBAcbmN0c0BkZWJp
YW4ub3JnAAoJEFYbYzTQRS5E7moA/0HTHdkDttTSNKg/SJlXPWAZE+QtwdhI71qL
/TiJ4F+nAPwN+T0LcrCEc1or3XJLBTsBud9wZThVti1q5V+hZEduAA==
=Pmvl
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.