Skip to content

Commit 07ea4e8

Browse files
author
Orta Therox
authored
Merge pull request #884 from ShuiRuTian/create-deprecatedjson-from-idlsource
Create deprecatedjson from mdn web
2 parents 951d1df + e70931f commit 07ea4e8

File tree

7 files changed

+76
-15
lines changed

7 files changed

+76
-15
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,7 @@ __pycache__/
281281
generated/
282282
lib/
283283
inputfiles/browser.webidl.json
284-
.vscode
284+
.vscode/*
285+
!.vscode/launch.template.json
285286
package-lock.json
286287
yarn.lock

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 separate file rather than merge in comment.json is mdn/apiDescriptions.json would also possibly be deprecated.

baselines/dom.generated.d.ts

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2330,7 +2330,9 @@ declare var AudioParamMap: {
23302330
new(): AudioParamMap;
23312331
};
23322332

2333-
/** The Web Audio API events that occur when a ScriptProcessorNode input buffer is ready to be processed. */
2333+
/** The Web Audio API events that occur when a ScriptProcessorNode input buffer is ready to be processed.
2334+
* @deprecated 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.
2335+
*/
23342336
interface AudioProcessingEvent extends Event {
23352337
readonly inputBuffer: AudioBuffer;
23362338
readonly outputBuffer: AudioBuffer;
@@ -10562,7 +10564,8 @@ declare var MouseEvent: {
1056210564
new(type: string, eventInitDict?: MouseEventInit): MouseEvent;
1056310565
};
1056410566

10565-
/** Provides event properties that are specific to modifications to the Document Object Model (DOM) hierarchy and nodes. */
10567+
/** Provides event properties that are specific to modifications to the Document Object Model (DOM) hierarchy and nodes.
10568+
* @deprecated 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. */
1056610569
interface MutationEvent extends Event {
1056710570
readonly attrChange: number;
1056810571
readonly attrName: string;
@@ -11548,7 +11551,9 @@ declare var PerformanceMeasure: {
1154811551
new(): PerformanceMeasure;
1154911552
};
1155011553

11551-
/** The legacy PerformanceNavigation interface represents information about how the navigation to the current document was done. */
11554+
/** The legacy PerformanceNavigation interface represents information about how the navigation to the current document was done.
11555+
* @deprecated This interface is deprecated in the Navigation Timing Level 2 specification. Please use the PerformanceNavigationTiming interface instead.
11556+
*/
1155211557
interface PerformanceNavigation {
1155311558
readonly redirectCount: number;
1155411559
readonly type: number;
@@ -11638,7 +11643,9 @@ declare var PerformanceResourceTiming: {
1163811643
new(): PerformanceResourceTiming;
1163911644
};
1164011645

11641-
/** A legacy interface kept for backwards compatibility and contains properties that offer performance timing information for various events which occur during the loading and use of the current page. You get a PerformanceTiming object describing your page using the window.performance.timing property. */
11646+
/** A legacy interface kept for backwards compatibility and contains properties that offer performance timing information for various events which occur during the loading and use of the current page. You get a PerformanceTiming object describing your page using the window.performance.timing property.
11647+
* @deprecated This interface is deprecated in the Navigation Timing Level 2 specification. Please use the PerformanceNavigationTiming interface instead.
11648+
*/
1164211649
interface PerformanceTiming {
1164311650
readonly connectEnd: number;
1164411651
readonly connectStart: number;
@@ -14820,7 +14827,9 @@ interface ScriptProcessorNodeEventMap {
1482014827
"audioprocess": AudioProcessingEvent;
1482114828
}
1482214829

14823-
/** Allows the generation, processing, or analyzing of audio using JavaScript. */
14830+
/** Allows the generation, processing, or analyzing of audio using JavaScript.
14831+
* @deprecated 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).
14832+
*/
1482414833
interface ScriptProcessorNode extends AudioNode {
1482514834
/** @deprecated */
1482614835
readonly bufferSize: number;
@@ -14944,7 +14953,9 @@ declare var ServiceWorkerContainer: {
1494414953
new(): ServiceWorkerContainer;
1494514954
};
1494614955

14947-
/** This ServiceWorker API interface contains information about an event sent to a ServiceWorkerContainer target. This extends the default message event to allow setting a ServiceWorker object as the source of a message. The event object is accessed via the handler function of a message event, when fired by a message received from a service worker. */
14956+
/** This ServiceWorker API interface contains information about an event sent to a ServiceWorkerContainer target. This extends the default message event to allow setting a ServiceWorker object as the source of a message. The event object is accessed via the handler function of a message event, when fired by a message received from a service worker.
14957+
* @deprecated In modern browsers, this interface has been deprecated. Service worker messages will now use the MessageEvent interface, for consistency with other web messaging features.
14958+
*/
1494814959
interface ServiceWorkerMessageEvent extends Event {
1494914960
readonly data: any;
1495014961
readonly lastEventId: string;

inputfiles/deprecatedMessage.json

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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+
"SVGAltGlyphItemElement": "This interface was removed in the SVG 2 specification.\n",
4+
"PerformanceTiming": "This interface is deprecated in the Navigation Timing Level 2 specification. Please use the PerformanceNavigationTiming interface instead.\n",
5+
"MouseScrollEvent": "Do not use this interface for wheel events.Like MouseWheelEvent, this interface is non-standard and deprecated. It was used in Gecko-based browsers only. Instead use the standard WheelEvent.\n",
6+
"SVGAltGlyphDefElement": "This interface was removed in the SVG 2 specification.\n",
7+
"SVGExternalResourcesRequired": "This interface was removed in the SVG 2 specification.\n",
8+
"SVGMatrix": "SVG 2 replaced the SVGMatrix interface by the more general DOMMatrix and DOMMatrixReadOnly interfaces.\n",
9+
"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",
10+
"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.\n",
11+
"SVGRenderingIntent": "This interface was removed in the SVG 2 specification.\n",
12+
"PerformanceNavigation": "This interface is deprecated in the Navigation Timing Level 2 specification. Please use the PerformanceNavigationTiming interface instead.\n",
13+
"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.\n",
14+
"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).\n",
15+
"SVGGlyphElement": "This interface was removed in the SVG 2 specification.\n",
16+
"MouseWheelEvent": "Do not use this interface for wheel events.Like MouseScrollEvent, this interface is non-standard and deprecated. It was used in non-Gecko browsers only. Instead use the standard WheelEvent.\n",
17+
"IDBDatabaseException": "This interface was removed from the specification and was replaced by usage of DOMException.\n",
18+
"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\n",
19+
"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.\n",
20+
"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).\n",
21+
"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.\n",
22+
"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.\n",
23+
"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.\n",
24+
"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.\n",
25+
"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.\n",
26+
"DOMLocator": "This is not implemented in Mozilla\n",
27+
"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.\n",
28+
"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.\n",
29+
"BlobBuilder": "The BlobBuilder interface has been deprecated in favor of the newly introduced Blob constructor.\n",
30+
"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.\n",
31+
"DOMConfiguration": "This interface has never been supported in Gecko, and has been removed from the DOM specification.\n",
32+
"FileError": "This interface is obsolete per the latest specification. Use the new DOM4 DOMError interface instead.\n"
33+
}

src/emitter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,7 @@ export function emitWebIdl(webidl: Browser.WebIdl, flavor: Flavor, iterator: boo
653653
if (entity.comment) {
654654
entity.comment.split('\n').forEach(print);
655655
}
656-
if (entity.deprecated) {
656+
if (entity.deprecated && !entity.comment?.includes('@deprecated')) {
657657
print(`/** @deprecated */`);
658658
}
659659
}

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
}

src/index.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ function emitDom() {
6666
const overriddenItems = require(path.join(inputFolder, "overridingTypes.json"));
6767
const addedItems = require(path.join(inputFolder, "addedTypes.json"));
6868
const comments = require(path.join(inputFolder, "comments.json"));
69+
const deprecatedInfo = require(path.join(inputFolder, "deprecatedMessage.json"));
6970
const documentationFromMDN = require(path.join(inputFolder, 'mdn', 'apiDescriptions.json'));
7071
const removedItems = require(path.join(inputFolder, "removedTypes.json"));
7172
const idlSources: any[] = require(path.join(inputFolder, "idlSources.json"));
@@ -111,6 +112,19 @@ function emitDom() {
111112
return idl;
112113
}
113114

115+
function mergeDeprecatedMessage(idl: Browser.WebIdl, descriptions: Record<string, string>) {
116+
const namespaces = arrayToMap(idl.namespaces!, i => i.name, i => i);
117+
for (const [key, value] of Object.entries(descriptions)) {
118+
const target = idl.interfaces!.interface[key] || namespaces[key];
119+
if (target) {
120+
const comment = target.comment ?? "";
121+
const deprecated = "\n * @deprecated " + transformVerbosity(key, value);
122+
target.comment = comment + deprecated;
123+
}
124+
}
125+
return idl;
126+
}
127+
114128
function transformVerbosity(name: string, description: string): string {
115129
for (const regTemplate of removeVerboseIntroductions) {
116130
const [{ source: template }, replace] = regTemplate;
@@ -178,6 +192,7 @@ function emitDom() {
178192
webidl = merge(webidl, addedItems);
179193
webidl = merge(webidl, overriddenItems);
180194
webidl = merge(webidl, comments);
195+
webidl = mergeDeprecatedMessage(webidl, deprecatedInfo);
181196
for (const name in webidl.interfaces!.interface) {
182197
const i = webidl.interfaces!.interface[name];
183198
if (i["override-exposed"]) {

0 commit comments

Comments
 (0)