generate shorter code

This commit is contained in:
Tobias Koppers 2021-05-10 09:43:03 +02:00
parent 7d42aa7a30
commit 1879f243dd
1 changed files with 7 additions and 6 deletions

View File

@ -25,7 +25,7 @@ class TrustedTypesRuntimeModule extends HelperRuntimeModule {
if (!trustedTypesPolicy) {
// Skip Trusted Types logic.
return Template.asString([
`${fn} = ${runtimeTemplate.basicFunction("url", ["return url;"])};`
`${fn} = ${runtimeTemplate.returningFunction("url", "url")};`
]);
}
@ -33,16 +33,17 @@ class TrustedTypesRuntimeModule extends HelperRuntimeModule {
"var policy;",
`${fn} = ${runtimeTemplate.basicFunction("url", [
"// Create Trusted Type policy if Trusted Types are available and the policy doesn't exist yet.",
"if (typeof policy === 'undefined') {",
"if (policy === undefined) {",
Template.indent([
"policy = {",
Template.indent([
"createScriptURL: function(url) {",
Template.indent("return url;"),
"}"
`createScriptURL: ${runtimeTemplate.returningFunction(
"url",
"url"
)}`
]),
"};",
"if (typeof trustedTypes !== 'undefined' && trustedTypes.createPolicy) {",
'if (typeof trustedTypes !== "undefined" && trustedTypes.createPolicy) {',
Template.indent([
`policy = trustedTypes.createPolicy(${JSON.stringify(
trustedTypesPolicy