yaml 2.0.0-5 → 2.0.0-9
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-doc.js +1 -1
- package/browser/dist/compose/compose-node.js +10 -1
- package/browser/dist/compose/compose-scalar.js +2 -1
- package/browser/dist/compose/composer.js +3 -2
- package/browser/dist/compose/resolve-block-map.js +15 -5
- package/browser/dist/compose/resolve-block-scalar.js +2 -2
- package/browser/dist/compose/resolve-block-seq.js +1 -1
- package/browser/dist/compose/resolve-end.js +2 -2
- package/browser/dist/compose/resolve-flow-collection.js +14 -6
- package/browser/dist/compose/resolve-flow-scalar.js +19 -7
- package/browser/dist/compose/resolve-props.js +30 -7
- package/browser/dist/compose/util-map-includes.js +17 -0
- package/browser/dist/doc/Document.js +26 -2
- package/browser/dist/doc/createNode.js +11 -5
- package/browser/dist/doc/directives.js +5 -0
- package/browser/dist/node_modules/tslib/tslib.es6.js +164 -0
- package/browser/dist/nodes/Collection.js +28 -15
- package/browser/dist/nodes/Node.js +7 -0
- package/browser/dist/nodes/Pair.js +9 -1
- package/browser/dist/nodes/addPairToJSMap.js +4 -3
- package/browser/dist/options.js +2 -0
- package/browser/dist/parse/cst-scalar.js +2 -6
- package/browser/dist/parse/lexer.js +64 -31
- package/browser/dist/parse/parser.js +53 -52
- package/browser/dist/schema/Schema.js +5 -0
- package/browser/dist/schema/tags.js +9 -5
- package/browser/dist/stringify/stringify.js +2 -1
- package/browser/dist/stringify/stringifyCollection.js +23 -9
- package/browser/dist/stringify/stringifyComment.js +14 -0
- package/browser/dist/stringify/stringifyDocument.js +8 -5
- package/browser/dist/stringify/stringifyPair.js +5 -7
- package/browser/dist/stringify/stringifyString.js +35 -34
- package/browser/dist/util.js +3 -0
- package/dist/compose/compose-doc.js +1 -1
- package/dist/compose/compose-node.js +10 -1
- package/dist/compose/compose-scalar.js +2 -1
- package/dist/compose/composer.js +3 -2
- package/dist/compose/resolve-block-map.d.ts +2 -1
- package/dist/compose/resolve-block-map.js +15 -5
- package/dist/compose/resolve-block-scalar.js +2 -2
- package/dist/compose/resolve-block-seq.js +1 -1
- package/dist/compose/resolve-end.js +2 -2
- package/dist/compose/resolve-flow-collection.js +14 -6
- package/dist/compose/resolve-flow-scalar.js +19 -7
- package/dist/compose/resolve-props.d.ts +3 -4
- package/dist/compose/resolve-props.js +30 -7
- 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 +10 -2
- package/dist/doc/Document.js +25 -1
- package/dist/doc/createNode.d.ts +2 -1
- package/dist/doc/createNode.js +10 -4
- package/dist/doc/directives.d.ts +1 -0
- package/dist/doc/directives.js +5 -0
- package/dist/errors.d.ts +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/node_modules/tslib/tslib.es6.js +76 -0
- package/dist/nodes/Alias.d.ts +7 -3
- package/dist/nodes/Collection.d.ts +10 -4
- package/dist/nodes/Collection.js +27 -14
- package/dist/nodes/Node.d.ts +10 -3
- package/dist/nodes/Node.js +7 -0
- package/dist/nodes/Pair.d.ts +7 -2
- package/dist/nodes/Pair.js +8 -0
- package/dist/nodes/Scalar.d.ts +2 -0
- package/dist/nodes/YAMLMap.d.ts +2 -0
- package/dist/nodes/YAMLSeq.d.ts +2 -0
- package/dist/nodes/addPairToJSMap.js +3 -2
- package/dist/options.d.ts +40 -3
- package/dist/options.js +2 -0
- package/dist/parse/cst-scalar.d.ts +6 -0
- package/dist/parse/cst-scalar.js +2 -6
- package/dist/parse/lexer.d.ts +3 -1
- package/dist/parse/lexer.js +64 -31
- package/dist/parse/parser.d.ts +1 -0
- package/dist/parse/parser.js +53 -52
- package/dist/schema/Schema.d.ts +1 -0
- package/dist/schema/Schema.js +5 -0
- package/dist/schema/tags.js +9 -5
- package/dist/stringify/stringify.js +2 -1
- package/dist/stringify/stringifyCollection.d.ts +1 -1
- package/dist/stringify/stringifyCollection.js +24 -10
- package/dist/stringify/stringifyComment.d.ts +2 -0
- package/dist/stringify/{addComment.js → stringifyComment.js} +5 -1
- package/dist/stringify/stringifyDocument.js +9 -6
- package/dist/stringify/stringifyPair.js +9 -11
- package/dist/stringify/stringifyString.js +35 -34
- package/dist/test-events.d.ts +1 -1
- package/dist/util.d.ts +3 -0
- package/dist/util.js +6 -0
- package/package.json +9 -8
- package/util.d.ts +3 -0
- package/browser/dist/stringify/addComment.js +0 -11
- package/dist/stringify/addComment.d.ts +0 -2
|
@@ -8,8 +8,8 @@ function resolveBlockSeq({ composeNode, composeEmptyNode }, ctx, bs, onError) {
|
|
|
8
8
|
let offset = bs.offset;
|
|
9
9
|
for (const { start, value } of bs.items) {
|
|
10
10
|
const props = resolveProps.resolveProps(start, {
|
|
11
|
-
ctx,
|
|
12
11
|
indicator: 'seq-item-ind',
|
|
12
|
+
next: value,
|
|
13
13
|
offset,
|
|
14
14
|
onError,
|
|
15
15
|
startOnNewline: true
|
|
@@ -13,8 +13,8 @@ function resolveEnd(end, offset, reqSpace, onError) {
|
|
|
13
13
|
break;
|
|
14
14
|
case 'comment': {
|
|
15
15
|
if (reqSpace && !hasSpace)
|
|
16
|
-
onError(token, '
|
|
17
|
-
const cb = source.substring(1);
|
|
16
|
+
onError(token, 'MISSING_CHAR', 'Comments must be separated from other tokens by white space characters');
|
|
17
|
+
const cb = source.substring(1) || ' ';
|
|
18
18
|
if (!comment)
|
|
19
19
|
comment = cb;
|
|
20
20
|
else
|
|
@@ -7,6 +7,7 @@ var YAMLSeq = require('../nodes/YAMLSeq.js');
|
|
|
7
7
|
var resolveEnd = require('./resolve-end.js');
|
|
8
8
|
var resolveProps = require('./resolve-props.js');
|
|
9
9
|
var utilContainsNewline = require('./util-contains-newline.js');
|
|
10
|
+
var utilMapIncludes = require('./util-map-includes.js');
|
|
10
11
|
|
|
11
12
|
const blockMsg = 'Block collections are not allowed within flow collections';
|
|
12
13
|
const isBlock = (token) => token && (token.type === 'block-map' || token.type === 'block-seq');
|
|
@@ -19,11 +20,12 @@ function resolveFlowCollection({ composeNode, composeEmptyNode }, ctx, fc, onErr
|
|
|
19
20
|
coll.flow = true;
|
|
20
21
|
let offset = fc.offset;
|
|
21
22
|
for (let i = 0; i < fc.items.length; ++i) {
|
|
22
|
-
const
|
|
23
|
+
const collItem = fc.items[i];
|
|
24
|
+
const { start, key, sep, value } = collItem;
|
|
23
25
|
const props = resolveProps.resolveProps(start, {
|
|
24
|
-
ctx,
|
|
25
26
|
flow: fcName,
|
|
26
27
|
indicator: 'explicit-key-ind',
|
|
28
|
+
next: key || (sep === null || sep === void 0 ? void 0 : sep[0]),
|
|
27
29
|
offset,
|
|
28
30
|
onError,
|
|
29
31
|
startOnNewline: false
|
|
@@ -101,9 +103,9 @@ function resolveFlowCollection({ composeNode, composeEmptyNode }, ctx, fc, onErr
|
|
|
101
103
|
onError(keyNode.range, 'BLOCK_IN_FLOW', blockMsg);
|
|
102
104
|
// value properties
|
|
103
105
|
const valueProps = resolveProps.resolveProps(sep || [], {
|
|
104
|
-
ctx,
|
|
105
106
|
flow: fcName,
|
|
106
107
|
indicator: 'map-value-ind',
|
|
108
|
+
next: value,
|
|
107
109
|
offset: keyNode.range[2],
|
|
108
110
|
onError,
|
|
109
111
|
startOnNewline: false
|
|
@@ -146,8 +148,14 @@ function resolveFlowCollection({ composeNode, composeEmptyNode }, ctx, fc, onErr
|
|
|
146
148
|
keyNode.comment = valueProps.comment;
|
|
147
149
|
}
|
|
148
150
|
const pair = new Pair.Pair(keyNode, valueNode);
|
|
149
|
-
if (
|
|
150
|
-
|
|
151
|
+
if (ctx.options.keepSourceTokens)
|
|
152
|
+
pair.srcToken = collItem;
|
|
153
|
+
if (isMap) {
|
|
154
|
+
const map = coll;
|
|
155
|
+
if (utilMapIncludes.mapIncludes(ctx, map.items, keyNode))
|
|
156
|
+
onError(keyStart, 'DUPLICATE_KEY', 'Map keys must be unique');
|
|
157
|
+
map.items.push(pair);
|
|
158
|
+
}
|
|
151
159
|
else {
|
|
152
160
|
const map = new YAMLMap.YAMLMap(ctx.schema);
|
|
153
161
|
map.flow = true;
|
|
@@ -161,7 +169,7 @@ function resolveFlowCollection({ composeNode, composeEmptyNode }, ctx, fc, onErr
|
|
|
161
169
|
const [ce, ...ee] = fc.end;
|
|
162
170
|
let cePos = offset;
|
|
163
171
|
if (ce && ce.source === expectedEnd)
|
|
164
|
-
cePos
|
|
172
|
+
cePos = ce.offset + ce.source.length;
|
|
165
173
|
else {
|
|
166
174
|
onError(offset + 1, 'MISSING_CHAR', `Expected ${fcName} to end with ${expectedEnd}`);
|
|
167
175
|
if (ce && ce.source.length !== 1)
|
|
@@ -41,25 +41,31 @@ function resolveFlowScalar(scalar, strict, onError) {
|
|
|
41
41
|
};
|
|
42
42
|
}
|
|
43
43
|
function plainValue(source, onError) {
|
|
44
|
-
let
|
|
44
|
+
let badChar = '';
|
|
45
45
|
switch (source[0]) {
|
|
46
46
|
/* istanbul ignore next should not happen */
|
|
47
47
|
case '\t':
|
|
48
|
-
|
|
48
|
+
badChar = 'a tab character';
|
|
49
|
+
break;
|
|
50
|
+
case ',':
|
|
51
|
+
badChar = 'flow indicator character ,';
|
|
52
|
+
break;
|
|
53
|
+
case '%':
|
|
54
|
+
badChar = 'directive indicator character %';
|
|
49
55
|
break;
|
|
50
56
|
case '|':
|
|
51
57
|
case '>': {
|
|
52
|
-
|
|
58
|
+
badChar = `block scalar indicator ${source[0]}`;
|
|
53
59
|
break;
|
|
54
60
|
}
|
|
55
61
|
case '@':
|
|
56
62
|
case '`': {
|
|
57
|
-
|
|
63
|
+
badChar = `reserved character ${source[0]}`;
|
|
58
64
|
break;
|
|
59
65
|
}
|
|
60
66
|
}
|
|
61
|
-
if (
|
|
62
|
-
onError(0, 'BAD_SCALAR_START',
|
|
67
|
+
if (badChar)
|
|
68
|
+
onError(0, 'BAD_SCALAR_START', `Plain value cannot start with ${badChar}`);
|
|
63
69
|
return foldLines(source);
|
|
64
70
|
}
|
|
65
71
|
function singleQuotedValue(source, onError) {
|
|
@@ -131,6 +137,12 @@ function doubleQuotedValue(source, onError) {
|
|
|
131
137
|
while (next === ' ' || next === '\t')
|
|
132
138
|
next = source[++i + 1];
|
|
133
139
|
}
|
|
140
|
+
else if (next === '\r' && source[i + 1] === '\n') {
|
|
141
|
+
// skip escaped CRLF newlines, but still trim the following line
|
|
142
|
+
next = source[++i + 1];
|
|
143
|
+
while (next === ' ' || next === '\t')
|
|
144
|
+
next = source[++i + 1];
|
|
145
|
+
}
|
|
134
146
|
else if (next === 'x' || next === 'u' || next === 'U') {
|
|
135
147
|
const length = { x: 2, u: 4, U: 8 }[next];
|
|
136
148
|
res += parseCharCode(source, i + 1, length, onError);
|
|
@@ -148,7 +160,7 @@ function doubleQuotedValue(source, onError) {
|
|
|
148
160
|
let next = source[i + 1];
|
|
149
161
|
while (next === ' ' || next === '\t')
|
|
150
162
|
next = source[++i + 1];
|
|
151
|
-
if (next !== '\n')
|
|
163
|
+
if (next !== '\n' && !(next === '\r' && source[i + 2] === '\n'))
|
|
152
164
|
res += i > wsStart ? source.slice(wsStart, i + 1) : ch;
|
|
153
165
|
}
|
|
154
166
|
else {
|
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
import type { SourceToken } from '../parse/cst.js';
|
|
2
|
-
import type { ComposeContext } from './compose-node.js';
|
|
1
|
+
import type { SourceToken, Token } from '../parse/cst.js';
|
|
3
2
|
import type { ComposeErrorHandler } from './composer.js';
|
|
4
3
|
export interface ResolvePropsArg {
|
|
5
|
-
ctx: ComposeContext;
|
|
6
4
|
flow?: string;
|
|
7
5
|
indicator: 'doc-start' | 'explicit-key-ind' | 'map-value-ind' | 'seq-item-ind';
|
|
6
|
+
next: Token | null | undefined;
|
|
8
7
|
offset: number;
|
|
9
8
|
onError: ComposeErrorHandler;
|
|
10
9
|
startOnNewline: boolean;
|
|
11
10
|
}
|
|
12
|
-
export declare function resolveProps(tokens: SourceToken[], {
|
|
11
|
+
export declare function resolveProps(tokens: SourceToken[], { flow, indicator, next, offset, onError, startOnNewline }: ResolvePropsArg): {
|
|
13
12
|
comma: SourceToken | null;
|
|
14
13
|
found: SourceToken | null;
|
|
15
14
|
spaceBefore: boolean;
|
|
@@ -1,18 +1,26 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
function resolveProps(tokens, {
|
|
3
|
+
function resolveProps(tokens, { flow, indicator, next, offset, onError, startOnNewline }) {
|
|
4
4
|
let spaceBefore = false;
|
|
5
5
|
let atNewline = startOnNewline;
|
|
6
6
|
let hasSpace = startOnNewline;
|
|
7
7
|
let comment = '';
|
|
8
8
|
let commentSep = '';
|
|
9
9
|
let hasNewline = false;
|
|
10
|
+
let reqSpace = false;
|
|
10
11
|
let anchor = null;
|
|
11
12
|
let tag = null;
|
|
12
13
|
let comma = null;
|
|
13
14
|
let found = null;
|
|
14
15
|
let start = null;
|
|
15
16
|
for (const token of tokens) {
|
|
17
|
+
if (reqSpace) {
|
|
18
|
+
if (token.type !== 'space' &&
|
|
19
|
+
token.type !== 'newline' &&
|
|
20
|
+
token.type !== 'comma')
|
|
21
|
+
onError(token.offset, 'MISSING_CHAR', 'Tags and anchors must be separated from the next token by white space');
|
|
22
|
+
reqSpace = false;
|
|
23
|
+
}
|
|
16
24
|
switch (token.type) {
|
|
17
25
|
case 'space':
|
|
18
26
|
// At the doc level, tabs at line start may be parsed
|
|
@@ -26,23 +34,29 @@ function resolveProps(tokens, { ctx, flow, indicator, offset, onError, startOnNe
|
|
|
26
34
|
hasSpace = true;
|
|
27
35
|
break;
|
|
28
36
|
case 'comment': {
|
|
29
|
-
if (
|
|
30
|
-
onError(token, '
|
|
31
|
-
const cb = token.source.substring(1);
|
|
37
|
+
if (!hasSpace)
|
|
38
|
+
onError(token, 'MISSING_CHAR', 'Comments must be separated from other tokens by white space characters');
|
|
39
|
+
const cb = token.source.substring(1) || ' ';
|
|
32
40
|
if (!comment)
|
|
33
41
|
comment = cb;
|
|
34
42
|
else
|
|
35
43
|
comment += commentSep + cb;
|
|
36
44
|
commentSep = '';
|
|
45
|
+
atNewline = false;
|
|
37
46
|
break;
|
|
38
47
|
}
|
|
39
48
|
case 'newline':
|
|
40
|
-
if (atNewline
|
|
41
|
-
|
|
49
|
+
if (atNewline) {
|
|
50
|
+
if (comment)
|
|
51
|
+
comment += token.source;
|
|
52
|
+
else
|
|
53
|
+
spaceBefore = true;
|
|
54
|
+
}
|
|
55
|
+
else
|
|
56
|
+
commentSep += token.source;
|
|
42
57
|
atNewline = true;
|
|
43
58
|
hasNewline = true;
|
|
44
59
|
hasSpace = true;
|
|
45
|
-
commentSep += token.source;
|
|
46
60
|
break;
|
|
47
61
|
case 'anchor':
|
|
48
62
|
if (anchor)
|
|
@@ -52,6 +66,7 @@ function resolveProps(tokens, { ctx, flow, indicator, offset, onError, startOnNe
|
|
|
52
66
|
start = token.offset;
|
|
53
67
|
atNewline = false;
|
|
54
68
|
hasSpace = false;
|
|
69
|
+
reqSpace = true;
|
|
55
70
|
break;
|
|
56
71
|
case 'tag': {
|
|
57
72
|
if (tag)
|
|
@@ -61,6 +76,7 @@ function resolveProps(tokens, { ctx, flow, indicator, offset, onError, startOnNe
|
|
|
61
76
|
start = token.offset;
|
|
62
77
|
atNewline = false;
|
|
63
78
|
hasSpace = false;
|
|
79
|
+
reqSpace = true;
|
|
64
80
|
break;
|
|
65
81
|
}
|
|
66
82
|
case indicator:
|
|
@@ -89,6 +105,13 @@ function resolveProps(tokens, { ctx, flow, indicator, offset, onError, startOnNe
|
|
|
89
105
|
}
|
|
90
106
|
const last = tokens[tokens.length - 1];
|
|
91
107
|
const end = last ? last.offset + last.source.length : offset;
|
|
108
|
+
if (reqSpace &&
|
|
109
|
+
next &&
|
|
110
|
+
next.type !== 'space' &&
|
|
111
|
+
next.type !== 'newline' &&
|
|
112
|
+
next.type !== 'comma' &&
|
|
113
|
+
(next.type !== 'scalar' || next.source !== ''))
|
|
114
|
+
onError(next.offset, 'MISSING_CHAR', 'Tags and anchors must be separated from the next token by white space');
|
|
92
115
|
return {
|
|
93
116
|
comma,
|
|
94
117
|
found,
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var Node = require('../nodes/Node.js');
|
|
4
|
+
|
|
5
|
+
function mapIncludes(ctx, items, search) {
|
|
6
|
+
const { uniqueKeys } = ctx.options;
|
|
7
|
+
if (uniqueKeys === false)
|
|
8
|
+
return false;
|
|
9
|
+
const isEqual = typeof uniqueKeys === 'function'
|
|
10
|
+
? uniqueKeys
|
|
11
|
+
: (a, b) => a === b ||
|
|
12
|
+
(Node.isScalar(a) &&
|
|
13
|
+
Node.isScalar(b) &&
|
|
14
|
+
a.value === b.value &&
|
|
15
|
+
!(a.value === '<<' && ctx.schema.merge));
|
|
16
|
+
return items.some(pair => isEqual(pair.key, search));
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
exports.mapIncludes = mapIncludes;
|
package/dist/doc/Document.d.ts
CHANGED
|
@@ -27,8 +27,10 @@ export declare class Document<T = unknown> {
|
|
|
27
27
|
errors: YAMLError[];
|
|
28
28
|
options: Required<Omit<ParseOptions & DocumentOptions, 'lineCounter' | 'directives' | 'version'>>;
|
|
29
29
|
/**
|
|
30
|
-
* The [start, value-end, node-end] character offsets for the part of the
|
|
31
|
-
* source parsed into this document (undefined if not parsed).
|
|
30
|
+
* The `[start, value-end, node-end]` character offsets for the part of the
|
|
31
|
+
* source parsed into this document (undefined if not parsed). The `value-end`
|
|
32
|
+
* and `node-end` positions are themselves not included in their respective
|
|
33
|
+
* ranges.
|
|
32
34
|
*/
|
|
33
35
|
range?: Range;
|
|
34
36
|
/** The schema used with the document. Use `setSchema()` to change. */
|
|
@@ -41,6 +43,12 @@ export declare class Document<T = unknown> {
|
|
|
41
43
|
*/
|
|
42
44
|
constructor(value?: any, options?: DocumentOptions & SchemaOptions & ParseOptions & CreateNodeOptions);
|
|
43
45
|
constructor(value: any, replacer: null | Replacer, options?: DocumentOptions & SchemaOptions & ParseOptions & CreateNodeOptions);
|
|
46
|
+
/**
|
|
47
|
+
* Create a deep copy of this Document and its contents.
|
|
48
|
+
*
|
|
49
|
+
* Custom Node values that inherit from `Object` still refer to their original instances.
|
|
50
|
+
*/
|
|
51
|
+
clone(): Document<T>;
|
|
44
52
|
/** Adds a value to the document. */
|
|
45
53
|
add(value: any): void;
|
|
46
54
|
/** Adds a value to the document. */
|
package/dist/doc/Document.js
CHANGED
|
@@ -50,6 +50,29 @@ class Document {
|
|
|
50
50
|
this.contents = this.createNode(value, _replacer, options$1);
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
|
+
/**
|
|
54
|
+
* Create a deep copy of this Document and its contents.
|
|
55
|
+
*
|
|
56
|
+
* Custom Node values that inherit from `Object` still refer to their original instances.
|
|
57
|
+
*/
|
|
58
|
+
clone() {
|
|
59
|
+
const copy = Object.create(Document.prototype, {
|
|
60
|
+
[Node.NODE_TYPE]: { value: Node.DOC }
|
|
61
|
+
});
|
|
62
|
+
copy.commentBefore = this.commentBefore;
|
|
63
|
+
copy.comment = this.comment;
|
|
64
|
+
copy.errors = this.errors.slice();
|
|
65
|
+
copy.warnings = this.warnings.slice();
|
|
66
|
+
copy.options = Object.assign({}, this.options);
|
|
67
|
+
copy.directives = this.directives.clone();
|
|
68
|
+
copy.schema = this.schema.clone();
|
|
69
|
+
copy.contents = Node.isNode(this.contents)
|
|
70
|
+
? this.contents.clone(copy.schema)
|
|
71
|
+
: this.contents;
|
|
72
|
+
if (this.range)
|
|
73
|
+
copy.range = this.range.slice();
|
|
74
|
+
return copy;
|
|
75
|
+
}
|
|
53
76
|
/** Adds a value to the document. */
|
|
54
77
|
add(value) {
|
|
55
78
|
if (assertCollection(this.contents))
|
|
@@ -94,9 +117,10 @@ class Document {
|
|
|
94
117
|
options = replacer;
|
|
95
118
|
replacer = undefined;
|
|
96
119
|
}
|
|
97
|
-
const { anchorPrefix, flow, keepUndefined, onTagObj, tag } = options || {};
|
|
120
|
+
const { aliasDuplicateObjects, anchorPrefix, flow, keepUndefined, onTagObj, tag } = options || {};
|
|
98
121
|
const { onAnchor, setAnchors, sourceObjects } = anchors.createNodeAnchors(this, anchorPrefix || 'a');
|
|
99
122
|
const ctx = {
|
|
123
|
+
aliasDuplicateObjects: aliasDuplicateObjects !== null && aliasDuplicateObjects !== void 0 ? aliasDuplicateObjects : true,
|
|
100
124
|
keepUndefined: keepUndefined !== null && keepUndefined !== void 0 ? keepUndefined : false,
|
|
101
125
|
onAnchor,
|
|
102
126
|
onTagObj,
|
package/dist/doc/createNode.d.ts
CHANGED
|
@@ -3,7 +3,8 @@ import type { Schema } from '../schema/Schema.js';
|
|
|
3
3
|
import type { CollectionTag, ScalarTag } from '../schema/types.js';
|
|
4
4
|
import type { Replacer } from './Document.js';
|
|
5
5
|
export interface CreateNodeContext {
|
|
6
|
-
|
|
6
|
+
aliasDuplicateObjects: boolean;
|
|
7
|
+
keepUndefined: boolean;
|
|
7
8
|
onAnchor(source: unknown): string;
|
|
8
9
|
onTagObj?: (tagObj: ScalarTag | CollectionTag) => void;
|
|
9
10
|
sourceObjects: Map<unknown, {
|
package/dist/doc/createNode.js
CHANGED
|
@@ -17,6 +17,8 @@ function findTagObject(value, tagName, tags) {
|
|
|
17
17
|
}
|
|
18
18
|
function createNode(value, tagName, ctx) {
|
|
19
19
|
var _a, _b;
|
|
20
|
+
if (Node.isDocument(value))
|
|
21
|
+
value = value.contents;
|
|
20
22
|
if (Node.isNode(value))
|
|
21
23
|
return value;
|
|
22
24
|
if (Node.isPair(value)) {
|
|
@@ -32,11 +34,11 @@ function createNode(value, tagName, ctx) {
|
|
|
32
34
|
// https://tc39.es/ecma262/#sec-serializejsonproperty
|
|
33
35
|
value = value.valueOf();
|
|
34
36
|
}
|
|
35
|
-
const { onAnchor, onTagObj, schema, sourceObjects } = ctx;
|
|
37
|
+
const { aliasDuplicateObjects, onAnchor, onTagObj, schema, sourceObjects } = ctx;
|
|
36
38
|
// Detect duplicate references to the same object & use Alias nodes for all
|
|
37
39
|
// after first. The `ref` wrapper allows for circular references to resolve.
|
|
38
40
|
let ref = undefined;
|
|
39
|
-
if (value && typeof value === 'object') {
|
|
41
|
+
if (aliasDuplicateObjects && value && typeof value === 'object') {
|
|
40
42
|
ref = sourceObjects.get(value);
|
|
41
43
|
if (ref) {
|
|
42
44
|
if (!ref.anchor)
|
|
@@ -54,8 +56,12 @@ function createNode(value, tagName, ctx) {
|
|
|
54
56
|
if (!tagObj) {
|
|
55
57
|
if (value && typeof value.toJSON === 'function')
|
|
56
58
|
value = value.toJSON();
|
|
57
|
-
if (!value || typeof value !== 'object')
|
|
58
|
-
|
|
59
|
+
if (!value || typeof value !== 'object') {
|
|
60
|
+
const node = new Scalar.Scalar(value);
|
|
61
|
+
if (ref)
|
|
62
|
+
ref.node = node;
|
|
63
|
+
return node;
|
|
64
|
+
}
|
|
59
65
|
tagObj =
|
|
60
66
|
value instanceof Map
|
|
61
67
|
? schema[Node.MAP]
|
package/dist/doc/directives.d.ts
CHANGED
|
@@ -20,6 +20,7 @@ export declare class Directives {
|
|
|
20
20
|
*/
|
|
21
21
|
private atNextDocument?;
|
|
22
22
|
constructor(yaml?: Directives['yaml'], tags?: Directives['tags']);
|
|
23
|
+
clone(): Directives;
|
|
23
24
|
/**
|
|
24
25
|
* During parsing, get a Directives instance for the current document and
|
|
25
26
|
* update the stream state according to the current version's spec.
|
package/dist/doc/directives.js
CHANGED
|
@@ -22,6 +22,11 @@ class Directives {
|
|
|
22
22
|
this.yaml = Object.assign({}, Directives.defaultYaml, yaml);
|
|
23
23
|
this.tags = Object.assign({}, Directives.defaultTags, tags);
|
|
24
24
|
}
|
|
25
|
+
clone() {
|
|
26
|
+
const copy = new Directives(this.yaml, this.tags);
|
|
27
|
+
copy.marker = this.marker;
|
|
28
|
+
return copy;
|
|
29
|
+
}
|
|
25
30
|
/**
|
|
26
31
|
* During parsing, get a Directives instance for the current document and
|
|
27
32
|
* update the stream state according to the current version's spec.
|
package/dist/errors.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { LineCounter } from './parse/line-counter';
|
|
2
|
-
export declare type ErrorCode = 'ALIAS_PROPS' | 'BAD_DIRECTIVE' | 'BAD_DQ_ESCAPE' | 'BAD_INDENT' | 'BAD_PROP_ORDER' | 'BAD_SCALAR_START' | 'BLOCK_AS_IMPLICIT_KEY' | 'BLOCK_IN_FLOW' | '
|
|
2
|
+
export declare type ErrorCode = 'ALIAS_PROPS' | 'BAD_ALIAS' | 'BAD_DIRECTIVE' | 'BAD_DQ_ESCAPE' | 'BAD_INDENT' | 'BAD_PROP_ORDER' | 'BAD_SCALAR_START' | 'BLOCK_AS_IMPLICIT_KEY' | 'BLOCK_IN_FLOW' | 'DUPLICATE_KEY' | 'IMPOSSIBLE' | 'KEY_OVER_1024_CHARS' | 'MISSING_CHAR' | 'MULTILINE_IMPLICIT_KEY' | 'MULTIPLE_ANCHORS' | 'MULTIPLE_DOCS' | 'MULTIPLE_TAGS' | 'TAB_AS_INDENT' | 'TAG_RESOLVE_FAILED' | 'UNEXPECTED_TOKEN';
|
|
3
3
|
export declare type LinePos = {
|
|
4
4
|
line: number;
|
|
5
5
|
col: number;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
export { Composer } from './compose/composer.js';
|
|
2
2
|
export { Document } from './doc/Document.js';
|
|
3
3
|
export { Schema } from './schema/Schema.js';
|
|
4
|
-
export { YAMLError, YAMLParseError, YAMLWarning } from './errors.js';
|
|
4
|
+
export { ErrorCode, YAMLError, YAMLParseError, YAMLWarning } from './errors.js';
|
|
5
5
|
export { Alias } from './nodes/Alias.js';
|
|
6
|
-
export { isAlias, isCollection, isDocument, isMap, isNode, isPair, isScalar, isSeq, Node, ParsedNode } from './nodes/Node.js';
|
|
6
|
+
export { isAlias, isCollection, isDocument, isMap, isNode, isPair, isScalar, isSeq, Node, ParsedNode, Range } from './nodes/Node.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';
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/*! *****************************************************************************
|
|
4
|
+
Copyright (c) Microsoft Corporation.
|
|
5
|
+
|
|
6
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
7
|
+
purpose with or without fee is hereby granted.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
10
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
11
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
12
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
13
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
14
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
15
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
16
|
+
***************************************************************************** */
|
|
17
|
+
/* global Reflect, Promise */
|
|
18
|
+
|
|
19
|
+
var extendStatics = function(d, b) {
|
|
20
|
+
extendStatics = Object.setPrototypeOf ||
|
|
21
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
22
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
23
|
+
return extendStatics(d, b);
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
function __extends(d, b) {
|
|
27
|
+
if (typeof b !== "function" && b !== null)
|
|
28
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
29
|
+
extendStatics(d, b);
|
|
30
|
+
function __() { this.constructor = d; }
|
|
31
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function __generator(thisArg, body) {
|
|
35
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
36
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
37
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
38
|
+
function step(op) {
|
|
39
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
40
|
+
while (_) try {
|
|
41
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
42
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
43
|
+
switch (op[0]) {
|
|
44
|
+
case 0: case 1: t = op; break;
|
|
45
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
46
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
47
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
48
|
+
default:
|
|
49
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
50
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
51
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
52
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
53
|
+
if (t[2]) _.ops.pop();
|
|
54
|
+
_.trys.pop(); continue;
|
|
55
|
+
}
|
|
56
|
+
op = body.call(thisArg, _);
|
|
57
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
58
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function __values(o) {
|
|
63
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
64
|
+
if (m) return m.call(o);
|
|
65
|
+
if (o && typeof o.length === "number") return {
|
|
66
|
+
next: function () {
|
|
67
|
+
if (o && i >= o.length) o = void 0;
|
|
68
|
+
return { value: o && o[i++], done: !o };
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
exports.__extends = __extends;
|
|
75
|
+
exports.__generator = __generator;
|
|
76
|
+
exports.__values = __values;
|
package/dist/nodes/Alias.d.ts
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
|
-
import type { Document } from '../doc/Document';
|
|
1
|
+
import type { Document } from '../doc/Document.js';
|
|
2
|
+
import type { FlowScalar } from '../parse/cst.js';
|
|
2
3
|
import type { StringifyContext } from '../stringify/stringify.js';
|
|
3
4
|
import { NodeBase, Range } from './Node.js';
|
|
4
5
|
import type { Scalar } from './Scalar';
|
|
5
6
|
import type { ToJSContext } from './toJS.js';
|
|
6
|
-
import type { YAMLMap } from './YAMLMap';
|
|
7
|
-
import type { YAMLSeq } from './YAMLSeq';
|
|
7
|
+
import type { YAMLMap } from './YAMLMap.js';
|
|
8
|
+
import type { YAMLSeq } from './YAMLSeq.js';
|
|
8
9
|
export declare namespace Alias {
|
|
9
10
|
interface Parsed extends Alias {
|
|
10
11
|
range: Range;
|
|
12
|
+
srcToken?: FlowScalar & {
|
|
13
|
+
type: 'alias';
|
|
14
|
+
};
|
|
11
15
|
}
|
|
12
16
|
}
|
|
13
17
|
export declare class Alias extends NodeBase {
|
|
@@ -15,6 +15,12 @@ export declare abstract class Collection extends NodeBase {
|
|
|
15
15
|
*/
|
|
16
16
|
flow?: boolean;
|
|
17
17
|
constructor(type: symbol, schema?: Schema);
|
|
18
|
+
/**
|
|
19
|
+
* Create a copy of this collection.
|
|
20
|
+
*
|
|
21
|
+
* @param schema - If defined, overwrites the original's schema
|
|
22
|
+
*/
|
|
23
|
+
clone(schema?: Schema): Collection;
|
|
18
24
|
/** Adds a value to the collection. */
|
|
19
25
|
abstract add(value: unknown): void;
|
|
20
26
|
/**
|
|
@@ -47,21 +53,21 @@ export declare abstract class Collection extends NodeBase {
|
|
|
47
53
|
* Removes a value from the collection.
|
|
48
54
|
* @returns `true` if the item was found and removed.
|
|
49
55
|
*/
|
|
50
|
-
deleteIn(
|
|
56
|
+
deleteIn(path: Iterable<unknown>): boolean;
|
|
51
57
|
/**
|
|
52
58
|
* Returns item at `key`, or `undefined` if not found. By default unwraps
|
|
53
59
|
* scalar values from their surrounding node; to disable set `keepScalar` to
|
|
54
60
|
* `true` (collections are always returned intact).
|
|
55
61
|
*/
|
|
56
|
-
getIn(
|
|
62
|
+
getIn(path: Iterable<unknown>, keepScalar?: boolean): unknown;
|
|
57
63
|
hasAllNullValues(allowScalar?: boolean): boolean;
|
|
58
64
|
/**
|
|
59
65
|
* Checks if the collection includes a value with the key `key`.
|
|
60
66
|
*/
|
|
61
|
-
hasIn(
|
|
67
|
+
hasIn(path: Iterable<unknown>): boolean;
|
|
62
68
|
/**
|
|
63
69
|
* Sets a value in this collection. For `!!set`, `value` needs to be a
|
|
64
70
|
* boolean to add/remove the item from the set.
|
|
65
71
|
*/
|
|
66
|
-
setIn(
|
|
72
|
+
setIn(path: Iterable<unknown>, value: unknown): void;
|
|
67
73
|
}
|