Skip to content

Commit

Permalink
improve scopes
Browse files Browse the repository at this point in the history
  • Loading branch information
gurgunday committed Jul 14, 2024
1 parent 94a5305 commit 399a275
Showing 1 changed file with 10 additions and 14 deletions.
24 changes: 10 additions & 14 deletions src/html.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ const escapeRegExp = /["&'<>`]/;
const escapeFunction = (string) => {
const stringLength = string.length;
let start = 0;
let end = 0;
let escaped = "";

for (; end !== stringLength; ++end) {
for (let end = 0; end !== stringLength; ++end) {
switch (string.charCodeAt(end)) {
case 34: // "
escaped += string.slice(start, end) + "&#34;";
Expand Down Expand Up @@ -35,7 +34,7 @@ const escapeFunction = (string) => {
}
}

escaped += string.slice(start, end);
escaped += string.slice(start, stringLength);

return escaped;
};
Expand All @@ -47,10 +46,9 @@ const escapeFunction = (string) => {
*/
const html = ({ raw: literals }, ...expressions) => {
const expressionsLength = expressions.length;
let index = 0;
let accumulator = "";

for (; index !== expressionsLength; ++index) {
for (let index = 0; index !== expressionsLength; ++index) {
const expression = expressions[index];
let literal = literals[index];
let string =
Expand All @@ -71,7 +69,7 @@ const html = ({ raw: literals }, ...expressions) => {
accumulator += literal + string;
}

accumulator += literals[index];
accumulator += literals[expressionsLength];

return accumulator;
};
Expand All @@ -83,9 +81,8 @@ const html = ({ raw: literals }, ...expressions) => {
*/
const htmlGenerator = function* ({ raw: literals }, ...expressions) {
const expressionsLength = expressions.length;
let index = 0;

for (; index !== expressionsLength; ++index) {
for (let index = 0; index !== expressionsLength; ++index) {
let expression = expressions[index];
let literal = literals[index];
let string;
Expand Down Expand Up @@ -168,8 +165,8 @@ const htmlGenerator = function* ({ raw: literals }, ...expressions) {
}
}

if (literals[index]) {
yield literals[index];
if (literals[expressionsLength]) {
yield literals[expressionsLength];
}
};

Expand All @@ -180,9 +177,8 @@ const htmlGenerator = function* ({ raw: literals }, ...expressions) {
*/
const htmlAsyncGenerator = async function* ({ raw: literals }, ...expressions) {
const expressionsLength = expressions.length;
let index = 0;

for (; index !== expressionsLength; ++index) {
for (let index = 0; index !== expressionsLength; ++index) {
let expression = await expressions[index];

Check warning on line 182 in src/html.js

View workflow job for this annotation

GitHub Actions / test (^18)

Unexpected `await` inside a loop

Check warning on line 182 in src/html.js

View workflow job for this annotation

GitHub Actions / test (lts/*)

Unexpected `await` inside a loop
let literal = literals[index];
let string;
Expand Down Expand Up @@ -268,8 +264,8 @@ const htmlAsyncGenerator = async function* ({ raw: literals }, ...expressions) {
}
}

if (literals[index]) {
yield literals[index];
if (literals[expressionsLength]) {
yield literals[expressionsLength];
}
};

Expand Down

0 comments on commit 399a275

Please sign in to comment.