UNPKG

6.8 kBTypeScriptView Raw
1/**
2 * @license
3 * Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
4 * This code may only be used under the BSD style license found at
5 * http://polymer.github.io/LICENSE.txt
6 * The complete set of authors may be found at
7 * http://polymer.github.io/AUTHORS.txt
8 * The complete set of contributors may be found at
9 * http://polymer.github.io/CONTRIBUTORS.txt
10 * Code distributed by Google as part of the polymer project is also
11 * subject to an additional IP rights grant found at
12 * http://polymer.github.io/PATENTS.txt
13 */
14import { NodePath } from '@babel/traverse';
15import * as babel from '@babel/types';
16import * as doctrine from 'doctrine';
17import { MethodParam, ScannedMethod, ScannedProperty } from '../index';
18import { Result } from '../model/analysis';
19import { ImmutableSet } from '../model/immutable';
20import { Privacy } from '../model/model';
21import { ScannedEvent, SourceRange, Warning } from '../model/model';
22import { ParsedDocument } from '../parser/document';
23import { JavaScriptDocument } from './javascript-document';
24import * as jsdoc from './jsdoc';
25/**
26 * Returns whether a Babel node matches a particular object path.
27 *
28 * e.g. you have a MemberExpression node, and want to see whether it represents
29 * `Foo.Bar.Baz`:
30 * matchesCallExpressio
31 (node, ['Foo', 'Bar', 'Baz'])
32 *
33 * @param {babel.Node} expression The Babel node to match against.
34 * @param {Array<string>} path The path to look for.
35 */
36export declare function matchesCallExpression(expression: babel.MemberExpression, path: string[]): boolean;
37export declare type PropertyOrMethod = babel.ObjectProperty | babel.ObjectMethod | babel.ClassMethod | babel.AssignmentProperty;
38/**
39 * Given a property or method, return its name, or undefined if that name can't
40 * be determined.
41 */
42export declare function getPropertyName(prop: PropertyOrMethod): string | undefined;
43/**
44 * Yields properties and methods, filters out spread expressions or anything
45 * else.
46 */
47export declare function getSimpleObjectProperties(node: babel.ObjectExpression): IterableIterator<babel.ObjectMember>;
48/** Like getSimpleObjectProperties but deals with paths. */
49export declare function getSimpleObjectPropPaths(nodePath: NodePath<babel.ObjectExpression>): IterableIterator<NodePath<babel.ObjectMethod> | NodePath<babel.ObjectProperty>>;
50export declare const CLOSURE_CONSTRUCTOR_MAP: Map<string, string>;
51/**
52 * AST expression -> Closure type.
53 *
54 * Accepts literal values, and native constructors.
55 *
56 * @param {Node} node A Babel expression node.
57 * @return {string} The type of that expression, in Closure terms.
58 */
59export declare function getClosureType(node: babel.Node, parsedJsdoc: doctrine.Annotation | undefined, sourceRange: SourceRange, document: ParsedDocument): Result<string, Warning>;
60/**
61 * Tries to find the comment for the given node.
62 *
63 * Will look up the tree at comments on parents as appropriate, but should
64 * not look at unrelated nodes. Stops at the nearest statement boundary.
65 */
66export declare function getBestComment(nodePath: NodePath): string | undefined;
67export declare function getAttachedComment(node: babel.Node): string | undefined;
68/**
69 * Returns all comments from a tree defined with @event.
70 */
71export declare function getEventComments(node: babel.Node): Map<string, ScannedEvent>;
72export declare function getPropertyValue(node: babel.ObjectExpression, name: string): babel.Node | undefined;
73/**
74 * Create a ScannedMethod object from an estree Property AST node.
75 */
76export declare function toScannedMethod(node: babel.ObjectProperty | babel.ObjectMethod | babel.ClassMethod, sourceRange: SourceRange, document: JavaScriptDocument): ScannedMethod;
77export declare function getReturnFromAnnotation(jsdocAnn: jsdoc.Annotation): {
78 type?: string;
79 desc?: string;
80} | undefined;
81/**
82 * Examine the body of a function to see if we can infer something about its
83 * return type. This currently only handles the case where a function definitely
84 * returns void.
85 */
86export declare function inferReturnFromBody(node: babel.Function): {
87 type: string;
88} | undefined;
89export declare function toMethodParam(nodeParam: babel.LVal, jsdocAnn?: jsdoc.Annotation): MethodParam;
90export declare function getOrInferPrivacy(name: string, annotation: jsdoc.Annotation | undefined, defaultPrivacy?: Privacy): Privacy;
91/**
92 * Properties on element prototypes that are part of the custom elment
93 * lifecycle or Polymer configuration syntax.
94 *
95 * TODO(rictic): only treat the Polymer ones as private when dealing with
96 * Polymer.
97 */
98export declare const configurationProperties: ImmutableSet<string>;
99/**
100 * Scan any methods on the given node, if it's a class expression/declaration.
101 */
102export declare function getMethods(node: babel.Node, document: JavaScriptDocument): Map<string, ScannedMethod>;
103export declare function getConstructorMethod(astNode: babel.Node, document: JavaScriptDocument): ScannedMethod | undefined;
104export declare function getConstructorClassMethod(astNode: babel.Class): babel.ClassMethod | undefined;
105/**
106 * Scan any static methods on the given node, if it's a class
107 * expression/declaration.
108 */
109export declare function getStaticMethods(node: babel.Node, document: JavaScriptDocument): Map<string, ScannedMethod>;
110export declare function extractPropertyFromGetterOrSetter(method: babel.ClassMethod | babel.ObjectMethod, jsdocAnn: jsdoc.Annotation | undefined, document: JavaScriptDocument): ScannedProperty | null;
111/**
112 * Extracts properties (including accessors) from a given class
113 * or object expression.
114 */
115export declare function extractPropertiesFromClassOrObjectBody(node: babel.Class | babel.ObjectExpression, document: JavaScriptDocument): Map<string, ScannedProperty>;
116/**
117 * Get the canonical statement or declaration for the given node.
118 *
119 * It would otherwise be difficult, or require specialized code for each kind of
120 * feature, to determine which node is the canonical node for a feature. This
121 * function is simple, it only walks up, and it stops once it reaches a clear
122 * feature boundary. And since we're calling this function both on the indexing
123 * and the lookup sides, we can be confident that both will agree on the same
124 * node.
125 *
126 * There may be more than one feature within a single statement (e.g. `export
127 * class Foo {}` is both a Class and an Export, but between `kind` and `id` we
128 * should still have enough info to narrow down to the intended feature.
129 *
130 * See `DeclaredWithStatement` and `BaseDocumentQuery` to see where this is
131 * used.
132 */
133export declare function getCanonicalStatement(nodePath: NodePath): babel.Statement | undefined;
134/** What names does a declaration assign to? */
135export declare function getBindingNamesFromDeclaration(declaration: babel.Declaration | null | undefined): IterableIterator<string>;