當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript compiler-cli.getExpressionScope函數代碼示例

本文整理匯總了TypeScript中@angular/compiler-cli.getExpressionScope函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript getExpressionScope函數的具體用法?TypeScript getExpressionScope怎麽用?TypeScript getExpressionScope使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了getExpressionScope函數的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: findAttribute

 const attributeValueSymbol = (ast: AST, inEvent: boolean = false): boolean => {
   const attribute = findAttribute(info);
   if (attribute) {
     if (inSpan(templatePosition, spanOf(attribute.valueSpan))) {
       const dinfo = diagnosticInfoFromTemplateInfo(info);
       const scope = getExpressionScope(dinfo, path, inEvent);
       if (attribute.valueSpan) {
         const expressionOffset = attribute.valueSpan.start.offset + 1;
         const result = getExpressionSymbol(
             scope, ast, templatePosition - expressionOffset, info.template.query);
         if (result) {
           symbol = result.symbol;
           span = offsetSpan(result.span, expressionOffset);
         }
       }
       return true;
     }
   }
   return false;
 };
開發者ID:DanielKucal,項目名稱:angular,代碼行數:20,代碼來源:locate_symbol.ts

示例2: locateSymbol

export function locateSymbol(info: TemplateInfo): SymbolInfo|undefined {
  if (!info.position) return undefined;
  const templatePosition = info.position - info.template.span.start;
  const path = findTemplateAstAt(info.templateAst, templatePosition);
  if (path.tail) {
    let symbol: Symbol|undefined = undefined;
    let span: Span|undefined = undefined;
    const attributeValueSymbol = (ast: AST, inEvent: boolean = false): boolean => {
      const attribute = findAttribute(info);
      if (attribute) {
        if (inSpan(templatePosition, spanOf(attribute.valueSpan))) {
          const dinfo = diagnosticInfoFromTemplateInfo(info);
          const scope = getExpressionScope(dinfo, path, inEvent);
          if (attribute.valueSpan) {
            const expressionOffset = attribute.valueSpan.start.offset + 1;
            const result = getExpressionSymbol(
                scope, ast, templatePosition - expressionOffset, info.template.query);
            if (result) {
              symbol = result.symbol;
              span = offsetSpan(result.span, expressionOffset);
            }
          }
          return true;
        }
      }
      return false;
    };
    path.tail.visit(
        {
          visitNgContent(ast) {},
          visitEmbeddedTemplate(ast) {},
          visitElement(ast) {
            const component = ast.directives.find(d => d.directive.isComponent);
            if (component) {
              symbol = info.template.query.getTypeSymbol(component.directive.type.reference);
              symbol = symbol && new OverrideKindSymbol(symbol, 'component');
              span = spanOf(ast);
            } else {
              // Find a directive that matches the element name
              const directive = ast.directives.find(
                  d => d.directive.selector != null && d.directive.selector.indexOf(ast.name) >= 0);
              if (directive) {
                symbol = info.template.query.getTypeSymbol(directive.directive.type.reference);
                symbol = symbol && new OverrideKindSymbol(symbol, 'directive');
                span = spanOf(ast);
              }
            }
          },
          visitReference(ast) {
            symbol = ast.value && info.template.query.getTypeSymbol(tokenReference(ast.value));
            span = spanOf(ast);
          },
          visitVariable(ast) {},
          visitEvent(ast) {
            if (!attributeValueSymbol(ast.handler, /* inEvent */ true)) {
              symbol = findOutputBinding(info, path, ast);
              symbol = symbol && new OverrideKindSymbol(symbol, 'event');
              span = spanOf(ast);
            }
          },
          visitElementProperty(ast) { attributeValueSymbol(ast.value); },
          visitAttr(ast) {},
          visitBoundText(ast) {
            const expressionPosition = templatePosition - ast.sourceSpan.start.offset;
            if (inSpan(expressionPosition, ast.value.span)) {
              const dinfo = diagnosticInfoFromTemplateInfo(info);
              const scope = getExpressionScope(dinfo, path, /* includeEvent */ false);
              const result =
                  getExpressionSymbol(scope, ast.value, expressionPosition, info.template.query);
              if (result) {
                symbol = result.symbol;
                span = offsetSpan(result.span, ast.sourceSpan.start.offset);
              }
            }
          },
          visitText(ast) {},
          visitDirective(ast) {
            symbol = info.template.query.getTypeSymbol(ast.directive.type.reference);
            span = spanOf(ast);
          },
          visitDirectiveProperty(ast) {
            if (!attributeValueSymbol(ast.value)) {
              symbol = findInputBinding(info, path, ast);
              span = spanOf(ast);
            }
          }
        },
        null);
    if (symbol && span) {
      return {symbol, span: offsetSpan(span, info.template.span.start)};
    }
  }
}
開發者ID:DanielKucal,項目名稱:angular,代碼行數:93,代碼來源:locate_symbol.ts


注:本文中的@angular/compiler-cli.getExpressionScope函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。