Skip to content

Commit 58c1269

Browse files
author
elevatebart
committed
fix: remove attribute check
1 parent 966d593 commit 58c1269

File tree

3 files changed

+1
-149
lines changed

3 files changed

+1
-149
lines changed

src/utils/checkTemplate.spec.ts

+1-67
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ test("parse valid object not to throw", () => {
218218
).not.toThrow();
219219
});
220220

221-
test("parse expression using mutiple lines to throw", () => {
221+
test("parse expression using multiple lines to throw", () => {
222222
expect(() =>
223223
checkTemplate({
224224
template: `<div><CustomSelect @event="
@@ -301,69 +301,3 @@ test("parse v-for nested expressions and add their vars to available data", () =
301301
).not.toThrow();
302302
});
303303

304-
test("throw error when mixed case attributes", () => {
305-
expect(() =>
306-
checkTemplate({
307-
template: `<div aA="as">
308-
<div/>
309-
</div>`,
310-
})
311-
).toThrowError("[VueLive] Invalid attribute name: aA");
312-
});
313-
314-
test.each(defaultAttrAllowList)(
315-
"don't throw error for allowed SVG attribute %s",
316-
(attr) => {
317-
expect(() =>
318-
checkTemplate({
319-
template: `<svg ${attr}="as">
320-
<g/>
321-
</svg>`,
322-
})
323-
).not.toThrowError(`[VueLive] Invalid attribute name: ${attr}`);
324-
}
325-
);
326-
327-
test("throw error when invalid character attributes", () => {
328-
expect(() =>
329-
checkTemplate({
330-
template: `<div $s="as">
331-
<div/>
332-
</div>`,
333-
})
334-
).toThrowError("[VueLive] Invalid attribute name: $s");
335-
});
336-
337-
test("throw error when invalid character attributes $", () => {
338-
expect(() =>
339-
checkTemplate({
340-
template: `<div $s="as">
341-
<div/>
342-
</div>`,
343-
})
344-
).toThrowError("[VueLive] Invalid attribute name: $s");
345-
});
346-
347-
test("throw error when invalid character attributes +", () => {
348-
expect(() =>
349-
checkTemplate({
350-
template: `<div s+tata="as">
351-
<div/>
352-
</div>`,
353-
})
354-
).toThrowError("[VueLive] Invalid attribute name: s+tata");
355-
});
356-
357-
test("not error when all attributes are valid", () => {
358-
expect(() =>
359-
checkTemplate({
360-
template: `<div>
361-
<div ja-da="0" />
362-
<div v-bind:da="0" />
363-
<div v-on:da="0" />
364-
<div :da="0" />
365-
<div @da="co()" />
366-
</div>`,
367-
})
368-
).not.toThrow();
369-
});

src/utils/checkTemplate.ts

-14
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { parse as parseVue } from "@vue/compiler-dom";
22
import { createCompilerError } from "@vue/compiler-core";
33
import { parse as parseEs } from "acorn";
44
import { ancestor, simple } from "acorn-walk";
5-
import defaultAttrAllowList from "./defaultAttrAllowList";
65

76
const ELEMENT = 1;
87
const SIMPLE_EXPRESSION = 4;
@@ -66,10 +65,6 @@ export default function (
6665
...setupOutput,
6766
];
6867

69-
// Define list of attributes for which name check will be skipped. Defaults to known camelCased SVG attributes.
70-
// Allow future enhancement via $options.attrAllowList
71-
const attrAllowList = $options.attrAllowList || defaultAttrAllowList;
72-
7368
traverse(ast, [
7469
(templateAst: any, parentTemplateVars: any) => {
7570
const templateVars: string[] = [];
@@ -81,15 +76,6 @@ export default function (
8176
type: number;
8277
exp?: { content: string };
8378
}) => {
84-
if (
85-
!attrAllowList.includes(attr.name) &&
86-
!/^[a-z-:]+$/g.test(attr.name)
87-
) {
88-
throw new VueLiveParseTemplateAttrError(
89-
"[VueLive] Invalid attribute name: " + attr.name,
90-
attr.loc
91-
);
92-
}
9379
const exp =
9480
attr.type !== SIMPLE_EXPRESSION && attr.exp
9581
? attr.exp.content

src/utils/defaultAttrAllowList.ts

-68
This file was deleted.

0 commit comments

Comments
 (0)