Skip to content

Isometric line figures that answer the pointer. For React and for anything with a DOM.

Skill: the validator's import check ends the keyword before the binding, so a name such as important or imported is not an import

Lucas Marquesce6df9538bb2
diff --git a/packages/hairline/test/skill/validate.test.ts b/packages/hairline/test/skill/validate.test.ts
index a689818..e61c863 100644
--- a/packages/hairline/test/skill/validate.test.ts
+++ b/packages/hairline/test/skill/validate.test.ts
@@ -61,6 +61,8 @@ const HONEST: [why: string, code: string][] = [
["a read-out with a number sign", 'const label = "pillar #101";'],
["the word import in a string", 'const note = "import";'],
["the word import inside a longer name", "const important = true;"],
+ ["a name that starts with import, before a comma", "const [important, b] = [1, 2];"],
+ ["a name that starts with import, as an argument", "f(imported, 1);"],
];
describe("honest additions that pass", () => {
@@ -87,6 +89,8 @@ const BROKEN: [id: string, why: string, figure: string, change?: (page: string)
["outside", "a node made by hand", plus('document.createElementNS("http://www.w3.org/2000/svg", "path");')],
["outside", "a script tag in a string", plus('const s = "</script>";')],
["outside", "an import statement", plus('import { x } from "./x.js";')],
+ ["outside", "a default import", plus('import x from "./x.js";')],
+ ["outside", "a namespace import", plus('import * as x from "./x.js";')],
["outside", "a dynamic import", plus('import("./x.js");')],
["outside", "a URL in a string", plus('const u = "https://example.com/a.json";')],
["clock", "its own frame", plus("requestAnimationFrame(() => {});")],
diff --git a/skills/hairline-create/validate.mjs b/skills/hairline-create/validate.mjs
index 6524933..5f06d90 100644
--- a/skills/hairline-create/validate.mjs
+++ b/skills/hairline-create/validate.mjs
@@ -83,7 +83,9 @@ const BAD = [
"rule 04. The figure sets a stroke width, colour, fill, filter, gradient or shadow of its own. Use the kernel's classes and nothing else: sil, hi, lo, nf, fo, dash, dot, dot m, dot off."],
["outside", /\bfetch\s*\(|XMLHttpRequest|WebSocket|EventSource|sendBeacon|https?:\/\/|\burl\(|<\/?script|<(?:link|img|iframe|style)\b|new\s+Image\b|createElement|\beval\s*\(|new\s+Function\b|localStorage|sessionStorage|\.cookie\b/,
"the figure reaches outside the file or makes nodes by hand. One self-contained file: no fetch, import, URL, script tag or storage, and every node comes from HL.mk.",
- /\bimport\s*(?:\(|["'`{*]|[\w$]+\s*(?:,|from\b))/],
+ // The keyword ends where the binding starts, so `important` or `imported` is a name, not an import.
+ // `import.meta` is left alone on purpose: by itself it reaches nothing outside the file.
+ /\bimport(?:\s*["'`({*]|\s+[\w$]+\s*(?:,|from\b))/],
["clock", /\bsetInterval\b|\bsetTimeout\b|\brequestAnimationFrame\b|\.animate\s*\(|<animate|IntersectionObserver|\bmatchMedia\b/,
"rule 07. The figure runs a clock of its own. Move inside HL.register(stage, tick), with springs (stepS) or tweens (tset, tval); a delay is a tween's delay. The loop sleeps offscreen and honours reduced motion for you."],
["hit", /getBoundingClientRect|elementFromPoint|elementsFromPoint|:hover|(?:addEventListener|\.on)\s*\(\s*(?:\w+\s*,\s*)?["'`](?:mouse|pointer|touch|click)|\bon(?:mouse|pointer|touch|click)\w*\s*=/,