Preprocessing bugfix

This commit is contained in:
Bán Dénes 2023-01-30 14:57:24 +01:00
parent c45523f38a
commit 480c362c1e
3 changed files with 24 additions and 1 deletions

View file

@ -14,7 +14,9 @@
### Minor ### Minor
- Support "direct" anchors, as in, recognize num arrays and parse them as x/y/r
- Add full anchor support to individual points (via `adjust`, probably) - Add full anchor support to individual points (via `adjust`, probably)
- Handle unnecessary (but seemingly consistent, so easy to confuse) `key` subfield of row-level overrides
- Allow footprints to access raw array/object fields from points with templating - Allow footprints to access raw array/object fields from points with templating
- Include raw kicad footprint integrations - Include raw kicad footprint integrations
- pull torik's script to be able to convert raw kicad footprints into positionable ergogen ones - pull torik's script to be able to convert raw kicad footprints into positionable ergogen ones

View file

@ -42,11 +42,14 @@ const traverse = exports.traverse = (config, root, breadcrumbs, op) => {
} }
return result return result
} else if (a.type(config)() == 'array') { } else if (a.type(config)() == 'array') {
// needed so that arrays can set output the same way as objects within ops
const dummy = {}
const result = [] const result = []
let index = 0 let index = 0
for (const val of config) { for (const val of config) {
breadcrumbs.push(`[${index}]`) breadcrumbs.push(`[${index}]`)
result[index] = traverse(val, root, breadcrumbs, op) op(dummy, 'dummykey', traverse(val, root, breadcrumbs, op), root, breadcrumbs)
result[index] = dummy.dummykey
breadcrumbs.pop() breadcrumbs.pop()
index++ index++
} }

View file

@ -24,6 +24,7 @@ describe('Prepare', function() {
}) })
it('inherit', function() { it('inherit', function() {
// normal case
p.inherit({ p.inherit({
a: { a: {
x: 1, x: 1,
@ -43,6 +44,23 @@ describe('Prepare', function() {
z: 3, z: 3,
w: 4 w: 4
}) })
// should apply to objects within arrays as well!
p.inherit({
a: {
x: 1,
y: 2
},
b: [
{
$extends: 'a',
z: 3
}
]
}).b[0].should.deep.equal({
x: 1,
y: 2,
z: 3
})
}) })
it('parameterize', function() { it('parameterize', function() {