Skip to content

Commit 0116228

Browse files
committed
[compiler] Errors for eval(), with statments, class declarations (#33746)
* Error for `eval()` * More specific error message for `with (expr) { ... }` syntax * More specific error message for class declarations --- [//]: # (BEGIN SAPLING FOOTER) Stack created with [Sapling](https://sapling-scm.com). Best reviewed with [ReviewStack](https://reviewstack.dev/facebook/react/pull/33746). * #33752 * #33751 * #33750 * #33748 * #33747 * __->__ #33746 DiffTrain build for [4a3ff8e](4a3ff8e)
1 parent 80e4d87 commit 0116228

35 files changed

+129
-93
lines changed

compiled/eslint-plugin-react-hooks/index.js

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30936,7 +30936,7 @@ function lower$1(func, env, bindings = null, capturedRefs = new Map()) {
3093630936
});
3093730937
}
3093830938
function lowerStatement(builder, stmtPath, label = null) {
30939-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29;
30939+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31, _32, _33;
3094030940
const stmtNode = stmtPath.node;
3094130941
switch (stmtNode.type) {
3094230942
case 'ThrowStatement': {
@@ -31823,12 +31823,40 @@ function lowerStatement(builder, stmtPath, label = null) {
3182331823
}, continuationBlock);
3182431824
return;
3182531825
}
31826+
case 'WithStatement': {
31827+
builder.errors.push({
31828+
reason: `JavaScript 'with' syntax is not supported`,
31829+
description: `'with' syntax is considered deprecated and removed from JavaScript standards, consider alternatives`,
31830+
severity: ErrorSeverity.InvalidJS,
31831+
loc: (_28 = stmtPath.node.loc) !== null && _28 !== void 0 ? _28 : null,
31832+
suggestions: null,
31833+
});
31834+
lowerValueToTemporary(builder, {
31835+
kind: 'UnsupportedNode',
31836+
loc: (_29 = stmtPath.node.loc) !== null && _29 !== void 0 ? _29 : GeneratedSource,
31837+
node: stmtPath.node,
31838+
});
31839+
return;
31840+
}
31841+
case 'ClassDeclaration': {
31842+
builder.errors.push({
31843+
reason: `Support nested class declarations`,
31844+
severity: ErrorSeverity.Todo,
31845+
loc: (_30 = stmtPath.node.loc) !== null && _30 !== void 0 ? _30 : null,
31846+
suggestions: null,
31847+
});
31848+
lowerValueToTemporary(builder, {
31849+
kind: 'UnsupportedNode',
31850+
loc: (_31 = stmtPath.node.loc) !== null && _31 !== void 0 ? _31 : GeneratedSource,
31851+
node: stmtPath.node,
31852+
});
31853+
return;
31854+
}
3182631855
case 'TypeAlias':
3182731856
case 'TSInterfaceDeclaration':
3182831857
case 'TSTypeAliasDeclaration': {
3182931858
return;
3183031859
}
31831-
case 'ClassDeclaration':
3183231860
case 'DeclareClass':
3183331861
case 'DeclareExportAllDeclaration':
3183431862
case 'DeclareExportDeclaration':
@@ -31851,17 +31879,16 @@ function lowerStatement(builder, stmtPath, label = null) {
3185131879
case 'TSExportAssignment':
3185231880
case 'TSImportEqualsDeclaration':
3185331881
case 'TSModuleDeclaration':
31854-
case 'TSNamespaceExportDeclaration':
31855-
case 'WithStatement': {
31882+
case 'TSNamespaceExportDeclaration': {
3185631883
builder.errors.push({
3185731884
reason: `(BuildHIR::lowerStatement) Handle ${stmtPath.type} statements`,
3185831885
severity: ErrorSeverity.Todo,
31859-
loc: (_28 = stmtPath.node.loc) !== null && _28 !== void 0 ? _28 : null,
31886+
loc: (_32 = stmtPath.node.loc) !== null && _32 !== void 0 ? _32 : null,
3186031887
suggestions: null,
3186131888
});
3186231889
lowerValueToTemporary(builder, {
3186331890
kind: 'UnsupportedNode',
31864-
loc: (_29 = stmtPath.node.loc) !== null && _29 !== void 0 ? _29 : GeneratedSource,
31891+
loc: (_33 = stmtPath.node.loc) !== null && _33 !== void 0 ? _33 : GeneratedSource,
3186531892
node: stmtPath.node,
3186631893
});
3186731894
return;
@@ -33634,7 +33661,7 @@ function lowerValueToTemporary(builder, value) {
3363433661
return place;
3363533662
}
3363633663
function lowerIdentifier(builder, exprPath) {
33637-
var _a;
33664+
var _a, _b;
3363833665
const exprNode = exprPath.node;
3363933666
const exprLoc = (_a = exprNode.loc) !== null && _a !== void 0 ? _a : GeneratedSource;
3364033667
const binding = builder.resolveIdentifier(exprPath);
@@ -33650,6 +33677,15 @@ function lowerIdentifier(builder, exprPath) {
3365033677
return place;
3365133678
}
3365233679
default: {
33680+
if (binding.kind === 'Global' && binding.name === 'eval') {
33681+
builder.errors.push({
33682+
reason: `The 'eval' function is not supported`,
33683+
description: 'Eval is an anti-pattern in JavaScript, and the code executed cannot be evaluated by React Compiler',
33684+
severity: ErrorSeverity.InvalidJS,
33685+
loc: (_b = exprPath.node.loc) !== null && _b !== void 0 ? _b : null,
33686+
suggestions: null,
33687+
});
33688+
}
3365333689
return lowerValueToTemporary(builder, {
3365433690
kind: 'LoadGlobal',
3365533691
binding,

compiled/facebook-www/REVISION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
956d770adf59e1f8a00a7b7c52b5727ef9e353e7
1+
4a3ff8eed65f96cda7617150f92de3544d5ddf6a
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
956d770adf59e1f8a00a7b7c52b5727ef9e353e7
1+
4a3ff8eed65f96cda7617150f92de3544d5ddf6a

compiled/facebook-www/React-dev.classic.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1434,7 +1434,7 @@ __DEV__ &&
14341434
exports.useTransition = function () {
14351435
return resolveDispatcher().useTransition();
14361436
};
1437-
exports.version = "19.2.0-www-classic-956d770a-20250708";
1437+
exports.version = "19.2.0-www-classic-4a3ff8ee-20250709";
14381438
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
14391439
"function" ===
14401440
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&

compiled/facebook-www/React-dev.modern.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1434,7 +1434,7 @@ __DEV__ &&
14341434
exports.useTransition = function () {
14351435
return resolveDispatcher().useTransition();
14361436
};
1437-
exports.version = "19.2.0-www-modern-956d770a-20250708";
1437+
exports.version = "19.2.0-www-modern-4a3ff8ee-20250709";
14381438
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
14391439
"function" ===
14401440
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&

compiled/facebook-www/React-prod.classic.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -610,4 +610,4 @@ exports.useSyncExternalStore = function (
610610
exports.useTransition = function () {
611611
return ReactSharedInternals.H.useTransition();
612612
};
613-
exports.version = "19.2.0-www-classic-956d770a-20250708";
613+
exports.version = "19.2.0-www-classic-4a3ff8ee-20250709";

compiled/facebook-www/React-prod.modern.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -610,4 +610,4 @@ exports.useSyncExternalStore = function (
610610
exports.useTransition = function () {
611611
return ReactSharedInternals.H.useTransition();
612612
};
613-
exports.version = "19.2.0-www-modern-956d770a-20250708";
613+
exports.version = "19.2.0-www-modern-4a3ff8ee-20250709";

compiled/facebook-www/React-profiling.classic.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,7 @@ exports.useSyncExternalStore = function (
614614
exports.useTransition = function () {
615615
return ReactSharedInternals.H.useTransition();
616616
};
617-
exports.version = "19.2.0-www-classic-956d770a-20250708";
617+
exports.version = "19.2.0-www-classic-4a3ff8ee-20250709";
618618
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
619619
"function" ===
620620
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&

compiled/facebook-www/React-profiling.modern.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,7 @@ exports.useSyncExternalStore = function (
614614
exports.useTransition = function () {
615615
return ReactSharedInternals.H.useTransition();
616616
};
617-
exports.version = "19.2.0-www-modern-956d770a-20250708";
617+
exports.version = "19.2.0-www-modern-4a3ff8ee-20250709";
618618
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
619619
"function" ===
620620
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&

compiled/facebook-www/ReactART-dev.classic.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19299,10 +19299,10 @@ __DEV__ &&
1929919299
(function () {
1930019300
var internals = {
1930119301
bundleType: 1,
19302-
version: "19.2.0-www-classic-956d770a-20250708",
19302+
version: "19.2.0-www-classic-4a3ff8ee-20250709",
1930319303
rendererPackageName: "react-art",
1930419304
currentDispatcherRef: ReactSharedInternals,
19305-
reconcilerVersion: "19.2.0-www-classic-956d770a-20250708"
19305+
reconcilerVersion: "19.2.0-www-classic-4a3ff8ee-20250709"
1930619306
};
1930719307
internals.overrideHookState = overrideHookState;
1930819308
internals.overrideHookStateDeletePath = overrideHookStateDeletePath;
@@ -19336,7 +19336,7 @@ __DEV__ &&
1933619336
exports.Shape = Shape;
1933719337
exports.Surface = Surface;
1933819338
exports.Text = Text;
19339-
exports.version = "19.2.0-www-classic-956d770a-20250708";
19339+
exports.version = "19.2.0-www-classic-4a3ff8ee-20250709";
1934019340
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
1934119341
"function" ===
1934219342
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&

0 commit comments

Comments
 (0)