Skip to content

Commit 8c9935f

Browse files
committed
Add update-resources script
1 parent 659a50f commit 8c9935f

9 files changed

+366
-39
lines changed

Diff for: lib/utils/deprecated-html-elements.json

+31-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,31 @@
1-
["acronym","applet","basefont","bgsound","big","blink","center","command","content","dir","element","font","frame","frameset","image","isindex","keygen","listing","marquee","menuitem","multicol","nextid","nobr","noembed","noframes","plaintext","shadow","spacer","strike","tt","xmp"]
1+
[
2+
"acronym",
3+
"applet",
4+
"basefont",
5+
"bgsound",
6+
"big",
7+
"blink",
8+
"center",
9+
"dir",
10+
"font",
11+
"frame",
12+
"frameset",
13+
"isindex",
14+
"keygen",
15+
"listing",
16+
"marquee",
17+
"menuitem",
18+
"multicol",
19+
"nextid",
20+
"nobr",
21+
"noembed",
22+
"noframes",
23+
"param",
24+
"plaintext",
25+
"rb",
26+
"rtc",
27+
"spacer",
28+
"strike",
29+
"tt",
30+
"xmp"
31+
]

Diff for: lib/utils/html-elements.json

+113-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,113 @@
1-
["html","body","base","head","link","meta","style","title","address","article","aside","footer","header","h1","h2","h3","h4","h5","h6","hgroup","nav","section","div","dd","dl","dt","figcaption","figure","hr","img","li","main","ol","p","pre","ul","a","b","abbr","bdi","bdo","br","cite","code","data","dfn","em","i","kbd","mark","q","rp","rt","rtc","ruby","s","samp","small","span","strong","sub","sup","time","u","var","wbr","area","audio","map","track","video","embed","object","param","source","canvas","script","noscript","del","ins","caption","col","colgroup","table","thead","tbody","tfoot","td","th","tr","button","datalist","fieldset","form","input","label","legend","meter","optgroup","option","output","progress","select","textarea","details","dialog","menu","menuitem","summary","content","element","shadow","template","slot","blockquote","iframe","noframes","picture"]
1+
[
2+
"a",
3+
"abbr",
4+
"address",
5+
"area",
6+
"article",
7+
"aside",
8+
"audio",
9+
"b",
10+
"base",
11+
"bdi",
12+
"bdo",
13+
"blockquote",
14+
"body",
15+
"br",
16+
"button",
17+
"canvas",
18+
"caption",
19+
"cite",
20+
"code",
21+
"col",
22+
"colgroup",
23+
"data",
24+
"datalist",
25+
"dd",
26+
"del",
27+
"details",
28+
"dfn",
29+
"dialog",
30+
"div",
31+
"dl",
32+
"dt",
33+
"em",
34+
"embed",
35+
"fieldset",
36+
"figcaption",
37+
"figure",
38+
"footer",
39+
"form",
40+
"h1",
41+
"h2",
42+
"h3",
43+
"h4",
44+
"h5",
45+
"h6",
46+
"head",
47+
"header",
48+
"hgroup",
49+
"hr",
50+
"html",
51+
"i",
52+
"iframe",
53+
"img",
54+
"input",
55+
"ins",
56+
"kbd",
57+
"label",
58+
"legend",
59+
"li",
60+
"link",
61+
"main",
62+
"map",
63+
"mark",
64+
"menu",
65+
"meta",
66+
"meter",
67+
"nav",
68+
"noscript",
69+
"object",
70+
"ol",
71+
"optgroup",
72+
"option",
73+
"output",
74+
"p",
75+
"picture",
76+
"pre",
77+
"progress",
78+
"q",
79+
"rp",
80+
"rt",
81+
"ruby",
82+
"s",
83+
"samp",
84+
"script",
85+
"section",
86+
"select",
87+
"slot",
88+
"small",
89+
"source",
90+
"span",
91+
"strong",
92+
"style",
93+
"sub",
94+
"summary",
95+
"sup",
96+
"table",
97+
"tbody",
98+
"td",
99+
"template",
100+
"textarea",
101+
"tfoot",
102+
"th",
103+
"thead",
104+
"time",
105+
"title",
106+
"tr",
107+
"track",
108+
"u",
109+
"ul",
110+
"var",
111+
"video",
112+
"wbr"
113+
]

Diff for: lib/utils/svg-elements.json

+65-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,65 @@
1-
["a","animate","animateMotion","animateTransform","audio","canvas","circle","clipPath","defs","desc","discard","ellipse","feBlend","feColorMatrix","feComponentTransfer","feComposite","feConvolveMatrix","feDiffuseLighting","feDisplacementMap","feDistantLight","feDropShadow","feFlood","feFuncA","feFuncB","feFuncG","feFuncR","feGaussianBlur","feImage","feMerge","feMergeNode","feMorphology","feOffset","fePointLight","feSpecularLighting","feSpotLight","feTile","feTurbulence","filter","foreignObject","g","iframe","image","line","linearGradient","marker","mask","metadata","mpath","path","pattern","polygon","polyline","radialGradient","rect","script","set","stop","style","svg","switch","symbol","text","textPath","title","tspan","unknown","use","video","view"]
1+
[
2+
"a",
3+
"animate",
4+
"animateMotion",
5+
"animateTransform",
6+
"circle",
7+
"clipPath",
8+
"defs",
9+
"desc",
10+
"ellipse",
11+
"feBlend",
12+
"feColorMatrix",
13+
"feComponentTransfer",
14+
"feComposite",
15+
"feConvolveMatrix",
16+
"feDiffuseLighting",
17+
"feDisplacementMap",
18+
"feDistantLight",
19+
"feDropShadow",
20+
"feFlood",
21+
"feFuncA",
22+
"feFuncB",
23+
"feFuncG",
24+
"feFuncR",
25+
"feGaussianBlur",
26+
"feImage",
27+
"feMerge",
28+
"feMergeNode",
29+
"feMorphology",
30+
"feOffset",
31+
"fePointLight",
32+
"feSpecularLighting",
33+
"feSpotLight",
34+
"feTile",
35+
"feTurbulence",
36+
"filter",
37+
"foreignObject",
38+
"g",
39+
"image",
40+
"line",
41+
"linearGradient",
42+
"marker",
43+
"mask",
44+
"metadata",
45+
"mpath",
46+
"path",
47+
"pattern",
48+
"polygon",
49+
"polyline",
50+
"radialGradient",
51+
"rect",
52+
"script",
53+
"set",
54+
"stop",
55+
"style",
56+
"svg",
57+
"switch",
58+
"symbol",
59+
"text",
60+
"textPath",
61+
"title",
62+
"tspan",
63+
"use",
64+
"view"
65+
]

Diff for: package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989
"mocha": "^10.0.0",
9090
"nyc": "^15.1.0",
9191
"prettier": "^2.6.2",
92-
"typescript": "^4.9.3",
92+
"typescript": "^5.0.4",
9393
"vitepress": "^1.0.0-alpha.29"
9494
}
9595
}

Diff for: tests/lib/rules/no-reserved-component-names.js

-4
Original file line numberDiff line numberDiff line change
@@ -279,8 +279,6 @@ const invalidElements = [
279279
'Defs',
280280
'desc',
281281
'Desc',
282-
'discard',
283-
'Discard',
284282
'ellipse',
285283
'Ellipse',
286284
'feBlend',
@@ -352,8 +350,6 @@ const invalidElements = [
352350
'textPath',
353351
'tspan',
354352
'Tspan',
355-
'unknown',
356-
'Unknown',
357353
'use',
358354
'Use',
359355
'view',

Diff for: tools/lib/http.js

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
const https = require('https')
2+
const { URL } = require('url')
3+
4+
module.exports = {
5+
httpGet
6+
}
7+
function httpGet(url) {
8+
return new Promise((resolve, reject) => {
9+
let result = ''
10+
https
11+
.get(url, (res) => {
12+
if (res.statusCode && res.statusCode >= 300 && res.statusCode < 400) {
13+
// redirect
14+
let redirectUrl = res.headers.location
15+
if (!redirectUrl.startsWith('http')) {
16+
const baseUrl = new URL(url)
17+
baseUrl.pathname = redirectUrl
18+
redirectUrl = String(baseUrl)
19+
}
20+
resolve(httpGet(redirectUrl))
21+
return
22+
}
23+
res.setEncoding('utf8')
24+
res.on('data', (chunk) => {
25+
result += String(chunk)
26+
})
27+
res.on('end', () => {
28+
resolve(result)
29+
})
30+
res.on('error', reject)
31+
})
32+
.on('error', reject)
33+
})
34+
}

Diff for: tools/update-resources.js

+120
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
'use strict'
2+
3+
const fs = require('fs')
4+
const tsParser = require('@typescript-eslint/parser')
5+
const { httpGet } = require('./lib/http')
6+
7+
/**
8+
* @typedef {import('@typescript-eslint/types').TSESTree.TSInterfaceDeclaration} TSInterfaceDeclaration
9+
*/
10+
11+
main()
12+
13+
async function main() {
14+
const libDomDTsText = await httpGet(
15+
'https://unpkg.com/typescript/lib/lib.dom.d.ts'
16+
)
17+
const rootNode = tsParser.parse(libDomDTsText, {
18+
loc: true,
19+
range: true
20+
})
21+
updateDeprecatedHTMLElements()
22+
updateHTMLElements()
23+
updateSVGElements()
24+
25+
// ------------------------------------------------------------------------------
26+
// Update deprecated-html-elements.json
27+
// ------------------------------------------------------------------------------
28+
function updateDeprecatedHTMLElements() {
29+
const DEPRECATED_HTML_ELEMENTS_PATH = require.resolve(
30+
'../lib/utils/deprecated-html-elements.json'
31+
)
32+
const elements = new Set()
33+
/** @type {TSInterfaceDeclaration} */
34+
const interfaceDeclaration = rootNode.body.find(
35+
(body) =>
36+
body.type === 'TSInterfaceDeclaration' &&
37+
body.id.name === 'HTMLElementDeprecatedTagNameMap'
38+
)
39+
40+
for (const name of extractPropNames(interfaceDeclaration)) {
41+
elements.add(name)
42+
}
43+
44+
fs.writeFileSync(
45+
DEPRECATED_HTML_ELEMENTS_PATH,
46+
`${JSON.stringify([...elements].sort(), null, 2)}\n`,
47+
'utf8'
48+
)
49+
}
50+
51+
// ------------------------------------------------------------------------------
52+
// Update html-elements.json
53+
// ------------------------------------------------------------------------------
54+
function updateHTMLElements() {
55+
const HTML_ELEMENTS_PATH = require.resolve(
56+
'../lib/utils/html-elements.json'
57+
)
58+
const elements = new Set()
59+
const deprecatedHtmlElements = new Set(
60+
require('../lib/utils/deprecated-html-elements.json')
61+
)
62+
/** @type {TSInterfaceDeclaration} */
63+
const interfaceDeclaration = rootNode.body.find(
64+
(body) =>
65+
body.type === 'TSInterfaceDeclaration' &&
66+
body.id.name === 'HTMLElementTagNameMap'
67+
)
68+
69+
for (const name of extractPropNames(interfaceDeclaration)) {
70+
if (deprecatedHtmlElements.has(name)) {
71+
continue
72+
}
73+
elements.add(name)
74+
}
75+
76+
fs.writeFileSync(
77+
HTML_ELEMENTS_PATH,
78+
`${JSON.stringify([...elements].sort(), null, 2)}\n`,
79+
'utf8'
80+
)
81+
}
82+
83+
// ------------------------------------------------------------------------------
84+
// Update svg-elements.json
85+
// ------------------------------------------------------------------------------
86+
function updateSVGElements() {
87+
const SVG_ELEMENTS_PATH = require.resolve('../lib/utils/svg-elements.json')
88+
const elements = new Set()
89+
/** @type {TSInterfaceDeclaration} */
90+
const interfaceDeclaration = rootNode.body.find(
91+
(body) =>
92+
body.type === 'TSInterfaceDeclaration' &&
93+
body.id.name === 'SVGElementTagNameMap'
94+
)
95+
96+
for (const name of extractPropNames(interfaceDeclaration)) {
97+
elements.add(name)
98+
}
99+
100+
fs.writeFileSync(
101+
SVG_ELEMENTS_PATH,
102+
`${JSON.stringify([...elements].sort(), null, 2)}\n`,
103+
'utf8'
104+
)
105+
}
106+
}
107+
108+
/**
109+
* @param {TSInterfaceDeclaration} node
110+
*/
111+
function* extractPropNames(node) {
112+
for (const m of node.body.body) {
113+
if (
114+
(m.type === 'TSPropertySignature' || m.type === 'TSMethodSignature') &&
115+
(m.key.type === 'Identifier' || m.key.type === 'Literal')
116+
) {
117+
yield m.key.type === 'Identifier' ? m.key.name : `${m.key.value}`
118+
}
119+
}
120+
}

0 commit comments

Comments
 (0)