Skip to content

Commit 33f5b60

Browse files
alan-agius4filipesilva
authored andcommitted
refactor(@angular-devkit/build-angular): remove target parameter from BuildBrowserFeatures ctor
1 parent 86e4201 commit 33f5b60

File tree

2 files changed

+16
-41
lines changed

2 files changed

+16
-41
lines changed

packages/angular_devkit/build_angular/src/utils/build-browser-features.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,22 @@ import { feature, features } from 'caniuse-lite';
1111
import * as ts from 'typescript';
1212

1313
export class BuildBrowserFeatures {
14-
private readonly _es6TargetOrLater: boolean;
1514
readonly supportedBrowsers: string[];
1615

1716
constructor(
1817
private projectRoot: string,
19-
private scriptTarget: ts.ScriptTarget,
2018
) {
2119
this.supportedBrowsers = browserslist(undefined, { path: this.projectRoot });
22-
this._es6TargetOrLater = this.scriptTarget > ts.ScriptTarget.ES5;
2320
}
2421

2522
/**
2623
* True, when one or more browsers requires ES5
2724
* support and the scirpt target is ES2015 or greater.
2825
*/
29-
isDifferentialLoadingNeeded(): boolean {
30-
return this._es6TargetOrLater && this.isEs5SupportNeeded();
26+
isDifferentialLoadingNeeded(scriptTarget: ts.ScriptTarget): boolean {
27+
const es6TargetOrLater = scriptTarget > ts.ScriptTarget.ES5;
28+
29+
return es6TargetOrLater && this.isEs5SupportNeeded();
3130
}
3231

3332
/**

packages/angular_devkit/build_angular/src/utils/build-browser-features_spec.ts

Lines changed: 12 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -30,47 +30,35 @@ describe('BuildBrowserFeatures', () => {
3030
'.browserslistrc': 'IE 9-11',
3131
});
3232

33-
const buildBrowserFeatures = new BuildBrowserFeatures(
34-
workspaceRootSysPath,
35-
ScriptTarget.ES2015,
36-
);
37-
expect(buildBrowserFeatures.isDifferentialLoadingNeeded()).toBe(true);
33+
const buildBrowserFeatures = new BuildBrowserFeatures(workspaceRootSysPath);
34+
expect(buildBrowserFeatures.isDifferentialLoadingNeeded(ScriptTarget.ES2015)).toBe(true);
3835
});
3936

4037
it('should be false for Chrome and ES2015', () => {
4138
host.writeMultipleFiles({
4239
'.browserslistrc': 'last 1 chrome version',
4340
});
4441

45-
const buildBrowserFeatures = new BuildBrowserFeatures(
46-
workspaceRootSysPath,
47-
ScriptTarget.ES2015,
48-
);
49-
expect(buildBrowserFeatures.isDifferentialLoadingNeeded()).toBe(false);
42+
const buildBrowserFeatures = new BuildBrowserFeatures(workspaceRootSysPath);
43+
expect(buildBrowserFeatures.isDifferentialLoadingNeeded(ScriptTarget.ES2015)).toBe(false);
5044
});
5145

5246
it('detects no need for differential loading for target is ES5', () => {
5347
host.writeMultipleFiles({
5448
'.browserslistrc': 'last 1 chrome version',
5549
});
5650

57-
const buildBrowserFeatures = new BuildBrowserFeatures(
58-
workspaceRootSysPath,
59-
ScriptTarget.ES5,
60-
);
61-
expect(buildBrowserFeatures.isDifferentialLoadingNeeded()).toBe(false);
51+
const buildBrowserFeatures = new BuildBrowserFeatures(workspaceRootSysPath);
52+
expect(buildBrowserFeatures.isDifferentialLoadingNeeded(ScriptTarget.ES5)).toBe(false);
6253
});
6354

6455
it('should be false for Safari 10.1 when target is ES2015', () => {
6556
host.writeMultipleFiles({
6657
'.browserslistrc': 'Safari 10.1',
6758
});
6859

69-
const buildBrowserFeatures = new BuildBrowserFeatures(
70-
workspaceRootSysPath,
71-
ScriptTarget.ES2015,
72-
);
73-
expect(buildBrowserFeatures.isDifferentialLoadingNeeded()).toBe(false);
60+
const buildBrowserFeatures = new BuildBrowserFeatures(workspaceRootSysPath);
61+
expect(buildBrowserFeatures.isDifferentialLoadingNeeded(ScriptTarget.ES2015)).toBe(false);
7462
});
7563
});
7664

@@ -80,10 +68,7 @@ describe('BuildBrowserFeatures', () => {
8068
'.browserslistrc': 'Safari 10.1',
8169
});
8270

83-
const buildBrowserFeatures = new BuildBrowserFeatures(
84-
workspaceRootSysPath,
85-
ScriptTarget.ES2015,
86-
);
71+
const buildBrowserFeatures = new BuildBrowserFeatures(workspaceRootSysPath);
8772
expect(buildBrowserFeatures.isFeatureSupported('es6-module')).toBe(true);
8873
});
8974

@@ -92,10 +77,7 @@ describe('BuildBrowserFeatures', () => {
9277
'.browserslistrc': 'IE 9',
9378
});
9479

95-
const buildBrowserFeatures = new BuildBrowserFeatures(
96-
workspaceRootSysPath,
97-
ScriptTarget.ES2015,
98-
);
80+
const buildBrowserFeatures = new BuildBrowserFeatures(workspaceRootSysPath);
9981
expect(buildBrowserFeatures.isFeatureSupported('es6-module')).toBe(false);
10082
});
10183

@@ -104,10 +86,7 @@ describe('BuildBrowserFeatures', () => {
10486
'.browserslistrc': 'last 1 chrome version',
10587
});
10688

107-
const buildBrowserFeatures = new BuildBrowserFeatures(
108-
workspaceRootSysPath,
109-
ScriptTarget.ES2015,
110-
);
89+
const buildBrowserFeatures = new BuildBrowserFeatures(workspaceRootSysPath);
11190
expect(buildBrowserFeatures.isFeatureSupported('es6-module')).toBe(true);
11291
});
11392

@@ -116,10 +95,7 @@ describe('BuildBrowserFeatures', () => {
11695
'.browserslistrc': 'Edge 18',
11796
});
11897

119-
const buildBrowserFeatures = new BuildBrowserFeatures(
120-
workspaceRootSysPath,
121-
ScriptTarget.ES2015,
122-
);
98+
const buildBrowserFeatures = new BuildBrowserFeatures(workspaceRootSysPath);
12399
expect(buildBrowserFeatures.isFeatureSupported('es6-module')).toBe(true);
124100
});
125101
});

0 commit comments

Comments
 (0)