index.js
function getViewRoot(source) {
	const tokens = parse(source);

	let position = tokens.length;
	let tagDepth = 0;
	let tagName;
	let token;

	/**
	 * Loop backwards through the view's source and find the last closing tag
	 * and its matching opening tag to determine the view's root node position.
	 */
	while (token = tokens[--position]) {
		if (token.type !== TokenTypes.TagStart) {
			continue;
		}

		let tag = parseTag(position, tokens);

		// the last node in the source is a self-closing tag; use that
		if (!tagName && tag.self) {
			break;
		}

		// this is the last tag in the source; save the name and find its pair
		if (!tagName) {
			tagName = tag.name;
			tagDepth++;
			continue;
		}

		// ignore any tags with a different name
		if (tag.name !== tagName) {
			continue;
		}

		// increase tags' depth in the tree for closing tags
		if (!tag.open) {
			tagDepth++;
		}

		// decrease tags' depth in the tree for opening (not self-closing) tags
		if (tag.open && !tag.self) {
			tagDepth--;
		}

		// if the tag's depth reached 0, it means this is the opening tag
		if (tagDepth === 0) {
			break;
		}
	}

	token = tokens[position];

	return token ? token.start : 0;
}
function getViewRoot(source) {
	const tokens = parse(source);

	let position = tokens.length;
	let tagDepth = 0;
	let tagName;
	let token;

	/**
	 * Loop backwards through the view's source and find the last closing tag
	 * and its matching opening tag to determine the view's root node position.
	 */
	while (token = tokens[--position]) {
		if (token.type !== TokenTypes.TagStart) {
			continue;
		}

		let tag = parseTag(position, tokens);

		// the last node in the source is a self-closing tag; use that
		if (!tagName && tag.self) {
			break;
		}

		// this is the last tag in the source; save the name and find its pair
		if (!tagName) {
			tagName = tag.name;
			tagDepth++;
			continue;
		}

		// ignore any tags with a different name
		if (tag.name !== tagName) {
			continue;
		}

		// increase tags' depth in the tree for closing tags
		if (!tag.open) {
			tagDepth++;
		}

		// decrease tags' depth in the tree for opening (not self-closing) tags
		if (tag.open && !tag.self) {
			tagDepth--;
		}

		// if the tag's depth reached 0, it means this is the opening tag
		if (tagDepth === 0) {
			break;
		}
	}

	token = tokens[position];

	return token ? token.start : 0;
}
function getViewRoot ( source ) { const tokens = parse ( source ) ; let position = tokens . length ; let tagDepth = 0 ; let tagName ; let token ; /**
	 * Loop backwards through the view's source and find the last closing tag
	 * and its matching opening tag to determine the view's root node position.
	 */ while ( token = tokens [ -- position ] ) { if ( token . type !== TokenTypes . TagStart ) { continue ; } let tag = parseTag ( position , tokens ) ; // the last node in the source is a self-closing tag; use that if ( ! tagName && tag . self ) { break ; } // this is the last tag in the source; save the name and find its pair if ( ! tagName ) { tagName = tag . name ; tagDepth ++ ; continue ; } // ignore any tags with a different name if ( tag . name !== tagName ) { continue ; } // increase tags' depth in the tree for closing tags if ( ! tag . open ) { tagDepth ++ ; } // decrease tags' depth in the tree for opening (not self-closing) tags if ( tag . open && ! tag . self ) { tagDepth -- ; } // if the tag's depth reached 0, it means this is the opening tag if ( tagDepth === 0 ) { break ; } } token = tokens [ position ] ; return token ? token . start : 0 ; }
Finds the position of the opening JSX tag in the source code.
Finds the position of the opening JSX tag in the source code .