-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add patching ability to temporarily patch until they are solved by MDN
- Loading branch information
Showing
11 changed files
with
429 additions
and
120 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
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,106 @@ | ||
import * as rawProperties from 'mdn-data/css/properties.json'; | ||
import * as rawSyntaxes from 'mdn-data/css/syntaxes.json'; | ||
import { getPropertyData, getTypesData } from './compat'; | ||
import { createPropertyDataTypeResolver, resolveDataTypes } from './data-types'; | ||
import { IExtendedProperty, properties as patchedProperties, syntaxes as patchedSyntaxes } from './data/patches'; | ||
import { error, warn } from './logger'; | ||
import parse from './parser'; | ||
import typing, { hasType } from './typer'; | ||
|
||
export const properties: { [property: string]: IExtendedProperty } = {}; | ||
|
||
for (const name in rawProperties) { | ||
properties[name] = { | ||
...rawProperties[name], | ||
syntax: getPropertySyntax(name), | ||
shorthand: | ||
name in patchedProperties && typeof patchedProperties[name].shorthand === 'boolean' | ||
? patchedProperties[name].shorthand | ||
: Array.isArray(rawProperties[name].computed), | ||
}; | ||
} | ||
|
||
for (const name in patchedProperties) { | ||
if (!(name in properties)) { | ||
properties[name] = patchedProperties[name]; | ||
} | ||
} | ||
|
||
const validatedPropertySyntaxes: string[] = []; | ||
|
||
export function getPropertySyntax(name: string) { | ||
const patch = patchedProperties[name]; | ||
|
||
if (patch && patch.syntax) { | ||
if (!validatedPropertySyntaxes.includes(name) && rawProperties[name] && rawProperties[name].syntax) { | ||
const compatibilityData = getPropertyData(name); | ||
|
||
if (isEqual(compatibilityData, patch.syntax, rawProperties[name].syntax)) { | ||
error(); | ||
} | ||
|
||
validatedPropertySyntaxes.push(name); | ||
} | ||
|
||
return patch.syntax; | ||
} | ||
|
||
if (!rawProperties[name]) { | ||
warn('Data for property `%s` is missing', name); | ||
} | ||
|
||
return rawProperties[name] && rawProperties[name].syntax; | ||
} | ||
|
||
const validatedSyntaxes: string[] = []; | ||
|
||
export function getSyntax(name: string) { | ||
const patch = patchedSyntaxes[name]; | ||
|
||
if (patch && patch.syntax) { | ||
if (!validatedSyntaxes.includes(name) && rawSyntaxes[name] && rawSyntaxes[name].syntax) { | ||
const compatibilityData = getTypesData(name); | ||
|
||
if (isEqual(compatibilityData, patch.syntax, rawSyntaxes[name].syntax)) { | ||
error(); | ||
} | ||
|
||
validatedSyntaxes.push(name); | ||
} | ||
|
||
return patch.syntax; | ||
} | ||
|
||
if (!rawSyntaxes[name]) { | ||
warn('Data for syntax `%s` is missing', name); | ||
} | ||
|
||
return rawSyntaxes[name] && rawSyntaxes[name].syntax; | ||
} | ||
|
||
function isEqual(compat: MDN.CompatData | null, syntaxA: string, syntaxB: string): boolean { | ||
// Dissolve all data types to check whether it already exists or not | ||
const dissolvedTypesA = resolveDataTypes( | ||
typing(parse(syntaxA)), | ||
createPropertyDataTypeResolver(compat, Infinity), | ||
Infinity, | ||
); | ||
const dissolvedTypesB = resolveDataTypes( | ||
typing(parse(syntaxA)), | ||
createPropertyDataTypeResolver(compat, Infinity), | ||
Infinity, | ||
); | ||
|
||
for (const type of dissolvedTypesA) { | ||
if (!hasType(dissolvedTypesB, type)) { | ||
return false; | ||
} | ||
} | ||
for (const type of dissolvedTypesB) { | ||
if (!hasType(dissolvedTypesA, type)) { | ||
return false; | ||
} | ||
} | ||
|
||
return true; | ||
} |
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,76 @@ | ||
export interface IExtendedProperty extends Partial<MDN.Property> { | ||
shorthand: boolean; | ||
} | ||
|
||
export const properties: { | ||
[property: string]: IExtendedProperty; | ||
} = { | ||
/** | ||
* https://drafts.csswg.org/css-overflow-3/#max-lines | ||
* Should be added to `mdn-browser-compat-data` when https://github.com/mdn/data/pull/207 is merged | ||
*/ | ||
'-webkit-line-clamp': { | ||
syntax: 'none | <integer>', | ||
shorthand: true, | ||
}, | ||
/** | ||
* https://drafts.csswg.org/css-overflow-3/#block-ellipsis | ||
* https://github.com/mdn/data/pull/207 | ||
*/ | ||
'block-overflow': { | ||
syntax: 'clip | ellipsis | <string>', | ||
shorthand: false, | ||
}, | ||
/** | ||
* https://drafts.csswg.org/css-overflow-3/#line-clamp | ||
* https://github.com/mdn/data/pull/207 | ||
*/ | ||
'line-clamp': { | ||
syntax: 'none | <integer>', | ||
shorthand: true, | ||
}, | ||
/** | ||
* https://drafts.csswg.org/css-overflow-3/#max-lines | ||
* https://github.com/mdn/data/pull/207 | ||
*/ | ||
'max-lines': { | ||
syntax: 'none | <integer>', | ||
shorthand: false, | ||
}, | ||
/** | ||
* https://drafts.csswg.org/css-scroll-anchoring/#exclusion-api | ||
* https://github.com/mdn/data/pull/206 | ||
*/ | ||
'overflow-anchor': { | ||
syntax: 'auto | none', | ||
shorthand: false, | ||
}, | ||
/** | ||
* https://drafts.csswg.org/css-overflow-3/#logical | ||
* https://github.com/mdn/data/pull/207 | ||
*/ | ||
'overflow-block': { | ||
syntax: "<'overflow'>", | ||
shorthand: false, | ||
}, | ||
/** | ||
* https://drafts.csswg.org/css-overflow-3/#logical | ||
* https://github.com/mdn/data/pull/207 | ||
*/ | ||
'overflow-inline': { | ||
syntax: "<'overflow'>", | ||
shorthand: false, | ||
}, | ||
}; | ||
|
||
export const syntaxes: { | ||
[property: string]: MDN.Syntax; | ||
} = { | ||
/** | ||
* https://developer.mozilla.org/en-US/docs/Web/CSS/-moz-outline-radius | ||
* https://github.com/mdn/data/pull/208 | ||
*/ | ||
'outline-radius': { | ||
syntax: '<length> | <percentage>', | ||
}, | ||
}; |
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,11 @@ | ||
import chalk from 'chalk'; | ||
|
||
export const error: typeof console.error = (message, ...params) => { | ||
// Complete the build process but exit with failure when done | ||
process.exitCode = 1; | ||
console.error(typeof message === 'string' ? chalk.magenta('ERROR! ' + message) : message, ...params); | ||
}; | ||
|
||
export const warn: typeof console.warn = (message, ...params) => { | ||
console.info(typeof message === 'string' ? chalk.yellow(message) : message, ...params); | ||
}; |
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.