UNPKG

3.39 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 { ResolvedUrl } from './url';
15/**
16 * Describes a range of text within a source file.
17 *
18 * NOTE: `line` and `column` Position properties are indexed from zero. Consider
19 * displaying them to users as one-indexed numbers to match text editor
20 * conventions.
21 */
22export interface SourceRange {
23 readonly file: ResolvedUrl;
24 readonly start: SourcePosition;
25 readonly end: SourcePosition;
26}
27export interface SourcePosition {
28 /** The line number, starting from zero. */
29 readonly line: number;
30 /** The column offset within the line, starting from zero. */
31 readonly column: number;
32}
33export interface LocationOffset {
34 /** Zero based line index. */
35 readonly line: number;
36 /** Zero based column index. */
37 readonly col: number;
38 /**
39 * The url of the source file.
40 */
41 readonly filename?: ResolvedUrl;
42}
43/**
44 * Corrects source ranges based on an offset.
45 *
46 * Source ranges for inline documents need to be corrected relative to their
47 * positions in their containing documents.
48 *
49 * For example, if a <script> tag appears in the fifth line of its containing
50 * document, we need to move all the source ranges inside that script tag down
51 * by 5 lines. We also need to correct the column offsets, but only for the
52 * first line of the <script> contents.
53 */
54export declare function correctSourceRange(sourceRange: SourceRange, locationOffset?: LocationOffset | null): SourceRange;
55export declare function correctSourceRange(sourceRange: undefined, locationOffset?: LocationOffset | null): undefined;
56export declare function correctSourceRange(sourceRange?: SourceRange, locationOffset?: LocationOffset | null): SourceRange | undefined;
57export declare function correctPosition(position: SourcePosition, locationOffset: LocationOffset): SourcePosition;
58export declare function uncorrectSourceRange(sourceRange?: SourceRange, locationOffset?: LocationOffset | null): SourceRange | undefined;
59export declare function uncorrectPosition(position: SourcePosition, locationOffset: LocationOffset): SourcePosition;
60/**
61 * Returns -1 if source position `a` comes before source position `b`, returns 0
62 * if they are the same, returns 1 if `a` comes after `b`.
63 */
64export declare function comparePosition(a: SourcePosition, b: SourcePosition): number;
65/**
66 * If the position is inside the range, returns 0. If it comes before the range,
67 * it returns -1. If it comes after the range, it returns 1.
68 *
69 * TODO(rictic): test this method directly (currently most of its tests are
70 * indirectly, through ast-from-source-position).
71 */
72export declare function comparePositionAndRange(position: SourcePosition, range: SourceRange, includeEdges?: boolean): 1 | -1 | 0;
73export declare function isPositionInsideRange(position: SourcePosition, range: SourceRange | undefined, includeEdges?: boolean): boolean;