Skip to content

Commit 3f3d66d

Browse files
committed
Migrate to @webref/css
1 parent ab21aaa commit 3f3d66d

31 files changed

+588
-457
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
node_modules/
2+
tsconfig.tsbuildinfo

__tests__/src.typer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import parse from '../src/syntax/parser';
2-
import typer, { Type } from '../src/syntax/typer';
1+
import parse from '../src/syntax/parser.mjs';
2+
import typer, { Type } from '../src/syntax/typer.mjs';
33

44
describe('typing', () => {
55
it('types combinators', () => {

build.ts renamed to build.mts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import * as chokidar from 'chokidar';
22
import * as path from 'path';
33
import * as prettier from 'prettier';
4-
import { FLOW_FILENAME, TYPESCRIPT_FILENAME, writeFileAsync } from './utils';
4+
import { FLOW_FILENAME, TYPESCRIPT_FILENAME, writeFileAsync } from './utils.mjs';
55
import { runCLI } from 'jest';
66
import { fileURLToPath } from 'url';
77
import { Config } from '@jest/types';
8-
import { declarator } from './src/declarator';
9-
import generateFlow from './src/flow';
10-
import generateTypescript from './src/typescript';
8+
import { declarator } from './src/declarator.mjs';
9+
import generateFlow from './src/flow.mjs';
10+
import generateTypescript from './src/typescript.mjs';
1111

1212
const __dirname = path.dirname(fileURLToPath(import.meta.url));
1313

package-lock.json

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"@types/node": "^24.10.1",
2222
"@types/prettier": "^3.0.0",
2323
"@types/turndown": "^5.0.6",
24+
"@webref/css": "^8.1.1",
2425
"babel-jest": "^30.2.0",
2526
"chalk": "^5.6.2",
2627
"chokidar": "^4.0.3",
@@ -44,11 +45,11 @@
4445
"scripts": {
4546
"prepublish": "npm install --no-save --prefix __tests__ && npm install --no-save --prefix __tests__/__fixtures__",
4647
"release": "release-it",
47-
"update": "tsx update.ts",
48-
"build": "tsx --inspect build.ts --start",
49-
"watch": "tsx build.ts --watch",
48+
"update": "tsx update.mts",
49+
"build": "tsx build.mts --start",
50+
"watch": "tsx build.mts --watch",
5051
"lint": "eslint . --ext .js,.jsx,.ts,.tsx --fix",
51-
"pretty": "prettier --write build.ts **/*.{ts,js,json,md}",
52+
"pretty": "prettier --write build.mts **/*.{ts,js,json,md}",
5253
"lazy": "tsc && npm run lint",
5354
"test": "jest --runInBand",
5455
"test:src": "jest src.*.ts",

src/collections/at-rules.mts

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import { atrules } from '../data/css.mjs';
2+
import parse from '../syntax/parser.mjs';
3+
import typer, { IStringLiteral, ResolvedType, Type } from '../syntax/typer.mjs';
4+
import { compatNames, compatSyntax, getAtRuleData, getCompats, isAddedBySome } from '../utils/compat.mjs';
5+
import { IDataTypeDictionary, resolveDataTypes } from './data-types.mjs';
6+
7+
interface IDescriptor {
8+
name: string;
9+
types: ResolvedType[];
10+
}
11+
12+
export interface IAtRuleDescriptors {
13+
[descriptor: string]: IDescriptor;
14+
}
15+
16+
export async function getAtRules(dataTypeDictionary: IDataTypeDictionary, minTypesInDataTypes: number) {
17+
const literals: IStringLiteral[] = [];
18+
const rules: { [name: string]: IAtRuleDescriptors } = {};
19+
20+
for (const atrule of atrules) {
21+
const atName = atrule.name;
22+
const name = atName.slice(1);
23+
24+
literals.push({
25+
type: Type.StringLiteral,
26+
literal: atName,
27+
});
28+
29+
if (atrule.descriptors) {
30+
const descriptors: IAtRuleDescriptors = {};
31+
const compatibilityData = getAtRuleData(name);
32+
let hasSupportedProperties = false;
33+
const descriptorNames = atrule.descriptors.map(({ name }) => name);
34+
35+
for (const descriptor of atrule.descriptors) {
36+
const { syntax, name: descriptorName } = descriptor;
37+
if (syntax) {
38+
let entities = parse(syntax);
39+
let properties = [descriptorName];
40+
41+
if (compatibilityData && descriptorName in compatibilityData) {
42+
const compats = getCompats(compatibilityData[descriptorName]);
43+
44+
if (compats.every(compat => !isAddedBySome(compat))) {
45+
// The property needs to be added by some browsers
46+
continue;
47+
}
48+
49+
entities = compatSyntax(compatibilityData, entities);
50+
properties = properties.concat(
51+
...compats.map(compat =>
52+
// We mix current and obsolete for now
53+
compatNames(compat, descriptorName)
54+
.concat(compatNames(compat, descriptorName, true))
55+
.filter(property => !descriptorNames.includes(property)),
56+
),
57+
);
58+
}
59+
60+
const types = resolveDataTypes(dataTypeDictionary, typer(entities), minTypesInDataTypes);
61+
62+
for (const property of properties) {
63+
hasSupportedProperties = true;
64+
descriptors[property] = {
65+
name: descriptorName,
66+
types,
67+
};
68+
}
69+
}
70+
}
71+
72+
if (hasSupportedProperties) {
73+
rules[name] = descriptors;
74+
}
75+
}
76+
}
77+
78+
return {
79+
literals,
80+
rules,
81+
};
82+
}

src/collections/at-rules.ts

Lines changed: 0 additions & 80 deletions
This file was deleted.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import mdnBrowserCompatData, { Identifier } from '@mdn/browser-compat-data';
2-
import { hasType, ResolvedType, Type, TypeType } from '../syntax/typer';
3-
import { alternativeAttributes } from '../utils/compat';
2+
import { hasType, ResolvedType, Type, TypeType } from '../syntax/typer.mjs';
3+
import { alternativeAttributes } from '../utils/compat.mjs';
44

55
function assembleAttributes(attributes: ResolvedType[], dataset: { [key: string]: Identifier }): ResolvedType[] {
66
const nextAttributes = [...attributes];
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { Identifier } from '@mdn/browser-compat-data';
2-
import parse from '../syntax/parser';
3-
import typer, { DataType, hasType, IDataType, ResolvedType, Type, TypeType } from '../syntax/typer';
4-
import { compatSyntax } from '../utils/compat';
5-
import { getPropertySyntax, getSyntax } from './syntaxes';
2+
import parse from '../syntax/parser.mjs';
3+
import typer, { DataType, hasType, IDataType, ResolvedType, Type, TypeType } from '../syntax/typer.mjs';
4+
import { compatSyntax } from '../utils/compat.mjs';
5+
import { getPropertySyntax, getSyntax } from './syntaxes.mjs';
66

77
export interface IDataTypeDictionary {
88
[key: string]: ResolvedType[];
Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { properties as rawSvgProperties } from '../data/svg';
2-
import parse from '../syntax/parser';
3-
import typer, { ResolvedType } from '../syntax/typer';
4-
import { composeCommentBlock } from '../utils/comment';
1+
import { properties as rawSvgProperties } from '../data/svg.mjs';
2+
import parse from '../syntax/parser.mjs';
3+
import typer, { ResolvedType } from '../syntax/typer.mjs';
4+
import { composeCommentBlock } from '../utils/comment.mjs';
55
import {
66
compatNames,
77
compatSyntax,
@@ -10,10 +10,10 @@ import {
1010
getTypesData,
1111
isAddedBySome,
1212
isDeprecated,
13-
} from '../utils/compat';
14-
import { warn } from '../utils/logger';
15-
import { createPropertyDataTypeResolver, IDataTypeDictionary, resolveDataTypes } from './data-types';
16-
import { getProperties, getPropertySyntax } from './syntaxes';
13+
} from '../utils/compat.mjs';
14+
import { warn } from '../utils/logger.mjs';
15+
import { createPropertyDataTypeResolver, IDataTypeDictionary, resolveDataTypes } from './data-types.mjs';
16+
import { getProperties, getPropertySyntax } from './syntaxes.mjs';
1717

1818
const ALL = 'all';
1919

@@ -51,9 +51,15 @@ export async function getGlobals(
5151
dataTypeDictionary: IDataTypeDictionary,
5252
minTypesInDataTypes: number,
5353
): Promise<ResolvedType[]> {
54+
const syntax = getPropertySyntax(ALL);
55+
56+
if (!syntax) {
57+
throw new Error(`Syntax for ${ALL} is missing`);
58+
}
59+
5460
const dataTypes = resolveDataTypes(
5561
dataTypeDictionary,
56-
typer(compatSyntax(getGlobalCompatibilityData(), parse(getPropertySyntax(ALL)))),
62+
typer(compatSyntax(getGlobalCompatibilityData(), parse(syntax))),
5763
minTypesInDataTypes,
5864
);
5965

@@ -94,12 +100,17 @@ export async function getHtmlProperties(dataTypeDictionary: IDataTypeDictionary,
94100
}
95101

96102
const data = propertiesMap[originalName];
103+
const syntax = getPropertySyntax(originalName);
104+
105+
if (!syntax) {
106+
continue;
107+
}
97108

98109
// Default values
99-
let entities = parse(getPropertySyntax(originalName));
110+
let entities = parse(syntax);
100111
let currentNames: string[] = [originalName];
101112
let obsoleteNames: string[] = [];
102-
let deprecated = isDeprecated(data);
113+
let deprecated: boolean = false;
103114

104115
const compatibilityData = getPropertyData(originalName);
105116

@@ -118,7 +129,7 @@ export async function getHtmlProperties(dataTypeDictionary: IDataTypeDictionary,
118129
obsoleteNames = obsoleteNames.concat(
119130
...compats.map(compat => filterMissingProperties(compatNames(compat, originalName, true))),
120131
);
121-
deprecated = compats.every(compat => isDeprecated(data, compat));
132+
deprecated = compats.every(compat => isDeprecated(compat));
122133
}
123134

124135
if (deprecated) {

0 commit comments

Comments
 (0)