@alloy-js/typescript 0.23.0-dev.7 → 0.23.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 +27 -0
- package/dist/dev/src/components/FunctionBase.js +1 -9
- package/dist/dev/src/components/FunctionBase.js.map +1 -1
- package/dist/dev/src/components/ImportStatement.js +42 -10
- package/dist/dev/src/components/ImportStatement.js.map +1 -1
- package/dist/dev/src/name-conflict-resolver.js +8 -2
- package/dist/dev/src/name-conflict-resolver.js.map +1 -1
- package/dist/dev/src/symbols/index.js +9 -3
- package/dist/dev/src/symbols/index.js.map +1 -1
- package/dist/dev/src/symbols/reference.js +19 -9
- package/dist/dev/src/symbols/reference.js.map +1 -1
- package/dist/dev/src/symbols/ts-module-scope.js +66 -2
- package/dist/dev/src/symbols/ts-module-scope.js.map +1 -1
- package/dist/dev/test/externals.test.js +17 -13
- package/dist/dev/test/externals.test.js.map +1 -1
- package/dist/dev/test/function-declaration.test.js +65 -7
- package/dist/dev/test/function-declaration.test.js.map +1 -1
- package/dist/dev/test/imports-reactive.test.js +223 -0
- package/dist/dev/test/imports-reactive.test.js.map +1 -0
- package/dist/dev/test/imports.test.js +262 -80
- package/dist/dev/test/imports.test.js.map +1 -1
- package/dist/dev/test/name-conflict.test.js.map +1 -1
- package/dist/src/components/FunctionBase.js +1 -5
- package/dist/src/components/FunctionBase.js.map +1 -1
- package/dist/src/components/ImportStatement.d.ts.map +1 -1
- package/dist/src/components/ImportStatement.js +16 -8
- package/dist/src/components/ImportStatement.js.map +1 -1
- package/dist/src/name-conflict-resolver.d.ts +2 -2
- package/dist/src/name-conflict-resolver.d.ts.map +1 -1
- package/dist/src/name-conflict-resolver.js +8 -2
- package/dist/src/name-conflict-resolver.js.map +1 -1
- package/dist/src/symbols/index.d.ts.map +1 -1
- package/dist/src/symbols/index.js +9 -3
- package/dist/src/symbols/index.js.map +1 -1
- package/dist/src/symbols/reference.d.ts.map +1 -1
- package/dist/src/symbols/reference.js +13 -3
- package/dist/src/symbols/reference.js.map +1 -1
- package/dist/src/symbols/ts-module-scope.d.ts +7 -0
- package/dist/src/symbols/ts-module-scope.d.ts.map +1 -1
- package/dist/src/symbols/ts-module-scope.js +66 -2
- package/dist/src/symbols/ts-module-scope.js.map +1 -1
- package/dist/test/externals.test.js +5 -1
- package/dist/test/externals.test.js.map +1 -1
- package/dist/test/function-declaration.test.js +42 -0
- package/dist/test/function-declaration.test.js.map +1 -1
- package/dist/test/imports-reactive.test.d.ts +2 -0
- package/dist/test/imports-reactive.test.d.ts.map +1 -0
- package/dist/test/imports-reactive.test.js +167 -0
- package/dist/test/imports-reactive.test.js.map +1 -0
- package/dist/test/imports.test.js +121 -3
- package/dist/test/imports.test.js.map +1 -1
- package/dist/test/name-conflict.test.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/docs/api/components/ArrowFunction.md +71 -0
- package/docs/api/components/BarrelFile.md +58 -0
- package/docs/api/components/BlockScope.md +97 -0
- package/docs/api/components/CallSignature.md +45 -0
- package/docs/api/components/CaseClause.md +102 -0
- package/docs/api/components/CatchClause.md +50 -0
- package/docs/api/components/ClassDeclaration.md +61 -0
- package/docs/api/components/ClassField.md +63 -0
- package/docs/api/components/ClassMember.md +56 -0
- package/docs/api/components/ClassMethod.md +75 -0
- package/docs/api/components/CommaList.md +31 -0
- package/docs/api/components/Declaration.md +87 -0
- package/docs/api/components/ElseClause.md +29 -0
- package/docs/api/components/ElseIfClause.md +30 -0
- package/docs/api/components/EnumDeclaration.md +29 -0
- package/docs/api/components/EnumMember.md +46 -0
- package/docs/api/components/ExportStatement.md +26 -0
- package/docs/api/components/FinallyClause.md +50 -0
- package/docs/api/components/FunctionCallExpression.md +29 -0
- package/docs/api/components/FunctionDeclaration.md +57 -0
- package/docs/api/components/FunctionExpression.md +71 -0
- package/docs/api/components/IfStatement.md +30 -0
- package/docs/api/components/ImportStatement.md +29 -0
- package/docs/api/components/ImportStatements.md +25 -0
- package/docs/api/components/InterfaceDeclaration.md +38 -0
- package/docs/api/components/InterfaceMember.md +99 -0
- package/docs/api/components/InterfaceMethod.md +74 -0
- package/docs/api/components/JSDoc.md +29 -0
- package/docs/api/components/JSDocComment.md +29 -0
- package/docs/api/components/JSDocExample.md +31 -0
- package/docs/api/components/MemberExpression.md +58 -0
- package/docs/api/components/NewExpression.md +26 -0
- package/docs/api/components/ObjectExpression.md +32 -0
- package/docs/api/components/ObjectProperty.md +44 -0
- package/docs/api/components/ObjectSpreadProperty.md +29 -0
- package/docs/api/components/PackageDirectory.md +102 -0
- package/docs/api/components/PackageJsonFile.md +82 -0
- package/docs/api/components/Reference.md +26 -0
- package/docs/api/components/SingleLineCommentBlock.md +29 -0
- package/docs/api/components/SourceFile.md +41 -0
- package/docs/api/components/SwitchStatement.md +30 -0
- package/docs/api/components/TSConfigJson.md +25 -0
- package/docs/api/components/TryStatement.md +50 -0
- package/docs/api/components/TypeRefContext.md +35 -0
- package/docs/api/components/ValueExpression.md +25 -0
- package/docs/api/components/VarDeclaration.md +44 -0
- package/docs/api/components/ensureTypeRefContext.md +28 -0
- package/docs/api/components/index.md +49 -0
- package/docs/api/contexts/Package-context.md +21 -0
- package/docs/api/contexts/PackageMetadata-context.md +18 -0
- package/docs/api/contexts/SourceFile-context.md +20 -0
- package/docs/api/contexts/index.md +5 -0
- package/docs/api/functions/createInstanceMemberSymbol.md +38 -0
- package/docs/api/functions/createLexicalScope.md +27 -0
- package/docs/api/functions/createMemberScope.md +28 -0
- package/docs/api/functions/createMemberSymbol.md +42 -0
- package/docs/api/functions/createPackage.md +18 -0
- package/docs/api/functions/createPrivateInstanceMemberSymbol.md +38 -0
- package/docs/api/functions/createPrivateStaticMemberSymbol.md +38 -0
- package/docs/api/functions/createStaticMemberSymbol.md +38 -0
- package/docs/api/functions/createTSNamePolicy.md +17 -0
- package/docs/api/functions/createTransientValueSymbol.md +17 -0
- package/docs/api/functions/createTypeAndValueSymbol.md +38 -0
- package/docs/api/functions/createTypeSymbol.md +38 -0
- package/docs/api/functions/createValueSymbol.md +38 -0
- package/docs/api/functions/decl.md +38 -0
- package/docs/api/functions/declMember.md +42 -0
- package/docs/api/functions/declType.md +38 -0
- package/docs/api/functions/getPackageScope.md +20 -0
- package/docs/api/functions/getSourceDirectoryData.md +18 -0
- package/docs/api/functions/index.md +27 -0
- package/docs/api/functions/ref.md +25 -0
- package/docs/api/functions/tsNameConflictResolver.md +19 -0
- package/docs/api/functions/useTSLexicalScope.md +17 -0
- package/docs/api/functions/useTSLexicalScopeIfPresent.md +17 -0
- package/docs/api/functions/useTSMemberScope.md +17 -0
- package/docs/api/functions/useTSNamePolicy.md +17 -0
- package/docs/api/functions/useTSScope.md +17 -0
- package/docs/api/index.md +7 -0
- package/docs/api/types/AddImportOptions.md +7 -0
- package/docs/api/types/BlockScopeProps.md +5 -0
- package/docs/api/types/CaseClauseProps.md +5 -0
- package/docs/api/types/CaseClausePropsBase.md +9 -0
- package/docs/api/types/CommonDeclarationProps.md +7 -0
- package/docs/api/types/CreatePackageProps.md +12 -0
- package/docs/api/types/CreateTsSymbolOptions.md +12 -0
- package/docs/api/types/DeclarationProps.md +5 -0
- package/docs/api/types/DeclarationPropsBase.md +8 -0
- package/docs/api/types/ExportConditions.md +7 -0
- package/docs/api/types/ExportPath.md +5 -0
- package/docs/api/types/ExternalPackage.md +7 -0
- package/docs/api/types/FunctionBodyProps.md +7 -0
- package/docs/api/types/FunctionParametersProps.md +10 -0
- package/docs/api/types/FunctionTypeParameterDescriptor.md +10 -0
- package/docs/api/types/FunctionTypeParametersProps.md +10 -0
- package/docs/api/types/FunctionTypeProps.md +13 -0
- package/docs/api/types/ImportRecords.md +5 -0
- package/docs/api/types/ImportedSymbol.md +8 -0
- package/docs/api/types/InterfaceExpressionProps.md +7 -0
- package/docs/api/types/InterfaceMemberProps.md +5 -0
- package/docs/api/types/InterfaceMemberPropsBase.md +11 -0
- package/docs/api/types/MemberExpressionPartProps.md +15 -0
- package/docs/api/types/ModuleExports.md +18 -0
- package/docs/api/types/ModuleSymbolsDescriptor.md +10 -0
- package/docs/api/types/NamedMap.md +18 -0
- package/docs/api/types/NamedModuleDescriptor.md +17 -0
- package/docs/api/types/PackageDescriptor.md +7 -0
- package/docs/api/types/PackageExports.md +7 -0
- package/docs/api/types/PackageRefkeys.md +10 -0
- package/docs/api/types/ParameterDescriptor.md +11 -0
- package/docs/api/types/ParameterDescriptorBase.md +16 -0
- package/docs/api/types/RefOptions.md +7 -0
- package/docs/api/types/SourceDirectoryData.md +7 -0
- package/docs/api/types/SourceFileHeaderProps.md +8 -0
- package/docs/api/types/TSLexicalScope.md +13 -0
- package/docs/api/types/TSMemberScope.md +14 -0
- package/docs/api/types/TSModuleScope.md +17 -0
- package/docs/api/types/TSOutputScope.md +5 -0
- package/docs/api/types/TSOutputSymbol.md +28 -0
- package/docs/api/types/TSPackageScope.md +21 -0
- package/docs/api/types/TSPackageScopeOptions.md +9 -0
- package/docs/api/types/TypeDeclarationProps.md +8 -0
- package/docs/api/types/TypeParameterDescriptor.md +13 -0
- package/docs/api/types/TypeScriptElements.md +5 -0
- package/docs/api/types/index.md +47 -0
- package/docs/api/variables/FunctionType.md +24 -0
- package/docs/api/variables/InterfaceExpression.md +5 -0
- package/docs/api/variables/TSSymbolFlags.md +5 -0
- package/docs/api/variables/TypeDeclaration.md +5 -0
- package/docs/api/variables/index.md +6 -0
- package/package.json +6 -6
- package/src/components/FunctionBase.tsx +1 -1
- package/src/components/ImportStatement.tsx +26 -12
- package/src/name-conflict-resolver.ts +12 -8
- package/src/symbols/index.ts +18 -3
- package/src/symbols/reference.tsx +17 -6
- package/src/symbols/ts-module-scope.ts +79 -2
- package/temp/api.json +68 -2
- package/test/externals.test.tsx +5 -1
- package/test/function-declaration.test.tsx +36 -0
- package/test/imports-reactive.test.tsx +128 -0
- package/test/imports.test.tsx +136 -2
- package/test/name-conflict.test.tsx +4 -4
package/temp/api.json
CHANGED
|
@@ -14941,6 +14941,72 @@
|
|
|
14941
14941
|
"isStatic": false,
|
|
14942
14942
|
"isProtected": false,
|
|
14943
14943
|
"isAbstract": false
|
|
14944
|
+
},
|
|
14945
|
+
{
|
|
14946
|
+
"kind": "Method",
|
|
14947
|
+
"canonicalReference": "@alloy-js/typescript!TSModuleScope#removeImport:member(1)",
|
|
14948
|
+
"docComment": "/**\n * Decrement the refcount for an import previously registered via\n * {@link TSModuleScope.addImport | addImport}. When the last live consumer goes away, the local import\n * symbol is deleted, which removes it from the module's name spaces and\n * triggers name-conflict-resolver reconciliation.\n */\n",
|
|
14949
|
+
"excerptTokens": [
|
|
14950
|
+
{
|
|
14951
|
+
"kind": "Content",
|
|
14952
|
+
"text": "removeImport(targetSymbol: "
|
|
14953
|
+
},
|
|
14954
|
+
{
|
|
14955
|
+
"kind": "Reference",
|
|
14956
|
+
"text": "TSOutputSymbol",
|
|
14957
|
+
"canonicalReference": "@alloy-js/typescript!TSOutputSymbol:class"
|
|
14958
|
+
},
|
|
14959
|
+
{
|
|
14960
|
+
"kind": "Content",
|
|
14961
|
+
"text": ", options?: "
|
|
14962
|
+
},
|
|
14963
|
+
{
|
|
14964
|
+
"kind": "Reference",
|
|
14965
|
+
"text": "AddImportOptions",
|
|
14966
|
+
"canonicalReference": "@alloy-js/typescript!AddImportOptions:interface"
|
|
14967
|
+
},
|
|
14968
|
+
{
|
|
14969
|
+
"kind": "Content",
|
|
14970
|
+
"text": "): "
|
|
14971
|
+
},
|
|
14972
|
+
{
|
|
14973
|
+
"kind": "Content",
|
|
14974
|
+
"text": "void"
|
|
14975
|
+
},
|
|
14976
|
+
{
|
|
14977
|
+
"kind": "Content",
|
|
14978
|
+
"text": ";"
|
|
14979
|
+
}
|
|
14980
|
+
],
|
|
14981
|
+
"isStatic": false,
|
|
14982
|
+
"returnTypeTokenRange": {
|
|
14983
|
+
"startIndex": 5,
|
|
14984
|
+
"endIndex": 6
|
|
14985
|
+
},
|
|
14986
|
+
"releaseTag": "Public",
|
|
14987
|
+
"isProtected": false,
|
|
14988
|
+
"overloadIndex": 1,
|
|
14989
|
+
"parameters": [
|
|
14990
|
+
{
|
|
14991
|
+
"parameterName": "targetSymbol",
|
|
14992
|
+
"parameterTypeTokenRange": {
|
|
14993
|
+
"startIndex": 1,
|
|
14994
|
+
"endIndex": 2
|
|
14995
|
+
},
|
|
14996
|
+
"isOptional": false
|
|
14997
|
+
},
|
|
14998
|
+
{
|
|
14999
|
+
"parameterName": "options",
|
|
15000
|
+
"parameterTypeTokenRange": {
|
|
15001
|
+
"startIndex": 3,
|
|
15002
|
+
"endIndex": 4
|
|
15003
|
+
},
|
|
15004
|
+
"isOptional": true
|
|
15005
|
+
}
|
|
15006
|
+
],
|
|
15007
|
+
"isOptional": false,
|
|
15008
|
+
"isAbstract": false,
|
|
15009
|
+
"name": "removeImport"
|
|
14944
15010
|
}
|
|
14945
15011
|
],
|
|
14946
15012
|
"extendsTokenRange": {
|
|
@@ -14968,8 +15034,8 @@
|
|
|
14968
15034
|
},
|
|
14969
15035
|
{
|
|
14970
15036
|
"kind": "Reference",
|
|
14971
|
-
"text": "
|
|
14972
|
-
"canonicalReference": "@alloy-js/
|
|
15037
|
+
"text": "OutputSymbol",
|
|
15038
|
+
"canonicalReference": "@alloy-js/core!OutputSymbol:class"
|
|
14973
15039
|
},
|
|
14974
15040
|
{
|
|
14975
15041
|
"kind": "Content",
|
package/test/externals.test.tsx
CHANGED
|
@@ -175,7 +175,11 @@ it("can import static members", () => {
|
|
|
175
175
|
</Output>,
|
|
176
176
|
).toRenderTo({
|
|
177
177
|
"index.ts": `
|
|
178
|
-
import {
|
|
178
|
+
import {
|
|
179
|
+
noMembers,
|
|
180
|
+
server,
|
|
181
|
+
simpleName,
|
|
182
|
+
} from "@modelcontextprotocol/sdk/server/index.js";
|
|
179
183
|
|
|
180
184
|
function foo() {
|
|
181
185
|
server();
|
|
@@ -388,6 +388,42 @@ describe("symbols", () => {
|
|
|
388
388
|
}
|
|
389
389
|
`);
|
|
390
390
|
});
|
|
391
|
+
|
|
392
|
+
it("adds symbols for members of parameters when a type and default are provided", () => {
|
|
393
|
+
const ifaceRk = refkey();
|
|
394
|
+
const ifaceMemberRk = refkey();
|
|
395
|
+
const paramRk = refkey();
|
|
396
|
+
|
|
397
|
+
const param: ParameterDescriptor = {
|
|
398
|
+
name: "myParam",
|
|
399
|
+
refkey: paramRk,
|
|
400
|
+
type: ifaceRk,
|
|
401
|
+
default: "undefined",
|
|
402
|
+
};
|
|
403
|
+
|
|
404
|
+
const decl = (
|
|
405
|
+
<List doubleHardline>
|
|
406
|
+
<InterfaceDeclaration name="IFace" refkey={ifaceRk}>
|
|
407
|
+
<InterfaceMember name="myProp" refkey={ifaceMemberRk}>
|
|
408
|
+
string
|
|
409
|
+
</InterfaceMember>
|
|
410
|
+
</InterfaceDeclaration>
|
|
411
|
+
<FunctionDeclaration name="fn" parameters={[param]}>
|
|
412
|
+
{memberRefkey(paramRk, ifaceMemberRk)}
|
|
413
|
+
</FunctionDeclaration>
|
|
414
|
+
</List>
|
|
415
|
+
);
|
|
416
|
+
|
|
417
|
+
expect(toSourceText(decl)).toBe(d`
|
|
418
|
+
interface IFace {
|
|
419
|
+
myProp: string
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
function fn(myParam: IFace = undefined) {
|
|
423
|
+
myParam.myProp
|
|
424
|
+
}
|
|
425
|
+
`);
|
|
426
|
+
});
|
|
391
427
|
});
|
|
392
428
|
|
|
393
429
|
it("has parameters and return type in type ref context", () => {
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Output,
|
|
3
|
+
printTree,
|
|
4
|
+
ref,
|
|
5
|
+
refkey,
|
|
6
|
+
renderTree,
|
|
7
|
+
Show,
|
|
8
|
+
} from "@alloy-js/core";
|
|
9
|
+
import "@alloy-js/core/testing";
|
|
10
|
+
import { expect, it } from "vitest";
|
|
11
|
+
import * as ts from "../src/components/index.js";
|
|
12
|
+
import { createPackage, PackageDirectory, SourceFile } from "../src/index.js";
|
|
13
|
+
|
|
14
|
+
const testLib = () =>
|
|
15
|
+
createPackage({
|
|
16
|
+
name: "testLib",
|
|
17
|
+
version: "1.0.0",
|
|
18
|
+
descriptor: {
|
|
19
|
+
".": { named: ["foo"] },
|
|
20
|
+
},
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
function sourceFileText(printed: string): string {
|
|
24
|
+
// Strip the surrounding package.json / tsconfig.json blobs and keep the
|
|
25
|
+
// text from index.ts onwards. The file content follows the last tsconfig
|
|
26
|
+
// closing brace.
|
|
27
|
+
const marker = "\n}";
|
|
28
|
+
const idx = printed.lastIndexOf(marker);
|
|
29
|
+
return idx === -1 ? printed : printed.slice(idx + marker.length);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
it("removes an import when the reference is removed", () => {
|
|
33
|
+
const lib = testLib();
|
|
34
|
+
const showIt = ref(true);
|
|
35
|
+
|
|
36
|
+
const tree = renderTree(
|
|
37
|
+
<Output externals={[lib]}>
|
|
38
|
+
<PackageDirectory path="." name="test" version="1.0.0">
|
|
39
|
+
<SourceFile path="index.ts">
|
|
40
|
+
<Show when={showIt.value}>x = {lib.foo};</Show>
|
|
41
|
+
</SourceFile>
|
|
42
|
+
</PackageDirectory>
|
|
43
|
+
</Output>,
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
const initial = sourceFileText(printTree(tree));
|
|
47
|
+
showIt.value = false;
|
|
48
|
+
const off = sourceFileText(printTree(tree));
|
|
49
|
+
showIt.value = true;
|
|
50
|
+
const back = sourceFileText(printTree(tree));
|
|
51
|
+
|
|
52
|
+
// With no live reference, the import line should not be in the file.
|
|
53
|
+
expect(off).not.toMatch(/import .* from "testLib"/);
|
|
54
|
+
// After re-showing, we should be back to the initial output.
|
|
55
|
+
expect(back).toEqual(initial);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it("does not leak name-conflict aliases across re-renders", () => {
|
|
59
|
+
const lib = testLib();
|
|
60
|
+
const showLocal = ref(true);
|
|
61
|
+
const fooRk = refkey("local-foo");
|
|
62
|
+
|
|
63
|
+
const tree = renderTree(
|
|
64
|
+
<Output externals={[lib]}>
|
|
65
|
+
<PackageDirectory path="." name="test" version="1.0.0">
|
|
66
|
+
<SourceFile path="index.ts">
|
|
67
|
+
<Show when={showLocal.value}>
|
|
68
|
+
<ts.VarDeclaration const name="foo" refkey={fooRk}>
|
|
69
|
+
1
|
|
70
|
+
</ts.VarDeclaration>
|
|
71
|
+
;
|
|
72
|
+
</Show>
|
|
73
|
+
use = {lib.foo};
|
|
74
|
+
</SourceFile>
|
|
75
|
+
</PackageDirectory>
|
|
76
|
+
</Output>,
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
sourceFileText(printTree(tree));
|
|
80
|
+
showLocal.value = false;
|
|
81
|
+
const off = sourceFileText(printTree(tree));
|
|
82
|
+
showLocal.value = true;
|
|
83
|
+
const back = sourceFileText(printTree(tree));
|
|
84
|
+
showLocal.value = false;
|
|
85
|
+
const off2 = sourceFileText(printTree(tree));
|
|
86
|
+
showLocal.value = true;
|
|
87
|
+
const back2 = sourceFileText(printTree(tree));
|
|
88
|
+
|
|
89
|
+
// While the local is hidden, the import should be the plain name, not an
|
|
90
|
+
// alias — the conflict is gone.
|
|
91
|
+
expect(off).toMatch(/import \{ foo \} from "testLib"/);
|
|
92
|
+
expect(off2).toMatch(/import \{ foo \} from "testLib"/);
|
|
93
|
+
// Off snapshots after repeated toggles must be identical (no drift).
|
|
94
|
+
expect(off2).toEqual(off);
|
|
95
|
+
// Back-on snapshots after repeated toggles must be identical too — no
|
|
96
|
+
// `foo_3`/`foo_4` drift.
|
|
97
|
+
expect(back2).toEqual(back);
|
|
98
|
+
// No generated name should drift beyond the expected `_2` suffix.
|
|
99
|
+
expect(back).not.toMatch(/foo_3|foo_4/);
|
|
100
|
+
expect(back2).not.toMatch(/foo_3|foo_4/);
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
it("removes only one ref count at a time", () => {
|
|
104
|
+
const lib = testLib();
|
|
105
|
+
const showA = ref(true);
|
|
106
|
+
const showB = ref(true);
|
|
107
|
+
|
|
108
|
+
const tree = renderTree(
|
|
109
|
+
<Output externals={[lib]}>
|
|
110
|
+
<PackageDirectory path="." name="test" version="1.0.0">
|
|
111
|
+
<SourceFile path="index.ts">
|
|
112
|
+
<Show when={showA.value}>a = {lib.foo};</Show>
|
|
113
|
+
<Show when={showB.value}>b = {lib.foo};</Show>
|
|
114
|
+
</SourceFile>
|
|
115
|
+
</PackageDirectory>
|
|
116
|
+
</Output>,
|
|
117
|
+
);
|
|
118
|
+
|
|
119
|
+
// Hide only one of the two references — the import must still be present.
|
|
120
|
+
showA.value = false;
|
|
121
|
+
const oneHidden = sourceFileText(printTree(tree));
|
|
122
|
+
expect(oneHidden).toMatch(/import \{ foo \} from "testLib"/);
|
|
123
|
+
|
|
124
|
+
// Hide the second — now the import should go away.
|
|
125
|
+
showB.value = false;
|
|
126
|
+
const bothHidden = sourceFileText(printTree(tree));
|
|
127
|
+
expect(bothHidden).not.toMatch(/import .* from "testLib"/);
|
|
128
|
+
});
|
package/test/imports.test.tsx
CHANGED
|
@@ -276,8 +276,14 @@ it("works with importing the same name many times from different files with the
|
|
|
276
276
|
).toRenderTo({
|
|
277
277
|
"test-import.ts": `
|
|
278
278
|
import { conflict, type MyInterface } from "./test1.js";
|
|
279
|
-
import {
|
|
280
|
-
|
|
279
|
+
import {
|
|
280
|
+
conflict as conflict_2,
|
|
281
|
+
type MyInterface as MyInterface_2,
|
|
282
|
+
} from "./test2.js";
|
|
283
|
+
import {
|
|
284
|
+
conflict as conflict_3,
|
|
285
|
+
type MyInterface as MyInterface_3,
|
|
286
|
+
} from "./test3.js";
|
|
281
287
|
|
|
282
288
|
const one: MyInterface = conflict;
|
|
283
289
|
const two: MyInterface_2 = conflict_2;
|
|
@@ -634,3 +640,131 @@ describe("type imports", () => {
|
|
|
634
640
|
});
|
|
635
641
|
});
|
|
636
642
|
});
|
|
643
|
+
|
|
644
|
+
describe("import formatting", () => {
|
|
645
|
+
it("breaks long imports across lines", () => {
|
|
646
|
+
const lib = createPackage({
|
|
647
|
+
name: "testLib",
|
|
648
|
+
version: "1.0.0",
|
|
649
|
+
descriptor: {
|
|
650
|
+
".": {
|
|
651
|
+
named: [
|
|
652
|
+
"alphaItem",
|
|
653
|
+
"bravoItem",
|
|
654
|
+
"charlieItem",
|
|
655
|
+
"deltaItem",
|
|
656
|
+
"echoItem",
|
|
657
|
+
"foxtrotItem",
|
|
658
|
+
],
|
|
659
|
+
},
|
|
660
|
+
},
|
|
661
|
+
});
|
|
662
|
+
|
|
663
|
+
expect(
|
|
664
|
+
<Output externals={[lib]} printWidth={40}>
|
|
665
|
+
<ts.SourceFile path="test.ts">
|
|
666
|
+
{lib.alphaItem};
|
|
667
|
+
<hbr />
|
|
668
|
+
{lib.bravoItem};
|
|
669
|
+
<hbr />
|
|
670
|
+
{lib.charlieItem};
|
|
671
|
+
<hbr />
|
|
672
|
+
{lib.deltaItem};
|
|
673
|
+
<hbr />
|
|
674
|
+
{lib.echoItem};
|
|
675
|
+
<hbr />
|
|
676
|
+
{lib.foxtrotItem};
|
|
677
|
+
</ts.SourceFile>
|
|
678
|
+
</Output>,
|
|
679
|
+
).toRenderTo({
|
|
680
|
+
"test.ts": `
|
|
681
|
+
import {
|
|
682
|
+
alphaItem,
|
|
683
|
+
bravoItem,
|
|
684
|
+
charlieItem,
|
|
685
|
+
deltaItem,
|
|
686
|
+
echoItem,
|
|
687
|
+
foxtrotItem,
|
|
688
|
+
} from "testLib";
|
|
689
|
+
|
|
690
|
+
alphaItem;
|
|
691
|
+
bravoItem;
|
|
692
|
+
charlieItem;
|
|
693
|
+
deltaItem;
|
|
694
|
+
echoItem;
|
|
695
|
+
foxtrotItem;
|
|
696
|
+
`,
|
|
697
|
+
});
|
|
698
|
+
});
|
|
699
|
+
|
|
700
|
+
it("keeps short imports on one line", () => {
|
|
701
|
+
const lib = createPackage({
|
|
702
|
+
name: "testLib",
|
|
703
|
+
version: "1.0.0",
|
|
704
|
+
descriptor: {
|
|
705
|
+
".": { named: ["a", "b"] },
|
|
706
|
+
},
|
|
707
|
+
});
|
|
708
|
+
|
|
709
|
+
expect(
|
|
710
|
+
<Output externals={[lib]} printWidth={40}>
|
|
711
|
+
<ts.SourceFile path="test.ts">
|
|
712
|
+
{lib.a};
|
|
713
|
+
<hbr />
|
|
714
|
+
{lib.b};
|
|
715
|
+
</ts.SourceFile>
|
|
716
|
+
</Output>,
|
|
717
|
+
).toRenderTo({
|
|
718
|
+
"test.ts": `
|
|
719
|
+
import { a, b } from "testLib";
|
|
720
|
+
|
|
721
|
+
a;
|
|
722
|
+
b;
|
|
723
|
+
`,
|
|
724
|
+
});
|
|
725
|
+
});
|
|
726
|
+
|
|
727
|
+
it("breaks long default + named imports", () => {
|
|
728
|
+
const lib = createPackage({
|
|
729
|
+
name: "testLib",
|
|
730
|
+
version: "1.0.0",
|
|
731
|
+
descriptor: {
|
|
732
|
+
".": {
|
|
733
|
+
default: "Big",
|
|
734
|
+
named: ["alphaItem", "bravoItem", "charlieItem", "deltaItem"],
|
|
735
|
+
},
|
|
736
|
+
},
|
|
737
|
+
});
|
|
738
|
+
|
|
739
|
+
expect(
|
|
740
|
+
<Output externals={[lib]} printWidth={40}>
|
|
741
|
+
<ts.SourceFile path="test.ts">
|
|
742
|
+
{lib.default};
|
|
743
|
+
<hbr />
|
|
744
|
+
{lib.alphaItem};
|
|
745
|
+
<hbr />
|
|
746
|
+
{lib.bravoItem};
|
|
747
|
+
<hbr />
|
|
748
|
+
{lib.charlieItem};
|
|
749
|
+
<hbr />
|
|
750
|
+
{lib.deltaItem};
|
|
751
|
+
</ts.SourceFile>
|
|
752
|
+
</Output>,
|
|
753
|
+
).toRenderTo({
|
|
754
|
+
"test.ts": `
|
|
755
|
+
import Big, {
|
|
756
|
+
alphaItem,
|
|
757
|
+
bravoItem,
|
|
758
|
+
charlieItem,
|
|
759
|
+
deltaItem,
|
|
760
|
+
} from "testLib";
|
|
761
|
+
|
|
762
|
+
Big;
|
|
763
|
+
alphaItem;
|
|
764
|
+
bravoItem;
|
|
765
|
+
charlieItem;
|
|
766
|
+
deltaItem;
|
|
767
|
+
`,
|
|
768
|
+
});
|
|
769
|
+
});
|
|
770
|
+
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Output } from "@alloy-js/core";
|
|
1
|
+
import { Output, OutputSymbol } from "@alloy-js/core";
|
|
2
2
|
import { camelCase } from "change-case";
|
|
3
3
|
import { expect, it } from "vitest";
|
|
4
4
|
import {
|
|
@@ -10,11 +10,11 @@ import {
|
|
|
10
10
|
import { ParameterDescriptor } from "../src/parameter-descriptor.js";
|
|
11
11
|
|
|
12
12
|
it("handles custom name conflict resolver based on metadata", () => {
|
|
13
|
-
function resolver(name: string, symbols:
|
|
14
|
-
const goodNamedSymbols = symbols.filter(
|
|
13
|
+
function resolver(name: string, symbols: OutputSymbol[]) {
|
|
14
|
+
const goodNamedSymbols = (symbols as TSOutputSymbol[]).filter(
|
|
15
15
|
(s) => ~s.tsFlags & TSSymbolFlags.LocalImportSymbol,
|
|
16
16
|
);
|
|
17
|
-
const badNamedSymbols = symbols.filter(
|
|
17
|
+
const badNamedSymbols = (symbols as TSOutputSymbol[]).filter(
|
|
18
18
|
(s) => s.tsFlags & TSSymbolFlags.LocalImportSymbol,
|
|
19
19
|
);
|
|
20
20
|
let nameCount = 1;
|