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

@ts-ignore false positive inside strings and other comments #25240

Closed
ajafff opened this issue Jun 26, 2018 · 2 comments
Closed

@ts-ignore false positive inside strings and other comments #25240

ajafff opened this issue Jun 26, 2018 · 2 comments
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug

Comments

@ajafff
Copy link
Contributor

ajafff commented Jun 26, 2018

TypeScript Version: 3.0.0-dev.20180621

Search Terms: ts-ignore

Code

<>
    // @ts-ignore
    {nonExistent}
</>;

`
// @ts-ignore
${nonExistent}
`;

"\
// @ts-ignore"
nonExistent;

/**
// @ts-ignore all the things */
nonExistent;

Expected behavior:

3 times Cannot find name 'nonExistent'.

Actual behavior:

No error, because the regex used to lookup the comment doesn't (and cannot reliably) check the surroundings of the comment.

To fix this, you probably need to use getTokenAtPosition and get(Leading|Trailing)CommentRanges to check if this is really a comment.

Playground Link: https://agentcooper.github.io/typescript-play/?jsx=1#code/DwPgUABFEPQxABALgZwLQEsDmA7A9gE4Cmk0A3vjgKIAeGKSROSAvmMDCANxhgAGYOIlSZchEgBIKeanQZNW-HmABEAHUHxk6bPmIqwlWvUbNlMAFQXNwnWOIQAhgBtnEJAAsi7jxhxYUCAsYQxljeTMgA

Related Issues:

@mhegazy
Copy link
Contributor

mhegazy commented Jun 26, 2018

This is actually working as intended. // @ts-ignore is not meant to be a special lexical entity, it is just a marker on the line before, that can be insider another comment, JSX text or a string.

@mhegazy mhegazy added the Working as Intended The behavior described is the intended behavior; this is not a bug label Jun 26, 2018
@typescript-bot
Copy link
Collaborator

Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug
Projects
None yet
Development

No branches or pull requests

3 participants