UNPKG

eslint-codemod-utils

Version:

A collection of AST helper functions for more complex ESLint rule fixes.

97 lines (88 loc) 2.11 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const __1 = require(".."); const program_1 = __importDefault(require("../__fixtures__/program")); describe('program', () => { test('basic', () => { // The fixture is plain JSON with string-literal `type` fields rather than // `AST_NODE_TYPES` enum members, so widen via `unknown` into the loose // input type that `program(…)` accepts. expect(String((0, __1.program)(program_1.default))).eq(`import A, { Welcome } from '@atlaskit/welcome' import { X } from './other' import tmm, * as x from 'thing' import 'blah' const someImport = import('hello.js') const someStatement = probably.blob function App({a: a}, {b: c}) { return ( <div> <Welcome name="Sara" otherName={2} isBlanketHidden {...x()} /> <Welcome name="Cahal" /> <Welcome name="Edite" /> </div> ); } const silly = (1, 3) new X(\`\${hello}: "world" \${1 == 2 ? \`\${Welcome}\` : ''}\`) X() let z,zz,zzz const p = class Z {} class D extends B { constructor () { super() this.hello='hi' } other () { return this.hello; } } switch (e) { case 'x': false; ''; default: 'zz'; } const v1 = 1 + 4 + 2 { let a = 1 } ; [] if (1 < 3) {} else if (1 == 0) { console.log('success') } else { console.log('error') } const yy = { a: 1, get z() {}, set j(j) {}, init: function () {}, blob: async function () {}, b: function () {}, c: function d() {}, pp: function () {}, zz: async function () {} } for (let i = 0;;i++) { continue } try { throw new Error('bad thing'); } catch {} finally { console.log('cleanup') } while (i < 0) { break } const y = <Modal isOpen={true} onClick={onClick}> hello </Modal> ReactDOM.render(<App />, document.getElementById('root')) export { b as y }from './other' export default b export const yyy = 10 export * from 's'`); }); });