Skip to content

Commit 6598ca9

Browse files
committed
Type improvements on SCE. Typedoc fixes
1 parent 4a82031 commit 6598ca9

File tree

98 files changed

+2802
-123
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

98 files changed

+2802
-123
lines changed

src/angular.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ const moduleRegistry: ModuleRegistry = {};
4848
*/
4949
export class Angular extends EventTarget {
5050
public subapps: Angular[] = [];
51+
/** @internal */
5152
public _subapp: boolean;
53+
/** @internal */
5254
public _bootsrappedModules: Array<string | any> = [];
5355

5456
public $eventBus!: ng.PubSubService;

src/animations/interface.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,13 @@ export interface AnimationOptions {
4040
/** Optional completion callback (driver/queue dependent). */
4141
onDone?: () => void;
4242

43-
/** Internal flag: whether domOperation has fired. */
43+
/** @internal Internal flag: whether domOperation has fired. */
4444
_domOperationFired?: boolean;
4545

46-
/** Internal flag: whether preparation has been performed. */
46+
/** @internal Internal flag: whether preparation has been performed. */
4747
_prepared?: boolean;
4848

49-
/** Internal flag: skip preparation classes. */
49+
/** @internal Internal flag: skip preparation classes. */
5050
_skipPreparationClasses?: boolean;
5151

5252
/** Whether to clean up styles after animation completes. */
@@ -117,7 +117,7 @@ export interface AnimationOptions {
117117
* `end()` forces completion (may be synchronous depending on driver).
118118
*/
119119
export interface Animator {
120-
/** Whether this handle is expected to perform a real animation. */
120+
/** @internal Whether this handle is expected to perform a real animation. */
121121
_willAnimate: boolean;
122122

123123
/** Start the animation and return a runner you can control/cancel. */

src/animations/runner/animate-runner.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,15 @@ function schedule(fn: VoidFunction): void {
8585
}
8686

8787
export class AnimateRunner {
88+
/** @internal */
8889
_host: AnimationHost;
90+
/** @internal */
8991
_doneCallbacks: Array<(ok: boolean) => void>;
92+
/** @internal */
9093
_state: number;
94+
/** @internal */
9195
_promise: Promise<void> | null;
96+
/** @internal */
9297
_tick: (fn: VoidFunction) => void;
9398

9499
/**
@@ -256,6 +261,7 @@ export class AnimateRunner {
256261
// ---------------------------------------------------------------------------
257262

258263
/**
264+
* @internal
259265
* Executes a list of runners sequentially.
260266
* Each must complete before the next starts.
261267
*/
@@ -278,6 +284,7 @@ export class AnimateRunner {
278284
}
279285

280286
/**
287+
* @internal
281288
* Waits until all runners complete.
282289
*/
283290
static _all(runners: AnimateRunner[], callback: (ok: boolean) => void): void {

src/core/compile/compile.ts

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ import {
4141
simpleCompare,
4242
trim,
4343
} from "../../shared/utils.ts";
44-
import { SCE_CONTEXTS } from "../../services/sce/sce.ts";
44+
import { SCE_CONTEXTS, type SceContext } from "../../services/sce/sce.ts";
4545
import { PREFIX_REGEXP } from "../../shared/constants.ts";
4646
import {
4747
createEventDirective,
@@ -344,7 +344,7 @@ export interface TextInterpolateLinkState {
344344
export interface AttrInterpolateLinkState {
345345
_name: string;
346346
_value: string;
347-
_trustedContext?: string;
347+
_trustedContext?: SceContext;
348348
_allOrNothing: boolean;
349349
_interpolateFn?: InterpolationFunction;
350350
}
@@ -910,7 +910,14 @@ export class CompileProvider {
910910
/**
911911
* The security context of DOM Properties.
912912
*/
913-
const PROP_CONTEXTS = nullObject() as Record<string, string>;
913+
const PROP_CONTEXTS = nullObject() as Record<string, SceContext>;
914+
915+
const LEGACY_SCE_CONTEXTS: Record<string, SceContext> = {
916+
html: SCE_CONTEXTS._HTML,
917+
mediaUrl: SCE_CONTEXTS._MEDIA_URL,
918+
resourceUrl: SCE_CONTEXTS._RESOURCE_URL,
919+
url: SCE_CONTEXTS._URL,
920+
};
914921

915922
/**
916923
* Defines the security context for DOM properties bound by ng-prop-*.
@@ -925,20 +932,22 @@ export class CompileProvider {
925932
propertyName: string,
926933
ctx: string,
927934
) {
935+
const normalizedCtx = LEGACY_SCE_CONTEXTS[ctx] || ctx;
936+
928937
const key = `${elementName.toLowerCase()}|${propertyName.toLowerCase()}`;
929938

930-
if (key in PROP_CONTEXTS && PROP_CONTEXTS[key] !== ctx) {
939+
if (key in PROP_CONTEXTS && PROP_CONTEXTS[key] !== normalizedCtx) {
931940
throw $compileMinErr(
932941
"ctxoverride",
933942
"Property context '{0}.{1}' already set to '{2}', cannot override to '{3}'.",
934943
elementName,
935944
propertyName,
936945
PROP_CONTEXTS[key],
937-
ctx,
946+
normalizedCtx,
938947
);
939948
}
940949

941-
PROP_CONTEXTS[key] = ctx;
950+
PROP_CONTEXTS[key] = normalizedCtx as SceContext;
942951

943952
return this;
944953
};
@@ -953,18 +962,18 @@ export class CompileProvider {
953962
*/
954963
(function registerNativePropertyContexts() {
955964
/** Registers the same security context for a list of `element|property` keys. */
956-
function registerContext(ctx: string, items: string[]) {
965+
function registerContext(ctx: SceContext, items: string[]) {
957966
items.forEach((v) => {
958967
PROP_CONTEXTS[v.toLowerCase()] = ctx;
959968
});
960969
}
961970

962-
registerContext(SCE_CONTEXTS.HTML, [
971+
registerContext(SCE_CONTEXTS._HTML, [
963972
"iframe|srcdoc",
964973
"*|innerHTML",
965974
"*|outerHTML",
966975
]);
967-
registerContext(SCE_CONTEXTS.URL, [
976+
registerContext(SCE_CONTEXTS._URL, [
968977
"area|href",
969978
"area|ping",
970979
"a|href",
@@ -976,7 +985,7 @@ export class CompileProvider {
976985
"ins|cite",
977986
"q|cite",
978987
]);
979-
registerContext(SCE_CONTEXTS.MEDIA_URL, [
988+
registerContext(SCE_CONTEXTS._MEDIA_URL, [
980989
"audio|src",
981990
"img|src",
982991
"img|srcset",
@@ -986,7 +995,7 @@ export class CompileProvider {
986995
"video|src",
987996
"video|poster",
988997
]);
989-
registerContext(SCE_CONTEXTS.RESOURCE_URL, [
998+
registerContext(SCE_CONTEXTS._RESOURCE_URL, [
990999
"*|formAction",
9911000
"applet|code",
9921001
"applet|codebase",
@@ -3490,9 +3499,9 @@ export class CompileProvider {
34903499
function getTrustedAttrContext(
34913500
nodeName: string,
34923501
attrNormalizedName: string,
3493-
) {
3502+
): SceContext | undefined {
34943503
if (attrNormalizedName === "srcdoc") {
3495-
return $sce.HTML;
3504+
return SCE_CONTEXTS._HTML;
34963505
}
34973506

34983507
// All nodes with src attributes require a RESOURCE_URL value, except for
@@ -3502,30 +3511,30 @@ export class CompileProvider {
35023511
["img", "video", "audio", "source", "track"].indexOf(nodeName) ===
35033512
-1
35043513
) {
3505-
return $sce.RESOURCE_URL;
3514+
return SCE_CONTEXTS._RESOURCE_URL;
35063515
}
35073516

3508-
return $sce.MEDIA_URL;
3517+
return SCE_CONTEXTS._MEDIA_URL;
35093518
}
35103519

35113520
if (attrNormalizedName === "xlinkHref") {
35123521
// Some xlink:href are okay, most aren't
35133522
if (nodeName === "image") {
3514-
return $sce.MEDIA_URL;
3523+
return SCE_CONTEXTS._MEDIA_URL;
35153524
}
35163525

35173526
if (nodeName === "a") {
3518-
return $sce.URL;
3527+
return SCE_CONTEXTS._URL;
35193528
}
35203529

3521-
return $sce.RESOURCE_URL;
3530+
return SCE_CONTEXTS._RESOURCE_URL;
35223531
}
35233532

35243533
if (
35253534
nodeName === "image" &&
35263535
(attrNormalizedName === "href" || attrNormalizedName === "ngHref")
35273536
) {
3528-
return $sce.MEDIA_URL;
3537+
return SCE_CONTEXTS._MEDIA_URL;
35293538
}
35303539

35313540
if (
@@ -3537,14 +3546,14 @@ export class CompileProvider {
35373546
// links can be stylesheets or imports, which can run script in the current origin
35383547
(nodeName === "link" && attrNormalizedName === "href")
35393548
) {
3540-
return $sce.RESOURCE_URL;
3549+
return SCE_CONTEXTS._RESOURCE_URL;
35413550
}
35423551

35433552
if (
35443553
nodeName === "a" &&
35453554
(attrNormalizedName === "href" || attrNormalizedName === "ngHref")
35463555
) {
3547-
return $sce.URL;
3556+
return SCE_CONTEXTS._URL;
35483557
}
35493558

35503559
return undefined;
@@ -3554,7 +3563,7 @@ export class CompileProvider {
35543563
function getTrustedPropContext(
35553564
nodeName: string,
35563565
propNormalizedName: string,
3557-
) {
3566+
): SceContext | undefined {
35583567
const prop = propNormalizedName.toLowerCase();
35593568

35603569
return (

src/core/di/internal-injector.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,12 @@ const INSTANTIATING = true;
1919
type InjectableFn = Function | AnnotatedFactory<(...args: any[]) => any>;
2020

2121
class AbstractInjector {
22+
/** @internal */
2223
_cache: Record<string, any>;
2324
strictDi: boolean;
25+
/** @internal */
2426
_path: string[];
27+
/** @internal */
2528
_modules: Record<string, NgModule>;
2629

2730
/**
@@ -68,6 +71,7 @@ class AbstractInjector {
6871
}
6972

7073
/**
74+
* @internal
7175
* Get the injection arguments for a function.
7276
*
7377
* @param {Function|ng.AnnotatedFactory<any>} fn
@@ -179,6 +183,7 @@ class AbstractInjector {
179183
* @returns {any}
180184
*/
181185

186+
/** @internal */
182187
_factory(serviceName: string): any {
183188
void serviceName;
184189

@@ -200,6 +205,7 @@ export class ProviderInjector extends AbstractInjector {
200205
}
201206

202207
/**
208+
* @internal
203209
* Factory method for creating services.
204210
* @param {string} caller - The name of the caller requesting the service.
205211
* @throws {Error} If the provider is unknown.
@@ -225,6 +231,7 @@ export class InjectorService extends AbstractInjector {
225231
/* empty */
226232
};
227233

234+
/** @internal */
228235
_providerInjector: ProviderInjector;
229236

230237
/**
@@ -244,6 +251,7 @@ export class InjectorService extends AbstractInjector {
244251
* @param {string} serviceName
245252
* @returns {*}
246253
*/
254+
/** @internal */
247255
_factory(serviceName: string): any {
248256
const provider = this._providerInjector.get(serviceName + providerSuffix);
249257

src/core/filter/filter.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const SUFFIX = "Filter";
1616
export class FilterProvider {
1717
static $inject = [$t._provide];
1818

19+
/** @internal */
1920
_$provide: Provider;
2021
$get: [string, ($injector: ng.InjectorService) => FilterService];
2122

src/core/interpolate/interpolate.spec.js

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { createInjector } from "../di/injector.ts";
22
import { Angular } from "../../angular.ts";
33
import { wait } from "../../shared/test-utils.ts";
4+
import { SCE_CONTEXTS } from "../../services/sce/sce.ts";
45

56
describe("$interpolate", () => {
67
let $interpolate, $injector, $rootScope, $sce;
@@ -384,7 +385,7 @@ describe("$interpolate", () => {
384385
const scope = $rootScope.$new();
385386
scope.foo = "foo";
386387
await wait();
387-
$interpolate("{{foo}}", true, sce.HTML)(scope);
388+
$interpolate("{{foo}}", true, SCE_CONTEXTS._HTML)(scope);
388389
expect(errors[0]).toMatch("unsafe value");
389390
});
390391

@@ -395,7 +396,9 @@ describe("$interpolate", () => {
395396

396397
it("should interpolate trusted expressions in a specific trustedContext", () => {
397398
const foo = sce.trustAsHtml("foo");
398-
expect($interpolate("{{foo}}", true, sce.HTML)({ foo })).toBe("foo");
399+
expect($interpolate("{{foo}}", true, SCE_CONTEXTS._HTML)({ foo })).toBe(
400+
"foo",
401+
);
399402
});
400403

401404
// The concatenation of trusted values does not necessarily result in a trusted value. (For
@@ -405,7 +408,7 @@ describe("$interpolate", () => {
405408
const foo = sce.trustAsHtml("foo");
406409
const bar = sce.trustAsHtml("bar");
407410
expect(() =>
408-
$interpolate("{{foo}}{{bar}}", true, sce.HTML)({ foo, bar }),
411+
$interpolate("{{foo}}{{bar}}", true, SCE_CONTEXTS._HTML)({ foo, bar }),
409412
).toThrowError(/Error while interpolating/);
410413
});
411414
});
@@ -491,7 +494,7 @@ describe("$interpolate", () => {
491494

492495
describe("isTrustedContext", () => {
493496
it("should NOT interpolate a multi-part expression when isTrustedContext is RESOURCE_URL", () => {
494-
const isTrustedContext = $sce.RESOURCE_URL;
497+
const isTrustedContext = SCE_CONTEXTS._RESOURCE_URL;
495498
expect(() => {
496499
$interpolate("constant/{{var}}", true, isTrustedContext)("val");
497500
}).toThrowError(/Can't interpolate:/);
@@ -510,25 +513,42 @@ describe("$interpolate", () => {
510513
});
511514

512515
it("should interpolate a multi-part expression when isTrustedContext is URL", () => {
513-
expect($interpolate("some/{{id}}", true, $sce.URL)({})).toEqual("some/");
514-
expect($interpolate("some/{{id}}", true, $sce.URL)({ id: 1 })).toEqual(
515-
"some/1",
516+
expect($interpolate("some/{{id}}", true, SCE_CONTEXTS._URL)({})).toEqual(
517+
"some/",
516518
);
517519
expect(
518-
$interpolate("{{foo}}{{bar}}", true, $sce.URL)({ foo: 1, bar: 2 }),
520+
$interpolate("some/{{id}}", true, SCE_CONTEXTS._URL)({ id: 1 }),
521+
).toEqual("some/1");
522+
expect(
523+
$interpolate(
524+
"{{foo}}{{bar}}",
525+
true,
526+
SCE_CONTEXTS._URL,
527+
)({
528+
foo: 1,
529+
bar: 2,
530+
}),
519531
).toEqual("12");
520532
});
521533

522534
it("should interpolate and sanitize a multi-part expression when isTrustedContext is URL", () => {
523-
expect($interpolate("some/{{id}}", true, $sce.URL)({})).toEqual("some/");
535+
expect($interpolate("some/{{id}}", true, SCE_CONTEXTS._URL)({})).toEqual(
536+
"some/",
537+
);
524538
expect(
525-
$interpolate("some/{{id}}", true, $sce.URL)({ id: "javascript:" }),
539+
$interpolate(
540+
"some/{{id}}",
541+
true,
542+
SCE_CONTEXTS._URL,
543+
)({
544+
id: "javascript:",
545+
}),
526546
).toEqual("some/javascript:");
527547
expect(
528548
$interpolate(
529549
"{{foo}}{{bar}}",
530550
true,
531-
$sce.URL,
551+
SCE_CONTEXTS._URL,
532552
)({ foo: "javascript:", bar: "javascript:" }),
533553
).toEqual("unsafe:javascript:javascript:");
534554
});

0 commit comments

Comments
 (0)