diff --git a/package.json b/package.json index 42d616f4..5f5fd365 100644 --- a/package.json +++ b/package.json @@ -49,6 +49,7 @@ "jest": "26.6.3", "js-yaml": "4.1.0", "postcss": "8.3.0", + "postcss-calc": "8.0.0", "postcss-import": "14.0.2", "postcss-load-config": "3.0.1", "postcss-node-sass": "3.1.0", diff --git a/script/analyze-variables.js b/script/analyze-variables.js index d626e2b2..3bfd3ac0 100755 --- a/script/analyze-variables.js +++ b/script/analyze-variables.js @@ -4,6 +4,7 @@ const {join} = require('path') const fs = require('fs') const atImport = require('postcss-import') const syntax = require('postcss-scss') +const calc = require('postcss-calc') const processor = postcss([ atImport({path: ['src']}), @@ -20,7 +21,14 @@ async function analyzeVariables(fileName) { if (!result.variables[`$${message.name}`].values.includes(message.value)) { result.variables[`$${message.name}`].values.push(message.value) } - const computed = message.value + let computed = message.value + try { + const c = `--temp-property: calc(${message.value})`.replace('round(', '(') + computed = postcss().use(calc()).process(c).css + computed = computed.replace('--temp-property: ', '') + } catch (e) { + // Couldn't calculate because value might not be a number + } result.variables[`$${message.name}`].computed = computed } } diff --git a/yarn.lock b/yarn.lock index 1b4be9f4..fde43311 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5337,6 +5337,14 @@ posix-character-classes@^0.1.0: resolved "https://registry.yarnpkg.com/posix-character-classes/-/posix-character-classes-0.1.1.tgz#01eac0fe3b5af71a2a6c02feabb8c1fef7e00eab" integrity sha1-AerA/jta9xoqbAL+q7jB/vfgDqs= +postcss-calc@8.0.0: + version "8.0.0" + resolved "https://registry.yarnpkg.com/postcss-calc/-/postcss-calc-8.0.0.tgz#a05b87aacd132740a5db09462a3612453e5df90a" + integrity sha512-5NglwDrcbiy8XXfPM11F3HeC6hoT9W7GUH/Zi5U/p7u3Irv4rHhdDcIZwG0llHXV4ftsBjpfWMXAnXNl4lnt8g== + dependencies: + postcss-selector-parser "^6.0.2" + postcss-value-parser "^4.0.2" + postcss-custom-properties@^10.0.0: version "10.0.0" resolved "https://registry.yarnpkg.com/postcss-custom-properties/-/postcss-custom-properties-10.0.0.tgz#5cb31afc530f58ad241f1e836dd5f5f7065334df"