Skip to content

Commit a72e6ea

Browse files
committed
feature: @putout/engine-runner: reason: fix
1 parent 882439a commit a72e6ea

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

packages/engine-runner/lib/run-fix.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ const tryToFix = (fix, {path, pathOptions, position, options}) => {
4141
return;
4242

4343
e.loc = e.loc || position;
44+
e.reason = 'fix';
4445

4546
throw e;
4647
};

packages/engine-runner/lib/try-throw-with-reason.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ module.exports.tryThrowWithReason = (fn, ...args) => {
66
const [error, result] = tryCatch(fn, ...args);
77

88
if (error) {
9-
error.reason = 'traverse';
9+
error.reason ??= 'traverse';
1010
throw error;
1111
}
1212

packages/engine-runner/test/runner.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1097,3 +1097,35 @@ test('putout: runner: runPlugins: traverse: reason', (t) => {
10971097
t.equal(error.reason, 'traverse');
10981098
t.end();
10991099
});
1100+
1101+
test('putout: runner: runPlugins: fix: reason', (t) => {
1102+
const duplicator = {
1103+
report: () => '',
1104+
fix: () => {
1105+
throw Error('x');
1106+
},
1107+
traverse: ({push}) => ({
1108+
DebuggerStatement: (path) => {
1109+
push(path);
1110+
},
1111+
}),
1112+
};
1113+
1114+
const code = 'debugger';
1115+
const ast = parse(code);
1116+
1117+
const plugins = loadPlugins({
1118+
pluginNames: [
1119+
['duplicator', duplicator],
1120+
],
1121+
});
1122+
1123+
const [error] = tryCatch(runPlugins, {
1124+
ast,
1125+
fix: true,
1126+
plugins,
1127+
});
1128+
1129+
t.equal(error.reason, 'fix');
1130+
t.end();
1131+
});

0 commit comments

Comments
 (0)