-
Notifications
You must be signed in to change notification settings - Fork 185
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #91 from Microsoft/octref/mdn
[WIP] Use MDN to enhance CSS LS. Part of #68
- Loading branch information
Showing
12 changed files
with
1,957 additions
and
367 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
const path = require('path') | ||
const fs = require('fs') | ||
|
||
const mdnDocumentations = require('./mdn-documentation') | ||
|
||
const mdnExcludedProperties = [ | ||
'--*', // custom properties | ||
'gap', // grid-gap | ||
'row-gap', // grid-row-gap | ||
'image-resolution', // https://www.w3.org/TR/css-images-4/#propdef-image-resolution | ||
] | ||
|
||
function buildPropertiesWithMDNData(vscProperties) { | ||
const propertyMap = {} | ||
|
||
const mdnProperties = require('mdn-data/css/properties.json') | ||
const mdnAtRules = require('mdn-data/css/at-rules.json') | ||
|
||
// Flatten at-rule properties and put all properties together | ||
const allMDNProperties = mdnProperties | ||
for (const atRuleName of Object.keys(mdnAtRules)) { | ||
if (mdnAtRules[atRuleName].descriptors) { | ||
for (const atRulePropertyName of Object.keys(mdnAtRules[atRuleName].descriptors)) { | ||
allMDNProperties[atRulePropertyName] = mdnAtRules[atRuleName].descriptors[atRulePropertyName] | ||
} | ||
} | ||
} | ||
|
||
mdnExcludedProperties.forEach(p => { | ||
delete allMDNProperties[p] | ||
}) | ||
|
||
/** | ||
* 1. Go through VSC properties. For each entry that has a matching entry in MDN, merge both entry. | ||
*/ | ||
vscProperties.forEach(p => { | ||
if (p.name) { | ||
if (allMDNProperties[p.name]) { | ||
propertyMap[p.name] = { | ||
...p, | ||
...extractMDNProperties(allMDNProperties[p.name]) | ||
} | ||
} else { | ||
propertyMap[p.name] = p | ||
} | ||
} | ||
}) | ||
|
||
/** | ||
* 2. Go through MDN properties. For each entry that hasn't been recorded, add it with empty description. | ||
*/ | ||
for (const pn of Object.keys(allMDNProperties)) { | ||
if (!propertyMap[pn]) { | ||
propertyMap[pn] = { | ||
name: pn, | ||
desc: mdnDocumentations[pn] ? mdnDocumentations[pn] : '', | ||
restriction: 'none', | ||
...extractMDNProperties(allMDNProperties[pn]) | ||
} | ||
} | ||
} | ||
|
||
return Object.values(propertyMap) | ||
} | ||
|
||
/** | ||
* Extract only the MDN data that we use | ||
*/ | ||
function extractMDNProperties(mdnEntry) { | ||
return { | ||
status: mdnEntry.status, | ||
syntax: mdnEntry.syntax | ||
} | ||
} | ||
|
||
module.exports = { | ||
buildPropertiesWithMDNData | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.