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

Move common rules to common module for TypeScript lexer #1530

Merged
merged 1 commit into from Jun 2, 2020

Conversation

pyrmont
Copy link
Contributor

@pyrmont pyrmont commented Jun 1, 2020

Because the TSX lexer needs to inherit from both the TypeScript lexer and the JSX lexer (and because Ruby does not have multiple inheritance), most of the TypeScript lexer was extracted into a common module.

Some rules were not moved, though and this caused differences in the output from the TypeScript and TSX lexers that were not correct. This fixes that problem by adopting the same approach used with the ObjectiveC common module: using Ruby's Module#extended hook.

@pyrmont pyrmont added the needs-review The PR needs to be reviewed label Jun 1, 2020
@pyrmont pyrmont self-assigned this Jun 1, 2020
@pyrmont
Copy link
Contributor Author

pyrmont commented Jun 1, 2020

This will fix the problem referred to in #1516 where the TypeScript and TSX lexers treat optional chaining differently.

@pyrmont pyrmont merged commit 30fc93f into rouge-ruby:master Jun 2, 2020
@pyrmont pyrmont deleted the bugfix.typescript-common-rules branch June 2, 2020 20:05
@pyrmont pyrmont removed the needs-review The PR needs to be reviewed label Jun 2, 2020
mattt pushed a commit to NSHipster/rouge that referenced this pull request May 19, 2021
…uby#1530)

The TypeScript lexer was refactored in a previous commit to move its
memoisation methods into a module that could be mixed in by the TSX
lexer. This is because the TSX lexer needs to inherit from both the
TypeScript lexer and the JSX lexer but can't do that direclty because
Ruby does not support multiple inheritance.

While the memoisation methods were moved, changes to states of
TypeScript lexer were not refactored out. This means that the TypeScript
and TSX lexers can lex the same code differently. This commit fixes that
problem by adopting the same approach used with the ObjectiveC common
module: using Ruby's `Module#extended` hook.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant