Skip to content

Commit 2382f1d

Browse files
committed
Just code improvement
1 parent d7af37c commit 2382f1d

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

parsercss.js

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,14 @@ class Parser {
7777
parseCSSBlock(rules = '') {
7878
this.blockRules = []
7979
this.rules = (rules != Parser.EMPTY)? rules : this.rules
80-
this.parseCSSRules()
81-
.split(Parser.SEMICOLON)
82-
.map(decl => {
83-
let [prop, value] = decl.split(Parser.DOTS).map(i => i.trim())
84-
if (prop != Parser.EMPTY && value != Parser.EMPTY)
85-
this.blockRules.push(new Rule(prop, Parser.REGEX_REPLACE(value, Parser.DATA_URI_VALUES)))
86-
})
80+
this.rules = this.parseCSSRules().split(Parser.SEMICOLON)
81+
this.rules.pop()
82+
83+
this.rules.map(decl => {
84+
let [prop, value] = decl.split(Parser.DOTS).map(i => i.trim())
85+
if (prop != Parser.EMPTY && value != Parser.EMPTY)
86+
this.blockRules.push(new Rule(prop, Parser.REGEX_REPLACE(value, Parser.DATA_URI_VALUES)))
87+
})
8788

8889
return this.blockRules
8990
}
@@ -95,7 +96,8 @@ class Parser {
9596
*/
9697
parseCSSRules() {
9798
let params = {}
98-
return this.rules.split(Parser.BREAK_LINE)
99+
return this.rules
100+
.split(Parser.BREAK_LINE)
99101
.filter(d => d != Parser.EMPTY)
100102
.map(decl => {
101103
if (decl.includes(Parser.END_BRACKET_RULE)) {
@@ -106,14 +108,18 @@ class Parser {
106108
}
107109
p_keys.map(p => {
108110
if (p.includes(Parser.DATA_URI)) {
109-
params[p] = Parser.REGEX_REPLACE(p, Parser.DATA_URI_KEYS)
110-
decl = Parser.REGEX_REPLACE(decl, params)
111+
params[p] = Parser.REGEX_REPLACE(p, Parser.DATA_URI_KEYS)
112+
decl = Parser.REGEX_REPLACE(decl, params)
111113
}
112-
})
114+
})
113115
}
114116

115117
return decl.trim()
116118
}).join('')
119+
// this.rules.pop()
120+
// console.log(this.rules)
121+
// this.rules = this.rule.join('')
122+
return this.rules
117123
}
118124

119125
/**
@@ -133,9 +139,9 @@ class Parser {
133139
* @return string css
134140
*/
135141
clearCode(css = '') {
136-
this.css = ((css != Parser.EMPTY)? css:this.css)
137-
.replace(Parser.REGEX_COMMENTS, Parser.EMPTY)
138-
return Parser.REGEX_REPLACE(this.css, {' ':'', '\n': '', '\t': ''})
142+
console.log(this.css)
143+
this.css = ((css != Parser.EMPTY)? css:this.css).replace(Parser.REGEX_COMMENTS, Parser.EMPTY)
144+
return Parser.REGEX_REPLACE(this.css, {'\n': '', '\t': ''})
139145
}
140146
}
141147

0 commit comments

Comments
 (0)