Skip to content

Commit f8969db

Browse files
Uptake compiler internals (#2357)
Main changes: - Ast reference updated to `@typespec/compiler/ast` - Stop using `getOption` - Keep tgcc workaround as using internal api
1 parent ef9e311 commit f8969db

File tree

14 files changed

+43
-30
lines changed

14 files changed

+43
-30
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
# Change versionKind to one of: internal, fix, dependencies, feature, deprecation, breaking
3+
changeKind: fix
4+
packages:
5+
- "@azure-tools/typespec-autorest"
6+
- "@azure-tools/typespec-azure-core"
7+
- "@azure-tools/typespec-azure-resource-manager"
8+
- "@azure-tools/typespec-client-generator-core"
9+
---
10+
11+
Cleanup use of typespec compiler internal apis.

core

Submodule core updated 68 files

packages/typespec-autorest/src/openapi.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ import {
4444
Scalar,
4545
StringLiteral,
4646
StringTemplate,
47-
SyntaxKind,
4847
Type,
4948
TypeNameOptions,
5049
Union,
@@ -101,6 +100,7 @@ import {
101100
resolvePath,
102101
serializeValueAsJson,
103102
} from "@typespec/compiler";
103+
import { SyntaxKind } from "@typespec/compiler/ast";
104104
import { $ } from "@typespec/compiler/experimental/typekit";
105105
import { TwoLevelMap } from "@typespec/compiler/utils";
106106
import {

packages/typespec-azure-core/src/rules/composition-over-inheritance.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import {
2-
SyntaxKind,
32
createRule,
43
getDiscriminator,
54
getTypeName,
65
isTemplateInstance,
76
paramMessage,
87
} from "@typespec/compiler";
8+
import { SyntaxKind } from "@typespec/compiler/ast";
99

1010
export const compositionOverInheritanceRule = createRule({
1111
name: "composition-over-inheritance",

packages/typespec-azure-core/src/rules/friendly-name.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ import {
1414
Operation,
1515
paramMessage,
1616
Scalar,
17-
SyntaxKind,
1817
Type,
1918
Union,
2019
UnionVariant,
2120
} from "@typespec/compiler";
21+
import { SyntaxKind } from "@typespec/compiler/ast";
2222

2323
export const friendlyNameRule = createRule({
2424
name: "friendly-name",

packages/typespec-azure-core/src/rules/no-enum.ts

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
import {
22
CodeFix,
33
Enum,
4-
EnumMemberNode,
5-
EnumSpreadMemberNode,
6-
Node,
7-
SyntaxKind,
8-
TypeSpecScriptNode,
94
createRule,
105
getPositionBeforeTrivia,
116
getSourceLocation,
127
paramMessage,
138
} from "@typespec/compiler";
9+
import {
10+
type EnumMemberNode,
11+
type EnumSpreadMemberNode,
12+
type Node,
13+
SyntaxKind,
14+
type TypeSpecScriptNode,
15+
} from "@typespec/compiler/ast";
1416
import { getVersionsForEnum } from "@typespec/versioning";
1517
export const noEnumRule = createRule({
1618
name: "no-enum",

packages/typespec-azure-core/src/rules/prevent-rest-library.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ import {
22
Interface,
33
Operation,
44
Program,
5-
TypeReferenceNode,
65
createRule,
76
getNamespaceFullName,
87
} from "@typespec/compiler";
8+
import { TypeReferenceNode } from "@typespec/compiler/ast";
99
import { isExcludedCoreType } from "./utils.js";
1010

1111
function getTypeReferenceNamespace(program: Program, ref: TypeReferenceNode): string {

packages/typespec-azure-core/src/rules/spread-discriminated-model.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { Model, SyntaxKind, createRule, getDiscriminator, paramMessage } from "@typespec/compiler";
1+
import { Model, createRule, getDiscriminator, paramMessage } from "@typespec/compiler";
2+
import { SyntaxKind } from "@typespec/compiler/ast";
23

34
export const spreadDiscriminatedModelRule = createRule({
45
name: "spread-discriminated-model",

packages/typespec-azure-core/src/rules/utils.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ import {
1111
Program,
1212
Scalar,
1313
SourceLocation,
14-
SyntaxKind,
1514
Union,
1615
UnionVariant,
1716
} from "@typespec/compiler";
17+
import { SyntaxKind } from "@typespec/compiler/ast";
1818

1919
type DeclarableType =
2020
| Namespace

packages/typespec-azure-resource-manager/src/commontypes.private.decorators.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export const namespace = "Azure.ResourceManager.CommonTypes.Private";
1919
export const ArmCommonTypesDefaultVersion = "v3";
2020

2121
function getArmTypesPath(program: Program): string {
22-
return program.getOption("arm-types-path") || "{arm-types-dir}";
22+
return "{arm-types-dir}";
2323
}
2424

2525
function storeCommonTypeRecord(

packages/typespec-azure-resource-manager/src/rules/core-operations.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@ import {
33
ModelProperty,
44
Operation,
55
Program,
6-
SyntaxKind,
76
createRule,
87
paramMessage,
98
} from "@typespec/compiler";
9+
import { SyntaxKind } from "@typespec/compiler/ast";
1010
import { HttpVerb, getOperationVerb } from "@typespec/http";
11-
1211
import {
1312
getNamespaceName,
1413
getSourceModel,

packages/typespec-azure-resource-manager/src/rules/utils.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import {
99
Namespace,
1010
Operation,
1111
Program,
12-
SyntaxKind,
1312
} from "@typespec/compiler";
13+
import { SyntaxKind } from "@typespec/compiler/ast";
1414
import { getResourceOperation } from "@typespec/rest";
1515
import { ArmResourceOperation } from "../operations.js";
1616
import { ArmResourceDetails, getArmResourceKind } from "../resource.js";

packages/typespec-client-generator-core/src/decorators.ts

+9-11
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,16 @@
11
import {
2-
AugmentDecoratorStatementNode,
32
DecoratorContext,
4-
DecoratorExpressionNode,
53
DecoratorFunction,
64
Enum,
75
EnumMember,
86
Interface,
97
Model,
108
ModelProperty,
119
Namespace,
12-
Node,
1310
Operation,
1411
Program,
1512
RekeyableMap,
1613
Scalar,
17-
SyntaxKind,
1814
Type,
1915
Union,
2016
getDiscriminator,
@@ -24,6 +20,7 @@ import {
2420
isTemplateDeclaration,
2521
isTemplateDeclarationOrInstance,
2622
} from "@typespec/compiler";
23+
import { SyntaxKind, type Node } from "@typespec/compiler/ast";
2724
import {
2825
AccessDecorator,
2926
AlternateTypeDecorator,
@@ -789,19 +786,20 @@ export const $clientName: ClientNameDecorator = (
789786
// workaround for current lack of functionality in compiler
790787
// https://github.com/microsoft/typespec/issues/2717
791788
if (entity.kind === "Model" || entity.kind === "Operation") {
792-
if ((context.decoratorTarget as Node).kind === SyntaxKind.AugmentDecoratorStatement) {
789+
const target = context.decoratorTarget as Node;
790+
if (target.kind === SyntaxKind.AugmentDecoratorStatement) {
793791
if (
794-
ignoreDiagnostics(
795-
context.program.checker.resolveTypeReference(
796-
(context.decoratorTarget as AugmentDecoratorStatementNode).targetType,
797-
),
792+
(
793+
ignoreDiagnostics(
794+
(context.program.checker as any).resolveTypeReference(target.targetType),
795+
) as any
798796
)?.node !== entity.node
799797
) {
800798
return;
801799
}
802800
}
803-
if ((context.decoratorTarget as Node).kind === SyntaxKind.DecoratorExpression) {
804-
if ((context.decoratorTarget as DecoratorExpressionNode).parent !== entity.node) {
801+
if (target.kind === SyntaxKind.DecoratorExpression) {
802+
if (target.parent !== entity.node) {
805803
return;
806804
}
807805
}

packages/typespec-client-generator-core/src/validate.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
import {
2-
AugmentDecoratorStatementNode,
3-
DecoratorExpressionNode,
42
Enum,
53
EnumMember,
64
Interface,
@@ -10,11 +8,15 @@ import {
108
Operation,
119
Program,
1210
Scalar,
13-
SyntaxKind,
1411
Type,
1512
Union,
1613
UnionVariant,
1714
} from "@typespec/compiler";
15+
import {
16+
AugmentDecoratorStatementNode,
17+
DecoratorExpressionNode,
18+
SyntaxKind,
19+
} from "@typespec/compiler/ast";
1820
import { DuplicateTracker } from "@typespec/compiler/utils";
1921
import { createTCGCContext } from "./context.js";
2022
import { getClientNameOverride } from "./decorators.js";

0 commit comments

Comments
 (0)