Skip to content

Commit 8aed1d5

Browse files
committed
Export and use utility functions from lib/utils
Export `createStateSymbol` from `lib/utils`, and export all of utils in `@typespec/compiler` so they can be used by other packages. Additionally, replace duplicate definitions of `utils` functions in `@typespec/compiler` with imports from `utils`.
1 parent 2bd7bc0 commit 8aed1d5

File tree

3 files changed

+8
-17
lines changed

3 files changed

+8
-17
lines changed

packages/compiler/src/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
export { resolveCompilerOptions, ResolveCompilerOptionsOptions } from "./config/index.js";
22
export * from "./core/index.js";
33
export * from "./lib/decorators.js";
4+
export * from "./lib/utils.js";
45
export * from "./server/index.js";
56
export type { PackageJson } from "./types/package-json.js";
67
import * as formatter from "./formatter/index.js";

packages/compiler/src/lib/decorators.ts

+6-16
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,12 @@ import {
9999
Value,
100100
} from "../core/types.js";
101101
import { setKey } from "./key.js";
102-
import { useStateMap, useStateSet } from "./utils.js";
102+
import {
103+
createStateSymbol,
104+
filterModelPropertiesInPlace,
105+
useStateMap,
106+
useStateSet,
107+
} from "./utils.js";
103108

104109
export { $encodedName, resolveEncodedName } from "./encoded-names.js";
105110
export { serializeValueAsJson } from "./examples.js";
@@ -121,10 +126,6 @@ function replaceTemplatedStringFromProperties(formatString: string, sourceObject
121126
});
122127
}
123128

124-
export function createStateSymbol(name: string) {
125-
return Symbol.for(`TypeSpec.${name}`);
126-
}
127-
128129
const [getSummary, setSummary] = useStateMap<Type, string>("summary");
129130
/**
130131
* @summary attaches a documentation string. It is typically used to give a short, single-line
@@ -810,17 +811,6 @@ function validateEncodeData(context: DecoratorContext, target: Type, encodeData:
810811

811812
export { getEncode };
812813

813-
export function filterModelPropertiesInPlace(
814-
model: Model,
815-
filter: (prop: ModelProperty) => boolean,
816-
) {
817-
for (const [key, prop] of model.properties) {
818-
if (!filter(prop)) {
819-
model.properties.delete(key);
820-
}
821-
}
822-
}
823-
824814
// -- @withOptionalProperties decorator ---------------------
825815

826816
export const $withOptionalProperties: WithOptionalPropertiesDecorator = (

packages/compiler/src/lib/utils.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { Model, ModelProperty, Type } from "../core/types.js";
22
import { unsafe_useStateMap, unsafe_useStateSet } from "../experimental/state-accessor.js";
33

4-
function createStateSymbol(name: string) {
4+
export function createStateSymbol(name: string) {
55
return Symbol.for(`TypeSpec.${name}`);
66
}
77

0 commit comments

Comments
 (0)