diff --git a/src/index.js b/src/index.js index 420cc15..cb3c083 100644 --- a/src/index.js +++ b/src/index.js @@ -1,5 +1,6 @@ import _ from 'lodash'; import isThere from 'is-there'; +import sass from 'node-sass'; import path, {resolve, basename, extname} from 'path'; import 'json5/lib/register'; // Enable JSON5 support @@ -61,8 +62,8 @@ export function parseValue(value) { return parseList(value); } else if (_.isPlainObject(value)) { return parseMap(value); - } else if (value === '') { - return '""'; // Return explicitly an empty string (Sass would otherwise throw an error as the variable is set to nothing) + } else if (shouldBeStringified(value)) { + return `"${value}"`; } else { return value; } @@ -81,6 +82,18 @@ export function parseMap(map) { .join(',')})`; } +export function shouldBeStringified(value) { + try { + sass.renderSync({ + data: `$foo: ${value};` + }); + + return false; + } catch(error) { + return true + } +} + // Super-hacky: Override Babel's transpiled export to provide both // a default CommonJS export and named exports. // Fixes: https://github.com/Updater/node-sass-json-importer/issues/32