Comparing version 0.1.3 to 0.1.4
@@ -37,8 +37,2 @@ 'use strict'; | ||
return booleanLiteral(value); | ||
default: | ||
return { | ||
type: 'Literal', | ||
value | ||
}; | ||
} | ||
@@ -45,0 +39,0 @@ } |
@@ -7,2 +7,3 @@ 'use strict'; | ||
var builders = require('../ast/builders.js'); | ||
var internalScope = require('../templates/internal-scope.js'); | ||
var sandbox = require('../templates/sandbox.js'); | ||
@@ -12,3 +13,2 @@ var scope = require('../templates/scope.js'); | ||
const pos = builders.identifier('pos'); | ||
function generateMemberExpression(iterator, { | ||
@@ -28,6 +28,6 @@ deep, | ||
const isLastNode = iterator.nextNode === null || iterator.nextNode === 'KeyExpression'; | ||
const right = builders.sequenceExpression([builders.assignmentExpression('=', pos, isLastNode ? builders.conditionalExpression(builders.binaryExpression('!==', scope['default'].property, builders.literal(value)), builders.numericLiteral(-1), scope['default'].depth) : builders.callExpression(builders.memberExpression(scope['default'].path, builders.identifier('indexOf')), [builders.literal(value), iterator.state.pos === 0 ? pos : builders.binaryExpression('+', pos, builders.numericLiteral(1))])), builders.binaryExpression('===', pos, builders.numericLiteral(-1))]); | ||
const right = builders.sequenceExpression([builders.assignmentExpression('=', internalScope['default'].pos, isLastNode ? builders.conditionalExpression(builders.binaryExpression('!==', scope['default'].property, builders.literal(value)), builders.numericLiteral(-1), scope['default'].depth) : builders.callExpression(builders.memberExpression(scope['default'].path, builders.identifier('indexOf')), [builders.literal(value), iterator.state.pos === 0 ? internalScope['default'].pos : builders.binaryExpression('+', internalScope['default'].pos, builders.numericLiteral(1))])), builders.binaryExpression('===', internalScope['default'].pos, builders.numericLiteral(-1))]); | ||
if (isLastNode) { | ||
return builders.logicalExpression('||', builders.binaryExpression('<', scope['default'].depth, iterator.state.pos === 0 ? pos : builders.binaryExpression('+', pos, builders.numericLiteral(iterator.state.pos))), right); | ||
return builders.logicalExpression('||', builders.binaryExpression('<', scope['default'].depth, iterator.state.pos === 0 ? internalScope['default'].pos : builders.binaryExpression('+', internalScope['default'].pos, builders.numericLiteral(iterator.state.pos))), right); | ||
} | ||
@@ -41,6 +41,6 @@ | ||
if (!iterator.feedback.fixed && iterator.state.absolutePos !== 0) { | ||
left = builders.binaryExpression('<', scope['default'].depth, iterator.state.pos === 0 ? pos : builders.binaryExpression('+', pos, builders.numericLiteral(iterator.state.pos))); | ||
left = builders.binaryExpression('<', scope['default'].depth, iterator.state.pos === 0 ? internalScope['default'].pos : builders.binaryExpression('+', internalScope['default'].pos, builders.numericLiteral(iterator.state.pos))); | ||
} | ||
const right = builders.binaryExpression('!==', builders.memberExpression(scope['default'].path, iterator.state.pos === 0 ? builders.numericLiteral(0) : iterator.feedback.fixed ? builders.numericLiteral(iterator.state.pos) : builders.binaryExpression('+', pos, builders.numericLiteral(iterator.state.pos)), true), builders.literal(value)); | ||
const right = builders.binaryExpression('!==', builders.memberExpression(scope['default'].path, iterator.state.pos === 0 ? builders.numericLiteral(0) : iterator.feedback.fixed ? builders.numericLiteral(iterator.state.pos) : builders.binaryExpression('+', internalScope['default'].pos, builders.numericLiteral(iterator.state.pos)), true), builders.literal(value)); | ||
return left !== void 0 ? builders.logicalExpression('||', left, right) : right; | ||
@@ -63,3 +63,3 @@ } | ||
function generateSliceExpression(iterator, node, tree) { | ||
const member = iterator.state.inverted ? builders.binaryExpression('-', scope['default'].depth, builders.numericLiteral(iterator.state.pos)) : iterator.state.pos === 0 ? builders.numericLiteral(0) : iterator.feedback.fixed ? builders.numericLiteral(iterator.state.pos) : builders.binaryExpression('+', pos, builders.numericLiteral(iterator.state.pos)); | ||
const member = iterator.state.inverted ? builders.binaryExpression('-', scope['default'].depth, builders.numericLiteral(iterator.state.pos)) : iterator.state.pos === 0 ? builders.numericLiteral(0) : iterator.feedback.fixed ? builders.numericLiteral(iterator.state.pos) : builders.binaryExpression('+', internalScope['default'].pos, builders.numericLiteral(iterator.state.pos)); | ||
const path = iterator.feedback.bailed ? scope['default'].property : builders.memberExpression(scope['default'].path, member, true); | ||
@@ -96,3 +96,3 @@ const isNumberBinaryExpression = builders.binaryExpression('!==', builders.unaryExpression('typeof', path), builders.stringLiteral('number')); | ||
} else if (iterator.nextNode === null && !iterator.feedback.fixed) { | ||
return builders.sequenceExpression([builders.assignmentExpression('=', builders.identifier('pos'), builders.conditionalExpression(builders.binaryExpression('<', scope['default'].depth, builders.numericLiteral(iterator.state.pos)), builders.numericLiteral(-1), scope['default'].depth)), builders.binaryExpression('===', builders.identifier('pos'), builders.numericLiteral(-1))]); | ||
return builders.sequenceExpression([builders.assignmentExpression('=', internalScope['default'].pos, builders.conditionalExpression(builders.binaryExpression('<', scope['default'].depth, builders.numericLiteral(iterator.state.pos)), builders.numericLiteral(-1), scope['default'].depth)), builders.binaryExpression('===', internalScope['default'].pos, builders.numericLiteral(-1))]); | ||
} else { | ||
@@ -110,5 +110,5 @@ return null; | ||
if (iterator.feedback.bailed || !deep || iterator.state.inverted) return node; | ||
const assignment = builders.sequenceExpression([builders.assignmentExpression('=', builders.identifier('pos'), builders.conditionalExpression(node, builders.numericLiteral(-1), scope['default'].depth)), builders.binaryExpression('===', pos, builders.numericLiteral(-1))]); | ||
const assignment = builders.sequenceExpression([builders.assignmentExpression('=', internalScope['default'].pos, builders.conditionalExpression(node, builders.numericLiteral(-1), scope['default'].depth)), builders.binaryExpression('===', internalScope['default'].pos, builders.numericLiteral(-1))]); | ||
if (iterator.state.pos === 0) return assignment; | ||
return builders.logicalExpression('||', builders.binaryExpression('<', scope['default'].depth, iterator.state.pos === 0 ? pos : builders.binaryExpression('+', pos, builders.numericLiteral(iterator.state.pos))), assignment); | ||
return builders.logicalExpression('||', builders.binaryExpression('<', scope['default'].depth, iterator.state.pos === 0 ? internalScope['default'].pos : builders.binaryExpression('+', internalScope['default'].pos, builders.numericLiteral(iterator.state.pos))), assignment); | ||
} | ||
@@ -115,0 +115,0 @@ function rewriteESTree(node, pos) { |
@@ -10,2 +10,4 @@ 'use strict'; | ||
var emitCall = require('../templates/emit-call.js'); | ||
var fnParams = require('../templates/fn-params.js'); | ||
var internalScope = require('../templates/internal-scope.js'); | ||
var scope = require('../templates/scope.js'); | ||
@@ -15,2 +17,3 @@ var tree = require('../tree/tree.js'); | ||
const POS_VARIABLE_DECLARATION = builders.variableDeclaration('let', [builders.variableDeclarator(internalScope['default'].pos, builders.numericLiteral(0))]); | ||
function baseline(jsonPaths, format) { | ||
@@ -23,6 +26,10 @@ const tree$1 = new tree['default']({ | ||
const _callbacks = builders.identifier('_callbacks'); | ||
traverse: for (const [id, nodes] of jsonPaths) { | ||
const iterator$1 = new iterator['default'](nodes); | ||
traverse: for (const [id, nodes] of jsonPaths) { | ||
const hash = JSON.stringify(nodes); | ||
if (iterator$1.length === -1) { | ||
continue; | ||
} | ||
const hash = JSON.stringify(iterator$1.nodes); | ||
const existingHash = hashes.get(hash); | ||
@@ -34,10 +41,18 @@ | ||
void (((_callbacks$get = callbacks.get(existingHash)) === null || _callbacks$get === void 0 ? void 0 : _callbacks$get.push(id)) ?? callbacks.set(existingHash, [id])); | ||
continue; | ||
} | ||
const method = tree$1.getMethodByHash(existingHash); | ||
hashes.set(hash, id); | ||
const iterator$1 = new iterator['default'](nodes); | ||
if (method === void 0) { | ||
break; | ||
} | ||
if (iterator$1.length === -1) { | ||
let body = method.body.body; | ||
if (iterator$1.feedback.bailed) { | ||
body = body[0].expression.arguments[1].body.body; | ||
} | ||
body.push(emitCall['default'](id, iterator$1.modifiers)); | ||
continue; | ||
} else { | ||
hashes.set(hash, id); | ||
} | ||
@@ -61,7 +76,8 @@ | ||
const branch = iterator$1.feedback.bailed ? [] : [builders.ifStatement(builders.binaryExpression(iterator$1.feedback.fixed ? '!==' : '<', scope['default'].depth, builders.numericLiteral(iterator$1.length - 1)), builders.returnStatement())].concat(iterator$1.feedback.fixed ? [] : builders.variableDeclaration('let', [builders.variableDeclarator(builders.identifier('pos'), builders.numericLiteral(0))])); | ||
const branch = iterator$1.feedback.bailed ? [] : [builders.ifStatement(builders.binaryExpression(iterator$1.feedback.fixed ? '!==' : '<', scope['default'].depth, builders.numericLiteral(iterator$1.length - 1)), builders.returnStatement())].concat(iterator$1.feedback.fixed ? [] : POS_VARIABLE_DECLARATION); | ||
const zone = iterator$1.feedback.bailed ? null : tree$1.traversalZones.create(); | ||
const inverseAt = iterator$1.feedback.inverseAt; | ||
for (const node of iterator$1) { | ||
if (guards.isDeep(node)) { | ||
if (guards.isDeep(node) || inverseAt === iterator$1.state.absolutePos) { | ||
zone === null || zone === void 0 ? void 0 : zone.allIn(); | ||
@@ -115,3 +131,3 @@ } | ||
if (!iterator$1.feedback.fixed && !iterator$1.feedback.bailed && !iterator$1.state.inverted) { | ||
branch.push(builders.ifStatement(builders.binaryExpression('!==', scope['default'].depth, iterator$1.state.pos === 0 ? builders.identifier('pos') : builders.binaryExpression('+', builders.identifier('pos'), builders.numericLiteral(iterator$1.state.pos))), builders.returnStatement())); | ||
branch.push(builders.ifStatement(builders.binaryExpression('!==', scope['default'].depth, iterator$1.state.pos === 0 ? internalScope['default'].pos : builders.binaryExpression('+', internalScope['default'].pos, builders.numericLiteral(iterator$1.state.pos))), builders.returnStatement())); | ||
} | ||
@@ -122,9 +138,9 @@ | ||
if (iterator$1.feedback.bailed) { | ||
branch.splice(0, branch.length, builders.expressionStatement(builders.callExpression(scope['default'].bail, [builders.stringLiteral(id), builders.arrowFunctionExpression([scope['default']._], emitCall['default'](iterator$1.modifiers).expression), builders.arrayExpression([...branch])]))); | ||
branch.splice(0, branch.length, builders.expressionStatement(builders.callExpression(scope['default'].bail, [builders.stringLiteral(id), builders.arrowFunctionExpression([scope['default']._], builders.blockStatement([builders.expressionStatement(emitCall['default'](ctx.id, iterator$1.modifiers).expression)])), builders.arrayExpression([...branch])]))); | ||
} else { | ||
branch.push(emitCall['default'](iterator$1.modifiers)); | ||
branch.push(emitCall['default'](ctx.id, iterator$1.modifiers)); | ||
} | ||
if (placement === 'body') { | ||
tree$1.push(builders.expressionStatement(builders.callExpression(builders.memberExpression(builders.identifier('_tree'), builders.stringLiteral(id), true), [scope['default']._, builders.memberExpression(_callbacks, builders.stringLiteral(id), true)])), placement); | ||
tree$1.push(builders.expressionStatement(builders.callExpression(builders.memberExpression(internalScope['default'].tree, builders.stringLiteral(id), true), fnParams['default'])), placement); | ||
} else { | ||
@@ -138,3 +154,2 @@ tree$1.push(builders.stringLiteral(id), placement); | ||
tree$1.push(builders.objectExpression(Array.from(callbacks.entries()).map(([key, values]) => builders.objectProperty(builders.stringLiteral(key), builders.arrayExpression(values.map(value => builders.stringLiteral(value)))))), 'callbacks'); | ||
return tree$1; | ||
@@ -141,0 +156,0 @@ } |
@@ -29,3 +29,2 @@ 'use strict'; | ||
const QUOTE = /"/g; | ||
const customGenerator = { ...astring__namespace.baseGenerator, | ||
@@ -72,3 +71,3 @@ | ||
StringLiteral(node, state) { | ||
state.write(`"${node.value.replace(QUOTE, '\\"')}"`, node); | ||
state.write(JSON.stringify(node.value), node); | ||
} | ||
@@ -75,0 +74,0 @@ |
@@ -7,4 +7,4 @@ 'use strict'; | ||
var guards = require('../guards.js'); | ||
var emitCall = require('../templates/emit-call.js'); | ||
var scope = require('../templates/scope.js'); | ||
var emitCall = require('../templates/emit-call.js'); | ||
@@ -17,3 +17,3 @@ // covers: | ||
tree.push(builders.blockStatement([builders.ifStatement(builders.binaryExpression('===', scope['default'].property, builders.stringLiteral(nodes[0].value)), builders.blockStatement([emitCall['default'](ctx.iterator.modifiers)]))]), 'tree-method'); | ||
tree.push(builders.blockStatement([builders.ifStatement(builders.binaryExpression('!==', scope['default'].property, builders.stringLiteral(nodes[0].value)), builders.returnStatement()), emitCall['default'](ctx.id, ctx.iterator.modifiers)]), 'tree-method'); | ||
tree.push(builders.stringLiteral(ctx.id), 'traverse'); | ||
@@ -20,0 +20,0 @@ return true; |
@@ -15,3 +15,3 @@ 'use strict'; | ||
tree.push(builders.blockStatement([emitCall['default'](ctx.iterator.modifiers)]), 'tree-method'); | ||
tree.push(builders.blockStatement([emitCall['default'](ctx.id, ctx.iterator.modifiers)]), 'tree-method'); | ||
tree.push(builders.stringLiteral(ctx.id), 'traverse'); | ||
@@ -18,0 +18,0 @@ return true; |
@@ -7,3 +7,3 @@ 'use strict'; | ||
var guards = require('../guards.js'); | ||
var fnParams = require('../templates/fn-params.js'); | ||
var emitCall = require('../templates/emit-call.js'); | ||
var sandbox = require('../templates/sandbox.js'); | ||
@@ -17,4 +17,4 @@ var scope = require('../templates/scope.js'); | ||
const GET_IDENTIFIER = builders.identifier('get'); | ||
const IS_OBJECT_CALL_EXPRESSION = builders.callExpression(IS_OBJECT_IDENTIFIER, [VALUE_IDENTIFIER]); | ||
const DUMP_SCOPE_OBJECT_EXPRESSION = builders.variableDeclaration('const', [builders.variableDeclarator(builders.identifier('emptyScope'), builders.objectExpression([builders.objectMethod('method', scope['default'].emit.property, [], builders.blockStatement([]))]))]); | ||
const IS_NOT_OBJECT_IF_STATEMENT = builders.ifStatement(builders.unaryExpression('!', builders.callExpression(IS_OBJECT_IDENTIFIER, [VALUE_IDENTIFIER])), builders.returnStatement()); | ||
const IS_NULL_SCOPE_IF_STATEMENT = builders.ifStatement(builders.binaryExpression('===', scope['default']._, builders.nullLiteral()), builders.returnStatement()); | ||
@@ -39,12 +39,8 @@ function toLiteral(node) { | ||
tree.addRuntimeDependency(IS_OBJECT_IDENTIFIER.name); | ||
const emitCall = builders.memberExpression(builders.callExpression(scope['default'].fork, [builders.arrayExpression(nodes.map(toLiteral))]), scope['default'].emit.property, false, true); | ||
if (tree.format === 'ES2018') { | ||
tree.addRuntimeDependency(GET_IDENTIFIER.name); | ||
tree.push(DUMP_SCOPE_OBJECT_EXPRESSION, 'program'); | ||
emitCall.optional = false; | ||
emitCall.object = builders.logicalExpression('||', emitCall.object, DUMP_SCOPE_OBJECT_EXPRESSION.declarations[0].id); | ||
} | ||
tree.pushAll([[builders.blockStatement([valueVariableDeclaration, builders.ifStatement(IS_OBJECT_CALL_EXPRESSION, builders.blockStatement([builders.expressionStatement(builders.callExpression(emitCall, [fnParams.fnIdentifier, builders.numericLiteral(ctx.iterator.modifiers.parents), builders.booleanLiteral(ctx.iterator.modifiers.keyed)]))]))]), 'tree-method'], [treeMethodCall['default'](ctx.id), 'body']]); | ||
tree.pushAll([[builders.blockStatement([valueVariableDeclaration, IS_NOT_OBJECT_IF_STATEMENT, builders.expressionStatement(builders.assignmentExpression('=', scope['default']._, builders.callExpression(scope['default'].fork, [builders.arrayExpression(nodes.map(toLiteral))]))), IS_NULL_SCOPE_IF_STATEMENT, emitCall['default'](ctx.id, ctx.iterator.modifiers)]), 'tree-method'], [treeMethodCall['default'](ctx.id), 'body']]); | ||
return true; | ||
@@ -51,0 +47,0 @@ }); |
@@ -5,2 +5,3 @@ 'use strict'; | ||
var allParents = require('./all-parents.js'); | ||
var deepSingleMember = require('./deep-single-member.js'); | ||
@@ -13,4 +14,4 @@ var deepWildcard = require('./deep-wildcard.js'); | ||
var fastPaths = [root['default'], onlyFilterScriptExpression['default'], deepSingleMember['default'], deepWildcard['default'], topLevelWildcard['default'], fixed['default']]; | ||
var fastPaths = [root['default'], onlyFilterScriptExpression['default'], deepSingleMember['default'], deepWildcard['default'], topLevelWildcard['default'], fixed['default'], allParents['default']]; | ||
exports['default'] = fastPaths; |
@@ -21,3 +21,3 @@ 'use strict'; | ||
const condition = builders.unaryExpression('!', generators.rewriteESTree(jsep['default'](nodes[0].value), 0), true); | ||
tree.pushAll([[builders.blockStatement([...(guards.isDeep(nodes[0]) ? [] : [TOP_LEVEL_DEPTH_IF_STATEMENT]), builders.ifStatement(condition, builders.returnStatement()), emitCall['default'](ctx.iterator.modifiers)]), 'tree-method'], [builders.stringLiteral(ctx.id), 'traverse']]); | ||
tree.pushAll([[builders.blockStatement([...(guards.isDeep(nodes[0]) ? [] : [TOP_LEVEL_DEPTH_IF_STATEMENT]), builders.ifStatement(condition, builders.returnStatement()), emitCall['default'](ctx.id, ctx.iterator.modifiers)]), 'tree-method'], [builders.stringLiteral(ctx.id), 'traverse']]); | ||
@@ -24,0 +24,0 @@ if (!guards.isDeep(nodes[0])) { |
@@ -5,11 +5,9 @@ 'use strict'; | ||
var builders = require('../ast/builders.js'); | ||
var emitCall$1 = require('../templates/emit-call.js'); | ||
var emitCall = require('../templates/emit-call.js'); | ||
// covers: $ | ||
const emitCall = emitCall$1['default']({ | ||
const EMIT_ROOT_CALL_EXPRESSION = emitCall['default']('$', { | ||
keyed: false, | ||
parents: 0 | ||
}); | ||
emitCall.expression.arguments[0] = builders.memberExpression(builders.identifier('_callbacks'), builders.identifier('$')); | ||
var root = ((nodes, tree) => { | ||
@@ -20,3 +18,3 @@ if (nodes.length > 0) { | ||
tree.push(emitCall, 'body'); | ||
tree.push(EMIT_ROOT_CALL_EXPRESSION, 'body'); | ||
return true; | ||
@@ -23,0 +21,0 @@ }); |
@@ -11,3 +11,3 @@ 'use strict'; | ||
// Covers: | ||
const BINARY_EXPRESSION = builders.binaryExpression('===', scope['default'].depth, builders.numericLiteral(0)); | ||
const IS_NOT_ZERO_DEPTH_IF_STATEMENT = builders.ifStatement(builders.binaryExpression('!==', scope['default'].depth, builders.numericLiteral(0)), builders.returnStatement()); | ||
var topLevelWildcard = ((nodes, tree, ctx) => { | ||
@@ -20,3 +20,3 @@ var _tree$traversalZones$; | ||
tree.push(builders.blockStatement([builders.ifStatement(BINARY_EXPRESSION, builders.blockStatement([emitCall['default'](ctx.iterator.modifiers)]))]), 'tree-method'); | ||
tree.push(builders.blockStatement([IS_NOT_ZERO_DEPTH_IF_STATEMENT, emitCall['default'](ctx.id, ctx.iterator.modifiers)]), 'tree-method'); | ||
tree.push(builders.stringLiteral(ctx.id), 'traverse'); | ||
@@ -23,0 +23,0 @@ (_tree$traversalZones$ = tree.traversalZones.create()) === null || _tree$traversalZones$ === void 0 ? void 0 : _tree$traversalZones$.resize().attach(); |
@@ -46,3 +46,3 @@ 'use strict'; | ||
class Iterator { | ||
#nodes; | ||
nodes; | ||
#i; | ||
@@ -52,6 +52,6 @@ | ||
this.modifiers = Iterator.trim(nodes); | ||
this.#nodes = Iterator.compact(nodes); | ||
this.nodes = Iterator.compact(nodes); | ||
this.#i = -1; | ||
this.feedback = Iterator.analyze(this.#nodes, this.modifiers.keyed || this.modifiers.parents > 0); | ||
this.length = this.#nodes.length; | ||
this.feedback = Iterator.analyze(this.nodes, this.modifiers.keyed || this.modifiers.parents > 0); | ||
this.length = this.nodes.length; | ||
this.state = { | ||
@@ -70,3 +70,3 @@ absolutePos: -1, | ||
get nextNode() { | ||
return this.#i + 1 < this.#nodes.length ? this.#nodes[this.#i + 1] : null; | ||
return this.#i + 1 < this.nodes.length ? this.nodes[this.#i + 1] : null; | ||
} | ||
@@ -159,3 +159,3 @@ | ||
if (this.feedback.bailed) { | ||
return yield* this.#nodes; | ||
return yield* this.nodes; | ||
} | ||
@@ -166,3 +166,3 @@ | ||
let order = 1; | ||
const nodes = this.feedback.inverseAt !== -1 ? this.#nodes.slice() : this.#nodes; | ||
const nodes = this.feedback.inverseAt !== -1 ? this.nodes.slice() : this.nodes; | ||
@@ -169,0 +169,0 @@ for (let i = 0; i < nodes.length; i++) { |
@@ -6,6 +6,5 @@ 'use strict'; | ||
var builders = require('../ast/builders.js'); | ||
var fnParams = require('./fn-params.js'); | ||
var scope = require('./scope.js'); | ||
function generateEmitCall({ | ||
function generateEmitCall(id, { | ||
parents, | ||
@@ -16,5 +15,5 @@ keyed | ||
// todo: add check | ||
return builders.expressionStatement(builders.callExpression(scope['default'].emit, [fnParams.fnIdentifier, builders.numericLiteral(parents), builders.booleanLiteral(keyed)])); | ||
return builders.expressionStatement(builders.callExpression(scope['default'].emit, [builders.stringLiteral(id), builders.numericLiteral(parents), builders.booleanLiteral(keyed)])); | ||
} | ||
exports['default'] = generateEmitCall; |
@@ -5,10 +5,6 @@ 'use strict'; | ||
var builders = require('../ast/builders.js'); | ||
var scope = require('./scope.js'); | ||
const fnIdentifier = builders.identifier('fn'); // scope, fn | ||
var fnParams = [scope['default']._]; | ||
var fnParams = [scope['default']._, fnIdentifier]; | ||
exports['default'] = fnParams; | ||
exports.fnIdentifier = fnIdentifier; |
@@ -11,2 +11,3 @@ 'use strict'; | ||
bail: builders.memberExpression(SCOPE_IDENTIFIER, builders.identifier('bail')), | ||
callbacks: builders.memberExpression(SCOPE_IDENTIFIER, builders.identifier('callbacks')), | ||
depth: builders.memberExpression(SCOPE_IDENTIFIER, builders.identifier('depth')), | ||
@@ -18,4 +19,2 @@ destroy: builders.memberExpression(SCOPE_IDENTIFIER, builders.identifier('destroy')), | ||
property: builders.memberExpression(SCOPE_IDENTIFIER, builders.identifier('property')), | ||
proxyCallbacks: builders.memberExpression(SCOPE_IDENTIFIER, builders.identifier('proxyCallbacks')), | ||
registerTree: builders.memberExpression(SCOPE_IDENTIFIER, builders.identifier('registerTree')), | ||
sandbox: builders.memberExpression(SCOPE_IDENTIFIER, builders.identifier('sandbox')), | ||
@@ -22,0 +21,0 @@ traverse: builders.memberExpression(SCOPE_IDENTIFIER, builders.identifier('traverse')), |
@@ -6,9 +6,10 @@ 'use strict'; | ||
var builders = require('../ast/builders.js'); | ||
var scope = require('./scope.js'); | ||
var fnParams = require('./fn-params.js'); | ||
var internalScope = require('./internal-scope.js'); | ||
function treeMethodCall(id) { | ||
const property = builders.stringLiteral(id); | ||
return builders.expressionStatement(builders.callExpression(builders.memberExpression(builders.identifier('_tree'), property, true), [scope['default']._, builders.memberExpression(builders.identifier('_callbacks'), property, true)])); | ||
return builders.expressionStatement(builders.callExpression(builders.memberExpression(internalScope['default'].tree, property, true), fnParams['default'])); | ||
} | ||
exports['default'] = treeMethodCall; |
@@ -6,3 +6,3 @@ 'use strict'; | ||
var builders = require('../ast/builders.js'); | ||
var toObjectLiteral = require('../templates/to-object-literal.js'); | ||
var buildJson = require('../templates/build-json.js'); | ||
@@ -19,3 +19,3 @@ class TraversalZones { | ||
const zonesIdentifier = builders.identifier('zones'); | ||
return builders.variableDeclaration('const', [builders.variableDeclarator(zonesIdentifier, toObjectLiteral['default'](mergeZones(this.#zones)))]); | ||
return builders.variableDeclaration('const', [builders.variableDeclarator(zonesIdentifier, buildJson['default'](mergeZones(this.#zones)))]); | ||
} | ||
@@ -43,3 +43,4 @@ | ||
#zones; | ||
#localZones = []; | ||
#localZones; | ||
#relationships; | ||
@@ -50,2 +51,3 @@ constructor(zones) { | ||
this.#localZones = [this.root]; | ||
this.#relationships = new Map(); | ||
} | ||
@@ -55,2 +57,3 @@ | ||
this.#zones.attach(this.root); | ||
this.#relationships.clear(); | ||
} | ||
@@ -63,3 +66,18 @@ | ||
if (value === null) continue; | ||
value[property] = property === '**' ? null : {}; | ||
if (property === '**') { | ||
const parent = this.#relationships.get(value); | ||
if ('*' in parent) { | ||
delete parent['*']; | ||
parent['**'] = null; | ||
continue; | ||
} | ||
value[property] = null; | ||
} else { | ||
value[property] = {}; | ||
this.#relationships.set(value[property], value); | ||
} | ||
this.#localZones[i++] = value[property]; | ||
@@ -66,0 +84,0 @@ } |
@@ -8,2 +8,3 @@ 'use strict'; | ||
var fnParams = require('../templates/fn-params.js'); | ||
var internalScope = require('../templates/internal-scope.js'); | ||
var scope = require('../templates/scope.js'); | ||
@@ -14,3 +15,3 @@ var treeMethodCall = require('../templates/tree-method-call.js'); | ||
const params = [builders.identifier('input'), builders.identifier('callbacks')]; | ||
const NEW_SCOPE_VARIABLE_DECLARATION = builders.variableDeclaration('const', [builders.variableDeclarator(scope['default']._, builders.newExpression(builders.identifier('Scope'), [params[0]]))]); | ||
const NEW_SCOPE_VARIABLE_DECLARATION = builders.variableDeclaration('const', [builders.variableDeclarator(scope['default']._, builders.newExpression(builders.identifier('Scope'), params))]); | ||
/* | ||
@@ -26,3 +27,3 @@ import { | ||
export default function (input, callbacks) { | ||
const scope = new Scope(input); | ||
const scope = new Scope(input, callbacks); | ||
@@ -47,3 +48,2 @@ try { | ||
#traverse = new Set(); | ||
#callbacks = null; | ||
@@ -64,2 +64,6 @@ constructor({ | ||
getMethodByHash(hash) { | ||
return this.#tree.properties.find(prop => prop.key.value === hash); | ||
} | ||
push(node, placement) { | ||
@@ -71,6 +75,2 @@ switch (placement) { | ||
case 'tree-property': | ||
this.#tree.properties.push(builders.objectProperty(builders.stringLiteral(this.ctx.id), node)); | ||
break; | ||
case 'program': | ||
@@ -90,6 +90,2 @@ if (!this.#program.has(node)) { | ||
case 'callbacks': | ||
this.#callbacks = node; | ||
break; | ||
case 'traverse': | ||
@@ -108,5 +104,4 @@ this.#traverse.add(treeMethodCall['default'](node.value)); | ||
toString() { | ||
const proxyTree = builders.variableDeclaration('const', [builders.variableDeclarator(builders.identifier('_tree'), builders.callExpression(scope['default'].registerTree, [builders.identifier('tree')]))]); | ||
const traversalZones = this.traversalZones.root; | ||
return dump['default'](builders.program([builders.importDeclaration([...this.#runtimeDependencies].map(dep => builders.importSpecifier(builders.identifier(dep), builders.identifier(dep))), builders.stringLiteral('nimma/runtime')), ...this.#program, traversalZones, this.#tree.properties.length === 0 ? null : builders.variableDeclaration('const', [builders.variableDeclarator(builders.identifier('tree'), this.#tree)]), builders.exportDefaultDeclaration(builders.functionDeclaration(null, params, builders.blockStatement([NEW_SCOPE_VARIABLE_DECLARATION, this.#tree.properties.length === 0 ? null : proxyTree, builders.variableDeclaration('const', [builders.variableDeclarator(builders.identifier('_callbacks'), builders.callExpression(scope['default'].proxyCallbacks, [builders.identifier('callbacks'), this.#callbacks ?? builders.objectExpression([])]))]), builders.tryStatement(builders.blockStatement([...this.#body, this.#traverse.size === 0 ? null : builders.expressionStatement(builders.callExpression(scope['default'].traverse, [builders.arrowFunctionExpression([], builders.blockStatement(Array.from(this.#traverse))), traversalZones === null ? builders.nullLiteral() : traversalZones.declarations[0].id]))].filter(Boolean)), null, builders.blockStatement([builders.expressionStatement(builders.callExpression(scope['default'].destroy, []))]))].filter(Boolean))))].filter(Boolean))); | ||
return dump['default'](builders.program([builders.importDeclaration([...this.#runtimeDependencies].map(dep => builders.importSpecifier(builders.identifier(dep), builders.identifier(dep))), builders.stringLiteral('nimma/runtime')), ...this.#program, traversalZones, this.#tree.properties.length === 0 ? null : builders.variableDeclaration('const', [builders.variableDeclarator(internalScope['default'].tree, this.#tree)]), builders.exportDefaultDeclaration(builders.functionDeclaration(null, params, builders.blockStatement([NEW_SCOPE_VARIABLE_DECLARATION, builders.tryStatement(builders.blockStatement([...this.#body, this.#traverse.size === 0 ? null : builders.expressionStatement(builders.callExpression(scope['default'].traverse, [builders.arrowFunctionExpression([], builders.blockStatement(Array.from(this.#traverse))), traversalZones === null ? builders.nullLiteral() : traversalZones.declarations[0].id]))].filter(Boolean)), null, builders.blockStatement([builders.expressionStatement(builders.callExpression(scope['default'].destroy, []))]))].filter(Boolean))))].filter(Boolean))); | ||
} | ||
@@ -113,0 +108,0 @@ |
@@ -8,2 +8,3 @@ 'use strict'; | ||
var iterator = require('../codegen/iterator.js'); | ||
var scope = require('../codegen/templates/scope.js'); | ||
var parser = require('../parser/parser.js'); | ||
@@ -60,3 +61,3 @@ var index$1 = require('../runtime/index.js'); | ||
const fb = fallback.attach(tree); | ||
tree.push(builders.forOfStatement(builders.variableDeclaration('const', [builders.variableDeclarator(path)]), builders.arrayExpression(erroredExpressions.map(expression => builders.stringLiteral(expression))), builders.blockStatement([builders.callExpression(fb, [builders.identifier('input'), path, builders.memberExpression(builders.identifier('_callbacks'), path, true)])])), 'body'); | ||
tree.push(builders.forOfStatement(builders.variableDeclaration('const', [builders.variableDeclarator(path)]), builders.arrayExpression(erroredExpressions.map(expression => builders.stringLiteral(expression))), builders.blockStatement([builders.callExpression(fb, [builders.identifier('input'), path, builders.memberExpression(scope['default'].callbacks, path, true)])])), 'body'); | ||
} | ||
@@ -63,0 +64,0 @@ |
@@ -139,3 +139,3 @@ 'use strict'; | ||
peg$c1 = function (nodes, modifiers) { | ||
return [...nodes].concat(Array.isArray(modifiers) ? modifiers : modifiers === null ? [] : modifiers); | ||
return nodes.concat(Array.isArray(modifiers) ? modifiers : modifiers === null ? [] : modifiers); | ||
}, | ||
@@ -167,4 +167,14 @@ peg$c2 = "$", | ||
}, | ||
peg$c14 = function (value) { | ||
peg$c14 = function () { | ||
return /^\$\.{2}[~^]*$/.test(input); | ||
}, | ||
peg$c15 = "..", | ||
peg$c16 = peg$literalExpectation("..", false), | ||
peg$c17 = function () { | ||
return { | ||
type: 'AllParentExpression' | ||
}; | ||
}, | ||
peg$c18 = function (value) { | ||
return { | ||
type: "MemberExpression", | ||
@@ -174,9 +184,9 @@ value | ||
}, | ||
peg$c15 = "(", | ||
peg$c16 = peg$literalExpectation("(", false), | ||
peg$c17 = ")", | ||
peg$c18 = peg$literalExpectation(")", false), | ||
peg$c19 = "?(", | ||
peg$c20 = peg$literalExpectation("?(", false), | ||
peg$c21 = function (value) { | ||
peg$c19 = "(", | ||
peg$c20 = peg$literalExpectation("(", false), | ||
peg$c21 = ")", | ||
peg$c22 = peg$literalExpectation(")", false), | ||
peg$c23 = "?(", | ||
peg$c24 = peg$literalExpectation("?(", false), | ||
peg$c25 = function (value) { | ||
return { | ||
@@ -187,5 +197,5 @@ type: "ScriptFilterExpression", | ||
}, | ||
peg$c22 = ":", | ||
peg$c23 = peg$literalExpectation(":", false), | ||
peg$c24 = function (value) { | ||
peg$c26 = ":", | ||
peg$c27 = peg$literalExpectation(":", false), | ||
peg$c28 = function (value) { | ||
return { | ||
@@ -199,9 +209,9 @@ type: "SliceExpression", | ||
}, | ||
peg$c25 = "@", | ||
peg$c26 = peg$literalExpectation("@", false), | ||
peg$c27 = /^[a-z]/, | ||
peg$c28 = peg$classExpectation([["a", "z"]], false, false), | ||
peg$c29 = "()", | ||
peg$c30 = peg$literalExpectation("()", false), | ||
peg$c31 = function (value) { | ||
peg$c29 = "@", | ||
peg$c30 = peg$literalExpectation("@", false), | ||
peg$c31 = /^[a-z]/, | ||
peg$c32 = peg$classExpectation([["a", "z"]], false, false), | ||
peg$c33 = "()", | ||
peg$c34 = peg$literalExpectation("()", false), | ||
peg$c35 = function (value) { | ||
return { | ||
@@ -212,5 +222,5 @@ type: 'ScriptFilterExpression', | ||
}, | ||
peg$c32 = "~", | ||
peg$c33 = peg$literalExpectation("~", false), | ||
peg$c34 = function () { | ||
peg$c36 = "~", | ||
peg$c37 = peg$literalExpectation("~", false), | ||
peg$c38 = function () { | ||
return { | ||
@@ -220,5 +230,5 @@ type: "KeyExpression" | ||
}, | ||
peg$c35 = "^", | ||
peg$c36 = peg$literalExpectation("^", false), | ||
peg$c37 = function () { | ||
peg$c39 = "^", | ||
peg$c40 = peg$literalExpectation("^", false), | ||
peg$c41 = function () { | ||
return { | ||
@@ -228,39 +238,39 @@ type: "ParentExpression" | ||
}, | ||
peg$c38 = /^[.]/, | ||
peg$c39 = peg$classExpectation(["."], false, false), | ||
peg$c40 = /^[$_\-]/, | ||
peg$c41 = peg$classExpectation(["$", "_", "-"], false, false), | ||
peg$c42 = "\"", | ||
peg$c43 = peg$literalExpectation("\"", false), | ||
peg$c44 = /^[^"]/, | ||
peg$c45 = peg$classExpectation(["\""], true, false), | ||
peg$c46 = "'", | ||
peg$c47 = peg$literalExpectation("'", false), | ||
peg$c48 = /^[^']/, | ||
peg$c49 = peg$classExpectation(["'"], true, false), | ||
peg$c50 = function () { | ||
peg$c42 = /^[.]/, | ||
peg$c43 = peg$classExpectation(["."], false, false), | ||
peg$c44 = /^[$_\-]/, | ||
peg$c45 = peg$classExpectation(["$", "_", "-"], false, false), | ||
peg$c46 = "\"", | ||
peg$c47 = peg$literalExpectation("\"", false), | ||
peg$c48 = /^[^"]/, | ||
peg$c49 = peg$classExpectation(["\""], true, false), | ||
peg$c50 = "'", | ||
peg$c51 = peg$literalExpectation("'", false), | ||
peg$c52 = /^[^']/, | ||
peg$c53 = peg$classExpectation(["'"], true, false), | ||
peg$c54 = function () { | ||
return text().slice(1, -1); | ||
}, | ||
peg$c51 = "-", | ||
peg$c52 = peg$literalExpectation("-", false), | ||
peg$c53 = function () { | ||
peg$c55 = "-", | ||
peg$c56 = peg$literalExpectation("-", false), | ||
peg$c57 = function () { | ||
return Number(text()); | ||
}, | ||
peg$c54 = "*", | ||
peg$c55 = peg$literalExpectation("*", false), | ||
peg$c56 = /^[A-Za-z]/, | ||
peg$c57 = peg$classExpectation([["A", "Z"], ["a", "z"]], false, false), | ||
peg$c58 = /^[0-9]/, | ||
peg$c59 = peg$classExpectation([["0", "9"]], false, false), | ||
peg$c60 = /^[ \t]/, | ||
peg$c61 = peg$classExpectation([" ", "\t"], false, false), | ||
peg$c62 = /^["]/, | ||
peg$c63 = peg$classExpectation(["\""], false, false), | ||
peg$c64 = /^[']/, | ||
peg$c65 = peg$classExpectation(["'"], false, false), | ||
peg$c66 = /^[ $@.,_=<>!|&+~%\^*\/;\-[\]]/, | ||
peg$c67 = peg$classExpectation([" ", "$", "@", ".", ",", "_", "=", "<", ">", "!", "|", "&", "+", "~", "%", "^", "*", "/", ";", "-", "[", "]"], false, false), | ||
peg$c68 = ".length", | ||
peg$c69 = peg$literalExpectation(".length", false), | ||
peg$c70 = function (value) { | ||
peg$c58 = "*", | ||
peg$c59 = peg$literalExpectation("*", false), | ||
peg$c60 = /^[A-Za-z]/, | ||
peg$c61 = peg$classExpectation([["A", "Z"], ["a", "z"]], false, false), | ||
peg$c62 = /^[0-9]/, | ||
peg$c63 = peg$classExpectation([["0", "9"]], false, false), | ||
peg$c64 = /^[ \t]/, | ||
peg$c65 = peg$classExpectation([" ", "\t"], false, false), | ||
peg$c66 = /^["]/, | ||
peg$c67 = peg$classExpectation(["\""], false, false), | ||
peg$c68 = /^[']/, | ||
peg$c69 = peg$classExpectation(["'"], false, false), | ||
peg$c70 = /^[ $@.,_=<>!|&+~%\^*\/;\-[\]]/, | ||
peg$c71 = peg$classExpectation([" ", "$", "@", ".", ",", "_", "=", "<", ">", "!", "|", "&", "+", "~", "%", "^", "*", "/", ";", "-", "[", "]"], false, false), | ||
peg$c72 = ".length", | ||
peg$c73 = peg$literalExpectation(".length", false), | ||
peg$c74 = function (value) { | ||
return { | ||
@@ -392,27 +402,5 @@ type: "SliceExpression", | ||
s2 = []; | ||
s3 = peg$currPos; | ||
s4 = peg$parseDescendant(); | ||
s3 = peg$parseAllParentExpression(); | ||
if (s4 === peg$FAILED) { | ||
s4 = null; | ||
} | ||
if (s4 !== peg$FAILED) { | ||
s5 = peg$parseNode(); | ||
if (s5 !== peg$FAILED) { | ||
peg$savedPos = s3; | ||
s4 = peg$c0(s4, s5); | ||
s3 = s4; | ||
} else { | ||
peg$currPos = s3; | ||
s3 = peg$FAILED; | ||
} | ||
} else { | ||
peg$currPos = s3; | ||
s3 = peg$FAILED; | ||
} | ||
while (s3 !== peg$FAILED) { | ||
s2.push(s3); | ||
if (s3 === peg$FAILED) { | ||
s3 = peg$currPos; | ||
@@ -442,2 +430,32 @@ s4 = peg$parseDescendant(); | ||
while (s3 !== peg$FAILED) { | ||
s2.push(s3); | ||
s3 = peg$parseAllParentExpression(); | ||
if (s3 === peg$FAILED) { | ||
s3 = peg$currPos; | ||
s4 = peg$parseDescendant(); | ||
if (s4 === peg$FAILED) { | ||
s4 = null; | ||
} | ||
if (s4 !== peg$FAILED) { | ||
s5 = peg$parseNode(); | ||
if (s5 !== peg$FAILED) { | ||
peg$savedPos = s3; | ||
s4 = peg$c0(s4, s5); | ||
s3 = s4; | ||
} else { | ||
peg$currPos = s3; | ||
s3 = peg$FAILED; | ||
} | ||
} else { | ||
peg$currPos = s3; | ||
s3 = peg$FAILED; | ||
} | ||
} | ||
} | ||
if (s2 !== peg$FAILED) { | ||
@@ -828,2 +846,42 @@ s3 = []; | ||
function peg$parseAllParentExpression() { | ||
var s0, s1, s2; | ||
s0 = peg$currPos; | ||
peg$savedPos = peg$currPos; | ||
s1 = peg$c14(); | ||
if (s1) { | ||
s1 = void 0; | ||
} else { | ||
s1 = peg$FAILED; | ||
} | ||
if (s1 !== peg$FAILED) { | ||
if (input.substr(peg$currPos, 2) === peg$c15) { | ||
s2 = peg$c15; | ||
peg$currPos += 2; | ||
} else { | ||
s2 = peg$FAILED; | ||
{ | ||
peg$fail(peg$c16); | ||
} | ||
} | ||
if (s2 !== peg$FAILED) { | ||
peg$savedPos = s0; | ||
s1 = peg$c17(); | ||
s0 = s1; | ||
} else { | ||
peg$currPos = s0; | ||
s0 = peg$FAILED; | ||
} | ||
} else { | ||
peg$currPos = s0; | ||
s0 = peg$FAILED; | ||
} | ||
return s0; | ||
} | ||
function peg$parseMemberExpression() { | ||
@@ -883,3 +941,3 @@ var s0, s1, s2, s3, s4; | ||
peg$savedPos = s0; | ||
s1 = peg$c14(s1); | ||
s1 = peg$c18(s1); | ||
} | ||
@@ -896,3 +954,3 @@ | ||
if (input.charCodeAt(peg$currPos) === 40) { | ||
s1 = peg$c15; | ||
s1 = peg$c19; | ||
peg$currPos++; | ||
@@ -903,3 +961,3 @@ } else { | ||
{ | ||
peg$fail(peg$c16); | ||
peg$fail(peg$c20); | ||
} | ||
@@ -913,3 +971,3 @@ } | ||
if (input.charCodeAt(peg$currPos) === 41) { | ||
s3 = peg$c17; | ||
s3 = peg$c21; | ||
peg$currPos++; | ||
@@ -920,3 +978,3 @@ } else { | ||
{ | ||
peg$fail(peg$c18); | ||
peg$fail(peg$c22); | ||
} | ||
@@ -949,4 +1007,4 @@ } | ||
if (input.substr(peg$currPos, 2) === peg$c19) { | ||
s1 = peg$c19; | ||
if (input.substr(peg$currPos, 2) === peg$c23) { | ||
s1 = peg$c23; | ||
peg$currPos += 2; | ||
@@ -957,3 +1015,3 @@ } else { | ||
{ | ||
peg$fail(peg$c20); | ||
peg$fail(peg$c24); | ||
} | ||
@@ -967,3 +1025,3 @@ } | ||
if (input.charCodeAt(peg$currPos) === 41) { | ||
s3 = peg$c17; | ||
s3 = peg$c21; | ||
peg$currPos++; | ||
@@ -974,3 +1032,3 @@ } else { | ||
{ | ||
peg$fail(peg$c18); | ||
peg$fail(peg$c22); | ||
} | ||
@@ -981,3 +1039,3 @@ } | ||
peg$savedPos = s0; | ||
s1 = peg$c21(s2); | ||
s1 = peg$c25(s2); | ||
s0 = s1; | ||
@@ -1010,3 +1068,3 @@ } else { | ||
if (input.charCodeAt(peg$currPos) === 58) { | ||
s5 = peg$c22; | ||
s5 = peg$c26; | ||
peg$currPos++; | ||
@@ -1017,3 +1075,3 @@ } else { | ||
{ | ||
peg$fail(peg$c23); | ||
peg$fail(peg$c27); | ||
} | ||
@@ -1049,3 +1107,3 @@ } | ||
if (input.charCodeAt(peg$currPos) === 58) { | ||
s4 = peg$c22; | ||
s4 = peg$c26; | ||
peg$currPos++; | ||
@@ -1056,3 +1114,3 @@ } else { | ||
{ | ||
peg$fail(peg$c23); | ||
peg$fail(peg$c27); | ||
} | ||
@@ -1089,3 +1147,3 @@ } | ||
if (input.charCodeAt(peg$currPos) === 58) { | ||
s5 = peg$c22; | ||
s5 = peg$c26; | ||
peg$currPos++; | ||
@@ -1096,3 +1154,3 @@ } else { | ||
{ | ||
peg$fail(peg$c23); | ||
peg$fail(peg$c27); | ||
} | ||
@@ -1140,3 +1198,3 @@ } | ||
peg$savedPos = s0; | ||
s1 = peg$c24(s1); | ||
s1 = peg$c28(s1); | ||
} | ||
@@ -1155,3 +1213,3 @@ | ||
if (input.charCodeAt(peg$currPos) === 64) { | ||
s3 = peg$c25; | ||
s3 = peg$c29; | ||
peg$currPos++; | ||
@@ -1162,3 +1220,3 @@ } else { | ||
{ | ||
peg$fail(peg$c26); | ||
peg$fail(peg$c30); | ||
} | ||
@@ -1170,3 +1228,3 @@ } | ||
if (peg$c27.test(input.charAt(peg$currPos))) { | ||
if (peg$c31.test(input.charAt(peg$currPos))) { | ||
s5 = input.charAt(peg$currPos); | ||
@@ -1178,3 +1236,3 @@ peg$currPos++; | ||
{ | ||
peg$fail(peg$c28); | ||
peg$fail(peg$c32); | ||
} | ||
@@ -1187,3 +1245,3 @@ } | ||
if (peg$c27.test(input.charAt(peg$currPos))) { | ||
if (peg$c31.test(input.charAt(peg$currPos))) { | ||
s5 = input.charAt(peg$currPos); | ||
@@ -1195,3 +1253,3 @@ peg$currPos++; | ||
{ | ||
peg$fail(peg$c28); | ||
peg$fail(peg$c32); | ||
} | ||
@@ -1205,4 +1263,4 @@ } | ||
if (s4 !== peg$FAILED) { | ||
if (input.substr(peg$currPos, 2) === peg$c29) { | ||
s5 = peg$c29; | ||
if (input.substr(peg$currPos, 2) === peg$c33) { | ||
s5 = peg$c33; | ||
peg$currPos += 2; | ||
@@ -1213,3 +1271,3 @@ } else { | ||
{ | ||
peg$fail(peg$c30); | ||
peg$fail(peg$c34); | ||
} | ||
@@ -1242,3 +1300,3 @@ } | ||
peg$savedPos = s0; | ||
s1 = peg$c31(s1); | ||
s1 = peg$c35(s1); | ||
} | ||
@@ -1255,3 +1313,3 @@ | ||
if (input.charCodeAt(peg$currPos) === 126) { | ||
s1 = peg$c32; | ||
s1 = peg$c36; | ||
peg$currPos++; | ||
@@ -1262,3 +1320,3 @@ } else { | ||
{ | ||
peg$fail(peg$c33); | ||
peg$fail(peg$c37); | ||
} | ||
@@ -1269,3 +1327,3 @@ } | ||
peg$savedPos = s0; | ||
s1 = peg$c34(); | ||
s1 = peg$c38(); | ||
} | ||
@@ -1282,3 +1340,3 @@ | ||
if (input.charCodeAt(peg$currPos) === 94) { | ||
s1 = peg$c35; | ||
s1 = peg$c39; | ||
peg$currPos++; | ||
@@ -1289,3 +1347,3 @@ } else { | ||
{ | ||
peg$fail(peg$c36); | ||
peg$fail(peg$c40); | ||
} | ||
@@ -1296,3 +1354,3 @@ } | ||
peg$savedPos = s0; | ||
s1 = peg$c37(); | ||
s1 = peg$c41(); | ||
} | ||
@@ -1319,3 +1377,3 @@ | ||
if (peg$c38.test(input.charAt(peg$currPos))) { | ||
if (peg$c42.test(input.charAt(peg$currPos))) { | ||
s1 = input.charAt(peg$currPos); | ||
@@ -1327,3 +1385,3 @@ peg$currPos++; | ||
{ | ||
peg$fail(peg$c39); | ||
peg$fail(peg$c43); | ||
} | ||
@@ -1333,3 +1391,3 @@ } | ||
if (s1 !== peg$FAILED) { | ||
if (peg$c38.test(input.charAt(peg$currPos))) { | ||
if (peg$c42.test(input.charAt(peg$currPos))) { | ||
s2 = input.charAt(peg$currPos); | ||
@@ -1341,3 +1399,3 @@ peg$currPos++; | ||
{ | ||
peg$fail(peg$c39); | ||
peg$fail(peg$c43); | ||
} | ||
@@ -1370,3 +1428,3 @@ } | ||
if (peg$c40.test(input.charAt(peg$currPos))) { | ||
if (peg$c44.test(input.charAt(peg$currPos))) { | ||
s2 = input.charAt(peg$currPos); | ||
@@ -1378,3 +1436,3 @@ peg$currPos++; | ||
{ | ||
peg$fail(peg$c41); | ||
peg$fail(peg$c45); | ||
} | ||
@@ -1395,3 +1453,3 @@ } | ||
if (peg$c40.test(input.charAt(peg$currPos))) { | ||
if (peg$c44.test(input.charAt(peg$currPos))) { | ||
s2 = input.charAt(peg$currPos); | ||
@@ -1403,3 +1461,3 @@ peg$currPos++; | ||
{ | ||
peg$fail(peg$c41); | ||
peg$fail(peg$c45); | ||
} | ||
@@ -1441,3 +1499,3 @@ } | ||
if (input.charCodeAt(peg$currPos) === 34) { | ||
s2 = peg$c42; | ||
s2 = peg$c46; | ||
peg$currPos++; | ||
@@ -1448,3 +1506,3 @@ } else { | ||
{ | ||
peg$fail(peg$c43); | ||
peg$fail(peg$c47); | ||
} | ||
@@ -1457,3 +1515,3 @@ } | ||
if (peg$c44.test(input.charAt(peg$currPos))) { | ||
if (peg$c48.test(input.charAt(peg$currPos))) { | ||
s5 = input.charAt(peg$currPos); | ||
@@ -1465,3 +1523,3 @@ peg$currPos++; | ||
{ | ||
peg$fail(peg$c45); | ||
peg$fail(peg$c49); | ||
} | ||
@@ -1473,3 +1531,3 @@ } | ||
if (peg$c44.test(input.charAt(peg$currPos))) { | ||
if (peg$c48.test(input.charAt(peg$currPos))) { | ||
s5 = input.charAt(peg$currPos); | ||
@@ -1481,3 +1539,3 @@ peg$currPos++; | ||
{ | ||
peg$fail(peg$c45); | ||
peg$fail(peg$c49); | ||
} | ||
@@ -1495,3 +1553,3 @@ } | ||
if (input.charCodeAt(peg$currPos) === 34) { | ||
s4 = peg$c42; | ||
s4 = peg$c46; | ||
peg$currPos++; | ||
@@ -1502,3 +1560,3 @@ } else { | ||
{ | ||
peg$fail(peg$c43); | ||
peg$fail(peg$c47); | ||
} | ||
@@ -1527,3 +1585,3 @@ } | ||
if (input.charCodeAt(peg$currPos) === 39) { | ||
s2 = peg$c46; | ||
s2 = peg$c50; | ||
peg$currPos++; | ||
@@ -1534,3 +1592,3 @@ } else { | ||
{ | ||
peg$fail(peg$c47); | ||
peg$fail(peg$c51); | ||
} | ||
@@ -1543,3 +1601,3 @@ } | ||
if (peg$c48.test(input.charAt(peg$currPos))) { | ||
if (peg$c52.test(input.charAt(peg$currPos))) { | ||
s5 = input.charAt(peg$currPos); | ||
@@ -1551,3 +1609,3 @@ peg$currPos++; | ||
{ | ||
peg$fail(peg$c49); | ||
peg$fail(peg$c53); | ||
} | ||
@@ -1559,3 +1617,3 @@ } | ||
if (peg$c48.test(input.charAt(peg$currPos))) { | ||
if (peg$c52.test(input.charAt(peg$currPos))) { | ||
s5 = input.charAt(peg$currPos); | ||
@@ -1567,3 +1625,3 @@ peg$currPos++; | ||
{ | ||
peg$fail(peg$c49); | ||
peg$fail(peg$c53); | ||
} | ||
@@ -1581,3 +1639,3 @@ } | ||
if (input.charCodeAt(peg$currPos) === 39) { | ||
s4 = peg$c46; | ||
s4 = peg$c50; | ||
peg$currPos++; | ||
@@ -1588,3 +1646,3 @@ } else { | ||
{ | ||
peg$fail(peg$c47); | ||
peg$fail(peg$c51); | ||
} | ||
@@ -1612,3 +1670,3 @@ } | ||
peg$savedPos = s0; | ||
s1 = peg$c50(); | ||
s1 = peg$c54(); | ||
} | ||
@@ -1628,3 +1686,3 @@ | ||
if (input.charCodeAt(peg$currPos) === 45) { | ||
s1 = peg$c51; | ||
s1 = peg$c55; | ||
peg$currPos++; | ||
@@ -1635,3 +1693,3 @@ } else { | ||
{ | ||
peg$fail(peg$c52); | ||
peg$fail(peg$c56); | ||
} | ||
@@ -1659,3 +1717,3 @@ } | ||
peg$savedPos = s0; | ||
s1 = peg$c53(); | ||
s1 = peg$c57(); | ||
s0 = s1; | ||
@@ -1678,3 +1736,3 @@ } else { | ||
if (input.charCodeAt(peg$currPos) === 42) { | ||
s0 = peg$c54; | ||
s0 = peg$c58; | ||
peg$currPos++; | ||
@@ -1685,3 +1743,3 @@ } else { | ||
{ | ||
peg$fail(peg$c55); | ||
peg$fail(peg$c59); | ||
} | ||
@@ -1696,3 +1754,3 @@ } | ||
if (peg$c56.test(input.charAt(peg$currPos))) { | ||
if (peg$c60.test(input.charAt(peg$currPos))) { | ||
s0 = input.charAt(peg$currPos); | ||
@@ -1704,3 +1762,3 @@ peg$currPos++; | ||
{ | ||
peg$fail(peg$c57); | ||
peg$fail(peg$c61); | ||
} | ||
@@ -1715,3 +1773,3 @@ } | ||
if (peg$c58.test(input.charAt(peg$currPos))) { | ||
if (peg$c62.test(input.charAt(peg$currPos))) { | ||
s0 = input.charAt(peg$currPos); | ||
@@ -1723,3 +1781,3 @@ peg$currPos++; | ||
{ | ||
peg$fail(peg$c59); | ||
peg$fail(peg$c63); | ||
} | ||
@@ -1734,3 +1792,3 @@ } | ||
if (peg$c60.test(input.charAt(peg$currPos))) { | ||
if (peg$c64.test(input.charAt(peg$currPos))) { | ||
s0 = input.charAt(peg$currPos); | ||
@@ -1742,3 +1800,3 @@ peg$currPos++; | ||
{ | ||
peg$fail(peg$c61); | ||
peg$fail(peg$c65); | ||
} | ||
@@ -1905,3 +1963,3 @@ } | ||
if (peg$c62.test(input.charAt(peg$currPos))) { | ||
if (peg$c66.test(input.charAt(peg$currPos))) { | ||
s1 = input.charAt(peg$currPos); | ||
@@ -1913,3 +1971,3 @@ peg$currPos++; | ||
{ | ||
peg$fail(peg$c63); | ||
peg$fail(peg$c67); | ||
} | ||
@@ -1921,3 +1979,3 @@ } | ||
if (peg$c44.test(input.charAt(peg$currPos))) { | ||
if (peg$c48.test(input.charAt(peg$currPos))) { | ||
s3 = input.charAt(peg$currPos); | ||
@@ -1929,3 +1987,3 @@ peg$currPos++; | ||
{ | ||
peg$fail(peg$c45); | ||
peg$fail(peg$c49); | ||
} | ||
@@ -1937,3 +1995,3 @@ } | ||
if (peg$c44.test(input.charAt(peg$currPos))) { | ||
if (peg$c48.test(input.charAt(peg$currPos))) { | ||
s3 = input.charAt(peg$currPos); | ||
@@ -1945,3 +2003,3 @@ peg$currPos++; | ||
{ | ||
peg$fail(peg$c45); | ||
peg$fail(peg$c49); | ||
} | ||
@@ -1952,3 +2010,3 @@ } | ||
if (s2 !== peg$FAILED) { | ||
if (peg$c62.test(input.charAt(peg$currPos))) { | ||
if (peg$c66.test(input.charAt(peg$currPos))) { | ||
s3 = input.charAt(peg$currPos); | ||
@@ -1960,3 +2018,3 @@ peg$currPos++; | ||
{ | ||
peg$fail(peg$c63); | ||
peg$fail(peg$c67); | ||
} | ||
@@ -1984,3 +2042,3 @@ } | ||
if (peg$c64.test(input.charAt(peg$currPos))) { | ||
if (peg$c68.test(input.charAt(peg$currPos))) { | ||
s1 = input.charAt(peg$currPos); | ||
@@ -1992,3 +2050,3 @@ peg$currPos++; | ||
{ | ||
peg$fail(peg$c65); | ||
peg$fail(peg$c69); | ||
} | ||
@@ -2000,3 +2058,3 @@ } | ||
if (peg$c48.test(input.charAt(peg$currPos))) { | ||
if (peg$c52.test(input.charAt(peg$currPos))) { | ||
s3 = input.charAt(peg$currPos); | ||
@@ -2008,3 +2066,3 @@ peg$currPos++; | ||
{ | ||
peg$fail(peg$c49); | ||
peg$fail(peg$c53); | ||
} | ||
@@ -2016,3 +2074,3 @@ } | ||
if (peg$c48.test(input.charAt(peg$currPos))) { | ||
if (peg$c52.test(input.charAt(peg$currPos))) { | ||
s3 = input.charAt(peg$currPos); | ||
@@ -2024,3 +2082,3 @@ peg$currPos++; | ||
{ | ||
peg$fail(peg$c49); | ||
peg$fail(peg$c53); | ||
} | ||
@@ -2031,3 +2089,3 @@ } | ||
if (s2 !== peg$FAILED) { | ||
if (peg$c64.test(input.charAt(peg$currPos))) { | ||
if (peg$c68.test(input.charAt(peg$currPos))) { | ||
s3 = input.charAt(peg$currPos); | ||
@@ -2039,3 +2097,3 @@ peg$currPos++; | ||
{ | ||
peg$fail(peg$c65); | ||
peg$fail(peg$c69); | ||
} | ||
@@ -2067,3 +2125,3 @@ } | ||
if (peg$c66.test(input.charAt(peg$currPos))) { | ||
if (peg$c70.test(input.charAt(peg$currPos))) { | ||
s0 = input.charAt(peg$currPos); | ||
@@ -2075,3 +2133,3 @@ peg$currPos++; | ||
{ | ||
peg$fail(peg$c67); | ||
peg$fail(peg$c71); | ||
} | ||
@@ -2088,3 +2146,3 @@ } | ||
if (input.charCodeAt(peg$currPos) === 40) { | ||
s1 = peg$c15; | ||
s1 = peg$c19; | ||
peg$currPos++; | ||
@@ -2095,3 +2153,3 @@ } else { | ||
{ | ||
peg$fail(peg$c16); | ||
peg$fail(peg$c20); | ||
} | ||
@@ -2159,3 +2217,3 @@ } | ||
if (input.charCodeAt(peg$currPos) === 41) { | ||
s3 = peg$c17; | ||
s3 = peg$c21; | ||
peg$currPos++; | ||
@@ -2166,3 +2224,3 @@ } else { | ||
{ | ||
peg$fail(peg$c18); | ||
peg$fail(peg$c22); | ||
} | ||
@@ -2195,3 +2253,3 @@ } | ||
if (input.charCodeAt(peg$currPos) === 64) { | ||
s1 = peg$c25; | ||
s1 = peg$c29; | ||
peg$currPos++; | ||
@@ -2202,3 +2260,3 @@ } else { | ||
{ | ||
peg$fail(peg$c26); | ||
peg$fail(peg$c30); | ||
} | ||
@@ -2230,4 +2288,4 @@ } | ||
if (input.substr(peg$currPos, 7) === peg$c68) { | ||
s1 = peg$c68; | ||
if (input.substr(peg$currPos, 7) === peg$c72) { | ||
s1 = peg$c72; | ||
peg$currPos += 7; | ||
@@ -2238,3 +2296,3 @@ } else { | ||
{ | ||
peg$fail(peg$c69); | ||
peg$fail(peg$c73); | ||
} | ||
@@ -2254,3 +2312,3 @@ } | ||
if (input.charCodeAt(peg$currPos) === 45) { | ||
s3 = peg$c51; | ||
s3 = peg$c55; | ||
peg$currPos++; | ||
@@ -2261,3 +2319,3 @@ } else { | ||
{ | ||
peg$fail(peg$c52); | ||
peg$fail(peg$c56); | ||
} | ||
@@ -2297,3 +2355,3 @@ } | ||
peg$savedPos = s0; | ||
s1 = peg$c70(s5); | ||
s1 = peg$c74(s5); | ||
s0 = s1; | ||
@@ -2300,0 +2358,0 @@ } else { |
@@ -8,3 +8,2 @@ 'use strict'; | ||
var isObject = require('./codegen-functions/is-object.js'); | ||
var noop = require('./codegen-functions/noop.js'); | ||
var scope = require('./scope.js'); | ||
@@ -17,3 +16,2 @@ | ||
exports.isObject = isObject['default']; | ||
exports.noop = noop['default']; | ||
exports.Scope = scope['default']; |
@@ -5,30 +5,15 @@ 'use strict'; | ||
function safeCall(errors, target, args) { | ||
try { | ||
target(...args); | ||
} catch (ex) { | ||
errors.push(ex); | ||
} | ||
} | ||
function proxyCallbacks(errors, callbacks, map) { | ||
function proxyCallbacks(callbacks, errors) { | ||
const _callbacks = {}; | ||
for (const key of Object.keys(callbacks)) { | ||
const mappedValues = map[key]; | ||
const fn = callbacks[key]; | ||
if (Array.isArray(mappedValues)) { | ||
_callbacks[key] = (...args) => { | ||
safeCall(errors, fn, args); | ||
for (const value of mappedValues) { | ||
_callbacks[value](...args); | ||
} | ||
}; | ||
} else { | ||
_callbacks[key] = (...args) => { | ||
safeCall(errors, fn, args); | ||
}; | ||
} | ||
_callbacks[key] = (...args) => { | ||
try { | ||
fn(...args); | ||
} catch (ex) { | ||
errors.push(ex); | ||
} | ||
}; | ||
} | ||
@@ -35,0 +20,0 @@ |
@@ -13,12 +13,11 @@ 'use strict'; | ||
#parent; | ||
#tree; | ||
#output; | ||
constructor(root, parent = null) { | ||
constructor(root, callbacks, parent = null) { | ||
this.root = root; | ||
this.#parent = parent; | ||
this.#tree = null; | ||
this.path = []; | ||
this.errors = []; | ||
this.sandbox = new sandbox.Sandbox(this.path, root, null); | ||
this.callbacks = proxyCallbacks['default'](callbacks, this.errors); | ||
const self = this; | ||
@@ -81,3 +80,3 @@ this.#output = { | ||
fork(path) { | ||
const newScope = new Scope(this.root, this); | ||
const newScope = new Scope(this.root, this.callbacks, this); | ||
@@ -108,13 +107,5 @@ for (const segment of path) { | ||
proxyCallbacks(callbacks, map) { | ||
return proxyCallbacks['default'](this.errors, callbacks, map); | ||
} | ||
emit(id, pos, withKeys) { | ||
const fn = this.callbacks[id]; | ||
registerTree(tree) { | ||
this.#tree = { ...tree | ||
}; | ||
return this.#tree; | ||
} | ||
emit(fn, pos, withKeys) { | ||
if (pos === 0 && !withKeys) { | ||
@@ -121,0 +112,0 @@ return void fn(this.#output); |
@@ -37,8 +37,2 @@ 'use strict'; | ||
return booleanLiteral(value); | ||
default: | ||
return { | ||
type: 'Literal', | ||
value | ||
}; | ||
} | ||
@@ -45,0 +39,0 @@ } |
@@ -7,2 +7,3 @@ 'use strict'; | ||
var builders = require('../ast/builders.js'); | ||
var internalScope = require('../templates/internal-scope.js'); | ||
var sandbox = require('../templates/sandbox.js'); | ||
@@ -12,3 +13,2 @@ var scope = require('../templates/scope.js'); | ||
const pos = builders.identifier('pos'); | ||
function generateMemberExpression(iterator, { | ||
@@ -28,6 +28,6 @@ deep, | ||
const isLastNode = iterator.nextNode === null || iterator.nextNode === 'KeyExpression'; | ||
const right = builders.sequenceExpression([builders.assignmentExpression('=', pos, isLastNode ? builders.conditionalExpression(builders.binaryExpression('!==', scope['default'].property, builders.literal(value)), builders.numericLiteral(-1), scope['default'].depth) : builders.callExpression(builders.memberExpression(scope['default'].path, builders.identifier('indexOf')), [builders.literal(value), iterator.state.pos === 0 ? pos : builders.binaryExpression('+', pos, builders.numericLiteral(1))])), builders.binaryExpression('===', pos, builders.numericLiteral(-1))]); | ||
const right = builders.sequenceExpression([builders.assignmentExpression('=', internalScope['default'].pos, isLastNode ? builders.conditionalExpression(builders.binaryExpression('!==', scope['default'].property, builders.literal(value)), builders.numericLiteral(-1), scope['default'].depth) : builders.callExpression(builders.memberExpression(scope['default'].path, builders.identifier('indexOf')), [builders.literal(value), iterator.state.pos === 0 ? internalScope['default'].pos : builders.binaryExpression('+', internalScope['default'].pos, builders.numericLiteral(1))])), builders.binaryExpression('===', internalScope['default'].pos, builders.numericLiteral(-1))]); | ||
if (isLastNode) { | ||
return builders.logicalExpression('||', builders.binaryExpression('<', scope['default'].depth, iterator.state.pos === 0 ? pos : builders.binaryExpression('+', pos, builders.numericLiteral(iterator.state.pos))), right); | ||
return builders.logicalExpression('||', builders.binaryExpression('<', scope['default'].depth, iterator.state.pos === 0 ? internalScope['default'].pos : builders.binaryExpression('+', internalScope['default'].pos, builders.numericLiteral(iterator.state.pos))), right); | ||
} | ||
@@ -41,6 +41,6 @@ | ||
if (!iterator.feedback.fixed && iterator.state.absolutePos !== 0) { | ||
left = builders.binaryExpression('<', scope['default'].depth, iterator.state.pos === 0 ? pos : builders.binaryExpression('+', pos, builders.numericLiteral(iterator.state.pos))); | ||
left = builders.binaryExpression('<', scope['default'].depth, iterator.state.pos === 0 ? internalScope['default'].pos : builders.binaryExpression('+', internalScope['default'].pos, builders.numericLiteral(iterator.state.pos))); | ||
} | ||
const right = builders.binaryExpression('!==', builders.memberExpression(scope['default'].path, iterator.state.pos === 0 ? builders.numericLiteral(0) : iterator.feedback.fixed ? builders.numericLiteral(iterator.state.pos) : builders.binaryExpression('+', pos, builders.numericLiteral(iterator.state.pos)), true), builders.literal(value)); | ||
const right = builders.binaryExpression('!==', builders.memberExpression(scope['default'].path, iterator.state.pos === 0 ? builders.numericLiteral(0) : iterator.feedback.fixed ? builders.numericLiteral(iterator.state.pos) : builders.binaryExpression('+', internalScope['default'].pos, builders.numericLiteral(iterator.state.pos)), true), builders.literal(value)); | ||
return left !== void 0 ? builders.logicalExpression('||', left, right) : right; | ||
@@ -63,3 +63,3 @@ } | ||
function generateSliceExpression(iterator, node, tree) { | ||
const member = iterator.state.inverted ? builders.binaryExpression('-', scope['default'].depth, builders.numericLiteral(iterator.state.pos)) : iterator.state.pos === 0 ? builders.numericLiteral(0) : iterator.feedback.fixed ? builders.numericLiteral(iterator.state.pos) : builders.binaryExpression('+', pos, builders.numericLiteral(iterator.state.pos)); | ||
const member = iterator.state.inverted ? builders.binaryExpression('-', scope['default'].depth, builders.numericLiteral(iterator.state.pos)) : iterator.state.pos === 0 ? builders.numericLiteral(0) : iterator.feedback.fixed ? builders.numericLiteral(iterator.state.pos) : builders.binaryExpression('+', internalScope['default'].pos, builders.numericLiteral(iterator.state.pos)); | ||
const path = iterator.feedback.bailed ? scope['default'].property : builders.memberExpression(scope['default'].path, member, true); | ||
@@ -96,3 +96,3 @@ const isNumberBinaryExpression = builders.binaryExpression('!==', builders.unaryExpression('typeof', path), builders.stringLiteral('number')); | ||
} else if (iterator.nextNode === null && !iterator.feedback.fixed) { | ||
return builders.sequenceExpression([builders.assignmentExpression('=', builders.identifier('pos'), builders.conditionalExpression(builders.binaryExpression('<', scope['default'].depth, builders.numericLiteral(iterator.state.pos)), builders.numericLiteral(-1), scope['default'].depth)), builders.binaryExpression('===', builders.identifier('pos'), builders.numericLiteral(-1))]); | ||
return builders.sequenceExpression([builders.assignmentExpression('=', internalScope['default'].pos, builders.conditionalExpression(builders.binaryExpression('<', scope['default'].depth, builders.numericLiteral(iterator.state.pos)), builders.numericLiteral(-1), scope['default'].depth)), builders.binaryExpression('===', internalScope['default'].pos, builders.numericLiteral(-1))]); | ||
} else { | ||
@@ -110,5 +110,5 @@ return null; | ||
if (iterator.feedback.bailed || !deep || iterator.state.inverted) return node; | ||
const assignment = builders.sequenceExpression([builders.assignmentExpression('=', builders.identifier('pos'), builders.conditionalExpression(node, builders.numericLiteral(-1), scope['default'].depth)), builders.binaryExpression('===', pos, builders.numericLiteral(-1))]); | ||
const assignment = builders.sequenceExpression([builders.assignmentExpression('=', internalScope['default'].pos, builders.conditionalExpression(node, builders.numericLiteral(-1), scope['default'].depth)), builders.binaryExpression('===', internalScope['default'].pos, builders.numericLiteral(-1))]); | ||
if (iterator.state.pos === 0) return assignment; | ||
return builders.logicalExpression('||', builders.binaryExpression('<', scope['default'].depth, iterator.state.pos === 0 ? pos : builders.binaryExpression('+', pos, builders.numericLiteral(iterator.state.pos))), assignment); | ||
return builders.logicalExpression('||', builders.binaryExpression('<', scope['default'].depth, iterator.state.pos === 0 ? internalScope['default'].pos : builders.binaryExpression('+', internalScope['default'].pos, builders.numericLiteral(iterator.state.pos))), assignment); | ||
} | ||
@@ -115,0 +115,0 @@ function rewriteESTree(node, pos) { |
@@ -10,2 +10,4 @@ 'use strict'; | ||
var emitCall = require('../templates/emit-call.js'); | ||
var fnParams = require('../templates/fn-params.js'); | ||
var internalScope = require('../templates/internal-scope.js'); | ||
var scope = require('../templates/scope.js'); | ||
@@ -15,2 +17,3 @@ var tree = require('../tree/tree.js'); | ||
const POS_VARIABLE_DECLARATION = builders.variableDeclaration('let', [builders.variableDeclarator(internalScope['default'].pos, builders.numericLiteral(0))]); | ||
function baseline(jsonPaths, format) { | ||
@@ -23,6 +26,10 @@ const tree$1 = new tree['default']({ | ||
const _callbacks = builders.identifier('_callbacks'); | ||
traverse: for (const [id, nodes] of jsonPaths) { | ||
const iterator$1 = new iterator['default'](nodes); | ||
traverse: for (const [id, nodes] of jsonPaths) { | ||
const hash = JSON.stringify(nodes); | ||
if (iterator$1.length === -1) { | ||
continue; | ||
} | ||
const hash = JSON.stringify(iterator$1.nodes); | ||
const existingHash = hashes.get(hash); | ||
@@ -34,10 +41,18 @@ | ||
void ((_callbacks$get$push = (_callbacks$get = callbacks.get(existingHash)) === null || _callbacks$get === void 0 ? void 0 : _callbacks$get.push(id)) !== null && _callbacks$get$push !== void 0 ? _callbacks$get$push : callbacks.set(existingHash, [id])); | ||
continue; | ||
} | ||
const method = tree$1.getMethodByHash(existingHash); | ||
hashes.set(hash, id); | ||
const iterator$1 = new iterator['default'](nodes); | ||
if (method === void 0) { | ||
break; | ||
} | ||
if (iterator$1.length === -1) { | ||
let body = method.body.body; | ||
if (iterator$1.feedback.bailed) { | ||
body = body[0].expression.arguments[1].body.body; | ||
} | ||
body.push(emitCall['default'](id, iterator$1.modifiers)); | ||
continue; | ||
} else { | ||
hashes.set(hash, id); | ||
} | ||
@@ -61,7 +76,8 @@ | ||
const branch = iterator$1.feedback.bailed ? [] : [builders.ifStatement(builders.binaryExpression(iterator$1.feedback.fixed ? '!==' : '<', scope['default'].depth, builders.numericLiteral(iterator$1.length - 1)), builders.returnStatement())].concat(iterator$1.feedback.fixed ? [] : builders.variableDeclaration('let', [builders.variableDeclarator(builders.identifier('pos'), builders.numericLiteral(0))])); | ||
const branch = iterator$1.feedback.bailed ? [] : [builders.ifStatement(builders.binaryExpression(iterator$1.feedback.fixed ? '!==' : '<', scope['default'].depth, builders.numericLiteral(iterator$1.length - 1)), builders.returnStatement())].concat(iterator$1.feedback.fixed ? [] : POS_VARIABLE_DECLARATION); | ||
const zone = iterator$1.feedback.bailed ? null : tree$1.traversalZones.create(); | ||
const inverseAt = iterator$1.feedback.inverseAt; | ||
for (const node of iterator$1) { | ||
if (guards.isDeep(node)) { | ||
if (guards.isDeep(node) || inverseAt === iterator$1.state.absolutePos) { | ||
zone === null || zone === void 0 ? void 0 : zone.allIn(); | ||
@@ -115,3 +131,3 @@ } | ||
if (!iterator$1.feedback.fixed && !iterator$1.feedback.bailed && !iterator$1.state.inverted) { | ||
branch.push(builders.ifStatement(builders.binaryExpression('!==', scope['default'].depth, iterator$1.state.pos === 0 ? builders.identifier('pos') : builders.binaryExpression('+', builders.identifier('pos'), builders.numericLiteral(iterator$1.state.pos))), builders.returnStatement())); | ||
branch.push(builders.ifStatement(builders.binaryExpression('!==', scope['default'].depth, iterator$1.state.pos === 0 ? internalScope['default'].pos : builders.binaryExpression('+', internalScope['default'].pos, builders.numericLiteral(iterator$1.state.pos))), builders.returnStatement())); | ||
} | ||
@@ -122,9 +138,9 @@ | ||
if (iterator$1.feedback.bailed) { | ||
branch.splice(0, branch.length, builders.expressionStatement(builders.callExpression(scope['default'].bail, [builders.stringLiteral(id), builders.arrowFunctionExpression([scope['default']._], emitCall['default'](iterator$1.modifiers).expression), builders.arrayExpression([...branch])]))); | ||
branch.splice(0, branch.length, builders.expressionStatement(builders.callExpression(scope['default'].bail, [builders.stringLiteral(id), builders.arrowFunctionExpression([scope['default']._], builders.blockStatement([builders.expressionStatement(emitCall['default'](ctx.id, iterator$1.modifiers).expression)])), builders.arrayExpression([...branch])]))); | ||
} else { | ||
branch.push(emitCall['default'](iterator$1.modifiers)); | ||
branch.push(emitCall['default'](ctx.id, iterator$1.modifiers)); | ||
} | ||
if (placement === 'body') { | ||
tree$1.push(builders.expressionStatement(builders.callExpression(builders.memberExpression(builders.identifier('_tree'), builders.stringLiteral(id), true), [scope['default']._, builders.memberExpression(_callbacks, builders.stringLiteral(id), true)])), placement); | ||
tree$1.push(builders.expressionStatement(builders.callExpression(builders.memberExpression(internalScope['default'].tree, builders.stringLiteral(id), true), fnParams['default'])), placement); | ||
} else { | ||
@@ -138,3 +154,2 @@ tree$1.push(builders.stringLiteral(id), placement); | ||
tree$1.push(builders.objectExpression(Array.from(callbacks.entries()).map(([key, values]) => builders.objectProperty(builders.stringLiteral(key), builders.arrayExpression(values.map(value => builders.stringLiteral(value)))))), 'callbacks'); | ||
return tree$1; | ||
@@ -141,0 +156,0 @@ } |
@@ -29,3 +29,2 @@ 'use strict'; | ||
const QUOTE = /"/g; | ||
const customGenerator = { ...astring__namespace.baseGenerator, | ||
@@ -72,3 +71,3 @@ | ||
StringLiteral(node, state) { | ||
state.write(`"${node.value.replace(QUOTE, '\\"')}"`, node); | ||
state.write(JSON.stringify(node.value), node); | ||
} | ||
@@ -75,0 +74,0 @@ |
@@ -7,4 +7,4 @@ 'use strict'; | ||
var guards = require('../guards.js'); | ||
var emitCall = require('../templates/emit-call.js'); | ||
var scope = require('../templates/scope.js'); | ||
var emitCall = require('../templates/emit-call.js'); | ||
@@ -17,3 +17,3 @@ // covers: | ||
tree.push(builders.blockStatement([builders.ifStatement(builders.binaryExpression('===', scope['default'].property, builders.stringLiteral(nodes[0].value)), builders.blockStatement([emitCall['default'](ctx.iterator.modifiers)]))]), 'tree-method'); | ||
tree.push(builders.blockStatement([builders.ifStatement(builders.binaryExpression('!==', scope['default'].property, builders.stringLiteral(nodes[0].value)), builders.returnStatement()), emitCall['default'](ctx.id, ctx.iterator.modifiers)]), 'tree-method'); | ||
tree.push(builders.stringLiteral(ctx.id), 'traverse'); | ||
@@ -20,0 +20,0 @@ return true; |
@@ -15,3 +15,3 @@ 'use strict'; | ||
tree.push(builders.blockStatement([emitCall['default'](ctx.iterator.modifiers)]), 'tree-method'); | ||
tree.push(builders.blockStatement([emitCall['default'](ctx.id, ctx.iterator.modifiers)]), 'tree-method'); | ||
tree.push(builders.stringLiteral(ctx.id), 'traverse'); | ||
@@ -18,0 +18,0 @@ return true; |
@@ -7,3 +7,3 @@ 'use strict'; | ||
var guards = require('../guards.js'); | ||
var fnParams = require('../templates/fn-params.js'); | ||
var emitCall = require('../templates/emit-call.js'); | ||
var sandbox = require('../templates/sandbox.js'); | ||
@@ -17,4 +17,4 @@ var scope = require('../templates/scope.js'); | ||
const GET_IDENTIFIER = builders.identifier('get'); | ||
const IS_OBJECT_CALL_EXPRESSION = builders.callExpression(IS_OBJECT_IDENTIFIER, [VALUE_IDENTIFIER]); | ||
const DUMP_SCOPE_OBJECT_EXPRESSION = builders.variableDeclaration('const', [builders.variableDeclarator(builders.identifier('emptyScope'), builders.objectExpression([builders.objectMethod('method', scope['default'].emit.property, [], builders.blockStatement([]))]))]); | ||
const IS_NOT_OBJECT_IF_STATEMENT = builders.ifStatement(builders.unaryExpression('!', builders.callExpression(IS_OBJECT_IDENTIFIER, [VALUE_IDENTIFIER])), builders.returnStatement()); | ||
const IS_NULL_SCOPE_IF_STATEMENT = builders.ifStatement(builders.binaryExpression('===', scope['default']._, builders.nullLiteral()), builders.returnStatement()); | ||
@@ -39,12 +39,8 @@ function toLiteral(node) { | ||
tree.addRuntimeDependency(IS_OBJECT_IDENTIFIER.name); | ||
const emitCall = builders.memberExpression(builders.callExpression(scope['default'].fork, [builders.arrayExpression(nodes.map(toLiteral))]), scope['default'].emit.property, false, true); | ||
if (tree.format === 'ES2018') { | ||
tree.addRuntimeDependency(GET_IDENTIFIER.name); | ||
tree.push(DUMP_SCOPE_OBJECT_EXPRESSION, 'program'); | ||
emitCall.optional = false; | ||
emitCall.object = builders.logicalExpression('||', emitCall.object, DUMP_SCOPE_OBJECT_EXPRESSION.declarations[0].id); | ||
} | ||
tree.pushAll([[builders.blockStatement([valueVariableDeclaration, builders.ifStatement(IS_OBJECT_CALL_EXPRESSION, builders.blockStatement([builders.expressionStatement(builders.callExpression(emitCall, [fnParams.fnIdentifier, builders.numericLiteral(ctx.iterator.modifiers.parents), builders.booleanLiteral(ctx.iterator.modifiers.keyed)]))]))]), 'tree-method'], [treeMethodCall['default'](ctx.id), 'body']]); | ||
tree.pushAll([[builders.blockStatement([valueVariableDeclaration, IS_NOT_OBJECT_IF_STATEMENT, builders.expressionStatement(builders.assignmentExpression('=', scope['default']._, builders.callExpression(scope['default'].fork, [builders.arrayExpression(nodes.map(toLiteral))]))), IS_NULL_SCOPE_IF_STATEMENT, emitCall['default'](ctx.id, ctx.iterator.modifiers)]), 'tree-method'], [treeMethodCall['default'](ctx.id), 'body']]); | ||
return true; | ||
@@ -51,0 +47,0 @@ }); |
@@ -5,2 +5,3 @@ 'use strict'; | ||
var allParents = require('./all-parents.js'); | ||
var deepSingleMember = require('./deep-single-member.js'); | ||
@@ -13,4 +14,4 @@ var deepWildcard = require('./deep-wildcard.js'); | ||
var fastPaths = [root['default'], onlyFilterScriptExpression['default'], deepSingleMember['default'], deepWildcard['default'], topLevelWildcard['default'], fixed['default']]; | ||
var fastPaths = [root['default'], onlyFilterScriptExpression['default'], deepSingleMember['default'], deepWildcard['default'], topLevelWildcard['default'], fixed['default'], allParents['default']]; | ||
exports['default'] = fastPaths; |
@@ -21,3 +21,3 @@ 'use strict'; | ||
const condition = builders.unaryExpression('!', generators.rewriteESTree(jsep['default'](nodes[0].value), 0), true); | ||
tree.pushAll([[builders.blockStatement([...(guards.isDeep(nodes[0]) ? [] : [TOP_LEVEL_DEPTH_IF_STATEMENT]), builders.ifStatement(condition, builders.returnStatement()), emitCall['default'](ctx.iterator.modifiers)]), 'tree-method'], [builders.stringLiteral(ctx.id), 'traverse']]); | ||
tree.pushAll([[builders.blockStatement([...(guards.isDeep(nodes[0]) ? [] : [TOP_LEVEL_DEPTH_IF_STATEMENT]), builders.ifStatement(condition, builders.returnStatement()), emitCall['default'](ctx.id, ctx.iterator.modifiers)]), 'tree-method'], [builders.stringLiteral(ctx.id), 'traverse']]); | ||
@@ -24,0 +24,0 @@ if (!guards.isDeep(nodes[0])) { |
@@ -5,11 +5,9 @@ 'use strict'; | ||
var builders = require('../ast/builders.js'); | ||
var emitCall$1 = require('../templates/emit-call.js'); | ||
var emitCall = require('../templates/emit-call.js'); | ||
// covers: $ | ||
const emitCall = emitCall$1['default']({ | ||
const EMIT_ROOT_CALL_EXPRESSION = emitCall['default']('$', { | ||
keyed: false, | ||
parents: 0 | ||
}); | ||
emitCall.expression.arguments[0] = builders.memberExpression(builders.identifier('_callbacks'), builders.identifier('$')); | ||
var root = ((nodes, tree) => { | ||
@@ -20,3 +18,3 @@ if (nodes.length > 0) { | ||
tree.push(emitCall, 'body'); | ||
tree.push(EMIT_ROOT_CALL_EXPRESSION, 'body'); | ||
return true; | ||
@@ -23,0 +21,0 @@ }); |
@@ -11,3 +11,3 @@ 'use strict'; | ||
// Covers: | ||
const BINARY_EXPRESSION = builders.binaryExpression('===', scope['default'].depth, builders.numericLiteral(0)); | ||
const IS_NOT_ZERO_DEPTH_IF_STATEMENT = builders.ifStatement(builders.binaryExpression('!==', scope['default'].depth, builders.numericLiteral(0)), builders.returnStatement()); | ||
var topLevelWildcard = ((nodes, tree, ctx) => { | ||
@@ -20,3 +20,3 @@ var _tree$traversalZones$; | ||
tree.push(builders.blockStatement([builders.ifStatement(BINARY_EXPRESSION, builders.blockStatement([emitCall['default'](ctx.iterator.modifiers)]))]), 'tree-method'); | ||
tree.push(builders.blockStatement([IS_NOT_ZERO_DEPTH_IF_STATEMENT, emitCall['default'](ctx.id, ctx.iterator.modifiers)]), 'tree-method'); | ||
tree.push(builders.stringLiteral(ctx.id), 'traverse'); | ||
@@ -23,0 +23,0 @@ (_tree$traversalZones$ = tree.traversalZones.create()) === null || _tree$traversalZones$ === void 0 ? void 0 : _tree$traversalZones$.resize().attach(); |
@@ -48,4 +48,2 @@ 'use strict'; | ||
var _nodes2 = /*#__PURE__*/new WeakMap(); | ||
var _i = /*#__PURE__*/new WeakMap(); | ||
@@ -56,6 +54,3 @@ | ||
constructor(nodes) { | ||
_nodes2.set(this, { | ||
writable: true, | ||
value: void 0 | ||
}); | ||
_rollupPluginBabelHelpers.defineProperty(this, "nodes", void 0); | ||
@@ -68,9 +63,8 @@ _i.set(this, { | ||
this.modifiers = Iterator.trim(nodes); | ||
this.nodes = Iterator.compact(nodes); | ||
_rollupPluginBabelHelpers.classPrivateFieldSet(this, _nodes2, Iterator.compact(nodes)); | ||
_rollupPluginBabelHelpers.classPrivateFieldSet(this, _i, -1); | ||
this.feedback = Iterator.analyze(_rollupPluginBabelHelpers.classPrivateFieldGet(this, _nodes2), this.modifiers.keyed || this.modifiers.parents > 0); | ||
this.length = _rollupPluginBabelHelpers.classPrivateFieldGet(this, _nodes2).length; | ||
this.feedback = Iterator.analyze(this.nodes, this.modifiers.keyed || this.modifiers.parents > 0); | ||
this.length = this.nodes.length; | ||
this.state = { | ||
@@ -89,3 +83,3 @@ absolutePos: -1, | ||
get nextNode() { | ||
return _rollupPluginBabelHelpers.classPrivateFieldGet(this, _i) + 1 < _rollupPluginBabelHelpers.classPrivateFieldGet(this, _nodes2).length ? _rollupPluginBabelHelpers.classPrivateFieldGet(this, _nodes2)[_rollupPluginBabelHelpers.classPrivateFieldGet(this, _i) + 1] : null; | ||
return _rollupPluginBabelHelpers.classPrivateFieldGet(this, _i) + 1 < this.nodes.length ? this.nodes[_rollupPluginBabelHelpers.classPrivateFieldGet(this, _i) + 1] : null; | ||
} | ||
@@ -180,3 +174,3 @@ | ||
if (this.feedback.bailed) { | ||
return yield* _rollupPluginBabelHelpers.classPrivateFieldGet(this, _nodes2); | ||
return yield* this.nodes; | ||
} | ||
@@ -187,3 +181,3 @@ | ||
let order = 1; | ||
const nodes = this.feedback.inverseAt !== -1 ? _rollupPluginBabelHelpers.classPrivateFieldGet(this, _nodes2).slice() : _rollupPluginBabelHelpers.classPrivateFieldGet(this, _nodes2); | ||
const nodes = this.feedback.inverseAt !== -1 ? this.nodes.slice() : this.nodes; | ||
@@ -190,0 +184,0 @@ for (let i = 0; i < nodes.length; i++) { |
@@ -6,6 +6,5 @@ 'use strict'; | ||
var builders = require('../ast/builders.js'); | ||
var fnParams = require('./fn-params.js'); | ||
var scope = require('./scope.js'); | ||
function generateEmitCall({ | ||
function generateEmitCall(id, { | ||
parents, | ||
@@ -16,5 +15,5 @@ keyed | ||
// todo: add check | ||
return builders.expressionStatement(builders.callExpression(scope['default'].emit, [fnParams.fnIdentifier, builders.numericLiteral(parents), builders.booleanLiteral(keyed)])); | ||
return builders.expressionStatement(builders.callExpression(scope['default'].emit, [builders.stringLiteral(id), builders.numericLiteral(parents), builders.booleanLiteral(keyed)])); | ||
} | ||
exports['default'] = generateEmitCall; |
@@ -5,10 +5,6 @@ 'use strict'; | ||
var builders = require('../ast/builders.js'); | ||
var scope = require('./scope.js'); | ||
const fnIdentifier = builders.identifier('fn'); // scope, fn | ||
var fnParams = [scope['default']._]; | ||
var fnParams = [scope['default']._, fnIdentifier]; | ||
exports['default'] = fnParams; | ||
exports.fnIdentifier = fnIdentifier; |
@@ -11,2 +11,3 @@ 'use strict'; | ||
bail: builders.memberExpression(SCOPE_IDENTIFIER, builders.identifier('bail')), | ||
callbacks: builders.memberExpression(SCOPE_IDENTIFIER, builders.identifier('callbacks')), | ||
depth: builders.memberExpression(SCOPE_IDENTIFIER, builders.identifier('depth')), | ||
@@ -18,4 +19,2 @@ destroy: builders.memberExpression(SCOPE_IDENTIFIER, builders.identifier('destroy')), | ||
property: builders.memberExpression(SCOPE_IDENTIFIER, builders.identifier('property')), | ||
proxyCallbacks: builders.memberExpression(SCOPE_IDENTIFIER, builders.identifier('proxyCallbacks')), | ||
registerTree: builders.memberExpression(SCOPE_IDENTIFIER, builders.identifier('registerTree')), | ||
sandbox: builders.memberExpression(SCOPE_IDENTIFIER, builders.identifier('sandbox')), | ||
@@ -22,0 +21,0 @@ traverse: builders.memberExpression(SCOPE_IDENTIFIER, builders.identifier('traverse')), |
@@ -6,9 +6,10 @@ 'use strict'; | ||
var builders = require('../ast/builders.js'); | ||
var scope = require('./scope.js'); | ||
var fnParams = require('./fn-params.js'); | ||
var internalScope = require('./internal-scope.js'); | ||
function treeMethodCall(id) { | ||
const property = builders.stringLiteral(id); | ||
return builders.expressionStatement(builders.callExpression(builders.memberExpression(builders.identifier('_tree'), property, true), [scope['default']._, builders.memberExpression(builders.identifier('_callbacks'), property, true)])); | ||
return builders.expressionStatement(builders.callExpression(builders.memberExpression(internalScope['default'].tree, property, true), fnParams['default'])); | ||
} | ||
exports['default'] = treeMethodCall; |
@@ -7,3 +7,3 @@ 'use strict'; | ||
var builders = require('../ast/builders.js'); | ||
var toObjectLiteral = require('../templates/to-object-literal.js'); | ||
var buildJson = require('../templates/build-json.js'); | ||
@@ -33,3 +33,3 @@ var _isDestroyed = /*#__PURE__*/new WeakMap(); | ||
const zonesIdentifier = builders.identifier('zones'); | ||
return builders.variableDeclaration('const', [builders.variableDeclarator(zonesIdentifier, toObjectLiteral['default'](mergeZones(_rollupPluginBabelHelpers.classPrivateFieldGet(this, _zones))))]); | ||
return builders.variableDeclaration('const', [builders.variableDeclarator(zonesIdentifier, buildJson['default'](mergeZones(_rollupPluginBabelHelpers.classPrivateFieldGet(this, _zones))))]); | ||
} | ||
@@ -59,2 +59,4 @@ | ||
var _relationships = /*#__PURE__*/new WeakMap(); | ||
class Zone { | ||
@@ -69,5 +71,10 @@ constructor(zones) { | ||
writable: true, | ||
value: [] | ||
value: void 0 | ||
}); | ||
_relationships.set(this, { | ||
writable: true, | ||
value: void 0 | ||
}); | ||
_rollupPluginBabelHelpers.classPrivateFieldSet(this, _zones2, zones); | ||
@@ -78,2 +85,4 @@ | ||
_rollupPluginBabelHelpers.classPrivateFieldSet(this, _localZones, [this.root]); | ||
_rollupPluginBabelHelpers.classPrivateFieldSet(this, _relationships, new Map()); | ||
} | ||
@@ -83,2 +92,4 @@ | ||
_rollupPluginBabelHelpers.classPrivateFieldGet(this, _zones2).attach(this.root); | ||
_rollupPluginBabelHelpers.classPrivateFieldGet(this, _relationships).clear(); | ||
} | ||
@@ -91,3 +102,19 @@ | ||
if (value === null) continue; | ||
value[property] = property === '**' ? null : {}; | ||
if (property === '**') { | ||
const parent = _rollupPluginBabelHelpers.classPrivateFieldGet(this, _relationships).get(value); | ||
if ('*' in parent) { | ||
delete parent['*']; | ||
parent['**'] = null; | ||
continue; | ||
} | ||
value[property] = null; | ||
} else { | ||
value[property] = {}; | ||
_rollupPluginBabelHelpers.classPrivateFieldGet(this, _relationships).set(value[property], value); | ||
} | ||
_rollupPluginBabelHelpers.classPrivateFieldGet(this, _localZones)[i++] = value[property]; | ||
@@ -94,0 +121,0 @@ } |
@@ -9,2 +9,3 @@ 'use strict'; | ||
var fnParams = require('../templates/fn-params.js'); | ||
var internalScope = require('../templates/internal-scope.js'); | ||
var scope = require('../templates/scope.js'); | ||
@@ -15,3 +16,3 @@ var treeMethodCall = require('../templates/tree-method-call.js'); | ||
const params = [builders.identifier('input'), builders.identifier('callbacks')]; | ||
const NEW_SCOPE_VARIABLE_DECLARATION = builders.variableDeclaration('const', [builders.variableDeclarator(scope['default']._, builders.newExpression(builders.identifier('Scope'), [params[0]]))]); | ||
const NEW_SCOPE_VARIABLE_DECLARATION = builders.variableDeclaration('const', [builders.variableDeclarator(scope['default']._, builders.newExpression(builders.identifier('Scope'), params))]); | ||
/* | ||
@@ -27,3 +28,3 @@ import { | ||
export default function (input, callbacks) { | ||
const scope = new Scope(input); | ||
const scope = new Scope(input, callbacks); | ||
@@ -52,4 +53,2 @@ try { | ||
var _callbacks = /*#__PURE__*/new WeakMap(); | ||
class ESTree { | ||
@@ -84,7 +83,2 @@ constructor({ | ||
_callbacks.set(this, { | ||
writable: true, | ||
value: null | ||
}); | ||
this.format = format; | ||
@@ -101,2 +95,6 @@ this.ctx = null; | ||
getMethodByHash(hash) { | ||
return _rollupPluginBabelHelpers.classPrivateFieldGet(this, _tree).properties.find(prop => prop.key.value === hash); | ||
} | ||
push(node, placement) { | ||
@@ -109,7 +107,2 @@ switch (placement) { | ||
case 'tree-property': | ||
_rollupPluginBabelHelpers.classPrivateFieldGet(this, _tree).properties.push(builders.objectProperty(builders.stringLiteral(this.ctx.id), node)); | ||
break; | ||
case 'program': | ||
@@ -129,7 +122,2 @@ if (!_rollupPluginBabelHelpers.classPrivateFieldGet(this, _program).has(node)) { | ||
case 'callbacks': | ||
_rollupPluginBabelHelpers.classPrivateFieldSet(this, _callbacks, node); | ||
break; | ||
case 'traverse': | ||
@@ -149,7 +137,4 @@ _rollupPluginBabelHelpers.classPrivateFieldGet(this, _traverse).add(treeMethodCall['default'](node.value)); | ||
toString() { | ||
var _classPrivateFieldGet2; | ||
const proxyTree = builders.variableDeclaration('const', [builders.variableDeclarator(builders.identifier('_tree'), builders.callExpression(scope['default'].registerTree, [builders.identifier('tree')]))]); | ||
const traversalZones = this.traversalZones.root; | ||
return dump['default'](builders.program([builders.importDeclaration([..._rollupPluginBabelHelpers.classPrivateFieldGet(this, _runtimeDependencies)].map(dep => builders.importSpecifier(builders.identifier(dep), builders.identifier(dep))), builders.stringLiteral('nimma/legacy/runtime')), ..._rollupPluginBabelHelpers.classPrivateFieldGet(this, _program), traversalZones, _rollupPluginBabelHelpers.classPrivateFieldGet(this, _tree).properties.length === 0 ? null : builders.variableDeclaration('const', [builders.variableDeclarator(builders.identifier('tree'), _rollupPluginBabelHelpers.classPrivateFieldGet(this, _tree))]), builders.exportDefaultDeclaration(builders.functionDeclaration(null, params, builders.blockStatement([NEW_SCOPE_VARIABLE_DECLARATION, _rollupPluginBabelHelpers.classPrivateFieldGet(this, _tree).properties.length === 0 ? null : proxyTree, builders.variableDeclaration('const', [builders.variableDeclarator(builders.identifier('_callbacks'), builders.callExpression(scope['default'].proxyCallbacks, [builders.identifier('callbacks'), (_classPrivateFieldGet2 = _rollupPluginBabelHelpers.classPrivateFieldGet(this, _callbacks)) !== null && _classPrivateFieldGet2 !== void 0 ? _classPrivateFieldGet2 : builders.objectExpression([])]))]), builders.tryStatement(builders.blockStatement([..._rollupPluginBabelHelpers.classPrivateFieldGet(this, _body), _rollupPluginBabelHelpers.classPrivateFieldGet(this, _traverse).size === 0 ? null : builders.expressionStatement(builders.callExpression(scope['default'].traverse, [builders.arrowFunctionExpression([], builders.blockStatement(Array.from(_rollupPluginBabelHelpers.classPrivateFieldGet(this, _traverse)))), traversalZones === null ? builders.nullLiteral() : traversalZones.declarations[0].id]))].filter(Boolean)), null, builders.blockStatement([builders.expressionStatement(builders.callExpression(scope['default'].destroy, []))]))].filter(Boolean))))].filter(Boolean))); | ||
return dump['default'](builders.program([builders.importDeclaration([..._rollupPluginBabelHelpers.classPrivateFieldGet(this, _runtimeDependencies)].map(dep => builders.importSpecifier(builders.identifier(dep), builders.identifier(dep))), builders.stringLiteral('nimma/legacy/runtime')), ..._rollupPluginBabelHelpers.classPrivateFieldGet(this, _program), traversalZones, _rollupPluginBabelHelpers.classPrivateFieldGet(this, _tree).properties.length === 0 ? null : builders.variableDeclaration('const', [builders.variableDeclarator(internalScope['default'].tree, _rollupPluginBabelHelpers.classPrivateFieldGet(this, _tree))]), builders.exportDefaultDeclaration(builders.functionDeclaration(null, params, builders.blockStatement([NEW_SCOPE_VARIABLE_DECLARATION, builders.tryStatement(builders.blockStatement([..._rollupPluginBabelHelpers.classPrivateFieldGet(this, _body), _rollupPluginBabelHelpers.classPrivateFieldGet(this, _traverse).size === 0 ? null : builders.expressionStatement(builders.callExpression(scope['default'].traverse, [builders.arrowFunctionExpression([], builders.blockStatement(Array.from(_rollupPluginBabelHelpers.classPrivateFieldGet(this, _traverse)))), traversalZones === null ? builders.nullLiteral() : traversalZones.declarations[0].id]))].filter(Boolean)), null, builders.blockStatement([builders.expressionStatement(builders.callExpression(scope['default'].destroy, []))]))].filter(Boolean))))].filter(Boolean))); | ||
} | ||
@@ -156,0 +141,0 @@ |
@@ -9,2 +9,3 @@ 'use strict'; | ||
var iterator = require('../codegen/iterator.js'); | ||
var scope = require('../codegen/templates/scope.js'); | ||
var parser = require('../parser/parser.js'); | ||
@@ -74,3 +75,3 @@ var index$1 = require('../runtime/index.js'); | ||
const fb = fallback.attach(tree); | ||
tree.push(builders.forOfStatement(builders.variableDeclaration('const', [builders.variableDeclarator(path)]), builders.arrayExpression(erroredExpressions.map(expression => builders.stringLiteral(expression))), builders.blockStatement([builders.callExpression(fb, [builders.identifier('input'), path, builders.memberExpression(builders.identifier('_callbacks'), path, true)])])), 'body'); | ||
tree.push(builders.forOfStatement(builders.variableDeclaration('const', [builders.variableDeclarator(path)]), builders.arrayExpression(erroredExpressions.map(expression => builders.stringLiteral(expression))), builders.blockStatement([builders.callExpression(fb, [builders.identifier('input'), path, builders.memberExpression(scope['default'].callbacks, path, true)])])), 'body'); | ||
} | ||
@@ -77,0 +78,0 @@ |
@@ -139,3 +139,3 @@ 'use strict'; | ||
peg$c1 = function (nodes, modifiers) { | ||
return [...nodes].concat(Array.isArray(modifiers) ? modifiers : modifiers === null ? [] : modifiers); | ||
return nodes.concat(Array.isArray(modifiers) ? modifiers : modifiers === null ? [] : modifiers); | ||
}, | ||
@@ -167,4 +167,14 @@ peg$c2 = "$", | ||
}, | ||
peg$c14 = function (value) { | ||
peg$c14 = function () { | ||
return /^\$\.{2}[~^]*$/.test(input); | ||
}, | ||
peg$c15 = "..", | ||
peg$c16 = peg$literalExpectation("..", false), | ||
peg$c17 = function () { | ||
return { | ||
type: 'AllParentExpression' | ||
}; | ||
}, | ||
peg$c18 = function (value) { | ||
return { | ||
type: "MemberExpression", | ||
@@ -174,9 +184,9 @@ value | ||
}, | ||
peg$c15 = "(", | ||
peg$c16 = peg$literalExpectation("(", false), | ||
peg$c17 = ")", | ||
peg$c18 = peg$literalExpectation(")", false), | ||
peg$c19 = "?(", | ||
peg$c20 = peg$literalExpectation("?(", false), | ||
peg$c21 = function (value) { | ||
peg$c19 = "(", | ||
peg$c20 = peg$literalExpectation("(", false), | ||
peg$c21 = ")", | ||
peg$c22 = peg$literalExpectation(")", false), | ||
peg$c23 = "?(", | ||
peg$c24 = peg$literalExpectation("?(", false), | ||
peg$c25 = function (value) { | ||
return { | ||
@@ -187,5 +197,5 @@ type: "ScriptFilterExpression", | ||
}, | ||
peg$c22 = ":", | ||
peg$c23 = peg$literalExpectation(":", false), | ||
peg$c24 = function (value) { | ||
peg$c26 = ":", | ||
peg$c27 = peg$literalExpectation(":", false), | ||
peg$c28 = function (value) { | ||
return { | ||
@@ -199,9 +209,9 @@ type: "SliceExpression", | ||
}, | ||
peg$c25 = "@", | ||
peg$c26 = peg$literalExpectation("@", false), | ||
peg$c27 = /^[a-z]/, | ||
peg$c28 = peg$classExpectation([["a", "z"]], false, false), | ||
peg$c29 = "()", | ||
peg$c30 = peg$literalExpectation("()", false), | ||
peg$c31 = function (value) { | ||
peg$c29 = "@", | ||
peg$c30 = peg$literalExpectation("@", false), | ||
peg$c31 = /^[a-z]/, | ||
peg$c32 = peg$classExpectation([["a", "z"]], false, false), | ||
peg$c33 = "()", | ||
peg$c34 = peg$literalExpectation("()", false), | ||
peg$c35 = function (value) { | ||
return { | ||
@@ -212,5 +222,5 @@ type: 'ScriptFilterExpression', | ||
}, | ||
peg$c32 = "~", | ||
peg$c33 = peg$literalExpectation("~", false), | ||
peg$c34 = function () { | ||
peg$c36 = "~", | ||
peg$c37 = peg$literalExpectation("~", false), | ||
peg$c38 = function () { | ||
return { | ||
@@ -220,5 +230,5 @@ type: "KeyExpression" | ||
}, | ||
peg$c35 = "^", | ||
peg$c36 = peg$literalExpectation("^", false), | ||
peg$c37 = function () { | ||
peg$c39 = "^", | ||
peg$c40 = peg$literalExpectation("^", false), | ||
peg$c41 = function () { | ||
return { | ||
@@ -228,39 +238,39 @@ type: "ParentExpression" | ||
}, | ||
peg$c38 = /^[.]/, | ||
peg$c39 = peg$classExpectation(["."], false, false), | ||
peg$c40 = /^[$_\-]/, | ||
peg$c41 = peg$classExpectation(["$", "_", "-"], false, false), | ||
peg$c42 = "\"", | ||
peg$c43 = peg$literalExpectation("\"", false), | ||
peg$c44 = /^[^"]/, | ||
peg$c45 = peg$classExpectation(["\""], true, false), | ||
peg$c46 = "'", | ||
peg$c47 = peg$literalExpectation("'", false), | ||
peg$c48 = /^[^']/, | ||
peg$c49 = peg$classExpectation(["'"], true, false), | ||
peg$c50 = function () { | ||
peg$c42 = /^[.]/, | ||
peg$c43 = peg$classExpectation(["."], false, false), | ||
peg$c44 = /^[$_\-]/, | ||
peg$c45 = peg$classExpectation(["$", "_", "-"], false, false), | ||
peg$c46 = "\"", | ||
peg$c47 = peg$literalExpectation("\"", false), | ||
peg$c48 = /^[^"]/, | ||
peg$c49 = peg$classExpectation(["\""], true, false), | ||
peg$c50 = "'", | ||
peg$c51 = peg$literalExpectation("'", false), | ||
peg$c52 = /^[^']/, | ||
peg$c53 = peg$classExpectation(["'"], true, false), | ||
peg$c54 = function () { | ||
return text().slice(1, -1); | ||
}, | ||
peg$c51 = "-", | ||
peg$c52 = peg$literalExpectation("-", false), | ||
peg$c53 = function () { | ||
peg$c55 = "-", | ||
peg$c56 = peg$literalExpectation("-", false), | ||
peg$c57 = function () { | ||
return Number(text()); | ||
}, | ||
peg$c54 = "*", | ||
peg$c55 = peg$literalExpectation("*", false), | ||
peg$c56 = /^[A-Za-z]/, | ||
peg$c57 = peg$classExpectation([["A", "Z"], ["a", "z"]], false, false), | ||
peg$c58 = /^[0-9]/, | ||
peg$c59 = peg$classExpectation([["0", "9"]], false, false), | ||
peg$c60 = /^[ \t]/, | ||
peg$c61 = peg$classExpectation([" ", "\t"], false, false), | ||
peg$c62 = /^["]/, | ||
peg$c63 = peg$classExpectation(["\""], false, false), | ||
peg$c64 = /^[']/, | ||
peg$c65 = peg$classExpectation(["'"], false, false), | ||
peg$c66 = /^[ $@.,_=<>!|&+~%\^*\/;\-[\]]/, | ||
peg$c67 = peg$classExpectation([" ", "$", "@", ".", ",", "_", "=", "<", ">", "!", "|", "&", "+", "~", "%", "^", "*", "/", ";", "-", "[", "]"], false, false), | ||
peg$c68 = ".length", | ||
peg$c69 = peg$literalExpectation(".length", false), | ||
peg$c70 = function (value) { | ||
peg$c58 = "*", | ||
peg$c59 = peg$literalExpectation("*", false), | ||
peg$c60 = /^[A-Za-z]/, | ||
peg$c61 = peg$classExpectation([["A", "Z"], ["a", "z"]], false, false), | ||
peg$c62 = /^[0-9]/, | ||
peg$c63 = peg$classExpectation([["0", "9"]], false, false), | ||
peg$c64 = /^[ \t]/, | ||
peg$c65 = peg$classExpectation([" ", "\t"], false, false), | ||
peg$c66 = /^["]/, | ||
peg$c67 = peg$classExpectation(["\""], false, false), | ||
peg$c68 = /^[']/, | ||
peg$c69 = peg$classExpectation(["'"], false, false), | ||
peg$c70 = /^[ $@.,_=<>!|&+~%\^*\/;\-[\]]/, | ||
peg$c71 = peg$classExpectation([" ", "$", "@", ".", ",", "_", "=", "<", ">", "!", "|", "&", "+", "~", "%", "^", "*", "/", ";", "-", "[", "]"], false, false), | ||
peg$c72 = ".length", | ||
peg$c73 = peg$literalExpectation(".length", false), | ||
peg$c74 = function (value) { | ||
return { | ||
@@ -392,27 +402,5 @@ type: "SliceExpression", | ||
s2 = []; | ||
s3 = peg$currPos; | ||
s4 = peg$parseDescendant(); | ||
s3 = peg$parseAllParentExpression(); | ||
if (s4 === peg$FAILED) { | ||
s4 = null; | ||
} | ||
if (s4 !== peg$FAILED) { | ||
s5 = peg$parseNode(); | ||
if (s5 !== peg$FAILED) { | ||
peg$savedPos = s3; | ||
s4 = peg$c0(s4, s5); | ||
s3 = s4; | ||
} else { | ||
peg$currPos = s3; | ||
s3 = peg$FAILED; | ||
} | ||
} else { | ||
peg$currPos = s3; | ||
s3 = peg$FAILED; | ||
} | ||
while (s3 !== peg$FAILED) { | ||
s2.push(s3); | ||
if (s3 === peg$FAILED) { | ||
s3 = peg$currPos; | ||
@@ -442,2 +430,32 @@ s4 = peg$parseDescendant(); | ||
while (s3 !== peg$FAILED) { | ||
s2.push(s3); | ||
s3 = peg$parseAllParentExpression(); | ||
if (s3 === peg$FAILED) { | ||
s3 = peg$currPos; | ||
s4 = peg$parseDescendant(); | ||
if (s4 === peg$FAILED) { | ||
s4 = null; | ||
} | ||
if (s4 !== peg$FAILED) { | ||
s5 = peg$parseNode(); | ||
if (s5 !== peg$FAILED) { | ||
peg$savedPos = s3; | ||
s4 = peg$c0(s4, s5); | ||
s3 = s4; | ||
} else { | ||
peg$currPos = s3; | ||
s3 = peg$FAILED; | ||
} | ||
} else { | ||
peg$currPos = s3; | ||
s3 = peg$FAILED; | ||
} | ||
} | ||
} | ||
if (s2 !== peg$FAILED) { | ||
@@ -828,2 +846,42 @@ s3 = []; | ||
function peg$parseAllParentExpression() { | ||
var s0, s1, s2; | ||
s0 = peg$currPos; | ||
peg$savedPos = peg$currPos; | ||
s1 = peg$c14(); | ||
if (s1) { | ||
s1 = void 0; | ||
} else { | ||
s1 = peg$FAILED; | ||
} | ||
if (s1 !== peg$FAILED) { | ||
if (input.substr(peg$currPos, 2) === peg$c15) { | ||
s2 = peg$c15; | ||
peg$currPos += 2; | ||
} else { | ||
s2 = peg$FAILED; | ||
{ | ||
peg$fail(peg$c16); | ||
} | ||
} | ||
if (s2 !== peg$FAILED) { | ||
peg$savedPos = s0; | ||
s1 = peg$c17(); | ||
s0 = s1; | ||
} else { | ||
peg$currPos = s0; | ||
s0 = peg$FAILED; | ||
} | ||
} else { | ||
peg$currPos = s0; | ||
s0 = peg$FAILED; | ||
} | ||
return s0; | ||
} | ||
function peg$parseMemberExpression() { | ||
@@ -883,3 +941,3 @@ var s0, s1, s2, s3, s4; | ||
peg$savedPos = s0; | ||
s1 = peg$c14(s1); | ||
s1 = peg$c18(s1); | ||
} | ||
@@ -896,3 +954,3 @@ | ||
if (input.charCodeAt(peg$currPos) === 40) { | ||
s1 = peg$c15; | ||
s1 = peg$c19; | ||
peg$currPos++; | ||
@@ -903,3 +961,3 @@ } else { | ||
{ | ||
peg$fail(peg$c16); | ||
peg$fail(peg$c20); | ||
} | ||
@@ -913,3 +971,3 @@ } | ||
if (input.charCodeAt(peg$currPos) === 41) { | ||
s3 = peg$c17; | ||
s3 = peg$c21; | ||
peg$currPos++; | ||
@@ -920,3 +978,3 @@ } else { | ||
{ | ||
peg$fail(peg$c18); | ||
peg$fail(peg$c22); | ||
} | ||
@@ -949,4 +1007,4 @@ } | ||
if (input.substr(peg$currPos, 2) === peg$c19) { | ||
s1 = peg$c19; | ||
if (input.substr(peg$currPos, 2) === peg$c23) { | ||
s1 = peg$c23; | ||
peg$currPos += 2; | ||
@@ -957,3 +1015,3 @@ } else { | ||
{ | ||
peg$fail(peg$c20); | ||
peg$fail(peg$c24); | ||
} | ||
@@ -967,3 +1025,3 @@ } | ||
if (input.charCodeAt(peg$currPos) === 41) { | ||
s3 = peg$c17; | ||
s3 = peg$c21; | ||
peg$currPos++; | ||
@@ -974,3 +1032,3 @@ } else { | ||
{ | ||
peg$fail(peg$c18); | ||
peg$fail(peg$c22); | ||
} | ||
@@ -981,3 +1039,3 @@ } | ||
peg$savedPos = s0; | ||
s1 = peg$c21(s2); | ||
s1 = peg$c25(s2); | ||
s0 = s1; | ||
@@ -1010,3 +1068,3 @@ } else { | ||
if (input.charCodeAt(peg$currPos) === 58) { | ||
s5 = peg$c22; | ||
s5 = peg$c26; | ||
peg$currPos++; | ||
@@ -1017,3 +1075,3 @@ } else { | ||
{ | ||
peg$fail(peg$c23); | ||
peg$fail(peg$c27); | ||
} | ||
@@ -1049,3 +1107,3 @@ } | ||
if (input.charCodeAt(peg$currPos) === 58) { | ||
s4 = peg$c22; | ||
s4 = peg$c26; | ||
peg$currPos++; | ||
@@ -1056,3 +1114,3 @@ } else { | ||
{ | ||
peg$fail(peg$c23); | ||
peg$fail(peg$c27); | ||
} | ||
@@ -1089,3 +1147,3 @@ } | ||
if (input.charCodeAt(peg$currPos) === 58) { | ||
s5 = peg$c22; | ||
s5 = peg$c26; | ||
peg$currPos++; | ||
@@ -1096,3 +1154,3 @@ } else { | ||
{ | ||
peg$fail(peg$c23); | ||
peg$fail(peg$c27); | ||
} | ||
@@ -1140,3 +1198,3 @@ } | ||
peg$savedPos = s0; | ||
s1 = peg$c24(s1); | ||
s1 = peg$c28(s1); | ||
} | ||
@@ -1155,3 +1213,3 @@ | ||
if (input.charCodeAt(peg$currPos) === 64) { | ||
s3 = peg$c25; | ||
s3 = peg$c29; | ||
peg$currPos++; | ||
@@ -1162,3 +1220,3 @@ } else { | ||
{ | ||
peg$fail(peg$c26); | ||
peg$fail(peg$c30); | ||
} | ||
@@ -1170,3 +1228,3 @@ } | ||
if (peg$c27.test(input.charAt(peg$currPos))) { | ||
if (peg$c31.test(input.charAt(peg$currPos))) { | ||
s5 = input.charAt(peg$currPos); | ||
@@ -1178,3 +1236,3 @@ peg$currPos++; | ||
{ | ||
peg$fail(peg$c28); | ||
peg$fail(peg$c32); | ||
} | ||
@@ -1187,3 +1245,3 @@ } | ||
if (peg$c27.test(input.charAt(peg$currPos))) { | ||
if (peg$c31.test(input.charAt(peg$currPos))) { | ||
s5 = input.charAt(peg$currPos); | ||
@@ -1195,3 +1253,3 @@ peg$currPos++; | ||
{ | ||
peg$fail(peg$c28); | ||
peg$fail(peg$c32); | ||
} | ||
@@ -1205,4 +1263,4 @@ } | ||
if (s4 !== peg$FAILED) { | ||
if (input.substr(peg$currPos, 2) === peg$c29) { | ||
s5 = peg$c29; | ||
if (input.substr(peg$currPos, 2) === peg$c33) { | ||
s5 = peg$c33; | ||
peg$currPos += 2; | ||
@@ -1213,3 +1271,3 @@ } else { | ||
{ | ||
peg$fail(peg$c30); | ||
peg$fail(peg$c34); | ||
} | ||
@@ -1242,3 +1300,3 @@ } | ||
peg$savedPos = s0; | ||
s1 = peg$c31(s1); | ||
s1 = peg$c35(s1); | ||
} | ||
@@ -1255,3 +1313,3 @@ | ||
if (input.charCodeAt(peg$currPos) === 126) { | ||
s1 = peg$c32; | ||
s1 = peg$c36; | ||
peg$currPos++; | ||
@@ -1262,3 +1320,3 @@ } else { | ||
{ | ||
peg$fail(peg$c33); | ||
peg$fail(peg$c37); | ||
} | ||
@@ -1269,3 +1327,3 @@ } | ||
peg$savedPos = s0; | ||
s1 = peg$c34(); | ||
s1 = peg$c38(); | ||
} | ||
@@ -1282,3 +1340,3 @@ | ||
if (input.charCodeAt(peg$currPos) === 94) { | ||
s1 = peg$c35; | ||
s1 = peg$c39; | ||
peg$currPos++; | ||
@@ -1289,3 +1347,3 @@ } else { | ||
{ | ||
peg$fail(peg$c36); | ||
peg$fail(peg$c40); | ||
} | ||
@@ -1296,3 +1354,3 @@ } | ||
peg$savedPos = s0; | ||
s1 = peg$c37(); | ||
s1 = peg$c41(); | ||
} | ||
@@ -1319,3 +1377,3 @@ | ||
if (peg$c38.test(input.charAt(peg$currPos))) { | ||
if (peg$c42.test(input.charAt(peg$currPos))) { | ||
s1 = input.charAt(peg$currPos); | ||
@@ -1327,3 +1385,3 @@ peg$currPos++; | ||
{ | ||
peg$fail(peg$c39); | ||
peg$fail(peg$c43); | ||
} | ||
@@ -1333,3 +1391,3 @@ } | ||
if (s1 !== peg$FAILED) { | ||
if (peg$c38.test(input.charAt(peg$currPos))) { | ||
if (peg$c42.test(input.charAt(peg$currPos))) { | ||
s2 = input.charAt(peg$currPos); | ||
@@ -1341,3 +1399,3 @@ peg$currPos++; | ||
{ | ||
peg$fail(peg$c39); | ||
peg$fail(peg$c43); | ||
} | ||
@@ -1370,3 +1428,3 @@ } | ||
if (peg$c40.test(input.charAt(peg$currPos))) { | ||
if (peg$c44.test(input.charAt(peg$currPos))) { | ||
s2 = input.charAt(peg$currPos); | ||
@@ -1378,3 +1436,3 @@ peg$currPos++; | ||
{ | ||
peg$fail(peg$c41); | ||
peg$fail(peg$c45); | ||
} | ||
@@ -1395,3 +1453,3 @@ } | ||
if (peg$c40.test(input.charAt(peg$currPos))) { | ||
if (peg$c44.test(input.charAt(peg$currPos))) { | ||
s2 = input.charAt(peg$currPos); | ||
@@ -1403,3 +1461,3 @@ peg$currPos++; | ||
{ | ||
peg$fail(peg$c41); | ||
peg$fail(peg$c45); | ||
} | ||
@@ -1441,3 +1499,3 @@ } | ||
if (input.charCodeAt(peg$currPos) === 34) { | ||
s2 = peg$c42; | ||
s2 = peg$c46; | ||
peg$currPos++; | ||
@@ -1448,3 +1506,3 @@ } else { | ||
{ | ||
peg$fail(peg$c43); | ||
peg$fail(peg$c47); | ||
} | ||
@@ -1457,3 +1515,3 @@ } | ||
if (peg$c44.test(input.charAt(peg$currPos))) { | ||
if (peg$c48.test(input.charAt(peg$currPos))) { | ||
s5 = input.charAt(peg$currPos); | ||
@@ -1465,3 +1523,3 @@ peg$currPos++; | ||
{ | ||
peg$fail(peg$c45); | ||
peg$fail(peg$c49); | ||
} | ||
@@ -1473,3 +1531,3 @@ } | ||
if (peg$c44.test(input.charAt(peg$currPos))) { | ||
if (peg$c48.test(input.charAt(peg$currPos))) { | ||
s5 = input.charAt(peg$currPos); | ||
@@ -1481,3 +1539,3 @@ peg$currPos++; | ||
{ | ||
peg$fail(peg$c45); | ||
peg$fail(peg$c49); | ||
} | ||
@@ -1495,3 +1553,3 @@ } | ||
if (input.charCodeAt(peg$currPos) === 34) { | ||
s4 = peg$c42; | ||
s4 = peg$c46; | ||
peg$currPos++; | ||
@@ -1502,3 +1560,3 @@ } else { | ||
{ | ||
peg$fail(peg$c43); | ||
peg$fail(peg$c47); | ||
} | ||
@@ -1527,3 +1585,3 @@ } | ||
if (input.charCodeAt(peg$currPos) === 39) { | ||
s2 = peg$c46; | ||
s2 = peg$c50; | ||
peg$currPos++; | ||
@@ -1534,3 +1592,3 @@ } else { | ||
{ | ||
peg$fail(peg$c47); | ||
peg$fail(peg$c51); | ||
} | ||
@@ -1543,3 +1601,3 @@ } | ||
if (peg$c48.test(input.charAt(peg$currPos))) { | ||
if (peg$c52.test(input.charAt(peg$currPos))) { | ||
s5 = input.charAt(peg$currPos); | ||
@@ -1551,3 +1609,3 @@ peg$currPos++; | ||
{ | ||
peg$fail(peg$c49); | ||
peg$fail(peg$c53); | ||
} | ||
@@ -1559,3 +1617,3 @@ } | ||
if (peg$c48.test(input.charAt(peg$currPos))) { | ||
if (peg$c52.test(input.charAt(peg$currPos))) { | ||
s5 = input.charAt(peg$currPos); | ||
@@ -1567,3 +1625,3 @@ peg$currPos++; | ||
{ | ||
peg$fail(peg$c49); | ||
peg$fail(peg$c53); | ||
} | ||
@@ -1581,3 +1639,3 @@ } | ||
if (input.charCodeAt(peg$currPos) === 39) { | ||
s4 = peg$c46; | ||
s4 = peg$c50; | ||
peg$currPos++; | ||
@@ -1588,3 +1646,3 @@ } else { | ||
{ | ||
peg$fail(peg$c47); | ||
peg$fail(peg$c51); | ||
} | ||
@@ -1612,3 +1670,3 @@ } | ||
peg$savedPos = s0; | ||
s1 = peg$c50(); | ||
s1 = peg$c54(); | ||
} | ||
@@ -1628,3 +1686,3 @@ | ||
if (input.charCodeAt(peg$currPos) === 45) { | ||
s1 = peg$c51; | ||
s1 = peg$c55; | ||
peg$currPos++; | ||
@@ -1635,3 +1693,3 @@ } else { | ||
{ | ||
peg$fail(peg$c52); | ||
peg$fail(peg$c56); | ||
} | ||
@@ -1659,3 +1717,3 @@ } | ||
peg$savedPos = s0; | ||
s1 = peg$c53(); | ||
s1 = peg$c57(); | ||
s0 = s1; | ||
@@ -1678,3 +1736,3 @@ } else { | ||
if (input.charCodeAt(peg$currPos) === 42) { | ||
s0 = peg$c54; | ||
s0 = peg$c58; | ||
peg$currPos++; | ||
@@ -1685,3 +1743,3 @@ } else { | ||
{ | ||
peg$fail(peg$c55); | ||
peg$fail(peg$c59); | ||
} | ||
@@ -1696,3 +1754,3 @@ } | ||
if (peg$c56.test(input.charAt(peg$currPos))) { | ||
if (peg$c60.test(input.charAt(peg$currPos))) { | ||
s0 = input.charAt(peg$currPos); | ||
@@ -1704,3 +1762,3 @@ peg$currPos++; | ||
{ | ||
peg$fail(peg$c57); | ||
peg$fail(peg$c61); | ||
} | ||
@@ -1715,3 +1773,3 @@ } | ||
if (peg$c58.test(input.charAt(peg$currPos))) { | ||
if (peg$c62.test(input.charAt(peg$currPos))) { | ||
s0 = input.charAt(peg$currPos); | ||
@@ -1723,3 +1781,3 @@ peg$currPos++; | ||
{ | ||
peg$fail(peg$c59); | ||
peg$fail(peg$c63); | ||
} | ||
@@ -1734,3 +1792,3 @@ } | ||
if (peg$c60.test(input.charAt(peg$currPos))) { | ||
if (peg$c64.test(input.charAt(peg$currPos))) { | ||
s0 = input.charAt(peg$currPos); | ||
@@ -1742,3 +1800,3 @@ peg$currPos++; | ||
{ | ||
peg$fail(peg$c61); | ||
peg$fail(peg$c65); | ||
} | ||
@@ -1905,3 +1963,3 @@ } | ||
if (peg$c62.test(input.charAt(peg$currPos))) { | ||
if (peg$c66.test(input.charAt(peg$currPos))) { | ||
s1 = input.charAt(peg$currPos); | ||
@@ -1913,3 +1971,3 @@ peg$currPos++; | ||
{ | ||
peg$fail(peg$c63); | ||
peg$fail(peg$c67); | ||
} | ||
@@ -1921,3 +1979,3 @@ } | ||
if (peg$c44.test(input.charAt(peg$currPos))) { | ||
if (peg$c48.test(input.charAt(peg$currPos))) { | ||
s3 = input.charAt(peg$currPos); | ||
@@ -1929,3 +1987,3 @@ peg$currPos++; | ||
{ | ||
peg$fail(peg$c45); | ||
peg$fail(peg$c49); | ||
} | ||
@@ -1937,3 +1995,3 @@ } | ||
if (peg$c44.test(input.charAt(peg$currPos))) { | ||
if (peg$c48.test(input.charAt(peg$currPos))) { | ||
s3 = input.charAt(peg$currPos); | ||
@@ -1945,3 +2003,3 @@ peg$currPos++; | ||
{ | ||
peg$fail(peg$c45); | ||
peg$fail(peg$c49); | ||
} | ||
@@ -1952,3 +2010,3 @@ } | ||
if (s2 !== peg$FAILED) { | ||
if (peg$c62.test(input.charAt(peg$currPos))) { | ||
if (peg$c66.test(input.charAt(peg$currPos))) { | ||
s3 = input.charAt(peg$currPos); | ||
@@ -1960,3 +2018,3 @@ peg$currPos++; | ||
{ | ||
peg$fail(peg$c63); | ||
peg$fail(peg$c67); | ||
} | ||
@@ -1984,3 +2042,3 @@ } | ||
if (peg$c64.test(input.charAt(peg$currPos))) { | ||
if (peg$c68.test(input.charAt(peg$currPos))) { | ||
s1 = input.charAt(peg$currPos); | ||
@@ -1992,3 +2050,3 @@ peg$currPos++; | ||
{ | ||
peg$fail(peg$c65); | ||
peg$fail(peg$c69); | ||
} | ||
@@ -2000,3 +2058,3 @@ } | ||
if (peg$c48.test(input.charAt(peg$currPos))) { | ||
if (peg$c52.test(input.charAt(peg$currPos))) { | ||
s3 = input.charAt(peg$currPos); | ||
@@ -2008,3 +2066,3 @@ peg$currPos++; | ||
{ | ||
peg$fail(peg$c49); | ||
peg$fail(peg$c53); | ||
} | ||
@@ -2016,3 +2074,3 @@ } | ||
if (peg$c48.test(input.charAt(peg$currPos))) { | ||
if (peg$c52.test(input.charAt(peg$currPos))) { | ||
s3 = input.charAt(peg$currPos); | ||
@@ -2024,3 +2082,3 @@ peg$currPos++; | ||
{ | ||
peg$fail(peg$c49); | ||
peg$fail(peg$c53); | ||
} | ||
@@ -2031,3 +2089,3 @@ } | ||
if (s2 !== peg$FAILED) { | ||
if (peg$c64.test(input.charAt(peg$currPos))) { | ||
if (peg$c68.test(input.charAt(peg$currPos))) { | ||
s3 = input.charAt(peg$currPos); | ||
@@ -2039,3 +2097,3 @@ peg$currPos++; | ||
{ | ||
peg$fail(peg$c65); | ||
peg$fail(peg$c69); | ||
} | ||
@@ -2067,3 +2125,3 @@ } | ||
if (peg$c66.test(input.charAt(peg$currPos))) { | ||
if (peg$c70.test(input.charAt(peg$currPos))) { | ||
s0 = input.charAt(peg$currPos); | ||
@@ -2075,3 +2133,3 @@ peg$currPos++; | ||
{ | ||
peg$fail(peg$c67); | ||
peg$fail(peg$c71); | ||
} | ||
@@ -2088,3 +2146,3 @@ } | ||
if (input.charCodeAt(peg$currPos) === 40) { | ||
s1 = peg$c15; | ||
s1 = peg$c19; | ||
peg$currPos++; | ||
@@ -2095,3 +2153,3 @@ } else { | ||
{ | ||
peg$fail(peg$c16); | ||
peg$fail(peg$c20); | ||
} | ||
@@ -2159,3 +2217,3 @@ } | ||
if (input.charCodeAt(peg$currPos) === 41) { | ||
s3 = peg$c17; | ||
s3 = peg$c21; | ||
peg$currPos++; | ||
@@ -2166,3 +2224,3 @@ } else { | ||
{ | ||
peg$fail(peg$c18); | ||
peg$fail(peg$c22); | ||
} | ||
@@ -2195,3 +2253,3 @@ } | ||
if (input.charCodeAt(peg$currPos) === 64) { | ||
s1 = peg$c25; | ||
s1 = peg$c29; | ||
peg$currPos++; | ||
@@ -2202,3 +2260,3 @@ } else { | ||
{ | ||
peg$fail(peg$c26); | ||
peg$fail(peg$c30); | ||
} | ||
@@ -2230,4 +2288,4 @@ } | ||
if (input.substr(peg$currPos, 7) === peg$c68) { | ||
s1 = peg$c68; | ||
if (input.substr(peg$currPos, 7) === peg$c72) { | ||
s1 = peg$c72; | ||
peg$currPos += 7; | ||
@@ -2238,3 +2296,3 @@ } else { | ||
{ | ||
peg$fail(peg$c69); | ||
peg$fail(peg$c73); | ||
} | ||
@@ -2254,3 +2312,3 @@ } | ||
if (input.charCodeAt(peg$currPos) === 45) { | ||
s3 = peg$c51; | ||
s3 = peg$c55; | ||
peg$currPos++; | ||
@@ -2261,3 +2319,3 @@ } else { | ||
{ | ||
peg$fail(peg$c52); | ||
peg$fail(peg$c56); | ||
} | ||
@@ -2297,3 +2355,3 @@ } | ||
peg$savedPos = s0; | ||
s1 = peg$c70(s5); | ||
s1 = peg$c74(s5); | ||
s0 = s1; | ||
@@ -2300,0 +2358,0 @@ } else { |
@@ -8,3 +8,2 @@ 'use strict'; | ||
var isObject = require('./codegen-functions/is-object.js'); | ||
var noop = require('./codegen-functions/noop.js'); | ||
var scope = require('./scope.js'); | ||
@@ -17,3 +16,2 @@ | ||
exports.isObject = isObject['default']; | ||
exports.noop = noop['default']; | ||
exports.Scope = scope['default']; |
@@ -5,30 +5,15 @@ 'use strict'; | ||
function safeCall(errors, target, args) { | ||
try { | ||
target(...args); | ||
} catch (ex) { | ||
errors.push(ex); | ||
} | ||
} | ||
function proxyCallbacks(errors, callbacks, map) { | ||
function proxyCallbacks(callbacks, errors) { | ||
const _callbacks = {}; | ||
for (const key of Object.keys(callbacks)) { | ||
const mappedValues = map[key]; | ||
const fn = callbacks[key]; | ||
if (Array.isArray(mappedValues)) { | ||
_callbacks[key] = (...args) => { | ||
safeCall(errors, fn, args); | ||
for (const value of mappedValues) { | ||
_callbacks[value](...args); | ||
} | ||
}; | ||
} else { | ||
_callbacks[key] = (...args) => { | ||
safeCall(errors, fn, args); | ||
}; | ||
} | ||
_callbacks[key] = (...args) => { | ||
try { | ||
fn(...args); | ||
} catch (ex) { | ||
errors.push(ex); | ||
} | ||
}; | ||
} | ||
@@ -35,0 +20,0 @@ |
@@ -15,8 +15,6 @@ 'use strict'; | ||
var _tree = /*#__PURE__*/new WeakMap(); | ||
var _output = /*#__PURE__*/new WeakMap(); | ||
class Scope { | ||
constructor(root, parent = null) { | ||
constructor(root, callbacks, parent = null) { | ||
_ticks.set(this, { | ||
@@ -32,7 +30,2 @@ writable: true, | ||
_tree.set(this, { | ||
writable: true, | ||
value: void 0 | ||
}); | ||
_output.set(this, { | ||
@@ -47,7 +40,6 @@ writable: true, | ||
_rollupPluginBabelHelpers.classPrivateFieldSet(this, _tree, null); | ||
this.path = []; | ||
this.errors = []; | ||
this.sandbox = new sandbox.Sandbox(this.path, root, null); | ||
this.callbacks = proxyCallbacks['default'](callbacks, this.errors); | ||
const self = this; | ||
@@ -111,3 +103,3 @@ | ||
fork(path) { | ||
const newScope = new Scope(this.root, this); | ||
const newScope = new Scope(this.root, this.callbacks, this); | ||
@@ -138,16 +130,7 @@ for (const segment of path) { | ||
proxyCallbacks(callbacks, map) { | ||
return proxyCallbacks['default'](this.errors, callbacks, map); | ||
} | ||
emit(id, pos, withKeys) { | ||
var _this$sandbox$at; | ||
registerTree(tree) { | ||
_rollupPluginBabelHelpers.classPrivateFieldSet(this, _tree, { ...tree | ||
}); | ||
const fn = this.callbacks[id]; | ||
return _rollupPluginBabelHelpers.classPrivateFieldGet(this, _tree); | ||
} | ||
emit(fn, pos, withKeys) { | ||
var _this$sandbox$at; | ||
if (pos === 0 && !withKeys) { | ||
@@ -154,0 +137,0 @@ return void fn(_rollupPluginBabelHelpers.classPrivateFieldGet(this, _output)); |
{ | ||
"name": "nimma", | ||
"version": "0.1.3", | ||
"version": "0.1.4", | ||
"description": "JSONPath engine that scales.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
613743
205
18954