Skip to content
Merged
Show file tree
Hide file tree
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
5 changes: 4 additions & 1 deletion lib/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ module.exports = function(input) {
} else if (
code === comma ||
code === colon ||
(code === slash && value.charCodeAt(next + 1) !== star)
(code === slash &&
value.charCodeAt(next + 1) !== star &&
(!parent ||
(parent && parent.type === "function" && parent.value !== "calc")))
) {
before = token;
} else {
Expand Down
110 changes: 110 additions & 0 deletions test/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,46 @@ var tests = [
}
]
},
{
message: "should correctly parse subtraction with spaces",
fixture: "calc(1 - 2)",
expected: [
{
type: "function",
sourceIndex: 0,
value: "calc",
before: "",
after: "",
nodes: [
{
type: "word",
sourceIndex: 5,
value: "1"
},
{
type: "space",
sourceIndex: 6,
value: " "
},
{
type: "word",
sourceIndex: 7,
value: "-"
},
{
type: "space",
sourceIndex: 8,
value: " "
},
{
type: "word",
sourceIndex: 9,
value: "2"
}
]
}
]
},
{
message: "should correctly parse multiplication with spaces",
fixture: "calc(1 * 2)",
Expand Down Expand Up @@ -532,6 +572,46 @@ var tests = [
}
]
},
{
message: "should correctly parse division with spaces",
fixture: "calc(1 / 2)",
expected: [
{
type: "function",
sourceIndex: 0,
value: "calc",
before: "",
after: "",
nodes: [
{
type: "word",
sourceIndex: 5,
value: "1"
},
{
type: "space",
sourceIndex: 6,
value: " "
},
{
type: "word",
sourceIndex: 7,
value: "/"
},
{
type: "space",
sourceIndex: 8,
value: " "
},
{
type: "word",
sourceIndex: 9,
value: "2"
}
]
}
]
},
{
message: "should correctly parse multiplication without spaces",
fixture: "calc(1*2)",
Expand Down Expand Up @@ -562,6 +642,36 @@ var tests = [
}
]
},
{
message: "should correctly parse division without spaces",
fixture: "calc(1/2)",
expected: [
{
type: "function",
sourceIndex: 0,
value: "calc",
before: "",
after: "",
nodes: [
{
type: "word",
sourceIndex: 5,
value: "1"
},
{
type: "word",
sourceIndex: 6,
value: "/"
},
{
type: "word",
sourceIndex: 7,
value: "2"
}
]
}
]
},
{
message: "should correctly process nested calc functions",
fixture: "calc(((768px - 100vw) / 2) - 15px)",
Expand Down