Skip to content

Instantly share code, notes, and snippets.

@guest271314
Created June 21, 2019 06:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save guest271314/daa1c6455ec8a2b6b89aff245e95c615 to your computer and use it in GitHub Desktop.
Save guest271314/daa1c6455ec8a2b6b89aff245e95c615 to your computer and use it in GitHub Desktop.
nameofall: Get all const, let, class variables names as strings
// 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