Skip to content

Commit

Permalink
refactor: skip unused createScript and createScriptURL
Browse files Browse the repository at this point in the history
  • Loading branch information
haoqunjiang authored and yyx990803 committed May 30, 2024
1 parent 0dc028e commit cc5cd3c
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions packages/runtime-dom/src/nodeOps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,17 @@ import type {
TrustedTypesWindow,
} from 'trusted-types/lib'

let policy: TrustedTypePolicy | undefined = undefined
function getPolicy(): TrustedTypePolicy | undefined {
type VueTrustedTypePolicy =
| Pick<TrustedTypePolicy, 'name' | 'createHTML'>
| undefined

let policy: VueTrustedTypePolicy = undefined
function getPolicy(): VueTrustedTypePolicy {
const ttWindow = window as unknown as TrustedTypesWindow
if (ttWindow.trustedTypes && !policy) {
try {
policy = ttWindow.trustedTypes.createPolicy('vue', {
createHTML: val => val,
createScript: val => val,
createScriptURL: val => val,
})
} catch (e: unknown) {
// `createPolicy` throws a TypeError if the name is a duplicate
Expand Down

0 comments on commit cc5cd3c

Please sign in to comment.