Skip to content

Commit

Permalink
~在选择器中不是hack类型还是sign类型
Browse files Browse the repository at this point in the history
  • Loading branch information
army8735 committed Jun 11, 2015
1 parent 9478ef2 commit 3504cbe
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 9 deletions.
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "homunculus",
"version": "0.9.7",
"version": "0.9.8",
"description": "A lexer&parser by Javascript",
"maintainers": [
{
Expand Down Expand Up @@ -59,14 +59,14 @@
"readmeFilename": "README.md",
"devDependencies": {
"blanket": "^1.1.6",
"coveralls": "^2.10.0",
"coveralls": "^2.11.2",
"expect.js": "^0.3.1",
"gulp": "^3.8.1",
"gulp": "^3.8.11",
"gulp-clean": "^0.2.4",
"gulp-util": "^2.2.14",
"mocha": "^1.18.2",
"mocha-lcov-reporter": "0.0.1",
"through2": "^0.4.2",
"gulp-util": "^3.0.1",
"mocha": "^2.2.4",
"mocha-lcov-reporter": "^0.0.2",
"through2": "^0.6.1",
"unicode-7.0.0": "^0.1.5"
}
}
10 changes: 9 additions & 1 deletion src/lexer/CssLexer.js
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,15 @@ var CssLexer = Lexer.extend(function(rule) {
this.va = false;
break;
case '~':
if(!this.value && ['"', "'", '@', '$'].indexOf(this.code.charAt(this.index)) == -1) {
if(this.sel && !this.param) {
var last = this.tokenList[this.tokenList.length - 1];
if(last) {
if(last.type() == Token.SIGN && ['{', '}'].indexOf(last.content()) > -1) {
token.type(Token.HACK);
}
}
}
else if(!this.value && ['"', "'", '@', '$'].indexOf(this.code.charAt(this.index)) == -1) {
token.type(Token.HACK);
}
default:
Expand Down
6 changes: 6 additions & 0 deletions tests/csslexer.js
Original file line number Diff line number Diff line change
Expand Up @@ -886,6 +886,12 @@ describe('csslexer', function() {
expect(join(tokens)).to.eql(['.a', '{', '$fn', '(', '~', '""', ')', '}']);
expect(type(tokens)).to.eql([21, 8, 16, 8, 8, 7, 8, 8]);
});
it('in selector', function() {
var lexer = homunculus.getLexer('css');
var tokens = lexer.parse('a~b{}');
expect(join(tokens)).to.eql(['a', '~', 'b', '{', '}']);
expect(type(tokens)).to.eql([21, 8, 21, 8, 8]);
});
});
describe('index test', function() {
var lexer = homunculus.getLexer('css');
Expand Down
10 changes: 9 additions & 1 deletion web/lexer/CssLexer.js
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,15 @@ var CssLexer = Lexer.extend(function(rule) {
this.va = false;
break;
case '~':
if(!this.value && ['"', "'", '@', '$'].indexOf(this.code.charAt(this.index)) == -1) {
if(this.sel && !this.param) {
var last = this.tokenList[this.tokenList.length - 1];
if(last) {
if(last.type() == Token.SIGN && ['{', '}'].indexOf(last.content()) > -1) {
token.type(Token.HACK);
}
}
}
else if(!this.value && ['"', "'", '@', '$'].indexOf(this.code.charAt(this.index)) == -1) {
token.type(Token.HACK);
}
default:
Expand Down

0 comments on commit 3504cbe

Please sign in to comment.