yaml 2.0.0-3 → 2.0.0-7
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 +1 -1
- package/README.md +46 -26
- package/browser/dist/compose/compose-collection.js +59 -0
- package/browser/dist/compose/compose-doc.js +39 -0
- package/browser/dist/compose/compose-node.js +79 -0
- package/browser/dist/compose/compose-scalar.js +74 -0
- package/browser/dist/compose/composer.js +219 -0
- package/browser/dist/compose/resolve-block-map.js +93 -0
- package/browser/dist/compose/resolve-block-scalar.js +185 -0
- package/browser/dist/compose/resolve-block-seq.js +40 -0
- package/browser/dist/compose/resolve-end.js +37 -0
- package/browser/dist/compose/resolve-flow-collection.js +189 -0
- package/browser/dist/compose/resolve-flow-scalar.js +217 -0
- package/browser/dist/compose/resolve-props.js +126 -0
- package/browser/dist/compose/util-contains-newline.js +34 -0
- package/browser/dist/compose/util-empty-scalar-position.js +27 -0
- package/browser/dist/compose/util-map-includes.js +17 -0
- package/browser/dist/doc/Document.js +251 -348
- package/browser/dist/doc/anchors.js +72 -0
- package/browser/dist/doc/applyReviver.js +41 -28
- package/browser/dist/doc/createNode.js +75 -55
- package/browser/dist/doc/directives.js +161 -0
- package/browser/dist/errors.js +50 -72
- package/browser/dist/index.js +16 -72
- package/browser/dist/log.js +11 -7
- package/browser/dist/nodes/Alias.js +94 -0
- package/browser/dist/nodes/Collection.js +133 -0
- package/browser/dist/nodes/Node.js +41 -0
- package/browser/dist/nodes/Pair.js +28 -0
- package/browser/dist/nodes/Scalar.js +23 -0
- package/browser/dist/nodes/YAMLMap.js +116 -0
- package/browser/dist/nodes/YAMLSeq.js +105 -0
- package/browser/dist/nodes/addPairToJSMap.js +103 -0
- package/browser/dist/nodes/toJS.js +35 -0
- package/browser/dist/options.js +14 -95
- package/browser/dist/parse/cst-scalar.js +219 -0
- package/browser/dist/parse/cst-stringify.js +61 -0
- package/browser/dist/parse/cst-visit.js +97 -0
- package/browser/dist/parse/cst.js +98 -0
- package/browser/dist/parse/lexer.js +674 -0
- package/browser/dist/parse/line-counter.js +39 -0
- package/browser/dist/parse/parser.js +876 -0
- package/browser/dist/public-api.js +101 -0
- package/browser/dist/schema/Schema.js +23 -0
- package/browser/dist/schema/common/map.js +42 -0
- package/browser/dist/schema/common/null.js +13 -0
- package/browser/dist/schema/common/seq.js +33 -0
- package/browser/dist/schema/common/string.js +14 -0
- package/browser/dist/schema/core/bool.js +19 -0
- package/browser/dist/schema/core/float.js +40 -0
- package/browser/dist/schema/core/int.js +38 -0
- package/browser/dist/schema/core/schema.js +23 -0
- package/browser/dist/schema/json/schema.js +62 -0
- package/browser/dist/schema/tags.js +79 -0
- package/browser/dist/schema/yaml-1.1/binary.js +66 -0
- package/browser/dist/schema/yaml-1.1/bool.js +26 -0
- package/browser/dist/schema/yaml-1.1/float.js +43 -0
- package/browser/dist/schema/yaml-1.1/int.js +71 -0
- package/browser/dist/schema/yaml-1.1/omap.js +73 -0
- package/browser/dist/schema/yaml-1.1/pairs.js +77 -0
- package/browser/dist/schema/yaml-1.1/schema.js +37 -0
- package/browser/dist/schema/yaml-1.1/set.js +87 -0
- package/browser/dist/schema/yaml-1.1/timestamp.js +101 -0
- package/browser/dist/stringify/foldFlowLines.js +121 -139
- package/browser/dist/stringify/stringify.js +87 -72
- package/browser/dist/stringify/stringifyCollection.js +122 -0
- package/browser/dist/stringify/stringifyComment.js +14 -0
- package/browser/dist/stringify/stringifyDocument.js +64 -0
- package/browser/dist/stringify/stringifyNumber.js +20 -23
- package/browser/dist/stringify/stringifyPair.js +111 -0
- package/browser/dist/stringify/stringifyString.js +295 -322
- package/browser/dist/util.js +4 -4
- package/browser/dist/visit.js +134 -71
- package/browser/index.js +4 -1
- package/dist/compose/compose-collection.d.ts +5 -0
- package/dist/compose/compose-collection.js +61 -0
- package/dist/compose/compose-doc.d.ts +6 -0
- package/dist/compose/compose-doc.js +41 -0
- package/dist/compose/compose-node.d.ts +25 -0
- package/dist/compose/compose-node.js +82 -0
- package/dist/compose/compose-scalar.d.ts +5 -0
- package/dist/compose/compose-scalar.js +76 -0
- package/dist/compose/composer.d.ts +62 -0
- package/dist/compose/composer.js +223 -0
- package/dist/compose/resolve-block-map.d.ts +6 -0
- package/dist/compose/resolve-block-map.js +95 -0
- package/dist/compose/resolve-block-scalar.d.ts +10 -0
- package/dist/compose/resolve-block-scalar.js +187 -0
- package/dist/compose/resolve-block-seq.d.ts +5 -0
- package/dist/compose/resolve-block-seq.js +42 -0
- package/dist/compose/resolve-end.d.ts +6 -0
- package/dist/compose/resolve-end.js +39 -0
- package/dist/compose/resolve-flow-collection.d.ts +6 -0
- package/dist/compose/resolve-flow-collection.js +191 -0
- package/dist/compose/resolve-flow-scalar.d.ts +10 -0
- package/dist/compose/resolve-flow-scalar.js +219 -0
- package/dist/compose/resolve-props.d.ts +21 -0
- package/dist/compose/resolve-props.js +128 -0
- package/dist/compose/util-contains-newline.d.ts +2 -0
- package/dist/compose/util-contains-newline.js +36 -0
- package/dist/compose/util-empty-scalar-position.d.ts +2 -0
- package/dist/compose/util-empty-scalar-position.js +29 -0
- package/dist/compose/util-map-includes.d.ts +4 -0
- package/dist/compose/util-map-includes.js +19 -0
- package/dist/doc/Document.d.ts +130 -0
- package/dist/doc/Document.js +250 -347
- package/dist/doc/anchors.d.ts +24 -0
- package/dist/doc/anchors.js +77 -0
- package/dist/doc/applyReviver.d.ts +9 -0
- package/dist/doc/applyReviver.js +41 -28
- package/dist/doc/createNode.d.ts +16 -0
- package/dist/doc/createNode.js +75 -55
- package/dist/doc/directives.d.ts +46 -0
- package/dist/doc/directives.js +163 -0
- package/dist/errors.d.ts +21 -0
- package/dist/errors.js +51 -74
- package/dist/index.d.ts +19 -0
- package/dist/index.js +39 -70
- package/dist/log.d.ts +3 -0
- package/dist/log.js +11 -6
- package/dist/nodes/Alias.d.ts +24 -0
- package/dist/nodes/Alias.js +96 -0
- package/dist/nodes/Collection.d.ts +67 -0
- package/dist/nodes/Collection.js +137 -0
- package/dist/nodes/Node.d.ts +48 -0
- package/dist/nodes/Node.js +59 -0
- package/dist/nodes/Pair.d.ts +16 -0
- package/dist/nodes/Pair.js +31 -0
- package/dist/nodes/Scalar.d.ts +40 -0
- package/dist/nodes/Scalar.js +26 -0
- package/dist/nodes/YAMLMap.d.ts +39 -0
- package/dist/nodes/YAMLMap.js +119 -0
- package/dist/nodes/YAMLSeq.d.ts +53 -0
- package/dist/nodes/YAMLSeq.js +107 -0
- package/dist/nodes/addPairToJSMap.d.ts +3 -0
- package/dist/nodes/addPairToJSMap.js +105 -0
- package/dist/nodes/toJS.d.ts +30 -0
- package/dist/nodes/toJS.js +37 -0
- package/dist/options.d.ts +278 -0
- package/dist/options.js +13 -96
- package/dist/parse/cst-scalar.d.ts +58 -0
- package/dist/parse/cst-scalar.js +223 -0
- package/dist/parse/cst-stringify.d.ts +8 -0
- package/dist/parse/cst-stringify.js +63 -0
- package/dist/parse/cst-visit.d.ts +39 -0
- package/dist/parse/cst-visit.js +99 -0
- package/dist/parse/cst.d.ts +106 -0
- package/dist/parse/cst.js +112 -0
- package/dist/parse/lexer.d.ts +85 -0
- package/dist/parse/lexer.js +676 -0
- package/dist/parse/line-counter.d.ts +22 -0
- package/dist/parse/line-counter.js +41 -0
- package/dist/parse/parser.d.ts +84 -0
- package/dist/parse/parser.js +880 -0
- package/dist/public-api.d.ts +43 -0
- package/dist/public-api.js +106 -0
- package/dist/schema/Schema.d.ts +16 -0
- package/dist/schema/Schema.js +25 -0
- package/dist/schema/common/map.d.ts +2 -0
- package/dist/schema/common/map.js +44 -0
- package/dist/schema/common/null.d.ts +4 -0
- package/dist/schema/common/null.js +15 -0
- package/dist/schema/common/seq.d.ts +2 -0
- package/dist/schema/common/seq.js +35 -0
- package/dist/schema/common/string.d.ts +2 -0
- package/dist/schema/common/string.js +16 -0
- package/dist/schema/core/bool.d.ts +4 -0
- package/dist/schema/core/bool.js +21 -0
- package/dist/schema/core/float.d.ts +4 -0
- package/dist/schema/core/float.js +44 -0
- package/dist/schema/core/int.d.ts +4 -0
- package/dist/schema/core/int.js +42 -0
- package/dist/schema/core/schema.d.ts +1 -0
- package/dist/schema/core/schema.js +25 -0
- package/dist/schema/json/schema.d.ts +2 -0
- package/dist/schema/json/schema.js +64 -0
- package/dist/schema/tags.d.ts +41 -0
- package/dist/schema/tags.js +82 -0
- package/dist/schema/types.d.ts +82 -0
- package/dist/schema/yaml-1.1/binary.d.ts +2 -0
- package/dist/schema/yaml-1.1/binary.js +68 -0
- package/dist/schema/yaml-1.1/bool.d.ts +7 -0
- package/dist/schema/yaml-1.1/bool.js +29 -0
- package/dist/schema/yaml-1.1/float.d.ts +4 -0
- package/dist/schema/yaml-1.1/float.js +47 -0
- package/dist/schema/yaml-1.1/int.d.ts +5 -0
- package/dist/schema/yaml-1.1/int.js +76 -0
- package/dist/schema/yaml-1.1/omap.d.ts +21 -0
- package/dist/schema/yaml-1.1/omap.js +76 -0
- package/dist/schema/yaml-1.1/pairs.d.ts +10 -0
- package/dist/schema/yaml-1.1/pairs.js +81 -0
- package/dist/schema/yaml-1.1/schema.d.ts +1 -0
- package/dist/schema/yaml-1.1/schema.js +39 -0
- package/dist/schema/yaml-1.1/set.d.ts +22 -0
- package/dist/schema/yaml-1.1/set.js +90 -0
- package/dist/schema/yaml-1.1/timestamp.d.ts +6 -0
- package/dist/schema/yaml-1.1/timestamp.js +105 -0
- package/dist/stringify/foldFlowLines.d.ts +34 -0
- package/dist/stringify/foldFlowLines.js +121 -139
- package/dist/stringify/stringify.d.ts +18 -0
- package/dist/stringify/stringify.js +87 -71
- package/dist/stringify/stringifyCollection.d.ts +21 -0
- package/dist/stringify/stringifyCollection.js +124 -0
- package/dist/stringify/stringifyComment.d.ts +2 -0
- package/dist/stringify/stringifyComment.js +17 -0
- package/dist/stringify/stringifyDocument.d.ts +3 -0
- package/dist/stringify/stringifyDocument.js +66 -0
- package/dist/stringify/stringifyNumber.d.ts +2 -0
- package/dist/stringify/stringifyNumber.js +20 -23
- package/dist/stringify/stringifyPair.d.ts +3 -0
- package/dist/stringify/stringifyPair.js +113 -0
- package/dist/stringify/stringifyString.d.ts +3 -0
- package/dist/stringify/stringifyString.js +295 -322
- package/dist/test-events.d.ts +4 -0
- package/dist/test-events.js +124 -148
- package/dist/util.d.ts +6 -0
- package/dist/util.js +9 -12
- package/dist/visit.d.ts +63 -0
- package/dist/visit.js +134 -71
- package/package.json +31 -39
- package/util.js +2 -14
- package/browser/dist/_virtual/_rollupPluginBabelHelpers.js +0 -16
- package/browser/dist/ast/Alias.js +0 -95
- package/browser/dist/ast/Collection.js +0 -192
- package/browser/dist/ast/Merge.js +0 -71
- package/browser/dist/ast/Node.js +0 -3
- package/browser/dist/ast/Pair.js +0 -200
- package/browser/dist/ast/Scalar.js +0 -21
- package/browser/dist/ast/YAMLMap.js +0 -91
- package/browser/dist/ast/YAMLSeq.js +0 -67
- package/browser/dist/ast/toJS.js +0 -29
- package/browser/dist/constants.js +0 -40
- package/browser/dist/cst/Alias.js +0 -26
- package/browser/dist/cst/BlankLine.js +0 -34
- package/browser/dist/cst/BlockValue.js +0 -240
- package/browser/dist/cst/Collection.js +0 -259
- package/browser/dist/cst/CollectionItem.js +0 -123
- package/browser/dist/cst/Comment.js +0 -27
- package/browser/dist/cst/Directive.js +0 -53
- package/browser/dist/cst/Document.js +0 -262
- package/browser/dist/cst/FlowCollection.js +0 -201
- package/browser/dist/cst/Node.js +0 -355
- package/browser/dist/cst/ParseContext.js +0 -234
- package/browser/dist/cst/PlainValue.js +0 -171
- package/browser/dist/cst/QuoteDouble.js +0 -224
- package/browser/dist/cst/QuoteSingle.js +0 -100
- package/browser/dist/cst/Range.js +0 -56
- package/browser/dist/cst/parse.js +0 -46
- package/browser/dist/cst/source-utils.js +0 -169
- package/browser/dist/doc/Anchors.js +0 -115
- package/browser/dist/doc/Schema.js +0 -34
- package/browser/dist/doc/getSchemaTags.js +0 -33
- package/browser/dist/doc/listTagNames.js +0 -27
- package/browser/dist/doc/parseContents.js +0 -60
- package/browser/dist/doc/parseDirectives.js +0 -107
- package/browser/dist/resolve/collection-utils.js +0 -86
- package/browser/dist/resolve/resolveMap.js +0 -315
- package/browser/dist/resolve/resolveNode.js +0 -173
- package/browser/dist/resolve/resolveScalar.js +0 -20
- package/browser/dist/resolve/resolveSeq.js +0 -170
- package/browser/dist/resolve/resolveTag.js +0 -107
- package/browser/dist/resolve/resolveTagName.js +0 -87
- package/browser/dist/stringify/addComment.js +0 -10
- package/browser/dist/stringify/stringifyTag.js +0 -28
- package/browser/dist/tags/core.js +0 -128
- package/browser/dist/tags/failsafe/index.js +0 -7
- package/browser/dist/tags/failsafe/map.js +0 -37
- package/browser/dist/tags/failsafe/seq.js +0 -34
- package/browser/dist/tags/failsafe/string.js +0 -20
- package/browser/dist/tags/index.js +0 -39
- package/browser/dist/tags/json.js +0 -62
- package/browser/dist/tags/options.js +0 -31
- package/browser/dist/tags/yaml-1.1/binary.js +0 -83
- package/browser/dist/tags/yaml-1.1/index.js +0 -174
- package/browser/dist/tags/yaml-1.1/omap.js +0 -86
- package/browser/dist/tags/yaml-1.1/pairs.js +0 -62
- package/browser/dist/tags/yaml-1.1/set.js +0 -78
- package/browser/dist/tags/yaml-1.1/timestamp.js +0 -101
- package/browser/dist/types.js +0 -10
- package/cst.d.ts +0 -185
- package/dist/_virtual/_rollupPluginBabelHelpers.js +0 -18
- package/dist/ast/Alias.js +0 -97
- package/dist/ast/Collection.js +0 -196
- package/dist/ast/Merge.js +0 -74
- package/dist/ast/Node.js +0 -5
- package/dist/ast/Pair.js +0 -203
- package/dist/ast/Scalar.js +0 -24
- package/dist/ast/YAMLMap.js +0 -94
- package/dist/ast/YAMLSeq.js +0 -69
- package/dist/ast/toJS.js +0 -31
- package/dist/constants.js +0 -46
- package/dist/cst/Alias.js +0 -28
- package/dist/cst/BlankLine.js +0 -36
- package/dist/cst/BlockValue.js +0 -243
- package/dist/cst/Collection.js +0 -262
- package/dist/cst/CollectionItem.js +0 -125
- package/dist/cst/Comment.js +0 -29
- package/dist/cst/Directive.js +0 -55
- package/dist/cst/Document.js +0 -264
- package/dist/cst/FlowCollection.js +0 -203
- package/dist/cst/Node.js +0 -357
- package/dist/cst/ParseContext.js +0 -236
- package/dist/cst/PlainValue.js +0 -173
- package/dist/cst/QuoteDouble.js +0 -226
- package/dist/cst/QuoteSingle.js +0 -102
- package/dist/cst/Range.js +0 -58
- package/dist/cst/parse.js +0 -48
- package/dist/cst/source-utils.js +0 -173
- package/dist/doc/Anchors.js +0 -117
- package/dist/doc/Schema.js +0 -36
- package/dist/doc/getSchemaTags.js +0 -35
- package/dist/doc/listTagNames.js +0 -29
- package/dist/doc/parseContents.js +0 -62
- package/dist/doc/parseDirectives.js +0 -109
- package/dist/resolve/collection-utils.js +0 -91
- package/dist/resolve/resolveMap.js +0 -317
- package/dist/resolve/resolveNode.js +0 -175
- package/dist/resolve/resolveScalar.js +0 -22
- package/dist/resolve/resolveSeq.js +0 -172
- package/dist/resolve/resolveTag.js +0 -109
- package/dist/resolve/resolveTagName.js +0 -89
- package/dist/stringify/addComment.js +0 -13
- package/dist/stringify/stringifyTag.js +0 -30
- package/dist/tags/core.js +0 -138
- package/dist/tags/failsafe/index.js +0 -9
- package/dist/tags/failsafe/map.js +0 -39
- package/dist/tags/failsafe/seq.js +0 -36
- package/dist/tags/failsafe/string.js +0 -22
- package/dist/tags/index.js +0 -42
- package/dist/tags/json.js +0 -64
- package/dist/tags/options.js +0 -37
- package/dist/tags/yaml-1.1/binary.js +0 -85
- package/dist/tags/yaml-1.1/index.js +0 -176
- package/dist/tags/yaml-1.1/omap.js +0 -89
- package/dist/tags/yaml-1.1/pairs.js +0 -66
- package/dist/tags/yaml-1.1/set.js +0 -81
- package/dist/tags/yaml-1.1/timestamp.js +0 -105
- package/dist/types.js +0 -29
- package/index.d.ts +0 -519
- package/index.js +0 -1
- package/types.d.ts +0 -379
- package/types.js +0 -17
- package/types.mjs +0 -17
- package/util.d.ts +0 -76
- package/util.mjs +0 -15
package/dist/test-events.js
CHANGED
|
@@ -1,158 +1,134 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var
|
|
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
|
-
|
|
3
|
+
var Node = require('./nodes/Node.js');
|
|
4
|
+
var publicApi = require('./public-api.js');
|
|
5
|
+
var visit = require('./visit.js');
|
|
6
|
+
|
|
7
|
+
const scalarChar = {
|
|
8
|
+
BLOCK_FOLDED: '>',
|
|
9
|
+
BLOCK_LITERAL: '|',
|
|
10
|
+
PLAIN: ':',
|
|
11
|
+
QUOTE_DOUBLE: '"',
|
|
12
|
+
QUOTE_SINGLE: "'"
|
|
13
|
+
};
|
|
14
|
+
function anchorExists(doc, anchor) {
|
|
15
|
+
let found = false;
|
|
16
|
+
visit.visit(doc, {
|
|
17
|
+
Value(_key, node) {
|
|
18
|
+
if (node.anchor === anchor) {
|
|
19
|
+
found = true;
|
|
20
|
+
return visit.visit.BREAK;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
return found;
|
|
25
|
+
}
|
|
26
|
+
// test harness for yaml-test-suite event tests
|
|
27
|
+
function testEvents(src) {
|
|
28
|
+
var _a;
|
|
29
|
+
const docs = publicApi.parseAllDocuments(src);
|
|
30
|
+
const errDoc = docs.find(doc => doc.errors.length > 0);
|
|
31
|
+
const error = errDoc ? errDoc.errors[0].message : null;
|
|
32
|
+
const events = ['+STR'];
|
|
33
|
+
try {
|
|
34
|
+
for (let i = 0; i < docs.length; ++i) {
|
|
35
|
+
const doc = docs[i];
|
|
36
|
+
let root = doc.contents;
|
|
37
|
+
if (Array.isArray(root))
|
|
38
|
+
root = root[0];
|
|
39
|
+
// eslint-disable-next-line no-sparse-arrays
|
|
40
|
+
const [rootStart, , rootEnd] = doc.range || [0, , 0];
|
|
41
|
+
const error = doc.errors[0];
|
|
42
|
+
if (error && (!error.pos || error.pos[0] < rootStart))
|
|
43
|
+
throw new Error();
|
|
44
|
+
let docStart = '+DOC';
|
|
45
|
+
if (doc.directives.marker)
|
|
46
|
+
docStart += ' ---';
|
|
47
|
+
else if (doc.contents && doc.contents.range[2] === doc.contents.range[0])
|
|
48
|
+
continue;
|
|
49
|
+
events.push(docStart);
|
|
50
|
+
addEvents(events, doc, (_a = error === null || error === void 0 ? void 0 : error.pos[0]) !== null && _a !== void 0 ? _a : -1, root);
|
|
51
|
+
let docEnd = '-DOC';
|
|
52
|
+
if (rootEnd) {
|
|
53
|
+
const post = src.slice(rootStart, rootEnd);
|
|
54
|
+
if (/^\.\.\.($|\s)/m.test(post))
|
|
55
|
+
docEnd += ' ...';
|
|
56
|
+
}
|
|
57
|
+
events.push(docEnd);
|
|
58
|
+
}
|
|
41
59
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
events.push('-STR');
|
|
50
|
-
return {
|
|
51
|
-
events,
|
|
52
|
-
error
|
|
53
|
-
};
|
|
60
|
+
catch (e) {
|
|
61
|
+
return { events, error: error || e };
|
|
62
|
+
}
|
|
63
|
+
events.push('-STR');
|
|
64
|
+
return { events, error };
|
|
54
65
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
if (e && node.cstNode === e) throw new Error();
|
|
63
|
-
let props = '';
|
|
64
|
-
let anchor = doc.anchors.getName(node);
|
|
65
|
-
|
|
66
|
-
if (anchor) {
|
|
67
|
-
if (/\d$/.test(anchor)) {
|
|
68
|
-
const alt = anchor.replace(/\d$/, '');
|
|
69
|
-
if (doc.anchors.getNode(alt)) anchor = alt;
|
|
66
|
+
function addEvents(events, doc, errPos, node) {
|
|
67
|
+
if (!node) {
|
|
68
|
+
events.push('=VAL :');
|
|
69
|
+
return;
|
|
70
70
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
71
|
+
if (errPos !== -1 && Node.isNode(node) && node.range[0] >= errPos)
|
|
72
|
+
throw new Error();
|
|
73
|
+
let props = '';
|
|
74
|
+
let anchor = Node.isScalar(node) || Node.isCollection(node) ? node.anchor : undefined;
|
|
75
|
+
if (anchor) {
|
|
76
|
+
if (/\d$/.test(anchor)) {
|
|
77
|
+
const alt = anchor.replace(/\d$/, '');
|
|
78
|
+
if (anchorExists(doc, alt))
|
|
79
|
+
anchor = alt;
|
|
80
|
+
}
|
|
81
|
+
props = ` &${anchor}`;
|
|
82
|
+
}
|
|
83
|
+
if (Node.isNode(node) && node.tag)
|
|
84
|
+
props += ` <${node.tag}>`;
|
|
85
|
+
if (Node.isMap(node)) {
|
|
86
|
+
events.push(`+MAP${props}`);
|
|
87
|
+
node.items.forEach(({ key, value }) => {
|
|
88
|
+
addEvents(events, doc, errPos, key);
|
|
89
|
+
addEvents(events, doc, errPos, value);
|
|
90
|
+
});
|
|
91
|
+
events.push('-MAP');
|
|
92
|
+
}
|
|
93
|
+
else if (Node.isSeq(node)) {
|
|
94
|
+
events.push(`+SEQ${props}`);
|
|
95
|
+
node.items.forEach(item => {
|
|
96
|
+
addEvents(events, doc, errPos, item);
|
|
97
|
+
});
|
|
98
|
+
events.push('-SEQ');
|
|
99
|
+
}
|
|
100
|
+
else if (Node.isPair(node)) {
|
|
101
|
+
events.push(`+MAP${props}`);
|
|
102
|
+
addEvents(events, doc, errPos, node.key);
|
|
103
|
+
addEvents(events, doc, errPos, node.value);
|
|
104
|
+
events.push('-MAP');
|
|
105
|
+
}
|
|
106
|
+
else if (Node.isAlias(node)) {
|
|
107
|
+
let alias = node.source;
|
|
108
|
+
if (alias && /\d$/.test(alias)) {
|
|
109
|
+
const alt = alias.replace(/\d$/, '');
|
|
110
|
+
if (anchorExists(doc, alt))
|
|
111
|
+
alias = alt;
|
|
93
112
|
}
|
|
94
|
-
|
|
95
113
|
events.push(`=ALI${props} *${alias}`);
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
case 'QUOTE_SINGLE':
|
|
116
|
-
scalar = "'";
|
|
117
|
-
break;
|
|
118
|
-
|
|
119
|
-
case 'PAIR':
|
|
120
|
-
events.push(`+MAP${props}`);
|
|
121
|
-
addEvents(events, doc, e, node.key);
|
|
122
|
-
addEvents(events, doc, e, node.value);
|
|
123
|
-
events.push('-MAP');
|
|
124
|
-
break;
|
|
125
|
-
|
|
126
|
-
case 'FLOW_SEQ':
|
|
127
|
-
case 'SEQ':
|
|
128
|
-
events.push(`+SEQ${props}`);
|
|
129
|
-
node.items.forEach(item => {
|
|
130
|
-
addEvents(events, doc, e, item);
|
|
131
|
-
});
|
|
132
|
-
events.push('-SEQ');
|
|
133
|
-
break;
|
|
134
|
-
|
|
135
|
-
case 'FLOW_MAP':
|
|
136
|
-
case 'MAP':
|
|
137
|
-
events.push(`+MAP${props}`);
|
|
138
|
-
node.items.forEach(({
|
|
139
|
-
key,
|
|
140
|
-
value
|
|
141
|
-
}) => {
|
|
142
|
-
addEvents(events, doc, e, key);
|
|
143
|
-
addEvents(events, doc, e, value);
|
|
144
|
-
});
|
|
145
|
-
events.push('-MAP');
|
|
146
|
-
break;
|
|
147
|
-
|
|
148
|
-
default:
|
|
149
|
-
throw new Error(`Unexpected node type ${node.type}`);
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
if (scalar) {
|
|
153
|
-
const value = node.cstNode.strValue.replace(/\\/g, '\\\\').replace(/\0/g, '\\0').replace(/\x07/g, '\\a').replace(/\x08/g, '\\b').replace(/\t/g, '\\t').replace(/\n/g, '\\n').replace(/\v/g, '\\v').replace(/\f/g, '\\f').replace(/\r/g, '\\r').replace(/\x1b/g, '\\e');
|
|
154
|
-
events.push(`=VAL${props} ${scalar}${value}`);
|
|
155
|
-
}
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
const scalar = scalarChar[String(node.type)];
|
|
117
|
+
if (!scalar)
|
|
118
|
+
throw new Error(`Unexpected node type ${node.type}`);
|
|
119
|
+
const value = node.source
|
|
120
|
+
.replace(/\\/g, '\\\\')
|
|
121
|
+
.replace(/\0/g, '\\0')
|
|
122
|
+
.replace(/\x07/g, '\\a')
|
|
123
|
+
.replace(/\x08/g, '\\b')
|
|
124
|
+
.replace(/\t/g, '\\t')
|
|
125
|
+
.replace(/\n/g, '\\n')
|
|
126
|
+
.replace(/\v/g, '\\v')
|
|
127
|
+
.replace(/\f/g, '\\f')
|
|
128
|
+
.replace(/\r/g, '\\r')
|
|
129
|
+
.replace(/\x1b/g, '\\e');
|
|
130
|
+
events.push(`=VAL${props} ${scalar}${value}`);
|
|
131
|
+
}
|
|
156
132
|
}
|
|
157
133
|
|
|
158
134
|
exports.testEvents = testEvents;
|
package/dist/util.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { debug, LogLevelId, warn } from './log.js';
|
|
2
|
+
export { findPair } from './nodes/YAMLMap.js';
|
|
3
|
+
export { toJS, ToJSContext } from './nodes/toJS.js';
|
|
4
|
+
export { foldFlowLines } from './stringify/foldFlowLines';
|
|
5
|
+
export { stringifyNumber } from './stringify/stringifyNumber.js';
|
|
6
|
+
export { stringifyString } from './stringify/stringifyString.js';
|
package/dist/util.js
CHANGED
|
@@ -1,21 +1,18 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var log = require('./log.js');
|
|
4
|
+
var YAMLMap = require('./nodes/YAMLMap.js');
|
|
5
|
+
var toJS = require('./nodes/toJS.js');
|
|
6
|
+
var foldFlowLines = require('./stringify/foldFlowLines.js');
|
|
3
7
|
var stringifyNumber = require('./stringify/stringifyNumber.js');
|
|
4
8
|
var stringifyString = require('./stringify/stringifyString.js');
|
|
5
|
-
var constants = require('./constants.js');
|
|
6
|
-
var errors = require('./errors.js');
|
|
7
|
-
var YAMLMap = require('./ast/YAMLMap.js');
|
|
8
|
-
var toJS = require('./ast/toJS.js');
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
|
|
12
|
-
exports.
|
|
13
|
-
exports.
|
|
14
|
-
exports.Type = constants.Type;
|
|
15
|
-
exports.YAMLError = errors.YAMLError;
|
|
16
|
-
exports.YAMLReferenceError = errors.YAMLReferenceError;
|
|
17
|
-
exports.YAMLSemanticError = errors.YAMLSemanticError;
|
|
18
|
-
exports.YAMLSyntaxError = errors.YAMLSyntaxError;
|
|
19
|
-
exports.YAMLWarning = errors.YAMLWarning;
|
|
12
|
+
exports.debug = log.debug;
|
|
13
|
+
exports.warn = log.warn;
|
|
20
14
|
exports.findPair = YAMLMap.findPair;
|
|
21
15
|
exports.toJS = toJS.toJS;
|
|
16
|
+
exports.foldFlowLines = foldFlowLines.foldFlowLines;
|
|
17
|
+
exports.stringifyNumber = stringifyNumber.stringifyNumber;
|
|
18
|
+
exports.stringifyString = stringifyString.stringifyString;
|
package/dist/visit.d.ts
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type { Document } from './doc/Document.js';
|
|
2
|
+
import type { Alias } from './nodes/Alias.js';
|
|
3
|
+
import { Node } from './nodes/Node.js';
|
|
4
|
+
import type { Pair } from './nodes/Pair.js';
|
|
5
|
+
import type { Scalar } from './nodes/Scalar.js';
|
|
6
|
+
import type { YAMLMap } from './nodes/YAMLMap.js';
|
|
7
|
+
import type { YAMLSeq } from './nodes/YAMLSeq.js';
|
|
8
|
+
export declare type visitorFn<T> = (key: number | 'key' | 'value' | null, node: T, path: readonly (Document | Node | Pair)[]) => void | symbol | number | Node | Pair;
|
|
9
|
+
export declare type visitor = visitorFn<unknown> | {
|
|
10
|
+
Alias?: visitorFn<Alias>;
|
|
11
|
+
Collection?: visitorFn<YAMLMap | YAMLSeq>;
|
|
12
|
+
Map?: visitorFn<YAMLMap>;
|
|
13
|
+
Node?: visitorFn<Alias | Scalar | YAMLMap | YAMLSeq>;
|
|
14
|
+
Pair?: visitorFn<Pair>;
|
|
15
|
+
Scalar?: visitorFn<Scalar>;
|
|
16
|
+
Seq?: visitorFn<YAMLSeq>;
|
|
17
|
+
Value?: visitorFn<Scalar | YAMLMap | YAMLSeq>;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Apply a visitor to an AST node or document.
|
|
21
|
+
*
|
|
22
|
+
* Walks through the tree (depth-first) starting from `node`, calling a
|
|
23
|
+
* `visitor` function with three arguments:
|
|
24
|
+
* - `key`: For sequence values and map `Pair`, the node's index in the
|
|
25
|
+
* collection. Within a `Pair`, `'key'` or `'value'`, correspondingly.
|
|
26
|
+
* `null` for the root node.
|
|
27
|
+
* - `node`: The current node.
|
|
28
|
+
* - `path`: The ancestry of the current node.
|
|
29
|
+
*
|
|
30
|
+
* The return value of the visitor may be used to control the traversal:
|
|
31
|
+
* - `undefined` (default): Do nothing and continue
|
|
32
|
+
* - `visit.SKIP`: Do not visit the children of this node, continue with next
|
|
33
|
+
* sibling
|
|
34
|
+
* - `visit.BREAK`: Terminate traversal completely
|
|
35
|
+
* - `visit.REMOVE`: Remove the current node, then continue with the next one
|
|
36
|
+
* - `Node`: Replace the current node, then continue by visiting it
|
|
37
|
+
* - `number`: While iterating the items of a sequence or map, set the index
|
|
38
|
+
* of the next step. This is useful especially if the index of the current
|
|
39
|
+
* node has changed.
|
|
40
|
+
*
|
|
41
|
+
* If `visitor` is a single function, it will be called with all values
|
|
42
|
+
* encountered in the tree, including e.g. `null` values. Alternatively,
|
|
43
|
+
* separate visitor functions may be defined for each `Map`, `Pair`, `Seq`,
|
|
44
|
+
* `Alias` and `Scalar` node. To define the same visitor function for more than
|
|
45
|
+
* one node type, use the `Collection` (map and seq), `Value` (map, seq & scalar)
|
|
46
|
+
* and `Node` (alias, map, seq & scalar) targets. Of all these, only the most
|
|
47
|
+
* specific defined one will be used for each node.
|
|
48
|
+
*/
|
|
49
|
+
export declare function visit(node: Node | Document | null, visitor: visitorFn<unknown> | {
|
|
50
|
+
Alias?: visitorFn<Alias>;
|
|
51
|
+
Collection?: visitorFn<YAMLMap | YAMLSeq>;
|
|
52
|
+
Map?: visitorFn<YAMLMap>;
|
|
53
|
+
Node?: visitorFn<Alias | Scalar | YAMLMap | YAMLSeq>;
|
|
54
|
+
Pair?: visitorFn<Pair>;
|
|
55
|
+
Scalar?: visitorFn<Scalar>;
|
|
56
|
+
Seq?: visitorFn<YAMLSeq>;
|
|
57
|
+
Value?: visitorFn<Scalar | YAMLMap | YAMLSeq>;
|
|
58
|
+
}): void;
|
|
59
|
+
export declare namespace visit {
|
|
60
|
+
var BREAK: symbol;
|
|
61
|
+
var SKIP: symbol;
|
|
62
|
+
var REMOVE: symbol;
|
|
63
|
+
}
|
package/dist/visit.js
CHANGED
|
@@ -1,85 +1,148 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var Node = require('./ast/Node.js');
|
|
5
|
-
var Pair = require('./ast/Pair.js');
|
|
6
|
-
var Scalar = require('./ast/Scalar.js');
|
|
7
|
-
var YAMLMap = require('./ast/YAMLMap.js');
|
|
8
|
-
var YAMLSeq = require('./ast/YAMLSeq.js');
|
|
9
|
-
var Document = require('./doc/Document.js');
|
|
3
|
+
var Node = require('./nodes/Node.js');
|
|
10
4
|
|
|
11
5
|
const BREAK = Symbol('break visit');
|
|
12
6
|
const SKIP = Symbol('skip children');
|
|
13
7
|
const REMOVE = Symbol('remove node');
|
|
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
|
-
|
|
8
|
+
/**
|
|
9
|
+
* Apply a visitor to an AST node or document.
|
|
10
|
+
*
|
|
11
|
+
* Walks through the tree (depth-first) starting from `node`, calling a
|
|
12
|
+
* `visitor` function with three arguments:
|
|
13
|
+
* - `key`: For sequence values and map `Pair`, the node's index in the
|
|
14
|
+
* collection. Within a `Pair`, `'key'` or `'value'`, correspondingly.
|
|
15
|
+
* `null` for the root node.
|
|
16
|
+
* - `node`: The current node.
|
|
17
|
+
* - `path`: The ancestry of the current node.
|
|
18
|
+
*
|
|
19
|
+
* The return value of the visitor may be used to control the traversal:
|
|
20
|
+
* - `undefined` (default): Do nothing and continue
|
|
21
|
+
* - `visit.SKIP`: Do not visit the children of this node, continue with next
|
|
22
|
+
* sibling
|
|
23
|
+
* - `visit.BREAK`: Terminate traversal completely
|
|
24
|
+
* - `visit.REMOVE`: Remove the current node, then continue with the next one
|
|
25
|
+
* - `Node`: Replace the current node, then continue by visiting it
|
|
26
|
+
* - `number`: While iterating the items of a sequence or map, set the index
|
|
27
|
+
* of the next step. This is useful especially if the index of the current
|
|
28
|
+
* node has changed.
|
|
29
|
+
*
|
|
30
|
+
* If `visitor` is a single function, it will be called with all values
|
|
31
|
+
* encountered in the tree, including e.g. `null` values. Alternatively,
|
|
32
|
+
* separate visitor functions may be defined for each `Map`, `Pair`, `Seq`,
|
|
33
|
+
* `Alias` and `Scalar` node. To define the same visitor function for more than
|
|
34
|
+
* one node type, use the `Collection` (map and seq), `Value` (map, seq & scalar)
|
|
35
|
+
* and `Node` (alias, map, seq & scalar) targets. Of all these, only the most
|
|
36
|
+
* specific defined one will be used for each node.
|
|
37
|
+
*/
|
|
38
|
+
function visit(node, visitor) {
|
|
39
|
+
if (typeof visitor === 'object' &&
|
|
40
|
+
(visitor.Collection || visitor.Node || visitor.Value)) {
|
|
41
|
+
visitor = Object.assign({
|
|
42
|
+
Alias: visitor.Node,
|
|
43
|
+
Map: visitor.Node,
|
|
44
|
+
Scalar: visitor.Node,
|
|
45
|
+
Seq: visitor.Node
|
|
46
|
+
}, visitor.Value && {
|
|
47
|
+
Map: visitor.Value,
|
|
48
|
+
Scalar: visitor.Value,
|
|
49
|
+
Seq: visitor.Value
|
|
50
|
+
}, visitor.Collection && {
|
|
51
|
+
Map: visitor.Collection,
|
|
52
|
+
Seq: visitor.Collection
|
|
53
|
+
}, visitor);
|
|
41
54
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
if (typeof ctrl !== 'symbol') {
|
|
47
|
-
if (node instanceof YAMLMap.YAMLMap || node instanceof YAMLSeq.YAMLSeq) {
|
|
48
|
-
path = Object.freeze(path.concat(node));
|
|
49
|
-
|
|
50
|
-
for (let i = 0; i < node.items.length; ++i) {
|
|
51
|
-
const ci = _visit(i, node.items[i], visitor, path);
|
|
52
|
-
|
|
53
|
-
if (typeof ci === 'number') i = ci - 1;else if (ci === BREAK) return BREAK;else if (ci === REMOVE) {
|
|
54
|
-
node.items.splice(i, 1);
|
|
55
|
-
i -= 1;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
} else if (node instanceof Pair.Pair) {
|
|
59
|
-
path = Object.freeze(path.concat(node));
|
|
60
|
-
|
|
61
|
-
const ck = _visit('key', node.key, visitor, path);
|
|
62
|
-
|
|
63
|
-
if (ck === BREAK) return BREAK;else if (ck === REMOVE) node.key = null;
|
|
64
|
-
|
|
65
|
-
const cv = _visit('value', node.value, visitor, path);
|
|
66
|
-
|
|
67
|
-
if (cv === BREAK) return BREAK;else if (cv === REMOVE) node.value = null;
|
|
55
|
+
if (Node.isDocument(node)) {
|
|
56
|
+
const cd = _visit(null, node.contents, visitor, Object.freeze([node]));
|
|
57
|
+
if (cd === REMOVE)
|
|
58
|
+
node.contents = null;
|
|
68
59
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
return ctrl;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
function visit(node, visitor) {
|
|
75
|
-
if (node instanceof Document.Document) {
|
|
76
|
-
const cd = _visit(null, node.contents, visitor, Object.freeze([node]));
|
|
77
|
-
|
|
78
|
-
if (cd === REMOVE) node.contents = null;
|
|
79
|
-
} else _visit(null, node, visitor, Object.freeze([]));
|
|
60
|
+
else
|
|
61
|
+
_visit(null, node, visitor, Object.freeze([]));
|
|
80
62
|
}
|
|
63
|
+
// Without the `as symbol` casts, TS declares these in the `visit`
|
|
64
|
+
// namespace using `var`, but then complains about that because
|
|
65
|
+
// `unique symbol` must be `const`.
|
|
66
|
+
/** Terminate visit traversal completely */
|
|
81
67
|
visit.BREAK = BREAK;
|
|
68
|
+
/** Do not visit the children of the current node */
|
|
82
69
|
visit.SKIP = SKIP;
|
|
70
|
+
/** Remove the current node */
|
|
83
71
|
visit.REMOVE = REMOVE;
|
|
72
|
+
function _visit(key, node, visitor, path) {
|
|
73
|
+
let ctrl = undefined;
|
|
74
|
+
if (typeof visitor === 'function')
|
|
75
|
+
ctrl = visitor(key, node, path);
|
|
76
|
+
else if (Node.isMap(node)) {
|
|
77
|
+
if (visitor.Map)
|
|
78
|
+
ctrl = visitor.Map(key, node, path);
|
|
79
|
+
}
|
|
80
|
+
else if (Node.isSeq(node)) {
|
|
81
|
+
if (visitor.Seq)
|
|
82
|
+
ctrl = visitor.Seq(key, node, path);
|
|
83
|
+
}
|
|
84
|
+
else if (Node.isPair(node)) {
|
|
85
|
+
if (visitor.Pair)
|
|
86
|
+
ctrl = visitor.Pair(key, node, path);
|
|
87
|
+
}
|
|
88
|
+
else if (Node.isScalar(node)) {
|
|
89
|
+
if (visitor.Scalar)
|
|
90
|
+
ctrl = visitor.Scalar(key, node, path);
|
|
91
|
+
}
|
|
92
|
+
else if (Node.isAlias(node)) {
|
|
93
|
+
if (visitor.Alias)
|
|
94
|
+
ctrl = visitor.Alias(key, node, path);
|
|
95
|
+
}
|
|
96
|
+
if (Node.isNode(ctrl) || Node.isPair(ctrl)) {
|
|
97
|
+
const parent = path[path.length - 1];
|
|
98
|
+
if (Node.isCollection(parent)) {
|
|
99
|
+
parent.items[key] = ctrl;
|
|
100
|
+
}
|
|
101
|
+
else if (Node.isPair(parent)) {
|
|
102
|
+
if (key === 'key')
|
|
103
|
+
parent.key = ctrl;
|
|
104
|
+
else
|
|
105
|
+
parent.value = ctrl;
|
|
106
|
+
}
|
|
107
|
+
else if (Node.isDocument(parent)) {
|
|
108
|
+
parent.contents = ctrl;
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
const pt = Node.isAlias(parent) ? 'alias' : 'scalar';
|
|
112
|
+
throw new Error(`Cannot replace node with ${pt} parent`);
|
|
113
|
+
}
|
|
114
|
+
return _visit(key, ctrl, visitor, path);
|
|
115
|
+
}
|
|
116
|
+
if (typeof ctrl !== 'symbol') {
|
|
117
|
+
if (Node.isCollection(node)) {
|
|
118
|
+
path = Object.freeze(path.concat(node));
|
|
119
|
+
for (let i = 0; i < node.items.length; ++i) {
|
|
120
|
+
const ci = _visit(i, node.items[i], visitor, path);
|
|
121
|
+
if (typeof ci === 'number')
|
|
122
|
+
i = ci - 1;
|
|
123
|
+
else if (ci === BREAK)
|
|
124
|
+
return BREAK;
|
|
125
|
+
else if (ci === REMOVE) {
|
|
126
|
+
node.items.splice(i, 1);
|
|
127
|
+
i -= 1;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
else if (Node.isPair(node)) {
|
|
132
|
+
path = Object.freeze(path.concat(node));
|
|
133
|
+
const ck = _visit('key', node.key, visitor, path);
|
|
134
|
+
if (ck === BREAK)
|
|
135
|
+
return BREAK;
|
|
136
|
+
else if (ck === REMOVE)
|
|
137
|
+
node.key = null;
|
|
138
|
+
const cv = _visit('value', node.value, visitor, path);
|
|
139
|
+
if (cv === BREAK)
|
|
140
|
+
return BREAK;
|
|
141
|
+
else if (cv === REMOVE)
|
|
142
|
+
node.value = null;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
return ctrl;
|
|
146
|
+
}
|
|
84
147
|
|
|
85
148
|
exports.visit = visit;
|