@tslite/services 0.0.0-stage → 1.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (176) hide show
  1. package/LICENSE +55 -0
  2. package/NOTICE +13 -0
  3. package/dist/_namespaces/edit.d.ts +8 -0
  4. package/dist/_namespaces/edit.js +11 -0
  5. package/dist/_namespaces/ts.Completions.StringCompletions.d.ts +1 -0
  6. package/dist/_namespaces/ts.Completions.StringCompletions.js +2 -0
  7. package/dist/_namespaces/ts.Completions.d.ts +2 -0
  8. package/dist/_namespaces/ts.Completions.js +3 -0
  9. package/dist/_namespaces/ts.FindAllReferences.d.ts +2 -0
  10. package/dist/_namespaces/ts.FindAllReferences.js +3 -0
  11. package/dist/_namespaces/ts.GoToDefinition.d.ts +1 -0
  12. package/dist/_namespaces/ts.GoToDefinition.js +2 -0
  13. package/dist/_namespaces/ts.NavigationBar.d.ts +1 -0
  14. package/dist/_namespaces/ts.NavigationBar.js +2 -0
  15. package/dist/_namespaces/ts.OrganizeImports.d.ts +1 -0
  16. package/dist/_namespaces/ts.OrganizeImports.js +2 -0
  17. package/dist/_namespaces/ts.OutliningElementsCollector.d.ts +1 -0
  18. package/dist/_namespaces/ts.OutliningElementsCollector.js +2 -0
  19. package/dist/_namespaces/ts.Rename.d.ts +1 -0
  20. package/dist/_namespaces/ts.Rename.js +2 -0
  21. package/dist/_namespaces/ts.SignatureHelp.d.ts +1 -0
  22. package/dist/_namespaces/ts.SignatureHelp.js +2 -0
  23. package/dist/_namespaces/ts.SmartSelectionRange.d.ts +1 -0
  24. package/dist/_namespaces/ts.SmartSelectionRange.js +2 -0
  25. package/dist/_namespaces/ts.SymbolDisplay.d.ts +1 -0
  26. package/dist/_namespaces/ts.SymbolDisplay.js +2 -0
  27. package/dist/_namespaces/ts.codefix.d.ts +26 -0
  28. package/dist/_namespaces/ts.codefix.js +27 -0
  29. package/dist/_namespaces/ts.d.ts +17 -0
  30. package/dist/_namespaces/ts.formatting.d.ts +7 -0
  31. package/dist/_namespaces/ts.formatting.js +8 -0
  32. package/dist/_namespaces/ts.js +20 -0
  33. package/dist/_namespaces/ts.refactor.addOrRemoveBracesToArrowFunction.d.ts +1 -0
  34. package/dist/_namespaces/ts.refactor.addOrRemoveBracesToArrowFunction.js +2 -0
  35. package/dist/_namespaces/ts.refactor.convertParamsToDestructuredObject.d.ts +1 -0
  36. package/dist/_namespaces/ts.refactor.convertParamsToDestructuredObject.js +2 -0
  37. package/dist/_namespaces/ts.refactor.convertStringOrTemplateLiteral.d.ts +1 -0
  38. package/dist/_namespaces/ts.refactor.convertStringOrTemplateLiteral.js +2 -0
  39. package/dist/_namespaces/ts.refactor.d.ts +9 -0
  40. package/dist/_namespaces/ts.refactor.extractSymbol.d.ts +1 -0
  41. package/dist/_namespaces/ts.refactor.extractSymbol.js +2 -0
  42. package/dist/_namespaces/ts.refactor.js +10 -0
  43. package/dist/_namespaces/ts.textChanges.d.ts +1 -0
  44. package/dist/_namespaces/ts.textChanges.js +2 -0
  45. package/dist/classifier.d.ts +5 -0
  46. package/dist/classifier.js +439 -0
  47. package/dist/codeFixProvider.d.ts +13 -0
  48. package/dist/codeFixProvider.js +84 -0
  49. package/dist/codefixes/addConvertToUnknownForNonOverlappingTypes.d.ts +1 -0
  50. package/dist/codefixes/addConvertToUnknownForNonOverlappingTypes.js +21 -0
  51. package/dist/codefixes/addEmptyExportDeclaration.d.ts +1 -0
  52. package/dist/codefixes/addEmptyExportDeclaration.js +17 -0
  53. package/dist/codefixes/addMissingAsync.d.ts +1 -0
  54. package/dist/codefixes/addMissingAsync.js +75 -0
  55. package/dist/codefixes/addMissingAwait.d.ts +1 -0
  56. package/dist/codefixes/addMissingAwait.js +236 -0
  57. package/dist/codefixes/addMissingConst.d.ts +1 -0
  58. package/dist/codefixes/addMissingConst.js +91 -0
  59. package/dist/codefixes/addNameToNamelessParameter.d.ts +1 -0
  60. package/dist/codefixes/addNameToNamelessParameter.js +29 -0
  61. package/dist/codefixes/convertConstToLet.d.ts +1 -0
  62. package/dist/codefixes/convertConstToLet.js +30 -0
  63. package/dist/codefixes/convertToAsyncFunction.d.ts +1 -0
  64. package/dist/codefixes/convertToAsyncFunction.js +495 -0
  65. package/dist/codefixes/convertToMappedObjectType.d.ts +1 -0
  66. package/dist/codefixes/convertToMappedObjectType.js +48 -0
  67. package/dist/codefixes/correctQualifiedNameToIndexedAccessType.d.ts +1 -0
  68. package/dist/codefixes/correctQualifiedNameToIndexedAccessType.js +33 -0
  69. package/dist/codefixes/fixAddModuleReferTypeMissingTypeof.d.ts +1 -0
  70. package/dist/codefixes/fixAddModuleReferTypeMissingTypeof.js +27 -0
  71. package/dist/codefixes/fixAwaitInSyncFunction.d.ts +1 -0
  72. package/dist/codefixes/fixAwaitInSyncFunction.js +69 -0
  73. package/dist/codefixes/fixExpectedComma.d.ts +1 -0
  74. package/dist/codefixes/fixExpectedComma.js +35 -0
  75. package/dist/codefixes/fixInvalidJsxCharacters.d.ts +1 -0
  76. package/dist/codefixes/fixInvalidJsxCharacters.js +41 -0
  77. package/dist/codefixes/fixMissingCallParentheses.d.ts +1 -0
  78. package/dist/codefixes/fixMissingCallParentheses.js +42 -0
  79. package/dist/codefixes/fixSpelling.d.ts +1 -0
  80. package/dist/codefixes/fixSpelling.js +94 -0
  81. package/dist/codefixes/fixUnreachableCode.d.ts +1 -0
  82. package/dist/codefixes/fixUnreachableCode.js +65 -0
  83. package/dist/codefixes/fixUnusedIdentifier.d.ts +1 -0
  84. package/dist/codefixes/fixUnusedIdentifier.js +224 -0
  85. package/dist/codefixes/helpers.d.ts +8 -0
  86. package/dist/codefixes/helpers.js +53 -0
  87. package/dist/codefixes/importFixes.d.ts +14 -0
  88. package/dist/codefixes/importFixes.js +441 -0
  89. package/dist/codefixes/inferFromUsage.d.ts +1 -0
  90. package/dist/codefixes/inferFromUsage.js +742 -0
  91. package/dist/codefixes/removeUnnecessaryAwait.d.ts +1 -0
  92. package/dist/codefixes/removeUnnecessaryAwait.js +41 -0
  93. package/dist/codefixes/returnValueCorrect.d.ts +1 -0
  94. package/dist/codefixes/returnValueCorrect.js +132 -0
  95. package/dist/codefixes/splitTypeOnlyImport.d.ts +1 -0
  96. package/dist/codefixes/splitTypeOnlyImport.js +32 -0
  97. package/dist/codefixes/useBigintLiteral.d.ts +1 -0
  98. package/dist/codefixes/useBigintLiteral.js +29 -0
  99. package/dist/completions.d.ts +83 -0
  100. package/dist/completions.js +1720 -0
  101. package/dist/documentHighlights.d.ts +8 -0
  102. package/dist/documentHighlights.js +367 -0
  103. package/dist/documentRegistry.d.ts +36 -0
  104. package/dist/documentRegistry.js +63 -0
  105. package/dist/editingServices.d.ts +1 -0
  106. package/dist/editingServices.js +4 -0
  107. package/dist/findAllReferences.d.ts +113 -0
  108. package/dist/findAllReferences.js +1366 -0
  109. package/dist/formatting/formatting.d.ts +26 -0
  110. package/dist/formatting/formatting.js +1021 -0
  111. package/dist/formatting/formattingContext.d.ts +34 -0
  112. package/dist/formatting/formattingContext.js +78 -0
  113. package/dist/formatting/formattingScanner.d.ts +14 -0
  114. package/dist/formatting/formattingScanner.js +228 -0
  115. package/dist/formatting/rule.d.ts +31 -0
  116. package/dist/formatting/rule.js +22 -0
  117. package/dist/formatting/rules.d.ts +7 -0
  118. package/dist/formatting/rules.js +610 -0
  119. package/dist/formatting/rulesMap.d.ts +5 -0
  120. package/dist/formatting/rulesMap.js +127 -0
  121. package/dist/formatting/smartIndenter.d.ts +44 -0
  122. package/dist/formatting/smartIndenter.js +518 -0
  123. package/dist/getEditsForFileRename.d.ts +6 -0
  124. package/dist/getEditsForFileRename.js +86 -0
  125. package/dist/goToDefinition.d.ts +8 -0
  126. package/dist/goToDefinition.js +246 -0
  127. package/dist/importTracker.d.ts +50 -0
  128. package/dist/importTracker.js +422 -0
  129. package/dist/index.d.ts +1 -0
  130. package/dist/index.js +3 -0
  131. package/dist/navigationBar.d.ts +3 -0
  132. package/dist/navigationBar.js +549 -0
  133. package/dist/organizeImports.d.ts +18 -0
  134. package/dist/organizeImports.js +290 -0
  135. package/dist/outliningElementsCollector.d.ts +2 -0
  136. package/dist/outliningElementsCollector.js +261 -0
  137. package/dist/refactorProvider.d.ts +5 -0
  138. package/dist/refactorProvider.js +16 -0
  139. package/dist/refactors/addOrRemoveBracesToArrowFunction.d.ts +1 -0
  140. package/dist/refactors/addOrRemoveBracesToArrowFunction.js +86 -0
  141. package/dist/refactors/convertExport.d.ts +1 -0
  142. package/dist/refactors/convertExport.js +126 -0
  143. package/dist/refactors/convertImport.d.ts +1 -0
  144. package/dist/refactors/convertImport.js +116 -0
  145. package/dist/refactors/convertParamsToDestructuredObject.d.ts +1 -0
  146. package/dist/refactors/convertParamsToDestructuredObject.js +282 -0
  147. package/dist/refactors/convertStringOrTemplateLiteral.d.ts +1 -0
  148. package/dist/refactors/convertStringOrTemplateLiteral.js +148 -0
  149. package/dist/refactors/extractSymbol.d.ts +60 -0
  150. package/dist/refactors/extractSymbol.js +1281 -0
  151. package/dist/refactors/extractType.d.ts +1 -0
  152. package/dist/refactors/extractType.js +102 -0
  153. package/dist/refactors/moveToNewFile.d.ts +1 -0
  154. package/dist/refactors/moveToNewFile.js +477 -0
  155. package/dist/rename.d.ts +2 -0
  156. package/dist/rename.js +100 -0
  157. package/dist/services.d.ts +48 -0
  158. package/dist/services.js +1480 -0
  159. package/dist/signatureHelp.d.ts +8 -0
  160. package/dist/signatureHelp.js +414 -0
  161. package/dist/smartSelection.d.ts +2 -0
  162. package/dist/smartSelection.js +243 -0
  163. package/dist/stringCompletions.d.ts +4 -0
  164. package/dist/stringCompletions.js +220 -0
  165. package/dist/suggestionDiagnostics.d.ts +6 -0
  166. package/dist/suggestionDiagnostics.js +92 -0
  167. package/dist/symbolDisplay.d.ts +16 -0
  168. package/dist/symbolDisplay.js +400 -0
  169. package/dist/textChanges.d.ts +161 -0
  170. package/dist/textChanges.js +1163 -0
  171. package/dist/types.d.ts +908 -0
  172. package/dist/types.js +263 -0
  173. package/dist/utilities.d.ts +283 -0
  174. package/dist/utilities.js +1981 -0
  175. package/package.json +45 -3
  176. package/README.md +0 -3
@@ -0,0 +1,34 @@
1
+ import type { FormatCodeSettings, Node, SourceFileLike } from "../_namespaces/edit.js";
2
+ import type { TextRangeWithKind } from "../_namespaces/ts.formatting.js";
3
+ export declare enum FormattingRequestKind {
4
+ FormatDocument = 0,
5
+ FormatSelection = 1,
6
+ FormatOnEnter = 2,
7
+ FormatOnSemicolon = 3,
8
+ FormatOnOpeningCurlyBrace = 4,
9
+ FormatOnClosingCurlyBrace = 5
10
+ }
11
+ export declare class FormattingContext {
12
+ readonly sourceFile: SourceFileLike;
13
+ formattingRequestKind: FormattingRequestKind;
14
+ options: FormatCodeSettings;
15
+ currentTokenSpan: TextRangeWithKind;
16
+ nextTokenSpan: TextRangeWithKind;
17
+ contextNode: Node;
18
+ currentTokenParent: Node;
19
+ nextTokenParent: Node;
20
+ private contextNodeAllOnSameLine;
21
+ private nextNodeAllOnSameLine;
22
+ private tokensAreOnSameLine;
23
+ private contextNodeBlockIsOnOneLine;
24
+ private nextNodeBlockIsOnOneLine;
25
+ constructor(sourceFile: SourceFileLike, formattingRequestKind: FormattingRequestKind, options: FormatCodeSettings);
26
+ updateContext(currentRange: TextRangeWithKind, currentTokenParent: Node, nextRange: TextRangeWithKind, nextTokenParent: Node, commonParent: Node): void;
27
+ ContextNodeAllOnSameLine(): boolean;
28
+ NextNodeAllOnSameLine(): boolean;
29
+ TokensAreOnSameLine(): boolean;
30
+ ContextNodeBlockIsOnOneLine(): boolean;
31
+ NextNodeBlockIsOnOneLine(): boolean;
32
+ private NodeIsOnOneLine;
33
+ private BlockIsOnOneLine;
34
+ }
@@ -0,0 +1,78 @@
1
+ // Modificado de microsoft/TypeScript v3.9.10, src/services/formatting/formattingContext.ts: o namespace virou módulo ES, com os imports explícitos.
2
+ import { Debug, SyntaxKind, findChildOfKind, } from "../_namespaces/edit.js";
3
+ export var FormattingRequestKind;
4
+ (function (FormattingRequestKind) {
5
+ FormattingRequestKind[FormattingRequestKind["FormatDocument"] = 0] = "FormatDocument";
6
+ FormattingRequestKind[FormattingRequestKind["FormatSelection"] = 1] = "FormatSelection";
7
+ FormattingRequestKind[FormattingRequestKind["FormatOnEnter"] = 2] = "FormatOnEnter";
8
+ FormattingRequestKind[FormattingRequestKind["FormatOnSemicolon"] = 3] = "FormatOnSemicolon";
9
+ FormattingRequestKind[FormattingRequestKind["FormatOnOpeningCurlyBrace"] = 4] = "FormatOnOpeningCurlyBrace";
10
+ FormattingRequestKind[FormattingRequestKind["FormatOnClosingCurlyBrace"] = 5] = "FormatOnClosingCurlyBrace";
11
+ })(FormattingRequestKind || (FormattingRequestKind = {}));
12
+ export class FormattingContext {
13
+ constructor(sourceFile, formattingRequestKind, options) {
14
+ this.sourceFile = sourceFile;
15
+ this.formattingRequestKind = formattingRequestKind;
16
+ this.options = options;
17
+ }
18
+ updateContext(currentRange, currentTokenParent, nextRange, nextTokenParent, commonParent) {
19
+ this.currentTokenSpan = Debug.checkDefined(currentRange);
20
+ this.currentTokenParent = Debug.checkDefined(currentTokenParent);
21
+ this.nextTokenSpan = Debug.checkDefined(nextRange);
22
+ this.nextTokenParent = Debug.checkDefined(nextTokenParent);
23
+ this.contextNode = Debug.checkDefined(commonParent);
24
+ // drop cached results
25
+ this.contextNodeAllOnSameLine = undefined;
26
+ this.nextNodeAllOnSameLine = undefined;
27
+ this.tokensAreOnSameLine = undefined;
28
+ this.contextNodeBlockIsOnOneLine = undefined;
29
+ this.nextNodeBlockIsOnOneLine = undefined;
30
+ }
31
+ ContextNodeAllOnSameLine() {
32
+ if (this.contextNodeAllOnSameLine === undefined) {
33
+ this.contextNodeAllOnSameLine = this.NodeIsOnOneLine(this.contextNode);
34
+ }
35
+ return this.contextNodeAllOnSameLine;
36
+ }
37
+ NextNodeAllOnSameLine() {
38
+ if (this.nextNodeAllOnSameLine === undefined) {
39
+ this.nextNodeAllOnSameLine = this.NodeIsOnOneLine(this.nextTokenParent);
40
+ }
41
+ return this.nextNodeAllOnSameLine;
42
+ }
43
+ TokensAreOnSameLine() {
44
+ if (this.tokensAreOnSameLine === undefined) {
45
+ const startLine = this.sourceFile.getLineAndCharacterOfPosition(this.currentTokenSpan.pos).line;
46
+ const endLine = this.sourceFile.getLineAndCharacterOfPosition(this.nextTokenSpan.pos).line;
47
+ this.tokensAreOnSameLine = (startLine === endLine);
48
+ }
49
+ return this.tokensAreOnSameLine;
50
+ }
51
+ ContextNodeBlockIsOnOneLine() {
52
+ if (this.contextNodeBlockIsOnOneLine === undefined) {
53
+ this.contextNodeBlockIsOnOneLine = this.BlockIsOnOneLine(this.contextNode);
54
+ }
55
+ return this.contextNodeBlockIsOnOneLine;
56
+ }
57
+ NextNodeBlockIsOnOneLine() {
58
+ if (this.nextNodeBlockIsOnOneLine === undefined) {
59
+ this.nextNodeBlockIsOnOneLine = this.BlockIsOnOneLine(this.nextTokenParent);
60
+ }
61
+ return this.nextNodeBlockIsOnOneLine;
62
+ }
63
+ NodeIsOnOneLine(node) {
64
+ const startLine = this.sourceFile.getLineAndCharacterOfPosition(node.getStart(this.sourceFile)).line;
65
+ const endLine = this.sourceFile.getLineAndCharacterOfPosition(node.getEnd()).line;
66
+ return startLine === endLine;
67
+ }
68
+ BlockIsOnOneLine(node) {
69
+ const openBrace = findChildOfKind(node, SyntaxKind.OpenBraceToken, this.sourceFile);
70
+ const closeBrace = findChildOfKind(node, SyntaxKind.CloseBraceToken, this.sourceFile);
71
+ if (openBrace && closeBrace) {
72
+ const startLine = this.sourceFile.getLineAndCharacterOfPosition(openBrace.getEnd()).line;
73
+ const endLine = this.sourceFile.getLineAndCharacterOfPosition(closeBrace.getStart(this.sourceFile)).line;
74
+ return startLine === endLine;
75
+ }
76
+ return false;
77
+ }
78
+ }
@@ -0,0 +1,14 @@
1
+ import { LanguageVariant } from "../_namespaces/edit.js";
2
+ import type { Node } from "../_namespaces/edit.js";
3
+ import type { TextRangeWithKind, TokenInfo } from "../_namespaces/ts.formatting.js";
4
+ export interface FormattingScanner {
5
+ advance(): void;
6
+ isOnToken(): boolean;
7
+ isOnEOF(): boolean;
8
+ readTokenInfo(n: Node): TokenInfo;
9
+ readEOFTokenRange(): TextRangeWithKind;
10
+ getCurrentLeadingTrivia(): TextRangeWithKind[] | undefined;
11
+ lastTrailingTriviaWasNewLine(): boolean;
12
+ skipToEndOf(node: Node): void;
13
+ }
14
+ export declare function getFormattingScanner<T>(text: string, languageVariant: LanguageVariant, startPos: number, endPos: number, cb: (scanner: FormattingScanner) => T): T;
@@ -0,0 +1,228 @@
1
+ // Modificado de microsoft/TypeScript v3.9.10, src/services/formatting/formattingScanner.ts: o namespace virou módulo ES, com os imports explícitos.
2
+ import { Debug, LanguageVariant, ScriptTarget, SyntaxKind, append, createScanner, findAncestor, isJsxAttribute, isJsxElement, isJsxText, isKeyword, isParenthesizedExpression, isToken, isTrivia, last, } from "../_namespaces/edit.js";
3
+ import { createTextRangeWithKind, } from "../_namespaces/ts.formatting.js";
4
+ const standardScanner = createScanner(ScriptTarget.Latest, /*skipTrivia*/ false, LanguageVariant.Standard);
5
+ const jsxScanner = createScanner(ScriptTarget.Latest, /*skipTrivia*/ false, LanguageVariant.JSX);
6
+ var ScanAction;
7
+ (function (ScanAction) {
8
+ ScanAction[ScanAction["Scan"] = 0] = "Scan";
9
+ ScanAction[ScanAction["RescanGreaterThanToken"] = 1] = "RescanGreaterThanToken";
10
+ // Na tag, também o reescaneamento da barra como literal de regex (CK-02).
11
+ ScanAction[ScanAction["RescanTemplateToken"] = 2] = "RescanTemplateToken";
12
+ ScanAction[ScanAction["RescanJsxIdentifier"] = 3] = "RescanJsxIdentifier";
13
+ ScanAction[ScanAction["RescanJsxText"] = 4] = "RescanJsxText";
14
+ ScanAction[ScanAction["RescanJsxAttributeValue"] = 5] = "RescanJsxAttributeValue";
15
+ })(ScanAction || (ScanAction = {}));
16
+ export function getFormattingScanner(text, languageVariant, startPos, endPos, cb) {
17
+ const scanner = languageVariant === LanguageVariant.JSX ? jsxScanner : standardScanner;
18
+ scanner.setText(text);
19
+ scanner.setTextPos(startPos);
20
+ let wasNewLine = true;
21
+ let leadingTrivia;
22
+ let trailingTrivia;
23
+ let savedPos;
24
+ let lastScanAction;
25
+ let lastTokenInfo;
26
+ const res = cb({
27
+ advance,
28
+ readTokenInfo,
29
+ readEOFTokenRange,
30
+ isOnToken,
31
+ isOnEOF,
32
+ getCurrentLeadingTrivia: () => leadingTrivia,
33
+ lastTrailingTriviaWasNewLine: () => wasNewLine,
34
+ skipToEndOf,
35
+ });
36
+ lastTokenInfo = undefined;
37
+ scanner.setText(undefined);
38
+ return res;
39
+ function advance() {
40
+ lastTokenInfo = undefined;
41
+ const isStarted = scanner.getStartPos() !== startPos;
42
+ if (isStarted) {
43
+ wasNewLine = !!trailingTrivia && last(trailingTrivia).kind === SyntaxKind.NewLineTrivia;
44
+ }
45
+ else {
46
+ scanner.scan();
47
+ }
48
+ leadingTrivia = undefined;
49
+ trailingTrivia = undefined;
50
+ let pos = scanner.getStartPos();
51
+ // Read leading trivia and token
52
+ while (pos < endPos) {
53
+ const t = scanner.getToken();
54
+ if (!isTrivia(t)) {
55
+ break;
56
+ }
57
+ // consume leading trivia
58
+ scanner.scan();
59
+ const item = {
60
+ pos,
61
+ end: scanner.getStartPos(),
62
+ kind: t
63
+ };
64
+ pos = scanner.getStartPos();
65
+ leadingTrivia = append(leadingTrivia, item);
66
+ }
67
+ savedPos = scanner.getStartPos();
68
+ }
69
+ function shouldRescanGreaterThanToken(node) {
70
+ switch (node.kind) {
71
+ case SyntaxKind.GreaterThanEqualsToken:
72
+ case SyntaxKind.GreaterThanGreaterThanEqualsToken:
73
+ case SyntaxKind.GreaterThanGreaterThanGreaterThanEqualsToken:
74
+ case SyntaxKind.GreaterThanGreaterThanGreaterThanToken:
75
+ case SyntaxKind.GreaterThanGreaterThanToken:
76
+ return true;
77
+ }
78
+ return false;
79
+ }
80
+ function shouldRescanJsxIdentifier(node) {
81
+ if (node.parent) {
82
+ switch (node.parent.kind) {
83
+ case SyntaxKind.JsxAttribute:
84
+ case SyntaxKind.JsxOpeningElement:
85
+ case SyntaxKind.JsxClosingElement:
86
+ case SyntaxKind.JsxSelfClosingElement:
87
+ // May parse an identifier like `module-layout`; that will be scanned as a keyword at first, but we should parse the whole thing to get an identifier.
88
+ return isKeyword(node.kind) || node.kind === SyntaxKind.Identifier;
89
+ }
90
+ }
91
+ return false;
92
+ }
93
+ function shouldRescanJsxText(node) {
94
+ const isJSXText = isJsxText(node);
95
+ if (isJSXText) {
96
+ const containingElement = findAncestor(node.parent, p => isJsxElement(p));
97
+ if (!containingElement)
98
+ return false; // should never happen
99
+ return !isParenthesizedExpression(containingElement.parent);
100
+ }
101
+ return false;
102
+ }
103
+ function shouldRescanTemplateToken(container) {
104
+ return container.kind === SyntaxKind.TemplateMiddle ||
105
+ container.kind === SyntaxKind.TemplateTail;
106
+ }
107
+ function shouldRescanJsxAttributeValue(node) {
108
+ return node.parent && isJsxAttribute(node.parent) && node.parent.initializer === node;
109
+ }
110
+ // Na tag, também o literal de regex, que se reescaneava a partir da barra (CK-02).
111
+ function readTokenInfo(n) {
112
+ Debug.assert(isOnToken());
113
+ // normally scanner returns the smallest available token
114
+ // check the kind of context node to determine if scanner should have more greedy behavior and consume more text.
115
+ const expectedScanAction = shouldRescanGreaterThanToken(n) ? 1 /* ScanAction.RescanGreaterThanToken */ :
116
+ shouldRescanTemplateToken(n) ? 2 /* ScanAction.RescanTemplateToken */ :
117
+ shouldRescanJsxIdentifier(n) ? 3 /* ScanAction.RescanJsxIdentifier */ :
118
+ shouldRescanJsxText(n) ? 4 /* ScanAction.RescanJsxText */ :
119
+ shouldRescanJsxAttributeValue(n) ? 5 /* ScanAction.RescanJsxAttributeValue */ :
120
+ 0 /* ScanAction.Scan */;
121
+ if (lastTokenInfo && expectedScanAction === lastScanAction) {
122
+ // readTokenInfo was called before with the same expected scan action.
123
+ // No need to re-scan text, return existing 'lastTokenInfo'
124
+ // it is ok to call fixTokenKind here since it does not affect
125
+ // what portion of text is consumed. In contrast rescanning can change it,
126
+ // i.e. for '>=' when originally scanner eats just one character
127
+ // and rescanning forces it to consume more.
128
+ return fixTokenKind(lastTokenInfo, n);
129
+ }
130
+ if (scanner.getStartPos() !== savedPos) {
131
+ Debug.assert(lastTokenInfo !== undefined);
132
+ // readTokenInfo was called before but scan action differs - rescan text
133
+ scanner.setTextPos(savedPos);
134
+ scanner.scan();
135
+ }
136
+ let currentToken = getNextToken(n, expectedScanAction);
137
+ const token = createTextRangeWithKind(scanner.getStartPos(), scanner.getTextPos(), currentToken);
138
+ // consume trailing trivia
139
+ if (trailingTrivia) {
140
+ trailingTrivia = undefined;
141
+ }
142
+ while (scanner.getStartPos() < endPos) {
143
+ currentToken = scanner.scan();
144
+ if (!isTrivia(currentToken)) {
145
+ break;
146
+ }
147
+ const trivia = createTextRangeWithKind(scanner.getStartPos(), scanner.getTextPos(), currentToken);
148
+ if (!trailingTrivia) {
149
+ trailingTrivia = [];
150
+ }
151
+ trailingTrivia.push(trivia);
152
+ if (currentToken === SyntaxKind.NewLineTrivia) {
153
+ // move past new line
154
+ scanner.scan();
155
+ break;
156
+ }
157
+ }
158
+ lastTokenInfo = { leadingTrivia, trailingTrivia, token };
159
+ return fixTokenKind(lastTokenInfo, n);
160
+ }
161
+ function getNextToken(n, expectedScanAction) {
162
+ const token = scanner.getToken();
163
+ lastScanAction = 0 /* ScanAction.Scan */;
164
+ switch (expectedScanAction) {
165
+ case 1 /* ScanAction.RescanGreaterThanToken */:
166
+ if (token === SyntaxKind.GreaterThanToken) {
167
+ lastScanAction = 1 /* ScanAction.RescanGreaterThanToken */;
168
+ const newToken = scanner.reScanGreaterToken();
169
+ Debug.assert(n.kind === newToken);
170
+ return newToken;
171
+ }
172
+ break;
173
+ case 2 /* ScanAction.RescanTemplateToken */:
174
+ if (token === SyntaxKind.CloseBraceToken) {
175
+ lastScanAction = 2 /* ScanAction.RescanTemplateToken */;
176
+ // Na tag, com o `isTaggedTemplate` do template marcado (CK-02).
177
+ return scanner.reScanTemplateToken();
178
+ }
179
+ break;
180
+ case 3 /* ScanAction.RescanJsxIdentifier */:
181
+ lastScanAction = 3 /* ScanAction.RescanJsxIdentifier */;
182
+ return scanner.scanJsxIdentifier();
183
+ case 4 /* ScanAction.RescanJsxText */:
184
+ lastScanAction = 4 /* ScanAction.RescanJsxText */;
185
+ return scanner.reScanJsxToken();
186
+ case 5 /* ScanAction.RescanJsxAttributeValue */:
187
+ lastScanAction = 5 /* ScanAction.RescanJsxAttributeValue */;
188
+ return scanner.reScanJsxAttributeValue();
189
+ case 0 /* ScanAction.Scan */:
190
+ break;
191
+ default:
192
+ Debug.assertNever(expectedScanAction);
193
+ }
194
+ return token;
195
+ }
196
+ function readEOFTokenRange() {
197
+ Debug.assert(isOnEOF());
198
+ return createTextRangeWithKind(scanner.getStartPos(), scanner.getTextPos(), SyntaxKind.EndOfFileToken);
199
+ }
200
+ function isOnToken() {
201
+ const current = lastTokenInfo ? lastTokenInfo.token.kind : scanner.getToken();
202
+ const startPos = lastTokenInfo ? lastTokenInfo.token.pos : scanner.getStartPos();
203
+ return startPos < endPos && current !== SyntaxKind.EndOfFileToken && !isTrivia(current);
204
+ }
205
+ function isOnEOF() {
206
+ const current = lastTokenInfo ? lastTokenInfo.token.kind : scanner.getToken();
207
+ return current === SyntaxKind.EndOfFileToken;
208
+ }
209
+ // when containing node in the tree is token
210
+ // but its kind differs from the kind that was returned by the scanner,
211
+ // then kind needs to be fixed. This might happen in cases
212
+ // when parser interprets token differently, i.e keyword treated as identifier
213
+ function fixTokenKind(tokenInfo, container) {
214
+ if (isToken(container) && tokenInfo.token.kind !== container.kind) {
215
+ tokenInfo.token.kind = container.kind;
216
+ }
217
+ return tokenInfo;
218
+ }
219
+ function skipToEndOf(node) {
220
+ scanner.setTextPos(node.end);
221
+ savedPos = scanner.getStartPos();
222
+ lastScanAction = undefined;
223
+ lastTokenInfo = undefined;
224
+ wasNewLine = false;
225
+ leadingTrivia = undefined;
226
+ trailingTrivia = undefined;
227
+ }
228
+ }
@@ -0,0 +1,31 @@
1
+ import { SyntaxKind } from "../_namespaces/edit.js";
2
+ import { FormattingContext } from "../_namespaces/ts.formatting.js";
3
+ export interface Rule {
4
+ readonly debugName: string;
5
+ readonly context: readonly ContextPredicate[];
6
+ readonly action: RuleAction;
7
+ readonly flags: RuleFlags;
8
+ }
9
+ export type ContextPredicate = (context: FormattingContext) => boolean;
10
+ export declare const anyContext: readonly ContextPredicate[];
11
+ export declare enum RuleAction {
12
+ None = 0,
13
+ StopProcessingSpaceActions = 1,
14
+ StopProcessingTokenActions = 2,
15
+ InsertSpace = 4,
16
+ InsertNewLine = 8,
17
+ DeleteSpace = 16,
18
+ DeleteToken = 32,
19
+ InsertTrailingSemicolon = 64,
20
+ StopAction = 3,
21
+ ModifySpaceAction = 28,
22
+ ModifyTokenAction = 96
23
+ }
24
+ export declare enum RuleFlags {
25
+ None = 0,
26
+ CanDeleteNewLines = 1
27
+ }
28
+ export interface TokenRange {
29
+ readonly tokens: readonly SyntaxKind[];
30
+ readonly isSpecific: boolean;
31
+ }
@@ -0,0 +1,22 @@
1
+ // Modificado de microsoft/TypeScript v3.9.10, src/services/formatting/rule.ts: o namespace virou módulo ES, com os imports explícitos.
2
+ import { emptyArray, } from "../_namespaces/edit.js";
3
+ export const anyContext = emptyArray;
4
+ export var RuleAction;
5
+ (function (RuleAction) {
6
+ RuleAction[RuleAction["None"] = 0] = "None";
7
+ RuleAction[RuleAction["StopProcessingSpaceActions"] = 1] = "StopProcessingSpaceActions";
8
+ RuleAction[RuleAction["StopProcessingTokenActions"] = 2] = "StopProcessingTokenActions";
9
+ RuleAction[RuleAction["InsertSpace"] = 4] = "InsertSpace";
10
+ RuleAction[RuleAction["InsertNewLine"] = 8] = "InsertNewLine";
11
+ RuleAction[RuleAction["DeleteSpace"] = 16] = "DeleteSpace";
12
+ RuleAction[RuleAction["DeleteToken"] = 32] = "DeleteToken";
13
+ RuleAction[RuleAction["InsertTrailingSemicolon"] = 64] = "InsertTrailingSemicolon";
14
+ RuleAction[RuleAction["StopAction"] = 3] = "StopAction";
15
+ RuleAction[RuleAction["ModifySpaceAction"] = 28] = "ModifySpaceAction";
16
+ RuleAction[RuleAction["ModifyTokenAction"] = 96] = "ModifyTokenAction";
17
+ })(RuleAction || (RuleAction = {}));
18
+ export var RuleFlags;
19
+ (function (RuleFlags) {
20
+ RuleFlags[RuleFlags["None"] = 0] = "None";
21
+ RuleFlags[RuleFlags["CanDeleteNewLines"] = 1] = "CanDeleteNewLines";
22
+ })(RuleFlags || (RuleFlags = {}));
@@ -0,0 +1,7 @@
1
+ import type { Rule, TokenRange } from "../_namespaces/ts.formatting.js";
2
+ export interface RuleSpec {
3
+ readonly leftTokenRange: TokenRange;
4
+ readonly rightTokenRange: TokenRange;
5
+ readonly rule: Rule;
6
+ }
7
+ export declare function getAllRules(): RuleSpec[];