Skip to content

Commit

Permalink
fix(47062): support generic arrow function with default type paramete…
Browse files Browse the repository at this point in the history
…r in tsx (microsoft#47112)

* fix(47062): support generic arrow function with default type parameter in tsx

* test: update test "completionListIsGlobalCompletion"
  • Loading branch information
hi-ogawa authored and mprobst committed Jan 10, 2022
1 parent 54bfe54 commit 950e31e
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/compiler/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4433,7 +4433,7 @@ namespace ts {
return true;
}
}
else if (third === SyntaxKind.CommaToken) {
else if (third === SyntaxKind.CommaToken || third === SyntaxKind.EqualsToken) {
return true;
}
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,7 @@ tests/cases/conformance/jsx/file.tsx(24,25): error TS1382: Unexpected token. Did
!!! error TS1382: Unexpected token. Did you mean `{'>'}` or `>`?
x5.isElement;

// This is a generic function
var x6 = <T = string,>() => {};
x6();

6 changes: 6 additions & 0 deletions tests/baselines/reference/tsxGenericArrowFunctionParsing.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ x4.isElement;
var x5 = <T extends>() => {}</T>;
x5.isElement;

// This is a generic function
var x6 = <T = string,>() => {};
x6();


//// [file.jsx]
Expand All @@ -44,3 +47,6 @@ x4.isElement;
// This is an element
var x5 = <T extends>() => </T>;
x5.isElement;
// This is a generic function
var x6 = function () { };
x6();
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,11 @@ x5.isElement;
>x5 : Symbol(x5, Decl(file.tsx, 23, 3))
>isElement : Symbol(JSX.Element.isElement, Decl(file.tsx, 1, 20))

// This is a generic function
var x6 = <T = string,>() => {};
>x6 : Symbol(x6, Decl(file.tsx, 27, 3))
>T : Symbol(T, Decl(file.tsx, 27, 10))

x6();
>x6 : Symbol(x6, Decl(file.tsx, 27, 3))

Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,12 @@ x5.isElement;
>x5 : JSX.Element
>isElement : any

// This is a generic function
var x6 = <T = string,>() => {};
>x6 : <T = string>() => void
><T = string,>() => {} : <T = string>() => void

x6();
>x6() : void
>x6 : <T = string>() => void

Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,6 @@ x4.isElement;
var x5 = <T extends>() => {}</T>;
x5.isElement;

// This is a generic function
var x6 = <T = string,>() => {};
x6();
2 changes: 1 addition & 1 deletion tests/cases/fourslash/completionListIsGlobalCompletion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ verify.completions(
{ marker: "7", exact: completion.globalsInsideFunction(x), isGlobalCompletion: true },
{ marker: "9", exact: ["x", "y"], isGlobalCompletion: false },
{ marker: "10", exact: completion.classElementKeywords, isGlobalCompletion: false, isNewIdentifierLocation: true },
{ marker: "13", exact: globals.filter(name => name !== 'z'), isGlobalCompletion: false },
{ marker: "13", exact: globals, isGlobalCompletion: false },
{ marker: "15", exact: globals.filter(name => name !== 'x'), isGlobalCompletion: true, isNewIdentifierLocation: true },
{ marker: "16", unsorted: [...x, completion.globalThisEntry, ...completion.globalsVars, completion.undefinedVarEntry].filter(name => name !== 'user'), isGlobalCompletion: false },
{ marker: "17", exact: completion.globalKeywords, isGlobalCompletion: false },
Expand Down

0 comments on commit 950e31e

Please sign in to comment.