|
import { |
|
Delim, |
|
Ident, |
|
Dimension, |
|
Percentage, |
|
Number as NumberToken, |
|
Hash, |
|
Colon, |
|
LeftSquareBracket |
|
} from '../../tokenizer/index.js'; |
|
|
|
const NUMBERSIGN = 0x0023; |
|
const AMPERSAND = 0x0026; |
|
const ASTERISK = 0x002A; |
|
const PLUSSIGN = 0x002B; |
|
const SOLIDUS = 0x002F; |
|
const FULLSTOP = 0x002E; |
|
const GREATERTHANSIGN = 0x003E; |
|
const VERTICALLINE = 0x007C; |
|
const TILDE = 0x007E; |
|
|
|
function onWhiteSpace(next, children) { |
|
if (children.last !== null && children.last.type !== 'Combinator' && |
|
next !== null && next.type !== 'Combinator') { |
|
children.push({ |
|
type: 'Combinator', |
|
loc: null, |
|
name: ' ' |
|
}); |
|
} |
|
} |
|
|
|
function getNode() { |
|
switch (this.tokenType) { |
|
case LeftSquareBracket: |
|
return this.AttributeSelector(); |
|
|
|
case Hash: |
|
return this.IdSelector(); |
|
|
|
case Colon: |
|
if (this.lookupType(1) === Colon) { |
|
return this.PseudoElementSelector(); |
|
} else { |
|
return this.PseudoClassSelector(); |
|
} |
|
|
|
case Ident: |
|
return this.TypeSelector(); |
|
|
|
case NumberToken: |
|
case Percentage: |
|
return this.Percentage(); |
|
|
|
case Dimension: |
|
|
|
if (this.charCodeAt(this.tokenStart) === FULLSTOP) { |
|
this.error('Identifier is expected', this.tokenStart + 1); |
|
} |
|
break; |
|
|
|
case Delim: { |
|
const code = this.charCodeAt(this.tokenStart); |
|
|
|
switch (code) { |
|
case PLUSSIGN: |
|
case GREATERTHANSIGN: |
|
case TILDE: |
|
case SOLIDUS: |
|
return this.Combinator(); |
|
|
|
case FULLSTOP: |
|
return this.ClassSelector(); |
|
|
|
case ASTERISK: |
|
case VERTICALLINE: |
|
return this.TypeSelector(); |
|
|
|
case NUMBERSIGN: |
|
return this.IdSelector(); |
|
|
|
case AMPERSAND: |
|
return this.NestingSelector(); |
|
} |
|
|
|
break; |
|
} |
|
} |
|
}; |
|
|
|
export default { |
|
onWhiteSpace, |
|
getNode |
|
}; |
|
|