Skip to content

Commit

Permalink
Address small follow-up issues from recent PRs (#607)
Browse files Browse the repository at this point in the history
From #604, use `for...of` rather than `.forEach`.

From #540, exclude optional chaining snippets in `removeToken`, switch JSX test
to actually test JSX.
  • Loading branch information
alangpierce authored Apr 11, 2021
1 parent 9489132 commit 6277a20
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 15 deletions.
3 changes: 2 additions & 1 deletion src/TokenProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,8 @@ export default class TokenProcessor {
}

removeInitialToken(): void {
this.replaceToken("");
this.resultCode += this.previousWhitespaceAndComments();
this.tokenIndex++;
}

removeToken(): void {
Expand Down
4 changes: 2 additions & 2 deletions src/register.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ export function registerAll(hookOptions?: HookOptions): RevertFunction {
];

return () => {
reverts.forEach((fn) => {
for (const fn of reverts) {
fn();
});
}
};
}
27 changes: 15 additions & 12 deletions test/jest-test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
ESMODULE_PREFIX,
IMPORT_DEFAULT_PREFIX,
JSX_PREFIX,
NULLISH_COALESCE_PREFIX,
OPTIONAL_CHAIN_PREFIX,
} from "./prefixes";
Expand Down Expand Up @@ -185,20 +186,22 @@ jest.mock('a', (arg) => ({
it("transforms jsx in parameters", () => {
assertResult(
`
import {x, X} from './a';
jest.mock('a': number, (arg: string) => ({
f(x: string): void {
return (x: X);
}
}): any);
import React from 'react';
import {x} from './a';
jest.mock('a', (arg) => ({
f(x) {
return <div />;
}
}));
x()
`,
`"use strict";
`"use strict";${JSX_PREFIX}${IMPORT_DEFAULT_PREFIX}
jest.mock('a', (arg) => ({
f(x) {
return (x);
}
}));
f(x) {
return _react2.default.createElement('div', {__self: this, __source: {fileName: _jsxFileName, lineNumber: 6}} );
}
}));
var _react = require('react'); var _react2 = _interopRequireDefault(_react);
var _a = require('./a');
Expand All @@ -207,7 +210,7 @@ jest.mock('a', (arg) => ({
;
_a.x.call(void 0, )
`,
{transforms: ["jsx", "jest", "imports", "flow"]},
{transforms: ["jsx", "jest", "imports"]},
);
});

Expand Down

0 comments on commit 6277a20

Please sign in to comment.