@htmlplus/element 2.9.3 → 2.9.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.
Files changed (70) hide show
  1. package/README.md +0 -1
  2. package/client/decorators/bind.js +1 -1
  3. package/client/decorators/context.js +4 -6
  4. package/client/decorators/element.d.ts +1 -1
  5. package/client/decorators/element.js +44 -47
  6. package/client/decorators/event.d.ts +1 -1
  7. package/client/decorators/event.js +4 -5
  8. package/client/decorators/listen.d.ts +1 -1
  9. package/client/decorators/listen.js +1 -1
  10. package/client/decorators/method.d.ts +1 -1
  11. package/client/decorators/property.d.ts +1 -1
  12. package/client/decorators/property.js +7 -8
  13. package/client/decorators/state.d.ts +1 -1
  14. package/client/decorators/watch.d.ts +1 -1
  15. package/client/utils/appendToMethod.js +1 -1
  16. package/client/utils/attributes.d.ts +1 -1
  17. package/client/utils/attributes.js +1 -1
  18. package/client/utils/call.js +1 -2
  19. package/client/utils/config.js +1 -1
  20. package/client/utils/direction.d.ts +1 -1
  21. package/client/utils/event.d.ts +1 -1
  22. package/client/utils/getFramework.d.ts +1 -1
  23. package/client/utils/getStyles.d.ts +1 -1
  24. package/client/utils/getStyles.js +1 -2
  25. package/client/utils/getTag.d.ts +1 -1
  26. package/client/utils/getTag.js +1 -2
  27. package/client/utils/host.d.ts +1 -1
  28. package/client/utils/host.js +1 -1
  29. package/client/utils/isEvent.js +1 -1
  30. package/client/utils/isRTL.d.ts +1 -1
  31. package/client/utils/query.d.ts +1 -1
  32. package/client/utils/query.js +1 -2
  33. package/client/utils/queryAll.d.ts +1 -1
  34. package/client/utils/queryAll.js +1 -2
  35. package/client/utils/request.d.ts +1 -1
  36. package/client/utils/request.js +2 -3
  37. package/client/utils/shadowRoot.d.ts +1 -1
  38. package/client/utils/shadowRoot.js +1 -2
  39. package/client/utils/slots.d.ts +1 -1
  40. package/client/utils/slots.js +1 -2
  41. package/client/utils/toDecorator.d.ts +1 -1
  42. package/client/utils/toEvent.js +1 -1
  43. package/client/utils/toProperty.js +2 -2
  44. package/client/utils/updateAttribute.d.ts +1 -1
  45. package/package.json +19 -19
  46. package/transformer/plugins/assets.d.ts +1 -1
  47. package/transformer/plugins/copy.d.ts +1 -1
  48. package/transformer/plugins/customElement.d.ts +1 -1
  49. package/transformer/plugins/customElement.js +12 -13
  50. package/transformer/plugins/document.d.ts +1 -1
  51. package/transformer/plugins/document.js +18 -26
  52. package/transformer/plugins/extract.d.ts +1 -1
  53. package/transformer/plugins/extract.js +3 -4
  54. package/transformer/plugins/parse.d.ts +1 -1
  55. package/transformer/plugins/read.d.ts +2 -3
  56. package/transformer/plugins/readme.d.ts +1 -1
  57. package/transformer/plugins/style.d.ts +1 -1
  58. package/transformer/plugins/validate.d.ts +1 -1
  59. package/transformer/plugins/validate.js +1 -2
  60. package/transformer/plugins/visualStudioCode.d.ts +1 -1
  61. package/transformer/plugins/visualStudioCode.js +3 -4
  62. package/transformer/plugins/webTypes.d.ts +1 -1
  63. package/transformer/plugins/webTypes.js +15 -19
  64. package/transformer/transformer.d.ts +1 -1
  65. package/transformer/utils/addDependency.js +2 -3
  66. package/transformer/utils/extractAttribute.js +1 -1
  67. package/transformer/utils/extractFromComment.js +11 -8
  68. package/transformer/utils/getInitializer.js +1 -2
  69. package/transformer/utils/getType.js +3 -3
  70. package/transformer/utils/hasDecorator.js +1 -1
@@ -1,4 +1,4 @@
1
- import { TransformerPlugin } from '../transformer.types';
1
+ import { TransformerPlugin } from '../transformer.types.js';
2
2
  export declare const COPY_OPTIONS: Partial<CopyOptions>;
3
3
  export interface CopyOptions {
4
4
  at?: 'start' | 'run' | 'finish';
@@ -1,4 +1,4 @@
1
- import { TransformerPlugin } from '../transformer.types';
1
+ import { TransformerPlugin } from '../transformer.types.js';
2
2
  export declare const CUSTOM_ELEMENT_OPTIONS: Partial<CustomElementOptions>;
3
3
  export interface CustomElementOptions {
4
4
  prefix?: string;
@@ -49,8 +49,7 @@ export const customElement = (options) => {
49
49
  if (name.name != 'className')
50
50
  return;
51
51
  const hasClass = path.parentPath.node.attributes.some((attribute) => {
52
- var _a;
53
- return ((_a = attribute.name) === null || _a === void 0 ? void 0 : _a.name) == 'class';
52
+ return attribute.name?.name == 'class';
54
53
  });
55
54
  if (hasClass)
56
55
  return path.remove();
@@ -61,6 +60,10 @@ export const customElement = (options) => {
61
60
  visitor(ast, {
62
61
  JSXAttribute(path) {
63
62
  const { name, value } = path.node;
63
+ if (name.name == 'value') {
64
+ name.name = '.' + name.name;
65
+ return;
66
+ }
64
67
  const key = ['tabIndex', 'viewBox'];
65
68
  if (!key.includes(name.name))
66
69
  return;
@@ -79,13 +82,12 @@ export const customElement = (options) => {
79
82
  return t.callExpression(t.identifier(local), [
80
83
  node,
81
84
  t.arrayExpression(attributes.map((attribute) => {
82
- var _a;
83
85
  switch (attribute.type) {
84
86
  case 'JSXSpreadAttribute':
85
87
  return attribute.argument;
86
88
  default:
87
89
  return t.objectExpression([
88
- t.objectProperty(t.stringLiteral(attribute.name.name), ((_a = attribute.value) === null || _a === void 0 ? void 0 : _a.type) == 'JSXExpressionContainer'
90
+ t.objectProperty(t.stringLiteral(attribute.name.name), attribute.value?.type == 'JSXExpressionContainer'
89
91
  ? attribute.value.expression
90
92
  : attribute.value || t.booleanLiteral(true))
91
93
  ]);
@@ -181,9 +183,8 @@ export const customElement = (options) => {
181
183
  // add type to properties
182
184
  visitor(ast, {
183
185
  Decorator(path) {
184
- var _a, _b;
185
186
  const { expression } = path.node;
186
- if (((_a = expression.callee) === null || _a === void 0 ? void 0 : _a.name) != CONSTANTS.DECORATOR_PROPERTY)
187
+ if (expression.callee?.name != CONSTANTS.DECORATOR_PROPERTY)
187
188
  return;
188
189
  if (!expression.arguments.length) {
189
190
  expression.arguments.push(t.objectExpression([]));
@@ -197,8 +198,7 @@ export const customElement = (options) => {
197
198
  argument.properties = filtered;
198
199
  let type = 0;
199
200
  const extract = (input) => {
200
- var _a;
201
- switch (input === null || input === void 0 ? void 0 : input.type) {
201
+ switch (input?.type) {
202
202
  case 'BooleanLiteral':
203
203
  type |= CONSTANTS.TYPE_BOOLEAN;
204
204
  break;
@@ -264,8 +264,8 @@ export const customElement = (options) => {
264
264
  break;
265
265
  }
266
266
  // TODO
267
- if ((input === null || input === void 0 ? void 0 : input.type) == 'TSParenthesizedType' &&
268
- ((_a = input === null || input === void 0 ? void 0 : input.typeAnnotation) === null || _a === void 0 ? void 0 : _a.type) == 'TSIntersectionType') {
267
+ if (input?.type == 'TSParenthesizedType' &&
268
+ input?.typeAnnotation?.type == 'TSIntersectionType') {
269
269
  let types = input.types || input.typeAnnotation.types;
270
270
  if (types.length != 2)
271
271
  return;
@@ -275,7 +275,7 @@ export const customElement = (options) => {
275
275
  extract(types[0]);
276
276
  }
277
277
  };
278
- extract(getType(context.directoryPath, ast, (_b = path.parentPath.node.typeAnnotation) === null || _b === void 0 ? void 0 : _b.typeAnnotation));
278
+ extract(getType(context.directoryPath, ast, path.parentPath.node.typeAnnotation?.typeAnnotation));
279
279
  argument.properties.push(t.objectProperty(t.identifier(CONSTANTS.DECORATOR_PROPERTY_TYPE), t.numericLiteral(type)));
280
280
  }
281
281
  });
@@ -294,12 +294,11 @@ export const customElement = (options) => {
294
294
  });
295
295
  });
296
296
  const events = context.classEvents.map((event) => {
297
- var _a;
298
297
  const key = event.key;
299
298
  const typeAnnotation = event.typeAnnotation;
300
299
  return Object.assign(t.tSPropertySignature(t.identifier(camelCase('on-' + key.name)), t.tsTypeAnnotation(t.tsFunctionType(undefined, [
301
300
  Object.assign({}, t.identifier('event'), {
302
- typeAnnotation: t.tsTypeAnnotation(t.tsTypeReference(t.identifier('CustomEvent'), (_a = typeAnnotation === null || typeAnnotation === void 0 ? void 0 : typeAnnotation['typeAnnotation']) === null || _a === void 0 ? void 0 : _a.typeParameters))
301
+ typeAnnotation: t.tsTypeAnnotation(t.tsTypeReference(t.identifier('CustomEvent'), typeAnnotation?.['typeAnnotation']?.typeParameters))
303
302
  })
304
303
  ], t.tsTypeAnnotation(t.tsVoidKeyword())))), {
305
304
  optional: true,
@@ -1,4 +1,4 @@
1
- import { TransformerPlugin, TransformerPluginContext } from '../transformer.types';
1
+ import { TransformerPlugin, TransformerPluginContext } from '../transformer.types.js';
2
2
  export declare const DOCUMENT_OPTIONS: Partial<DocumentOptions>;
3
3
  export interface DocumentOptions {
4
4
  destination: string;
@@ -11,13 +11,11 @@ export const document = (options) => {
11
11
  const name = 'document';
12
12
  options = Object.assign({}, DOCUMENT_OPTIONS, options);
13
13
  const finish = (global) => {
14
- var _a, _b;
15
14
  const json = {
16
15
  elements: []
17
16
  };
18
17
  for (const context of global.contexts) {
19
18
  const events = context.classEvents.map((event) => {
20
- var _a, _b;
21
19
  const cancelable = (() => {
22
20
  if (!event.decorators)
23
21
  return false;
@@ -36,11 +34,11 @@ export const document = (options) => {
36
34
  }
37
35
  }
38
36
  }
39
- catch (_a) { }
37
+ catch { }
40
38
  return false;
41
39
  })();
42
- const detail = print((_a = event.typeAnnotation) === null || _a === void 0 ? void 0 : _a['typeAnnotation']);
43
- const detailReference = getTypeReference(context.fileAST, (_b = event.typeAnnotation) === null || _b === void 0 ? void 0 : _b['typeAnnotation'].typeParameters.params[0]);
40
+ const detail = print(event.typeAnnotation?.['typeAnnotation']);
41
+ const detailReference = getTypeReference(context.fileAST, event.typeAnnotation?.['typeAnnotation'].typeParameters.params[0]);
44
42
  const name = event.key['name'];
45
43
  return Object.assign({
46
44
  cancelable,
@@ -55,36 +53,31 @@ export const document = (options) => {
55
53
  .sort((a, b) => (a > b ? 1 : -1))
56
54
  .pop();
57
55
  const methods = context.classMethods.map((method) => {
58
- var _a, _b;
59
56
  const async = method.async;
60
57
  const name = method.key['name'];
61
58
  const comments = extractFromComment(method);
62
59
  // TODO
63
- const parameters = method.params.map((param) => {
64
- var _a, _b, _c, _d;
65
- return ({
66
- description: (_b = (_a = comments.params) === null || _a === void 0 ? void 0 : _a.find((item) => item.name == param['name'])) === null || _b === void 0 ? void 0 : _b.description,
67
- required: !param['optional'],
68
- name: param['name'],
69
- type: print((_c = param === null || param === void 0 ? void 0 : param['typeAnnotation']) === null || _c === void 0 ? void 0 : _c.typeAnnotation) || undefined,
70
- typeReference: getTypeReference(context.fileAST, (_d = param === null || param === void 0 ? void 0 : param['typeAnnotation']) === null || _d === void 0 ? void 0 : _d.typeAnnotation)
71
- });
72
- });
60
+ const parameters = method.params.map((param) => ({
61
+ description: comments.params?.find((item) => item.name == param['name'])?.description,
62
+ required: !param['optional'],
63
+ name: param['name'],
64
+ type: print(param?.['typeAnnotation']?.typeAnnotation) || undefined,
65
+ typeReference: getTypeReference(context.fileAST, param?.['typeAnnotation']?.typeAnnotation)
66
+ }));
73
67
  // TODO
74
68
  delete comments.params;
75
- const returns = print((_a = method.returnType) === null || _a === void 0 ? void 0 : _a['typeAnnotation']) || 'void';
76
- const returnsReference = getTypeReference(context.fileAST, (_b = method.returnType) === null || _b === void 0 ? void 0 : _b['typeAnnotation']);
69
+ const returns = print(method.returnType?.['typeAnnotation']) || 'void';
70
+ const returnsReference = getTypeReference(context.fileAST, method.returnType?.['typeAnnotation']);
77
71
  const signature = [
78
72
  method.key['name'],
79
73
  '(',
80
74
  parameters
81
75
  .map((parameter) => {
82
- var _a;
83
76
  let string = '';
84
77
  string += parameter.name;
85
78
  string += parameter.required ? '' : '?';
86
79
  string += parameter.type ? ': ' : '';
87
- string += (_a = parameter.type) !== null && _a !== void 0 ? _a : '';
80
+ string += parameter.type ?? '';
88
81
  return string;
89
82
  })
90
83
  .join(', '),
@@ -116,7 +109,6 @@ export const document = (options) => {
116
109
  });
117
110
  });
118
111
  const properties = context.classProperties.map((property) => {
119
- var _a, _b, _c;
120
112
  const attribute = extractAttribute(property) || kebabCase(property.key['name']);
121
113
  // TODO
122
114
  const initializer = getInitializer(property.value);
@@ -141,15 +133,15 @@ export const document = (options) => {
141
133
  }
142
134
  }
143
135
  }
144
- catch (_a) { }
136
+ catch { }
145
137
  return false;
146
138
  })();
147
139
  const required = 'optional' in property && !property.optional;
148
140
  // TODO
149
141
  const type = property['returnType']
150
- ? print((_a = property['returnType']) === null || _a === void 0 ? void 0 : _a['typeAnnotation'])
151
- : print((_b = property.typeAnnotation) === null || _b === void 0 ? void 0 : _b['typeAnnotation']);
152
- const typeReference = getTypeReference(context.fileAST, (_c = property.typeAnnotation) === null || _c === void 0 ? void 0 : _c['typeAnnotation']);
142
+ ? print(property['returnType']?.['typeAnnotation'])
143
+ : print(property.typeAnnotation?.['typeAnnotation']);
144
+ const typeReference = getTypeReference(context.fileAST, property.typeAnnotation?.['typeAnnotation']);
153
145
  return Object.assign({
154
146
  attribute,
155
147
  initializer,
@@ -191,7 +183,7 @@ export const document = (options) => {
191
183
  styles,
192
184
  title
193
185
  }, extractFromComment(context.class));
194
- const transformed = ((_b = (_a = options).transformer) === null || _b === void 0 ? void 0 : _b.call(_a, context, element)) || element;
186
+ const transformed = options.transformer?.(context, element) || element;
195
187
  json.elements.push(transformed);
196
188
  }
197
189
  json.elements = json.elements.sort((a, b) => (a.title > b.title ? 1 : -1));
@@ -1,2 +1,2 @@
1
- import { TransformerPlugin } from '../transformer.types';
1
+ import { TransformerPlugin } from '../transformer.types.js';
2
2
  export declare const extract: () => TransformerPlugin;
@@ -5,14 +5,13 @@ import { hasDecorator } from '../utils/index.js';
5
5
  export const extract = () => {
6
6
  const name = 'extract';
7
7
  const run = (context) => {
8
- var _a, _b, _c, _d, _e;
9
- const { declaration, leadingComments } = (_a = context.fileAST) === null || _a === void 0 ? void 0 : _a.program.body.find((child) => {
8
+ const { declaration, leadingComments } = context.fileAST?.program.body.find((child) => {
10
9
  return t.isExportNamedDeclaration(child);
11
10
  });
12
11
  context.class = declaration;
13
12
  context.class.leadingComments = leadingComments; // TODO
14
- context.classMembers = ((_c = (_b = context.class) === null || _b === void 0 ? void 0 : _b.body) === null || _c === void 0 ? void 0 : _c.body) || [];
15
- context.className = (_e = (_d = context.class) === null || _d === void 0 ? void 0 : _d.id) === null || _e === void 0 ? void 0 : _e.name;
13
+ context.classMembers = context.class?.body?.body || [];
14
+ context.className = context.class?.id?.name;
16
15
  context.elementKey = kebabCase(context.className || '');
17
16
  context.classEvents = context.classMembers.filter((member) => hasDecorator(member, CONSTANTS.DECORATOR_EVENT));
18
17
  context.classMethods = context.classMembers.filter((member) => hasDecorator(member, CONSTANTS.DECORATOR_METHOD));
@@ -1,5 +1,5 @@
1
1
  import { ParserOptions } from '@babel/parser';
2
- import { TransformerPlugin } from '../transformer.types';
2
+ import { TransformerPlugin } from '../transformer.types.js';
3
3
  export declare const PARSE_OPTIONS: Partial<ParseOptions>;
4
4
  export interface ParseOptions extends ParserOptions {
5
5
  }
@@ -1,8 +1,7 @@
1
- /// <reference types="node" />
2
- import { TransformerPlugin } from '../transformer.types';
1
+ import { TransformerPlugin } from '../transformer.types.js';
3
2
  export declare const READ_OPTIONS: Partial<ReadOptions>;
4
3
  export interface ReadOptions {
5
- encoding: BufferEncoding;
4
+ encoding: 'utf8' | 'ascii' | 'utf-8' | 'utf16le' | 'utf-16le' | 'ucs2' | 'ucs-2' | 'base64' | 'base64url' | 'latin1' | 'binary' | 'hex';
6
5
  flag?: string | undefined;
7
6
  }
8
7
  export declare const read: (options?: ReadOptions) => TransformerPlugin;
@@ -1,4 +1,4 @@
1
- import { TransformerPlugin, TransformerPluginContext } from '../transformer.types';
1
+ import { TransformerPlugin, TransformerPluginContext } from '../transformer.types.js';
2
2
  export declare const README_OPTIONS: Partial<ReadmeOptions>;
3
3
  export interface ReadmeOptions {
4
4
  source?: (context: TransformerPluginContext) => string;
@@ -1,4 +1,4 @@
1
- import { TransformerPlugin, TransformerPluginContext } from '../transformer.types';
1
+ import { TransformerPlugin, TransformerPluginContext } from '../transformer.types.js';
2
2
  export declare const STYLE_OPTIONS: Partial<StyleOptions>;
3
3
  export interface StyleOptions {
4
4
  source?: (context: TransformerPluginContext) => string | string[];
@@ -1,2 +1,2 @@
1
- import { TransformerPlugin } from '../transformer.types';
1
+ import { TransformerPlugin } from '../transformer.types.js';
2
2
  export declare const validate: () => TransformerPlugin;
@@ -7,8 +7,7 @@ export const validate = () => {
7
7
  context.skipped = true;
8
8
  visitor(context.fileAST, {
9
9
  ImportDeclaration(path) {
10
- var _a;
11
- if (((_a = path.node.source) === null || _a === void 0 ? void 0 : _a.value) !== CONSTANTS.PACKAGE_NAME)
10
+ if (path.node.source?.value !== CONSTANTS.PACKAGE_NAME)
12
11
  return;
13
12
  for (const specifier of path.node.specifiers) {
14
13
  if (specifier.imported.name !== CONSTANTS.DECORATOR_ELEMENT)
@@ -1,4 +1,4 @@
1
- import { TransformerPlugin, TransformerPluginContext } from '../transformer.types';
1
+ import { TransformerPlugin, TransformerPluginContext } from '../transformer.types.js';
2
2
  export declare const VISUAL_STUDIO_CODE_OPTIONS: Partial<VisualStudioCodeOptions>;
3
3
  export interface VisualStudioCodeOptions {
4
4
  destination?: string;
@@ -9,7 +9,6 @@ export const visualStudioCode = (options) => {
9
9
  const name = 'visualStudioCode';
10
10
  options = Object.assign({}, VISUAL_STUDIO_CODE_OPTIONS, options);
11
11
  const finish = (global) => {
12
- var _a, _b, _c, _d, _e;
13
12
  const contexts = global.contexts.sort((a, b) => {
14
13
  return a.elementKey.toUpperCase() > b.elementKey.toUpperCase() ? +1 : -1;
15
14
  });
@@ -25,7 +24,7 @@ export const visualStudioCode = (options) => {
25
24
  references: [
26
25
  {
27
26
  name: 'Source code',
28
- url: (_b = (_a = options).reference) === null || _b === void 0 ? void 0 : _b.call(_a, context)
27
+ url: options.reference?.(context)
29
28
  }
30
29
  ]
31
30
  }, extractFromComment(context.class, ['description']));
@@ -34,7 +33,7 @@ export const visualStudioCode = (options) => {
34
33
  name: extractAttribute(property) || kebabCase(property.key['name']),
35
34
  values: []
36
35
  }, extractFromComment(property, ['description']));
37
- const type = print(getType(context.directoryPath, context.fileAST, (_c = property.typeAnnotation) === null || _c === void 0 ? void 0 : _c['typeAnnotation']));
36
+ const type = print(getType(context.directoryPath, context.fileAST, property.typeAnnotation?.['typeAnnotation']));
38
37
  const sections = type.split('|');
39
38
  for (const section of sections) {
40
39
  const trimmed = section.trim();
@@ -63,7 +62,7 @@ export const visualStudioCode = (options) => {
63
62
  }
64
63
  tag.attributes.push(attribute);
65
64
  }
66
- const transformed = ((_e = (_d = options).transformer) === null || _e === void 0 ? void 0 : _e.call(_d, context, tag)) || tag;
65
+ const transformed = options.transformer?.(context, tag) || tag;
67
66
  json.tags.push(transformed);
68
67
  }
69
68
  const dirname = path.dirname(options.destination);
@@ -1,4 +1,4 @@
1
- import { TransformerPlugin, TransformerPluginContext } from '../transformer.types';
1
+ import { TransformerPlugin, TransformerPluginContext } from '../transformer.types.js';
2
2
  export declare const WEB_TYPES_OPTIONS: Partial<WebTypesOptions>;
3
3
  export interface WebTypesOptions {
4
4
  destination?: string;
@@ -11,7 +11,6 @@ export const webTypes = (options) => {
11
11
  const name = 'webTypes';
12
12
  options = Object.assign({}, WEB_TYPES_OPTIONS, options);
13
13
  const finish = (global) => {
14
- var _a, _b, _c, _d, _e, _f, _g, _h;
15
14
  const contexts = global.contexts.sort((a, b) => {
16
15
  return a.elementKey.toUpperCase() > b.elementKey.toUpperCase() ? +1 : -1;
17
16
  });
@@ -32,42 +31,39 @@ export const webTypes = (options) => {
32
31
  }
33
32
  };
34
33
  for (const context of contexts) {
35
- const attributes = (_a = context.classProperties) === null || _a === void 0 ? void 0 : _a.map((property) => {
36
- var _a;
37
- return Object.assign({
38
- name: extractAttribute(property) || kebabCase(property.key['name']),
39
- value: {
40
- // kind: TODO
41
- type: print(getType(context.directoryPath, context.fileAST, (_a = property.typeAnnotation) === null || _a === void 0 ? void 0 : _a['typeAnnotation']))
42
- // required: TODO
43
- // default: TODO
44
- },
45
- default: getInitializer(property.value)
46
- }, extractFromComment(property, ['description', 'deprecated', 'experimental']));
47
- });
48
- const events = (_b = context.classEvents) === null || _b === void 0 ? void 0 : _b.map((event) => Object.assign({
34
+ const attributes = context.classProperties?.map((property) => Object.assign({
35
+ name: extractAttribute(property) || kebabCase(property.key['name']),
36
+ value: {
37
+ // kind: TODO
38
+ type: print(getType(context.directoryPath, context.fileAST, property.typeAnnotation?.['typeAnnotation']))
39
+ // required: TODO
40
+ // default: TODO
41
+ },
42
+ default: getInitializer(property.value)
43
+ }, extractFromComment(property, ['description', 'deprecated', 'experimental'])));
44
+ const events = context.classEvents?.map((event) => Object.assign({
49
45
  name: kebabCase(event.key['name']) // TODO
50
46
  // 'value': TODO
51
47
  }, extractFromComment(event, ['description', 'deprecated', 'experimental'])));
52
- const methods = (_c = context.classMethods) === null || _c === void 0 ? void 0 : _c.map((method) => Object.assign({
48
+ const methods = context.classMethods?.map((method) => Object.assign({
53
49
  name: method.key['name']
54
50
  // 'value': TODO
55
51
  }, extractFromComment(method, ['description', 'deprecated', 'experimental'])));
56
- const properties = (_d = context.classProperties) === null || _d === void 0 ? void 0 : _d.map((property) => Object.assign({
52
+ const properties = context.classProperties?.map((property) => Object.assign({
57
53
  name: property.key['name'],
58
54
  // 'value': TODO
59
55
  default: getInitializer(property.value)
60
56
  }, extractFromComment(property, ['description', 'deprecated', 'experimental'])));
61
57
  const element = Object.assign({
62
58
  'name': context.elementKey,
63
- 'doc-url': (_f = (_e = options).reference) === null || _f === void 0 ? void 0 : _f.call(_e, context),
59
+ 'doc-url': options.reference?.(context),
64
60
  'js': {
65
61
  events,
66
62
  properties: [].concat(properties, methods)
67
63
  },
68
64
  attributes
69
65
  }, extractFromComment(context.class, ['description', 'deprecated', 'experimental', 'slots']));
70
- const transformed = ((_h = (_g = options).transformer) === null || _h === void 0 ? void 0 : _h.call(_g, context, element)) || element;
66
+ const transformed = options.transformer?.(context, element) || element;
71
67
  json.contributions.html.elements.push(transformed);
72
68
  }
73
69
  const dirname = path.dirname(options.destination);
@@ -1,4 +1,4 @@
1
- import { TransformerPlugin, TransformerPluginContext } from './transformer.types';
1
+ import { TransformerPlugin, TransformerPluginContext } from './transformer.types.js';
2
2
  export declare const transformer: (...plugins: TransformerPlugin[]) => {
3
3
  start: () => Promise<void>;
4
4
  run: (filePath: string) => Promise<TransformerPluginContext>;
@@ -21,13 +21,12 @@ export function addDependency(path, source, local, imported, comment) {
21
21
  return {
22
22
  node: declaration
23
23
  };
24
- let specifier = declaration === null || declaration === void 0 ? void 0 : declaration.specifiers.find((specifier) => {
25
- var _a;
24
+ let specifier = declaration?.specifiers.find((specifier) => {
26
25
  if (isDefault) {
27
26
  return specifier.type == 'ImportDefaultSpecifier';
28
27
  }
29
28
  else if (isImport) {
30
- return ((_a = specifier.imported) === null || _a === void 0 ? void 0 : _a.name) == imported;
29
+ return specifier.imported?.name == imported;
31
30
  }
32
31
  });
33
32
  if (specifier)
@@ -6,5 +6,5 @@ export const extractAttribute = (property) => {
6
6
  .expression.arguments[0].properties.find((property) => property.key.name == 'attribute').value
7
7
  .value;
8
8
  }
9
- catch (_a) { }
9
+ catch { }
10
10
  };
@@ -1,14 +1,17 @@
1
1
  export const extractFromComment = (node, whitelist) => {
2
- var _a, _b, _c, _d, _e, _f, _g, _h;
3
2
  const normalized = [];
4
3
  const result = {
5
4
  description: ''
6
5
  };
7
- const lines = (_d = (_c = (_b = (_a = node.leadingComments) === null || _a === void 0 ? void 0 : _a.map((comment) => {
6
+ const lines = node.leadingComments
7
+ ?.map((comment) => {
8
8
  if (comment.type == 'CommentLine')
9
9
  return comment.value;
10
10
  return comment.value.split('\n');
11
- })) === null || _b === void 0 ? void 0 : _b.flat()) === null || _c === void 0 ? void 0 : _c.map((line) => line.trim().replace(/^\*/, '').trim())) === null || _d === void 0 ? void 0 : _d.filter((line) => line.trim());
11
+ })
12
+ ?.flat()
13
+ ?.map((line) => line.trim().replace(/^\*/, '').trim())
14
+ ?.filter((line) => line.trim());
12
15
  for (const line of lines || []) {
13
16
  if (line.startsWith('@')) {
14
17
  normalized.push(line);
@@ -27,15 +30,15 @@ export const extractFromComment = (node, whitelist) => {
27
30
  const groups = regex.exec(line);
28
31
  if (!groups)
29
32
  continue;
30
- const tag = (_e = groups[1]) === null || _e === void 0 ? void 0 : _e.trim();
31
- const type = (_f = groups[2]) === null || _f === void 0 ? void 0 : _f.trim().slice(1, -1);
32
- const name = (_g = groups[3]) === null || _g === void 0 ? void 0 : _g.trim();
33
- const description = (_h = groups[4]) === null || _h === void 0 ? void 0 : _h.trim();
33
+ const tag = groups[1]?.trim();
34
+ const type = groups[2]?.trim().slice(1, -1);
35
+ const name = groups[3]?.trim();
36
+ const description = groups[4]?.trim();
34
37
  if (name && description) {
35
38
  const key = tag + 's';
36
39
  if (whitelist && !whitelist.includes(key))
37
40
  continue;
38
- (result[key] || (result[key] = [])).push({ name, type, description });
41
+ (result[key] ||= []).push({ name, type, description });
39
42
  }
40
43
  else {
41
44
  const key = tag;
@@ -1,4 +1,3 @@
1
1
  export const getInitializer = (node) => {
2
- var _a;
3
- return ((_a = node === null || node === void 0 ? void 0 : node.extra) === null || _a === void 0 ? void 0 : _a.raw) || (node === null || node === void 0 ? void 0 : node['value']);
2
+ return node?.extra?.raw || node?.['value'];
4
3
  };
@@ -42,14 +42,14 @@ export const getType = (directory, file, node) => {
42
42
  .find((reference) => fs.existsSync(reference));
43
43
  const content = fs.readFileSync(reference, 'utf8');
44
44
  const filePath = resolve(directory, path.node.source.value + '.ts');
45
- path.$ast || (path.$ast = parse(content, {
45
+ path.$ast ||= parse(content, {
46
46
  allowImportExportEverywhere: true,
47
47
  plugins: ['typescript'],
48
48
  ranges: false
49
- }));
49
+ });
50
50
  result = getType(dirname(filePath), path.$ast, node);
51
51
  }
52
- catch (_a) { }
52
+ catch { }
53
53
  path.stop();
54
54
  break;
55
55
  }
@@ -1,5 +1,5 @@
1
1
  export const hasDecorator = (node, name) => {
2
2
  if (!node.decorators)
3
3
  return false;
4
- return !!node.decorators.some((decorator) => { var _a; return ((_a = decorator.expression.callee) === null || _a === void 0 ? void 0 : _a.name) == name; });
4
+ return !!node.decorators.some((decorator) => decorator.expression.callee?.name == name);
5
5
  };