Skip to content

Commit

Permalink
fix: merge transform visitors
Browse files Browse the repository at this point in the history
  • Loading branch information
j4k0xb committed Dec 25, 2023
1 parent 0aff344 commit 38f0910
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
12 changes: 6 additions & 6 deletions packages/webcrack/src/ast-utils/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,12 @@ export function mergeTransforms(options: {
return {
name: options.name,
tags: options.tags,
run(ast, state) {
state.changes += applyTransforms(ast, options.transforms, {
name: options.name,
log: false,
}).changes;
},
scope: options.transforms.some((t) => t.scope),
visitor() {
return visitors.merge(
options.transforms.flatMap((t) => t.visitor?.() ?? []),
);
}
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@ test('member expression (Babel)', () =>
test.skip('computed member expression (Babel)', () =>
expectJS(`
var _a;
(_a = a) === null || _a === void 0 ? void 0 : _a[0];
(_a = a) === null || _a === undefined ? undefined : _a[0];
`).toMatchInlineSnapshot(`a?.[0];`));

test.skip('call expression (Babel)', () =>
expectJS(`
var _a;
(_a = a) === null || _a === void 0 ? void 0 : _a();
(_a = a) === null || _a === undefined ? undefined : _a();
`).toMatchInlineSnapshot(`a?.();`));

test.skip('call expression (TS)', () =>
expectJS(`
a === null || a === void 0 ? void 0 : a();
a === null || a === undefined ? undefined : a();
`).toMatchInlineSnapshot(`a?.();`));
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default {

const tmpVar = m.capture(m.identifier());
const tmpMember = m.capture(m.memberExpression(m.fromCapture(tmpVar)));
// Example (Babel): var _tmp; (_tmp = object) === null || _tmp === void 0 ? void 0 : _tmp.property;
// Example (Babel): var _tmp; (_tmp = object) === null || _tmp === undefined ? undefined : _tmp.property;
const tmpMatcher = m.conditionalExpression(
m.logicalExpression(
'||',
Expand Down

0 comments on commit 38f0910

Please sign in to comment.