@vinejs/compiler
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -21,5 +21,5 @@ import { BaseNode } from './base.js'; | ||
} | ||
#getFieldNames() { | ||
let fieldNames = this.#node.properties.map((child) => child.fieldName); | ||
const groupsFieldNames = this.#node.groups.flatMap((group) => this.#getGroupFieldNames(group)); | ||
#getFieldNames(node) { | ||
let fieldNames = node.properties.map((child) => child.fieldName); | ||
const groupsFieldNames = node.groups.flatMap((group) => this.#getGroupFieldNames(group)); | ||
return fieldNames.concat(groupsFieldNames); | ||
@@ -29,10 +29,3 @@ } | ||
return group.conditions.flatMap((condition) => { | ||
if (condition.schema.type === 'sub_object') { | ||
return condition.schema.children.map((child) => { | ||
return child.fieldName; | ||
}); | ||
} | ||
else { | ||
return this.#getGroupFieldNames(condition.schema); | ||
} | ||
return this.#getFieldNames(condition.schema); | ||
}); | ||
@@ -65,10 +58,8 @@ } | ||
const guardBuffer = buffer.child(); | ||
if (condition.schema.type === 'group') { | ||
this.#compileObjectGroup(condition.schema, guardBuffer, parent); | ||
} | ||
else { | ||
condition.schema.children.forEach((child) => { | ||
this.#compiler.compileNode(child, guardBuffer, parent); | ||
}); | ||
} | ||
condition.schema.properties.forEach((child) => { | ||
this.#compiler.compileNode(child, guardBuffer, parent); | ||
}); | ||
condition.schema.groups.forEach((child) => { | ||
this.#compileObjectGroup(child, guardBuffer, parent); | ||
}); | ||
buffer.writeStatement(defineConditionalGuard({ | ||
@@ -105,3 +96,3 @@ variableName: this.field.variableName, | ||
allowUnknownProperties: this.#node.allowUnknownProperties, | ||
fieldsToIgnore: this.#node.allowUnknownProperties ? this.#getFieldNames() : [], | ||
fieldsToIgnore: this.#node.allowUnknownProperties ? this.#getFieldNames(this.#node) : [], | ||
})}`, | ||
@@ -108,0 +99,0 @@ }); |
@@ -58,4 +58,5 @@ export type RefIdentifier = `ref://${number}`; | ||
type: 'sub_object'; | ||
children: CompilerNodes[]; | ||
} | ObjectGroupNode; | ||
properties: CompilerNodes[]; | ||
groups: ObjectGroupNode[]; | ||
}; | ||
}[]; | ||
@@ -62,0 +63,0 @@ }; |
{ | ||
"name": "@vinejs/compiler", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Low level compiler for VineJS validator", | ||
@@ -5,0 +5,0 @@ "type": "module", |
@@ -48,5 +48,5 @@ /* | ||
*/ | ||
#getFieldNames(): string[] { | ||
let fieldNames = this.#node.properties.map((child) => child.fieldName) | ||
const groupsFieldNames = this.#node.groups.flatMap((group) => this.#getGroupFieldNames(group)) | ||
#getFieldNames(node: Pick<ObjectNode, 'properties' | 'groups'>): string[] { | ||
let fieldNames = node.properties.map((child) => child.fieldName) | ||
const groupsFieldNames = node.groups.flatMap((group) => this.#getGroupFieldNames(group)) | ||
return fieldNames.concat(groupsFieldNames) | ||
@@ -60,9 +60,3 @@ } | ||
return group.conditions.flatMap((condition) => { | ||
if (condition.schema.type === 'sub_object') { | ||
return condition.schema.children.map((child) => { | ||
return child.fieldName | ||
}) | ||
} else { | ||
return this.#getGroupFieldNames(condition.schema) | ||
} | ||
return this.#getFieldNames(condition.schema) | ||
}) | ||
@@ -109,10 +103,10 @@ } | ||
if (condition.schema.type === 'group') { | ||
this.#compileObjectGroup(condition.schema, guardBuffer, parent) | ||
} else { | ||
condition.schema.children.forEach((child) => { | ||
this.#compiler.compileNode(child, guardBuffer, parent) | ||
}) | ||
} | ||
condition.schema.properties.forEach((child) => { | ||
this.#compiler.compileNode(child, guardBuffer, parent) | ||
}) | ||
condition.schema.groups.forEach((child) => { | ||
this.#compileObjectGroup(child, guardBuffer, parent) | ||
}) | ||
buffer.writeStatement( | ||
@@ -176,3 +170,3 @@ defineConditionalGuard({ | ||
allowUnknownProperties: this.#node.allowUnknownProperties, | ||
fieldsToIgnore: this.#node.allowUnknownProperties ? this.#getFieldNames() : [], | ||
fieldsToIgnore: this.#node.allowUnknownProperties ? this.#getFieldNames(this.#node) : [], | ||
})}`, | ||
@@ -179,0 +173,0 @@ }) |
@@ -264,8 +264,17 @@ /* | ||
*/ | ||
schema: | ||
| { | ||
type: 'sub_object' | ||
children: CompilerNodes[] | ||
} | ||
| ObjectGroupNode | ||
schema: { | ||
type: 'sub_object' | ||
/** | ||
* Object known properties | ||
*/ | ||
properties: CompilerNodes[] | ||
/** | ||
* A collection of object groups to merge into the main object. | ||
* Each group is a collection of conditionals with a sub-object | ||
* inside them. | ||
*/ | ||
groups: ObjectGroupNode[] | ||
} | ||
}[] | ||
@@ -272,0 +281,0 @@ } |
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
129253
3150