Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 19 additions & 16 deletions lib/less-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,17 @@ import { convertImport } from './nodes/import.js';
const importantPattern = /(!\s*important)$/i;

class LessParser extends Parser {
#lastNode;

constructor(...arguments_) {
super(...arguments_);

this.lastNode = null;
this.#lastNode = null;
}

comment(token) {
if (token[4] === 'inline') {
this.inlineComment(token);
this.#inlineComment(token);
} else {
super.comment(token);
}
Expand All @@ -27,12 +29,12 @@ class LessParser extends Parser {

atrule(token) {
if (token[4] !== 'variable') {
this.prepareAtRuleTokens();
this.#prepareAtRuleTokens();
}

super.atrule(token);

const node = this.lastNode;
const node = this.#lastNode;

convertImport(node);

Expand All @@ -59,14 +61,14 @@ class LessParser extends Parser {
decl(...arguments_) {
super.decl(...arguments_);

const node = this.lastNode;
const node = this.#lastNode;
// #123: add `extend` decorator to nodes
if (/extend\(.+\)/i.test(node.value)) {
node.extend = true;
}
}

functionCall(tokens) {
#functionCall(tokens) {
const [firstToken, secondToken] = tokens;
// prepend a space so the `name` will be parsed correctly
firstToken[1] = ` ${firstToken[1]}`;
Expand All @@ -91,17 +93,17 @@ class LessParser extends Parser {
}

this.atrule(this.tokenizer.nextToken());
const node = this.lastNode;
const node = this.#lastNode;
node.function = true;
node.params = params;
}

init(node, line, column) {
super.init(node, line, column);
this.lastNode = node;
this.#lastNode = node;
}

inlineComment(token) {
#inlineComment(token) {
const node = new Comment();
const text = token[1].slice(2);

Expand All @@ -121,7 +123,7 @@ class LessParser extends Parser {
}
}

mixin(tokens) {
#mixin(tokens) {
const [firstToken] = tokens;

if (firstToken[1] === '.' || firstToken[1] === '#') {
Expand Down Expand Up @@ -208,7 +210,7 @@ class LessParser extends Parser {
}

this.atrule(this.tokenizer.nextToken());
const node = this.lastNode;
const node = this.#lastNode;
node.mixin = true;
node.raws.identifier = identifier;

Expand All @@ -218,7 +220,7 @@ class LessParser extends Parser {
}
}

prepareAtRuleTokens() {
#prepareAtRuleTokens() {
const tokens = [];
let token = this.tokenizer.nextToken();

Expand All @@ -241,9 +243,10 @@ class LessParser extends Parser {
rule(tokens) {
super.rule(tokens);

const node = this.#lastNode;
// #123: add `extend` decorator to nodes
if (/:extend\(.+\)/i.test(this.lastNode.selector)) {
this.lastNode.extend = true;
if (/:extend\(.+\)/i.test(node.selector)) {
node.extend = true;
}
}

Expand All @@ -255,7 +258,7 @@ class LessParser extends Parser {

if (firstToken[0] === 'word') {
if (firstToken[1].startsWith('.') || firstToken[1].startsWith('#')) {
this.mixin(tokens);
this.#mixin(tokens);
return;
}

Expand All @@ -264,7 +267,7 @@ class LessParser extends Parser {
secondToken &&
(secondToken[0] === '(' || secondToken[0] === 'brackets')
) {
this.functionCall(tokens);
this.#functionCall(tokens);
return;
}
}
Expand Down
Loading