Repository navigation
Conversation
Instance.get() previously assumed result.parent.children[0] existed whenever isPropertyNamePointer was true. This caused an unhandled TypeError when the property was missing or when targeting the root node, and returned the first array element when targeting an array index. Safely check result?.parent?.type === 'property' and return undefined otherwise.
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 an issue where
Instance.get()throws an unhandledTypeErrorinstead of returningundefinedwhen attempting to resolve a non-existent property name pointer (e.g."#*/missing"or"#*").Additionally, resolves a bug where querying a property name pointer against an array index (e.g.
"#*/1") returned the first item of the array instead ofundefined.Cause
In
lib/instance.js:When
isPropertyNamePointeristrue:resultisundefined(missing property), accessingresult.parentthrowsTypeError: Cannot read properties of undefined (reading 'parent').resultis the root node,result.parentisundefined, so accessingresult.parent.childrenthrowsTypeError: Cannot read properties of undefined (reading 'children').resultis an array element,result.parentis the array node (not a property node), soresult.parent.children[0]returns the first array element instead ofundefined.Solution
Verify that
result?.parentexists and is of type"property":Verification
lib/instance.spec.tscovering:#*/foo)#*/missing)#*)#*/1)npm testpasses forlib/instance.spec.ts(44/44 tests)npm run lintpasses (0 errors)npm run check-typespasses (0 errors)