Skip to content

Commit 5fd0701

Browse files
Fixed bug where tagged templates with a literal adjacent to EOF showed sig help.
1 parent 44e6bcf commit 5fd0701

7 files changed

Lines changed: 51 additions & 6 deletions

src/compiler/emitter.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -715,7 +715,7 @@ module ts {
715715
};
716716
}
717717
}
718-
718+
719719
function emitEnumDeclaration(node: EnumDeclaration) {
720720
if (resolver.isDeclarationVisible(node)) {
721721
emitJsDocComments(node);
@@ -3558,7 +3558,7 @@ module ts {
35583558
return leadingComments;
35593559
}
35603560

3561-
3561+
35623562
function getLeadingCommentsToEmit(node: Node) {
35633563
// Emit the leading comments only if the parent's pos doesn't match because parent should take care of emitting these comments
35643564
if (node.parent.kind === SyntaxKind.SourceFile || node.pos !== node.parent.pos) {

src/compiler/parser.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -823,9 +823,10 @@ module ts {
823823
return false;
824824
}
825825

826-
// If we didn't end in a backtick, we must still be in the middle of a template.
827-
// If we did, make sure that it's not the *initial* backtick.
828-
return sourceText.charCodeAt(node.end - 1) !== CharacterCodes.backtick || node.text.length === 0;
826+
// If we didn't end in a backtick, we must still be in the middle of a template literal,
827+
// but if it's the *initial* backtick (whereby the token is 1 char long), then it's unclosed.
828+
var width = node.end - getTokenPosOfNode(node);
829+
return width < 2 || sourceText.charCodeAt(node.end - 1) !== CharacterCodes.backtick;
829830
}
830831

831832
export function isModifier(token: SyntaxKind): boolean {

src/services/signatureHelp.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ module ts.SignatureHelp {
296296
Debug.assert(templateExpression.kind === SyntaxKind.TemplateExpression);
297297

298298
// If we're just after a template tail, don't show signature help.
299-
if (node.kind === SyntaxKind.TemplateTail && position >= node.getEnd() && !isUnterminatedTemplateEnd(<LiteralExpression>node)) {
299+
if (node.kind === SyntaxKind.TemplateTail && !isInsideTemplateLiteral(<LiteralExpression>node, position)) {
300300
return undefined;
301301
}
302302

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
//// function foo(strs, ...rest) {
4+
//// }
5+
////
6+
//// /*1*/fo/*2*/o /*3*/`abcd${0 + 1}abcd{1 + 1}`/*4*/ /*5*/
7+
8+
test.markers().forEach(m => {
9+
goTo.position(m.position);
10+
verify.not.signatureHelpPresent();
11+
});
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
//// function foo(strs, ...rest) {
4+
//// }
5+
////
6+
//// /*1*/fo/*2*/o /*3*/`abcd${0 + 1}abcd{1 + 1}abcd`/*4*/ /*5*/
7+
8+
test.markers().forEach(m => {
9+
goTo.position(m.position);
10+
verify.not.signatureHelpPresent();
11+
});
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
//// function foo(strs, ...rest) {
4+
//// }
5+
////
6+
//// /*1*/fo/*2*/o /*3*/``/*4*/ /*5*/
7+
8+
test.markers().forEach(m => {
9+
goTo.position(m.position);
10+
verify.not.signatureHelpPresent();
11+
});
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
//// function foo(strs, ...rest) {
4+
//// }
5+
////
6+
//// /*1*/fo/*2*/o /*3*/`abcd`/*4*/ /*5*/
7+
8+
test.markers().forEach(m => {
9+
goTo.position(m.position);
10+
verify.not.signatureHelpPresent();
11+
});

0 commit comments

Comments
 (0)