Skip to content

Commit 2424511

Browse files
committed
perf: use charCodeAt
1 parent b6f844d commit 2424511

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/html.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ const html = ({ raw: literals }, ...expressions) => {
5555
? expression.join("")
5656
: `${expression}`;
5757

58-
if (literal && literal[literal.length - 1] === "!") {
58+
if (literal && literal.charCodeAt(literal.length - 1) === 33) {
5959
literal = literal.slice(0, -1);
6060
} else if (string && escapeRegExp.test(string)) {
6161
string = escapeFunction(string);
@@ -87,7 +87,8 @@ const htmlGenerator = function* ({ raw: literals }, ...expressions) {
8787
string = "";
8888
} else {
8989
if (expression[symbolIterator]) {
90-
const isRaw = literal !== "" && literal[literal.length - 1] === "!";
90+
const isRaw =
91+
literal !== "" && literal.charCodeAt(literal.length - 1) === 33;
9192

9293
if (isRaw) {
9394
literal = literal.slice(0, -1);
@@ -147,7 +148,7 @@ const htmlGenerator = function* ({ raw: literals }, ...expressions) {
147148
string = `${expression}`;
148149
}
149150

150-
if (literal && literal[literal.length - 1] === "!") {
151+
if (literal && literal.charCodeAt(literal.length - 1) === 33) {
151152
literal = literal.slice(0, -1);
152153
} else if (string && escapeRegExp.test(string)) {
153154
string = escapeFunction(string);
@@ -183,7 +184,8 @@ const htmlAsyncGenerator = async function* ({ raw: literals }, ...expressions) {
183184
string = "";
184185
} else {
185186
if (expression[symbolIterator] || expression[symbolAsyncIterator]) {
186-
const isRaw = literal !== "" && literal[literal.length - 1] === "!";
187+
const isRaw =
188+
literal !== "" && literal.charCodeAt(literal.length - 1) === 33;
187189

188190
if (isRaw) {
189191
literal = literal.slice(0, -1);
@@ -243,7 +245,7 @@ const htmlAsyncGenerator = async function* ({ raw: literals }, ...expressions) {
243245
string = `${expression}`;
244246
}
245247

246-
if (literal && literal[literal.length - 1] === "!") {
248+
if (literal && literal.charCodeAt(literal.length - 1) === 33) {
247249
literal = literal.slice(0, -1);
248250
} else if (string && escapeRegExp.test(string)) {
249251
string = escapeFunction(string);

0 commit comments

Comments
 (0)