mlly icon indicating copy to clipboard operation
mlly copied to clipboard

feat: More info about dynamic imports

Open Kolobok12309 opened this issue 3 years ago • 0 comments

For example new props isStatic: boolean - this import can changes or it static string staticSpecifier: string or specifier: string - if isStatic: true it can be useful

My case for this props, i write small webpack loader for add some query params(?foo=bar) to some imports(doesn't matter static or dynamic)

Currently code that i use

const removeComments = text => text
  .replace(/\/\*.*\*\//gm, '')
  .replace(/\/\/.*\n/gm, '');

const isStaticDynamicImport = (expression) => {
  const normalized = removeComments(expression);

  return (normalized.startsWith('\'') && normalized.endsWith('\''))
    || (normalized.startsWith('"') && normalized.endsWith('"'));
};

// Not very stable i think
const getStaticSpecifier = (expression) => 
  removeComments(expression).slice(1, -1);

Kolobok12309 avatar Oct 11 '22 08:10 Kolobok12309