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

Should not place errors on comments #6653

Closed
egamma opened this issue Jan 27, 2016 · 4 comments
Closed

Should not place errors on comments #6653

egamma opened this issue Jan 27, 2016 · 4 comments
Labels
Bug A bug in TypeScript Help Wanted You can do this VS Code Tracked There is a VS Code equivalent to this issue
Milestone

Comments

@egamma
Copy link
Member

egamma commented Jan 27, 2016

From @alexandrudima on January 27, 2016 13:39

Testing #2218

Interesting squiggly placement strategy:

Number(3).

var x = 3;

// Just_some_good_text_that_did_nothing_wrong

salsa-error-on-comment

Copied from original issue: microsoft/vscode#2449

@egamma egamma self-assigned this Jan 27, 2016
@billti billti added this to the Community milestone Jan 27, 2016
@billti billti added Bug A bug in TypeScript Help Wanted You can do this labels Jan 27, 2016
@billti billti changed the title Salsa should not place errors on comments Should not place errors on comments Jan 27, 2016
@billti
Copy link
Member

billti commented Jan 27, 2016

This is not Salsa specific (happens in TypeScript also). It's likely as the last comment is the last token in the file (and there is no next statement after the error), so it attaches there. Minor issue. Could fix if trivial, else maybe wont fix.

@mhegazy mhegazy added Help Wanted You can do this and removed Help Wanted You can do this labels Feb 20, 2016
@zakhenry
Copy link

Looks like the problem is in this position https://github.com/Microsoft/TypeScript/blob/3853bb86d0f26e150666ab736092824eb781babc/src/compiler/parser.ts#L1849

Relevant excerpt:

        function parseRightSideOfDot(allowIdentifierNames: boolean): Identifier {
            // Technically a keyword is valid here as all identifiers and keywords are identifier names.
            // However, often we'll encounter this in error situations when the identifier or keyword
            // is actually starting another valid construct.
            //
            // So, we check for the following specific case:
            //
            //      name.
            //      identifierOrKeyword identifierNameOrKeyword
            //
            // Note: the newlines are important here.  For example, if that above code
            // were rewritten into:
            //
            //      name.identifierOrKeyword
            //      identifierNameOrKeyword
            //
            // Then we would consider it valid.  That's because ASI would take effect and
            // the code would be implicitly: "name.identifierOrKeyword; identifierNameOrKeyword".
            // In the first case though, ASI will not take effect because there is not a
            // line terminator after the identifier or keyword.
            if (scanner.hasPrecedingLineBreak() && tokenIsIdentifierOrKeyword(token)) {
                const matchesPattern = lookAhead(nextTokenIsIdentifierOrKeywordOnSameLine);

                if (matchesPattern) {
                    // Report that we need an identifier.  However, report it right after the dot,
                    // and not on the next token.  This is because the next token might actually
                    // be an identifier and the error would be quite confusing.
                    return <Identifier>createMissingNode(SyntaxKind.Identifier, /*reportAtCurrentPosition*/ true, Diagnostics.Identifier_expected);
                }
            }

            return allowIdentifierNames ? parseIdentifierName() : parseIdentifier();
        }

I think, maybe changing the reportAtCurrentPosition arg to false may fix the issue as the comment says it should be reported right after the dot, which would be the parseErrorAtCurrentToken case I believe. Sorry I'm not sure how to get TS set up to get all the tests running / where to put new unit tests etc to fully dive in and fix this.

@DanielRosenwasser
Copy link
Member

Hey @xiphiaz, I think that's call is ultimately the cause. The change you're proposing would end up leaving an error at the end of file token, which is still potentially less confusing. Give it a try and we'll see.

I'd put a new test in tests/cases/compiler/missingIdentifierWithTrailingComment01.ts with the following contents:

Number(3).

// var x = 3;

// Just_some_good_text_that_did_nothing_wrong

Take a look at the relevant section in our CONTRIBUTING.md for writing a new test and running our test suite.

@mhegazy mhegazy added the VS Code Tracked There is a VS Code equivalent to this issue label Dec 16, 2016
@RyanCavanaugh RyanCavanaugh modified the milestones: Community, Backlog Mar 7, 2019
@mjbvz
Copy link
Contributor

mjbvz commented Nov 9, 2022

Closing this since it does not seem to happen in VS code 1.74:

Screen Shot 2022-11-09 at 1 41 08 PM

@mjbvz mjbvz closed this as completed Nov 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Help Wanted You can do this VS Code Tracked There is a VS Code equivalent to this issue
Projects
None yet
Development

No branches or pull requests

7 participants