Skip to content

Commit 95f29fb

Browse files
clydinhansl
authored andcommitted
refactor(@angular-devkit/build-optimizer): remove unused import purifier
1 parent 46da426 commit 95f29fb

File tree

3 files changed

+0
-74
lines changed

3 files changed

+0
-74
lines changed

packages/angular_devkit/build_optimizer/src/build-optimizer/build-optimizer_spec.ts

-2
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ describe('build-optimizer', () => {
5858
`;
5959
// tslint:disable:max-line-length
6060
const output = tags.oneLine`
61-
/** PURE_IMPORTS_START _angular_core,tslib PURE_IMPORTS_END */
6261
${imports}
6362
import { __extends } from "tslib";
6463
var ChangeDetectionStrategy = /*@__PURE__*/ (function (ChangeDetectionStrategy) {
@@ -93,7 +92,6 @@ describe('build-optimizer', () => {
9392

9493
it('supports flagging module as side-effect free', () => {
9594
const output = tags.oneLine`
96-
/** PURE_IMPORTS_START PURE_IMPORTS_END */
9795
var RenderType_MdOption = /*@__PURE__*/ ɵcrt({ encapsulation: 2, styles: styles_MdOption });
9896
`;
9997
const input = tags.stripIndent`

packages/angular_devkit/build_optimizer/src/transforms/prefix-functions.ts

-34
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,8 @@ export function getPrefixFunctionsTransformer(): ts.TransformerFactory<ts.Source
1515
const transformer: ts.Transformer<ts.SourceFile> = (sf: ts.SourceFile) => {
1616

1717
const topLevelFunctions = findTopLevelFunctions(sf);
18-
const pureImports = findPureImports(sf);
19-
const pureImportsComment = `* PURE_IMPORTS_START ${pureImports.join(',')} PURE_IMPORTS_END `;
2018

2119
const visitor: ts.Visitor = (node: ts.Node): ts.Node => {
22-
23-
// Add the pure imports comment to the first node.
24-
if (node.parent && node.parent.parent === undefined && node.pos === 0) {
25-
const newNode = ts.addSyntheticLeadingComment(
26-
node, ts.SyntaxKind.MultiLineCommentTrivia, pureImportsComment, true);
27-
28-
// Replace node with modified one.
29-
return ts.visitEachChild(newNode, visitor, context);
30-
}
31-
3220
// Add pure function comment to top level functions.
3321
if (topLevelFunctions.has(node)) {
3422
const newNode = ts.addSyntheticLeadingComment(
@@ -109,28 +97,6 @@ export function findTopLevelFunctions(parentNode: ts.Node): Set<ts.Node> {
10997
return topLevelFunctions;
11098
}
11199

112-
export function findPureImports(parentNode: ts.Node): string[] {
113-
const pureImports: string[] = [];
114-
ts.forEachChild(parentNode, cb);
115-
116-
function cb(node: ts.Node) {
117-
if (node.kind === ts.SyntaxKind.ImportDeclaration
118-
&& (node as ts.ImportDeclaration).importClause) {
119-
120-
// Save the path of the import transformed into snake case and remove relative paths.
121-
const moduleSpecifier = (node as ts.ImportDeclaration).moduleSpecifier as ts.StringLiteral;
122-
const pureImport = moduleSpecifier.text
123-
.replace(/[\/@\-]/g, '_')
124-
.replace(/^\.+/, '');
125-
pureImports.push(pureImport);
126-
}
127-
128-
ts.forEachChild(node, cb);
129-
}
130-
131-
return pureImports;
132-
}
133-
134100
function hasPureComment(node: ts.Node) {
135101
if (!node) {
136102
return false;

packages/angular_devkit/build_optimizer/src/transforms/prefix-functions_spec.ts

-38
Original file line numberDiff line numberDiff line change
@@ -15,45 +15,14 @@ const transform = (content: string) => transformJavascript(
1515
{ content, getTransforms: [getPrefixFunctionsTransformer] }).content;
1616

1717
describe('prefix-functions', () => {
18-
const emptyImportsComment = '/** PURE_IMPORTS_START PURE_IMPORTS_END */';
1918
const clazz = 'var Clazz = (function () { function Clazz() { } return Clazz; }());';
2019

21-
describe('pure imports', () => {
22-
it('adds import list', () => {
23-
const input = tags.stripIndent`
24-
import { Injectable } from '@angular/core';
25-
import { Something } from './relative/pure_import';
26-
var foo = Injectable;
27-
var bar = Something;
28-
`;
29-
const output = tags.stripIndent`
30-
/** PURE_IMPORTS_START _angular_core,_relative_pure_import PURE_IMPORTS_END */
31-
${input}
32-
`;
33-
34-
expect(tags.oneLine`${transform(input)}`).toEqual(tags.oneLine`${output}`);
35-
});
36-
37-
it('adds import list even with no imports', () => {
38-
const input = tags.stripIndent`
39-
var foo = 42;
40-
`;
41-
const output = tags.stripIndent`
42-
${emptyImportsComment}
43-
${input}
44-
`;
45-
46-
expect(tags.oneLine`${transform(input)}`).toEqual(tags.oneLine`${output}`);
47-
});
48-
});
49-
5020
describe('pure functions', () => {
5121
it('adds comment to new calls', () => {
5222
const input = tags.stripIndent`
5323
var newClazz = new Clazz();
5424
`;
5525
const output = tags.stripIndent`
56-
${emptyImportsComment}
5726
var newClazz = /*@__PURE__*/ new Clazz();
5827
`;
5928

@@ -65,7 +34,6 @@ describe('prefix-functions', () => {
6534
var newClazz = Clazz();
6635
`;
6736
const output = tags.stripIndent`
68-
${emptyImportsComment}
6937
var newClazz = /*@__PURE__*/ Clazz();
7038
`;
7139

@@ -78,7 +46,6 @@ describe('prefix-functions', () => {
7846
var ClazzTwo = (function () { function Clazz() { } return Clazz; })();
7947
`;
8048
const output = tags.stripIndent`
81-
${emptyImportsComment}
8249
var Clazz = /*@__PURE__*/ (function () { function Clazz() { } return Clazz; }());
8350
var ClazzTwo = /*@__PURE__*/ (function () { function Clazz() { } return Clazz; })();
8451
`;
@@ -99,7 +66,6 @@ describe('prefix-functions', () => {
9966
};
10067
`;
10168
const output = tags.stripIndent`
102-
${emptyImportsComment}
10369
${input}
10470
`;
10571

@@ -118,7 +84,6 @@ describe('prefix-functions', () => {
11884
export { MyFunction };
11985
`;
12086
const output = tags.stripIndent`
121-
${emptyImportsComment}
12287
${input}
12388
`;
12489

@@ -137,7 +102,6 @@ describe('prefix-functions', () => {
137102
}
138103
`;
139104
const output = tags.stripIndent`
140-
${emptyImportsComment}
141105
${input}
142106
`;
143107

@@ -156,7 +120,6 @@ describe('prefix-functions', () => {
156120
};
157121
`;
158122
const output = tags.stripIndent`
159-
${emptyImportsComment}
160123
${input}
161124
`;
162125

@@ -172,7 +135,6 @@ describe('prefix-functions', () => {
172135
};
173136
`;
174137
const output = tags.stripIndent`
175-
${emptyImportsComment}
176138
${input}
177139
`;
178140

0 commit comments

Comments
 (0)