REFACTOR: unify naming of only emoji (#8741)

This commit is contained in:
Joffrey JAFFEUX 2020-01-17 17:21:08 +01:00 committed by GitHub
parent 28d09227f5
commit 3b5a6c9895
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 7 deletions

View File

@ -241,7 +241,7 @@ function applyEmoji(
result[result.length - 1].type === "emoji" && result[result.length - 1].type === "emoji" &&
result.filter(r => r.type === "emoji").length <= 3 result.filter(r => r.type === "emoji").length <= 3
) { ) {
let allEmojiLine = true; let onlyEmojiLine = true;
let index = 0; let index = 0;
const checkNextToken = t => { const checkNextToken = t => {
@ -250,7 +250,7 @@ function applyEmoji(
} }
if (!["emoji", "text"].includes(t.type)) { if (!["emoji", "text"].includes(t.type)) {
allEmojiLine = false; onlyEmojiLine = false;
} }
// a text token should always have an emoji before // a text token should always have an emoji before
@ -260,11 +260,11 @@ function applyEmoji(
((result[index - 1] && result[index - 1].type !== "emoji") || ((result[index - 1] && result[index - 1].type !== "emoji") ||
t.content !== " ") t.content !== " ")
) { ) {
allEmojiLine = false; onlyEmojiLine = false;
} }
// exit as soon as possible // exit as soon as possible
if (allEmojiLine) { if (onlyEmojiLine) {
index += 1; index += 1;
checkNextToken(result[index]); checkNextToken(result[index]);
} }
@ -272,10 +272,10 @@ function applyEmoji(
checkNextToken(result[index]); checkNextToken(result[index]);
if (allEmojiLine) { if (onlyEmojiLine) {
result.forEach(r => { result.forEach(r => {
if (r.type === "emoji") { if (r.type === "emoji") {
applyAllEmojiClass(r); applyOnlyEmojiClass(r);
} }
}); });
} }
@ -285,7 +285,7 @@ function applyEmoji(
return result; return result;
} }
function applyAllEmojiClass(token) { function applyOnlyEmojiClass(token) {
token.attrs.forEach(attr => { token.attrs.forEach(attr => {
if (attr[0] === "class") { if (attr[0] === "class") {
attr[1] = `${attr[1]} only-emoji`; attr[1] = `${attr[1]} only-emoji`;