flow-parser 0.322.0 → 0.324.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/README.md +25 -32
- package/dist/FlowParserWASM.js +1 -1
- package/dist/estree/TransformComponentSyntax.js +1 -0
- package/dist/estree/TransformComponentSyntax.js.flow +1 -0
- package/package.json +2 -2
- package/dist/transform/print/comments/comments.js +0 -196
- package/dist/transform/print/comments/comments.js.flow +0 -330
- package/dist/transform/print/comments/prettier/common/util.js +0 -186
- package/dist/transform/print/comments/prettier/language-js/comments.js +0 -552
- package/dist/transform/print/comments/prettier/language-js/loc.js +0 -24
- package/dist/transform/print/comments/prettier/language-js/printer-estree.js +0 -20
- package/dist/transform/print/comments/prettier/language-js/utils.js +0 -69
- package/dist/transform/print/comments/prettier/main/comments.js +0 -313
- package/dist/transform/print/comments/prettier/utils/get-last.js +0 -4
- package/dist/transform/print/detachedNodeTypes.js +0 -1
- package/dist/transform/print/detachedNodeTypes.js.flow +0 -24
- package/dist/transform/print/print.js +0 -52
- package/dist/transform/print/print.js.flow +0 -87
|
@@ -1,186 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const stringWidth = require('string-width');
|
|
4
|
-
const getLast = require('../utils/get-last.js');
|
|
5
|
-
const notAsciiRegex = /[^\x20-\x7F]/;
|
|
6
|
-
function skip(chars) {
|
|
7
|
-
return (text, index, opts) => {
|
|
8
|
-
const backwards = opts && opts.backwards;
|
|
9
|
-
if (index === false) {
|
|
10
|
-
return false;
|
|
11
|
-
}
|
|
12
|
-
const {
|
|
13
|
-
length
|
|
14
|
-
} = text;
|
|
15
|
-
let cursor = index;
|
|
16
|
-
while (cursor >= 0 && cursor < length) {
|
|
17
|
-
const c = text.charAt(cursor);
|
|
18
|
-
if (chars instanceof RegExp) {
|
|
19
|
-
if (!chars.test(c)) {
|
|
20
|
-
return cursor;
|
|
21
|
-
}
|
|
22
|
-
} else if (!chars.includes(c)) {
|
|
23
|
-
return cursor;
|
|
24
|
-
}
|
|
25
|
-
backwards ? cursor-- : cursor++;
|
|
26
|
-
}
|
|
27
|
-
if (cursor === -1 || cursor === length) {
|
|
28
|
-
return cursor;
|
|
29
|
-
}
|
|
30
|
-
return false;
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
const skipWhitespace = skip(/\s/);
|
|
34
|
-
const skipSpaces = skip(' \t');
|
|
35
|
-
const skipToLineEnd = skip(',; \t');
|
|
36
|
-
const skipEverythingButNewLine = skip(/[^\n\r]/);
|
|
37
|
-
function skipInlineComment(text, index) {
|
|
38
|
-
if (index === false) {
|
|
39
|
-
return false;
|
|
40
|
-
}
|
|
41
|
-
if (text.charAt(index) === '/' && text.charAt(index + 1) === '*') {
|
|
42
|
-
for (let i = index + 2; i < text.length; ++i) {
|
|
43
|
-
if (text.charAt(i) === '*' && text.charAt(i + 1) === '/') {
|
|
44
|
-
return i + 2;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
return index;
|
|
49
|
-
}
|
|
50
|
-
function skipTrailingComment(text, index) {
|
|
51
|
-
if (index === false) {
|
|
52
|
-
return false;
|
|
53
|
-
}
|
|
54
|
-
if (text.charAt(index) === '/' && text.charAt(index + 1) === '/') {
|
|
55
|
-
return skipEverythingButNewLine(text, index);
|
|
56
|
-
}
|
|
57
|
-
return index;
|
|
58
|
-
}
|
|
59
|
-
function skipNewline(text, index, opts) {
|
|
60
|
-
const backwards = opts && opts.backwards;
|
|
61
|
-
if (index === false) {
|
|
62
|
-
return false;
|
|
63
|
-
}
|
|
64
|
-
const atIndex = text.charAt(index);
|
|
65
|
-
if (backwards) {
|
|
66
|
-
if (text.charAt(index - 1) === '\r' && atIndex === '\n') {
|
|
67
|
-
return index - 2;
|
|
68
|
-
}
|
|
69
|
-
if (atIndex === '\n' || atIndex === '\r' || atIndex === '\u2028' || atIndex === '\u2029') {
|
|
70
|
-
return index - 1;
|
|
71
|
-
}
|
|
72
|
-
} else {
|
|
73
|
-
if (atIndex === '\r' && text.charAt(index + 1) === '\n') {
|
|
74
|
-
return index + 2;
|
|
75
|
-
}
|
|
76
|
-
if (atIndex === '\n' || atIndex === '\r' || atIndex === '\u2028' || atIndex === '\u2029') {
|
|
77
|
-
return index + 1;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
return index;
|
|
81
|
-
}
|
|
82
|
-
function hasNewline(text, index, opts = {}) {
|
|
83
|
-
const idx = skipSpaces(text, opts.backwards ? index - 1 : index, opts);
|
|
84
|
-
const idx2 = skipNewline(text, idx, opts);
|
|
85
|
-
return idx !== idx2;
|
|
86
|
-
}
|
|
87
|
-
function hasNewlineInRange(text, start, end) {
|
|
88
|
-
for (let i = start; i < end; ++i) {
|
|
89
|
-
if (text.charAt(i) === '\n') {
|
|
90
|
-
return true;
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
return false;
|
|
94
|
-
}
|
|
95
|
-
function isNextLineEmptyAfterIndex(text, index) {
|
|
96
|
-
let oldIdx = null;
|
|
97
|
-
let idx = index;
|
|
98
|
-
while (idx !== oldIdx) {
|
|
99
|
-
oldIdx = idx;
|
|
100
|
-
idx = skipToLineEnd(text, idx);
|
|
101
|
-
idx = skipInlineComment(text, idx);
|
|
102
|
-
idx = skipSpaces(text, idx);
|
|
103
|
-
}
|
|
104
|
-
idx = skipTrailingComment(text, idx);
|
|
105
|
-
idx = skipNewline(text, idx);
|
|
106
|
-
return idx !== false && hasNewline(text, idx);
|
|
107
|
-
}
|
|
108
|
-
function getNextNonSpaceNonCommentCharacterIndexWithStartIndex(text, idx) {
|
|
109
|
-
let oldIdx = null;
|
|
110
|
-
let nextIdx = idx;
|
|
111
|
-
while (nextIdx !== oldIdx) {
|
|
112
|
-
oldIdx = nextIdx;
|
|
113
|
-
nextIdx = skipSpaces(text, nextIdx);
|
|
114
|
-
nextIdx = skipInlineComment(text, nextIdx);
|
|
115
|
-
nextIdx = skipTrailingComment(text, nextIdx);
|
|
116
|
-
nextIdx = skipNewline(text, nextIdx);
|
|
117
|
-
}
|
|
118
|
-
return nextIdx;
|
|
119
|
-
}
|
|
120
|
-
function getNextNonSpaceNonCommentCharacterIndex(text, node, locEnd) {
|
|
121
|
-
return getNextNonSpaceNonCommentCharacterIndexWithStartIndex(text, locEnd(node));
|
|
122
|
-
}
|
|
123
|
-
function getNextNonSpaceNonCommentCharacter(text, node, locEnd) {
|
|
124
|
-
return text.charAt(getNextNonSpaceNonCommentCharacterIndex(text, node, locEnd));
|
|
125
|
-
}
|
|
126
|
-
function getStringWidth(text) {
|
|
127
|
-
if (!text) {
|
|
128
|
-
return 0;
|
|
129
|
-
}
|
|
130
|
-
if (!notAsciiRegex.test(text)) {
|
|
131
|
-
return text.length;
|
|
132
|
-
}
|
|
133
|
-
return stringWidth(text);
|
|
134
|
-
}
|
|
135
|
-
function addCommentHelper(node, comment) {
|
|
136
|
-
const comments = node.comments || (node.comments = []);
|
|
137
|
-
comments.push(comment);
|
|
138
|
-
comment.printed = false;
|
|
139
|
-
comment.nodeDescription = describeNodeForDebugging(node);
|
|
140
|
-
}
|
|
141
|
-
function addLeadingComment(node, comment) {
|
|
142
|
-
comment.leading = true;
|
|
143
|
-
comment.trailing = false;
|
|
144
|
-
addCommentHelper(node, comment);
|
|
145
|
-
}
|
|
146
|
-
function addDanglingComment(node, comment, marker) {
|
|
147
|
-
comment.leading = false;
|
|
148
|
-
comment.trailing = false;
|
|
149
|
-
if (marker) {
|
|
150
|
-
comment.marker = marker;
|
|
151
|
-
}
|
|
152
|
-
addCommentHelper(node, comment);
|
|
153
|
-
}
|
|
154
|
-
function addTrailingComment(node, comment) {
|
|
155
|
-
comment.leading = false;
|
|
156
|
-
comment.trailing = true;
|
|
157
|
-
addCommentHelper(node, comment);
|
|
158
|
-
}
|
|
159
|
-
function isNonEmptyArray(object) {
|
|
160
|
-
return Array.isArray(object) && object.length > 0;
|
|
161
|
-
}
|
|
162
|
-
function describeNodeForDebugging(node) {
|
|
163
|
-
const nodeType = node.type || node.kind || '(unknown type)';
|
|
164
|
-
let nodeName = String(node.name || node.id && (typeof node.id === 'object' ? node.id.name : node.id) || node.key && (typeof node.key === 'object' ? node.key.name : node.key) || node.value && (typeof node.value === 'object' ? '' : String(node.value)) || node.operator || '');
|
|
165
|
-
if (nodeName.length > 20) {
|
|
166
|
-
nodeName = nodeName.slice(0, 19) + '…';
|
|
167
|
-
}
|
|
168
|
-
return nodeType + (nodeName ? ' ' + nodeName : '');
|
|
169
|
-
}
|
|
170
|
-
module.exports = {
|
|
171
|
-
getStringWidth,
|
|
172
|
-
getLast,
|
|
173
|
-
getNextNonSpaceNonCommentCharacterIndexWithStartIndex,
|
|
174
|
-
getNextNonSpaceNonCommentCharacterIndex,
|
|
175
|
-
getNextNonSpaceNonCommentCharacter,
|
|
176
|
-
skipWhitespace,
|
|
177
|
-
skipSpaces,
|
|
178
|
-
skipNewline,
|
|
179
|
-
isNextLineEmptyAfterIndex,
|
|
180
|
-
hasNewline,
|
|
181
|
-
hasNewlineInRange,
|
|
182
|
-
addLeadingComment,
|
|
183
|
-
addDanglingComment,
|
|
184
|
-
addTrailingComment,
|
|
185
|
-
isNonEmptyArray
|
|
186
|
-
};
|