Skip to content

Commit

Permalink
Merge pull request #330 from niftylettuce/master
Browse files Browse the repository at this point in the history
fix: fixed core bug with getPreservedText (closes #328)
  • Loading branch information
jrit authored Mar 19, 2019
2 parents e3646e5 + 6eae36c commit 8e025ef
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions lib/inline.js
Original file line number Diff line number Diff line change
Expand Up @@ -352,8 +352,8 @@ function getStylesData($, options) {
mediaQueries: options.preserveMediaQueries,
fontFaces: options.preserveFontFaces,
keyFrames: options.preserveKeyFrames,
pseudos: juiceClient.ignoredPseudos
});
pseudos: options.preservePseudos
}, juiceClient.ignoredPseudos);
if (preservedText) {
styleElement.childNodes[0].nodeValue = preservedText;
} else {
Expand Down
4 changes: 2 additions & 2 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ exports.parseCSS = function(css) {
* @api public
*/

exports.getPreservedText = function(css, options) {
exports.getPreservedText = function(css, options, ignoredPseudos) {
var parsed = mensch.parse(css, {position: true, comments: true});
var rules = typeof parsed.stylesheet != 'undefined' && parsed.stylesheet.rules ? parsed.stylesheet.rules : [];
var preserved = [];
Expand All @@ -95,7 +95,7 @@ exports.getPreservedText = function(css, options) {
if ((options.fontFaces && rules[i].type === 'font-face') ||
(options.mediaQueries && rules[i].type === 'media') ||
(options.keyFrames && rules[i].type === 'keyframes') ||
(options.pseudos && rules[i].selectors && this.matchesPseudo(rules[i].selectors[0], options.pseudos))) {
(options.pseudos && rules[i].selectors && this.matchesPseudo(rules[i].selectors[0], ignoredPseudos))) {
preserved.unshift(
mensch.stringify(
{ stylesheet: { rules: [ rules[i] ] }},
Expand Down
4 changes: 2 additions & 2 deletions test/juice.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,6 @@ it('test style attributes and important priority', function() {

it('test that preserved text order is stable', function() {
assert.deepEqual(
utils.getPreservedText('div { color: red; } @media (min-width: 320px) { div { color: green; } } @media (max-width: 640px) { div { color: blue; } }', { mediaQueries: true }).replace(/\s+/g, ' '),
utils.getPreservedText('div { color: red; } @media (min-width: 320px) { div { color: green; } } @media (max-width: 640px) { div { color: blue; } }', { mediaQueries: true }, juice.ignoredPseudos).replace(/\s+/g, ' '),
' @media (min-width: 320px) { div { color: green; } } @media (max-width: 640px) { div { color: blue; } } ');
});
});

0 comments on commit 8e025ef

Please sign in to comment.