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
16 changes: 11 additions & 5 deletions src/js/css-calc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ const REG_TYPE_DIM = new RegExp(`^(${NUM})(${ANGLE}|${LENGTH})$`);
const REG_TYPE_DIM_PCT = new RegExp(`^(${NUM})(${ANGLE}|${LENGTH}|%)$`);
const REG_TYPE_PCT = new RegExp(`^(${NUM})%$`);

/* type definitions */
/**
* @type CalcASTNode - AST node for calc()
*/
type CalcASTNode = string | CalcASTNode[];

/**
* Calclator
*/
Expand Down Expand Up @@ -695,13 +701,13 @@ export const sortCalcValues = (
* @param isRoot - is root node
* @returns resolved value
*/
const resolveNode = (node: any[], isRoot: boolean): string => {
const resolveNode = (node: CalcASTNode[], isRoot: boolean): string => {
const flatItems: string[] = [];
for (const item of node) {
if (Array.isArray(item)) {
flatItems.push(resolveNode(item, false));
} else {
flatItems.push(item as string);
flatItems.push(item);
}
}
if (isRoot) {
Expand Down Expand Up @@ -759,10 +765,10 @@ export const serializeCalc = (value: string, opt: Options = {}): string => {
return res;
})
.filter(v => v);
const stack: any[][] = [[]];
const stack: CalcASTNode[][] = [[]];
for (const item of items) {
if (REG_PAREN_OPEN.test(item)) {
const newNode = [item];
const newNode: CalcASTNode[] = [item];
const parent = stack[stack.length - 1];
if (parent) {
parent.push(newNode);
Expand Down Expand Up @@ -798,7 +804,7 @@ export const serializeCalc = (value: string, opt: Options = {}): string => {
if (Array.isArray(item)) {
flatItems.push(resolveNode(item, false));
} else {
flatItems.push(item as string);
flatItems.push(item);
}
}
if (flatItems.length >= TRIA) {
Expand Down
Loading