1
1
'use strict'
2
2
3
3
const fs = require ( 'fs' )
4
- const tsParser = require ( '@typescript-eslint/parser ' )
4
+ const jsdom = require ( 'jsdom ' )
5
5
const { httpGet } = require ( './lib/http' )
6
6
7
- /**
8
- * @typedef {import('@typescript-eslint/types').TSESTree.TSInterfaceDeclaration } TSInterfaceDeclaration
9
- */
10
-
11
7
main ( )
12
8
13
9
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
- } )
10
+ const [ bcdJson , obsoleteHtml ] = await Promise . all ( [
11
+ httpGet ( 'https://unpkg.com/@mdn/browser-compat-data/data.json' ) ,
12
+ httpGet ( 'https://html.spec.whatwg.org/multipage/obsolete.html' )
13
+ ] )
14
+ const bcd = JSON . parse ( bcdJson )
15
+
21
16
updateDeprecatedHTMLElements ( )
22
17
updateHTMLElements ( )
23
18
updateSVGElements ( )
@@ -30,15 +25,17 @@ async function main() {
30
25
'../lib/utils/deprecated-html-elements.json'
31
26
)
32
27
const elements = new Set ( )
33
- /** @type {TSInterfaceDeclaration } */
34
- const interfaceDeclaration = rootNode . body . find (
35
- ( body ) =>
36
- body . type === 'TSInterfaceDeclaration' &&
37
- body . id . name === 'HTMLElementDeprecatedTagNameMap'
28
+
29
+ const domDl = jsdom . JSDOM . fragment ( obsoleteHtml ) . querySelector (
30
+ '[id="non-conforming-features"] ~ dl'
38
31
)
32
+ for ( const code of domDl . querySelectorAll ( 'dt code' ) ) {
33
+ const name = code . textContent . trim ( )
34
+ if ( name ) elements . add ( name )
35
+ }
39
36
40
- for ( const name of extractPropNames ( interfaceDeclaration ) ) {
41
- elements . add ( name )
37
+ if ( elements . size === 0 ) {
38
+ throw new Error ( 'No deprecated HTML elements found' )
42
39
}
43
40
44
41
fs . writeFileSync (
@@ -59,20 +56,21 @@ async function main() {
59
56
const deprecatedHtmlElements = new Set (
60
57
require ( '../lib/utils/deprecated-html-elements.json' )
61
58
)
62
- /** @type {TSInterfaceDeclaration } */
63
- const interfaceDeclaration = rootNode . body . find (
64
- ( body ) =>
65
- body . type === 'TSInterfaceDeclaration' &&
66
- body . id . name === 'HTMLElementTagNameMap'
67
- )
68
59
69
- for ( const name of extractPropNames ( interfaceDeclaration ) ) {
60
+ for ( const [ name , element ] of Object . entries ( bcd . html . elements ) ) {
70
61
if ( deprecatedHtmlElements . has ( name ) ) {
71
62
continue
72
63
}
64
+ if ( element . __compat . status . deprecated ) {
65
+ continue
66
+ }
73
67
elements . add ( name )
74
68
}
75
69
70
+ if ( elements . size === 0 ) {
71
+ throw new Error ( 'No HTML elements found' )
72
+ }
73
+
76
74
fs . writeFileSync (
77
75
HTML_ELEMENTS_PATH ,
78
76
`${ JSON . stringify ( [ ...elements ] . sort ( ) , null , 2 ) } \n` ,
@@ -86,35 +84,22 @@ async function main() {
86
84
function updateSVGElements ( ) {
87
85
const SVG_ELEMENTS_PATH = require . resolve ( '../lib/utils/svg-elements.json' )
88
86
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
87
96
- for ( const name of extractPropNames ( interfaceDeclaration ) ) {
88
+ for ( const [ name , element ] of Object . entries ( bcd . svg . elements ) ) {
89
+ if ( element . __compat . status . deprecated ) {
90
+ continue
91
+ }
97
92
elements . add ( name )
98
93
}
99
94
95
+ if ( elements . size === 0 ) {
96
+ throw new Error ( 'No SVG elements found' )
97
+ }
98
+
100
99
fs . writeFileSync (
101
100
SVG_ELEMENTS_PATH ,
102
101
`${ JSON . stringify ( [ ...elements ] . sort ( ) , null , 2 ) } \n` ,
103
102
'utf8'
104
103
)
105
104
}
106
105
}
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