<commit_before>namespace $ {

	export function $mol_view_tree_trim_remarks( def : $mol_tree ) {
		return def.transform( ( [ node ] , sub )=> ( node.type === '-' ) ? null : node.clone({ sub : sub() }) )
	}

	export function $mol_view_tree_classes( defs : $mol_tree ) {
		return $mol_view_tree_trim_remarks( defs )
	}

	export function $mol_view_tree_class_name( val : $mol_tree ) {
		return val.type
	}

	export function $mol_view_tree_super_name( val : $mol_tree ) {
		if( val.sub.length != 1 ) throw val.error( 'Wrong sub count' )
		return val.sub[0].type
	}

	export function $mol_view_tree_class_props( def : $mol_tree ) {
		const props : { [ key : string ] : $mol_tree } = {}
		
		const catch_prop = ( prop : $mol_tree )=> {
			if( prop.sub.length === 0 ) return
			if( prop.sub[0].type === '-' ) return
					
			props[ prop.type ] = props[ prop.type ]

			const def = prop.clone({
				sub : [ prop.sub[0].transform( ( [ node , ... stack ] , sub )=> {

					if( [ '<=' , '<=>' , '=>' ].indexOf( node.type ) === -1 ) return node.clone({ sub : sub() })
					
					catch_prop( node.sub[0] )

					return node.clone({
						sub : [ node.sub[0].clone({
							sub : []
						}) ]
					})
					
				} )]
			})

			if( props[ prop.type ] ) {
				if( props[ prop.type ].toString() !== def.toString() ) {
					throw def.error( 'Property already defined with another default value' )
				}
			} else {
				props[ prop.type ] = def
			}
		}

		def.sub[0].sub.map( catch_prop )
		
		return def.clone({
			type : '' ,
			sub : Object.keys( props ).map( name => props[ name ] ) ,
		})

	}

	export function $mol_view_tree_prop_name( prop : $mol_tree ) {
		return ( prop.type.match( /^\w+/ ) || [] )[0] || ''
	}

	export function $mol_view_tree_prop_key( prop : $mol_tree ) {
		return ( prop.type.match( /!(\w+)$/ ) || [] )[1] || ''
	}

	export function $mol_view_tree_prop_next( prop : $mol_tree ) {
		return ( prop.type.match( /\?(\w+)$/ ) || [] )[1] || ''
	}

	export function $mol_view_tree_prop_value( prop : $mol_tree ) {
		if( prop.sub.length != 1 ) throw prop.error( `Wrong sub count (${ prop.sub.length })` )
		return prop.sub[0]
	}

	export function $mol_view_tree_value_type( val : $mol_tree ) {
		
		switch( val.type ) {
			case 'true' : return 'bool'
			case 'false' : return 'bool'
			case 'null' : return 'null'
			case '*' : return 'dict'
			case '/' : return 'list'
			case '@' : return 'locale'
			case '' : return 'string'
			case '<=' : return 'get'
			case '<=>' : return 'bind'
			case '=>' : return 'put'
		}

		if( val.type[0] === '$' ) return 'object'

		if( Number( val.type ).toString() == val.type ) return 'number'

		throw val.error( 'Wrong value' )
	}

	export function $mol_view_tree_compile( tree : $mol_tree ) {
		
		var content = ''
		var locales : { [ key : string ] : string } = {}
		
		for( let def of $mol_view_tree_classes( tree ).sub ) {
			if( !/^\$\w+$/.test( def.type ) ) throw def.error( 'Wrong component name' )
			
			var parent = def.sub[0]
			
			var propDefs : { [ key : string ] : $mol_tree } = {}
			var members : { [ key : string ] : string } = {}
			
			for( let param of $mol_view_tree_class_props( def ).sub ) { try {
				var needSet = false
				var needReturn = true
				var needCache = false
				var keys : string[] = []
	
				if( param.type === '<=>' ) {
					param = param.sub[0]
				}
	
				if( param.type === '<=' ) {
					param = param.sub[0]
				}
				
				var propName = /(.*?)(?:\!(\w+))?(?:\?(\w+))?$/.exec( param.type )
				
				if( propName[3] ) {
					needSet = true
					needCache = true
				}
				
				const getValue = ( value : $mol_tree )=> { try {
					switch( true ) {
						case( value.type === '' ) :
							return JSON.stringify( value.value )
						case( value.type === '@' ) :
							const key = `${ def.type }_${ param.type.replace( /[?!].*/ , '' ) }`
							locales[ key ] = value.value
							return`$mol_locale.text( ${ JSON.stringify( key ) } )`
						case( value.type === '-' ) :
							return null
						case( value.type === '/' ) :
							var items : string[] = []
							value.sub.forEach( item => {
								if( item.type === '-' ) return
								if( item.type === '^' ) {
									items.push( `...super.${ param.type }()` )
									return
								}
								var val = getValue( item )
								if( val ) items.push( val )
							} )
							return '[]' + ( items.length ? '.concat( ' + items.join(' , ') + ' )' : ' as any[]' )
						case( value.type[0] === '$' ) :
							needCache = true
							var overs : string[] = []
							value.sub.forEach( over => {
								if( /^-?$/.test( over.type ) ) return ''
								var overName = /(.*?)(?:\!(\w+))?(?:\?(\w+))?$/.exec( over.type )
								var ns = needSet<commit_msg>$mol_view_tree: use $mol_locale from context.<commit_after>namespace $ {

	export function $mol_view_tree_trim_remarks( def : $mol_tree ) {
		return def.transform( ( [ node ] , sub )=> ( node.type === '-' ) ? null : node.clone({ sub : sub() }) )
	}

	export function $mol_view_tree_classes( defs : $mol_tree ) {
		return $mol_view_tree_trim_remarks( defs )
	}

	export function $mol_view_tree_class_name( val : $mol_tree ) {
		return val.type
	}

	export function $mol_view_tree_super_name( val : $mol_tree ) {
		if( val.sub.length != 1 ) throw val.error( 'Wrong sub count' )
		return val.sub[0].type
	}

	export function $mol_view_tree_class_props( def : $mol_tree ) {
		const props : { [ key : string ] : $mol_tree } = {}
		
		const catch_prop = ( prop : $mol_tree )=> {
			if( prop.sub.length === 0 ) return
			if( prop.sub[0].type === '-' ) return
					
			props[ prop.type ] = props[ prop.type ]

			const def = prop.clone({
				sub : [ prop.sub[0].transform( ( [ node , ... stack ] , sub )=> {

					if( [ '<=' , '<=>' , '=>' ].indexOf( node.type ) === -1 ) return node.clone({ sub : sub() })
					
					catch_prop( node.sub[0] )

					return node.clone({
						sub : [ node.sub[0].clone({
							sub : []
						}) ]
					})
					
				} )]
			})

			if( props[ prop.type ] ) {
				if( props[ prop.type ].toString() !== def.toString() ) {
					throw def.error( 'Property already defined with another default value' )
				}
			} else {
				props[ prop.type ] = def
			}
		}

		def.sub[0].sub.map( catch_prop )
		
		return def.clone({
			type : '' ,
			sub : Object.keys( props ).map( name => props[ name ] ) ,
		})

	}

	export function $mol_view_tree_prop_name( prop : $mol_tree ) {
		return ( prop.type.match( /^\w+/ ) || [] )[0] || ''
	}

	export function $mol_view_tree_prop_key( prop : $mol_tree ) {
		return ( prop.type.match( /!(\w+)$/ ) || [] )[1] || ''
	}

	export function $mol_view_tree_prop_next( prop : $mol_tree ) {
		return ( prop.type.match( /\?(\w+)$/ ) || [] )[1] || ''
	}

	export function $mol_view_tree_prop_value( prop : $mol_tree ) {
		if( prop.sub.length != 1 ) throw prop.error( `Wrong sub count (${ prop.sub.length })` )
		return prop.sub[0]
	}

	export function $mol_view_tree_value_type( val : $mol_tree ) {
		
		switch( val.type ) {
			case 'true' : return 'bool'
			case 'false' : return 'bool'
			case 'null' : return 'null'
			case '*' : return 'dict'
			case '/' : return 'list'
			case '@' : return 'locale'
			case '' : return 'string'
			case '<=' : return 'get'
			case '<=>' : return 'bind'
			case '=>' : return 'put'
		}

		if( val.type[0] === '$' ) return 'object'

		if( Number( val.type ).toString() == val.type ) return 'number'

		throw val.error( 'Wrong value' )
	}

	export function $mol_view_tree_compile( tree : $mol_tree ) {
		
		var content = ''
		var locales : { [ key : string ] : string } = {}
		
		for( let def of $mol_view_tree_classes( tree ).sub ) {
			if( !/^\$\w+$/.test( def.type ) ) throw def.error( 'Wrong component name' )
			
			var parent = def.sub[0]
			
			var propDefs : { [ key : string ] : $mol_tree } = {}
			var members : { [ key : string ] : string } = {}
			
			for( let param of $mol_view_tree_class_props( def ).sub ) { try {
				var needSet = false
				var needReturn = true
				var needCache = false
				var keys : string[] = []
	
				if( param.type === '<=>' ) {
					param = param.sub[0]
				}
	
				if( param.type === '<=' ) {
					param = param.sub[0]
				}
				
				var propName = /(.*?)(?:\!(\w+))?(?:\?(\w+))?$/.exec( param.type )
				
				if( propName[3] ) {
					needSet = true
					needCache = true
				}
				
				const getValue = ( value : $mol_tree )=> { try {
					switch( true ) {
						case( value.type === '' ) :
							return JSON.stringify( value.value )
						case( value.type === '@' ) :
							const key = `${ def.type }_${ param.type.replace( /[?!].*/ , '' ) }`
							locales[ key ] = value.value
							return `this.$.$mol_locale.text( ${ JSON.stringify( key ) } )`
						case( value.type === '-' ) :
							return null
						case( value.type === '/' ) :
							var items : string[] = []
							value.sub.forEach( item => {
								if( item.type === '-' ) return
								if( item.type === '^' ) {
									items.push( `...super.${ param.type }()` )
									return
								}
								var val = getValue( item )
								if( val ) items.push( val )
							} )
							return '[]' + ( items.length ? '.concat( ' + items.join(' , ') + ' )' : ' as any[]' )
						case( value.type[0] === '$' ) :
							needCache = true
							var overs : string[] = []
							value.sub.forEach( over => {
								if( /^-?$/.test( over.type ) ) return ''
								var overName = /(.*?)(?:\!(\w+))?(?:\?(\w+))?$/.exec( over.type )
								var ns = needSet
{'fraction_non_alphanumeric': 0.19713679745493107, 'fraction_numerical': 0.0042417815482502655, 'mean_word_length': 2.2917975567190227, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '463248', 'n_tokens_mistral': 4283, 'n_tokens_neox': 3355, 'n_words': 764}