fix(core): mark Trusted Types as declarations (#39471)
Angular-internal type definitions for Trusted Types were added in #39211. When compiled using the Closure compiler with certain optimization flags, identifiers from these type definitions (such as createPolicy) are currently uglified and renamed to shorter strings. This causes Angular applications compiled in this way to fail to create a Trusted Types policy, and fall bock to using strings. To fix this, mark the internal Trusted Types definitions as declarations using the "declare" keyword. Also convert types to interfaces, for the reasons explained in https://ncjamieson.com/prefer-interfaces/ PR Close #39471
This commit is contained in:
parent
8af32fcb16
commit
f54662e931
|
@ -28,24 +28,25 @@ import {global} from '../util';
|
||||||
* will keep Angular's public API surface free of references to Trusted Types.
|
* will keep Angular's public API surface free of references to Trusted Types.
|
||||||
* For internal and semi-private APIs that need to reference Trusted Types, the
|
* For internal and semi-private APIs that need to reference Trusted Types, the
|
||||||
* minimal type definitions for the Trusted Types API provided by this module
|
* minimal type definitions for the Trusted Types API provided by this module
|
||||||
* should be used instead.
|
* should be used instead. They are marked as "declare" to prevent them from
|
||||||
|
* being renamed by compiler optimization.
|
||||||
*
|
*
|
||||||
* Adapted from
|
* Adapted from
|
||||||
* https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/trusted-types/index.d.ts
|
* https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/trusted-types/index.d.ts
|
||||||
* but restricted to the API surface used within Angular.
|
* but restricted to the API surface used within Angular.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export type TrustedScript = {
|
export declare interface TrustedScript {
|
||||||
__brand__: 'TrustedScript'
|
__brand__: 'TrustedScript';
|
||||||
};
|
}
|
||||||
|
|
||||||
export interface TrustedTypePolicyFactory {
|
export declare interface TrustedTypePolicyFactory {
|
||||||
createPolicy(policyName: string, policyOptions: {
|
createPolicy(policyName: string, policyOptions: {
|
||||||
createScript?: (input: string) => string,
|
createScript?: (input: string) => string,
|
||||||
}): TrustedTypePolicy;
|
}): TrustedTypePolicy;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface TrustedTypePolicy {
|
export declare interface TrustedTypePolicy {
|
||||||
createScript(input: string): TrustedScript;
|
createScript(input: string): TrustedScript;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,24 +17,25 @@
|
||||||
* will keep Angular's public API surface free of references to Trusted Types.
|
* will keep Angular's public API surface free of references to Trusted Types.
|
||||||
* For internal and semi-private APIs that need to reference Trusted Types, the
|
* For internal and semi-private APIs that need to reference Trusted Types, the
|
||||||
* minimal type definitions for the Trusted Types API provided by this module
|
* minimal type definitions for the Trusted Types API provided by this module
|
||||||
* should be used instead.
|
* should be used instead. They are marked as "declare" to prevent them from
|
||||||
|
* being renamed by compiler optimization.
|
||||||
*
|
*
|
||||||
* Adapted from
|
* Adapted from
|
||||||
* https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/trusted-types/index.d.ts
|
* https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/trusted-types/index.d.ts
|
||||||
* but restricted to the API surface used within Angular.
|
* but restricted to the API surface used within Angular.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export type TrustedHTML = {
|
export declare interface TrustedHTML {
|
||||||
__brand__: 'TrustedHTML'
|
__brand__: 'TrustedHTML';
|
||||||
};
|
}
|
||||||
export type TrustedScript = {
|
export declare interface TrustedScript {
|
||||||
__brand__: 'TrustedScript'
|
__brand__: 'TrustedScript';
|
||||||
};
|
}
|
||||||
export type TrustedScriptURL = {
|
export declare interface TrustedScriptURL {
|
||||||
__brand__: 'TrustedScriptURL'
|
__brand__: 'TrustedScriptURL';
|
||||||
};
|
}
|
||||||
|
|
||||||
export interface TrustedTypePolicyFactory {
|
export declare interface TrustedTypePolicyFactory {
|
||||||
createPolicy(policyName: string, policyOptions: {
|
createPolicy(policyName: string, policyOptions: {
|
||||||
createHTML?: (input: string) => string,
|
createHTML?: (input: string) => string,
|
||||||
createScript?: (input: string) => string,
|
createScript?: (input: string) => string,
|
||||||
|
@ -43,7 +44,7 @@ export interface TrustedTypePolicyFactory {
|
||||||
getAttributeType(tagName: string, attribute: string): string|null;
|
getAttributeType(tagName: string, attribute: string): string|null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface TrustedTypePolicy {
|
export declare interface TrustedTypePolicy {
|
||||||
createHTML(input: string): TrustedHTML;
|
createHTML(input: string): TrustedHTML;
|
||||||
createScript(input: string): TrustedScript;
|
createScript(input: string): TrustedScript;
|
||||||
createScriptURL(input: string): TrustedScriptURL;
|
createScriptURL(input: string): TrustedScriptURL;
|
||||||
|
|
Loading…
Reference in New Issue