babel-plugin-transform-commonjs-npm-1.1.6-0007fa2809 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. diff --git a/dist/index.js b/dist/index.js
  2. index 0f9a4b342c75d75309b78a36473fb5c68f7b89b5..57effed56c190a946756d191cb3d390dbc84aee3 100644
  3. --- a/dist/index.js
  4. +++ b/dist/index.js
  5. @@ -92,18 +92,32 @@ exports.default = helper_plugin_utils_1.declare((api, options) => {
  6. const specifiers = [];
  7. // Convert to named import.
  8. if (core_1.types.isObjectPattern(path.parentPath.node.id)) {
  9. - path.parentPath.node.id.properties.forEach(prop => {
  10. - specifiers.push(core_1.types.importSpecifier(prop.value, prop.key));
  11. - state.globals.add(prop.value.name);
  12. - });
  13. - const decl = core_1.types.importDeclaration(specifiers, core_1.types.stringLiteral(str.value));
  14. - // @ts-ignore
  15. - decl.__replaced = true;
  16. - path.scope.getProgramParent().path.unshiftContainer('body', decl);
  17. - path.parentPath.remove();
  18. + if(node.arguments[0].value.startsWith('.') || node.arguments[0].value.startsWith('@uppy/')) {
  19. + const id = path.scope.generateUidIdentifier(node.arguments[0].value)
  20. + const destructuring = core_1.types.variableDeclarator(path.parentPath.node.id, id)
  21. + const decl = core_1.types.importDeclaration([core_1.types.importDefaultSpecifier(id)], core_1.types.stringLiteral(str.value));
  22. + // @ts-ignore
  23. + decl.__replaced = true;
  24. + path.scope.getProgramParent().path.unshiftContainer('body', decl);
  25. + path.parentPath.replaceWith(destructuring)
  26. + } else {
  27. + path.parentPath.node.id.properties.forEach(prop => {
  28. + specifiers.push(core_1.types.importSpecifier(prop.value, prop.key));
  29. + state.globals.add(prop.value.name);
  30. + });
  31. + const decl = core_1.types.importDeclaration(specifiers, core_1.types.stringLiteral(str.value));
  32. + // @ts-ignore
  33. + decl.__replaced = true;
  34. + path.scope.getProgramParent().path.unshiftContainer('body', decl);
  35. + path.parentPath.remove()
  36. + }
  37. }
  38. + else if (node.arguments[0].value === 'tus-js-client' && str) {
  39. + const decl = core_1.types.importDeclaration([core_1.types.importNamespaceSpecifier(path.parentPath.node.id)], core_1.types.stringLiteral(str.value))
  40. + path.scope.getProgramParent().path.unshiftContainer('body', decl);
  41. + path.parentPath.remove()
  42. // Convert to default import.
  43. - else if (str) {
  44. + } else if (str) {
  45. const { parentPath } = path;
  46. const { left } = parentPath.node;
  47. // @ts-ignore