mirror of
https://github.com/morluto/rea.git
synced 2026-11-22 06:25:44 +00:00
fix(javascript): keep CommonJS wrapper redeclarations from inventing application owners (#12084)
fix(javascript): keep wrapper redeclarations from inventing application owners A top-level lexical declaration that reuses a CommonJS wrapper parameter cannot evaluate, and its recovered syntax is complete. Counting that diagnostic as dropped syntax marked the entrypoint as an unexamined loader and erased another package's proven loadFile root. Co-authored-by: Cursor Agent <cursoragent@cursor.com> Co-authored-by: morluto <morluto@users.noreply.github.com>
This commit is contained in:
7 files changed
+188
-5
No files matched your search
@@ -74,7 +74,9 @@ import {
|
||||
indexJavaScriptBindingsWithReceiversSteps,
|
||||
} from "./javascriptSemanticAnalysis.js";
|
||||
import {
|
||||
commonJsWrapperRedeclarationCount,
|
||||
javaScriptSourceLoaderCondition,
|
||||
recoveredJavaScriptSyntaxErrorCount,
|
||||
type ParsedJavaScriptSource,
|
||||
} from "./javascriptSourceParser.js";
|
||||
|
||||
@@ -101,7 +103,8 @@ export const memberMutationRefusedJavaScriptStaticAnalysis = (
|
||||
file: ParsedJavaScriptSource,
|
||||
refusal: AnalysisResourceConstraintError,
|
||||
): JavaScriptStaticAnalysis => {
|
||||
const parserErrors = file.errors.length;
|
||||
const parserErrors = recoveredJavaScriptSyntaxErrorCount(file.errors);
|
||||
const wrapperRedeclarations = commonJsWrapperRedeclarationCount(file.errors);
|
||||
const loaderCondition = javaScriptSourceLoaderCondition(file.program);
|
||||
const accumulator = createJavaScriptAnalysisAccumulator(source.length);
|
||||
addSourceMapDirectives(source, file.comments ?? [], accumulator);
|
||||
@@ -113,7 +116,14 @@ export const memberMutationRefusedJavaScriptStaticAnalysis = (
|
||||
: { status: "recovered", error_count: parserErrors },
|
||||
semantics: {
|
||||
unknown_findings: null,
|
||||
uncertainty: loaderCondition === undefined ? [] : ["conditional-loader"],
|
||||
uncertainty: [
|
||||
...(loaderCondition === undefined
|
||||
? []
|
||||
: ["conditional-loader" as const]),
|
||||
...(wrapperRedeclarations === 0
|
||||
? []
|
||||
: ["commonjs-wrapper-redeclaration" as const]),
|
||||
],
|
||||
},
|
||||
examination: {
|
||||
status: "not-examined",
|
||||
@@ -255,7 +265,8 @@ const finalizeStaticAnalysis = (
|
||||
bindings: JavaScriptSemanticAnalysisState,
|
||||
routes: JavaScriptRouteSourceFacts,
|
||||
): JavaScriptStaticAnalysis => {
|
||||
const parserErrors = file.errors.length;
|
||||
const parserErrors = recoveredJavaScriptSyntaxErrorCount(file.errors);
|
||||
const wrapperRedeclarations = commonJsWrapperRedeclarationCount(file.errors);
|
||||
const typeOnlySideEffect = hasUncertainTypeOnlyModuleSideEffect(file.program);
|
||||
// A `worker` or `service-worker` reference records a URL relative to the
|
||||
// importing source, so `new Worker(new URL("electron", import.meta.url))` is
|
||||
@@ -310,6 +321,9 @@ const finalizeStaticAnalysis = (
|
||||
...(typeOnlySideEffect
|
||||
? ["type-only-module-side-effect" as const]
|
||||
: []),
|
||||
...(wrapperRedeclarations === 0
|
||||
? []
|
||||
: ["commonjs-wrapper-redeclaration" as const]),
|
||||
],
|
||||
},
|
||||
examination: {
|
||||
@@ -352,6 +366,11 @@ const finalizeStaticAnalysis = (
|
||||
: [
|
||||
"The parser recovered from syntax errors; affected facts are partial.",
|
||||
]),
|
||||
...(wrapperRedeclarations === 0
|
||||
? []
|
||||
: [
|
||||
"A top-level lexical declaration redeclares a CommonJS wrapper parameter, so this module cannot evaluate. Recovered syntax was examined completely.",
|
||||
]),
|
||||
...(accumulator.unknownFindings === 0
|
||||
? []
|
||||
: [
|
||||
|
||||
Reference in new issue
Block a user