Skip to content

Commit 9999de2

Browse files
committed
Initial cut on using MDN data
1 parent 0e45d41 commit 9999de2

File tree

6 files changed

+7520
-376
lines changed

6 files changed

+7520
-376
lines changed

build/generate_browserjs.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,9 @@ function toSource(object, keyName) {
343343

344344
var parser = new xml2js.Parser({explicitArray : false});
345345
var schemaFileName= 'css-schema.xml';
346+
347+
var { buildPropertiesWithMDNData } = require('./mdn-data-importer')
348+
346349
fs.readFile(path.resolve(__dirname, schemaFileName), function(err, data) {
347350
parser.parseString(data, function (err, result) {
348351

@@ -360,7 +363,7 @@ fs.readFile(path.resolve(__dirname, schemaFileName), function(err, data) {
360363
atdirectives: atdirectives,
361364
pseudoclasses: pseudoclasses,
362365
pseudoelements: pseudoelements,
363-
properties: properties
366+
properties: buildPropertiesWithMDNData(properties)
364367
}
365368
};
366369

build/mdn-data-importer.js

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
const path = require('path')
7+
const fs = require('fs')
8+
9+
function buildPropertiesWithMDNData(vscProperties) {
10+
const propertyMap = {}
11+
12+
const mdnProperties = require('mdn-data/css/properties.json')
13+
const mdnAtRules = require('mdn-data/css/at-rules.json')
14+
15+
// Flatten at-rule properties and put all properties together
16+
const allMDNProperties = mdnProperties
17+
for (const atRuleName of Object.keys(mdnAtRules)) {
18+
if (mdnAtRules[atRuleName].descriptors) {
19+
for (const atRulePropertyName of Object.keys(mdnAtRules[atRuleName].descriptors)) {
20+
allMDNProperties[atRulePropertyName] = mdnAtRules[atRuleName].descriptors[atRulePropertyName]
21+
}
22+
}
23+
}
24+
25+
/**
26+
* 1. Go through VSC properties. For each entry that has a matching entry in MDN, merge both entry.
27+
*/
28+
vscProperties.forEach(p => {
29+
if (p.name) {
30+
if (allMDNProperties[p.name]) {
31+
propertyMap[p.name] = {
32+
...p,
33+
...allMDNProperties[p.name]
34+
}
35+
} else {
36+
propertyMap[p.name] = p
37+
}
38+
}
39+
})
40+
41+
/**
42+
* 2. Go through MDN properties. For each entry that hasn't been recorded, add it with empty description.
43+
*/
44+
for (const pn of Object.keys(allMDNProperties)) {
45+
if (!propertyMap[pn]) {
46+
propertyMap[pn] = {
47+
name: pn,
48+
description: '',
49+
...allMDNProperties[pn]
50+
}
51+
}
52+
}
53+
54+
return Object.values(propertyMap)
55+
}
56+
57+
module.exports = {
58+
buildPropertiesWithMDNData
59+
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"@types/mocha": "^2.2.33",
1919
"@types/node": "^7.0.43",
2020
"istanbul": "^0.4.5",
21+
"mdn-data": "^1.1.1",
2122
"mkdirp": "^0.5.1",
2223
"mocha": "^5.0.4",
2324
"rimraf": "^2.6.2",

0 commit comments

Comments
 (0)