@@ -31,5 +31,12 @@ import { Alias } from '../nodes/Alias.js'; | ||
| case 'flow-collection': | ||
| node = composeCollection(CN, ctx, token, props, onError); | ||
| if (anchor) | ||
| node.anchor = anchor.source.substring(1); | ||
| try { | ||
| node = composeCollection(CN, ctx, token, props, onError); | ||
| if (anchor) | ||
| node.anchor = anchor.source.substring(1); | ||
| } | ||
| catch (error) { | ||
| // Almost certainly here due to a stack overflow | ||
| const message = error instanceof Error ? error.message : String(error); | ||
| onError(token, 'RESOURCE_EXHAUSTION', message); | ||
| } | ||
| break; | ||
@@ -41,6 +48,6 @@ default: { | ||
| onError(token, 'UNEXPECTED_TOKEN', message); | ||
| node = composeEmptyNode(ctx, token.offset, undefined, null, props, onError); | ||
| isSrcToken = false; | ||
| } | ||
| } | ||
| node ?? (node = composeEmptyNode(ctx, token.offset, undefined, null, props, onError)); | ||
| if (anchor && node.anchor === '') | ||
@@ -47,0 +54,0 @@ onError(anchor, 'BAD_ALIAS', 'Anchor cannot be an empty string'); |
@@ -23,2 +23,3 @@ import { anchorIsValid } from '../doc/anchors.js'; | ||
| singleQuote: null, | ||
| trailingComma: false, | ||
| trueStr: 'true', | ||
@@ -25,0 +26,0 @@ verifyAliasOrder: true |
@@ -105,8 +105,18 @@ import { isNode, isPair } from '../nodes/identity.js'; | ||
| let str = stringify(item, itemCtx, () => (comment = null)); | ||
| if (i < items.length - 1) | ||
| reqNewline || (reqNewline = lines.length > linesAtValue || str.includes('\n')); | ||
| if (i < items.length - 1) { | ||
| str += ','; | ||
| } | ||
| else if (ctx.options.trailingComma) { | ||
| if (ctx.options.lineWidth > 0) { | ||
| reqNewline || (reqNewline = lines.reduce((sum, line) => sum + line.length + 2, 2) + | ||
| (str.length + 2) > | ||
| ctx.options.lineWidth); | ||
| } | ||
| if (reqNewline) { | ||
| str += ','; | ||
| } | ||
| } | ||
| if (comment) | ||
| str += lineComment(str, itemIndent, commentString(comment)); | ||
| if (!reqNewline && (lines.length > linesAtValue || str.includes('\n'))) | ||
| reqNewline = true; | ||
| lines.push(str); | ||
@@ -113,0 +123,0 @@ linesAtValue = lines.length; |
@@ -33,5 +33,12 @@ 'use strict'; | ||
| case 'flow-collection': | ||
| node = composeCollection.composeCollection(CN, ctx, token, props, onError); | ||
| if (anchor) | ||
| node.anchor = anchor.source.substring(1); | ||
| try { | ||
| node = composeCollection.composeCollection(CN, ctx, token, props, onError); | ||
| if (anchor) | ||
| node.anchor = anchor.source.substring(1); | ||
| } | ||
| catch (error) { | ||
| // Almost certainly here due to a stack overflow | ||
| const message = error instanceof Error ? error.message : String(error); | ||
| onError(token, 'RESOURCE_EXHAUSTION', message); | ||
| } | ||
| break; | ||
@@ -43,6 +50,6 @@ default: { | ||
| onError(token, 'UNEXPECTED_TOKEN', message); | ||
| node = composeEmptyNode(ctx, token.offset, undefined, null, props, onError); | ||
| isSrcToken = false; | ||
| } | ||
| } | ||
| node ?? (node = composeEmptyNode(ctx, token.offset, undefined, null, props, onError)); | ||
| if (anchor && node.anchor === '') | ||
@@ -49,0 +56,0 @@ onError(anchor, 'BAD_ALIAS', 'Anchor cannot be an empty string'); |
+1
-1
| import type { LineCounter } from './parse/line-counter'; | ||
| export 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' | 'NON_STRING_KEY' | 'TAB_AS_INDENT' | 'TAG_RESOLVE_FAILED' | 'UNEXPECTED_TOKEN' | 'BAD_COLLECTION_TYPE'; | ||
| export 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' | 'NON_STRING_KEY' | 'RESOURCE_EXHAUSTION' | 'TAB_AS_INDENT' | 'TAG_RESOLVE_FAILED' | 'UNEXPECTED_TOKEN' | 'BAD_COLLECTION_TYPE'; | ||
| export type LinePos = { | ||
@@ -4,0 +4,0 @@ line: number; |
@@ -330,2 +330,8 @@ import type { Reviver } from './doc/applyReviver'; | ||
| /** | ||
| * Add a trailing comma after the last entry in a flow map or flow sequence that's split across multiple lines. | ||
| * | ||
| * Default: `'false'` | ||
| */ | ||
| trailingComma?: boolean; | ||
| /** | ||
| * String representation for `true`. | ||
@@ -332,0 +338,0 @@ * With the core schema, use `'true'`, `'True'`, or `'TRUE'`. |
@@ -25,2 +25,3 @@ 'use strict'; | ||
| singleQuote: null, | ||
| trailingComma: false, | ||
| trueStr: 'true', | ||
@@ -27,0 +28,0 @@ verifyAliasOrder: true |
@@ -107,8 +107,18 @@ 'use strict'; | ||
| let str = stringify.stringify(item, itemCtx, () => (comment = null)); | ||
| if (i < items.length - 1) | ||
| reqNewline || (reqNewline = lines.length > linesAtValue || str.includes('\n')); | ||
| if (i < items.length - 1) { | ||
| str += ','; | ||
| } | ||
| else if (ctx.options.trailingComma) { | ||
| if (ctx.options.lineWidth > 0) { | ||
| reqNewline || (reqNewline = lines.reduce((sum, line) => sum + line.length + 2, 2) + | ||
| (str.length + 2) > | ||
| ctx.options.lineWidth); | ||
| } | ||
| if (reqNewline) { | ||
| str += ','; | ||
| } | ||
| } | ||
| if (comment) | ||
| str += stringifyComment.lineComment(str, itemIndent, commentString(comment)); | ||
| if (!reqNewline && (lines.length > linesAtValue || str.includes('\n'))) | ||
| reqNewline = true; | ||
| lines.push(str); | ||
@@ -115,0 +125,0 @@ linesAtValue = lines.length; |
+1
-1
| { | ||
| "name": "yaml", | ||
| "version": "2.8.2", | ||
| "version": "2.8.3", | ||
| "license": "ISC", | ||
@@ -5,0 +5,0 @@ "author": "Eemeli Aro <eemeli@gmail.com>", |
AI-detected potential code anomaly
Supply chain riskAI has identified unusual behaviors that may pose a security risk.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
AI-detected potential code anomaly
Supply chain riskAI has identified unusual behaviors that may pose a security risk.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
684613
0.24%18096
0.23%