-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Better template literals support in checker #32064
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
Better template literals support in checker #32064
Conversation
Any chance to get initial review comments (messages, utility functions) and preference regarding |
832c1c2
to
55b876f
Compare
85454e5
to
caef2dc
Compare
Is there anything I should do before this PR can be reviewed? If it's only 7 of 8 progress - this is because I still waiting for reply about template literals in import types and import...require. This change will involve not only update to checker and utils, but also for various services (findAllReferences, importTracker, rename to name few) |
@@ -50,6 +50,7 @@ var v = { | |||
|
|||
[`hello bye`]() { }, | |||
>[`hello bye`] : Symbol([`hello bye`], Decl(computedPropertyNames10_ES5.ts, 12, 22)) | |||
>`hello bye` : Symbol([`hello bye`], Decl(computedPropertyNames10_ES5.ts, 12, 22)) |
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.
All these computed property name symbol baseline changes are a bit odd... do you know what caused this?
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.
These are result of commit 30ff964
Intent was to bring template literals into line with numbers and regular strings in computed property names.
They produce separate symbols for names https://github.com/microsoft/TypeScript/pull/32064/files/caef2dc945cbb42cbfb021d9737f07033916180d#diff-739db372f229c7fa65d1a1da3101251aR36-R42
This one and last commit were under question for me, because I haven't found what exact behavior they will enable except unifying produced symbols and types with string literals in similar condition.
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.
Huh, interesting. I think that’s probably fine, then.
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.
I have no strong opinion about these commits and will revert if anyone considers its necessary.
These were found as comparisons of StringLiteral
and NoSubstitutionTemplateLiteral
usages. I would expect that last 2 commits will help in services (not included in this PR) but looks like there are a lot of differences that filter out template literals before symbols for them will be checked (which will need separate investigation).
I’d vote no. A separate PR would make it a bit easier, if you want to do it.
Yep.
Updating the diagnostic messages is fine in general, but I’m personally not sure it’s necessary. I casually think of |
Thanks for the feedback. I will revert changes to diagnostics and create separate to discuss whether templates should be supported in imports. |
caef2dc
to
efae717
Compare
I reverted changes to the diagnostic messages. Separate issue for |
Is there anything else required from my side? |
efae717
to
ed1f919
Compare
@IllusionMH not at the moment—since this is essentially a feature and we already released the 3.6 beta, we’re planning to include this in 3.7. I wanted to answer your open questions right away, but I’ll be reviewing the rest of it probably after we release 3.6-rc. Thanks for your patience! 🌟 |
Oh, I see. Issue was marked as a bug, so I hoped it would make it into 3.6 but I see your point. Will wait then. |
ed1f919
to
49a4352
Compare
@typescript-bot test this |
Heya @andrewbranch, I've started to run the extended test suite on this PR at 49a4352. You can monitor the build here. It should now contribute to this PR's status checks. |
Cool, all the tests pass! @IllusionMH I think the icing on the cake to ship with this would be to trigger string literal completions on a backtick character where appropriate: It’s a bit hard to tell here, but when completions appear inside backticks, it’s because I pressed ⌃Space on my keyboard. So it shows that the string literal completions are available, they’re just not being triggered. What do you think? |
@IllusionMH I think my preference would be that any particular “feature” ships with support in the core compiler and in the services at the same time. So, it’s ok to do import types in a later PR (I also noticed that indexed access types don’t yet work with template strings: Good find with the property renaming. That one seems important. Another thing to check is find-all-references. The reasons I think it’s good to ship language features with services support:
Thanks as always for your excellent work 🙌 |
OK, I'll take a look at UPD. Checked case type KeyType<T> = T[`key`];
// ^^^^^ ExpressionStatement
declare module `*.tpl` {}
// ^^^^^^^^^^^^^^ ExpressionStatement
let a: Promise<`test`>;
// ^^^^^^^^ ExpressionStatement In these cases template literals treated as not in let b: Promise<'test'>;
// ^^^^^^ LiteralType
let i: import(`module`);
// ^^^^^^^^ LiteralType Frankly speaking at this point I don't have ideas how to fix #29331. But since it affects only TS specific cases (types position, should work fine in valid JS positions) I would prefer to exclude that fix from this PR as mentioned in original issue for this PR #31548. Probably in the end I will avoid imports part for consistency ( However services affects valid JS parts so I will work on fixes for them. |
@andrewbranch I've created microsoft/vscode#80234 to implement triggers for completions on backticks (or any required changes related to services in future) |
@IllusionMH thanks for investigating all these threads! I think your updated plan sounds good.
Ping me when you’re ready for a review of whatever service changes you make 👍 |
👋 @IllusionMH is there anything I can do to help here? Just wanted to give you a heads up that we’ll be releaseing 3.7 beta on October 1, so we won’t be able to merge new features for 3.7 after that. Of course you’re not obligated to anything, just didn’t want it to come as a surprise. I might be able to help get this over the finish line if you’re short on time. |
Still working on this one, but have less time than before. Good news - still working on rename service - now it renames computed properties and indexed access with template literals, but also removes surrounding Bad news - there are more cases in services where |
49a4352
to
0b21d9b
Compare
Looks like change to I can see 2 options:
Any suggestions in this situation? |
Let’s leave those as-is. I think this PR should make NoSubstitutionTemplateLiterals work the same as StringLiterals currently work. |
Couple of questions:
UPD. I'rechecked original scope + services folder to find any noticeable diffrences, but there is nothing that I was able to see in editor -most things are related to places where template literals are no allowed (import/export declarations, field names, type parameters etc.). Only thing that looks off - |
const propertyName = isPropertyAccessExpression(node) | ||
? declarationNameToString(node.name) | ||
: getTextOfNode(node.argumentExpression); | ||
const originalNode = getOriginalNode(node, isAccessExpression); |
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.
Just curious, what was this one needed for?
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.
Template literals and string literals with extended Unicode escapes will be first processed with es2015 transformer which will replace them with Synthesized
string literals that don't have reference to parent element or to original node.
Under the hood getTextOfNode(node.argumentExpression)
will call getSourceFileOfNode
on Synthesized
string literal which will return undefined
(because node.parent
is undefined
) and then getSourceTextOfNodeFromSourceFile
that will try to access sourceFile.text
and exception will be thrown.
On the other hand ElementAccessExpression
even if will be replaced with Synthesized
node, it will have link to original node. Therefore originalNode.argumentExpression
will have proper parent references up to source file and text will be retrieved correctly.
@typescript-bot user test this |
Heya @andrewbranch, I've started to run the extended test suite on this PR at cc8a514. You can monitor the build here. It should now contribute to this PR's status checks. |
Heya @andrewbranch, I've started to run the parallelized community code test suite on this PR at cc8a514. You can monitor the build here. It should now contribute to this PR's status checks. |
I’d like to get another set of eyes on this if possible, so I’m going to leave it open until Friday to try to give the rest of the team some time to look at it. But assuming the extended tests don‘t turn up anything horrifying, I think this is great 👍 |
The user suite test run you requested has finished and failed. I've opened a PR with the baseline diff from master. |
^ Changes/failures look unrelated |
cc8a514
to
11086c9
Compare
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.
Since I'd like to get this into the beta, I'll make the simple change I requested and then merge after we discuss at the design meeting.
Thank you for suggestions, reviews, and patience! |
Fixes #31548
Fixes #30962
You can check details for each propose changes in issue. This PR contain implementation for next items from there:
typeof
conditionconst
initializers inside an ambient declarationsisExpressionNode
checks- 8. Optional suggestion: Support template literals inSeparate issue will be createdlet a: import(`test`)
andimport b = require(`test`)
At this point last item is still in progress and I would like to know if this change should be implemented at all, because it will also affect types as well as
services/findAllReferences.ts
andservices/importTracker.ts
. Should I implement this one in this PR?Two pints are still under questions for me:
node.kind ==== SyntaxKind.X
?