<commit_before>import { getKey, getKeypath, normalise } from 'shared/keypaths';
import getInnerContext from 'shared/getInnerContext';

export default function resolveRef ( ractive, ref, fragment ) {
	var keypath;

	ref = normalise( ref );

	// If a reference begins '~/', it's a top-level reference
	if ( ref.substr( 0, 2 ) === '~/' ) {
		keypath = ref.substring( 2 );
		createMappingIfNecessary( ractive, getKey( keypath ), fragment );
	}

	// If a reference begins with '.', it's either a restricted reference or
	// an ancestor reference...
	else if ( ref[0] === '.' ) {
		keypath = resolveAncestorRef( getInnerContext( fragment ), ref );

		if ( keypath ) {
			createMappingIfNecessary( ractive, getKey( keypath ), fragment );
		}
	}

	// ...otherwise we need to figure out the keypath based on context
	else {
		keypath = resolveAmbiguousReference( ractive, ref, fragment );
	}

	return keypath;
}

function resolveAncestorRef ( baseContext, ref ) {
	var contextKeys;

	// TODO...
	if ( typeof baseContext !== 'string' ) {
		baseContext = baseContext.str;
	}

	// {{.}} means 'current context'
	if ( ref === '.' ) return baseContext;

	contextKeys = baseContext ? baseContext.split( '.' ) : [];

	// ancestor references (starting "../") go up the tree
	if ( ref.substr( 0, 3 ) === '../' ) {
		while ( ref.substr( 0, 3 ) === '../' ) {<commit_msg>small fix<commit_after>import { getKey, getKeypath, normalise } from 'shared/keypaths';
import getInnerContext from 'shared/getInnerContext';

export default function resolveRef ( ractive, ref, fragment ) {
	var keypath;

	ref = normalise( ref );

	// If a reference begins '~/', it's a top-level reference
	if ( ref.substr( 0, 2 ) === '~/' ) {
		keypath = ref.substring( 2 );
		createMappingIfNecessary( ractive, getKey( keypath ), fragment );
	}

	// If a reference begins with '.', it's either a restricted reference or
	// an ancestor reference...
	else if ( ref[0] === '.' ) {
		keypath = resolveAncestorRef( getInnerContext( fragment ), ref );

		if ( keypath ) {
			createMappingIfNecessary( ractive, getKey( keypath ), fragment );
		}
	}

	// ...otherwise we need to figure out the keypath based on context
	else {
		keypath = resolveAmbiguousReference( ractive, ref, fragment );
	}

	return keypath;
}

function resolveAncestorRef ( baseContext, ref ) {
	var contextKeys;

	// TODO...
	if ( baseContext != undefined && typeof baseContext !== 'string' ) {
		baseContext = baseContext.str;
	}

	// {{.}} means 'current context'
	if ( ref === '.' ) return baseContext;

	contextKeys = baseContext ? baseContext.split( '.' ) : [];

	// ancestor references (starting "../") go up the tree
	if ( ref.substr( 0, 3 ) === '../' ) {
		while ( ref.substr( 0, 3 ) === '../' ) {
{'fraction_non_alphanumeric': 0.15491923641703378, 'fraction_numerical': 0.005873715124816446, 'mean_word_length': 3.3810289389067525, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '7524376', 'n_tokens_mistral': 951, 'n_tokens_neox': 852, 'n_words': 259}