Created
June 21, 2019 06:38
-
-
Save guest271314/daa1c6455ec8a2b6b89aff245e95c615 to your computer and use it in GitHub Desktop.
nameofall: Get all const, let, class variables names as strings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://esdiscuss.org/topic/what-do-you-think-about-a-c-6-like-nameof-expression-for | |
// TODO handle destructuring assignment, default values, shorthand assignments, e.g., | |
/* | |
const [{ | |
a = 1, | |
b = 2 | |
}, cd] = [...[source]]; | |
*/ | |
/* | |
usage sourceCode.match(nameofall); // ["const x", "let z"]; | |
*/ | |
const nameofall = /((const|let)\s+)\w+(?=\s+(=|in|of))|class\s+\w+(?=\s)/gi; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment