Skip to content

Commit

Permalink
Merge branch 'master' into encode-decode
Browse files Browse the repository at this point in the history
  • Loading branch information
lahmatiy committed Jun 1, 2020
2 parents a2b8191 + 771c337 commit ac8e0d2
Show file tree
Hide file tree
Showing 65 changed files with 439 additions and 24 deletions.
24 changes: 20 additions & 4 deletions lib/syntax/function/var.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { Comma } = require('../../tokenizer/types');
const { Comma, WhiteSpace } = require('../../tokenizer/types');

// var( <ident> , <value>? )
module.exports = function() {
Expand All @@ -13,10 +13,26 @@ module.exports = function() {

if (this.tokenType === Comma) {
children.push(this.Operator());
children.push(this.parseCustomProperty

const startIndex = this.tokenIndex;
const value = this.parseCustomProperty
? this.Value(null)
: this.Raw(this.tokenIndex, this.consumeUntilExclamationMarkOrSemicolon, false)
);
: this.Raw(this.tokenIndex, this.consumeUntilExclamationMarkOrSemicolon, false);

if (value.type === 'Value' && value.children.isEmpty) {
for (let offset = startIndex - this.tokenIndex; offset <= 0; offset++) {
if (this.lookupType(offset) === WhiteSpace) {
value.children.appendData({
type: 'WhiteSpace',
loc: null,
value: ' '
});
break;
}
}
}

children.push(value);
}

return children;
Expand Down
18 changes: 17 additions & 1 deletion lib/syntax/node/Declaration.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ const {
Hash,
Colon,
Semicolon,
Delim
Delim,
WhiteSpace
} = require('../../tokenizer/types');

const EXCLAMATIONMARK = 0x0021; // U+0021 EXCLAMATION MARK (!)
Expand Down Expand Up @@ -58,6 +59,8 @@ module.exports = {
this.skipSC();
this.eat(Colon);

const valueStart = this.tokenIndex;

if (!customProperty) {
this.skipSC();
}
Expand All @@ -68,6 +71,19 @@ module.exports = {
value = consumeRaw.call(this, this.tokenIndex);
}

if (customProperty && value.type === 'Value' && value.children.isEmpty) {
for (let offset = valueStart - this.tokenIndex; offset <= 0; offset++) {
if (this.lookupType(offset) === WhiteSpace) {
value.children.appendData({
type: 'WhiteSpace',
loc: null,
value: ' '
});
break;
}
}
}

if (this.isDelim(EXCLAMATIONMARK)) {
important = getImportant.call(this);
this.skipSC();
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,21 @@
}
}
},
"empty (parseCustomProperty:true)": {
"options": {
"parseCustomProperty": true
},
"source": "--var:",
"ast": {
"type": "Declaration",
"important": false,
"property": "--var",
"value": {
"type": "Value",
"children": []
}
}
},
"empty with important": {
"source": "--var:!important",
"ast": {
Expand All @@ -95,6 +110,21 @@
}
}
},
"empty with important (parseCustomProperty:true)": {
"options": {
"parseCustomProperty": true
},
"source": "--var:!important",
"ast": {
"type": "Declaration",
"important": true,
"property": "--var",
"value": {
"type": "Value",
"children": []
}
}
},
"should preserve single spaces": {
"source": "--var: ",
"ast": {
Expand All @@ -107,6 +137,26 @@
}
}
},
"should preserve single spaces (parseCustomProperty:true)": {
"options": {
"parseCustomProperty": true
},
"source": "--var: ",
"ast": {
"type": "Declaration",
"important": false,
"property": "--var",
"value": {
"type": "Value",
"children": [
{
"type": "WhiteSpace",
"value": " "
}
]
}
}
},
"should preserve single spaces with important": {
"source": "--var: !important",
"ast": {
Expand All @@ -119,6 +169,26 @@
}
}
},
"should preserve single spaces with important (parseCustomProperty:true)": {
"options": {
"parseCustomProperty": true
},
"source": "--var: !important",
"ast": {
"type": "Declaration",
"important": true,
"property": "--var",
"value": {
"type": "Value",
"children": [
{
"type": "WhiteSpace",
"value": " "
}
]
}
}
},
"spaces and comments": {
"source": "--var: /* 1 */ ",
"ast": {
Expand All @@ -131,6 +201,118 @@
}
}
},
"spaces and comments (parseCustomProperty:true)": {
"options": {
"parseCustomProperty": true
},
"source": "--var: /* 1 */ ",
"generate": "--var: ",
"ast": {
"type": "Declaration",
"important": false,
"property": "--var",
"value": {
"type": "Value",
"children": [
{
"type": "WhiteSpace",
"value": " "
}
]
}
}
},
"spaces and comments #2 (parseCustomProperty:true)": {
"options": {
"parseCustomProperty": true
},
"source": "--var: /* 1 */",
"generate": "--var: ",
"ast": {
"type": "Declaration",
"important": false,
"property": "--var",
"value": {
"type": "Value",
"children": [
{
"type": "WhiteSpace",
"value": " "
}
]
}
}
},
"spaces and comments #3 (parseCustomProperty:true)": {
"options": {
"parseCustomProperty": true
},
"source": "--var:/* 1 */ ",
"generate": "--var: ",
"ast": {
"type": "Declaration",
"important": false,
"property": "--var",
"value": {
"type": "Value",
"children": [
{
"type": "WhiteSpace",
"value": " "
}
]
}
}
},
"only a comment": {
"source": "--var:/* 1 */",
"ast": {
"type": "Declaration",
"important": false,
"property": "--var",
"value": {
"type": "Raw",
"value": "/* 1 */"
}
}
},
"only a comment (parseCustomProperty:true)": {
"options": {
"parseCustomProperty": true
},
"source": "--var:/* 1 */",
"generate": "--var:",
"ast": {
"type": "Declaration",
"important": false,
"property": "--var",
"value": {
"type": "Value",
"children": []
}
}
},
"whitespace beetween comments (parseCustomProperty:true)": {
"options": {
"parseCustomProperty": true
},
"source": "--var:/* 1 */ /* 2 */",
"generate": "--var: ",
"ast": {
"type": "Declaration",
"important": false,
"property": "--var",
"value": {
"type": "Value",
"children": [
{
"type": "WhiteSpace",
"value": " "
}
]
}
}
},
"should parse a custom property value when parseCustomProperty is true": {
"options": {
"parseCustomProperty": true
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit ac8e0d2

Please sign in to comment.