@htmlplus/element 0.4.5 → 0.4.8

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/bundlers/index.d.ts +2 -0
  2. package/bundlers/index.js +2 -0
  3. package/bundlers/rollup.d.ts +7 -0
  4. package/bundlers/rollup.js +21 -0
  5. package/bundlers/vite.d.ts +7 -0
  6. package/bundlers/vite.js +25 -0
  7. package/client/decorators/attributes.d.ts +1 -1
  8. package/client/decorators/attributes.js +4 -4
  9. package/client/decorators/element.d.ts +1 -1
  10. package/client/decorators/element.js +14 -22
  11. package/client/decorators/event.d.ts +1 -1
  12. package/client/decorators/listen.d.ts +1 -1
  13. package/client/decorators/method.d.ts +1 -1
  14. package/client/decorators/property.d.ts +1 -1
  15. package/client/decorators/property.js +4 -4
  16. package/client/decorators/state.d.ts +1 -1
  17. package/client/decorators/state.js +4 -4
  18. package/client/decorators/watch.d.ts +1 -1
  19. package/client/helpers/direction.d.ts +1 -1
  20. package/client/helpers/isRTL.d.ts +1 -1
  21. package/client/helpers/slots.d.ts +1 -1
  22. package/client/utils/getMemberType.d.ts +1 -1
  23. package/client/utils/getMemberType.js +2 -2
  24. package/client/utils/getMembersKey.d.ts +1 -1
  25. package/client/utils/getStyles.d.ts +1 -1
  26. package/client/utils/host.d.ts +1 -1
  27. package/client/utils/index.d.ts +1 -1
  28. package/client/utils/index.js +1 -1
  29. package/client/utils/request.d.ts +1 -1
  30. package/client/utils/request.js +3 -3
  31. package/client/utils/syncAttributes.d.ts +1 -0
  32. package/client/utils/{sync.js → syncAttributes.js} +1 -1
  33. package/client/{vendor → vendors}/uhtml.d.ts +7 -0
  34. package/client/{vendor → vendors}/uhtml.js +1 -0
  35. package/compiler/compiler.d.ts +1 -1
  36. package/compiler/plugins/assets.d.ts +1 -1
  37. package/compiler/plugins/copy.d.ts +13 -0
  38. package/compiler/plugins/copy.js +26 -0
  39. package/compiler/plugins/customElement.d.ts +1 -1
  40. package/compiler/plugins/customElement.js +31 -38
  41. package/compiler/plugins/customElementReact/customElementReact.d.ts +1 -1
  42. package/compiler/plugins/document.d.ts +1 -1
  43. package/compiler/plugins/document.js +37 -35
  44. package/compiler/plugins/extract.d.ts +1 -1
  45. package/compiler/plugins/index.d.ts +1 -0
  46. package/compiler/plugins/index.js +1 -0
  47. package/compiler/plugins/parse.d.ts +1 -1
  48. package/compiler/plugins/read.d.ts +1 -1
  49. package/compiler/plugins/style.d.ts +2 -2
  50. package/compiler/plugins/style.js +6 -2
  51. package/compiler/plugins/validate.d.ts +1 -1
  52. package/compiler/plugins/visualStudioCode.d.ts +1 -1
  53. package/compiler/plugins/webTypes.d.ts +2 -2
  54. package/compiler/plugins/webTypes.js +75 -51
  55. package/compiler/utils/addDependency.d.ts +9 -2
  56. package/compiler/utils/addDependency.js +35 -16
  57. package/compiler/utils/getInitializer.d.ts +1 -1
  58. package/compiler/utils/getInitializer.js +2 -8
  59. package/compiler/utils/index.d.ts +1 -0
  60. package/compiler/utils/index.js +1 -0
  61. package/compiler/utils/removeUnusedImport.d.ts +1 -0
  62. package/compiler/utils/removeUnusedImport.js +49 -0
  63. package/constants/index.d.ts +9 -2
  64. package/constants/index.js +10 -2
  65. package/package.json +5 -11
  66. package/types/global.d.ts +1 -1
  67. package/types/index.d.ts +4 -4
  68. package/types/index.js +4 -4
  69. package/types/plugin.d.ts +1 -1
  70. package/client/utils/sync.d.ts +0 -1
@@ -0,0 +1,2 @@
1
+ export * from './rollup.js';
2
+ export * from './vite.js';
@@ -0,0 +1,2 @@
1
+ export * from './rollup.js';
2
+ export * from './vite.js';
@@ -0,0 +1,7 @@
1
+ import { Plugin } from '../types';
2
+ export declare const rollup: (...plugins: Array<Plugin>) => {
3
+ name: string;
4
+ buildStart(): Promise<void>;
5
+ load(id: any): Promise<string | undefined>;
6
+ buildEnd(): Promise<void>;
7
+ };
@@ -0,0 +1,21 @@
1
+ import compiler from '../compiler/index.js';
2
+ export const rollup = (...plugins) => {
3
+ const { start, next, finish } = compiler(...plugins);
4
+ return {
5
+ name: 'htmlplus',
6
+ async buildStart() {
7
+ await start();
8
+ },
9
+ async load(id) {
10
+ if (!id.endsWith('.tsx'))
11
+ return;
12
+ const { isInvalid, script } = await next(id);
13
+ if (isInvalid)
14
+ return;
15
+ return script;
16
+ },
17
+ async buildEnd() {
18
+ await finish();
19
+ }
20
+ };
21
+ };
@@ -0,0 +1,7 @@
1
+ import { Plugin } from '../types';
2
+ export declare const vite: (...plugins: Array<Plugin>) => {
3
+ name: string;
4
+ buildStart(): Promise<void>;
5
+ load(id: any): Promise<string | undefined>;
6
+ buildEnd(): Promise<void>;
7
+ };
@@ -0,0 +1,25 @@
1
+ import path from 'path';
2
+ import compiler from '../compiler/index.js';
3
+ export const vite = (...plugins) => {
4
+ const { start, next, finish } = compiler(...plugins);
5
+ return {
6
+ name: 'htmlplus',
7
+ async buildStart() {
8
+ await start();
9
+ },
10
+ async load(id) {
11
+ if (!id.endsWith('.tsx'))
12
+ return;
13
+ let { isInvalid, script, stylePath } = await next(id);
14
+ if (isInvalid)
15
+ return;
16
+ if (script && stylePath) {
17
+ script = script.replace(path.basename(stylePath), `${path.basename(stylePath)}?inline`);
18
+ }
19
+ return script;
20
+ },
21
+ async buildEnd() {
22
+ await finish();
23
+ }
24
+ };
25
+ };
@@ -1,2 +1,2 @@
1
- import { PlusElement } from '../../types/index.js';
1
+ import { PlusElement } from '../../types';
2
2
  export declare function Attributes(): (target: PlusElement, propertyKey: PropertyKey) => void;
@@ -1,13 +1,13 @@
1
1
  import * as CONSTANTS from '../../constants/index.js';
2
- import { appendToMethod, host, sync } from '../utils/index.js';
2
+ import { appendToMethod, host, syncAttributes } from '../utils/index.js';
3
3
  export function Attributes() {
4
4
  return function (target, propertyKey) {
5
- const updates = new Map();
5
+ const symbol = Symbol();
6
6
  appendToMethod(target, CONSTANTS.LIFECYCLE_CONNECTED, function () {
7
- updates.set(this, sync(host(this)));
7
+ this[symbol] = syncAttributes(host(this));
8
8
  });
9
9
  appendToMethod(target, CONSTANTS.LIFECYCLE_UPDATED, function () {
10
- updates.get(this)(this[propertyKey]);
10
+ this[symbol](this[propertyKey]);
11
11
  });
12
12
  };
13
13
  }
@@ -1,2 +1,2 @@
1
- import { PlusElement } from '../../types/index.js';
1
+ import { PlusElement } from '../../types';
2
2
  export declare function Element(tag?: string): (constructor: PlusElement) => void;
@@ -1,58 +1,50 @@
1
1
  import { camelCase, paramCase } from 'change-case';
2
2
  import * as CONSTANTS from '../../constants/index.js';
3
3
  import { call, getMembersKey, getMemberType, isServer, parseValue, request } from '../utils/index.js';
4
- import * as uhtml from '../vendor/uhtml.js';
5
4
  export function Element(tag) {
6
5
  return function (constructor) {
7
6
  if (isServer())
8
7
  return;
9
8
  if (customElements.get(tag))
10
9
  return;
11
- const instances = new Map();
12
10
  class Plus extends HTMLElement {
13
11
  constructor() {
14
12
  super();
15
13
  this.attachShadow({ mode: 'open' });
16
14
  // TODO
17
- const instance = new constructor();
18
- instances.set(this, instance);
19
- instance[CONSTANTS.API_HOST] = () => this;
20
- instance['uhtml'] = uhtml;
21
- instance[CONSTANTS.API_STATUS] = 'initialize';
15
+ this[CONSTANTS.API_INSTANCE] = new constructor();
16
+ this[CONSTANTS.API_INSTANCE][CONSTANTS.API_HOST] = () => this;
17
+ this[CONSTANTS.API_INSTANCE][CONSTANTS.API_STATUS] = 'initialize';
22
18
  }
19
+ // TODO: ignore functions
23
20
  static get observedAttributes() {
24
- // TODO: ignore functions
25
21
  return getMembersKey(constructor).map((key) => paramCase(key));
26
22
  }
27
23
  adoptedCallback() {
28
- const instance = instances.get(this);
29
- call(instance, CONSTANTS.LIFECYCLE_ADOPTED);
24
+ call(this[CONSTANTS.API_INSTANCE], CONSTANTS.LIFECYCLE_ADOPTED);
30
25
  }
31
26
  // TODO
32
27
  attributeChangedCallback(name, prev, next) {
33
- const instance = instances.get(this);
34
28
  const key = camelCase(name);
35
- const type = getMemberType(instance, key);
29
+ const type = getMemberType(this[CONSTANTS.API_INSTANCE], key);
36
30
  const parsed = parseValue(next, type);
37
- instance[key] = parsed;
31
+ this[CONSTANTS.API_INSTANCE][key] = parsed;
38
32
  }
39
33
  connectedCallback() {
40
- const instance = instances.get(this);
41
- instance[CONSTANTS.API_STATUS] = 'connected';
42
- call(instance, CONSTANTS.LIFECYCLE_CONNECTED);
43
- request(instance)
34
+ this[CONSTANTS.API_INSTANCE][CONSTANTS.API_STATUS] = 'connected';
35
+ call(this[CONSTANTS.API_INSTANCE], CONSTANTS.LIFECYCLE_CONNECTED);
36
+ request(this[CONSTANTS.API_INSTANCE])
44
37
  .then(() => {
45
- instance[CONSTANTS.API_STATUS] = 'loaded';
46
- call(instance, CONSTANTS.LIFECYCLE_LOADED);
38
+ this[CONSTANTS.API_INSTANCE][CONSTANTS.API_STATUS] = 'loaded';
39
+ call(this[CONSTANTS.API_INSTANCE], CONSTANTS.LIFECYCLE_LOADED);
47
40
  })
48
41
  .catch((error) => {
49
42
  throw error;
50
43
  });
51
44
  }
52
45
  disconnectedCallback() {
53
- const instance = instances.get(this);
54
- instance[CONSTANTS.API_STATUS] = 'disconnected';
55
- call(instance, CONSTANTS.LIFECYCLE_DISCONNECTED);
46
+ this[CONSTANTS.API_INSTANCE][CONSTANTS.API_STATUS] = 'disconnected';
47
+ call(this[CONSTANTS.API_INSTANCE], CONSTANTS.LIFECYCLE_DISCONNECTED);
56
48
  }
57
49
  }
58
50
  customElements.define(tag, Plus);
@@ -1,4 +1,4 @@
1
- import { PlusElement } from '../../types/index.js';
1
+ import { PlusElement } from '../../types';
2
2
  export declare type EventEmitter<T = any> = (data?: T) => CustomEvent<T>;
3
3
  export interface EventOptions {
4
4
  /**
@@ -1,4 +1,4 @@
1
- import { PlusElement } from '../../types/index.js';
1
+ import { PlusElement } from '../../types';
2
2
  export interface ListenOptions {
3
3
  target?: 'host' | 'body' | 'document' | 'window';
4
4
  once?: boolean;
@@ -1,2 +1,2 @@
1
- import { PlusElement } from '../../types/index.js';
1
+ import { PlusElement } from '../../types';
2
2
  export declare function Method(): (target: PlusElement, propertyKey: PropertyKey) => void;
@@ -1,4 +1,4 @@
1
- import { PlusElement } from '../../types/index.js';
1
+ import { PlusElement } from '../../types';
2
2
  export interface PropertyOptions {
3
3
  /**
4
4
  * Whether property value is reflected back to the associated attribute. default is `false`.
@@ -5,16 +5,16 @@ export function Property(options) {
5
5
  return function (target, propertyKey) {
6
6
  const name = String(propertyKey);
7
7
  const attribute = paramCase(name);
8
+ const symbol = Symbol();
8
9
  const type = getMemberType(target, name);
9
- const values = new Map();
10
10
  function get() {
11
- return values.get(this);
11
+ return this[symbol];
12
12
  }
13
13
  function set(input) {
14
- const value = values.get(this);
14
+ const value = this[symbol];
15
15
  if (input === value)
16
16
  return;
17
- values.set(this, input);
17
+ this[symbol] = input;
18
18
  const isReady = this[CONSTANTS.API_STATUS] == 'initialize';
19
19
  request(this, { [name]: [input, value] }).then(() => {
20
20
  const element = host(this);
@@ -1,2 +1,2 @@
1
- import { PlusElement } from '../../types/index.js';
1
+ import { PlusElement } from '../../types';
2
2
  export declare function State(): (target: PlusElement, propertyKey: PropertyKey) => void;
@@ -2,15 +2,15 @@ import { defineProperty, request } from '../utils/index.js';
2
2
  export function State() {
3
3
  return function (target, propertyKey) {
4
4
  const name = String(propertyKey);
5
- const values = new Map();
5
+ const symbol = Symbol();
6
6
  function get() {
7
- return values.get(this);
7
+ return this[symbol];
8
8
  }
9
9
  function set(input) {
10
- const value = values.get(this);
10
+ const value = this[symbol];
11
11
  if (input === value)
12
12
  return;
13
- values.set(this, input);
13
+ this[symbol] = input;
14
14
  request(this, { [name]: [input, value] })
15
15
  .then(() => undefined)
16
16
  .catch((error) => {
@@ -1,4 +1,4 @@
1
- import { PlusElement } from '../../types/index.js';
1
+ import { PlusElement } from '../../types';
2
2
  /**
3
3
  * Monitors properties and states to catch changes.
4
4
  * The decorated method will be invoked after any
@@ -1,3 +1,3 @@
1
- import { PlusElement } from '../../types/index.js';
1
+ import { PlusElement } from '../../types';
2
2
  export declare type Direction = 'ltr' | 'rtl';
3
3
  export declare const direction: (target: PlusElement) => Direction;
@@ -1,2 +1,2 @@
1
- import { PlusElement } from '../../types/index.js';
1
+ import { PlusElement } from '../../types';
2
2
  export declare const isRTL: (target: PlusElement) => boolean;
@@ -1,4 +1,4 @@
1
- import { PlusElement } from '../../types/index.js';
1
+ import { PlusElement } from '../../types';
2
2
  declare type Slots = {
3
3
  [key: string]: boolean;
4
4
  };
@@ -1,2 +1,2 @@
1
- import { PlusElement } from '../../types/index.js';
1
+ import { PlusElement } from '../../types';
2
2
  export declare const getMemberType: (target: PlusElement, key: string) => string;
@@ -1,5 +1,5 @@
1
1
  import * as CONSTANTS from '../../constants/index.js';
2
2
  export const getMemberType = (target, key) => {
3
- var _a;
4
- return (_a = (target.constructor[CONSTANTS.STATIC_MEMBERS] || target[CONSTANTS.STATIC_MEMBERS] || {})[key]) === null || _a === void 0 ? void 0 : _a[0];
3
+ var _a, _b;
4
+ return (_b = (_a = (target.constructor[CONSTANTS.STATIC_MEMBERS] || target[CONSTANTS.STATIC_MEMBERS])) === null || _a === void 0 ? void 0 : _a[key]) === null || _b === void 0 ? void 0 : _b[CONSTANTS.STATIC_MEMBERS_TYPE];
5
5
  };
@@ -1,2 +1,2 @@
1
- import { PlusElement } from '../../types/index.js';
1
+ import { PlusElement } from '../../types';
2
2
  export declare const getMembersKey: (target: PlusElement) => string[];
@@ -1,2 +1,2 @@
1
- import { PlusElement } from '../../types/index.js';
1
+ import { PlusElement } from '../../types';
2
2
  export declare const getStyles: (target: PlusElement) => string | undefined;
@@ -1,2 +1,2 @@
1
- import { PlusElement } from '../../types/index.js';
1
+ import { PlusElement } from '../../types';
2
2
  export declare const host: (target: PlusElement) => HTMLElement;
@@ -13,7 +13,7 @@ export * from './off.js';
13
13
  export * from './on.js';
14
14
  export * from './parseValue.js';
15
15
  export * from './request.js';
16
- export * from './sync.js';
16
+ export * from './syncAttributes.js';
17
17
  export * from './task.js';
18
18
  export * from './toBoolean.js';
19
19
  export * from './toEvent.js';
@@ -13,7 +13,7 @@ export * from './off.js';
13
13
  export * from './on.js';
14
14
  export * from './parseValue.js';
15
15
  export * from './request.js';
16
- export * from './sync.js';
16
+ export * from './syncAttributes.js';
17
17
  export * from './task.js';
18
18
  export * from './toBoolean.js';
19
19
  export * from './toEvent.js';
@@ -1,4 +1,4 @@
1
- import { PlusElement } from '../../types/index.js';
1
+ import { PlusElement } from '../../types';
2
2
  export declare const request: (target: PlusElement, state?: {
3
3
  [key: string]: [any, any];
4
4
  } | undefined) => Promise<boolean>;
@@ -1,7 +1,7 @@
1
1
  import * as CONSTANTS from '../../constants/index.js';
2
- import { call } from '../utils/call';
3
- import { task } from '../utils/task';
4
- import { html, render } from '../vendor/uhtml.js';
2
+ import { call } from '../utils/call.js';
3
+ import { task } from '../utils/task.js';
4
+ import { html, render } from '../vendors/uhtml.js';
5
5
  import { getStyles } from './getStyles.js';
6
6
  import { host } from './host.js';
7
7
  const targets = new Map();
@@ -0,0 +1 @@
1
+ export declare const syncAttributes: (node: HTMLElement) => (next?: any) => void;
@@ -3,7 +3,7 @@ import { off } from './off.js';
3
3
  import { on } from './on.js';
4
4
  import { toEvent } from './toEvent.js';
5
5
  import { updateAttribute } from './updateAttribute.js';
6
- export const sync = (node) => {
6
+ export const syncAttributes = (node) => {
7
7
  let prev = {};
8
8
  return (next = {}) => {
9
9
  const prevClass = (prev.class || '').split(' ');
@@ -1,3 +1,10 @@
1
+ declare namespace _default {
2
+ export { Hole };
3
+ export { html };
4
+ export { render };
5
+ export { svg };
6
+ }
7
+ export default _default;
1
8
  /**
2
9
  * Holds all details wrappers needed to render the content further on.
3
10
  * @constructor
@@ -698,3 +698,4 @@ const render = (where, what) => {
698
698
  const html = tag('html');
699
699
  const svg = tag('svg');
700
700
  export { Hole, html, render, svg };
701
+ export default { Hole, html, render, svg };
@@ -1,4 +1,4 @@
1
- import { Context, Plugin } from '../types/index.js';
1
+ import { Context, Plugin } from '../types';
2
2
  declare const _default: (...plugins: Array<Plugin>) => {
3
3
  start: () => Promise<void>;
4
4
  next: (filePath: string) => Promise<Context>;
@@ -1,4 +1,4 @@
1
- import { Context } from '../../types/index.js';
1
+ import { Context } from '../../types';
2
2
  export declare type AssetsOptions = {
3
3
  destination: (context: Context) => string;
4
4
  source?: (context: Context) => string;
@@ -0,0 +1,13 @@
1
+ export interface CopyOptions {
2
+ at?: 'finish' | 'start';
3
+ destination: string;
4
+ source: string;
5
+ transformer?: (parameters: {
6
+ content: string;
7
+ }) => string;
8
+ }
9
+ export declare const copy: (options: CopyOptions) => {
10
+ name: string;
11
+ start: () => void;
12
+ finish: () => void;
13
+ };
@@ -0,0 +1,26 @@
1
+ import fs from 'fs-extra';
2
+ import path from 'path';
3
+ const defaults = {
4
+ at: 'finish',
5
+ };
6
+ export const copy = (options) => {
7
+ const name = 'copy';
8
+ options = Object.assign({}, defaults, options);
9
+ const copy = (caller) => {
10
+ if (options.at != caller)
11
+ return;
12
+ let content;
13
+ content = fs.readFileSync(options.source, 'utf8');
14
+ if (options.transformer)
15
+ content = options.transformer({ content });
16
+ fs.ensureDirSync(path.dirname(options.destination));
17
+ fs.writeFileSync(options.destination, content, 'utf8');
18
+ };
19
+ const start = () => {
20
+ copy('start');
21
+ };
22
+ const finish = () => {
23
+ copy('finish');
24
+ };
25
+ return { name, start, finish };
26
+ };
@@ -1,4 +1,4 @@
1
- import { Context } from '../../types/index.js';
1
+ import { Context } from '../../types';
2
2
  export interface CustomElementOptions {
3
3
  typings?: boolean;
4
4
  }
@@ -21,20 +21,15 @@ export const customElement = (options) => {
21
21
  return;
22
22
  if (value.type != 'JSXExpressionContainer')
23
23
  return;
24
- const local = addDependency(ast, CONSTANTS.PACKAGE_NAME, CONSTANTS.UTILS_STYLE_MAP);
24
+ const { local } = addDependency(path, CONSTANTS.PACKAGE_NAME, CONSTANTS.UTILS_STYLE_MAP, CONSTANTS.UTILS_STYLE_MAP);
25
+ // TODO: remove 'local!'
25
26
  path.replaceWith(t.jsxAttribute(t.jsxIdentifier('style'), t.jsxExpressionContainer(t.callExpression(t.identifier(local), [value.expression]))));
26
27
  path.skip();
27
28
  }
28
29
  });
29
30
  // TODO
30
- visitor(ast, {
31
- ClassDeclaration(path) {
32
- const { body, id } = path.node;
33
- if (id.name != context.className)
34
- return;
35
- body.body.unshift(t.classProperty(t.identifier('uhtml')));
36
- }
37
- });
31
+ const { node } = addDependency(ast, CONSTANTS.VENDOR_UHTML, 'uhtml');
32
+ t.addComment(node, 'leading', CONSTANTS.COMMENT_AUTO_ADDED_DEPENDENCY, true);
38
33
  // replace 'className' attribute to 'class'
39
34
  visitor(ast, {
40
35
  JSXAttribute(path) {
@@ -67,17 +62,15 @@ export const customElement = (options) => {
67
62
  exit(path) {
68
63
  if (path.parent.type == 'JSXElement' || path.parent.type == 'JSXFragment') {
69
64
  path.replaceWith(t.identifier(print(path.node)));
70
- return;
71
65
  }
72
66
  else {
73
- path.replaceWith(t.memberExpression(t.memberExpression(t.thisExpression(), t.identifier('uhtml')), t.identifier(`html\`${print(path.node)}\``)));
74
- return;
67
+ path.replaceWith(t.memberExpression(t.identifier('uhtml'), t.identifier(`html\`${print(path.node)}\``)));
75
68
  }
76
69
  }
77
70
  },
78
71
  JSXFragment: {
79
72
  exit(path) {
80
- path.replaceWith(t.memberExpression(t.memberExpression(t.thisExpression(), t.identifier('uhtml')), t.identifier(['html`', ...path.node.children.map((child) => print(child)), '`'].join(''))));
73
+ path.replaceWith(t.memberExpression(t.identifier('uhtml'), t.identifier(['html`', ...path.node.children.map((child) => print(child)), '`'].join(''))));
81
74
  }
82
75
  },
83
76
  JSXExpressionContainer: {
@@ -101,34 +94,34 @@ export const customElement = (options) => {
101
94
  const { body, id } = path.node;
102
95
  if (id.name != context.className)
103
96
  return;
104
- body.body.unshift(t.classProperty(t.identifier(CONSTANTS.STATIC_MEMBERS), t.objectExpression([
97
+ const node = t.classProperty(t.identifier(CONSTANTS.STATIC_MEMBERS), t.objectExpression([
105
98
  ...context.classProperties.map((property) => {
106
- var _a, _b;
107
- const type = (_b = (_a = property.typeAnnotation) === null || _a === void 0 ? void 0 : _a.typeAnnotation) === null || _b === void 0 ? void 0 : _b.type;
108
- const elements = [];
109
- switch (type) {
110
- case 'TSBooleanKeyword':
111
- elements.push(t.stringLiteral(CONSTANTS.TYPE_BOOLEAN));
112
- break;
113
- case 'TSStringKeyword':
114
- elements.push(t.stringLiteral(CONSTANTS.TYPE_STRING));
115
- break;
116
- case 'TSNumberKeyword':
117
- elements.push(t.stringLiteral(CONSTANTS.TYPE_NUMBER));
118
- break;
119
- default:
120
- elements.push(t.nullLiteral());
121
- break;
99
+ const properties = [];
100
+ if (property.value) {
101
+ properties.push(t.objectProperty(t.identifier(CONSTANTS.STATIC_MEMBERS_INITIALIZER), property.value));
102
+ }
103
+ const type = (() => {
104
+ var _a, _b;
105
+ switch ((_b = (_a = property.typeAnnotation) === null || _a === void 0 ? void 0 : _a.typeAnnotation) === null || _b === void 0 ? void 0 : _b.type) {
106
+ case 'TSBooleanKeyword':
107
+ return t.stringLiteral(CONSTANTS.TYPE_BOOLEAN);
108
+ case 'TSStringKeyword':
109
+ return t.stringLiteral(CONSTANTS.TYPE_STRING);
110
+ case 'TSNumberKeyword':
111
+ return t.stringLiteral(CONSTANTS.TYPE_NUMBER);
112
+ }
113
+ })();
114
+ if (type) {
115
+ properties.push(t.objectProperty(t.identifier(CONSTANTS.STATIC_MEMBERS_TYPE), type));
122
116
  }
123
- if (property.value)
124
- elements.push(property.value);
125
- return t.objectProperty(t.identifier(property.key['name']), t.arrayExpression(elements));
117
+ return t.objectProperty(t.identifier(property.key['name']), t.objectExpression(properties));
126
118
  }),
127
- ...context.classMethods.map((method) => {
128
- const elements = [t.stringLiteral(CONSTANTS.TYPE_FUNCTION)];
129
- return t.objectProperty(t.identifier(method.key['name']), t.arrayExpression(elements));
130
- })
131
- ]), undefined, undefined, undefined, true));
119
+ ...context.classMethods.map((method) => t.objectProperty(t.identifier(method.key['name']), t.objectExpression([
120
+ t.objectProperty(t.identifier(CONSTANTS.STATIC_MEMBERS_TYPE), t.stringLiteral(CONSTANTS.TYPE_FUNCTION))
121
+ ])))
122
+ ]), undefined, undefined, undefined, true);
123
+ t.addComment(node, 'leading', CONSTANTS.COMMENT_AUTO_ADDED_PROPERTY, true);
124
+ body.body.unshift(node);
132
125
  }
133
126
  });
134
127
  // attach typings
@@ -1,4 +1,4 @@
1
- import { Global } from '../../../types/index.js';
1
+ import { Global } from '../../../types';
2
2
  export interface CustomElementReactOptions {
3
3
  compact?: boolean;
4
4
  destination: string;
@@ -1,4 +1,4 @@
1
- import { Global } from '../../types/index.js';
1
+ import { Global } from '../../types';
2
2
  export interface DocumentOptions {
3
3
  destination: string;
4
4
  }