Skip to content

Commit 34c38b8

Browse files
committed
feature: @putout/plugin-extract-keywords-from-variables: MemberExpression
1 parent 3797de4 commit 34c38b8

File tree

6 files changed

+18
-1
lines changed

6 files changed

+18
-1
lines changed

packages/plugin-extract-keywords-from-variables/lib/extract-keywords-from-variables.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const {
1313
isAssignmentExpression,
1414
isExportNamedDeclaration,
1515
isIdentifier,
16+
isMemberExpression,
1617
} = types;
1718

1819
const {
@@ -23,7 +24,7 @@ const {
2324
isModuleDeclarationKeyword,
2425
} = operator;
2526

26-
const isInit = (a) => isIdentifier(a) || isLiteral(a) || isArrowFunctionExpression(a);
27+
const isInit = (a) => isIdentifier(a) || isLiteral(a) || isMemberExpression(a) || isArrowFunctionExpression(a);
2728

2829
const buildDeclaration = (type) => (nextPath, path) => {
2930
const {expression} = nextPath.node;

packages/plugin-extract-keywords-from-variables/test/extract-keywords-from-variables.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,16 @@ test('putout: extract-keywords-from-variables: transform: destr', (t) => {
5454
t.end();
5555
});
5656

57+
test('putout: extract-keywords-from-variables: transform: member', (t) => {
58+
t.transform('member');
59+
t.end();
60+
});
61+
62+
test('putout: extract-keywords-from-variables: transform: arrow', (t) => {
63+
t.transform('arrow');
64+
t.end();
65+
});
66+
5767
test('putout: extract-keywords-from-variables: report: const', (t) => {
5868
t.report('const', `Extract 'const' from variable`);
5969
t.end();
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
const a = (x) => x + 1;
2+
fn(a);
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
const a (x) => x + 1;
2+
fn(a);
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
var a = b.a;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
var a b.a;

0 commit comments

Comments
 (0)