@1adybug/prettier-plugin-sort-imports 0.0.14 → 0.0.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +9 -2
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -99,7 +99,8 @@ function formatImportStatement(statement) {
99
99
  const namedPartsWithComments = [];
100
100
  for (const content of importContents){
101
101
  if ("default" === content.name) {
102
- if (isExport && content.alias) namedParts.push(`default as ${content.alias}`);
102
+ if (isExport) if (content.alias) namedParts.push(`default as ${content.alias}`);
103
+ else namedParts.push("default");
103
104
  else parts.push(content.alias ?? "default");
104
105
  continue;
105
106
  }
@@ -557,6 +558,13 @@ function mergeImports(imports) {
557
558
  const src_require = createRequire(import.meta.url);
558
559
  function preprocessImports(text, options, config = {}) {
559
560
  try {
561
+ const parser = options.parser;
562
+ const supportedParsers = [
563
+ "babel",
564
+ "typescript",
565
+ "babel-ts"
566
+ ];
567
+ if (!parser || !supportedParsers.includes(parser)) return text;
560
568
  const imports = parseImports(text);
561
569
  if (0 === imports.length) return text;
562
570
  const optionsConfig = options;
@@ -593,7 +601,6 @@ function preprocessImports(text, options, config = {}) {
593
601
  const separator = needsExtraNewline ? "\n\n" : "\n";
594
602
  return beforeImports + formattedImports + separator + afterImports;
595
603
  } catch (error) {
596
- console.error("Failed to sort imports:", error);
597
604
  return text;
598
605
  }
599
606
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@1adybug/prettier-plugin-sort-imports",
3
3
  "type": "module",
4
- "version": "0.0.14",
4
+ "version": "0.0.16",
5
5
  "description": "一个 Prettier 插件,用于对 JavaScript/TypeScript 文件的导入语句进行分组和排序",
6
6
  "keywords": [
7
7
  "prettier",