yaml 2.0.0-10 → 2.0.0-5
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 -2
- package/browser/dist/compose/compose-node.js +1 -10
- package/browser/dist/compose/compose-scalar.js +10 -17
- package/browser/dist/compose/composer.js +2 -3
- package/browser/dist/compose/resolve-block-map.js +5 -22
- package/browser/dist/compose/resolve-block-scalar.js +2 -2
- package/browser/dist/compose/resolve-block-seq.js +1 -6
- package/browser/dist/compose/resolve-end.js +2 -2
- package/browser/dist/compose/resolve-flow-collection.js +8 -24
- package/browser/dist/compose/resolve-flow-scalar.js +7 -19
- package/browser/dist/compose/resolve-props.js +7 -32
- package/browser/dist/doc/Document.js +12 -58
- package/browser/dist/doc/createNode.js +5 -11
- package/browser/dist/doc/directives.js +0 -5
- package/browser/dist/nodes/Collection.js +15 -28
- package/browser/dist/nodes/Node.js +0 -7
- package/browser/dist/nodes/Pair.js +1 -9
- package/browser/dist/nodes/YAMLMap.js +1 -1
- package/browser/dist/nodes/YAMLSeq.js +1 -1
- package/browser/dist/nodes/addPairToJSMap.js +3 -4
- package/browser/dist/options.js +0 -2
- package/browser/dist/parse/cst-scalar.js +6 -2
- package/browser/dist/parse/lexer.js +31 -67
- package/browser/dist/parse/parser.js +55 -62
- package/browser/dist/public-api.js +4 -2
- package/browser/dist/schema/Schema.js +3 -14
- package/browser/dist/schema/core/float.js +1 -4
- package/browser/dist/schema/tags.js +13 -17
- package/browser/dist/schema/yaml-1.1/float.js +1 -4
- package/browser/dist/stringify/addComment.js +11 -0
- package/browser/dist/stringify/stringify.js +17 -47
- package/browser/dist/stringify/stringifyCollection.js +72 -116
- package/browser/dist/stringify/stringifyDocument.js +9 -16
- package/browser/dist/stringify/stringifyPair.js +20 -29
- package/browser/dist/stringify/stringifyString.js +41 -39
- package/browser/dist/util.js +0 -3
- package/dist/compose/compose-doc.js +1 -2
- package/dist/compose/compose-node.d.ts +0 -1
- package/dist/compose/compose-node.js +1 -10
- package/dist/compose/compose-scalar.js +9 -16
- package/dist/compose/composer.js +2 -3
- package/dist/compose/resolve-block-map.d.ts +1 -2
- package/dist/compose/resolve-block-map.js +5 -22
- package/dist/compose/resolve-block-scalar.js +2 -2
- package/dist/compose/resolve-block-seq.js +1 -6
- package/dist/compose/resolve-end.js +2 -2
- package/dist/compose/resolve-flow-collection.js +8 -24
- package/dist/compose/resolve-flow-scalar.js +7 -19
- package/dist/compose/resolve-props.d.ts +4 -3
- package/dist/compose/resolve-props.js +7 -32
- package/dist/doc/Document.d.ts +5 -16
- package/dist/doc/Document.js +11 -57
- package/dist/doc/createNode.d.ts +1 -2
- package/dist/doc/createNode.js +4 -10
- package/dist/doc/directives.d.ts +0 -1
- package/dist/doc/directives.js +0 -5
- package/dist/errors.d.ts +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/nodes/Alias.d.ts +3 -7
- package/dist/nodes/Collection.d.ts +4 -10
- package/dist/nodes/Collection.js +14 -27
- package/dist/nodes/Node.d.ts +3 -10
- package/dist/nodes/Node.js +0 -7
- package/dist/nodes/Pair.d.ts +2 -7
- package/dist/nodes/Pair.js +0 -8
- package/dist/nodes/Scalar.d.ts +0 -2
- package/dist/nodes/YAMLMap.d.ts +0 -2
- package/dist/nodes/YAMLMap.js +1 -1
- package/dist/nodes/YAMLSeq.d.ts +0 -2
- package/dist/nodes/YAMLSeq.js +1 -1
- package/dist/nodes/addPairToJSMap.js +2 -3
- package/dist/options.d.ts +6 -81
- package/dist/options.js +0 -2
- package/dist/parse/cst-scalar.d.ts +0 -6
- package/dist/parse/cst-scalar.js +6 -2
- package/dist/parse/lexer.d.ts +1 -3
- package/dist/parse/lexer.js +31 -67
- package/dist/parse/parser.d.ts +0 -1
- package/dist/parse/parser.js +55 -62
- package/dist/public-api.js +4 -2
- package/dist/schema/Schema.d.ts +4 -6
- package/dist/schema/Schema.js +2 -13
- package/dist/schema/core/float.js +1 -4
- package/dist/schema/tags.d.ts +2 -1
- package/dist/schema/tags.js +13 -17
- package/dist/schema/yaml-1.1/float.js +1 -4
- package/dist/stringify/addComment.d.ts +2 -0
- package/dist/stringify/addComment.js +13 -0
- package/dist/stringify/stringify.d.ts +3 -5
- package/dist/stringify/stringify.js +17 -47
- package/dist/stringify/stringifyCollection.d.ts +7 -3
- package/dist/stringify/stringifyCollection.js +72 -116
- package/dist/stringify/stringifyDocument.js +9 -16
- package/dist/stringify/stringifyPair.js +20 -29
- package/dist/stringify/stringifyString.js +41 -39
- package/dist/test-events.d.ts +1 -1
- package/dist/test-events.js +2 -4
- package/dist/util.d.ts +0 -3
- package/dist/util.js +0 -6
- package/package.json +12 -14
- package/browser/dist/compose/util-flow-indent-check.js +0 -15
- package/browser/dist/compose/util-map-includes.js +0 -17
- package/browser/dist/node_modules/tslib/tslib.es6.js +0 -164
- package/browser/dist/stringify/stringifyComment.js +0 -18
- package/dist/compose/util-flow-indent-check.d.ts +0 -3
- package/dist/compose/util-flow-indent-check.js +0 -17
- package/dist/compose/util-map-includes.d.ts +0 -4
- package/dist/compose/util-map-includes.js +0 -19
- package/dist/node_modules/tslib/tslib.es6.js +0 -76
- package/dist/stringify/stringifyComment.d.ts +0 -10
- package/dist/stringify/stringifyComment.js +0 -22
- package/util.d.ts +0 -3
|
@@ -9,7 +9,6 @@ var toJS = require('./toJS.js');
|
|
|
9
9
|
const MERGE_KEY = '<<';
|
|
10
10
|
function addPairToJSMap(ctx, map, { key, value }) {
|
|
11
11
|
if (ctx && ctx.doc.schema.merge && isMergeKey(key)) {
|
|
12
|
-
value = Node.isAlias(value) ? value.resolve(ctx.doc) : value;
|
|
13
12
|
if (Node.isSeq(value))
|
|
14
13
|
for (const it of value.items)
|
|
15
14
|
mergeToJSMap(ctx, map, it);
|
|
@@ -55,9 +54,9 @@ const isMergeKey = (key) => key === MERGE_KEY ||
|
|
|
55
54
|
// Keys in mapping nodes earlier in the sequence override keys specified in
|
|
56
55
|
// later mapping nodes. -- http://yaml.org/type/merge.html
|
|
57
56
|
function mergeToJSMap(ctx, map, value) {
|
|
58
|
-
const source = ctx && Node.isAlias(value) ? value.resolve(ctx.doc) :
|
|
57
|
+
const source = ctx && Node.isAlias(value) ? value.resolve(ctx.doc) : null;
|
|
59
58
|
if (!Node.isMap(source))
|
|
60
|
-
throw new Error('Merge sources must be
|
|
59
|
+
throw new Error('Merge sources must be map aliases');
|
|
61
60
|
const srcMap = source.toJSON(null, ctx, Map);
|
|
62
61
|
for (const [key, value] of srcMap) {
|
|
63
62
|
if (map instanceof Map) {
|
package/dist/options.d.ts
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import type { Reviver } from './doc/applyReviver.js';
|
|
2
2
|
import type { Directives } from './doc/directives.js';
|
|
3
3
|
import type { LogLevelId } from './log.js';
|
|
4
|
-
import type { ParsedNode } from './nodes/Node.js';
|
|
5
4
|
import type { Pair } from './nodes/Pair.js';
|
|
6
5
|
import type { Scalar } from './nodes/Scalar.js';
|
|
7
6
|
import type { LineCounter } from './parse/line-counter.js';
|
|
8
|
-
import type {
|
|
7
|
+
import type { SchemaName } from './schema/Schema.js';
|
|
9
8
|
import type { Tags } from './schema/tags.js';
|
|
10
9
|
import type { CollectionTag, ScalarTag } from './schema/types.js';
|
|
11
10
|
export declare type ParseOptions = {
|
|
@@ -17,13 +16,6 @@ export declare type ParseOptions = {
|
|
|
17
16
|
* https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/BigInt
|
|
18
17
|
*/
|
|
19
18
|
intAsBigInt?: boolean;
|
|
20
|
-
/**
|
|
21
|
-
* Include a `srcToken` value on each parsed `Node`, containing the CST token
|
|
22
|
-
* that was composed into this node.
|
|
23
|
-
*
|
|
24
|
-
* Default: `false`
|
|
25
|
-
*/
|
|
26
|
-
keepSourceTokens?: boolean;
|
|
27
19
|
/**
|
|
28
20
|
* If set, newlines will be tracked, to allow for `lineCounter.linePos(offset)`
|
|
29
21
|
* to provide the `{ line, col }` positions within the input.
|
|
@@ -42,19 +34,6 @@ export declare type ParseOptions = {
|
|
|
42
34
|
* Default: `true`
|
|
43
35
|
*/
|
|
44
36
|
strict?: boolean;
|
|
45
|
-
/**
|
|
46
|
-
* YAML requires map keys to be unique. By default, this is checked by
|
|
47
|
-
* comparing scalar values with `===`; deep equality is not checked for
|
|
48
|
-
* aliases or collections. If merge keys are enabled by the schema,
|
|
49
|
-
* multiple `<<` keys are allowed.
|
|
50
|
-
*
|
|
51
|
-
* Set `false` to disable, or provide your own comparator function to
|
|
52
|
-
* customise. The comparator will be passed two `ParsedNode` values, and
|
|
53
|
-
* is expected to return a `boolean` indicating their equality.
|
|
54
|
-
*
|
|
55
|
-
* Default: `true`
|
|
56
|
-
*/
|
|
57
|
-
uniqueKeys?: boolean | ((a: ParsedNode, b: ParsedNode) => boolean);
|
|
58
37
|
};
|
|
59
38
|
export declare type DocumentOptions = {
|
|
60
39
|
/**
|
|
@@ -76,14 +55,6 @@ export declare type DocumentOptions = {
|
|
|
76
55
|
version?: '1.1' | '1.2';
|
|
77
56
|
};
|
|
78
57
|
export declare type SchemaOptions = {
|
|
79
|
-
/**
|
|
80
|
-
* When parsing, warn about compatibility issues with the given schema.
|
|
81
|
-
* When stringifying, use scalar styles that are parsed correctly
|
|
82
|
-
* by the `compat` schema as well as the actual schema.
|
|
83
|
-
*
|
|
84
|
-
* Default: `null`
|
|
85
|
-
*/
|
|
86
|
-
compat?: string | Tags | null;
|
|
87
58
|
/**
|
|
88
59
|
* Array of additional tags to include in the schema, or a function that may
|
|
89
60
|
* modify the schema's base tag array.
|
|
@@ -107,39 +78,18 @@ export declare type SchemaOptions = {
|
|
|
107
78
|
/**
|
|
108
79
|
* The base schema to use.
|
|
109
80
|
*
|
|
110
|
-
*
|
|
111
|
-
* - `'failsafe'`: A minimal schema that parses all scalars as strings
|
|
112
|
-
* - `'core'`: The YAML 1.2 core schema
|
|
113
|
-
* - `'json'`: The YAML 1.2 JSON schema, with minimal rules for JSON compatibility
|
|
114
|
-
* - `'yaml-1.1'`: The YAML 1.1 schema
|
|
115
|
-
*
|
|
116
|
-
* If using another (custom) schema, the `customTags` array needs to
|
|
117
|
-
* fully define the schema's tags.
|
|
118
|
-
*
|
|
119
|
-
* Default: `'core'` for YAML 1.2, `'yaml-1.1'` for earlier versions
|
|
81
|
+
* Default: `"core"` for YAML 1.2, `"yaml-1.1"` for earlier versions
|
|
120
82
|
*/
|
|
121
|
-
schema?:
|
|
83
|
+
schema?: SchemaName;
|
|
122
84
|
/**
|
|
123
85
|
* When adding to or stringifying a map, sort the entries.
|
|
124
86
|
* If `true`, sort by comparing key values with `<`.
|
|
125
|
-
* Does not affect item order when parsing.
|
|
126
87
|
*
|
|
127
88
|
* Default: `false`
|
|
128
89
|
*/
|
|
129
90
|
sortMapEntries?: boolean | ((a: Pair, b: Pair) => number);
|
|
130
|
-
/**
|
|
131
|
-
* Override default values for `toString()` options.
|
|
132
|
-
*/
|
|
133
|
-
toStringDefaults?: ToStringOptions;
|
|
134
91
|
};
|
|
135
92
|
export declare type CreateNodeOptions = {
|
|
136
|
-
/**
|
|
137
|
-
* During node construction, use anchors and aliases to keep strictly equal
|
|
138
|
-
* non-null objects as equivalent in YAML.
|
|
139
|
-
*
|
|
140
|
-
* Default: `true`
|
|
141
|
-
*/
|
|
142
|
-
aliasDuplicateObjects?: boolean;
|
|
143
93
|
/**
|
|
144
94
|
* Default prefix for anchors.
|
|
145
95
|
*
|
|
@@ -189,30 +139,6 @@ export declare type ToJSOptions = {
|
|
|
189
139
|
reviver?: Reviver;
|
|
190
140
|
};
|
|
191
141
|
export declare type ToStringOptions = {
|
|
192
|
-
/**
|
|
193
|
-
* Use block quote styles for scalar values where applicable.
|
|
194
|
-
* Set to `false` to disable block quotes completely.
|
|
195
|
-
*
|
|
196
|
-
* Default: `true`
|
|
197
|
-
*/
|
|
198
|
-
blockQuote?: boolean | 'folded' | 'literal';
|
|
199
|
-
/**
|
|
200
|
-
* Enforce `'block'` or `'flow'` style on maps and sequences.
|
|
201
|
-
* Empty collections will always be stringified as `{}` or `[]`.
|
|
202
|
-
*
|
|
203
|
-
* Default: `'any'`, allowing each node to set its style separately
|
|
204
|
-
* with its `flow: boolean` (default `false`) property.
|
|
205
|
-
*/
|
|
206
|
-
collectionStyle?: 'any' | 'block' | 'flow';
|
|
207
|
-
/**
|
|
208
|
-
* Comment stringifier.
|
|
209
|
-
* Output should be valid for the current schema.
|
|
210
|
-
*
|
|
211
|
-
* By default, empty comment lines are left empty,
|
|
212
|
-
* lines consisting of a single space are replaced by `#`,
|
|
213
|
-
* and all other lines are prefixed with a `#`.
|
|
214
|
-
*/
|
|
215
|
-
commentString?: (comment: string) => string;
|
|
216
142
|
/**
|
|
217
143
|
* The default type of string literal used to stringify implicit key values.
|
|
218
144
|
* Output may use other types if required to fully represent the value.
|
|
@@ -306,12 +232,11 @@ export declare type ToStringOptions = {
|
|
|
306
232
|
*/
|
|
307
233
|
simpleKeys?: boolean;
|
|
308
234
|
/**
|
|
309
|
-
*
|
|
310
|
-
* Set to `false` to disable single quotes completely.
|
|
235
|
+
* Prefer 'single quote' rather than "double quote" where applicable.
|
|
311
236
|
*
|
|
312
|
-
* Default: `
|
|
237
|
+
* Default: `false`
|
|
313
238
|
*/
|
|
314
|
-
singleQuote?: boolean
|
|
239
|
+
singleQuote?: boolean;
|
|
315
240
|
/**
|
|
316
241
|
* String representation for `true`.
|
|
317
242
|
* With the core schema, use `'true'`, `'True'`, or `'TRUE'`.
|
package/dist/options.js
CHANGED
|
@@ -6,12 +6,6 @@ import type { BlockScalar, FlowScalar, SourceToken, Token } from './cst.js';
|
|
|
6
6
|
* If `token` is a CST flow or block scalar, determine its string value and a few other attributes.
|
|
7
7
|
* Otherwise, return `null`.
|
|
8
8
|
*/
|
|
9
|
-
export declare function resolveAsScalar(token: FlowScalar | BlockScalar, strict?: boolean, onError?: (offset: number, code: ErrorCode, message: string) => void): {
|
|
10
|
-
value: string;
|
|
11
|
-
type: Scalar.Type | null;
|
|
12
|
-
comment: string;
|
|
13
|
-
range: Range;
|
|
14
|
-
};
|
|
15
9
|
export declare function resolveAsScalar(token: Token | null | undefined, strict?: boolean, onError?: (offset: number, code: ErrorCode, message: string) => void): {
|
|
16
10
|
value: string;
|
|
17
11
|
type: Scalar.Type | null;
|
package/dist/parse/cst-scalar.js
CHANGED
|
@@ -5,6 +5,10 @@ var resolveFlowScalar = require('../compose/resolve-flow-scalar.js');
|
|
|
5
5
|
var errors = require('../errors.js');
|
|
6
6
|
var stringifyString = require('../stringify/stringifyString.js');
|
|
7
7
|
|
|
8
|
+
/**
|
|
9
|
+
* If `token` is a CST flow or block scalar, determine its string value and a few other attributes.
|
|
10
|
+
* Otherwise, return `null`.
|
|
11
|
+
*/
|
|
8
12
|
function resolveAsScalar(token, strict = true, onError) {
|
|
9
13
|
if (token) {
|
|
10
14
|
const _onError = (pos, code, message) => {
|
|
@@ -46,7 +50,7 @@ function createScalarToken(value, context) {
|
|
|
46
50
|
implicitKey,
|
|
47
51
|
indent: indent > 0 ? ' '.repeat(indent) : '',
|
|
48
52
|
inFlow,
|
|
49
|
-
options: {
|
|
53
|
+
options: { lineWidth: -1 }
|
|
50
54
|
});
|
|
51
55
|
const end = (_a = context.end) !== null && _a !== void 0 ? _a : [
|
|
52
56
|
{ type: 'newline', offset: -1, indent, source: '\n' }
|
|
@@ -115,7 +119,7 @@ function setScalarValue(token, value, context = {}) {
|
|
|
115
119
|
implicitKey: implicitKey || indent === null,
|
|
116
120
|
indent: indent !== null && indent > 0 ? ' '.repeat(indent) : '',
|
|
117
121
|
inFlow,
|
|
118
|
-
options: {
|
|
122
|
+
options: { lineWidth: -1 }
|
|
119
123
|
});
|
|
120
124
|
switch (source[0]) {
|
|
121
125
|
case '|':
|
package/dist/parse/lexer.d.ts
CHANGED
|
@@ -47,8 +47,6 @@ export declare class Lexer {
|
|
|
47
47
|
private indentNext;
|
|
48
48
|
/** Indentation level of the current line. */
|
|
49
49
|
private indentValue;
|
|
50
|
-
/** Position of the next \n character. */
|
|
51
|
-
private lineEndPos;
|
|
52
50
|
/** Stores the state of the lexer if reaching the end of incpomplete input */
|
|
53
51
|
private next;
|
|
54
52
|
/** A pointer to `buffer`; the current position of the lexer. */
|
|
@@ -80,7 +78,7 @@ export declare class Lexer {
|
|
|
80
78
|
private pushCount;
|
|
81
79
|
private pushToIndex;
|
|
82
80
|
private pushIndicators;
|
|
83
|
-
private
|
|
81
|
+
private pushVerbatimTag;
|
|
84
82
|
private pushNewline;
|
|
85
83
|
private pushSpaces;
|
|
86
84
|
private pushUntil;
|
package/dist/parse/lexer.js
CHANGED
|
@@ -81,11 +81,9 @@ function isEmpty(ch) {
|
|
|
81
81
|
return false;
|
|
82
82
|
}
|
|
83
83
|
}
|
|
84
|
-
const
|
|
85
|
-
const
|
|
86
|
-
const
|
|
87
|
-
const invalidAnchorChars = ' ,[]{}\n\r\t'.split('');
|
|
88
|
-
const isNotAnchorChar = (ch) => !ch || invalidAnchorChars.includes(ch);
|
|
84
|
+
const invalidFlowScalarChars = [',', '[', ']', '{', '}'];
|
|
85
|
+
const invalidIdentifierChars = [' ', ',', '[', ']', '{', '}', '\n', '\r', '\t'];
|
|
86
|
+
const isNotIdentifierChar = (ch) => !ch || invalidIdentifierChars.includes(ch);
|
|
89
87
|
/**
|
|
90
88
|
* Splits an input string into lexical tokens, i.e. smaller strings that are
|
|
91
89
|
* easily identifiable by `tokens.tokenType()`.
|
|
@@ -136,8 +134,6 @@ class Lexer {
|
|
|
136
134
|
this.indentNext = 0;
|
|
137
135
|
/** Indentation level of the current line. */
|
|
138
136
|
this.indentValue = 0;
|
|
139
|
-
/** Position of the next \n character. */
|
|
140
|
-
this.lineEndPos = null;
|
|
141
137
|
/** Stores the state of the lexer if reaching the end of incpomplete input */
|
|
142
138
|
this.next = null;
|
|
143
139
|
/** A pointer to `buffer`; the current position of the lexer. */
|
|
@@ -150,10 +146,8 @@ class Lexer {
|
|
|
150
146
|
* @returns A generator of lexical tokens
|
|
151
147
|
*/
|
|
152
148
|
*lex(source, incomplete = false) {
|
|
153
|
-
if (source)
|
|
149
|
+
if (source)
|
|
154
150
|
this.buffer = this.buffer ? this.buffer + source : source;
|
|
155
|
-
this.lineEndPos = null;
|
|
156
|
-
}
|
|
157
151
|
this.atEnd = !incomplete;
|
|
158
152
|
let next = this.next || 'stream';
|
|
159
153
|
while (next && (incomplete || this.hasChars(1)))
|
|
@@ -196,11 +190,7 @@ class Lexer {
|
|
|
196
190
|
return offset;
|
|
197
191
|
}
|
|
198
192
|
getLine() {
|
|
199
|
-
let end = this.
|
|
200
|
-
if (typeof end !== 'number' || (end !== -1 && end < this.pos)) {
|
|
201
|
-
end = this.buffer.indexOf('\n', this.pos);
|
|
202
|
-
this.lineEndPos = end;
|
|
203
|
-
}
|
|
193
|
+
let end = this.buffer.indexOf('\n', this.pos);
|
|
204
194
|
if (end === -1)
|
|
205
195
|
return this.atEnd ? this.buffer.substring(this.pos) : null;
|
|
206
196
|
if (this.buffer[end - 1] === '\r')
|
|
@@ -213,7 +203,6 @@ class Lexer {
|
|
|
213
203
|
setNext(state) {
|
|
214
204
|
this.buffer = this.buffer.substring(this.pos);
|
|
215
205
|
this.pos = 0;
|
|
216
|
-
this.lineEndPos = null;
|
|
217
206
|
this.next = state;
|
|
218
207
|
return null;
|
|
219
208
|
}
|
|
@@ -338,7 +327,7 @@ class Lexer {
|
|
|
338
327
|
yield* this.pushCount(1);
|
|
339
328
|
return 'doc';
|
|
340
329
|
case '*':
|
|
341
|
-
yield* this.pushUntil(
|
|
330
|
+
yield* this.pushUntil(isNotIdentifierChar);
|
|
342
331
|
return 'doc';
|
|
343
332
|
case '"':
|
|
344
333
|
case "'":
|
|
@@ -366,7 +355,7 @@ class Lexer {
|
|
|
366
355
|
const line = this.getLine();
|
|
367
356
|
if (line === null)
|
|
368
357
|
return this.setNext('flow');
|
|
369
|
-
if ((indent !== -1 && indent < this.indentNext
|
|
358
|
+
if ((indent !== -1 && indent < this.indentNext) ||
|
|
370
359
|
(indent === 0 &&
|
|
371
360
|
(line.startsWith('---') || line.startsWith('...')) &&
|
|
372
361
|
isEmpty(line[3]))) {
|
|
@@ -384,11 +373,8 @@ class Lexer {
|
|
|
384
373
|
}
|
|
385
374
|
}
|
|
386
375
|
let n = 0;
|
|
387
|
-
while (line[n] === ',')
|
|
388
|
-
n += yield* this.pushCount(1);
|
|
389
|
-
n += yield* this.pushSpaces(true);
|
|
390
|
-
this.flowKey = false;
|
|
391
|
-
}
|
|
376
|
+
while (line[n] === ',')
|
|
377
|
+
n += (yield* this.pushCount(1)) + (yield* this.pushSpaces(true));
|
|
392
378
|
n += yield* this.pushIndicators();
|
|
393
379
|
switch (line[n]) {
|
|
394
380
|
case undefined:
|
|
@@ -409,7 +395,7 @@ class Lexer {
|
|
|
409
395
|
this.flowLevel -= 1;
|
|
410
396
|
return this.flowLevel ? 'flow' : 'doc';
|
|
411
397
|
case '*':
|
|
412
|
-
yield* this.pushUntil(
|
|
398
|
+
yield* this.pushUntil(isNotIdentifierChar);
|
|
413
399
|
return 'flow';
|
|
414
400
|
case '"':
|
|
415
401
|
case "'":
|
|
@@ -418,7 +404,6 @@ class Lexer {
|
|
|
418
404
|
case ':': {
|
|
419
405
|
const next = this.charAt(1);
|
|
420
406
|
if (this.flowKey || isEmpty(next) || next === ',') {
|
|
421
|
-
this.flowKey = false;
|
|
422
407
|
yield* this.pushCount(1);
|
|
423
408
|
yield* this.pushSpaces(true);
|
|
424
409
|
return 'flow';
|
|
@@ -448,19 +433,17 @@ class Lexer {
|
|
|
448
433
|
end = this.buffer.indexOf('"', end + 1);
|
|
449
434
|
}
|
|
450
435
|
}
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
if (nl !== -1) {
|
|
455
|
-
while (nl !== -1) {
|
|
436
|
+
let nl = this.buffer.indexOf('\n', this.pos);
|
|
437
|
+
if (nl !== -1 && nl < end) {
|
|
438
|
+
while (nl !== -1 && nl < end) {
|
|
456
439
|
const cs = this.continueScalar(nl + 1);
|
|
457
440
|
if (cs === -1)
|
|
458
441
|
break;
|
|
459
|
-
nl =
|
|
442
|
+
nl = this.buffer.indexOf('\n', cs);
|
|
460
443
|
}
|
|
461
|
-
if (nl !== -1) {
|
|
444
|
+
if (nl !== -1 && nl < end) {
|
|
462
445
|
// this is an error caused by an unexpected unindent
|
|
463
|
-
end = nl -
|
|
446
|
+
end = nl - 1;
|
|
464
447
|
}
|
|
465
448
|
}
|
|
466
449
|
if (end === -1) {
|
|
@@ -560,18 +543,17 @@ class Lexer {
|
|
|
560
543
|
end = i;
|
|
561
544
|
}
|
|
562
545
|
else if (isEmpty(ch)) {
|
|
563
|
-
|
|
546
|
+
const next = this.buffer[i + 1];
|
|
547
|
+
if (next === '#' || (inFlow && invalidFlowScalarChars.includes(next)))
|
|
548
|
+
break;
|
|
564
549
|
if (ch === '\r') {
|
|
565
550
|
if (next === '\n') {
|
|
566
551
|
i += 1;
|
|
567
552
|
ch = '\n';
|
|
568
|
-
next = this.buffer[i + 1];
|
|
569
553
|
}
|
|
570
554
|
else
|
|
571
555
|
end = i;
|
|
572
556
|
}
|
|
573
|
-
if (next === '#' || (inFlow && invalidFlowScalarChars.includes(next)))
|
|
574
|
-
break;
|
|
575
557
|
if (ch === '\n') {
|
|
576
558
|
const cs = this.continueScalar(i + 1);
|
|
577
559
|
if (cs === -1)
|
|
@@ -613,11 +595,13 @@ class Lexer {
|
|
|
613
595
|
*pushIndicators() {
|
|
614
596
|
switch (this.charAt(0)) {
|
|
615
597
|
case '!':
|
|
616
|
-
|
|
617
|
-
(yield* this.
|
|
618
|
-
|
|
598
|
+
if (this.charAt(1) === '<')
|
|
599
|
+
return ((yield* this.pushVerbatimTag()) +
|
|
600
|
+
(yield* this.pushSpaces(true)) +
|
|
601
|
+
(yield* this.pushIndicators()));
|
|
602
|
+
// fallthrough
|
|
619
603
|
case '&':
|
|
620
|
-
return ((yield* this.pushUntil(
|
|
604
|
+
return ((yield* this.pushUntil(isNotIdentifierChar)) +
|
|
621
605
|
(yield* this.pushSpaces(true)) +
|
|
622
606
|
(yield* this.pushIndicators()));
|
|
623
607
|
case ':':
|
|
@@ -626,8 +610,6 @@ class Lexer {
|
|
|
626
610
|
if (isEmpty(this.charAt(1))) {
|
|
627
611
|
if (this.flowLevel === 0)
|
|
628
612
|
this.indentNext = this.indentValue + 1;
|
|
629
|
-
else if (this.flowKey)
|
|
630
|
-
this.flowKey = false;
|
|
631
613
|
return ((yield* this.pushCount(1)) +
|
|
632
614
|
(yield* this.pushSpaces(true)) +
|
|
633
615
|
(yield* this.pushIndicators()));
|
|
@@ -635,30 +617,12 @@ class Lexer {
|
|
|
635
617
|
}
|
|
636
618
|
return 0;
|
|
637
619
|
}
|
|
638
|
-
*
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
return yield* this.pushToIndex(ch === '>' ? i + 1 : i, false);
|
|
645
|
-
}
|
|
646
|
-
else {
|
|
647
|
-
let i = this.pos + 1;
|
|
648
|
-
let ch = this.buffer[i];
|
|
649
|
-
while (ch) {
|
|
650
|
-
if (tagChars.includes(ch))
|
|
651
|
-
ch = this.buffer[++i];
|
|
652
|
-
else if (ch === '%' &&
|
|
653
|
-
hexDigits.includes(this.buffer[i + 1]) &&
|
|
654
|
-
hexDigits.includes(this.buffer[i + 2])) {
|
|
655
|
-
ch = this.buffer[(i += 3)];
|
|
656
|
-
}
|
|
657
|
-
else
|
|
658
|
-
break;
|
|
659
|
-
}
|
|
660
|
-
return yield* this.pushToIndex(i, false);
|
|
661
|
-
}
|
|
620
|
+
*pushVerbatimTag() {
|
|
621
|
+
let i = this.pos + 2;
|
|
622
|
+
let ch = this.buffer[i];
|
|
623
|
+
while (!isEmpty(ch) && ch !== '>')
|
|
624
|
+
ch = this.buffer[++i];
|
|
625
|
+
return yield* this.pushToIndex(ch === '>' ? i + 1 : i, false);
|
|
662
626
|
}
|
|
663
627
|
*pushNewline() {
|
|
664
628
|
const ch = this.buffer[this.pos];
|
package/dist/parse/parser.d.ts
CHANGED
package/dist/parse/parser.js
CHANGED
|
@@ -22,6 +22,38 @@ function includesNonEmpty(list) {
|
|
|
22
22
|
}
|
|
23
23
|
return false;
|
|
24
24
|
}
|
|
25
|
+
function atFirstEmptyLineAfterComments(start) {
|
|
26
|
+
let hasComment = false;
|
|
27
|
+
for (let i = 0; i < start.length; ++i) {
|
|
28
|
+
switch (start[i].type) {
|
|
29
|
+
case 'space':
|
|
30
|
+
break;
|
|
31
|
+
case 'comment':
|
|
32
|
+
hasComment = true;
|
|
33
|
+
break;
|
|
34
|
+
case 'newline':
|
|
35
|
+
if (!hasComment)
|
|
36
|
+
return false;
|
|
37
|
+
break;
|
|
38
|
+
default:
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
if (hasComment) {
|
|
43
|
+
for (let i = start.length - 1; i >= 0; --i) {
|
|
44
|
+
switch (start[i].type) {
|
|
45
|
+
/* istanbul ignore next */
|
|
46
|
+
case 'space':
|
|
47
|
+
break;
|
|
48
|
+
case 'newline':
|
|
49
|
+
return true;
|
|
50
|
+
default:
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
25
57
|
function isFlowToken(token) {
|
|
26
58
|
switch (token === null || token === void 0 ? void 0 : token.type) {
|
|
27
59
|
case 'alias':
|
|
@@ -207,7 +239,6 @@ class Parser {
|
|
|
207
239
|
this.indent += source.length;
|
|
208
240
|
break;
|
|
209
241
|
case 'doc-mode':
|
|
210
|
-
case 'flow-error-end':
|
|
211
242
|
return;
|
|
212
243
|
default:
|
|
213
244
|
this.atNewLine = false;
|
|
@@ -280,14 +311,9 @@ class Parser {
|
|
|
280
311
|
}
|
|
281
312
|
else {
|
|
282
313
|
const top = this.peek(1);
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
token.indent = 'indent' in top ? top.indent :
|
|
286
|
-
}
|
|
287
|
-
else if (token.type === 'flow-collection' && top.type === 'document') {
|
|
288
|
-
// Ignore all indent for top-level flow collections
|
|
289
|
-
token.indent = 0;
|
|
290
|
-
}
|
|
314
|
+
// For these, parent indent is needed instead of own
|
|
315
|
+
if (token.type === 'block-scalar' || token.type === 'flow-collection')
|
|
316
|
+
token.indent = 'indent' in top ? top.indent : -1;
|
|
291
317
|
if (token.type === 'flow-collection')
|
|
292
318
|
fixFlowSeqItems(token);
|
|
293
319
|
switch (top.type) {
|
|
@@ -480,38 +506,24 @@ class Parser {
|
|
|
480
506
|
switch (this.type) {
|
|
481
507
|
case 'newline':
|
|
482
508
|
this.onKeyLine = false;
|
|
483
|
-
if (it.
|
|
484
|
-
const
|
|
485
|
-
const
|
|
486
|
-
if ((
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
509
|
+
if (!it.sep && atFirstEmptyLineAfterComments(it.start)) {
|
|
510
|
+
const prev = map.items[map.items.length - 2];
|
|
511
|
+
const end = (_a = prev === null || prev === void 0 ? void 0 : prev.value) === null || _a === void 0 ? void 0 : _a.end;
|
|
512
|
+
if (Array.isArray(end)) {
|
|
513
|
+
Array.prototype.push.apply(end, it.start);
|
|
514
|
+
it.start = [this.sourceToken];
|
|
515
|
+
return;
|
|
516
|
+
}
|
|
490
517
|
}
|
|
491
|
-
|
|
492
|
-
it.sep.push(this.sourceToken);
|
|
493
|
-
else
|
|
494
|
-
it.start.push(this.sourceToken);
|
|
495
|
-
return;
|
|
518
|
+
// fallthrough
|
|
496
519
|
case 'space':
|
|
497
520
|
case 'comment':
|
|
498
521
|
if (it.value)
|
|
499
522
|
map.items.push({ start: [this.sourceToken] });
|
|
500
523
|
else if (it.sep)
|
|
501
524
|
it.sep.push(this.sourceToken);
|
|
502
|
-
else
|
|
503
|
-
if (this.atIndentedComment(it.start, map.indent)) {
|
|
504
|
-
const prev = map.items[map.items.length - 2];
|
|
505
|
-
const end = (_a = prev === null || prev === void 0 ? void 0 : prev.value) === null || _a === void 0 ? void 0 : _a.end;
|
|
506
|
-
if (Array.isArray(end)) {
|
|
507
|
-
Array.prototype.push.apply(end, it.start);
|
|
508
|
-
end.push(this.sourceToken);
|
|
509
|
-
map.items.pop();
|
|
510
|
-
return;
|
|
511
|
-
}
|
|
512
|
-
}
|
|
525
|
+
else
|
|
513
526
|
it.start.push(this.sourceToken);
|
|
514
|
-
}
|
|
515
527
|
return;
|
|
516
528
|
}
|
|
517
529
|
if (this.indent >= map.indent) {
|
|
@@ -616,34 +628,22 @@ class Parser {
|
|
|
616
628
|
const it = seq.items[seq.items.length - 1];
|
|
617
629
|
switch (this.type) {
|
|
618
630
|
case 'newline':
|
|
619
|
-
if (it.value) {
|
|
620
|
-
const
|
|
621
|
-
const
|
|
622
|
-
if ((
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
631
|
+
if (!it.value && atFirstEmptyLineAfterComments(it.start)) {
|
|
632
|
+
const prev = seq.items[seq.items.length - 2];
|
|
633
|
+
const end = (_a = prev === null || prev === void 0 ? void 0 : prev.value) === null || _a === void 0 ? void 0 : _a.end;
|
|
634
|
+
if (Array.isArray(end)) {
|
|
635
|
+
Array.prototype.push.apply(end, it.start);
|
|
636
|
+
it.start = [this.sourceToken];
|
|
637
|
+
return;
|
|
638
|
+
}
|
|
626
639
|
}
|
|
627
|
-
|
|
628
|
-
it.start.push(this.sourceToken);
|
|
629
|
-
return;
|
|
640
|
+
// fallthrough
|
|
630
641
|
case 'space':
|
|
631
642
|
case 'comment':
|
|
632
643
|
if (it.value)
|
|
633
644
|
seq.items.push({ start: [this.sourceToken] });
|
|
634
|
-
else
|
|
635
|
-
if (this.atIndentedComment(it.start, seq.indent)) {
|
|
636
|
-
const prev = seq.items[seq.items.length - 2];
|
|
637
|
-
const end = (_a = prev === null || prev === void 0 ? void 0 : prev.value) === null || _a === void 0 ? void 0 : _a.end;
|
|
638
|
-
if (Array.isArray(end)) {
|
|
639
|
-
Array.prototype.push.apply(end, it.start);
|
|
640
|
-
end.push(this.sourceToken);
|
|
641
|
-
seq.items.pop();
|
|
642
|
-
return;
|
|
643
|
-
}
|
|
644
|
-
}
|
|
645
|
+
else
|
|
645
646
|
it.start.push(this.sourceToken);
|
|
646
|
-
}
|
|
647
647
|
return;
|
|
648
648
|
case 'anchor':
|
|
649
649
|
case 'tag':
|
|
@@ -838,13 +838,6 @@ class Parser {
|
|
|
838
838
|
}
|
|
839
839
|
return null;
|
|
840
840
|
}
|
|
841
|
-
atIndentedComment(start, indent) {
|
|
842
|
-
if (this.type !== 'comment')
|
|
843
|
-
return false;
|
|
844
|
-
if (this.indent <= indent)
|
|
845
|
-
return false;
|
|
846
|
-
return start.every(st => st.type === 'newline' || st.type === 'space');
|
|
847
|
-
}
|
|
848
841
|
*documentEnd(docEnd) {
|
|
849
842
|
if (this.type !== 'doc-mode') {
|
|
850
843
|
if (docEnd.end)
|
package/dist/public-api.js
CHANGED
|
@@ -8,8 +8,10 @@ var lineCounter = require('./parse/line-counter.js');
|
|
|
8
8
|
var parser = require('./parse/parser.js');
|
|
9
9
|
|
|
10
10
|
function parseOptions(options) {
|
|
11
|
-
const prettyErrors = options.prettyErrors !== false;
|
|
12
|
-
const lineCounter$1 = options
|
|
11
|
+
const prettyErrors = !options || options.prettyErrors !== false;
|
|
12
|
+
const lineCounter$1 = (options && options.lineCounter) ||
|
|
13
|
+
(prettyErrors && new lineCounter.LineCounter()) ||
|
|
14
|
+
null;
|
|
13
15
|
return { lineCounter: lineCounter$1, prettyErrors };
|
|
14
16
|
}
|
|
15
17
|
/**
|