@alloy-js/core 0.6.0 → 0.7.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alloy-js/core",
3
- "version": "0.6.0",
3
+ "version": "0.7.0",
4
4
  "description": "",
5
5
  "main": "./dist/src/index.js",
6
6
  "exports": {
package/src/binder.ts CHANGED
@@ -99,9 +99,9 @@ export interface OutputSymbol {
99
99
  binder: Binder;
100
100
 
101
101
  /**
102
- * A unique value that references this symbol.
102
+ * The unique values that reference this symbol.
103
103
  */
104
- refkey: Refkey;
104
+ refkeys: Refkey[];
105
105
 
106
106
  /**
107
107
  * The instance members available on this symbol.
@@ -228,6 +228,7 @@ export type CreateSymbolOptions<T extends OutputSymbol = OutputSymbol> = {
228
228
  name: string;
229
229
  scope?: OutputScope;
230
230
  refkey?: Refkey;
231
+ refkeys?: Refkey[];
231
232
  flags?: OutputSymbolFlags;
232
233
  } & Omit<T, keyof OutputSymbol>;
233
234
 
@@ -524,10 +525,20 @@ export function createOutputBinder(options: BinderOptions = {}): Binder {
524
525
  name,
525
526
  scope = useDefaultScope(args.flags),
526
527
  refkey,
528
+ refkeys,
527
529
  flags = OutputSymbolFlags.None,
528
530
  ...rest
529
531
  } = args;
530
532
 
533
+ const allRefkeys = [];
534
+ if (refkey) {
535
+ allRefkeys.push(refkey);
536
+ }
537
+
538
+ if (refkeys) {
539
+ allRefkeys.push(...refkeys);
540
+ }
541
+
531
542
  if (!scope) {
532
543
  throw new Error(
533
544
  "No scope was provided and no scope could be found in context",
@@ -556,7 +567,7 @@ export function createOutputBinder(options: BinderOptions = {}): Binder {
556
567
  originalName: name,
557
568
  name: name,
558
569
  scope,
559
- refkey,
570
+ refkeys: allRefkeys,
560
571
  binder,
561
572
  flags,
562
573
  ...rest,
@@ -583,7 +594,9 @@ export function createOutputBinder(options: BinderOptions = {}): Binder {
583
594
  }
584
595
 
585
596
  scope.symbols.add(symbol);
586
- scope.symbolsByRefkey.set(symbol.refkey, symbol);
597
+ for (const refkey of allRefkeys) {
598
+ scope.symbolsByRefkey.set(refkey, symbol);
599
+ }
587
600
 
588
601
  deconflict(symbol);
589
602
  notifyRefkey(symbol);
@@ -598,9 +611,11 @@ export function createOutputBinder(options: BinderOptions = {}): Binder {
598
611
  return;
599
612
  }
600
613
 
601
- const resolution = waitingDeclarations.get(symbol.refkey);
602
- if (!resolution) return;
603
- resolution.value = undefined;
614
+ for (const refkey of symbol.refkeys) {
615
+ const resolution = waitingDeclarations.get(refkey);
616
+ if (!resolution) return;
617
+ resolution.value = undefined;
618
+ }
604
619
  }
605
620
 
606
621
  function instantiateSymbolInto(source: OutputSymbol, target: OutputSymbol) {
@@ -619,7 +634,8 @@ export function createOutputBinder(options: BinderOptions = {}): Binder {
619
634
  createSymbol({
620
635
  name: sym.name,
621
636
  scope: target.instanceMemberScope!,
622
- refkey: refkey(target.refkey, sym.refkey),
637
+ // todo: fix this or change this or something??
638
+ refkeys: [refkey(target.refkeys[0], sym.refkeys[0])],
623
639
  flags: sym.flags | OutputSymbolFlags.InstanceMember,
624
640
  });
625
641
  }
@@ -816,22 +832,21 @@ export function createOutputBinder(options: BinderOptions = {}): Binder {
816
832
 
817
833
  function notifyRefkey(symbol: OutputSymbol): void {
818
834
  effect(() => {
819
- const refkey = symbol.refkey;
820
- if (!refkey) return;
821
-
822
- // notify those waiting for this refkey
823
- knownDeclarations.set(refkey, symbol);
824
- if (waitingDeclarations.has(refkey)) {
825
- const signal = waitingDeclarations.get(refkey)!;
826
- signal.value = symbol;
827
- }
835
+ for (const refkey of symbol.refkeys) {
836
+ // notify those waiting for this refkey
837
+ knownDeclarations.set(refkey, symbol);
838
+ if (waitingDeclarations.has(refkey)) {
839
+ const signal = waitingDeclarations.get(refkey)!;
840
+ signal.value = symbol;
841
+ }
828
842
 
829
- // notify those waiting for this symbol name
830
- const waitingScope = waitingSymbolNames.get(symbol.scope);
831
- if (waitingScope) {
832
- const waitingName = waitingScope.get(symbol.name);
833
- if (waitingName) {
834
- waitingName.value = symbol;
843
+ // notify those waiting for this symbol name
844
+ const waitingScope = waitingSymbolNames.get(symbol.scope);
845
+ if (waitingScope) {
846
+ const waitingName = waitingScope.get(symbol.name);
847
+ if (waitingName) {
848
+ waitingName.value = symbol;
849
+ }
835
850
  }
836
851
  }
837
852
  });
@@ -304,6 +304,7 @@ export namespace JSX {
304
304
  literalline: {};
305
305
  lbr: {};
306
306
  indent: { children: Children };
307
+ indentIfBreak: { children: Children; groupId: symbol; negate?: boolean };
307
308
  fill: { children: Children };
308
309
  breakParent: {};
309
310
  ifBreak: { children: Children; flatContents?: Children; groupId?: symbol };
@@ -357,6 +358,8 @@ export function taggedComponent<TProps = Props>(
357
358
  export const intrinsicElementKey = Symbol();
358
359
 
359
360
  export type IndentIntrinsicElement = IntrinsicElementBase<"indent">;
361
+ export type IndentIfBreakIntrinsicElement =
362
+ IntrinsicElementBase<"indentIfBreak">;
360
363
  export type BrIntrinsicElement = IntrinsicElementBase<"br">;
361
364
  export type LineIntrinsicElement = IntrinsicElementBase<"line">;
362
365
  export type HbrIntrinsicElement = IntrinsicElementBase<"hbr">;
@@ -379,6 +382,7 @@ export type IfBreakIntrinsicElement = IntrinsicElementBase<"ifBreak">;
379
382
 
380
383
  export type IntrinsicElement =
381
384
  | IndentIntrinsicElement
385
+ | IndentIfBreakIntrinsicElement
382
386
  | BrIntrinsicElement
383
387
  | LineIntrinsicElement
384
388
  | HbrIntrinsicElement
package/src/render.ts CHANGED
@@ -32,6 +32,7 @@ const {
32
32
  group,
33
33
  hardline,
34
34
  indent,
35
+ indentIfBreak,
35
36
  line,
36
37
  lineSuffix,
37
38
  lineSuffixBoundary,
@@ -348,6 +349,19 @@ function appendChild(node: RenderedTextTree, rawChild: Child) {
348
349
  switch (child.name) {
349
350
  case "indent":
350
351
  return formatHookWithChildren(indent);
352
+ case "indentIfBreak":
353
+ node.push(
354
+ createRenderTreeHook(newNode, {
355
+ print(tree, print) {
356
+ return indentIfBreak(print(tree), {
357
+ groupId: child.props.groupId,
358
+ negate: child.props.negate,
359
+ });
360
+ },
361
+ }),
362
+ );
363
+ renderWorker(newNode, child.props.children);
364
+ return;
351
365
  case "fill":
352
366
  return formatHookWithChildren(fill as any);
353
367
  case "group":
@@ -1,4 +1,4 @@
1
- import { mkdirSync, statSync, writeFileSync } from "node:fs";
1
+ import { existsSync, mkdirSync, writeFileSync } from "node:fs";
2
2
  import { relative, resolve } from "pathe";
3
3
  import { OutputDirectory } from "./render.js";
4
4
  import { traverseOutput } from "./utils.js";
@@ -10,7 +10,7 @@ export function writeOutput(output: OutputDirectory, basePath: string = "") {
10
10
  traverseOutput(output, {
11
11
  visitDirectory(directory) {
12
12
  const path = resolve(basePath, directory.path);
13
- if (statSync(path)) {
13
+ if (existsSync(path)) {
14
14
  return;
15
15
  }
16
16
  // eslint-disable-next-line no-console
@@ -19,7 +19,7 @@ export function writeOutput(output: OutputDirectory, basePath: string = "") {
19
19
  },
20
20
  visitFile(file) {
21
21
  const path = resolve(basePath, file.path);
22
- if (statSync(path)) {
22
+ if (existsSync(path)) {
23
23
  // eslint-disable-next-line no-console
24
24
  console.log("overwrite", relative(process.cwd(), path));
25
25
  } else {
package/temp/api.json CHANGED
@@ -4229,7 +4229,16 @@
4229
4229
  },
4230
4230
  {
4231
4231
  "kind": "Content",
4232
- "text": ";\n flags?: "
4232
+ "text": ";\n refkeys?: "
4233
+ },
4234
+ {
4235
+ "kind": "Reference",
4236
+ "text": "Refkey",
4237
+ "canonicalReference": "@alloy-js/core!Refkey:type"
4238
+ },
4239
+ {
4240
+ "kind": "Content",
4241
+ "text": "[];\n flags?: "
4233
4242
  },
4234
4243
  {
4235
4244
  "kind": "Reference",
@@ -4281,7 +4290,7 @@
4281
4290
  ],
4282
4291
  "typeTokenRange": {
4283
4292
  "startIndex": 5,
4284
- "endIndex": 16
4293
+ "endIndex": 18
4285
4294
  }
4286
4295
  },
4287
4296
  {
@@ -6133,6 +6142,37 @@
6133
6142
  ],
6134
6143
  "name": "Indent"
6135
6144
  },
6145
+ {
6146
+ "kind": "TypeAlias",
6147
+ "canonicalReference": "@alloy-js/core!IndentIfBreakIntrinsicElement:type",
6148
+ "docComment": "",
6149
+ "excerptTokens": [
6150
+ {
6151
+ "kind": "Content",
6152
+ "text": "export type IndentIfBreakIntrinsicElement = "
6153
+ },
6154
+ {
6155
+ "kind": "Reference",
6156
+ "text": "IntrinsicElementBase",
6157
+ "canonicalReference": "@alloy-js/core!IntrinsicElementBase:interface"
6158
+ },
6159
+ {
6160
+ "kind": "Content",
6161
+ "text": "<\"indentIfBreak\">"
6162
+ },
6163
+ {
6164
+ "kind": "Content",
6165
+ "text": ";"
6166
+ }
6167
+ ],
6168
+ "fileUrlPath": "src/jsx-runtime.ts",
6169
+ "releaseTag": "Public",
6170
+ "name": "IndentIfBreakIntrinsicElement",
6171
+ "typeTokenRange": {
6172
+ "startIndex": 1,
6173
+ "endIndex": 3
6174
+ }
6175
+ },
6136
6176
  {
6137
6177
  "kind": "TypeAlias",
6138
6178
  "canonicalReference": "@alloy-js/core!IndentIntrinsicElement:type",
@@ -6309,6 +6349,15 @@
6309
6349
  "kind": "Content",
6310
6350
  "text": " | "
6311
6351
  },
6352
+ {
6353
+ "kind": "Reference",
6354
+ "text": "IndentIfBreakIntrinsicElement",
6355
+ "canonicalReference": "@alloy-js/core!IndentIfBreakIntrinsicElement:type"
6356
+ },
6357
+ {
6358
+ "kind": "Content",
6359
+ "text": " | "
6360
+ },
6312
6361
  {
6313
6362
  "kind": "Reference",
6314
6363
  "text": "BrIntrinsicElement",
@@ -6477,7 +6526,7 @@
6477
6526
  "name": "IntrinsicElement",
6478
6527
  "typeTokenRange": {
6479
6528
  "startIndex": 1,
6480
- "endIndex": 38
6529
+ "endIndex": 40
6481
6530
  }
6482
6531
  },
6483
6532
  {
@@ -7822,6 +7871,42 @@
7822
7871
  "endIndex": 4
7823
7872
  }
7824
7873
  },
7874
+ {
7875
+ "kind": "PropertySignature",
7876
+ "canonicalReference": "@alloy-js/core!JSX.IntrinsicElements#indentIfBreak:member",
7877
+ "docComment": "",
7878
+ "excerptTokens": [
7879
+ {
7880
+ "kind": "Content",
7881
+ "text": "indentIfBreak: "
7882
+ },
7883
+ {
7884
+ "kind": "Content",
7885
+ "text": "{\n children: "
7886
+ },
7887
+ {
7888
+ "kind": "Reference",
7889
+ "text": "Children",
7890
+ "canonicalReference": "@alloy-js/core!Children:type"
7891
+ },
7892
+ {
7893
+ "kind": "Content",
7894
+ "text": ";\n groupId: symbol;\n negate?: boolean;\n }"
7895
+ },
7896
+ {
7897
+ "kind": "Content",
7898
+ "text": ";"
7899
+ }
7900
+ ],
7901
+ "isReadonly": false,
7902
+ "isOptional": false,
7903
+ "releaseTag": "Public",
7904
+ "name": "indentIfBreak",
7905
+ "propertyTypeTokenRange": {
7906
+ "startIndex": 1,
7907
+ "endIndex": 4
7908
+ }
7909
+ },
7825
7910
  {
7826
7911
  "kind": "PropertySignature",
7827
7912
  "canonicalReference": "@alloy-js/core!JSX.IntrinsicElements#lbr:member",
@@ -11214,18 +11299,22 @@
11214
11299
  },
11215
11300
  {
11216
11301
  "kind": "PropertySignature",
11217
- "canonicalReference": "@alloy-js/core!OutputSymbol#refkey:member",
11218
- "docComment": "/**\n * A unique value that references this symbol.\n */\n",
11302
+ "canonicalReference": "@alloy-js/core!OutputSymbol#refkeys:member",
11303
+ "docComment": "/**\n * The unique values that reference this symbol.\n */\n",
11219
11304
  "excerptTokens": [
11220
11305
  {
11221
11306
  "kind": "Content",
11222
- "text": "refkey: "
11307
+ "text": "refkeys: "
11223
11308
  },
11224
11309
  {
11225
11310
  "kind": "Reference",
11226
11311
  "text": "Refkey",
11227
11312
  "canonicalReference": "@alloy-js/core!Refkey:type"
11228
11313
  },
11314
+ {
11315
+ "kind": "Content",
11316
+ "text": "[]"
11317
+ },
11229
11318
  {
11230
11319
  "kind": "Content",
11231
11320
  "text": ";"
@@ -11234,10 +11323,10 @@
11234
11323
  "isReadonly": false,
11235
11324
  "isOptional": false,
11236
11325
  "releaseTag": "Public",
11237
- "name": "refkey",
11326
+ "name": "refkeys",
11238
11327
  "propertyTypeTokenRange": {
11239
11328
  "startIndex": 1,
11240
- "endIndex": 2
11329
+ "endIndex": 3
11241
11330
  }
11242
11331
  },
11243
11332
  {
@@ -158,7 +158,7 @@ describe("static members", () => {
158
158
  const resolution = binder.resolveDeclarationByKey(
159
159
  root,
160
160
  undefined,
161
- staticSym.refkey,
161
+ staticSym.refkeys[0],
162
162
  );
163
163
  expect(resolution.value).toBeDefined();
164
164
  const { commonScope, pathUp, pathDown, targetDeclaration, memberPath } =
@@ -202,7 +202,7 @@ describe("static members", () => {
202
202
  const resolution = binder.resolveDeclarationByKey(
203
203
  root,
204
204
  undefined,
205
- nested_static.refkey,
205
+ nested_static.refkeys[0],
206
206
  );
207
207
  expect(resolution.value).toBeDefined();
208
208
  const { commonScope, pathUp, pathDown, targetDeclaration, memberPath } =
@@ -284,7 +284,7 @@ describe("instance members", () => {
284
284
  const resolution = binder.resolveDeclarationByKey(
285
285
  undefined,
286
286
  rootSym.instanceMemberScope!,
287
- instance.refkey,
287
+ instance.refkeys[0],
288
288
  );
289
289
  expect(resolution.value).toBeDefined();
290
290
  const { commonScope, pathUp, pathDown, targetDeclaration, memberPath } =
@@ -318,7 +318,7 @@ describe("instance members", () => {
318
318
  });
319
319
 
320
320
  expect(() =>
321
- binder.resolveDeclarationByKey(root, undefined, instance.refkey),
321
+ binder.resolveDeclarationByKey(root, undefined, instance.refkeys[0]),
322
322
  ).toThrow(/Cannot resolve member symbols/);
323
323
  });
324
324
  });
@@ -349,7 +349,10 @@ describe("instantiating members", () => {
349
349
  instantiation.flags & OutputSymbolFlags.InstanceMemberContainer,
350
350
  ).toBeTruthy();
351
351
  expect(instantiation.instanceMemberScope).toBeDefined();
352
- const expectedRefkey = refkey(instantiation.refkey, instance.refkey);
352
+ const expectedRefkey = refkey(
353
+ instantiation.refkeys[0],
354
+ instance.refkeys[0],
355
+ );
353
356
  expect(
354
357
  instantiation.instanceMemberScope!.symbolsByRefkey.get(expectedRefkey),
355
358
  ).toBeDefined();
@@ -380,7 +383,10 @@ describe("instantiating members", () => {
380
383
  instantiation.flags & OutputSymbolFlags.InstanceMemberContainer,
381
384
  ).toBeTruthy();
382
385
  expect(instantiation.instanceMemberScope).toBeDefined();
383
- const expectedRefkey = refkey(instantiation.refkey, instance.refkey);
386
+ const expectedRefkey = refkey(
387
+ instantiation.refkeys[0],
388
+ instance.refkeys[0],
389
+ );
384
390
  expect(
385
391
  instantiation.instanceMemberScope!.symbolsByRefkey.get(expectedRefkey),
386
392
  ).toBeDefined();
@@ -393,7 +399,7 @@ describe("instantiating members", () => {
393
399
  flags: OutputSymbolFlags.InstanceMember,
394
400
  });
395
401
  const newExpectedRefkey = refkey(
396
- instantiation.refkey,
402
+ instantiation.refkeys[0],
397
403
  newInstanceMemberRefkey,
398
404
  );
399
405
  expect(
@@ -558,7 +564,7 @@ describe("refkey resolution", () => {
558
564
 
559
565
  expect(resolvedSym.value).toBe(undefined);
560
566
 
561
- sym.refkey = key;
567
+ sym.refkeys[0] = key;
562
568
  expect(resolvedSym.value?.targetDeclaration).toBe(sym);
563
569
  });
564
570
  });
@@ -581,7 +587,7 @@ describe("Deleting symbols", () => {
581
587
 
582
588
  expect(resolvedSym.value).toBe(undefined);
583
589
 
584
- sym.refkey = key;
590
+ sym.refkeys[0] = key;
585
591
  expect(resolvedSym.value?.targetDeclaration).toBe(sym);
586
592
 
587
593
  binder.deleteSymbol(sym);