Skip to content

createMissingNode: Only assign '.text' or '.escapedText' on nodes of the correct type#17439

Merged
2 commits merged into
masterfrom
createMissingIdentifier
Jul 27, 2017
Merged

createMissingNode: Only assign '.text' or '.escapedText' on nodes of the correct type#17439
2 commits merged into
masterfrom
createMissingIdentifier

Conversation

@ghost
Copy link
Copy Markdown

@ghost ghost commented Jul 26, 2017

Fixes #17346

@ghost ghost force-pushed the createMissingIdentifier branch from 942b9e8 to cfddbbc Compare July 26, 2017 22:02
Comment thread src/compiler/parser.ts
case SyntaxKind.Identifier:
(result as Identifier).escapedText = "" as __String;
break;
default: // TODO: GH#17346
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

To preserve the intent of current behaviors, why not just replace the switch with

if (kind === SyntaxKind.Identifier) {
    (result as Identifier).escapedText = "" as __String;
}
else if (isLiteralKind(kind)) {
    (result as LiteralLikeNode).text = "";
}

?
This would also preserve the behavior when createMissingNode is called via parseExpected, or other indirect calls. We could also add some overloads for specific syntax kinds to avoid the need for casts.

@ghost ghost force-pushed the createMissingIdentifier branch from ff9cf9b to 08afce6 Compare July 27, 2017 14:42
@ghost ghost merged commit 977d907 into master Jul 27, 2017
@ghost ghost deleted the createMissingIdentifier branch July 27, 2017 17:34
@microsoft microsoft locked and limited conversation to collaborators Jun 14, 2018
This pull request was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants