source: imaps-frontend/node_modules/css-tree/lib/syntax/node/Block.js@ d565449

main
Last change on this file since d565449 was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 2.3 KB
Line 
1var TYPE = require('../../tokenizer').TYPE;
2var rawMode = require('./Raw').mode;
3
4var WHITESPACE = TYPE.WhiteSpace;
5var COMMENT = TYPE.Comment;
6var SEMICOLON = TYPE.Semicolon;
7var ATKEYWORD = TYPE.AtKeyword;
8var LEFTCURLYBRACKET = TYPE.LeftCurlyBracket;
9var RIGHTCURLYBRACKET = TYPE.RightCurlyBracket;
10
11function consumeRaw(startToken) {
12 return this.Raw(startToken, null, true);
13}
14function consumeRule() {
15 return this.parseWithFallback(this.Rule, consumeRaw);
16}
17function consumeRawDeclaration(startToken) {
18 return this.Raw(startToken, rawMode.semicolonIncluded, true);
19}
20function consumeDeclaration() {
21 if (this.scanner.tokenType === SEMICOLON) {
22 return consumeRawDeclaration.call(this, this.scanner.tokenIndex);
23 }
24
25 var node = this.parseWithFallback(this.Declaration, consumeRawDeclaration);
26
27 if (this.scanner.tokenType === SEMICOLON) {
28 this.scanner.next();
29 }
30
31 return node;
32}
33
34module.exports = {
35 name: 'Block',
36 structure: {
37 children: [[
38 'Atrule',
39 'Rule',
40 'Declaration'
41 ]]
42 },
43 parse: function(isDeclaration) {
44 var consumer = isDeclaration ? consumeDeclaration : consumeRule;
45
46 var start = this.scanner.tokenStart;
47 var children = this.createList();
48
49 this.eat(LEFTCURLYBRACKET);
50
51 scan:
52 while (!this.scanner.eof) {
53 switch (this.scanner.tokenType) {
54 case RIGHTCURLYBRACKET:
55 break scan;
56
57 case WHITESPACE:
58 case COMMENT:
59 this.scanner.next();
60 break;
61
62 case ATKEYWORD:
63 children.push(this.parseWithFallback(this.Atrule, consumeRaw));
64 break;
65
66 default:
67 children.push(consumer.call(this));
68 }
69 }
70
71 if (!this.scanner.eof) {
72 this.eat(RIGHTCURLYBRACKET);
73 }
74
75 return {
76 type: 'Block',
77 loc: this.getLocation(start, this.scanner.tokenStart),
78 children: children
79 };
80 },
81 generate: function(node) {
82 this.chunk('{');
83 this.children(node, function(prev) {
84 if (prev.type === 'Declaration') {
85 this.chunk(';');
86 }
87 });
88 this.chunk('}');
89 },
90 walkContext: 'block'
91};
Note: See TracBrowser for help on using the repository browser.