Skip to content

Commit 502e988

Browse files
committed
Merge remote-tracking branch 'origin/main' into fix/mapped-type-dts-emit-type-param-constraint
2 parents 2e29ffe + 8179321 commit 502e988

81 files changed

Lines changed: 7085 additions & 328 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.dprint.jsonc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@
5656
],
5757
// Note: if adding new languages, make sure settings.template.json is updated too.
5858
"plugins": [
59-
"https://plugins.dprint.dev/typescript-0.88.3.wasm",
60-
"https://plugins.dprint.dev/json-0.19.0.wasm",
61-
"https://plugins.dprint.dev/prettier-0.27.0.json@3557a62b4507c55a47d8cde0683195b14d13c41dda66d0f0b0e111aed107e2fe"
59+
"https://plugins.dprint.dev/typescript-0.88.8.wasm",
60+
"https://plugins.dprint.dev/json-0.19.1.wasm",
61+
"https://plugins.dprint.dev/prettier-0.32.1.json@19aa403ef0862ba8c41164e3dc6f84c0b7a66c2b11e42726b23dd25e6302ada9"
6262
]
6363
}

package-lock.json

Lines changed: 159 additions & 159 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
"chalk": "^4.1.2",
6060
"chokidar": "^3.5.3",
6161
"diff": "^5.1.0",
62-
"dprint": "^0.42.3",
62+
"dprint": "^0.45.0",
6363
"esbuild": "^0.19.0",
6464
"eslint": "^8.22.0",
6565
"eslint-formatter-autolinkable-stylish": "^1.2.0",

src/compiler/checker.ts

Lines changed: 203 additions & 59 deletions
Large diffs are not rendered by default.

src/compiler/emitter.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3607,7 +3607,14 @@ export function createPrinter(printerOptions: PrinterOptions = {}, handlers: Pri
36073607

36083608
function willEmitLeadingNewLine(node: Expression): boolean {
36093609
if (!currentSourceFile) return false;
3610-
if (some(getLeadingCommentRanges(currentSourceFile.text, node.pos), commentWillEmitNewLine)) return true;
3610+
const leadingCommentRanges = getLeadingCommentRanges(currentSourceFile.text, node.pos);
3611+
if (leadingCommentRanges) {
3612+
const parseNode = getParseTreeNode(node);
3613+
if (parseNode && isParenthesizedExpression(parseNode.parent)) {
3614+
return true;
3615+
}
3616+
}
3617+
if (some(leadingCommentRanges, commentWillEmitNewLine)) return true;
36113618
if (some(getSyntheticLeadingComments(node), commentWillEmitNewLine)) return true;
36123619
if (isPartiallyEmittedExpression(node)) {
36133620
if (node.pos !== node.expression.pos) {

src/compiler/types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5825,8 +5825,8 @@ export interface Symbol {
58255825
/** @internal */ exportSymbol?: Symbol; // Exported symbol associated with this symbol
58265826
/** @internal */ constEnumOnlyModule: boolean | undefined; // True if module contains only const enums or other modules with only const enums
58275827
/** @internal */ isReferenced?: SymbolFlags; // True if the symbol is referenced elsewhere. Keeps track of the meaning of a reference in case a symbol is both a type parameter and parameter.
5828+
/** @internal */ lastAssignmentPos?: number; // Source position of last node that assigns value to symbol
58285829
/** @internal */ isReplaceableByMethod?: boolean; // Can this Javascript class property be replaced by a method symbol?
5829-
/** @internal */ isAssigned?: boolean; // True if the symbol is a parameter with assignments
58305830
/** @internal */ assignmentDeclarationMembers?: Map<number, Declaration>; // detected late-bound assignment declarations associated with the symbol
58315831
}
58325832

@@ -10074,6 +10074,7 @@ export interface UserPreferences {
1007410074
readonly organizeImportsNumericCollation?: boolean;
1007510075
readonly organizeImportsAccentCollation?: boolean;
1007610076
readonly organizeImportsCaseFirst?: "upper" | "lower" | false;
10077+
readonly organizeImportsTypeOrder?: "first" | "last" | "inline";
1007710078
readonly excludeLibrarySymbolsInNavTo?: boolean;
1007810079
}
1007910080

src/compiler/utilities.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,7 @@ import {
282282
isJSDoc,
283283
isJSDocAugmentsTag,
284284
isJSDocFunctionType,
285+
isJSDocImplementsTag,
285286
isJSDocLinkLike,
286287
isJSDocMemberName,
287288
isJSDocNameReference,
@@ -2452,7 +2453,7 @@ export function isPartOfTypeNode(node: Node): boolean {
24522453
case SyntaxKind.VoidKeyword:
24532454
return node.parent.kind !== SyntaxKind.VoidExpression;
24542455
case SyntaxKind.ExpressionWithTypeArguments:
2455-
return isHeritageClause(node.parent) && !isExpressionWithTypeArgumentsInClassExtendsClause(node);
2456+
return isPartOfTypeExpressionWithTypeArguments(node);
24562457
case SyntaxKind.TypeParameter:
24572458
return node.parent.kind === SyntaxKind.MappedType || node.parent.kind === SyntaxKind.InferType;
24582459

@@ -2491,7 +2492,7 @@ export function isPartOfTypeNode(node: Node): boolean {
24912492
}
24922493
switch (parent.kind) {
24932494
case SyntaxKind.ExpressionWithTypeArguments:
2494-
return isHeritageClause(parent.parent) && !isExpressionWithTypeArgumentsInClassExtendsClause(parent);
2495+
return isPartOfTypeExpressionWithTypeArguments(parent);
24952496
case SyntaxKind.TypeParameter:
24962497
return node === (parent as TypeParameterDeclaration).constraint;
24972498
case SyntaxKind.JSDocTemplateTag:
@@ -2527,6 +2528,12 @@ export function isPartOfTypeNode(node: Node): boolean {
25272528
return false;
25282529
}
25292530

2531+
function isPartOfTypeExpressionWithTypeArguments(node: Node) {
2532+
return isJSDocImplementsTag(node.parent)
2533+
|| isJSDocAugmentsTag(node.parent)
2534+
|| isHeritageClause(node.parent) && !isExpressionWithTypeArgumentsInClassExtendsClause(node);
2535+
}
2536+
25302537
/** @internal */
25312538
export function isChildOfNodeWithKind(node: Node, kind: SyntaxKind): boolean {
25322539
while (node) {
@@ -8178,7 +8185,7 @@ function Symbol(this: Symbol, flags: SymbolFlags, name: __String) {
81788185
this.exportSymbol = undefined;
81798186
this.constEnumOnlyModule = undefined;
81808187
this.isReferenced = undefined;
8181-
this.isAssigned = undefined;
8188+
this.lastAssignmentPos = undefined;
81828189
(this as any).links = undefined; // used by TransientSymbol
81838190
}
81848191

@@ -10351,12 +10358,6 @@ export function isCatchClauseVariableDeclaration(node: Node) {
1035110358
return node.kind === SyntaxKind.VariableDeclaration && node.parent.kind === SyntaxKind.CatchClause;
1035210359
}
1035310360

10354-
/** @internal */
10355-
export function isParameterOrCatchClauseVariable(symbol: Symbol) {
10356-
const declaration = symbol.valueDeclaration && getRootDeclaration(symbol.valueDeclaration);
10357-
return !!declaration && (isParameter(declaration) || isCatchClauseVariableDeclaration(declaration));
10358-
}
10359-
1036010361
/** @internal */
1036110362
export function isFunctionExpressionOrArrowFunction(node: Node): node is FunctionExpression | ArrowFunction {
1036210363
return node.kind === SyntaxKind.FunctionExpression || node.kind === SyntaxKind.ArrowFunction;

src/harness/fourslashImpl.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3521,10 +3521,12 @@ export class TestState {
35213521
actualTextArray.push(text);
35223522

35233523
// Undo changes to perform next fix
3524-
const span = change.textChanges[0].span;
3525-
const deletedText = originalContent.substr(span.start, change.textChanges[0].span.length);
3526-
const insertedText = change.textChanges[0].newText;
3527-
this.editScriptAndUpdateMarkers(fileName, span.start, span.start + insertedText.length, deletedText);
3524+
for (const textChange of change.textChanges) {
3525+
const span = textChange.span;
3526+
const deletedText = originalContent.slice(span.start, span.start + textChange.span.length);
3527+
const insertedText = textChange.newText;
3528+
this.editScriptAndUpdateMarkers(fileName, span.start, span.start + insertedText.length, deletedText);
3529+
}
35283530
}
35293531
if (expectedTextArray.length !== actualTextArray.length) {
35303532
this.raiseError(`Expected ${expectedTextArray.length} import fixes, got ${actualTextArray.length}:\n\n${actualTextArray.join("\n\n" + "-".repeat(20) + "\n\n")}`);

src/server/protocol.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3643,6 +3643,13 @@ export interface UserPreferences {
36433643
* Default: `false`
36443644
*/
36453645
readonly organizeImportsCaseFirst?: "upper" | "lower" | false;
3646+
/**
3647+
* Indicates where named type-only imports should sort. "inline" sorts named imports without regard to if the import is
3648+
* type-only.
3649+
*
3650+
* Default: `last`
3651+
*/
3652+
readonly organizeImportsTypeOrder?: "last" | "first" | "inline";
36463653

36473654
/**
36483655
* Indicates whether {@link ReferencesResponseItem.lineText} is supported.

src/services/codefixes/importFixes.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ import {
5353
getSourceFileOfNode,
5454
getSymbolId,
5555
getTokenAtPosition,
56+
getTokenPosOfNode,
5657
getTypeKeywordOfTypeOnlyImport,
5758
getUniqueSymbolId,
5859
hostGetCanonicalFileName,
@@ -1406,14 +1407,14 @@ function promoteFromTypeOnly(
14061407
if (aliasDeclaration.parent.elements.length > 1 && sortKind) {
14071408
const newSpecifier = factory.updateImportSpecifier(aliasDeclaration, /*isTypeOnly*/ false, aliasDeclaration.propertyName, aliasDeclaration.name);
14081409
const comparer = OrganizeImports.getOrganizeImportsComparer(preferences, sortKind === SortKind.CaseInsensitive);
1409-
const insertionIndex = OrganizeImports.getImportSpecifierInsertionIndex(aliasDeclaration.parent.elements, newSpecifier, comparer);
1410-
if (aliasDeclaration.parent.elements.indexOf(aliasDeclaration) !== insertionIndex) {
1410+
const insertionIndex = OrganizeImports.getImportSpecifierInsertionIndex(aliasDeclaration.parent.elements, newSpecifier, comparer, preferences);
1411+
if (insertionIndex !== aliasDeclaration.parent.elements.indexOf(aliasDeclaration)) {
14111412
changes.delete(sourceFile, aliasDeclaration);
14121413
changes.insertImportSpecifierAtIndex(sourceFile, newSpecifier, aliasDeclaration.parent, insertionIndex);
14131414
return aliasDeclaration;
14141415
}
14151416
}
1416-
changes.deleteRange(sourceFile, aliasDeclaration.getFirstToken()!);
1417+
changes.deleteRange(sourceFile, { pos: getTokenPosOfNode(aliasDeclaration.getFirstToken()!), end: getTokenPosOfNode(aliasDeclaration.propertyName ?? aliasDeclaration.name) });
14171418
return aliasDeclaration;
14181419
}
14191420
else {
@@ -1538,7 +1539,7 @@ function doAddExistingFix(
15381539
// type-only, there's no need to ask for the insertion index - it's 0.
15391540
const insertionIndex = promoteFromTypeOnly && !spec.isTypeOnly
15401541
? 0
1541-
: OrganizeImports.getImportSpecifierInsertionIndex(existingSpecifiers, spec, comparer);
1542+
: OrganizeImports.getImportSpecifierInsertionIndex(existingSpecifiers, spec, comparer, preferences);
15421543
changes.insertImportSpecifierAtIndex(sourceFile, spec, clause.namedBindings as NamedImports, insertionIndex);
15431544
}
15441545
}

0 commit comments

Comments
 (0)