in src/material/schematics/ng-update/migrations/hammer-gestures-v9/hammer-gestures-migration.ts [429:473]
private _checkForRuntimeHammerUsage(node: ts.Node) {
if (this._usedInRuntime) {
return;
}
// Detects usages of "window.Hammer".
if (ts.isPropertyAccessExpression(node) && node.name.text === 'Hammer') {
const originExpr = unwrapExpression(node.expression);
if (ts.isIdentifier(originExpr) && originExpr.text === 'window') {
this._usedInRuntime = true;
}
return;
}
// Detects usages of "window['Hammer']".
if (
ts.isElementAccessExpression(node) &&
ts.isStringLiteral(node.argumentExpression) &&
node.argumentExpression.text === 'Hammer'
) {
const originExpr = unwrapExpression(node.expression);
if (ts.isIdentifier(originExpr) && originExpr.text === 'window') {
this._usedInRuntime = true;
}
return;
}
// Handles usages of plain identifier with the name "Hammer". These usage
// are valid if they resolve to "@types/hammerjs". e.g. "new Hammer(myElement)".
if (
ts.isIdentifier(node) &&
node.text === 'Hammer' &&
!ts.isPropertyAccessExpression(node.parent) &&
!ts.isElementAccessExpression(node.parent)
) {
const symbol = this._getDeclarationSymbolOfNode(node);
if (
symbol &&
symbol.valueDeclaration &&
symbol.valueDeclaration.getSourceFile().fileName.includes('@types/hammerjs')
) {
this._usedInRuntime = true;
}
}
}