@veloceapps/sdk 8.0.0-176 → 8.0.0-178

Sign up to get free protection for your applications and to get access to all the features.
@@ -1668,22 +1668,26 @@ const vendorMap = {
1668
1668
  lodash: lodash,
1669
1669
  };
1670
1670
 
1671
- const importRegexp = new RegExp(`import([ \\n\\t]*(?:[^ \\n\\t\\{\\}]+[ \\n\\t]*,?)?(?:[ \\n\\t]*\\{(?:[ \\n\\t]*[^ \\n\\t"'\\{\\}]+[ \\n\\t]*,?)+\\})?[ \\n\\t]*)from[ \\n\\t]*(['"])([^'"\\n]+)(?:['"]);`, 'g');
1671
+ const importRegexp = new RegExp(`import\\s+(?:{[^{}]+}|.*?)\\s*(?:from)?\\s*['"].*?['"]|import\\(.*?\\)`, 'g');
1672
+ const importPartsRegexp = new RegExp(`import ([\\n\\t]*(?:[^ \\n\\t\\{\\}]+[ \\n\\t]*,?)?(?:[ \\n\\t]*\\{(?:[ \\n\\t]*[^ \\n\\t"'\\{\\}]+[ \\n\\t]*,?)+\\})?[\\n\\t]*) from[ \\n\\t]*(['"])([^'"\\n]+)(?:['"])`, 'g');
1672
1673
  const normalizeImports = (script, elementPath) => {
1673
- const result = script.replace(importRegexp, (match, g1, g2, src) => {
1674
- const imports = g1
1675
- .trim()
1676
- .slice(1, -1)
1677
- .split(',')
1678
- .map(item => item.trim());
1679
- imports.forEach(item => {
1680
- if (!vendorMap[src]?.[item]) {
1681
- throw new Error(`Failed to import ${item} from '${src}' in ${elementPath}/script.ts`);
1682
- }
1674
+ return script.replace(importRegexp, match => {
1675
+ return match.replace(importPartsRegexp, (_, g1, __, src) => {
1676
+ const strObj = g1.replace(/ as /g, ': ').trim();
1677
+ const imports = strObj
1678
+ .slice(1, -1)
1679
+ .split(',')
1680
+ .map(item => item.split(':')[0])
1681
+ .filter(isDefined)
1682
+ .map(item => item.trim());
1683
+ imports.forEach(item => {
1684
+ if (!vendorMap[src]?.[item]) {
1685
+ throw new Error(`Failed to import ${item} from '${src}' in ${elementPath}/script.ts`);
1686
+ }
1687
+ });
1688
+ return `const ${strObj} = vendor['${src}'];`;
1683
1689
  });
1684
- return `const ${g1} = vendor['${src}'];`;
1685
1690
  });
1686
- return result;
1687
1691
  };
1688
1692
  const getScriptClass = (metadata) => {
1689
1693
  if (!metadata?.script) {