Skip to content

Latest commit

 

History

History
53 lines (39 loc) · 1.05 KB

File metadata and controls

53 lines (39 loc) · 1.05 KB

optional-chaining

Usage

npx typescript-optional-chaining-codemod optional-chaining path/of/files/ or/some**/*glob.js

# or

yarn global add typescript-optional-chaining-codemod
typescript-optional-chaining-codemod optional-chaining path/of/files/ or/some**/*glob.js

Input / Output


basic

Input (basic.input.ts):

foo && foo.bar;
foo.bar && foo.bar.baz;
foo && foo.bar && foo.bar.baz;
foo && foo.bar && foo.bar.baz();
foo && foo.bar && foo.bar.baz && foo.bar.baz();
foo.bar && foo.bar.baz();

(foo || {}).bar;
((foo || {}).bar || {}).baz;
((foo || {}).bar || {}).baz();

Output (basic.output.ts):

foo?.bar;
foo.bar?.baz;
foo?.bar?.baz;
foo?.bar?.baz();
foo.bar?.baz();

foo?.bar;
foo?.bar?.baz;
foo?.bar?.baz();