-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathvalidateMarkup.js
More file actions
59 lines (56 loc) · 1.73 KB
/
validateMarkup.js
File metadata and controls
59 lines (56 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import { getOwnerStack } from './component-stack';
import { serializeVNode } from './debug';
/**
* @param {import('./internal').Internal} parent
* @returns {import('./internal').Internal | null}
*/
function getClosestDomNodeParent(parent) {
if (!parent) return null;
if (typeof parent.type == 'function') {
return getClosestDomNodeParent(parent._parent);
}
return parent;
}
/**
* @param {import('./internal').Internal} internal
* @return {void}
*/
export function validateTableMarkup(internal) {
const { type, _parent: parent } = internal;
const parentDomInternal = getClosestDomNodeParent(parent);
if (parentDomInternal === null) return;
if (
(type === 'thead' || type === 'tfoot' || type === 'tbody') &&
parentDomInternal.type !== 'table'
) {
console.error(
'Improper nesting of table. Your <thead/tbody/tfoot> should have a <table> parent.' +
serializeVNode(internal) +
`\n\n${getOwnerStack(internal)}`
);
} else if (
type === 'tr' &&
parentDomInternal.type !== 'thead' &&
parentDomInternal.type !== 'tfoot' &&
parentDomInternal.type !== 'tbody' &&
parentDomInternal.type !== 'table'
) {
console.error(
'Improper nesting of table. Your <tr> should have a <thead/tbody/tfoot/table> parent.' +
serializeVNode(internal) +
`\n\n${getOwnerStack(internal)}`
);
} else if (type === 'td' && parentDomInternal.type !== 'tr') {
console.error(
'Improper nesting of table. Your <td> should have a <tr> parent.' +
serializeVNode(internal) +
`\n\n${getOwnerStack(internal)}`
);
} else if (type === 'th' && parentDomInternal.type !== 'tr') {
console.error(
'Improper nesting of table. Your <th> should have a <tr>.' +
serializeVNode(internal) +
`\n\n${getOwnerStack(internal)}`
);
}
}