Skip to content

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

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions src/compiler/factoryPublic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3403,7 +3403,7 @@ namespace ts {
node.emitNode = {} as EmitNode;
}

return node.emitNode;
return node && node.emitNode;
Copy link
Contributor

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.

}

/**
Expand Down Expand Up @@ -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;
Copy link
Contributor

Choose a reason for hiding this comment

The 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 node that is undefined however we expect a defined node.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably a symbol.valueDeclaration via some means, since that's a known hole in our current type definitions.

return (emitNode && emitNode.sourceMapRange) || node;
}

Expand All @@ -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];
}
Expand All @@ -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;
}

Expand All @@ -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;
}

Expand All @@ -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;
}

Expand All @@ -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;
}

Expand All @@ -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;
}

Expand Down Expand Up @@ -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) {
Expand All @@ -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;

Expand Down