Skip to content

Commit be34ece

Browse files
author
Song Gao
committed
beta version.
1 parent 13b6f3a commit be34ece

File tree

10 files changed

+266
-9
lines changed

10 files changed

+266
-9
lines changed

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ The common steps to send a pull request are:
5353

5454
### What are the TypeScript team's heuristics for PRs to the DOM APIs
5555

56-
Changes to this repo can have pretty drastic ecosystem effects, because these types are included by default in TypeScript.
56+
Changes to this repo can have pretty drastic ecosystem effects, because these types are included by default in TypeScript.
5757
Due to this, we tend to be quite conservative with our approach to introducing changes.
58-
To give you a sense of whether we will accept changes, you can use these heuristics to know up-front if we'll be open to merging.
58+
To give you a sense of whether we will accept changes, you can use these heuristics to know up-front if we'll be open to merging.
5959

6060
#### Fixes
6161

@@ -71,9 +71,9 @@ To give you a sense of whether we will accept changes, you can use these heurist
7171
> For example, adding a new spec or subsection via a new or updated IDL file
7272
7373
- Does the new objects or fields show up in [mdn/browser-compat-data](https://github.com/mdn/browser-compat-data)? If not, it's likely too soon.
74-
- Is the IDL source from WHATWG?
74+
- Is the IDL source from WHATWG?
7575
- Are the additions available in at least two of Firefox, Safari and Chromium?
76-
- Is the IDL source from W3C?
76+
- Is the IDL source from W3C?
7777
- What stage of the [W3C process](https://en.wikipedia.org/wiki/World_Wide_Web_Consortium#Specification_maturation) is the proposal for these changes: We aim for Proposed recommendation, but can accept Candidate recommendation for stable looking proposals.
7878
- If it's at Working draft the additions available in all three of Firefox, Safari and Chromium
7979
- Could any types added at the global scope have naming conflicts?
@@ -103,3 +103,4 @@ To give you a sense of whether we will accept changes, you can use these heurist
103103
- `overridingTypes.json`: types that are defined in the spec file but has a better or more up-to-date definitions in the json files.
104104
- `removedTypes.json`: types that are defined in the spec file but should be removed.
105105
- `comments.json`: comment strings to be embedded in the generated .js files.
106+
- `deprecatedMessage.json`: the reason why one type is deprecated. The reason why it is a sprecate file rather than merge in comment.json is mdn/apiDescriptions.json would also possiably be deprecated.

inputfiles/deprecatedMessage.json

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"MutationEvent": "DOM4 [DOM] provides a new mechanism using a MutationObserver interface which addresses the use cases that mutation events solve, but in a more performant manner. Thus, this specification describes mutation events for reference and completeness of legacy behavior, but deprecates the use of the MutationEvent interface.",
3+
"IDBFactorySync": " The synchronous version of the IndexedDB API was originally intended for use only with Web Workers, and was eventually removed from the spec because its need was questionable. It may however be reintroduced in the future if there is enough demand from web developers.",
4+
"MouseScrollEvent": "Do not use this interface for wheel events.\n\nLike MouseWheelEvent, this interface is non-standard and deprecated. It was used in Gecko-based browsers only. Instead use the standard WheelEvent.\n",
5+
"SVGExternalResourcesRequired": " This interface was removed in the SVG 2 specification.",
6+
"IDBCursorSync": " The synchronous version of the IndexedDB API was originally intended for use only with Web Workers, and was eventually removed from the spec because its need was questionable. It may however be reintroduced in the future if there is enough demand from web developers.",
7+
"IDBTransactionSync": " The synchronous version of the IndexedDB API was originally intended for use only with Web Workers, and was eventually removed from the spec because its need was questionable. It may however be reintroduced in the future if there is enough demand from web developers.",
8+
"IDBEnvironmentSync": " The synchronous version of the IndexedDB API was originally intended for use only with Web Workers, and was eventually removed from the spec because its need was questionable. It may however be reintroduced in the future if there is enough demand from web developers.",
9+
"SVGAltGlyphDefElement": " This interface was removed in the SVG 2 specification.",
10+
"IDBVersionChangeRequest": " The latest specification does not include this interface anymore as the IDBDatabase.setVersion() method has been removed. See the compatibility table for version details.The new way to do it is to use the IDBOpenDBRequest interface which has now the onblocked handler and the newly needed onupgradeneeded one.",
11+
"IDBDatabaseException": " This interface was removed from the specification and was replaced by usage of DOMException.",
12+
"FileError": " This interface is obsolete per the latest specification. Use the new DOM4 DOMError interface instead.",
13+
"IDBObjectStoreSync": " The synchronous version of the IndexedDB API was originally intended for use only with Web Workers, and was eventually removed from the spec because its need was questionable. It may however be reintroduced in the future if there is enough demand from web developers.",
14+
"LocalMediaStream": " This interface is no longer available in any mainstream browser. Do not use LocalMediaStream; you need to update any code that does use it as soon as possible or your content or application will stop working. See Stopping a video stream in MediaStreamTrack to learn how. All other functionality is found in MediaStream.",
15+
"SVGAltGlyphItemElement": " This interface was removed in the SVG 2 specification.",
16+
"SVGGlyphElement": " This interface was removed in the SVG 2 specification.",
17+
"SVGRenderingIntent": " This interface was removed in the SVG 2 specification.",
18+
"BlobBuilder": " The BlobBuilder interface has been deprecated in favor of the newly introduced Blob constructor.",
19+
"MouseWheelEvent": "Do not use this interface for wheel events.\n\nLike MouseScrollEvent, this interface is non-standard and deprecated. It was used in non-Gecko browsers only. Instead use the standard WheelEvent.\n",
20+
"ServiceWorkerMessageEvent": " In modern browsers, this interface has been deprecated. Service worker messages will now use the MessageEvent interface, for consistency with other web messaging features.",
21+
"ScriptProcessorNode": " As of the August 29 2014 Web Audio API spec publication, this feature has been marked as deprecated, and was replaced by AudioWorklet (see AudioWorkletNode).",
22+
"IDBIndexSync": " The synchronous version of the IndexedDB API was originally intended for use only with Web Workers, and was eventually removed from the spec because its need was questionable. It may however be reintroduced in the future if there is enough demand from web developers.",
23+
"NameList": " Although this interface was previously implemented in Gecko, there was no way to actually create one. NameList has been removed, effective with Gecko 10.0",
24+
"DOMLocator": " This is not implemented in Mozilla",
25+
"RTCSessionDescriptionCallback": "Because this function type is part of the legacy WebRTC API, you should avoid using it (and the callback-based forms of createOffer() and createAnswer() that make use of it).\n",
26+
"SVGMatrix": " SVG 2 replaced the SVGMatrix interface by the more general DOMMatrix and DOMMatrixReadOnly interfaces.",
27+
"DOMConfiguration": " This interface has never been supported in Gecko, and has been removed from the DOM specification.",
28+
"AudioProcessingEvent": " As of the August 29 2014 Web Audio API spec publication, this feature has been marked as deprecated, and is soon to be replaced by AudioWorklet.",
29+
"IDBEnvironment": " The indexedDB property that was previously defined in this mixin is instead now WindowOrWorkerGlobalScope.indexedDB (that is, defined as a member of the WindowOrWorkerGlobalScope mixin).",
30+
"IDBDatabaseSync": " The synchronous version of the IndexedDB API was originally intended for use only with Web Workers, and was eventually removed from the spec because its need was questionable. It may however be reintroduced in the future if there is enough demand from web developers.",
31+
"PerformanceNavigation": "This interface is deprecated in the Navigation Timing Level 2 specification. Please use the PerformanceNavigationTiming interface instead.\n"
32+
}

manualAnalytics/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# READ ME!
2+
All files in this folder aimes to be used by USER rather than CODE.
3+
4+
Users could have a quick view of some data.
5+
mdnDeprecatedApis.ts -- all api names marked as deprecated in `https://developer.mozilla.org/en-US/docs/Web/API`
6+
idlSourceAppearDeprecateText.ts -- check web pages in `inputfiles/idlSources.json`, to see whether there is text "deprecate".
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import * as fs from "fs";
2+
import * as path from "path";
3+
import fetch from "node-fetch";
4+
// import { JSDOM } from "jsdom";
5+
6+
interface IDLSource {
7+
url: string;
8+
title: string;
9+
deprecated?: boolean;
10+
local?: boolean;
11+
}
12+
13+
async function fetchIDLs() {
14+
const idlSources = (require("../inputfiles/idlSources.json") as IDLSource[]);
15+
await Promise.all(idlSources.map(async source => {
16+
if (source.local) {
17+
return;
18+
}
19+
await fetchIDL(source);
20+
})).then(
21+
()=>{
22+
console.log();
23+
console.log(deprecatedSet);
24+
}
25+
);
26+
}
27+
28+
const tmpLocalFolder = path.join(__dirname, "localIdlSource");
29+
const deprecatedSet = new Set<string>();
30+
31+
// ['https://www.w3.org/TR/css-color-3/', 'https://www.w3.org/TR/credential-management-1/', 'https://www.w3.org/TR/css-text-decor-3/', 'https://w3c.github.io/media-playback-quality/', 'https://www.w3.org/TR/css-text-3/', 'https://drafts.csswg.org/css-images-3/', 'https://www.w3.org/TR/secure-contexts/', 'https://www.w3.org/TR/SVG2/types.html', 'https://html.spec.whatwg.org/multipage/obsolete.html', 'https://notifications.spec.whatwg.org/', 'https://www.w3.org/TR/SVG2/text.html', 'https://fetch.spec.whatwg.org/', 'https://html.spec.whatwg.org/multipage/webappapis.html', 'https://dom.spec.whatwg.org/', 'https://drafts.fxtf.org/css-masking-1/', 'https://www.w3.org/TR/filter-effects-1/', 'https://drafts.csswg.org/cssom/', 'https://w3c.github.io/webrtc-pc/', 'https://webaudio.github.io/web-audio-api/', 'https://heycam.github.io/webidl/', 'https://www.w3.org/TR/SVG2/pservers.html', 'https://www.w3.org/TR/uievents/']
32+
33+
async function fetchIDL(source: IDLSource) {
34+
35+
if (!fs.existsSync(tmpLocalFolder)) {
36+
fs.mkdirSync(tmpLocalFolder);
37+
}
38+
39+
if (source.url.endsWith(".idl")) {
40+
return;
41+
}
42+
43+
const localFile = path.join(tmpLocalFolder, source.title);
44+
let webPageContent: string;
45+
if (fs.existsSync(localFile)) {
46+
webPageContent = fs.readFileSync(localFile, { encoding: "utf-8" });
47+
}
48+
else {
49+
const response = await fetch(source.url);
50+
webPageContent = await response.text();
51+
fs.writeFileSync(localFile, webPageContent);
52+
}
53+
if(webPageContent.toLowerCase().includes("deprecated")){
54+
deprecatedSet.add(source.url);
55+
}
56+
// const dom = JSDOM.fragment(
57+
// ""// webPageContent
58+
// );
59+
60+
}
61+
62+
fetchIDLs();

manualAnalytics/mdnDeprecatedApis.ts

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
import * as fs from "fs";
2+
import fetch from "node-fetch";
3+
import { JSDOM } from "jsdom";
4+
import path from "path";
5+
6+
const outputFolder = __dirname
7+
8+
const mdnDeprecatedApisFile = path.join(outputFolder, "mdnDeprecatedApis.json");
9+
const mdnObsoleteApisFile = path.join(outputFolder, "mdnObsoleteApis.json");
10+
const mdnDeprecatedApisReasonFile = path.join(outputFolder, "mdnDeprecatedApisReason.json");
11+
const mdnObsoleteApisReasonFile = path.join(outputFolder, "mdnObsoleteApisReason.json");
12+
13+
const mdnApiWeb = "https://developer.mozilla.org/en-US/docs/Web/API"
14+
15+
async function fetchInterfaceDescriptions() {
16+
const fragment = await fetchDom(mdnApiWeb);
17+
const InterfacesSelector = '#wikiArticle > div:nth-child(8)';
18+
19+
const interfacesFragment = fragment.querySelector(InterfacesSelector);
20+
21+
if (!interfacesFragment) {
22+
// This is not that right, but is better than nothing.
23+
throw new Error("css selector for interfaces has been changed!");
24+
}
25+
26+
const deprecatedIconSelector = '.icon-thumbs-down-alt';
27+
const deprecatedAPIs = [];
28+
29+
for (const deprecatedIconElem of interfacesFragment.querySelectorAll(deprecatedIconSelector)) {
30+
const deprecatedAPI = deprecatedIconElem?.parentElement?.parentElement?.previousSibling?.textContent;
31+
if (!deprecatedAPI) {
32+
console.dir(deprecatedIconElem);
33+
throw new Error("some element could not ");
34+
}
35+
deprecatedAPIs.push(deprecatedAPI);
36+
}
37+
38+
const obsoleteIconSelector = '.icon-trash';
39+
const obsoleteAPIs = [];
40+
for (const obsoleteIconElem of interfacesFragment.querySelectorAll(obsoleteIconSelector)) {
41+
const obsoleteAPI = obsoleteIconElem?.parentElement?.parentElement?.previousSibling?.textContent;
42+
if (!obsoleteAPI) {
43+
console.dir(obsoleteIconElem);
44+
throw new Error("some element could not ");
45+
}
46+
obsoleteAPIs.push(obsoleteAPI);
47+
}
48+
49+
fs.writeFileSync(mdnDeprecatedApisFile, JSON.stringify(deprecatedAPIs));
50+
fs.writeFileSync(mdnObsoleteApisFile, JSON.stringify(obsoleteAPIs));
51+
}
52+
53+
async function fetchDeprecatedApiReasons() {
54+
await fetchInterfaceDescriptions();
55+
56+
const deprecatedAPIArray: string[] = require(mdnDeprecatedApisFile);
57+
const obsoleteAPIArray: string[] = require(mdnObsoleteApisFile);
58+
59+
// const maekDeprecatedJsdocApiArray = [...deprecatedAPIArray, ...obsoleteAPIArray];
60+
61+
// const deprecatedAPIArray: string[] = JSON.parse(s);
62+
// use Promise.all to acclete.
63+
const mdnDeprecatedApisReason: Record<string, string> = {};
64+
const mdnObsoleteApisReason: Record<string, string> = {};
65+
66+
Promise.all(deprecatedAPIArray.map(async apiName => {
67+
const fragment = await fetchDom(`${mdnApiWeb}/${apiName}`);
68+
69+
let isSearchedArea = true;
70+
const searchArea = Array.from(fragment.querySelector("#wikiArticle")?.children!).filter(item => {
71+
if (item.tagName === "H2") {
72+
isSearchedArea = false;
73+
}
74+
return isSearchedArea;
75+
});
76+
const reason1 = searchArea.find(e => e.className.split(' ').includes("warning"))?.textContent;
77+
const reason2 = searchArea.find(e => e.className.split(' ').includes("note"))?.textContent;
78+
79+
// const reason1 = fragment.querySelector("#wikiArticle > .warning")?.textContent;
80+
// const reason2 = fragment.querySelector("#wikiArticle > .note")?.textContent;
81+
82+
if (reason1 && reason2) {
83+
throw new Error("not consider situation! api name is " + apiName);
84+
}
85+
if (!reason1 && !reason2) {
86+
return Promise.resolve();
87+
}
88+
const reason = reason1 ?? reason2;
89+
if (!reason) {
90+
throw new Error("impossiable");
91+
}
92+
mdnDeprecatedApisReason[apiName] = reason.substring(reason.indexOf(':') + 1).replace("\n", "");
93+
})).then(() => {
94+
fs.writeFileSync(mdnDeprecatedApisReasonFile, JSON.stringify(mdnDeprecatedApisReason));
95+
})
96+
97+
Promise.all(obsoleteAPIArray.map(async apiName => {
98+
const fragment = await fetchDom(`${mdnApiWeb}/${apiName}`);
99+
100+
let isSearchedArea = true;
101+
const searchArea = Array.from(fragment.querySelector("#wikiArticle")?.children!).filter(item => {
102+
if (item.tagName === "H2") {
103+
isSearchedArea = false;
104+
}
105+
return isSearchedArea;
106+
});
107+
const reason1 = searchArea.find(e => e.className.split(' ').includes("warning"))?.textContent;
108+
const reason2 = searchArea.find(e => e.className.split(' ').includes("note"))?.textContent;
109+
110+
// const reason1 = fragment.querySelector("#wikiArticle > .warning")?.textContent;
111+
// const reason2 = fragment.querySelector("#wikiArticle > .note")?.textContent;
112+
113+
if (reason1 && reason2 && apiName !== "IDBEnvironment") {
114+
throw new Error("not consider situation! api name is " + apiName);
115+
}
116+
if (!reason1 && !reason2) {
117+
return Promise.resolve();
118+
}
119+
const reason = reason1 ?? reason2;
120+
if (!reason) {
121+
throw new Error("impossiable");
122+
}
123+
mdnObsoleteApisReason[apiName] = reason.substring(reason.indexOf(':') + 1).replace("\n", "");
124+
})).then(() => {
125+
fs.writeFileSync(mdnObsoleteApisReasonFile, JSON.stringify(mdnObsoleteApisReason));
126+
})
127+
}
128+
129+
async function fetchDom(url: string) {
130+
const response = await fetch(url);
131+
if (!response.ok) {
132+
throw new Error(`Failed to fetch ${url}`);
133+
}
134+
const responseString = await response.text();
135+
136+
return JSDOM.fragment(responseString);
137+
}
138+
139+
fetchDeprecatedApiReasons();

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"node-fetch": "^2.6.0",
2020
"print-diff": "^0.1.1",
2121
"styleless-innertext": "^1.1.2",
22+
"ts-node": "^8.10.2",
2223
"typescript": "next",
2324
"webidl2": "^23.12.1"
2425
}

src/emitter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,7 @@ export function emitWebIdl(webidl: Browser.WebIdl, flavor: Flavor) {
640640
if (entity.comment) {
641641
entity.comment.split('\n').forEach(print);
642642
}
643-
if (entity.deprecated) {
643+
if (entity.deprecated && !entity.comment?.includes('@deprecated')) {
644644
print(`/** @deprecated */`);
645645
}
646646
}

src/helpers.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,11 @@ export function merge<T>(target: T, src: T, shallow?: boolean): T {
7070
if (Array.isArray(targetProp) !== Array.isArray(srcProp)) {
7171
throw new Error("Mismatch on property: " + k + JSON.stringify(srcProp));
7272
}
73-
if (shallow && typeof (target[k] as any).name === "string" && typeof (src[k] as any).name === "string") {
74-
target[k] = src[k];
73+
if (shallow && typeof (targetProp as any).name === "string" && typeof (srcProp as any).name === "string") {
74+
target[k] = srcProp;
7575
}
7676
else {
77-
target[k] = merge(target[k], src[k], shallow);
77+
target[k] = merge(targetProp, srcProp, shallow);
7878
}
7979
}
8080
}

0 commit comments

Comments
 (0)