@tsrx/content-mapper 0.1.0 → 0.1.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.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tsrx/content-mapper",
3
3
  "description": "TypeScript 7 content mapper for .tsrx files",
4
- "version": "0.1.0",
4
+ "version": "0.1.1",
5
5
  "license": "MIT",
6
6
  "author": "Dominic Gannaway",
7
7
  "type": "module",
@@ -20,9 +20,9 @@
20
20
  ],
21
21
  "exports": {
22
22
  "./package.json": "./package.json",
23
- "./mapper": "./src/mapper.js",
24
- "./rpc": "./src/rpc.js",
25
- "./protocol": "./src/protocol.js"
23
+ "./mapper": "./dist/mapper.js",
24
+ "./rpc": "./dist/rpc.js",
25
+ "./protocol": "./dist/protocol.js"
26
26
  },
27
27
  "typescript": {
28
28
  "contentMapper": {
@@ -51,10 +51,10 @@
51
51
  "vue": "3.6.0-beta.12",
52
52
  "@tsrx/core": "0.2.4",
53
53
  "@tsrx/solid": "0.2.4",
54
- "@tsrx/preact": "0.2.4",
55
- "@tsrx/typescript-plugin": "0.4.6",
54
+ "@tsrx/react": "0.3.4",
56
55
  "@tsrx/vue": "0.2.4",
57
- "@tsrx/react": "0.3.4"
56
+ "@tsrx/typescript-plugin": "0.4.7",
57
+ "@tsrx/preact": "0.2.4"
58
58
  },
59
59
  "publishConfig": {
60
60
  "access": "public"
@@ -27,7 +27,7 @@ export function build_export_stub(program) {
27
27
  for (const statement of program?.body ?? []) {
28
28
  switch (statement.type) {
29
29
  case 'ExportAllDeclaration': {
30
- const exported = statement.exported ? ` as ${export_name(statement.exported)}` : '';
30
+ const exported = statement.exported ? ` as ${print_name(statement.exported)}` : '';
31
31
  lines.push(
32
32
  `export ${type_modifier(statement)}*${exported} from ${JSON.stringify(String(statement.source.value))};`,
33
33
  );
@@ -40,8 +40,8 @@ export function build_export_stub(program) {
40
40
  if (statement.source) {
41
41
  const statement_is_type = type_modifier(statement) !== '';
42
42
  const specifiers = statement.specifiers.map((specifier) => {
43
- const local = export_name(specifier.local);
44
- const exported = export_name(specifier.exported);
43
+ const local = print_name(specifier.local);
44
+ const exported = print_name(specifier.exported);
45
45
  // `export type { A }` marks the statement; `export { type A }`
46
46
  // marks the specifier. Never write both.
47
47
  const modifier = statement_is_type ? '' : type_modifier(specifier);
@@ -70,7 +70,7 @@ export function build_export_stub(program) {
70
70
  }
71
71
 
72
72
  for (const name of names) {
73
- if (!/^[\p{ID_Start}_$][\p{ID_Continue}$]*$/u.test(name)) continue;
73
+ if (!identifier_pattern.test(name)) continue;
74
74
  lines.push(`export declare const ${name}: any;`);
75
75
  lines.push(`export type ${name} = any;`);
76
76
  }
@@ -94,7 +94,11 @@ function type_modifier(node) {
94
94
  return /** @type {{ exportKind?: string }} */ (node).exportKind === 'type' ? 'type ' : '';
95
95
  }
96
96
 
97
+ const identifier_pattern = /^[\p{ID_Start}_$][\p{ID_Continue}$]*$/u;
98
+
97
99
  /**
100
+ * The name an export binds, as a plain string: `a` for `export { a }` and
101
+ * `foo-bar` for `export { "foo-bar" as a } from`.
98
102
  * @param {AST.Identifier | AST.Literal | AST.Expression} node
99
103
  * @returns {string}
100
104
  */
@@ -104,6 +108,18 @@ function export_name(node) {
104
108
  return '';
105
109
  }
106
110
 
111
+ /**
112
+ * The name as it must be written back in a re-export: an identifier as is, an
113
+ * arbitrary module namespace name (`export { "foo-bar" as a } from`,
114
+ * `export * as "ns-name" from`) quoted, so the stub stays valid TypeScript.
115
+ * @param {AST.Identifier | AST.Literal | AST.Expression} node
116
+ * @returns {string}
117
+ */
118
+ function print_name(node) {
119
+ const name = export_name(node);
120
+ return identifier_pattern.test(name) ? name : JSON.stringify(name);
121
+ }
122
+
107
123
  /**
108
124
  * @param {AST.Declaration | AST.Node} declaration
109
125
  * @returns {string[]}