wrec 0.36.1 → 0.36.2

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.
@@ -1,5 +1,3 @@
1
- declare type AnyClass = new (...args: any[]) => any;
2
-
3
1
  declare type ChangeCallback = (change: StateChange) => void;
4
2
 
5
3
  export declare function createElement(name: string, attributes: StringToString, innerHTML: string): HTMLElement;
@@ -19,12 +17,14 @@ declare type PropertyConfig<T = any> = {
19
17
  computed?: string;
20
18
  dispatch?: boolean;
21
19
  required?: boolean;
22
- type: AnyClass;
20
+ type: PropertyType;
23
21
  usedBy?: string | string[];
24
22
  value?: T;
25
23
  values?: T extends string ? string[] : never;
26
24
  };
27
25
 
26
+ declare type PropertyType = typeof Array | typeof Boolean | typeof Number | typeof Object | typeof String;
27
+
28
28
  declare type StateChange = {
29
29
  state: WrecState;
30
30
  statePath: string;
package/dist/wrec.d.ts CHANGED
@@ -1,5 +1,3 @@
1
- declare type AnyClass = new (...args: any[]) => any;
2
-
3
1
  declare type ChangeCallback = (change: StateChange) => void;
4
2
 
5
3
  export declare function createElement(name: string, attributes: StringToString, innerHTML: string): HTMLElement;
@@ -19,12 +17,14 @@ declare type PropertyConfig<T = any> = {
19
17
  computed?: string;
20
18
  dispatch?: boolean;
21
19
  required?: boolean;
22
- type: AnyClass;
20
+ type: PropertyType;
23
21
  usedBy?: string | string[];
24
22
  value?: T;
25
23
  values?: T extends string ? string[] : never;
26
24
  };
27
25
 
26
+ declare type PropertyType = typeof Array | typeof Boolean | typeof Number | typeof Object | typeof String;
27
+
28
28
  declare type StateChange = {
29
29
  state: WrecState;
30
30
  statePath: string;
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.1",
5
+ "version": "0.36.2",
6
6
  "license": "MIT",
7
7
  "repository": {
8
8
  "type": "git",
@@ -41,7 +41,9 @@ function analyzeSourceFile(sourceFile) {
41
41
  if (!ts.isPropertyAssignment(property)) continue;
42
42
 
43
43
  const propName = getMemberName(property);
44
- if (!propName || !/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(propName)) continue;
44
+ if (!propName || !/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(propName)) {
45
+ continue;
46
+ }
45
47
 
46
48
  const declareType = getDeclareType(property.initializer);
47
49
  if (!declareType) continue;
package/scripts/lint.js CHANGED
@@ -1180,6 +1180,15 @@ function getPropertyConfigTypeName(typeName) {
1180
1180
  }
1181
1181
  }
1182
1182
 
1183
+ // Gets the base constructor name from a generic-looking type expression.
1184
+ function getPropertyTypeGenericBaseName(sourceFile, expression) {
1185
+ if (!expression) return undefined;
1186
+
1187
+ const text = expression.getText(sourceFile).trim();
1188
+ const match = text.match(/^([A-Za-z_$][\w$]*)\s*<[\s\S]+>$/);
1189
+ return match?.[1];
1190
+ }
1191
+
1183
1192
  // Derives a readable property type string from syntax or the type checker.
1184
1193
  function getPropertyTypeText(checker, sourceFile, expression) {
1185
1194
  const typeText = getTypeSyntaxText(sourceFile, expression);
@@ -1982,6 +1991,16 @@ function validatePropertyConfigs(
1982
1991
  findings.missingTypeProperties.push(
1983
1992
  `property "${propName}" does not specify a type`
1984
1993
  );
1994
+ } else if (
1995
+ SUPPORTED_PROPERTY_TYPE_NAMES.has(
1996
+ getPropertyTypeGenericBaseName(sourceFile, typeExpression)
1997
+ )
1998
+ ) {
1999
+ findings.invalidTypeProperties.push(
2000
+ `property "${propName}" type cannot use generic syntax like ` +
2001
+ `"${typeExpression.getText(sourceFile).trim()}"; use ` +
2002
+ `"${getPropertyTypeGenericBaseName(sourceFile, typeExpression)}" instead`
2003
+ );
1985
2004
  } else if (
1986
2005
  !SUPPORTED_PROPERTY_TYPE_NAMES.has(typeExpressionKind(typeExpression))
1987
2006
  ) {
File without changes