@stoplight/yaml
Advanced tools
Comparing version 3.5.1 to 3.5.2
export * from './buildJsonPath'; | ||
export * from './dereferenceAnchor'; | ||
export * from './getJsonPathForPosition'; | ||
@@ -3,0 +4,0 @@ export * from './getLocationForJsonPath'; |
@@ -5,2 +5,3 @@ "use strict"; | ||
tslib_1.__exportStar(require("./buildJsonPath"), exports); | ||
tslib_1.__exportStar(require("./dereferenceAnchor"), exports); | ||
tslib_1.__exportStar(require("./getJsonPathForPosition"), exports); | ||
@@ -7,0 +8,0 @@ tslib_1.__exportStar(require("./getLocationForJsonPath"), exports); |
{ | ||
"name": "@stoplight/yaml", | ||
"version": "3.5.1", | ||
"version": "3.5.2", | ||
"description": "Useful functions when working with YAML.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
import { IDiagnostic } from '@stoplight/types'; | ||
import { IParseOptions, Kind, YAMLAnchorReference, YAMLMapping, YAMLNode, YAMLScalar } from './types'; | ||
import { IParseOptions, Kind, YAMLMapping, YAMLNode, YAMLScalar } from './types'; | ||
export declare const parseWithPointers: <T>(value: string, options?: IParseOptions | undefined) => import("@stoplight/types").IParserResult<T | undefined, YAMLNode, number[], IParseOptions>; | ||
export declare const walkAST: (node: YAMLAnchorReference | import("./types").YAMLBaseNode<Kind.INCLUDE_REF> | YAMLScalar | import("./types").YAMLMap | YAMLMapping | import("./types").YAMLSequence | null, options: IParseOptions | undefined, lineMap: number[], diagnostics: IDiagnostic[]) => unknown; | ||
export declare const walkAST: (node: import("./types").YAMLAnchorReference | import("./types").YAMLBaseNode<Kind.INCLUDE_REF> | YAMLScalar | import("./types").YAMLMap | YAMLMapping | import("./types").YAMLSequence | null, options: IParseOptions | undefined, lineMap: number[], diagnostics: IDiagnostic[]) => unknown; |
@@ -6,2 +6,3 @@ "use strict"; | ||
const buildJsonPath_1 = require("./buildJsonPath"); | ||
const dereferenceAnchor_1 = require("./dereferenceAnchor"); | ||
const lineForPosition_1 = require("./lineForPosition"); | ||
@@ -88,6 +89,6 @@ const types_2 = require("./types"); | ||
case types_2.Kind.ANCHOR_REF: { | ||
if (utils_1.isObject(node.value) && isCircularAnchorRef(node)) { | ||
node.value = dereferenceAnchor(node.value, node.referencesAnchor); | ||
if (utils_1.isObject(node.value)) { | ||
node.value = dereferenceAnchor_1.dereferenceAnchor(node.value, node.referencesAnchor); | ||
} | ||
return node.value && exports.walkAST(node.value, options, lineMap, diagnostics); | ||
return exports.walkAST(node.value, options, lineMap, diagnostics); | ||
} | ||
@@ -100,35 +101,2 @@ default: | ||
}; | ||
const isCircularAnchorRef = (anchorRef) => { | ||
const { referencesAnchor } = anchorRef; | ||
let node = anchorRef; | ||
while ((node = node.parent)) { | ||
if ('anchorId' in node && node.anchorId === referencesAnchor) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
}; | ||
const dereferenceAnchor = (node, anchorId) => { | ||
if (!utils_1.isObject(node)) | ||
return node; | ||
if (node.kind === types_2.Kind.ANCHOR_REF && node.referencesAnchor === anchorId) | ||
return null; | ||
switch (node.kind) { | ||
case types_2.Kind.MAP: | ||
return Object.assign({}, node, { mappings: node.mappings.map(mapping => dereferenceAnchor(mapping, anchorId)) }); | ||
case types_2.Kind.SEQ: | ||
return Object.assign({}, node, { items: node.items.map(item => dereferenceAnchor(item, anchorId)) }); | ||
case types_2.Kind.MAPPING: | ||
return Object.assign({}, node, { value: dereferenceAnchor(node.value, anchorId) }); | ||
case types_2.Kind.SCALAR: | ||
return node; | ||
case types_2.Kind.ANCHOR_REF: | ||
if (utils_1.isObject(node.value) && isCircularAnchorRef(node)) { | ||
return null; | ||
} | ||
return node; | ||
default: | ||
return node; | ||
} | ||
}; | ||
function getScalarValue(node) { | ||
@@ -135,0 +103,0 @@ switch (yaml_ast_parser_1.determineScalarType(node)) { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
63438
39
694