@alloy-js/typescript 0.11.0 → 0.13.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/CHANGELOG.md +17 -0
- package/dist/src/components/ClassDeclaration.d.ts +2 -0
- package/dist/src/components/ClassDeclaration.d.ts.map +1 -1
- package/dist/src/components/ClassDeclaration.js +14 -2
- package/dist/src/components/FunctionBase.d.ts.map +1 -1
- package/dist/src/components/FunctionBase.js +13 -3
- package/dist/src/components/FunctionType.d.ts +7 -8
- package/dist/src/components/FunctionType.d.ts.map +1 -1
- package/dist/src/components/FunctionType.js +29 -25
- package/dist/src/components/ImportStatement.d.ts.map +1 -1
- package/dist/src/components/ImportStatement.js +9 -2
- package/dist/src/components/Interface.d.ts +3 -2
- package/dist/src/components/Interface.d.ts.map +1 -1
- package/dist/src/components/Interface.js +8 -4
- package/dist/src/components/JSDocComment.js +1 -1
- package/dist/src/components/MemberDeclaration.d.ts +4 -0
- package/dist/src/components/MemberDeclaration.d.ts.map +1 -1
- package/dist/src/components/MemberDeclaration.js +1 -1
- package/dist/src/components/MemberExpression.d.ts.map +1 -1
- package/dist/src/components/MemberExpression.js +3 -2
- package/dist/src/components/Reference.d.ts +8 -1
- package/dist/src/components/Reference.d.ts.map +1 -1
- package/dist/src/components/Reference.js +7 -2
- package/dist/src/components/TypeDeclaration.d.ts +1 -1
- package/dist/src/components/TypeDeclaration.d.ts.map +1 -1
- package/dist/src/components/TypeDeclaration.js +3 -2
- package/dist/src/components/TypeRefContext.d.ts +22 -0
- package/dist/src/components/TypeRefContext.d.ts.map +1 -0
- package/dist/src/components/TypeRefContext.js +41 -0
- package/dist/src/components/VarDeclaration.d.ts +1 -0
- package/dist/src/components/VarDeclaration.d.ts.map +1 -1
- package/dist/src/components/VarDeclaration.js +9 -3
- package/dist/src/components/index.d.ts +1 -0
- package/dist/src/components/index.d.ts.map +1 -1
- package/dist/src/components/index.js +1 -0
- package/dist/src/components/stc/index.d.ts +1 -0
- package/dist/src/components/stc/index.d.ts.map +1 -1
- package/dist/src/components/stc/index.js +1 -0
- package/dist/src/context/type-ref-context.d.ts +15 -0
- package/dist/src/context/type-ref-context.d.ts.map +1 -0
- package/dist/src/context/type-ref-context.js +12 -0
- package/dist/src/parameter-descriptor.d.ts +6 -0
- package/dist/src/parameter-descriptor.d.ts.map +1 -1
- package/dist/src/symbols/reference.d.ts +4 -1
- package/dist/src/symbols/reference.d.ts.map +1 -1
- package/dist/src/symbols/reference.js +11 -5
- package/dist/src/symbols/ts-module-scope.d.ts +4 -1
- package/dist/src/symbols/ts-module-scope.d.ts.map +1 -1
- package/dist/src/symbols/ts-module-scope.js +10 -3
- package/dist/src/symbols/ts-output-symbol.d.ts +2 -1
- package/dist/src/symbols/ts-output-symbol.d.ts.map +1 -1
- package/dist/src/symbols/ts-output-symbol.js +1 -0
- package/dist/test/class.test.js +108 -5
- package/dist/test/enum-jsdoc.test.js +6 -6
- package/dist/test/function-declaration-jsdoc.test.js +3 -3
- package/dist/test/imports.test.d.ts.map +1 -1
- package/dist/test/imports.test.js +293 -2
- package/dist/test/interface-jsdoc.test.js +9 -9
- package/dist/test/jsdoc.test.js +5 -5
- package/dist/test/jsdocparam.test.js +8 -8
- package/dist/test/member-expression.test.js +218 -2
- package/dist/test/var-declaration-jsdoc.test.js +3 -3
- package/dist/test/var-declaration.test.js +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +4 -4
- package/src/components/ClassDeclaration.tsx +19 -3
- package/src/components/FunctionBase.tsx +14 -3
- package/src/components/FunctionType.tsx +45 -40
- package/src/components/ImportStatement.tsx +30 -3
- package/src/components/Interface.tsx +41 -34
- package/src/components/JSDocComment.tsx +1 -1
- package/src/components/MemberDeclaration.tsx +7 -1
- package/src/components/MemberExpression.tsx +7 -2
- package/src/components/Reference.tsx +12 -2
- package/src/components/TypeDeclaration.tsx +16 -13
- package/src/components/TypeRefContext.tsx +49 -0
- package/src/components/VarDeclaration.tsx +6 -2
- package/src/components/index.ts +1 -0
- package/src/components/stc/index.ts +1 -0
- package/src/context/type-ref-context.tsx +19 -0
- package/src/parameter-descriptor.ts +7 -0
- package/src/symbols/reference.ts +17 -5
- package/src/symbols/ts-module-scope.ts +19 -4
- package/src/symbols/ts-output-symbol.ts +1 -0
- package/temp/api.json +613 -220
- package/test/class.test.tsx +75 -5
- package/test/enum-jsdoc.test.tsx +6 -6
- package/test/function-declaration-jsdoc.test.tsx +3 -3
- package/test/imports.test.tsx +215 -1
- package/test/interface-jsdoc.test.tsx +9 -9
- package/test/jsdoc.test.tsx +5 -5
- package/test/jsdocparam.test.tsx +8 -8
- package/test/member-expression.test.tsx +171 -2
- package/test/var-declaration-jsdoc.test.tsx +3 -3
- package/test/var-declaration.test.tsx +1 -1
|
@@ -31,6 +31,7 @@ export * from "./SourceFile.js";
|
|
|
31
31
|
export * from "./SwitchStatement.js";
|
|
32
32
|
export * from "./TsConfigJson.js";
|
|
33
33
|
export * from "./TypeDeclaration.js";
|
|
34
|
+
export * from "./TypeRefContext.js";
|
|
34
35
|
export * from "./ValueExpression.js";
|
|
35
36
|
export * from "./VarDeclaration.js";
|
|
36
37
|
export {};
|
|
@@ -40,6 +40,7 @@ export declare const CaseClause: import("@alloy-js/core").StcSignature<base.Case
|
|
|
40
40
|
export declare const TSConfigJson: import("@alloy-js/core").StcSignature<base.TSConfigJsonProps>;
|
|
41
41
|
export declare const FunctionType: import("@alloy-js/core").StcSignature<base.FunctionTypeProps>;
|
|
42
42
|
export declare const TypeDeclaration: import("@alloy-js/core").StcSignature<base.TypeDeclarationProps>;
|
|
43
|
+
export declare const TypeRefContext: import("@alloy-js/core").StcSignature<base.TypeRefContextProps>;
|
|
43
44
|
export declare const ValueExpression: import("@alloy-js/core").StcSignature<base.ValueExpressionProps>;
|
|
44
45
|
export declare const VarDeclaration: import("@alloy-js/core").StcSignature<base.VarDeclarationProps>;
|
|
45
46
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
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 -41,5 +41,6 @@ export const CaseClause = stc(base.CaseClause);
|
|
|
41
41
|
export const TSConfigJson = stc(base.TSConfigJson);
|
|
42
42
|
export const FunctionType = stc(base.FunctionType);
|
|
43
43
|
export const TypeDeclaration = stc(base.TypeDeclaration);
|
|
44
|
+
export const TypeRefContext = stc(base.TypeRefContext);
|
|
44
45
|
export const ValueExpression = stc(base.ValueExpression);
|
|
45
46
|
export const VarDeclaration = stc(base.VarDeclaration);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ComponentContext } from "@alloy-js/core";
|
|
2
|
+
interface TypeRefContext {
|
|
3
|
+
/** If in a type context */
|
|
4
|
+
type?: boolean;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Provides scopes for instance and static private members.
|
|
8
|
+
*/
|
|
9
|
+
export declare const TypeRefContext: ComponentContext<TypeRefContext>;
|
|
10
|
+
/**
|
|
11
|
+
* @returns 'true' if in a type context, 'false' if in a value context.
|
|
12
|
+
*/
|
|
13
|
+
export declare function isTypeRefContext(): boolean;
|
|
14
|
+
export {};
|
|
15
|
+
//# sourceMappingURL=type-ref-context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type-ref-context.d.ts","sourceRoot":"","sources":["../../../src/context/type-ref-context.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAA6B,MAAM,gBAAgB,CAAC;AAE7E,UAAU,cAAc;IACtB,2BAA2B;IAC3B,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AAED;;GAEG;AACH,eAAO,MAAM,cAAc,EAAE,gBAAgB,CAAC,cAAc,CAC3B,CAAC;AAElC;;GAEG;AACH,wBAAgB,gBAAgB,IAAI,OAAO,CAE1C"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { createContext, useContext } from "@alloy-js/core";
|
|
2
|
+
/**
|
|
3
|
+
* Provides scopes for instance and static private members.
|
|
4
|
+
*/
|
|
5
|
+
export const TypeRefContext = createContext();
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @returns 'true' if in a type context, 'false' if in a value context.
|
|
9
|
+
*/
|
|
10
|
+
export function isTypeRefContext() {
|
|
11
|
+
return useContext(TypeRefContext)?.type ?? false;
|
|
12
|
+
}
|
|
@@ -19,6 +19,12 @@ export interface ParameterDescriptorBase {
|
|
|
19
19
|
* Whether the parameter is optional.
|
|
20
20
|
*/
|
|
21
21
|
readonly optional?: boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Whether the parameter is can be null or undefined.
|
|
24
|
+
* when optional is true, this will be set to true by default,
|
|
25
|
+
* but explicitly setting this to false will override that.
|
|
26
|
+
*/
|
|
27
|
+
readonly nullish?: boolean;
|
|
22
28
|
/**
|
|
23
29
|
* Arbitrary metadata for the parameter symbol.
|
|
24
30
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parameter-descriptor.d.ts","sourceRoot":"","sources":["../../src/parameter-descriptor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAElD;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC;;OAEG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB;;OAEG;IACH,QAAQ,CAAC,IAAI,CAAC,EAAE,QAAQ,CAAC;IAEzB;;OAEG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAEpC;;OAEG;IACH,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC;IAE5B;;OAEG;IACH,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAE5C;;OAEG;IACH,QAAQ,CAAC,GAAG,CAAC,EAAE,QAAQ,CAAC;CACzB;AAED;;GAEG;AACH,MAAM,WAAW,mBAAoB,SAAQ,uBAAuB;IAClE;;OAEG;IACH,QAA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,SAAQ,uBAAuB;IAClE;;OAEG;IACH,QAAQ,CAAC,OAAO,CAAC,EAAE,QAAQ,CAAC;CAC7B;AAED;;GAEG;AACH,MAAM,WAAW,+BACf,SAAQ,uBAAuB;CAAG;AAEpC;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC;;OAEG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB;;OAEG;IACH,QAAQ,CAAC,OAAO,CAAC,EAAE,QAAQ,CAAC;IAE5B;;OAEG;IACH,QAAQ,CAAC,OAAO,CAAC,EAAE,QAAQ,CAAC;IAE5B;;OAEG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAEpC;;OAEG;IACH,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC7C"}
|
|
@@ -1,3 +1,6 @@
|
|
|
1
1
|
import { Refkey } from "@alloy-js/core";
|
|
2
|
-
export
|
|
2
|
+
export interface RefOptions {
|
|
3
|
+
type?: boolean;
|
|
4
|
+
}
|
|
5
|
+
export declare function ref(refkey: Refkey, options?: RefOptions): () => string;
|
|
3
6
|
//# sourceMappingURL=reference.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reference.d.ts","sourceRoot":"","sources":["../../../src/symbols/reference.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,MAAM,EAKP,MAAM,gBAAgB,CAAC;AAcxB,wBAAgB,GAAG,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,MAAM,
|
|
1
|
+
{"version":3,"file":"reference.d.ts","sourceRoot":"","sources":["../../../src/symbols/reference.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,MAAM,EAKP,MAAM,gBAAgB,CAAC;AAcxB,MAAM,WAAW,UAAU;IACzB,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AACD,wBAAgB,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,UAAU,GAAG,MAAM,MAAM,CAuGtE"}
|
|
@@ -4,7 +4,7 @@ import { SourceFileContext } from "../components/SourceFile.js";
|
|
|
4
4
|
import { usePrivateScope } from "../context/private-scope.js";
|
|
5
5
|
import { isValidJSIdentifier } from "../utils.js";
|
|
6
6
|
import { TSSymbolFlags } from "./ts-output-symbol.js";
|
|
7
|
-
export function ref(refkey) {
|
|
7
|
+
export function ref(refkey, options) {
|
|
8
8
|
const sourceFile = useContext(SourceFileContext);
|
|
9
9
|
const resolveResult = resolve(refkey);
|
|
10
10
|
const currentScope = useMemberScope();
|
|
@@ -65,7 +65,9 @@ export function ref(refkey) {
|
|
|
65
65
|
} else if (targetLocation === "module") {
|
|
66
66
|
const symbolPath = [...pathDown.slice(1).map(s => s.owner), targetDeclaration];
|
|
67
67
|
const importSymbol = symbolPath[0];
|
|
68
|
-
localSymbol = untrack(() => sourceFile.scope.addImport(importSymbol, pathDown[0]
|
|
68
|
+
localSymbol = untrack(() => sourceFile.scope.addImport(importSymbol, pathDown[0], {
|
|
69
|
+
type: options?.type
|
|
70
|
+
}));
|
|
69
71
|
}
|
|
70
72
|
if (memberPath && memberPath.length > 0) {
|
|
71
73
|
if (localSymbol) {
|
|
@@ -86,14 +88,18 @@ function buildMemberExpression(path) {
|
|
|
86
88
|
memberExpr += base.name;
|
|
87
89
|
path = path.slice(1);
|
|
88
90
|
}
|
|
91
|
+
let prevNullish = base.tsFlags & TSSymbolFlags.Nullish;
|
|
89
92
|
for (const sym of path) {
|
|
93
|
+
const optional = prevNullish ? "?" : "";
|
|
90
94
|
if (sym.tsFlags & TSSymbolFlags.PrivateMember) {
|
|
91
|
-
memberExpr +=
|
|
95
|
+
memberExpr += `${optional}.#${sym.name}`;
|
|
92
96
|
} else if (isValidJSIdentifier(sym.name) && !(sym.tsFlags & TSSymbolFlags.TypeSymbol)) {
|
|
93
|
-
memberExpr +=
|
|
97
|
+
memberExpr += `${optional}.${sym.name}`;
|
|
94
98
|
} else {
|
|
95
|
-
|
|
99
|
+
const joiner = sym.tsFlags & TSSymbolFlags.Nullish ? "?." : "";
|
|
100
|
+
memberExpr += `${joiner}[${JSON.stringify(sym.name)}]`;
|
|
96
101
|
}
|
|
102
|
+
prevNullish = sym.tsFlags & TSSymbolFlags.Nullish;
|
|
97
103
|
}
|
|
98
104
|
return memberExpr;
|
|
99
105
|
}
|
|
@@ -5,6 +5,9 @@ export interface ImportedSymbol {
|
|
|
5
5
|
target: TSOutputSymbol;
|
|
6
6
|
}
|
|
7
7
|
export type ImportRecords = Map<TSModuleScope, Set<ImportedSymbol>>;
|
|
8
|
+
export interface AddImportOptions {
|
|
9
|
+
type?: boolean;
|
|
10
|
+
}
|
|
8
11
|
export interface TSModuleScope extends OutputScope {
|
|
9
12
|
kind: "module";
|
|
10
13
|
exportedSymbols: Map<Refkey, TSOutputSymbol>;
|
|
@@ -13,7 +16,7 @@ export interface TSModuleScope extends OutputScope {
|
|
|
13
16
|
*/
|
|
14
17
|
importedSymbols: Map<TSOutputSymbol, TSOutputSymbol>;
|
|
15
18
|
importedModules: ImportRecords;
|
|
16
|
-
addImport(symbol: TSOutputSymbol, module: TSModuleScope): TSOutputSymbol;
|
|
19
|
+
addImport(symbol: TSOutputSymbol, module: TSModuleScope, options?: AddImportOptions): TSOutputSymbol;
|
|
17
20
|
}
|
|
18
21
|
export declare function createTSModuleScope(binder: Binder, parent: OutputScope, path: string): TSModuleScope;
|
|
19
22
|
//# sourceMappingURL=ts-module-scope.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ts-module-scope.d.ts","sourceRoot":"","sources":["../../../src/symbols/ts-module-scope.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAU,MAAM,gBAAgB,CAAC;AACrE,OAAO,EAEL,cAAc,EAEf,MAAM,uBAAuB,CAAC;AAE/B,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,c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M,EAAE,MAAM,EACd,MAAM,EAAE,WAAW,EACnB,IAAI,EAAE,MAAM,GACX,aAAa,CA6Cf"}
|
|
@@ -8,9 +8,13 @@ export function createTSModuleScope(binder, parent, path) {
|
|
|
8
8
|
exportedSymbols: new Map(),
|
|
9
9
|
importedSymbols: new Map(),
|
|
10
10
|
importedModules: new Map(),
|
|
11
|
-
addImport(targetSymbol, targetModule) {
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
addImport(targetSymbol, targetModule, options) {
|
|
12
|
+
const existing = this.importedSymbols.get(targetSymbol);
|
|
13
|
+
if (existing) {
|
|
14
|
+
if (!options?.type && existing.tsFlags & TSSymbolFlags.TypeSymbol) {
|
|
15
|
+
existing.tsFlags &= ~TSSymbolFlags.TypeSymbol;
|
|
16
|
+
}
|
|
17
|
+
return existing;
|
|
14
18
|
}
|
|
15
19
|
if (targetModule.kind !== "module") {
|
|
16
20
|
throw new Error("Cannot import symbol that isn't in module scope");
|
|
@@ -25,6 +29,9 @@ export function createTSModuleScope(binder, parent, path) {
|
|
|
25
29
|
refkey: refkey({}),
|
|
26
30
|
tsFlags: TSSymbolFlags.LocalImportSymbol
|
|
27
31
|
});
|
|
32
|
+
if (options?.type) {
|
|
33
|
+
localSymbol.tsFlags |= TSSymbolFlags.TypeSymbol;
|
|
34
|
+
}
|
|
28
35
|
this.importedSymbols.set(targetSymbol, localSymbol);
|
|
29
36
|
this.importedModules.get(targetModule).add({
|
|
30
37
|
local: localSymbol,
|
|
@@ -7,7 +7,8 @@ export declare enum TSSymbolFlags {
|
|
|
7
7
|
TypeSymbol = 2,
|
|
8
8
|
ParameterSymbol = 4,
|
|
9
9
|
PrivateMember = 8,
|
|
10
|
-
PrivateMemberContainer = 16
|
|
10
|
+
PrivateMemberContainer = 16,
|
|
11
|
+
Nullish = 32
|
|
11
12
|
}
|
|
12
13
|
export interface TSOutputSymbol extends OutputSymbol {
|
|
13
14
|
scope: TSOutputScope;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ts-output-symbol.d.ts","sourceRoot":"","sources":["../../../src/symbols/ts-output-symbol.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,MAAM,EACN,YAAY,EACZ,iBAAiB,EACjB,MAAM,EAEP,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAuB,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAG1E,oBAAY,aAAa;IACvB,IAAI,IAAsB;IAC1B,iBAAiB,IAAc;IAC/B,UAAU,IAAqB;IAC/B,eAAe,IAAgB;IAC/B,aAAa,IAAkB;IAC/B,sBAAsB,KAAS;
|
|
1
|
+
{"version":3,"file":"ts-output-symbol.d.ts","sourceRoot":"","sources":["../../../src/symbols/ts-output-symbol.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,MAAM,EACN,YAAY,EACZ,iBAAiB,EACjB,MAAM,EAEP,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAuB,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAG1E,oBAAY,aAAa;IACvB,IAAI,IAAsB;IAC1B,iBAAiB,IAAc;IAC/B,UAAU,IAAqB;IAC/B,eAAe,IAAgB;IAC/B,aAAa,IAAkB;IAC/B,sBAAsB,KAAS;IAC/B,OAAO,KAAS;CACjB;AAED,MAAM,WAAW,cAAe,SAAQ,YAAY;IAClD,KAAK,EAAE,aAAa,CAAC;IACrB,MAAM,EAAE,OAAO,CAAC;IAChB,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,EAAE,aAAa,CAAC;IACvB,kBAAkB,CAAC,EAAE,aAAa,CAAC;IACnC,wBAAwB,CAAC,EAAE,aAAa,CAAC;CAC1C;AAED,MAAM,WAAW,qBAAqB;IACpC,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAC3B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,aAAa,CAAC;IACtB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,KAAK,CAAC,EAAE,iBAAiB,CAAC;IAC1B,OAAO,CAAC,EAAE,aAAa,CAAC;IACxB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC;AAED,wBAAgB,cAAc,CAAC,OAAO,EAAE,qBAAqB,GAAG,cAAc,CAsC7E"}
|
|
@@ -9,6 +9,7 @@ export let TSSymbolFlags = /*#__PURE__*/function (TSSymbolFlags) {
|
|
|
9
9
|
TSSymbolFlags[TSSymbolFlags["ParameterSymbol"] = 4] = "ParameterSymbol";
|
|
10
10
|
TSSymbolFlags[TSSymbolFlags["PrivateMember"] = 8] = "PrivateMember";
|
|
11
11
|
TSSymbolFlags[TSSymbolFlags["PrivateMemberContainer"] = 16] = "PrivateMemberContainer";
|
|
12
|
+
TSSymbolFlags[TSSymbolFlags["Nullish"] = 32] = "Nullish";
|
|
12
13
|
return TSSymbolFlags;
|
|
13
14
|
}({});
|
|
14
15
|
export function createTSSymbol(options) {
|
package/dist/test/class.test.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createComponent as _$createComponent, createIntrinsic as _$createIntrinsic } from "@alloy-js/core/jsx-runtime";
|
|
2
|
-
import { List, refkey, StatementList } from "@alloy-js/core";
|
|
2
|
+
import { List, Output, refkey, render, StatementList } from "@alloy-js/core";
|
|
3
3
|
import "@alloy-js/core/testing";
|
|
4
4
|
import { d } from "@alloy-js/core/testing";
|
|
5
5
|
import { describe, expect, it } from "vitest";
|
|
@@ -205,6 +205,109 @@ describe("instance members", () => {
|
|
|
205
205
|
}
|
|
206
206
|
`);
|
|
207
207
|
});
|
|
208
|
+
it("doesn't conflict with variables outside the class", () => {
|
|
209
|
+
const rk = refkey();
|
|
210
|
+
const res = toSourceText(_$createComponent(List, {
|
|
211
|
+
get children() {
|
|
212
|
+
return [_$createComponent(ts.VarDeclaration, {
|
|
213
|
+
name: "one",
|
|
214
|
+
children: "1;"
|
|
215
|
+
}), _$createComponent(ts.VarDeclaration, {
|
|
216
|
+
name: "two",
|
|
217
|
+
children: "2;"
|
|
218
|
+
}), _$createComponent(ts.ClassDeclaration, {
|
|
219
|
+
name: "Foo",
|
|
220
|
+
get children() {
|
|
221
|
+
return _$createComponent(StatementList, {
|
|
222
|
+
get children() {
|
|
223
|
+
return [_$createComponent(ts.ClassField, {
|
|
224
|
+
name: "one",
|
|
225
|
+
refkey: rk,
|
|
226
|
+
children: "1"
|
|
227
|
+
}), _$createComponent(ts.ClassMethod, {
|
|
228
|
+
name: "two",
|
|
229
|
+
get children() {
|
|
230
|
+
return [rk, " + 1"];
|
|
231
|
+
}
|
|
232
|
+
})];
|
|
233
|
+
}
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
})];
|
|
237
|
+
}
|
|
238
|
+
}));
|
|
239
|
+
expect(res).toEqual(d`
|
|
240
|
+
const one = 1;
|
|
241
|
+
const two = 2;
|
|
242
|
+
class Foo {
|
|
243
|
+
one = 1;
|
|
244
|
+
two() {
|
|
245
|
+
this.one + 1
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
`);
|
|
249
|
+
});
|
|
250
|
+
it("doesn't conflict with imports from other files", () => {
|
|
251
|
+
const rk1 = refkey();
|
|
252
|
+
const rk2 = refkey();
|
|
253
|
+
const tree = render(_$createComponent(Output, {
|
|
254
|
+
nameConflictResolver: () => {
|
|
255
|
+
console.log("CONFLIT");
|
|
256
|
+
},
|
|
257
|
+
get children() {
|
|
258
|
+
return [_$createComponent(ts.SourceFile, {
|
|
259
|
+
path: "decl.ts",
|
|
260
|
+
get children() {
|
|
261
|
+
return _$createComponent(StatementList, {
|
|
262
|
+
get children() {
|
|
263
|
+
return [_$createComponent(ts.VarDeclaration, {
|
|
264
|
+
"export": true,
|
|
265
|
+
name: "one",
|
|
266
|
+
refkey: rk1,
|
|
267
|
+
children: "1"
|
|
268
|
+
}), _$createComponent(ts.VarDeclaration, {
|
|
269
|
+
"export": true,
|
|
270
|
+
name: "two",
|
|
271
|
+
refkey: rk2,
|
|
272
|
+
children: "2"
|
|
273
|
+
})];
|
|
274
|
+
}
|
|
275
|
+
});
|
|
276
|
+
}
|
|
277
|
+
}), _$createComponent(ts.SourceFile, {
|
|
278
|
+
path: "ref.ts",
|
|
279
|
+
get children() {
|
|
280
|
+
return _$createComponent(ts.ClassDeclaration, {
|
|
281
|
+
name: "Foo",
|
|
282
|
+
get children() {
|
|
283
|
+
return _$createComponent(StatementList, {
|
|
284
|
+
get children() {
|
|
285
|
+
return [_$createComponent(ts.ClassField, {
|
|
286
|
+
name: "one",
|
|
287
|
+
children: rk1
|
|
288
|
+
}), _$createComponent(ts.ClassMethod, {
|
|
289
|
+
name: "two",
|
|
290
|
+
children: rk2
|
|
291
|
+
})];
|
|
292
|
+
}
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
})];
|
|
298
|
+
}
|
|
299
|
+
}));
|
|
300
|
+
expect(tree.contents[1].contents).toEqual(d`
|
|
301
|
+
import { one, two } from "./decl.js";
|
|
302
|
+
|
|
303
|
+
class Foo {
|
|
304
|
+
one = one;
|
|
305
|
+
two() {
|
|
306
|
+
two
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
`);
|
|
310
|
+
});
|
|
208
311
|
});
|
|
209
312
|
describe("static members", () => {
|
|
210
313
|
it("renders", () => {
|
|
@@ -385,15 +488,15 @@ it("renders a class with docs for the class and its members", () => {
|
|
|
385
488
|
expect(res).toEqual(d`
|
|
386
489
|
/**
|
|
387
490
|
* This is a class documentation
|
|
388
|
-
|
|
491
|
+
*/
|
|
389
492
|
class Foo {
|
|
390
493
|
/**
|
|
391
494
|
* This is a field documentation
|
|
392
|
-
|
|
495
|
+
*/
|
|
393
496
|
bar = 123;
|
|
394
497
|
/**
|
|
395
498
|
* This is a method documentation
|
|
396
|
-
|
|
499
|
+
*/
|
|
397
500
|
baz() {
|
|
398
501
|
return 123;
|
|
399
502
|
}
|
|
@@ -431,7 +534,7 @@ it("renders a method with parameter docs", () => {
|
|
|
431
534
|
* @param {string} b - Line 1 for b.
|
|
432
535
|
* This is a long description that
|
|
433
536
|
* should continue in the next line.
|
|
434
|
-
|
|
537
|
+
*/
|
|
435
538
|
bar(a: number, b: string): void {}
|
|
436
539
|
}
|
|
437
540
|
`);
|
|
@@ -24,7 +24,7 @@ it("renders an enum declaration with documentation", () => {
|
|
|
24
24
|
expect(res).toEqual(d`
|
|
25
25
|
/**
|
|
26
26
|
* Color enumeration for the application
|
|
27
|
-
|
|
27
|
+
*/
|
|
28
28
|
enum Color {
|
|
29
29
|
Red,
|
|
30
30
|
Green,
|
|
@@ -63,25 +63,25 @@ it("renders an enum declaration with documented members", () => {
|
|
|
63
63
|
expect(res).toEqual(d`
|
|
64
64
|
/**
|
|
65
65
|
* Represents cardinal directions. Used for navigation purposes
|
|
66
|
-
|
|
66
|
+
*/
|
|
67
67
|
enum Direction {
|
|
68
68
|
/**
|
|
69
69
|
* Bound to the north
|
|
70
|
-
|
|
70
|
+
*/
|
|
71
71
|
North = 0,
|
|
72
72
|
/**
|
|
73
73
|
* Bound to the East
|
|
74
74
|
*
|
|
75
75
|
* A second doc paragraph
|
|
76
|
-
|
|
76
|
+
*/
|
|
77
77
|
East = 1,
|
|
78
78
|
/**
|
|
79
79
|
* Opposite to North
|
|
80
|
-
|
|
80
|
+
*/
|
|
81
81
|
South = 2,
|
|
82
82
|
/**
|
|
83
83
|
* Going west!
|
|
84
|
-
|
|
84
|
+
*/
|
|
85
85
|
West = 3,
|
|
86
86
|
}
|
|
87
87
|
`);
|
|
@@ -19,7 +19,7 @@ it("renders a function declaration with documentation", () => {
|
|
|
19
19
|
* A function that greets a person
|
|
20
20
|
*
|
|
21
21
|
* @param {string} name
|
|
22
|
-
|
|
22
|
+
*/
|
|
23
23
|
function greet(name: string): string {}
|
|
24
24
|
`);
|
|
25
25
|
});
|
|
@@ -44,7 +44,7 @@ it("With documented parameters", () => {
|
|
|
44
44
|
*
|
|
45
45
|
* @param {number} price
|
|
46
46
|
* @param {number} [taxRate]
|
|
47
|
-
|
|
47
|
+
*/
|
|
48
48
|
export function calculateTotal(price: number, taxRate?: number): number {}
|
|
49
49
|
`);
|
|
50
50
|
});
|
|
@@ -86,6 +86,6 @@ it("renders a function with a reference", () => {
|
|
|
86
86
|
* Creates a new user
|
|
87
87
|
*
|
|
88
88
|
* @param {User} user - The user object to create
|
|
89
|
-
|
|
89
|
+
*/
|
|
90
90
|
function createUser(user: User): void {}`);
|
|
91
91
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"imports.test.d.ts","sourceRoot":"","sources":["../../test/imports.test.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"imports.test.d.ts","sourceRoot":"","sources":["../../test/imports.test.tsx"],"names":[],"mappings":"AAQA,OAAO,wBAAwB,CAAC"}
|