source: trip-planner-front/node_modules/css-tree/lib/syntax/node/MediaFeature.js

Last change on this file was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 1.9 KB
RevLine 
[6a3a178]1var TYPE = require('../../tokenizer').TYPE;
2
3var IDENT = TYPE.Ident;
4var NUMBER = TYPE.Number;
5var DIMENSION = TYPE.Dimension;
6var LEFTPARENTHESIS = TYPE.LeftParenthesis;
7var RIGHTPARENTHESIS = TYPE.RightParenthesis;
8var COLON = TYPE.Colon;
9var DELIM = TYPE.Delim;
10
11module.exports = {
12 name: 'MediaFeature',
13 structure: {
14 name: String,
15 value: ['Identifier', 'Number', 'Dimension', 'Ratio', null]
16 },
17 parse: function() {
18 var start = this.scanner.tokenStart;
19 var name;
20 var value = null;
21
22 this.eat(LEFTPARENTHESIS);
23 this.scanner.skipSC();
24
25 name = this.consume(IDENT);
26 this.scanner.skipSC();
27
28 if (this.scanner.tokenType !== RIGHTPARENTHESIS) {
29 this.eat(COLON);
30 this.scanner.skipSC();
31
32 switch (this.scanner.tokenType) {
33 case NUMBER:
34 if (this.lookupNonWSType(1) === DELIM) {
35 value = this.Ratio();
36 } else {
37 value = this.Number();
38 }
39
40 break;
41
42 case DIMENSION:
43 value = this.Dimension();
44 break;
45
46 case IDENT:
47 value = this.Identifier();
48
49 break;
50
51 default:
52 this.error('Number, dimension, ratio or identifier is expected');
53 }
54
55 this.scanner.skipSC();
56 }
57
58 this.eat(RIGHTPARENTHESIS);
59
60 return {
61 type: 'MediaFeature',
62 loc: this.getLocation(start, this.scanner.tokenStart),
63 name: name,
64 value: value
65 };
66 },
67 generate: function(node) {
68 this.chunk('(');
69 this.chunk(node.name);
70 if (node.value !== null) {
71 this.chunk(':');
72 this.node(node.value);
73 }
74 this.chunk(')');
75 }
76};
Note: See TracBrowser for help on using the repository browser.