-
-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3016597
commit d96075d
Showing
2 changed files
with
51 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -82,6 +82,9 @@ module.exports = class LessParser extends Parser { | |
} | ||
|
||
unknownWord(tokens) { | ||
// NOTE: keep commented for examining unknown structures | ||
// console.log('unknown', tokens); | ||
|
||
const [first] = tokens; | ||
|
||
// TODO: move this into a util function/file | ||
|
@@ -110,6 +113,29 @@ module.exports = class LessParser extends Parser { | |
tokens = tokens.concat(tokensAfter); | ||
} | ||
|
||
const importantTokens = []; | ||
|
||
for (const token of tokens) { | ||
if (token[1] === '!' || importantTokens.length) { | ||
importantTokens.push(token); | ||
} | ||
|
||
if (token[1] === 'important') { | ||
break; | ||
} | ||
} | ||
|
||
if (importantTokens.length) { | ||
const [bangToken] = importantTokens; | ||
const bangIndex = tokens.indexOf(bangToken); | ||
const last = importantTokens[importantTokens.length - 1]; | ||
const start = [bangToken[2], bangToken[3]]; | ||
const end = [last[4], last[5]]; | ||
const combined = importantTokens.map((t) => t[1]).reduce((a, c) => a + c); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
shellscape
Author
Owner
|
||
const newToken = ['word', combined].concat(start, end); | ||
tokens.splice(bangIndex, importantTokens.length, newToken); | ||
} | ||
|
||
const importantIndex = tokens.findIndex((t) => importantPattern.test(t[1])); | ||
|
||
if (importantIndex > 0) { | ||
|
@@ -125,28 +151,14 @@ module.exports = class LessParser extends Parser { | |
this.lastNode.mixin = true; | ||
this.lastNode.raws.identifier = identifier; | ||
|
||
// const importantIndex = tokens.findIndex((t) => importantPattern.test(t[1])); | ||
|
||
if (important) { | ||
this.lastNode.important = true; | ||
this.lastNode.raws.important = important; | ||
} | ||
|
||
// if (importantIndex > 0) { | ||
// nodes.splice(importantIndex, 1); | ||
// [this.lastNode.raws.important] = this.lastNode.params.match(importantPattern); | ||
|
||
// this.lastNode.params = this.lastNode.params.replace(importantPattern, ''); | ||
|
||
// const [spaces] = this.lastNode.params.match(/\s+$/) || ['']; | ||
// this.lastNode.raws.between = spaces; | ||
// this.lastNode.params = this.lastNode.params.trim(); | ||
// } | ||
|
||
return; | ||
} | ||
// NOTE: keep commented for examining unknown structures | ||
// console.log('unknown', tokens); | ||
|
||
super.unknownWord(tokens); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
IMO,
const combined = importantTokens.map((t) => t[1]).join('');
would be easier to read.