UNPKG

nimma

Version:

Scalable JSONPath engine.

50 lines (37 loc) 1.17 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var builders = require('../ast/builders.cjs'); var emitCall = require('../templates/emit-call.cjs'); var sandbox = require('../templates/sandbox.cjs'); var consts = require('../tree/consts.cjs'); // covers: // $.. const IS_OBJECT_IDENTIFIER = builders.identifier('isObject'); const IS_NOT_OBJECT_IF_STATEMENT = builders.ifStatement( builders.unaryExpression( '!', builders.callExpression(IS_OBJECT_IDENTIFIER, [sandbox.default.value]), ), builders.returnStatement(), ); const EMIT_ROOT_CALL_EXPRESSION = emitCall.default(builders.stringLiteral('$..'), { keyed: false, parents: 0, }); var allParents = (nodes, tree, ctx) => { if (nodes.length !== 1 || nodes[0].type !== 'AllParentExpression') { return false; } tree.addRuntimeDependency(IS_OBJECT_IDENTIFIER.name); tree.addTreeMethod( ctx.id, builders.blockStatement([ IS_NOT_OBJECT_IF_STATEMENT, emitCall.default(ctx.id, ctx.iterator.modifiers), ]), consts.NEEDS_TRAVERSAL, ); tree.body.push(EMIT_ROOT_CALL_EXPRESSION); return true; }; exports.default = allParents;