[IMP] components: crash when using unknown suffix/modifiers

This commit is contained in:
Géry Debongnie
2022-01-19 11:35:34 +01:00
committed by Aaron Bohy
parent a2e8abc243
commit 89d63ff29a
4 changed files with 35 additions and 5 deletions
+9 -1
View File
@@ -39,6 +39,7 @@ export interface CodeGenOptions extends Config {
// of HTML (as we will parse it as xml later)
const xmlDoc = document.implementation.createDocument(null, null, null);
const MODS = new Set(["stop", "capture", "prevent", "self", "synthetic"]);
// -----------------------------------------------------------------------------
// BlockDescription
// -----------------------------------------------------------------------------
@@ -504,7 +505,12 @@ export class CodeGenerator {
const modifiers = rawEvent
.split(".")
.slice(1)
.map((m) => `"${m}"`);
.map((m) => {
if (!MODS.has(m)) {
throw new Error(`Unknown event modifier: '${m}'`);
}
return `"${m}"`;
});
let modifiersCode = "";
if (modifiers.length) {
modifiersCode = `${modifiers.join(",")}, `;
@@ -1022,6 +1028,8 @@ export class CodeGenerator {
this.helpers.add("bind");
propName = name;
propValue = `bind(ctx, ${propValue})`;
} else {
throw new Error("Invalid prop suffix");
}
}
propName = /^[a-z_]+$/i.test(propName) ? propName : `'${propName}'`;