Skip to content

Commit 285041d

Browse files
committed
wip
1 parent a891f5b commit 285041d

File tree

4 files changed

+244
-257
lines changed

4 files changed

+244
-257
lines changed

packages/cli/src/helper/languages/javascript/cleanup.ts

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -251,8 +251,7 @@ export function cleanupUnusedJavascriptImports(
251251
if (
252252
importSpecifierToRemove.length ===
253253
depImport.importSpecifierIdentifiers.length &&
254-
(removeDefaultImport || !depImport.importIdentifier) &&
255-
(removeNameSpaceImport || !depImport.namespaceImport)
254+
(removeDefaultImport || removeNameSpaceImport)
256255
) {
257256
indexesToRemove.push({
258257
startIndex: depImport.node.startIndex,
@@ -265,20 +264,6 @@ export function cleanupUnusedJavascriptImports(
265264
endIndex: importSpecifier.endIndex,
266265
});
267266
});
268-
269-
if (removeDefaultImport && depImport.importIdentifier) {
270-
indexesToRemove.push({
271-
startIndex: depImport.importIdentifier.startIndex,
272-
endIndex: depImport.importIdentifier.endIndex,
273-
});
274-
}
275-
276-
if (removeNameSpaceImport && depImport.namespaceImport) {
277-
indexesToRemove.push({
278-
startIndex: depImport.namespaceImport.startIndex,
279-
endIndex: depImport.namespaceImport.endIndex,
280-
});
281-
}
282267
}
283268
});
284269

packages/cli/src/helper/languages/javascript/imports.test.ts

Lines changed: 49 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -56,53 +56,53 @@ import * as test from './test';
5656
expect(imports[1].importSpecifierIdentifiers.length).toBe(0);
5757
});
5858

59-
it("Should work with require import", () => {
60-
const parser = new Parser();
61-
parser.setLanguage(Javascript);
62-
63-
const tree = parser.parse(`
64-
const { test1, test2 } = require('@nestjs/common');
65-
const test = require('./test');
66-
`);
67-
68-
const imports = getJavascriptImports(parser, tree.rootNode);
69-
70-
expect(imports.length).toBe(2);
71-
72-
expect(imports[0].source).toBe("@nestjs/common");
73-
expect(imports[0].importIdentifier).toBe(undefined);
74-
expect(imports[0].importSpecifierIdentifiers.length).toBe(2);
75-
expect(imports[0].importSpecifierIdentifiers[0].text).toBe("test1");
76-
expect(imports[0].importSpecifierIdentifiers[1].text).toBe("test2");
77-
78-
expect(imports[1].source).toBe("./test");
79-
expect(imports[1].importIdentifier).not.toBe(undefined);
80-
expect(imports[1].importIdentifier?.text).toBe("test");
81-
expect(imports[1].importSpecifierIdentifiers.length).toBe(0);
82-
});
83-
84-
it("Should work with dynamic import", () => {
85-
const parser = new Parser();
86-
parser.setLanguage(Javascript);
87-
88-
const tree = parser.parse(`
89-
const { test1, test2 } = import('@nestjs/common');
90-
const test = import('./test');
91-
`);
92-
93-
const imports = getJavascriptImports(parser, tree.rootNode);
94-
95-
expect(imports.length).toBe(2);
96-
97-
expect(imports[0].source).toBe("@nestjs/common");
98-
expect(imports[0].importIdentifier).toBe(undefined);
99-
expect(imports[0].importSpecifierIdentifiers.length).toBe(2);
100-
expect(imports[0].importSpecifierIdentifiers[0].text).toBe("test1");
101-
expect(imports[0].importSpecifierIdentifiers[1].text).toBe("test2");
102-
103-
expect(imports[1].source).toBe("./test");
104-
expect(imports[1].importIdentifier).not.toBe(undefined);
105-
expect(imports[1].importIdentifier?.text).toBe("test");
106-
expect(imports[1].importSpecifierIdentifiers.length).toBe(0);
107-
});
59+
// it("Should work with require import", () => {
60+
// const parser = new Parser();
61+
// parser.setLanguage(Javascript);
62+
63+
// const tree = parser.parse(`
64+
// const { test1, test2 } = require('@nestjs/common');
65+
// const test = require('./test');
66+
// `);
67+
68+
// const imports = getJavascriptImports(parser, tree.rootNode);
69+
70+
// expect(imports.length).toBe(2);
71+
72+
// expect(imports[0].source).toBe("@nestjs/common");
73+
// expect(imports[0].importIdentifier).toBe(undefined);
74+
// expect(imports[0].importSpecifierIdentifiers.length).toBe(2);
75+
// expect(imports[0].importSpecifierIdentifiers[0].text).toBe("test1");
76+
// expect(imports[0].importSpecifierIdentifiers[1].text).toBe("test2");
77+
78+
// expect(imports[1].source).toBe("./test");
79+
// expect(imports[1].importIdentifier).not.toBe(undefined);
80+
// expect(imports[1].importIdentifier?.text).toBe("test");
81+
// expect(imports[1].importSpecifierIdentifiers.length).toBe(0);
82+
// });
83+
84+
// it("Should work with dynamic import", () => {
85+
// const parser = new Parser();
86+
// parser.setLanguage(Javascript);
87+
88+
// const tree = parser.parse(`
89+
// const { test1, test2 } = import('@nestjs/common');
90+
// const test = import('./test');
91+
// `);
92+
93+
// const imports = getJavascriptImports(parser, tree.rootNode);
94+
95+
// expect(imports.length).toBe(2);
96+
97+
// expect(imports[0].source).toBe("@nestjs/common");
98+
// expect(imports[0].importIdentifier).toBe(undefined);
99+
// expect(imports[0].importSpecifierIdentifiers.length).toBe(2);
100+
// expect(imports[0].importSpecifierIdentifiers[0].text).toBe("test1");
101+
// expect(imports[0].importSpecifierIdentifiers[1].text).toBe("test2");
102+
103+
// expect(imports[1].source).toBe("./test");
104+
// expect(imports[1].importIdentifier).not.toBe(undefined);
105+
// expect(imports[1].importIdentifier?.text).toBe("test");
106+
// expect(imports[1].importSpecifierIdentifiers.length).toBe(0);
107+
// });
108108
});

0 commit comments

Comments
 (0)