Skip to content
This repository has been archived by the owner on Jan 19, 2019. It is now read-only.

Breaking: Allow comment scanner to rescan tokens (fixes #216) #219

Merged
merged 1 commit into from
May 9, 2017

Conversation

soda0289
Copy link
Member

Template strings and regex patterns need to be rescaned to not scan tokens as comments. I aslo re-factored the comment code and removed the attachComment option since it is no longer needed.

The code pattern was taken from here:
https://github.com/Microsoft/TypeScript/blob/2b10611fbfb63c4fe24d865dc275fec016af003e/src/services/formatting/formattingScanner.ts

I'm not sure if there is a better way to find the container token node. We could use a list of scanned tokens then search through it for a possible container but I think we need to know the node and not the token to find a container. The method I use currently walks the ast searching for a container node.

@eslintbot
Copy link

LGTM

@soda0289
Copy link
Member Author

soda0289 commented Apr 14, 2017

@JamesHenry Can you give this a review when you get a chance, no rush. Maybe there is a better way to find a container token or we could use the typescript format scanner?

@eslintbot
Copy link

LGTM

@eslintbot
Copy link

LGTM

@soda0289 soda0289 closed this May 6, 2017
@soda0289 soda0289 reopened this May 6, 2017
Copy link
Member

@JamesHenry JamesHenry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs major rebase (or perhaps a fresh branch would be easier?)

@eslintbot
Copy link

LGTM

@soda0289 soda0289 mentioned this pull request May 6, 2017
@eslintbot
Copy link

LGTM

@soda0289
Copy link
Member Author

soda0289 commented May 6, 2017

@JamesHenry its rebased now. I but the comment code in a separate file

@azz
Copy link
Contributor

azz commented May 7, 2017

Does the following parse correctly:

/* // test */

@soda0289
Copy link
Member Author

soda0289 commented May 7, 2017

I added a test case for it. This is the result https://github.com/eslint/typescript-eslint-parser/blob/a5e2293d5d44c43b26b18e93eac27013ae0fe766/tests/fixtures/comments/line-comment-with-block-syntax.result.js

I changed the logic so line comments only remove //. Block comments only remove /* and */

@@ -0,0 +1,147 @@
/**
* @fileoverview Convert comment using TypeScript token scanner
* @author Nicholas C. Zakas
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically I wrote all the comment code 😄

@@ -69,8 +70,8 @@ module.exports = (ast, extra) => {
/**
* Add the comment nodes to the AST (that were parsed separately in parser.js)
*/
if (extra.comment || extra.attachComment) {
estree.comments = extra.comments || [];
if (extra.comment) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this was redundant until now, but this is breaking change - prettier currently uses the attachComment version and will need to be updated.

I think we should still make the change, but we will need to update it to Breaking

@JamesHenry
Copy link
Member

This looks great @soda0289, thanks for all digging around reScan etc

Template strings and regex patterns need to be rescaned to
not scan tokens as comments.

Fix how comment tokens are removed.
@soda0289 soda0289 changed the title Fix: Allow comment scanner to rescan tokens (fixes #216) Breaking: Allow comment scanner to rescan tokens (fixes #216) May 7, 2017
@eslintbot
Copy link

LGTM

@soda0289
Copy link
Member Author

soda0289 commented May 7, 2017

@JamesHenry Thanks for the review.

Made the recommended changes and fixed a comment in parser.js.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants