Skip to content

a couple of fixes following 0.3.0 release #55

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 27, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 57 additions & 46 deletions lib/build/node-sass.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,54 +146,65 @@ module.exports = function (bannerWidth, libraryPaths) {
function reworkPlugin(stylesheet) {

// visit each node (selector) in the stylesheet recursively using the official utility method
visit(stylesheet, function (declarations) {

// each node may have multiple declarations
declarations.forEach(function (declaration) {

// reverse the original source-map to find the original sass file
var cssStart = declaration.position.start;
var sassStart = sourceMapConsumer.originalPositionFor({
line: cssStart.line,
column: cssStart.column
});
if (!sassStart.source) {
throw new Error('failed to decode node-sass source map'); // this can occur with regressions in libsass
// each node may have multiple declarations
visit(stylesheet, function visitor(declarations) {
declarations
.forEach(eachDeclaration);
});

/**
* Process a declaration from the syntax tree.
* @param declaration
*/
function eachDeclaration(declaration) {
var URL_STATEMENT_REGEX = /(url\s*\()\s*(?:(['"])((?:(?!\2).)*)(\2)|([^'"](?:(?!\)).)*[^'"]))\s*(\))/g;

// reverse the original source-map to find the original sass file
var cssStart = declaration.position.start;
var sassStart = sourceMapConsumer.originalPositionFor({
line : cssStart.line,
column: cssStart.column
});
if (!sassStart.source) {
throw new Error('failed to decode node-sass source map'); // this can occur with regressions in libsass
}
var sassDir = path.dirname(sassStart.source);

// allow multiple url() values in the declaration
// split by url statements and process the content
// additional capture groups are needed to match quotations correctly
// escaped quotations are not considered
declaration.value = declaration.value
.split(URL_STATEMENT_REGEX)
.map(eachSplitOrGroup)
.join('');

/**
* Encode the content portion of <code>url()</code> statements.
* There are 4 capture groups in the split making every 5th unmatched.
* @param {string} token A single split item
* @param i The index of the item in the split
* @returns {string} Every 3 or 5 items is an encoded url everything else is as is
*/
function eachSplitOrGroup(token, i) {

// we can get groups as undefined under certain match circumstances
var initialised = token || '';

// the content of the url() statement is either in group 3 or group 5
var mod = i % 7;
if ((mod === 3) || (mod === 5)) {

// remove query string or hash suffix
var uri = initialised.split(/[?#]/g).shift();
return uri && encodeRelativeURL(sassDir, uri) || initialised;
}
var sassDir = path.dirname(sassStart.source);

// allow multiple url() values in the declaration
// split by url statements and process the content
// additional capture groups are needed to match quotations correctly
// escaped quotations are not considered
declaration.value = declaration.value
.split(/(url\s*\(\s*)(['"]?)((?:(?!\2|\?|#]).)*(?:(?!\2).)*)(\2\s*\))/g)
.map(eachSplitOrGroup)
.join('');

/**
* Encode the content portion of <code>url()</code> statements.
* There are 4 capture groups in the split making every 5th unmatched.
* @param {string} token A single split item
* @param i The index of the item in the split
* @returns {string} Every 3 or 5 items is an encoded url everything else is as is
*/
function eachSplitOrGroup(token, i) {

// the quoted or unquoted content of the url() statement
if (i % 5 === 3) {

// remove query string or hash suffix
var uri = token.split(/[?#]/g).shift();
return encodeRelativeURL(sassDir, uri) || token;
}
// everything else, including parentheses and quotation (where present) and media statements
else {
return token;
}
// everything else, including parentheses and quotation (where present) and media statements
else {
return initialised;
}
});
});
}
}
}

/**
Expand Down
14 changes: 7 additions & 7 deletions npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "angularity",
"description": "An opinionated NodeJs build system for ECMAScript 6 AngularJs projects",
"version": "0.3.0",
"version": "0.3.1",
"tags": [
"build",
"system",
Expand Down Expand Up @@ -112,7 +112,7 @@
},
"devDependencies": {
"angularity-helloworld-es5": "angularity/angularity-helloworld-es5#ci-build-0.2.0-E",
"angularity-todo-es5": "angularity/angularity-todo-es5#ci-build-0.2.0-E",
"angularity-todo-es5": "angularity/angularity-todo-es5#ci-build-0.2.0-F",
"autodocs": "^0.6.8",
"jasmine-diff-matchers": "~2.0.0",
"jasmine-node": "2.0.0-beta4",
Expand Down