wrec 0.31.3 → 0.31.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -1
- package/scripts/lint.js +26 -6
- package/scripts/scaffold.js +40 -0
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "wrec",
|
|
3
3
|
"description": "a small library that greatly simplifies building web components",
|
|
4
4
|
"author": "R. Mark Volkmann",
|
|
5
|
-
"version": "0.31.
|
|
5
|
+
"version": "0.31.5",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
@@ -30,6 +30,7 @@
|
|
|
30
30
|
},
|
|
31
31
|
"bin": {
|
|
32
32
|
"wrec-lint": "./scripts/lint.js",
|
|
33
|
+
"wrec-scaffold": "./scripts/scaffold.js",
|
|
33
34
|
"wrec-usedby": "./scripts/used-by.js"
|
|
34
35
|
},
|
|
35
36
|
"files": [
|
package/scripts/lint.js
CHANGED
|
@@ -1107,6 +1107,24 @@ function getParameterType(checker, parameterSymbol, location, isRestArgument) {
|
|
|
1107
1107
|
return typeArguments[0] ?? parameterType;
|
|
1108
1108
|
}
|
|
1109
1109
|
|
|
1110
|
+
// Returns the Wrec property config type name for a normalized type string.
|
|
1111
|
+
function getPropertyConfigTypeName(typeName) {
|
|
1112
|
+
switch (typeName) {
|
|
1113
|
+
case 'array':
|
|
1114
|
+
return 'Array';
|
|
1115
|
+
case 'boolean':
|
|
1116
|
+
return 'Boolean';
|
|
1117
|
+
case 'number':
|
|
1118
|
+
return 'Number';
|
|
1119
|
+
case 'object':
|
|
1120
|
+
return 'Object';
|
|
1121
|
+
case 'string':
|
|
1122
|
+
return 'String';
|
|
1123
|
+
default:
|
|
1124
|
+
return typeName;
|
|
1125
|
+
}
|
|
1126
|
+
}
|
|
1127
|
+
|
|
1110
1128
|
// Derives a readable property type string from syntax or the type checker.
|
|
1111
1129
|
function getPropertyTypeText(checker, sourceFile, expression) {
|
|
1112
1130
|
const typeText = getTypeSyntaxText(sourceFile, expression);
|
|
@@ -1590,9 +1608,11 @@ function validateCheckedBinding(
|
|
|
1590
1608
|
const expectedType = inputType === 'checkbox' ? 'boolean' : 'string';
|
|
1591
1609
|
if (propInfo.typeText === expectedType) return;
|
|
1592
1610
|
|
|
1611
|
+
const expectedTypeName = getPropertyConfigTypeName(expectedType);
|
|
1612
|
+
|
|
1593
1613
|
findings.invalidCheckedBindings.push(
|
|
1594
1614
|
`input type="${inputType}" attribute "${attrName}" refers to ` +
|
|
1595
|
-
`property "${propName}" whose type is not ${
|
|
1615
|
+
`property "${propName}" whose type is not ${expectedTypeName}`
|
|
1596
1616
|
);
|
|
1597
1617
|
}
|
|
1598
1618
|
|
|
@@ -1640,7 +1660,7 @@ function validateDefaultValue(checker, typeExpression, valueExpression) {
|
|
|
1640
1660
|
if (
|
|
1641
1661
|
!(valueType.flags & (ts.TypeFlags.String | ts.TypeFlags.StringLiteral))
|
|
1642
1662
|
) {
|
|
1643
|
-
return {typeName: '
|
|
1663
|
+
return {typeName: 'String', valueTypeName};
|
|
1644
1664
|
}
|
|
1645
1665
|
return undefined;
|
|
1646
1666
|
}
|
|
@@ -1649,7 +1669,7 @@ function validateDefaultValue(checker, typeExpression, valueExpression) {
|
|
|
1649
1669
|
if (
|
|
1650
1670
|
!(valueType.flags & (ts.TypeFlags.Number | ts.TypeFlags.NumberLiteral))
|
|
1651
1671
|
) {
|
|
1652
|
-
return {typeName: '
|
|
1672
|
+
return {typeName: 'Number', valueTypeName};
|
|
1653
1673
|
}
|
|
1654
1674
|
return undefined;
|
|
1655
1675
|
}
|
|
@@ -1658,14 +1678,14 @@ function validateDefaultValue(checker, typeExpression, valueExpression) {
|
|
|
1658
1678
|
if (
|
|
1659
1679
|
!(valueType.flags & (ts.TypeFlags.Boolean | ts.TypeFlags.BooleanLiteral))
|
|
1660
1680
|
) {
|
|
1661
|
-
return {typeName: '
|
|
1681
|
+
return {typeName: 'Boolean', valueTypeName};
|
|
1662
1682
|
}
|
|
1663
1683
|
return undefined;
|
|
1664
1684
|
}
|
|
1665
1685
|
|
|
1666
1686
|
if (typeKind === 'Array') {
|
|
1667
1687
|
if (!checker.isArrayType(valueType) && !checker.isTupleType(valueType)) {
|
|
1668
|
-
return {typeName: '
|
|
1688
|
+
return {typeName: 'Array', valueTypeName};
|
|
1669
1689
|
}
|
|
1670
1690
|
return undefined;
|
|
1671
1691
|
}
|
|
@@ -1676,7 +1696,7 @@ function validateDefaultValue(checker, typeExpression, valueExpression) {
|
|
|
1676
1696
|
!checker.isArrayType(valueType) &&
|
|
1677
1697
|
!checker.isTupleType(valueType);
|
|
1678
1698
|
if (!isObjectLike) {
|
|
1679
|
-
return {typeName: '
|
|
1699
|
+
return {typeName: 'Object', valueTypeName};
|
|
1680
1700
|
}
|
|
1681
1701
|
}
|
|
1682
1702
|
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import fs from 'node:fs';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import {fileURLToPath} from 'node:url';
|
|
6
|
+
|
|
7
|
+
function fail(message) {
|
|
8
|
+
console.error(message);
|
|
9
|
+
process.exit(1);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function toClassName(tagName) {
|
|
13
|
+
return tagName
|
|
14
|
+
.split('-')
|
|
15
|
+
.filter(Boolean)
|
|
16
|
+
.map(part => part[0].toUpperCase() + part.slice(1))
|
|
17
|
+
.join('');
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const [tagName] = process.argv.slice(2);
|
|
21
|
+
|
|
22
|
+
if (!tagName) fail('usage: npx wrec-scaffold {tag-name}');
|
|
23
|
+
if (!tagName.includes('-')) fail('tag name must contain at least one hyphen');
|
|
24
|
+
|
|
25
|
+
const className = toClassName(tagName);
|
|
26
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
27
|
+
const __dirname = path.dirname(__filename);
|
|
28
|
+
const templatePath = path.join(__dirname, 'template.ts');
|
|
29
|
+
const outputPath = path.resolve(process.cwd(), `${tagName}.ts`);
|
|
30
|
+
|
|
31
|
+
if (fs.existsSync(outputPath)) {
|
|
32
|
+
fail(`file already exists: ${outputPath}`);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const template = fs.readFileSync(templatePath, 'utf8');
|
|
36
|
+
const output = template
|
|
37
|
+
.replaceAll('{class}', className)
|
|
38
|
+
.replaceAll('{tag}', tagName);
|
|
39
|
+
|
|
40
|
+
fs.writeFileSync(outputPath, output);
|