- Delete old Vite+Svelte frontend - Initialize new SvelteKit project with TypeScript - Configure Tailwind CSS v4 + DaisyUI - Implement JWT authentication with auto-refresh - Create login page with form validation (Zod) - Add protected route guards - Update Docker configuration for single-stage build - Add E2E tests with Playwright (6/11 passing) - Fix Svelte 5 reactivity with $state() runes Known issues: - 5 E2E tests failing (timing/async issues) - Token refresh implementation needs debugging - Validation error display timing
81 lines
2.3 KiB
JavaScript
81 lines
2.3 KiB
JavaScript
import jsTokens from 'js-tokens';
|
|
|
|
const FILL_COMMENT = " ";
|
|
function stripLiteralFromToken(token, fillChar, filter) {
|
|
if (token.type === "SingleLineComment") {
|
|
return FILL_COMMENT.repeat(token.value.length);
|
|
}
|
|
if (token.type === "MultiLineComment") {
|
|
return token.value.replace(/[^\n]/g, FILL_COMMENT);
|
|
}
|
|
if (token.type === "StringLiteral") {
|
|
if (!token.closed) {
|
|
return token.value;
|
|
}
|
|
const body = token.value.slice(1, -1);
|
|
if (filter(body)) {
|
|
return token.value[0] + fillChar.repeat(body.length) + token.value[token.value.length - 1];
|
|
}
|
|
}
|
|
if (token.type === "NoSubstitutionTemplate") {
|
|
const body = token.value.slice(1, -1);
|
|
if (filter(body)) {
|
|
return `\`${body.replace(/[^\n]/g, fillChar)}\``;
|
|
}
|
|
}
|
|
if (token.type === "RegularExpressionLiteral") {
|
|
const body = token.value;
|
|
if (filter(body)) {
|
|
return body.replace(/\/(.*)\/(\w?)$/g, (_, $1, $2) => `/${fillChar.repeat($1.length)}/${$2}`);
|
|
}
|
|
}
|
|
if (token.type === "TemplateHead") {
|
|
const body = token.value.slice(1, -2);
|
|
if (filter(body)) {
|
|
return `\`${body.replace(/[^\n]/g, fillChar)}\${`;
|
|
}
|
|
}
|
|
if (token.type === "TemplateTail") {
|
|
const body = token.value.slice(0, -2);
|
|
if (filter(body)) {
|
|
return `}${body.replace(/[^\n]/g, fillChar)}\``;
|
|
}
|
|
}
|
|
if (token.type === "TemplateMiddle") {
|
|
const body = token.value.slice(1, -2);
|
|
if (filter(body)) {
|
|
return `}${body.replace(/[^\n]/g, fillChar)}\${`;
|
|
}
|
|
}
|
|
return token.value;
|
|
}
|
|
function optionsWithDefaults(options) {
|
|
return {
|
|
fillChar: options?.fillChar ?? " ",
|
|
filter: options?.filter ?? (() => true)
|
|
};
|
|
}
|
|
function stripLiteral(code, options) {
|
|
let result = "";
|
|
const _options = optionsWithDefaults(options);
|
|
for (const token of jsTokens(code, { jsx: false })) {
|
|
result += stripLiteralFromToken(token, _options.fillChar, _options.filter);
|
|
}
|
|
return result;
|
|
}
|
|
function stripLiteralDetailed(code, options) {
|
|
let result = "";
|
|
const tokens = [];
|
|
const _options = optionsWithDefaults(options);
|
|
for (const token of jsTokens(code, { jsx: false })) {
|
|
tokens.push(token);
|
|
result += stripLiteralFromToken(token, _options.fillChar, _options.filter);
|
|
}
|
|
return {
|
|
result,
|
|
tokens
|
|
};
|
|
}
|
|
|
|
export { stripLiteral, stripLiteralDetailed, stripLiteralDetailed as stripLiteralJsTokens };
|