Skip to content

Commit

Permalink
handle nextValue and update test data
Browse files Browse the repository at this point in the history
  • Loading branch information
OnkarRuikar committed Oct 5, 2023
1 parent 3248097 commit f0595f8
Show file tree
Hide file tree
Showing 602 changed files with 780 additions and 350 deletions.
15 changes: 14 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,18 @@
"ecmaVersion": "latest",
"sourceType": "module"
},
"rules": {}
"rules": {
"n/no-unpublished-import": [
"error",
{
"allowModules": ["diff"]
}
],
"n/no-extraneous-import": [
"error",
{
"allowModules": ["colors"]
}
]
}
}
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules/
node_modules/
.idea
1 change: 1 addition & 0 deletions .nmvrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v16
66 changes: 29 additions & 37 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"type": "module",
"main": "index.js",
"scripts": {
"add-syntax": "node testing/add-syntax.js",
"eslint": "eslint --fix .",
"prettier-check": "prettier --check .",
"prettier-format": "prettier --write .",
Expand All @@ -15,6 +16,7 @@
"css-tree": "^2.3.1"
},
"devDependencies": {
"diff": "^5.1.0",
"eslint": "^8.50.0",
"eslint-plugin-import": "^2.28.1",
"eslint-plugin-n": "^16.0.1",
Expand All @@ -23,6 +25,6 @@
"prettier-plugin-packagejson": "^2.4.5"
},
"engines": {
"node": "^14.13.0 || >=15.0.0"
"node": "^10 || ^12.20.0 || ^14.13.0 || >=15.0.0"
}
}
29 changes: 21 additions & 8 deletions query-syntax.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,18 @@ function addToConstructMap(map, list) {
}
}

function appendPropertyNewValues(list) {
for (const item of list) {
const property = properties.get(item.name);
if (property && item.newValues) {
property.value += ` | ${item.newValues}`;
}
}
}

function extractDataFromSpec(spec) {
addToConstructMap(properties, spec.properties);
appendPropertyNewValues(spec.properties);
addToConstructMap(atrules, spec.atrules);
addToConstructMap(selectors, spec.selectors);

Expand Down Expand Up @@ -111,23 +121,23 @@ function getTypesForSyntaxes(syntaxes, typesToOmit, constituents) {
if (node.type === "Type" && !constituents.includes(node.name)) {
constituents.push(node.name);
}
/* if (node.type === "Function" && !constituents.includes(node.name)) {
constituents.push(node.name);
} */
}

for (const syntax of syntaxes) {
try {
const ast = definitionSyntax.parse(syntax);
definitionSyntax.walk(ast, processNode);
} catch (e) {
console.log("error parsing syntax: ", syntax);
console.log("error parsing syntax: ", syntax, e);
}
}
}

function getValue(name) {
return functions.get(`${name}()`) || types.get(name) || values.get(name);
if (name.includes("()")) {
return functions.get(name);
}
return types.get(name) || values.get(name);
}

/**
Expand Down Expand Up @@ -174,7 +184,9 @@ export function getConstituentSyntaxes(itemSyntax, typesToOmit) {
if (constituentSyntaxEntry && constituentSyntaxEntry.value) {
constituentSyntaxes.push(constituentSyntaxEntry.value);
} else if (constituentSyntaxEntry && constituentSyntaxEntry.values) {
constituentSyntaxes.push(constituentSyntaxes.values);
constituentSyntaxes.push(
...constituentSyntaxEntry.values.map((v) => v.value)
);
}
}
}
Expand All @@ -189,7 +201,8 @@ export function getConstituentSyntaxes(itemSyntax, typesToOmit) {
syntaxes.push({
type: constituent,
syntax:
valueEntry.value || valueEntry.values.map((v) => v.name).join(" | "),
valueEntry.value ||
valueEntry.values.map((v) => `<${v.name}>`).join(" | "),
});
}
}
Expand All @@ -210,7 +223,7 @@ export function getSyntax(name, type, typesToOmit) {

switch (type) {
case "property":
syntax = properties.get(name)?.value;
syntax = properties.has(name) ? properties.get(name).value : undefined;
break;
case "type":
if (name.endsWith(">")) {
Expand Down
41 changes: 41 additions & 0 deletions testing/add-syntax.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
This script updates syntax for given CSS feature and type in test data.
*/

/* eslint-disable-next-line n/no-unsupported-features/node-builtins */
import fs from "node:fs/promises";
import * as Utils from "./utils.js";

const helpMessage =
"Usage:\n\t" +
"npm run add-syntax '[feature-name]' '[feature-type]'\n\t" +
"node testing/add-syntax '[feature-name]' '[feature-type]'\n";

if (process.argv.length < 3) {
console.error(helpMessage);
/* eslint-disable-next-line no-process-exit, n/no-process-exit */
process.exit(1);
} else if (process.argv[2] === "--help" || process.argv[2] === "-h") {
console.info(helpMessage);
/* eslint-disable-next-line no-process-exit, n/no-process-exit */
process.exit(0);
}

const name = process.argv[2];
const type = process.argv[3];
let syntax = Utils.getSyntaxForType(name, type);

if (syntax) {
syntax = {
name: name,
type: type,
...syntax,
};

await fs.writeFile(
`testing/data/${type}__${name}.json`,
JSON.stringify(syntax, undefined, " ")
);
}

console.log(`Added ${type}__${name}`);
27 changes: 27 additions & 0 deletions testing/check-syntaxes.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,30 @@
/*
This script tests all the syntaxes in test data against syntaxes returend by the current code.
*/

/* eslint-disable-next-line n/no-unsupported-features/node-builtins */
import fs from "node:fs/promises";
import * as Utils from "./utils.js";
import * as Diff from "diff";
/* eslint-disable-next-line no-unused-vars */

function logDiff(oldString, newString) {
const diff = Diff.diffLines(oldString, newString);

for (const part of diff) {
let prefix = "";
if (part.added) {
prefix = "+";
} else if (part.removed) {
prefix = "-";
}
let value = prefix + part.value.replaceAll("\n", "\n" + prefix);
value = value.replace(/[+-]$/gm, "");
process.stdout.write(value);
}

console.log("\n----");
}

const errors = [];
let total = 0;
Expand All @@ -20,6 +45,8 @@ for await (const filePath of Utils.walkSync("testing/data")) {
);

if (oldSyntax !== newSyntax) {
console.warn(`${data.name} ${data.type}`);
logDiff(oldSyntax, newSyntax);
errors.push(`${data.name} ${data.type}`);
}
} catch (e) {
Expand Down
6 changes: 0 additions & 6 deletions testing/data/@counter-style.json

This file was deleted.

6 changes: 0 additions & 6 deletions testing/data/@counter-style__fallback.json

This file was deleted.

6 changes: 0 additions & 6 deletions testing/data/@counter-style__speak-as.json

This file was deleted.

6 changes: 0 additions & 6 deletions testing/data/@counter-style__system.json

This file was deleted.

Loading

0 comments on commit f0595f8

Please sign in to comment.