Skip to content
Closed
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
28 changes: 14 additions & 14 deletions lib/parsers.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ const SYS_COLORS = new Set([
]);

// AST node types
// TODO: Export and use in properties/*.js in the future
const AST_TYPES = Object.freeze({
CALC: "Calc",
DIMENSION: "Dimension",
Expand Down Expand Up @@ -639,22 +638,23 @@ const parseGradient = (val) => {
};

module.exports = {
prepareValue,
isGlobalKeyword,
hasVarFunc,
AST_TYPES,
hasCalcFunc,
splitValue,
parseCSS,
hasVarFunc,
isGlobalKeyword,
isValidPropertyValue,
resolveCalc,
parsePropertyValue,
parseNumber,
parseAngle,
parseCSS,
parseColor,
parseGradient,
parseLength,
parsePercentage,
parseLengthPercentage,
parseAngle,
parseUrl,
parseNumber,
parsePercentage,
parsePropertyValue,
parseString,
parseColor,
parseGradient
parseUrl,
prepareValue,
resolveCalc,
splitValue
};
58 changes: 45 additions & 13 deletions lib/utils/propertyDescriptors.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,50 @@

const parsers = require("../parsers");

exports.getPropertyDescriptor = function getPropertyDescriptor(property) {
return {
set(v) {
v = parsers.parsePropertyValue(property, v, {
globalObject: this._global
const { AST_TYPES } = parsers;

const getPropertyDescriptor = (property) => ({
set(v) {
const value = parsers.prepareValue(v, this._global);
if (parsers.hasVarFunc(value)) {
this._setProperty(property, value);
} else {
const parsedValue = parsers.parsePropertyValue(property, v, {
globalObject: this._global,
inArray: true
});
this._setProperty(property, v);
},
get() {
return this.getPropertyValue(property);
},
enumerable: true,
configurable: true
};
if (Array.isArray(parsedValue)) {
if (parsedValue.length === 1) {
const [{ name, type }] = parsedValue;
switch (type) {
case AST_TYPES.GLOBAL_KEYWORD:
case AST_TYPES.IDENTIFIER: {
// Set the normalized name for keywords or identifiers.
this._setProperty(property, name);
break;
}
default: {
// Set the prepared value for Calc, Dimension, etc.
this._setProperty(property, value);
}
}
} else {
// Set the prepared value for lists containing multiple values.
this._setProperty(property, value);
}
} else if (typeof parsedValue === "string") {
// Empty string.
this._setProperty(property, parsedValue);
}
}
},
get() {
return this.getPropertyValue(property);
},
enumerable: true,
configurable: true
});

module.exports = {
getPropertyDescriptor
};