fcis 0.1.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.
Files changed (151) hide show
  1. package/.plans/001-fcis-analyzer.md +832 -0
  2. package/.plans/002-fcis-analyzer-improvements.md +205 -0
  3. package/README.md +272 -0
  4. package/TECHNICAL.md +386 -0
  5. package/dist/cli.d.ts +1 -0
  6. package/dist/cli.js +1836 -0
  7. package/dist/cli.js.map +1 -0
  8. package/dist/index.d.ts +709 -0
  9. package/dist/index.js +1845 -0
  10. package/dist/index.js.map +1 -0
  11. package/package.json +47 -0
  12. package/pnpm-workspace.yaml +0 -0
  13. package/src/analyzer.ts +266 -0
  14. package/src/classification/classifier.ts +156 -0
  15. package/src/classification/derive-status.ts +171 -0
  16. package/src/classification/quality-scorer.ts +481 -0
  17. package/src/cli.ts +286 -0
  18. package/src/detection/detect-markers.ts +480 -0
  19. package/src/detection/markers.ts +332 -0
  20. package/src/extraction/extract-functions.ts +570 -0
  21. package/src/extraction/extractor.ts +188 -0
  22. package/src/index.ts +111 -0
  23. package/src/reporting/report-console.ts +416 -0
  24. package/src/reporting/report-json.ts +232 -0
  25. package/src/scoring/scorer.ts +504 -0
  26. package/src/types.ts +248 -0
  27. package/tests/classifier.test.ts +480 -0
  28. package/tests/derive-status.test.ts +464 -0
  29. package/tests/detect-markers.test.ts +639 -0
  30. package/tests/extractor.test.ts +155 -0
  31. package/tests/integration.test.ts +706 -0
  32. package/tests/quality-scorer.test.ts +650 -0
  33. package/tests/scorer.test.ts +768 -0
  34. package/tsconfig.json +34 -0
  35. package/tsup.config.ts +17 -0
  36. package/vendor/ts-morph/.editorconfig +10 -0
  37. package/vendor/ts-morph/.gitattributes +11 -0
  38. package/vendor/ts-morph/.github/CODE_OF_CONDUCT.md +77 -0
  39. package/vendor/ts-morph/.github/ISSUE_TEMPLATE/bug_report.md +29 -0
  40. package/vendor/ts-morph/.github/ISSUE_TEMPLATE/custom.md +4 -0
  41. package/vendor/ts-morph/.github/ISSUE_TEMPLATE/feature_request.md +18 -0
  42. package/vendor/ts-morph/.github/workflows/ci.yml +50 -0
  43. package/vendor/ts-morph/.github/workflows/publish.yml +53 -0
  44. package/vendor/ts-morph/.vscode/settings.json +10 -0
  45. package/vendor/ts-morph/CONTRIBUTING.md +23 -0
  46. package/vendor/ts-morph/DEVELOPMENT.md +32 -0
  47. package/vendor/ts-morph/LICENSE +21 -0
  48. package/vendor/ts-morph/deno.json +8 -0
  49. package/vendor/ts-morph/deno.lock +1233 -0
  50. package/vendor/ts-morph/docs/CNAME +1 -0
  51. package/vendor/ts-morph/docs/Gemfile +2 -0
  52. package/vendor/ts-morph/docs/_config.yml +5 -0
  53. package/vendor/ts-morph/docs/_layouts/default.html +159 -0
  54. package/vendor/ts-morph/docs/_script-templates/main.ts +116 -0
  55. package/vendor/ts-morph/docs/assets/css/style.scss +212 -0
  56. package/vendor/ts-morph/docs/details/ambient.md +38 -0
  57. package/vendor/ts-morph/docs/details/async.md +31 -0
  58. package/vendor/ts-morph/docs/details/classes.md +314 -0
  59. package/vendor/ts-morph/docs/details/comment-ranges.md +7 -0
  60. package/vendor/ts-morph/docs/details/comments.md +122 -0
  61. package/vendor/ts-morph/docs/details/decorators.md +119 -0
  62. package/vendor/ts-morph/docs/details/documentation.md +73 -0
  63. package/vendor/ts-morph/docs/details/enums.md +117 -0
  64. package/vendor/ts-morph/docs/details/exports.md +308 -0
  65. package/vendor/ts-morph/docs/details/expressions.md +46 -0
  66. package/vendor/ts-morph/docs/details/functions.md +150 -0
  67. package/vendor/ts-morph/docs/details/generators.md +27 -0
  68. package/vendor/ts-morph/docs/details/identifiers.md +79 -0
  69. package/vendor/ts-morph/docs/details/imports.md +191 -0
  70. package/vendor/ts-morph/docs/details/index.md +52 -0
  71. package/vendor/ts-morph/docs/details/initializers.md +40 -0
  72. package/vendor/ts-morph/docs/details/interfaces.md +218 -0
  73. package/vendor/ts-morph/docs/details/literals.md +20 -0
  74. package/vendor/ts-morph/docs/details/modifiers.md +38 -0
  75. package/vendor/ts-morph/docs/details/modules.md +113 -0
  76. package/vendor/ts-morph/docs/details/namespaces.md +7 -0
  77. package/vendor/ts-morph/docs/details/object-literal-expressions.md +106 -0
  78. package/vendor/ts-morph/docs/details/parameters.md +64 -0
  79. package/vendor/ts-morph/docs/details/signatures.md +41 -0
  80. package/vendor/ts-morph/docs/details/source-files.md +292 -0
  81. package/vendor/ts-morph/docs/details/type-aliases.md +34 -0
  82. package/vendor/ts-morph/docs/details/type-parameters.md +72 -0
  83. package/vendor/ts-morph/docs/details/types.md +254 -0
  84. package/vendor/ts-morph/docs/details/variables.md +110 -0
  85. package/vendor/ts-morph/docs/emitting.md +151 -0
  86. package/vendor/ts-morph/docs/index.md +25 -0
  87. package/vendor/ts-morph/docs/manipulation/code-writer.md +20 -0
  88. package/vendor/ts-morph/docs/manipulation/formatting.md +76 -0
  89. package/vendor/ts-morph/docs/manipulation/index.md +136 -0
  90. package/vendor/ts-morph/docs/manipulation/order.md +14 -0
  91. package/vendor/ts-morph/docs/manipulation/performance.md +222 -0
  92. package/vendor/ts-morph/docs/manipulation/removing.md +31 -0
  93. package/vendor/ts-morph/docs/manipulation/renaming.md +106 -0
  94. package/vendor/ts-morph/docs/manipulation/settings.md +76 -0
  95. package/vendor/ts-morph/docs/manipulation/structures.md +117 -0
  96. package/vendor/ts-morph/docs/manipulation/transforms.md +84 -0
  97. package/vendor/ts-morph/docs/metrics/performance.json +4 -0
  98. package/vendor/ts-morph/docs/navigation/ambient-modules.md +22 -0
  99. package/vendor/ts-morph/docs/navigation/compiler-nodes.md +82 -0
  100. package/vendor/ts-morph/docs/navigation/directories.md +287 -0
  101. package/vendor/ts-morph/docs/navigation/example.md +50 -0
  102. package/vendor/ts-morph/docs/navigation/finding-references.md +53 -0
  103. package/vendor/ts-morph/docs/navigation/getting-source-files.md +59 -0
  104. package/vendor/ts-morph/docs/navigation/images/getChildrenVsForEachChild.gif +0 -0
  105. package/vendor/ts-morph/docs/navigation/index.md +94 -0
  106. package/vendor/ts-morph/docs/navigation/language-service.md +23 -0
  107. package/vendor/ts-morph/docs/navigation/program.md +25 -0
  108. package/vendor/ts-morph/docs/navigation/type-checker.md +33 -0
  109. package/vendor/ts-morph/docs/setup/adding-source-files.md +145 -0
  110. package/vendor/ts-morph/docs/setup/ast-viewers.md +46 -0
  111. package/vendor/ts-morph/docs/setup/diagnostics.md +109 -0
  112. package/vendor/ts-morph/docs/setup/file-system.md +106 -0
  113. package/vendor/ts-morph/docs/setup/images/atom-ast.png +0 -0
  114. package/vendor/ts-morph/docs/setup/images/atom-ast_small.png +0 -0
  115. package/vendor/ts-morph/docs/setup/images/atom-command-palette.png +0 -0
  116. package/vendor/ts-morph/docs/setup/images/atom-file.png +0 -0
  117. package/vendor/ts-morph/docs/setup/images/ts-ast-viewer.png +0 -0
  118. package/vendor/ts-morph/docs/setup/index.md +94 -0
  119. package/vendor/ts-morph/docs/utilities.md +55 -0
  120. package/vendor/ts-morph/dprint.json +23 -0
  121. package/vendor/ts-morph/package.json +30 -0
  122. package/vendor/ts-morph/packages/bootstrap/LICENSE +21 -0
  123. package/vendor/ts-morph/packages/bootstrap/lib/ts-morph-bootstrap.d.ts +397 -0
  124. package/vendor/ts-morph/packages/bootstrap/package.json +46 -0
  125. package/vendor/ts-morph/packages/bootstrap/readme.md +200 -0
  126. package/vendor/ts-morph/packages/common/LICENSE +21 -0
  127. package/vendor/ts-morph/packages/common/lib/ts-morph-common.d.ts +1082 -0
  128. package/vendor/ts-morph/packages/common/lib/typescript.d.ts +11439 -0
  129. package/vendor/ts-morph/packages/common/package.json +65 -0
  130. package/vendor/ts-morph/packages/common/readme.md +5 -0
  131. package/vendor/ts-morph/packages/scripts/changeTypeScriptVersion.ts +28 -0
  132. package/vendor/ts-morph/packages/scripts/createDeclarationProject.ts +47 -0
  133. package/vendor/ts-morph/packages/scripts/deps.ts +2 -0
  134. package/vendor/ts-morph/packages/scripts/execScript.ts +31 -0
  135. package/vendor/ts-morph/packages/scripts/folders.ts +11 -0
  136. package/vendor/ts-morph/packages/scripts/getDevCompilerVersions.ts +19 -0
  137. package/vendor/ts-morph/packages/scripts/mod.ts +7 -0
  138. package/vendor/ts-morph/packages/scripts/utils/Memoize.ts +36 -0
  139. package/vendor/ts-morph/packages/scripts/utils/forEachTypeText.ts +23 -0
  140. package/vendor/ts-morph/packages/scripts/utils/makeConstructorsPrivate.ts +26 -0
  141. package/vendor/ts-morph/packages/scripts/utils/mod.ts +4 -0
  142. package/vendor/ts-morph/packages/scripts/utils/printDiagnostics.ts +10 -0
  143. package/vendor/ts-morph/packages/ts-morph/LICENSE +21 -0
  144. package/vendor/ts-morph/packages/ts-morph/lib/ts-morph.d.ts +11198 -0
  145. package/vendor/ts-morph/packages/ts-morph/package.json +78 -0
  146. package/vendor/ts-morph/packages/ts-morph/readme.md +111 -0
  147. package/vendor/ts-morph/readme.md +14 -0
  148. package/vendor/ts-morph/rfcs/README.md +13 -0
  149. package/vendor/ts-morph/rfcs/RFC-0001 - Inserting Into Statements Handling Comments.md +181 -0
  150. package/vendor/ts-morph/tsconfig.common.json +17 -0
  151. package/vitest.config.ts +16 -0
@@ -0,0 +1,191 @@
1
+ ---
2
+ title: Imports
3
+ ---
4
+
5
+ ## Imports
6
+
7
+ Imports of a source file or module can be retrieved by calling:
8
+
9
+ ```ts
10
+ // get them all
11
+ const imports = sourceFile.getImportDeclarations();
12
+ // or get the first one that matches a condition
13
+ const importWithDefaultImport = sourceFile.getImportDeclaration(i => i.getDefaultImport() != null);
14
+ const someModuleImport = sourceFile.getImportDeclaration("module-specifier-text");
15
+ ```
16
+
17
+ ### Add/Insert
18
+
19
+ Add or insert use `insertImportDeclaration`, `insertImportDeclarations`, `addImportDeclaration`, or `addImportDeclarations`:
20
+
21
+ ```ts
22
+ const importDeclaration = sourceFile.addImportDeclaration({
23
+ defaultImport: "MyClass",
24
+ moduleSpecifier: "./file",
25
+ });
26
+ ```
27
+
28
+ ### Remove
29
+
30
+ Call `.remove()`:
31
+
32
+ ```ts
33
+ importDeclaration.remove();
34
+ ```
35
+
36
+ ### Module specifier
37
+
38
+ Get it:
39
+
40
+ ```ts
41
+ const moduleSpecifier = importDeclaration.getModuleSpecifier(); // returns: StringLiteral
42
+ ```
43
+
44
+ Or get it's value:
45
+
46
+ ```ts
47
+ const moduleSpecifierValue = importDeclaration.getModuleSpecifierValue(); // returns: string
48
+ ```
49
+
50
+ _Example:_ For `import settings from "./settings";` would return `./settings`.
51
+
52
+ Set it:
53
+
54
+ ```ts
55
+ importDeclaration.setModuleSpecifier("./new-file");
56
+ // or set by source file
57
+ importDeclaration.setModuleSpecifier(sourceFile);
58
+ ```
59
+
60
+ Get the referenced source file:
61
+
62
+ ```ts
63
+ const sourceFile = importDeclaration.getModuleSpecifierSourceFile(); // returns: SourceFile | undefined
64
+ ```
65
+
66
+ Get if the module specifier is relative (starts with `./` or `../`):
67
+
68
+ ```ts
69
+ importDeclaration.isModuleSpecifierRelative();
70
+ ```
71
+
72
+ ### Default import
73
+
74
+ Get it:
75
+
76
+ ```ts
77
+ const defaultImport = importDeclaration.getDefaultImport(); // returns: Identifier | undefined
78
+ ```
79
+
80
+ Set it:
81
+
82
+ ```ts
83
+ importDeclaration.setDefaultImport("MyClass");
84
+ importDeclaration.renameDefaultImport("MyClass2");
85
+ importDeclaration.removeDefaultImport();
86
+ ```
87
+
88
+ #### Example
89
+
90
+ Given the file:
91
+
92
+ ```ts
93
+ import MyClass from "./file";
94
+
95
+ const instance = new MyClass();
96
+ ```
97
+
98
+ Doing the following:
99
+
100
+ ```ts
101
+ const importDeclaration = sourceFile.getImportDeclarations()[0];
102
+ importDeclaration.renameDefaultImport("NewName");
103
+ ```
104
+
105
+ Will rename the default import and all its usages:
106
+
107
+ ```ts
108
+ import NewName from "./file";
109
+
110
+ const instance = new NewName();
111
+ ```
112
+
113
+ ### Namespace import
114
+
115
+ Get it:
116
+
117
+ ```ts
118
+ const namespaceImport = importDeclaration.getNamespaceImport(); // returns: Identifier | undefined
119
+ ```
120
+
121
+ Set it:
122
+
123
+ ```ts
124
+ importDeclaration.setNamespaceImport("newName");
125
+ ```
126
+
127
+ _Note:_ Setting the namespace import for an existing namespace import will rename any uses of the namespace import in the current file.
128
+
129
+ Remove it:
130
+
131
+ ```ts
132
+ importDeclaration.removeNamespaceImport();
133
+ ```
134
+
135
+ ### Named imports
136
+
137
+ Getting a named import:
138
+
139
+ ```ts
140
+ const namedImports = importDeclaration.getNamedImports(); // returns: ImportSpecifier
141
+ ```
142
+
143
+ Adding or inserting named imports can be done via the `addNamedImport`, `addNamedImports`, `insertNamedImport`, or `insertNamedImports` methods.
144
+
145
+ ```ts
146
+ const namedImport = importDeclaration.addNamedImport({
147
+ name: "MyClass",
148
+ alias: "MyAliasName", // alias is optional
149
+ });
150
+ // or
151
+ importDeclaration.addNamedImports(["MyClass", "SomeInterface"]);
152
+ ```
153
+
154
+ Removing one named import:
155
+
156
+ ```ts
157
+ namedImport.remove();
158
+ ```
159
+
160
+ Removing all named imports:
161
+
162
+ ```ts
163
+ importDeclaration.removeNamedImports();
164
+ ```
165
+
166
+ #### Import specifier
167
+
168
+ Import specifiers are the individual named imports.
169
+
170
+ ##### Name
171
+
172
+ ```ts
173
+ namedImport.getNameNode(); // returns: Identifier
174
+ namedImport.setName("NewName");
175
+ ```
176
+
177
+ ##### Alias
178
+
179
+ ```ts
180
+ namedImport.getAliasNode(); // returns: Identifier | undefined
181
+ namedImport.setAlias("NewAliasName");
182
+ namedImport.renameAlias("NewAliasName");
183
+ ```
184
+
185
+ _Note:_ Renaming the alias will set or rename any uses of the alias or identifier in the current file to the new value.
186
+
187
+ ##### Parent import declaration
188
+
189
+ ```ts
190
+ namedImport.getImportDeclaration(); // returns: ImportDeclaration
191
+ ```
@@ -0,0 +1,52 @@
1
+ ---
2
+ title: Details
3
+ ---
4
+
5
+ ## Details
6
+
7
+ There is navigation support for most parts of the language at the current moment, but not everything.
8
+
9
+ Manipulation support is lacking.
10
+
11
+ Find out more information about:
12
+
13
+ - [Source Files](source-files)
14
+ - [Classes](classes)
15
+ - [Decorators](decorators)
16
+ - [Enums](enums)
17
+ - [Functions](functions)
18
+ - [Imports](imports)
19
+ - [Interfaces](interfaces)
20
+ - [Modules](modules)
21
+ - [Parameters](parameters)
22
+ - [Type Parameters](type-parameters)
23
+ - [Type Aliases](type-aliases)
24
+ - [Variables](variables)
25
+ - Type parameters - todo
26
+ - Symbols - todo
27
+
28
+ Types:
29
+
30
+ - [Types](types)
31
+ - [Signatures](signatures)
32
+ - Type Nodes - todo
33
+
34
+ Common:
35
+
36
+ - [Expressions](expressions)
37
+ - [Object Literal Expressions](object-literal-expressions)
38
+ - [Identifiers](identifiers)
39
+ - [Ambient](ambient)
40
+ - [Async](async)
41
+ - [Exports](exports)
42
+ - [Generators](generators)
43
+ - [Initializers](initializers)
44
+ - [JS Docs](documentation)
45
+ - [Literals](literals)
46
+ - [Modifiers](modifiers)
47
+ - [Comments](comments)
48
+ - Question tokenable - todo
49
+ - Readonly - todo
50
+ - Return Types - todo
51
+ - Scope - todo
52
+ - Static - todo
@@ -0,0 +1,40 @@
1
+ ---
2
+ title: Initializers
3
+ ---
4
+
5
+ ## Initializers
6
+
7
+ ### Getting
8
+
9
+ For example, given the following code:
10
+
11
+ ```ts
12
+ const add = function(a: number, b: number) {
13
+ return a + b;
14
+ };
15
+ ```
16
+
17
+ The initializer can be retrieved in any of these ways:
18
+
19
+ ```ts
20
+ variableDeclaration.getInitializer(); // returns: Expression | undefined
21
+ variableDeclaration.getInitializerOrThrow(); // returns: Expression
22
+ variableDeclaration.getInitializerIfKind(SyntaxKind.FunctionExpression); // returns: Expression | undefined
23
+ variableDeclaration.getInitializerIfKindOrThrow(SyntaxKind.FunctionExpression); // returns: Expression
24
+ ```
25
+
26
+ ### Removing
27
+
28
+ Use `.removeInitializer()` on the parent node. For example:
29
+
30
+ ```ts
31
+ variableDeclaration.removeInitializer();
32
+ ```
33
+
34
+ ### Setting
35
+
36
+ Use `.setInitializer(...)`:
37
+
38
+ ```ts
39
+ variableDeclaration.setInitializer("2 + 2");
40
+ ```
@@ -0,0 +1,218 @@
1
+ ---
2
+ title: Interfaces
3
+ ---
4
+
5
+ ## Interface Declarations
6
+
7
+ Interface declarations can be retrieved from source files, namespaces, or function bodies:
8
+
9
+ ```ts
10
+ const interfaces = sourceFile.getInterfaces();
11
+ const interface1 = sourceFile.getInterface("Interface1");
12
+ const firstInterfaceWith5Properties = sourceFile.getInterface(i => i.getProperties().length === 5);
13
+ ```
14
+
15
+ ### Add/Insert
16
+
17
+ Add or insert interfaces to a source file, namespace, or function like declarations by calling `addInterface()`, `addInterfaces()`, `insertInterface()`, or `insertInterfaces()`.
18
+
19
+ ```ts
20
+ const interfaceDeclaration = sourceFile.addInterface({
21
+ name: "InterfaceName",
22
+ });
23
+ ```
24
+
25
+ ### Remove
26
+
27
+ Call `.remove()`:
28
+
29
+ ```ts
30
+ interfaceDeclaration.remove();
31
+ ```
32
+
33
+ ### Extends expressions
34
+
35
+ Will return [`ExpressionWithTypeArguments[]`](expressions):
36
+
37
+ ```ts
38
+ const extendsExpressions = interfaceDeclaration.getExtends();
39
+ ```
40
+
41
+ Add or insert extends expressions:
42
+
43
+ ```ts
44
+ interfaceDeclaration.addExtends("Named");
45
+ interfaceDeclaration.addExtends(["Named", "Aged"]);
46
+ interfaceDeclaration.insertExtends(1, "Named");
47
+ interfaceDeclaration.insertExtends(2, ["Named", "Aged"]);
48
+ ```
49
+
50
+ Remove an expression:
51
+
52
+ ```ts
53
+ interfaceDeclaration.removeExtends(0); // index
54
+ interfaceDeclaration.removeExtends(interfaceDeclaration.getExtends()[0]); // node
55
+ ```
56
+
57
+ ### Members
58
+
59
+ Get all the members of the interface:
60
+
61
+ ```ts
62
+ const members = interfaceDeclaration.getMembers();
63
+ ```
64
+
65
+ ### Construct signatures
66
+
67
+ Use:
68
+
69
+ ```ts
70
+ const constructSignatures = interfaceDeclaration.getConstructSignatures();
71
+ const constructSignature = interfaceDeclaration.getConstructSignature(c => c.getParameters().length > 2);
72
+ ```
73
+
74
+ #### Add/Insert
75
+
76
+ To add or insert use `addConstructSignature()`, `addConstructSignatures()`, `insertConstructSignature`, or `insertConstructSignatures()`:
77
+
78
+ ```ts
79
+ const constructSignature = interfaceDeclaration.addConstructSignature({ returnType: "SomeClass" });
80
+ ```
81
+
82
+ #### Remove
83
+
84
+ Remove a construct signature:
85
+
86
+ ```ts
87
+ constructSignature.remove();
88
+ ```
89
+
90
+ ### Call signatures
91
+
92
+ Use:
93
+
94
+ ```ts
95
+ const callSignatures = interfaceDeclaration.getCallSignatures();
96
+ const callSignature = interfaceDeclaration.getCallSignature(c => c.getParameters().length > 2);
97
+ ```
98
+
99
+ #### Add/Insert
100
+
101
+ To add or insert use `addCallSignature()`, `addCallSignatures()`, `insertCallSignature`, or `insertCallSignatures()`:
102
+
103
+ ```ts
104
+ const callSignature = interfaceDeclaration.addCallSignature({ returnType: "SomeClass" });
105
+ ```
106
+
107
+ #### Remove
108
+
109
+ Remove a call signature:
110
+
111
+ ```ts
112
+ callSignature.remove();
113
+ ```
114
+
115
+ ### Index signatures
116
+
117
+ Use:
118
+
119
+ ```ts
120
+ const indexSignatures = interfaceDeclaration.getIndexSignatures();
121
+ const indexSignature = interfaceDeclaration.getIndexSignature(s => s.getKeyName() === "keyName");
122
+ ```
123
+
124
+ #### Add/Insert
125
+
126
+ To add or insert use `addIndexSignature()`, `addIndexSignatures()`, `insertIndexSignature`, or `insertIndexSignatures()`:
127
+
128
+ ```ts
129
+ const indexSignature = interfaceDeclaration.addIndexSignature({
130
+ keyName: "someKey", // defaults to key
131
+ keyType: "string", // defaults to string
132
+ returnType: "SomeClass",
133
+ });
134
+ ```
135
+
136
+ #### Remove
137
+
138
+ Remove an index signature:
139
+
140
+ ```ts
141
+ indexSignature.remove();
142
+ ```
143
+
144
+ ### Method signatures
145
+
146
+ Use:
147
+
148
+ ```ts
149
+ const methodSignatures = interfaceDeclaration.getMethods();
150
+ const myMethod = interfaceDeclaration.getMethod("myMethod");
151
+ const firstMethodWith4Params = interfaceDeclaration.getMethod(m => m.getParameters().length === 4);
152
+ ```
153
+
154
+ #### Add/Insert
155
+
156
+ To add or insert use `addMethod()`, `addMethods()`, `insertMethod`, or `insertMethods()`:
157
+
158
+ ```ts
159
+ const methodSignature = interfaceDeclaration.insertMethod(1, { name: "newMethod", returnType: "boolean" });
160
+ ```
161
+
162
+ #### Remove
163
+
164
+ Remove a method signature:
165
+
166
+ ```ts
167
+ methodSignature.remove();
168
+ ```
169
+
170
+ ### Properties
171
+
172
+ Use:
173
+
174
+ ```ts
175
+ const properties = interfaceDeclaration.getProperties();
176
+ const myProperty = interfaceDeclaration.getProperty("myProperty");
177
+ const firstStringProperty = interfaceDeclaration.getProperty(p => p.getType().getText() === "string");
178
+ ```
179
+
180
+ #### Add/Insert
181
+
182
+ To add or insert use `addProperty()`, `addProperties()`, `insertProperty`, or `insertProperties()`:
183
+
184
+ ```ts
185
+ const propertySignature = interfaceDeclaration.insertProperty(1, { name: "newProperty", type: "string" });
186
+ ```
187
+
188
+ #### Remove
189
+
190
+ Remove a property signature:
191
+
192
+ ```ts
193
+ propertySignature.remove();
194
+ ```
195
+
196
+ ### Base Types
197
+
198
+ ```ts
199
+ const baseTypes = interfaceDeclaration.getBaseTypes();
200
+ ```
201
+
202
+ ### Base Declarations
203
+
204
+ Gets the base interface, type alias, or class declarations:
205
+
206
+ ```ts
207
+ const baseDeclarations = interfaceDeclaration.getBaseDeclarations();
208
+ ```
209
+
210
+ ### Implementations
211
+
212
+ Get the implementations.
213
+
214
+ ```ts
215
+ const implementations = interfaceDeclaration.getImplementations();
216
+ ```
217
+
218
+ Similar to "go to implementation" command available in IDEs.
@@ -0,0 +1,20 @@
1
+ ---
2
+ title: Literals
3
+ ---
4
+
5
+ ## Literals
6
+
7
+ Literals:
8
+
9
+ - `StringLiteral` (ex. `"some string"`)
10
+ - `NumericLiteral` (ex. `5`, `10.53`)
11
+ - `TrueLiteral` / `FalseLiteral` (ex. `true` / `false`)
12
+ - `NoSubstitutionTemplateLiteral` (ex. `` `some string` ``)
13
+ - `RegularExpressionLiteral` (ex. `/pattern/gi`)
14
+
15
+ Methods:
16
+
17
+ - `.getLiteralValue()` - Returns the string, number, boolean, or RegExp value.
18
+ - `.setLiteralValue(...)` - Allows setting the literal value.
19
+ - `isTerminated()` - If the literal is terminated.
20
+ - `hasExtendedUnicodeEscape()` - If the literal has a unicode escape (ex. `\u{20bb7}`)
@@ -0,0 +1,38 @@
1
+ ---
2
+ title: Modifiers
3
+ ---
4
+
5
+ ## Modifiers
6
+
7
+ Modifiers are nodes that modify other nodes. For example, the `private` keyword is a modifier that changes the scope of a method on a class.
8
+
9
+ Only certain nodes can have modifiers and they will have these functions.
10
+
11
+ ### Getting all modifiers
12
+
13
+ ```ts
14
+ functionDeclaration.getModifiers();
15
+ ```
16
+
17
+ ### Getting first modifier by syntax kind
18
+
19
+ Use `getFirstModifierByKind(syntaxKind: SyntaxKind);`.
20
+
21
+ ```ts
22
+ functionDeclaration.getFirstModifierByKind(SyntaxKind.AsyncKeyword);
23
+ ```
24
+
25
+ ### Telling if has a modifier
26
+
27
+ ```ts
28
+ functionDeclaration.hasModifier(SyntaxKind.AsyncKeyword); // returns: boolean
29
+ ```
30
+
31
+ ### Toggle modifier
32
+
33
+ Toggles a modifier on or off:
34
+
35
+ ```ts
36
+ functionDeclaration.toggleModifier("async");
37
+ functionDeclaration.toggleModifier("async", false); // or explicit toggle
38
+ ```
@@ -0,0 +1,113 @@
1
+ ---
2
+ title: Module / Namespace Declarations
3
+ ---
4
+
5
+ ## Module / Namespace Declarations
6
+
7
+ Module declarations may look like any of the following:
8
+
9
+ ```ts ignore-error: 2664
10
+ namespace MyNamespace {
11
+ }
12
+
13
+ module MyModule {
14
+ }
15
+
16
+ declare module "some-module" {
17
+ }
18
+
19
+ declare module "other-module";
20
+ ```
21
+
22
+ They can be retrieved from source files or other modules/namespaces:
23
+
24
+ ```ts
25
+ const modules = sourceFile.getModules();
26
+ const namespace1 = sourceFile.getModule("Namespace1");
27
+ const firstNamespaceWithClass = sourceFile.getModule(n => n.getClasses().length > 0);
28
+ ```
29
+
30
+ Most of the information you can get about namespaces is covered in other sections.
31
+
32
+ Note: Although it's a compile error, you can also retrieve namespaces from function bodies.
33
+
34
+ ### Add/Insert
35
+
36
+ Add or insert namespaces to a source file, namespace, or function like declarations by calling `addModule()`, `addModules()`, `insertModule()`, or `insertModules()`.
37
+
38
+ ```ts
39
+ const moduleDeclaration = sourceFile.addModule({
40
+ name: "ModuleName",
41
+ });
42
+ ```
43
+
44
+ ### Remove
45
+
46
+ Call `.remove()`:
47
+
48
+ ```ts
49
+ moduleDeclaration.remove();
50
+ ```
51
+
52
+ ### Module, namespace, or `global`?
53
+
54
+ Check for the declaration kind or keywords:
55
+
56
+ ```ts
57
+ moduleDeclaration.getDeclarationKind(); // returns: ModuleDeclarationKind
58
+ // or
59
+ moduleDeclaration.hasModuleKeyword(); // returns: boolean
60
+ moduleDeclaration.hasNamespaceKeyword(); // returns: boolean
61
+ ```
62
+
63
+ Or set the declaration kind:
64
+
65
+ ```ts
66
+ moduleDeclaration.setDeclarationKind(ModuleDeclarationKind.Namespace);
67
+ moduleDeclaration.setDeclarationKind(ModuleDeclarationKind.Module);
68
+ moduleDeclaration.setDeclarationKind(ModuleDeclarationKind.Global);
69
+ ```
70
+
71
+ Or get the keyword:
72
+
73
+ ```ts
74
+ // returns: the module or namespace keyword or undefined if global
75
+ moduleDeclaration.getDeclarationKindKeyword();
76
+ ```
77
+
78
+ **Reminder:** Module declarations that are `global` have the following syntax:
79
+
80
+ ```ts ignore-error: 2664, 2669
81
+ declare module "my-library" {
82
+ // this is a global namespace declaration
83
+ global {
84
+ const foo: string;
85
+ }
86
+ }
87
+ ```
88
+
89
+ ### Unwrap
90
+
91
+ A module declaration can be replaced with its body using the `.unwrap()` method.
92
+
93
+ Given the following code:
94
+
95
+ ```ts
96
+ namespace MyNamespace {
97
+ function someFunction() {
98
+ }
99
+
100
+ class SomeClass {
101
+ }
102
+ }
103
+ ```
104
+
105
+ Calling `.unwrap()` will change the code to the following:
106
+
107
+ ```ts
108
+ function someFunction() {
109
+ }
110
+
111
+ class SomeClass {
112
+ }
113
+ ```
@@ -0,0 +1,7 @@
1
+ ---
2
+ title: Namespaces
3
+ ---
4
+
5
+ ## Namespaces
6
+
7
+ See [Modules](modules).