Skip to content

Commit 3463c6d

Browse files
committed
Can parse CSS rule code contexts, too.
1 parent 9573b68 commit 3463c6d

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

index.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,13 @@ var scssContextParser = (function () {
147147
end : lineNumberFor(endIndex) + 1
148148
};
149149
}
150+
} else {
151+
var codeStart = ctxCode.indexOf('{');
152+
if (codeStart > 0) {
153+
context.type = 'css';
154+
context.name = ctxCode.slice(0, codeStart).trim();
155+
context.value = extractCode(ctxCode, codeStart).trim();
156+
}
150157
}
151158

152159
return context;

test/fixtures/rule.test.scss

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.foo {
2+
font-weight: bold;
3+
color: red;
4+
.bar {
5+
color: blue;
6+
}
7+
}

test/test.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,17 @@ describe('ScssCommentParser', function () {
137137
});
138138
});
139139

140+
describe('css rule', function(){
141+
it('should detect it', function(){
142+
var context = parser.contextParser(getContent('rule.test.scss'));
143+
assert.deepEqual(context, {
144+
type: 'css',
145+
name: '.foo',
146+
value: 'font-weight: bold;\n color: red;\n .bar {\n color: blue;\n }'
147+
});
148+
});
149+
});
150+
140151
describe('unknown', function(){
141152
it('should assing unknown', function(){
142153
var context = parser.contextParser(getContent('unknown.test.scss'));
@@ -209,4 +220,4 @@ describe('ScssCommentParser', function () {
209220
assert.equal(parser.extractCode('{{ /* }} */ }}'), '{ /* }} */ }');
210221
});
211222
});
212-
});
223+
});

0 commit comments

Comments
 (0)