mirror of
https://github.com/morluto/rea.git
synced 2026-10-22 13:52:32 -05:00
refactor(javascript): normalize erased expression syntax once
This commit is contained in:
1 parent
cfb12e47dc
commit
b628bba1fa
17 files changed
+313
-205
No files matched your search
@@ -20,6 +20,7 @@ import { compareUnicodeCodePoints } from "../unicodeCodePointOrder.js";
|
||||
import {
|
||||
readExactJavaScriptLiteral,
|
||||
semanticStaticPropertyKey,
|
||||
unwrapJavaScriptExpression,
|
||||
} from "./javascriptAstValues.js";
|
||||
import {
|
||||
semanticAmbiguousProvenance,
|
||||
@@ -170,6 +171,18 @@ const evaluateExpression = (
|
||||
): JavaScriptSemanticValue => {
|
||||
if (context.expressionDepth > SEMANTIC_EXPRESSION_DEPTH_LIMIT)
|
||||
return semanticResourceLimitUnknown("expression-depth");
|
||||
const unwrapped = unwrapJavaScriptExpression(node);
|
||||
if (unwrapped.depth > 0) {
|
||||
if (
|
||||
context.expressionDepth + unwrapped.depth >
|
||||
SEMANTIC_EXPRESSION_DEPTH_LIMIT
|
||||
)
|
||||
return semanticResourceLimitUnknown("expression-depth");
|
||||
return evaluateExpression(unwrapped.node, {
|
||||
...context,
|
||||
expressionDepth: context.expressionDepth + unwrapped.depth,
|
||||
});
|
||||
}
|
||||
const literal = readExactJavaScriptLiteral(node);
|
||||
if (literal.found)
|
||||
return typeof literal.value === "number"
|
||||
@@ -199,14 +212,6 @@ const evaluateExpression = (
|
||||
if (t.isBinaryExpression(node, { operator: "+" }))
|
||||
return evaluateAddition(node, context);
|
||||
if (t.isUnaryExpression(node)) return evaluateUnary(node, context);
|
||||
if (
|
||||
(t.isTSAsExpression(node) ||
|
||||
t.isTSTypeAssertion(node) ||
|
||||
t.isTSNonNullExpression(node) ||
|
||||
t.isTSSatisfiesExpression(node)) &&
|
||||
t.isExpression(node.expression)
|
||||
)
|
||||
return evaluateExpression(node.expression, nestedContext(context));
|
||||
return { status: "unknown", reason: `Unsupported ${node.type} value.` };
|
||||
};
|
||||
|
||||
@@ -531,6 +536,21 @@ const provenanceForExpression = (
|
||||
"unknown",
|
||||
semanticResourceLimitReason("expression-depth"),
|
||||
);
|
||||
const unwrapped = unwrapJavaScriptExpression(node);
|
||||
if (unwrapped.depth > 0) {
|
||||
if (
|
||||
context.expressionDepth + unwrapped.depth >
|
||||
SEMANTIC_EXPRESSION_DEPTH_LIMIT
|
||||
)
|
||||
return semanticUnresolvedProvenance(
|
||||
"unknown",
|
||||
semanticResourceLimitReason("expression-depth"),
|
||||
);
|
||||
return provenanceForExpression(unwrapped.node, {
|
||||
...context,
|
||||
expressionDepth: context.expressionDepth + unwrapped.depth,
|
||||
});
|
||||
}
|
||||
const required = semanticRequireOrigin(node, context.state);
|
||||
if (required !== undefined) return semanticOriginsProvenance([required]);
|
||||
if (t.isIdentifier(node)) {
|
||||
|
||||
Reference in new issue
Block a user