Skip to content

Commit

Permalink
[compiler] Errors in earlier functions dont stop subsequent compilation
Browse files Browse the repository at this point in the history
Errors in an earlier component/hook shouldn't stop later components from compiling.

ghstack-source-id: b8a8e6cfa8b99546b6e49f947596750688f168b1
Pull Request resolved: #30844
  • Loading branch information
josephsavona committed Aug 29, 2024
1 parent c741d2d commit 6873fda
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -310,8 +310,6 @@ export function compileProgram(
pass.opts.eslintSuppressionRules ?? DEFAULT_ESLINT_SUPPRESSIONS,
pass.opts.flowSuppressions,
);
const lintError = suppressionsToCompilerError(suppressions);
let hasCriticalError = lintError != null;
const queue: Array<{
kind: 'original' | 'outlined';
fn: BabelFn;
Expand Down Expand Up @@ -385,22 +383,21 @@ export function compileProgram(
);
}

if (lintError != null) {
/**
* Note that Babel does not attach comment nodes to nodes; they are dangling off of the
* Program node itself. We need to figure out whether an eslint suppression range
* applies to this function first.
*/
const suppressionsInFunction = filterSuppressionsThatAffectFunction(
suppressions,
fn,
);
if (suppressionsInFunction.length > 0) {
if (optOutDirectives.length > 0) {
logError(lintError, pass, fn.node.loc ?? null);
} else {
handleError(lintError, pass, fn.node.loc ?? null);
}
/**
* Note that Babel does not attach comment nodes to nodes; they are dangling off of the
* Program node itself. We need to figure out whether an eslint suppression range
* applies to this function first.
*/
const suppressionsInFunction = filterSuppressionsThatAffectFunction(
suppressions,
fn,
);
if (suppressionsInFunction.length > 0) {
const lintError = suppressionsToCompilerError(suppressionsInFunction);
if (optOutDirectives.length > 0) {
logError(lintError, pass, fn.node.loc ?? null);
} else {
handleError(lintError, pass, fn.node.loc ?? null);
}
}

Expand Down Expand Up @@ -436,7 +433,6 @@ export function compileProgram(
return null;
}
}
hasCriticalError ||= isCriticalError(err);
handleError(err, pass, fn.node.loc ?? null);
return null;
}
Expand Down Expand Up @@ -470,7 +466,7 @@ export function compileProgram(
return null;
}

if (!pass.opts.noEmit && !hasCriticalError) {
if (!pass.opts.noEmit) {
return compiledFn;
}
return null;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@

## Input

```javascript
// @panicThreshold(none)
import {useHook} from 'shared-runtime';

function InvalidComponent(props) {
if (props.cond) {
useHook();
}
return <div>Hello World!</div>;
}

function ValidComponent(props) {
return <div>{props.greeting}</div>;
}

```

## Code

```javascript
import { c as _c } from "react/compiler-runtime"; // @panicThreshold(none)
import { useHook } from "shared-runtime";

function InvalidComponent(props) {
if (props.cond) {
useHook();
}
return <div>Hello World!</div>;
}

function ValidComponent(props) {
const $ = _c(2);
let t0;
if ($[0] !== props.greeting) {
t0 = <div>{props.greeting}</div>;
$[0] = props.greeting;
$[1] = t0;
} else {
t0 = $[1];
}
return t0;
}

```
### Eval output
(kind: exception) Fixture not implemented
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// @panicThreshold(none)
import {useHook} from 'shared-runtime';

function InvalidComponent(props) {
if (props.cond) {
useHook();
}
return <div>Hello World!</div>;
}

function ValidComponent(props) {
return <div>{props.greeting}</div>;
}

0 comments on commit 6873fda

Please sign in to comment.