Skip to content

Commit eee874c

Browse files
authored
Cross-fork lint: Support named export declaration (#20784)
Noticed this didn't work when I ran `replace-fork` and a named export declaration in ReactFiberReconciler was not properly fixed.
1 parent 3b870b1 commit eee874c

3 files changed

Lines changed: 72 additions & 37 deletions

File tree

‎packages/react-reconciler/src/ReactFiberReconciler.old.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ export {
104104
IdleLanePriorityasIdleEventPriority,
105105
}from'./ReactFiberLane.old';
106106

107-
export{registerMutableSourceForHydration}from'./ReactMutableSource.new';
107+
export{registerMutableSourceForHydration}from'./ReactMutableSource.old';
108108
export{createPortal}from'./ReactPortal';
109109
export{
110110
createComponentSelector,

‎scripts/eslint-rules/__tests__/no-cross-fork-imports-test.internal.js‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,5 +94,29 @@ ruleTester.run('eslint-rules/no-cross-fork-imports', rule, {
9494
],
9595
output: "import {scheduleUpdateOnFiber} from './ReactFiberWorkLoop.new';",
9696
},
97+
{
98+
code: "export {DiscreteEventPriority} from './ReactFiberLane.old.js';",
99+
filename: 'ReactFiberReconciler.new.js',
100+
errors: [
101+
{
102+
message:
103+
'A module that belongs to the new fork cannot import a module '+
104+
'from the old fork.',
105+
},
106+
],
107+
output: "export {DiscreteEventPriority} from './ReactFiberLane.new';",
108+
},
109+
{
110+
code: "export {DiscreteEventPriority} from './ReactFiberLane.new.js';",
111+
filename: 'ReactFiberReconciler.old.js',
112+
errors: [
113+
{
114+
message:
115+
'A module that belongs to the old fork cannot import a module '+
116+
'from the new fork.',
117+
},
118+
],
119+
output: "export {DiscreteEventPriority} from './ReactFiberLane.old';",
120+
},
97121
],
98122
});

‎scripts/eslint-rules/no-cross-fork-imports.js‎

Lines changed: 47 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -26,48 +26,59 @@ module.exports = {
2626
constsourceFilename=context.getFilename();
2727

2828
if(isOldFork(sourceFilename)){
29+
constvisitor=node=>{
30+
constsourceNode=node.source;
31+
if(sourceNode===null){
32+
return;
33+
}
34+
constfilename=sourceNode.value;
35+
if(isNewFork(filename)){
36+
context.report({
37+
node: sourceNode,
38+
message:
39+
'A module that belongs to the old fork cannot import a module '+
40+
'from the new fork.',
41+
fix(fixer){
42+
returnfixer.replaceText(
43+
sourceNode,
44+
`'${filename.replace(/\.new(\.js)?$/,'.old')}'`
45+
);
46+
},
47+
});
48+
}
49+
};
2950
return{
30-
ImportDeclaration(node){
31-
constimportSourceNode=node.source;
32-
constfilename=importSourceNode.value;
33-
if(isNewFork(filename)){
34-
context.report({
35-
node: importSourceNode,
36-
message:
37-
'A module that belongs to the old fork cannot import a module '+
38-
'from the new fork.',
39-
fix(fixer){
40-
returnfixer.replaceText(
41-
importSourceNode,
42-
`'${filename.replace(/\.new(\.js)?$/,'.old')}'`
43-
);
44-
},
45-
});
46-
}
47-
},
51+
ImportDeclaration: visitor,
52+
ExportNamedDeclaration: visitor,
4853
};
4954
}
5055

5156
if(isNewFork(sourceFilename)){
57+
constvisitor=node=>{
58+
constsourceNode=node.source;
59+
if(sourceNode===null){
60+
return;
61+
}
62+
constfilename=sourceNode.value;
63+
if(isOldFork(filename)){
64+
context.report({
65+
node: sourceNode,
66+
message:
67+
'A module that belongs to the new fork cannot import a module '+
68+
'from the old fork.',
69+
fix(fixer){
70+
returnfixer.replaceText(
71+
sourceNode,
72+
`'${filename.replace(/\.old(\.js)?$/,'.new')}'`
73+
);
74+
},
75+
});
76+
}
77+
};
78+
5279
return{
53-
ImportDeclaration(node){
54-
constimportSourceNode=node.source;
55-
constfilename=importSourceNode.value;
56-
if(isOldFork(filename)){
57-
context.report({
58-
node: importSourceNode,
59-
message:
60-
'A module that belongs to the new fork cannot import a module '+
61-
'from the old fork.',
62-
fix(fixer){
63-
returnfixer.replaceText(
64-
importSourceNode,
65-
`'${filename.replace(/\.old(\.js)?$/,'.new')}'`
66-
);
67-
},
68-
});
69-
}
70-
},
80+
ImportDeclaration: visitor,
81+
ExportNamedDeclaration: visitor,
7182
};
7283
}
7384

0 commit comments

Comments
 (0)