modify code in input.js and save,you will see genrated code in output.js
If you wanna konw about option-chain implement progress,keep page moving up
The simplest implementation
Although simple, it achieves the simplest effect,But add another attribute and kneel immediately
Repair normal ‘.’ symbol also triggers “?.” Conversion problem
Obviously, b.c does not need to judge b, so we continue to improve it
Try again, it ‘s not bad
But if you add an optional value There will be problems
Store calculation results
a==null?undefined:a.bIt was repeated twice,So let’s optimize it again, as shown below First,we create a unique variable in the current scope and injects it into the scope. Then, while performing the ternary operation, we assign the result and store the operation result
You think it’s over, but there’s another question
avoid ‘undefined’ being declared,like ‘let undefined = 2’
In order to prevent a big brother from assigning an undefined value, we need to use Babel’s API to build the undefined value in the scope here is the result below
add ‘&&’ form
Before we finish, let’s play again. Babel’s afferent option constructs another form