ether-code 0.3.8 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cli/ether.js +280 -328
- package/ether-parser.js +40 -4
- package/generators/css-generator.js +505 -252
- package/package.json +1 -1
package/ether-parser.js
CHANGED
|
@@ -219,11 +219,15 @@ class EtherParser {
|
|
|
219
219
|
this.skipNewlines()
|
|
220
220
|
|
|
221
221
|
while (!this.isAtEnd()) {
|
|
222
|
+
const startPos = this.pos
|
|
222
223
|
const rule = this.parseCSSRule()
|
|
223
224
|
if (rule) {
|
|
224
225
|
stylesheet.rules.push(rule)
|
|
225
226
|
}
|
|
226
227
|
this.skipNewlines()
|
|
228
|
+
if (this.pos === startPos && !this.isAtEnd()) {
|
|
229
|
+
this.advance()
|
|
230
|
+
}
|
|
227
231
|
}
|
|
228
232
|
|
|
229
233
|
return stylesheet
|
|
@@ -298,11 +302,27 @@ class EtherParser {
|
|
|
298
302
|
const token = this.current()
|
|
299
303
|
|
|
300
304
|
if (!token || token.type === TokenType.NEWLINE || token.type === TokenType.INDENT ||
|
|
301
|
-
token.type === TokenType.
|
|
305
|
+
token.type === TokenType.EOF) {
|
|
302
306
|
break
|
|
303
307
|
}
|
|
304
308
|
|
|
305
|
-
if (token.type === TokenType.
|
|
309
|
+
if (token.type === TokenType.COLON) {
|
|
310
|
+
this.advance()
|
|
311
|
+
const next = this.current()
|
|
312
|
+
if (next && next.type === TokenType.COLON) {
|
|
313
|
+
this.advance()
|
|
314
|
+
const pseudoName = this.current()
|
|
315
|
+
if (pseudoName && pseudoName.type === TokenType.IDENTIFIER) {
|
|
316
|
+
parts.push('::' + pseudoName.value)
|
|
317
|
+
this.advance()
|
|
318
|
+
}
|
|
319
|
+
} else if (next && next.type === TokenType.IDENTIFIER) {
|
|
320
|
+
parts.push(':' + next.value)
|
|
321
|
+
this.advance()
|
|
322
|
+
} else {
|
|
323
|
+
break
|
|
324
|
+
}
|
|
325
|
+
} else if (token.type === TokenType.DOT) {
|
|
306
326
|
this.advance()
|
|
307
327
|
const name = this.current()
|
|
308
328
|
if (name && name.type === TokenType.IDENTIFIER) {
|
|
@@ -334,12 +354,28 @@ class EtherParser {
|
|
|
334
354
|
} else if (token.type === TokenType.TILDE) {
|
|
335
355
|
parts.push('~')
|
|
336
356
|
this.advance()
|
|
357
|
+
} else if (token.type === TokenType.LBRACKET) {
|
|
358
|
+
let attrSelector = '['
|
|
359
|
+
this.advance()
|
|
360
|
+
while (!this.isAtEnd()) {
|
|
361
|
+
const attrToken = this.current()
|
|
362
|
+
if (!attrToken || attrToken.type === TokenType.RBRACKET) {
|
|
363
|
+
attrSelector += ']'
|
|
364
|
+
this.advance()
|
|
365
|
+
break
|
|
366
|
+
}
|
|
367
|
+
attrSelector += attrToken.value
|
|
368
|
+
this.advance()
|
|
369
|
+
}
|
|
370
|
+
parts.push(attrSelector)
|
|
371
|
+
} else if (token.type === TokenType.EQUALS) {
|
|
372
|
+
break
|
|
337
373
|
} else {
|
|
338
374
|
break
|
|
339
375
|
}
|
|
340
376
|
}
|
|
341
377
|
|
|
342
|
-
return parts.join(' ').replace(/\s+([,>+~])\s+/g, ' $1 ').trim()
|
|
378
|
+
return parts.join(' ').replace(/\s+([,>+~])\s+/g, ' $1 ').replace(/\s+(::?)/g, '$1').trim()
|
|
343
379
|
}
|
|
344
380
|
|
|
345
381
|
translateCSSSelector(selector) {
|
|
@@ -3098,4 +3134,4 @@ class EtherParser {
|
|
|
3098
3134
|
|
|
3099
3135
|
module.exports = {
|
|
3100
3136
|
EtherParser
|
|
3101
|
-
}
|
|
3137
|
+
}
|