Repository navigation
Fix type guards throwing on null or undefined in protocol package - #1940
Open
Siddharth S (codeXsidd) wants to merge 2 commits into
Open
Siddharth S (codeXsidd) wants to merge 2 commits into
Siddharth S (codeXsidd) wants to merge 2 commits into
Conversation
…l or undefined
Author
|
@microsoft-github-policy-service agree |
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
Ensures
TextDocumentFilter.is,TextDocumentRegistrationOptions.is,WorkDoneProgressOptions.hasWorkDoneProgress, andDiagnosticServerCancellationData.issafely handlenullandundefinedwithout throwingTypeErrorand return boolean results.Problem
TextDocumentFilter.isdid not verify whether a non-string candidate is an object literal before reading candidate properties (candidate.language). PassingnullorundefinedthrewTypeError: Cannot read properties of null (reading 'language')instead of returningfalse.Consequently, composite guards like
DocumentSelector.is([null])andTextDocumentRegistrationOptions.is({ documentSelector: [null] })crashed with aTypeError. In addition,TextDocumentRegistrationOptions.is(null),WorkDoneProgressOptions.hasWorkDoneProgress(null), andDiagnosticServerCancellationData.is(null)returnednullrather than booleanfalse.Solution
Is.objectLiteral(candidate)checks inTextDocumentFilter.is,TextDocumentRegistrationOptions.is,WorkDoneProgressOptions.hasWorkDoneProgress, andDiagnosticServerCancellationData.is.protocol/src/node/test/documentFilter.test.tscoveringTextDocumentFilter.is,DocumentSelector.is,TextDocumentRegistrationOptions.is,WorkDoneProgressOptions.hasWorkDoneProgress, andDiagnosticServerCancellationData.isfor valid filters, relative patterns, invalid values, andnull/undefined.Testing
npm run compile:protocol: passed cleanlynpm run compile(full project build mode across all packages): passed cleanlynpm --prefix protocol run lint: passed cleanly (0 errors)npm --prefix protocol run test:node: passed (all 26 tests passing)npm --prefix types test: passed (all 58 tests passing)npm --prefix server test: passed (all 17 tests passing)Related Issue
Closes #1939