|
2 | 2 |
|
3 | 3 | const parsers = require("../parsers"); |
4 | 4 |
|
5 | | -exports.getPropertyDescriptor = function getPropertyDescriptor(property) { |
6 | | - return { |
7 | | - set(v) { |
8 | | - v = parsers.parsePropertyValue(property, v, { |
9 | | - globalObject: this._global |
| 5 | +const { AST_TYPES } = parsers; |
| 6 | + |
| 7 | +const getPropertyDescriptor = (property) => ({ |
| 8 | + set(v) { |
| 9 | + const value = parsers.prepareValue(v, this._global); |
| 10 | + if (parsers.hasVarFunc(value)) { |
| 11 | + this._setProperty(property, value); |
| 12 | + } else { |
| 13 | + const parsedValue = parsers.parsePropertyValue(property, v, { |
| 14 | + globalObject: this._global, |
| 15 | + inArray: true |
10 | 16 | }); |
11 | | - this._setProperty(property, v); |
12 | | - }, |
13 | | - get() { |
14 | | - return this.getPropertyValue(property); |
15 | | - }, |
16 | | - enumerable: true, |
17 | | - configurable: true |
18 | | - }; |
| 17 | + if (Array.isArray(parsedValue)) { |
| 18 | + if (parsedValue.length === 1) { |
| 19 | + const [{ name, type, value: itemValue }] = parsedValue; |
| 20 | + switch (type) { |
| 21 | + case AST_TYPES.CALC: { |
| 22 | + this._setProperty(property, `${name}(${itemValue})`); |
| 23 | + break; |
| 24 | + } |
| 25 | + case AST_TYPES.GLOBAL_KEYWORD: |
| 26 | + case AST_TYPES.IDENTIFIER: { |
| 27 | + // Set the normalized name for keywords or identifiers. |
| 28 | + this._setProperty(property, name); |
| 29 | + break; |
| 30 | + } |
| 31 | + default: { |
| 32 | + // Set the prepared value for Dimension, Function, etc. |
| 33 | + this._setProperty(property, value); |
| 34 | + } |
| 35 | + } |
| 36 | + } else { |
| 37 | + // Set the prepared value for lists containing multiple values. |
| 38 | + this._setProperty(property, value); |
| 39 | + } |
| 40 | + } else if (typeof parsedValue === "string") { |
| 41 | + // Empty string. |
| 42 | + this._setProperty(property, parsedValue); |
| 43 | + } |
| 44 | + } |
| 45 | + }, |
| 46 | + get() { |
| 47 | + return this.getPropertyValue(property); |
| 48 | + }, |
| 49 | + enumerable: true, |
| 50 | + configurable: true |
| 51 | +}); |
| 52 | + |
| 53 | +module.exports = { |
| 54 | + getPropertyDescriptor |
19 | 55 | }; |
0 commit comments