Sha256: a6b8d61d2d84b7b35068168d4a23dcf1b391c3913c54f7f70caad86b0a2c1525

Contents?: true

Size: 1.29 KB

Versions: 23

Compression:

Stored size: 1.29 KB

Contents

'use strict';

const tokenize = require('postcss/lib/tokenize');

function templateTokenize(input) {
	let pos = input.quasis[0].start;
	const quasis = input.quasis.filter((quasi) => quasi.start !== quasi.end);
	const tokenizer = tokenize.apply(this, arguments);

	function tokenInExpressions(token, returned) {
		const start = pos;

		pos += token[1].length;

		if (
			!quasis.some((quasi) => start >= quasi.start && pos <= quasi.end) ||
			(returned.length && token[0] === returned[0][0])
		) {
			return true;
		} else if (returned.length) {
			back(token);
		}
	}

	function back(token) {
		pos -= token[1].length;

		return tokenizer.back.apply(tokenizer, arguments);
	}

	function nextToken() {
		const args = arguments;
		const returned = [];
		let token;
		let line;
		let column;

		while (
			(token = tokenizer.nextToken.apply(tokenizer, args)) &&
			tokenInExpressions(token, returned)
		) {
			line = token[4] || token[2] || line;
			column = token[5] || token[3] || column;
			returned.push(token);
		}

		if (returned.length) {
			token = [
				returned[0][0],
				returned.map((token) => token[1]).join(''),
				returned[0][2],
				returned[0][3],
				line,
				column,
			];
		}

		return token;
	}

	return Object.assign({}, tokenizer, {
		back,
		nextToken,
	});
}

module.exports = templateTokenize;

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
trusty-cms-5.0.7 node_modules/@stylelint/postcss-css-in-js/template-tokenize.js
trusty-cms-5.0.6 node_modules/@stylelint/postcss-css-in-js/template-tokenize.js
trusty-cms-5.0.5 node_modules/@stylelint/postcss-css-in-js/template-tokenize.js
trusty-cms-5.0.4 node_modules/@stylelint/postcss-css-in-js/template-tokenize.js
trusty-cms-5.0.3 node_modules/@stylelint/postcss-css-in-js/template-tokenize.js
trusty-cms-5.0.2 node_modules/@stylelint/postcss-css-in-js/template-tokenize.js
trusty-cms-5.0.1 node_modules/@stylelint/postcss-css-in-js/template-tokenize.js
trusty-cms-4.3.5 node_modules/@stylelint/postcss-css-in-js/template-tokenize.js
trusty-cms-5.0.0 node_modules/@stylelint/postcss-css-in-js/template-tokenize.js
trusty-cms-4.3.4 node_modules/@stylelint/postcss-css-in-js/template-tokenize.js
trusty-cms-4.3.3 node_modules/@stylelint/postcss-css-in-js/template-tokenize.js
trusty-cms-4.3.2 node_modules/@stylelint/postcss-css-in-js/template-tokenize.js
trusty-cms-4.3.1 node_modules/@stylelint/postcss-css-in-js/template-tokenize.js
trusty-cms-4.3 node_modules/@stylelint/postcss-css-in-js/template-tokenize.js
trusty-cms-4.2.3 node_modules/@stylelint/postcss-css-in-js/template-tokenize.js
trusty-cms-4.2.2 node_modules/@stylelint/postcss-css-in-js/template-tokenize.js
trusty-cms-4.2.1 node_modules/@stylelint/postcss-css-in-js/template-tokenize.js
trusty-cms-4.2 node_modules/@stylelint/postcss-css-in-js/template-tokenize.js
trusty-cms-4.1.9 node_modules/@stylelint/postcss-css-in-js/template-tokenize.js
trusty-cms-4.1.8 node_modules/@stylelint/postcss-css-in-js/template-tokenize.js