Skip to content

Commit 87e1dac

Browse files
refactor: remove unnecessary stuff
1 parent 190f9bc commit 87e1dac

File tree

2 files changed

+32
-34
lines changed

2 files changed

+32
-34
lines changed

src/__tests__/exceptions.js

+19-14
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,32 @@
11
import {throws} from './util/helpers';
22

33
// Unclosed elements
4-
throws('unclosed string', 'a[href="wow]');
5-
throws('unclosed comment', '/* oops');
6-
throws('unclosed pseudo element', 'button::');
7-
throws('unclosed pseudo class', 'a:');
4+
throws('unclosed string', 'a[href="wow]', 'Unclosed quote');
5+
throws('unclosed comment', '/* oops', 'Unclosed comment');
6+
throws('unclosed pseudo element', 'button::', 'Expected a pseudo-class or pseudo-element.');
7+
throws('unclosed pseudo class', 'a:', 'Expected a pseudo-class or pseudo-element.');
88
throws('unclosed attribute selector', '[name="james"][href');
99

10-
throws('no opening parenthesis', ')');
11-
throws('no opening parenthesis (2)', ':global.foo)');
12-
throws('no opening parenthesis (3)', 'h1:not(h2:not(h3)))');
10+
throws('no opening parenthesis', ')', 'Expected an opening parenthesis.');
11+
throws('no opening parenthesis (2)', ':global.foo)', 'Expected an opening parenthesis.');
12+
throws('no opening parenthesis (3)', 'h1:not(h2:not(h3)))', 'Expected an opening parenthesis.');
1313

14-
throws('no opening square bracket', ']');
15-
throws('no opening square bracket (2)', ':global.foo]');
16-
throws('no opening square bracket (3)', '[global]]');
14+
throws('no opening square bracket', ']', 'Expected an opening square bracket.');
15+
throws('no opening square bracket (2)', ':global.foo]', 'Expected an opening square bracket.');
16+
throws('no opening square bracket (3)', '[global]]', 'Expected an opening square bracket.');
1717

18-
throws('bad pseudo element', 'button::"after"');
19-
throws('missing closing parenthesis in pseudo', ':not([attr="test"]:not([attr="test"])');
18+
throws('bad pseudo element', 'button::"after"', 'Expected a pseudo-class or pseudo-element.');
19+
throws('missing closing parenthesis in pseudo', ':not([attr="test"]:not([attr="test"])', 'Expected a closing parenthesis.');
2020

21-
throws('bad syntax', '-moz-osx-font-smoothing: grayscale');
22-
throws('bad syntax (2)', '! .body');
21+
throws('bad syntax', '-moz-osx-font-smoothing: grayscale', 'Expected a pseudo-class or pseudo-element.');
22+
throws('bad syntax (2)', '! .body', 'Unexpected \'!\'. Escaping special characters with \\ may help.');
2323

2424
throws('missing backslash for semicolon', '.;');
2525
throws('missing backslash for semicolon (2)', '.\;');
2626
throws('unexpected / foo', '-Option\/root', "Unexpected '/'. Escaping special characters with \\ may help.");
2727
throws('bang in selector', '.foo !optional', "Unexpected '!'. Escaping special characters with \\ may help.");
28+
29+
throws('misplaced parenthesis', ':not(', 'Expected a closing parenthesis.');
30+
throws('misplaced parenthesis (2)', ':not)', 'Expected an opening parenthesis.');
31+
throws('misplaced parenthesis (3)', ':not((', 'Expected a closing parenthesis.');
32+
throws('misplaced parenthesis (4)', ':not))', 'Expected an opening parenthesis.');

src/parser.js

+13-20
Original file line numberDiff line numberDiff line change
@@ -620,10 +620,14 @@ export default class Parser {
620620
});
621621
}
622622

623-
missingParenthesis () {
623+
missingOpeningParenthesis () {
624624
return this.expected('opening parenthesis', this.currToken[TOKEN.START_POS]);
625625
}
626626

627+
missingClosingParenthesis () {
628+
return this.expected('closing parenthesis', this.currToken[TOKEN.START_POS]);
629+
}
630+
627631
missingSquareBracket () {
628632
return this.expected('opening square bracket', this.currToken[TOKEN.START_POS]);
629633
}
@@ -702,6 +706,10 @@ export default class Parser {
702706
parenValue += this.parseParenthesisToken(this.currToken);
703707
this.position ++;
704708
}
709+
if (unbalanced) {
710+
this.position --;
711+
return this.missingClosingParenthesis();
712+
}
705713
if (last) {
706714
last.appendToPropertyAndEscape("value", parenValue, parenValue);
707715
} else {
@@ -718,7 +726,8 @@ export default class Parser {
718726
}
719727
}
720728
if (unbalanced) {
721-
return this.expected('closing parenthesis', this.currToken[TOKEN.START_POS]);
729+
this.position --;
730+
return this.missingClosingParenthesis();
722731
}
723732
}
724733

@@ -733,22 +742,13 @@ export default class Parser {
733742
return this.expected(['pseudo-class', 'pseudo-element'], this.position - 1);
734743
}
735744
if (this.currToken[TOKEN.TYPE] === tokens.word) {
736-
this.splitWord(false, (first, length) => {
745+
this.splitWord(false, (first) => {
737746
pseudoStr += first;
738747
this.newNode(new Pseudo({
739748
value: pseudoStr,
740749
source: getTokenSourceSpan(startingToken, this.currToken),
741750
sourceIndex: startingToken[TOKEN.START_POS],
742751
}));
743-
if (
744-
length > 1 &&
745-
this.nextToken &&
746-
this.nextToken[TOKEN.TYPE] === tokens.openParenthesis
747-
) {
748-
this.error('Misplaced parenthesis.', {
749-
index: this.nextToken[TOKEN.START_POS],
750-
});
751-
}
752752
});
753753
} else {
754754
return this.expected(['pseudo-class', 'pseudo-element'], this.currToken[TOKEN.START_POS]);
@@ -813,13 +813,6 @@ export default class Parser {
813813
this.position ++;
814814
let current = this.content();
815815
word += current;
816-
if (current.lastIndexOf('\\') === current.length - 1) {
817-
let next = this.nextToken;
818-
if (next && next[TOKEN.TYPE] === tokens.space) {
819-
word += this.requiredSpace(this.content(next));
820-
this.position ++;
821-
}
822-
}
823816
nextToken = this.nextToken;
824817
}
825818
const hasClass = indexesOf(word, '.').filter(i => word[i - 1] !== '\\');
@@ -905,7 +898,7 @@ export default class Parser {
905898
break;
906899
case tokens.closeParenthesis:
907900
if (throwOnParenthesis) {
908-
this.missingParenthesis();
901+
this.missingOpeningParenthesis();
909902
}
910903
break;
911904
case tokens.openSquare:

0 commit comments

Comments
 (0)