@no22/dison 1.0.0 → 1.1.0

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/dist/runtime.js CHANGED
@@ -16,11 +16,15 @@
16
16
  // - 複数ファイルにまたがって同名クラスが存在しても、参照そのものが
17
17
  // キーになるため衝突しない(docs/multi-file-support.md参照)。
18
18
  //
19
- // TYPE_BINDINGS(bind用)は従来通り型名の文字列でキー化する。bindの左辺は
20
- // interface/型エイリアスもあり得るが、これらは実行時に値を持たないため
21
- // DI_REGISTRYと同じ手法(実体参照でのキー化)が使えない。複数ファイルに
22
- // またがるinterface/型エイリアスの名前衝突は未解決の課題として残る
23
- // (docs/multi-file-support.md 3.4節)。
19
+ // TYPE_BINDINGS(bind用)のキーは、型が具象クラスなら実体参照(Function)、
20
+ // それ以外(interface/型エイリアス/ジェネリクス)なら型名の文字列を使う。
21
+ // 具象クラスの実体キー化はDI_REGISTRYと同じ発想で、複数ファイルにまたがる
22
+ // 同名クラスが衝突しなくなる(手動tokenなしで自動的に別の実体として区別される。
23
+ // どの型を実体キーにするかの判定はcodegen/collisionsが担う。
24
+ // docs/type-identity-matching.md)。bindの左辺がinterface/型エイリアスの場合は
25
+ // 実行時に値が無いため実体参照できず、文字列キーのまま。複数ファイルに
26
+ // またがる同名interface/型エイリアスの衝突は "as <トークン>" で回避する
27
+ // (docs/bind-interface-token.md)。
24
28
  export function generateRuntimeDeclarations(exportKeyword) {
25
29
  return (`// Global dependency registry (per-property override).\n` +
26
30
  `// Keying on the class itself (not its name) lets tsc catch a typo in the\n` +
@@ -38,26 +42,34 @@ export function generateRuntimeDeclarations(exportKeyword) {
38
42
  ` return DI_REGISTRY.get(cls)?.[prop];\n` +
39
43
  `}\n\n` +
40
44
  `// Global type-replacement registry (bind).\n` +
41
- `// The key is either a type-name string (class, interface, or type alias name)\n` +
42
- `// or a Symbol explicitly given via an "as <token>" clause (used to avoid\n` +
43
- `// name collisions between same-named interfaces/type aliases across files).\n` +
44
- `${exportKeyword}const TYPE_BINDINGS = new Map<string | symbol, () => any>();\n` +
45
- `const _resolvingTypeBindings = new Set<string | symbol>();\n\n` +
45
+ `// The key is one of:\n` +
46
+ `// - The class itself (Function). When a bind/injectable type is a concrete\n` +
47
+ `// class, the class value (not its name string) is used as the key (same\n` +
48
+ `// idea as DI_REGISTRY). Same-named classes across files no longer collide\n` +
49
+ `// as a result (no manual token needed; with string keys, unrelated\n` +
50
+ `// same-named classes used to pollute each other).\n` +
51
+ `// - A type-name string. Used for interfaces/type aliases (no runtime value)\n` +
52
+ `// and generics with concrete type arguments (Repository<User>).\n` +
53
+ `// - A Symbol explicitly given via an "as <token>" clause (to avoid collisions\n` +
54
+ `// between same-named interfaces/type aliases across files. docs/bind-interface-token.md).\n` +
55
+ `${exportKeyword}const TYPE_BINDINGS = new Map<string | symbol | Function, () => any>();\n` +
56
+ `const _resolvingTypeBindings = new Set<string | symbol | Function>();\n\n` +
46
57
  `// bindType<T> takes T as an explicit type argument, so tsc raises a\n` +
47
58
  `// compile error if the replacement factory isn't compatible with the\n` +
48
59
  `// original type. T may be an interface or type alias (used only as a\n` +
49
60
  `// type argument).\n` +
50
- `${exportKeyword}function bindType<T>(typeKey: string | symbol, factory: () => T): void {\n` +
61
+ `${exportKeyword}function bindType<T>(typeKey: string | symbol | Function, factory: () => T): void {\n` +
51
62
  ` TYPE_BINDINGS.set(typeKey, factory);\n` +
52
63
  `}\n\n` +
53
64
  `// Resolves a value by recursively walking TYPE_BINDINGS. bind chains\n` +
54
65
  `// (e.g. bind A = B; bind B = C; makes resolving A eventually reach C).\n` +
55
66
  `// A cycle (A -> B -> A) raises a clear error instead of a stack overflow.\n` +
56
- `${exportKeyword}function resolveType<T>(typeKey: string | symbol, defaultFactory: () => T): T {\n` +
67
+ `${exportKeyword}function resolveType<T>(typeKey: string | symbol | Function, defaultFactory: () => T): T {\n` +
57
68
  ` const bound = TYPE_BINDINGS.get(typeKey);\n` +
58
69
  ` if (!bound) return defaultFactory();\n` +
59
70
  ` if (_resolvingTypeBindings.has(typeKey)) {\n` +
60
- ` throw new Error('Detected a circular "bind" reference ("' + String(typeKey) + '"). The bind chain loops back on itself.');\n` +
71
+ ` const label = typeof typeKey === 'function' ? (typeKey.name || '<anonymous class>') : String(typeKey);\n` +
72
+ ` throw new Error('Detected a circular "bind" reference ("' + label + '"). The bind chain loops back on itself.');\n` +
61
73
  ` }\n` +
62
74
  ` _resolvingTypeBindings.add(typeKey);\n` +
63
75
  ` try {\n` +
@@ -1 +1 @@
1
- {"version":3,"file":"runtime.js","sourceRoot":"","sources":["../src/runtime.ts"],"names":[],"mappings":"AAAA,wEAAwE;AACxE,gBAAgB;AAChB,wEAAwE;AAExE,6DAA6D;AAC7D,oEAAoE;AACpE,2CAA2C;AAC3C,sCAAsC;AACtC,EAAE;AACF,kDAAkD;AAClD,oCAAoC;AACpC,gDAAgD;AAChD,yCAAyC;AACzC,wCAAwC;AACxC,gDAAgD;AAChD,mBAAmB;AACnB,sCAAsC;AACtC,kDAAkD;AAClD,EAAE;AACF,iDAAiD;AACjD,0CAA0C;AAC1C,2CAA2C;AAC3C,wCAAwC;AACxC,qCAAqC;AACrC,MAAM,UAAU,2BAA2B,CAAC,aAA6B;IACvE,OAAO,CACL,0DAA0D;QAC1D,6EAA6E;QAC7E,gEAAgE;QAChE,GAAG,aAAa,6EAA6E;QAC7F,GAAG,aAAa,sFAAsF;QACtG,uCAAuC;QACvC,mBAAmB;QACnB,mBAAmB;QACnB,oCAAoC;QACpC,OAAO;QACP,4BAA4B;QAC5B,OAAO;QACP,GAAG,aAAa,gFAAgF;QAChG,0CAA0C;QAC1C,OAAO;QACP,+CAA+C;QAC/C,kFAAkF;QAClF,6EAA6E;QAC7E,gFAAgF;QAChF,GAAG,aAAa,gEAAgE;QAChF,gEAAgE;QAChE,wEAAwE;QACxE,yEAAyE;QACzE,yEAAyE;QACzE,sBAAsB;QACtB,GAAG,aAAa,4EAA4E;QAC5F,0CAA0C;QAC1C,OAAO;QACP,yEAAyE;QACzE,2EAA2E;QAC3E,8EAA8E;QAC9E,GAAG,aAAa,mFAAmF;QACnG,+CAA+C;QAC/C,0CAA0C;QAC1C,gDAAgD;QAChD,kIAAkI;QAClI,OAAO;QACP,0CAA0C;QAC1C,WAAW;QACX,uBAAuB;QACvB,iBAAiB;QACjB,+CAA+C;QAC/C,OAAO;QACP,KAAK,CACN,CAAC;AACJ,CAAC;AAED,oDAAoD;AACpD,uDAAuD;AACvD,uDAAuD;AACvD,yDAAyD;AACzD,MAAM,CAAC,MAAM,2BAA2B,GACtC,0CAA0C;IAC1C,yEAAyE;IACzE,yCAAyC;IACzC,6FAA6F;IAC7F,2BAA2B,CAAC,SAAS,CAAC,CAAC"}
1
+ {"version":3,"file":"runtime.js","sourceRoot":"","sources":["../src/runtime.ts"],"names":[],"mappings":"AAAA,wEAAwE;AACxE,gBAAgB;AAChB,wEAAwE;AAExE,6DAA6D;AAC7D,oEAAoE;AACpE,2CAA2C;AAC3C,sCAAsC;AACtC,EAAE;AACF,kDAAkD;AAClD,oCAAoC;AACpC,gDAAgD;AAChD,yCAAyC;AACzC,wCAAwC;AACxC,gDAAgD;AAChD,mBAAmB;AACnB,sCAAsC;AACtC,kDAAkD;AAClD,EAAE;AACF,oDAAoD;AACpD,4CAA4C;AAC5C,4CAA4C;AAC5C,4CAA4C;AAC5C,yCAAyC;AACzC,+DAA+D;AAC/D,qCAAqC;AACrC,+CAA+C;AAC/C,kCAAkC;AAClC,MAAM,UAAU,2BAA2B,CAAC,aAA6B;IACvE,OAAO,CACL,0DAA0D;QAC1D,6EAA6E;QAC7E,gEAAgE;QAChE,GAAG,aAAa,6EAA6E;QAC7F,GAAG,aAAa,sFAAsF;QACtG,uCAAuC;QACvC,mBAAmB;QACnB,mBAAmB;QACnB,oCAAoC;QACpC,OAAO;QACP,4BAA4B;QAC5B,OAAO;QACP,GAAG,aAAa,gFAAgF;QAChG,0CAA0C;QAC1C,OAAO;QACP,+CAA+C;QAC/C,yBAAyB;QACzB,iFAAiF;QACjF,gFAAgF;QAChF,kFAAkF;QAClF,2EAA2E;QAC3E,0DAA0D;QAC1D,kFAAkF;QAClF,wEAAwE;QACxE,oFAAoF;QACpF,kGAAkG;QAClG,GAAG,aAAa,2EAA2E;QAC3F,2EAA2E;QAC3E,wEAAwE;QACxE,yEAAyE;QACzE,yEAAyE;QACzE,sBAAsB;QACtB,GAAG,aAAa,uFAAuF;QACvG,0CAA0C;QAC1C,OAAO;QACP,yEAAyE;QACzE,2EAA2E;QAC3E,8EAA8E;QAC9E,GAAG,aAAa,8FAA8F;QAC9G,+CAA+C;QAC/C,0CAA0C;QAC1C,gDAAgD;QAChD,8GAA8G;QAC9G,wHAAwH;QACxH,OAAO;QACP,0CAA0C;QAC1C,WAAW;QACX,uBAAuB;QACvB,iBAAiB;QACjB,+CAA+C;QAC/C,OAAO;QACP,KAAK,CACN,CAAC;AACJ,CAAC;AAED,oDAAoD;AACpD,uDAAuD;AACvD,uDAAuD;AACvD,yDAAyD;AACzD,MAAM,CAAC,MAAM,2BAA2B,GACtC,0CAA0C;IAC1C,yEAAyE;IACzE,yCAAyC;IACzC,6FAA6F;IAC7F,2BAA2B,CAAC,SAAS,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@no22/dison",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "type": "module",
5
5
  "description": "An experimental DSL that transpiles to TypeScript, with property injection built into the language itself.",
6
6
  "main": "./dist/core.js",