@tslite/services 1.16.0 → 1.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/NOTICE +3 -1
- package/dist/_namespaces/edit.d.ts +1 -1
- package/dist/_namespaces/edit.js +10759 -11
- package/dist/_namespaces/ts.codefix.d.ts +0 -1
- package/dist/_namespaces/ts.js +10196 -19
- package/dist/classifier.d.ts +3 -1
- package/dist/codeFixProvider.d.ts +2 -1
- package/dist/codefixes/helpers.d.ts +3 -1
- package/dist/codefixes/importFixes.d.ts +3 -1
- package/dist/completions.d.ts +5 -2
- package/dist/documentHighlights.d.ts +3 -1
- package/dist/documentRegistry.d.ts +2 -1
- package/dist/findAllReferences.d.ts +3 -1
- package/dist/formatting/formatting.d.ts +3 -2
- package/dist/formatting/formattingContext.d.ts +2 -1
- package/dist/formatting/formattingScanner.d.ts +2 -2
- package/dist/formatting/rule.d.ts +1 -1
- package/dist/formatting/rulesMap.d.ts +1 -1
- package/dist/formatting/smartIndenter.d.ts +2 -1
- package/dist/getEditsForFileRename.d.ts +4 -1
- package/dist/goToDefinition.d.ts +3 -1
- package/dist/importTracker.d.ts +2 -1
- package/dist/navigationBar.d.ts +3 -1
- package/dist/organizeImports.d.ts +4 -2
- package/dist/outliningElementsCollector.d.ts +3 -1
- package/dist/refactorProvider.d.ts +1 -1
- package/dist/refactors/extractSymbol.d.ts +2 -1
- package/dist/rename.d.ts +3 -1
- package/dist/services.d.ts +5 -2
- package/dist/signatureHelp.d.ts +3 -1
- package/dist/smartSelection.d.ts +2 -1
- package/dist/stringCompletions.d.ts +3 -1
- package/dist/suggestionDiagnostics.d.ts +4 -3
- package/dist/symbolDisplay.d.ts +3 -1
- package/dist/textChanges.d.ts +4 -2
- package/dist/types.d.ts +3 -3
- package/dist/utilities.d.ts +7 -2
- package/package.json +7 -5
- package/dist/_namespaces/ts.Completions.StringCompletions.js +0 -2
- package/dist/_namespaces/ts.Completions.js +0 -3
- package/dist/_namespaces/ts.FindAllReferences.js +0 -3
- package/dist/_namespaces/ts.GoToDefinition.js +0 -2
- package/dist/_namespaces/ts.NavigationBar.js +0 -2
- package/dist/_namespaces/ts.OrganizeImports.js +0 -2
- package/dist/_namespaces/ts.OutliningElementsCollector.js +0 -2
- package/dist/_namespaces/ts.Rename.js +0 -2
- package/dist/_namespaces/ts.SignatureHelp.js +0 -2
- package/dist/_namespaces/ts.SmartSelectionRange.js +0 -2
- package/dist/_namespaces/ts.SymbolDisplay.js +0 -2
- package/dist/_namespaces/ts.codefix.js +0 -27
- package/dist/_namespaces/ts.formatting.js +0 -8
- package/dist/_namespaces/ts.refactor.addOrRemoveBracesToArrowFunction.js +0 -2
- package/dist/_namespaces/ts.refactor.convertParamsToDestructuredObject.js +0 -2
- package/dist/_namespaces/ts.refactor.convertStringOrTemplateLiteral.js +0 -2
- package/dist/_namespaces/ts.refactor.extractSymbol.js +0 -2
- package/dist/_namespaces/ts.refactor.js +0 -10
- package/dist/_namespaces/ts.textChanges.js +0 -2
- package/dist/classifier.js +0 -715
- package/dist/codeFixProvider.js +0 -84
- package/dist/codefixes/addConvertToUnknownForNonOverlappingTypes.d.ts +0 -1
- package/dist/codefixes/addConvertToUnknownForNonOverlappingTypes.js +0 -21
- package/dist/codefixes/addEmptyExportDeclaration.js +0 -17
- package/dist/codefixes/addMissingAsync.js +0 -75
- package/dist/codefixes/addMissingAwait.js +0 -236
- package/dist/codefixes/addMissingConst.js +0 -91
- package/dist/codefixes/addNameToNamelessParameter.js +0 -29
- package/dist/codefixes/convertConstToLet.js +0 -30
- package/dist/codefixes/convertToAsyncFunction.js +0 -495
- package/dist/codefixes/convertToMappedObjectType.js +0 -48
- package/dist/codefixes/correctQualifiedNameToIndexedAccessType.js +0 -33
- package/dist/codefixes/fixAddModuleReferTypeMissingTypeof.js +0 -27
- package/dist/codefixes/fixAwaitInSyncFunction.js +0 -69
- package/dist/codefixes/fixExpectedComma.js +0 -35
- package/dist/codefixes/fixInvalidJsxCharacters.js +0 -41
- package/dist/codefixes/fixMissingCallParentheses.js +0 -42
- package/dist/codefixes/fixSpelling.js +0 -94
- package/dist/codefixes/fixUnreachableCode.js +0 -65
- package/dist/codefixes/fixUnusedIdentifier.js +0 -224
- package/dist/codefixes/helpers.js +0 -53
- package/dist/codefixes/importFixes.js +0 -441
- package/dist/codefixes/inferFromUsage.js +0 -742
- package/dist/codefixes/removeUnnecessaryAwait.js +0 -41
- package/dist/codefixes/returnValueCorrect.js +0 -132
- package/dist/codefixes/splitTypeOnlyImport.js +0 -32
- package/dist/codefixes/useBigintLiteral.js +0 -29
- package/dist/completions.js +0 -1720
- package/dist/documentHighlights.js +0 -367
- package/dist/documentRegistry.js +0 -63
- package/dist/editingServices.js +0 -4
- package/dist/findAllReferences.js +0 -1366
- package/dist/formatting/formatting.js +0 -1021
- package/dist/formatting/formattingContext.js +0 -78
- package/dist/formatting/formattingScanner.js +0 -228
- package/dist/formatting/rule.js +0 -22
- package/dist/formatting/rules.js +0 -610
- package/dist/formatting/rulesMap.js +0 -127
- package/dist/formatting/smartIndenter.js +0 -518
- package/dist/getEditsForFileRename.js +0 -86
- package/dist/goToDefinition.js +0 -246
- package/dist/importTracker.js +0 -422
- package/dist/index.js +0 -3
- package/dist/navigationBar.js +0 -549
- package/dist/organizeImports.js +0 -290
- package/dist/outliningElementsCollector.js +0 -261
- package/dist/refactorProvider.js +0 -16
- package/dist/refactors/addOrRemoveBracesToArrowFunction.js +0 -86
- package/dist/refactors/convertExport.js +0 -126
- package/dist/refactors/convertImport.js +0 -116
- package/dist/refactors/convertParamsToDestructuredObject.js +0 -282
- package/dist/refactors/convertStringOrTemplateLiteral.js +0 -148
- package/dist/refactors/extractSymbol.js +0 -1281
- package/dist/refactors/extractType.js +0 -102
- package/dist/refactors/moveToNewFile.js +0 -477
- package/dist/rename.js +0 -100
- package/dist/services.js +0 -1480
- package/dist/signatureHelp.js +0 -414
- package/dist/smartSelection.js +0 -243
- package/dist/stringCompletions.js +0 -220
- package/dist/suggestionDiagnostics.js +0 -92
- package/dist/symbolDisplay.js +0 -400
- package/dist/textChanges.js +0 -1163
- package/dist/types.js +0 -263
- package/dist/utilities.js +0 -1981
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
// Modificado de microsoft/TypeScript v3.9.10, src/services/formatting/rulesMap.ts: o namespace virou módulo ES, com os imports explícitos.
|
|
2
|
-
import { Debug, SyntaxKind, every, } from "../_namespaces/edit.js";
|
|
3
|
-
import { anyContext, getAllRules, } from "../_namespaces/ts.formatting.js";
|
|
4
|
-
export function getFormatContext(options, host) {
|
|
5
|
-
return { options, getRules: getRulesMap(), host };
|
|
6
|
-
}
|
|
7
|
-
let rulesMapCache;
|
|
8
|
-
function getRulesMap() {
|
|
9
|
-
if (rulesMapCache === undefined) {
|
|
10
|
-
rulesMapCache = createRulesMap(getAllRules());
|
|
11
|
-
}
|
|
12
|
-
return rulesMapCache;
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* For a given rule action, gets a mask of other rule actions that
|
|
16
|
-
* cannot be applied at the same position.
|
|
17
|
-
*/
|
|
18
|
-
function getRuleActionExclusion(ruleAction) {
|
|
19
|
-
let mask = 0;
|
|
20
|
-
if (ruleAction & 1 /* RuleAction.StopProcessingSpaceActions */) {
|
|
21
|
-
mask |= 28 /* RuleAction.ModifySpaceAction */;
|
|
22
|
-
}
|
|
23
|
-
if (ruleAction & 2 /* RuleAction.StopProcessingTokenActions */) {
|
|
24
|
-
mask |= 96 /* RuleAction.ModifyTokenAction */;
|
|
25
|
-
}
|
|
26
|
-
if (ruleAction & 28 /* RuleAction.ModifySpaceAction */) {
|
|
27
|
-
mask |= 28 /* RuleAction.ModifySpaceAction */;
|
|
28
|
-
}
|
|
29
|
-
if (ruleAction & 96 /* RuleAction.ModifyTokenAction */) {
|
|
30
|
-
mask |= 96 /* RuleAction.ModifyTokenAction */;
|
|
31
|
-
}
|
|
32
|
-
return mask;
|
|
33
|
-
}
|
|
34
|
-
function createRulesMap(rules) {
|
|
35
|
-
const map = buildMap(rules);
|
|
36
|
-
return context => {
|
|
37
|
-
const bucket = map[getRuleBucketIndex(context.currentTokenSpan.kind, context.nextTokenSpan.kind)];
|
|
38
|
-
if (bucket) {
|
|
39
|
-
const rules = [];
|
|
40
|
-
let ruleActionMask = 0;
|
|
41
|
-
for (const rule of bucket) {
|
|
42
|
-
const acceptRuleActions = ~getRuleActionExclusion(ruleActionMask);
|
|
43
|
-
if (rule.action & acceptRuleActions && every(rule.context, c => c(context))) {
|
|
44
|
-
rules.push(rule);
|
|
45
|
-
ruleActionMask |= rule.action;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
if (rules.length) {
|
|
49
|
-
return rules;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
function buildMap(rules) {
|
|
55
|
-
// Map from bucket index to array of rules
|
|
56
|
-
const map = new Array(mapRowLength * mapRowLength);
|
|
57
|
-
// This array is used only during construction of the rulesbucket in the map
|
|
58
|
-
const rulesBucketConstructionStateList = new Array(map.length);
|
|
59
|
-
for (const rule of rules) {
|
|
60
|
-
const specificRule = rule.leftTokenRange.isSpecific && rule.rightTokenRange.isSpecific;
|
|
61
|
-
for (const left of rule.leftTokenRange.tokens) {
|
|
62
|
-
for (const right of rule.rightTokenRange.tokens) {
|
|
63
|
-
const index = getRuleBucketIndex(left, right);
|
|
64
|
-
let rulesBucket = map[index];
|
|
65
|
-
if (rulesBucket === undefined) {
|
|
66
|
-
rulesBucket = map[index] = [];
|
|
67
|
-
}
|
|
68
|
-
addRule(rulesBucket, rule.rule, specificRule, rulesBucketConstructionStateList, index);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
return map;
|
|
73
|
-
}
|
|
74
|
-
function getRuleBucketIndex(row, column) {
|
|
75
|
-
Debug.assert(row <= SyntaxKind.LastKeyword && column <= SyntaxKind.LastKeyword, "Must compute formatting context from tokens");
|
|
76
|
-
return (row * mapRowLength) + column;
|
|
77
|
-
}
|
|
78
|
-
const maskBitSize = 5;
|
|
79
|
-
const mask = 0b11111; // MaskBitSize bits
|
|
80
|
-
const mapRowLength = SyntaxKind.LastToken + 1;
|
|
81
|
-
var RulesPosition;
|
|
82
|
-
(function (RulesPosition) {
|
|
83
|
-
RulesPosition[RulesPosition["StopRulesSpecific"] = 0] = "StopRulesSpecific";
|
|
84
|
-
RulesPosition[RulesPosition["StopRulesAny"] = 5] = "StopRulesAny";
|
|
85
|
-
RulesPosition[RulesPosition["ContextRulesSpecific"] = 10] = "ContextRulesSpecific";
|
|
86
|
-
RulesPosition[RulesPosition["ContextRulesAny"] = 15] = "ContextRulesAny";
|
|
87
|
-
RulesPosition[RulesPosition["NoContextRulesSpecific"] = 20] = "NoContextRulesSpecific";
|
|
88
|
-
RulesPosition[RulesPosition["NoContextRulesAny"] = 25] = "NoContextRulesAny";
|
|
89
|
-
})(RulesPosition || (RulesPosition = {}));
|
|
90
|
-
// The Rules list contains all the inserted rules into a rulebucket in the following order:
|
|
91
|
-
// 1- Ignore rules with specific token combination
|
|
92
|
-
// 2- Ignore rules with any token combination
|
|
93
|
-
// 3- Context rules with specific token combination
|
|
94
|
-
// 4- Context rules with any token combination
|
|
95
|
-
// 5- Non-context rules with specific token combination
|
|
96
|
-
// 6- Non-context rules with any token combination
|
|
97
|
-
//
|
|
98
|
-
// The member rulesInsertionIndexBitmap is used to describe the number of rules
|
|
99
|
-
// in each sub-bucket (above) hence can be used to know the index of where to insert
|
|
100
|
-
// the next rule. It's a bitmap which contains 6 different sections each is given 5 bits.
|
|
101
|
-
//
|
|
102
|
-
// Example:
|
|
103
|
-
// In order to insert a rule to the end of sub-bucket (3), we get the index by adding
|
|
104
|
-
// the values in the bitmap segments 3rd, 2nd, and 1st.
|
|
105
|
-
function addRule(rules, rule, specificTokens, constructionState, rulesBucketIndex) {
|
|
106
|
-
const position = rule.action & 3 /* RuleAction.StopAction */ ?
|
|
107
|
-
specificTokens ? RulesPosition.StopRulesSpecific : RulesPosition.StopRulesAny :
|
|
108
|
-
rule.context !== anyContext ?
|
|
109
|
-
specificTokens ? RulesPosition.ContextRulesSpecific : RulesPosition.ContextRulesAny :
|
|
110
|
-
specificTokens ? RulesPosition.NoContextRulesSpecific : RulesPosition.NoContextRulesAny;
|
|
111
|
-
const state = constructionState[rulesBucketIndex] || 0;
|
|
112
|
-
rules.splice(getInsertionIndex(state, position), 0, rule);
|
|
113
|
-
constructionState[rulesBucketIndex] = increaseInsertionIndex(state, position);
|
|
114
|
-
}
|
|
115
|
-
function getInsertionIndex(indexBitmap, maskPosition) {
|
|
116
|
-
let index = 0;
|
|
117
|
-
for (let pos = 0; pos <= maskPosition; pos += maskBitSize) {
|
|
118
|
-
index += indexBitmap & mask;
|
|
119
|
-
indexBitmap >>= maskBitSize;
|
|
120
|
-
}
|
|
121
|
-
return index;
|
|
122
|
-
}
|
|
123
|
-
function increaseInsertionIndex(indexBitmap, maskPosition) {
|
|
124
|
-
const value = ((indexBitmap >> maskPosition) & mask) + 1;
|
|
125
|
-
Debug.assert((value & mask) === value, "Adding more rules into the sub-bucket than allowed. Maximum allowed is 32 rules.");
|
|
126
|
-
return (indexBitmap & ~(mask << maskPosition)) | (value << maskPosition);
|
|
127
|
-
}
|
|
@@ -1,518 +0,0 @@
|
|
|
1
|
-
// Modificado de microsoft/TypeScript v3.9.10, src/services/formatting/smartIndenter.ts: o namespace virou módulo ES, com os imports explícitos.
|
|
2
|
-
import { CharacterCodes, Debug, IndentStyle, SyntaxKind, contains, find, findChildOfKind, findListItemInfo, findNextToken, findPrecedingToken, getLineAndCharacterOfPosition, getLineStartPositionForPosition, getRangeOfEnclosingComment, getStartPositionOfLine, isCallExpression, isCallOrNewExpression, isDeclaration, isStatementButNotDeclaration, isStringOrRegularExpressionOrTemplateLiteral, isWhiteSpaceLike, isWhiteSpaceSingleLine, positionBelongsToNode, rangeContainsRange, rangeContainsStartEnd, skipTrivia, } from "../_namespaces/edit.js";
|
|
3
|
-
export var SmartIndenter;
|
|
4
|
-
(function (SmartIndenter) {
|
|
5
|
-
let Value;
|
|
6
|
-
(function (Value) {
|
|
7
|
-
Value[Value["Unknown"] = -1] = "Unknown";
|
|
8
|
-
})(Value || (Value = {}));
|
|
9
|
-
/**
|
|
10
|
-
* @param assumeNewLineBeforeCloseBrace
|
|
11
|
-
* `false` when called on text from a real source file.
|
|
12
|
-
* `true` when we need to assume `position` is on a newline.
|
|
13
|
-
*
|
|
14
|
-
* This is useful for codefixes. Consider
|
|
15
|
-
* ```
|
|
16
|
-
* function f() {
|
|
17
|
-
* |}
|
|
18
|
-
* ```
|
|
19
|
-
* with `position` at `|`.
|
|
20
|
-
*
|
|
21
|
-
* When inserting some text after an open brace, we would like to get indentation as if a newline was already there.
|
|
22
|
-
* By default indentation at `position` will be 0 so 'assumeNewLineBeforeCloseBrace' overrides this behavior.
|
|
23
|
-
*/
|
|
24
|
-
function getIndentation(position, sourceFile, options, assumeNewLineBeforeCloseBrace = false) {
|
|
25
|
-
if (position > sourceFile.text.length) {
|
|
26
|
-
return getBaseIndentation(options); // past EOF
|
|
27
|
-
}
|
|
28
|
-
// no indentation when the indent style is set to none,
|
|
29
|
-
// so we can return fast
|
|
30
|
-
if (options.indentStyle === IndentStyle.None) {
|
|
31
|
-
return 0;
|
|
32
|
-
}
|
|
33
|
-
// Na tag, sem o token de um JSDoc (o `excludeJsdoc`, CK-03).
|
|
34
|
-
const precedingToken = findPrecedingToken(position, sourceFile, /*startNode*/ undefined);
|
|
35
|
-
// eslint-disable-next-line no-null/no-null
|
|
36
|
-
const enclosingCommentRange = getRangeOfEnclosingComment(sourceFile, position, precedingToken || null);
|
|
37
|
-
if (enclosingCommentRange && enclosingCommentRange.kind === SyntaxKind.MultiLineCommentTrivia) {
|
|
38
|
-
return getCommentIndent(sourceFile, position, options, enclosingCommentRange);
|
|
39
|
-
}
|
|
40
|
-
if (!precedingToken) {
|
|
41
|
-
return getBaseIndentation(options);
|
|
42
|
-
}
|
|
43
|
-
// no indentation in string \regex\template literals
|
|
44
|
-
const precedingTokenIsLiteral = isStringOrRegularExpressionOrTemplateLiteral(precedingToken.kind);
|
|
45
|
-
if (precedingTokenIsLiteral && precedingToken.getStart(sourceFile) <= position && position < precedingToken.end) {
|
|
46
|
-
return 0;
|
|
47
|
-
}
|
|
48
|
-
const lineAtPosition = sourceFile.getLineAndCharacterOfPosition(position).line;
|
|
49
|
-
// indentation is first non-whitespace character in a previous line
|
|
50
|
-
// for block indentation, we should look for a line which contains something that's not
|
|
51
|
-
// whitespace.
|
|
52
|
-
if (options.indentStyle === IndentStyle.Block) {
|
|
53
|
-
return getBlockIndent(sourceFile, position, options);
|
|
54
|
-
}
|
|
55
|
-
if (precedingToken.kind === SyntaxKind.CommaToken && precedingToken.parent.kind !== SyntaxKind.BinaryExpression) {
|
|
56
|
-
// previous token is comma that separates items in list - find the previous item and try to derive indentation from it
|
|
57
|
-
const actualIndentation = getActualIndentationForListItemBeforeComma(precedingToken, sourceFile, options);
|
|
58
|
-
if (actualIndentation !== -1 /* Value.Unknown */) {
|
|
59
|
-
return actualIndentation;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
const containerList = getListByPosition(position, precedingToken.parent, sourceFile);
|
|
63
|
-
// use list position if the preceding token is before any list items
|
|
64
|
-
if (containerList && !rangeContainsRange(containerList, precedingToken)) {
|
|
65
|
-
return getActualIndentationForListStartLine(containerList, sourceFile, options) + options.indentSize; // TODO: GH#18217
|
|
66
|
-
}
|
|
67
|
-
return getSmartIndent(sourceFile, position, precedingToken, lineAtPosition, assumeNewLineBeforeCloseBrace, options);
|
|
68
|
-
}
|
|
69
|
-
SmartIndenter.getIndentation = getIndentation;
|
|
70
|
-
function getCommentIndent(sourceFile, position, options, enclosingCommentRange) {
|
|
71
|
-
const previousLine = getLineAndCharacterOfPosition(sourceFile, position).line - 1;
|
|
72
|
-
const commentStartLine = getLineAndCharacterOfPosition(sourceFile, enclosingCommentRange.pos).line;
|
|
73
|
-
Debug.assert(commentStartLine >= 0);
|
|
74
|
-
if (previousLine <= commentStartLine) {
|
|
75
|
-
return findFirstNonWhitespaceColumn(getStartPositionOfLine(commentStartLine, sourceFile), position, sourceFile, options);
|
|
76
|
-
}
|
|
77
|
-
const startPositionOfLine = getStartPositionOfLine(previousLine, sourceFile);
|
|
78
|
-
const { column, character } = findFirstNonWhitespaceCharacterAndColumn(startPositionOfLine, position, sourceFile, options);
|
|
79
|
-
if (column === 0) {
|
|
80
|
-
return column;
|
|
81
|
-
}
|
|
82
|
-
const firstNonWhitespaceCharacterCode = sourceFile.text.charCodeAt(startPositionOfLine + character);
|
|
83
|
-
return firstNonWhitespaceCharacterCode === CharacterCodes.asterisk ? column - 1 : column;
|
|
84
|
-
}
|
|
85
|
-
function getBlockIndent(sourceFile, position, options) {
|
|
86
|
-
// move backwards until we find a line with a non-whitespace character,
|
|
87
|
-
// then find the first non-whitespace character for that line.
|
|
88
|
-
let current = position;
|
|
89
|
-
while (current > 0) {
|
|
90
|
-
const char = sourceFile.text.charCodeAt(current);
|
|
91
|
-
if (!isWhiteSpaceLike(char)) {
|
|
92
|
-
break;
|
|
93
|
-
}
|
|
94
|
-
current--;
|
|
95
|
-
}
|
|
96
|
-
const lineStart = getLineStartPositionForPosition(current, sourceFile);
|
|
97
|
-
return findFirstNonWhitespaceColumn(lineStart, current, sourceFile, options);
|
|
98
|
-
}
|
|
99
|
-
function getSmartIndent(sourceFile, position, precedingToken, lineAtPosition, assumeNewLineBeforeCloseBrace, options) {
|
|
100
|
-
// try to find node that can contribute to indentation and includes 'position' starting from 'precedingToken'
|
|
101
|
-
// if such node is found - compute initial indentation for 'position' inside this node
|
|
102
|
-
let previous;
|
|
103
|
-
let current = precedingToken;
|
|
104
|
-
while (current) {
|
|
105
|
-
if (positionBelongsToNode(current, position, sourceFile) && shouldIndentChildNode(options, current, previous, sourceFile, /*isNextChild*/ true)) {
|
|
106
|
-
const currentStart = getStartLineAndCharacterForNode(current, sourceFile);
|
|
107
|
-
const nextTokenKind = nextTokenIsCurlyBraceOnSameLineAsCursor(precedingToken, current, lineAtPosition, sourceFile);
|
|
108
|
-
const indentationDelta = nextTokenKind !== 0 /* NextTokenKind.Unknown */
|
|
109
|
-
// handle cases when codefix is about to be inserted before the close brace
|
|
110
|
-
? assumeNewLineBeforeCloseBrace && nextTokenKind === 2 /* NextTokenKind.CloseBrace */ ? options.indentSize : 0
|
|
111
|
-
: lineAtPosition !== currentStart.line ? options.indentSize : 0;
|
|
112
|
-
return getIndentationForNodeWorker(current, currentStart, /*ignoreActualIndentationRange*/ undefined, indentationDelta, sourceFile, /*isNextChild*/ true, options); // TODO: GH#18217
|
|
113
|
-
}
|
|
114
|
-
// check if current node is a list item - if yes, take indentation from it
|
|
115
|
-
// do not consider parent-child line sharing yet:
|
|
116
|
-
// function foo(a
|
|
117
|
-
// | preceding node 'a' does share line with its parent but indentation is expected
|
|
118
|
-
const actualIndentation = getActualIndentationForListItem(current, sourceFile, options, /*listIndentsChild*/ true);
|
|
119
|
-
if (actualIndentation !== -1 /* Value.Unknown */) {
|
|
120
|
-
return actualIndentation;
|
|
121
|
-
}
|
|
122
|
-
previous = current;
|
|
123
|
-
current = current.parent;
|
|
124
|
-
}
|
|
125
|
-
// no parent was found - return the base indentation of the SourceFile
|
|
126
|
-
return getBaseIndentation(options);
|
|
127
|
-
}
|
|
128
|
-
function getIndentationForNode(n, ignoreActualIndentationRange, sourceFile, options) {
|
|
129
|
-
const start = sourceFile.getLineAndCharacterOfPosition(n.getStart(sourceFile));
|
|
130
|
-
return getIndentationForNodeWorker(n, start, ignoreActualIndentationRange, /*indentationDelta*/ 0, sourceFile, /*isNextChild*/ false, options);
|
|
131
|
-
}
|
|
132
|
-
SmartIndenter.getIndentationForNode = getIndentationForNode;
|
|
133
|
-
function getBaseIndentation(options) {
|
|
134
|
-
return options.baseIndentSize || 0;
|
|
135
|
-
}
|
|
136
|
-
SmartIndenter.getBaseIndentation = getBaseIndentation;
|
|
137
|
-
function getIndentationForNodeWorker(current, currentStart, ignoreActualIndentationRange, indentationDelta, sourceFile, isNextChild, options) {
|
|
138
|
-
let parent = current.parent;
|
|
139
|
-
// Walk up the tree and collect indentation for parent-child node pairs. Indentation is not added if
|
|
140
|
-
// * parent and child nodes start on the same line, or
|
|
141
|
-
// * parent is an IfStatement and child starts on the same line as an 'else clause'.
|
|
142
|
-
while (parent) {
|
|
143
|
-
let useActualIndentation = true;
|
|
144
|
-
if (ignoreActualIndentationRange) {
|
|
145
|
-
const start = current.getStart(sourceFile);
|
|
146
|
-
useActualIndentation = start < ignoreActualIndentationRange.pos || start > ignoreActualIndentationRange.end;
|
|
147
|
-
}
|
|
148
|
-
const containingListOrParentStart = getContainingListOrParentStart(parent, current, sourceFile);
|
|
149
|
-
const parentAndChildShareLine = containingListOrParentStart.line === currentStart.line ||
|
|
150
|
-
childStartsOnTheSameLineWithElseInIfStatement(parent, current, currentStart.line, sourceFile);
|
|
151
|
-
if (useActualIndentation) {
|
|
152
|
-
// check if current node is a list item - if yes, take indentation from it
|
|
153
|
-
let actualIndentation = getActualIndentationForListItem(current, sourceFile, options, !parentAndChildShareLine);
|
|
154
|
-
if (actualIndentation !== -1 /* Value.Unknown */) {
|
|
155
|
-
return actualIndentation + indentationDelta;
|
|
156
|
-
}
|
|
157
|
-
// try to fetch actual indentation for current node from source text
|
|
158
|
-
actualIndentation = getActualIndentationForNode(current, parent, currentStart, parentAndChildShareLine, sourceFile, options);
|
|
159
|
-
if (actualIndentation !== -1 /* Value.Unknown */) {
|
|
160
|
-
return actualIndentation + indentationDelta;
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
// increase indentation if parent node wants its content to be indented and parent and child nodes don't start on the same line
|
|
164
|
-
if (shouldIndentChildNode(options, parent, current, sourceFile, isNextChild) && !parentAndChildShareLine) {
|
|
165
|
-
indentationDelta += options.indentSize;
|
|
166
|
-
}
|
|
167
|
-
// In our AST, a call argument's `parent` is the call-expression, not the argument list.
|
|
168
|
-
// We would like to increase indentation based on the relationship between an argument and its argument-list,
|
|
169
|
-
// so we spoof the starting position of the (parent) call-expression to match the (non-parent) argument-list.
|
|
170
|
-
// But, the spoofed start-value could then cause a problem when comparing the start position of the call-expression
|
|
171
|
-
// to *its* parent (in the case of an iife, an expression statement), adding an extra level of indentation.
|
|
172
|
-
//
|
|
173
|
-
// Instead, when at an argument, we unspoof the starting position of the enclosing call expression
|
|
174
|
-
// *after* applying indentation for the argument.
|
|
175
|
-
const useTrueStart = isArgumentAndStartLineOverlapsExpressionBeingCalled(parent, current, currentStart.line, sourceFile);
|
|
176
|
-
current = parent;
|
|
177
|
-
parent = current.parent;
|
|
178
|
-
currentStart = useTrueStart ? sourceFile.getLineAndCharacterOfPosition(current.getStart(sourceFile)) : containingListOrParentStart;
|
|
179
|
-
}
|
|
180
|
-
return indentationDelta + getBaseIndentation(options);
|
|
181
|
-
}
|
|
182
|
-
function getContainingListOrParentStart(parent, child, sourceFile) {
|
|
183
|
-
const containingList = getContainingList(child, sourceFile);
|
|
184
|
-
const startPos = containingList ? containingList.pos : parent.getStart(sourceFile);
|
|
185
|
-
return sourceFile.getLineAndCharacterOfPosition(startPos);
|
|
186
|
-
}
|
|
187
|
-
/*
|
|
188
|
-
* Function returns Value.Unknown if indentation cannot be determined
|
|
189
|
-
*/
|
|
190
|
-
function getActualIndentationForListItemBeforeComma(commaToken, sourceFile, options) {
|
|
191
|
-
// previous token is comma that separates items in list - find the previous item and try to derive indentation from it
|
|
192
|
-
const commaItemInfo = findListItemInfo(commaToken);
|
|
193
|
-
if (commaItemInfo && commaItemInfo.listItemIndex > 0) {
|
|
194
|
-
return deriveActualIndentationFromList(commaItemInfo.list.getChildren(), commaItemInfo.listItemIndex - 1, sourceFile, options);
|
|
195
|
-
}
|
|
196
|
-
else {
|
|
197
|
-
// handle broken code gracefully
|
|
198
|
-
return -1 /* Value.Unknown */;
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
/*
|
|
202
|
-
* Function returns Value.Unknown if actual indentation for node should not be used (i.e because node is nested expression)
|
|
203
|
-
*/
|
|
204
|
-
function getActualIndentationForNode(current, parent, currentLineAndChar, parentAndChildShareLine, sourceFile, options) {
|
|
205
|
-
// actual indentation is used for statements\declarations if one of cases below is true:
|
|
206
|
-
// - parent is SourceFile - by default immediate children of SourceFile are not indented except when user indents them manually
|
|
207
|
-
// - parent and child are not on the same line
|
|
208
|
-
const useActualIndentation = (isDeclaration(current) || isStatementButNotDeclaration(current)) &&
|
|
209
|
-
(parent.kind === SyntaxKind.SourceFile || !parentAndChildShareLine);
|
|
210
|
-
if (!useActualIndentation) {
|
|
211
|
-
return -1 /* Value.Unknown */;
|
|
212
|
-
}
|
|
213
|
-
return findColumnForFirstNonWhitespaceCharacterInLine(currentLineAndChar, sourceFile, options);
|
|
214
|
-
}
|
|
215
|
-
let NextTokenKind;
|
|
216
|
-
(function (NextTokenKind) {
|
|
217
|
-
NextTokenKind[NextTokenKind["Unknown"] = 0] = "Unknown";
|
|
218
|
-
NextTokenKind[NextTokenKind["OpenBrace"] = 1] = "OpenBrace";
|
|
219
|
-
NextTokenKind[NextTokenKind["CloseBrace"] = 2] = "CloseBrace";
|
|
220
|
-
})(NextTokenKind || (NextTokenKind = {}));
|
|
221
|
-
function nextTokenIsCurlyBraceOnSameLineAsCursor(precedingToken, current, lineAtPosition, sourceFile) {
|
|
222
|
-
const nextToken = findNextToken(precedingToken, current, sourceFile);
|
|
223
|
-
if (!nextToken) {
|
|
224
|
-
return 0 /* NextTokenKind.Unknown */;
|
|
225
|
-
}
|
|
226
|
-
if (nextToken.kind === SyntaxKind.OpenBraceToken) {
|
|
227
|
-
// open braces are always indented at the parent level
|
|
228
|
-
return 1 /* NextTokenKind.OpenBrace */;
|
|
229
|
-
}
|
|
230
|
-
else if (nextToken.kind === SyntaxKind.CloseBraceToken) {
|
|
231
|
-
// close braces are indented at the parent level if they are located on the same line with cursor
|
|
232
|
-
// this means that if new line will be added at $ position, this case will be indented
|
|
233
|
-
// class A {
|
|
234
|
-
// $
|
|
235
|
-
// }
|
|
236
|
-
/// and this one - not
|
|
237
|
-
// class A {
|
|
238
|
-
// $}
|
|
239
|
-
const nextTokenStartLine = getStartLineAndCharacterForNode(nextToken, sourceFile).line;
|
|
240
|
-
return lineAtPosition === nextTokenStartLine ? 2 /* NextTokenKind.CloseBrace */ : 0 /* NextTokenKind.Unknown */;
|
|
241
|
-
}
|
|
242
|
-
return 0 /* NextTokenKind.Unknown */;
|
|
243
|
-
}
|
|
244
|
-
function getStartLineAndCharacterForNode(n, sourceFile) {
|
|
245
|
-
return sourceFile.getLineAndCharacterOfPosition(n.getStart(sourceFile));
|
|
246
|
-
}
|
|
247
|
-
function isArgumentAndStartLineOverlapsExpressionBeingCalled(parent, child, childStartLine, sourceFile) {
|
|
248
|
-
if (!(isCallExpression(parent) && contains(parent.arguments, child))) {
|
|
249
|
-
return false;
|
|
250
|
-
}
|
|
251
|
-
const expressionOfCallExpressionEnd = parent.expression.getEnd();
|
|
252
|
-
const expressionOfCallExpressionEndLine = getLineAndCharacterOfPosition(sourceFile, expressionOfCallExpressionEnd).line;
|
|
253
|
-
return expressionOfCallExpressionEndLine === childStartLine;
|
|
254
|
-
}
|
|
255
|
-
SmartIndenter.isArgumentAndStartLineOverlapsExpressionBeingCalled = isArgumentAndStartLineOverlapsExpressionBeingCalled;
|
|
256
|
-
function childStartsOnTheSameLineWithElseInIfStatement(parent, child, childStartLine, sourceFile) {
|
|
257
|
-
if (parent.kind === SyntaxKind.IfStatement && parent.elseStatement === child) {
|
|
258
|
-
const elseKeyword = findChildOfKind(parent, SyntaxKind.ElseKeyword, sourceFile);
|
|
259
|
-
Debug.assert(elseKeyword !== undefined);
|
|
260
|
-
const elseKeywordStartLine = getStartLineAndCharacterForNode(elseKeyword, sourceFile).line;
|
|
261
|
-
return elseKeywordStartLine === childStartLine;
|
|
262
|
-
}
|
|
263
|
-
return false;
|
|
264
|
-
}
|
|
265
|
-
SmartIndenter.childStartsOnTheSameLineWithElseInIfStatement = childStartsOnTheSameLineWithElseInIfStatement;
|
|
266
|
-
function argumentStartsOnSameLineAsPreviousArgument(parent, child, childStartLine, sourceFile) {
|
|
267
|
-
if (isCallOrNewExpression(parent)) {
|
|
268
|
-
if (!parent.arguments)
|
|
269
|
-
return false;
|
|
270
|
-
const currentNode = find(parent.arguments, arg => arg.pos === child.pos);
|
|
271
|
-
// If it's not one of the arguments, don't look past this
|
|
272
|
-
if (!currentNode)
|
|
273
|
-
return false;
|
|
274
|
-
const currentIndex = parent.arguments.indexOf(currentNode);
|
|
275
|
-
if (currentIndex === 0)
|
|
276
|
-
return false; // Can't look at previous node if first
|
|
277
|
-
const previousNode = parent.arguments[currentIndex - 1];
|
|
278
|
-
const lineOfPreviousNode = getLineAndCharacterOfPosition(sourceFile, previousNode.getEnd()).line;
|
|
279
|
-
if (childStartLine === lineOfPreviousNode) {
|
|
280
|
-
return true;
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
return false;
|
|
284
|
-
}
|
|
285
|
-
SmartIndenter.argumentStartsOnSameLineAsPreviousArgument = argumentStartsOnSameLineAsPreviousArgument;
|
|
286
|
-
function getContainingList(node, sourceFile) {
|
|
287
|
-
return node.parent && getListByRange(node.getStart(sourceFile), node.getEnd(), node.parent, sourceFile);
|
|
288
|
-
}
|
|
289
|
-
SmartIndenter.getContainingList = getContainingList;
|
|
290
|
-
function getListByPosition(pos, node, sourceFile) {
|
|
291
|
-
return node && getListByRange(pos, pos, node, sourceFile);
|
|
292
|
-
}
|
|
293
|
-
function getListByRange(start, end, node, sourceFile) {
|
|
294
|
-
switch (node.kind) {
|
|
295
|
-
case SyntaxKind.TypeReference:
|
|
296
|
-
return getList(node.typeArguments);
|
|
297
|
-
case SyntaxKind.ObjectLiteralExpression:
|
|
298
|
-
return getList(node.properties);
|
|
299
|
-
case SyntaxKind.ArrayLiteralExpression:
|
|
300
|
-
return getList(node.elements);
|
|
301
|
-
case SyntaxKind.TypeLiteral:
|
|
302
|
-
return getList(node.members);
|
|
303
|
-
// Na tag, também a `function`, a function expression, o método, o construtor, o tipo construtor e a construct
|
|
304
|
-
// signature (CK-02), e a method signature (CK-36).
|
|
305
|
-
case SyntaxKind.ArrowFunction:
|
|
306
|
-
case SyntaxKind.CallSignature:
|
|
307
|
-
return getList(node.typeParameters) || getList(node.parameters);
|
|
308
|
-
// Na tag, também a classe, a class expression e a interface (CK-02), e o `@template` do JSDoc (CK-03).
|
|
309
|
-
case SyntaxKind.TypeAliasDeclaration:
|
|
310
|
-
return getList(node.typeParameters);
|
|
311
|
-
// Na tag, também o `new` (CK-02).
|
|
312
|
-
case SyntaxKind.CallExpression:
|
|
313
|
-
return getList(node.typeArguments) || getList(node.arguments);
|
|
314
|
-
case SyntaxKind.VariableDeclarationList:
|
|
315
|
-
return getList(node.declarations);
|
|
316
|
-
case SyntaxKind.NamedImports:
|
|
317
|
-
case SyntaxKind.NamedExports:
|
|
318
|
-
return getList(node.elements);
|
|
319
|
-
case SyntaxKind.ObjectBindingPattern:
|
|
320
|
-
case SyntaxKind.ArrayBindingPattern:
|
|
321
|
-
return getList(node.elements);
|
|
322
|
-
}
|
|
323
|
-
function getList(list) {
|
|
324
|
-
return list && rangeContainsStartEnd(getVisualListRange(node, list, sourceFile), start, end) ? list : undefined;
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
|
-
function getVisualListRange(node, list, sourceFile) {
|
|
328
|
-
const children = node.getChildren(sourceFile);
|
|
329
|
-
for (let i = 1; i < children.length - 1; i++) {
|
|
330
|
-
if (children[i].pos === list.pos && children[i].end === list.end) {
|
|
331
|
-
return { pos: children[i - 1].end, end: children[i + 1].getStart(sourceFile) };
|
|
332
|
-
}
|
|
333
|
-
}
|
|
334
|
-
return list;
|
|
335
|
-
}
|
|
336
|
-
function getActualIndentationForListStartLine(list, sourceFile, options) {
|
|
337
|
-
if (!list) {
|
|
338
|
-
return -1 /* Value.Unknown */;
|
|
339
|
-
}
|
|
340
|
-
return findColumnForFirstNonWhitespaceCharacterInLine(sourceFile.getLineAndCharacterOfPosition(list.pos), sourceFile, options);
|
|
341
|
-
}
|
|
342
|
-
function getActualIndentationForListItem(node, sourceFile, options, listIndentsChild) {
|
|
343
|
-
if (node.parent && node.parent.kind === SyntaxKind.VariableDeclarationList) {
|
|
344
|
-
// VariableDeclarationList has no wrapping tokens
|
|
345
|
-
return -1 /* Value.Unknown */;
|
|
346
|
-
}
|
|
347
|
-
const containingList = getContainingList(node, sourceFile);
|
|
348
|
-
if (containingList) {
|
|
349
|
-
const index = containingList.indexOf(node);
|
|
350
|
-
if (index !== -1) {
|
|
351
|
-
const result = deriveActualIndentationFromList(containingList, index, sourceFile, options);
|
|
352
|
-
if (result !== -1 /* Value.Unknown */) {
|
|
353
|
-
return result;
|
|
354
|
-
}
|
|
355
|
-
}
|
|
356
|
-
return getActualIndentationForListStartLine(containingList, sourceFile, options) + (listIndentsChild ? options.indentSize : 0); // TODO: GH#18217
|
|
357
|
-
}
|
|
358
|
-
return -1 /* Value.Unknown */;
|
|
359
|
-
}
|
|
360
|
-
function deriveActualIndentationFromList(list, index, sourceFile, options) {
|
|
361
|
-
Debug.assert(index >= 0 && index < list.length);
|
|
362
|
-
const node = list[index];
|
|
363
|
-
// walk toward the start of the list starting from current node and check if the line is the same for all items.
|
|
364
|
-
// if end line for item [i - 1] differs from the start line for item [i] - find column of the first non-whitespace character on the line of item [i]
|
|
365
|
-
let lineAndCharacter = getStartLineAndCharacterForNode(node, sourceFile);
|
|
366
|
-
for (let i = index - 1; i >= 0; i--) {
|
|
367
|
-
if (list[i].kind === SyntaxKind.CommaToken) {
|
|
368
|
-
continue;
|
|
369
|
-
}
|
|
370
|
-
// skip list items that ends on the same line with the current list element
|
|
371
|
-
const prevEndLine = sourceFile.getLineAndCharacterOfPosition(list[i].end).line;
|
|
372
|
-
if (prevEndLine !== lineAndCharacter.line) {
|
|
373
|
-
return findColumnForFirstNonWhitespaceCharacterInLine(lineAndCharacter, sourceFile, options);
|
|
374
|
-
}
|
|
375
|
-
lineAndCharacter = getStartLineAndCharacterForNode(list[i], sourceFile);
|
|
376
|
-
}
|
|
377
|
-
return -1 /* Value.Unknown */;
|
|
378
|
-
}
|
|
379
|
-
function findColumnForFirstNonWhitespaceCharacterInLine(lineAndCharacter, sourceFile, options) {
|
|
380
|
-
const lineStart = sourceFile.getPositionOfLineAndCharacter(lineAndCharacter.line, 0);
|
|
381
|
-
return findFirstNonWhitespaceColumn(lineStart, lineStart + lineAndCharacter.character, sourceFile, options);
|
|
382
|
-
}
|
|
383
|
-
/**
|
|
384
|
-
* Character is the actual index of the character since the beginning of the line.
|
|
385
|
-
* Column - position of the character after expanding tabs to spaces.
|
|
386
|
-
* "0\t2$"
|
|
387
|
-
* value of 'character' for '$' is 3
|
|
388
|
-
* value of 'column' for '$' is 6 (assuming that tab size is 4)
|
|
389
|
-
*/
|
|
390
|
-
function findFirstNonWhitespaceCharacterAndColumn(startPos, endPos, sourceFile, options) {
|
|
391
|
-
let character = 0;
|
|
392
|
-
let column = 0;
|
|
393
|
-
for (let pos = startPos; pos < endPos; pos++) {
|
|
394
|
-
const ch = sourceFile.text.charCodeAt(pos);
|
|
395
|
-
if (!isWhiteSpaceSingleLine(ch)) {
|
|
396
|
-
break;
|
|
397
|
-
}
|
|
398
|
-
if (ch === CharacterCodes.tab) {
|
|
399
|
-
column += options.tabSize + (column % options.tabSize);
|
|
400
|
-
}
|
|
401
|
-
else {
|
|
402
|
-
column++;
|
|
403
|
-
}
|
|
404
|
-
character++;
|
|
405
|
-
}
|
|
406
|
-
return { column, character };
|
|
407
|
-
}
|
|
408
|
-
SmartIndenter.findFirstNonWhitespaceCharacterAndColumn = findFirstNonWhitespaceCharacterAndColumn;
|
|
409
|
-
function findFirstNonWhitespaceColumn(startPos, endPos, sourceFile, options) {
|
|
410
|
-
return findFirstNonWhitespaceCharacterAndColumn(startPos, endPos, sourceFile, options).column;
|
|
411
|
-
}
|
|
412
|
-
SmartIndenter.findFirstNonWhitespaceColumn = findFirstNonWhitespaceColumn;
|
|
413
|
-
function nodeWillIndentChild(settings, parent, child, sourceFile, indentByDefault) {
|
|
414
|
-
const childKind = child ? child.kind : SyntaxKind.Unknown;
|
|
415
|
-
switch (parent.kind) {
|
|
416
|
-
// Na tag, também a classe, a class expression, a interface, o enum, o `new`, a construct signature, o tipo
|
|
417
|
-
// construtor, o template marcado e a propriedade de classe (CK-02), e a method signature (CK-36).
|
|
418
|
-
case SyntaxKind.ExpressionStatement:
|
|
419
|
-
case SyntaxKind.TypeAliasDeclaration:
|
|
420
|
-
case SyntaxKind.ArrayLiteralExpression:
|
|
421
|
-
case SyntaxKind.Block:
|
|
422
|
-
case SyntaxKind.ModuleBlock:
|
|
423
|
-
case SyntaxKind.ObjectLiteralExpression:
|
|
424
|
-
case SyntaxKind.TypeLiteral:
|
|
425
|
-
case SyntaxKind.MappedType:
|
|
426
|
-
case SyntaxKind.TupleType:
|
|
427
|
-
case SyntaxKind.CaseBlock:
|
|
428
|
-
case SyntaxKind.DefaultClause:
|
|
429
|
-
case SyntaxKind.CaseClause:
|
|
430
|
-
case SyntaxKind.ParenthesizedExpression:
|
|
431
|
-
case SyntaxKind.PropertyAccessExpression:
|
|
432
|
-
case SyntaxKind.CallExpression:
|
|
433
|
-
case SyntaxKind.VariableStatement:
|
|
434
|
-
case SyntaxKind.ExportAssignment:
|
|
435
|
-
case SyntaxKind.ReturnStatement:
|
|
436
|
-
case SyntaxKind.ConditionalExpression:
|
|
437
|
-
case SyntaxKind.ArrayBindingPattern:
|
|
438
|
-
case SyntaxKind.ObjectBindingPattern:
|
|
439
|
-
case SyntaxKind.JsxOpeningElement:
|
|
440
|
-
case SyntaxKind.JsxOpeningFragment:
|
|
441
|
-
case SyntaxKind.JsxSelfClosingElement:
|
|
442
|
-
case SyntaxKind.JsxExpression:
|
|
443
|
-
case SyntaxKind.CallSignature:
|
|
444
|
-
case SyntaxKind.Parameter:
|
|
445
|
-
case SyntaxKind.FunctionType:
|
|
446
|
-
case SyntaxKind.ParenthesizedType:
|
|
447
|
-
case SyntaxKind.AwaitExpression:
|
|
448
|
-
case SyntaxKind.NamedExports:
|
|
449
|
-
case SyntaxKind.NamedImports:
|
|
450
|
-
case SyntaxKind.ExportSpecifier:
|
|
451
|
-
case SyntaxKind.ImportSpecifier:
|
|
452
|
-
return true;
|
|
453
|
-
case SyntaxKind.VariableDeclaration:
|
|
454
|
-
case SyntaxKind.PropertyAssignment:
|
|
455
|
-
case SyntaxKind.BinaryExpression:
|
|
456
|
-
if (!settings.indentMultiLineObjectLiteralBeginningOnBlankLine && sourceFile && childKind === SyntaxKind.ObjectLiteralExpression) { // TODO: GH#18217
|
|
457
|
-
return rangeIsOnOneLine(sourceFile, child);
|
|
458
|
-
}
|
|
459
|
-
if (parent.kind !== SyntaxKind.BinaryExpression) {
|
|
460
|
-
return true;
|
|
461
|
-
}
|
|
462
|
-
break;
|
|
463
|
-
case SyntaxKind.DoStatement:
|
|
464
|
-
case SyntaxKind.WhileStatement:
|
|
465
|
-
case SyntaxKind.ForInStatement:
|
|
466
|
-
case SyntaxKind.ForOfStatement:
|
|
467
|
-
case SyntaxKind.ForStatement:
|
|
468
|
-
case SyntaxKind.IfStatement:
|
|
469
|
-
// Na tag, também a `function`, a function expression, o método, o construtor e o acessor (CK-02).
|
|
470
|
-
case SyntaxKind.ArrowFunction:
|
|
471
|
-
return childKind !== SyntaxKind.Block;
|
|
472
|
-
case SyntaxKind.ExportDeclaration:
|
|
473
|
-
return childKind !== SyntaxKind.NamedExports;
|
|
474
|
-
case SyntaxKind.ImportDeclaration:
|
|
475
|
-
return childKind !== SyntaxKind.ImportClause ||
|
|
476
|
-
(!!child.namedBindings && child.namedBindings.kind !== SyntaxKind.NamedImports);
|
|
477
|
-
case SyntaxKind.JsxElement:
|
|
478
|
-
return childKind !== SyntaxKind.JsxClosingElement;
|
|
479
|
-
case SyntaxKind.JsxFragment:
|
|
480
|
-
return childKind !== SyntaxKind.JsxClosingFragment;
|
|
481
|
-
case SyntaxKind.IntersectionType:
|
|
482
|
-
case SyntaxKind.UnionType:
|
|
483
|
-
if (childKind === SyntaxKind.TypeLiteral) {
|
|
484
|
-
return false;
|
|
485
|
-
}
|
|
486
|
-
// falls through
|
|
487
|
-
}
|
|
488
|
-
// No explicit rule for given nodes so the result will follow the default value argument
|
|
489
|
-
return indentByDefault;
|
|
490
|
-
}
|
|
491
|
-
SmartIndenter.nodeWillIndentChild = nodeWillIndentChild;
|
|
492
|
-
function isControlFlowEndingStatement(kind, parent) {
|
|
493
|
-
switch (kind) {
|
|
494
|
-
case SyntaxKind.ReturnStatement:
|
|
495
|
-
case SyntaxKind.ThrowStatement:
|
|
496
|
-
case SyntaxKind.ContinueStatement:
|
|
497
|
-
case SyntaxKind.BreakStatement:
|
|
498
|
-
return parent.kind !== SyntaxKind.Block;
|
|
499
|
-
default:
|
|
500
|
-
return false;
|
|
501
|
-
}
|
|
502
|
-
}
|
|
503
|
-
/**
|
|
504
|
-
* True when the parent node should indent the given child by an explicit rule.
|
|
505
|
-
* @param isNextChild If true, we are judging indent of a hypothetical child *after* this one, not the current child.
|
|
506
|
-
*/
|
|
507
|
-
function shouldIndentChildNode(settings, parent, child, sourceFile, isNextChild = false) {
|
|
508
|
-
return nodeWillIndentChild(settings, parent, child, sourceFile, /*indentByDefault*/ false)
|
|
509
|
-
&& !(isNextChild && child && isControlFlowEndingStatement(child.kind, parent));
|
|
510
|
-
}
|
|
511
|
-
SmartIndenter.shouldIndentChildNode = shouldIndentChildNode;
|
|
512
|
-
function rangeIsOnOneLine(sourceFile, range) {
|
|
513
|
-
const rangeStart = skipTrivia(sourceFile.text, range.pos);
|
|
514
|
-
const startLine = sourceFile.getLineAndCharacterOfPosition(rangeStart).line;
|
|
515
|
-
const endLine = sourceFile.getLineAndCharacterOfPosition(range.end).line;
|
|
516
|
-
return startLine === endLine;
|
|
517
|
-
}
|
|
518
|
-
})(SmartIndenter || (SmartIndenter = {}));
|