Skip to content

Commit 05ee1db

Browse files
committed
Address review comments.
1 parent 35a637d commit 05ee1db

1 file changed

Lines changed: 48 additions & 48 deletions

File tree

packages/lit-html/src/static.ts

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
// Any new exports need to be added to the export statement in
88
// `packages/lit/src/index.all.ts`.
99

10-
import { html as coreHtml, svg as coreSvg, TemplateResult } from './lit-html.js';
10+
import {html as coreHtml, svg as coreSvg, TemplateResult} from './lit-html.js';
1111

1212
interface StaticValue {
1313
/** The value to interpolate as-is into the template. */
@@ -108,57 +108,57 @@ const stringsCache = new Map<string, TemplateStringsArray>();
108108
*/
109109
export const withStatic =
110110
(coreTag: typeof coreHtml | typeof coreSvg) =>
111-
(strings: TemplateStringsArray, ...values: unknown[]): TemplateResult => {
112-
const l = values.length;
113-
let staticValue: string | undefined;
114-
let dynamicValue: unknown;
115-
const staticStrings: Array<string> = [];
116-
const dynamicValues: Array<unknown> = [];
117-
let i = 0;
118-
let hasStatics = false;
119-
let s: string;
111+
(strings: TemplateStringsArray, ...values: unknown[]): TemplateResult => {
112+
const l = values.length;
113+
let staticValue: string | undefined;
114+
let dynamicValue: unknown;
115+
const staticStrings: Array<string> = [];
116+
const dynamicValues: Array<unknown> = [];
117+
let i = 0;
118+
let hasStatics = false;
119+
let s: string;
120120

121-
while (i < l) {
122-
s = strings[i];
123-
// Collect any unsafeStatic values, and their following template strings
124-
// so that we treat a run of template strings and unsafe static values as
125-
// a single template string.
126-
while (
127-
i < l &&
128-
((dynamicValue = values[i]),
129-
(staticValue = unwrapStaticValue(dynamicValue))) !== undefined
130-
) {
131-
s += staticValue + strings[++i];
132-
hasStatics = true;
133-
}
134-
dynamicValues.push(dynamicValue);
135-
staticStrings.push(s);
136-
i++;
137-
}
138-
// If the last value isn't static (which would have consumed the last
139-
// string), then we need to add the last string.
140-
if (i === l) {
141-
staticStrings.push(strings[l]);
121+
while (i < l) {
122+
s = strings[i];
123+
// Collect any unsafeStatic values, and their following template strings
124+
// so that we treat a run of template strings and unsafe static values as
125+
// a single template string.
126+
while (
127+
i < l &&
128+
((dynamicValue = values[i]),
129+
(staticValue = unwrapStaticValue(dynamicValue))) !== undefined
130+
) {
131+
s += staticValue + strings[++i];
132+
hasStatics = true;
142133
}
134+
dynamicValues.push(dynamicValue);
135+
staticStrings.push(s);
136+
i++;
137+
}
138+
// If the last value isn't static (which would have consumed the last
139+
// string), then we need to add the last string.
140+
if (i === l) {
141+
staticStrings.push(strings[l]);
142+
}
143143

144-
if (hasStatics) {
145-
const key = staticStrings.join('$$lit$$');
146-
strings = stringsCache.get(key)!;
147-
if (strings === undefined) {
148-
// Beware: in general this pattern is unsafe, and doing so may bypass
149-
// lit's security checks and allow an attacker to execute arbitrary
150-
// code and inject arbitrary content.
151-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
152-
(staticStrings as any).raw = staticStrings;
153-
stringsCache.set(
154-
key,
155-
(strings = staticStrings as unknown as TemplateStringsArray)
156-
);
157-
}
158-
values = dynamicValues;
144+
if (hasStatics) {
145+
const key = staticStrings.join('$$lit$$');
146+
strings = stringsCache.get(key)!;
147+
if (strings === undefined) {
148+
// Beware: in general this pattern is unsafe, and doing so may bypass
149+
// lit's security checks and allow an attacker to execute arbitrary
150+
// code and inject arbitrary content.
151+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
152+
(staticStrings as any).raw = staticStrings;
153+
stringsCache.set(
154+
key,
155+
(strings = staticStrings as unknown as TemplateStringsArray)
156+
);
159157
}
160-
return coreTag(strings, ...values);
161-
};
158+
values = dynamicValues;
159+
}
160+
return coreTag(strings, ...values);
161+
};
162162

163163
/**
164164
* Interprets a template literal as an HTML template that can efficiently

0 commit comments

Comments
 (0)