Skip to content

Commit

Permalink
Merge branch 'main' into release-5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielRosenwasser committed Jan 25, 2023
2 parents aa8df3e + 0141d1d commit d4d640f
Show file tree
Hide file tree
Showing 74 changed files with 1,859 additions and 540 deletions.
4 changes: 2 additions & 2 deletions .github/fabricbot.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
{
"name": "addReply",
"parameters": {
"comment": "Thanks for the PR! It looks like you've changed the TSServer protocol in some way. Please ensure that any changes here don't break consumers of the current TSServer API. For some extra review, we'll ping @sheetalkamat, @mjbvz, and @minestarks for you. Feel free to loop in other consumers/maintainers if necessary"
"comment": "Thanks for the PR! It looks like you've changed the TSServer protocol in some way. Please ensure that any changes here don't break consumers of the current TSServer API. For some extra review, we'll ping @sheetalkamat, @mjbvz, @zkat, and @joj for you. Feel free to loop in other consumers/maintainers if necessary"
}
}
],
Expand Down Expand Up @@ -487,7 +487,7 @@
{
"name": "addReply",
"parameters": {
"comment": "Thanks for the PR! It looks like you've changed 'preProcess.ts' in some way. Please ensure that any changes here don't break consumers with unique project systems such as Visual Studio. Pinging @sheetalkamat and @minestarks so they are aware of the changes."
"comment": "Thanks for the PR! It looks like you've changed 'preProcess.ts' in some way. Please ensure that any changes here don't break consumers with unique project systems such as Visual Studio. Pinging @sheetalkamat, @zkat, and @joj so they are aware of the changes."
}
}
]
Expand Down
745 changes: 303 additions & 442 deletions package-lock.json

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions scripts/build/options.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ const parsed = minimist(process.argv.slice(2), {
inspect: process.env.inspect || process.env["inspect-brk"] || process.env.i,
host: process.env.TYPESCRIPT_HOST || process.env.host || "node",
browser: process.env.browser || process.env.b || (os.platform() === "win32" ? "edge" : "chrome"),
timeout: process.env.timeout || 40000,
timeout: +(process.env.timeout ?? 0) || 40000,
tests: process.env.test || process.env.tests || process.env.t,
runners: process.env.runners || process.env.runner || process.env.ru,
light: process.env.light === undefined || process.env.light !== "false",
reporter: process.env.reporter || process.env.r,
fix: process.env.fix || process.env.f,
workers: process.env.workerCount || ((os.cpus().length - (ci ? 0 : 1)) || 1),
workers: +(process.env.workerCount ?? 0) || ((os.cpus().length - (ci ? 0 : 1)) || 1),
failed: false,
keepFailed: false,
lkg: true,
Expand Down Expand Up @@ -73,11 +73,11 @@ export default options;
* @property {string | boolean} break
* @property {string | boolean} inspect
* @property {string} runners
* @property {string|number} workers
* @property {number} workers
* @property {string} host
* @property {string} reporter
* @property {string} stackTraceLimit
* @property {string|number} timeout
* @property {number} timeout
* @property {boolean} failed
* @property {boolean} keepFailed
* @property {boolean} ci
Expand Down
4 changes: 2 additions & 2 deletions scripts/build/tests.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,9 @@ export async function cleanTestDirs() {
* @param {string} runners
* @param {boolean} light
* @param {string} [taskConfigsFolder]
* @param {string | number} [workerCount]
* @param {number} [workerCount]
* @param {string} [stackTraceLimit]
* @param {string | number} [timeout]
* @param {number} [timeout]
* @param {boolean} [keepFailed]
* @param {number | undefined} [shards]
* @param {number | undefined} [shardId]
Expand Down
21 changes: 12 additions & 9 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,10 @@ import {
createGetCanonicalFileName,
createGetSymbolWalker,
createModeAwareCacheKey,
createPrinter,
createPrinterWithDefaults,
createPrinterWithRemoveComments,
createPrinterWithRemoveCommentsNeverAsciiEscape,
createPrinterWithRemoveCommentsOmitTrailingSemicolon,
createPropertyNameNodeForIdentifierOrLiteral,
createSymbolTable,
createTextWriter,
Expand Down Expand Up @@ -6123,7 +6126,9 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
function symbolToStringWorker(writer: EmitTextWriter) {
const entity = builder(symbol, meaning!, enclosingDeclaration, nodeFlags)!; // TODO: GH#18217
// add neverAsciiEscape for GH#39027
const printer = enclosingDeclaration?.kind === SyntaxKind.SourceFile ? createPrinter({ removeComments: true, neverAsciiEscape: true }) : createPrinter({ removeComments: true });
const printer = enclosingDeclaration?.kind === SyntaxKind.SourceFile
? createPrinterWithRemoveCommentsNeverAsciiEscape()
: createPrinterWithRemoveComments();
const sourceFile = enclosingDeclaration && getSourceFileOfNode(enclosingDeclaration);
printer.writeNode(EmitHint.Unspecified, entity, /*sourceFile*/ sourceFile, writer);
return writer;
Expand All @@ -6142,7 +6147,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
sigOutput = kind === SignatureKind.Construct ? SyntaxKind.ConstructSignature : SyntaxKind.CallSignature;
}
const sig = nodeBuilder.signatureToSignatureDeclaration(signature, sigOutput, enclosingDeclaration, toNodeBuilderFlags(flags) | NodeBuilderFlags.IgnoreErrors | NodeBuilderFlags.WriteTypeParametersInQualifiedName);
const printer = createPrinter({ removeComments: true, omitTrailingSemicolon: true });
const printer = createPrinterWithRemoveCommentsOmitTrailingSemicolon();
const sourceFile = enclosingDeclaration && getSourceFileOfNode(enclosingDeclaration);
printer.writeNode(EmitHint.Unspecified, sig!, /*sourceFile*/ sourceFile, getTrailingSemicolonDeferringWriter(writer)); // TODO: GH#18217
return writer;
Expand All @@ -6155,8 +6160,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
if (typeNode === undefined) return Debug.fail("should always get typenode");
// The unresolved type gets a synthesized comment on `any` to hint to users that it's not a plain `any`.
// Otherwise, we always strip comments out.
const options = { removeComments: type !== unresolvedType };
const printer = createPrinter(options);
const printer = type !== unresolvedType ? createPrinterWithRemoveComments() : createPrinterWithDefaults();
const sourceFile = enclosingDeclaration && getSourceFileOfNode(enclosingDeclaration);
printer.writeNode(EmitHint.Unspecified, typeNode, /*sourceFile*/ sourceFile, writer);
const result = writer.getText();
Expand Down Expand Up @@ -9636,7 +9640,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
typePredicate.kind === TypePredicateKind.Identifier || typePredicate.kind === TypePredicateKind.AssertsIdentifier ? factory.createIdentifier(typePredicate.parameterName) : factory.createThisTypeNode(),
typePredicate.type && nodeBuilder.typeToTypeNode(typePredicate.type, enclosingDeclaration, toNodeBuilderFlags(flags) | NodeBuilderFlags.IgnoreErrors | NodeBuilderFlags.WriteTypeParametersInQualifiedName)! // TODO: GH#18217
);
const printer = createPrinter({ removeComments: true });
const printer = createPrinterWithRemoveComments();
const sourceFile = enclosingDeclaration && getSourceFileOfNode(enclosingDeclaration);
printer.writeNode(EmitHint.Unspecified, predicate, /*sourceFile*/ sourceFile, writer);
return writer;
Expand Down Expand Up @@ -27211,7 +27215,6 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
isFunctionLike(node) && !getImmediatelyInvokedFunctionExpression(node) ||
node.kind === SyntaxKind.ModuleBlock ||
node.kind === SyntaxKind.SourceFile ||
node.kind === SyntaxKind.CatchClause ||
node.kind === SyntaxKind.PropertyDeclaration)!;
}

Expand Down Expand Up @@ -27587,7 +27590,6 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
const isParameter = getRootDeclaration(declaration).kind === SyntaxKind.Parameter;
const declarationContainer = getControlFlowContainer(declaration);
let flowContainer = getControlFlowContainer(node);
const isCatch = flowContainer.kind === SyntaxKind.CatchClause;
const isOuterVariable = flowContainer !== declarationContainer;
const isSpreadDestructuringAssignmentTarget = node.parent && node.parent.parent && isSpreadAssignment(node.parent) && isDestructuringAssignmentTarget(node.parent.parent);
const isModuleExports = symbol.flags & SymbolFlags.ModuleExports;
Expand All @@ -27602,7 +27604,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
// We only look for uninitialized variables in strict null checking mode, and only when we can analyze
// the entire control flow graph from the variable's declaration (i.e. when the flow container and
// declaration container are the same).
const assumeInitialized = isParameter || isCatch || isAlias || isOuterVariable || isSpreadDestructuringAssignmentTarget || isModuleExports || isSameScopedBindingElement(node, declaration) ||
const assumeInitialized = isParameter || isAlias || isOuterVariable || isSpreadDestructuringAssignmentTarget || isModuleExports || isSameScopedBindingElement(node, declaration) ||
type !== autoType && type !== autoArrayType && (!strictNullChecks || (type.flags & (TypeFlags.AnyOrUnknown | TypeFlags.Void)) !== 0 ||
isInTypeQuery(node) || isInAmbientOrTypeNode(node) || node.parent.kind === SyntaxKind.ExportSpecifier) ||
node.parent.kind === SyntaxKind.NonNullExpression ||
Expand Down Expand Up @@ -43901,6 +43903,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
}

const isIllegalExportDefaultInCJS = !node.isExportEquals &&
!(node.flags & NodeFlags.Ambient) &&
compilerOptions.verbatimModuleSyntax &&
(moduleKind === ModuleKind.CommonJS || getSourceFileOfNode(node).impliedNodeFormat === ModuleKind.CommonJS);

Expand Down
12 changes: 12 additions & 0 deletions src/compiler/emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1343,6 +1343,18 @@ const enum PipelinePhase {
Emit,
}

/** @internal */
export const createPrinterWithDefaults = memoize(() => createPrinter({}));

/** @internal */
export const createPrinterWithRemoveComments = memoize(() => createPrinter({ removeComments: true }));

/** @internal */
export const createPrinterWithRemoveCommentsNeverAsciiEscape = memoize(() => createPrinter({ removeComments: true, neverAsciiEscape: true }));

/** @internal */
export const createPrinterWithRemoveCommentsOmitTrailingSemicolon = memoize(() => createPrinter({ removeComments: true, omitTrailingSemicolon: true }));

export function createPrinter(printerOptions: PrinterOptions = {}, handlers: PrintHandlers = {}): Printer {
const {
hasGlobalName,
Expand Down
14 changes: 14 additions & 0 deletions src/compiler/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1279,6 +1279,20 @@ export function getScriptTargetFeatures(): ScriptTargetFeatures {
BigUint64Array: ["at"],
ObjectConstructor: ["hasOwn"],
Error: ["cause"]
},
es2023: {
Array: ["findLastIndex", "findLast"],
Int8Array: ["findLastIndex", "findLast"],
Uint8Array: ["findLastIndex", "findLast"],
Uint8ClampedArray: ["findLastIndex", "findLast"],
Int16Array: ["findLastIndex", "findLast"],
Uint16Array: ["findLastIndex", "findLast"],
Int32Array: ["findLastIndex", "findLast"],
Uint32Array: ["findLastIndex", "findLast"],
Float32Array: ["findLastIndex", "findLast"],
Float64Array: ["findLastIndex", "findLast"],
BigInt64Array: ["findLastIndex", "findLast"],
BigUint64Array: ["findLastIndex", "findLast"],
}
};
}
Expand Down
2 changes: 1 addition & 1 deletion src/harness/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,7 @@ export class SessionClient implements LanguageService {
return notImplemented();
}

getDocCommentTemplateAtPosition(_fileName: string, _position: number, _options?: DocCommentTemplateOptions): TextInsertion {
getDocCommentTemplateAtPosition(_fileName: string, _position: number, _options?: DocCommentTemplateOptions, _formatOptions?: FormatCodeSettings): TextInsertion {
return notImplemented();
}

Expand Down
2 changes: 1 addition & 1 deletion src/harness/fourslashImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3249,7 +3249,7 @@ export class TestState {

public verifyDocCommentTemplate(expected: ts.TextInsertion | undefined, options?: ts.DocCommentTemplateOptions) {
const name = "verifyDocCommentTemplate";
const actual = this.languageService.getDocCommentTemplateAtPosition(this.activeFile.fileName, this.currentCaretPosition, options || { generateReturnInDocTemplate: true })!;
const actual = this.languageService.getDocCommentTemplateAtPosition(this.activeFile.fileName, this.currentCaretPosition, options || { generateReturnInDocTemplate: true }, this.formatCodeSettings)!;

if (expected === undefined) {
if (actual) {
Expand Down
2 changes: 1 addition & 1 deletion src/harness/fourslashInterfaceImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ export class Verify extends VerifyNegatable {

public docCommentTemplateAt(marker: string | FourSlash.Marker, expectedOffset: number, expectedText: string, options?: ts.DocCommentTemplateOptions) {
this.state.goToMarker(marker);
this.state.verifyDocCommentTemplate({ newText: expectedText.replace(/\r?\n/g, "\r\n"), caretOffset: expectedOffset }, options);
this.state.verifyDocCommentTemplate({ newText: expectedText.replace(/\r?\n/g, ts.testFormatSettings.newLineCharacter!), caretOffset: expectedOffset }, options);
}

public noDocCommentTemplateAt(marker: string | FourSlash.Marker) {
Expand Down
4 changes: 2 additions & 2 deletions src/harness/harnessLanguageService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -587,8 +587,8 @@ class LanguageServiceShimProxy implements ts.LanguageService {
getFormattingEditsAfterKeystroke(fileName: string, position: number, key: string, options: ts.FormatCodeOptions): ts.TextChange[] {
return unwrapJSONCallResult(this.shim.getFormattingEditsAfterKeystroke(fileName, position, key, JSON.stringify(options)));
}
getDocCommentTemplateAtPosition(fileName: string, position: number, options?: ts.DocCommentTemplateOptions): ts.TextInsertion {
return unwrapJSONCallResult(this.shim.getDocCommentTemplateAtPosition(fileName, position, options));
getDocCommentTemplateAtPosition(fileName: string, position: number, options?: ts.DocCommentTemplateOptions, formatOptions?: ts.FormatCodeSettings): ts.TextInsertion {
return unwrapJSONCallResult(this.shim.getDocCommentTemplateAtPosition(fileName, position, options, formatOptions));
}
isValidBraceCompletionAtPosition(fileName: string, position: number, openingBrace: number): boolean {
return unwrapJSONCallResult(this.shim.isValidBraceCompletionAtPosition(fileName, position, openingBrace));
Expand Down
2 changes: 1 addition & 1 deletion src/server/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2083,7 +2083,7 @@ export class Session<TMessage = string> implements EventSender {
private getDocCommentTemplate(args: protocol.FileLocationRequestArgs) {
const { file, languageService } = this.getFileAndLanguageServiceForSyntacticOperation(args);
const position = this.getPositionInFile(args, file);
return languageService.getDocCommentTemplateAtPosition(file, position, this.getPreferences(file));
return languageService.getDocCommentTemplateAtPosition(file, position, this.getPreferences(file), this.getFormatOptions(file));
}

private getSpanOfEnclosingComment(args: protocol.SpanOfEnclosingCommentRequestArgs) {
Expand Down
4 changes: 2 additions & 2 deletions src/services/callHierarchy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
ClassLikeDeclaration,
ClassStaticBlockDeclaration,
compareStringsCaseSensitive,
createPrinter,
createPrinterWithRemoveCommentsOmitTrailingSemicolon,
createTextRangeFromNode,
createTextSpanFromBounds,
createTextSpanFromRange,
Expand Down Expand Up @@ -245,7 +245,7 @@ function getCallHierarchyItemName(program: Program, node: CallHierarchyDeclarati
}
if (text === undefined) {
// get the text from printing the node on a single line without comments...
const printer = createPrinter({ removeComments: true, omitTrailingSemicolon: true });
const printer = createPrinterWithRemoveCommentsOmitTrailingSemicolon();
text = usingSingleLineStringWriter(writer => printer.writeNode(EmitHint.Unspecified, node, node.getSourceFile(), writer));
}
return { text, pos: declName.getStart(), end: declName.getEnd() };
Expand Down
4 changes: 2 additions & 2 deletions src/services/codefixes/fixUnmatchedParameter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ function getDeleteAction(context: CodeFixContext, { name, jsDocHost, jsDocParame
);
}

function getRenameAction(context: CodeFixContext, { name, signature, jsDocParameterTag }: Info) {
function getRenameAction(context: CodeFixContext, { name, jsDocHost, signature, jsDocParameterTag }: Info) {
if (!length(signature.parameters)) return undefined;

const sourceFile = context.sourceFile;
Expand All @@ -110,7 +110,7 @@ function getRenameAction(context: CodeFixContext, { name, signature, jsDocParame
jsDocParameterTag.comment
);
const changes = textChanges.ChangeTracker.with(context, changeTracker =>
changeTracker.replaceJSDocComment(sourceFile, signature, map(tags, t => t === jsDocParameterTag ? newJSDocParameterTag : t)));
changeTracker.replaceJSDocComment(sourceFile, jsDocHost, map(tags, t => t === jsDocParameterTag ? newJSDocParameterTag : t)));
return createCodeFixActionWithoutFixAll(renameUnmatchedParameter, changes, [Diagnostics.Rename_param_tag_name_0_to_1, name.getText(sourceFile), parameterName]);
}

Expand Down
6 changes: 2 additions & 4 deletions src/services/inlayHints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {
__String,
ArrowFunction,
CallExpression,
createPrinter,
createPrinterWithRemoveComments,
Debug,
EmitHint,
EnumMember,
Expand Down Expand Up @@ -53,7 +53,6 @@ import {
NodeBuilderFlags,
ParameterDeclaration,
PrefixUnaryExpression,
PrinterOptions,
PropertyDeclaration,
Signature,
skipParentheses,
Expand Down Expand Up @@ -383,8 +382,7 @@ export function provideInlayHints(context: InlayHintsContext): InlayHint[] {

function printTypeInSingleLine(type: Type) {
const flags = NodeBuilderFlags.IgnoreErrors | TypeFormatFlags.AllowUniqueESSymbolType | TypeFormatFlags.UseAliasDefinedOutsideCurrentScope;
const options: PrinterOptions = { removeComments: true };
const printer = createPrinter(options);
const printer = createPrinterWithRemoveComments();

return usingSingleLineStringWriter(writer => {
const typeNode = checker.typeToTypeNode(type, /*enclosingDeclaration*/ undefined, flags);
Expand Down
3 changes: 3 additions & 0 deletions src/services/jsDoc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ const jsDocTagNames = [
"lends",
"license",
"link",
"linkcode",
"linkplain",
"listens",
"member",
"memberof",
Expand All @@ -147,6 +149,7 @@ const jsDocTagNames = [
"package",
"param",
"private",
"prop",
"property",
"protected",
"public",
Expand Down
5 changes: 3 additions & 2 deletions src/services/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2436,8 +2436,9 @@ export function createLanguageService(
: Promise.reject("Host does not implement `installPackage`");
}

function getDocCommentTemplateAtPosition(fileName: string, position: number, options?: DocCommentTemplateOptions): TextInsertion | undefined {
return JsDoc.getDocCommentTemplateAtPosition(getNewLineOrDefaultFromHost(host, /*formatSettings*/ undefined), syntaxTreeCache.getCurrentSourceFile(fileName), position, options);
function getDocCommentTemplateAtPosition(fileName: string, position: number, options?: DocCommentTemplateOptions, formatOptions?: FormatCodeSettings): TextInsertion | undefined {
const formatSettings = formatOptions ? formatting.getFormatContext(formatOptions, host).options : undefined;
return JsDoc.getDocCommentTemplateAtPosition(getNewLineOrDefaultFromHost(host, formatSettings), syntaxTreeCache.getCurrentSourceFile(fileName), position, options);
}

function isValidBraceCompletionAtPosition(fileName: string, position: number, openingBrace: number): boolean {
Expand Down
Loading

0 comments on commit d4d640f

Please sign in to comment.