parse5 3.0.1 → 4.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/LICENSE +19 -19
- package/lib/common/unicode.js +47 -47
- package/lib/extensions/location_info/open_element_stack_mixin.js +34 -0
- package/lib/extensions/location_info/parser_mixin.js +213 -0
- package/lib/extensions/location_info/tokenizer_mixin.js +117 -0
- package/lib/extensions/position_tracking/preprocessor_mixin.js +72 -0
- package/lib/index.d.ts +1085 -1077
- package/lib/index.js +26 -4
- package/lib/parser/index.js +10 -6
- package/lib/parser/parser_stream.js +2 -2
- package/lib/sax/dev_null_stream.js +14 -14
- package/lib/sax/index.js +6 -1
- package/lib/serializer/index.js +1 -1
- package/lib/tokenizer/index.js +2 -6
- package/lib/tokenizer/preprocessor.js +0 -8
- package/lib/{common → utils}/merge_options.js +0 -0
- package/lib/utils/mixin.js +18 -0
- package/package.json +60 -63
- package/lib/location_info/parser_mixin.js +0 -210
- package/lib/location_info/tokenizer_mixin.js +0 -148
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var UNICODE = require('../common/unicode');
|
|
4
|
-
|
|
5
|
-
//Aliases
|
|
6
|
-
var $ = UNICODE.CODE_POINTS;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
exports.assign = function (tokenizer) {
|
|
10
|
-
//NOTE: obtain Tokenizer proto this way to avoid module circular references
|
|
11
|
-
var tokenizerProto = Object.getPrototypeOf(tokenizer),
|
|
12
|
-
tokenStartOffset = -1,
|
|
13
|
-
tokenCol = -1,
|
|
14
|
-
tokenLine = 1,
|
|
15
|
-
isEol = false,
|
|
16
|
-
lineStartPos = 0,
|
|
17
|
-
col = -1,
|
|
18
|
-
line = 1;
|
|
19
|
-
|
|
20
|
-
function attachLocationInfo(token) {
|
|
21
|
-
token.location = {
|
|
22
|
-
line: tokenLine,
|
|
23
|
-
col: tokenCol,
|
|
24
|
-
startOffset: tokenStartOffset,
|
|
25
|
-
endOffset: -1
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
//NOTE: patch consumption method to track line/col information
|
|
30
|
-
tokenizer._consume = function () {
|
|
31
|
-
var cp = tokenizerProto._consume.call(this);
|
|
32
|
-
|
|
33
|
-
//NOTE: LF should be in the last column of the line
|
|
34
|
-
if (isEol) {
|
|
35
|
-
isEol = false;
|
|
36
|
-
line++;
|
|
37
|
-
lineStartPos = this.preprocessor.sourcePos;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
if (cp === $.LINE_FEED)
|
|
41
|
-
isEol = true;
|
|
42
|
-
|
|
43
|
-
col = this.preprocessor.sourcePos - lineStartPos + 1;
|
|
44
|
-
|
|
45
|
-
return cp;
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
tokenizer._unconsume = function () {
|
|
49
|
-
tokenizerProto._unconsume.call(this);
|
|
50
|
-
isEol = false;
|
|
51
|
-
|
|
52
|
-
col = this.preprocessor.sourcePos - lineStartPos + 1;
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
//NOTE: patch token creation methods and attach location objects
|
|
56
|
-
tokenizer._createStartTagToken = function () {
|
|
57
|
-
tokenizerProto._createStartTagToken.call(this);
|
|
58
|
-
attachLocationInfo(this.currentToken);
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
tokenizer._createEndTagToken = function () {
|
|
62
|
-
tokenizerProto._createEndTagToken.call(this);
|
|
63
|
-
attachLocationInfo(this.currentToken);
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
tokenizer._createCommentToken = function () {
|
|
67
|
-
tokenizerProto._createCommentToken.call(this);
|
|
68
|
-
attachLocationInfo(this.currentToken);
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
tokenizer._createDoctypeToken = function (initialName) {
|
|
72
|
-
tokenizerProto._createDoctypeToken.call(this, initialName);
|
|
73
|
-
attachLocationInfo(this.currentToken);
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
tokenizer._createCharacterToken = function (type, ch) {
|
|
77
|
-
tokenizerProto._createCharacterToken.call(this, type, ch);
|
|
78
|
-
attachLocationInfo(this.currentCharacterToken);
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
tokenizer._createAttr = function (attrNameFirstCh) {
|
|
82
|
-
tokenizerProto._createAttr.call(this, attrNameFirstCh);
|
|
83
|
-
this.currentAttrLocation = {
|
|
84
|
-
line: line,
|
|
85
|
-
col: col,
|
|
86
|
-
startOffset: this.preprocessor.sourcePos,
|
|
87
|
-
endOffset: -1
|
|
88
|
-
};
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
tokenizer._leaveAttrName = function (toState) {
|
|
92
|
-
tokenizerProto._leaveAttrName.call(this, toState);
|
|
93
|
-
this._attachCurrentAttrLocationInfo();
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
tokenizer._leaveAttrValue = function (toState) {
|
|
97
|
-
tokenizerProto._leaveAttrValue.call(this, toState);
|
|
98
|
-
this._attachCurrentAttrLocationInfo();
|
|
99
|
-
};
|
|
100
|
-
|
|
101
|
-
tokenizer._attachCurrentAttrLocationInfo = function () {
|
|
102
|
-
this.currentAttrLocation.endOffset = this.preprocessor.sourcePos;
|
|
103
|
-
|
|
104
|
-
if (!this.currentToken.location.attrs)
|
|
105
|
-
this.currentToken.location.attrs = Object.create(null);
|
|
106
|
-
|
|
107
|
-
this.currentToken.location.attrs[this.currentAttr.name] = this.currentAttrLocation;
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
//NOTE: patch token emission methods to determine end location
|
|
111
|
-
tokenizer._emitCurrentToken = function () {
|
|
112
|
-
//NOTE: if we have pending character token make it's end location equal to the
|
|
113
|
-
//current token's start location.
|
|
114
|
-
if (this.currentCharacterToken)
|
|
115
|
-
this.currentCharacterToken.location.endOffset = this.currentToken.location.startOffset;
|
|
116
|
-
|
|
117
|
-
this.currentToken.location.endOffset = this.preprocessor.sourcePos + 1;
|
|
118
|
-
tokenizerProto._emitCurrentToken.call(this);
|
|
119
|
-
};
|
|
120
|
-
|
|
121
|
-
tokenizer._emitCurrentCharacterToken = function () {
|
|
122
|
-
//NOTE: if we have character token and it's location wasn't set in the _emitCurrentToken(),
|
|
123
|
-
//then set it's location at the current preprocessor position.
|
|
124
|
-
//We don't need to increment preprocessor position, since character token
|
|
125
|
-
//emission is always forced by the start of the next character token here.
|
|
126
|
-
//So, we already have advanced position.
|
|
127
|
-
if (this.currentCharacterToken && this.currentCharacterToken.location.endOffset === -1)
|
|
128
|
-
this.currentCharacterToken.location.endOffset = this.preprocessor.sourcePos;
|
|
129
|
-
|
|
130
|
-
tokenizerProto._emitCurrentCharacterToken.call(this);
|
|
131
|
-
};
|
|
132
|
-
|
|
133
|
-
//NOTE: patch initial states for each mode to obtain token start position
|
|
134
|
-
Object.keys(tokenizerProto.MODE)
|
|
135
|
-
|
|
136
|
-
.map(function (modeName) {
|
|
137
|
-
return tokenizerProto.MODE[modeName];
|
|
138
|
-
})
|
|
139
|
-
|
|
140
|
-
.forEach(function (state) {
|
|
141
|
-
tokenizer[state] = function (cp) {
|
|
142
|
-
tokenStartOffset = this.preprocessor.sourcePos;
|
|
143
|
-
tokenLine = line;
|
|
144
|
-
tokenCol = col;
|
|
145
|
-
tokenizerProto[state].call(this, cp);
|
|
146
|
-
};
|
|
147
|
-
});
|
|
148
|
-
};
|