@marko/language-tools 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/extractors/script/index.d.ts +19 -0
- package/dist/extractors/script/util/attach-scopes.d.ts +60 -0
- package/dist/extractors/script/util/is-valid-identifier.d.ts +1 -0
- package/dist/extractors/script/util/jsdoc-input-type.d.ts +9 -0
- package/dist/extractors/script/util/runtime-overrides.d.ts +1 -0
- package/dist/extractors/script/util/script-parser.d.ts +7 -0
- package/dist/extractors/style/index.d.ts +11 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +2842 -0
- package/dist/index.mjs +2808 -0
- package/dist/parser.d.ts +227 -0
- package/dist/util/extractor.d.ts +28 -0
- package/dist/util/get-node-at-offset.d.ts +2 -0
- package/marko.internal.d.ts +520 -0
- package/package.json +56 -0
package/dist/parser.d.ts
ADDED
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
import { type Range, type Ranges, TagType } from "htmljs-parser";
|
|
2
|
+
export type Repeated<T> = [T, ...T[]] | [...T[], T] | [T, ...T[], T];
|
|
3
|
+
export type Repeatable<T> = undefined | Repeated<T>;
|
|
4
|
+
export declare const UNFINISHED: number;
|
|
5
|
+
export { getLines, getPosition, getLocation, type Range, type Ranges, type Position, type Location, } from "htmljs-parser";
|
|
6
|
+
export type Parsed = ReturnType<typeof parse>;
|
|
7
|
+
export declare enum NodeType {
|
|
8
|
+
Program = 0,
|
|
9
|
+
Tag = 1,
|
|
10
|
+
OpenTagName = 2,
|
|
11
|
+
ShorthandId = 3,
|
|
12
|
+
ShorthandClassName = 4,
|
|
13
|
+
TagTypeArgs = 5,
|
|
14
|
+
TagTypeParams = 6,
|
|
15
|
+
TagVar = 7,
|
|
16
|
+
TagArgs = 8,
|
|
17
|
+
TagParams = 9,
|
|
18
|
+
AttrNamed = 10,
|
|
19
|
+
AttrName = 11,
|
|
20
|
+
AttrArgs = 12,
|
|
21
|
+
AttrValue = 13,
|
|
22
|
+
AttrMethod = 14,
|
|
23
|
+
AttrSpread = 15,
|
|
24
|
+
AttrTag = 16,
|
|
25
|
+
Text = 17,
|
|
26
|
+
CDATA = 18,
|
|
27
|
+
Doctype = 19,
|
|
28
|
+
Declaration = 20,
|
|
29
|
+
Comment = 21,
|
|
30
|
+
Placeholder = 22,
|
|
31
|
+
Scriptlet = 23,
|
|
32
|
+
Import = 24,
|
|
33
|
+
Export = 25,
|
|
34
|
+
Class = 26,
|
|
35
|
+
Style = 27,
|
|
36
|
+
Static = 28
|
|
37
|
+
}
|
|
38
|
+
export declare namespace Node {
|
|
39
|
+
type AnyNode = Program | Tag | OpenTagName | ShorthandId | ShorthandClassName | TagTypeArgs | TagTypeParams | TagVar | TagArgs | TagParams | AttrNamed | AttrName | AttrArgs | AttrValue | AttrMethod | AttrSpread | AttrTag | Text | CDATA | Doctype | Declaration | Comment | Placeholder | Scriptlet | Import | Export | Class | Style | Static;
|
|
40
|
+
type ParentNode = Program | Tag | AttrTag;
|
|
41
|
+
type StaticNode = Import | Export | Class | Style | Static;
|
|
42
|
+
type ParentTag = Tag | AttrTag;
|
|
43
|
+
type AttrNode = AttrNamed | AttrSpread;
|
|
44
|
+
type ControlFlowTag = Tag & {
|
|
45
|
+
nameText: "if" | "else" | "else-if" | "for" | "while";
|
|
46
|
+
bodyType: TagType.html;
|
|
47
|
+
};
|
|
48
|
+
type ChildNode = Tag | AttrTag | Text | Doctype | Declaration | CDATA | Placeholder | Scriptlet;
|
|
49
|
+
interface Commentable {
|
|
50
|
+
comments: Repeatable<Comment>;
|
|
51
|
+
}
|
|
52
|
+
interface Program extends Range, Commentable {
|
|
53
|
+
type: NodeType.Program;
|
|
54
|
+
parent: undefined;
|
|
55
|
+
static: StaticNode[];
|
|
56
|
+
body: ChildNode[];
|
|
57
|
+
}
|
|
58
|
+
interface Tag extends Range, Commentable {
|
|
59
|
+
type: NodeType.Tag;
|
|
60
|
+
parent: ParentNode;
|
|
61
|
+
owner: undefined;
|
|
62
|
+
concise: boolean;
|
|
63
|
+
selfClosed: boolean;
|
|
64
|
+
hasAttrTags: boolean;
|
|
65
|
+
open: Range;
|
|
66
|
+
close: Range | undefined;
|
|
67
|
+
nameText: string | undefined;
|
|
68
|
+
bodyType: Exclude<TagType, "statement">;
|
|
69
|
+
name: OpenTagName;
|
|
70
|
+
var: TagVar | undefined;
|
|
71
|
+
args: TagArgs | undefined;
|
|
72
|
+
params: TagParams | undefined;
|
|
73
|
+
shorthandId: ShorthandId | undefined;
|
|
74
|
+
shorthandClassNames: Repeatable<ShorthandClassName>;
|
|
75
|
+
typeArgs: TagTypeArgs | undefined;
|
|
76
|
+
typeParams: TagTypeParams | undefined;
|
|
77
|
+
attrs: Repeatable<AttrNode>;
|
|
78
|
+
body: Repeatable<ChildNode>;
|
|
79
|
+
}
|
|
80
|
+
interface AttrTag extends Range, Commentable {
|
|
81
|
+
type: NodeType.AttrTag;
|
|
82
|
+
parent: ParentTag;
|
|
83
|
+
owner: ParentTag | undefined;
|
|
84
|
+
concise: boolean;
|
|
85
|
+
selfClosed: boolean;
|
|
86
|
+
hasAttrTags: boolean;
|
|
87
|
+
open: Range;
|
|
88
|
+
close: Range | undefined;
|
|
89
|
+
nameText: string;
|
|
90
|
+
bodyType: TagType.html;
|
|
91
|
+
name: OpenTagName;
|
|
92
|
+
var: TagVar | undefined;
|
|
93
|
+
args: TagArgs | undefined;
|
|
94
|
+
params: TagParams | undefined;
|
|
95
|
+
shorthandId: ShorthandId | undefined;
|
|
96
|
+
shorthandClassNames: Repeatable<ShorthandClassName>;
|
|
97
|
+
typeArgs: TagTypeArgs | undefined;
|
|
98
|
+
typeParams: TagTypeParams | undefined;
|
|
99
|
+
attrs: Repeatable<AttrNode>;
|
|
100
|
+
body: Repeatable<ChildNode>;
|
|
101
|
+
}
|
|
102
|
+
interface OpenTagName extends Ranges.Template {
|
|
103
|
+
type: NodeType.OpenTagName;
|
|
104
|
+
parent: ParentTag;
|
|
105
|
+
}
|
|
106
|
+
interface ShorthandId extends Ranges.Template {
|
|
107
|
+
type: NodeType.ShorthandId;
|
|
108
|
+
parent: ParentTag;
|
|
109
|
+
}
|
|
110
|
+
interface ShorthandClassName extends Ranges.Template {
|
|
111
|
+
type: NodeType.ShorthandClassName;
|
|
112
|
+
parent: ParentTag;
|
|
113
|
+
}
|
|
114
|
+
interface TagTypeArgs extends Ranges.Value {
|
|
115
|
+
type: NodeType.TagTypeArgs;
|
|
116
|
+
parent: ParentTag;
|
|
117
|
+
}
|
|
118
|
+
interface TagTypeParams extends Ranges.Value {
|
|
119
|
+
type: NodeType.TagTypeParams;
|
|
120
|
+
parent: ParentTag;
|
|
121
|
+
}
|
|
122
|
+
interface TagVar extends Ranges.Value {
|
|
123
|
+
type: NodeType.TagVar;
|
|
124
|
+
parent: ParentTag;
|
|
125
|
+
}
|
|
126
|
+
interface TagArgs extends Ranges.Value {
|
|
127
|
+
type: NodeType.TagArgs;
|
|
128
|
+
parent: ParentTag;
|
|
129
|
+
}
|
|
130
|
+
interface TagParams extends Ranges.Value {
|
|
131
|
+
type: NodeType.TagParams;
|
|
132
|
+
parent: ParentTag;
|
|
133
|
+
}
|
|
134
|
+
interface Text extends Range {
|
|
135
|
+
type: NodeType.Text;
|
|
136
|
+
parent: ParentNode;
|
|
137
|
+
}
|
|
138
|
+
interface CDATA extends Ranges.Value {
|
|
139
|
+
type: NodeType.CDATA;
|
|
140
|
+
parent: ParentNode;
|
|
141
|
+
}
|
|
142
|
+
interface Doctype extends Ranges.Value {
|
|
143
|
+
type: NodeType.Doctype;
|
|
144
|
+
parent: ParentNode;
|
|
145
|
+
}
|
|
146
|
+
interface Declaration extends Ranges.Value {
|
|
147
|
+
type: NodeType.Declaration;
|
|
148
|
+
parent: ParentNode;
|
|
149
|
+
}
|
|
150
|
+
interface Comment extends Ranges.Value {
|
|
151
|
+
type: NodeType.Comment;
|
|
152
|
+
parent: ParentNode;
|
|
153
|
+
}
|
|
154
|
+
interface Placeholder extends Ranges.Value, Commentable {
|
|
155
|
+
type: NodeType.Placeholder;
|
|
156
|
+
parent: ParentNode;
|
|
157
|
+
escape: boolean;
|
|
158
|
+
}
|
|
159
|
+
interface Scriptlet extends Ranges.Value, Commentable {
|
|
160
|
+
type: NodeType.Scriptlet;
|
|
161
|
+
parent: ParentNode;
|
|
162
|
+
block: boolean;
|
|
163
|
+
}
|
|
164
|
+
interface AttrNamed extends Range {
|
|
165
|
+
type: NodeType.AttrNamed;
|
|
166
|
+
parent: ParentTag;
|
|
167
|
+
name: AttrName;
|
|
168
|
+
args: undefined | AttrArgs;
|
|
169
|
+
value: undefined | AttrValue | AttrMethod;
|
|
170
|
+
}
|
|
171
|
+
interface AttrName extends Range {
|
|
172
|
+
type: NodeType.AttrName;
|
|
173
|
+
parent: AttrNamed;
|
|
174
|
+
}
|
|
175
|
+
interface AttrArgs extends Ranges.Value {
|
|
176
|
+
type: NodeType.AttrArgs;
|
|
177
|
+
parent: AttrNamed;
|
|
178
|
+
}
|
|
179
|
+
interface AttrValue extends Range {
|
|
180
|
+
type: NodeType.AttrValue;
|
|
181
|
+
parent: AttrNamed;
|
|
182
|
+
value: Range;
|
|
183
|
+
bound: boolean;
|
|
184
|
+
}
|
|
185
|
+
interface AttrMethod extends Range {
|
|
186
|
+
type: NodeType.AttrMethod;
|
|
187
|
+
parent: AttrNamed;
|
|
188
|
+
typeParams: undefined | Ranges.Value;
|
|
189
|
+
params: Range;
|
|
190
|
+
body: Range;
|
|
191
|
+
}
|
|
192
|
+
interface AttrSpread extends Ranges.Value {
|
|
193
|
+
type: NodeType.AttrSpread;
|
|
194
|
+
parent: ParentTag;
|
|
195
|
+
}
|
|
196
|
+
interface Import extends Range, Commentable {
|
|
197
|
+
type: NodeType.Import;
|
|
198
|
+
parent: ParentNode;
|
|
199
|
+
}
|
|
200
|
+
interface Export extends Range, Commentable {
|
|
201
|
+
type: NodeType.Export;
|
|
202
|
+
parent: ParentNode;
|
|
203
|
+
}
|
|
204
|
+
interface Class extends Range, Commentable {
|
|
205
|
+
type: NodeType.Class;
|
|
206
|
+
parent: ParentNode;
|
|
207
|
+
}
|
|
208
|
+
interface Style extends Range, Commentable {
|
|
209
|
+
type: NodeType.Style;
|
|
210
|
+
parent: ParentNode;
|
|
211
|
+
ext: string | undefined;
|
|
212
|
+
value: Range;
|
|
213
|
+
}
|
|
214
|
+
interface Static extends Range, Commentable {
|
|
215
|
+
type: NodeType.Static;
|
|
216
|
+
parent: ParentNode;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
export declare function parse(code: string, filename?: string): {
|
|
220
|
+
read: (range: Range) => string;
|
|
221
|
+
locationAt: (range: Range) => import("htmljs-parser").Location;
|
|
222
|
+
positionAt: (offset: number) => import("htmljs-parser").Position;
|
|
223
|
+
nodeAt: (offset: number) => Node.AnyNode;
|
|
224
|
+
filename: string;
|
|
225
|
+
program: Node.Program;
|
|
226
|
+
code: string;
|
|
227
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { type Location, type Parsed, type Position, type Range } from "../parser";
|
|
2
|
+
interface Token {
|
|
3
|
+
generatedStart: number;
|
|
4
|
+
sourceStart: number;
|
|
5
|
+
length: number;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Utility to build up generate code from source ranges while maintaining a source mapping.
|
|
9
|
+
*/
|
|
10
|
+
export declare class Extractor {
|
|
11
|
+
#private;
|
|
12
|
+
constructor(parsed: Parsed);
|
|
13
|
+
write(str: string): this;
|
|
14
|
+
copy(range: Range | string | false | void | null): this;
|
|
15
|
+
end(): Extracted;
|
|
16
|
+
}
|
|
17
|
+
export declare class Extracted {
|
|
18
|
+
#private;
|
|
19
|
+
constructor(parsed: Parsed, generated: string, tokens: Token[]);
|
|
20
|
+
sourceOffsetAt(generatedOffset: number): number | void;
|
|
21
|
+
sourcePositionAt(generatedOffset: number): Position | void;
|
|
22
|
+
sourceLocationAt(generatedStart: number, generatedEnd: number): Location | undefined;
|
|
23
|
+
generatedOffsetAt(sourceOffset: number): number | void;
|
|
24
|
+
generatedPositionAt(sourceOffset: number): Position | void;
|
|
25
|
+
generatedLocationAt(sourceStart: number, sourceEnd: number): Location | undefined;
|
|
26
|
+
toString(): string;
|
|
27
|
+
}
|
|
28
|
+
export {};
|