yaml 2.3.0-0 → 2.3.0-2
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/browser/dist/compose/compose-collection.js +1 -1
- package/browser/dist/compose/compose-scalar.js +1 -1
- package/browser/dist/compose/composer.js +1 -1
- package/browser/dist/compose/resolve-flow-collection.js +1 -1
- package/browser/dist/compose/util-map-includes.js +1 -1
- package/browser/dist/doc/Document.js +2 -4
- package/browser/dist/doc/anchors.js +1 -1
- package/browser/dist/doc/createNode.js +1 -1
- package/browser/dist/doc/directives.js +1 -1
- package/browser/dist/index.js +1 -1
- package/browser/dist/nodes/Alias.js +9 -2
- package/browser/dist/nodes/Collection.js +2 -1
- package/browser/dist/nodes/Node.js +25 -35
- package/browser/dist/nodes/Pair.js +1 -1
- package/browser/dist/nodes/Scalar.js +2 -1
- package/browser/dist/nodes/YAMLMap.js +1 -1
- package/browser/dist/nodes/YAMLSeq.js +1 -1
- package/browser/dist/nodes/addPairToJSMap.js +1 -1
- package/browser/dist/nodes/identity.js +36 -0
- package/browser/dist/nodes/toJS.js +1 -1
- package/browser/dist/schema/Schema.js +1 -1
- package/browser/dist/schema/common/map.js +1 -1
- package/browser/dist/schema/common/seq.js +1 -1
- package/browser/dist/schema/yaml-1.1/omap.js +2 -2
- package/browser/dist/schema/yaml-1.1/pairs.js +1 -1
- package/browser/dist/schema/yaml-1.1/set.js +1 -1
- package/browser/dist/stringify/stringify.js +1 -1
- package/browser/dist/stringify/stringifyCollection.js +1 -1
- package/browser/dist/stringify/stringifyDocument.js +1 -1
- package/browser/dist/stringify/stringifyPair.js +1 -1
- package/browser/dist/stringify/stringifyString.js +6 -6
- package/browser/dist/util.js +2 -0
- package/browser/dist/visit.js +1 -1
- package/dist/compose/compose-collection.d.ts +1 -1
- package/dist/compose/compose-collection.js +3 -3
- package/dist/compose/compose-scalar.js +7 -7
- package/dist/compose/composer.d.ts +1 -1
- package/dist/compose/composer.js +3 -3
- package/dist/compose/resolve-flow-collection.d.ts +1 -1
- package/dist/compose/resolve-flow-collection.js +2 -2
- package/dist/compose/util-map-includes.d.ts +3 -3
- package/dist/compose/util-map-includes.js +3 -3
- package/dist/doc/Document.d.ts +2 -1
- package/dist/doc/Document.js +12 -14
- package/dist/doc/anchors.d.ts +2 -2
- package/dist/doc/anchors.js +2 -2
- package/dist/doc/createNode.d.ts +1 -1
- package/dist/doc/createNode.js +8 -8
- package/dist/doc/directives.js +3 -3
- package/dist/index.d.ts +2 -1
- package/dist/index.js +9 -9
- package/dist/nodes/Alias.d.ts +1 -1
- package/dist/nodes/Alias.js +12 -5
- package/dist/nodes/Collection.d.ts +3 -2
- package/dist/nodes/Collection.js +10 -9
- package/dist/nodes/Node.d.ts +4 -17
- package/dist/nodes/Node.js +25 -51
- package/dist/nodes/Pair.d.ts +2 -2
- package/dist/nodes/Pair.js +4 -4
- package/dist/nodes/Scalar.js +2 -1
- package/dist/nodes/YAMLMap.d.ts +1 -1
- package/dist/nodes/YAMLMap.js +9 -9
- package/dist/nodes/YAMLSeq.d.ts +1 -1
- package/dist/nodes/YAMLSeq.js +5 -5
- package/dist/nodes/addPairToJSMap.js +7 -7
- package/dist/nodes/identity.d.ts +23 -0
- package/dist/nodes/identity.js +53 -0
- package/dist/nodes/toJS.d.ts +1 -4
- package/dist/nodes/toJS.js +2 -2
- package/dist/schema/Schema.d.ts +1 -1
- package/dist/schema/Schema.js +4 -4
- package/dist/schema/common/map.js +2 -2
- package/dist/schema/common/seq.js +2 -2
- package/dist/schema/core/schema.d.ts +1 -1
- package/dist/schema/json/schema.d.ts +1 -1
- package/dist/schema/tags.d.ts +1 -1
- package/dist/schema/yaml-1.1/omap.d.ts +1 -1
- package/dist/schema/yaml-1.1/omap.js +4 -4
- package/dist/schema/yaml-1.1/pairs.d.ts +1 -1
- package/dist/schema/yaml-1.1/pairs.js +5 -5
- package/dist/schema/yaml-1.1/schema.d.ts +1 -1
- package/dist/schema/yaml-1.1/set.js +5 -5
- package/dist/stringify/stringify.js +8 -8
- package/dist/stringify/stringifyCollection.js +8 -8
- package/dist/stringify/stringifyDocument.d.ts +3 -3
- package/dist/stringify/stringifyDocument.js +2 -2
- package/dist/stringify/stringifyPair.js +9 -9
- package/dist/stringify/stringifyString.js +6 -6
- package/dist/test-events.js +8 -8
- package/dist/util.d.ts +2 -0
- package/dist/util.js +4 -0
- package/dist/visit.js +18 -18
- package/package.json +7 -4
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isNode, isMap } from '../nodes/
|
|
1
|
+
import { isNode, isMap } from '../nodes/identity.js';
|
|
2
2
|
import { Scalar } from '../nodes/Scalar.js';
|
|
3
3
|
import { resolveBlockMap } from './resolve-block-map.js';
|
|
4
4
|
import { resolveBlockSeq } from './resolve-block-seq.js';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SCALAR, isScalar } from '../nodes/
|
|
1
|
+
import { SCALAR, isScalar } from '../nodes/identity.js';
|
|
2
2
|
import { Scalar } from '../nodes/Scalar.js';
|
|
3
3
|
import { resolveBlockScalar } from './resolve-block-scalar.js';
|
|
4
4
|
import { resolveFlowScalar } from './resolve-flow-scalar.js';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Directives } from '../doc/directives.js';
|
|
2
2
|
import { Document } from '../doc/Document.js';
|
|
3
3
|
import { YAMLWarning, YAMLParseError } from '../errors.js';
|
|
4
|
-
import { isCollection, isPair } from '../nodes/
|
|
4
|
+
import { isCollection, isPair } from '../nodes/identity.js';
|
|
5
5
|
import { composeDoc } from './compose-doc.js';
|
|
6
6
|
import { resolveEnd } from './resolve-end.js';
|
|
7
7
|
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { Alias } from '../nodes/Alias.js';
|
|
2
2
|
import { isEmptyPath, collectionFromPath } from '../nodes/Collection.js';
|
|
3
|
-
import { NODE_TYPE, DOC, isNode, isCollection, isScalar } from '../nodes/
|
|
3
|
+
import { NODE_TYPE, DOC, isNode, isCollection, isScalar } from '../nodes/identity.js';
|
|
4
4
|
import { Pair } from '../nodes/Pair.js';
|
|
5
5
|
import { toJS } from '../nodes/toJS.js';
|
|
6
6
|
import { Schema } from '../schema/Schema.js';
|
|
7
|
-
import { stringify } from '../stringify/stringify.js';
|
|
8
7
|
import { stringifyDocument } from '../stringify/stringifyDocument.js';
|
|
9
8
|
import { anchorNames, findNewAnchor, createNodeAnchors } from './anchors.js';
|
|
10
9
|
import { applyReviver } from './applyReviver.js';
|
|
@@ -295,8 +294,7 @@ class Document {
|
|
|
295
294
|
keep: !json,
|
|
296
295
|
mapAsMap: mapAsMap === true,
|
|
297
296
|
mapKeyWarned: false,
|
|
298
|
-
maxAliasCount: typeof maxAliasCount === 'number' ? maxAliasCount : 100
|
|
299
|
-
stringify
|
|
297
|
+
maxAliasCount: typeof maxAliasCount === 'number' ? maxAliasCount : 100
|
|
300
298
|
};
|
|
301
299
|
const res = toJS(this.contents, jsonArg ?? '', ctx);
|
|
302
300
|
if (typeof onAnchor === 'function')
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Alias } from '../nodes/Alias.js';
|
|
2
|
-
import { isNode, isPair, MAP, SEQ, isDocument } from '../nodes/
|
|
2
|
+
import { isNode, isPair, MAP, SEQ, isDocument } from '../nodes/identity.js';
|
|
3
3
|
import { Scalar } from '../nodes/Scalar.js';
|
|
4
4
|
|
|
5
5
|
const defaultTagPrefix = 'tag:yaml.org,2002:';
|
package/browser/dist/index.js
CHANGED
|
@@ -3,7 +3,7 @@ export { Document } from './doc/Document.js';
|
|
|
3
3
|
export { Schema } from './schema/Schema.js';
|
|
4
4
|
export { YAMLError, YAMLParseError, YAMLWarning } from './errors.js';
|
|
5
5
|
export { Alias } from './nodes/Alias.js';
|
|
6
|
-
export { isAlias, isCollection, isDocument, isMap, isNode, isPair, isScalar, isSeq } from './nodes/
|
|
6
|
+
export { isAlias, isCollection, isDocument, isMap, isNode, isPair, isScalar, isSeq } from './nodes/identity.js';
|
|
7
7
|
export { Pair } from './nodes/Pair.js';
|
|
8
8
|
export { Scalar } from './nodes/Scalar.js';
|
|
9
9
|
export { YAMLMap } from './nodes/YAMLMap.js';
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { anchorIsValid } from '../doc/anchors.js';
|
|
2
2
|
import { visit } from '../visit.js';
|
|
3
|
-
import {
|
|
3
|
+
import { ALIAS, isAlias, isCollection, isPair } from './identity.js';
|
|
4
|
+
import { NodeBase } from './Node.js';
|
|
5
|
+
import { toJS } from './toJS.js';
|
|
4
6
|
|
|
5
7
|
class Alias extends NodeBase {
|
|
6
8
|
constructor(source) {
|
|
@@ -37,7 +39,12 @@ class Alias extends NodeBase {
|
|
|
37
39
|
const msg = `Unresolved alias (the anchor must be set before the alias): ${this.source}`;
|
|
38
40
|
throw new ReferenceError(msg);
|
|
39
41
|
}
|
|
40
|
-
|
|
42
|
+
let data = anchors.get(source);
|
|
43
|
+
if (!data) {
|
|
44
|
+
// Resolve anchors for Node.prototype.toJS()
|
|
45
|
+
toJS(source, null, ctx);
|
|
46
|
+
data = anchors.get(source);
|
|
47
|
+
}
|
|
41
48
|
/* istanbul ignore if */
|
|
42
49
|
if (!data || data.res === undefined) {
|
|
43
50
|
const msg = 'This should not happen: Alias anchor was not resolved?';
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { createNode } from '../doc/createNode.js';
|
|
2
|
-
import {
|
|
2
|
+
import { isNode, isPair, isCollection, isScalar } from './identity.js';
|
|
3
|
+
import { NodeBase } from './Node.js';
|
|
3
4
|
|
|
4
5
|
function collectionFromPath(schema, path, value) {
|
|
5
6
|
let v = value;
|
|
@@ -1,37 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const SCALAR = Symbol.for('yaml.scalar');
|
|
6
|
-
const SEQ = Symbol.for('yaml.seq');
|
|
7
|
-
const NODE_TYPE = Symbol.for('yaml.node.type');
|
|
8
|
-
const isAlias = (node) => !!node && typeof node === 'object' && node[NODE_TYPE] === ALIAS;
|
|
9
|
-
const isDocument = (node) => !!node && typeof node === 'object' && node[NODE_TYPE] === DOC;
|
|
10
|
-
const isMap = (node) => !!node && typeof node === 'object' && node[NODE_TYPE] === MAP;
|
|
11
|
-
const isPair = (node) => !!node && typeof node === 'object' && node[NODE_TYPE] === PAIR;
|
|
12
|
-
const isScalar = (node) => !!node && typeof node === 'object' && node[NODE_TYPE] === SCALAR;
|
|
13
|
-
const isSeq = (node) => !!node && typeof node === 'object' && node[NODE_TYPE] === SEQ;
|
|
14
|
-
function isCollection(node) {
|
|
15
|
-
if (node && typeof node === 'object')
|
|
16
|
-
switch (node[NODE_TYPE]) {
|
|
17
|
-
case MAP:
|
|
18
|
-
case SEQ:
|
|
19
|
-
return true;
|
|
20
|
-
}
|
|
21
|
-
return false;
|
|
22
|
-
}
|
|
23
|
-
function isNode(node) {
|
|
24
|
-
if (node && typeof node === 'object')
|
|
25
|
-
switch (node[NODE_TYPE]) {
|
|
26
|
-
case ALIAS:
|
|
27
|
-
case MAP:
|
|
28
|
-
case SCALAR:
|
|
29
|
-
case SEQ:
|
|
30
|
-
return true;
|
|
31
|
-
}
|
|
32
|
-
return false;
|
|
33
|
-
}
|
|
34
|
-
const hasAnchor = (node) => (isScalar(node) || isCollection(node)) && !!node.anchor;
|
|
1
|
+
import { applyReviver } from '../doc/applyReviver.js';
|
|
2
|
+
import { NODE_TYPE, isDocument } from './identity.js';
|
|
3
|
+
import { toJS } from './toJS.js';
|
|
4
|
+
|
|
35
5
|
class NodeBase {
|
|
36
6
|
constructor(type) {
|
|
37
7
|
Object.defineProperty(this, NODE_TYPE, { value: type });
|
|
@@ -43,6 +13,26 @@ class NodeBase {
|
|
|
43
13
|
copy.range = this.range.slice();
|
|
44
14
|
return copy;
|
|
45
15
|
}
|
|
16
|
+
/** A plain JavaScript representation of this node. */
|
|
17
|
+
toJS(doc, { mapAsMap, maxAliasCount, onAnchor, reviver } = {}) {
|
|
18
|
+
if (!isDocument(doc))
|
|
19
|
+
throw new TypeError('A document argument is required');
|
|
20
|
+
const ctx = {
|
|
21
|
+
anchors: new Map(),
|
|
22
|
+
doc,
|
|
23
|
+
keep: true,
|
|
24
|
+
mapAsMap: mapAsMap === true,
|
|
25
|
+
mapKeyWarned: false,
|
|
26
|
+
maxAliasCount: typeof maxAliasCount === 'number' ? maxAliasCount : 100
|
|
27
|
+
};
|
|
28
|
+
const res = toJS(this, '', ctx);
|
|
29
|
+
if (typeof onAnchor === 'function')
|
|
30
|
+
for (const { count, res } of ctx.anchors.values())
|
|
31
|
+
onAnchor(res, count);
|
|
32
|
+
return typeof reviver === 'function'
|
|
33
|
+
? applyReviver(reviver, { '': res }, '', res)
|
|
34
|
+
: res;
|
|
35
|
+
}
|
|
46
36
|
}
|
|
47
37
|
|
|
48
|
-
export {
|
|
38
|
+
export { NodeBase };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createNode } from '../doc/createNode.js';
|
|
2
2
|
import { stringifyPair } from '../stringify/stringifyPair.js';
|
|
3
3
|
import { addPairToJSMap } from './addPairToJSMap.js';
|
|
4
|
-
import { NODE_TYPE, PAIR, isNode } from './
|
|
4
|
+
import { NODE_TYPE, PAIR, isNode } from './identity.js';
|
|
5
5
|
|
|
6
6
|
function createPair(key, value, ctx) {
|
|
7
7
|
const k = createNode(key, undefined, ctx);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { SCALAR } from './identity.js';
|
|
2
|
+
import { NodeBase } from './Node.js';
|
|
2
3
|
import { toJS } from './toJS.js';
|
|
3
4
|
|
|
4
5
|
const isScalarValue = (value) => !value || (typeof value !== 'function' && typeof value !== 'object');
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { stringifyCollection } from '../stringify/stringifyCollection.js';
|
|
2
2
|
import { addPairToJSMap } from './addPairToJSMap.js';
|
|
3
3
|
import { Collection } from './Collection.js';
|
|
4
|
-
import { isPair, isScalar, MAP } from './
|
|
4
|
+
import { isPair, isScalar, MAP } from './identity.js';
|
|
5
5
|
import { Pair } from './Pair.js';
|
|
6
6
|
import { isScalarValue } from './Scalar.js';
|
|
7
7
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { stringifyCollection } from '../stringify/stringifyCollection.js';
|
|
2
2
|
import { Collection } from './Collection.js';
|
|
3
|
-
import { SEQ, isScalar } from './
|
|
3
|
+
import { SEQ, isScalar } from './identity.js';
|
|
4
4
|
import { isScalarValue } from './Scalar.js';
|
|
5
5
|
import { toJS } from './toJS.js';
|
|
6
6
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { warn } from '../log.js';
|
|
2
2
|
import { createStringifyContext } from '../stringify/stringify.js';
|
|
3
|
-
import { isAlias, isSeq, isScalar, isMap, isNode } from './
|
|
3
|
+
import { isAlias, isSeq, isScalar, isMap, isNode } from './identity.js';
|
|
4
4
|
import { Scalar } from './Scalar.js';
|
|
5
5
|
import { toJS } from './toJS.js';
|
|
6
6
|
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
const ALIAS = Symbol.for('yaml.alias');
|
|
2
|
+
const DOC = Symbol.for('yaml.document');
|
|
3
|
+
const MAP = Symbol.for('yaml.map');
|
|
4
|
+
const PAIR = Symbol.for('yaml.pair');
|
|
5
|
+
const SCALAR = Symbol.for('yaml.scalar');
|
|
6
|
+
const SEQ = Symbol.for('yaml.seq');
|
|
7
|
+
const NODE_TYPE = Symbol.for('yaml.node.type');
|
|
8
|
+
const isAlias = (node) => !!node && typeof node === 'object' && node[NODE_TYPE] === ALIAS;
|
|
9
|
+
const isDocument = (node) => !!node && typeof node === 'object' && node[NODE_TYPE] === DOC;
|
|
10
|
+
const isMap = (node) => !!node && typeof node === 'object' && node[NODE_TYPE] === MAP;
|
|
11
|
+
const isPair = (node) => !!node && typeof node === 'object' && node[NODE_TYPE] === PAIR;
|
|
12
|
+
const isScalar = (node) => !!node && typeof node === 'object' && node[NODE_TYPE] === SCALAR;
|
|
13
|
+
const isSeq = (node) => !!node && typeof node === 'object' && node[NODE_TYPE] === SEQ;
|
|
14
|
+
function isCollection(node) {
|
|
15
|
+
if (node && typeof node === 'object')
|
|
16
|
+
switch (node[NODE_TYPE]) {
|
|
17
|
+
case MAP:
|
|
18
|
+
case SEQ:
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
function isNode(node) {
|
|
24
|
+
if (node && typeof node === 'object')
|
|
25
|
+
switch (node[NODE_TYPE]) {
|
|
26
|
+
case ALIAS:
|
|
27
|
+
case MAP:
|
|
28
|
+
case SCALAR:
|
|
29
|
+
case SEQ:
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
const hasAnchor = (node) => (isScalar(node) || isCollection(node)) && !!node.anchor;
|
|
35
|
+
|
|
36
|
+
export { ALIAS, DOC, MAP, NODE_TYPE, PAIR, SCALAR, SEQ, hasAnchor, isAlias, isCollection, isDocument, isMap, isNode, isPair, isScalar, isSeq };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { isScalar, isPair } from '../../nodes/identity.js';
|
|
2
2
|
import { toJS } from '../../nodes/toJS.js';
|
|
3
|
-
import { isScalar, isPair } from '../../nodes/Node.js';
|
|
4
3
|
import { YAMLMap } from '../../nodes/YAMLMap.js';
|
|
4
|
+
import { YAMLSeq } from '../../nodes/YAMLSeq.js';
|
|
5
5
|
import { resolvePairs, createPairs } from './pairs.js';
|
|
6
6
|
|
|
7
7
|
class YAMLOMap extends YAMLSeq {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isSeq, isPair, isMap } from '../../nodes/
|
|
1
|
+
import { isSeq, isPair, isMap } from '../../nodes/identity.js';
|
|
2
2
|
import { Pair, createPair } from '../../nodes/Pair.js';
|
|
3
3
|
import { Scalar } from '../../nodes/Scalar.js';
|
|
4
4
|
import { YAMLSeq } from '../../nodes/YAMLSeq.js';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { anchorIsValid } from '../doc/anchors.js';
|
|
2
|
-
import { isPair, isAlias, isNode, isScalar, isCollection } from '../nodes/
|
|
2
|
+
import { isPair, isAlias, isNode, isScalar, isCollection } from '../nodes/identity.js';
|
|
3
3
|
import { stringifyComment } from './stringifyComment.js';
|
|
4
4
|
import { stringifyString } from './stringifyString.js';
|
|
5
5
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Collection } from '../nodes/Collection.js';
|
|
2
|
-
import { isNode, isPair } from '../nodes/
|
|
2
|
+
import { isNode, isPair } from '../nodes/identity.js';
|
|
3
3
|
import { stringify } from './stringify.js';
|
|
4
4
|
import { lineComment, indentComment } from './stringifyComment.js';
|
|
5
5
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isCollection, isNode, isScalar, isSeq } from '../nodes/
|
|
1
|
+
import { isCollection, isNode, isScalar, isSeq } from '../nodes/identity.js';
|
|
2
2
|
import { Scalar } from '../nodes/Scalar.js';
|
|
3
3
|
import { stringify } from './stringify.js';
|
|
4
4
|
import { lineComment, indentComment } from './stringifyComment.js';
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Scalar } from '../nodes/Scalar.js';
|
|
2
2
|
import { foldFlowLines, FOLD_QUOTED, FOLD_FLOW, FOLD_BLOCK } from './foldFlowLines.js';
|
|
3
3
|
|
|
4
|
-
const getFoldOptions = (ctx) => ({
|
|
5
|
-
indentAtStart: ctx.indentAtStart,
|
|
4
|
+
const getFoldOptions = (ctx, isBlock) => ({
|
|
5
|
+
indentAtStart: isBlock ? ctx.indent.length : ctx.indentAtStart,
|
|
6
6
|
lineWidth: ctx.options.lineWidth,
|
|
7
7
|
minContentWidth: ctx.options.minContentWidth
|
|
8
8
|
});
|
|
@@ -115,7 +115,7 @@ function doubleQuotedString(value, ctx) {
|
|
|
115
115
|
str = start ? str + json.slice(start) : json;
|
|
116
116
|
return implicitKey
|
|
117
117
|
? str
|
|
118
|
-
: foldFlowLines(str, indent, FOLD_QUOTED, getFoldOptions(ctx));
|
|
118
|
+
: foldFlowLines(str, indent, FOLD_QUOTED, getFoldOptions(ctx, false));
|
|
119
119
|
}
|
|
120
120
|
function singleQuotedString(value, ctx) {
|
|
121
121
|
if (ctx.options.singleQuote === false ||
|
|
@@ -127,7 +127,7 @@ function singleQuotedString(value, ctx) {
|
|
|
127
127
|
const res = "'" + value.replace(/'/g, "''").replace(/\n+/g, `$&\n${indent}`) + "'";
|
|
128
128
|
return ctx.implicitKey
|
|
129
129
|
? res
|
|
130
|
-
: foldFlowLines(res, indent, FOLD_FLOW, getFoldOptions(ctx));
|
|
130
|
+
: foldFlowLines(res, indent, FOLD_FLOW, getFoldOptions(ctx, false));
|
|
131
131
|
}
|
|
132
132
|
function quotedString(value, ctx) {
|
|
133
133
|
const { singleQuote } = ctx.options;
|
|
@@ -234,7 +234,7 @@ function blockString({ comment, type, value }, ctx, onComment, onChompKeep) {
|
|
|
234
234
|
.replace(/(?:^|\n)([\t ].*)(?:([\n\t ]*)\n(?![\n\t ]))?/g, '$1$2') // more-indented lines aren't folded
|
|
235
235
|
// ^ more-ind. ^ empty ^ capture next empty lines only at end of indent
|
|
236
236
|
.replace(/\n+/g, `$&${indent}`);
|
|
237
|
-
const body = foldFlowLines(`${start}${value}${end}`, indent, FOLD_BLOCK, getFoldOptions(ctx));
|
|
237
|
+
const body = foldFlowLines(`${start}${value}${end}`, indent, FOLD_BLOCK, getFoldOptions(ctx, true));
|
|
238
238
|
return `${header}\n${indent}${body}`;
|
|
239
239
|
}
|
|
240
240
|
function plainString(item, ctx, onComment, onChompKeep) {
|
|
@@ -284,7 +284,7 @@ function plainString(item, ctx, onComment, onChompKeep) {
|
|
|
284
284
|
}
|
|
285
285
|
return implicitKey
|
|
286
286
|
? str
|
|
287
|
-
: foldFlowLines(str, indent, FOLD_FLOW, getFoldOptions(ctx));
|
|
287
|
+
: foldFlowLines(str, indent, FOLD_FLOW, getFoldOptions(ctx, false));
|
|
288
288
|
}
|
|
289
289
|
function stringifyString(item, ctx, onComment, onChompKeep) {
|
|
290
290
|
const { implicitKey, inFlow } = ctx;
|
package/browser/dist/util.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
export { createNode } from './doc/createNode.js';
|
|
1
2
|
export { debug, warn } from './log.js';
|
|
3
|
+
export { createPair } from './nodes/Pair.js';
|
|
2
4
|
export { findPair } from './nodes/YAMLMap.js';
|
|
3
5
|
export { toJS } from './nodes/toJS.js';
|
|
4
6
|
export { map as mapTag } from './schema/common/map.js';
|
package/browser/dist/visit.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isDocument, isNode, isPair, isCollection, isMap, isSeq, isScalar, isAlias } from './nodes/
|
|
1
|
+
import { isDocument, isNode, isPair, isCollection, isMap, isSeq, isScalar, isAlias } from './nodes/identity.js';
|
|
2
2
|
|
|
3
3
|
const BREAK = Symbol('break visit');
|
|
4
4
|
const SKIP = Symbol('skip children');
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ParsedNode } from '../nodes/Node.js';
|
|
1
|
+
import type { ParsedNode } from '../nodes/Node.js';
|
|
2
2
|
import type { BlockMap, BlockSequence, FlowCollection, SourceToken } from '../parse/cst.js';
|
|
3
3
|
import type { ComposeContext, ComposeNode } from './compose-node.js';
|
|
4
4
|
import type { ComposeErrorHandler } from './composer.js';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var identity = require('../nodes/identity.js');
|
|
4
4
|
var Scalar = require('../nodes/Scalar.js');
|
|
5
5
|
var resolveBlockMap = require('./resolve-block-map.js');
|
|
6
6
|
var resolveBlockSeq = require('./resolve-block-seq.js');
|
|
@@ -33,7 +33,7 @@ function composeCollection(CN, ctx, token, tagToken, onError) {
|
|
|
33
33
|
coll.tag = Coll.tagName;
|
|
34
34
|
return coll;
|
|
35
35
|
}
|
|
36
|
-
const expType =
|
|
36
|
+
const expType = identity.isMap(coll) ? 'map' : 'seq';
|
|
37
37
|
let tag = ctx.schema.tags.find(t => t.collection === expType && t.tag === tagName);
|
|
38
38
|
if (!tag) {
|
|
39
39
|
const kt = ctx.schema.knownTags[tagName];
|
|
@@ -48,7 +48,7 @@ function composeCollection(CN, ctx, token, tagToken, onError) {
|
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
50
|
const res = tag.resolve(coll, msg => onError(tagToken, 'TAG_RESOLVE_FAILED', msg), ctx.options);
|
|
51
|
-
const node =
|
|
51
|
+
const node = identity.isNode(res)
|
|
52
52
|
? res
|
|
53
53
|
: new Scalar.Scalar(res);
|
|
54
54
|
node.range = coll.range;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var identity = require('../nodes/identity.js');
|
|
4
4
|
var Scalar = require('../nodes/Scalar.js');
|
|
5
5
|
var resolveBlockScalar = require('./resolve-block-scalar.js');
|
|
6
6
|
var resolveFlowScalar = require('./resolve-flow-scalar.js');
|
|
@@ -16,11 +16,11 @@ function composeScalar(ctx, token, tagToken, onError) {
|
|
|
16
16
|
? findScalarTagByName(ctx.schema, value, tagName, tagToken, onError)
|
|
17
17
|
: token.type === 'scalar'
|
|
18
18
|
? findScalarTagByTest(ctx, value, token, onError)
|
|
19
|
-
: ctx.schema[
|
|
19
|
+
: ctx.schema[identity.SCALAR];
|
|
20
20
|
let scalar;
|
|
21
21
|
try {
|
|
22
22
|
const res = tag.resolve(value, msg => onError(tagToken ?? token, 'TAG_RESOLVE_FAILED', msg), ctx.options);
|
|
23
|
-
scalar =
|
|
23
|
+
scalar = identity.isScalar(res) ? res : new Scalar.Scalar(res);
|
|
24
24
|
}
|
|
25
25
|
catch (error) {
|
|
26
26
|
const msg = error instanceof Error ? error.message : String(error);
|
|
@@ -41,7 +41,7 @@ function composeScalar(ctx, token, tagToken, onError) {
|
|
|
41
41
|
}
|
|
42
42
|
function findScalarTagByName(schema, value, tagName, tagToken, onError) {
|
|
43
43
|
if (tagName === '!')
|
|
44
|
-
return schema[
|
|
44
|
+
return schema[identity.SCALAR]; // non-specific tag
|
|
45
45
|
const matchWithTest = [];
|
|
46
46
|
for (const tag of schema.tags) {
|
|
47
47
|
if (!tag.collection && tag.tag === tagName) {
|
|
@@ -62,13 +62,13 @@ function findScalarTagByName(schema, value, tagName, tagToken, onError) {
|
|
|
62
62
|
return kt;
|
|
63
63
|
}
|
|
64
64
|
onError(tagToken, 'TAG_RESOLVE_FAILED', `Unresolved tag: ${tagName}`, tagName !== 'tag:yaml.org,2002:str');
|
|
65
|
-
return schema[
|
|
65
|
+
return schema[identity.SCALAR];
|
|
66
66
|
}
|
|
67
67
|
function findScalarTagByTest({ directives, schema }, value, token, onError) {
|
|
68
|
-
const tag = schema.tags.find(tag => tag.default && tag.test?.test(value)) || schema[
|
|
68
|
+
const tag = schema.tags.find(tag => tag.default && tag.test?.test(value)) || schema[identity.SCALAR];
|
|
69
69
|
if (schema.compat) {
|
|
70
70
|
const compat = schema.compat.find(tag => tag.default && tag.test?.test(value)) ??
|
|
71
|
-
schema[
|
|
71
|
+
schema[identity.SCALAR];
|
|
72
72
|
if (tag.tag !== compat.tag) {
|
|
73
73
|
const ts = directives.tagString(tag.tag);
|
|
74
74
|
const cs = directives.tagString(compat.tag);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Directives } from '../doc/directives.js';
|
|
2
2
|
import { Document } from '../doc/Document.js';
|
|
3
3
|
import { ErrorCode, YAMLParseError, YAMLWarning } from '../errors.js';
|
|
4
|
-
import { ParsedNode, Range } from '../nodes/Node.js';
|
|
4
|
+
import type { ParsedNode, Range } from '../nodes/Node.js';
|
|
5
5
|
import type { DocumentOptions, ParseOptions, SchemaOptions } from '../options.js';
|
|
6
6
|
import type { Token } from '../parse/cst.js';
|
|
7
7
|
type ErrorSource = number | [number, number] | Range | {
|
package/dist/compose/composer.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
var directives = require('../doc/directives.js');
|
|
4
4
|
var Document = require('../doc/Document.js');
|
|
5
5
|
var errors = require('../errors.js');
|
|
6
|
-
var
|
|
6
|
+
var identity = require('../nodes/identity.js');
|
|
7
7
|
var composeDoc = require('./compose-doc.js');
|
|
8
8
|
var resolveEnd = require('./resolve-end.js');
|
|
9
9
|
|
|
@@ -83,9 +83,9 @@ class Composer {
|
|
|
83
83
|
else if (afterEmptyLine || doc.directives.docStart || !dc) {
|
|
84
84
|
doc.commentBefore = comment;
|
|
85
85
|
}
|
|
86
|
-
else if (
|
|
86
|
+
else if (identity.isCollection(dc) && !dc.flow && dc.items.length > 0) {
|
|
87
87
|
let it = dc.items[0];
|
|
88
|
-
if (
|
|
88
|
+
if (identity.isPair(it))
|
|
89
89
|
it = it.key;
|
|
90
90
|
const cb = it.commentBefore;
|
|
91
91
|
it.commentBefore = cb ? `${comment}\n${cb}` : comment;
|
|
@@ -3,4 +3,4 @@ import { YAMLSeq } from '../nodes/YAMLSeq.js';
|
|
|
3
3
|
import type { FlowCollection } from '../parse/cst.js';
|
|
4
4
|
import type { ComposeContext, ComposeNode } from './compose-node.js';
|
|
5
5
|
import type { ComposeErrorHandler } from './composer.js';
|
|
6
|
-
export declare function resolveFlowCollection({ composeNode, composeEmptyNode }: ComposeNode, ctx: ComposeContext, fc: FlowCollection, onError: ComposeErrorHandler): YAMLMap.Parsed<import("../
|
|
6
|
+
export declare function resolveFlowCollection({ composeNode, composeEmptyNode }: ComposeNode, ctx: ComposeContext, fc: FlowCollection, onError: ComposeErrorHandler): YAMLMap.Parsed<import("../index.js").ParsedNode, import("../index.js").ParsedNode | null> | YAMLSeq.Parsed<import("../index.js").ParsedNode>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var identity = require('../nodes/identity.js');
|
|
4
4
|
var Pair = require('../nodes/Pair.js');
|
|
5
5
|
var YAMLMap = require('../nodes/YAMLMap.js');
|
|
6
6
|
var YAMLSeq = require('../nodes/YAMLSeq.js');
|
|
@@ -75,7 +75,7 @@ function resolveFlowCollection({ composeNode, composeEmptyNode }, ctx, fc, onErr
|
|
|
75
75
|
}
|
|
76
76
|
if (prevItemComment) {
|
|
77
77
|
let prev = coll.items[coll.items.length - 1];
|
|
78
|
-
if (
|
|
78
|
+
if (identity.isPair(prev))
|
|
79
79
|
prev = prev.value ?? prev.key;
|
|
80
80
|
if (prev.comment)
|
|
81
81
|
prev.comment += '\n' + prevItemComment;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ParsedNode } from '../nodes/Node';
|
|
2
|
-
import { Pair } from '../nodes/Pair';
|
|
3
|
-
import { ComposeContext } from './compose-node';
|
|
1
|
+
import type { ParsedNode } from '../nodes/Node.js';
|
|
2
|
+
import type { Pair } from '../nodes/Pair.js';
|
|
3
|
+
import type { ComposeContext } from './compose-node.js';
|
|
4
4
|
export declare function mapIncludes(ctx: ComposeContext, items: Pair<ParsedNode>[], search: ParsedNode): boolean;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var identity = require('../nodes/identity.js');
|
|
4
4
|
|
|
5
5
|
function mapIncludes(ctx, items, search) {
|
|
6
6
|
const { uniqueKeys } = ctx.options;
|
|
@@ -9,8 +9,8 @@ function mapIncludes(ctx, items, search) {
|
|
|
9
9
|
const isEqual = typeof uniqueKeys === 'function'
|
|
10
10
|
? uniqueKeys
|
|
11
11
|
: (a, b) => a === b ||
|
|
12
|
-
(
|
|
13
|
-
|
|
12
|
+
(identity.isScalar(a) &&
|
|
13
|
+
identity.isScalar(b) &&
|
|
14
14
|
a.value === b.value &&
|
|
15
15
|
!(a.value === '<<' && ctx.schema.merge));
|
|
16
16
|
return items.some(pair => isEqual(pair.key, search));
|
package/dist/doc/Document.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { YAMLError, YAMLWarning } from '../errors.js';
|
|
2
2
|
import { Alias } from '../nodes/Alias.js';
|
|
3
|
-
import {
|
|
3
|
+
import { NODE_TYPE } from '../nodes/identity.js';
|
|
4
|
+
import type { Node, NodeType, ParsedNode, Range } from '../nodes/Node.js';
|
|
4
5
|
import { Pair } from '../nodes/Pair.js';
|
|
5
6
|
import type { Scalar } from '../nodes/Scalar.js';
|
|
6
7
|
import type { YAMLMap } from '../nodes/YAMLMap.js';
|