wrec 0.36.2 → 0.36.4
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/dist/wrec-ssr.d.ts +1 -1
- package/dist/wrec.d.ts +1 -1
- package/package.json +1 -1
- package/scripts/lint.js +48 -2
package/dist/wrec-ssr.d.ts
CHANGED
|
@@ -23,7 +23,7 @@ declare type PropertyConfig<T = any> = {
|
|
|
23
23
|
values?: T extends string ? string[] : never;
|
|
24
24
|
};
|
|
25
25
|
|
|
26
|
-
declare type PropertyType = typeof Array | typeof Boolean | typeof Number | typeof Object | typeof String;
|
|
26
|
+
declare type PropertyType = typeof Array | typeof Boolean | typeof HTMLElementBase | typeof Number | typeof Object | typeof String;
|
|
27
27
|
|
|
28
28
|
declare type StateChange = {
|
|
29
29
|
state: WrecState;
|
package/dist/wrec.d.ts
CHANGED
|
@@ -23,7 +23,7 @@ declare type PropertyConfig<T = any> = {
|
|
|
23
23
|
values?: T extends string ? string[] : never;
|
|
24
24
|
};
|
|
25
25
|
|
|
26
|
-
declare type PropertyType = typeof Array | typeof Boolean | typeof Number | typeof Object | typeof String;
|
|
26
|
+
declare type PropertyType = typeof Array | typeof Boolean | typeof HTMLElementBase | typeof Number | typeof Object | typeof String;
|
|
27
27
|
|
|
28
28
|
declare type StateChange = {
|
|
29
29
|
state: WrecState;
|
package/package.json
CHANGED
package/scripts/lint.js
CHANGED
|
@@ -122,6 +122,7 @@ const RESERVED_PROPERTY_NAMES = new Set(['class', 'style']);
|
|
|
122
122
|
const SUPPORTED_PROPERTY_TYPE_NAMES = new Set([
|
|
123
123
|
'Array',
|
|
124
124
|
'Boolean',
|
|
125
|
+
'HTMLElement',
|
|
125
126
|
'Number',
|
|
126
127
|
'Object',
|
|
127
128
|
'String'
|
|
@@ -1101,6 +1102,12 @@ function getComponentPropertyMaps(filePath, sourceText, seen = new Set()) {
|
|
|
1101
1102
|
return propertyMaps;
|
|
1102
1103
|
}
|
|
1103
1104
|
|
|
1105
|
+
// Returns the constructed instance type for a constructor expression.
|
|
1106
|
+
function getConstructedType(checker, expression) {
|
|
1107
|
+
const constructorType = checker.getTypeAtLocation(expression);
|
|
1108
|
+
return constructorType.getConstructSignatures()[0]?.getReturnType();
|
|
1109
|
+
}
|
|
1110
|
+
|
|
1104
1111
|
// Returns the referenced property name for a single `this.prop` binding.
|
|
1105
1112
|
function getPropertyNameInAttribute(attrValue) {
|
|
1106
1113
|
const match = attrValue.trim().match(PROPERTY_REF_RE);
|
|
@@ -1673,12 +1680,44 @@ function typeExpressionMatchesDeclaredType(
|
|
|
1673
1680
|
typeExpression,
|
|
1674
1681
|
declaredTypeNode
|
|
1675
1682
|
) {
|
|
1683
|
+
const typeKind = typeExpressionKind(typeExpression);
|
|
1676
1684
|
const declaredType = checker.getTypeFromTypeNode(declaredTypeNode);
|
|
1677
1685
|
|
|
1678
|
-
if (
|
|
1686
|
+
if (typeKind === 'Boolean') {
|
|
1687
|
+
return checker.isTypeAssignableTo(checker.getBooleanType(), declaredType);
|
|
1688
|
+
}
|
|
1689
|
+
|
|
1690
|
+
if (typeKind === 'Number') {
|
|
1691
|
+
return checker.isTypeAssignableTo(checker.getNumberType(), declaredType);
|
|
1692
|
+
}
|
|
1693
|
+
|
|
1694
|
+
if (typeKind === 'String') {
|
|
1695
|
+
return checker.isTypeAssignableTo(checker.getStringType(), declaredType);
|
|
1696
|
+
}
|
|
1697
|
+
|
|
1698
|
+
if (typeKind === 'Object') {
|
|
1679
1699
|
return isNonArrayObjectLikeType(checker, declaredType);
|
|
1680
1700
|
}
|
|
1681
1701
|
|
|
1702
|
+
if (typeKind === 'Array') {
|
|
1703
|
+
const declaredTypes = declaredType.isUnion()
|
|
1704
|
+
? declaredType.types
|
|
1705
|
+
: [declaredType];
|
|
1706
|
+
return declaredTypes.every(
|
|
1707
|
+
type =>
|
|
1708
|
+
Boolean(type.flags & (ts.TypeFlags.Any | ts.TypeFlags.Unknown)) ||
|
|
1709
|
+
checker.isArrayType(type) ||
|
|
1710
|
+
checker.isTupleType(type)
|
|
1711
|
+
);
|
|
1712
|
+
}
|
|
1713
|
+
|
|
1714
|
+
if (typeKind === 'HTMLElement') {
|
|
1715
|
+
const elementType = getConstructedType(checker, typeExpression);
|
|
1716
|
+
return elementType
|
|
1717
|
+
? checker.isTypeAssignableTo(elementType, declaredType)
|
|
1718
|
+
: false;
|
|
1719
|
+
}
|
|
1720
|
+
|
|
1682
1721
|
const runtimeType = checker.getTypeAtLocation(typeExpression);
|
|
1683
1722
|
return checker.isTypeAssignableTo(runtimeType, declaredType);
|
|
1684
1723
|
}
|
|
@@ -1842,6 +1881,13 @@ function validateDefaultValue(checker, typeExpression, valueExpression) {
|
|
|
1842
1881
|
}
|
|
1843
1882
|
}
|
|
1844
1883
|
|
|
1884
|
+
if (typeKind === 'HTMLElement') {
|
|
1885
|
+
const elementType = getConstructedType(checker, typeExpression);
|
|
1886
|
+
if (!elementType || !checker.isTypeAssignableTo(valueType, elementType)) {
|
|
1887
|
+
return {typeName: 'HTMLElement', valueTypeName};
|
|
1888
|
+
}
|
|
1889
|
+
}
|
|
1890
|
+
|
|
1845
1891
|
return undefined;
|
|
1846
1892
|
}
|
|
1847
1893
|
|
|
@@ -2006,7 +2052,7 @@ function validatePropertyConfigs(
|
|
|
2006
2052
|
) {
|
|
2007
2053
|
findings.invalidTypeProperties.push(
|
|
2008
2054
|
`property "${propName}" type must be one of ` +
|
|
2009
|
-
'Boolean, Number, String, Object, or
|
|
2055
|
+
'Boolean, Number, String, Object, Array, or HTMLElement'
|
|
2010
2056
|
);
|
|
2011
2057
|
} else if (declaredTypeNode) {
|
|
2012
2058
|
if (
|