mlly
mlly copied to clipboard
feat: More info about dynamic imports
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);