fix($parse): properly handle dots at the end of identifiers

Fixes #4613
Fixes #4912
this line is unreadable by Slovak and German eyes (I know that Polish and French eyes are better at this). Can we rewrite it to:

```
lastDot = ident.lastIndexOf('.');
if (lastDot === -1) {
  lastDot = undefined;
}
```

thanks!