Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(ivy): don't crash on an unknown localref target
Previously the template binder would crash when encountering an unknown localref (# reference) such as `<div #ref="foo">` when no directive has `exportAs: "foo"`. With this commit, the compiler instead generates a template diagnostic error informing the user about the invalid reference.
- Loading branch information
Showing
8 changed files
with
119 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/** | ||
* @license | ||
* Copyright Google Inc. All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
|
||
import {AbsoluteSourceSpan, BindingPipe, TmplAstReference} from '@angular/compiler'; | ||
import * as ts from 'typescript'; | ||
|
||
import {ErrorCode, ngErrorCode} from '../../diagnostics'; | ||
|
||
import {TcbSourceResolver, absoluteSourceSpanToSourceLocation, makeTemplateDiagnostic} from './diagnostics'; | ||
|
||
/** | ||
* Collects reports on template diagnostics which are | ||
*/ | ||
export interface OutOfBandDiagnosticRecorder { | ||
readonly diagnostics: ts.Diagnostic[]; | ||
|
||
missingReferenceTarget(id: string, ref: TmplAstReference): void; | ||
} | ||
|
||
export class OutOfBandDiagnosticRecorderImpl implements OutOfBandDiagnosticRecorder { | ||
readonly diagnostics: ts.Diagnostic[] = []; | ||
|
||
constructor(private resolver: TcbSourceResolver) {} | ||
|
||
missingReferenceTarget(id: string, ref: TmplAstReference): void { | ||
const mapping = this.resolver.getSourceMapping(id); | ||
const value = ref.value.trim(); | ||
|
||
const errorMsg = `No directive found with exportAs '${value}'.`; | ||
this.diagnostics.push(makeTemplateDiagnostic( | ||
mapping, ref.valueSpan || ref.sourceSpan, ts.DiagnosticCategory.Error, | ||
ngErrorCode(ErrorCode.MISSING_REFERENCE_TARGET), errorMsg)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters