[lexical-code-prism] Bug Fix: read the language maps as own properties - #8981
Merged
etrepum merged 1 commit intoAug 9, 2026
Merged
Conversation
`CODE_LANGUAGE_MAP` and `CODE_LANGUAGE_FRIENDLY_NAME_MAP` are plain objects, and both lookups were plain index reads, so a language named after a member of `Object.prototype` came back as the inherited value. `normalizeCodeLanguage` and `getLanguageFriendlyName` are typed as returning a string and returned the `Object` function instead. A code block's language is whatever the document carries, so the name is not ours to choose: the markdown transformer hands the info string of a fence straight to `$createCodeNode`.
luantaraschi
requested review from
acywatson,
etrepum,
ivailop7 and
potatowagon
as code owners
August 8, 2026 16:57
|
@luantaraschi is attempting to deploy a commit to the Meta Open Source Team on Vercel. A member of the Team first needs to authorize it. |
etrepum
approved these changes
Aug 8, 2026
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
normalizeCodeLanguageandgetLanguageFriendlyNameare declared as returning a string, and for a handful of language names they return a function instead.Both read their map with a plain index, and both maps are object literals:
So a language whose name matches a member of
Object.prototyperesolves to the inherited value rather than falling through tolang:The language of a code block is whatever the document carries, so the name is not ours to choose. The markdown transformer reads the info string of a fence and hands it straight to
$createCodeNode:so importing
```constructoris enough to reach it. From there the playground'sCodeActionMenuPluginrendersgetLanguageFriendlyName(lang)as the label and passesnormalizeCodeLanguage(...)tocanBePrettier, both of which now receive a function.Worth mentioning because it is the thing that convinced me the fix belongs here rather than at the call sites: the sibling facade already gets this right.
normalizeCodeLanguagein@lexical/code-shikilooks the name up withbundledLanguagesInfo.find(...), an array search, so no name can reach a prototype member.I kept both maps as plain objects, since they are exported and swapping them for a
Mapwould be a breaking change for anyone reading or spreading them. The lookups go through a small helper that only accepts own properties, which leaves the||fallback behaving exactly as before for every language that is actually in the map.Test plan
Two tests added to
CodePrismLanguageOptions.test.ts: one walks the six names above through both functions, and one asserts the ordinary mappings still work, so the guard cannot quietly swallow a real language.Before
The new test fails on the current code:
After
The wider suite is unchanged:
packages/lexical-code-prism,packages/lexical-code-shikiandpackages/lexical-code-coretogether give 10 files, 213 tests, all passing.