@alloy-js/json 0.20.0-dev.0 → 0.20.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.
Files changed (54) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/dist/src/components/array.test.js +2 -1
  3. package/dist/src/components/array.test.js.map +1 -0
  4. package/dist/src/components/index.js +2 -1
  5. package/dist/src/components/index.js.map +1 -0
  6. package/dist/src/components/json-array.d.ts.map +1 -1
  7. package/dist/src/components/json-array.js +15 -22
  8. package/dist/src/components/json-array.js.map +1 -0
  9. package/dist/src/components/json-object.d.ts.map +1 -1
  10. package/dist/src/components/json-object.js +15 -15
  11. package/dist/src/components/json-object.js.map +1 -0
  12. package/dist/src/components/json-value.js +2 -1
  13. package/dist/src/components/json-value.js.map +1 -0
  14. package/dist/src/components/json-value.test.js +2 -1
  15. package/dist/src/components/json-value.test.js.map +1 -0
  16. package/dist/src/components/object.test.js +2 -1
  17. package/dist/src/components/object.test.js.map +1 -0
  18. package/dist/src/components/primitives.test.js +2 -1
  19. package/dist/src/components/primitives.test.js.map +1 -0
  20. package/dist/src/components/reference.js +2 -1
  21. package/dist/src/components/reference.js.map +1 -0
  22. package/dist/src/components/reference.test.js +2 -1
  23. package/dist/src/components/reference.test.js.map +1 -0
  24. package/dist/src/components/source-file.d.ts.map +1 -1
  25. package/dist/src/components/source-file.js +6 -9
  26. package/dist/src/components/source-file.js.map +1 -0
  27. package/dist/src/components/stc/index.js +2 -1
  28. package/dist/src/components/stc/index.js.map +1 -0
  29. package/dist/src/context/JsonFileContext.js +2 -1
  30. package/dist/src/context/JsonFileContext.js.map +1 -0
  31. package/dist/src/context/index.js +2 -1
  32. package/dist/src/context/index.js.map +1 -0
  33. package/dist/src/index.js +2 -1
  34. package/dist/src/index.js.map +1 -0
  35. package/dist/src/symbols/index.d.ts.map +1 -1
  36. package/dist/src/symbols/index.js +25 -7
  37. package/dist/src/symbols/index.js.map +1 -0
  38. package/dist/src/symbols/json-symbol.d.ts +5 -2
  39. package/dist/src/symbols/json-symbol.d.ts.map +1 -1
  40. package/dist/src/symbols/json-symbol.js +17 -3
  41. package/dist/src/symbols/json-symbol.js.map +1 -0
  42. package/dist/test/utils.js +2 -1
  43. package/dist/test/utils.js.map +1 -0
  44. package/dist/test/vitest.setup.js +2 -1
  45. package/dist/test/vitest.setup.js.map +1 -0
  46. package/dist/tsconfig.tsbuildinfo +1 -1
  47. package/package.json +7 -7
  48. package/src/components/json-array.tsx +13 -27
  49. package/src/components/json-object.tsx +14 -17
  50. package/src/components/source-file.tsx +4 -6
  51. package/src/symbols/index.ts +38 -8
  52. package/src/symbols/json-symbol.ts +23 -2
  53. package/temp/api.json +130 -3
  54. package/tsdoc-metadata.json +1 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alloy-js/json",
3
- "version": "0.20.0-dev.0",
3
+ "version": "0.20.0",
4
4
  "description": "",
5
5
  "exports": {
6
6
  ".": {
@@ -17,17 +17,17 @@
17
17
  "author": "brian.terlson@microsoft.com",
18
18
  "license": "MIT",
19
19
  "dependencies": {
20
- "@alloy-js/core": "~0.19.0 || >= 0.20.0-dev.0",
21
- "pathe": "^2.0.3"
20
+ "pathe": "^2.0.3",
21
+ "@alloy-js/core": "~0.20.0"
22
22
  },
23
23
  "devDependencies": {
24
- "@alloy-js/cli": "~0.19.0 || >= 0.20.0-dev.0",
25
- "@alloy-js/rollup-plugin": "~0.1.0 || >= 0.1.1-dev.0",
26
24
  "@microsoft/api-extractor": "~7.52.8",
27
25
  "@rollup/plugin-typescript": "^12.1.2",
28
- "concurrently": "^9.1.2",
26
+ "concurrently": "^9.2.0",
29
27
  "typescript": "^5.8.3",
30
- "vitest": "^3.2.4"
28
+ "vitest": "^3.2.4",
29
+ "@alloy-js/cli": "~0.20.0",
30
+ "@alloy-js/rollup-plugin": "~0.1.0"
31
31
  },
32
32
  "type": "module",
33
33
  "scripts": {
@@ -1,14 +1,14 @@
1
1
  import {
2
2
  Children,
3
+ emitSymbol,
3
4
  For,
4
5
  Indent,
5
6
  List,
6
7
  MemberDeclaration,
7
8
  MemberScope,
9
+ moveTakenMembersTo,
8
10
  onCleanup,
9
- OutputSymbolFlags,
10
11
  Refkey,
11
- useMemberDeclaration,
12
12
  useMemberScope,
13
13
  } from "@alloy-js/core";
14
14
  import { JsonOutputSymbol } from "../symbols/json-symbol.js";
@@ -55,19 +55,15 @@ export type JsonArrayProps =
55
55
  * @see {@link @alloy-js/core#(MemberScopeContext:variable)}
56
56
  */
57
57
  export function JsonArray(props: JsonArrayProps) {
58
- const memberSymbol = useMemberDeclaration();
59
- if (!memberSymbol) {
60
- throw new Error("Missing assignment symbol.");
61
- }
62
- memberSymbol.flags |= OutputSymbolFlags.StaticMemberContainer;
63
-
64
- if (props.refkey) {
65
- memberSymbol.refkeys = [props.refkey].flat();
66
- }
58
+ const arraySym = new JsonOutputSymbol("array symbol", undefined, {
59
+ transient: true,
60
+ refkeys: props.refkey ? [props.refkey].flat() : undefined,
61
+ });
62
+ emitSymbol(arraySym);
67
63
 
68
64
  if (!("jsValue" in props)) {
69
65
  return (
70
- <MemberScope owner={memberSymbol}>
66
+ <MemberScope ownerSymbol={arraySym} name="array scope">
71
67
  <group>
72
68
  [
73
69
  <Indent softline trailingBreak>
@@ -84,7 +80,7 @@ export function JsonArray(props: JsonArrayProps) {
84
80
  const jsValue = props.jsValue ?? [];
85
81
 
86
82
  return (
87
- <MemberScope owner={memberSymbol}>
83
+ <MemberScope ownerSymbol={arraySym}>
88
84
  <group>
89
85
  [
90
86
  <Indent softline trailingBreak>
@@ -126,20 +122,10 @@ export type JsonArrayElementProps =
126
122
  */
127
123
  export function JsonArrayElement(props: JsonArrayElementProps) {
128
124
  const memberScope = useMemberScope();
129
- if (!memberScope) {
130
- throw new Error("Missing member scope.");
131
- }
132
-
133
- if (!memberScope.staticMembers) {
134
- throw new Error("Missing static members scope.");
135
- }
136
-
137
- const name = String(memberScope.staticMembers.symbols.size);
138
-
139
- const sym = new JsonOutputSymbol(name, {
140
- flags: OutputSymbolFlags.StaticMember,
141
- });
142
-
125
+ const ownerSymbol = memberScope.ownerSymbol as JsonOutputSymbol;
126
+ const name = String(ownerSymbol.staticMembers.size);
127
+ const sym = new JsonOutputSymbol(name, ownerSymbol.staticMembers);
128
+ moveTakenMembersTo(sym);
143
129
  onCleanup(() => {
144
130
  sym.delete();
145
131
  });
@@ -1,15 +1,16 @@
1
1
  import {
2
2
  Children,
3
3
  computed,
4
+ emitSymbol,
4
5
  For,
5
6
  Indent,
6
7
  List,
7
8
  MemberDeclaration,
8
9
  MemberScope,
10
+ moveTakenMembersTo,
9
11
  onCleanup,
10
- OutputSymbolFlags,
11
12
  Refkey,
12
- useMemberDeclaration,
13
+ useMemberScope,
13
14
  } from "@alloy-js/core";
14
15
  import { JsonOutputSymbol } from "../symbols/json-symbol.js";
15
16
  import { JsonValue } from "./json-value.jsx";
@@ -60,19 +61,15 @@ export type JsonObjectProps =
60
61
  * @see {@link @alloy-js/core#MemberScopeContext}
61
62
  */
62
63
  export function JsonObject(props: JsonObjectProps) {
63
- const memberSymbol = useMemberDeclaration();
64
- if (!memberSymbol) {
65
- throw new Error("Missing assignment symbol.");
66
- }
67
- memberSymbol.flags |= OutputSymbolFlags.StaticMemberContainer;
68
-
69
- if (props.refkey) {
70
- memberSymbol.refkeys = [props.refkey].flat();
71
- }
64
+ const objectSym = new JsonOutputSymbol("object symbol", undefined, {
65
+ transient: true,
66
+ refkeys: props.refkey ? [props.refkey].flat() : undefined,
67
+ });
68
+ emitSymbol(objectSym);
72
69
 
73
70
  if (!("jsValue" in props)) {
74
71
  return (
75
- <MemberScope owner={memberSymbol}>
72
+ <MemberScope ownerSymbol={objectSym} name="object scope">
76
73
  <group>
77
74
  {"{"}
78
75
  <Indent
@@ -104,7 +101,7 @@ export function JsonObject(props: JsonObjectProps) {
104
101
  });
105
102
 
106
103
  return (
107
- <MemberScope owner={memberSymbol}>
104
+ <MemberScope ownerSymbol={objectSym}>
108
105
  <group>
109
106
  {"{"}
110
107
  <Indent
@@ -153,10 +150,10 @@ export type ObjectPropertyProps =
153
150
  * @see {@link @alloy-js/core#(MemberDeclarationContext:variable)}
154
151
  */
155
152
  export function JsonObjectProperty(props: ObjectPropertyProps) {
156
- const sym = new JsonOutputSymbol(props.name, {
157
- flags: OutputSymbolFlags.StaticMember,
158
- });
159
-
153
+ const memberScope = useMemberScope();
154
+ const ownerSymbol = memberScope.ownerSymbol as JsonOutputSymbol;
155
+ const sym = new JsonOutputSymbol(props.name, ownerSymbol.staticMembers);
156
+ moveTakenMembersTo(sym);
160
157
  onCleanup(() => {
161
158
  sym.delete();
162
159
  });
@@ -2,7 +2,7 @@ import {
2
2
  Children,
3
3
  SourceFile as CoreSourceFile,
4
4
  createSourceFileTap,
5
- MemberDeclaration,
5
+ moveTakenMembersTo,
6
6
  } from "@alloy-js/core";
7
7
  import { JsonFileContext } from "../context/JsonFileContext.js";
8
8
  import { JsonOutputSymbol } from "../symbols/json-symbol.js";
@@ -25,8 +25,8 @@ export interface SourceFileProps {
25
25
  *
26
26
  */
27
27
  export function SourceFile(props: SourceFileProps) {
28
- const jsonValueSym = new JsonOutputSymbol("");
29
-
28
+ const jsonValueSym = new JsonOutputSymbol(props.path, undefined);
29
+ moveTakenMembersTo(jsonValueSym);
30
30
  const fileContext: JsonFileContext = {
31
31
  symbol: jsonValueSym,
32
32
  path: props.path,
@@ -40,9 +40,7 @@ export function SourceFile(props: SourceFileProps) {
40
40
  <CoreSourceFile filetype="json" path={props.path} reference={Reference}>
41
41
  <SfTapper />
42
42
  <JsonFileContext.Provider value={fileContext}>
43
- <MemberDeclaration symbol={jsonValueSym}>
44
- {props.children}
45
- </MemberDeclaration>
43
+ {props.children}
46
44
  </JsonFileContext.Provider>
47
45
  </CoreSourceFile>
48
46
  );
@@ -16,27 +16,57 @@ export function ref(refkey: Refkey) {
16
16
  if (resolveResult.value === undefined) {
17
17
  return "<Unresolved Symbol>";
18
18
  }
19
- const { targetDeclaration, memberPath } = resolveResult.value;
19
+ const {
20
+ pathDown,
21
+ pathUp,
22
+ lexicalDeclaration,
23
+ memberPath,
24
+ commonScope,
25
+ fullSymbolPath,
26
+ } = resolveResult.value;
20
27
 
21
28
  let ref = "";
22
- if (targetDeclaration !== sourceFile.symbol) {
29
+ let isCrossFile = false;
30
+ // When we have no common scope and we don't path up through the symbol
31
+ // we're referencing (i.e. the symbol we're referencing isn't the symbol for
32
+ // the file the reference occurs in), append the file path.
33
+ if (
34
+ commonScope === undefined &&
35
+ pathUp[0] &&
36
+ pathUp[0].ownerSymbol !== lexicalDeclaration
37
+ ) {
23
38
  const currentPath = sourceFile.symbol.name;
24
- const targetPath = targetDeclaration.name;
39
+ const targetPath = lexicalDeclaration.name;
40
+ isCrossFile = true;
25
41
  ref += relative(dirname(currentPath), targetPath);
26
42
  }
27
43
 
28
44
  ref += "#";
29
45
 
30
- if (!memberPath || memberPath.length === 0) {
46
+ if (
47
+ commonScope === undefined &&
48
+ pathDown.length === 0 &&
49
+ memberPath.length === 0
50
+ ) {
51
+ // we are referring to the root of a file
31
52
  return ref;
32
53
  }
33
54
 
34
55
  ref += "/";
35
56
 
36
- ref += memberPath
37
- .slice(1)
38
- .map((segment) => segment.name)
39
- .join("/");
57
+ if (isCrossFile) {
58
+ // the lexical declaration is the file symbol, so we just need any
59
+ // additional members.
60
+ ref += memberPath.map((s) => s.name).join("/");
61
+ } else {
62
+ // merge together the member scopes, lexical declaration, and member path
63
+ ref += fullSymbolPath
64
+ .slice(1)
65
+ .map((s) => s.ownerSymbol!.name)
66
+ .concat(lexicalDeclaration.name)
67
+ .concat(memberPath.map((s) => s.name))
68
+ .join("/");
69
+ }
40
70
 
41
71
  return ref;
42
72
  });
@@ -1,4 +1,5 @@
1
1
  import {
2
+ OutputSpace,
2
3
  OutputSymbol,
3
4
  OutputSymbolOptions,
4
5
  track,
@@ -21,6 +22,8 @@ export enum JsonSymbolFlags {
21
22
  * `StaticMember` flag.
22
23
  */
23
24
  export class JsonOutputSymbol extends OutputSymbol {
25
+ static readonly memberSpaces = ["static"] as const;
26
+
24
27
  #jsonFlags: JsonSymbolFlags;
25
28
  get jsonFlags(): JsonSymbolFlags {
26
29
  track(this, TrackOpTypes.GET, "jsonFlags");
@@ -37,11 +40,29 @@ export class JsonOutputSymbol extends OutputSymbol {
37
40
  trigger(this, TriggerOpTypes.SET, "jsonFlags", value, old);
38
41
  }
39
42
 
40
- constructor(name: string, options: CreateJsonSymbolOptions = {}) {
41
- super(name, options);
43
+ constructor(
44
+ name: string,
45
+ spaces: OutputSpace[] | OutputSpace | undefined,
46
+ options: CreateJsonSymbolOptions = {},
47
+ ) {
48
+ super(name, spaces, options);
42
49
 
43
50
  this.#jsonFlags = options.jsonFlags ?? JsonSymbolFlags.None;
44
51
  }
52
+
53
+ copy() {
54
+ const options = this.getCopyOptions();
55
+ const copy = new JsonOutputSymbol(this.name, undefined, {
56
+ ...options,
57
+ jsonFlags: this.#jsonFlags,
58
+ });
59
+ this.initializeCopy(copy);
60
+ return copy;
61
+ }
62
+
63
+ get staticMembers() {
64
+ return this.memberSpaceFor("static")!;
65
+ }
45
66
  }
46
67
 
47
68
  export interface CreateJsonSymbolOptions extends OutputSymbolOptions {
package/temp/api.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "metadata": {
3
3
  "toolPackage": "@microsoft/api-extractor",
4
- "toolVersion": "7.52.8",
4
+ "toolVersion": "7.52.9",
5
5
  "schemaVersion": 1011,
6
6
  "oldestForwardsCompatibleVersion": 1001,
7
7
  "tsdocConfig": {
@@ -1195,6 +1195,28 @@
1195
1195
  "kind": "Content",
1196
1196
  "text": "string"
1197
1197
  },
1198
+ {
1199
+ "kind": "Content",
1200
+ "text": ", spaces: "
1201
+ },
1202
+ {
1203
+ "kind": "Reference",
1204
+ "text": "OutputSpace",
1205
+ "canonicalReference": "@alloy-js/core!OutputSpace:type"
1206
+ },
1207
+ {
1208
+ "kind": "Content",
1209
+ "text": "[] | "
1210
+ },
1211
+ {
1212
+ "kind": "Reference",
1213
+ "text": "OutputSpace",
1214
+ "canonicalReference": "@alloy-js/core!OutputSpace:type"
1215
+ },
1216
+ {
1217
+ "kind": "Content",
1218
+ "text": " | undefined"
1219
+ },
1198
1220
  {
1199
1221
  "kind": "Content",
1200
1222
  "text": ", options?: "
@@ -1222,15 +1244,55 @@
1222
1244
  "isOptional": false
1223
1245
  },
1224
1246
  {
1225
- "parameterName": "options",
1247
+ "parameterName": "spaces",
1226
1248
  "parameterTypeTokenRange": {
1227
1249
  "startIndex": 3,
1228
- "endIndex": 4
1250
+ "endIndex": 7
1251
+ },
1252
+ "isOptional": false
1253
+ },
1254
+ {
1255
+ "parameterName": "options",
1256
+ "parameterTypeTokenRange": {
1257
+ "startIndex": 8,
1258
+ "endIndex": 9
1229
1259
  },
1230
1260
  "isOptional": true
1231
1261
  }
1232
1262
  ]
1233
1263
  },
1264
+ {
1265
+ "kind": "Method",
1266
+ "canonicalReference": "@alloy-js/json!JsonOutputSymbol#copy:member(1)",
1267
+ "docComment": "",
1268
+ "excerptTokens": [
1269
+ {
1270
+ "kind": "Content",
1271
+ "text": "copy(): "
1272
+ },
1273
+ {
1274
+ "kind": "Reference",
1275
+ "text": "JsonOutputSymbol",
1276
+ "canonicalReference": "@alloy-js/json!JsonOutputSymbol:class"
1277
+ },
1278
+ {
1279
+ "kind": "Content",
1280
+ "text": ";"
1281
+ }
1282
+ ],
1283
+ "isStatic": false,
1284
+ "returnTypeTokenRange": {
1285
+ "startIndex": 1,
1286
+ "endIndex": 2
1287
+ },
1288
+ "releaseTag": "Public",
1289
+ "isProtected": false,
1290
+ "overloadIndex": 1,
1291
+ "parameters": [],
1292
+ "isOptional": false,
1293
+ "isAbstract": false,
1294
+ "name": "copy"
1295
+ },
1234
1296
  {
1235
1297
  "kind": "Property",
1236
1298
  "canonicalReference": "@alloy-js/json!JsonOutputSymbol#jsonFlags:member",
@@ -1270,6 +1332,71 @@
1270
1332
  "isStatic": false,
1271
1333
  "isProtected": false,
1272
1334
  "isAbstract": false
1335
+ },
1336
+ {
1337
+ "kind": "Property",
1338
+ "canonicalReference": "@alloy-js/json!JsonOutputSymbol.memberSpaces:member",
1339
+ "docComment": "",
1340
+ "excerptTokens": [
1341
+ {
1342
+ "kind": "Content",
1343
+ "text": "static readonly memberSpaces: "
1344
+ },
1345
+ {
1346
+ "kind": "Content",
1347
+ "text": "readonly [\"static\"]"
1348
+ },
1349
+ {
1350
+ "kind": "Content",
1351
+ "text": ";"
1352
+ }
1353
+ ],
1354
+ "isReadonly": true,
1355
+ "isOptional": false,
1356
+ "releaseTag": "Public",
1357
+ "name": "memberSpaces",
1358
+ "propertyTypeTokenRange": {
1359
+ "startIndex": 1,
1360
+ "endIndex": 2
1361
+ },
1362
+ "isStatic": true,
1363
+ "isProtected": false,
1364
+ "isAbstract": false
1365
+ },
1366
+ {
1367
+ "kind": "Property",
1368
+ "canonicalReference": "@alloy-js/json!JsonOutputSymbol#staticMembers:member",
1369
+ "docComment": "",
1370
+ "excerptTokens": [
1371
+ {
1372
+ "kind": "Content",
1373
+ "text": "get staticMembers(): "
1374
+ },
1375
+ {
1376
+ "kind": "Content",
1377
+ "text": "import(\"@alloy-js/core\")."
1378
+ },
1379
+ {
1380
+ "kind": "Reference",
1381
+ "text": "OutputMemberSpace",
1382
+ "canonicalReference": "@alloy-js/core!OutputMemberSpace:class"
1383
+ },
1384
+ {
1385
+ "kind": "Content",
1386
+ "text": ";"
1387
+ }
1388
+ ],
1389
+ "isReadonly": true,
1390
+ "isOptional": false,
1391
+ "releaseTag": "Public",
1392
+ "name": "staticMembers",
1393
+ "propertyTypeTokenRange": {
1394
+ "startIndex": 1,
1395
+ "endIndex": 3
1396
+ },
1397
+ "isStatic": false,
1398
+ "isProtected": false,
1399
+ "isAbstract": false
1273
1400
  }
1274
1401
  ],
1275
1402
  "extendsTokenRange": {
@@ -5,7 +5,7 @@
5
5
  "toolPackages": [
6
6
  {
7
7
  "packageName": "@microsoft/api-extractor",
8
- "packageVersion": "7.52.8"
8
+ "packageVersion": "7.52.9"
9
9
  }
10
10
  ]
11
11
  }