当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript polymer-analyzer.Document类代码示例

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


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

示例1: _getDependencies

  function _getDependencies(document: Document, viaEager: boolean) {
    // HTML document dependencies include external modules referenced by script
    // src attribute, external modules imported by inline module import
    // statements, and HTML imports (recursively).
    if (document.kinds.has('html-document')) {
      _getHtmlExternalModuleDependencies(document);
      _getHtmlInlineModuleDependencies(document);
      _getImportDependencies(
          document.getFeatures({kind: 'html-import', ...getFeaturesOptions}),
          viaEager);
    }

    // JavaScript documents, when parsed as modules, have dependencies defined
    // by their import statements.
    if (document.kinds.has('js-document')) {
      _getImportDependencies(
          // TODO(usergenic): We should be able to filter here on:
          // `.filter((d) => d.parsedAsSourceType === 'module')`
          // here, but Analyzer wont report that if there are no
          // import/export statements in the imported file.
          document.getFeatures({kind: 'js-import', ...getFeaturesOptions}) as
              Set<Import>,
          viaEager);
    }
  }
开发者ID:MehdiRaash,项目名称:tools,代码行数:25,代码来源:deps-index.ts

示例2: getCustomPropertyAssignmentCompletions

 private getCustomPropertyAssignmentCompletions(
     document: Document, assignment: CssCustomPropertyAssignment) {
   const propertyAssignments = document.getFeatures({
     kind: 'css-custom-property-assignment',
     imported: true,
     externalPackages: true
   });
   const propertyUses = document.getFeatures({
     kind: 'css-custom-property-use',
     imported: true,
     externalPackages: true
   });
   const names = new Set<string>();
   for (const assignment of propertyAssignments) {
     names.add(assignment.name);
   }
   for (const use of propertyUses) {
     names.add(use.name);
   }
   names.delete(assignment.name);
   const items = [...names].sort().map((name): CompletionItem => {
     return {label: name, kind: CompletionItemKind.Variable};
   });
   return {isIncomplete: false, items};
 }
开发者ID:Polymer,项目名称:tools,代码行数:25,代码来源:auto-completer.ts

示例3: getEs6ImportResolutions

 getEs6ImportResolutions(document: Document): Map<string, ResolvedUrl> {
   const jsImports = document.getFeatures({
     kind: 'js-import',
     imported: false,
     externalPackages: true,
     excludeBackreferences: true,
   });
   const resolutions = new Map<string, ResolvedUrl>();
   for (const jsImport of jsImports) {
     const node = jsImport.astNode.node;
     if ('source' in node) {
       if (node.source && jsImport.document !== undefined) {
         resolutions.set(node.source.value, jsImport.document.url);
       }
     } else if (
         node.callee && node.callee.type + '' === 'Import' &&
         jsImport.document !== undefined) {
       const source = node.arguments[0];
       if (source) {
         if (babel.isStringLiteral(source)) {
           resolutions.set(source.value, jsImport.document.url);
         }
       }
     }
   }
   return resolutions;
 }
开发者ID:Polymer,项目名称:tools,代码行数:27,代码来源:es6-rewriter.ts

示例4: _rollupInlineModuleScripts

 /**
  * Inlines the contents of external module scripts and rolls-up imported
  * modules into inline scripts.
  */
 private async _rollupInlineModuleScripts(ast: ASTNode) {
   this.document = await this._reanalyze(serialize(ast));
   rewriteObject(ast, this.document.parsedDocument.ast);
   dom5.removeFakeRootElements(ast);
   const es6Rewriter =
       new Es6Rewriter(this.bundler, this.manifest, this.assignedBundle);
   const inlineModuleScripts =
       [...this.document.getFeatures({
         kind: 'js-document',
         imported: false,
         externalPackages: true,
         excludeBackreferences: true,
       })].filter(({
                    isInline,
                    parsedDocument: {parsedAsSourceType}
                  }) => isInline && parsedAsSourceType === 'module');
   for (const inlineModuleScript of inlineModuleScripts) {
     const ast = clone(inlineModuleScript.parsedDocument.ast);
     const importResolutions =
         es6Rewriter.getEs6ImportResolutions(inlineModuleScript);
     es6Rewriter.rewriteEs6SourceUrlsToResolved(ast, importResolutions);
     const serializedCode = serializeEs6(ast).code;
     const {code} = await es6Rewriter.rollup(
         this.document.parsedDocument.baseUrl,
         serializedCode,
         inlineModuleScript);
     if (inlineModuleScript.astNode &&
         inlineModuleScript.astNode.language === 'html') {
       // Second argument 'true' tells encodeString to escape the <script>
       // content.
       dom5.setTextContent(
           inlineModuleScript.astNode.node, encodeString(`\n${code}\n`, true));
     }
   }
 }
开发者ID:Polymer,项目名称:tools,代码行数:39,代码来源:html-bundler.ts

示例5: getElementTagCompletions

 private getElementTagCompletions(
     document: Document, location: TagName|TextNode) {
   const elements = [
     ...document.getFeatures(
         {kind: 'element', externalPackages: true, imported: true})
   ].filter((e) => e.tagName);
   const prefix = location.kind === 'tagName' ? '' : '<';
   const items = elements.map((e) => {
     const tagName = e.tagName!;
     const item: CompletionItem = {
       label: `<${tagName}>`,
       documentation: this.documentationFromMarkdown(e.description),
       filterText: tagName.replace(/-/g, ''),
       kind: CompletionItemKind.Class,
       insertText: `${prefix}${e.tagName}></${e.tagName}>`
     };
     if (this.clientSupportsSnippets) {
       item.insertText =
           `${prefix}${this.generateAutoCompletionForElement(e)}`;
       item.insertTextFormat = InsertTextFormat.Snippet;
     }
     return item;
   });
   return {isIncomplete: false, items};
 }
开发者ID:Polymer,项目名称:tools,代码行数:25,代码来源:auto-completer.ts

示例6: _inlineModuleScripts

 /**
  * Inlines the contents of external module scripts and rolls-up imported
  * modules into inline scripts.
  */
 private async _inlineModuleScripts(ast: ASTNode) {
   this.document = await this._reanalyze(serialize(ast));
   rewriteObject(ast, this.document.parsedDocument.ast);
   dom5.removeFakeRootElements(ast);
   const es6Rewriter =
       new Es6Rewriter(this.bundler, this.manifest, this.assignedBundle);
   const inlineModuleScripts =
       [...this.document.getFeatures({
         kind: 'js-document',
         imported: false,
         externalPackages: true,
         excludeBackreferences: true,
       })].filter(({
                    isInline,
                    parsedDocument: {parsedAsSourceType}
                  }) => isInline && parsedAsSourceType === 'module');
   for (const inlineModuleScript of inlineModuleScripts) {
     const {code} = await es6Rewriter.rollup(
         this.document.parsedDocument.baseUrl,
         inlineModuleScript.parsedDocument.contents);
     // Second argument 'true' tells encodeString to escape the <script>
     // content.
     dom5.setTextContent(
         (inlineModuleScript.astNode as any).node,
         encodeString(`\n${code}\n`, true));
   }
 }
开发者ID:Polymer,项目名称:vulcanize,代码行数:31,代码来源:html-bundler.ts

示例7: getAstAtPosition

 async getAstAtPosition(document: Document, position: SourcePosition):
     Promise<AstLocation|undefined> {
   const parsedDocument = document.parsedDocument;
   if (parsedDocument instanceof ParsedHtmlDocument) {
     const node = getHtmlAstLocationForPosition(parsedDocument, position);
     // The position is in an inline style tag, so we need to get its
     // Document and recurse through into it to find the best match.
     if (node && node.kind === 'styleTagContents' && node.textNode) {
       const cssDocuments = document.getFeatures({kind: 'css-document'});
       const styleElement = node.textNode.parentNode;
       for (const cssDocument of cssDocuments) {
         if (cssDocument.astNode === styleElement) {
           return this.getAstAtPosition(cssDocument, position);
         }
       }
     }
     return {language: 'html', document, node};
   } else if (parsedDocument instanceof ParsedCssDocument) {
     return {
       language: 'css',
       document,
       node: getCssAstLocationForPosition(parsedDocument, position)
     };
   }
 }
开发者ID:asdfg9822,项目名称:polymer-editor-service,代码行数:25,代码来源:feature-finder.ts

示例8: getSlotNameCompletions

 private getSlotNameCompletions(document: Document, location: AttributeValue) {
   const parent = location.element.parentNode;
   if (!parent || !parent.tagName) {
     return {isIncomplete: false, items: []};
   }
   const parentDefinitions = document.getFeatures({
     kind: 'element',
     id: parent.tagName,
     imported: true,
     externalPackages: true
   });
   const slotNames = new Set();
   for (const parentDefn of parentDefinitions) {
     for (const slot of parentDefn.slots) {
       if (slot.name) {
         slotNames.add(slot.name);
       }
     }
   }
   const items = [...slotNames].map((name): CompletionItem => {
     return {
       label: name,
       kind: CompletionItemKind.Variable,
     };
   });
   return {isIncomplete: false, items};
 }
开发者ID:Polymer,项目名称:tools,代码行数:27,代码来源:auto-completer.ts

示例9: getModuleExportNames

export function getModuleExportNames(document: Document): Set<string> {
  const exports_ = document.getFeatures({kind: 'export'});
  const identifiers = new Set<string>();
  for (const export_ of exports_) {
    for (const identifier of export_.identifiers) {
      identifiers.add(identifier);
    }
  }
  return identifiers;
}
开发者ID:MehdiRaash,项目名称:tools,代码行数:10,代码来源:es6-module-utils.ts

示例10: 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,代码来源:


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