Skip to content
Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/pr-create-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ permissions:
jobs:
comment:
# Don't auto-close actual release PRs
if: ${{github.actor != 'JAForbes' || !contains(github.event.issue.title, "Release - v")}}
if: ${{github.actor != 'JAForbes' || !contains(github.event.issue.title, 'Release - v')}}
uses: MithrilJS/infra/.github/workflows/reject-pr.yml@main
secrets: inherit
64 changes: 64 additions & 0 deletions render/tests/test-normalizeChildren.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,68 @@ o.spec("normalizeChildren", function() {
])
}).throws(TypeError)
})
o("disallows mixed keys, ending with null", function() {
o(function() {
Vnode.normalizeChildren([
{key: 1},
null,
])
}).throws(TypeError)
})
o("disallows mixed keys, starting with null", function() {
o(function() {
Vnode.normalizeChildren([
null,
{key: 2},
])
}).throws(TypeError)
})
o("disallows mixed keys, ending with undefined", function() {
o(function() {
Vnode.normalizeChildren([
{key: 1},
undefined,
])
}).throws(TypeError)
})
o("disallows mixed keys, starting with undefined", function() {
o(function() {
Vnode.normalizeChildren([
undefined,
{key: 2},
])
}).throws(TypeError)
})
o("disallows mixed keys, ending with false", function() {
o(function() {
Vnode.normalizeChildren([
{key: 1},
false,
])
}).throws(TypeError)
})
o("disallows mixed keys, starting with false", function() {
o(function() {
Vnode.normalizeChildren([
false,
{key: 2},
])
}).throws(TypeError)
})
o("disallows mixed keys, ending with true", function() {
o(function() {
Vnode.normalizeChildren([
{key: 1},
true,
])
}).throws(TypeError)
})
o("disallows mixed keys, starting with true", function() {
o(function() {
Vnode.normalizeChildren([
true,
{key: 2},
])
}).throws(TypeError)
})
})
2 changes: 1 addition & 1 deletion render/vnode.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Vnode.normalizeChildren = function(input) {
for (var i = 1; i < input.length; i++) {
if ((input[i] != null && input[i].key != null) !== isKeyed) {
throw new TypeError(
isKeyed && (input[i] != null || typeof input[i] === "boolean")
isKeyed && (input[i] == null || typeof input[i] === "boolean")
? "In fragments, vnodes must either all have keys or none have keys. You may wish to consider using an explicit keyed empty fragment, m.fragment({key: ...}), instead of a hole."
: "In fragments, vnodes must either all have keys or none have keys."
)
Expand Down
10 changes: 9 additions & 1 deletion scripts/_bundler-impl.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ module.exports = async (input) => {
const include = /(?:((?:var|let|const|,|)[\t ]*)([\w_$\.\[\]"'`]+)(\s*=\s*))?require\(([^\)]+)\)(\s*[`\.\(\[])?/gm
let uuid = 0
async function process(filepath, data) {
for (const [, binding] of matchAll(data, declaration)) bindings.set(binding, 0)
for (const [, binding] of matchAll(data, declaration)) {
if (!bindings.has(binding)) bindings.set(binding, 0)
}

const tasks = []

Expand Down Expand Up @@ -164,6 +166,12 @@ module.exports = async (input) => {
return pre + b.replace(/\d+$/, "") + post
})

// fix comment‑only lines
const commentOnlyLines = /^(?:[ \t]*\/\/[^\r\n]*|[ \t]*\/\*[\s\S]*?\*\/[ \t]*)\r?$/gm
code = code.replace(commentOnlyLines, (comment) =>
comment.replace(variables, (match) => match.replace(/\d+$/, ""))
)

return code
.replace(/("|')use strict\1;?/gm, "") // remove extraneous "use strict"
.replace(/module\.exports\s*=\s*/gm, escapeReplace(rest ? `var _${uuid}` + eq : def + (rest ? "_" : "") + variable + eq)) // export
Expand Down
75 changes: 75 additions & 0 deletions scripts/tests/test-bundler.js
Original file line number Diff line number Diff line change
Expand Up @@ -293,4 +293,79 @@ o.spec("bundler", async () => {

o(await bundle(p("a.js"))).equals(";(function() {\nvar b0 = {b: 1}\nvar b = function() {return b0.b}\n}());")
})
o.spec("fix comments", () => {
o("fix /* */ comments", async () => {
await setup({
"a.js": 'var b = require("./b")\nvar c = require("./c")',
"b.js": "var a = 1\nmodule.exports = a",
"c.js": "var a = 2\n/* a */\nmodule.exports = a",
})

o(await bundle(p("a.js"))).equals(";(function() {\nvar a = 1\nvar b = a\nvar a0 = 2\n/* a */\nvar c = a0\n}());")
})
o("fix // comments", async () => {
await setup({
"a.js": 'var b = require("./b")\nvar c = require("./c")',
"b.js": "var a = 1\nmodule.exports = a",
"c.js": "var a = 2\n// a\nmodule.exports = a",
})

o(await bundle(p("a.js"))).equals(";(function() {\nvar a = 1\nvar b = a\nvar a0 = 2\n// a\nvar c = a0\n}());")
})
o("fix multi-line /* */ comments", async () => {
await setup({
"a.js": 'var b = require("./b")\nvar c = require("./c")',
"b.js": "var a = 1\nmodule.exports = a",
"c.js": "var a = 2\n/* \na */\nmodule.exports = a",
})

o(await bundle(p("a.js"))).equals(";(function() {\nvar a = 1\nvar b = a\nvar a0 = 2\n/* \na */\nvar c = a0\n}());")
})
o("does not fix trailing /* */ comments", async () => {
await setup({
"a.js": 'var b = require("./b")\nvar c = require("./c")',
"b.js": "var a = 1\nmodule.exports = a",
"c.js": "var a = 2/* a */\nmodule.exports = a",
})

o(await bundle(p("a.js"))).equals(";(function() {\nvar a = 1\nvar b = a\nvar a0 = 2/* a0 */\nvar c = a0\n}());")
})
o("does not fix trailing // comments", async () => {
await setup({
"a.js": 'var b = require("./b")\nvar c = require("./c")',
"b.js": "var a = 1\nmodule.exports = a",
"c.js": "var a = 2// a\nmodule.exports = a",
})

o(await bundle(p("a.js"))).equals(";(function() {\nvar a = 1\nvar b = a\nvar a0 = 2// a0\nvar c = a0\n}());")
})
o("does not fix trailing multi-line /* */ comments", async () => {
await setup({
"a.js": 'var b = require("./b")\nvar c = require("./c")',
"b.js": "var a = 1\nmodule.exports = a",
"c.js": "var a = 2/* \na */\nmodule.exports = a",
})

o(await bundle(p("a.js"))).equals(";(function() {\nvar a = 1\nvar b = a\nvar a0 = 2/* \na0 */\nvar c = a0\n}());")
})
})
o("prevents double suffixes (mountRedraw00)", async () => {
await setup({
// /index.js (request(b), mount-redraw(z), route(c))
"a.js": 'var b = require("./b")\nvar z = require("./z")\nvar c = require("./c")',
// /request.js
"b.js": 'var z = require("./z")\nmodule.exports = require("./p")(z)',
// /route.js
"c.js": 'var z = require("./z")\nmodule.exports = require("./q")(z)',
// /request/request.js
"p.js": "module.exports = function(z){}",
// /api/router.js
"q.js": "module.exports = function(z){}",
// /mount-redraw.js
"z.js": "module.exports = {}",
})

// check that the argument z2 is not z00
o(await bundle(p("a.js"))).equals(";(function() {\nvar z0 = {}\nvar _1 = function(z1){}\nvar b = _1(z0)\nvar z = z0\nvar _5 = function(z2){}\nvar c = _5(z)\n}());")
})
})