Skip to content

Commit

Permalink
fix(build) registered language names should use - not _ (#3264)
Browse files Browse the repository at this point in the history
* Fix registered language name for grammar names with dash, fixes #3263.
  • Loading branch information
fredrikekre committed Jul 5, 2021
1 parent 55f68f7 commit 1cb086b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/stub.js
Expand Up @@ -5,7 +5,11 @@ import * as builtIns from "builtInLanguages";
const hljs = HighlightJS;

for (const key of Object.keys(builtIns)) {
const languageName = key.replace("grmr_", "");
// our builtInLanguages Rollup plugin has to use `_` to allow identifiers to be
// compatible with `export` naming conventions, so we need to convert the
// identifiers back into the more typical dash style that we use for language
// naming via the API
const languageName = key.replace("grmr_", "").replace("_", "-");
hljs.registerLanguage(languageName, builtIns[key]);
}
// console.log(hljs.listLanguages());
Expand Down
9 changes: 9 additions & 0 deletions test/builds/browser_build_as_commonjs.js
Expand Up @@ -21,4 +21,13 @@ API.forEach(n => {
assert(_ => keys.includes(n), `API should include ${n}`);
});

// See e.g. highlightjs/highlight.js#3263
const langs = ["python", "python-repl"]
langs.forEach(n => {
assert(_ => {
res = hljs.getLanguage(n);
return typeof res === 'object' && res !== null
})
})

console.log("Pass: browser build works with Node.js just fine.")

0 comments on commit 1cb086b

Please sign in to comment.