MCPcopy Create free account
hub / github.com/arktypeio/arktype / compileDefault

Function compileDefault

ark/schema/structure/structure.ts:1788–1811  ·  view source on GitHub ↗
(
	js: NodeCompiler,
	node: Optional.Node.withDefault,
	out: string,
	isPlain = false
)

Source from the content-addressed store, hash-verified

1786 : `Object.getPrototypeOf(${target}) === Object.prototype ? (${target}${js.prop(key)} = ${value}) : ${js.ref(setOwnValue)}(${target}, ${js.serialize(key)}, ${value})`
1787
1788export const compileDefault = (
1789 js: NodeCompiler,
1790 node: Optional.Node.withDefault,
1791 out: string,
1792 isPlain = false
1793): NodeCompiler => {
1794 if (hasPlainDefault(node)) {
1795 return js.line(
1796 jsSetOwnProp(
1797 js,
1798 out,
1799 node.key,
1800 serializeDefault(js, node.default),
1801 isPlain
1802 )
1803 )
1804 }
1805 return compileDefaultMorph(
1806 js,
1807 node,
1808 `${js.ref(node.defMorph)}(${out}${node.defMorph.length === 2 ? ", ctx" : ""})`,
1809 out
1810 )
1811}
1812
1813// one compileDefault writes as a value, calling nothing
1814const hasPlainDefault = (node: Prop.Node): boolean =>

Callers 3

jsCopyOnceMethod · 0.85
jsDefaultsMethod · 0.85
jsDeleteTransformMethod · 0.85

Calls 6

hasPlainDefaultFunction · 0.85
jsSetOwnPropFunction · 0.85
serializeDefaultFunction · 0.85
compileDefaultMorphFunction · 0.85
lineMethod · 0.80
refMethod · 0.45

Tested by

no test coverage detected