Skip to content

Commit 21a971c

Browse files
committed
fix: @putout/plugin-minify: merge-variables: no loc
1 parent ad46321 commit 21a971c

File tree

1 file changed

+3
-2
lines changed
  • packages/plugin-minify/lib/merge-variables

1 file changed

+3
-2
lines changed

packages/plugin-minify/lib/merge-variables/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const {
77

88
const {remove} = operator;
99
const getNode = (a) => a.node;
10+
const maybeStartLine = (a) => a.node.loc?.start.line || 0;
1011

1112
export const report = () => `Merge variables`;
1213

@@ -51,7 +52,7 @@ export const traverse = ({push, uplist}) => ({
5152
const [path, ...vars] = allVars;
5253
const {kind} = path.parentPath.node;
5354
const {bindings} = path.scope;
54-
const startLine = path.node.loc?.start.line;
55+
const startLine = maybeStartLine(path);
5556

5657
for (const [index, path] of vars.entries()) {
5758
const {node} = path;
@@ -60,7 +61,7 @@ export const traverse = ({push, uplist}) => ({
6061
if (isCallExpression(init) && isMemberExpression(init.callee)) {
6162
const binding = bindings[init.callee.object.name];
6263

63-
if (binding && startLine && startLine !== path.node.loc.start.line - index) {
64+
if (binding && startLine && startLine !== maybeStartLine(path) - index) {
6465
vars.splice(index, 2);
6566
continue;
6667
}

0 commit comments

Comments
 (0)