-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflags.data.js
More file actions
153 lines (145 loc) · 4.67 KB
/
flags.data.js
File metadata and controls
153 lines (145 loc) · 4.67 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
const versions = [
{
id: "6.3",
url: "https://raw.githubusercontent.com/swiftlang/swift/swift-6.3-DEVELOPMENT-SNAPSHOT-2026-01-09-a/include/swift/Basic/Features.def",
},
{
id: "6.2",
url: "https://raw.githubusercontent.com/swiftlang/swift/refs/tags/swift-6.2-RELEASE/include/swift/Basic/Features.def",
},
{
id: "6.1.2",
url: "https://raw.githubusercontent.com/apple/swift/swift-6.1.2-RELEASE/include/swift/Basic/Features.def",
},
{
id: "6.0",
url: "https://raw.githubusercontent.com/apple/swift/release/6.0/include/swift/Basic/Features.def",
},
{
id: "5.10",
url: "https://raw.githubusercontent.com/apple/swift/swift-5.10-RELEASE/include/swift/Basic/Features.def",
},
];
/// Extra links to be added to specific features
const extraLinks = [
{
feature: "StrictConcurrency",
links: [
{
title: "An Introduction to Isolation in Swift",
url: "https://www.massicotte.org/intro-to-isolation",
},
{
title: "Data-race safety in Swift 5.10",
url: "https://www.swift.org/blog/swift-5.10-released/#data-race-safety-in-swift-510",
},
{
title: "The Swift Book: Concurrency",
url: "https://docs.swift.org/swift-book/documentation/the-swift-programming-language/concurrency/",
},
{
title: "How to determine where tasks and async functions run in Swift?",
url: "https://www.donnywals.com/how-to-determine-where-tasks-and-async-functions-run-in-swift/?utm_source=swiftyflags",
},
],
},
];
const regexLanguageFeature = /(?<=LANGUAGE_FEATURE\()[^,]+(?=,)|"([^"]+)"/gm;
const regexUpcomingFeature = /(?<=UPCOMING_FEATURE\()[^,]+(?=,)/gm;
const regexExperimentalFeature = /(?<=EXPERIMENTAL_FEATURE\()[^,]+(?=,)/gm;
// features from exampels and others we don't want to show up
const blackListedFeatures = [
'"#if $FeatureName"',
'"langOpts.<option name>"',
"FeatureName",
];
export default {
async load() {
const remoteFeatures = await Promise.all(
versions.map(async (v) => {
const response = await fetch(v.url);
const text = await response.text();
// LANGUAGE_FEATURE(...
const rows = text.split("\n");
const languageFeatures = rows
.map((row) => {
const match = row.match(regexLanguageFeature);
if (match) {
return {
name: match[0].trim(),
description: (match[1]?.trim() ?? "").replace(/"/g, ""),
type: "feature",
version: v.id,
};
}
return null;
})
.filter((f) => f !== null)
.sort((a, b) => a.name.localeCompare(b.name));
// UPCOMING_FEATURE(...
const upcomingFeatureMatches = text.match(regexUpcomingFeature);
const upcomingFeatures = (upcomingFeatureMatches ?? [])
.map((m) => {
return {
name: m.trim(),
type: "upcoming",
version: v.id,
};
})
.flat()
.sort((a, b) => a.name.localeCompare(b.name));
// EXPERIMENTAL_FEATURE(...
const experimentalFeatureMatches = text.match(regexExperimentalFeature);
const experimentalFeatures = (experimentalFeatureMatches ?? [])
.map((m) => {
return {
name: m.trim(),
type: "experimental",
version: v.id,
};
})
.flat()
.sort((a, b) => a.name.localeCompare(b.name));
return languageFeatures
.concat(upcomingFeatures)
.concat(experimentalFeatures);
}),
);
const groupedFeatures = remoteFeatures
.flat()
.filter((f) => !blackListedFeatures.includes(f.name))
.reduce((acc, obj) => {
let key = obj.name;
if (!acc[key]) {
acc[key] = {
name: key,
types: [],
versions: [],
descriptions: [],
docsUrl: `https://www.swift.org/swift-evolution/#?search=${key}`,
};
}
if (!acc[key].versions.includes(obj.version)) {
acc[key].versions.push(obj.version);
acc[key].descriptions.push({
v: obj.version,
value: obj.description,
});
acc[key].types.push({ v: obj.version, value: obj.type });
}
return acc;
}, {});
const list = Object.values(groupedFeatures).map((f) => {
const extraLink = extraLinks.find((el) => el.feature === f.name);
if (extraLink) {
f.extraLinks = extraLink.links;
} else {
f.extraLinks = [];
}
return f;
});
return {
flags: list,
};
},
};