diff --git a/src/visitor.ts b/src/visitor.ts index 45b268b..faafed4 100644 --- a/src/visitor.ts +++ b/src/visitor.ts @@ -20,6 +20,7 @@ interface Result { } interface ParentInfo { + value: any, type: Class decorators: any[] } @@ -102,7 +103,7 @@ function objectVisitor(value: any, ast: ObjectNode, opt: VisitorOption): Result const node = ast.properties.get(property.name) as SuperNode const option = { path: getPath(opt.path, property.name), extension: opt.extension, - decorators: property.decorators, parent: { type: ast.type, decorators: opt.decorators }, + decorators: property.decorators, parent: { value, type: ast.type, decorators: opt.decorators }, guessArrayElement: opt.guessArrayElement } const propValue = pipeline(value[property.name], node, option) diff --git a/test/__snapshots__/visitor.spec.ts.snap b/test/__snapshots__/visitor.spec.ts.snap index c1a1a90..f000514 100644 --- a/test/__snapshots__/visitor.spec.ts.snap +++ b/test/__snapshots__/visitor.spec.ts.snap @@ -143,6 +143,9 @@ Object { "parent": Object { "decorators": Array [], "type": Tag, + "value": Object { + "age": "12", + }, }, "result": 12, }, @@ -160,6 +163,11 @@ Object { "parent": Object { "decorators": Array [], "type": Animal, + "value": Object { + "tag": Object { + "age": "12", + }, + }, }, "result": Tag { "age": Object { @@ -170,6 +178,9 @@ Object { }, ], "type": Tag, + "value": Object { + "age": "12", + }, }, "result": 12, }, @@ -189,12 +200,32 @@ Object { "parent": Object { "decorators": Array [], "type": Animal, + "value": Object { + "tag": Array [ + Object { + "age": "12", + }, + Object { + "age": "12", + }, + ], + }, }, "result": Array [ Object { "parent": Object { "decorators": Array [], "type": Animal, + "value": Object { + "tag": Array [ + Object { + "age": "12", + }, + Object { + "age": "12", + }, + ], + }, }, "result": Tag { "age": Object { @@ -209,6 +240,9 @@ Object { }, ], "type": Tag, + "value": Object { + "age": "12", + }, }, "result": 12, }, @@ -218,6 +252,16 @@ Object { "parent": Object { "decorators": Array [], "type": Animal, + "value": Object { + "tag": Array [ + Object { + "age": "12", + }, + Object { + "age": "12", + }, + ], + }, }, "result": Tag { "age": Object { @@ -232,6 +276,9 @@ Object { }, ], "type": Tag, + "value": Object { + "age": "12", + }, }, "result": 12, }, @@ -257,6 +304,9 @@ Object { }, ], "type": Tag, + "value": Object { + "age": "12", + }, }, "result": 12, },