-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Fix missing undefined
checks
#36599
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix missing undefined
checks
#36599
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3403,7 +3403,7 @@ namespace ts { | |
node.emitNode = {} as EmitNode; | ||
} | ||
|
||
return node.emitNode; | ||
return node && node.emitNode; | ||
} | ||
|
||
/** | ||
|
@@ -3448,7 +3448,7 @@ namespace ts { | |
* Gets a custom text range to use when emitting source maps. | ||
*/ | ||
export function getSourceMapRange(node: Node): SourceMapRange { | ||
const emitNode = node.emitNode; | ||
const emitNode = node && node.emitNode; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we're getting an error here its because we are somehow being passed a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably a |
||
return (emitNode && emitNode.sourceMapRange) || node; | ||
} | ||
|
||
|
@@ -3473,7 +3473,7 @@ namespace ts { | |
* Gets the TextRange to use for source maps for a token of a node. | ||
*/ | ||
export function getTokenSourceMapRange(node: Node, token: SyntaxKind): SourceMapRange | undefined { | ||
const emitNode = node.emitNode; | ||
const emitNode = node && node.emitNode; | ||
const tokenSourceMapRanges = emitNode && emitNode.tokenSourceMapRanges; | ||
return tokenSourceMapRanges && tokenSourceMapRanges[token]; | ||
} | ||
|
@@ -3493,7 +3493,7 @@ namespace ts { | |
*/ | ||
/*@internal*/ | ||
export function getStartsOnNewLine(node: Node) { | ||
const emitNode = node.emitNode; | ||
const emitNode = node && node.emitNode; | ||
return emitNode && emitNode.startsOnNewLine; | ||
} | ||
|
||
|
@@ -3510,7 +3510,7 @@ namespace ts { | |
* Gets a custom text range to use when emitting comments. | ||
*/ | ||
export function getCommentRange(node: Node) { | ||
const emitNode = node.emitNode; | ||
const emitNode = node && node.emitNode; | ||
return (emitNode && emitNode.commentRange) || node; | ||
} | ||
|
||
|
@@ -3523,7 +3523,7 @@ namespace ts { | |
} | ||
|
||
export function getSyntheticLeadingComments(node: Node): SynthesizedComment[] | undefined { | ||
const emitNode = node.emitNode; | ||
const emitNode = node && node.emitNode; | ||
return emitNode && emitNode.leadingComments; | ||
} | ||
|
||
|
@@ -3537,7 +3537,7 @@ namespace ts { | |
} | ||
|
||
export function getSyntheticTrailingComments(node: Node): SynthesizedComment[] | undefined { | ||
const emitNode = node.emitNode; | ||
const emitNode = node && node.emitNode; | ||
return emitNode && emitNode.trailingComments; | ||
} | ||
|
||
|
@@ -3563,7 +3563,7 @@ namespace ts { | |
* Gets the constant value to emit for an expression. | ||
*/ | ||
export function getConstantValue(node: PropertyAccessExpression | ElementAccessExpression): string | number | undefined { | ||
const emitNode = node.emitNode; | ||
const emitNode = node && node.emitNode; | ||
return emitNode && emitNode.constantValue; | ||
} | ||
|
||
|
@@ -3602,7 +3602,7 @@ namespace ts { | |
* Removes an EmitHelper from a node. | ||
*/ | ||
export function removeEmitHelper(node: Node, helper: EmitHelper): boolean { | ||
const emitNode = node.emitNode; | ||
const emitNode = node && node.emitNode; | ||
if (emitNode) { | ||
const helpers = emitNode.helpers; | ||
if (helpers) { | ||
|
@@ -3616,15 +3616,15 @@ namespace ts { | |
* Gets the EmitHelpers of a node. | ||
*/ | ||
export function getEmitHelpers(node: Node): EmitHelper[] | undefined { | ||
const emitNode = node.emitNode; | ||
const emitNode = node && node.emitNode; | ||
return emitNode && emitNode.helpers; | ||
} | ||
|
||
/** | ||
* Moves matching emit helpers from a source node to a target node. | ||
*/ | ||
export function moveEmitHelpers(source: Node, target: Node, predicate: (helper: EmitHelper) => boolean) { | ||
const sourceEmitNode = source.emitNode; | ||
const sourceEmitNode = source && source.emitNode; | ||
const sourceEmitHelpers = sourceEmitNode && sourceEmitNode.helpers; | ||
if (!some(sourceEmitHelpers)) return; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We shouldn't need this. We initialize the value if it isn't set two lines before this.