Failed to parse file typescript[.tsc]

Hello there.

We are using SonarQube Enterprise EditionVersion 10.4.1 (build 88267) on server.
We are using AzureDevops.

Our scan fails with Failed to Parse file error:

##[error]ERROR: Failed to parse file [src/app/guard/clientGurad.ts] at line 16: A parameter property is only allowed in a constructor implementation.
ERROR: Failed to parse file [src/app/guard/clientGurad.ts] at line 16: A parameter property is only allowed in a constructor implementation.

This is a fragment of the clientGurad.ts file:

export class clientGuard implements CanActivate{
    constructor(private router: Router,
        private validateToken: ValidatetokenService
    ){}

    //@ts-ignore
    canActivate(private route: ActivatedRouteSnapshot){

        let tokenURL = route.paramMap.get('token');
        this.validateToken.queryValidateToken(tokenURL).subscribe((data: genericTokenR) =>{
            if(data.successfull){
                return true;
            }else{
                this.router.navigate(['/notfound']);
                return false;
            }
        })
    }
}

Please help us to solve this.

Thanks!

Hi Alejandro,

what’s the purpose of having private in the method argument? This is not valid syntax, so it’s expected that the parser will fail.

Hi, Tibor.

Thanks for your respond.

The developer tells me that “to get the token and validate it to know if the user has access to the path he wants to access and if not redirect him to the login”. Also, that this is the first time that this error occurs in Sonar since the code has been there for a long time and the error has never happened before.

Hi,

I understand the meaning of the code. However, the private keyword should simply not be there. It’s not a valid syntax, so the parser failure is the intended behavior.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.