11
import {getOrInsertWith} from '../Utils/utils';
12
import {Environment} from '../HIR';
13
import {DEFAULT_EXPORT} from '../HIR/Environment';
14
+import {CompileProgramResult} from './Program';
15
16
function throwInvalidReact(
17
options: Omit<CompilerErrorDetailOptions, 'severity'>,
37
const parent = path.parentPath;
38
if (parent != null && parent.isCallExpression()) {
39
const args = parent.get('arguments');
40
+ const maybeCalleeLoc = path.node.loc;
41
+ const hasInferredEffect =
42
+ maybeCalleeLoc != null &&
43
+ context.inferredEffectLocations.has(maybeCalleeLoc);
44
/**
45
* Only error on untransformed references of the form `useMyEffect(...)`
46
* or `moduleNamespace.useMyEffect(...)`, with matching argument counts.
47
* TODO: do we also want a mode to also hard error on non-call references?
48
*/
44
- if (args.length === numArgs) {
49
+ if (args.length === numArgs && !hasInferredEffect) {
50
const maybeErrorDiagnostic = matchCompilerDiagnostic(
51
path,
52
context.transformErrors,
102
filename: string | null,
103
logger: Logger | null,
104
env: EnvironmentConfig,
100
- transformErrors: Array<{fn: NodePath<t.Node>; error: CompilerError}>,
105
+ compileResult: CompileProgramResult | null,
106
): void {
107
const moduleLoadChecks = new Map<
108
string,
131
}
132
}
133
if (moduleLoadChecks.size > 0) {
129
- transformProgram(path, moduleLoadChecks, filename, logger, transformErrors);
134
+ transformProgram(path, moduleLoadChecks, filename, logger, compileResult);
135
}
136
}
137
141
logger: Logger | null;
142
filename: string | null;
143
transformErrors: Array<{fn: NodePath<t.Node>; error: CompilerError}>;
144
+ inferredEffectLocations: Set<t.SourceLocation>;
145
};
146
type CheckInvalidReferenceFn = (
147
paths: Array<NodePath<t.Node>>,
229
moduleLoadChecks: Map<string, Map<string, CheckInvalidReferenceFn>>,
230
filename: string | null,
231
logger: Logger | null,
226
- transformErrors: Array<{fn: NodePath<t.Node>; error: CompilerError}>,
232
+ compileResult: CompileProgramResult | null,
233
): void {
234
const traversalState: TraversalState = {
235
shouldInvalidateScopes: true,
236
program: path,
237
filename,
238
logger,
233
- transformErrors,
239
+ transformErrors: compileResult?.retryErrors ?? [],
240
+ inferredEffectLocations:
241
+ compileResult?.inferredEffectLocations ?? new Set(),
242
};
243
path.traverse({
244
ImportDeclaration(path: NodePath<t.ImportDeclaration>) {