Skip to content

Commit

Permalink
fix: improvements to malformed !important recognition
Browse files Browse the repository at this point in the history
  • Loading branch information
revelt committed Feb 21, 2021
1 parent cf34cf4 commit 7c9d70b
Show file tree
Hide file tree
Showing 8 changed files with 293 additions and 216 deletions.
2 changes: 1 addition & 1 deletion packages/codsen-tokenizer/coverage/coverage-summary.json
@@ -1 +1 @@
{"total":{"lines":{"total":864,"covered":805,"skipped":0,"pct":93.17},"statements":{"total":892,"covered":831,"skipped":0,"pct":93.16},"functions":{"total":43,"covered":41,"skipped":0,"pct":95.35},"branches":{"total":1390,"covered":1282,"skipped":0,"pct":92.23}}}
{"total":{"lines":{"total":864,"covered":805,"skipped":0,"pct":93.17},"statements":{"total":892,"covered":831,"skipped":0,"pct":93.16},"functions":{"total":43,"covered":41,"skipped":0,"pct":95.35},"branches":{"total":1392,"covered":1284,"skipped":0,"pct":92.24}}}
8 changes: 5 additions & 3 deletions packages/codsen-tokenizer/dist/codsen-tokenizer.cjs.js
Expand Up @@ -1871,7 +1871,9 @@ function tokenizer(str, originalOpts) {
/* istanbul ignore else */


if (!doNothing && property && (property.valueStarts && !property.valueEnds && str[rightVal] !== "!" || property.importantStarts && !property.importantEnds) && (!property.valueEnds || str[rightVal] !== ";") && ( // either end of string was reached
if (!doNothing && property && (property.valueStarts && !property.valueEnds && str[rightVal] !== "!" && ( // either non-whitespace character doesn't exist on the right
!rightVal || // or at that character !important does not start
!str.slice(rightVal).match(importantStartsRegexp)) || property.importantStarts && !property.importantEnds) && (!property.valueEnds || str[rightVal] !== ";") && ( // either end of string was reached
!str[_i] || // or it's a whitespace
!str[_i].trim() || // or it's a semicolon after a value
!property.valueEnds && str[_i] === ";" || // or we reached the end of the attribute
Expand Down Expand Up @@ -1938,7 +1940,7 @@ function tokenizer(str, originalOpts) {
property.importantStarts = _i;
} else if (str[_i] === ";") {
property.semi = _i;
} else if (rightVal && str[rightVal] === "!" || importantStartsRegexp.test(str.slice(_i))) {
} else if (rightVal && str[rightVal] === "!" || str.slice(_i).match(importantStartsRegexp)) {
property.importantStarts = stringLeftRight.right(str, _i);
} else if (!rightVal || str[rightVal] !== ";") {
property.end = stringLeftRight.left(str, _i + 1) + 1;
Expand Down Expand Up @@ -1978,7 +1980,7 @@ function tokenizer(str, originalOpts) {
/* istanbul ignore else */


if (!doNothing && property && property.valueEnds && !property.importantStarts && (str[_i] === "!" || isLatinLetter(str[_i])) && importantStartsRegexp.test(str.slice(_i))) {
if (!doNothing && property && property.valueEnds && !property.importantStarts && (str[_i] === "!" || isLatinLetter(str[_i])) && str.slice(_i).match(importantStartsRegexp)) {
property.importantStarts = _i;
} // catch the start of a css property's value
// -------------------------------------------------------------------------
Expand Down
8 changes: 5 additions & 3 deletions packages/codsen-tokenizer/dist/codsen-tokenizer.dev.umd.js
Expand Up @@ -5410,7 +5410,9 @@ function tokenizer(str, originalOpts) {
/* istanbul ignore else */


if (!doNothing && property && (property.valueStarts && !property.valueEnds && str[rightVal] !== "!" || property.importantStarts && !property.importantEnds) && (!property.valueEnds || str[rightVal] !== ";") && ( // either end of string was reached
if (!doNothing && property && (property.valueStarts && !property.valueEnds && str[rightVal] !== "!" && ( // either non-whitespace character doesn't exist on the right
!rightVal || // or at that character !important does not start
!str.slice(rightVal).match(importantStartsRegexp)) || property.importantStarts && !property.importantEnds) && (!property.valueEnds || str[rightVal] !== ";") && ( // either end of string was reached
!str[_i] || // or it's a whitespace
!str[_i].trim() || // or it's a semicolon after a value
!property.valueEnds && str[_i] === ";" || // or we reached the end of the attribute
Expand Down Expand Up @@ -5477,7 +5479,7 @@ function tokenizer(str, originalOpts) {
property.importantStarts = _i;
} else if (str[_i] === ";") {
property.semi = _i;
} else if (rightVal && str[rightVal] === "!" || importantStartsRegexp.test(str.slice(_i))) {
} else if (rightVal && str[rightVal] === "!" || str.slice(_i).match(importantStartsRegexp)) {
property.importantStarts = right(str, _i);
} else if (!rightVal || str[rightVal] !== ";") {
property.end = left(str, _i + 1) + 1;
Expand Down Expand Up @@ -5517,7 +5519,7 @@ function tokenizer(str, originalOpts) {
/* istanbul ignore else */


if (!doNothing && property && property.valueEnds && !property.importantStarts && (str[_i] === "!" || isLatinLetter(str[_i])) && importantStartsRegexp.test(str.slice(_i))) {
if (!doNothing && property && property.valueEnds && !property.importantStarts && (str[_i] === "!" || isLatinLetter(str[_i])) && str.slice(_i).match(importantStartsRegexp)) {
property.importantStarts = _i;
} // catch the start of a css property's value
// -------------------------------------------------------------------------
Expand Down
8 changes: 5 additions & 3 deletions packages/codsen-tokenizer/dist/codsen-tokenizer.esm.js
Expand Up @@ -1842,7 +1842,9 @@ function tokenizer(str, originalOpts) {
/* istanbul ignore else */


if (!doNothing && property && (property.valueStarts && !property.valueEnds && str[rightVal] !== "!" || property.importantStarts && !property.importantEnds) && (!property.valueEnds || str[rightVal] !== ";") && ( // either end of string was reached
if (!doNothing && property && (property.valueStarts && !property.valueEnds && str[rightVal] !== "!" && ( // either non-whitespace character doesn't exist on the right
!rightVal || // or at that character !important does not start
!str.slice(rightVal).match(importantStartsRegexp)) || property.importantStarts && !property.importantEnds) && (!property.valueEnds || str[rightVal] !== ";") && ( // either end of string was reached
!str[i] || // or it's a whitespace
!str[i].trim() || // or it's a semicolon after a value
!property.valueEnds && str[i] === ";" || // or we reached the end of the attribute
Expand Down Expand Up @@ -1909,7 +1911,7 @@ function tokenizer(str, originalOpts) {
property.importantStarts = i;
} else if (str[i] === ";") {
property.semi = i;
} else if (rightVal && str[rightVal] === "!" || importantStartsRegexp.test(str.slice(i))) {
} else if (rightVal && str[rightVal] === "!" || str.slice(i).match(importantStartsRegexp)) {
property.importantStarts = right(str, i);
} else if (!rightVal || str[rightVal] !== ";") {
property.end = left(str, i + 1) + 1;
Expand Down Expand Up @@ -1949,7 +1951,7 @@ function tokenizer(str, originalOpts) {
/* istanbul ignore else */


if (!doNothing && property && property.valueEnds && !property.importantStarts && (str[i] === "!" || isLatinLetter(str[i])) && importantStartsRegexp.test(str.slice(i))) {
if (!doNothing && property && property.valueEnds && !property.importantStarts && (str[i] === "!" || isLatinLetter(str[i])) && str.slice(i).match(importantStartsRegexp)) {
property.importantStarts = i;
} // catch the start of a css property's value
// -------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion packages/codsen-tokenizer/dist/codsen-tokenizer.mjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/codsen-tokenizer/dist/codsen-tokenizer.umd.js

Large diffs are not rendered by default.

0 comments on commit 7c9d70b

Please sign in to comment.