This repository was archived by the owner on Jun 23, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathparse-result.js
More file actions
78 lines (64 loc) · 1.76 KB
/
parse-result.js
File metadata and controls
78 lines (64 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*
* Parse result-specific refract elements.
*
* General structure:
*
* + ParseResult
* + Annotation
*/
import apiDescription from 'minim-api-description';
export function namespace(options) {
const minim = options.base;
const ArrayElement = minim.getElementClass('array');
const StringElement = minim.getElementClass('string');
// First, modify the default list of special attributes to include
// the new `sourceMap` attribute, which is an unrefracted array of
// refracted source map elements.
minim._attributeElementArrayKeys.push('sourceMap');
class ParseResult extends ArrayElement {
constructor() {
super(...arguments);
this.element = 'parseResult';
}
get api() {
return this.children(item => item.classes.contains('api')).first();
}
get annotations() {
return this.children(item => item.element === 'annotation');
}
get warnings() {
return this.children(
item => item.element === 'annotation' &&
item.classes.contains('warning'));
}
get errors() {
return this.children(
item => item.element === 'annotation' &&
item.classes.contains('error'));
}
}
class Annotation extends StringElement {
constructor() {
super(...arguments);
this.element = 'annotation';
}
get code() {
return this.attributes.getValue('code');
}
set code(value) {
this.attributes.set('code', value);
}
}
class SourceMap extends minim.BaseElement {
constructor() {
super(...arguments);
this.element = 'sourceMap';
}
}
minim
.use(apiDescription)
.register('parseResult', ParseResult)
.register('annotation', Annotation)
.register('sourceMap', SourceMap);
}
export default {namespace};