@tbela99/css-parser 2.0.1 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +86 -1
- package/README.md +15 -7
- package/architecture.png +0 -0
- package/dist/{src/data → data}/properties.json.js +86 -2
- package/dist/{src/data → data}/validation.json.js +4848 -3750
- package/dist/index-umd-web.js +18234 -9498
- package/dist/index.d.ts +1251 -373
- package/dist/{src/lib → lib}/ast/arena-node.js +119 -57
- package/dist/{src/lib → lib}/ast/arena.js +1034 -655
- package/dist/{src/lib → lib}/ast/cache.js +36 -31
- package/dist/{src/lib → lib}/ast/features/calc.js +37 -27
- package/dist/{src/lib → lib}/ast/features/if.js +24 -19
- package/dist/{src/lib → lib}/ast/features/index.js +3 -2
- package/dist/{src/lib → lib}/ast/features/inlinecssvariables.js +42 -23
- package/dist/lib/ast/features/mixin.js +953 -0
- package/dist/{src/lib → lib}/ast/features/prefix.js +82 -69
- package/dist/lib/ast/features/shorthand.js +129 -0
- package/dist/lib/ast/features/transform.js +188 -0
- package/dist/{src/lib → lib}/ast/features/type.js +2 -2
- package/dist/{src/lib → lib}/ast/math/expression.js +150 -150
- package/dist/{src/lib → lib}/ast/math/math.js +8 -8
- package/dist/{src/lib → lib}/ast/minify.js +932 -354
- package/dist/lib/ast/mixins/custom-function.js +393 -0
- package/dist/lib/ast/mixins/utils.js +53 -0
- package/dist/lib/ast/mixins/variables.js +678 -0
- package/dist/lib/ast/strings.js +906 -0
- package/dist/lib/ast/transform/compute.js +560 -0
- package/dist/lib/ast/transform/matrix.js +67 -0
- package/dist/lib/ast/transform/minify.js +325 -0
- package/dist/lib/ast/transform/perspective.js +24 -0
- package/dist/{src/lib → lib}/ast/transform/rotate.js +16 -7
- package/dist/lib/ast/transform/scale.js +43 -0
- package/dist/lib/ast/transform/skew.js +38 -0
- package/dist/lib/ast/transform/translate.js +56 -0
- package/dist/lib/ast/transform/utils.js +390 -0
- package/dist/{src/lib → lib}/ast/types.js +7 -15
- package/dist/{src/lib → lib}/ast/walk.js +19 -19
- package/dist/{src/lib → lib}/fs/resolve.js +15 -15
- package/dist/{src/lib → lib}/parser/declaration/list.js +55 -26
- package/dist/{src/lib → lib}/parser/declaration/map.js +85 -72
- package/dist/{src/lib → lib}/parser/declaration/set.js +32 -27
- package/dist/lib/parser/input.js +85 -0
- package/dist/{src/lib → lib}/parser/linesmap.js +3 -16
- package/dist/{src/lib → lib}/parser/parse.js +852 -619
- package/dist/lib/parser/source.js +71 -0
- package/dist/{src/lib → lib}/parser/tokenize.js +886 -722
- package/dist/{src/lib → lib}/parser/utils/angle.js +3 -3
- package/dist/{src/lib → lib}/parser/utils/at-rule-container.js +68 -35
- package/dist/{src/lib → lib}/parser/utils/at-rule-font-feature-values.js +3 -3
- package/dist/{src/lib → lib}/parser/utils/at-rule-generic.js +31 -13
- package/dist/{src/lib → lib}/parser/utils/at-rule-import.js +29 -16
- package/dist/{src/lib → lib}/parser/utils/at-rule-media.js +77 -58
- package/dist/{src/lib → lib}/parser/utils/at-rule-support.js +18 -20
- package/dist/{src/lib → lib}/parser/utils/at-rule-when-else.js +9 -8
- package/dist/{src/lib → lib}/parser/utils/at-rule.js +3 -3
- package/dist/{src/lib → lib}/parser/utils/base64.js +2 -2
- package/dist/lib/parser/utils/cache.js +53 -0
- package/dist/lib/parser/utils/canonical.js +78 -0
- package/dist/lib/parser/utils/codes.js +93 -0
- package/dist/{src/lib → lib}/parser/utils/config.js +2 -2
- package/dist/{src/lib → lib}/parser/utils/declaration.js +67 -49
- package/dist/{src/lib → lib}/parser/utils/eq.js +14 -14
- package/dist/{src/lib → lib}/parser/utils/hash.js +4 -4
- package/dist/lib/parser/utils/selector.js +720 -0
- package/dist/{src/lib → lib}/parser/utils/text.js +2 -2
- package/dist/{src/lib → lib}/parser/utils/token.js +2 -2
- package/dist/{src/lib → lib}/parser/utils/type.js +11 -9
- package/dist/{src/lib → lib}/printer/render.js +536 -243
- package/dist/lib/printer/result.js +148 -0
- package/dist/{src/lib → lib}/printer/sourcemap/lib/codec.js +5 -8
- package/dist/{src/lib → lib}/printer/sourcemap/sourcemap.js +13 -13
- package/dist/lib/printer/writer.js +252 -0
- package/dist/{src/lib → lib}/syntax/color/a98rgb.js +6 -6
- package/dist/{src/lib → lib}/syntax/color/alpha.js +12 -11
- package/dist/{src/lib → lib}/syntax/color/cmyk.js +11 -6
- package/dist/{src/lib → lib}/syntax/color/color-mix.js +78 -67
- package/dist/{src/lib → lib}/syntax/color/color.js +52 -47
- package/dist/{src/lib → lib}/syntax/color/hex.js +17 -17
- package/dist/{src/lib → lib}/syntax/color/hsl.js +8 -8
- package/dist/{src/lib → lib}/syntax/color/hwb.js +6 -7
- package/dist/{src/lib → lib}/syntax/color/lab.js +8 -8
- package/dist/{src/lib → lib}/syntax/color/lch.js +12 -11
- package/dist/{src/lib → lib}/syntax/color/oklab.js +9 -9
- package/dist/{src/lib → lib}/syntax/color/oklch.js +5 -5
- package/dist/{src/lib → lib}/syntax/color/p3.js +2 -2
- package/dist/{src/lib → lib}/syntax/color/prophotorgb.js +4 -4
- package/dist/{src/lib → lib}/syntax/color/rec2020.js +3 -3
- package/dist/{src/lib → lib}/syntax/color/relative-color.js +41 -34
- package/dist/{src/lib → lib}/syntax/color/rgb.js +17 -17
- package/dist/{src/lib → lib}/syntax/color/srgb.js +20 -20
- package/dist/{src/lib → lib}/syntax/color/utils/color-type.js +6 -4
- package/dist/{src/lib → lib}/syntax/color/utils/colorspace.js +12 -14
- package/dist/{src/lib → lib}/syntax/color/utils/components.js +13 -13
- package/dist/{src/lib → lib}/syntax/color/utils/distance.js +2 -2
- package/dist/{src/lib → lib}/syntax/color/utils/make-color.js +6 -4
- package/dist/{src/lib → lib}/syntax/color/utils/matrix.js +2 -2
- package/dist/{src/lib → lib}/syntax/color/xyz.js +5 -10
- package/dist/{src/lib → lib}/syntax/color/xyzd50.js +3 -3
- package/dist/{src/lib → lib}/syntax/constants.js +30 -3
- package/dist/{src/lib → lib}/syntax/syntax.js +151 -116
- package/dist/lib/validation/config.js +173 -0
- package/dist/lib/validation/first.js +571 -0
- package/dist/{src/lib → lib}/validation/match.js +1256 -579
- package/dist/{src/lib → lib}/validation/parser/parse.js +85 -59
- package/dist/{src/lib → lib}/validation/parser/typedef.js +6 -2
- package/dist/{src/lib → lib}/validation/utils/list.js +3 -19
- package/dist/{src/node.js → node.js} +92 -80
- package/dist/{src/types.js → types.js} +2 -2
- package/dist/{src/utils → utils}/sync.js +13 -8
- package/dist/version.d.ts +4 -0
- package/dist/version.js +13 -0
- package/dist/{src/web.js → web.js} +80 -75
- package/package.json +13 -13
- package/dist/package.json.js +0 -10
- package/dist/src/lib/ast/features/shorthand.js +0 -87
- package/dist/src/lib/ast/features/transform.js +0 -85
- package/dist/src/lib/ast/transform/compute.js +0 -358
- package/dist/src/lib/ast/transform/matrix.js +0 -88
- package/dist/src/lib/ast/transform/minify.js +0 -267
- package/dist/src/lib/ast/transform/perspective.js +0 -16
- package/dist/src/lib/ast/transform/scale.js +0 -39
- package/dist/src/lib/ast/transform/skew.js +0 -30
- package/dist/src/lib/ast/transform/translate.js +0 -39
- package/dist/src/lib/ast/transform/utils.js +0 -287
- package/dist/src/lib/parser/source.js +0 -127
- package/dist/src/lib/parser/utils/cache.js +0 -54
- package/dist/src/lib/parser/utils/selector.js +0 -440
- package/dist/src/lib/validation/config.js +0 -120
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/*
|
|
2
|
-
CSS parser, minifier and validator for node and the browser
|
|
2
|
+
CSS parser, minifier and validator for node, deno, bun and the browser
|
|
3
3
|
|
|
4
4
|
Author(s): Thierry Bela
|
|
5
|
-
Version: 2.0
|
|
5
|
+
Version: 2.2.0
|
|
6
6
|
License: MIT
|
|
7
7
|
*/
|
|
8
8
|
import { numericTokenTypes, TokenField } from '../arena.js';
|
|
@@ -19,7 +19,7 @@ const numbers = new Set(["sin", "cos", "asin", "acos", "sign", "tan"]);
|
|
|
19
19
|
*/
|
|
20
20
|
function numericValue(arena, token) {
|
|
21
21
|
const fraction = arena.getFraction(token);
|
|
22
|
-
if (fraction
|
|
22
|
+
if (fraction !== 0) {
|
|
23
23
|
return [arena.numericValue[arena.firstChild[fraction]], arena.numericValue[arena.lastChild[fraction]]];
|
|
24
24
|
}
|
|
25
25
|
return getValue(arena, token);
|
|
@@ -31,7 +31,7 @@ function numericValue(arena, token) {
|
|
|
31
31
|
* @param val
|
|
32
32
|
*/
|
|
33
33
|
function setNumericValue(arena, token, val) {
|
|
34
|
-
if (typeof val
|
|
34
|
+
if (typeof val === "number") {
|
|
35
35
|
arena.setFraction(token, null);
|
|
36
36
|
arena.numericValue[token] = val;
|
|
37
37
|
return;
|
|
@@ -66,17 +66,17 @@ function evaluate(arena, tokens) {
|
|
|
66
66
|
*/
|
|
67
67
|
function evaluateTokens(arena, tokens) {
|
|
68
68
|
let nodes;
|
|
69
|
-
if (tokens.length
|
|
70
|
-
(arena.dataTypes[tokens[0]]
|
|
71
|
-
arena.dataTypes[tokens[0]]
|
|
72
|
-
mathFuncs.includes(arena.
|
|
69
|
+
if (tokens.length === 1 &&
|
|
70
|
+
(arena.dataTypes[tokens[0]] === EnumToken.MathFunctionTokenType ||
|
|
71
|
+
arena.dataTypes[tokens[0]] === EnumToken.FunctionTokenType) &&
|
|
72
|
+
mathFuncs.includes(arena.resolveString(arena.stringValue[tokens[0]]))) {
|
|
73
73
|
const chi = [];
|
|
74
|
-
for (let t = arena.firstToken[tokens[0]]; t
|
|
74
|
+
for (let t = arena.firstToken[tokens[0]]; t !== 0; t = arena.nextSibling[t]) {
|
|
75
75
|
const typ = arena.dataTypes[t];
|
|
76
|
-
if (chi.length
|
|
76
|
+
if (chi.length === 0 || typ === EnumToken.CommaTokenType) {
|
|
77
77
|
chi.push([]);
|
|
78
78
|
}
|
|
79
|
-
if (typ
|
|
79
|
+
if (typ === EnumToken.WhitespaceTokenType || typ === EnumToken.CommaTokenType) {
|
|
80
80
|
continue;
|
|
81
81
|
}
|
|
82
82
|
chi[chi.length - 1].push(t);
|
|
@@ -96,7 +96,7 @@ function evaluateTokens(arena, tokens) {
|
|
|
96
96
|
return tokens;
|
|
97
97
|
}
|
|
98
98
|
if (arena.dataTypes[result[0]] === EnumToken.MathFunctionTokenType &&
|
|
99
|
-
arena.
|
|
99
|
+
arena.resolveString(arena.stringValue[result[0]]) === "calc" &&
|
|
100
100
|
arena.tokenCount(result[0]) === 1) {
|
|
101
101
|
return arena.tokens(result[0]);
|
|
102
102
|
}
|
|
@@ -104,15 +104,15 @@ function evaluateTokens(arena, tokens) {
|
|
|
104
104
|
}
|
|
105
105
|
nodes = inlineExpression(arena, evaluateExpression(arena, buildExpression(arena, tokens)));
|
|
106
106
|
if (nodes.length <= 1) {
|
|
107
|
-
if (nodes.length
|
|
108
|
-
if (arena.dataTypes[nodes[0]]
|
|
107
|
+
if (nodes.length === 1) {
|
|
108
|
+
if (arena.dataTypes[nodes[0]] === EnumToken.BinaryExpressionTokenType) {
|
|
109
109
|
return inlineExpression(arena, nodes[0]);
|
|
110
110
|
}
|
|
111
|
-
if (arena.dataTypes[nodes[0]]
|
|
111
|
+
if (arena.dataTypes[nodes[0]] === EnumToken.IdenTokenType &&
|
|
112
112
|
// @ts-expect-error
|
|
113
|
-
typeof Math[arena.
|
|
113
|
+
typeof Math[arena.resolveString(arena.stringValue[nodes[0]]).toUpperCase()] === "number") {
|
|
114
114
|
// @ts-ignore
|
|
115
|
-
const val = Math[arena.
|
|
115
|
+
const val = Math[arena.resolveString(arena.stringValue[nodes[0]]).toUpperCase()];
|
|
116
116
|
arena.resetToken(nodes[0], EnumToken.NumberTokenType, val);
|
|
117
117
|
return nodes;
|
|
118
118
|
}
|
|
@@ -126,10 +126,10 @@ function evaluateTokens(arena, tokens) {
|
|
|
126
126
|
for (i = 0; i < nodes.length; i++) {
|
|
127
127
|
token = nodes[i];
|
|
128
128
|
typ = arena.dataTypes[token];
|
|
129
|
-
if (typ
|
|
129
|
+
if (typ === EnumToken.Add || typ === EnumToken.Plus) {
|
|
130
130
|
continue;
|
|
131
131
|
}
|
|
132
|
-
if (typ
|
|
132
|
+
if (typ === EnumToken.Sub) {
|
|
133
133
|
if (!isScalarToken(arena, nodes[i + 1])) {
|
|
134
134
|
token = arena.createList(EnumToken.ListToken, [nodes[i], nodes[i + 1]]);
|
|
135
135
|
arena.spanLocation(token, nodes[i], nodes[i + 1]);
|
|
@@ -150,7 +150,7 @@ function evaluateTokens(arena, tokens) {
|
|
|
150
150
|
const result = [];
|
|
151
151
|
for (const [key, values] of map) {
|
|
152
152
|
const token = values.reduce((acc, curr) => doEvaluate(arena, acc, curr, EnumToken.Add));
|
|
153
|
-
if (arena.dataTypes[token]
|
|
153
|
+
if (arena.dataTypes[token] !== EnumToken.BinaryExpressionTokenType) {
|
|
154
154
|
// inlined: arena.isNumeric(token)
|
|
155
155
|
if (numericTokenTypes.has(arena.dataTypes[token]) && arena.numericValue[token] < 0) {
|
|
156
156
|
arena.numericValue[token] = -arena.numericValue[token];
|
|
@@ -158,9 +158,9 @@ function evaluateTokens(arena, tokens) {
|
|
|
158
158
|
continue;
|
|
159
159
|
}
|
|
160
160
|
}
|
|
161
|
-
if (result.length > 0 && key
|
|
161
|
+
if (result.length > 0 && key !== EnumToken.ListToken) {
|
|
162
162
|
// inlined: arena.isNumeric(token)
|
|
163
|
-
if (numericTokenTypes.has(arena.dataTypes[token]) && arena.numericValue[token]
|
|
163
|
+
if (numericTokenTypes.has(arena.dataTypes[token]) && arena.numericValue[token] === 0) {
|
|
164
164
|
continue;
|
|
165
165
|
}
|
|
166
166
|
result.push(tokenAt(arena, EnumToken.Add, token));
|
|
@@ -186,11 +186,11 @@ function doEvaluate(arena, l, r, op) {
|
|
|
186
186
|
let rType = arena.dataTypes[r];
|
|
187
187
|
if (!isScalarToken(arena, l) ||
|
|
188
188
|
!isScalarToken(arena, r) ||
|
|
189
|
-
(lType
|
|
189
|
+
(lType === rType && arena.unit[l] !== 0 && arena.unit[r] !== 0 && arena.unit[l] !== arena.unit[r])) {
|
|
190
190
|
return defaultReturn();
|
|
191
191
|
}
|
|
192
|
-
if (lType
|
|
193
|
-
const val = arena.
|
|
192
|
+
if (lType === EnumToken.IdenTokenType) {
|
|
193
|
+
const val = arena.resolveString(arena.stringValue[l]);
|
|
194
194
|
if (equalsIgnoreCase(val, "Infinity")) {
|
|
195
195
|
arena.dataTypes[l] = lType = EnumToken.InfinityTokenType;
|
|
196
196
|
}
|
|
@@ -201,8 +201,8 @@ function doEvaluate(arena, l, r, op) {
|
|
|
201
201
|
arena.dataTypes[l] = lType = EnumToken.NaNTokenType;
|
|
202
202
|
}
|
|
203
203
|
}
|
|
204
|
-
if (rType
|
|
205
|
-
const val = arena.
|
|
204
|
+
if (rType === EnumToken.IdenTokenType) {
|
|
205
|
+
const val = arena.resolveString(arena.stringValue[r]);
|
|
206
206
|
if (equalsIgnoreCase(val, "Infinity")) {
|
|
207
207
|
arena.dataTypes[r] = rType = EnumToken.InfinityTokenType;
|
|
208
208
|
}
|
|
@@ -211,80 +211,80 @@ function doEvaluate(arena, l, r, op) {
|
|
|
211
211
|
}
|
|
212
212
|
}
|
|
213
213
|
// https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Values/calc-keyword#notes
|
|
214
|
-
if (lType
|
|
214
|
+
if (lType === EnumToken.NaNTokenType || rType === EnumToken.NaNTokenType) {
|
|
215
215
|
return computeNaN(arena, l, r, defaultReturn);
|
|
216
216
|
}
|
|
217
|
-
if (lType
|
|
218
|
-
lType
|
|
219
|
-
rType
|
|
220
|
-
rType
|
|
217
|
+
if (lType === EnumToken.InfinityTokenType ||
|
|
218
|
+
lType === EnumToken.NegativeInfinityTokenType ||
|
|
219
|
+
rType === EnumToken.InfinityTokenType ||
|
|
220
|
+
rType === EnumToken.NegativeInfinityTokenType) {
|
|
221
221
|
return computeInfinity(arena, l, r, op, defaultReturn);
|
|
222
222
|
}
|
|
223
|
-
if (lType
|
|
223
|
+
if (lType === EnumToken.FunctionTokenType || lType === EnumToken.MathFunctionTokenType) {
|
|
224
224
|
const val = evaluateFunc(arena, l);
|
|
225
225
|
if (val == null ||
|
|
226
|
-
(val.length
|
|
227
|
-
(arena.dataTypes[val[0]]
|
|
228
|
-
arena.dataTypes[val[0]]
|
|
226
|
+
(val.length === 1 &&
|
|
227
|
+
(arena.dataTypes[val[0]] === EnumToken.MathFunctionTokenType ||
|
|
228
|
+
arena.dataTypes[val[0]] === EnumToken.FunctionTokenType))) {
|
|
229
229
|
return defaultReturn();
|
|
230
230
|
}
|
|
231
|
-
if (val.length
|
|
231
|
+
if (val.length === 1) {
|
|
232
232
|
l = val[0];
|
|
233
233
|
lType = arena.dataTypes[l];
|
|
234
234
|
}
|
|
235
235
|
}
|
|
236
|
-
if (rType
|
|
236
|
+
if (rType === EnumToken.FunctionTokenType || rType === EnumToken.MathFunctionTokenType) {
|
|
237
237
|
const val = evaluateFunc(arena, r);
|
|
238
238
|
if (val == null ||
|
|
239
|
-
(val.length
|
|
240
|
-
(arena.dataTypes[val[0]]
|
|
241
|
-
arena.dataTypes[val[0]]
|
|
239
|
+
(val.length === 1 &&
|
|
240
|
+
(arena.dataTypes[val[0]] === EnumToken.MathFunctionTokenType ||
|
|
241
|
+
arena.dataTypes[val[0]] === EnumToken.FunctionTokenType))) {
|
|
242
242
|
return defaultReturn();
|
|
243
243
|
}
|
|
244
|
-
if (val.length
|
|
244
|
+
if (val.length === 1) {
|
|
245
245
|
r = val[0];
|
|
246
246
|
rType = arena.dataTypes[r];
|
|
247
247
|
}
|
|
248
248
|
}
|
|
249
|
-
if (op
|
|
250
|
-
if (lType
|
|
249
|
+
if (op === EnumToken.Add || op === EnumToken.Plus || op === EnumToken.Sub) {
|
|
250
|
+
if (lType !== rType) {
|
|
251
251
|
return defaultReturn();
|
|
252
252
|
}
|
|
253
253
|
}
|
|
254
|
-
let typ = lType
|
|
254
|
+
let typ = lType === EnumToken.NumberTokenType || lType === EnumToken.IdenTokenType
|
|
255
255
|
? rType
|
|
256
|
-
: rType
|
|
256
|
+
: rType === EnumToken.NumberTokenType
|
|
257
257
|
? lType
|
|
258
|
-
: lType
|
|
258
|
+
: lType === EnumToken.PercentageTokenType
|
|
259
259
|
? rType
|
|
260
260
|
: lType;
|
|
261
261
|
let v1 = numericValue(arena, l);
|
|
262
262
|
let v2 = numericValue(arena, r);
|
|
263
|
-
if (op
|
|
264
|
-
if (lType
|
|
265
|
-
if (typeof v1
|
|
263
|
+
if (op === EnumToken.Mul) {
|
|
264
|
+
if (lType !== EnumToken.NumberTokenType && rType !== EnumToken.NumberTokenType) {
|
|
265
|
+
if (typeof v1 === "number" && lType === EnumToken.PercentageTokenType) {
|
|
266
266
|
v1 = [v1, 100];
|
|
267
267
|
}
|
|
268
|
-
else if (typeof v2
|
|
268
|
+
else if (typeof v2 === "number" && rType === EnumToken.PercentageTokenType) {
|
|
269
269
|
v2 = [v2, 100];
|
|
270
270
|
}
|
|
271
271
|
}
|
|
272
272
|
}
|
|
273
|
-
if (op
|
|
273
|
+
if (op === EnumToken.Div && v2 == 0) {
|
|
274
274
|
if (v1 == 0) {
|
|
275
275
|
arena.resetToken(l, EnumToken.IdenTokenType, "NaN");
|
|
276
276
|
return l;
|
|
277
277
|
}
|
|
278
278
|
let sign = Math.sign(v1) * Math.sign(v2);
|
|
279
279
|
sign = Object.is(sign, -0) ? -1 : 1;
|
|
280
|
-
arena.resetToken(l, lType
|
|
280
|
+
arena.resetToken(l, lType === EnumToken.IdenTokenType ? EnumToken.NumberTokenType : lType, sign);
|
|
281
281
|
return defaultReturn();
|
|
282
282
|
}
|
|
283
283
|
// @ts-ignore
|
|
284
284
|
const val = compute(v1, v2, op);
|
|
285
285
|
// the result inherits the unit of the dimension operand
|
|
286
286
|
const base = lType === EnumToken.NumberTokenType || lType === EnumToken.IdenTokenType ? r : l;
|
|
287
|
-
const token = arena.createToken(typ
|
|
287
|
+
const token = arena.createToken(typ === EnumToken.IdenTokenType ? EnumToken.NumberTokenType : typ);
|
|
288
288
|
arena.unit[token] = arena.unit[base];
|
|
289
289
|
setNumericValue(arena, token, val);
|
|
290
290
|
arena.spanLocation(token, l, r);
|
|
@@ -301,30 +301,30 @@ function doEvaluate(arena, l, r, op) {
|
|
|
301
301
|
function computeNaN(arena, l, r, defaultReturn) {
|
|
302
302
|
const lType = arena.dataTypes[l];
|
|
303
303
|
const rType = arena.dataTypes[r];
|
|
304
|
-
if (lType
|
|
305
|
-
if (rType
|
|
306
|
-
(rType
|
|
304
|
+
if (lType === EnumToken.NaNTokenType) {
|
|
305
|
+
if (rType === EnumToken.NumberTokenType ||
|
|
306
|
+
(rType === EnumToken.IdenTokenType &&
|
|
307
307
|
// @ts-expect-error
|
|
308
|
-
typeof Math[arena.
|
|
308
|
+
typeof Math[arena.resolveString(arena.stringValue[r]).toUpperCase()] === "string")) {
|
|
309
309
|
return l;
|
|
310
310
|
}
|
|
311
311
|
// NaN Infinity e pi ...
|
|
312
|
-
if (rType
|
|
313
|
-
rType
|
|
314
|
-
rType
|
|
312
|
+
if (rType === EnumToken.IdenTokenType ||
|
|
313
|
+
rType === EnumToken.InfinityTokenType ||
|
|
314
|
+
rType === EnumToken.NegativeInfinityTokenType) {
|
|
315
315
|
return l;
|
|
316
316
|
}
|
|
317
317
|
// inlined: arena.isNumeric(r)
|
|
318
318
|
if (numericTokenTypes.has(arena.dataTypes[r])) {
|
|
319
319
|
setNumericValue(arena, r, 1);
|
|
320
320
|
}
|
|
321
|
-
return rType
|
|
321
|
+
return rType === EnumToken.NaNTokenType ? l : defaultReturn();
|
|
322
322
|
}
|
|
323
|
-
if (rType
|
|
324
|
-
if (lType
|
|
325
|
-
(lType
|
|
323
|
+
if (rType === EnumToken.NaNTokenType) {
|
|
324
|
+
if (lType === EnumToken.NumberTokenType ||
|
|
325
|
+
(lType === EnumToken.IdenTokenType &&
|
|
326
326
|
// @ts-expect-error
|
|
327
|
-
typeof Math[arena.
|
|
327
|
+
typeof Math[arena.resolveString(arena.stringValue[l]).toUpperCase()] === "string")) {
|
|
328
328
|
return r;
|
|
329
329
|
}
|
|
330
330
|
// inlined: arena.isNumeric(l)
|
|
@@ -346,61 +346,61 @@ function computeNaN(arena, l, r, defaultReturn) {
|
|
|
346
346
|
function computeInfinity(arena, l, r, op, defaultReturn) {
|
|
347
347
|
const lType = arena.dataTypes[l];
|
|
348
348
|
const rType = arena.dataTypes[r];
|
|
349
|
-
if (lType
|
|
350
|
-
if (rType
|
|
349
|
+
if (lType === EnumToken.InfinityTokenType || lType === EnumToken.NegativeInfinityTokenType) {
|
|
350
|
+
if (rType === EnumToken.InfinityTokenType || rType === EnumToken.NegativeInfinityTokenType) {
|
|
351
351
|
// Infinity / Infinity Infinity - Infinity
|
|
352
|
-
if (op
|
|
352
|
+
if (op === EnumToken.Div || (op === EnumToken.Add && lType !== rType) || (op === EnumToken.Sub && lType === rType)) {
|
|
353
353
|
arena.dataTypes[l] = EnumToken.NaNTokenType;
|
|
354
354
|
return l;
|
|
355
355
|
}
|
|
356
|
-
if (lType
|
|
356
|
+
if (lType !== rType) {
|
|
357
357
|
arena.dataTypes[l] = EnumToken.NegativeInfinityTokenType;
|
|
358
358
|
}
|
|
359
359
|
return l;
|
|
360
360
|
}
|
|
361
361
|
const value = getValue(arena, r);
|
|
362
362
|
const sign = Math.sign(value);
|
|
363
|
-
const isNumber = rType
|
|
363
|
+
const isNumber = rType === EnumToken.NumberTokenType || rType === EnumToken.IdenTokenType;
|
|
364
364
|
// Infinity * 0
|
|
365
|
-
if (value
|
|
365
|
+
if (value === 0 && op === EnumToken.Mul) {
|
|
366
366
|
arena.dataTypes[l] = EnumToken.NaNTokenType;
|
|
367
367
|
return isNumber ? l : defaultReturn();
|
|
368
368
|
}
|
|
369
369
|
if (isNumber) {
|
|
370
370
|
arena.numericValue[r] /= arena.numericValue[r] * sign;
|
|
371
371
|
}
|
|
372
|
-
if (op
|
|
372
|
+
if (op === EnumToken.Div) {
|
|
373
373
|
if (isNumber) {
|
|
374
374
|
arena.resetToken(r, EnumToken.NumberTokenType, sign < 0 ? -0 : 0);
|
|
375
375
|
return r;
|
|
376
376
|
}
|
|
377
377
|
return defaultReturn();
|
|
378
378
|
}
|
|
379
|
-
if (sign
|
|
379
|
+
if (sign === -1) {
|
|
380
380
|
arena.dataTypes[l] =
|
|
381
|
-
lType
|
|
381
|
+
lType === EnumToken.InfinityTokenType ? EnumToken.NegativeInfinityTokenType : EnumToken.InfinityTokenType;
|
|
382
382
|
}
|
|
383
383
|
return isNumber ? l : defaultReturn();
|
|
384
384
|
}
|
|
385
|
-
if (rType
|
|
385
|
+
if (rType === EnumToken.InfinityTokenType || rType === EnumToken.NegativeInfinityTokenType) {
|
|
386
386
|
const value = getValue(arena, l);
|
|
387
387
|
let sign = Math.sign(value);
|
|
388
|
-
const isNumber = lType
|
|
388
|
+
const isNumber = lType === EnumToken.NumberTokenType || lType === EnumToken.IdenTokenType;
|
|
389
389
|
if (isNumber) {
|
|
390
390
|
arena.resetToken(l, EnumToken.NumberTokenType, sign);
|
|
391
391
|
}
|
|
392
|
-
if (value
|
|
392
|
+
if (value === 0 && op === EnumToken.Mul) {
|
|
393
393
|
arena.dataTypes[l] = EnumToken.NaNTokenType;
|
|
394
394
|
return l;
|
|
395
395
|
}
|
|
396
|
-
if (op
|
|
396
|
+
if (op === EnumToken.Div) {
|
|
397
397
|
if (isNumber) {
|
|
398
398
|
arena.resetToken(l, EnumToken.NumberTokenType, sign < 0 ? -0 : 0);
|
|
399
399
|
return l;
|
|
400
400
|
}
|
|
401
401
|
return defaultReturn();
|
|
402
402
|
}
|
|
403
|
-
return isNumber || value
|
|
403
|
+
return isNumber || value === 0 ? r : defaultReturn();
|
|
404
404
|
}
|
|
405
405
|
return defaultReturn();
|
|
406
406
|
}
|
|
@@ -411,11 +411,11 @@ function computeInfinity(arena, l, r, op, defaultReturn) {
|
|
|
411
411
|
*/
|
|
412
412
|
function getValue(arena, t) {
|
|
413
413
|
const typ = arena.dataTypes[t];
|
|
414
|
-
if (typ
|
|
414
|
+
if (typ === EnumToken.IdenTokenType) {
|
|
415
415
|
// @ts-ignore
|
|
416
|
-
return Math[arena.
|
|
416
|
+
return Math[arena.resolveString(arena.stringValue[t]).toUpperCase()];
|
|
417
417
|
}
|
|
418
|
-
if (typ
|
|
418
|
+
if (typ === EnumToken.FractionTokenType) {
|
|
419
419
|
return arena.numericValue[arena.firstChild[t]] / arena.numericValue[arena.lastChild[t]];
|
|
420
420
|
}
|
|
421
421
|
// inlined: arena.isNumeric(t)
|
|
@@ -424,7 +424,7 @@ function getValue(arena, t) {
|
|
|
424
424
|
return NaN;
|
|
425
425
|
}
|
|
426
426
|
const fraction = arena.getFraction(t);
|
|
427
|
-
if (fraction
|
|
427
|
+
if (fraction !== 0) {
|
|
428
428
|
return arena.numericValue[arena.firstChild[fraction]] / arena.numericValue[arena.lastChild[fraction]];
|
|
429
429
|
}
|
|
430
430
|
return arena.numericValue[t];
|
|
@@ -435,13 +435,13 @@ function getValue(arena, t) {
|
|
|
435
435
|
* @param token
|
|
436
436
|
*/
|
|
437
437
|
function toRadians(arena, token) {
|
|
438
|
-
if (arena.dataTypes[token]
|
|
438
|
+
if (arena.dataTypes[token] === EnumToken.NumberTokenType) {
|
|
439
439
|
arena.dataTypes[token] = EnumToken.AngleTokenType;
|
|
440
440
|
// inlined: arena.setUnitString(token, "rad")
|
|
441
441
|
arena.unit[token] = arena.internString("rad");
|
|
442
442
|
}
|
|
443
|
-
else if (arena.dataTypes[token]
|
|
444
|
-
switch (arena.
|
|
443
|
+
else if (arena.dataTypes[token] === EnumToken.AngleTokenType && arena.resolveString(arena.unit[token]) !== "rad") {
|
|
444
|
+
switch (arena.resolveString(arena.unit[token])) {
|
|
445
445
|
case "deg":
|
|
446
446
|
arena.numericValue[token] *= Math.PI / 180;
|
|
447
447
|
// inlined: arena.setUnitString(token, "rad")
|
|
@@ -468,7 +468,7 @@ function toRadians(arena, token) {
|
|
|
468
468
|
*/
|
|
469
469
|
function evaluateFunc(arena, token) {
|
|
470
470
|
const values = arena.tokens(token);
|
|
471
|
-
const name = arena.
|
|
471
|
+
const name = arena.resolveString(arena.stringValue[token]);
|
|
472
472
|
switch (name) {
|
|
473
473
|
case "sin":
|
|
474
474
|
case "cos":
|
|
@@ -484,15 +484,15 @@ function evaluateFunc(arena, token) {
|
|
|
484
484
|
case "sqrt":
|
|
485
485
|
case "exp": {
|
|
486
486
|
const value = evaluateTokens(arena, values);
|
|
487
|
-
let val = arena.dataTypes[value[0]]
|
|
488
|
-
arena.dataTypes[value[0]]
|
|
489
|
-
arena.dataTypes[value[0]]
|
|
487
|
+
let val = arena.dataTypes[value[0]] === EnumToken.NumberTokenType ||
|
|
488
|
+
arena.dataTypes[value[0]] === EnumToken.AngleTokenType ||
|
|
489
|
+
arena.dataTypes[value[0]] === EnumToken.PercentageTokenType
|
|
490
490
|
? getValue(arena, value[0])
|
|
491
491
|
: getValue(arena, value[0]);
|
|
492
492
|
// @ts-ignore
|
|
493
493
|
const computed = Math[name](val);
|
|
494
494
|
return [
|
|
495
|
-
name
|
|
495
|
+
name === "asin" || name === "acos" || name === "atan"
|
|
496
496
|
? tokenAt(arena, EnumToken.AngleTokenType, value[0], computed, "rad")
|
|
497
497
|
: tokenAt(arena, numbers.has(name) ? EnumToken.NumberTokenType : arena.dataTypes[value[0]], value[0], computed),
|
|
498
498
|
];
|
|
@@ -519,20 +519,20 @@ function evaluateFunc(arena, token) {
|
|
|
519
519
|
case "rem": {
|
|
520
520
|
{
|
|
521
521
|
const first = arena.firstToken[token];
|
|
522
|
-
const typ = first
|
|
523
|
-
for (let t = first
|
|
524
|
-
if (arena.dataTypes[t]
|
|
525
|
-
arena.dataTypes[t]
|
|
526
|
-
arena.dataTypes[t]
|
|
522
|
+
const typ = first === 0 ? 0 : arena.dataTypes[first];
|
|
523
|
+
for (let t = first === 0 ? 0 : arena.nextSibling[first]; t !== 0; t = arena.nextSibling[t]) {
|
|
524
|
+
if (arena.dataTypes[t] === EnumToken.WhitespaceTokenType ||
|
|
525
|
+
arena.dataTypes[t] === EnumToken.CommaTokenType ||
|
|
526
|
+
arena.dataTypes[t] === EnumToken.CommentTokenType) {
|
|
527
527
|
continue;
|
|
528
528
|
}
|
|
529
|
-
if (arena.dataTypes[t]
|
|
529
|
+
if (arena.dataTypes[t] !== typ) {
|
|
530
530
|
return null;
|
|
531
531
|
}
|
|
532
532
|
}
|
|
533
533
|
}
|
|
534
534
|
const chi = values.filter((t) => ![EnumToken.WhitespaceTokenType, EnumToken.CommentTokenType].includes(arena.dataTypes[t]));
|
|
535
|
-
if (name
|
|
535
|
+
if (name === "atan2") {
|
|
536
536
|
for (let i = 0; i < chi.length; i++) {
|
|
537
537
|
toRadians(arena, chi[i]);
|
|
538
538
|
}
|
|
@@ -543,23 +543,23 @@ function evaluateFunc(arena, token) {
|
|
|
543
543
|
const val1 = getValue(arena, v1[0]);
|
|
544
544
|
const val2 = getValue(arena, v2[0]);
|
|
545
545
|
const result = arena.clone(v1[0], true);
|
|
546
|
-
if (name
|
|
546
|
+
if (name === "rem") {
|
|
547
547
|
setNumericValue(arena, result, +(val1 % val2).toFixed(rem(val1, val2)));
|
|
548
548
|
return [result];
|
|
549
549
|
}
|
|
550
550
|
arena.copyLocation(result, token);
|
|
551
|
-
if (name
|
|
551
|
+
if (name === "pow") {
|
|
552
552
|
setNumericValue(arena, result, Math.pow(val1, val2));
|
|
553
553
|
return [result];
|
|
554
554
|
}
|
|
555
|
-
if (name
|
|
555
|
+
if (name === "atan2") {
|
|
556
556
|
arena.dataTypes[result] = EnumToken.AngleTokenType;
|
|
557
557
|
// inlined: arena.setUnitString(result, "rad")
|
|
558
558
|
arena.unit[result] = arena.internString("rad");
|
|
559
559
|
setNumericValue(arena, result, Math.atan2(val1, val2));
|
|
560
560
|
return [result];
|
|
561
561
|
}
|
|
562
|
-
setNumericValue(arena, result, val2
|
|
562
|
+
setNumericValue(arena, result, val2 === 0 ? val1 : val1 - Math.floor(val1 / val2) * val2);
|
|
563
563
|
return [result];
|
|
564
564
|
}
|
|
565
565
|
case "clamp":
|
|
@@ -569,62 +569,62 @@ function evaluateFunc(arena, token) {
|
|
|
569
569
|
case "round":
|
|
570
570
|
case "min":
|
|
571
571
|
case "max": {
|
|
572
|
-
const strategy = name
|
|
573
|
-
? arena.
|
|
572
|
+
const strategy = name === "round" && values.length > 0 && arena.dataTypes[values[0]] === EnumToken.IdenTokenType
|
|
573
|
+
? arena.resolveString(arena.stringValue[values.shift()])
|
|
574
574
|
: null;
|
|
575
575
|
const valuesMap = new Map();
|
|
576
576
|
for (const curr of values) {
|
|
577
|
-
if (arena.dataTypes[curr]
|
|
578
|
-
arena.dataTypes[curr]
|
|
579
|
-
arena.dataTypes[curr]
|
|
577
|
+
if (arena.dataTypes[curr] === EnumToken.CommaTokenType ||
|
|
578
|
+
arena.dataTypes[curr] === EnumToken.WhitespaceTokenType ||
|
|
579
|
+
arena.dataTypes[curr] === EnumToken.CommentTokenType) {
|
|
580
580
|
continue;
|
|
581
581
|
}
|
|
582
582
|
// the argument is evaluated on a copy: the function is returned unchanged when it cannot be computed
|
|
583
583
|
const result = evaluateTokens(arena, [arena.clone(curr, true)]);
|
|
584
|
-
const key = arena.dataTypes[result[0]] + arena.
|
|
584
|
+
const key = arena.dataTypes[result[0]] + arena.resolveString(arena.unit[result[0]]);
|
|
585
585
|
if (!valuesMap.has(key)) {
|
|
586
586
|
valuesMap.set(key, []);
|
|
587
587
|
}
|
|
588
588
|
valuesMap.get(key).push(result[0]);
|
|
589
589
|
}
|
|
590
|
-
if (valuesMap.size
|
|
590
|
+
if (valuesMap.size === 1) {
|
|
591
591
|
const values = valuesMap.values().next().value;
|
|
592
|
-
if (name
|
|
592
|
+
if (name === "log") {
|
|
593
593
|
const val1 = getValue(arena, values[0]);
|
|
594
|
-
const val2 = values.length
|
|
594
|
+
const val2 = values.length === 2 ? getValue(arena, values[1]) : null;
|
|
595
595
|
const result = arena.clone(values[0], true);
|
|
596
596
|
setNumericValue(arena, result, Math.log(val1) / Math.log(val2));
|
|
597
597
|
arena.copyLocation(result, token);
|
|
598
598
|
return [result];
|
|
599
599
|
}
|
|
600
|
-
if (name
|
|
600
|
+
if (name === "min" || name === "max") {
|
|
601
601
|
let val = getValue(arena, values[0]);
|
|
602
602
|
let val2 = val;
|
|
603
603
|
let ret = values[0];
|
|
604
604
|
for (const curr of values.slice(1)) {
|
|
605
605
|
val2 = getValue(arena, curr);
|
|
606
|
-
if (val2 < val && name
|
|
606
|
+
if (val2 < val && name === "min") {
|
|
607
607
|
val = val2;
|
|
608
608
|
ret = curr;
|
|
609
609
|
}
|
|
610
|
-
else if (val2 > val && name
|
|
610
|
+
else if (val2 > val && name === "max") {
|
|
611
611
|
val = val2;
|
|
612
612
|
ret = curr;
|
|
613
613
|
}
|
|
614
614
|
}
|
|
615
615
|
return [ret];
|
|
616
616
|
}
|
|
617
|
-
if (name
|
|
617
|
+
if (name === "round") {
|
|
618
618
|
let val = getValue(arena, values[0]);
|
|
619
619
|
let val2 = getValue(arena, values[1]);
|
|
620
|
-
if (strategy == null || strategy
|
|
620
|
+
if (strategy == null || strategy === "down") {
|
|
621
621
|
val = val - (val % val2);
|
|
622
622
|
}
|
|
623
623
|
else {
|
|
624
624
|
val =
|
|
625
|
-
strategy
|
|
625
|
+
strategy === "to-zero"
|
|
626
626
|
? Math.trunc(val / val2) * val2
|
|
627
|
-
: strategy
|
|
627
|
+
: strategy === "nearest"
|
|
628
628
|
? Math.round(val / val2) * val2
|
|
629
629
|
: Math.ceil(val / val2) * val2;
|
|
630
630
|
}
|
|
@@ -645,9 +645,9 @@ function evaluateFunc(arena, token) {
|
|
|
645
645
|
*/
|
|
646
646
|
function inlineExpression(arena, token) {
|
|
647
647
|
const result = [];
|
|
648
|
-
if (arena.dataTypes[token]
|
|
648
|
+
if (arena.dataTypes[token] === EnumToken.BinaryExpressionTokenType) {
|
|
649
649
|
const op = arena.numericValue[token];
|
|
650
|
-
if (op
|
|
650
|
+
if (op === EnumToken.Mul || op === EnumToken.Div) {
|
|
651
651
|
result.push(token);
|
|
652
652
|
}
|
|
653
653
|
else {
|
|
@@ -673,37 +673,37 @@ function inlineExpression(arena, token) {
|
|
|
673
673
|
* @param token
|
|
674
674
|
*/
|
|
675
675
|
function evaluateExpression(arena, token) {
|
|
676
|
-
if (arena.dataTypes[token]
|
|
676
|
+
if (arena.dataTypes[token] !== EnumToken.BinaryExpressionTokenType) {
|
|
677
677
|
return token;
|
|
678
678
|
}
|
|
679
679
|
let l = arena.field(token, TokenField.L);
|
|
680
680
|
let r = arena.field(token, TokenField.R);
|
|
681
|
-
if (arena.dataTypes[r]
|
|
681
|
+
if (arena.dataTypes[r] === EnumToken.BinaryExpressionTokenType) {
|
|
682
682
|
r = evaluateExpression(arena, r);
|
|
683
683
|
}
|
|
684
|
-
if (arena.dataTypes[l]
|
|
684
|
+
if (arena.dataTypes[l] === EnumToken.BinaryExpressionTokenType) {
|
|
685
685
|
l = evaluateExpression(arena, l);
|
|
686
686
|
}
|
|
687
687
|
return doEvaluate(arena, l, r, arena.numericValue[token]);
|
|
688
688
|
}
|
|
689
689
|
function isScalarToken(arena, token) {
|
|
690
690
|
const typ = arena.dataTypes[token];
|
|
691
|
-
return (arena.unit[token]
|
|
692
|
-
typ
|
|
693
|
-
(typ
|
|
694
|
-
(typ
|
|
691
|
+
return (arena.unit[token] !== 0 ||
|
|
692
|
+
typ === EnumToken.MathFunctionTokenType ||
|
|
693
|
+
(typ === EnumToken.FunctionTokenType && mathFuncs.includes(arena.resolveString(arena.stringValue[token]))) ||
|
|
694
|
+
(typ === EnumToken.IdenTokenType &&
|
|
695
695
|
// @ts-ignore
|
|
696
|
-
typeof Math[arena.
|
|
697
|
-
(typ
|
|
698
|
-
(typ
|
|
699
|
-
(equalsIgnoreCase(arena.
|
|
700
|
-
equalsIgnoreCase(arena.
|
|
701
|
-
typ
|
|
702
|
-
typ
|
|
703
|
-
typ
|
|
704
|
-
typ
|
|
705
|
-
typ
|
|
706
|
-
typ
|
|
696
|
+
typeof Math[arena.resolveString(arena.stringValue[token]).toUpperCase()] === "number") ||
|
|
697
|
+
(typ === EnumToken.IdenTokenType && arena.resolveString(arena.stringValue[token]) === "NaN") ||
|
|
698
|
+
(typ === EnumToken.IdenTokenType &&
|
|
699
|
+
(equalsIgnoreCase(arena.resolveString(arena.stringValue[token]), "Infinity") ||
|
|
700
|
+
equalsIgnoreCase(arena.resolveString(arena.stringValue[token]), "-Infinity"))) ||
|
|
701
|
+
typ === EnumToken.NumberTokenType ||
|
|
702
|
+
typ === EnumToken.FractionTokenType ||
|
|
703
|
+
typ === EnumToken.PercentageTokenType ||
|
|
704
|
+
typ === EnumToken.NaNTokenType ||
|
|
705
|
+
typ === EnumToken.InfinityTokenType ||
|
|
706
|
+
typ === EnumToken.NegativeInfinityTokenType);
|
|
707
707
|
}
|
|
708
708
|
/**
|
|
709
709
|
*
|
|
@@ -712,16 +712,16 @@ function isScalarToken(arena, token) {
|
|
|
712
712
|
* @param tokens
|
|
713
713
|
*/
|
|
714
714
|
function buildExpression(arena, tokens) {
|
|
715
|
-
return factor(arena, factor(arena, tokens.filter((t) => arena.dataTypes[t]
|
|
715
|
+
return factor(arena, factor(arena, tokens.filter((t) => arena.dataTypes[t] !== EnumToken.WhitespaceTokenType), ["/", "*"]), ["+", "-"])[0];
|
|
716
716
|
}
|
|
717
717
|
function getArithmeticOperation(op) {
|
|
718
|
-
if (op
|
|
718
|
+
if (op === "+") {
|
|
719
719
|
return EnumToken.Add;
|
|
720
720
|
}
|
|
721
|
-
if (op
|
|
721
|
+
if (op === "-") {
|
|
722
722
|
return EnumToken.Sub;
|
|
723
723
|
}
|
|
724
|
-
if (op
|
|
724
|
+
if (op === "/") {
|
|
725
725
|
return EnumToken.Div;
|
|
726
726
|
}
|
|
727
727
|
return EnumToken.Mul;
|
|
@@ -734,9 +734,9 @@ function getArithmeticOperation(op) {
|
|
|
734
734
|
*/
|
|
735
735
|
function factorToken(arena, token) {
|
|
736
736
|
const typ = arena.dataTypes[token];
|
|
737
|
-
if (typ
|
|
738
|
-
((typ
|
|
739
|
-
arena.
|
|
737
|
+
if (typ === EnumToken.ParensTokenType ||
|
|
738
|
+
((typ === EnumToken.MathFunctionTokenType || typ === EnumToken.FunctionTokenType) &&
|
|
739
|
+
arena.resolveString(arena.stringValue[token]) === "calc")) {
|
|
740
740
|
return buildExpression(arena, arena.tokens(token));
|
|
741
741
|
}
|
|
742
742
|
return token;
|
|
@@ -750,23 +750,23 @@ function factorToken(arena, token) {
|
|
|
750
750
|
function factor(arena, tokens, ops) {
|
|
751
751
|
let isOp;
|
|
752
752
|
const opList = ops.map((x) => getArithmeticOperation(x));
|
|
753
|
-
if (tokens.length
|
|
753
|
+
if (tokens.length === 1) {
|
|
754
754
|
return [factorToken(arena, tokens[0])];
|
|
755
755
|
}
|
|
756
756
|
for (let i = 0; i < tokens.length; i++) {
|
|
757
|
-
if (arena.dataTypes[tokens[i]]
|
|
757
|
+
if (arena.dataTypes[tokens[i]] === EnumToken.ListToken) {
|
|
758
758
|
tokens.splice(i, 1, ...arena.tokens(tokens[i]));
|
|
759
759
|
}
|
|
760
760
|
const typ = arena.dataTypes[tokens[i]];
|
|
761
761
|
isOp = opList.includes(typ === EnumToken.Plus ? EnumToken.Add : typ);
|
|
762
762
|
if (isOp ||
|
|
763
763
|
typ === EnumToken.Star ||
|
|
764
|
-
(typ
|
|
764
|
+
(typ === EnumToken.LiteralTokenType && ops.includes(arena.resolveString(arena.stringValue[tokens[i]])))) {
|
|
765
765
|
const op = isOp
|
|
766
766
|
? typ === EnumToken.Plus
|
|
767
767
|
? EnumToken.Add
|
|
768
768
|
: typ
|
|
769
|
-
: getArithmeticOperation(arena.
|
|
769
|
+
: getArithmeticOperation(arena.resolveString(arena.stringValue[tokens[i]]));
|
|
770
770
|
const expression = arena.createBinaryExpression(op, factorToken(arena, tokens[i - 1]), factorToken(arena, tokens[i + 1]));
|
|
771
771
|
arena.spanLocation(expression, tokens[i - 1], tokens[i + 1]);
|
|
772
772
|
tokens.splice(i - 1, 3, expression);
|