Skip to content

Commit 3862d3b

Browse files
author
Anatoly Ostrovsky
committed
Optimizations for mangling
1 parent ed8d073 commit 3862d3b

File tree

24 files changed

+105
-130
lines changed

24 files changed

+105
-130
lines changed

@types/angular.d.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
export class Angular {
2-
/** @public */
3-
public $cache: Map<number, import("./interface.ts").ExpandoStore>;
2+
_$cache: Map<number, import("./interface.ts").ExpandoStore>;
43
/** @public @type {ng.PubSubService} */
54
public $eventBus: ng.PubSubService;
65
/**
6+
* @public
77
* @type {string} `version` from `package.json`
88
*/
9-
version: string;
9+
public version: string;
1010
/** @type {!Array<string|any>} */
11-
bootsrappedModules: Array<string | any>;
11+
_bootsrappedModules: Array<string | any>;
1212
/**
1313
* Gets the controller instance for a given element, if exists. Defaults to "ngControllerController"
1414
*

@types/core/parse/interpreter.d.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@ export class ASTInterpreter {
1010
* @param {function(any):any} $filter
1111
*/
1212
constructor($filter: (arg0: any) => any);
13-
$filter: (arg0: any) => any;
13+
_$filter: (arg0: any) => any;
1414
/**
1515
* Compiles the AST into a function.
16-
* @param {import("./ast/ast").ASTNode} ast - The AST to compile.
16+
* @param {import("./ast/ast.js").ASTNode} ast - The AST to compile.
1717
* @returns {import("./interface.ts").CompiledExpression}
1818
*/
19-
compile(ast: any): import("./interface.ts").CompiledExpression;
19+
compile(
20+
ast: import("./ast/ast.js").ASTNode,
21+
): import("./interface.ts").CompiledExpression;
2022
/**
2123
* Unary plus operation.
2224
* @param {function} argument - The argument function.

@types/router/glob/glob.d.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,11 @@ export class Glob {
6464
/**
6565
* @type {string}
6666
*/
67-
text: string;
68-
/**
69-
* @type {string[]}
70-
*/
71-
glob: string[];
67+
_text: string;
7268
/**
7369
* @type {RegExp}
7470
*/
75-
regexp: RegExp;
71+
_regexp: RegExp;
7672
/**
7773
* @param {string} name
7874
* @return {boolean}

@types/router/router.d.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,31 +12,33 @@ export class Router {
1212
* The parameter values from the latest successful transition
1313
* @type {StateParams}
1414
*/
15-
params: StateParams;
15+
_params: StateParams;
1616
/**
1717
* @type {number}
1818
*/
19-
lastStartedTransitionId: number;
19+
_lastStartedTransitionId: number;
2020
/**
2121
* @type {Queue<import("./transition/transition.js").Transition>}
2222
*/
23-
transitionHistory: Queue<import("./transition/transition.js").Transition>;
23+
_transitionHistory: Queue<import("./transition/transition.js").Transition>;
2424
/**
2525
* @type {Queue<import("./transition/transition.js").Transition>}
2626
*/
27-
successfulTransitions: Queue<import("./transition/transition.js").Transition>;
27+
_successfulTransitions: Queue<
28+
import("./transition/transition.js").Transition
29+
>;
2830
/**
2931
* @type {import("./state/interface.ts").StateDeclaration|undefined}
3032
*/
31-
current: import("./state/interface.ts").StateDeclaration | undefined;
33+
_current: import("./state/interface.ts").StateDeclaration | undefined;
3234
/**
3335
* @type {import("./state/state-object.js").StateObject|undefined}
3436
*/
35-
$current: import("./state/state-object.js").StateObject | undefined;
37+
_$current: import("./state/state-object.js").StateObject | undefined;
3638
/**
3739
* @type {import("./transition/transition.js").Transition|undefined}
3840
*/
39-
transition: import("./transition/transition.js").Transition | undefined;
41+
_transition: import("./transition/transition.js").Transition | undefined;
4042
$get: () => this;
4143
}
4244
/**

@types/router/transition/transition.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ export class Transition implements IHookRegistry {
2828
/**
2929
* @type {import('../router.js').Router}
3030
*/
31-
globals: import("../router.js").Router;
32-
transitionService: import("../transition/transition-service.js").TransitionProvider;
31+
_globals: import("../router.js").Router;
32+
_transitionService: import("../transition/transition-service.js").TransitionProvider;
3333
_deferred: any;
3434
/**
3535
* This promise is resolved or rejected based on the outcome of the Transition.

@types/router/view/view.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ export class ViewService {
1111
context: import("../state/state-object.js").StateObject | null,
1212
): import("../state/state-object.js").StateObject | null;
1313
_rootContext: any;
14-
viewConfigFactory(factory: any): void;
14+
_viewConfigFactory(factory: any): void;
1515
/**
1616
* @param path
1717
* @param decl
1818
* @return {import("../state/views.js").ViewConfig}
1919
*/
20-
createViewConfig(
20+
_createViewConfig(
2121
path: any,
2222
decl: any,
2323
): import("../state/views.js").ViewConfig;

@types/shared/utils.d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,6 @@ export function encodeUriSegment(val: string): string;
426426
* / "*" / "+" / "," / ";" / "="
427427
*/
428428
export function encodeUriQuery(val: any, pctEncodeSpaces: any): string;
429-
export function getNgAttribute(element: any, ngAttr: any): any;
430429
/**
431430
* Creates a shallow copy of an object, an array or a primitive.
432431
*

src/angular.js

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import {
22
assertNotHasOwnProperty,
33
errorHandlingConfig,
4-
getNgAttribute,
54
hasOwn,
65
isArray,
76
minErr,
@@ -26,24 +25,27 @@ const ngMinErr = minErr("ng");
2625

2726
const $injectorMinErr = minErr("$injector");
2827

28+
const STRICT_DI = "strict-di";
29+
2930
/** @type {Object.<string, NgModule>} */
3031
const moduleRegistry = {};
3132

3233
export class Angular {
3334
constructor() {
34-
/** @public */
35-
this.$cache = Cache;
35+
/* @ignore */
36+
this._$cache = Cache;
3637

3738
/** @public @type {ng.PubSubService} */
3839
this.$eventBus = EventBus;
3940

4041
/**
42+
* @public
4143
* @type {string} `version` from `package.json`
4244
*/
4345
this.version = "[VI]{version}[/VI]"; //inserted via rollup plugin
4446

4547
/** @type {!Array<string|any>} */
46-
this.bootsrappedModules = [];
48+
this._bootsrappedModules = [];
4749

4850
/**
4951
* Gets the controller instance for a given element, if exists. Defaults to "ngControllerController"
@@ -194,10 +196,10 @@ export class Angular {
194196
}
195197

196198
if (isArray(modules)) {
197-
this.bootsrappedModules = modules;
199+
this._bootsrappedModules = modules;
198200
}
199201

200-
this.bootsrappedModules.unshift([
202+
this._bootsrappedModules.unshift([
201203
"$provide",
202204
/**
203205
* @param {import('./interface.ts').Provider} $provide
@@ -207,9 +209,9 @@ export class Angular {
207209
},
208210
]);
209211

210-
this.bootsrappedModules.unshift("ng");
212+
this._bootsrappedModules.unshift("ng");
211213

212-
const injector = createInjector(this.bootsrappedModules, config.strictDi);
214+
const injector = createInjector(this._bootsrappedModules, config.strictDi);
213215

214216
injector.invoke([
215217
$t.$rootScope,
@@ -278,6 +280,7 @@ export class Angular {
278280
* @param {Element|Document} element
279281
*/
280282
init(element) {
283+
/** @type {Element} */
281284
let appElement;
282285

283286
let module;
@@ -292,12 +295,9 @@ export class Angular {
292295
/** @type {Element} */ (element).hasAttribute &&
293296
/** @type {Element} */ (element).hasAttribute(name)
294297
) {
295-
appElement = element;
298+
appElement = /** @type {Element} */ (element);
296299
module = /** @type {Element} */ (element).getAttribute(name);
297300
}
298-
});
299-
ngAttrPrefixes.forEach((prefix) => {
300-
const name = `${prefix}app`;
301301

302302
let candidate;
303303

@@ -311,7 +311,9 @@ export class Angular {
311311
});
312312

313313
if (appElement) {
314-
config.strictDi = getNgAttribute(appElement, "strict-di") !== null;
314+
config.strictDi =
315+
appElement.hasAttribute(STRICT_DI) ||
316+
appElement.hasAttribute(`data-${STRICT_DI}`);
315317
this.bootstrap(appElement, module ? [module] : [], config);
316318
}
317319
}

src/core/parse/ast/ast.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -127,15 +127,11 @@ export class AST {
127127
_ternary() {
128128
const test = this._logicalOR();
129129

130-
let alternate;
131-
132-
let consequent;
133-
134130
if (this._expect("?")) {
135-
alternate = this._assignment();
131+
const alternate = this._assignment();
136132

137133
if (this._consume(":")) {
138-
consequent = this._assignment();
134+
const consequent = this._assignment();
139135

140136
return {
141137
type: ASTType._ConditionalExpression,

src/core/parse/interpreter.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,24 @@ export class ASTInterpreter {
1616
* @param {function(any):any} $filter
1717
*/
1818
constructor($filter) {
19-
this.$filter = $filter;
19+
this._$filter = $filter;
2020
}
2121

2222
/**
2323
* Compiles the AST into a function.
24-
* @param {import("./ast/ast").ASTNode} ast - The AST to compile.
24+
* @param {import("./ast/ast.js").ASTNode} ast - The AST to compile.
2525
* @returns {import("./interface.ts").CompiledExpression}
2626
*/
2727
compile(ast) {
28-
const decoratedNode = findConstantAndWatchExpressions(ast, this.$filter);
28+
const decoratedNode = findConstantAndWatchExpressions(ast, this._$filter);
2929

30-
/** @type {import("./ast/ast").ASTNode} */
31-
let assignable;
30+
/** @type {import("./ast/ast.js").ASTNode} */
31+
const assignable = assignableAST(decoratedNode);
3232

3333
/** @type {import("./interface.ts").CompiledExpression} */
3434
let assign;
3535

36-
if ((assignable = assignableAST(decoratedNode))) {
36+
if (assignable) {
3737
assign = /** @type {import("./interface.ts").CompiledExpression} */ (
3838
this.#recurse(assignable)
3939
);
@@ -167,7 +167,7 @@ export class ASTInterpreter {
167167
args.push(self.#recurse(expr));
168168
});
169169

170-
if (ast.filter) right = this.$filter(ast.callee.name);
170+
if (ast.filter) right = this._$filter(ast.callee.name);
171171

172172
if (!ast.filter) right = this.#recurse(ast.callee, true);
173173

0 commit comments

Comments
 (0)