Skip to content

Commit

Permalink
Permit use of trailing comma in generics in TSX lexer (#1528)
Browse files Browse the repository at this point in the history
When TypeScript is used with React, the syntax for generics (`<T>`)
causes conflicts. The solution is to include a trailing comma (`<T,>`).
This commit updates the TSX lexer to support this use of a trailing
comma.
  • Loading branch information
pyrmont authored May 30, 2020
1 parent 3b9c422 commit c09cb89
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/rouge/lexers/tsx.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ class TSX < JSX

tag 'tsx'
filenames '*.tsx'

prepend :element_name do
rule %r/(\w+)(,)/ do
groups Name::Other, Punctuation
pop! 3
end
end
end
end
end
Expand Down
27 changes: 27 additions & 0 deletions spec/visual/samples/tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,30 @@ ReactDOM.render(
<LikeButton />,
document.getElementById('example')
);

const withAuthRedirect = (route: string, redirectIfAuthed: boolean) => <P,>(
Page: NextComponentType<NextPageContext, {}, P>
) => {
return class extends React.Component<P> {
static async getInitialProps(ctx: NextPageContext) {
const shouldContinue = await redirectBasedOnLogin(
ctx,
route,
redirectIfAuthed
);
if (!shouldContinue) {
return {};
}
if (Page.getInitialProps) {
return Page.getInitialProps(ctx);
}
}

render() {
return <Page {...this.props} />;
}
};
};

export const withLoginRedirect = withAuthRedirect('/login', false);
export const withDashboardRedirect = withAuthRedirect('/dashboard', true);

0 comments on commit c09cb89

Please sign in to comment.