Skip to content

Commit 4d9e6d3

Browse files
committed
Removing eval
1 parent 12f6a62 commit 4d9e6d3

1 file changed

Lines changed: 1 addition & 19 deletions

File tree

src/preprocessor/preprocessor.ts

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -337,25 +337,7 @@ const evaluteExpression = (node: PreprocessorAstNode, macros: Macros) =>
337337
// TODO: Handle non-base-10 numbers. Should these be parsed in the peg grammar?
338338
int_constant: (node) => parseInt(node.token, 10),
339339
unary_defined: (node) => node.identifier.identifier in macros,
340-
identifier: (node) => {
341-
// If the identifier is a pure number (e.g. "123"), parse it as an integer.
342-
if (/^\d+$/.test(node.identifier)) {
343-
return parseInt(node.identifier, 10);
344-
}
345-
346-
// If the identifier contains no letters (e.g. "1+2", "(1+2)*3"), try to evaluate it as a JS expression.
347-
if (!/[a-zA-Z]/.test(node.identifier)) {
348-
try {
349-
return eval(node.identifier);
350-
} catch (e) {
351-
// If evaluation fails, fall through to error below.
352-
}
353-
}
354-
// If it's not a number or evaluatable expression, throw an error (likely an unknown macro or invalid expression).
355-
throw new Error(
356-
`Preprocessing error: Unknown identifier or unsupported expression "${node.identifier}"`
357-
);
358-
},
340+
identifier: (node) => node.identifier,
359341
group: (node, visit) => visit(node.expression),
360342
binary: ({ left, right, operator: { literal } }, visit) => {
361343
switch (literal) {

0 commit comments

Comments
 (0)