X Tutup
The Wayback Machine - https://web.archive.org/web/20250416215355/https://github.com/microsoft/TypeScript/pull/42154
Skip to content

make boolean literal be a literal expression #42154

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

Conversation

Kingwl
Copy link
Contributor

@Kingwl Kingwl commented Dec 30, 2020

Fixes #42153

@typescript-bot typescript-bot added the For Uncommitted Bug PR for untriaged, rejected, closed or missing bug label Dec 30, 2020
@Kingwl Kingwl changed the title make boolean literal is a literal expression make boolean literal be a literal expression Jan 4, 2021
@typescript-bot typescript-bot added For Backlog Bug PRs that fix a backlog bug and removed For Uncommitted Bug PR for untriaged, rejected, closed or missing bug labels Jan 4, 2021
@sandersn sandersn requested a review from weswigham January 9, 2021 00:14
Copy link
Member

@sandersn sandersn left a comment

Choose a reason for hiding this comment

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

Not sure what to do about text not actually being defined for True/FalseLiteral.

@@ -1074,8 +1074,12 @@ namespace ts {
return SyntaxKind.FirstLiteralToken <= kind && kind <= SyntaxKind.LastLiteralToken;
}

export function isBooleanLiteral(node: Node): node is BooleanLiteral {
return node.kind === SyntaxKind.TrueKeyword || node.kind === SyntaxKind.FalseKeyword;
Copy link
Member

Choose a reason for hiding this comment

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

I wish we could move TrueKeyword inside the First/LastLiteralToken range, but it would probably not be worth the breaks it would cause.

readonly kind: SyntaxKind.FalseKeyword;
readonly text: never
Copy link
Member

Choose a reason for hiding this comment

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

I'm not a big fan of this. Maybe it would be better to change isLiteralExpression to type guard to a supertype of LiteralExpression? Presumably callers will want to access text, and should know that it's not defined in some cases.

Copy link
Member

Choose a reason for hiding this comment

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

I'm also not a fan of this. We use LiteralExpression to mean things that have a possibly differentiating literal value represented as a sequence of unicode characters (i.e., string, number, bigint, RegExp literal). This also disregards null as being a "literal" value. We perhaps could introduce a super-type shared between LiteralExpression and these keyword expressions, but I would not support a change that introduced an unused text property.

@sandersn
Copy link
Member

sandersn commented Jan 9, 2021

@weswigham Do you have an idea of how to address either of the problems I mentioned?

@sandersn sandersn self-assigned this Jan 9, 2021
Copy link
Member

@weswigham weswigham left a comment

Choose a reason for hiding this comment

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

If there's a place where out terminology is wrong, I think maybe it's more appropriate to call them BooleanKeywords rather than BooleanLiterals (though that name's already taken!), since literals are usually open-ended and these are very much not. Plus, I don't want an UndefinedLiteral or a NullLiteral later. In any case, I'm not sure this is a great idea. I'm going to close this ♥

@weswigham weswigham closed this Mar 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
For Backlog Bug PRs that fix a backlog bug
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Boolean literal should be LiteralExpression
5 participants
X Tutup