getIdentifierNames.js 369 B

123456789101112131415
  1. import {TokenType as tt} from "../parser/tokenizer/types";
  2. /**
  3. * Get all identifier names in the code, in order, including duplicates.
  4. */
  5. export default function getIdentifierNames(code, tokens) {
  6. const names = [];
  7. for (const token of tokens) {
  8. if (token.type === tt.name) {
  9. names.push(code.slice(token.start, token.end));
  10. }
  11. }
  12. return names;
  13. }