Skip to content

This plugin replaces objectPath.get (object-path) to new optional chaining syntax and remove unused object-path imports.

License

Notifications You must be signed in to change notification settings

aleksei0807/babel-plugin-object-path-get-to-optional-chaining

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

babel-plugin-object-path-get-to-optional-chaining

This plugin replaces objectPath.get (object-path) to new optional chaining syntax and remove unused object-path imports.

WORKING ONLY WITH BABEL 7. THIS PLUGIN NOT WORKING WITH BABEL 6.

Install

Babel install:

npm install --save-dev @babel/core @babel/cli @babel/preset-env

Plugin install:

npm i -D babel-plugin-object-path-get-to-optional-chaining

Usage

.babelrc

{
  "presets": [ "@babel/env" ],
  "plugins": [
    "object-path-get-to-optional-chaining"
  ]
}
./node_modules/.bin/babel src --out-dir src

Examples

from:

import objectPath from 'object-path'

objectPath.get(foo, 'bar.baz')
objectPath.get(foo.bar.baz.bar, 'baz')
objectPath.get(foo.bar, 'baz.bar')

to:

foo?.bar?.baz;
foo.bar.baz.bar?.baz;
foo.bar?.baz?.bar;

from:

import { get, set } from 'object-path'

get(foo, 'bar.baz')
get(foo.bar.baz.bar, 'baz')
get(foo.bar, 'baz.bar')

to:

import { set } from 'object-path';

foo?.bar?.baz;
foo.bar.baz.bar?.baz;
foo.bar?.baz?.bar;

from:

import { get } from 'object-path'

get(foo, 'bar.baz')
get(foo.bar.baz.bar, 'baz')
get(foo.bar, 'baz.bar')

to:

foo?.bar?.baz;
foo.bar.baz.bar?.baz;
foo.bar?.baz?.bar;

from:

import { get as objGet } from 'object-path'

objGet(foo, 'bar.baz')
objGet(foo.bar.baz.bar, 'baz')
objGet(foo.bar, 'baz.bar')

to:

foo?.bar?.baz;
foo.bar.baz.bar?.baz;
foo.bar?.baz?.bar;

from:

import { get as objGet, set as objSet } from 'object-path'

objGet(foo, 'bar.baz')
objGet(foo.bar.baz.bar, 'baz')
objGet(foo.bar, 'baz.bar')

to:

import { set as objSet } from 'object-path';

foo?.bar?.baz;
foo.bar.baz.bar?.baz;
foo.bar?.baz?.bar;

from:

import objectPath, { get as objGet, set as objSet } from 'object-path'

objGet(foo, 'bar.baz')
objGet(foo.bar.baz.bar, 'baz')
objGet(foo.bar, 'baz.bar')

to:

import { set as objSet } from 'object-path';

foo?.bar?.baz;
foo.bar.baz.bar?.baz;
foo.bar?.baz?.bar;

from:

import objectPath, { get as objGet, set as objSet } from 'object-path'

objGet(foo, 'bar.baz')
objGet(foo.bar.baz.bar, 'baz')
objGet(foo.bar, 'baz.bar')
objectPath.set(foo, 'baz')

to:

import objectPath, { set as objSet } from 'object-path';

foo?.bar?.baz;
foo.bar.baz.bar?.baz;
foo.bar?.baz?.bar;
objectPath.set(foo, 'baz');

from:

import objectPath, { get as objGet, set as objSet } from 'object-path'

objGet(foo, 'bar.baz')
objGet(foo.bar.baz.bar, 'baz')
objGet(foo.bar, 'baz.bar')
objectPath[cond ? 'get' : 'set'](foo, 'bar')

to:

import objectPath, { set as objSet } from 'object-path';

foo?.bar?.baz;
foo.bar.baz.bar?.baz;
foo.bar?.baz?.bar;
objectPath[cond ? 'get' : 'set'](foo, 'bar');

About

This plugin replaces objectPath.get (object-path) to new optional chaining syntax and remove unused object-path imports.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published