refactor(core): clean up return types
This commit is contained in:
parent
8bd1491dc8
commit
924534e98f
1 changed files with 13 additions and 10 deletions
|
@ -5,6 +5,7 @@ import { parseScript } from "esprima";
|
||||||
/**
|
/**
|
||||||
* @typedef {import('./define-config.mjs').McFlyConfig} McFlyConfig
|
* @typedef {import('./define-config.mjs').McFlyConfig} McFlyConfig
|
||||||
* @typedef {import('unstorage').Storage} Storage
|
* @typedef {import('unstorage').Storage} Storage
|
||||||
|
* @typedef {import('unstorage').StorageValue} StorageValue
|
||||||
* @typedef {import('ultrahtml').Node} HtmlNode
|
* @typedef {import('ultrahtml').Node} HtmlNode
|
||||||
* @typedef {import('estree').BaseNode} JsNode
|
* @typedef {import('estree').BaseNode} JsNode
|
||||||
* @typedef {import('h3').EventHandler} EventHandler
|
* @typedef {import('h3').EventHandler} EventHandler
|
||||||
|
@ -52,7 +53,7 @@ export function useMcFlyRoute({ config, storage }) {
|
||||||
* Gets the correct HTML depending on the path requested
|
* Gets the correct HTML depending on the path requested
|
||||||
* @param {string} path
|
* @param {string} path
|
||||||
* @param {Storage} storage
|
* @param {Storage} storage
|
||||||
* @returns
|
* @returns {Promise<StorageValue>}
|
||||||
*/
|
*/
|
||||||
async function getHtml(path, storage) {
|
async function getHtml(path, storage) {
|
||||||
const rawPath = path[path.length - 1] === "/" ? path.slice(0, -1) : path;
|
const rawPath = path[path.length - 1] === "/" ? path.slice(0, -1) : path;
|
||||||
|
@ -69,7 +70,7 @@ async function getHtml(path, storage) {
|
||||||
/**
|
/**
|
||||||
* Gets the storage path for a file
|
* Gets the storage path for a file
|
||||||
* @param {string} filename
|
* @param {string} filename
|
||||||
* @returns string
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
function getPath(filename) {
|
function getPath(filename) {
|
||||||
return `assets:pages${filename}`;
|
return `assets:pages${filename}`;
|
||||||
|
@ -80,7 +81,7 @@ function getPath(filename) {
|
||||||
* @param {string} html
|
* @param {string} html
|
||||||
* @param {'js'} type
|
* @param {'js'} type
|
||||||
* @param {Storage} storage
|
* @param {Storage} storage
|
||||||
* @returns Promise<string>
|
* @returns {Promise<string>}
|
||||||
*/
|
*/
|
||||||
async function insertRegistry(html, type, storage) {
|
async function insertRegistry(html, type, storage) {
|
||||||
const ast = parse(html);
|
const ast = parse(html);
|
||||||
|
@ -121,7 +122,7 @@ async function insertRegistry(html, type, storage) {
|
||||||
* @param {Array<string>} usedCustomElements
|
* @param {Array<string>} usedCustomElements
|
||||||
* @param {"js" | "ts"} type
|
* @param {"js" | "ts"} type
|
||||||
* @param {Storage} storage
|
* @param {Storage} storage
|
||||||
* @returns string
|
* @returns {Promise<string>}
|
||||||
*/
|
*/
|
||||||
async function buildRegistry(usedCustomElements, type, storage) {
|
async function buildRegistry(usedCustomElements, type, storage) {
|
||||||
let registryScript = `<script type='module'>`;
|
let registryScript = `<script type='module'>`;
|
||||||
|
@ -162,7 +163,7 @@ async function buildRegistry(usedCustomElements, type, storage) {
|
||||||
/**
|
/**
|
||||||
* Evaluates server:setup script and replaces all variables used in the HTML
|
* Evaluates server:setup script and replaces all variables used in the HTML
|
||||||
* @param {string} html
|
* @param {string} html
|
||||||
* @returns string
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
function doSetUp(html) {
|
function doSetUp(html) {
|
||||||
const ast = parse(html);
|
const ast = parse(html);
|
||||||
|
@ -210,7 +211,7 @@ function doSetUp(html) {
|
||||||
/**
|
/**
|
||||||
* Removes any instance of server:setup script in the HTML
|
* Removes any instance of server:setup script in the HTML
|
||||||
* @param {string} html
|
* @param {string} html
|
||||||
* @returns string
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
function deleteServerScripts(html) {
|
function deleteServerScripts(html) {
|
||||||
const ast = parse(html);
|
const ast = parse(html);
|
||||||
|
@ -229,7 +230,7 @@ function deleteServerScripts(html) {
|
||||||
/**
|
/**
|
||||||
* Cleans a JS string for save evaluation
|
* Cleans a JS string for save evaluation
|
||||||
* @param {Array<string>} scripts
|
* @param {Array<string>} scripts
|
||||||
* @returns string
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
function cleanScript(scripts) {
|
function cleanScript(scripts) {
|
||||||
let script = scripts.map((s) => s.trim()).join(" ");
|
let script = scripts.map((s) => s.trim()).join(" ");
|
||||||
|
@ -242,7 +243,7 @@ function cleanScript(scripts) {
|
||||||
/**
|
/**
|
||||||
* Checks if given node of a JS script is a comment
|
* Checks if given node of a JS script is a comment
|
||||||
* @param {JsNode} node
|
* @param {JsNode} node
|
||||||
* @returns boolean
|
* @returns {boolean}
|
||||||
*/
|
*/
|
||||||
function isComment(node) {
|
function isComment(node) {
|
||||||
return (
|
return (
|
||||||
|
@ -256,7 +257,7 @@ function isComment(node) {
|
||||||
/**
|
/**
|
||||||
* Removes all instances of comments in a JS string
|
* Removes all instances of comments in a JS string
|
||||||
* @param {string} script
|
* @param {string} script
|
||||||
* @returns string
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
function removeComments(script) {
|
function removeComments(script) {
|
||||||
const entries = [];
|
const entries = [];
|
||||||
|
@ -284,7 +285,7 @@ function removeComments(script) {
|
||||||
* Return HTML with all fragments replaced with the correct content in the storage
|
* Return HTML with all fragments replaced with the correct content in the storage
|
||||||
* @param {string} html
|
* @param {string} html
|
||||||
* @param {Storage} storage
|
* @param {Storage} storage
|
||||||
* @returns Promise<string>
|
* @returns {Promise<string>}
|
||||||
*/
|
*/
|
||||||
async function useFragments(html, storage) {
|
async function useFragments(html, storage) {
|
||||||
const fragmentFiles = await getFiles("html", storage);
|
const fragmentFiles = await getFiles("html", storage);
|
||||||
|
@ -331,6 +332,7 @@ async function useFragments(html, storage) {
|
||||||
* Replace a slot in a fragmentNode with given node
|
* Replace a slot in a fragmentNode with given node
|
||||||
* @param {HtmlNode} fragmentNode
|
* @param {HtmlNode} fragmentNode
|
||||||
* @param {HtmlNode} node
|
* @param {HtmlNode} node
|
||||||
|
* @returns {void}
|
||||||
*/
|
*/
|
||||||
function replaceSlots(fragmentNode, node) {
|
function replaceSlots(fragmentNode, node) {
|
||||||
walkSync(fragmentNode, (n) => {
|
walkSync(fragmentNode, (n) => {
|
||||||
|
@ -345,6 +347,7 @@ function replaceSlots(fragmentNode, node) {
|
||||||
* Get all files from the storage given a type
|
* Get all files from the storage given a type
|
||||||
* @param {string} type
|
* @param {string} type
|
||||||
* @param {Storage} storage
|
* @param {Storage} storage
|
||||||
|
* @returns {Promise<string[]>}
|
||||||
*/
|
*/
|
||||||
async function getFiles(type, storage) {
|
async function getFiles(type, storage) {
|
||||||
return (await storage.getKeys("assets:components"))
|
return (await storage.getKeys("assets:components"))
|
||||||
|
|
Loading…
Reference in a new issue