@alloy-js/typescript 0.22.0 → 0.23.0-dev.10
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/dist/dev/src/builtins/index.js +2 -0
- package/dist/dev/src/builtins/index.js.map +1 -0
- package/dist/dev/src/builtins/node.js +42 -0
- package/dist/dev/src/builtins/node.js.map +1 -0
- package/dist/dev/src/components/ArrayExpression.js +59 -0
- package/dist/dev/src/components/ArrayExpression.js.map +1 -0
- package/dist/dev/src/components/ArrowFunction.js +74 -0
- package/dist/dev/src/components/ArrowFunction.js.map +1 -0
- package/dist/dev/src/components/BarrelFile.js +87 -0
- package/dist/dev/src/components/BarrelFile.js.map +1 -0
- package/dist/dev/src/components/BlockScope.js +28 -0
- package/dist/dev/src/components/BlockScope.js.map +1 -0
- package/dist/dev/src/components/CallSignature.js +42 -0
- package/dist/dev/src/components/CallSignature.js.map +1 -0
- package/dist/dev/src/components/ClassDeclaration.js +279 -0
- package/dist/dev/src/components/ClassDeclaration.js.map +1 -0
- package/dist/dev/src/components/CommaList.js +21 -0
- package/dist/dev/src/components/CommaList.js.map +1 -0
- package/dist/dev/src/components/Declaration.js +60 -0
- package/dist/dev/src/components/Declaration.js.map +1 -0
- package/dist/dev/src/components/EnumDeclaration.js +96 -0
- package/dist/dev/src/components/EnumDeclaration.js.map +1 -0
- package/dist/dev/src/components/EnumMember.js +69 -0
- package/dist/dev/src/components/EnumMember.js.map +1 -0
- package/dist/dev/src/components/ExportStatement.js +18 -0
- package/dist/dev/src/components/ExportStatement.js.map +1 -0
- package/dist/dev/src/components/FunctionBase.js +364 -0
- package/dist/dev/src/components/FunctionBase.js.map +1 -0
- package/dist/dev/src/components/FunctionCallExpression.js +41 -0
- package/dist/dev/src/components/FunctionCallExpression.js.map +1 -0
- package/dist/dev/src/components/FunctionDeclaration.js +118 -0
- package/dist/dev/src/components/FunctionDeclaration.js.map +1 -0
- package/dist/dev/src/components/FunctionExpression.js +73 -0
- package/dist/dev/src/components/FunctionExpression.js.map +1 -0
- package/dist/dev/src/components/FunctionType.js +106 -0
- package/dist/dev/src/components/FunctionType.js.map +1 -0
- package/dist/dev/src/components/IfStatement.js +45 -0
- package/dist/dev/src/components/IfStatement.js.map +1 -0
- package/dist/dev/src/components/ImportStatement.js +142 -0
- package/dist/dev/src/components/ImportStatement.js.map +1 -0
- package/dist/dev/src/components/Interface.js +254 -0
- package/dist/dev/src/components/Interface.js.map +1 -0
- package/dist/dev/src/components/InterfaceMethod.js +120 -0
- package/dist/dev/src/components/InterfaceMethod.js.map +1 -0
- package/dist/dev/src/components/JSDoc.js +28 -0
- package/dist/dev/src/components/JSDoc.js.map +1 -0
- package/dist/dev/src/components/JSDocComment.js +27 -0
- package/dist/dev/src/components/JSDocComment.js.map +1 -0
- package/dist/dev/src/components/JSDocExample.js +44 -0
- package/dist/dev/src/components/JSDocExample.js.map +1 -0
- package/dist/dev/src/components/JSDocParam.js +175 -0
- package/dist/dev/src/components/JSDocParam.js.map +1 -0
- package/dist/dev/src/components/LexicalScope.js +29 -0
- package/dist/dev/src/components/LexicalScope.js.map +1 -0
- package/dist/dev/src/components/MemberDeclaration.js +29 -0
- package/dist/dev/src/components/MemberDeclaration.js.map +1 -0
- package/dist/dev/src/components/MemberExpression.js +284 -0
- package/dist/dev/src/components/MemberExpression.js.map +1 -0
- package/dist/dev/src/components/MemberScope.js +26 -0
- package/dist/dev/src/components/MemberScope.js.map +1 -0
- package/dist/dev/src/components/NewExpression.js +17 -0
- package/dist/dev/src/components/NewExpression.js.map +1 -0
- package/dist/dev/src/components/ObjectExpression.js +179 -0
- package/dist/dev/src/components/ObjectExpression.js.map +1 -0
- package/dist/dev/src/components/PackageDirectory.js +108 -0
- package/dist/dev/src/components/PackageDirectory.js.map +1 -0
- package/dist/dev/src/components/PackageJson.js +78 -0
- package/dist/dev/src/components/PackageJson.js.map +1 -0
- package/dist/dev/src/components/PropertyName.js +37 -0
- package/dist/dev/src/components/PropertyName.js.map +1 -0
- package/dist/dev/src/components/Reference.js +17 -0
- package/dist/dev/src/components/Reference.js.map +1 -0
- package/dist/dev/src/components/SingleLineCommentBlock.js +27 -0
- package/dist/dev/src/components/SingleLineCommentBlock.js.map +1 -0
- package/dist/dev/src/components/SourceFile.js +150 -0
- package/dist/dev/src/components/SourceFile.js.map +1 -0
- package/dist/dev/src/components/SwitchStatement.js +74 -0
- package/dist/dev/src/components/SwitchStatement.js.map +1 -0
- package/dist/dev/src/components/TryStatement.js +128 -0
- package/dist/dev/src/components/TryStatement.js.map +1 -0
- package/dist/dev/src/components/TryStatement.test.js +181 -0
- package/dist/dev/src/components/TryStatement.test.js.map +1 -0
- package/dist/dev/src/components/TsConfigJson.js +62 -0
- package/dist/dev/src/components/TsConfigJson.js.map +1 -0
- package/dist/dev/src/components/TypeDeclaration.js +46 -0
- package/dist/dev/src/components/TypeDeclaration.js.map +1 -0
- package/dist/dev/src/components/TypeRefContext.js +58 -0
- package/dist/dev/src/components/TypeRefContext.js.map +1 -0
- package/dist/dev/src/components/ValueExpression.js +42 -0
- package/dist/dev/src/components/ValueExpression.js.map +1 -0
- package/dist/dev/src/components/VarDeclaration.js +107 -0
- package/dist/dev/src/components/VarDeclaration.js.map +1 -0
- package/dist/dev/src/components/index.js +40 -0
- package/dist/dev/src/components/index.js.map +1 -0
- package/dist/dev/src/components/interface/expression.test.js +217 -0
- package/dist/dev/src/components/interface/expression.test.js.map +1 -0
- package/dist/dev/src/components/stc/index.js +48 -0
- package/dist/dev/src/components/stc/index.js.map +1 -0
- package/dist/dev/src/context/index.js +3 -0
- package/dist/dev/src/context/index.js.map +1 -0
- package/dist/dev/src/context/package-metadata.js +3 -0
- package/dist/dev/src/context/package-metadata.js.map +1 -0
- package/dist/dev/src/context/type-ref-context.js +13 -0
- package/dist/dev/src/context/type-ref-context.js.map +1 -0
- package/dist/dev/src/create-package.js +178 -0
- package/dist/dev/src/create-package.js.map +1 -0
- package/dist/dev/src/index.js +10 -0
- package/dist/dev/src/index.js.map +1 -0
- package/dist/dev/src/name-conflict-resolver.js +21 -0
- package/dist/dev/src/name-conflict-resolver.js.map +1 -0
- package/dist/dev/src/name-policy.js +52 -0
- package/dist/dev/src/name-policy.js.map +1 -0
- package/dist/dev/src/parameter-descriptor.js +2 -0
- package/dist/dev/src/parameter-descriptor.js.map +1 -0
- package/dist/dev/src/source-directory-data.js +13 -0
- package/dist/dev/src/source-directory-data.js.map +1 -0
- package/dist/dev/src/symbols/index.js +151 -0
- package/dist/dev/src/symbols/index.js.map +1 -0
- package/dist/dev/src/symbols/reference.js +155 -0
- package/dist/dev/src/symbols/reference.js.map +1 -0
- package/dist/dev/src/symbols/scopes.js +31 -0
- package/dist/dev/src/symbols/scopes.js.map +1 -0
- package/dist/dev/src/symbols/ts-lexical-scope.js +17 -0
- package/dist/dev/src/symbols/ts-lexical-scope.js.map +1 -0
- package/dist/dev/src/symbols/ts-member-scope.js +19 -0
- package/dist/dev/src/symbols/ts-member-scope.js.map +1 -0
- package/dist/dev/src/symbols/ts-module-scope.js +137 -0
- package/dist/dev/src/symbols/ts-module-scope.js.map +1 -0
- package/dist/dev/src/symbols/ts-output-symbol.js +144 -0
- package/dist/dev/src/symbols/ts-output-symbol.js.map +1 -0
- package/dist/dev/src/symbols/ts-package-scope.js +90 -0
- package/dist/dev/src/symbols/ts-package-scope.js.map +1 -0
- package/dist/dev/src/utils.js +46 -0
- package/dist/dev/src/utils.js.map +1 -0
- package/dist/dev/test/array.test.js +158 -0
- package/dist/dev/test/array.test.js.map +1 -0
- package/dist/dev/test/arrow-function.test.js +308 -0
- package/dist/dev/test/arrow-function.test.js.map +1 -0
- package/dist/dev/test/barrel.test.js +115 -0
- package/dist/dev/test/barrel.test.js.map +1 -0
- package/dist/dev/test/basic.test.js +131 -0
- package/dist/dev/test/basic.test.js.map +1 -0
- package/dist/dev/test/block-scope.test.js +51 -0
- package/dist/dev/test/block-scope.test.js.map +1 -0
- package/dist/dev/test/class.test.js +940 -0
- package/dist/dev/test/class.test.js.map +1 -0
- package/dist/dev/test/decl-helpers.test.js +217 -0
- package/dist/dev/test/decl-helpers.test.js.map +1 -0
- package/dist/dev/test/enum-jsdoc.test.js +133 -0
- package/dist/dev/test/enum-jsdoc.test.js.map +1 -0
- package/dist/dev/test/enum.test.js +461 -0
- package/dist/dev/test/enum.test.js.map +1 -0
- package/dist/dev/test/externals.test.js +493 -0
- package/dist/dev/test/externals.test.js.map +1 -0
- package/dist/dev/test/function-call-expression.test.js +144 -0
- package/dist/dev/test/function-call-expression.test.js.map +1 -0
- package/dist/dev/test/function-declaration-jsdoc.test.js +128 -0
- package/dist/dev/test/function-declaration-jsdoc.test.js.map +1 -0
- package/dist/dev/test/function-declaration.test.js +671 -0
- package/dist/dev/test/function-declaration.test.js.map +1 -0
- package/dist/dev/test/function-expression.test.js +308 -0
- package/dist/dev/test/function-expression.test.js.map +1 -0
- package/dist/dev/test/function-type.test.js +201 -0
- package/dist/dev/test/function-type.test.js.map +1 -0
- package/dist/dev/test/if-statement.test.js +38 -0
- package/dist/dev/test/if-statement.test.js.map +1 -0
- 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 +1673 -0
- package/dist/dev/test/imports.test.js.map +1 -0
- package/dist/dev/test/interface-jsdoc.test.js +267 -0
- package/dist/dev/test/interface-jsdoc.test.js.map +1 -0
- package/dist/dev/test/interface.test.js +986 -0
- package/dist/dev/test/interface.test.js.map +1 -0
- package/dist/dev/test/jscomment.test.js +123 -0
- package/dist/dev/test/jscomment.test.js.map +1 -0
- package/dist/dev/test/jsdoc.test.js +203 -0
- package/dist/dev/test/jsdoc.test.js.map +1 -0
- package/dist/dev/test/jsdocparam.test.js +237 -0
- package/dist/dev/test/jsdocparam.test.js.map +1 -0
- package/dist/dev/test/member-expression.test.js +2021 -0
- package/dist/dev/test/member-expression.test.js.map +1 -0
- package/dist/dev/test/name-conflict.test.js +119 -0
- package/dist/dev/test/name-conflict.test.js.map +1 -0
- package/dist/dev/test/name-policy.test.js +215 -0
- package/dist/dev/test/name-policy.test.js.map +1 -0
- package/dist/dev/test/new-expression.test.js +100 -0
- package/dist/dev/test/new-expression.test.js.map +1 -0
- package/dist/dev/test/object.test.js +167 -0
- package/dist/dev/test/object.test.js.map +1 -0
- package/dist/dev/test/package-external.test.js +281 -0
- package/dist/dev/test/package-external.test.js.map +1 -0
- package/dist/dev/test/package-json.test.js +113 -0
- package/dist/dev/test/package-json.test.js.map +1 -0
- package/dist/dev/test/package.test.js +188 -0
- package/dist/dev/test/package.test.js.map +1 -0
- package/dist/dev/test/reference.test.js +141 -0
- package/dist/dev/test/reference.test.js.map +1 -0
- package/dist/dev/test/source-file.test.js +50 -0
- package/dist/dev/test/source-file.test.js.map +1 -0
- package/dist/dev/test/switch-statement.test.js +94 -0
- package/dist/dev/test/switch-statement.test.js.map +1 -0
- package/dist/dev/test/utils.js +77 -0
- package/dist/dev/test/utils.js.map +1 -0
- package/dist/dev/test/value-expression.test.js +35 -0
- package/dist/dev/test/value-expression.test.js.map +1 -0
- package/dist/dev/test/values.test.js +618 -0
- package/dist/dev/test/values.test.js.map +1 -0
- package/dist/dev/test/var-declaration-jsdoc.test.js +63 -0
- package/dist/dev/test/var-declaration-jsdoc.test.js.map +1 -0
- package/dist/dev/test/var-declaration.test.js +395 -0
- package/dist/dev/test/var-declaration.test.js.map +1 -0
- package/dist/dev/test/vitest.setup.js +2 -0
- package/dist/dev/test/vitest.setup.js.map +1 -0
- package/dist/dev/testing/create-wrapper.js +12 -0
- package/dist/dev/testing/create-wrapper.js.map +1 -0
- package/dist/dev/testing/create-wrapper.test.js +231 -0
- package/dist/dev/testing/create-wrapper.test.js.map +1 -0
- package/dist/dev/testing/index.js +2 -0
- package/dist/dev/testing/index.js.map +1 -0
- package/dist/src/components/FunctionBase.js +1 -5
- package/dist/src/components/FunctionBase.js.map +1 -1
- package/dist/src/components/FunctionType.d.ts +1 -1
- package/dist/src/components/FunctionType.js +1 -1
- package/dist/src/components/FunctionType.js.map +1 -1
- package/dist/src/components/IfStatement.d.ts.map +1 -1
- package/dist/src/components/IfStatement.js +2 -3
- package/dist/src/components/IfStatement.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/components/Interface.d.ts +1 -1
- package/dist/src/components/Interface.d.ts.map +1 -1
- package/dist/src/components/Interface.js +24 -9
- package/dist/src/components/Interface.js.map +1 -1
- package/dist/src/components/MemberExpression.d.ts +1 -1
- package/dist/src/components/MemberExpression.d.ts.map +1 -1
- package/dist/src/components/MemberExpression.js +115 -330
- package/dist/src/components/MemberExpression.js.map +1 -1
- package/dist/src/components/MemberScope.d.ts.map +1 -1
- package/dist/src/components/MemberScope.js +6 -2
- package/dist/src/components/MemberScope.js.map +1 -1
- package/dist/src/components/PackageDirectory.d.ts.map +1 -1
- package/dist/src/components/PackageDirectory.js +2 -2
- package/dist/src/components/PackageDirectory.js.map +1 -1
- package/dist/src/components/SourceFile.d.ts.map +1 -1
- package/dist/src/components/SourceFile.js +4 -2
- package/dist/src/components/SourceFile.js.map +1 -1
- package/dist/src/components/TryStatement.d.ts +80 -0
- package/dist/src/components/TryStatement.d.ts.map +1 -0
- package/dist/src/components/TryStatement.js +112 -0
- package/dist/src/components/TryStatement.js.map +1 -0
- package/dist/src/components/TryStatement.test.d.ts +2 -0
- package/dist/src/components/TryStatement.test.d.ts.map +1 -0
- package/dist/src/components/TryStatement.test.js +121 -0
- package/dist/src/components/TryStatement.test.js.map +1 -0
- package/dist/src/components/TsConfigJson.d.ts.map +1 -1
- package/dist/src/components/TsConfigJson.js +5 -0
- package/dist/src/components/TsConfigJson.js.map +1 -1
- 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 +1 -1
- package/dist/src/components/TypeDeclaration.js.map +1 -1
- package/dist/src/components/TypeRefContext.d.ts +1 -1
- package/dist/src/components/TypeRefContext.d.ts.map +1 -1
- package/dist/src/components/TypeRefContext.js +1 -1
- package/dist/src/components/TypeRefContext.js.map +1 -1
- 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/index.js.map +1 -1
- package/dist/src/context/type-ref-context.d.ts.map +1 -1
- package/dist/src/context/type-ref-context.js +2 -2
- package/dist/src/context/type-ref-context.js.map +1 -1
- package/dist/src/create-package.d.ts.map +1 -1
- package/dist/src/create-package.js +7 -6
- package/dist/src/create-package.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 +53 -11
- 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 +8 -0
- package/dist/src/symbols/ts-module-scope.d.ts.map +1 -1
- package/dist/src/symbols/ts-module-scope.js +80 -5
- package/dist/src/symbols/ts-module-scope.js.map +1 -1
- package/dist/src/symbols/ts-output-symbol.d.ts +1 -0
- package/dist/src/symbols/ts-output-symbol.d.ts.map +1 -1
- package/dist/src/symbols/ts-output-symbol.js +20 -3
- package/dist/src/symbols/ts-output-symbol.js.map +1 -1
- package/dist/src/symbols/ts-package-scope.d.ts +1 -0
- package/dist/src/symbols/ts-package-scope.d.ts.map +1 -1
- package/dist/src/symbols/ts-package-scope.js +8 -0
- package/dist/src/symbols/ts-package-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 +15 -7
- package/src/components/FunctionBase.tsx +1 -1
- package/src/components/FunctionType.tsx +1 -1
- package/src/components/IfStatement.tsx +3 -3
- package/src/components/ImportStatement.tsx +26 -12
- package/src/components/Interface.tsx +58 -29
- package/src/components/MemberExpression.tsx +194 -454
- package/src/components/MemberScope.tsx +13 -3
- package/src/components/PackageDirectory.tsx +2 -1
- package/src/components/SourceFile.tsx +4 -1
- package/src/components/TryStatement.test.tsx +123 -0
- package/src/components/TryStatement.tsx +141 -0
- package/src/components/TsConfigJson.tsx +18 -9
- package/src/components/TypeDeclaration.tsx +15 -15
- package/src/components/TypeRefContext.tsx +2 -2
- package/src/components/index.ts +1 -0
- package/src/context/type-ref-context.tsx +6 -2
- package/src/create-package.ts +29 -15
- package/src/name-conflict-resolver.ts +12 -8
- package/src/symbols/index.ts +51 -10
- package/src/symbols/reference.tsx +17 -6
- package/src/symbols/ts-module-scope.ts +115 -11
- package/src/symbols/ts-output-symbol.ts +21 -2
- package/src/symbols/ts-package-scope.ts +9 -0
- package/temp/api.json +547 -73
- 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/vitest.config.ts +8 -0
|
@@ -1,17 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Children,
|
|
3
|
-
childrenArray,
|
|
4
3
|
computed,
|
|
4
|
+
createAccessExpression,
|
|
5
5
|
For,
|
|
6
|
-
isComponentCreator,
|
|
7
6
|
OutputSymbol,
|
|
8
|
-
reactive,
|
|
9
|
-
ref,
|
|
10
7
|
Refkey,
|
|
11
8
|
Show,
|
|
12
|
-
takeSymbols,
|
|
13
|
-
ToRefs,
|
|
14
|
-
useBinder,
|
|
15
9
|
} from "@alloy-js/core";
|
|
16
10
|
|
|
17
11
|
import { TSOutputSymbol, TSSymbolFlags } from "../symbols/ts-output-symbol.js";
|
|
@@ -21,14 +15,14 @@ export interface MemberExpressionProps {
|
|
|
21
15
|
children: Children;
|
|
22
16
|
}
|
|
23
17
|
|
|
24
|
-
|
|
18
|
+
type PartDescriptorWithId = PartDescriptorBase & {
|
|
25
19
|
id: Children;
|
|
26
|
-
}
|
|
20
|
+
};
|
|
27
21
|
|
|
28
|
-
|
|
22
|
+
type PartDescriptorWithIndex = PartDescriptorBase & {
|
|
29
23
|
index: number;
|
|
30
|
-
}
|
|
31
|
-
|
|
24
|
+
};
|
|
25
|
+
type PartDescriptorBase = {
|
|
32
26
|
accessStyle: "dot" | "bracket";
|
|
33
27
|
jsPrivate: boolean;
|
|
34
28
|
quoteId: boolean;
|
|
@@ -39,10 +33,131 @@ interface PartDescriptorBase {
|
|
|
39
33
|
* Whether to await the value that results from this part of the member expression.
|
|
40
34
|
*/
|
|
41
35
|
await?: boolean;
|
|
42
|
-
}
|
|
36
|
+
};
|
|
43
37
|
|
|
44
38
|
type PartDescriptor = PartDescriptorWithId | PartDescriptorWithIndex;
|
|
45
39
|
|
|
40
|
+
const exclusiveParts: (keyof MemberExpressionPartProps)[] = [
|
|
41
|
+
"children",
|
|
42
|
+
"args",
|
|
43
|
+
"refkey",
|
|
44
|
+
"symbol",
|
|
45
|
+
"id",
|
|
46
|
+
];
|
|
47
|
+
|
|
48
|
+
const { Expression, Part, registerOuterComponent } = createAccessExpression<
|
|
49
|
+
MemberExpressionPartProps,
|
|
50
|
+
PartDescriptor
|
|
51
|
+
>({
|
|
52
|
+
createDescriptor(partProps, sym, first) {
|
|
53
|
+
const foundProps = exclusiveParts.filter((key) => key in partProps);
|
|
54
|
+
if (foundProps.length > 1) {
|
|
55
|
+
throw new Error(
|
|
56
|
+
`Only one of ${foundProps.join(", ")} can be used for a MemberExpression part at a time`,
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
let id: Children;
|
|
61
|
+
if (partProps.args) {
|
|
62
|
+
id = undefined;
|
|
63
|
+
} else if (partProps.children !== undefined) {
|
|
64
|
+
id = partProps.children;
|
|
65
|
+
} else if (first && partProps.refkey) {
|
|
66
|
+
id = partProps.refkey;
|
|
67
|
+
} else if (partProps.id !== undefined) {
|
|
68
|
+
id =
|
|
69
|
+
isNumericIdentifier(partProps.id) ?
|
|
70
|
+
partProps.id
|
|
71
|
+
: escapeId(partProps.id);
|
|
72
|
+
} else if (partProps.index !== undefined) {
|
|
73
|
+
id = partProps.index;
|
|
74
|
+
} else if (sym) {
|
|
75
|
+
id = escapeId(sym.name);
|
|
76
|
+
} else {
|
|
77
|
+
id = "<unresolved symbol>";
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
let accessStyle: "dot" | "bracket";
|
|
81
|
+
if (partProps.children !== undefined) {
|
|
82
|
+
accessStyle =
|
|
83
|
+
typeof partProps.children === "string" ?
|
|
84
|
+
partProps.quoteId ?
|
|
85
|
+
"bracket"
|
|
86
|
+
: accessStyleForMemberName(partProps.children)
|
|
87
|
+
: "bracket";
|
|
88
|
+
} else if (partProps.args) {
|
|
89
|
+
accessStyle = "dot";
|
|
90
|
+
} else if (partProps.quoteId) {
|
|
91
|
+
accessStyle = "bracket";
|
|
92
|
+
} else if (partProps.id !== undefined) {
|
|
93
|
+
accessStyle =
|
|
94
|
+
isNumericIdentifier(partProps.id) ? "bracket" : (
|
|
95
|
+
accessStyleForMemberName(partProps.id)
|
|
96
|
+
);
|
|
97
|
+
} else if (partProps.index !== undefined) {
|
|
98
|
+
accessStyle = "bracket";
|
|
99
|
+
} else if (sym) {
|
|
100
|
+
accessStyle = accessStyleForMemberName(sym.name);
|
|
101
|
+
} else {
|
|
102
|
+
accessStyle = "dot";
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return {
|
|
106
|
+
id,
|
|
107
|
+
accessStyle,
|
|
108
|
+
quoteId:
|
|
109
|
+
partProps.quoteId ? partProps.quoteId
|
|
110
|
+
: partProps.id !== undefined ?
|
|
111
|
+
isNumericIdentifier(partProps.id) ? false
|
|
112
|
+
: !isValidJSIdentifier(partProps.id)
|
|
113
|
+
: sym ? !isValidJSIdentifier(sym.name)
|
|
114
|
+
: false,
|
|
115
|
+
nullish:
|
|
116
|
+
partProps.nullish ? partProps.nullish
|
|
117
|
+
: sym ? isNullish(sym)
|
|
118
|
+
: false,
|
|
119
|
+
args: partProps.args === true ? [] : partProps.args,
|
|
120
|
+
jsPrivate: !!sym && (sym as TSOutputSymbol).isPrivateMemberSymbol,
|
|
121
|
+
type: !!sym && (sym as TSOutputSymbol).isTypeSymbol,
|
|
122
|
+
await: partProps.await,
|
|
123
|
+
} as PartDescriptor;
|
|
124
|
+
},
|
|
125
|
+
|
|
126
|
+
getBase(part) {
|
|
127
|
+
return isIdPartDescriptor(part) ? part.id : part.index;
|
|
128
|
+
},
|
|
129
|
+
|
|
130
|
+
formatPart(part, prevPart, _inCallChain) {
|
|
131
|
+
if (prevPart.type) {
|
|
132
|
+
return formatArrayAccess(prevPart, part);
|
|
133
|
+
} else if (part.args !== undefined) {
|
|
134
|
+
return formatCallExpr(prevPart, part);
|
|
135
|
+
} else if (part.accessStyle === "dot") {
|
|
136
|
+
return formatDotAccess(prevPart, part);
|
|
137
|
+
} else {
|
|
138
|
+
return formatArrayAccess(prevPart, part);
|
|
139
|
+
}
|
|
140
|
+
},
|
|
141
|
+
|
|
142
|
+
isCallPart(part) {
|
|
143
|
+
return part.args !== undefined;
|
|
144
|
+
},
|
|
145
|
+
|
|
146
|
+
canUseCallChains(parts) {
|
|
147
|
+
for (const part of parts) {
|
|
148
|
+
if (part.await) return false;
|
|
149
|
+
}
|
|
150
|
+
return true;
|
|
151
|
+
},
|
|
152
|
+
|
|
153
|
+
wrapPartResult(expression, part, _index, isLast) {
|
|
154
|
+
if (part.await) {
|
|
155
|
+
return isLast ? <>await {expression}</> : <>(await {expression})</>;
|
|
156
|
+
}
|
|
157
|
+
return expression;
|
|
158
|
+
},
|
|
159
|
+
});
|
|
160
|
+
|
|
46
161
|
/**
|
|
47
162
|
* Create a member expression from parts. Each part can provide one of
|
|
48
163
|
* the following:
|
|
@@ -82,371 +197,80 @@ type PartDescriptor = PartDescriptorWithId | PartDescriptorWithIndex;
|
|
|
82
197
|
* ```
|
|
83
198
|
*/
|
|
84
199
|
export function MemberExpression(props: MemberExpressionProps): Children {
|
|
85
|
-
|
|
86
|
-
const parts = childrenToPartDescriptors(children);
|
|
87
|
-
// any symbols emitted from the children won't be relevant to
|
|
88
|
-
// parent scopes. TODO: emit the proper symbol if we know it?
|
|
89
|
-
takeSymbols();
|
|
90
|
-
|
|
91
|
-
if (parts.length === 0) {
|
|
92
|
-
return <></>;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
const isCallChain = computed(() => {
|
|
96
|
-
for (const part of parts) {
|
|
97
|
-
if (part.await) return false;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
let callCount = 0;
|
|
101
|
-
for (const part of parts) {
|
|
102
|
-
if (part.args !== undefined) callCount++;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
return callCount > 1;
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
// construct a member expression from the parts. When a part is nullish,
|
|
109
|
-
// and there is a subsequent part, we use `?.` instead of `.`. accessStyle determines
|
|
110
|
-
// whether we use dot or bracket notation.
|
|
111
|
-
|
|
112
|
-
return computed(() => {
|
|
113
|
-
return isCallChain.value ?
|
|
114
|
-
formatCallChain(parts)
|
|
115
|
-
: formatNonCallChain(parts);
|
|
116
|
-
});
|
|
200
|
+
return Expression(props);
|
|
117
201
|
}
|
|
118
202
|
|
|
119
203
|
/**
|
|
120
|
-
*
|
|
121
|
-
|
|
122
|
-
function childrenToPartDescriptors(children: Children[]): PartDescriptor[] {
|
|
123
|
-
const parts: PartDescriptor[] = [];
|
|
124
|
-
for (const child of children) {
|
|
125
|
-
if (!isComponentCreator(child, MemberExpression.Part)) {
|
|
126
|
-
// we ignore non-parts
|
|
127
|
-
continue;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
parts.push(
|
|
131
|
-
createPartDescriptorFromProps(child.props, child === children[0]),
|
|
132
|
-
);
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
return parts;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
const exclusiveParts: (keyof MemberExpressionPartProps)[] = [
|
|
139
|
-
"children",
|
|
140
|
-
"args",
|
|
141
|
-
"refkey",
|
|
142
|
-
"symbol",
|
|
143
|
-
"id",
|
|
144
|
-
];
|
|
145
|
-
/**
|
|
146
|
-
* Creates a reactive part descriptor from the given part props.
|
|
204
|
+
* A part of a member expression. Each part can provide one of the following
|
|
205
|
+
* props:
|
|
147
206
|
*
|
|
148
|
-
*
|
|
149
|
-
*
|
|
150
|
-
*
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
first: boolean,
|
|
155
|
-
) {
|
|
156
|
-
const foundProps = exclusiveParts.filter((key) => {
|
|
157
|
-
return key in partProps;
|
|
158
|
-
});
|
|
159
|
-
|
|
160
|
-
if (foundProps.length > 1) {
|
|
161
|
-
throw new Error(
|
|
162
|
-
`Only one of ${foundProps.join(", ")} can be used for a MemberExpression part at a time`,
|
|
163
|
-
);
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
const symbolSource = computed(() => {
|
|
167
|
-
if (partProps.refkey) {
|
|
168
|
-
return getSymbolForRefkey(partProps.refkey).value;
|
|
169
|
-
} else if (partProps.symbol) {
|
|
170
|
-
return partProps.symbol;
|
|
171
|
-
} else {
|
|
172
|
-
return undefined;
|
|
173
|
-
}
|
|
174
|
-
});
|
|
175
|
-
|
|
176
|
-
const part: ToRefs<PartDescriptor> = {
|
|
177
|
-
id: computed(() => {
|
|
178
|
-
if (partProps.args) {
|
|
179
|
-
return undefined;
|
|
180
|
-
} else if (partProps.children !== undefined) {
|
|
181
|
-
return partProps.children;
|
|
182
|
-
} else if (first && partProps.refkey) {
|
|
183
|
-
return partProps.refkey;
|
|
184
|
-
} else if (partProps.id !== undefined) {
|
|
185
|
-
return isNumericIdentifier(partProps.id) ?
|
|
186
|
-
partProps.id
|
|
187
|
-
: escapeId(partProps.id);
|
|
188
|
-
} else if (partProps.index !== undefined) {
|
|
189
|
-
return partProps.index;
|
|
190
|
-
} else if (symbolSource.value) {
|
|
191
|
-
return escapeId(symbolSource.value.name);
|
|
192
|
-
} else {
|
|
193
|
-
return "<unresolved symbol>";
|
|
194
|
-
}
|
|
195
|
-
}),
|
|
196
|
-
accessStyle: computed(() => {
|
|
197
|
-
if (partProps.children !== undefined) {
|
|
198
|
-
if (typeof partProps.children === "string") {
|
|
199
|
-
return partProps.quoteId ? "bracket" : (
|
|
200
|
-
accessStyleForMemberName(partProps.children)
|
|
201
|
-
);
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
return "bracket";
|
|
205
|
-
} else if (partProps.args) {
|
|
206
|
-
// not used
|
|
207
|
-
return "dot";
|
|
208
|
-
} else if (partProps.quoteId) {
|
|
209
|
-
return "bracket";
|
|
210
|
-
} else if (partProps.id !== undefined) {
|
|
211
|
-
return isNumericIdentifier(partProps.id) ? "bracket" : (
|
|
212
|
-
accessStyleForMemberName(partProps.id)
|
|
213
|
-
);
|
|
214
|
-
} else if (partProps.index !== undefined) {
|
|
215
|
-
return "bracket";
|
|
216
|
-
} else if (symbolSource.value) {
|
|
217
|
-
return accessStyleForMemberName(symbolSource.value.name);
|
|
218
|
-
} else {
|
|
219
|
-
return "dot";
|
|
220
|
-
}
|
|
221
|
-
}),
|
|
222
|
-
quoteId: computed(() => {
|
|
223
|
-
if (partProps.quoteId) {
|
|
224
|
-
return partProps.quoteId;
|
|
225
|
-
} else if (partProps.id !== undefined) {
|
|
226
|
-
return isNumericIdentifier(partProps.id) ? false : (
|
|
227
|
-
!isValidJSIdentifier(partProps.id)
|
|
228
|
-
);
|
|
229
|
-
} else if (symbolSource.value) {
|
|
230
|
-
return !isValidJSIdentifier(symbolSource.value.name);
|
|
231
|
-
} else {
|
|
232
|
-
return false;
|
|
233
|
-
}
|
|
234
|
-
}),
|
|
235
|
-
nullish: computed(() => {
|
|
236
|
-
if (partProps.nullish) {
|
|
237
|
-
return partProps.nullish;
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
if (symbolSource.value) {
|
|
241
|
-
return isNullish(symbolSource.value);
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
return false;
|
|
245
|
-
}),
|
|
246
|
-
args: ref<any>(partProps.args === true ? [] : partProps.args),
|
|
247
|
-
jsPrivate: computed(() => {
|
|
248
|
-
return (
|
|
249
|
-
!!symbolSource.value &&
|
|
250
|
-
(symbolSource.value as TSOutputSymbol).isPrivateMemberSymbol
|
|
251
|
-
);
|
|
252
|
-
}),
|
|
253
|
-
type: computed(() => {
|
|
254
|
-
return (
|
|
255
|
-
!!symbolSource.value &&
|
|
256
|
-
(symbolSource.value as TSOutputSymbol).isTypeSymbol
|
|
257
|
-
);
|
|
258
|
-
}),
|
|
259
|
-
await: computed(() => partProps.await),
|
|
260
|
-
};
|
|
261
|
-
|
|
262
|
-
return reactive(part);
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
/**
|
|
266
|
-
* replaces quotes with escaped quotes
|
|
267
|
-
*/
|
|
268
|
-
function escapeId(id: string) {
|
|
269
|
-
return id.replace(/"/g, '\\"');
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
/**
|
|
273
|
-
* Convert a refkey to a symbol ref using the current binder.
|
|
274
|
-
*/
|
|
275
|
-
function getSymbolForRefkey(refkey: Refkey) {
|
|
276
|
-
const binder = useBinder();
|
|
277
|
-
return binder!.getSymbolForRefkey(refkey);
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
/**
|
|
281
|
-
* Check if the given symbol is nullish.
|
|
282
|
-
*/
|
|
283
|
-
function isNullish(symbol: OutputSymbol): boolean {
|
|
284
|
-
return !!((symbol as TSOutputSymbol).tsFlags & TSSymbolFlags.Nullish);
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
/**
|
|
288
|
-
* Formatting of call chains (i.e. member expressions which have more than one
|
|
289
|
-
* call in them). The general approach is that line breaks occur after each
|
|
290
|
-
* call, and there is only one call per line. When there are non-call elements,
|
|
291
|
-
* they occur prior to the call part. The first part of the member expression
|
|
292
|
-
* contains all but the last non-call part.
|
|
207
|
+
* * **id**: The identifier for the member expression part
|
|
208
|
+
* * **refkey**: A refkey for a symbol whose name becomes the identifier
|
|
209
|
+
* * **symbol**: a symbol whose name becomes the identifier part
|
|
210
|
+
* * **args**: create a method call with the given args
|
|
211
|
+
* * **children**: arbitrary contents for the identifier part
|
|
212
|
+
* * **await**: whether to await the value that results from this part of the member expression
|
|
293
213
|
*
|
|
294
|
-
*
|
|
214
|
+
* Each part can have a nullish prop, which indicates that the part may be null
|
|
215
|
+
* or undefined.
|
|
295
216
|
*
|
|
296
|
-
*
|
|
297
|
-
*
|
|
298
|
-
*
|
|
299
|
-
*
|
|
300
|
-
* })
|
|
301
|
-
* .dummy.partial() // the next call part with non-call parts before it
|
|
302
|
-
* ```
|
|
217
|
+
* Each part can also have a quoteId prop, which indicates that the identifier
|
|
218
|
+
* of the part should be quoted (i.e. `["foo"]` instead of `.foo`). This is only
|
|
219
|
+
* necessary when providing the children prop, otherwise it is determined
|
|
220
|
+
* automatically.
|
|
303
221
|
*/
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
const expression: Children[] = [];
|
|
307
|
-
|
|
308
|
-
// break the expression into parts.
|
|
309
|
-
const chunks: PartDescriptor[][] = [];
|
|
222
|
+
MemberExpression.Part = Part;
|
|
223
|
+
registerOuterComponent(MemberExpression);
|
|
310
224
|
|
|
311
|
-
|
|
312
|
-
|
|
225
|
+
export interface MemberExpressionPartProps {
|
|
226
|
+
/**
|
|
227
|
+
* The identifier for this part of the member expression.
|
|
228
|
+
*/
|
|
229
|
+
id?: string | number;
|
|
313
230
|
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
}
|
|
231
|
+
/**
|
|
232
|
+
* The index for this part of the member expression. This is used when
|
|
233
|
+
* the part is an array access (i.e. `foo[0]`).
|
|
234
|
+
*/
|
|
235
|
+
index?: number;
|
|
320
236
|
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
237
|
+
/**
|
|
238
|
+
* Whether the identifier should be quoted or not. Only needed when
|
|
239
|
+
* providing the `children` prop, otherwise it is determined automatically.
|
|
240
|
+
*/
|
|
241
|
+
quoteId?: boolean;
|
|
324
242
|
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
// if we happen to take one
|
|
338
|
-
break;
|
|
339
|
-
}
|
|
340
|
-
}
|
|
243
|
+
/**
|
|
244
|
+
* A refkey for a symbol whose name becomes the identifier.
|
|
245
|
+
*/
|
|
246
|
+
refkey?: Refkey;
|
|
247
|
+
/**
|
|
248
|
+
* A symbol whose name becomes the identifier.
|
|
249
|
+
*/
|
|
250
|
+
symbol?: OutputSymbol;
|
|
251
|
+
/**
|
|
252
|
+
* Arguments to construct a call expression.
|
|
253
|
+
*/
|
|
254
|
+
args?: Children[] | boolean;
|
|
341
255
|
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
while (partIndex < parts.length && !parts[partIndex].args) {
|
|
347
|
-
pushPart();
|
|
348
|
-
}
|
|
349
|
-
while (partIndex < parts.length && parts[partIndex].args) {
|
|
350
|
-
pushPart();
|
|
351
|
-
}
|
|
352
|
-
}
|
|
256
|
+
/**
|
|
257
|
+
* Whether to await the value that results from this part of the member expression.
|
|
258
|
+
*/
|
|
259
|
+
await?: boolean;
|
|
353
260
|
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
if (chunkIndex === 0 && partIndex === 0) {
|
|
359
|
-
// first part is just gonna be the id
|
|
360
|
-
const firstPart =
|
|
361
|
-
isIdPartDescriptor(chunk[0]) ? chunk[0].id : chunk[0].index;
|
|
362
|
-
chunkExpression.push(firstPart);
|
|
363
|
-
continue;
|
|
364
|
-
}
|
|
365
|
-
const part = chunk[partIndex];
|
|
366
|
-
const prevPart =
|
|
367
|
-
partIndex === 0 ?
|
|
368
|
-
chunks[chunkIndex - 1].at(-1)!
|
|
369
|
-
: chunk[partIndex - 1];
|
|
370
|
-
|
|
371
|
-
if (part.args !== undefined) {
|
|
372
|
-
// For parts with only args (no name), append function call directly with appropriate nullish operator
|
|
373
|
-
chunkExpression.push(formatCallExpr(prevPart, part));
|
|
374
|
-
} else if (part.accessStyle === "dot") {
|
|
375
|
-
chunkExpression.push(formatDotAccess(prevPart, part));
|
|
376
|
-
} else {
|
|
377
|
-
// bracket notation - don't include the dot
|
|
378
|
-
chunkExpression.push(formatArrayAccess(prevPart, part));
|
|
379
|
-
}
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
expression.push(
|
|
383
|
-
chunkIndex === 0 ? chunkExpression : (
|
|
384
|
-
<>
|
|
385
|
-
<sbr />
|
|
386
|
-
{chunkExpression}
|
|
387
|
-
</>
|
|
388
|
-
),
|
|
389
|
-
);
|
|
390
|
-
}
|
|
261
|
+
/**
|
|
262
|
+
* This part is nullish. Subsequent parts use conditional access operators.
|
|
263
|
+
*/
|
|
264
|
+
nullish?: boolean;
|
|
391
265
|
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
});
|
|
266
|
+
/**
|
|
267
|
+
* The contents of this part. When passed, overrides the other props except
|
|
268
|
+
* nullish.
|
|
269
|
+
*/
|
|
270
|
+
children?: Children;
|
|
398
271
|
}
|
|
399
272
|
|
|
400
|
-
|
|
401
|
-
return computed(() => {
|
|
402
|
-
let expression: Children = [];
|
|
403
|
-
|
|
404
|
-
for (let i = 0; i < parts.length; i++) {
|
|
405
|
-
const part = parts[i];
|
|
406
|
-
const base = isIdPartDescriptor(part) ? part.id : part.index;
|
|
407
|
-
if (i === 0) {
|
|
408
|
-
(expression as Children[]).push(base);
|
|
409
|
-
} else {
|
|
410
|
-
// Determine if we should use nullish operator from previous part
|
|
411
|
-
const prevPart = parts[i - 1];
|
|
412
|
-
let partExpr;
|
|
413
|
-
|
|
414
|
-
if (prevPart.type) {
|
|
415
|
-
partExpr = formatArrayAccess(prevPart, part);
|
|
416
|
-
} else if (part.args !== undefined) {
|
|
417
|
-
// For parts with only args (no name), append function call directly with appropriate nullish operator
|
|
418
|
-
partExpr = formatCallExpr(prevPart, part);
|
|
419
|
-
} else if (part.accessStyle === "dot") {
|
|
420
|
-
partExpr = formatDotAccess(prevPart, part);
|
|
421
|
-
} else {
|
|
422
|
-
// bracket notation - don't include the dot
|
|
423
|
-
partExpr = formatArrayAccess(prevPart, part);
|
|
424
|
-
}
|
|
425
|
-
|
|
426
|
-
if (Array.isArray(expression)) {
|
|
427
|
-
expression.push(partExpr);
|
|
428
|
-
} else {
|
|
429
|
-
expression = (
|
|
430
|
-
<>
|
|
431
|
-
{expression}
|
|
432
|
-
{partExpr}
|
|
433
|
-
</>
|
|
434
|
-
);
|
|
435
|
-
}
|
|
436
|
-
}
|
|
437
|
-
|
|
438
|
-
if (part.await) {
|
|
439
|
-
if (i < parts.length - 1) {
|
|
440
|
-
expression = <>(await {expression})</>;
|
|
441
|
-
} else {
|
|
442
|
-
expression = <>await {expression}</>;
|
|
443
|
-
}
|
|
444
|
-
}
|
|
445
|
-
}
|
|
446
|
-
|
|
447
|
-
return expression;
|
|
448
|
-
});
|
|
449
|
-
}
|
|
273
|
+
// --- Formatting helpers ---
|
|
450
274
|
|
|
451
275
|
function formatArrayAccess(prevPart: PartDescriptor, part: PartDescriptor) {
|
|
452
276
|
return (
|
|
@@ -502,104 +326,20 @@ function formatCallExpr(prevPart: PartDescriptor, part: PartDescriptor) {
|
|
|
502
326
|
);
|
|
503
327
|
}
|
|
504
328
|
|
|
505
|
-
|
|
506
|
-
if (isValidJSIdentifier(name)) {
|
|
507
|
-
return "dot";
|
|
508
|
-
}
|
|
509
|
-
return "bracket";
|
|
510
|
-
}
|
|
329
|
+
// --- Utilities ---
|
|
511
330
|
|
|
512
|
-
function
|
|
513
|
-
|
|
514
|
-
for (const child of children) {
|
|
515
|
-
if (isComponentCreator(child, MemberExpression)) {
|
|
516
|
-
flattened.push(
|
|
517
|
-
...flattenMemberExpression(childrenArray(() => child.props.children)),
|
|
518
|
-
);
|
|
519
|
-
} else {
|
|
520
|
-
flattened.push(child);
|
|
521
|
-
}
|
|
522
|
-
}
|
|
523
|
-
return flattened;
|
|
331
|
+
function escapeId(id: string) {
|
|
332
|
+
return id.replace(/"/g, '\\"');
|
|
524
333
|
}
|
|
525
334
|
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
*/
|
|
530
|
-
id?: string | number;
|
|
531
|
-
|
|
532
|
-
/**
|
|
533
|
-
* The index for this part of the member expression. This is used when
|
|
534
|
-
* the part is an array access (i.e. `foo[0]`).
|
|
535
|
-
*/
|
|
536
|
-
index?: number;
|
|
537
|
-
|
|
538
|
-
/**
|
|
539
|
-
* Whether the identifier should be quoted or not. Only needed when
|
|
540
|
-
* providing the `children` prop, otherwise it is determined automatically.
|
|
541
|
-
*/
|
|
542
|
-
quoteId?: boolean;
|
|
543
|
-
|
|
544
|
-
/**
|
|
545
|
-
* A refkey for a symbol whose name becomes the identifier.
|
|
546
|
-
*/
|
|
547
|
-
refkey?: Refkey;
|
|
548
|
-
/**
|
|
549
|
-
* A symbol whose name becomes the identifier.
|
|
550
|
-
*/
|
|
551
|
-
symbol?: OutputSymbol;
|
|
552
|
-
/**
|
|
553
|
-
* Arguments to construct a call expression.
|
|
554
|
-
*/
|
|
555
|
-
args?: Children[] | boolean;
|
|
556
|
-
|
|
557
|
-
/**
|
|
558
|
-
* Whether to await the value that results from this part of the member expression.
|
|
559
|
-
*/
|
|
560
|
-
await?: boolean;
|
|
561
|
-
|
|
562
|
-
/**
|
|
563
|
-
* This part is nullish. Subsequent parts use conditional access operators.
|
|
564
|
-
*/
|
|
565
|
-
nullish?: boolean;
|
|
335
|
+
function isNullish(symbol: OutputSymbol): boolean {
|
|
336
|
+
return !!((symbol as TSOutputSymbol).tsFlags & TSSymbolFlags.Nullish);
|
|
337
|
+
}
|
|
566
338
|
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
* nullish.
|
|
570
|
-
*/
|
|
571
|
-
children?: Children;
|
|
339
|
+
function accessStyleForMemberName(name: string) {
|
|
340
|
+
return isValidJSIdentifier(name) ? "dot" : "bracket";
|
|
572
341
|
}
|
|
573
|
-
/**
|
|
574
|
-
* A part of a member expression. Each part can provide one of the following
|
|
575
|
-
* props:
|
|
576
|
-
*
|
|
577
|
-
* * **id**: The identifier for the member expression part
|
|
578
|
-
* * **refkey**: A refkey for a symbol whose name becomes the identifier
|
|
579
|
-
* * **symbol**: a symbol whose name becomes the identifier part
|
|
580
|
-
* * **args**: create a method call with the given args
|
|
581
|
-
* * **children**: arbitrary contents for the identifier part
|
|
582
|
-
* * **await**: whether to await the value that results from this part of the member expression
|
|
583
|
-
*
|
|
584
|
-
* Each part can have a nullish prop, which indicates that the part may be null
|
|
585
|
-
* or undefined.
|
|
586
|
-
*
|
|
587
|
-
* Each part can also have a quoteId prop, which indicates that the identifier
|
|
588
|
-
* of the part should be quoted (i.e. `["foo"]` instead of `.foo`). This is only
|
|
589
|
-
* necessary when providing the children prop, otherwise it is determined
|
|
590
|
-
* automatically.
|
|
591
|
-
*/
|
|
592
|
-
MemberExpression.Part = function (props: MemberExpressionPartProps) {
|
|
593
|
-
/**
|
|
594
|
-
* This component does nothing except hold props which are retrieved by
|
|
595
|
-
* the `MemberExpression` component.
|
|
596
|
-
*/
|
|
597
|
-
};
|
|
598
342
|
|
|
599
|
-
/**
|
|
600
|
-
* Check if the given id is a numeric identifier.
|
|
601
|
-
*
|
|
602
|
-
*/
|
|
603
343
|
function isNumericIdentifier(id: Children) {
|
|
604
344
|
return typeof id === "number";
|
|
605
345
|
}
|