Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 1 addition & 3 deletions lib/less-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
mergeDollarInterpolation,
mergeParamsInterpolation,
} from './nodes/interpolation.js';
import { isMixinToken } from './nodes/mixin.js';
import { convertImport } from './nodes/import.js';

const importantPattern = /(!\s*important)$/i;
Expand Down Expand Up @@ -260,8 +259,7 @@ class LessParser extends Parser {

const [firstToken] = tokens;

// TODO: move this into a util function/file
if (isMixinToken(firstToken)) {
if (firstToken[0] === 'mixin') {
this.mixin(tokens);
return;
}
Expand Down
21 changes: 20 additions & 1 deletion lib/less-tokenize.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,19 @@ const RE_HEX_ESCAPE = /[\da-f]/i
const RE_URL_NAME = /(^|[\t\n\f\r "'(),/:;[\]{}])url$/i
const RE_QUOTED = /[\t\n\f\r ]*["']/y

const HASH_COLOR_PATTERN = /^#[0-9a-fA-F]{6}$|^#[0-9a-fA-F]{3}$/
const UNPADDED_FRACTIONAL_NUMBERS_PATTERN = /^\.[0-9]+(?:\.[0-9]+)?$/

function isMixinToken(symbol) {
const [char] = symbol

return (
(char === '.' || char === '#') &&
!HASH_COLOR_PATTERN.test(symbol) &&
!UNPADDED_FRACTIONAL_NUMBERS_PATTERN.test(symbol)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot If I remove these two lines, the tests will still pass, are we missing tests or these two line just useless?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They preserve the previous classification: without them, #abc; and .5; become mixin calls instead of raising Unknown word. They don't affect ordinary declaration values. Added tokenizer and parser regression tests in 1eada3f.

)
}

// LESS PATCH {
const RE_NEW_LINE = /[\n\f\r]/g
// } LESS PATCH
Expand Down Expand Up @@ -273,7 +286,13 @@ export default function tokenizer(input, options = {}) {
next = RE_WORD_END.lastIndex - 2
}

currentToken = ['word', css.slice(pos, next + 1), pos, next]
content = css.slice(pos, next + 1)
currentToken = [
isMixinToken(content) ? 'mixin' : 'word',
content,
pos,
next,
]
pos = next
}

Expand Down
17 changes: 0 additions & 17 deletions lib/nodes/mixin.js

This file was deleted.

Loading