Skip to content

🤖 User test baselines have changed for optimizeDeferredTypeReferences #36612

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/compiler/scanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2068,10 +2068,19 @@ namespace ts {

// First non-whitespace character on this line.
let firstNonWhitespace = 0;
let lastNonWhitespace = -1;

// These initial values are special because the first line is:
// firstNonWhitespace = 0 to indicate that we want leading whitespace,

while (pos < end) {

// We want to keep track of the last non-whitespace (but including
// newlines character for hitting the end of the JSX Text region)
if (!isWhiteSpaceSingleLine(char)) {
lastNonWhitespace = pos;
}

char = text.charCodeAt(pos);
if (char === CharacterCodes.openBrace) {
break;
Expand All @@ -2084,6 +2093,8 @@ namespace ts {
break;
}

if (lastNonWhitespace > 0) lastNonWhitespace++;

// FirstNonWhitespace is 0, then we only see whitespaces so far. If we see a linebreak, we want to ignore that whitespaces.
// i.e (- : whitespace)
// <div>----
Expand All @@ -2096,10 +2107,13 @@ namespace ts {
else if (!isWhiteSpaceLike(char)) {
firstNonWhitespace = pos;
}

pos++;
}

tokenValue = text.substring(startPos, pos);
const endPosition = lastNonWhitespace === -1 ? pos : lastNonWhitespace;
tokenValue = text.substring(startPos, endPosition);

return firstNonWhitespace === -1 ? SyntaxKind.JsxTextAllWhiteSpaces : SyntaxKind.JsxText;
}

Expand Down
33 changes: 27 additions & 6 deletions src/services/formatting/formatting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,11 @@ namespace ts.formatting {
if (tokenInfo.token.end > node.end) {
break;
}
if (node.kind === SyntaxKind.JsxText) {
// Intentation rules for jsx text are handled by `indentMultilineCommentOrJsxText` inside `processChildNode`; just fastforward past it here
formattingScanner.advance();
continue;
}
consumeTokenAndAdvanceScanner(tokenInfo, node, nodeDynamicIndentation, node);
}

Expand Down Expand Up @@ -736,10 +741,21 @@ namespace ts.formatting {
const childIndentation = computeIndentation(child, childStartLine, childIndentationAmount, node, parentDynamicIndentation, effectiveParentStartLine);

processNode(child, childContextNode, childStartLine, undecoratedChildStartLine, childIndentation.indentation, childIndentation.delta);

if (child.kind === SyntaxKind.JsxText) {
const range: TextRange = { pos: child.getStart(), end: child.getEnd() };
indentMultilineCommentOrJsxText(range, childIndentation.indentation, /*firstLineIsIndented*/ true, /*indentFinalLine*/ false);
if (range.pos !== range.end) { // don't indent zero-width jsx text
const siblings = parent.getChildren(sourceFile);
const currentIndex = findIndex(siblings, arg => arg.pos === child.pos);
const previousNode = siblings[currentIndex - 1];
if (previousNode) {
// The jsx text needs no indentation whatsoever if it ends on the same line the previous sibling ends on
if (sourceFile.getLineAndCharacterOfPosition(range.end).line !== sourceFile.getLineAndCharacterOfPosition(previousNode.end).line) {
// The first line is (already) "indented" if the text starts on the same line as the previous sibling element ends on
const firstLineIsIndented = sourceFile.getLineAndCharacterOfPosition(range.pos).line === sourceFile.getLineAndCharacterOfPosition(previousNode.end).line;
indentMultilineCommentOrJsxText(range, childIndentation.indentation, firstLineIsIndented, /*indentFinalLine*/ false, /*jsxStyle*/ true);
}
}
}
}

childContextNode = node;
Expand Down Expand Up @@ -1039,7 +1055,7 @@ namespace ts.formatting {
return indentationString !== sourceFile.text.substr(startLinePosition, indentationString.length);
}

function indentMultilineCommentOrJsxText(commentRange: TextRange, indentation: number, firstLineIsIndented: boolean, indentFinalLine = true) {
function indentMultilineCommentOrJsxText(commentRange: TextRange, indentation: number, firstLineIsIndented: boolean, indentFinalLine = true, jsxTextStyleIndent?: boolean) {
// split comment in lines
let startLine = sourceFile.getLineAndCharacterOfPosition(commentRange.pos).line;
const endLine = sourceFile.getLineAndCharacterOfPosition(commentRange.end).line;
Expand Down Expand Up @@ -1070,7 +1086,7 @@ namespace ts.formatting {
const nonWhitespaceColumnInFirstPart =
SmartIndenter.findFirstNonWhitespaceCharacterAndColumn(startLinePos, parts[0].pos, sourceFile, options);

if (indentation === nonWhitespaceColumnInFirstPart.column) {
if (indentation === nonWhitespaceColumnInFirstPart.column && !jsxTextStyleIndent) {
return;
}

Expand All @@ -1081,14 +1097,19 @@ namespace ts.formatting {
}

// shift all parts on the delta size
const delta = indentation - nonWhitespaceColumnInFirstPart.column;
let delta = indentation - nonWhitespaceColumnInFirstPart.column;
for (let i = startIndex; i < parts.length; i++ , startLine++) {
const startLinePos = getStartPositionOfLine(startLine, sourceFile);
const nonWhitespaceCharacterAndColumn =
i === 0
? nonWhitespaceColumnInFirstPart
: SmartIndenter.findFirstNonWhitespaceCharacterAndColumn(parts[i].pos, parts[i].end, sourceFile, options);

if (jsxTextStyleIndent) {
// skip adding indentation to blank lines
if (isLineBreak(sourceFile.text.charCodeAt(getStartPositionOfLine(startLine, sourceFile)))) continue;
// reset delta on every line
delta = indentation - nonWhitespaceCharacterAndColumn.column;
}
const newIndentation = nonWhitespaceCharacterAndColumn.column + delta;
if (newIndentation > 0) {
const indentationString = getIndentationString(newIndentation, options);
Expand Down
8 changes: 7 additions & 1 deletion src/services/formatting/formattingScanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,13 @@ namespace ts.formatting {
}

function shouldRescanJsxText(node: Node): boolean {
return node.kind === SyntaxKind.JsxText;
const isJSXText = isJsxText(node);
if (isJSXText) {
const containingElement = findAncestor(node.parent, p => isJsxElement(p));
if (!containingElement) return false; // should never happen
return !isParenthesizedExpression(containingElement.parent);
}
return false;
}

function shouldRescanSlashToken(container: Node): boolean {
Expand Down
37 changes: 20 additions & 17 deletions src/services/suggestionDiagnostics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,8 @@ namespace ts {

function check(node: Node) {
if (isJsFile) {
switch (node.kind) {
case SyntaxKind.FunctionExpression:
const decl = getDeclarationOfExpando(node);
if (decl) {
const symbol = decl.symbol;
if (symbol && (symbol.exports && symbol.exports.size || symbol.members && symbol.members.size)) {
diags.push(createDiagnosticForNode(isVariableDeclaration(node.parent) ? node.parent.name : node, Diagnostics.This_constructor_function_may_be_converted_to_a_class_declaration));
break;
}
}
// falls through if no diagnostic was created
case SyntaxKind.FunctionDeclaration:
const symbol = node.symbol;
if (symbol.members && (symbol.members.size > 0)) {
diags.push(createDiagnosticForNode(isVariableDeclaration(node.parent) ? node.parent.name : node, Diagnostics.This_constructor_function_may_be_converted_to_a_class_declaration));
}
break;
if (canBeConvertedToClass(node)) {
diags.push(createDiagnosticForNode(isVariableDeclaration(node.parent) ? node.parent.name : node, Diagnostics.This_constructor_function_may_be_converted_to_a_class_declaration));
}
}
else {
Expand Down Expand Up @@ -193,4 +178,22 @@ namespace ts {
function getKeyFromNode(exp: FunctionLikeDeclaration) {
return `${exp.pos.toString()}:${exp.end.toString()}`;
}

function canBeConvertedToClass(node: Node): boolean {
if (node.kind === SyntaxKind.FunctionExpression) {
if (isVariableDeclaration(node.parent) && node.symbol.members?.size) {
return true;
}

const decl = getDeclarationOfExpando(node);
const symbol = decl?.symbol;
return !!(symbol && (symbol.exports?.size || symbol.members?.size));
}

if (node.kind === SyntaxKind.FunctionDeclaration) {
return !!node.symbol.members?.size;
}

return false;
}
}
18 changes: 9 additions & 9 deletions tests/baselines/reference/docker/azure-sdk.log
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ npm ERR! /root/.npm/_logs/XXXX-XX-XXXXXXXXX-debug.log
XX of XX: [@azure/service-bus] completed successfully in ? seconds
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! @azure/[email protected].7 build:es6: `tsc -p tsconfig.json`
npm ERR! @azure/[email protected].8 build:es6: `tsc -p tsconfig.json`
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the @azure/[email protected].7 build:es?script.
npm ERR! Failed at the @azure/[email protected].8 build:es?script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/XXXX-XX-XXXXXXXXX-debug.log
Expand Down Expand Up @@ -142,26 +142,26 @@ npm ERR! /root/.npm/_logs/XXXX-XX-XXXXXXXXX-debug.log
@azure/storage-file-datalake (? seconds)
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! @azure/[email protected].7 build:es6: `tsc -p tsconfig.json`
npm ERR! @azure/[email protected].8 build:es6: `tsc -p tsconfig.json`
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the @azure/[email protected].7 build:es?script.
npm ERR! Failed at the @azure/[email protected].8 build:es?script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/XXXX-XX-XXXXXXXXX-debug.log
================================
Error: Project(s) failed to build
Error: Project(s) failed
rush rebuild - Errors! ( ? seconds)



Standard error:

XX of XX: [@azure/app-configuration] failed to build!
XX of XX: [@azure/app-configuration] failed!
XX of XX: [@azure/cosmos] completed with warnings in ? seconds
XX of XX: [@azure/eventhubs-checkpointstore-blob] failed to build!
XX of XX: [@azure/keyvault-certificates] failed to build!
XX of XX: [@azure/storage-file-datalake] failed to build!
XX of XX: [@azure/eventhubs-checkpointstore-blob] failed!
XX of XX: [@azure/keyvault-certificates] failed!
XX of XX: [@azure/storage-file-datalake] failed!
[@azure/app-configuration] Returned error code: 2
[@azure/eventhubs-checkpointstore-blob] Returned error code: 2
[@azure/keyvault-certificates] Returned error code: 2
Expand Down
Loading