* Compiles this schema within the current root compilation context. If the schema was previously * compiled within this context, we reuse the cached FieldPathNode, otherwise we create a new one * and cache it in the compilation context.
()
| 51 | * and cache it in the compilation context. |
| 52 | */ |
| 53 | compile(): FieldPathNode { |
| 54 | if (compiledSchemas.has(this)) { |
| 55 | return compiledSchemas.get(this)!; |
| 56 | } |
| 57 | const path = FieldPathNode.newRoot(); |
| 58 | compiledSchemas.set(this, path); |
| 59 | let prevCompilingNode = currentCompilingNode; |
| 60 | try { |
| 61 | currentCompilingNode = path; |
| 62 | this.schemaFn(path.fieldPathProxy); |
| 63 | } finally { |
| 64 | // Use a try/finally to ensure we restore the previous root upon completion, |
| 65 | // even if there are errors while compiling the schema. |
| 66 | currentCompilingNode = prevCompilingNode; |
| 67 | } |
| 68 | return path; |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * Creates a SchemaImpl from the given SchemaOrSchemaFn. |