Skip to content

Commit

Permalink
additional declaration hacks (# and +)
Browse files Browse the repository at this point in the history
  • Loading branch information
lahmatiy committed Mar 9, 2017
1 parent aac4a7a commit 9e5161f
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 2 deletions.
4 changes: 4 additions & 0 deletions lib/syntax/node/Declaration.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ var HYPHENMINUS = TYPE.HyphenMinus;
var SEMICOLON = TYPE.Semicolon;
var RIGHTCURLYBRACKET = TYPE.RightCurlyBracket;
var RIGHTPARENTHESIS = TYPE.RightParenthesis;
var PLUSSIGN = TYPE.PlusSign;
var NUMBERSIGN = TYPE.NumberSign;
var BALANCED = true;

function readProperty() {
Expand All @@ -20,6 +22,8 @@ function readProperty() {
switch (this.scanner.tokenType) {
case ASTERISK:
case DOLLARSIGN:
case PLUSSIGN:
case NUMBERSIGN:
prefix = 1;
break;

Expand Down
6 changes: 5 additions & 1 deletion lib/utils/names.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,11 @@ function getPropertyInfo(property) {

if (hack === '/' && property[1] === '/') {
hack = '//';
} else if (hack !== '*' && hack !== '_' && hack !== '$') {
} else if (hack !== '_' &&
hack !== '*' &&
hack !== '$' &&
hack !== '#' &&
hack !== '+') {
hack = '';
}

Expand Down
34 changes: 34 additions & 0 deletions test/fixture/parse/declaration/Declaration.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,40 @@
}
}
},
"declaration property with # hack": {
"source": "#property:value",
"ast": {
"type": "Declaration",
"important": false,
"property": "#property",
"value": {
"type": "Value",
"children": [
{
"type": "Identifier",
"name": "value"
}
]
}
}
},
"declaration property with + hack": {
"source": "+property:value",
"ast": {
"type": "Declaration",
"important": false,
"property": "+property",
"value": {
"type": "Value",
"children": [
{
"type": "Identifier",
"name": "value"
}
]
}
}
},
"declaration.c.0": {
"source": "property/*test*/:value",
"translate": "property:value",
Expand Down
2 changes: 1 addition & 1 deletion test/names.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ describe('names utils', function() {
});

describe('should detect hacks', function() {
['*', '_', '$', '//'].forEach(function(hack) {
['*', '_', '$', '#', '+', '//'].forEach(function(hack) {
it(hack, function() {
assert.deepEqual(property(hack + 'test'), {
name: 'test',
Expand Down

0 comments on commit 9e5161f

Please sign in to comment.