Skip to content

Commit 46cadc4

Browse files
committed
Revert "Unseal this.refs"
This reverts commit 72bc471. We'll just not seal `this.refs` in React versions with `warnAboutStringRefs`.
1 parent 72bc471 commit 46cadc4

File tree

5 files changed

+1
-118
lines changed

5 files changed

+1
-118
lines changed

README.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -175,12 +175,6 @@ class ParentComponent extends React.Component {
175175
return (
176176
<div
177177
ref={(current) => {
178-
if (process.env.NODE_ENV !== 'production') {
179-
if (Object.isSealed(this.refs)) {
180-
this.refs = {};
181-
}
182-
}
183-
184178
this.refs["refComponent"] = current;
185179
}}
186180
/>

transforms/__testfixtures__/string-refs/literal-with-owner.output.js

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,49 +4,19 @@ class ParentComponent extends React.Component {
44
render() {
55
return (
66
<div ref={current => {
7-
if (process.env.NODE_ENV !== 'production') {
8-
if (Object.isSealed(this.refs)) {
9-
this.refs = {};
10-
}
11-
}
12-
137
this.refs['P'] = current;
148
}} id="P">
159
<div ref={current => {
16-
if (process.env.NODE_ENV !== 'production') {
17-
if (Object.isSealed(this.refs)) {
18-
this.refs = {};
19-
}
20-
}
21-
2210
this.refs['P_P1'] = current;
2311
}} id="P_P1">
2412
<span ref={current => {
25-
if (process.env.NODE_ENV !== 'production') {
26-
if (Object.isSealed(this.refs)) {
27-
this.refs = {};
28-
}
29-
}
30-
3113
this.refs['P_P1_C1'] = current;
3214
}} id="P_P1_C1" />
3315
<span ref={current => {
34-
if (process.env.NODE_ENV !== 'production') {
35-
if (Object.isSealed(this.refs)) {
36-
this.refs = {};
37-
}
38-
}
39-
4016
this.refs['P_P1_C2'] = current;
4117
}} id="P_P1_C2" />
4218
</div>
4319
<div ref={current => {
44-
if (process.env.NODE_ENV !== 'production') {
45-
if (Object.isSealed(this.refs)) {
46-
this.refs = {};
47-
}
48-
}
49-
5020
this.refs['P_OneOff'] = current;
5121
}} id="P_OneOff" />
5222
</div>
Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
import * as React from "react";
22

33
<div ref={current => {
4-
if (process.env.NODE_ENV !== 'production') {
5-
if (Object.isSealed(this.refs)) {
6-
this.refs = {};
7-
}
8-
}
9-
104
this.refs['bad'] = current;
115
}} />;

transforms/__testfixtures__/string-refs/typescript/literal-with-owner.output.tsx

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -8,49 +8,19 @@ class ParentComponent extends React.Component {
88
render() {
99
return (
1010
<div ref={current => {
11-
if (process.env.NODE_ENV !== 'production') {
12-
if (Object.isSealed(this.refs)) {
13-
this.refs = {};
14-
}
15-
}
16-
1711
this.refs['P'] = current;
1812
}} id="P">
1913
<div ref={current => {
20-
if (process.env.NODE_ENV !== 'production') {
21-
if (Object.isSealed(this.refs)) {
22-
this.refs = {};
23-
}
24-
}
25-
2614
this.refs['P_P1'] = current;
2715
}} id="P_P1">
2816
<span ref={current => {
29-
if (process.env.NODE_ENV !== 'production') {
30-
if (Object.isSealed(this.refs)) {
31-
this.refs = {};
32-
}
33-
}
34-
3517
this.refs['P_P1_C1'] = current;
3618
}} id="P_P1_C1" />
3719
<span ref={current => {
38-
if (process.env.NODE_ENV !== 'production') {
39-
if (Object.isSealed(this.refs)) {
40-
this.refs = {};
41-
}
42-
}
43-
4420
this.refs['P_P1_C2'] = current;
4521
}} id="P_P1_C2" />
4622
</div>
4723
<div ref={current => {
48-
if (process.env.NODE_ENV !== 'production') {
49-
if (Object.isSealed(this.refs)) {
50-
this.refs = {};
51-
}
52-
}
53-
5424
this.refs['P_OneOff'] = current;
5525
}} id="P_OneOff" />
5626
</div>

transforms/string-refs.js

Lines changed: 1 addition & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -40,56 +40,11 @@ export default (file, api, options) => {
4040
// Maybe JSCodeShift has such a helper as well?
4141
const currentIdentifierName = "current";
4242
valuePath.replace(
43-
// {(current) => {}}
43+
// {(current) => { this.refs[valuePath.node.value] = current }}
4444
j.jsxExpressionContainer(
4545
j.arrowFunctionExpression(
4646
[j.identifier(currentIdentifierName)],
4747
j.blockStatement([
48-
// if (process.env.NODE_ENV !== 'production')
49-
j.ifStatement(
50-
j.binaryExpression(
51-
"!==",
52-
j.memberExpression(
53-
j.memberExpression(
54-
j.identifier("process"),
55-
j.identifier("env")
56-
),
57-
j.identifier("NODE_ENV")
58-
),
59-
j.stringLiteral("production")
60-
),
61-
j.blockStatement([
62-
// if (Object.isSealed(this.refs))
63-
j.ifStatement(
64-
j.callExpression(
65-
j.memberExpression(
66-
j.identifier("Object"),
67-
j.identifier("isSealed")
68-
),
69-
[
70-
j.memberExpression(
71-
j.thisExpression(),
72-
j.identifier("refs")
73-
),
74-
]
75-
),
76-
j.blockStatement([
77-
// this.refs = {}
78-
j.expressionStatement(
79-
j.assignmentExpression(
80-
"=",
81-
j.memberExpression(
82-
j.thisExpression(),
83-
j.identifier("refs")
84-
),
85-
j.objectExpression([])
86-
)
87-
),
88-
])
89-
),
90-
])
91-
),
92-
// this.refs[valuePath.node.value] = current
9348
j.expressionStatement(
9449
j.assignmentExpression(
9550
"=",

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy