Skip to content

Commit

Permalink
Merge pull request #617 from junaidrsd/variable-declaration
Browse files Browse the repository at this point in the history
Saving variables should only change variable declarations
  • Loading branch information
hannu committed May 18, 2015
2 parents 75cfbbd + f8c5129 commit 9b9ec20
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/modules/variable-writer.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ var gonzales = require('gonzales-pe'),
});
if (isThisVariable) {
node.map(function(nnode) {
if (nnode.type === 'value') {
if (nnode.type === 'value' && nnode.content[0].type !== 'variable') {
nnode.content = [{
type: 'string',
content: variable.value
Expand Down
49 changes: 49 additions & 0 deletions test/unit/modules/variable-writer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,30 @@ describe('Variable Writer', function() {

describe('for SCSS syntax', function() {

it('should only change variable declaration', function() {
var str = multiline(function() {
/*
$primary-color: #fdf70a;
.foo {
background-color: $primary-color;
}
*/
}),
variables = [
{name: 'primary-color', value: '#00ff00'}
],
result = multiline(function() {
/*
$primary-color: #00ff00;
.foo {
background-color: $primary-color;
}
*/
}),
changed = writer.setVariables(str, 'scss', variables);
expect(changed).eql(result);
});

it('should change single value variable', function() {
var str = multiline(function() {
/*
Expand Down Expand Up @@ -115,6 +139,31 @@ describe('Variable Writer', function() {
});

describe('for LESS syntax', function() {

it('should only change variable declaration', function() {
var str = multiline(function() {
/*
@primary-color: #fdf70a;
.foo {
background-color: @primary-color;
}
*/
}),
variables = [
{name: 'primary-color', value: '#00ff00'}
],
result = multiline(function() {
/*
@primary-color: #00ff00;
.foo {
background-color: @primary-color;
}
*/
}),
changed = writer.setVariables(str, 'less', variables);
expect(changed).eql(result);
});

it('should change single value variable', function() {
var str = multiline(function() {
/*
Expand Down

0 comments on commit 9b9ec20

Please sign in to comment.