Skip to content

Commit

Permalink
Merge pull request #7 from sasstools/fix-uuquoted-import-path
Browse files Browse the repository at this point in the history
Fix tokenization of unquoted imports
  • Loading branch information
xzyfer authored Jan 29, 2017
2 parents adad62c + c9766b3 commit be165db
Show file tree
Hide file tree
Showing 8 changed files with 112 additions and 1 deletion.
1 change: 0 additions & 1 deletion lib/tokenize.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,6 @@ export default function tokenize(input, l, p) {

if ( code === slash && css.charCodeAt(pos + 1) !== slash ) {
tokens.push(['/', '/', line, pos - offset]);
pos += 2;
break;
}

Expand Down
1 change: 1 addition & 0 deletions test/fixture/double-quoted-import-path.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@import "foo/bar";
1 change: 1 addition & 0 deletions test/fixture/double-quoted-import.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@import "foo";
1 change: 1 addition & 0 deletions test/fixture/single-quoted-import-path.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@import 'foo/bar';
1 change: 1 addition & 0 deletions test/fixture/single-quoted-import.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@import 'foo';
1 change: 1 addition & 0 deletions test/fixture/unquoted-import-path.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@import foo/bar;
1 change: 1 addition & 0 deletions test/fixture/unquoted-import.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@import foo;
106 changes: 106 additions & 0 deletions test/import.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
var scss = require('..');
var fs = require('fs');
var path = require('path');
var assert = require('chai').assert;

var fixture = function(name) {
return fs.readFileSync(
path.join(__dirname, 'fixture', name)
);
}

describe('@import', function() {
it('should tokenize a @import with double quotes', function() {
assert.deepEqual(
[
['@', '@', 1, 1],
['ident', 'import', 1, 2, 1, 7],
['space', ' '],
['"', '"', 1, 9],
['string', 'foo', 1, 10, 1, 12],
['"', '"', 1, 13],
[';', ';', 1, 14],
['newline', '\n', 2, 0],
],
scss.tokenize(fixture('double-quoted-import.scss'))
);
});

it('should tokenize a @import with single quotes', function() {
assert.deepEqual(
[
['@', '@', 1, 1],
['ident', 'import', 1, 2, 1, 7],
['space', ' '],
['\'', '\'', 1, 9],
['string', 'foo', 1, 10, 1, 12],
['\'', '\'', 1, 13],
[';', ';', 1, 14],
['newline', '\n', 2, 0],
],
scss.tokenize(fixture('single-quoted-import.scss'))
);
});

it('should tokenize a @import without quotes', function() {
assert.deepEqual(
[
['@', '@', 1, 1],
['ident', 'import', 1, 2, 1, 7],
['space', ' '],
['ident', 'foo', 1, 9, 1, 11],
[';', ';', 1, 12],
['newline', '\n', 2, 0],
],
scss.tokenize(fixture('unquoted-import.scss'))
);
});

it('should tokenize a @import with double quotes and slash', function() {
assert.deepEqual(
[
['@', '@', 1, 1],
['ident', 'import', 1, 2, 1, 7],
['space', ' '],
['"', '"', 1, 9],
['string', 'foo/bar', 1, 10, 1, 16],
['"', '"', 1, 17],
[';', ';', 1, 18],
['newline', '\n', 2, 0],
],
scss.tokenize(fixture('double-quoted-import-path.scss'))
);
});

it('should tokenize a @import with single quotes and slash', function() {
assert.deepEqual(
[
['@', '@', 1, 1],
['ident', 'import', 1, 2, 1, 7],
['space', ' '],
['\'', '\'', 1, 9],
['string', 'foo/bar', 1, 10, 1, 16],
['\'', '\'', 1, 17],
[';', ';', 1, 18],
['newline', '\n', 2, 0],
],
scss.tokenize(fixture('single-quoted-import-path.scss'))
);
});

it('should tokenize a @import without quotes and slash', function() {
assert.deepEqual(
[
['@', '@', 1, 1],
['ident', 'import', 1, 2, 1, 7],
['space', ' '],
['ident', 'foo', 1, 9, 1, 11],
['/', '/', 1, 12],
['ident', 'bar', 1, 13, 1, 15],
[';', ';', 1, 16],
['newline', '\n', 2, 0],
],
scss.tokenize(fixture('unquoted-import-path.scss'))
);
});
});

0 comments on commit be165db

Please sign in to comment.