Skip to content
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

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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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