@1adybug/prettier-plugin-sort-imports 0.0.9 → 0.0.11

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 +7 -0
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -25,6 +25,11 @@ function analyzeUsedIdentifiers(code) {
25
25
  const node = path.node;
26
26
  if (path.parent?.type === "JSXOpeningElement" || path.parent?.type === "JSXClosingElement") usedIdentifiers.add(node.name);
27
27
  },
28
+ JSXMemberExpression (path) {
29
+ let current = path.node;
30
+ while("JSXMemberExpression" === current.type)current = current.object;
31
+ if ("JSXIdentifier" === current.type) usedIdentifiers.add(current.name);
32
+ },
28
33
  TSTypeReference (path) {
29
34
  const node = path.node;
30
35
  if ("Identifier" === node.typeName.type) usedIdentifiers.add(node.typeName.name);
@@ -163,6 +168,8 @@ function formatImportStatements(statements) {
163
168
  return statements.map(formatImportStatement).join("\n");
164
169
  }
165
170
  function parseImports(code) {
171
+ const hasImportOrExport = /^\s*(import|export)\s/m.test(code);
172
+ if (!hasImportOrExport) return [];
166
173
  const ast = parse(code, {
167
174
  sourceType: "module",
168
175
  plugins: [
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.9",
4
+ "version": "0.0.11",
5
5
  "description": "一个 Prettier 插件,用于对 JavaScript/TypeScript 文件的导入语句进行分组和排序",
6
6
  "keywords": [
7
7
  "prettier",