diff options
| author | Adam Mathes <adam@adammathes.com> | 2026-02-13 21:34:48 -0800 |
|---|---|---|
| committer | Adam Mathes <adam@adammathes.com> | 2026-02-13 21:34:48 -0800 |
| commit | 76cb9c2a39d477a64824a985ade40507e3bbade1 (patch) | |
| tree | 41e997aa9c6f538d3a136af61dae9424db2005a9 /vanilla/node_modules/css-tree/lib/syntax/node/MediaQuery.js | |
| parent | 819a39a21ac992b1393244a4c283bbb125208c69 (diff) | |
| download | neko-76cb9c2a39d477a64824a985ade40507e3bbade1.tar.gz neko-76cb9c2a39d477a64824a985ade40507e3bbade1.tar.bz2 neko-76cb9c2a39d477a64824a985ade40507e3bbade1.zip | |
feat(vanilla): add testing infrastructure and tests (NK-wjnczv)
Diffstat (limited to 'vanilla/node_modules/css-tree/lib/syntax/node/MediaQuery.js')
| -rw-r--r-- | vanilla/node_modules/css-tree/lib/syntax/node/MediaQuery.js | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/vanilla/node_modules/css-tree/lib/syntax/node/MediaQuery.js b/vanilla/node_modules/css-tree/lib/syntax/node/MediaQuery.js new file mode 100644 index 0000000..f569c75 --- /dev/null +++ b/vanilla/node_modules/css-tree/lib/syntax/node/MediaQuery.js @@ -0,0 +1,102 @@ +import { + Comma, + EOF, + Ident, + LeftCurlyBracket, + LeftParenthesis, + Function as FunctionToken, + Semicolon +} from '../../tokenizer/index.js'; + +export const name = 'MediaQuery'; +export const structure = { + modifier: [String, null], + mediaType: [String, null], + condition: ['Condition', null] +}; + +export function parse() { + const start = this.tokenStart; + let modifier = null; + let mediaType = null; + let condition = null; + + this.skipSC(); + + if (this.tokenType === Ident && this.lookupTypeNonSC(1) !== LeftParenthesis) { + // [ not | only ]? <media-type> + const ident = this.consume(Ident); + const identLowerCase = ident.toLowerCase(); + + if (identLowerCase === 'not' || identLowerCase === 'only') { + this.skipSC(); + modifier = identLowerCase; + mediaType = this.consume(Ident); + } else { + mediaType = ident; + } + + switch (this.lookupTypeNonSC(0)) { + case Ident: { + // and <media-condition-without-or> + this.skipSC(); + this.eatIdent('and'); + condition = this.Condition('media'); + break; + } + + case LeftCurlyBracket: + case Semicolon: + case Comma: + case EOF: + break; + + default: + this.error('Identifier or parenthesis is expected'); + } + } else { + switch (this.tokenType) { + case Ident: + case LeftParenthesis: + case FunctionToken: { + // <media-condition> + condition = this.Condition('media'); + break; + } + + case LeftCurlyBracket: + case Semicolon: + case EOF: + break; + + default: + this.error('Identifier or parenthesis is expected'); + } + } + + return { + type: 'MediaQuery', + loc: this.getLocation(start, this.tokenStart), + modifier, + mediaType, + condition + }; +} + +export function generate(node) { + if (node.mediaType) { + if (node.modifier) { + this.token(Ident, node.modifier); + } + + this.token(Ident, node.mediaType); + + if (node.condition) { + this.token(Ident, 'and'); + this.node(node.condition); + } + } else if (node.condition) { + this.node(node.condition); + } +} + |
