wrec 0.36.2 → 0.36.3

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.
@@ -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
@@ -2,7 +2,7 @@
2
2
  "name": "wrec",
3
3
  "description": "a library that greatly simplifies building web components",
4
4
  "author": "R. Mark Volkmann",
5
- "version": "0.36.2",
5
+ "version": "0.36.3",
6
6
  "license": "MIT",
7
7
  "repository": {
8
8
  "type": "git",
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);
@@ -1674,10 +1681,17 @@ function typeExpressionMatchesDeclaredType(
1674
1681
  declaredTypeNode
1675
1682
  ) {
1676
1683
  const declaredType = checker.getTypeFromTypeNode(declaredTypeNode);
1684
+ const typeKind = typeExpressionKind(typeExpression);
1677
1685
 
1678
- if (typeExpressionKind(typeExpression) === 'Object') {
1686
+ if (typeKind === 'Object') {
1679
1687
  return isNonArrayObjectLikeType(checker, declaredType);
1680
1688
  }
1689
+ if (typeKind === 'HTMLElement') {
1690
+ const elementType = getConstructedType(checker, typeExpression);
1691
+ return elementType
1692
+ ? checker.isTypeAssignableTo(elementType, declaredType)
1693
+ : false;
1694
+ }
1681
1695
 
1682
1696
  const runtimeType = checker.getTypeAtLocation(typeExpression);
1683
1697
  return checker.isTypeAssignableTo(runtimeType, declaredType);
@@ -1842,6 +1856,13 @@ function validateDefaultValue(checker, typeExpression, valueExpression) {
1842
1856
  }
1843
1857
  }
1844
1858
 
1859
+ if (typeKind === 'HTMLElement') {
1860
+ const elementType = getConstructedType(checker, typeExpression);
1861
+ if (!elementType || !checker.isTypeAssignableTo(valueType, elementType)) {
1862
+ return {typeName: 'HTMLElement', valueTypeName};
1863
+ }
1864
+ }
1865
+
1845
1866
  return undefined;
1846
1867
  }
1847
1868
 
@@ -2006,7 +2027,7 @@ function validatePropertyConfigs(
2006
2027
  ) {
2007
2028
  findings.invalidTypeProperties.push(
2008
2029
  `property "${propName}" type must be one of ` +
2009
- 'Boolean, Number, String, Object, or Array'
2030
+ 'Boolean, Number, String, Object, Array, or HTMLElement'
2010
2031
  );
2011
2032
  } else if (declaredTypeNode) {
2012
2033
  if (