@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.
- package/dist/index.js +7 -0
- 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: [
|