@esportsplus/template 0.32.5 → 0.33.1

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 (36) hide show
  1. package/build/{transformer → compiler}/codegen.js +8 -4
  2. package/build/{transformer → compiler}/index.d.ts +6 -0
  3. package/build/{transformer → compiler}/index.js +5 -0
  4. package/build/compiler/plugins/index.d.ts +2 -0
  5. package/build/compiler/plugins/index.js +2 -0
  6. package/build/constants.d.ts +2 -1
  7. package/build/constants.js +2 -1
  8. package/build/event/onconnect.d.ts +1 -0
  9. package/build/event/ontick.d.ts +1 -0
  10. package/build/index.d.ts +0 -6
  11. package/build/index.js +0 -6
  12. package/package.json +12 -11
  13. package/src/{transformer → compiler}/codegen.ts +13 -4
  14. package/src/{transformer → compiler}/index.ts +6 -0
  15. package/src/compiler/plugins/index.ts +2 -0
  16. package/src/constants.ts +3 -1
  17. package/src/event/onconnect.ts +1 -0
  18. package/src/event/ontick.ts +1 -0
  19. package/src/index.ts +0 -8
  20. package/test/vite.config.ts +1 -1
  21. /package/build/{transformer → compiler}/codegen.d.ts +0 -0
  22. /package/build/{transformer → compiler}/parser.d.ts +0 -0
  23. /package/build/{transformer → compiler}/parser.js +0 -0
  24. /package/build/{transformer → compiler}/plugins/tsc.d.ts +0 -0
  25. /package/build/{transformer → compiler}/plugins/tsc.js +0 -0
  26. /package/build/{transformer → compiler}/plugins/vite.d.ts +0 -0
  27. /package/build/{transformer → compiler}/plugins/vite.js +0 -0
  28. /package/build/{transformer → compiler}/ts-parser.d.ts +0 -0
  29. /package/build/{transformer → compiler}/ts-parser.js +0 -0
  30. /package/build/{transformer → compiler}/type-analyzer.d.ts +0 -0
  31. /package/build/{transformer → compiler}/type-analyzer.js +0 -0
  32. /package/src/{transformer → compiler}/parser.ts +0 -0
  33. /package/src/{transformer → compiler}/plugins/tsc.ts +0 -0
  34. /package/src/{transformer → compiler}/plugins/vite.ts +0 -0
  35. /package/src/{transformer → compiler}/ts-parser.ts +0 -0
  36. /package/src/{transformer → compiler}/type-analyzer.ts +0 -0
@@ -1,9 +1,10 @@
1
1
  import { ts } from '@esportsplus/typescript';
2
2
  import { ast, code as c, uid } from '@esportsplus/typescript/transformer';
3
3
  import { analyzeExpression, generateAttributeBinding, generateSpreadBindings } from './type-analyzer.js';
4
- import { COMPILER_ENTRYPOINT, COMPILER_NAMESPACE, COMPILER_TYPES, PACKAGE } from '../constants.js';
4
+ import { COMPILER_ENTRYPOINT, COMPILER_NAMESPACE, COMPILER_TYPES, PACKAGE, PACKAGE_COMPILER } from '../constants.js';
5
5
  import parser from './parser.js';
6
6
  const ARROW_EMPTY_PARAMS = /\(\s*\)\s*=>\s*$/;
7
+ const REGEX_PACKAGE_IMPORT = new RegExp(`import\\s*\\{[^}]*\\}\\s*from\\s*['"]${PACKAGE.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}['"];?\\n?`, 'g');
7
8
  let printer = ts.createPrinter({ newLine: ts.NewLineKind.LineFeed });
8
9
  function collectNestedTemplateReplacements(ctx, node, exprStart, replacements) {
9
10
  if (isNestedHtmlTemplate(node)) {
@@ -80,7 +81,7 @@ function generateTemplateCode(ctx, { html, slots }, exprTexts, exprNodes, isArro
80
81
  }
81
82
  }
82
83
  let name = uid('element'), suffix = path.slice(startIdx).join('.');
83
- declarations.push(`${name} = ${ancestorVar}.${suffix}!`);
84
+ declarations.push(`${name} = ${ancestorVar}.${suffix} as ${COMPILER_NAMESPACE}.Element`);
84
85
  nodes.set(key, name);
85
86
  }
86
87
  code.push(isArrowBody ? '{' : `(() => {`, `let ${declarations.join(',\n')};`);
@@ -155,7 +156,10 @@ function rewriteExpression(ctx, expr) {
155
156
  return c.replaceReverse(expr.getText(ctx.sourceFile), replacements);
156
157
  }
157
158
  const addImport = (code) => {
158
- return `import * as ${COMPILER_NAMESPACE} from '${PACKAGE}';\n` + code;
159
+ return `import * as ${COMPILER_NAMESPACE} from '${PACKAGE_COMPILER}';\n` + code;
160
+ };
161
+ const removePackageImport = (code) => {
162
+ return code.replace(REGEX_PACKAGE_IMPORT, '');
159
163
  };
160
164
  const generateCode = (templates, originalCode, sourceFile, checker) => {
161
165
  if (templates.length === 0) {
@@ -208,7 +212,7 @@ const generateCode = (templates, originalCode, sourceFile, checker) => {
208
212
  for (let [id, html] of ctx.hoistedFactories) {
209
213
  factories.push(`const ${id} = ${COMPILER_NAMESPACE}.template(\`${html}\`);`);
210
214
  }
211
- code = addImport(factories.join('\n') + code);
215
+ code = addImport(factories.join('\n') + removePackageImport(code));
212
216
  }
213
217
  return { changed, code };
214
218
  };
@@ -6,3 +6,9 @@ type TransformResult = {
6
6
  };
7
7
  declare const transform: (sourceFile: ts.SourceFile, program: ts.Program) => TransformResult;
8
8
  export { transform };
9
+ export * from '../attributes.js';
10
+ export * from '../event/index.js';
11
+ export { ArraySlot } from '../slot/array.js';
12
+ export { EffectSlot } from '../slot/effect.js';
13
+ export type * from '../types.js';
14
+ export * from '../utilities.js';
@@ -44,3 +44,8 @@ const transform = (sourceFile, program) => {
44
44
  return { changed, code: result, sourceFile };
45
45
  };
46
46
  export { transform };
47
+ export * from '../attributes.js';
48
+ export * from '../event/index.js';
49
+ export { ArraySlot } from '../slot/array.js';
50
+ export { EffectSlot } from '../slot/effect.js';
51
+ export * from '../utilities.js';
@@ -0,0 +1,2 @@
1
+ export { default as tsc } from './tsc.js';
2
+ export { default as vite } from './vite.js';
@@ -0,0 +1,2 @@
1
+ export { default as tsc } from './tsc.js';
2
+ export { default as vite } from './vite.js';
@@ -17,9 +17,10 @@ declare const enum COMPILER_TYPES {
17
17
  declare const DIRECT_ATTACH_EVENTS: Set<string>;
18
18
  declare const LIFECYCLE_EVENTS: Set<string>;
19
19
  declare const PACKAGE = "@esportsplus/template";
20
+ declare const PACKAGE_COMPILER = "@esportsplus/template/compiler";
20
21
  declare const SLOT_HTML = "<!--$-->";
21
22
  declare const STATE_HYDRATING = 0;
22
23
  declare const STATE_NONE = 1;
23
24
  declare const STATE_WAITING = 2;
24
25
  declare const STORE: unique symbol;
25
- export { ARRAY_SLOT, CLEANUP, COMPILER_ENTRYPOINT, COMPILER_ENTRYPOINT_REACTIVITY, COMPILER_NAMESPACE, COMPILER_TYPES, DIRECT_ATTACH_EVENTS, LIFECYCLE_EVENTS, PACKAGE, SLOT_HTML, STATE_HYDRATING, STATE_NONE, STATE_WAITING, STORE, };
26
+ export { ARRAY_SLOT, CLEANUP, COMPILER_ENTRYPOINT, COMPILER_ENTRYPOINT_REACTIVITY, COMPILER_NAMESPACE, COMPILER_TYPES, DIRECT_ATTACH_EVENTS, LIFECYCLE_EVENTS, PACKAGE, PACKAGE_COMPILER, SLOT_HTML, STATE_HYDRATING, STATE_NONE, STATE_WAITING, STORE, };
@@ -30,9 +30,10 @@ const LIFECYCLE_EVENTS = new Set([
30
30
  'onconnect', 'ondisconnect', 'onrender', 'onresize', 'ontick'
31
31
  ]);
32
32
  const PACKAGE = '@esportsplus/template';
33
+ const PACKAGE_COMPILER = '@esportsplus/template/compiler';
33
34
  const SLOT_HTML = '<!--$-->';
34
35
  const STATE_HYDRATING = 0;
35
36
  const STATE_NONE = 1;
36
37
  const STATE_WAITING = 2;
37
38
  const STORE = Symbol('template.store');
38
- export { ARRAY_SLOT, CLEANUP, COMPILER_ENTRYPOINT, COMPILER_ENTRYPOINT_REACTIVITY, COMPILER_NAMESPACE, COMPILER_TYPES, DIRECT_ATTACH_EVENTS, LIFECYCLE_EVENTS, PACKAGE, SLOT_HTML, STATE_HYDRATING, STATE_NONE, STATE_WAITING, STORE, };
39
+ export { ARRAY_SLOT, CLEANUP, COMPILER_ENTRYPOINT, COMPILER_ENTRYPOINT_REACTIVITY, COMPILER_NAMESPACE, COMPILER_TYPES, DIRECT_ATTACH_EVENTS, LIFECYCLE_EVENTS, PACKAGE, PACKAGE_COMPILER, SLOT_HTML, STATE_HYDRATING, STATE_NONE, STATE_WAITING, STORE, };
@@ -1,2 +1,3 @@
1
+ import { Element } from '../types.js';
1
2
  declare const _default: (element: Element, listener: Function) => void;
2
3
  export default _default;
@@ -1,3 +1,4 @@
1
+ import { Element } from '../types.js';
1
2
  declare const add: (task: VoidFunction) => void;
2
3
  declare const remove: (task: VoidFunction) => void;
3
4
  declare const _default: (element: Element, listener: Function) => void;
package/build/index.d.ts CHANGED
@@ -2,10 +2,4 @@ import './runtime.js';
2
2
  export { default as html } from './html.js';
3
3
  export { default as render } from './render.js';
4
4
  export { default as svg } from './svg.js';
5
- export * from './attributes.js';
6
- export * from './event/index.js';
7
- export { default as slot } from './slot/index.js';
8
- export { ArraySlot } from './slot/array.js';
9
- export { EffectSlot } from './slot/effect.js';
10
5
  export type { Attributes, Element, Renderable } from './types.js';
11
- export * from './utilities.js';
package/build/index.js CHANGED
@@ -2,9 +2,3 @@ import './runtime.js';
2
2
  export { default as html } from './html.js';
3
3
  export { default as render } from './render.js';
4
4
  export { default as svg } from './svg.js';
5
- export * from './attributes.js';
6
- export * from './event/index.js';
7
- export { default as slot } from './slot/index.js';
8
- export { ArraySlot } from './slot/array.js';
9
- export { EffectSlot } from './slot/effect.js';
10
- export * from './utilities.js';
package/package.json CHANGED
@@ -17,18 +17,19 @@
17
17
  "import": "./build/index.js",
18
18
  "types": "./build/index.d.ts"
19
19
  },
20
- "./constants": {
21
- "import": "./build/constants.js",
22
- "types": "./build/constants.d.ts"
20
+ "./compiler": {
21
+ "import": "./build/compiler/index.js",
22
+ "types": "./build/compiler/index.d.ts"
23
23
  },
24
- "./plugins/tsc": {
25
- "types": "./build/transformer/plugins/tsc.d.ts",
26
- "import": "./build/transformer/plugins/tsc.js",
27
- "require": "./build/transformer/plugins/tsc.js"
24
+ "./compiler/tsc": {
25
+ "types": "./build/compiler/plugins/tsc/index.d.ts",
26
+ "import": "./build/compiler/plugins/tsc/index.js",
27
+ "require": "./build/compiler/plugins/tsc/index.js"
28
28
  },
29
- "./plugins/vite": {
30
- "types": "./build/transformer/plugins/vite.d.ts",
31
- "import": "./build/transformer/plugins/vite.js"
29
+ "./compiler/vite": {
30
+ "types": "./build/compiler/plugins/vite/index.d.ts",
31
+ "import": "./build/compiler/plugins/vite/index.js",
32
+ "require": "./build/compiler/plugins/vite/index.js"
32
33
  }
33
34
  },
34
35
  "main": "./build/index.js",
@@ -40,7 +41,7 @@
40
41
  },
41
42
  "type": "module",
42
43
  "types": "./build/index.d.ts",
43
- "version": "0.32.5",
44
+ "version": "0.33.1",
44
45
  "scripts": {
45
46
  "build": "tsc",
46
47
  "build:test": "vite build --config test/vite.config.ts",
@@ -4,7 +4,7 @@ import type { ReactiveCallInfo, TemplateInfo } from './ts-parser';
4
4
  import { analyzeExpression, generateAttributeBinding, generateSpreadBindings } from './type-analyzer';
5
5
  import {
6
6
  COMPILER_ENTRYPOINT, COMPILER_NAMESPACE, COMPILER_TYPES,
7
- PACKAGE
7
+ PACKAGE, PACKAGE_COMPILER
8
8
  } from '~/constants';
9
9
  import parser from './parser';
10
10
 
@@ -44,6 +44,11 @@ type ParseResult = {
44
44
 
45
45
  const ARROW_EMPTY_PARAMS = /\(\s*\)\s*=>\s*$/;
46
46
 
47
+ const REGEX_PACKAGE_IMPORT = new RegExp(
48
+ `import\\s*\\{[^}]*\\}\\s*from\\s*['"]${PACKAGE.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}['"];?\\n?`,
49
+ 'g'
50
+ );
51
+
47
52
 
48
53
  let printer = ts.createPrinter({ newLine: ts.NewLineKind.LineFeed });
49
54
 
@@ -174,7 +179,7 @@ function generateTemplateCode(
174
179
  let name = uid('element'),
175
180
  suffix = path.slice(startIdx).join('.');
176
181
 
177
- declarations.push(`${name} = ${ancestorVar}.${suffix}!`);
182
+ declarations.push(`${name} = ${ancestorVar}.${suffix} as ${COMPILER_NAMESPACE}.Element`);
178
183
  nodes.set(key, name);
179
184
  }
180
185
 
@@ -295,7 +300,11 @@ function rewriteExpression(ctx: CodegenContext, expr: ts.Expression): string {
295
300
 
296
301
 
297
302
  const addImport = (code: string): string => {
298
- return `import * as ${COMPILER_NAMESPACE} from '${PACKAGE}';\n` + code;
303
+ return `import * as ${COMPILER_NAMESPACE} from '${PACKAGE_COMPILER}';\n` + code;
304
+ };
305
+
306
+ const removePackageImport = (code: string): string => {
307
+ return code.replace(REGEX_PACKAGE_IMPORT, '');
299
308
  };
300
309
 
301
310
  const generateCode = (templates: TemplateInfo[], originalCode: string, sourceFile: ts.SourceFile, checker?: ts.TypeChecker): CodegenResult => {
@@ -378,7 +387,7 @@ const generateCode = (templates: TemplateInfo[], originalCode: string, sourceFil
378
387
  factories.push(`const ${id} = ${COMPILER_NAMESPACE}.template(\`${html}\`);`);
379
388
  }
380
389
 
381
- code = addImport(factories.join('\n') + code);
390
+ code = addImport(factories.join('\n') + removePackageImport(code));
382
391
  }
383
392
 
384
393
  return { changed, code };
@@ -76,3 +76,9 @@ const transform = (sourceFile: ts.SourceFile, program: ts.Program): TransformRes
76
76
 
77
77
 
78
78
  export { transform };
79
+ export * from '~/attributes';
80
+ export * from '~/event';
81
+ export { ArraySlot } from '~/slot/array';
82
+ export { EffectSlot } from '~/slot/effect';
83
+ export type * from '~/types';
84
+ export * from '~/utilities';
@@ -0,0 +1,2 @@
1
+ export { default as tsc } from './tsc';
2
+ export { default as vite } from './vite';
package/src/constants.ts CHANGED
@@ -40,6 +40,8 @@ const LIFECYCLE_EVENTS = new Set<string>([
40
40
 
41
41
  const PACKAGE = '@esportsplus/template';
42
42
 
43
+ const PACKAGE_COMPILER = '@esportsplus/template/compiler';
44
+
43
45
 
44
46
  const SLOT_HTML = '<!--$-->';
45
47
 
@@ -58,6 +60,6 @@ export {
58
60
  COMPILER_ENTRYPOINT, COMPILER_ENTRYPOINT_REACTIVITY, COMPILER_NAMESPACE, COMPILER_TYPES,
59
61
  DIRECT_ATTACH_EVENTS,
60
62
  LIFECYCLE_EVENTS,
61
- PACKAGE,
63
+ PACKAGE, PACKAGE_COMPILER,
62
64
  SLOT_HTML, STATE_HYDRATING, STATE_NONE, STATE_WAITING, STORE,
63
65
  };
@@ -1,5 +1,6 @@
1
1
  import { root } from '@esportsplus/reactivity';
2
2
  import { add, remove } from './ontick';
3
+ import { Element } from '~/types';
3
4
 
4
5
 
5
6
  export default (element: Element, listener: Function) => {
@@ -1,3 +1,4 @@
1
+ import { Element } from '~/types';
1
2
  import { raf } from '~/utilities';
2
3
 
3
4
 
package/src/index.ts CHANGED
@@ -2,12 +2,4 @@ import './runtime';
2
2
  export { default as html } from './html';
3
3
  export { default as render } from './render';
4
4
  export { default as svg } from './svg';
5
-
6
- // Must be exported for compilation even if not used directly
7
- export * from './attributes';
8
- export * from './event';
9
- export { default as slot } from './slot';
10
- export { ArraySlot } from './slot/array';
11
- export { EffectSlot } from './slot/effect';
12
5
  export type { Attributes, Element, Renderable } from './types';
13
- export * from './utilities';
@@ -1,7 +1,7 @@
1
1
  import { defineConfig } from 'vite';
2
2
  import { resolve } from 'path';
3
3
  import tsconfigPaths from 'vite-tsconfig-paths';
4
- import templatePlugin from '../src/transformer/plugins/vite';
4
+ import templatePlugin from '../src/compiler/vite';
5
5
 
6
6
 
7
7
  export default defineConfig({
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes