Sha256: 757789234cd57586e41c838435679c0523d6657812c94688a113457f1e7236e5

Contents?: true

Size: 697 Bytes

Versions: 4

Compression:

Stored size: 697 Bytes

Contents

import Node from '../Node.js';

function containsNewLine(node) {
	return (
		node.type === 'JSXText' && !/\S/.test(node.value) && /\n/.test(node.value)
	);
}

export default class JSXClosingElement extends Node {
	transpile(code) {
		let spaceBeforeParen = true;

		const lastChild = this.parent.children[this.parent.children.length - 1];

		// omit space before closing paren if
		//   a) this is on a separate line, or
		//   b) there are no children but there are attributes
		if (
			(lastChild && containsNewLine(lastChild)) ||
			this.parent.openingElement.attributes.length
		) {
			spaceBeforeParen = false;
		}

		code.overwrite(this.start, this.end, spaceBeforeParen ? ' )' : ')');
	}
}

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
jass-0.9.5 vendor/node_modules/buble/src/program/types/JSXClosingElement.js
jass-0.9.4 vendor/node_modules/buble/src/program/types/JSXClosingElement.js
jass-0.9.3 vendor/node_modules/buble/src/program/types/JSXClosingElement.js
jass-0.9.1 vendor/node_modules/buble/src/program/types/JSXClosingElement.js