Skip to content

Commit 325704e

Browse files
committed
Additional mangle optimizations
1 parent a0740a7 commit 325704e

File tree

26 files changed

+178
-122
lines changed

26 files changed

+178
-122
lines changed

@types/core/filter/filter.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export class FilterProvider {
1010
* @param {ng.ProvideService} $provide
1111
*/
1212
constructor($provide: ng.ProvideService);
13-
$provide: import("../../interface.ts").Provider;
13+
_$provide: import("../../interface.ts").Provider;
1414
/**
1515
* Register a filter a config phase;
1616
* @param {string} name

@types/services/rest/rest.d.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ export class RestService<T, ID> {
1919
options?: any,
2020
);
2121
/** @private */
22-
private $http;
22+
private _$http;
2323
/** @private */
24-
private baseUrl;
24+
private _baseUrl;
2525
/** @private */
26-
private entityClass;
26+
private _entityClass;
2727
/** @private */
28-
private options;
28+
private _options;
2929
/**
3030
* Build full URL from template and parameters
3131
* @param {string} template
@@ -72,7 +72,7 @@ export class RestService<T, ID> {
7272
*/
7373
export class RestProvider {
7474
/** @private @type {ng.RestDefinition<any>[]} */
75-
private definitions;
75+
private _definitions;
7676
/**
7777
* Register a REST resource at config phase
7878
* @template T

@types/services/sse/sse.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ export class SseProvider {
1818
*/
1919
defaults: ng.SseConfig;
2020
$get: (string | ((log: ng.LogService) => ng.SseService))[];
21-
$log: import("../log/interface.ts").LogService;
21+
_$log: import("../log/interface.ts").LogService;
2222
#private;
2323
}

@types/shared/utils.d.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,18 @@ export function hasOwn(obj: object, key: string | number | symbol): boolean;
549549
* @returns {string[]}
550550
*/
551551
export function keys(obj: any): string[];
552+
/**
553+
* @template T
554+
* @param {{ [s: string]: T; } | ArrayLike<T>} obj
555+
* @returns {[string, T][]}
556+
*/
557+
export function entries<T>(
558+
obj:
559+
| {
560+
[s: string]: T;
561+
}
562+
| ArrayLike<T>,
563+
): [string, T][];
552564
/**
553565
* Wraps a function so it can only be called once.
554566
* Subsequent calls do nothing and return undefined.

src/animations/animate-css.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,13 @@ import {
33
removeElementData,
44
setCacheData,
55
} from "../shared/dom.js";
6-
import { isArray, isDefined, isNullOrUndefined } from "../shared/utils.js";
6+
import {
7+
entries,
8+
isArray,
9+
isDefined,
10+
isNullOrUndefined,
11+
keys,
12+
} from "../shared/utils.js";
713
import { AnimateRunner } from "./runner/animate-runner.js";
814
import {
915
ACTIVE_CLASS_SUFFIX,
@@ -76,7 +82,7 @@ function computeCssStyles(element, properties) {
7682

7783
const detectedStyles = window.getComputedStyle(element) || {};
7884

79-
Object.entries(properties).forEach(([actualStyleName, formalStyleName]) => {
85+
entries(properties).forEach(([actualStyleName, formalStyleName]) => {
8086
let val = detectedStyles[formalStyleName];
8187

8288
if (val) {
@@ -655,8 +661,8 @@ export function AnimateCssProvider() {
655661
applyAnimationClasses(element, options);
656662
applyAnimationStyles(element, options);
657663

658-
if (Object.keys(restoreStyles).length) {
659-
Object.entries(restoreStyles).forEach(([prop, value]) => {
664+
if (keys(restoreStyles).length) {
665+
entries(restoreStyles).forEach(([prop, value]) => {
660666
if (value) {
661667
node.style.setProperty(prop, value);
662668
} else {

src/animations/shared.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
import { extend, isArray, isString, minErr } from "../shared/utils.js";
1+
import {
2+
entries,
3+
extend,
4+
isArray,
5+
isString,
6+
keys,
7+
minErr,
8+
} from "../shared/utils.js";
29
import { ASTType } from "../core/parse/ast-type.js";
310
import { NodeType } from "../shared/dom.js";
411

@@ -282,7 +289,7 @@ export function resolveElementClasses(existing, toAdd, toRemove) {
282289
});
283290

284291
toRemove = splitClassesToLookup(toRemove);
285-
Object.keys(toRemove).forEach((key) => {
292+
keys(toRemove).forEach((key) => {
286293
flags[key] = flags[key] === ADD_CLASS ? null : REMOVE_CLASS;
287294
});
288295

@@ -291,7 +298,7 @@ export function resolveElementClasses(existing, toAdd, toRemove) {
291298
removeClass: "",
292299
};
293300

294-
Object.entries(flags).forEach(([klass, val]) => {
301+
entries(flags).forEach(([klass, val]) => {
295302
let prop, allow;
296303

297304
if (val === ADD_CLASS) {

src/core/compile/compile.js

Lines changed: 35 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
getCacheData,
77
getInheritedData,
88
isTextNode,
9+
NodeType,
910
setCacheData,
1011
setIsolateScope,
1112
setScope,
@@ -18,6 +19,7 @@ import {
1819
assertNotHasOwnProperty,
1920
bind,
2021
directiveNormalize,
22+
entries,
2123
equals,
2224
extend,
2325
getNodeName,
@@ -87,7 +89,7 @@ export class CompileProvider {
8789

8890
const bindings = Object.create(null);
8991

90-
Object.entries(scope).forEach(([scopeName, definition]) => {
92+
entries(scope).forEach(([scopeName, definition]) => {
9193
definition = definition.trim();
9294

9395
if (definition in bindingCache) {
@@ -174,10 +176,10 @@ export class CompileProvider {
174176
directive.require || (directive.controller && directive.name);
175177

176178
if (!isArray(require) && isObject(require)) {
177-
const entries = Object.entries(require);
179+
const entryList = entries(require);
178180

179-
for (let i = 0, len = entries.length; i < len; i++) {
180-
const [key, value] = entries[i];
181+
for (let i = 0, len = entryList.length; i < len; i++) {
182+
const [key, value] = entryList[i];
181183

182184
const match = value.match(REQUIRE_PREFIX_REGEXP);
183185

@@ -271,7 +273,7 @@ export class CompileProvider {
271273
}
272274
hasDirectives[name].push(directiveFactory);
273275
} else {
274-
Object.entries(name).forEach(([k, v]) => registerDirective(k, v));
276+
entries(name).forEach(([k, v]) => registerDirective(k, v));
275277
}
276278

277279
return this;
@@ -323,7 +325,7 @@ export class CompileProvider {
323325
*/
324326
this.component = function (name, options) {
325327
if (!isString(name)) {
326-
Object.entries(name).forEach(([key, val]) => this.component(key, val));
328+
entries(name).forEach(([key, val]) => this.component(key, val));
327329

328330
return this;
329331
}
@@ -368,7 +370,7 @@ export class CompileProvider {
368370
};
369371

370372
// Copy annotations (starting with $) over to the DDO
371-
Object.entries(options).forEach(([key, val]) => {
373+
entries(options).forEach(([key, val]) => {
372374
if (key.charAt(0) === "$") {
373375
ddo[key] = val;
374376
}
@@ -379,7 +381,7 @@ export class CompileProvider {
379381

380382
// Copy any annotation properties (starting with $) over to the factory and controller constructor functions
381383
// These could be used by libraries such as the new component router
382-
Object.entries(options).forEach(([key, val]) => {
384+
entries(options).forEach(([key, val]) => {
383385
if (key.charAt(0) === "$") {
384386
factory[key] = val;
385387

@@ -1056,7 +1058,7 @@ export class CompileProvider {
10561058
let nodeName;
10571059

10581060
switch (nodeType) {
1059-
case 1 /* Element */:
1061+
case NodeType._ELEMENT_NODE /* Element */:
10601062
nodeName = node.nodeName.toLowerCase();
10611063

10621064
if (ignoreDirective !== directiveNormalize(nodeName)) {
@@ -1174,7 +1176,7 @@ export class CompileProvider {
11741176
}
11751177

11761178
break;
1177-
case Node.TEXT_NODE:
1179+
case NodeType._TEXT_NODE:
11781180
addTextInterpolateDirective(directives, node.nodeValue);
11791181
break;
11801182
default:
@@ -1438,7 +1440,7 @@ export class CompileProvider {
14381440

14391441
// Bind the required controllers to the controller, if `require` is an object and `bindToController` is truthy
14401442
if (controllerDirectives) {
1441-
Object.entries(controllerDirectives).forEach(
1443+
entries(controllerDirectives).forEach(
14421444
([name, controllerDirective]) => {
14431445
const { require } = controllerDirective;
14441446

@@ -1817,7 +1819,7 @@ export class CompileProvider {
18171819
const filledSlots = Object.create(null);
18181820

18191821
// Parse the element selectors
1820-
Object.entries(directiveValue).forEach(
1822+
entries(directiveValue).forEach(
18211823
([slotName, elementSelector]) => {
18221824
// If an element selector starts with a ? then it is optional
18231825
const optional = elementSelector.charAt(0) === "?";
@@ -1859,7 +1861,7 @@ export class CompileProvider {
18591861
});
18601862

18611863
// Check for required slots that were not filled
1862-
Object.entries(filledSlots).forEach(([slotName, filled]) => {
1864+
entries(filledSlots).forEach(([slotName, filled]) => {
18631865
if (!filled) {
18641866
throw $compileMinErr(
18651867
"reqslot",
@@ -1937,11 +1939,14 @@ export class CompileProvider {
19371939
if (isString($template)) {
19381940
$template = Array.from(
19391941
createNodelistFromHTML($template),
1940-
).filter((x) => x.nodeType === 1);
1942+
).filter((x) => x.nodeType === NodeType._ELEMENT_NODE);
19411943
}
19421944
compileNode = $template[0];
19431945

1944-
if ($template.length !== 1 || compileNode.nodeType !== 1) {
1946+
if (
1947+
$template.length !== 1 ||
1948+
compileNode.nodeType !== NodeType._ELEMENT_NODE
1949+
) {
19451950
throw $compileMinErr(
19461951
"tplrt",
19471952
"Template for directive '{0}' must have exactly one root element. {1}",
@@ -2150,7 +2155,7 @@ export class CompileProvider {
21502155
if (
21512156
inheritType === "^^" &&
21522157
$element &&
2153-
$element.nodeType === Node.DOCUMENT_NODE
2158+
$element.nodeType === NodeType._DOCUMENT_NODE
21542159
) {
21552160
// inheritedData() uses the documentElement when it finds the document, so we would
21562161
// require from the element itself.
@@ -2185,7 +2190,7 @@ export class CompileProvider {
21852190
}
21862191
} else if (isObject(require)) {
21872192
value = {};
2188-
Object.entries(require).forEach(([property, controller]) => {
2193+
entries(require).forEach(([property, controller]) => {
21892194
value[property] = getControllers(
21902195
directiveName,
21912196
controller,
@@ -2341,7 +2346,7 @@ export class CompileProvider {
23412346
const dstAttr = dst.$attr;
23422347

23432348
// reapply the old attributes to the new element
2344-
Object.entries(dst).forEach(([key, value]) => {
2349+
entries(dst).forEach(([key, value]) => {
23452350
if (key.charAt(0) !== "$") {
23462351
if (src[key] && src[key] !== value) {
23472352
if (value.length) {
@@ -2355,7 +2360,7 @@ export class CompileProvider {
23552360
});
23562361

23572362
// copy the new attributes on the old attrs object
2358-
Object.entries(src).forEach(([key, value]) => {
2363+
entries(src).forEach(([key, value]) => {
23592364
// Check if we already set this attribute in the loop above.
23602365
// `dst` will never contain hasOwnProperty as DOM parser won't let it.
23612366
// You will get an "InvalidCharacterError: DOM Exception 5" error if you
@@ -2451,8 +2456,8 @@ export class CompileProvider {
24512456
createNodelistFromHTML(content),
24522457
).filter(
24532458
(node) =>
2454-
node.nodeType !== Node.COMMENT_NODE &&
2455-
node.nodeType !== Node.TEXT_NODE,
2459+
node.nodeType !== NodeType._COMMENT_NODE &&
2460+
node.nodeType !== NodeType._TEXT_NODE,
24562461
);
24572462
} else {
24582463
$template = removeComments(
@@ -2461,7 +2466,10 @@ export class CompileProvider {
24612466
}
24622467
compileNode = $template[0];
24632468

2464-
if ($template.length !== 1 || compileNode.nodeType !== 1) {
2469+
if (
2470+
$template.length !== 1 ||
2471+
compileNode.nodeType !== NodeType._ELEMENT_NODE
2472+
) {
24652473
throw $compileMinErr(
24662474
"tplrt",
24672475
"Template for directive '{0}' must have exactly one root element. {1}",
@@ -2513,7 +2521,7 @@ export class CompileProvider {
25132521
afterTemplateNodeLinkFn = afterTemplateNodeLinkFnCtx?.nodeLinkFn;
25142522

25152523
if ($rootElement) {
2516-
Object.entries($rootElement).forEach(([i, node]) => {
2524+
entries($rootElement).forEach(([i, node]) => {
25172525
if (node === compileNode) {
25182526
$rootElement[i] = $compileNode;
25192527
}
@@ -3091,7 +3099,7 @@ export class CompileProvider {
30913099
let changes;
30923100

30933101
if (bindings) {
3094-
Object.entries(bindings).forEach(([scopeName, definition]) => {
3102+
entries(bindings).forEach(([scopeName, definition]) => {
30953103
const {
30963104
attrName,
30973105
optional,
@@ -3273,7 +3281,7 @@ export class CompileProvider {
32733281
} else {
32743282
// manually set the handler to avoid watch cycles
32753283
if (isObject(val)) {
3276-
Object.entries(val).forEach(([key, value]) => {
3284+
entries(val).forEach(([key, value]) => {
32773285
scope.$target[key] = value;
32783286
});
32793287
} else {
@@ -3424,8 +3432,8 @@ function removeComments(jqNodes) {
34243432
const node = jqNodes[i];
34253433

34263434
if (
3427-
node.nodeType === Node.COMMENT_NODE ||
3428-
(node.nodeType === Node.TEXT_NODE && node.nodeValue.trim() === "")
3435+
node.nodeType === NodeType._COMMENT_NODE ||
3436+
(node.nodeType === NodeType._TEXT_NODE && node.nodeValue.trim() === "")
34293437
) {
34303438
[].splice.call(jqNodes, i, 1);
34313439
}

src/core/controller/controller.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {
22
assertArgFn,
33
assertNotHasOwnProperty,
4+
entries,
45
isArray,
56
isFunction,
67
isObject,
@@ -62,7 +63,7 @@ export class ControllerProvider {
6263
assertNotHasOwnProperty(name, "controller");
6364

6465
if (isObject(name)) {
65-
Object.entries(name).forEach(([key, value]) => {
66+
entries(name).forEach(([key, value]) => {
6667
this.controllers.set(key, value);
6768
});
6869
} else {

src/core/di/injector.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {
22
assert,
33
assertArgFn,
44
assertNotHasOwnProperty,
5+
entries,
56
isArray,
67
isFunction,
78
isNullOrUndefined,
@@ -341,7 +342,7 @@ export function createInjector(modulesToLoad, strictDi = false) {
341342
function supportObject(delegate) {
342343
return function (key, value) {
343344
if (isObject(key)) {
344-
Object.entries(key).forEach(([k, v]) => {
345+
entries(key).forEach(([k, v]) => {
345346
delegate(k, v);
346347
});
347348

0 commit comments

Comments
 (0)