@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,148 +0,0 @@
|
|
|
1
|
-
// Modificado de microsoft/TypeScript v3.9.10, src/services/refactors/convertStringOrTemplateLiteral.ts: o namespace virou módulo ES, com os imports explícitos.
|
|
2
|
-
import { Debug, Diagnostics, SyntaxKind, copyTrailingAsLeadingComments, copyTrailingComments, createNoSubstitutionTemplateLiteral, createTemplateExpression, createTemplateHead, createTemplateMiddle, createTemplateSpan, createTemplateTail, emptyArray, getLocaleSpecificMessage, getTokenAtPosition, getTrailingCommentRanges, isBinaryExpression, isParenthesizedExpression, isStringLiteral, textChanges, } from "../_namespaces/edit.js";
|
|
3
|
-
import { registerRefactor, } from "../_namespaces/ts.refactor.js";
|
|
4
|
-
const refactorName = "Convert to template string";
|
|
5
|
-
const refactorDescription = getLocaleSpecificMessage(Diagnostics.Convert_to_template_string);
|
|
6
|
-
registerRefactor(refactorName, { getEditsForAction, getAvailableActions });
|
|
7
|
-
function getAvailableActions(context) {
|
|
8
|
-
const { file, startPosition } = context;
|
|
9
|
-
const node = getNodeOrParentOfParentheses(file, startPosition);
|
|
10
|
-
const maybeBinary = getParentBinaryExpression(node);
|
|
11
|
-
const refactorInfo = { name: refactorName, description: refactorDescription, actions: [] };
|
|
12
|
-
if (isBinaryExpression(maybeBinary) && isStringConcatenationValid(maybeBinary)) {
|
|
13
|
-
refactorInfo.actions.push({ name: refactorName, description: refactorDescription });
|
|
14
|
-
return [refactorInfo];
|
|
15
|
-
}
|
|
16
|
-
return emptyArray;
|
|
17
|
-
}
|
|
18
|
-
function getNodeOrParentOfParentheses(file, startPosition) {
|
|
19
|
-
const node = getTokenAtPosition(file, startPosition);
|
|
20
|
-
const nestedBinary = getParentBinaryExpression(node);
|
|
21
|
-
const isNonStringBinary = !isStringConcatenationValid(nestedBinary);
|
|
22
|
-
if (isNonStringBinary &&
|
|
23
|
-
isParenthesizedExpression(nestedBinary.parent) &&
|
|
24
|
-
isBinaryExpression(nestedBinary.parent.parent)) {
|
|
25
|
-
return nestedBinary.parent.parent;
|
|
26
|
-
}
|
|
27
|
-
return node;
|
|
28
|
-
}
|
|
29
|
-
function getEditsForAction(context, actionName) {
|
|
30
|
-
const { file, startPosition } = context;
|
|
31
|
-
const node = getNodeOrParentOfParentheses(file, startPosition);
|
|
32
|
-
switch (actionName) {
|
|
33
|
-
case refactorDescription:
|
|
34
|
-
return { edits: getEditsForToTemplateLiteral(context, node) };
|
|
35
|
-
default:
|
|
36
|
-
return Debug.fail("invalid action");
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
function getEditsForToTemplateLiteral(context, node) {
|
|
40
|
-
const maybeBinary = getParentBinaryExpression(node);
|
|
41
|
-
const file = context.file;
|
|
42
|
-
const templateLiteral = nodesToTemplate(treeToArray(maybeBinary), file);
|
|
43
|
-
const trailingCommentRanges = getTrailingCommentRanges(file.text, maybeBinary.end);
|
|
44
|
-
if (trailingCommentRanges) {
|
|
45
|
-
const lastComment = trailingCommentRanges[trailingCommentRanges.length - 1];
|
|
46
|
-
const trailingRange = { pos: trailingCommentRanges[0].pos, end: lastComment.end };
|
|
47
|
-
// since suppressTrailingTrivia(maybeBinary) does not work, the trailing comment is removed manually
|
|
48
|
-
// otherwise it would have the trailing comment twice
|
|
49
|
-
return textChanges.ChangeTracker.with(context, t => {
|
|
50
|
-
t.deleteRange(file, trailingRange);
|
|
51
|
-
t.replaceNode(file, maybeBinary, templateLiteral);
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
else {
|
|
55
|
-
return textChanges.ChangeTracker.with(context, t => t.replaceNode(file, maybeBinary, templateLiteral));
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
function isNotEqualsOperator(node) {
|
|
59
|
-
return node.operatorToken.kind !== SyntaxKind.EqualsToken;
|
|
60
|
-
}
|
|
61
|
-
function getParentBinaryExpression(expr) {
|
|
62
|
-
while (isBinaryExpression(expr.parent) && isNotEqualsOperator(expr.parent)) {
|
|
63
|
-
expr = expr.parent;
|
|
64
|
-
}
|
|
65
|
-
return expr;
|
|
66
|
-
}
|
|
67
|
-
function isStringConcatenationValid(node) {
|
|
68
|
-
const { containsString, areOperatorsValid } = treeToArray(node);
|
|
69
|
-
return containsString && areOperatorsValid;
|
|
70
|
-
}
|
|
71
|
-
function treeToArray(current) {
|
|
72
|
-
if (isBinaryExpression(current)) {
|
|
73
|
-
const { nodes, operators, containsString: leftHasString, areOperatorsValid: leftOperatorValid } = treeToArray(current.left);
|
|
74
|
-
if (!leftHasString && !isStringLiteral(current.right)) {
|
|
75
|
-
return { nodes: [current], operators: [], containsString: false, areOperatorsValid: true };
|
|
76
|
-
}
|
|
77
|
-
const currentOperatorValid = current.operatorToken.kind === SyntaxKind.PlusToken;
|
|
78
|
-
const areOperatorsValid = leftOperatorValid && currentOperatorValid;
|
|
79
|
-
nodes.push(current.right);
|
|
80
|
-
operators.push(current.operatorToken);
|
|
81
|
-
return { nodes, operators, containsString: true, areOperatorsValid };
|
|
82
|
-
}
|
|
83
|
-
return { nodes: [current], operators: [], containsString: isStringLiteral(current), areOperatorsValid: true };
|
|
84
|
-
}
|
|
85
|
-
// to copy comments following the operator
|
|
86
|
-
// "foo" + /* comment */ "bar"
|
|
87
|
-
const copyTrailingOperatorComments = (operators, file) => (index, targetNode) => {
|
|
88
|
-
if (index < operators.length) {
|
|
89
|
-
copyTrailingComments(operators[index], targetNode, file, SyntaxKind.MultiLineCommentTrivia, /* hasTrailingNewLine */ false);
|
|
90
|
-
}
|
|
91
|
-
};
|
|
92
|
-
// to copy comments following the string
|
|
93
|
-
// "foo" /* comment */ + "bar" /* comment */ + "bar2"
|
|
94
|
-
const copyCommentFromMultiNode = (nodes, file, copyOperatorComments) => (indexes, targetNode) => {
|
|
95
|
-
while (indexes.length > 0) {
|
|
96
|
-
const index = indexes.shift();
|
|
97
|
-
copyTrailingComments(nodes[index], targetNode, file, SyntaxKind.MultiLineCommentTrivia, /* hasTrailingNewLine */ false);
|
|
98
|
-
copyOperatorComments(index, targetNode);
|
|
99
|
-
}
|
|
100
|
-
};
|
|
101
|
-
function concatConsecutiveString(index, nodes) {
|
|
102
|
-
let text = "";
|
|
103
|
-
const indexes = [];
|
|
104
|
-
while (index < nodes.length && isStringLiteral(nodes[index])) {
|
|
105
|
-
const stringNode = nodes[index];
|
|
106
|
-
text = text + stringNode.text;
|
|
107
|
-
indexes.push(index);
|
|
108
|
-
index++;
|
|
109
|
-
}
|
|
110
|
-
return [index, text, indexes];
|
|
111
|
-
}
|
|
112
|
-
function nodesToTemplate({ nodes, operators }, file) {
|
|
113
|
-
const copyOperatorComments = copyTrailingOperatorComments(operators, file);
|
|
114
|
-
const copyCommentFromStringLiterals = copyCommentFromMultiNode(nodes, file, copyOperatorComments);
|
|
115
|
-
const [begin, headText, headIndexes] = concatConsecutiveString(0, nodes);
|
|
116
|
-
if (begin === nodes.length) {
|
|
117
|
-
const noSubstitutionTemplateLiteral = createNoSubstitutionTemplateLiteral(headText);
|
|
118
|
-
copyCommentFromStringLiterals(headIndexes, noSubstitutionTemplateLiteral);
|
|
119
|
-
return noSubstitutionTemplateLiteral;
|
|
120
|
-
}
|
|
121
|
-
const templateSpans = [];
|
|
122
|
-
const templateHead = createTemplateHead(headText);
|
|
123
|
-
copyCommentFromStringLiterals(headIndexes, templateHead);
|
|
124
|
-
for (let i = begin; i < nodes.length; i++) {
|
|
125
|
-
const currentNode = getExpressionFromParenthesesOrExpression(nodes[i]);
|
|
126
|
-
copyOperatorComments(i, currentNode);
|
|
127
|
-
const [newIndex, subsequentText, stringIndexes] = concatConsecutiveString(i + 1, nodes);
|
|
128
|
-
i = newIndex - 1;
|
|
129
|
-
const templatePart = i === nodes.length - 1 ? createTemplateTail(subsequentText) : createTemplateMiddle(subsequentText);
|
|
130
|
-
copyCommentFromStringLiterals(stringIndexes, templatePart);
|
|
131
|
-
templateSpans.push(createTemplateSpan(currentNode, templatePart));
|
|
132
|
-
}
|
|
133
|
-
return createTemplateExpression(templateHead, templateSpans);
|
|
134
|
-
}
|
|
135
|
-
// to copy comments following the opening & closing parentheses
|
|
136
|
-
// "foo" + ( /* comment */ 5 + 5 ) /* comment */ + "bar"
|
|
137
|
-
function copyCommentsWhenParenthesized(node) {
|
|
138
|
-
const file = node.getSourceFile();
|
|
139
|
-
copyTrailingComments(node, node.expression, file, SyntaxKind.MultiLineCommentTrivia, /* hasTrailingNewLine */ false);
|
|
140
|
-
copyTrailingAsLeadingComments(node.expression, node.expression, file, SyntaxKind.MultiLineCommentTrivia, /* hasTrailingNewLine */ false);
|
|
141
|
-
}
|
|
142
|
-
function getExpressionFromParenthesesOrExpression(node) {
|
|
143
|
-
if (isParenthesizedExpression(node)) {
|
|
144
|
-
copyCommentsWhenParenthesized(node);
|
|
145
|
-
node = node.expression;
|
|
146
|
-
}
|
|
147
|
-
return node;
|
|
148
|
-
}
|