Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.idea
/node_modules
/coverage
_site
/HyperTalk Reference 2.4.pdf
.DS_Store
Expand Down
14,708 changes: 6,252 additions & 8,456 deletions package-lock.json

Large diffs are not rendered by default.

25 changes: 15 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@
"_hyperscript": "src/node-hyperscript.js"
},
"scripts": {
"test": "mocha-chrome test/index.html",
"test:debug": "web-test-runner --manual --open",
"types-check": "tsc",
"test": "npm run types-check && playwright install chromium && web-test-runner --browsers chromium --playwright",
"test:firefox": "playwright install firefox && web-test-runner --concurrency 1 --browsers firefox --playwright",
"test:webkit": "playwright install webkit && web-test-runner --browsers webkit --playwright",
"test:all": "playwright install chromium firefox webkit && web-test-runner --concurrency 1 --browsers chromium firefox webkit --playwright",
"dist": "cp -r src/* dist/ && npm run-script terser && npm run-script typings && gzip -k -f dist/_hyperscript.min.js > dist/_hyperscript.min.js.gz && exit",
"typings": "npx tsc --declaration dist/_hyperscript.js --allowJs --emitDeclarationOnly --skipLibCheck",
"www": "node scripts/www.js",
Expand All @@ -35,18 +40,18 @@
},
"devDependencies": {
"@11ty/eleventy": "^1.0.2",
"chai": "^4.2.0",
"fs-extra": "^9.0.0",
"@web/test-runner": "^0.20.2",
"@web/test-runner-playwright": "^0.11.1",
"chai": "^4.5.0",
"fs-extra": "^9.1.0",
"markdown-it": "^12.3.2",
"markdown-it-anchor": "^8.4.1",
"markdown-it-attrs": "^4.1.3",
"markdown-it-table-of-contents": "^0.6.0",
"mocha": "^7.1.1",
"mocha-chrome": "^2.2.0",
"sinon": "^9.0.2"
},
"dependencies": {
"markdown-it-deflist": "^2.1.0",
"terser": "^5.14.1"
"markdown-it-table-of-contents": "^0.6.0",
"mocha": "^11.1.0",
"sinon": "^10.0.1",
"terser": "^5.14.1",
"typescript": "^5.8.3"
}
}
1 change: 0 additions & 1 deletion src/_hyperscript.d.ts

This file was deleted.

28 changes: 9 additions & 19 deletions src/_hyperscript.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
/**
* @typedef {Object} Hyperscript
*/

(function (self, factory) {
const _hyperscript = factory(self)

Expand Down Expand Up @@ -1216,7 +1212,6 @@
requireElement(type, tokens, message, root) {
var result = this.parseElement(type, tokens, root);
if (!result) Parser.raiseParseError(tokens, message || "Expected " + type);
// @ts-ignore
return result;
}

Expand Down Expand Up @@ -1704,7 +1699,7 @@
/**
* @param {*} parseElement
* @param {Context} ctx
* @param {Boolean} shortCircuitOnValue
* @param {Boolean} [shortCircuitOnValue]
* @returns {*}
*/
unifiedEval(parseElement, ctx, shortCircuitOnValue) {
Expand Down Expand Up @@ -2437,8 +2432,7 @@


/** @type string | null */
// @ts-ignore
hyperscriptUrl = "document" in globalScope && document.currentScript ? document.currentScript.src : null;
hyperscriptUrl = "document" in globalScope && document.currentScript && document.currentScript instanceof HTMLScriptElement ? document.currentScript.src : null;
}


Expand Down Expand Up @@ -2473,6 +2467,7 @@
} else if (prop === 'clearAll') {
return clearAllCookies;
} else if (typeof prop === "string") {
// @ts-ignore string works fine with isNaN
if (!isNaN(prop)) {
return getCookiesAsArray()[parseInt(prop)];

Expand Down Expand Up @@ -2515,7 +2510,7 @@
finalValue+=";secure=" + value.path;
}
}
document.cookie= prop + "=" + finalValue;
document.cookie= String(prop) + "=" + finalValue;
return true;
}
})
Expand Down Expand Up @@ -3288,7 +3283,6 @@
args: [root],
op: function (context, rootVal) {
if (attribute) {
// @ts-ignore
var value = runtime.resolveAttribute(rootVal, attribute.name);
} else if (style) {
var value
Expand Down Expand Up @@ -3432,7 +3426,6 @@
attribute: attribute,
args: [root],
op: function (_ctx, rootVal) {
// @ts-ignore
var value = runtime.resolveAttribute(rootVal, attribute.name);
return value;
},
Expand Down Expand Up @@ -4339,12 +4332,10 @@
if (tokens.matchToken("debounced")) {
tokens.requireToken("at");
var timeExpr = parser.requireElement("unaryExpression", tokens);
// @ts-ignore
var debounceTime = timeExpr.evaluate({}); // OK No promise TODO make a literal time expr
} else if (tokens.matchToken("throttled")) {
tokens.requireToken("at");
var timeExpr = parser.requireElement("unaryExpression", tokens);
// @ts-ignore
var throttleTime = timeExpr.evaluate({}); // OK No promise TODO make a literal time expr
}

Expand Down Expand Up @@ -5915,7 +5906,7 @@
} else {
target.insertAdjacentHTML("beforeend", value); // insert at end, preserving existing content
}
runtime.processNode(target); // process parent so any new content i
runtime.processNode(/** @type {HTMLElement} */ (target)); // process parent so any new content works
return runtime.findNext(this, context);
} else if(setter) {
context.result = (target || "") + value;
Expand Down Expand Up @@ -6856,7 +6847,7 @@
};
return takeCmd;
} else {
var takeCmd = {
var takeCmd2 = {
attributeRef: attributeRef,
from: fromExpr,
forElt: forExpr,
Expand All @@ -6877,7 +6868,7 @@
return runtime.findNext(this, context);
},
};
return takeCmd;
return takeCmd2;
}
}
});
Expand Down Expand Up @@ -7489,9 +7480,8 @@
if (conversion === "JSON") {
return JSON.stringify(result);
} else if (conversion === "Form") {
/** @ts-ignore */
// TODO: does this work with multiple inputs of the same name?
return new URLSearchParams(result).toString();
return new URLSearchParams(/** @type {Record<string, string>} */ (result)).toString();
} else {
throw "Unknown conversion: " + conversion;
}
Expand Down Expand Up @@ -7701,7 +7691,7 @@
* @property {(keyword: string, definition: ParseRule) => void} addLeafExpression
* @property {(keyword: string, definition: ParseRule) => void} addIndirectExpression
*
* @property {(src: string, ctx?: Partial<Context>) => any} evaluate
* @property {(src: string, ctx?: Partial<Context>, args?: Object) => any} evaluate
* @property {(src: string) => ASTNode} parse
* @property {(node: Element) => void} processNode
*
Expand Down
2 changes: 1 addition & 1 deletion src/deno-hyperscript.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

// @ts-nocheck
const tempModule = window.module, tempExports = window.exports;
window.module = {}, window.exports = {};
await import('./_hyperscript.js');
Expand Down
2 changes: 1 addition & 1 deletion src/eventsource.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ interface EventSourceStub {

interface EventListenerEntry {
type: string
handler: EventHandlerNonNull
handler: (event: Event) => void
options?: any
}
10 changes: 5 additions & 5 deletions src/eventsource.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
if (typeof exports === 'object' && typeof exports['nodeName'] !== 'string') {
module.exports = plugin
} else {
if ('_hyperscript' in self) self._hyperscript.use(plugin)
if ('_hyperscript' in self) /** @type {import('../dist/_hyperscript').Hyperscript} */ (self._hyperscript).use(plugin)
}
})(typeof self !== 'undefined' ? self : this, self => {
/**
* @param {import("./_hyperscript.js").Hyperscript} _hyperscript
* @param {import('../dist/_hyperscript').Hyperscript} _hyperscript
*/
return _hyperscript => {
_hyperscript.addFeature("eventsource", function (parser, runtime, tokens) {
Expand Down Expand Up @@ -171,7 +171,7 @@
*
* @param {string} encoding
* @param {*} commandList
* @returns {EventHandlerNonNull}
* @returns {(event: Event) => void}
*/
function makeHandler(encoding, commandList) {
return function (evt) {
Expand Down Expand Up @@ -218,10 +218,10 @@

commandList.next = {
type: "implicitReturn",
op: function (/** @type {Context} */ _context) {
op: function (/** @type {any} */ _context) {
return runtime.HALT;
},
execute: function (/** @type {Context} */ _context) {
execute: function (/** @type {any} */ _context) {
// do nothing
},
};
Expand Down
2 changes: 1 addition & 1 deletion src/hdb.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
if (typeof exports === 'object' && typeof exports['nodeName'] !== 'string') {
module.exports = plugin
} else {
if ('_hyperscript' in self) self._hyperscript.use(plugin)
if ('_hyperscript' in self) /** @type {import('../dist/_hyperscript').Hyperscript} */ (self._hyperscript).use(plugin)
}
})(typeof self !== 'undefined' ? self : this, self => {
return _hyperscript => {
Expand Down
4 changes: 2 additions & 2 deletions src/socket.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
if (typeof exports === 'object' && typeof exports['nodeName'] !== 'string') {
module.exports = plugin
} else {
if ('_hyperscript' in self) self._hyperscript.use(plugin)
if ('_hyperscript' in self) /** @type {import('../dist/_hyperscript').Hyperscript} */ (self._hyperscript).use(plugin)
}
})(typeof self !== 'undefined' ? self : this, self => {

Expand Down Expand Up @@ -36,7 +36,7 @@
}

/**
* @param {HyperscriptObject} _hyperscript
* @param {import('../dist/_hyperscript').Hyperscript} _hyperscript
*/
return _hyperscript => {

Expand Down
4 changes: 2 additions & 2 deletions src/template.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
if (typeof exports === 'object' && typeof exports['nodeName'] !== 'string') {
module.exports = plugin
} else {
if ('_hyperscript' in self) self._hyperscript.use(plugin)
if ('_hyperscript' in self) /** @type {import('../dist/_hyperscript').Hyperscript} */ (self._hyperscript).use(plugin)
}
})(typeof self !== 'undefined' ? self : this, self => {

Expand All @@ -16,7 +16,7 @@
}

/**
* @param {HyperscriptObject} _hyperscript
* @param {import('../dist/_hyperscript').Hyperscript} _hyperscript
*/
return _hyperscript => {

Expand Down
2 changes: 1 addition & 1 deletion src/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
if (typeof exports === 'object' && typeof exports['nodeName'] !== 'string') {
module.exports = plugin
} else {
if ('_hyperscript' in self) self._hyperscript.use(plugin)
if ('_hyperscript' in self) /** @type {import('../dist/_hyperscript').Hyperscript} */ (self._hyperscript).use(plugin)
}
})(typeof self !== 'undefined' ? self : this, self => {

Expand Down
2 changes: 1 addition & 1 deletion test/core/regressions.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ describe("_hyperscript regressions", function () {
var d1 = byId("d1");
setTimeout(function(){
d1.innerHTML.should.equal("here");
delete foo;
foo = null;
done();
}, 10)
});
Expand Down
4 changes: 3 additions & 1 deletion test/features/on.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,10 @@ describe("the on feature", function () {

it("can be in a top level script tag", function (done) {
var div = make(
"<script type='text/hyperscript'>on load put \"Loaded\" into #loadedDemo.innerHTML</script><div id='loadedDemo'></div>"
"<script type='text/hyperscript'>on customEvent put \"Loaded\" into #loadedDemo.innerHTML</script><div id='loadedDemo'></div>"
);
let event = new Event('customEvent', {bubbles: true});
div.dispatchEvent(event);
setTimeout(function () {
byId("loadedDemo").innerText.should.equal("Loaded");
done();
Expand Down
10 changes: 9 additions & 1 deletion test/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,15 @@ <h2>Mocha Test Suite</h2>
<script src="../src/ext/tailwind.js"></script>

<script class="mocha-init">
mocha.setup("bdd");
mocha.setup({
ui: "bdd",
rootHooks: {
beforeEach(done) {
console.log(`${this?.currentTest?.parent?.title} - ${this?.currentTest?.title}`)
done()
},
},
})
mocha.checkLeaks();
should = chai.should();
assert = chai.assert;
Expand Down
11 changes: 7 additions & 4 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@
"compilerOptions": {
"strict": false,
"checkJs": true,
"outDir": "dist/lib",
"target":"ES2015"
"allowJs": true,
"noEmit": true,
"lib": ["dom", "dom.iterable"],
"moduleResolution": "node",
"target": "ES2015"
},
"include": ["src/lib/*", "src/bin/*", "src/lib/plugin/socket.js", "src/lib/plugin/template.js", "src/lib/plugin/worker.js", "src/lib/plugin/web.js"],
"exclude": ["node_modules"],
"include": ["src/*.js"],
"exclude": ["src/deno-hyperscript.js"]
}
Loading