-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP Add patcher to templorarily patch existing properties until they …
…are solved by MDN
- Loading branch information
Showing
6 changed files
with
135 additions
and
25 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 @@ | ||
export const properties: { [property: string]: Pick<MDN.Property, 'syntax'> } = {}; |
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,104 @@ | ||
import chalk from 'chalk'; | ||
import { createPropertyDataTypeResolver, resolveDataTypes } from './data-types'; | ||
import { properties as propertyPatches } from './data/css-patches'; | ||
import parse from './parser'; | ||
import typing, { addType, hasType, ResolvedType, Type } from './typer'; | ||
|
||
export default function patchProperty(name: string, types: ResolvedType[]): ResolvedType[] { | ||
if (!(name in propertyPatches)) { | ||
// Nothing to patch | ||
return types; | ||
} | ||
|
||
// Dissolve all data types to check whether it already exists or not | ||
const dissolvedTypes = resolveDataTypes(types, createPropertyDataTypeResolver(name, Infinity), Infinity); | ||
const patchTypes = typing(parse(propertyPatches[name].syntax)); | ||
|
||
let patchedTypes = types; | ||
|
||
for (const type of patchTypes) { | ||
if (!hasType(dissolvedTypes, type)) { | ||
patchedTypes = addType(patchedTypes, type); | ||
|
||
switch (type.type) { | ||
case Type.DataType: | ||
info('The property syntax patch with data type `<%s>` for property `%s` was added', type.name, name); | ||
break; | ||
case Type.Length: | ||
info('The property syntax patch with `<length>` for property `%s` was added', name); | ||
break; | ||
case Type.String: | ||
info('The property syntax patch resolved to `string` for property `%s` was added', name); | ||
break; | ||
case Type.Number: | ||
info('The property syntax patch resolved to `number` for property `%s` was added', name); | ||
break; | ||
case Type.NumericLiteral: | ||
case Type.StringLiteral: | ||
info('The property syntax patch with keyword `%s` for property `%s` was added', String(type.literal), name); | ||
break; | ||
default: | ||
info('A property syntax patch for property `%s` was added', name); | ||
} | ||
} else { | ||
switch (type.type) { | ||
case Type.DataType: | ||
error( | ||
'The property syntax patch with data type `<%s>` for property `%s` was ignored ' + | ||
'because it has been fixed permanently and must be removed', | ||
type.name, | ||
name, | ||
); | ||
break; | ||
case Type.Length: | ||
error( | ||
'The property syntax patch with `<length>` for property `%s` was ignored ' + | ||
'because it has been fixed permanently and must be removed', | ||
name, | ||
); | ||
break; | ||
case Type.String: | ||
error( | ||
'The property syntax patch resolved to `string` for property `%s` was ignored ' + | ||
'because it has been fixed permanently and must be removed', | ||
name, | ||
); | ||
break; | ||
case Type.Number: | ||
error( | ||
'The property syntax patch resolved to `number` for property `%s` was ignored ' + | ||
'because it has been fixed permanently and must be removed', | ||
name, | ||
); | ||
break; | ||
case Type.NumericLiteral: | ||
case Type.StringLiteral: | ||
error( | ||
'The property syntax patch with keyword `%s` for property `%s` was ignored ' + | ||
'because it has been fixed permanently and must be removed', | ||
String(type.literal), | ||
name, | ||
); | ||
break; | ||
default: | ||
error( | ||
'A property syntax patch for property `%s` was ignored because it has been fixed ' + | ||
'permanently and must be removed', | ||
name, | ||
); | ||
} | ||
} | ||
} | ||
|
||
return patchedTypes; | ||
} | ||
|
||
const error: typeof console.error = (message, ...params) => { | ||
// Complete the build process but exit with failure when done | ||
process.exitCode = 1; | ||
console.error(chalk.magenta('ERROR! ' + message), ...params); | ||
}; | ||
|
||
const info: typeof console.info = (message, ...params) => { | ||
console.info(chalk.cyan(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
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