Transforms:
foo && foo.bar;
foo.bar && foo.bar.baz;
(foo || {}).bar;
((foo || {}).bar || {}).baz;
((foo || {}).bar || {}).baz();
to
foo?.bar;
foo.bar?.baz;
foo?.bar;
foo?.bar?.baz;
foo?.bar?.baz();
To run a specific codemod from this project, you would run the following:
npx @nullvoxpopuli/optional-chaining-codemod path/of/files/ or/some**/*glob.js
# or
yarn global add @nullvoxpopuli/optional-chaining-codemod
optional-chaining-codemod path/of/files/ or/some**/*glob.js
# or
volta install @nullvoxpopuli/optional-chaining-codemod
optional-chaining-codemod path/of/files/ or/some**/*glob.js
yarn
yarn test
yarn update-docs