|
| 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 | +const mdnDocumentations = require('./mdn-documentation') |
| 10 | + |
| 11 | +const mdnExcludedProperties = [ |
| 12 | + '--*', // custom properties |
| 13 | + 'gap', // grid-gap |
| 14 | + 'row-gap', // grid-row-gap |
| 15 | + 'image-resolution', // https://www.w3.org/TR/css-images-4/#propdef-image-resolution |
| 16 | +] |
| 17 | + |
| 18 | +function buildPropertiesWithMDNData(vscProperties) { |
| 19 | + const propertyMap = {} |
| 20 | + |
| 21 | + const mdnProperties = require('mdn-data/css/properties.json') |
| 22 | + const mdnAtRules = require('mdn-data/css/at-rules.json') |
| 23 | + |
| 24 | + // Flatten at-rule properties and put all properties together |
| 25 | + const allMDNProperties = mdnProperties |
| 26 | + for (const atRuleName of Object.keys(mdnAtRules)) { |
| 27 | + if (mdnAtRules[atRuleName].descriptors) { |
| 28 | + for (const atRulePropertyName of Object.keys(mdnAtRules[atRuleName].descriptors)) { |
| 29 | + allMDNProperties[atRulePropertyName] = mdnAtRules[atRuleName].descriptors[atRulePropertyName] |
| 30 | + } |
| 31 | + } |
| 32 | + } |
| 33 | + |
| 34 | + mdnExcludedProperties.forEach(p => { |
| 35 | + delete allMDNProperties[p] |
| 36 | + }) |
| 37 | + |
| 38 | + /** |
| 39 | + * 1. Go through VSC properties. For each entry that has a matching entry in MDN, merge both entry. |
| 40 | + */ |
| 41 | + vscProperties.forEach(p => { |
| 42 | + if (p.name) { |
| 43 | + if (allMDNProperties[p.name]) { |
| 44 | + propertyMap[p.name] = { |
| 45 | + ...p, |
| 46 | + ...extractMDNProperties(allMDNProperties[p.name]) |
| 47 | + } |
| 48 | + } else { |
| 49 | + propertyMap[p.name] = p |
| 50 | + } |
| 51 | + } |
| 52 | + }) |
| 53 | + |
| 54 | + /** |
| 55 | + * 2. Go through MDN properties. For each entry that hasn't been recorded, add it with empty description. |
| 56 | + */ |
| 57 | + for (const pn of Object.keys(allMDNProperties)) { |
| 58 | + if (!propertyMap[pn]) { |
| 59 | + propertyMap[pn] = { |
| 60 | + name: pn, |
| 61 | + desc: mdnDocumentations[pn] ? mdnDocumentations[pn] : '', |
| 62 | + restriction: 'none', |
| 63 | + ...extractMDNProperties(allMDNProperties[pn]) |
| 64 | + } |
| 65 | + } |
| 66 | + } |
| 67 | + |
| 68 | + return Object.values(propertyMap) |
| 69 | +} |
| 70 | + |
| 71 | +/** |
| 72 | + * Extract only the MDN data that we use |
| 73 | + */ |
| 74 | +function extractMDNProperties(mdnEntry) { |
| 75 | + return { |
| 76 | + status: mdnEntry.status, |
| 77 | + syntax: mdnEntry.syntax |
| 78 | + } |
| 79 | +} |
| 80 | + |
| 81 | +module.exports = { |
| 82 | + buildPropertiesWithMDNData |
| 83 | +} |
0 commit comments