UNPKG

871 BJavaScriptView Raw
1'use strict';
2
3function emptyScalarPosition(offset, before, pos) {
4 if (before) {
5 if (pos === null)
6 pos = before.length;
7 for (let i = pos - 1; i >= 0; --i) {
8 let st = before[i];
9 switch (st.type) {
10 case 'space':
11 case 'comment':
12 case 'newline':
13 offset -= st.source.length;
14 continue;
15 }
16 // Technically, an empty scalar is immediately after the last non-empty
17 // node, but it's more useful to place it after any whitespace.
18 st = before[++i];
19 while (st?.type === 'space') {
20 offset += st.source.length;
21 st = before[++i];
22 }
23 break;
24 }
25 }
26 return offset;
27}
28
29exports.emptyScalarPosition = emptyScalarPosition;