Skip to content

fix(grammar-patch): handle non-plain-object inside in deep keys and bare RegExps in $merge (#4176) - #4185

Open
SawanTeja wants to merge 1 commit into
PrismJS:v2from
SawanTeja:fix-4176-grammar-patch
Open

SawanTeja wants to merge 1 commit into
PrismJS:v2from
SawanTeja:fix-4176-grammar-patch

Conversation

@SawanTeja

Copy link
Copy Markdown

Description

Fixes #4176

Changes

  • Deep keys in $insertBefore / $insertAfter: Replaced the truthiness check if (obj) with if (isPlainObject(obj) && tokens). Non-plain-object inside references (e.g. language-id strings such as inside: 'markup', bare RegExps, or functions) are safely skipped instead of throwing a TypeError.
  • Bare RegExps & arrays in $merge: Introduced a recursive mergeToken utility that converts bare RegExp targets to { pattern: target, ...tokens }, merges properties into token arrays (e.g. class-name), and reassigns the result back to grammar[key].
  • Object utils: Fixed isObject and isPlainObject to safely support Object.create(null) objects without throwing.
  • Tests: Added comprehensive unit test coverage in tests/core/grammar-patch.js.

Checklist

  • Tests pass (npm test)
  • Type check passes (npm run typecheck)
  • Linting passes (npm run lint)

@netlify

netlify Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for dev-prismjs-com ready!

Name Link
🔨 Latest commit 7afa8f8
🔍 Latest deploy log https://app.netlify.com/projects/dev-prismjs-com/deploys/6adce7d34f2ed8cfc229c46f
😎 Deploy Preview https://deploy-preview-4185--dev-prismjs-com.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

grammarPatch: deep / keys throw TypeError when the path crosses a string inside (e.g. inside: 'markup'); silently no-ops on bare-RegExp tokens

1 participant