Skip to content

Commit

Permalink
fix(types): preserve ReadonlyArray in compiled code to support older …
Browse files Browse the repository at this point in the history
…TypeScript versions
  • Loading branch information
a.inkin committed Sep 2, 2019
1 parent a162cfd commit 180e0dd
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 9 deletions.
7 changes: 2 additions & 5 deletions projects/ng-dompurify/src/lib/ng-dompurify.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {DOMPURIFY_CONFIG} from './tokens/dompurify-config';
import {DOMPURIFY_HOOKS} from './tokens/dompurify-hooks';
import {SANITIZE_STYLE} from './tokens/sanitize-style';
import {NgDompurifyConfig} from './types/ng-dompurify-config';
import {NgDompurifyHook} from './types/ng-dompurify-hook';
import {NgDompurifyHooks} from './types/ng-dompurify-hooks';
import {SanitizeStyle} from './types/sanitize-style';
import {createAfterSanitizeAttributes} from './utils/createAfterSanitizeAttributes';
import {createUponSanitizeElementHook} from './utils/createUponSanitizeElementHook';
Expand All @@ -15,9 +15,6 @@ import {createUponSanitizeElementHook} from './utils/createUponSanitizeElementHo
* use {@link DOMPURIFY_CONFIG} token to provide config ({@link NgDompurifyConfig})
* use {@link SANITIZE_STYLE} token to provide a style sanitizing method ({@link SanitizeStyle})
* use {@link DOMPURIFY_HOOKS} token to provide a hooks for DOMPurify ({@link addHook})
*
* Ambient type cannot be used without @dynamic https://github.com/angular/angular/issues/23395
* @dynamic
*/
@Injectable({
providedIn: 'root',
Expand All @@ -29,7 +26,7 @@ export class NgDompurifySanitizer extends Sanitizer {
@Inject(SANITIZE_STYLE)
private readonly sanitizeStyle: SanitizeStyle,
@Inject(DOMPURIFY_HOOKS)
hooks: ReadonlyArray<NgDompurifyHook>,
hooks: NgDompurifyHooks,
) {
super();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import {removeAllHooks} from 'dompurify';
import {NgDompurifySanitizer} from '../ng-dompurify.service';
import {DOMPURIFY_HOOKS} from '../tokens/dompurify-hooks';
import {SANITIZE_STYLE} from '../tokens/sanitize-style';
import {NgDompurifyHook} from '../types/ng-dompurify-hook';
import {NgDompurifyHooks} from '../types/ng-dompurify-hooks';
import {cleanHtml, dirtyHtml} from './test-samples/html';
import {sanitizeStyle} from './test-samples/sanitizeStyle';
import {cleanStyleTag, dirtyStyleTag} from './test-samples/style';
import {cleanUrl, dirtyUrl} from './test-samples/url';

describe('NgDompurifySanitizer', () => {
const hooks: ReadonlyArray<NgDompurifyHook> = [
const hooks: NgDompurifyHooks = [
{
name: 'beforeSanitizeAttributes',
hook: (node: Element) => {
Expand Down
4 changes: 2 additions & 2 deletions projects/ng-dompurify/src/lib/tokens/dompurify-hooks.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {InjectionToken} from '@angular/core';
import {NgDompurifyHook} from '../types/ng-dompurify-hook';
import {NgDompurifyHooks} from '../types/ng-dompurify-hooks';

/**
* Token for adding hooks to DOMPurify, see {@link addHook}
*/
export const DOMPURIFY_HOOKS = new InjectionToken<ReadonlyArray<NgDompurifyHook>>(
export const DOMPURIFY_HOOKS: InjectionToken<NgDompurifyHooks> = new InjectionToken<NgDompurifyHooks>(
'Hooks for DOMPurify',
{
factory: () => [],
Expand Down
3 changes: 3 additions & 0 deletions projects/ng-dompurify/src/lib/types/ng-dompurify-hooks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import {NgDompurifyHook} from './ng-dompurify-hook';

export type NgDompurifyHooks = ReadonlyArray<NgDompurifyHook>;
1 change: 1 addition & 0 deletions projects/ng-dompurify/src/public-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ export * from './lib/tokens/sanitize-style';
export * from './lib/types/dompurify-hook';
export * from './lib/types/ng-dompurify-config';
export * from './lib/types/ng-dompurify-hook';
export * from './lib/types/ng-dompurify-hooks';
export * from './lib/types/sanitize-style';

0 comments on commit 180e0dd

Please sign in to comment.