當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。