Repository navigation
fix(remark): prevent options mutation across multi-file builds in remark-table-of-contents - #1815
Open
cynicalmindset wants to merge 1 commit into
Conversation
…ark-table-of-contents
Author
|
@jdesrosiers PTAL |
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.
Summary
Fixes closure state leakage in
remark-table-of-contents.jsand eliminates phantom empty nested list items in the generated Table of Contents.Problem
npm run build -- specs), the plugin reassignsoptions.skipfrom anArrayinto aRegExpin the outer closure. On subsequent documents, invokingoptions.skip.push()throwsTypeError: options.skip.push is not a function.skipRegex.test(headingText), creating an empty nested sublist container (<li><ul></ul></li>) for skipped headings whose depth was greater thancurrentDepth.Root cause
options = { ...defaultOptions, ...options }) without local declaration.options.skipin place instead of creating a pre-compiledRegExpduring plugin instantiation.Changes
skipRegexcompilation to the outer plugin factory function.skipRegex.test(headingText)before creating child list nodes in the AST.remark/remark-table-of-contents.test.js.vitest-schema.config.js.Testing
remark/remark-table-of-contents.test.jsconfirms repeated invocations run withoutTypeError.Checklist
closes #1814