jsonpath-faster
Version:
Query JavaScript objects with JSONPath expressions. Compiles and caches JSONpath to JS
50 lines (45 loc) • 1.04 kB
JavaScript
"use strict";
const { js } = require("../util");
const { makeLadder } = require("../tokens");
const vivifyType = makeLadder([
{
when: {
expression: { type: "numeric_literal" },
operation: "subscript",
scope: "child"
},
gen: tok => js([])
},
{
when: {
expression: { type: ["identifier", "string_literal", "numeric_literal"] },
operation: ["member", "subscript"],
scope: "child"
},
gen: tok => js({})
}
]);
const shouldVivify = makeLadder([
{
when: [
{
scope: "child",
operation: "member",
expression: { type: ["identifier", "numeric_literal"] }
},
{
scope: "child",
operation: "subscript",
expression: {
type: ["string_literal", "numeric_literal", "script_expression"]
}
},
{ scope: "internal", operation: "terminal" },
{
expression: { type: "root", value: "$" }
}
],
gen: tok => true
}
]);
module.exports = { vivifyType, shouldVivify };