UNPKG

2 kBTypeScriptView Raw
1/**
2 * @license
3 * Copyright (c) 2016 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 * as babel from '@babel/types';
15import { InlineDocInfo, LocationOffset, Severity, SourceRange } from '../model/model';
16import { ResolvedUrl } from '../model/url';
17import { Parser } from '../parser/parser';
18import { UrlResolver } from '../url-loader/url-resolver';
19import { JavaScriptDocument } from './javascript-document';
20export declare type SourceType = 'script' | 'module';
21export declare class JavaScriptParser implements Parser<JavaScriptDocument> {
22 readonly sourceType?: SourceType;
23 parse(contents: string, url: ResolvedUrl, _urlResolver: UrlResolver, inlineInfo?: InlineDocInfo): JavaScriptDocument;
24}
25export declare class JavaScriptModuleParser extends JavaScriptParser {
26 readonly sourceType: SourceType;
27}
28export declare class JavaScriptScriptParser extends JavaScriptParser {
29 readonly sourceType: SourceType;
30}
31export declare type ParseResult = {
32 type: 'success';
33 sourceType: SourceType;
34 parsedFile: babel.File;
35} | {
36 type: 'failure';
37 warningish: {
38 sourceRange: SourceRange;
39 severity: Severity;
40 code: string;
41 message: string;
42 };
43};
44/**
45 * Parse the given contents and return either an AST or a parse error as a
46 * Warning. It needs the filename and the location offset to produce correct
47 * warnings.
48 */
49export declare function parseJs(contents: string, file: ResolvedUrl, locationOffset?: LocationOffset, warningCode?: string, sourceType?: SourceType): ParseResult;