diff --git a/README.md b/README.md index 301c249..dedc1c2 100644 --- a/README.md +++ b/README.md @@ -369,4 +369,4 @@ Special handling of some attributes require case sensitive names and values. For `script` and `style` tags must be closed with `` and `` respectively (case sensitive). -[hyperbuild can handle text script content.](./notes/Text%20script%20content.md) +[hyperbuild can handle escaped and double-escaped script content.](./notes/Script%20data.md) diff --git a/bench/bench.js b/bench/bench.js index 5b8eec5..301f822 100644 --- a/bench/bench.js +++ b/bench/bench.js @@ -57,7 +57,7 @@ const setSize = (program, test, result) => { for (const t of tests) { for (const p of Object.keys(programs)) { try { - setSize(p, t.name, programs[p](t.content).length); + setSize(p, t.name, programs[p](t.contentAsString, t.contentAsBuffer).length); } catch (err) { console.error(`Failed to run ${p} on test ${t.name}:`); console.error(err); @@ -72,7 +72,7 @@ const runTest = test => new Promise((resolve, reject) => { const suite = new benchmark.Suite(); for (const p of Object.keys(programs)) { suite.add(p, () => { - programs[p](test.content); + programs[p](test.contentAsString, test.contentAsBuffer); }); } suite diff --git a/bench/build.sh b/bench/build.sh index c13510c..e2fdf11 100755 --- a/bench/build.sh +++ b/bench/build.sh @@ -7,7 +7,11 @@ pushd "$(dirname "$0")" nodejs_cargo_toml="../nodejs/native/Cargo.toml" rm -rf node_modules -cp "$nodejs_cargo_toml" "$nodejs_cargo_toml.orig" +if [ -f "$nodejs_cargo_toml.orig" ]; then + echo 'Not altering Node.js Cargo.toml file' +else + cp "$nodejs_cargo_toml" "$nodejs_cargo_toml.orig" +fi sed -i 's%^hyperbuild = .*$%hyperbuild = { path = "../.." }%' "$nodejs_cargo_toml" HYPERBUILD_NODEJS_SKIP_BIN_DOWNLOAD=1 npm i mv "$nodejs_cargo_toml.orig" "$nodejs_cargo_toml" diff --git a/bench/minifiers.js b/bench/minifiers.js index 7561f4f..b3a3d04 100644 --- a/bench/minifiers.js +++ b/bench/minifiers.js @@ -3,7 +3,7 @@ const hyperbuild = require("hyperbuild"); const minimize = require("minimize"); module.exports = { - 'hyperbuild-nodejs': content => hyperbuild.minify(content), + 'hyperbuild-nodejs': (_, buffer) => hyperbuild.minify_in_place(Buffer.from(buffer)), 'html-minifier': content => htmlMinifier.minify(content, { collapseBooleanAttributes: true, collapseInlineTagWhitespace: true, diff --git a/bench/tests.js b/bench/tests.js index 3385756..ffc1dda 100644 --- a/bench/tests.js +++ b/bench/tests.js @@ -4,5 +4,6 @@ const path = require('path'); const testsDir = path.join(__dirname, 'tests'); module.exports = fs.readdirSync(testsDir).map(name => ({ name, - content: fs.readFileSync(path.join(testsDir, name), 'utf8'), + contentAsString: fs.readFileSync(path.join(testsDir, name), 'utf8'), + contentAsBuffer: fs.readFileSync(path.join(testsDir, name)), })).sort((a, b) => a.name.localeCompare(b.name)); diff --git a/gen/build/dom.js b/gen/build/dom.js index ceefc23..1660ed4 100644 --- a/gen/build/dom.js +++ b/gen/build/dom.js @@ -23,25 +23,16 @@ const fetchReactTypingsSource = async () => { }; const processReactTypeDeclarations = async (source) => { - let tagNameToInterfaceMap; let booleanAttributes = new Map(); const unvisited = [source]; while (unvisited.length) { const node = unvisited.shift(); - let matches; switch (node.kind) { case ts.SyntaxKind.InterfaceDeclaration: const name = node.name.escapedText; - if (name === "ReactHTML") { - // Each member of ReactHTML looks something like: - // - // area: DetailedHTMLFactory, HTMLAreaElement>; - // ^^^^ [1] ^^^^^^^^^^^^^^^ [2] - // - // Get mapping from tag name [1] to interface name [2]. - tagNameToInterfaceMap = Object.fromEntries(node.members.map(m => [m.name.escapedText, m.type.typeArguments[1].typeName.escapedText])); - } else if ((matches = /^([A-Za-z]+)HTMLAttributes/.exec(name))) { + let matches; + if ((matches = /^([A-Za-z]+)HTMLAttributes/.exec(name))) { const tagName = matches[1].toLowerCase(); if (!['all', 'webview'].includes(tagName)) { node.members diff --git a/gen/patterns.json b/gen/patterns.json index 33e5ed0..bf5c4ce 100644 --- a/gen/patterns.json +++ b/gen/patterns.json @@ -1,6 +1,5 @@ { "COMMENT_END": "-->", - "SCRIPT_END": "" } diff --git a/nodejs/lib/index.js b/nodejs/lib/index.js index 83b4ddd..c152c50 100644 --- a/nodejs/lib/index.js +++ b/nodejs/lib/index.js @@ -6,5 +6,9 @@ module.exports = { const len = hyperbuild.minify(buf); return buf.slice(0, len).toString(); }, - minify_in_place: hyperbuild.minify, + minify_in_place: buf => { + const len = hyperbuild.minify(buf); + // This does not do a copy. + return buf.slice(0, len); + }, }; diff --git a/notes/Text script content.md b/notes/Script data.md similarity index 93% rename from notes/Text script content.md rename to notes/Script data.md index 91849d6..acb5776 100644 --- a/notes/Text script content.md +++ b/notes/Script data.md @@ -1,4 +1,6 @@ -# Text script content +# Script data + +For legacy reasons, special handling is required for content inside a script tag; see https://www.w3.org/TR/html52/syntax.html#script-data-state for more details. ```html