diff --git a/.eslintrc b/.eslintrc index d758d36d..719ef1fa 100644 --- a/.eslintrc +++ b/.eslintrc @@ -12,6 +12,7 @@ "globals": { "globalThis": false }, + "reportUnusedDisableDirectives": true, "rules": { "class-methods-use-this": "off", "consistent-return": "off", @@ -26,32 +27,32 @@ "no-continue": "off", "no-multi-assign": "off", "no-nested-ternary": "off", + "no-new-object": "off", + "no-object-constructor": "error", "no-param-reassign": "off", "no-plusplus": "off", - "no-restricted-syntax": "off", + "no-restricted-syntax": ["error", "LabeledStatement", "WithStatement"], "no-return-assign": "off", "no-shadow": "off", "no-throw-literal": "off", "no-underscore-dangle": "off", "no-unused-expressions": "off", "no-use-before-define": "off", - "no-void": "off", "prefer-const": "off", "prefer-destructuring": ["error", { "object": true, "array": false }], - "prefer-rest-params": "off", - "prefer-promise-reject-errors": "off", - "symbol-description": "off", - "import/extensions": "off", + "import/extensions": ["error", "always"], "import/no-extraneous-dependencies": "off", "import/prefer-default-export": "off" }, "overrides": [ { - "files": "types/**/*.ts", + "files": "**/*.{ts,tsx}", "extends": ["airbnb-typescript/base", "prettier"], "rules": { "@typescript-eslint/no-shadow": "off", "@typescript-eslint/no-unused-expressions": "off", + "@typescript-eslint/no-use-before-define": "off", + "import/extensions": ["error", "always"], "import/no-cycle": "off" } } diff --git a/.husky/pre-commit b/.husky/pre-commit old mode 100644 new mode 100755 diff --git a/.husky/pre-push b/.husky/pre-push old mode 100644 new mode 100755 diff --git a/.npmignore b/.npmignore index bbcdd4e2..da7109e4 100644 --- a/.npmignore +++ b/.npmignore @@ -1,4 +1,6 @@ -/.circleci +/.github +/.husky +/.vscode /*.log /node_modules /docs @@ -7,4 +9,5 @@ /jsconfig.json /karma.conf.js /rollup.config.js +/web-test-runner.config.mjs **/tests/ diff --git a/html.js b/html.js index 04b4faa4..19c78199 100644 --- a/html.js +++ b/html.js @@ -203,13 +203,13 @@ const build = function(statics) { const CACHE = new Map(); -function html(statics) { +function html(statics, ...values) { let tmp = CACHE; tmp = evaluate( createElement, tmp.get(statics) || (tmp.set(statics, (tmp = build(statics))), tmp), - arguments, + [statics, ...values], [], ); diff --git a/html/html.js b/html/html.js index 824ca7aa..1061ee43 100644 --- a/html/html.js +++ b/html/html.js @@ -3,13 +3,13 @@ import { createElement } from "../src/core.js"; const CACHE = new Map(); -export function html(statics) { +export function html(statics, ...values) { let tmp = CACHE; tmp = evaluate( createElement, tmp.get(statics) || (tmp.set(statics, (tmp = build(statics))), tmp), - arguments, + [statics, ...values], [], ); diff --git a/jsx-runtime.js b/jsx-runtime.js index 9751eef1..c0aceaa7 100644 --- a/jsx-runtime.js +++ b/jsx-runtime.js @@ -3,11 +3,9 @@ import { createElement } from "./src/core.js"; export { Fragment } from "./src/core.js"; /** - * * @param {any} type * @param {any} props - * @param {any} [key ] - * @returns + * @param {any} [key] */ export const jsx = (type, props, key) => { if (props == undefined) { diff --git a/package-lock.json b/package-lock.json index 700494f9..4729c511 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,9 +11,9 @@ "devDependencies": { "@esm-bundle/chai": "^4.3.4-fix.0", "@rollup/plugin-node-resolve": "^13.3.0", - "@types/chai": "^4.2.18", - "@types/mocha": "^8.0.0", - "@web/test-runner": "^0.13.27", + "@types/chai": "^4.3.9", + "@types/mocha": "^8.2.3", + "@web/test-runner": "^0.13.31", "eslint": "^8.52.0", "eslint-config-airbnb-base": "^15.0.0", "eslint-config-airbnb-typescript": "^17.1.0", @@ -287,9 +287,9 @@ } }, "node_modules/@types/chai": { - "version": "4.3.5", - "resolved": "https://registry.npmjs.org/@types/chai/-/chai-4.3.5.tgz", - "integrity": "sha512-mEo1sAde+UCE6b2hxn332f1g1E8WfYRu6p5SvTKr2ZKC1f7gFJXk4h5PyGP9Dt6gCaG8y8XhwnXWC6Iy2cmBng==", + "version": "4.3.9", + "resolved": "https://registry.npmjs.org/@types/chai/-/chai-4.3.9.tgz", + "integrity": "sha512-69TtiDzu0bcmKQv3yg1Zx409/Kd7r0b5F1PfpYJfSHzLGtB53547V4u+9iqKYsTu/O2ai6KTb0TInNpvuQ3qmg==", "dev": true }, "node_modules/@types/co-body": { @@ -6041,9 +6041,9 @@ } }, "@types/chai": { - "version": "4.3.5", - "resolved": "https://registry.npmjs.org/@types/chai/-/chai-4.3.5.tgz", - "integrity": "sha512-mEo1sAde+UCE6b2hxn332f1g1E8WfYRu6p5SvTKr2ZKC1f7gFJXk4h5PyGP9Dt6gCaG8y8XhwnXWC6Iy2cmBng==", + "version": "4.3.9", + "resolved": "https://registry.npmjs.org/@types/chai/-/chai-4.3.9.tgz", + "integrity": "sha512-69TtiDzu0bcmKQv3yg1Zx409/Kd7r0b5F1PfpYJfSHzLGtB53547V4u+9iqKYsTu/O2ai6KTb0TInNpvuQ3qmg==", "dev": true }, "@types/co-body": { diff --git a/package.json b/package.json index 1b6231c4..8c46c9b7 100644 --- a/package.json +++ b/package.json @@ -78,7 +78,7 @@ "ssr": "node ssr/tests/ssr.js", "test:w": "web-test-runner --watch", "build:html": "rollup -c", - "prepare": "npm run test:ts && npm run test", + "prepare": "husky install && npm run test:ts && npm run test", "lint": "eslint .", "hook:push": "npm run lint && npm run test", "hook:commit": "npm run lint" @@ -104,9 +104,9 @@ "devDependencies": { "@esm-bundle/chai": "^4.3.4-fix.0", "@rollup/plugin-node-resolve": "^13.3.0", - "@types/chai": "^4.2.18", - "@types/mocha": "^8.0.0", - "@web/test-runner": "^0.13.27", + "@types/chai": "^4.3.9", + "@types/mocha": "^8.2.3", + "@web/test-runner": "^0.13.31", "eslint": "^8.52.0", "eslint-config-airbnb-base": "^15.0.0", "eslint-config-airbnb-typescript": "^17.1.0", @@ -118,9 +118,6 @@ "typescript": "^5.2.2" }, "prettier": { - "endOfLine": "lf", - "semi": true, - "singleQuote": false, "tabWidth": 4 } } diff --git a/src/context.js b/src/context.js index 0ddc5229..30d39b55 100644 --- a/src/context.js +++ b/src/context.js @@ -65,7 +65,6 @@ export const useConsumer = (id) => { }; /** - * * @type {import("context").UseContext} */ export const useContext = (context) => { @@ -92,7 +91,10 @@ export const createContext = (value) => { /** * @type {import("context").ComponentContext} */ - const context = () => void useProvider(Context, useHost().current); + const context = () => { + useProvider(Context, useHost().current); + return undefined; + }; context.props = { value: { diff --git a/src/css.js b/src/css.js index 18779817..8e0a1910 100644 --- a/src/css.js +++ b/src/css.js @@ -4,14 +4,14 @@ import { options } from "./options.js"; /** * It is used only if the browser supports adoptedStyleSheets. * caches the CSSStyleSheet using the css as a reference to the instance - * @type {{[id:string]:import("core").Sheet}} + * @type {{ [id: string]: import("core").Sheet }} */ const SHEETS = {}; /** * Create a Style from a string * @param {TemplateStringsArray} template - * @param {...any} args + * @param {any[]} args */ export function css(template, ...args) { const cssText = (template.raw || template).reduce( diff --git a/src/element/custom-element.js b/src/element/custom-element.js index 8b15a355..82644b14 100644 --- a/src/element/custom-element.js +++ b/src/element/custom-element.js @@ -6,10 +6,10 @@ import { setPrototype, transformValue } from "./set-prototype.js"; export { Any, createType } from "./set-prototype.js"; let ID = 0; + /** - * - * @param {Element & {dataset?:object}} node - * @returns {string|number} + * @param {Element & { dataset?: object }} node + * @returns {string | number} */ const getHydrateId = (node) => { const id = (node?.dataset || {})?.hydrate || ""; @@ -24,11 +24,11 @@ const getHydrateId = (node) => { */ export const c = (component, base) => { /** - * @type {import("./set-prototype").Attrs} + * @type {import("./set-prototype.js").Attrs} */ const attrs = {}; /** - * @type {import("./set-prototype").Values} + * @type {import("./set-prototype.js").Values} */ const values = {}; @@ -46,7 +46,9 @@ export const c = (component, base) => { super(); this._setup(); this._render = () => component({ ...this._props }); - for (const prop in values) this[prop] = values[prop]; + for (const prop in values) { + this[prop] = values[prop]; + } } /** @@ -104,7 +106,7 @@ export const c = (component, base) => { }; }); - this.symbolId = this.symbolId || Symbol(); + this.symbolId = this.symbolId || Symbol(className); const hooks = createHooks( () => this.update(), @@ -192,8 +194,8 @@ export const c = (component, base) => { /** * @this {import("dom").AtomicoThisInternal} * @param {string} attr - * @param {(string|null)} oldValue - * @param {(string|null)} value + * @param {string | null} oldValue + * @param {string | null} value */ attributeChangedCallback(attr, oldValue, value) { if (attrs[attr]) { diff --git a/src/element/errors.js b/src/element/errors.js index 0bc4b39e..4d1082be 100644 --- a/src/element/errors.js +++ b/src/element/errors.js @@ -1,6 +1,5 @@ export class Error { /** - * * @param {HTMLElement} target * @param {string} message * @param {string} value diff --git a/src/element/set-prototype.js b/src/element/set-prototype.js index 2a1c6d7e..c2a8b6aa 100644 --- a/src/element/set-prototype.js +++ b/src/element/set-prototype.js @@ -2,6 +2,7 @@ import { isFunction, isObject } from "../utils.js"; import { PropError } from "./errors.js"; export const CUSTOM_TYPE_NAME = "Custom"; + /** * The Any type avoids the validation of prop types * @type {null} @@ -16,11 +17,11 @@ const TRUE_VALUES = { true: 1, "": 1, 1: 1 }; /** * Constructs the setter and getter of the associated property * only if it is not defined in the prototype - * @param {Object} prototype - CustomElement prototype - * @param {string} prop - Name of the reactive property to associate with the customElement - * @param {any} schema - Structure to be evaluated for the definition of the property - * @param {Attrs} attrs - Dictionary of attributes to properties - * @param {Values} values - Values to initialize the customElements + * @param {object} prototype CustomElement prototype + * @param {string} prop Name of the reactive property to associate with the customElement + * @param {any} schema Structure to be evaluated for the definition of the property + * @param {Attrs} attrs Dictionary of attributes to properties + * @param {Values} values Values to initialize the customElements */ export function setPrototype(prototype, prop, schema, attrs, values) { /** @type {Schema} */ @@ -103,8 +104,8 @@ export function setPrototype(prototype, prop, schema, attrs, values) { /** * Dispatch an event - * @param {Element} node - DOM node to dispatch the event - * @param {InternalEvent & InternalEventInit} event - Event to dispatch on node + * @param {Element} node DOM node to dispatch the event + * @param {InternalEvent & InternalEventInit} event Event to dispatch on node */ export const dispatchEvent = ( node, @@ -113,7 +114,7 @@ export const dispatchEvent = ( /** * Transform a Camel Case string to a Kebab case - * @param {string} prop - string to apply the format + * @param {string} prop string to apply the format * @returns {string} */ export const getAttr = (prop) => prop.replace(/([A-Z])/g, "-$1").toLowerCase(); @@ -160,10 +161,8 @@ export const transformValue = (type, value) => new type(value); /** - * - * @param {import("schema").TypeCustom<(...args:any)=>any>} TypeCustom - * @param {*} value - * @returns + * @param {import("schema").TypeCustom<(...args: any[]) => any>} TypeCustom + * @param {any} value */ export const mapValue = ({ map }, value) => { try { @@ -172,11 +171,12 @@ export const mapValue = ({ map }, value) => { return { value, error: true }; } }; + /** * Filter the values based on their type * @param {any} type * @param {any} value - * @returns {{error?:boolean,value:any}} + * @returns {{ error?: boolean, value: any }} */ export const filterValue = (type, value) => type == null || value == null @@ -202,48 +202,49 @@ export const filterValue = (type, value) => : { value, error: true }; /** - * @param {(...args:any[])=>any} map - * @param {(...args:any[])=>any} [serialize] - * @returns {import("schema").TypeCustom<(...args:any)=>any>} + * @param {(...args: any[]) => any} map + * @param {(...args: any[]) => any} [serialize] + * @returns {import("schema").TypeCustom<(...args: any[]) => any>} */ export const createType = (map, serialize) => ({ name: CUSTOM_TYPE_NAME, map, serialize, }); + /** * Type any, used to avoid type validation. * @typedef {null} Any */ /** - * @typedef {Object} InternalEventInit - * @property {typeof CustomEvent|typeof Event} [base] - Optional constructor to initialize the event - * @property {boolean} [bubbles] - indicating whether the event bubbles. The default is false. - * @property {boolean} [cancelable] - indicating whether the event will trigger listeners outside of a shadow root. - * @property {boolean} [composed] - indicating whether the event will trigger listeners outside of a shadow root. - * @property {any} [detail] - indicating whether the event will trigger listeners outside of a shadow root. + * @typedef {object} InternalEventInit + * @property {typeof CustomEvent | typeof Event} [base] Optional constructor to initialize the event + * @property {boolean} [bubbles] indicating whether the event bubbles. The default is false. + * @property {boolean} [cancelable] indicating whether the event will trigger listeners outside of a shadow root. + * @property {boolean} [composed] indicating whether the event will trigger listeners outside of a shadow root. + * @property {any} [detail] indicating whether the event will trigger listeners outside of a shadow root. */ /** * Interface used by dispatchEvent to automate event firing - * @typedef {Object} InternalEvent - * @property {string} type - type of event to dispatch. + * @typedef {object} InternalEvent + * @property {string} type type of event to dispatch. */ /** - * @typedef {Object} Attrs + * @typedef {{ [attr: string]: { prop: string, type: Function } }} Attrs */ /** - * @typedef {Object} Values + * @typedef {{ [prop: string]: any }} Values */ /** - * @typedef {Object} Schema - * @property {any} [type] - data type to be worked as property and attribute - * @property {string} [attr] - allows customizing the name as an attribute by skipping the camelCase format - * @property {boolean} [reflect] - reflects property as attribute of node - * @property {InternalEvent & InternalEventInit} [event] - Allows to emit an event every time the property changes - * @property {any} [value] - defines a default value when instantiating the component + * @typedef {object} Schema + * @property {any} [type] data type to be worked as property and attribute + * @property {string} [attr] allows customizing the name as an attribute by skipping the camelCase format + * @property {boolean} [reflect] reflects property as attribute of node + * @property {InternalEvent & InternalEventInit} [event] Allows to emit an event every time the property changes + * @property {any} [value] defines a default value when instantiating the component */ diff --git a/src/hooks/create-hooks.js b/src/hooks/create-hooks.js index 79ad4840..e753ff98 100644 --- a/src/hooks/create-hooks.js +++ b/src/hooks/create-hooks.js @@ -5,7 +5,7 @@ const ID = Symbol.for("atomico.hooks"); globalThis[ID] = globalThis[ID] || {}; /** - * @type {{c:import("internal/hooks").SCOPE}} + * @type {{ c: import("internal/hooks").SCOPE }} */ let SCOPE = globalThis[ID]; diff --git a/src/hooks/custom-hooks/use-prop.js b/src/hooks/custom-hooks/use-prop.js index fcc75341..8d8eb1bd 100644 --- a/src/hooks/custom-hooks/use-prop.js +++ b/src/hooks/custom-hooks/use-prop.js @@ -1,7 +1,6 @@ import { useHost } from "../create-hooks.js"; /** - * * @type {import("core").UseProp} */ export const useProp = (name) => { diff --git a/src/hooks/custom-hooks/use-suspense.js b/src/hooks/custom-hooks/use-suspense.js index 1426771c..f3b785ac 100644 --- a/src/hooks/custom-hooks/use-suspense.js +++ b/src/hooks/custom-hooks/use-suspense.js @@ -47,20 +47,18 @@ export const useAsync = (callback, args) => { }; /** - * * @type {import("core").UseSuspense} */ - export const useSuspense = (fps = 8) => { const host = useHost(); + /** * @type {import("internal/hooks").ReturnSetStateUseSuspense} */ const [status, setStatus] = useState({ pending: true }); /** - * - * @param {()=>any} callback + * @param {() => any} callback * @param {number} deep */ const delay = (callback, deep) => @@ -94,6 +92,7 @@ export const useSuspense = (fps = 8) => { }, fps); } }; + /** * @param {Event} event */ diff --git a/src/hooks/tests/use-effect.test.js b/src/hooks/tests/use-effect.test.js index 0fed1334..7dffaa3f 100644 --- a/src/hooks/tests/use-effect.test.js +++ b/src/hooks/tests/use-effect.test.js @@ -1,6 +1,6 @@ import { expect } from "@esm-bundle/chai"; -import { createHooks } from "../create-hooks"; -import { useEffect } from "../hooks"; +import { createHooks } from "../create-hooks.js"; +import { useEffect } from "../hooks.js"; describe("src/hooks/use-effect", () => { /** diff --git a/src/hooks/tests/use-event.test.js b/src/hooks/tests/use-event.test.js index 6e33ad65..ccf9d074 100644 --- a/src/hooks/tests/use-event.test.js +++ b/src/hooks/tests/use-event.test.js @@ -1,6 +1,6 @@ import { expect } from "@esm-bundle/chai"; -import { createHooks } from "../create-hooks"; -import { useEvent } from "../custom-hooks/use-event"; +import { createHooks } from "../create-hooks.js"; +import { useEvent } from "../custom-hooks/use-event.js"; describe("src/hooks/custom-hooks/use-event", () => { it("association of useEvent to host", (done) => { diff --git a/src/hooks/tests/use-layout-effect.test.js b/src/hooks/tests/use-layout-effect.test.js index fb5e63d2..28449699 100644 --- a/src/hooks/tests/use-layout-effect.test.js +++ b/src/hooks/tests/use-layout-effect.test.js @@ -1,6 +1,6 @@ import { expect } from "@esm-bundle/chai"; -import { createHooks } from "../create-hooks"; -import { useLayoutEffect } from "../hooks"; +import { createHooks } from "../create-hooks.js"; +import { useLayoutEffect } from "../hooks.js"; describe("src/hooks/use-effect", () => { /** diff --git a/src/hooks/tests/use-memo.test.js b/src/hooks/tests/use-memo.test.js index 54921a4c..941901c0 100644 --- a/src/hooks/tests/use-memo.test.js +++ b/src/hooks/tests/use-memo.test.js @@ -1,6 +1,6 @@ import { expect } from "@esm-bundle/chai"; -import { createHooks } from "../create-hooks"; -import { useMemo, useCallback } from "../hooks"; +import { createHooks } from "../create-hooks.js"; +import { useMemo, useCallback } from "../hooks.js"; describe("src/hooks/use-callback", () => { it("reflection of useMemo", () => { diff --git a/src/hooks/tests/use-promise.test.js b/src/hooks/tests/use-promise.test.js index 45e91306..d63e32ec 100644 --- a/src/hooks/tests/use-promise.test.js +++ b/src/hooks/tests/use-promise.test.js @@ -72,6 +72,7 @@ describe("usePromise", () => { const load = () => { useAbortController(); + // eslint-disable-next-line prefer-promise-reject-errors const promise = usePromise(() => Promise.reject(10), []); switch (cycle++) { case 0: diff --git a/src/hooks/tests/use-prop.test.js b/src/hooks/tests/use-prop.test.js index ae5fe0a2..19cc53cc 100644 --- a/src/hooks/tests/use-prop.test.js +++ b/src/hooks/tests/use-prop.test.js @@ -1,6 +1,6 @@ import { expect } from "@esm-bundle/chai"; -import { createHooks } from "../create-hooks"; -import { useProp } from "../custom-hooks/use-prop"; +import { createHooks } from "../create-hooks.js"; +import { useProp } from "../custom-hooks/use-prop.js"; describe("src/hooks/custom-hooks/use-prop", () => { it("manipulation of the DOM object", () => { diff --git a/src/hooks/tests/use-reducer.test.js b/src/hooks/tests/use-reducer.test.js index cf36aace..31c23031 100644 --- a/src/hooks/tests/use-reducer.test.js +++ b/src/hooks/tests/use-reducer.test.js @@ -1,6 +1,6 @@ import { expect } from "@esm-bundle/chai"; -import { createHooks } from "../create-hooks"; -import { useReducer } from "../hooks"; +import { createHooks } from "../create-hooks.js"; +import { useReducer } from "../hooks.js"; describe("src/hooks/use-state", () => { it("initialState", () => { diff --git a/src/hooks/tests/use-ref.test.js b/src/hooks/tests/use-ref.test.js index 37016f83..2f216592 100644 --- a/src/hooks/tests/use-ref.test.js +++ b/src/hooks/tests/use-ref.test.js @@ -1,5 +1,5 @@ import { expect } from "@esm-bundle/chai"; -import { createHooks, useRef } from "../create-hooks"; +import { createHooks, useRef } from "../create-hooks.js"; describe("src/hooks/use-ref", () => { it("referencia persistente de creacion", () => { diff --git a/src/hooks/tests/use-state.test.js b/src/hooks/tests/use-state.test.js index 9a0408a8..a6567125 100644 --- a/src/hooks/tests/use-state.test.js +++ b/src/hooks/tests/use-state.test.js @@ -1,6 +1,6 @@ import { expect } from "@esm-bundle/chai"; -import { createHooks } from "../create-hooks"; -import { useState } from "../hooks"; +import { createHooks } from "../create-hooks.js"; +import { useState } from "../hooks.js"; describe("src/hooks/use-state", () => { it("single execution", () => { diff --git a/src/hooks/use-effect.js b/src/hooks/use-effect.js index 88d9030e..b3bd4bec 100644 --- a/src/hooks/use-effect.js +++ b/src/hooks/use-effect.js @@ -9,7 +9,7 @@ import { isEqualArray, isFunction } from "../utils.js"; /** * useLayoutEffect and useEffect have a similar algorithm * in that the position of the callback varies. - * @param {IdLayoutEffect|IdEffect|IdInsertionEffect} type + * @param {IdLayoutEffect | IdEffect | IdInsertionEffect} type * @return {import("internal/hooks").UseAnyEffect} */ const createEffect = (type) => (currentEffect, currentArgs) => { diff --git a/src/render.js b/src/render.js index 51110b11..3e24d9e2 100644 --- a/src/render.js +++ b/src/render.js @@ -56,6 +56,7 @@ export const Fragment = () => {}; export function RENDER(node, id, hydrate) { return diff(this, node, id, hydrate); } + /** * @type {import("vnode").H} */ @@ -226,8 +227,7 @@ function diff(newVnode, node, id = ID, hydrate = false, isSvg = false) { return node; } /** - * - * @param {Element|ShadowRoot} parent + * @param {Element | ShadowRoot} parent * @param {boolean} [hydrate] * @return {import("vnode").Fragment} */ @@ -270,7 +270,7 @@ function createFragment(parent, hydrate) { * it allows rendering the children of the virtual-dom * @param {any} children * @param {import("vnode").Fragment} fragment - * @param {Element|ShadowRoot} parent + * @param {Element | ShadowRoot} parent * @param {any} id * @param {boolean} [hydrate] * @param {boolean} [isSvg] @@ -300,7 +300,7 @@ export function renderChildren(children, fragment, parent, id, hydrate, isSvg) { children && flat(children, (child) => { - if (typeof child == "object" && child.$$ != $$) { + if (isObject(child) && child.$$ != $$) { return; } @@ -379,10 +379,9 @@ export function renderChildren(children, fragment, parent, id, hydrate, isSvg) { } /** - * * @param {Element} node - * @param {Object} props - * @param {Object} nextProps + * @param {object} props + * @param {object} nextProps * @param {boolean} isSvg * @param {import("vnode").Handlers} handlers */ @@ -397,7 +396,6 @@ export function diffProps(node, props, nextProps, handlers, isSvg) { } /** - * * @param {Element} node * @param {string} key * @param {any} prevValue @@ -484,7 +482,6 @@ export function setProperty(node, key, prevValue, nextValue, isSvg, handlers) { } /** - * * @param {Node} node * @param {string} type * @param {import("vnode").VNodeListener} [nextHandler] @@ -519,8 +516,7 @@ export function setEvent(node, type, nextHandler, handlers) { } /** - * - * @param {*} style + * @param {any} style * @param {string} key * @param {string} value */ diff --git a/src/tests/element-hooks.test.js b/src/tests/element-hooks.test.js index b172c3d2..c4ba92a8 100644 --- a/src/tests/element-hooks.test.js +++ b/src/tests/element-hooks.test.js @@ -1,5 +1,5 @@ import { expect } from "@esm-bundle/chai"; -import { useRef } from "../hooks/create-hooks"; +import { useRef } from "../hooks/create-hooks.js"; import { customElementScope } from "./element.test.js"; import { html } from "../../html.js"; diff --git a/src/tests/element.test.js b/src/tests/element.test.js index 9ceb1a1f..1b8d2c0f 100644 --- a/src/tests/element.test.js +++ b/src/tests/element.test.js @@ -374,7 +374,7 @@ describe("src/element", () => { let node = customElementScope(Wc); - let value = Symbol(); + let value = Symbol("value"); document.body.appendChild(node); diff --git a/src/tests/internal/set-prototype.test.js b/src/tests/internal/set-prototype.test.js index e7f4f649..d907055b 100644 --- a/src/tests/internal/set-prototype.test.js +++ b/src/tests/internal/set-prototype.test.js @@ -4,7 +4,7 @@ import { filterValue, reflectValue, getAttr, -} from "../../element/set-prototype"; +} from "../../element/set-prototype.js"; describe("internal: getAttr", () => { it("check getAttr", () => { @@ -70,7 +70,7 @@ describe("internal: filterValue", () => { }, { type: Object, - // eslint-disable-next-line no-new-object + // eslint-disable-next-line no-object-constructor success: [{}, new Object(), new (class {})()], }, { @@ -151,7 +151,7 @@ describe("internal: setPrototype", () => { it("declare basic", () => { class MyElement extends HTMLElement {} /** - * @type {Object} + * @type {import("../../element/set-prototype.js").Attrs} */ const attrs = {}; const values = {}; @@ -164,7 +164,7 @@ describe("internal: setPrototype", () => { it("declare shema", () => { class MyElement extends HTMLElement {} /** - * @type {Object} + * @type {import("../../element/set-prototype.js").Attrs} */ const attrs = {}; const values = {}; diff --git a/src/tests/render-children.test.js b/src/tests/render-children.test.js index feffde17..768dd340 100644 --- a/src/tests/render-children.test.js +++ b/src/tests/render-children.test.js @@ -2,7 +2,7 @@ import { expect } from "@esm-bundle/chai"; import { renderChildren } from "../render.js"; import { html } from "../../html.js"; /** - * @param {import("../render").Fragment} fragment + * @param {import("vnode").Fragment} fragment * @returns {Node[]} */ const fragmentToChildNodes = ({ markStart, markEnd }) => { @@ -13,14 +13,12 @@ const fragmentToChildNodes = ({ markStart, markEnd }) => { return list; }; /** - * * @param {number} min * @param {number} max * @returns {number} */ const random = (min, max) => Math.floor(Math.random() * (max - min + 1)) + min; /** - * * @param {number} size * @returns {number[]} */ @@ -41,7 +39,7 @@ describe("src/render#children", () => { const root = document.createElement("div"); const ref = {}; const children = [{}, {}, [{}], html``]; - const id = Symbol(); + const id = Symbol("id"); const fragment = renderChildren(children, null, root, id, false); const childNodes = fragmentToChildNodes(fragment); expect(childNodes).to.deep.equal([ref.current]); @@ -49,14 +47,14 @@ describe("src/render#children", () => { it("Render: Size", () => { const root = document.createElement("div"); const children = [...Array(10)].map(() => html``); - const id = Symbol(); + const id = Symbol("id"); const fragment = renderChildren(children, null, root, id, false); const childNodes = fragmentToChildNodes(fragment); expect(childNodes.length).to.equal(children.length); }); it("nested lists", () => { const root = document.createElement("div"); - const id = Symbol(); + const id = Symbol("id"); let count = 0; const list = [...Array(10)].map((_, index) => { const list = [...Array(5)].map( @@ -76,10 +74,9 @@ describe("src/render#children", () => { }); it("Render: Simple list rendering", () => { const root = document.createElement("div"); - const id = Symbol(); + const id = Symbol("id"); let fragment; /** - * * @param {number} size */ let update = (size) => { @@ -110,7 +107,7 @@ describe("src/render#children", () => { }); it("Render: Simple list rendering with keyes", () => { - const id = Symbol(); + const id = Symbol("id"); const host = document.createElement("div"); let size = 100; let fragment; diff --git a/src/tests/template.test.js b/src/tests/template.test.js index 82099919..9e73d5b3 100644 --- a/src/tests/template.test.js +++ b/src/tests/template.test.js @@ -1,6 +1,6 @@ import { expect } from "@esm-bundle/chai"; import { html } from "../../html.js"; -import { template } from "../template"; +import { template } from "../template.js"; describe("src/template", () => { it("check", () => { diff --git a/src/tests/utils.test.js b/src/tests/utils.test.js index f5b76493..48160e5a 100644 --- a/src/tests/utils.test.js +++ b/src/tests/utils.test.js @@ -1,5 +1,5 @@ import { expect } from "@esm-bundle/chai"; -import { isEqualArray, isFunction, isObject } from "../utils"; +import { isEqualArray, isFunction, isObject } from "../utils.js"; describe("src/utils", () => { it("isEqualArray", () => { diff --git a/src/utils.js b/src/utils.js index 16d8ddab..74dbd4f5 100644 --- a/src/utils.js +++ b/src/utils.js @@ -33,8 +33,7 @@ export const isObject = (value) => typeof value == "object"; export const { isArray } = Array; /** - * - * @param {Element & {dataset?:object}} node + * @param {Element & { dataset?: object }} node * @returns */ export const isHydrate = (node) => "hydrate" in (node?.dataset || {}); @@ -42,7 +41,7 @@ export const isHydrate = (node) => "hydrate" in (node?.dataset || {}); /** * @template {any[]} T * @param {T} list - * @param {(value:T[0])=>void} callback + * @param {(value: T[0]) => void} callback */ export function flat(list, callback) { let last; @@ -83,10 +82,9 @@ export function flat(list, callback) { } /** - * * @param {Element} target * @param {string} type - * @param {(event:Event)=>void} handler + * @param {(event: Event) => void} handler */ export const addListener = (target, type, handler) => { target.addEventListener(type, handler); diff --git a/ssr/load.js b/ssr/load.js index 688f9588..4f366214 100644 --- a/ssr/load.js +++ b/ssr/load.js @@ -12,8 +12,7 @@ let ID = 0; if (isServer()) setOptions(options); /** - * - * @param {import("../src/options").Options} options + * @param {import("core").Options} options */ function setOptions(options) { if (!isServer()) return; diff --git a/test-dom.js b/test-dom.js index cdac2e4d..336ede3a 100644 --- a/test-dom.js +++ b/test-dom.js @@ -2,7 +2,7 @@ import { h, render, Mark } from "./src/core.js"; import { isArray } from "./src/utils.js"; /** - * @type {Object} + * @type {{ [id: string]: { ref: HTMLDivElement, id: number, mount?: boolean } }} */ const TEST_HOST = {}; @@ -30,9 +30,8 @@ if (window.beforeEach) { } /** - * * @param {Element} node - * @param {string|symbol} [id] + * @param {string | symbol} [id] * @returns */ export const getFragment = (node, id) => { @@ -52,9 +51,9 @@ export const getFragment = (node, id) => { } return children; }; + /** - * - * @param {any} Vnode + * @param {any} vnode * @returns {HTMLDivElement} */ export function fixture(vnode) { @@ -85,7 +84,7 @@ export function fixture(vnode) { } /** - * @param {ChildNode | typeof window } node + * @param {ChildNode | typeof window} node * @param {string} type * @param {boolean | AddEventListenerOptions} [options] * @returns {Promise} @@ -96,7 +95,7 @@ export const asyncEventListener = (node, type, options) => }); /** - * @type {import("./types/test-dom").DispatchEvent} + * @type {import("./types/test-dom.js").DispatchEvent} */ export const dispatchEvent = (currentTarget, event, target) => { if (target != null) { diff --git a/tests/fixture.test.js b/tests/fixture.test.js index 90c0149b..8cdb4ff6 100644 --- a/tests/fixture.test.js +++ b/tests/fixture.test.js @@ -1,11 +1,11 @@ import { expect } from "@esm-bundle/chai"; -import { html } from "../core"; +import { html } from "../core.js"; import { fixture, getFragment, asyncEventListener, dispatchEvent, -} from "../test-dom"; +} from "../test-dom.js"; describe("fixture", () => { it("single", () => { diff --git a/tests/utils.test.js b/tests/utils.test.js index 635ec4ec..851c8782 100644 --- a/tests/utils.test.js +++ b/tests/utils.test.js @@ -1,5 +1,5 @@ import { expect } from "@esm-bundle/chai"; -import { serialize, checkIncompatibility } from "../utils"; +import { serialize, checkIncompatibility } from "../utils.js"; describe("utils", () => { it("serialize", () => { diff --git a/tsconfig.json b/tsconfig.json index a2df392b..0d5a5b13 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,6 +1,5 @@ { "include": ["src/**/*", "types/**/*"], - // "exclude": ["src/**/tests/","tests/"], "compilerOptions": { "strict": false, "noUnusedLocals": true, @@ -9,7 +8,7 @@ "jsxImportSource": "../", "target": "ESNext", "module": "ESNext", - "moduleResolution": "node", + "moduleResolution": "Node", "allowSyntheticDefaultImports": true, "allowJs": true, "declaration": true, diff --git a/types/core.d.ts b/types/core.d.ts index 360cf6a7..3515b9e0 100644 --- a/types/core.d.ts +++ b/types/core.d.ts @@ -165,9 +165,9 @@ export const useUpdate: Hooks.UseUpdate; /** * This hook is low level, it allows to know the render cycles of the hooks - * @param render - callback that runs between renders - * @param layoutEffect - callback that is executed after rendering - * @param effect - callback that is executed after layoutEffect + * @param render callback that runs between renders + * @param layoutEffect callback that is executed after rendering + * @param effect callback that is executed after layoutEffect */ export const useHook: Hooks.UseHook; diff --git a/types/hooks.d.ts b/types/hooks.d.ts index a0df12f5..f3cf2fd5 100644 --- a/types/hooks.d.ts +++ b/types/hooks.d.ts @@ -197,7 +197,7 @@ export type ReturnUseSuspense = }; /** - * @param fps - allows to delay in FPS the update of states + * @param fps allows to delay in FPS the update of states */ export type UseSuspense = (fps?: number) => ReturnUseSuspense; diff --git a/types/test-hooks.d.ts b/types/test-hooks.d.ts index 1eafa7cf..ec010682 100644 --- a/types/test-hooks.d.ts +++ b/types/test-hooks.d.ts @@ -4,7 +4,7 @@ export interface Hooks { } /** * create a scope for executing hooks without the need for components - * @param render - function that receives updates dispatched by useState or useReducer - * @param host - current for the useHost hook + * @param render function that receives updates dispatched by useState or useReducer + * @param host current for the useHost hook */ export function createHooks(render?: (result?: any) => any, host?: any): Hooks; diff --git a/types/tests/17-schema-infer.tsx b/types/tests/17-schema-infer.tsx index d6e04a1f..6bfd8094 100644 --- a/types/tests/17-schema-infer.tsx +++ b/types/tests/17-schema-infer.tsx @@ -1,4 +1,4 @@ -import { Component, Props, c } from "core"; +import { Component, c } from "core"; const x1: Component<{ value1: number[]; @@ -25,7 +25,7 @@ x1.props = { const X1 = c(x1); -function x2({ value1 = [1, 2, 3] }: Props) { +function x2() { return ; } @@ -40,5 +40,5 @@ const X2 = c(x1); value2={new Date()} value3={new MouseEvent("click")} value4={document.createElement("div")} - value6={(count: number) => {}} + value6={() => {}} />; diff --git a/types/tests/2-basic-Component.tsx b/types/tests/2-basic-Component.tsx index c5d84d03..e86c01af 100644 --- a/types/tests/2-basic-Component.tsx +++ b/types/tests/2-basic-Component.tsx @@ -3,9 +3,7 @@ import { c, Component } from "core"; const myComponent: Component< { value: string }, { onChange: CustomEvent<{ id: number }>; myMethod(value: number): void } -> = ({ value }) => { - return {value}; -}; +> = ({ value }) => {value}; myComponent.props = { value: String, diff --git a/utils.js b/utils.js index d440ddc5..b1723c0a 100644 --- a/utils.js +++ b/utils.js @@ -12,7 +12,7 @@ const COMPATIBILITY_LIST = [ /** * serialize a string - * @param {...any} args + * @param {any[]} args * @returns {string} */ export const serialize = (...args) => args.filter((value) => value).join(" ");