I want to start contributing to angular, I have an idea for a feature, I want the template compiler to issue a warning if a template contains two template variables of the same name. I think I managed to get close to the source files responsible: https://github.com/angular/angular/blob/master/packages/compiler/src/view_compiler/view_compiler.ts but couldn't quite find the spot, understandably. Is there anyone here who can guide me ?
- 
        but the compiler is doing that already - Reference "#t" is defined several times ("Max Koretskyi– Max Koretskyi2017-09-14 05:44:15 +00:00Commented Sep 14, 2017 at 5:44
- 
        How embarrassing, you're right... Thanks a lot anyway, I will look at that source file and try to discover how I didn't find out about it when I looked for it.Aviad P.– Aviad P.2017-09-14 07:54:35 +00:00Commented Sep 14, 2017 at 7:54
- 
        1I don't see any embarrassing in wanting to learn more and occassionaly missing something :). I sometimes do that too when working with something unfamiliar. I showed you where the logic you're asking about happens.Max Koretskyi– Max Koretskyi2017-09-14 08:37:15 +00:00Commented Sep 14, 2017 at 8:37
                    
                        Add a comment
                    
                 | 
            
                
            
        
         
    1 Answer
You need to look into the _assertNoReferenceDuplicationOnTemplate method:
  _assertNoReferenceDuplicationOnTemplate(result: TemplateAst[], errors): void {
    const existingReferences: string[] = [];
    result.filter(element => !!(<any>element).references)
       .forEach(element => (<any>element).references.forEach((reference: ReferenceAst) => {
          const name = reference.name;
          if (existingReferences.indexOf(name) < 0) {
            existingReferences.push(name);
          } else {
            const error = new TemplateParseError(
                `Reference "#${name}" is defined several times`, reference.sourceSpan,
                ParseErrorLevel.ERROR);
            errors.push(error);
          }
        }));
  }
Angular compiler creates AST with one node type being ElementAST which has references property:
export class ElementAst implements TemplateAst {
  constructor(
      public name: string,
      public references: ReferenceAst[],
      ...
And this is the property that is checked in the _assertNoReferenceDuplicationOnTemplate function and if found the error is generated.

