Skip to content

Commit 46bfb6d

Browse files
committed
fix: @putout/plugin-declare-before-reference: named-export
1 parent 9e4b434 commit 46bfb6d

5 files changed

Lines changed: 11 additions & 6 deletions

File tree

packages/plugin-declare-before-reference/lib/declare-before-reference.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const {
1414
isBlockStatement,
1515
isProgram,
1616
isArrowFunctionExpression,
17+
isExportDeclaration,
1718
} = types;
1819

1920
const isArrowOrBlock = (a) => isArrowFunctionExpression(a) || isBlockStatement(a);
@@ -33,6 +34,7 @@ export const fix = ({path, referencePath}) => {
3334

3435
delete node.loc;
3536

37+
const exportNode = path.parentPath.parentPath.node;
3638
remove(path.parentPath);
3739

3840
if (path.scope.uid !== programPath.scope.uid) {
@@ -52,6 +54,11 @@ export const fix = ({path, referencePath}) => {
5254
return;
5355
}
5456

57+
if (isExportDeclaration(exportNode)) {
58+
programPath.node.body.unshift(exportNode);
59+
return;
60+
}
61+
5562
programPath.node.body.unshift(node);
5663
};
5764

packages/plugin-declare-before-reference/test/declare-before-reference.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,8 @@ test('plugin-declare-before-reference: transform: arg', (t) => {
169169
t.end();
170170
});
171171

172-
test('plugin-declare-before-reference: transform: type-check', (t) => {
173-
t.transform('type-check');
172+
test('plugin-declare-before-reference: transform: named-export', (t) => {
173+
t.transform('named-export');
174174
t.end();
175175
});
176176

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
const getA = () => {
1+
export const getA = () => {
22
return false;
33
};
4-
54
export type GetA = typeof getA;

packages/plugin-declare-before-reference/test/fixture/type-check-fix.js renamed to packages/plugin-declare-before-reference/test/fixture/named-export-fix.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
const isIncreaseIndent = createTypeChecker([
1+
export const isIncreaseIndent = createTypeChecker([
22
['-: path.node.elements -> !', Boolean],
33
['+', isStringAndObject],
44
]);
5-
65
export const isMultiLine = createTypeChecker([
76
['-', isIncreaseIndent],
87
['+', isSimpleAndNotEmptyObject],

packages/plugin-declare-before-reference/test/fixture/type-check.js renamed to packages/plugin-declare-before-reference/test/fixture/named-export.js

File renamed without changes.

0 commit comments

Comments
 (0)