UNPKG

3.55 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 { Document, FileRelativeUrl, Import, JsAstNode, ResolvedUrl, ScannedImport, Warning } from '../model/model';
17import { Visitor } from './estree-visitor';
18import { JavaScriptDocument } from './javascript-document';
19import { JavaScriptScanner } from './javascript-scanner';
20import { SourceRange } from '../model/model';
21import { DeclaredWithStatement } from '../model/document';
22export interface JavaScriptImportScannerOptions {
23 /**
24 * Algorithm to use for resolving module specifiers in import
25 * and export statements when converting them to URLs.
26 * A value of 'node' uses Node.js resolution to find modules.
27 *
28 * If this argument is not given, module specifiers must be web-compatible
29 * urls.
30 */
31 moduleResolution?: 'node';
32}
33export declare type ImportNode = babel.ImportDeclaration | babel.CallExpression | babel.ExportAllDeclaration | babel.ExportNamedDeclaration;
34export declare class ScannedJavascriptImport extends ScannedImport {
35 readonly type: 'js-import';
36 readonly specifier: string;
37 readonly statementAst: babel.Statement | undefined;
38 readonly astNode: JsAstNode<ImportNode>;
39 readonly astNodePath: NodePath<babel.Node>;
40 constructor(url: FileRelativeUrl | undefined, sourceRange: SourceRange | undefined, urlSourceRange: SourceRange | undefined, ast: JsAstNode<ImportNode>, astNodePath: NodePath<babel.Node>, lazy: boolean, originalSpecifier: string, statementAst: babel.Statement | undefined);
41 protected constructImport(resolvedUrl: ResolvedUrl, relativeUrl: FileRelativeUrl, importedDocument: Document | undefined, _containingDocument: Document): JavascriptImport;
42}
43declare module '../model/queryable' {
44 interface FeatureKindMap {
45 'js-import': JavascriptImport;
46 }
47}
48export declare class JavascriptImport extends Import implements DeclaredWithStatement {
49 /**
50 * The original text of the specifier. Unlike `this.url`, this may not
51 * be a URL, but may be a bare module specifier, like 'jquery'.
52 */
53 readonly specifier: string;
54 readonly statementAst: babel.Statement | undefined;
55 readonly astNode: JsAstNode<ImportNode>;
56 readonly astNodePath: NodePath<babel.Node>;
57 constructor(url: ResolvedUrl, originalUrl: FileRelativeUrl, type: string, document: Document | undefined, sourceRange: SourceRange | undefined, urlSourceRange: SourceRange | undefined, ast: JsAstNode<ImportNode>, astNodePath: NodePath<babel.Node>, warnings: Warning[], lazy: boolean, specifier: string, statementAst: babel.Statement | undefined);
58}
59export declare class JavaScriptImportScanner implements JavaScriptScanner {
60 moduleResolution?: 'node';
61 constructor(options?: JavaScriptImportScannerOptions);
62 scan(document: JavaScriptDocument, visit: (visitor: Visitor) => Promise<void>): Promise<{
63 features: ScannedJavascriptImport[];
64 warnings: Warning[];
65 }>;
66 private _resolveSpecifier;
67}