Skip to content

Treat NoSubstitutionTemplateLiteral like StringLiteral in more places #26330

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

Merged
2 commits merged into from
Aug 10, 2018

Conversation

ghost
Copy link

@ghost ghost commented Aug 9, 2018

This is an immediate fix to the particular repro from #26321 but doesn't solve the general case. Still, don't see any reason not to treat these the same.

@ghost ghost force-pushed the nosubstitutiontemplateliteral branch from 4816ac8 to 04d7355 Compare August 9, 2018 17:57
@ghost ghost force-pushed the nosubstitutiontemplateliteral branch from 04d7355 to 924890a Compare August 9, 2018 17:59
@ghost ghost requested review from rbuckton, weswigham and sandersn August 9, 2018 18:27
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.

Looks fine as-is, but I'd like to know what happens if you change all calls to isStringOrNumericLiteral.

@@ -2566,6 +2566,10 @@ namespace ts {
|| kind === SyntaxKind.NumericLiteral;
Copy link
Member

Choose a reason for hiding this comment

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

what happens if you add || isNoSubstitutionTemplateLiteral(node) directly to isStringOrNumericLiteral ? Maybe you can just do that plus maybe change the name to be more accurate.

Copy link
Author

Choose a reason for hiding this comment

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

The only remaining uses are in getPropertyNameOfBindingOrAssignmentElement. That function has no return type, but changing it and recompiling shows a number of errors. Looks like the return type does need to be PropertyName | undefined which excludes NoSubstitutionTemplateLiteral.

@ghost ghost force-pushed the nosubstitutiontemplateliteral branch from a8488af to 40972ba Compare August 10, 2018 00:40
const kind = node.kind;
return kind === SyntaxKind.StringLiteral
|| kind === SyntaxKind.NumericLiteral;
export function isStringOrNumericLiteralLike(node: Node): node is StringLiteralLike | NumericLiteral {
Copy link
Contributor

Choose a reason for hiding this comment

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

The name implies that this includes BigInt literals once they are added to the language. I don't know if that is correct for all call sites

Copy link
Author

Choose a reason for hiding this comment

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

It looks like in most cases it would be -- { [0n]: true } is the same as { 0: true } so as long as IntLiteral#text doesn't include n this would work. @sheetalkamat is working on bigints.

Copy link
Member

Choose a reason for hiding this comment

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

@Andy-MS #25886 I think is the nearly complete implementation at this point (unless we have multiple implementations at the ready). But yeah, I guess indexing with bigint is fine - it's just odd, since in the typesystem that needs to go under the number index signature since 0n and 0 have the same string representation. Probably worth testing in #25886, at least! It's probably not a concern for this PR directly, since it'll need to be dealt with at the point they're added.

@weswigham weswigham mentioned this pull request Aug 10, 2018
@ghost ghost merged commit 08f5edb into master Aug 10, 2018
@ghost ghost deleted the nosubstitutiontemplateliteral branch August 10, 2018 23:00
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants