UNPKG

3.05 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 * as dom5 from 'dom5/lib/index-next';
16import { ASTNode } from 'parse5';
17import * as shady from 'shady-css-parser';
18import { ParsedCssDocument } from '..';
19import { ParsedHtmlDocument } from '../html/html-document';
20import { JavaScriptDocument } from '../javascript/javascript-document';
21import { Document, ScannedDocument } from './document';
22import { ScannedFeature } from './feature';
23import { Resolvable } from './resolvable';
24import { LocationOffset, SourceRange } from './source-range';
25import { ResolvedUrl } from './url';
26import { Warning } from './warning';
27export interface InlineDocInfo {
28 astNode?: AstNodeWithLanguage;
29 locationOffset?: LocationOffset;
30 baseUrl?: ResolvedUrl;
31}
32export interface HtmlAstNode {
33 language: 'html';
34 node: dom5.Node;
35 containingDocument: ParsedHtmlDocument;
36}
37export interface JsAstNode<N extends babel.Node = babel.Node> {
38 language: 'js';
39 node: N;
40 containingDocument: JavaScriptDocument;
41}
42export interface CssAstNode {
43 language: 'css';
44 node: shady.Node;
45 containingDocument: ParsedCssDocument;
46}
47export declare type AstNodeWithLanguage = HtmlAstNode | JsAstNode | CssAstNode;
48/**
49 * Represents an inline document, usually a <script> or <style> tag in an HTML
50 * document.
51 *
52 * @template N The AST node type
53 */
54export declare class ScannedInlineDocument implements ScannedFeature, Resolvable {
55 readonly type: 'html' | 'js' | 'css' | /* etc */ string;
56 readonly contents: string;
57 /** The location offset of this document within the containing document. */
58 readonly locationOffset: LocationOffset;
59 readonly attachedComment?: string;
60 scannedDocument?: ScannedDocument;
61 readonly sourceRange: SourceRange;
62 readonly warnings: Warning[];
63 readonly astNode: AstNodeWithLanguage;
64 constructor(type: string, contents: string, locationOffset: LocationOffset, attachedComment: string, sourceRange: SourceRange, astNode: AstNodeWithLanguage);
65 resolve(document: Document): Document | undefined;
66}
67declare module './queryable' {
68 interface FeatureKindMap {
69 'inline-document': InlineDocument;
70 }
71}
72export declare class InlineDocument extends Document {
73 constructor(base: ScannedDocument, containerDocument: Document);
74}
75export declare function getAttachedCommentText(node: ASTNode): string | undefined;
76export declare function getLocationOffsetOfStartOfTextContent(node: ASTNode, parsedDocument: ParsedHtmlDocument): LocationOffset;