Skip to content

Commit e98dfd9

Browse files
committed
fix(types): fix regressions with missing JSDoc and rebuild
1 parent 9b2a291 commit e98dfd9

12 files changed

Lines changed: 274 additions & 208 deletions

badges/coverage-badge.svg

Lines changed: 1 addition & 1 deletion
Loading

badges/tests-badge.svg

Lines changed: 1 addition & 1 deletion
Loading

dist/index-browser-esm.js

Lines changed: 60 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1225,6 +1225,57 @@ jsep.addUnaryOp('void');
12251225
jsep.addLiteral('null', null);
12261226
jsep.addLiteral('undefined', undefined);
12271227
const BLOCKED_PROTO_PROPERTIES = new Set(['constructor', '__proto__', '__defineGetter__', '__defineSetter__', '__lookupGetter__', '__lookupSetter__']);
1228+
1229+
/**
1230+
* @typedef {Record<
1231+
* string,
1232+
* (a: AnyParameter, b: AnyParameter) => UnknownResult
1233+
* >} OperatorTable
1234+
*/
1235+
1236+
// eslint-disable-next-line @stylistic/max-len -- Long
1237+
const BINOPS = Object.assign(Object.create(null), /** @type {OperatorTable} */{
1238+
'||': (a, b) => a || b(),
1239+
'&&': (a, b) => a && b(),
1240+
'|': (a, b) => a | b(),
1241+
'^': (a, b) => a ^ b(),
1242+
'&': (a, b) => a & b(),
1243+
// eslint-disable-next-line eqeqeq -- API
1244+
'==': (a, b) => a == b(),
1245+
// eslint-disable-next-line eqeqeq -- API
1246+
'!=': (a, b) => a != b(),
1247+
'===': (a, b) => a === b(),
1248+
'!==': (a, b) => a !== b(),
1249+
'<': (a, b) => a < b(),
1250+
'>': (a, b) => a > b(),
1251+
'<=': (a, b) => a <= b(),
1252+
'>=': (a, b) => a >= b(),
1253+
'<<': (a, b) => a << b(),
1254+
'>>': (a, b) => a >> b(),
1255+
'>>>': (a, b) => a >>> b(),
1256+
'+': (a, b) => a + b(),
1257+
'-': (a, b) => a - b(),
1258+
'*': (a, b) => a * b(),
1259+
'/': (a, b) => a / b(),
1260+
'%': (a, b) => a % b()
1261+
});
1262+
1263+
/**
1264+
* @typedef {{
1265+
* [key: string]: (a: AnyParameter) => UnknownResult
1266+
* }} UnaryOperatorTable
1267+
*/
1268+
1269+
// eslint-disable-next-line @stylistic/max-len -- Long
1270+
const UNOPS = Object.assign(Object.create(null), /** @type {UnaryOperatorTable} */{
1271+
'-': a => -(/** @type {EvaluatedResult} */a),
1272+
'!': a => !a,
1273+
'~': a => ~(/** @type {EvaluatedResult} */a),
1274+
// eslint-disable-next-line no-implicit-coercion -- API
1275+
'+': a => +(/** @type {EvaluatedResult} */a),
1276+
typeof: a => typeof a,
1277+
void: () => undefined
1278+
});
12281279
const SafeEval = {
12291280
/**
12301281
* @param {jsep.Expression} ast
@@ -1266,36 +1317,10 @@ const SafeEval = {
12661317
* @returns {UnknownResult}
12671318
*/
12681319
evalBinaryExpression(ast, subs) {
1269-
/**
1270-
* @typedef {{
1271-
* [key: string]: (a: AnyParameter, b: AnyParameter) => UnknownResult
1272-
* }} OperatorTable
1273-
*/
1274-
const result = /** @type {OperatorTable} */{
1275-
'||': (a, b) => a || b(),
1276-
'&&': (a, b) => a && b(),
1277-
'|': (a, b) => a | b(),
1278-
'^': (a, b) => a ^ b(),
1279-
'&': (a, b) => a & b(),
1280-
// eslint-disable-next-line eqeqeq -- API
1281-
'==': (a, b) => a == b(),
1282-
// eslint-disable-next-line eqeqeq -- API
1283-
'!=': (a, b) => a != b(),
1284-
'===': (a, b) => a === b(),
1285-
'!==': (a, b) => a !== b(),
1286-
'<': (a, b) => a < b(),
1287-
'>': (a, b) => a > b(),
1288-
'<=': (a, b) => a <= b(),
1289-
'>=': (a, b) => a >= b(),
1290-
'<<': (a, b) => a << b(),
1291-
'>>': (a, b) => a >> b(),
1292-
'>>>': (a, b) => a >>> b(),
1293-
'+': (a, b) => a + b(),
1294-
'-': (a, b) => a - b(),
1295-
'*': (a, b) => a * b(),
1296-
'/': (a, b) => a / b(),
1297-
'%': (a, b) => a % b()
1298-
}[ast.operator](SafeEval.evalAst(ast.left, subs), () => SafeEval.evalAst(ast.right, subs));
1320+
if (!Object.hasOwn(BINOPS, ast.operator)) {
1321+
throw new SyntaxError(`Unknown binary operator: ${ast.operator}`);
1322+
}
1323+
const result = BINOPS[ast.operator](SafeEval.evalAst(ast.left, subs), () => SafeEval.evalAst(ast.right, subs));
12991324
return result;
13001325
},
13011326
/**
@@ -1378,25 +1403,11 @@ const SafeEval = {
13781403
* @returns {UnknownResult}
13791404
*/
13801405
evalUnaryExpression(ast, subs) {
1381-
/**
1382-
* @typedef {{
1383-
* [key: string]: (a: AnyParameter) => UnknownResult
1384-
* }} UnaryOperatorTable
1385-
*/
1386-
const result = /** @type {UnaryOperatorTable} */{
1387-
'-': a => -(/** @type {EvaluatedResult} */
1388-
SafeEval.evalAst(a, subs)),
1389-
'!': a => !SafeEval.evalAst(a, subs),
1390-
'~': a => ~(/** @type {EvaluatedResult} */
1391-
SafeEval.evalAst(a, subs)),
1392-
// eslint-disable-next-line no-implicit-coercion -- API
1393-
'+': a => +(/** @type {EvaluatedResult} */
1394-
SafeEval.evalAst(a, subs)),
1395-
typeof: a => typeof SafeEval.evalAst(a, subs),
1396-
// eslint-disable-next-line no-void -- Ok
1397-
void: a => void SafeEval.evalAst(a, subs)
1398-
}[ast.operator](ast.argument);
1399-
return result;
1406+
if (!Object.hasOwn(UNOPS, ast.operator)) {
1407+
throw new SyntaxError(`Unknown unary operator: ${ast.operator}`);
1408+
}
1409+
const operand = SafeEval.evalAst(ast.argument, subs);
1410+
return UNOPS[ast.operator](operand);
14001411
},
14011412
/**
14021413
* @param {jsep.ArrayExpression} ast

dist/index-browser-esm.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index-browser-esm.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index-browser-umd.cjs

Lines changed: 60 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1231,6 +1231,57 @@
12311231
jsep.addLiteral('null', null);
12321232
jsep.addLiteral('undefined', undefined);
12331233
const BLOCKED_PROTO_PROPERTIES = new Set(['constructor', '__proto__', '__defineGetter__', '__defineSetter__', '__lookupGetter__', '__lookupSetter__']);
1234+
1235+
/**
1236+
* @typedef {Record<
1237+
* string,
1238+
* (a: AnyParameter, b: AnyParameter) => UnknownResult
1239+
* >} OperatorTable
1240+
*/
1241+
1242+
// eslint-disable-next-line @stylistic/max-len -- Long
1243+
const BINOPS = Object.assign(Object.create(null), /** @type {OperatorTable} */{
1244+
'||': (a, b) => a || b(),
1245+
'&&': (a, b) => a && b(),
1246+
'|': (a, b) => a | b(),
1247+
'^': (a, b) => a ^ b(),
1248+
'&': (a, b) => a & b(),
1249+
// eslint-disable-next-line eqeqeq -- API
1250+
'==': (a, b) => a == b(),
1251+
// eslint-disable-next-line eqeqeq -- API
1252+
'!=': (a, b) => a != b(),
1253+
'===': (a, b) => a === b(),
1254+
'!==': (a, b) => a !== b(),
1255+
'<': (a, b) => a < b(),
1256+
'>': (a, b) => a > b(),
1257+
'<=': (a, b) => a <= b(),
1258+
'>=': (a, b) => a >= b(),
1259+
'<<': (a, b) => a << b(),
1260+
'>>': (a, b) => a >> b(),
1261+
'>>>': (a, b) => a >>> b(),
1262+
'+': (a, b) => a + b(),
1263+
'-': (a, b) => a - b(),
1264+
'*': (a, b) => a * b(),
1265+
'/': (a, b) => a / b(),
1266+
'%': (a, b) => a % b()
1267+
});
1268+
1269+
/**
1270+
* @typedef {{
1271+
* [key: string]: (a: AnyParameter) => UnknownResult
1272+
* }} UnaryOperatorTable
1273+
*/
1274+
1275+
// eslint-disable-next-line @stylistic/max-len -- Long
1276+
const UNOPS = Object.assign(Object.create(null), /** @type {UnaryOperatorTable} */{
1277+
'-': a => -(/** @type {EvaluatedResult} */a),
1278+
'!': a => !a,
1279+
'~': a => ~(/** @type {EvaluatedResult} */a),
1280+
// eslint-disable-next-line no-implicit-coercion -- API
1281+
'+': a => +(/** @type {EvaluatedResult} */a),
1282+
typeof: a => typeof a,
1283+
void: () => undefined
1284+
});
12341285
const SafeEval = {
12351286
/**
12361287
* @param {jsep.Expression} ast
@@ -1272,36 +1323,10 @@
12721323
* @returns {UnknownResult}
12731324
*/
12741325
evalBinaryExpression(ast, subs) {
1275-
/**
1276-
* @typedef {{
1277-
* [key: string]: (a: AnyParameter, b: AnyParameter) => UnknownResult
1278-
* }} OperatorTable
1279-
*/
1280-
const result = /** @type {OperatorTable} */{
1281-
'||': (a, b) => a || b(),
1282-
'&&': (a, b) => a && b(),
1283-
'|': (a, b) => a | b(),
1284-
'^': (a, b) => a ^ b(),
1285-
'&': (a, b) => a & b(),
1286-
// eslint-disable-next-line eqeqeq -- API
1287-
'==': (a, b) => a == b(),
1288-
// eslint-disable-next-line eqeqeq -- API
1289-
'!=': (a, b) => a != b(),
1290-
'===': (a, b) => a === b(),
1291-
'!==': (a, b) => a !== b(),
1292-
'<': (a, b) => a < b(),
1293-
'>': (a, b) => a > b(),
1294-
'<=': (a, b) => a <= b(),
1295-
'>=': (a, b) => a >= b(),
1296-
'<<': (a, b) => a << b(),
1297-
'>>': (a, b) => a >> b(),
1298-
'>>>': (a, b) => a >>> b(),
1299-
'+': (a, b) => a + b(),
1300-
'-': (a, b) => a - b(),
1301-
'*': (a, b) => a * b(),
1302-
'/': (a, b) => a / b(),
1303-
'%': (a, b) => a % b()
1304-
}[ast.operator](SafeEval.evalAst(ast.left, subs), () => SafeEval.evalAst(ast.right, subs));
1326+
if (!Object.hasOwn(BINOPS, ast.operator)) {
1327+
throw new SyntaxError(`Unknown binary operator: ${ast.operator}`);
1328+
}
1329+
const result = BINOPS[ast.operator](SafeEval.evalAst(ast.left, subs), () => SafeEval.evalAst(ast.right, subs));
13051330
return result;
13061331
},
13071332
/**
@@ -1384,25 +1409,11 @@
13841409
* @returns {UnknownResult}
13851410
*/
13861411
evalUnaryExpression(ast, subs) {
1387-
/**
1388-
* @typedef {{
1389-
* [key: string]: (a: AnyParameter) => UnknownResult
1390-
* }} UnaryOperatorTable
1391-
*/
1392-
const result = /** @type {UnaryOperatorTable} */{
1393-
'-': a => -(/** @type {EvaluatedResult} */
1394-
SafeEval.evalAst(a, subs)),
1395-
'!': a => !SafeEval.evalAst(a, subs),
1396-
'~': a => ~(/** @type {EvaluatedResult} */
1397-
SafeEval.evalAst(a, subs)),
1398-
// eslint-disable-next-line no-implicit-coercion -- API
1399-
'+': a => +(/** @type {EvaluatedResult} */
1400-
SafeEval.evalAst(a, subs)),
1401-
typeof: a => typeof SafeEval.evalAst(a, subs),
1402-
// eslint-disable-next-line no-void -- Ok
1403-
void: a => void SafeEval.evalAst(a, subs)
1404-
}[ast.operator](ast.argument);
1405-
return result;
1412+
if (!Object.hasOwn(UNOPS, ast.operator)) {
1413+
throw new SyntaxError(`Unknown unary operator: ${ast.operator}`);
1414+
}
1415+
const operand = SafeEval.evalAst(ast.argument, subs);
1416+
return UNOPS[ast.operator](operand);
14061417
},
14071418
/**
14081419
* @param {jsep.ArrayExpression} ast

dist/index-browser-umd.min.cjs

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

dist/index-browser-umd.min.cjs.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index-node-cjs.cjs

Lines changed: 60 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1229,6 +1229,57 @@ jsep.addUnaryOp('void');
12291229
jsep.addLiteral('null', null);
12301230
jsep.addLiteral('undefined', undefined);
12311231
const BLOCKED_PROTO_PROPERTIES = new Set(['constructor', '__proto__', '__defineGetter__', '__defineSetter__', '__lookupGetter__', '__lookupSetter__']);
1232+
1233+
/**
1234+
* @typedef {Record<
1235+
* string,
1236+
* (a: AnyParameter, b: AnyParameter) => UnknownResult
1237+
* >} OperatorTable
1238+
*/
1239+
1240+
// eslint-disable-next-line @stylistic/max-len -- Long
1241+
const BINOPS = Object.assign(Object.create(null), /** @type {OperatorTable} */{
1242+
'||': (a, b) => a || b(),
1243+
'&&': (a, b) => a && b(),
1244+
'|': (a, b) => a | b(),
1245+
'^': (a, b) => a ^ b(),
1246+
'&': (a, b) => a & b(),
1247+
// eslint-disable-next-line eqeqeq -- API
1248+
'==': (a, b) => a == b(),
1249+
// eslint-disable-next-line eqeqeq -- API
1250+
'!=': (a, b) => a != b(),
1251+
'===': (a, b) => a === b(),
1252+
'!==': (a, b) => a !== b(),
1253+
'<': (a, b) => a < b(),
1254+
'>': (a, b) => a > b(),
1255+
'<=': (a, b) => a <= b(),
1256+
'>=': (a, b) => a >= b(),
1257+
'<<': (a, b) => a << b(),
1258+
'>>': (a, b) => a >> b(),
1259+
'>>>': (a, b) => a >>> b(),
1260+
'+': (a, b) => a + b(),
1261+
'-': (a, b) => a - b(),
1262+
'*': (a, b) => a * b(),
1263+
'/': (a, b) => a / b(),
1264+
'%': (a, b) => a % b()
1265+
});
1266+
1267+
/**
1268+
* @typedef {{
1269+
* [key: string]: (a: AnyParameter) => UnknownResult
1270+
* }} UnaryOperatorTable
1271+
*/
1272+
1273+
// eslint-disable-next-line @stylistic/max-len -- Long
1274+
const UNOPS = Object.assign(Object.create(null), /** @type {UnaryOperatorTable} */{
1275+
'-': a => -(/** @type {EvaluatedResult} */a),
1276+
'!': a => !a,
1277+
'~': a => ~(/** @type {EvaluatedResult} */a),
1278+
// eslint-disable-next-line no-implicit-coercion -- API
1279+
'+': a => +(/** @type {EvaluatedResult} */a),
1280+
typeof: a => typeof a,
1281+
void: () => undefined
1282+
});
12321283
const SafeEval = {
12331284
/**
12341285
* @param {jsep.Expression} ast
@@ -1270,36 +1321,10 @@ const SafeEval = {
12701321
* @returns {UnknownResult}
12711322
*/
12721323
evalBinaryExpression(ast, subs) {
1273-
/**
1274-
* @typedef {{
1275-
* [key: string]: (a: AnyParameter, b: AnyParameter) => UnknownResult
1276-
* }} OperatorTable
1277-
*/
1278-
const result = /** @type {OperatorTable} */{
1279-
'||': (a, b) => a || b(),
1280-
'&&': (a, b) => a && b(),
1281-
'|': (a, b) => a | b(),
1282-
'^': (a, b) => a ^ b(),
1283-
'&': (a, b) => a & b(),
1284-
// eslint-disable-next-line eqeqeq -- API
1285-
'==': (a, b) => a == b(),
1286-
// eslint-disable-next-line eqeqeq -- API
1287-
'!=': (a, b) => a != b(),
1288-
'===': (a, b) => a === b(),
1289-
'!==': (a, b) => a !== b(),
1290-
'<': (a, b) => a < b(),
1291-
'>': (a, b) => a > b(),
1292-
'<=': (a, b) => a <= b(),
1293-
'>=': (a, b) => a >= b(),
1294-
'<<': (a, b) => a << b(),
1295-
'>>': (a, b) => a >> b(),
1296-
'>>>': (a, b) => a >>> b(),
1297-
'+': (a, b) => a + b(),
1298-
'-': (a, b) => a - b(),
1299-
'*': (a, b) => a * b(),
1300-
'/': (a, b) => a / b(),
1301-
'%': (a, b) => a % b()
1302-
}[ast.operator](SafeEval.evalAst(ast.left, subs), () => SafeEval.evalAst(ast.right, subs));
1324+
if (!Object.hasOwn(BINOPS, ast.operator)) {
1325+
throw new SyntaxError(`Unknown binary operator: ${ast.operator}`);
1326+
}
1327+
const result = BINOPS[ast.operator](SafeEval.evalAst(ast.left, subs), () => SafeEval.evalAst(ast.right, subs));
13031328
return result;
13041329
},
13051330
/**
@@ -1382,25 +1407,11 @@ const SafeEval = {
13821407
* @returns {UnknownResult}
13831408
*/
13841409
evalUnaryExpression(ast, subs) {
1385-
/**
1386-
* @typedef {{
1387-
* [key: string]: (a: AnyParameter) => UnknownResult
1388-
* }} UnaryOperatorTable
1389-
*/
1390-
const result = /** @type {UnaryOperatorTable} */{
1391-
'-': a => -(/** @type {EvaluatedResult} */
1392-
SafeEval.evalAst(a, subs)),
1393-
'!': a => !SafeEval.evalAst(a, subs),
1394-
'~': a => ~(/** @type {EvaluatedResult} */
1395-
SafeEval.evalAst(a, subs)),
1396-
// eslint-disable-next-line no-implicit-coercion -- API
1397-
'+': a => +(/** @type {EvaluatedResult} */
1398-
SafeEval.evalAst(a, subs)),
1399-
typeof: a => typeof SafeEval.evalAst(a, subs),
1400-
// eslint-disable-next-line no-void -- Ok
1401-
void: a => void SafeEval.evalAst(a, subs)
1402-
}[ast.operator](ast.argument);
1403-
return result;
1410+
if (!Object.hasOwn(UNOPS, ast.operator)) {
1411+
throw new SyntaxError(`Unknown unary operator: ${ast.operator}`);
1412+
}
1413+
const operand = SafeEval.evalAst(ast.argument, subs);
1414+
return UNOPS[ast.operator](operand);
14041415
},
14051416
/**
14061417
* @param {jsep.ArrayExpression} ast

0 commit comments

Comments
 (0)