removeMaybeImportAttributes.js 599 B

12345678910111213141516171819202122
  1. import {ContextualKeyword} from "../parser/tokenizer/keywords";
  2. import {TokenType as tt} from "../parser/tokenizer/types";
  3. /**
  4. * Starting at a potential `with` or (legacy) `assert` token, remove the import
  5. * attributes if they exist.
  6. */
  7. export function removeMaybeImportAttributes(tokens) {
  8. if (
  9. tokens.matches2(tt._with, tt.braceL) ||
  10. (tokens.matches2(tt.name, tt.braceL) && tokens.matchesContextual(ContextualKeyword._assert))
  11. ) {
  12. // assert
  13. tokens.removeToken();
  14. // {
  15. tokens.removeToken();
  16. tokens.removeBalancedCode();
  17. // }
  18. tokens.removeToken();
  19. }
  20. }