fix: preserve non-enumerable properties in cached results#185
Open
mixelburg wants to merge 1 commit into
Open
Conversation
Fix two caching bugs: 1. .matter and .language were lost on cached calls (jonschlinkert#174) These properties are defined as non-enumerable via Reflect.defineProperty in toFile.js. Object.assign({}, cached) skips non-enumerable properties, so file.matter and file.language were undefined on the second call. 2. Invalid front-matter was cached (jonschlinkert#166) The file object was cached before parseMatter ran, so if parsing threw an error, the raw input was cached and the second call returned a wrong result. Moved cache write to after parseMatter succeeds. Fixes jonschlinkert#174, fixes jonschlinkert#166
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 two caching bugs:
1.
.matterand.languagelost on cached calls (#174)The
matterandlanguageproperties are defined as non-enumerable viaReflect.definePropertyintoFile.js. When the cache returns a shallow copy viaObject.assign({}, cached), non-enumerable properties are skipped. This means on the second (cached) call,file.matterandfile.languageareundefined.Fix: Explicitly copy
matterandlanguageafterObject.assign, following the same pattern already used fororig.2. Invalid front-matter was cached (#166)
The file object was cached before
parseMatterran, so if parsing threw an error (e.g. invalid YAML), the raw input stayed in the cache. The second call returned a wrong result instead of throwing again.Fix: Moved
matter.cache[file.content] = fileto afterparseMattersucceeds.Fixes #174, fixes #166