• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript polymer-analyzer.isPositionInsideRange函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中polymer-analyzer.isPositionInsideRange函数的典型用法代码示例。如果您正苦于以下问题:TypeScript isPositionInsideRange函数的具体用法?TypeScript isPositionInsideRange怎么用?TypeScript isPositionInsideRange使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了isPositionInsideRange函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: getAttributeAstLocation

/**
 * If the position is inside of the node's attributes section, return the
 * correct LocationResult.
 */
function getAttributeAstLocation(
    node: parse5.ASTNode,
    position: SourcePosition,
    document: ParsedHtmlDocument,
    location: Parse5Location): AttributesSection|AttributeValue|undefined {
  /**
   * TODO(rictic): upstream to @types the fact that regular locations (not just
   * element locations) can have attrs sometimes.
   */
  const attrs: parse5.AttributesLocationInfo =
      (isElementLocationInfo(location) && location.startTag.attrs) ||
      location['attrs'] || {};

  for (const attrName in attrs) {
    const range = document.sourceRangeForAttribute(node, attrName);
    if (isPositionInsideRange(position, range)) {
      if (isPositionInsideRange(
              position,
              document.sourceRangeForAttributeValue(node, attrName))) {
        return {kind: 'attributeValue', attribute: attrName, element: node};
      }
      return {kind: 'attribute', attribute: attrName, element: node};
    }
  }
}
开发者ID:Polymer,项目名称:tools,代码行数:29,代码来源:ast-from-source-position.ts


示例2: getDocumentContaining

export function getDocumentContaining(
    sourceRange: SourceRange|undefined, document: Document): ParsedDocument|
    undefined {
  if (!sourceRange) {
    return undefined;
  }
  let mostSpecificDocument: undefined|Document = undefined;
  for (const doc of document.getFeatures({kind: 'document'})) {
    if (isPositionInsideRange(sourceRange.start, doc.sourceRange)) {
      if (!mostSpecificDocument ||
          isPositionInsideRange(
              doc.sourceRange!.start, mostSpecificDocument.sourceRange)) {
        mostSpecificDocument = doc;
      }
    }
  }
  mostSpecificDocument = mostSpecificDocument || document;
  return mostSpecificDocument.parsedDocument;
}
开发者ID:MehdiRaash,项目名称:tools,代码行数:19,代码来源:util.ts


示例3: addImportMetaToElements

  /**
   * Adds a static importMeta property to Polymer elements.
   */
  private addImportMetaToElements(program: Program, scriptDocument: Document) {
    const elements = scriptDocument.getFeatures({'kind': 'polymer-element'});

    for (const element of elements) {
      // This is an analyzer wart. There's no way to avoid getting features
      // from the containing document when querying an inline document. Filed
      // as https://github.com/Polymer/polymer-analyzer/issues/712
      if (element.sourceRange === undefined ||
          !isPositionInsideRange(
              element.sourceRange.start, scriptDocument.sourceRange)) {
        continue;
      }

      const nodePath = getNodePathInProgram(program, element.astNode);

      if (nodePath === undefined) {
        console.warn(
            new Warning({
              code: 'not-found',
              message: `Can't find recast node for element ${element.tagName}`,
              parsedDocument: this.document.parsedDocument,
              severity: Severity.WARNING,
              sourceRange: element.sourceRange!
            }).toString());
        continue;
      }

      const importMeta = jsc.memberExpression(
          jsc.identifier('import'), jsc.identifier('meta'));

      const node = nodePath.node;
      if (node.type === 'ClassDeclaration' || node.type === 'ClassExpression') {
        // A Polymer 2.0 class-based element
        const getter = jsc.methodDefinition(
            'get',
            jsc.identifier('importMeta'),
            jsc.functionExpression(
                null,
                [],
                jsc.blockStatement([jsc.returnStatement(importMeta)])),
            true);
        node.body.body.splice(0, 0, getter);
      } else if (node.type === 'CallExpression') {
        // A Polymer hybrid/legacy factory function element
        const arg = node.arguments[0];
        if (arg && arg.type === 'ObjectExpression') {
          arg.properties.unshift(
              jsc.property('init', jsc.identifier('importMeta'), importMeta));
        }
      } else {
        console.error(`Internal Error, Class or CallExpression expected, got ${
            node.type}`);
      }
    }
  }
开发者ID:,项目名称:,代码行数:58,代码来源:


示例4: getAncestorDomModuleForElement

 private getAncestorDomModuleForElement(
     document: Document, element: dom5.Node) {
   const parsedDocument = document.parsedDocument;
   if (!(parsedDocument instanceof ParsedHtmlDocument)) {
     return;
   }
   const elementSourcePosition =
       parsedDocument.sourceRangeForNode(element)!.start;
   const domModules =
       document.getFeatures({kind: 'dom-module', imported: false});
   for (const domModule of domModules) {
     if (isPositionInsideRange(
             elementSourcePosition,
             parsedDocument.sourceRangeForNode(domModule.node))) {
       return domModule;
     }
   }
 }
开发者ID:Polymer,项目名称:tools,代码行数:18,代码来源:auto-completer.ts


示例5: getCssAstLocationForPosition

export function getCssAstLocationForPosition(
    document: ParsedCssDocument,
    position: SourcePosition): shadyCssParser.Node {
  let closest = document.ast;
  while (true) {
    let containingChild = undefined;
    for (const child of getChildren(closest)) {
      const sourceRange = document.sourceRangeForNode(child);
      if (!sourceRange) {
        continue;
      }
      if (isPositionInsideRange(position, sourceRange)) {
        containingChild = child;
        break;
      }
    }
    if (containingChild === undefined) {
      break;
    }
    closest = containingChild;
  }
  return closest;
}
开发者ID:MehdiRaash,项目名称:tools,代码行数:23,代码来源:ast-from-source-position.ts


示例6: internalGetAstLocationForPosition

function internalGetAstLocationForPosition(
    node: parse5.ASTNode, position: SourcePosition,
    document: ParsedHtmlDocument): undefined|HtmlAstLocation {
  const sourceRange = document.sourceRangeForNode(node);
  const location = node.__location;

  /**
   * An HTML5 parser must hallucinate certain nodes, even if they don't exist
   * in the original source text. e.g. <html> or <body>. So we might have
   * elements that have no sourceRange (because they don't exist in the text)
   * but they do have children that do. So we should check those children.
   */
  if (!(sourceRange && location)) {
    return findLocationInChildren(node, position, document);
  }

  if (!isPositionInsideRange(position, sourceRange)) {
    // definitively not in this node or any of its children
    return;
  }

  const locationInChildren = findLocationInChildren(node, position, document);
  if (locationInChildren) {
    return locationInChildren;
  }

  const attributeAstLocation =
      getAttributeAstLocation(node, position, document, location);
  if (attributeAstLocation) {
    return attributeAstLocation;
  }

  const startTagRange = document.sourceRangeForStartTag(node);
  const endTagRange = document.sourceRangeForEndTag(node);

  // If we're in the end tag... we're in the end tag.
  if (isPositionInsideRange(position, endTagRange, false)) {
    return {kind: 'endTag', element: node};
  }

  if (startTagRange && isPositionInsideRange(position, startTagRange, false)) {
    if (position.line === startTagRange.start.line) {
      // If the cursor is in the "<my-elem" part of the start tag.
      if (position.column <=
          startTagRange.start.column + (node.tagName || '').length + 1) {
        return {kind: 'tagName', element: node};
      }
    }
    // Otherwise we're in the start tag, but not in the tag name or any
    // particular attribute, but definitely in the attributes section.
    return {kind: 'attribute', attribute: null, element: node};
  }

  // The edges of a comment aren't part of the comment.
  if (parse5.treeAdapters.default.isCommentNode(node) &&
      isPositionInsideRange(position, sourceRange, false)) {
    return {kind: 'comment', commentNode: node};
  }

  if (parse5.treeAdapters.default.isTextNode(node)) {
    const parent = node.parentNode;
    if (parent && parent.tagName === 'script') {
      return {kind: 'scriptTagContents', textNode: node};
    }
    if (parent && parent.tagName === 'style') {
      return {kind: 'styleTagContents', textNode: node};
    }
    return {kind: 'text', textNode: node};
  }


  if (isPositionInsideRange(position, sourceRange, false)) {
    /**
     * This is tricky. Consider the position inside an empty element, i.e.
     * here:
     *    <script>|</script>.
     *
     * You can be between the start and end tags, but there won't be a text
     * node to attach to, but if you started typeing, there would be, so we
     * want to treat you as though you are.
     */
    if (startTagRange && endTagRange &&
        comparePositionAndRange(position, startTagRange, false) > 0 &&
        comparePositionAndRange(position, endTagRange, false) < 0) {
      if (node.tagName === 'script') {
        return {kind: 'scriptTagContents'};
      }
      if (node.tagName === 'style') {
        return {kind: 'styleTagContents'};
      }
      return {kind: 'text'};
    }

    /**
     * Ok, we're in this node, we're not in any of its children, but we're not
     * obviously in any attribute, tagname, start tag, or end tag. We might be
     * part of a unclosed tag in a mostly empty document. parse5 doesn't give
     * us much explicit signal in this case, but we can kinda infer it from the
     * tagName.
     */
//.........这里部分代码省略.........
开发者ID:MehdiRaash,项目名称:tools,代码行数:101,代码来源:ast-from-source-position.ts


示例7: getFeatureForAstLocation

  /**
   * Given an AstLocation, return a high level feature.
   */
  getFeatureForAstLocation(
      astWrapperLocation: AstLocation, position: SourcePosition): FoundFeature
      |undefined {
    if (astWrapperLocation.language === 'css') {
      const {document, node} = astWrapperLocation;
      const cssFeatures =
          new Set<CssCustomPropertyAssignment|CssCustomPropertyUse>([
            ...document.getFeatures({kind: 'css-custom-property-assignment'}),
            ...document.getFeatures({kind: 'css-custom-property-use'})
          ]);
      const nodeRange = document.parsedDocument.sourceRangeForNode(node);
      if (!nodeRange) {
        return;
      }
      for (const feature of cssFeatures) {
        if (isContained(feature.sourceRange, nodeRange)) {
          return {document, feature};
        }
      }
      return;
    }
    const document = astWrapperLocation.document;
    const htmlLocation = astWrapperLocation.node;
    if (htmlLocation.kind === 'tagName') {
      const feature = getOnly(document.getFeatures({
        kind: 'element',
        id: htmlLocation.element.nodeName,
        imported: true,
        externalPackages: true
      }));
      if (feature) {
        return {document, feature};
      }
      return;
    } else if (htmlLocation.kind === 'attribute') {
      const elements = document.getFeatures({
        kind: 'element',
        id: htmlLocation.element.nodeName,
        imported: true,
        externalPackages: true
      });
      if (elements.size === 0) {
        return;
      }

      const feature = concatMap(elements, (el) => el.attributes.values())
                          .find(at => at.name === htmlLocation.attribute);
      if (feature) {
        return {document, feature};
      }
      return;
    } else if (
        htmlLocation.kind === 'attributeValue' ||
        htmlLocation.kind === 'text') {
      const domModules = document.getFeatures({kind: 'dom-module'});
      for (const domModule of domModules) {
        if (!domModule.id) {
          continue;
        }
        const elements = document.getFeatures({
          kind: 'polymer-element',
          id: domModule.id,
          imported: true,
          externalPackages: true
        });
        if (elements.size !== 1) {
          continue;
        }
        const element = elements.values().next().value!;
        if (isPositionInsideRange(position, domModule.sourceRange)) {
          for (const databinding of domModule.databindings) {
            if (isPositionInsideRange(
                    position, databinding.sourceRange, true)) {
              for (const prop of databinding.properties) {
                if (isPositionInsideRange(position, prop.sourceRange, true)) {
                  return {
                    feature: new DatabindingFeature(
                        element, databinding, prop.name, prop.sourceRange),
                    document
                  };
                }
              }
              return {
                feature: new DatabindingFeature(
                    element, databinding, undefined, undefined),
                document
              };
            }
          }
        }
      }
    }
  }
开发者ID:asdfg9822,项目名称:polymer-editor-service,代码行数:96,代码来源:feature-finder.ts


示例8: isContained

function isContained(inner: SourceRange, outer: SourceRange) {
  return isPositionInsideRange(inner.start, outer, true) &&
      isPositionInsideRange(inner.end, outer, true);
}
开发者ID:asdfg9822,项目名称:polymer-editor-service,代码行数:4,代码来源:feature-finder.ts


示例9: inlineTemplates

  /**
   * Find Polymer element templates in the original HTML. Insert these
   * templates as strings as part of the javascript element declaration.
   */
  private inlineTemplates(program: Program, scriptDocument: Document) {
    const elements = scriptDocument.getFeatures({'kind': 'polymer-element'});
    const claimedDomModules = new Set<parse5.ASTNode>();

    for (const element of elements) {
      // This is an analyzer wart. There's no way to avoid getting features
      // from the containing document when querying an inline document. Filed
      // as https://github.com/Polymer/polymer-analyzer/issues/712
      if (element.sourceRange === undefined ||
          !isPositionInsideRange(
              element.sourceRange.start, scriptDocument.sourceRange)) {
        continue;
      }
      const domModule = element.domModule;
      if (domModule === undefined) {
        continue;
      }
      if (!canDomModuleBeInlined(domModule)) {
        continue;
      }
      claimedDomModules.add(domModule);
      const template = dom5.query(domModule, (e) => e.tagName === 'template');
      if (template === null) {
        continue;
      }

      // It's ok to tag templates with the expression `Polymer.html` without
      // adding an import because `Polymer.html` is re-exported by both
      // polymer.html and polymer-element.html and, crucially, template
      // inlining happens before rewriting references.
      const templateLiteral = jsc.taggedTemplateExpression(
          jsc.memberExpression(
              jsc.identifier('Polymer'), jsc.identifier('html')),
          serializeNodeToTemplateLiteral(
              parse5.treeAdapters.default.getTemplateContent(template)));
      const nodePath = getNodePathInProgram(program, element.astNode);

      if (nodePath === undefined) {
        console.warn(
            new Warning({
              code: 'not-found',
              message: `Can't find recast node for element ${element.tagName}`,
              parsedDocument: this.document.parsedDocument,
              severity: Severity.WARNING,
              sourceRange: element.sourceRange!
            }).toString());
        continue;
      }

      const node = nodePath.node;
      if (node.type === 'ClassDeclaration' || node.type === 'ClassExpression') {
        // A Polymer 2.0 class-based element
        node.body.body.splice(
            0,
            0,
            jsc.methodDefinition(
                'get',
                jsc.identifier('template'),
                jsc.functionExpression(
                    null, [], jsc.blockStatement([jsc.returnStatement(
                                  templateLiteral)])),
                true));
      } else if (node.type === 'CallExpression') {
        // A Polymer hybrid/legacy factory function element
        const arg = node.arguments[0];
        if (arg && arg.type === 'ObjectExpression') {
          arg.properties.unshift(jsc.property(
              'init', jsc.identifier('_template'), templateLiteral));
        }
      } else {
        console.error(`Internal Error, Class or CallExpression expected, got ${
            node.type}`);
      }
    }
    return claimedDomModules;
  }
开发者ID:,项目名称:,代码行数:80,代码来源:



注:本文中的polymer-analyzer.isPositionInsideRange函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript polymer-analyzer.makeParseLoader函数代码示例发布时间:2022-05-25
下一篇:
TypeScript polymer-analyzer.applyEdits函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap