Skip to content

Commit

Permalink
[css|less|sass|scss] Deep combinator support
Browse files Browse the repository at this point in the history
bgriffith committed Aug 28, 2017
1 parent bb76e64 commit b6278f8
Showing 24 changed files with 967 additions and 33 deletions.
60 changes: 51 additions & 9 deletions src/css/parse.js
Original file line number Diff line number Diff line change
@@ -961,6 +961,7 @@ function checkCombinator(i) {
if (l = checkCombinator1(i)) tokens[i].combinatorType = 1;
else if (l = checkCombinator2(i)) tokens[i].combinatorType = 2;
else if (l = checkCombinator3(i)) tokens[i].combinatorType = 3;
else if (l = checkCombinator4(i)) tokens[i].combinatorType = 4;

return l;
}
@@ -970,16 +971,48 @@ function getCombinator() {
if (type === 1) return getCombinator1();
if (type === 2) return getCombinator2();
if (type === 3) return getCombinator3();
if (type === 3) return getCombinator4();
}

/**
* (1) `>>>`
*
* @param {Number} i
* @return {Number}
*/
function checkCombinator1(i) {
if (i < tokensLength && tokens[i++].type === TokenType.GreaterThanSign &&
i < tokensLength && tokens[i++].type === TokenType.GreaterThanSign &&
i < tokensLength && tokens[i++].type === TokenType.GreaterThanSign)
return 3;

return 0;
}

/**
* @return {Node}
*/
function getCombinator1() {
const type = NodeType.CombinatorType;
const token = tokens[pos];
const line = token.ln;
const column = token.col;
const content = `>>>`;

// Skip combinator
pos += 3;

return newNode(type, content, line, column);
}

/**
* (1) `||`
* (2) `>>`
*
* @param {number} i
* @return {number}
* @param {Number} i
* @return {Number}
*/
function checkCombinator1(i) {
function checkCombinator2(i) {
if (i + 1 >= tokensLength) return 0;

if (tokens[i].type === TokenType.VerticalLine &&
@@ -992,9 +1025,9 @@ function checkCombinator1(i) {
}

/**
* @return {!Node}
* @return {Node}
*/
function getCombinator1() {
function getCombinator2() {
const type = NodeType.CombinatorType;
const token = tokens[pos];
const line = token.ln;
@@ -1011,16 +1044,22 @@ function getCombinator1() {
* (1) `>`
* (2) `+`
* (3) `~`
*
* @param {Number} i
* @return {Number}
*/
function checkCombinator2(i) {
function checkCombinator3(i) {
const type = tokens[i].type;
if (type === TokenType.PlusSign ||
type === TokenType.GreaterThanSign ||
type === TokenType.Tilde) return 1;
else return 0;
}

function getCombinator2() {
/**
* @return {Node}
*/
function getCombinator3() {
const type = NodeType.CombinatorType;
const token = tokens[pos];
const line = token.ln;
@@ -1036,7 +1075,7 @@ function getCombinator2() {
/**
* (1) `/panda/`
*/
function checkCombinator3(i) {
function checkCombinator4(i) {
const start = i;

if (tokens[i].type === TokenType.Solidus) i++;
@@ -1052,7 +1091,10 @@ function checkCombinator3(i) {
return i - start;
}

function getCombinator3() {
/**
* @return {Node}
*/
function getCombinator4() {
const type = NodeType.CombinatorType;
const token = tokens[pos];
const line = token.ln;
61 changes: 52 additions & 9 deletions src/less/parse.js
Original file line number Diff line number Diff line change
@@ -1072,6 +1072,7 @@ function checkCombinator(i) {
if (l = checkCombinator1(i)) tokens[i].combinatorType = 1;
else if (l = checkCombinator2(i)) tokens[i].combinatorType = 2;
else if (l = checkCombinator3(i)) tokens[i].combinatorType = 3;
else if (l = checkCombinator4(i)) tokens[i].combinatorType = 4;

return l;
}
@@ -1081,16 +1082,49 @@ function getCombinator() {
if (type === 1) return getCombinator1();
if (type === 2) return getCombinator2();
if (type === 3) return getCombinator3();
if (type === 3) return getCombinator4();
}


/**
* (1) `>>>`
*
* @param {Number} i
* @return {Number}
*/
function checkCombinator1(i) {
if (i < tokensLength && tokens[i++].type === TokenType.GreaterThanSign &&
i < tokensLength && tokens[i++].type === TokenType.GreaterThanSign &&
i < tokensLength && tokens[i++].type === TokenType.GreaterThanSign)
return 3;

return 0;
}

/**
* @return {Node}
*/
function getCombinator1() {
const type = NodeType.CombinatorType;
const token = tokens[pos];
const line = token.ln;
const column = token.col;
const content = `>>>`;

// Skip combinator
pos += 3;

return newNode(type, content, line, column);
}

/**
* (1) `||`
* (2) `>>`
*
* @param {number} i
* @return {number}
* @param {Number} i
* @return {Number}
*/
function checkCombinator1(i) {
function checkCombinator2(i) {
if (i + 1 >= tokensLength) return 0;

if (tokens[i].type === TokenType.VerticalLine &&
@@ -1103,9 +1137,9 @@ function checkCombinator1(i) {
}

/**
* @return {!Node}
* @return {Node}
*/
function getCombinator1() {
function getCombinator2() {
const type = NodeType.CombinatorType;
const token = tokens[pos];
const line = token.ln;
@@ -1122,16 +1156,22 @@ function getCombinator1() {
* (1) `>`
* (2) `+`
* (3) `~`
*
* @param {Number} i
* @return {Number}
*/
function checkCombinator2(i) {
function checkCombinator3(i) {
const type = tokens[i].type;
if (type === TokenType.PlusSign ||
type === TokenType.GreaterThanSign ||
type === TokenType.Tilde) return 1;
else return 0;
}

function getCombinator2() {
/**
* @return {Node}
*/
function getCombinator3() {
const type = NodeType.CombinatorType;
const token = tokens[pos];
const line = token.ln;
@@ -1147,7 +1187,7 @@ function getCombinator2() {
/**
* (1) `/panda/`
*/
function checkCombinator3(i) {
function checkCombinator4(i) {
const start = i;

if (tokens[i].type === TokenType.Solidus) i++;
@@ -1163,7 +1203,10 @@ function checkCombinator3(i) {
return i - start;
}

function getCombinator3() {
/**
* @return {Node}
*/
function getCombinator4() {
const type = NodeType.CombinatorType;
const token = tokens[pos];
const line = token.ln;
51 changes: 45 additions & 6 deletions src/sass/parse.js
Original file line number Diff line number Diff line change
@@ -1299,6 +1299,7 @@ function checkCombinator(i) {
if (l = checkCombinator1(i)) tokens[i].combinatorType = 1;
else if (l = checkCombinator2(i)) tokens[i].combinatorType = 2;
else if (l = checkCombinator3(i)) tokens[i].combinatorType = 3;
else if (l = checkCombinator4(i)) tokens[i].combinatorType = 4;

return l;
}
@@ -1311,6 +1312,38 @@ function getCombinator() {
if (type === 1) return getCombinator1();
if (type === 2) return getCombinator2();
if (type === 3) return getCombinator3();
if (type === 3) return getCombinator4();
}

/**
* (1) `>>>`
*
* @param {Number} i
* @return {Number}
*/
function checkCombinator1(i) {
if (i < tokensLength && tokens[i++].type === TokenType.GreaterThanSign &&
i < tokensLength && tokens[i++].type === TokenType.GreaterThanSign &&
i < tokensLength && tokens[i++].type === TokenType.GreaterThanSign)
return 3;

return 0;
}

/**
* @return {Node}
*/
function getCombinator1() {
const type = NodeType.CombinatorType;
const token = tokens[pos];
const line = token.ln;
const column = token.col;
const content = `>>>`;

// Skip combinator
pos += 3;

return newNode(type, content, line, column);
}

/**
@@ -1320,7 +1353,7 @@ function getCombinator() {
* @param {number} i
* @return {number}
*/
function checkCombinator1(i) {
function checkCombinator2(i) {
if (i + 1 >= tokensLength) return 0;

if (tokens[i].type === TokenType.VerticalLine &&
@@ -1335,7 +1368,7 @@ function checkCombinator1(i) {
/**
* @return {!Node}
*/
function getCombinator1() {
function getCombinator2() {
const type = NodeType.CombinatorType;
const token = tokens[pos];
const line = token.ln;
@@ -1356,15 +1389,18 @@ function getCombinator1() {
* @param {number} i
* @return {number}
*/
function checkCombinator2(i) {
function checkCombinator3(i) {
const type = tokens[i].type;
if (type === TokenType.PlusSign ||
type === TokenType.GreaterThanSign ||
type === TokenType.Tilde) return 1;
else return 0;
}

function getCombinator2() {
/**
* @return {Node}
*/
function getCombinator3() {
const type = NodeType.CombinatorType;
const token = tokens[pos];
const line = token.ln;
@@ -1380,7 +1416,7 @@ function getCombinator2() {
/**
* (1) `/panda/`
*/
function checkCombinator3(i) {
function checkCombinator4(i) {
const start = i;

if (tokens[i].type === TokenType.Solidus) i++;
@@ -1396,7 +1432,10 @@ function checkCombinator3(i) {
return i - start;
}

function getCombinator3() {
/**
* @return {Node}
*/
function getCombinator4() {
const type = NodeType.CombinatorType;
const token = tokens[pos];
const line = token.ln;
Loading

0 comments on commit b6278f8

Please sign in to comment.