Skip to content
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

Fix tokenization of unquoted imports #7

Merged
merged 1 commit into from
Jan 29, 2017
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
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'))
);
});
});