@stoplight/yaml
Advanced tools
Comparing version 2.7.0 to 2.8.0
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const yaml_ast_parser_1 = require("yaml-ast-parser"); | ||
const buildJsonPath_1 = require("./buildJsonPath"); | ||
const utils_1 = require("./utils"); | ||
exports.getJsonPathForPosition = ({ ast, lineMap }, { line, character }) => { | ||
@@ -12,3 +14,3 @@ if (line >= lineMap.length || character >= lineMap[line]) { | ||
return; | ||
const path = buildJsonPath(node); | ||
const path = buildJsonPath_1.buildJsonPath(node); | ||
if (path.length === 0) | ||
@@ -18,3 +20,2 @@ return; | ||
}; | ||
const isValidNode = (node) => node !== null && node !== undefined; | ||
function* walk(node) { | ||
@@ -25,3 +26,3 @@ switch (node.kind) { | ||
for (const mapping of node.mappings) { | ||
if (isValidNode(mapping)) { | ||
if (utils_1.isValidNode(mapping)) { | ||
yield mapping; | ||
@@ -33,6 +34,6 @@ } | ||
case yaml_ast_parser_1.Kind.MAPPING: | ||
if (isValidNode(node.key)) { | ||
if (utils_1.isValidNode(node.key)) { | ||
yield node.key; | ||
} | ||
if (isValidNode(node.value)) { | ||
if (utils_1.isValidNode(node.value)) { | ||
yield node.value; | ||
@@ -44,3 +45,3 @@ } | ||
for (const item of node.items) { | ||
if (isValidNode(item)) { | ||
if (utils_1.isValidNode(item)) { | ||
yield item; | ||
@@ -102,39 +103,2 @@ } | ||
} | ||
function buildJsonPath(node) { | ||
const path = []; | ||
let prevNode = node; | ||
while (node) { | ||
switch (node.kind) { | ||
case yaml_ast_parser_1.Kind.SCALAR: | ||
path.unshift(node.value); | ||
break; | ||
case yaml_ast_parser_1.Kind.MAPPING: | ||
if (prevNode !== node.key) { | ||
if (path.length > 0 && | ||
isValidNode(node.value) && | ||
node.value.value === path[0]) { | ||
path[0] = node.key.value; | ||
} | ||
else { | ||
path.unshift(node.key.value); | ||
} | ||
} | ||
break; | ||
case yaml_ast_parser_1.Kind.SEQ: | ||
if (prevNode) { | ||
const index = node.items.indexOf(prevNode); | ||
if (prevNode.kind === yaml_ast_parser_1.Kind.SCALAR) { | ||
path[0] = index; | ||
} | ||
else if (index !== -1) { | ||
path.unshift(index); | ||
} | ||
} | ||
break; | ||
} | ||
prevNode = node; | ||
node = node.parent; | ||
} | ||
return path; | ||
} | ||
//# sourceMappingURL=getJsonPathForPosition.js.map |
{ | ||
"name": "@stoplight/yaml", | ||
"version": "2.7.0", | ||
"version": "2.8.0", | ||
"description": "Useful functions when working with YAML.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -5,2 +5,3 @@ "use strict"; | ||
const yaml_ast_parser_1 = require("yaml-ast-parser"); | ||
const buildJsonPath_1 = require("./buildJsonPath"); | ||
const lineForPosition_1 = require("./lineForPosition"); | ||
@@ -138,2 +139,3 @@ exports.parseWithPointers = (value, options) => { | ||
message: 'duplicate key', | ||
path: buildJsonPath_1.buildJsonPath(node), | ||
range: { | ||
@@ -140,0 +142,0 @@ start: { |
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
48288
33
473