source: imaps-frontend/node_modules/css-tree/lib/syntax/node/Raw.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.4 KB
Line 
1var tokenizer = require('../../tokenizer');
2var TYPE = tokenizer.TYPE;
3
4var WhiteSpace = TYPE.WhiteSpace;
5var Semicolon = TYPE.Semicolon;
6var LeftCurlyBracket = TYPE.LeftCurlyBracket;
7var Delim = TYPE.Delim;
8var EXCLAMATIONMARK = 0x0021; // U+0021 EXCLAMATION MARK (!)
9
10function getOffsetExcludeWS() {
11 if (this.scanner.tokenIndex > 0) {
12 if (this.scanner.lookupType(-1) === WhiteSpace) {
13 return this.scanner.tokenIndex > 1
14 ? this.scanner.getTokenStart(this.scanner.tokenIndex - 1)
15 : this.scanner.firstCharOffset;
16 }
17 }
18
19 return this.scanner.tokenStart;
20}
21
22// 0, 0, false
23function balanceEnd() {
24 return 0;
25}
26
27// LEFTCURLYBRACKET, 0, false
28function leftCurlyBracket(tokenType) {
29 return tokenType === LeftCurlyBracket ? 1 : 0;
30}
31
32// LEFTCURLYBRACKET, SEMICOLON, false
33function leftCurlyBracketOrSemicolon(tokenType) {
34 return tokenType === LeftCurlyBracket || tokenType === Semicolon ? 1 : 0;
35}
36
37// EXCLAMATIONMARK, SEMICOLON, false
38function exclamationMarkOrSemicolon(tokenType, source, offset) {
39 if (tokenType === Delim && source.charCodeAt(offset) === EXCLAMATIONMARK) {
40 return 1;
41 }
42
43 return tokenType === Semicolon ? 1 : 0;
44}
45
46// 0, SEMICOLON, true
47function semicolonIncluded(tokenType) {
48 return tokenType === Semicolon ? 2 : 0;
49}
50
51module.exports = {
52 name: 'Raw',
53 structure: {
54 value: String
55 },
56 parse: function(startToken, mode, excludeWhiteSpace) {
57 var startOffset = this.scanner.getTokenStart(startToken);
58 var endOffset;
59
60 this.scanner.skip(
61 this.scanner.getRawLength(startToken, mode || balanceEnd)
62 );
63
64 if (excludeWhiteSpace && this.scanner.tokenStart > startOffset) {
65 endOffset = getOffsetExcludeWS.call(this);
66 } else {
67 endOffset = this.scanner.tokenStart;
68 }
69
70 return {
71 type: 'Raw',
72 loc: this.getLocation(startOffset, endOffset),
73 value: this.scanner.source.substring(startOffset, endOffset)
74 };
75 },
76 generate: function(node) {
77 this.chunk(node.value);
78 },
79
80 mode: {
81 default: balanceEnd,
82 leftCurlyBracket: leftCurlyBracket,
83 leftCurlyBracketOrSemicolon: leftCurlyBracketOrSemicolon,
84 exclamationMarkOrSemicolon: exclamationMarkOrSemicolon,
85 semicolonIncluded: semicolonIncluded
86 }
87};
Note: See TracBrowser for help on using the repository browser.