-
Notifications
You must be signed in to change notification settings - Fork 25.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(compiler-cli): symbol feature detection for the compiler (#54711)
Use the actual symbol presence in the .d.ts to detect whether two-way binding to writable signals should be template type-checked. PR Close #54711
- Loading branch information
Showing
2 changed files
with
43 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/** | ||
* @license | ||
* Copyright Google LLC 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 {ExternalReference} from '@angular/compiler'; | ||
import ts from 'typescript'; | ||
|
||
export function coreHasSymbol(program: ts.Program, symbol: ExternalReference): boolean|null { | ||
const checker = program.getTypeChecker(); | ||
for (const sf of program.getSourceFiles().filter(isMaybeCore)) { | ||
const sym = checker.getSymbolAtLocation(sf); | ||
if (sym === undefined || sym.exports === undefined) { | ||
continue; | ||
} | ||
if (!sym.exports.has('ɵɵtemplate' as ts.__String)) { | ||
// This is not @angular/core. | ||
continue; | ||
} | ||
return sym.exports.has(symbol.name as ts.__String); | ||
} | ||
// No @angular/core file found, so we have no information. | ||
return null; | ||
} | ||
|
||
export function isMaybeCore(sf: ts.SourceFile): boolean { | ||
return sf.isDeclarationFile && sf.fileName.includes('@angular/core') && | ||
sf.fileName.endsWith('index.d.ts'); | ||
} |