source: trip-planner-front/node_modules/css-tree/lib/syntax/node/Url.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: 2.0 KB
Line 
1var isWhiteSpace = require('../../tokenizer').isWhiteSpace;
2var cmpStr = require('../../tokenizer').cmpStr;
3var TYPE = require('../../tokenizer').TYPE;
4
5var FUNCTION = TYPE.Function;
6var URL = TYPE.Url;
7var RIGHTPARENTHESIS = TYPE.RightParenthesis;
8
9// <url-token> | <function-token> <string> )
10module.exports = {
11 name: 'Url',
12 structure: {
13 value: ['String', 'Raw']
14 },
15 parse: function() {
16 var start = this.scanner.tokenStart;
17 var value;
18
19 switch (this.scanner.tokenType) {
20 case URL:
21 var rawStart = start + 4;
22 var rawEnd = this.scanner.tokenEnd - 1;
23
24 while (rawStart < rawEnd && isWhiteSpace(this.scanner.source.charCodeAt(rawStart))) {
25 rawStart++;
26 }
27
28 while (rawStart < rawEnd && isWhiteSpace(this.scanner.source.charCodeAt(rawEnd - 1))) {
29 rawEnd--;
30 }
31
32 value = {
33 type: 'Raw',
34 loc: this.getLocation(rawStart, rawEnd),
35 value: this.scanner.source.substring(rawStart, rawEnd)
36 };
37
38 this.eat(URL);
39 break;
40
41 case FUNCTION:
42 if (!cmpStr(this.scanner.source, this.scanner.tokenStart, this.scanner.tokenEnd, 'url(')) {
43 this.error('Function name must be `url`');
44 }
45
46 this.eat(FUNCTION);
47 this.scanner.skipSC();
48 value = this.String();
49 this.scanner.skipSC();
50 this.eat(RIGHTPARENTHESIS);
51 break;
52
53 default:
54 this.error('Url or Function is expected');
55 }
56
57 return {
58 type: 'Url',
59 loc: this.getLocation(start, this.scanner.tokenStart),
60 value: value
61 };
62 },
63 generate: function(node) {
64 this.chunk('url');
65 this.chunk('(');
66 this.node(node.value);
67 this.chunk(')');
68 }
69};
Note: See TracBrowser for help on using the repository browser.