fkling / astexplorer

A web tool to explore the ASTs generated by various parsers.
https://astexplorer.net/
MIT License
6.2k stars 739 forks source link

fix: site stuck in infinite loop #608

Closed shaharkazaz closed 2 years ago

shaharkazaz commented 3 years ago

This PR fixes the following issues:

  1. When using the Angular HTML parser, the site crashes (stuck in an infinite loop) with the following template:
<div *ngFor="let hero of heroes; let i=index; let odd=odd; trackBy: trackById">
  ({{i}}) {{hero.name}}
</div>

This is caused by the fixSpan method, which isn't handling bound attributes from structural directives and has a while loop with a stop condition that doesn't meet in this case.

  1. The attribute span indexes are incorrect since it returns the first = index after the attribute, for example:
<div *ngFor="let hero of heroes; let i=index; let odd=odd; trackBy: trackById" [class.odd]="odd">
  ({{i}}) {{hero.name}}
</div>
  1. The input span indexes are wrong for inputs with structural directives ([class.odd]="odd")

The span for this attribute should be {start: 92, end: 95} but it's actually {start: 184, end: 187} this is because this attribute is referenced both as an input to the Template node and as an input to the Element node (the div)

shaharkazaz commented 3 years ago

@fkling Can you please review? 🙂

shaharkazaz commented 2 years ago

@fkling Can this be reviewed? still crashes the site

fkling commented 2 years ago

Thank you for taking the time to fix this @shaharkazaz! I apologize for being negligent with keep astexplorer up-to-date... Since I'm not familiar with the Angular parser there is not much for me to review, I trust that this is the right thing to do. It certainly fixes the issues you pointed out. Thank you again!