Skip to content

Commit 5cedf58

Browse files
committed
Merge branch 'master' of github.com:mcollina/fast-json-stringify
2 parents 17e8ccd + 33676d6 commit 5cedf58

File tree

2 files changed

+47
-9
lines changed

2 files changed

+47
-9
lines changed

index.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ function build (schema, options) {
5151
`
5252
}
5353

54-
var hasShemaSomeIf = hasIf(schema)
54+
var hasSchemaSomeIf = hasIf(schema)
5555

5656
var main
5757

@@ -94,7 +94,7 @@ function build (schema, options) {
9494

9595
var dependencies = []
9696
var dependenciesName = []
97-
if (hasAnyOf(schema) || hasShemaSomeIf) {
97+
if (hasAnyOf(schema) || hasSchemaSomeIf) {
9898
dependencies.push(new Ajv())
9999
dependenciesName.push('ajv')
100100
}
@@ -514,7 +514,7 @@ function addIfThenElse (schema, name, externalSchema, fullSchema) {
514514

515515
r = buildInnerObject(merged, name, externalSchema, fullSchema)
516516
code += r.code
517-
laterCode = r.laterCode
517+
laterCode += r.laterCode
518518

519519
code += `
520520
}
@@ -529,12 +529,12 @@ function addIfThenElse (schema, name, externalSchema, fullSchema) {
529529
if (merged.if && merged.then) {
530530
innerR = addIfThenElse(merged, name, externalSchema, fullSchema)
531531
code += innerR.code
532-
laterCode = innerR.laterCode
532+
laterCode += innerR.laterCode
533533
}
534534

535535
r = buildInnerObject(merged, name, externalSchema, fullSchema)
536536
code += r.code
537-
laterCode = r.laterCode
537+
laterCode += r.laterCode
538538

539539
code += `
540540
}

test/if-then-else.test.js

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,17 @@ const schema = {
1616
'properties': {
1717
'kind': { 'type': 'string', 'enum': ['foobar'] },
1818
'foo': { 'type': 'string' },
19-
'bar': { 'type': 'number' }
19+
'bar': { 'type': 'number' },
20+
'list': {
21+
'type': 'array',
22+
'items': {
23+
'type': 'object',
24+
'properties': {
25+
'name': {'type': 'string'},
26+
'value': {'type': 'string'}
27+
}
28+
}
29+
}
2030
}
2131
},
2232
'else': {
@@ -46,7 +56,17 @@ const nestedIfSchema = {
4656
'properties': {
4757
'kind': { 'type': 'string', 'enum': ['foobar'] },
4858
'foo': { 'type': 'string' },
49-
'bar': { 'type': 'number' }
59+
'bar': { 'type': 'number' },
60+
'list': {
61+
'type': 'array',
62+
'items': {
63+
'type': 'object',
64+
'properties': {
65+
'name': {'type': 'string'},
66+
'value': {'type': 'string'}
67+
}
68+
}
69+
}
5070
}
5171
},
5272
'else': {
@@ -78,7 +98,17 @@ const nestedElseSchema = {
7898
'properties': {
7999
'kind': { 'type': 'string', 'enum': ['foobar'] },
80100
'foo': { 'type': 'string' },
81-
'bar': { 'type': 'number' }
101+
'bar': { 'type': 'number' },
102+
'list': {
103+
'type': 'array',
104+
'items': {
105+
'type': 'object',
106+
'properties': {
107+
'name': {'type': 'string'},
108+
'value': {'type': 'string'}
109+
}
110+
}
111+
}
82112
}
83113
},
84114
'else': {
@@ -107,6 +137,10 @@ const nestedElseSchema = {
107137
const fooBarInput = {
108138
kind: 'foobar',
109139
foo: 'FOO',
140+
list: [{
141+
name: 'name',
142+
value: 'foo'
143+
}],
110144
bar: 42,
111145
hi: 'HI',
112146
hello: 45,
@@ -134,7 +168,11 @@ const alphabetInput = {
134168
const foobarOutput = JSON.stringify({
135169
kind: 'foobar',
136170
foo: 'FOO',
137-
bar: 42
171+
bar: 42,
172+
list: [{
173+
name: 'name',
174+
value: 'foo'
175+
}]
138176
})
139177
const greetingOutput = JSON.stringify({
140178
kind: 'greeting',

0 commit comments

Comments
 (0)