Skip to content

Commit 273e81a

Browse files
committed
add safe destructuring constant
1 parent 95bb459 commit 273e81a

File tree

4 files changed

+27
-9
lines changed

4 files changed

+27
-9
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ Fixed for any bug fixes.
99
Security to invite users to upgrade in case of vulnerabilities.
1010
-->
1111

12+
## [1.6.0] - 2022/07/27
13+
14+
### Added
15+
16+
- Const destructuring in a safe way to avoid the `Cannot destructure Property of Undefined Error` when the variable is `undefined`.
17+
1218
## [1.5.4] - 2022/07/08
1319

1420
### Fixed

README.md

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -95,14 +95,16 @@ Below is a list of all available snippets and the triggers of each one. The **
9595

9696
### Destructuring
9797

98-
| Trigger | Description | Result JS/TS |
99-
| -------: | ------------------------------- | ------------------------------------- |
100-
| `cod→` | const object dest | `const {prop, prop} = name█` |
101-
| `codr→` | const object dest with rest | `const {prop, prop, ...rest} = name█` |
102-
| `cad→` | const array dest | `const [prop, prop] = name█` |
103-
| `cadr→` | const array dest with rest | `const [prop, prop, ...rest] = name█` |
104-
| `pd→` | parameter object dest | `{prop, prop}█` |
105-
| `pdr→` | parameter object dest with rest | `{prop, prop, ...rest}█` |
98+
| Trigger | Description | Result JS/TS |
99+
| -------: | ------------------------------- | ---------------------------------------- |
100+
| `cod→` | const object dest | `const {prop, prop} = name█` |
101+
| `cods→` | const object dest safe | `const {prop, prop} = name || {}█` |
102+
| `codr→` | const object dest with rest | `const {prop, prop, ...rest} = name█` |
103+
| `cad→` | const array dest | `const [prop, prop] = name█` |
104+
| `cads→` | const array dest safe | `const [prop, prop] = name || []█` |
105+
| `cadr→` | const array dest with rest | `const [prop, prop, ...rest] = name█` |
106+
| `pd→` | parameter object dest | `{prop, prop}█` |
107+
| `pdr→` | parameter object dest with rest | `{prop, prop, ...rest}█` |
106108

107109
### Object Elements
108110

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "const-props-snippets",
33
"description": "VS Code Const & Props snippets for JS and TS",
4-
"version": "1.5.4",
4+
"version": "1.6.0",
55
"displayName": "Const & Props Snippets",
66
"publisher": "deinsoftware",
77
"icon": "images/light-icon.png",

snippets/destructuring.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
"body": "const {${2:prop}, ${3:prop}} = ${1:name}$0",
55
"description": "Constant Object Destructuring"
66
},
7+
"constantObjectDestructuringSafe": {
8+
"prefix": "cods",
9+
"body": "const {${2:prop}, ${3:prop}} = ${1:name} || {}$0",
10+
"description": "Constant Object Destructuring Safe"
11+
},
712
"constantObjectDestructuringWithRest": {
813
"prefix": "codr",
914
"body": "const {${2:prop}, ${3:prop}, ...rest} = ${1:name}$0",
@@ -14,6 +19,11 @@
1419
"body": "const [${2:prop}, ${3:prop}] = ${1:name}$0",
1520
"description": "Constant Array Destructuring"
1621
},
22+
"constantArrayDestructuringSafe": {
23+
"prefix": "cad",
24+
"body": "const [${2:prop}, ${3:prop}] = ${1:name} || []$0",
25+
"description": "Constant Array Destructuring Safe"
26+
},
1727
"constantArrayDestructuringWithRest": {
1828
"prefix": "cadr",
1929
"body": "const [${2:prop}, ${3:prop}, ...rest] = ${1:name}$0",

0 commit comments

Comments
 (0)