diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 5444c618353bd..54baf9c8a7e8b 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -406,6 +406,14 @@ namespace ts { setWriter(/*output*/ undefined); } + // TODO: Should this just be `emit`? + // See https://github.com/Microsoft/TypeScript/pull/18284#discussion_r137611034 + function emitIfPresent(node: Node | undefined) { + if (node) { + emit(node); + } + } + function emit(node: Node) { pipelineEmitWithNotification(EmitHint.Unspecified, node); } @@ -451,6 +459,7 @@ namespace ts { case EmitHint.SourceFile: return pipelineEmitSourceFile(node); case EmitHint.IdentifierName: return pipelineEmitIdentifierName(node); case EmitHint.Expression: return pipelineEmitExpression(node); + case EmitHint.MappedTypeParameter: return emitMappedTypeParameter(cast(node, isTypeParameterDeclaration)); case EmitHint.Unspecified: return pipelineEmitUnspecified(node); } } @@ -465,6 +474,12 @@ namespace ts { emitIdentifier(node); } + function emitMappedTypeParameter(node: TypeParameterDeclaration): void { + emit(node.name); + write(" in "); + emit(node.constraint); + } + function pipelineEmitUnspecified(node: Node): void { const kind = node.kind; @@ -898,9 +913,9 @@ namespace ts { function emitParameter(node: ParameterDeclaration) { emitDecorators(node, node.decorators); emitModifiers(node, node.modifiers); - writeIfPresent(node.dotDotDotToken, "..."); + emitIfPresent(node.dotDotDotToken); emit(node.name); - writeIfPresent(node.questionToken, "?"); + emitIfPresent(node.questionToken); emitWithPrefix(": ", node.type); emitExpressionWithPrefix(" = ", node.initializer); } @@ -918,7 +933,7 @@ namespace ts { emitDecorators(node, node.decorators); emitModifiers(node, node.modifiers); emit(node.name); - writeIfPresent(node.questionToken, "?"); + emitIfPresent(node.questionToken); emitWithPrefix(": ", node.type); write(";"); } @@ -927,7 +942,7 @@ namespace ts { emitDecorators(node, node.decorators); emitModifiers(node, node.modifiers); emit(node.name); - writeIfPresent(node.questionToken, "?"); + emitIfPresent(node.questionToken); emitWithPrefix(": ", node.type); emitExpressionWithPrefix(" = ", node.initializer); write(";"); @@ -937,7 +952,7 @@ namespace ts { emitDecorators(node, node.decorators); emitModifiers(node, node.modifiers); emit(node.name); - writeIfPresent(node.questionToken, "?"); + emitIfPresent(node.questionToken); emitTypeParameters(node, node.typeParameters); emitParameters(node, node.parameters); emitWithPrefix(": ", node.type); @@ -947,9 +962,9 @@ namespace ts { function emitMethodDeclaration(node: MethodDeclaration) { emitDecorators(node, node.decorators); emitModifiers(node, node.modifiers); - writeIfPresent(node.asteriskToken, "*"); + emitIfPresent(node.asteriskToken); emit(node.name); - writeIfPresent(node.questionToken, "?"); + emitIfPresent(node.questionToken); emitSignatureAndBody(node, emitSignatureHead); } @@ -1035,10 +1050,8 @@ namespace ts { function emitTypeLiteral(node: TypeLiteralNode) { write("{"); - // If the literal is empty, do not add spaces between braces. - if (node.members.length > 0) { - emitList(node, node.members, getEmitFlags(node) & EmitFlags.SingleLine ? ListFormat.SingleLineTypeLiteralMembers : ListFormat.MultiLineTypeLiteralMembers); - } + const flags = getEmitFlags(node) & EmitFlags.SingleLine ? ListFormat.SingleLineTypeLiteralMembers : ListFormat.MultiLineTypeLiteralMembers; + emitList(node, node.members, flags | ListFormat.NoSpaceIfEmpty); write("}"); } @@ -1094,13 +1107,16 @@ namespace ts { writeLine(); increaseIndent(); } - writeIfPresent(node.readonlyToken, "readonly "); + if (node.readonlyToken) { + emit(node.readonlyToken); + write(" "); + } + write("["); - emit(node.typeParameter.name); - write(" in "); - emit(node.typeParameter.constraint); + pipelineEmitWithNotification(EmitHint.MappedTypeParameter, node.typeParameter); write("]"); - writeIfPresent(node.questionToken, "?"); + + emitIfPresent(node.questionToken); write(": "); emit(node.type); write(";"); @@ -1148,7 +1164,7 @@ namespace ts { function emitBindingElement(node: BindingElement) { emitWithSuffix(node.propertyName, ": "); - writeIfPresent(node.dotDotDotToken, "..."); + emitIfPresent(node.dotDotDotToken); emit(node.name); emitExpressionWithPrefix(" = ", node.initializer); } @@ -1159,33 +1175,22 @@ namespace ts { function emitArrayLiteralExpression(node: ArrayLiteralExpression) { const elements = node.elements; - if (elements.length === 0) { - write("[]"); - } - else { - const preferNewLine = node.multiLine ? ListFormat.PreferNewLine : ListFormat.None; - emitExpressionList(node, elements, ListFormat.ArrayLiteralExpressionElements | preferNewLine); - } + const preferNewLine = node.multiLine ? ListFormat.PreferNewLine : ListFormat.None; + emitExpressionList(node, elements, ListFormat.ArrayLiteralExpressionElements | preferNewLine); } function emitObjectLiteralExpression(node: ObjectLiteralExpression) { - const properties = node.properties; - if (properties.length === 0) { - write("{}"); + const indentedFlag = getEmitFlags(node) & EmitFlags.Indented; + if (indentedFlag) { + increaseIndent(); } - else { - const indentedFlag = getEmitFlags(node) & EmitFlags.Indented; - if (indentedFlag) { - increaseIndent(); - } - const preferNewLine = node.multiLine ? ListFormat.PreferNewLine : ListFormat.None; - const allowTrailingComma = currentSourceFile.languageVersion >= ScriptTarget.ES5 ? ListFormat.AllowTrailingComma : ListFormat.None; - emitList(node, properties, ListFormat.ObjectLiteralExpressionProperties | allowTrailingComma | preferNewLine); + const preferNewLine = node.multiLine ? ListFormat.PreferNewLine : ListFormat.None; + const allowTrailingComma = currentSourceFile.languageVersion >= ScriptTarget.ES5 ? ListFormat.AllowTrailingComma : ListFormat.None; + emitList(node, node.properties, ListFormat.ObjectLiteralExpressionProperties | allowTrailingComma | preferNewLine); - if (indentedFlag) { - decreaseIndent(); - } + if (indentedFlag) { + decreaseIndent(); } } @@ -1286,7 +1291,8 @@ namespace ts { emitTypeParameters(node, node.typeParameters); emitParametersForArrow(node, node.parameters); emitWithPrefix(": ", node.type); - write(" =>"); + write(" "); + emit(node.equalsGreaterThanToken); } function emitDeleteExpression(node: DeleteExpression) { @@ -1364,13 +1370,13 @@ namespace ts { emitExpression(node.condition); increaseIndentIf(indentBeforeQuestion, " "); - write("?"); + emit(node.questionToken); increaseIndentIf(indentAfterQuestion, " "); emitExpression(node.whenTrue); decreaseIndentIf(indentBeforeQuestion, indentAfterQuestion); increaseIndentIf(indentBeforeColon, " "); - write(":"); + emit(node.colonToken); increaseIndentIf(indentAfterColon, " "); emitExpression(node.whenFalse); decreaseIndentIf(indentBeforeColon, indentAfterColon); @@ -1382,7 +1388,8 @@ namespace ts { } function emitYieldExpression(node: YieldExpression) { - write(node.asteriskToken ? "yield*" : "yield"); + write("yield"); + emit(node.asteriskToken); emitExpressionWithPrefix(" ", node.expression); } @@ -1662,7 +1669,9 @@ namespace ts { function emitFunctionDeclarationOrExpression(node: FunctionDeclaration | FunctionExpression) { emitDecorators(node, node.decorators); emitModifiers(node, node.modifiers); - write(node.asteriskToken ? "function* " : "function "); + write("function"); + emitIfPresent(node.asteriskToken); + write(" "); emitIdentifierName(node.name); emitSignatureAndBody(node, emitSignatureHead); } @@ -2068,9 +2077,7 @@ namespace ts { function emitJsxExpression(node: JsxExpression) { if (node.expression) { write("{"); - if (node.dotDotDotToken) { - write("..."); - } + emitIfPresent(node.dotDotDotToken); emitExpression(node.expression); write("}"); } @@ -2128,13 +2135,12 @@ namespace ts { emitTrailingCommentsOfPosition(statements.pos); } + let format = ListFormat.CaseOrDefaultClauseStatements; if (emitAsSingleStatement) { write(" "); - emit(statements[0]); - } - else { - emitList(parentNode, statements, ListFormat.CaseOrDefaultClauseStatements); + format &= ~(ListFormat.MultiLine | ListFormat.Indented); } + emitList(parentNode, statements, format); } function emitHeritageClause(node: HeritageClause) { @@ -2384,7 +2390,7 @@ namespace ts { function emitParametersForArrow(parentNode: FunctionTypeNode | ArrowFunction, parameters: NodeArray) { if (canEmitSimpleArrowHead(parentNode, parameters)) { - emit(parameters[0]); + emitList(parentNode, parameters, ListFormat.Parameters & ~ListFormat.Parenthesis); } else { emitParameters(parentNode, parameters); @@ -2427,7 +2433,7 @@ namespace ts { if (format & ListFormat.MultiLine) { writeLine(); } - else if (format & ListFormat.SpaceBetweenBraces) { + else if (format & ListFormat.SpaceBetweenBraces && !(format & ListFormat.NoSpaceIfEmpty)) { write(" "); } } @@ -2568,12 +2574,6 @@ namespace ts { } } - function writeIfPresent(node: Node, text: string) { - if (node) { - write(text); - } - } - function writeToken(token: SyntaxKind, pos: number, contextNode?: Node) { return onEmitSourceMapOfToken ? onEmitSourceMapOfToken(contextNode, token, pos, writeTokenText) @@ -2584,7 +2584,7 @@ namespace ts { if (onBeforeEmitToken) { onBeforeEmitToken(node); } - writeTokenText(node.kind); + write(tokenToString(node.kind)); if (onAfterEmitToken) { onAfterEmitToken(node); } @@ -3107,6 +3107,9 @@ namespace ts { NoTrailingNewLine = 1 << 16, // Do not emit a trailing NewLine for a MultiLine list. NoInterveningComments = 1 << 17, // Do not emit comments between each node + NoSpaceIfEmpty = 1 << 18, // If the literal is empty, do not add spaces between braces. + SingleElement = 1 << 19, + // Precomputed Formats Modifiers = SingleLine | SpaceBetweenSiblings | NoInterveningComments, HeritageClauses = SingleLine | SpaceBetweenSiblings, @@ -3118,7 +3121,7 @@ namespace ts { IntersectionTypeConstituents = AmpersandDelimited | SpaceBetweenSiblings | SingleLine, ObjectBindingPatternElements = SingleLine | AllowTrailingComma | SpaceBetweenBraces | CommaDelimited | SpaceBetweenSiblings, ArrayBindingPatternElements = SingleLine | AllowTrailingComma | CommaDelimited | SpaceBetweenSiblings, - ObjectLiteralExpressionProperties = PreserveLines | CommaDelimited | SpaceBetweenSiblings | SpaceBetweenBraces | Indented | Braces, + ObjectLiteralExpressionProperties = PreserveLines | CommaDelimited | SpaceBetweenSiblings | SpaceBetweenBraces | Indented | Braces | NoSpaceIfEmpty, ArrayLiteralExpressionElements = PreserveLines | CommaDelimited | SpaceBetweenSiblings | AllowTrailingComma | Indented | SquareBrackets, CommaListElements = CommaDelimited | SpaceBetweenSiblings | SingleLine, CallExpressionArguments = CommaDelimited | SpaceBetweenSiblings | SingleLine | Parenthesis, diff --git a/src/compiler/factory.ts b/src/compiler/factory.ts index 04e6b5553e894..25209c6278b4f 100644 --- a/src/compiler/factory.ts +++ b/src/compiler/factory.ts @@ -281,7 +281,7 @@ namespace ts { || node.questionToken !== questionToken || node.type !== type || node.initializer !== initializer - ? updateNode(createParameter(decorators, modifiers, dotDotDotToken, name, node.questionToken, type, initializer), node) + ? updateNode(createParameter(decorators, modifiers, dotDotDotToken, name, questionToken, type, initializer), node) : node; } @@ -1016,19 +1016,49 @@ namespace ts { return node; } + /* @deprecated */ export function updateArrowFunction( + node: ArrowFunction, + modifiers: ReadonlyArray | undefined, + typeParameters: ReadonlyArray | undefined, + parameters: ReadonlyArray, + type: TypeNode | undefined, + body: ConciseBody): ArrowFunction; export function updateArrowFunction( node: ArrowFunction, modifiers: ReadonlyArray | undefined, typeParameters: ReadonlyArray | undefined, parameters: ReadonlyArray, type: TypeNode | undefined, - body: ConciseBody) { + equalsGreaterThanToken: Token, + body: ConciseBody): ArrowFunction; + export function updateArrowFunction( + node: ArrowFunction, + modifiers: ReadonlyArray | undefined, + typeParameters: ReadonlyArray | undefined, + parameters: ReadonlyArray, + type: TypeNode | undefined, + equalsGreaterThanTokenOrBody: Token | ConciseBody, + bodyOrUndefined?: ConciseBody, + ): ArrowFunction { + let equalsGreaterThanToken: Token; + let body: ConciseBody; + if (bodyOrUndefined === undefined) { + equalsGreaterThanToken = node.equalsGreaterThanToken; + body = cast(equalsGreaterThanTokenOrBody, isConciseBody); + } + else { + equalsGreaterThanToken = cast(equalsGreaterThanTokenOrBody, (n): n is Token => + n.kind === SyntaxKind.EqualsGreaterThanToken); + body = bodyOrUndefined; + } + return node.modifiers !== modifiers || node.typeParameters !== typeParameters || node.parameters !== parameters || node.type !== type + || node.equalsGreaterThanToken !== equalsGreaterThanToken || node.body !== body - ? updateNode(createArrowFunction(modifiers, typeParameters, parameters, type, node.equalsGreaterThanToken, body), node) + ? updateNode(createArrowFunction(modifiers, typeParameters, parameters, type, equalsGreaterThanToken, body), node) : node; } @@ -1135,11 +1165,31 @@ namespace ts { return node; } - export function updateConditional(node: ConditionalExpression, condition: Expression, whenTrue: Expression, whenFalse: Expression) { + /* @deprecated */ export function updateConditional( + node: ConditionalExpression, + condition: Expression, + whenTrue: Expression, + whenFalse: Expression): ConditionalExpression; + export function updateConditional( + node: ConditionalExpression, + condition: Expression, + questionToken: Token, + whenTrue: Expression, + colonToken: Token, + whenFalse: Expression): ConditionalExpression; + export function updateConditional(node: ConditionalExpression, condition: Expression, ...args: any[]) { + if (args.length === 2) { + const [whenTrue, whenFalse] = args; + return updateConditional(node, condition, node.questionToken, whenTrue, node.colonToken, whenFalse); + } + Debug.assert(args.length === 4); + const [questionToken, whenTrue, colonToken, whenFalse] = args; return node.condition !== condition + || node.questionToken !== questionToken || node.whenTrue !== whenTrue + || node.colonToken !== colonToken || node.whenFalse !== whenFalse - ? updateNode(createConditional(condition, node.questionToken, whenTrue, node.colonToken, whenFalse), node) + ? updateNode(createConditional(condition, questionToken, whenTrue, colonToken, whenFalse), node) : node; } diff --git a/src/compiler/transformers/es2017.ts b/src/compiler/transformers/es2017.ts index 43058358ee5f7..85a44e35983d4 100644 --- a/src/compiler/transformers/es2017.ts +++ b/src/compiler/transformers/es2017.ts @@ -197,9 +197,10 @@ namespace ts { /*typeParameters*/ undefined, visitParameterList(node.parameters, visitor, context), /*type*/ undefined, + node.equalsGreaterThanToken, getFunctionFlags(node) & FunctionFlags.Async ? transformAsyncFunctionBody(node) - : visitFunctionBody(node.body, visitor, context) + : visitFunctionBody(node.body, visitor, context), ); } diff --git a/src/compiler/transformers/esnext.ts b/src/compiler/transformers/esnext.ts index 3bdcc9e9ee722..0fca09b454017 100644 --- a/src/compiler/transformers/esnext.ts +++ b/src/compiler/transformers/esnext.ts @@ -595,7 +595,8 @@ namespace ts { /*typeParameters*/ undefined, visitParameterList(node.parameters, visitor, context), /*type*/ undefined, - transformFunctionBody(node) + node.equalsGreaterThanToken, + transformFunctionBody(node), ); enclosingFunctionFlags = savedEnclosingFunctionFlags; return updated; diff --git a/src/compiler/transformers/ts.ts b/src/compiler/transformers/ts.ts index 692c758bc7504..ad7aaab252471 100644 --- a/src/compiler/transformers/ts.ts +++ b/src/compiler/transformers/ts.ts @@ -2291,7 +2291,8 @@ namespace ts { /*typeParameters*/ undefined, visitParameterList(node.parameters, visitor, context), /*type*/ undefined, - visitFunctionBody(node.body, visitor, context) + node.equalsGreaterThanToken, + visitFunctionBody(node.body, visitor, context), ); return updated; } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 5a5724503c082..1deef10a6138b 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -4223,10 +4223,11 @@ namespace ts { } export const enum EmitHint { - SourceFile, // Emitting a SourceFile - Expression, // Emitting an Expression - IdentifierName, // Emitting an IdentifierName - Unspecified, // Emitting an otherwise unspecified node + SourceFile, // Emitting a SourceFile + Expression, // Emitting an Expression + IdentifierName, // Emitting an IdentifierName + MappedTypeParameter, // Emitting a TypeParameterDeclaration inside of a MappedTypeNode + Unspecified, // Emitting an otherwise unspecified node } /* @internal */ diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 25ba99cb15403..f116794c9c6c5 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -4628,8 +4628,7 @@ namespace ts { /* @internal */ export function isNodeArray(array: ReadonlyArray): array is NodeArray { - return array.hasOwnProperty("pos") - && array.hasOwnProperty("end"); + return array.hasOwnProperty("pos") && array.hasOwnProperty("end"); } // Literals diff --git a/src/compiler/visitor.ts b/src/compiler/visitor.ts index 1ce42199372d8..7d46630e227d4 100644 --- a/src/compiler/visitor.ts +++ b/src/compiler/visitor.ts @@ -488,6 +488,7 @@ namespace ts { nodesVisitor((node).typeParameters, visitor, isTypeParameterDeclaration), visitParameterList((node).parameters, visitor, context, nodesVisitor), visitNode((node).type, visitor, isTypeNode), + visitNode((node).equalsGreaterThanToken, visitor, isToken), visitFunctionBody((node).body, visitor, context)); case SyntaxKind.DeleteExpression: @@ -523,7 +524,9 @@ namespace ts { case SyntaxKind.ConditionalExpression: return updateConditional(node, visitNode((node).condition, visitor, isExpression), + visitNode((node).questionToken, visitor, isToken), visitNode((node).whenTrue, visitor, isExpression), + visitNode((node).colonToken, visitor, isToken), visitNode((node).whenFalse, visitor, isExpression)); case SyntaxKind.TemplateExpression: diff --git a/src/services/formatting/formatting.ts b/src/services/formatting/formatting.ts index ad9b2f179aac6..8be7f0e9e7384 100644 --- a/src/services/formatting/formatting.ts +++ b/src/services/formatting/formatting.ts @@ -729,6 +729,7 @@ namespace ts.formatting { parent: Node, parentStartLine: number, parentDynamicIndentation: DynamicIndentation): void { + Debug.assert(isNodeArray(nodes)); const listStartToken = getOpenTokenForList(parent, nodes); const listEndToken = getCloseTokenForOpenToken(listStartToken); diff --git a/src/services/refactors/extractMethod.ts b/src/services/refactors/extractMethod.ts index 9634b9c817281..4cec56474b953 100644 --- a/src/services/refactors/extractMethod.ts +++ b/src/services/refactors/extractMethod.ts @@ -678,7 +678,7 @@ namespace ts.refactor.extractMethod { range.facts & RangeFacts.IsGenerator ? createToken(SyntaxKind.AsteriskToken) : undefined, functionName, /*questionToken*/ undefined, - /*typeParameters*/[], + /*typeParameters*/ undefined, parameters, returnType, body @@ -690,7 +690,7 @@ namespace ts.refactor.extractMethod { range.facts & RangeFacts.IsAsyncFunction ? [createToken(SyntaxKind.AsyncKeyword)] : undefined, range.facts & RangeFacts.IsGenerator ? createToken(SyntaxKind.AsteriskToken) : undefined, functionName, - /*typeParameters*/[], + /*typeParameters*/ undefined, parameters, returnType, body diff --git a/src/services/textChanges.ts b/src/services/textChanges.ts index bddfc205db4c4..1c2c40e77f218 100644 --- a/src/services/textChanges.ts +++ b/src/services/textChanges.ts @@ -5,19 +5,25 @@ namespace ts.textChanges { * Currently for simplicity we store recovered positions on the node itself. * It can be changed to side-table later if we decide that current design is too invasive. */ - function getPos(n: TextRange) { - return (n)["__pos"]; + function getPos(n: TextRange): number { + const result = (n)["__pos"]; + Debug.assert(typeof result === "number"); + return result; } - function setPos(n: TextRange, pos: number) { + function setPos(n: TextRange, pos: number): void { + Debug.assert(typeof pos === "number"); (n)["__pos"] = pos; } - function getEnd(n: TextRange) { - return (n)["__end"]; + function getEnd(n: TextRange): number { + const result = (n)["__end"]; + Debug.assert(typeof result === "number"); + return result; } - function setEnd(n: TextRange, end: number) { + function setEnd(n: TextRange, end: number): void { + Debug.assert(typeof end === "number"); (n)["__end"] = end; } @@ -582,7 +588,7 @@ namespace ts.textChanges { readonly node: Node; } - export function getNonformattedText(node: Node, sourceFile: SourceFile | undefined, newLine: NewLineKind): NonFormattedText { + function getNonformattedText(node: Node, sourceFile: SourceFile | undefined, newLine: NewLineKind): NonFormattedText { const options = { newLine, target: sourceFile && sourceFile.languageVersion }; const writer = new Writer(getNewLineCharacter(options)); const printer = createPrinter(options, writer); @@ -590,7 +596,7 @@ namespace ts.textChanges { return { text: writer.getText(), node: assignPositionsToNode(node) }; } - export function applyFormatting(nonFormattedText: NonFormattedText, sourceFile: SourceFile, initialIndentation: number, delta: number, rulesProvider: formatting.RulesProvider) { + function applyFormatting(nonFormattedText: NonFormattedText, sourceFile: SourceFile, initialIndentation: number, delta: number, rulesProvider: formatting.RulesProvider) { const lineMap = computeLineStarts(nonFormattedText.text); const file: SourceFileLike = { text: nonFormattedText.text, @@ -616,14 +622,10 @@ namespace ts.textChanges { function assignPositionsToNode(node: Node): Node { const visited = visitEachChild(node, assignPositionsToNode, nullTransformationContext, assignPositionsToNodeArray, assignPositionsToNode); // create proxy node for non synthesized nodes - const newNode = nodeIsSynthesized(visited) - ? visited - : (Proxy.prototype = visited, new (Proxy)()); + const newNode = nodeIsSynthesized(visited) ? visited : Object.create(visited) as Node; newNode.pos = getPos(node); newNode.end = getEnd(node); return newNode; - - function Proxy() { } } function assignPositionsToNodeArray(nodes: NodeArray, visitor: Visitor, test?: (node: Node) => boolean, start?: number, count?: number) { diff --git a/tests/baselines/reference/extractMethod/extractMethod4.js b/tests/baselines/reference/extractMethod/extractMethod4.js index 07029b2d05063..8d4feb3ea2364 100644 --- a/tests/baselines/reference/extractMethod/extractMethod4.js +++ b/tests/baselines/reference/extractMethod/extractMethod4.js @@ -24,9 +24,9 @@ namespace A { async function newFunction() { let y = 5; - if(z) { - await z1; - } + if (z) { + await z1; + } return foo(); } } @@ -44,9 +44,9 @@ namespace A { async function newFunction(z: number, z1: any) { let y = 5; - if(z) { - await z1; - } + if (z) { + await z1; + } return foo(); } } @@ -64,9 +64,9 @@ namespace A { async function newFunction(z: number, z1: any) { let y = 5; - if(z) { - await z1; - } + if (z) { + await z1; + } return foo(); } } @@ -83,8 +83,8 @@ namespace A { } async function newFunction(z: number, z1: any, foo: () => void) { let y = 5; - if(z) { - await z1; -} + if (z) { + await z1; + } return foo(); } diff --git a/tests/baselines/reference/sourceMapValidationStatements.js.map b/tests/baselines/reference/sourceMapValidationStatements.js.map index 5841f329e5edf..40d65e0106c1c 100644 --- a/tests/baselines/reference/sourceMapValidationStatements.js.map +++ b/tests/baselines/reference/sourceMapValidationStatements.js.map @@ -1,2 +1,2 @@ //// [sourceMapValidationStatements.js.map] -{"version":3,"file":"sourceMapValidationStatements.js","sourceRoot":"","sources":["sourceMapValidationStatements.ts"],"names":[],"mappings":"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"} \ No newline at end of file +{"version":3,"file":"sourceMapValidationStatements.js","sourceRoot":"","sources":["sourceMapValidationStatements.ts"],"names":[],"mappings":"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"} \ No newline at end of file diff --git a/tests/baselines/reference/sourceMapValidationStatements.sourcemap.txt b/tests/baselines/reference/sourceMapValidationStatements.sourcemap.txt index 7c5c5bfcfeba6..aec7eaafc0629 100644 --- a/tests/baselines/reference/sourceMapValidationStatements.sourcemap.txt +++ b/tests/baselines/reference/sourceMapValidationStatements.sourcemap.txt @@ -1251,15 +1251,19 @@ sourceFile:sourceMapValidationStatements.ts 7 > ^^^^ 8 > ^ 9 > ^ -10> ^^^ -11> ^ -12> ^^^ -13> ^ -14> ^^^ -15> ^ -16> ^^^ -17> ^ -18> ^ +10> ^ +11> ^ +12> ^ +13> ^ +14> ^^^ +15> ^ +16> ^ +17> ^ +18> ^ +19> ^ +20> ^^^ +21> ^ +22> ^ 1-> > 2 > var @@ -1270,15 +1274,19 @@ sourceFile:sourceMapValidationStatements.ts 7 > == 8 > 1 9 > ) -10> ? -11> x -12> + -13> 1 -14> : -15> x -16> - -17> 1 -18> ; +10> +11> ? +12> +13> x +14> + +15> 1 +16> +17> : +18> +19> x +20> - +21> 1 +22> ; 1->Emitted(74, 5) Source(72, 5) + SourceIndex(0) 2 >Emitted(74, 9) Source(72, 9) + SourceIndex(0) 3 >Emitted(74, 10) Source(72, 10) + SourceIndex(0) @@ -1288,15 +1296,19 @@ sourceFile:sourceMapValidationStatements.ts 7 >Emitted(74, 19) Source(72, 19) + SourceIndex(0) 8 >Emitted(74, 20) Source(72, 20) + SourceIndex(0) 9 >Emitted(74, 21) Source(72, 21) + SourceIndex(0) -10>Emitted(74, 24) Source(72, 24) + SourceIndex(0) -11>Emitted(74, 25) Source(72, 25) + SourceIndex(0) -12>Emitted(74, 28) Source(72, 28) + SourceIndex(0) -13>Emitted(74, 29) Source(72, 29) + SourceIndex(0) -14>Emitted(74, 32) Source(72, 32) + SourceIndex(0) -15>Emitted(74, 33) Source(72, 33) + SourceIndex(0) -16>Emitted(74, 36) Source(72, 36) + SourceIndex(0) -17>Emitted(74, 37) Source(72, 37) + SourceIndex(0) -18>Emitted(74, 38) Source(72, 38) + SourceIndex(0) +10>Emitted(74, 22) Source(72, 22) + SourceIndex(0) +11>Emitted(74, 23) Source(72, 23) + SourceIndex(0) +12>Emitted(74, 24) Source(72, 24) + SourceIndex(0) +13>Emitted(74, 25) Source(72, 25) + SourceIndex(0) +14>Emitted(74, 28) Source(72, 28) + SourceIndex(0) +15>Emitted(74, 29) Source(72, 29) + SourceIndex(0) +16>Emitted(74, 30) Source(72, 30) + SourceIndex(0) +17>Emitted(74, 31) Source(72, 31) + SourceIndex(0) +18>Emitted(74, 32) Source(72, 32) + SourceIndex(0) +19>Emitted(74, 33) Source(72, 33) + SourceIndex(0) +20>Emitted(74, 36) Source(72, 36) + SourceIndex(0) +21>Emitted(74, 37) Source(72, 37) + SourceIndex(0) +22>Emitted(74, 38) Source(72, 38) + SourceIndex(0) --- >>> (x == 1) ? x + 1 : x - 1; 1 >^^^^ @@ -1305,15 +1317,19 @@ sourceFile:sourceMapValidationStatements.ts 4 > ^^^^ 5 > ^ 6 > ^ -7 > ^^^ -8 > ^ -9 > ^^^ -10> ^ -11> ^^^ -12> ^ -13> ^^^ -14> ^ -15> ^ +7 > ^ +8 > ^ +9 > ^ +10> ^ +11> ^^^ +12> ^ +13> ^ +14> ^ +15> ^ +16> ^ +17> ^^^ +18> ^ +19> ^ 1 > > 2 > ( @@ -1321,30 +1337,38 @@ sourceFile:sourceMapValidationStatements.ts 4 > == 5 > 1 6 > ) -7 > ? -8 > x -9 > + -10> 1 -11> : -12> x -13> - -14> 1 -15> ; +7 > +8 > ? +9 > +10> x +11> + +12> 1 +13> +14> : +15> +16> x +17> - +18> 1 +19> ; 1 >Emitted(75, 5) Source(73, 5) + SourceIndex(0) 2 >Emitted(75, 6) Source(73, 6) + SourceIndex(0) 3 >Emitted(75, 7) Source(73, 7) + SourceIndex(0) 4 >Emitted(75, 11) Source(73, 11) + SourceIndex(0) 5 >Emitted(75, 12) Source(73, 12) + SourceIndex(0) 6 >Emitted(75, 13) Source(73, 13) + SourceIndex(0) -7 >Emitted(75, 16) Source(73, 16) + SourceIndex(0) -8 >Emitted(75, 17) Source(73, 17) + SourceIndex(0) -9 >Emitted(75, 20) Source(73, 20) + SourceIndex(0) -10>Emitted(75, 21) Source(73, 21) + SourceIndex(0) -11>Emitted(75, 24) Source(73, 24) + SourceIndex(0) -12>Emitted(75, 25) Source(73, 25) + SourceIndex(0) -13>Emitted(75, 28) Source(73, 28) + SourceIndex(0) -14>Emitted(75, 29) Source(73, 29) + SourceIndex(0) -15>Emitted(75, 30) Source(73, 30) + SourceIndex(0) +7 >Emitted(75, 14) Source(73, 14) + SourceIndex(0) +8 >Emitted(75, 15) Source(73, 15) + SourceIndex(0) +9 >Emitted(75, 16) Source(73, 16) + SourceIndex(0) +10>Emitted(75, 17) Source(73, 17) + SourceIndex(0) +11>Emitted(75, 20) Source(73, 20) + SourceIndex(0) +12>Emitted(75, 21) Source(73, 21) + SourceIndex(0) +13>Emitted(75, 22) Source(73, 22) + SourceIndex(0) +14>Emitted(75, 23) Source(73, 23) + SourceIndex(0) +15>Emitted(75, 24) Source(73, 24) + SourceIndex(0) +16>Emitted(75, 25) Source(73, 25) + SourceIndex(0) +17>Emitted(75, 28) Source(73, 28) + SourceIndex(0) +18>Emitted(75, 29) Source(73, 29) + SourceIndex(0) +19>Emitted(75, 30) Source(73, 30) + SourceIndex(0) --- >>> x === 1; 1 >^^^^ diff --git a/tests/baselines/reference/ternaryExpressionSourceMap.js.map b/tests/baselines/reference/ternaryExpressionSourceMap.js.map index 9340c972274f0..27160910378f4 100644 --- a/tests/baselines/reference/ternaryExpressionSourceMap.js.map +++ b/tests/baselines/reference/ternaryExpressionSourceMap.js.map @@ -1,2 +1,2 @@ //// [ternaryExpressionSourceMap.js.map] -{"version":3,"file":"ternaryExpressionSourceMap.js","sourceRoot":"","sources":["ternaryExpressionSourceMap.ts"],"names":[],"mappings":"AAAA,IAAI,CAAC,GAAG,CAAC,CAAC;AACV,IAAI,GAAG,GAAG,CAAC,GAAG,cAAM,OAAA,CAAC,EAAD,CAAC,GAAG,cAAM,OAAA,CAAC,EAAD,CAAC,CAAC"} \ No newline at end of file +{"version":3,"file":"ternaryExpressionSourceMap.js","sourceRoot":"","sources":["ternaryExpressionSourceMap.ts"],"names":[],"mappings":"AAAA,IAAI,CAAC,GAAG,CAAC,CAAC;AACV,IAAI,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,cAAM,OAAA,CAAC,EAAD,CAAC,CAAC,CAAC,CAAC,cAAM,OAAA,CAAC,EAAD,CAAC,CAAC"} \ No newline at end of file diff --git a/tests/baselines/reference/ternaryExpressionSourceMap.sourcemap.txt b/tests/baselines/reference/ternaryExpressionSourceMap.sourcemap.txt index d46e703e3570d..87e3ce023047a 100644 --- a/tests/baselines/reference/ternaryExpressionSourceMap.sourcemap.txt +++ b/tests/baselines/reference/ternaryExpressionSourceMap.sourcemap.txt @@ -35,55 +35,67 @@ sourceFile:ternaryExpressionSourceMap.ts 3 > ^^^ 4 > ^^^ 5 > ^ -6 > ^^^ -7 > ^^^^^^^^^^^^^^ -8 > ^^^^^^^ -9 > ^ -10> ^^ -11> ^ -12> ^^^ -13> ^^^^^^^^^^^^^^ -14> ^^^^^^^ -15> ^ -16> ^^ -17> ^ -18> ^ +6 > ^ +7 > ^ +8 > ^ +9 > ^^^^^^^^^^^^^^ +10> ^^^^^^^ +11> ^ +12> ^^ +13> ^ +14> ^ +15> ^ +16> ^ +17> ^^^^^^^^^^^^^^ +18> ^^^^^^^ +19> ^ +20> ^^ +21> ^ +22> ^ 1-> > 2 >var 3 > foo 4 > = 5 > x -6 > ? -7 > () => -8 > -9 > 0 -10> -11> 0 -12> : -13> () => -14> -15> 0 -16> -17> 0 -18> ; +6 > +7 > ? +8 > +9 > () => +10> +11> 0 +12> +13> 0 +14> +15> : +16> +17> () => +18> +19> 0 +20> +21> 0 +22> ; 1->Emitted(2, 1) Source(2, 1) + SourceIndex(0) 2 >Emitted(2, 5) Source(2, 5) + SourceIndex(0) 3 >Emitted(2, 8) Source(2, 8) + SourceIndex(0) 4 >Emitted(2, 11) Source(2, 11) + SourceIndex(0) 5 >Emitted(2, 12) Source(2, 12) + SourceIndex(0) -6 >Emitted(2, 15) Source(2, 15) + SourceIndex(0) -7 >Emitted(2, 29) Source(2, 21) + SourceIndex(0) -8 >Emitted(2, 36) Source(2, 21) + SourceIndex(0) -9 >Emitted(2, 37) Source(2, 22) + SourceIndex(0) -10>Emitted(2, 39) Source(2, 21) + SourceIndex(0) -11>Emitted(2, 40) Source(2, 22) + SourceIndex(0) -12>Emitted(2, 43) Source(2, 25) + SourceIndex(0) -13>Emitted(2, 57) Source(2, 31) + SourceIndex(0) -14>Emitted(2, 64) Source(2, 31) + SourceIndex(0) -15>Emitted(2, 65) Source(2, 32) + SourceIndex(0) -16>Emitted(2, 67) Source(2, 31) + SourceIndex(0) -17>Emitted(2, 68) Source(2, 32) + SourceIndex(0) -18>Emitted(2, 69) Source(2, 33) + SourceIndex(0) +6 >Emitted(2, 13) Source(2, 13) + SourceIndex(0) +7 >Emitted(2, 14) Source(2, 14) + SourceIndex(0) +8 >Emitted(2, 15) Source(2, 15) + SourceIndex(0) +9 >Emitted(2, 29) Source(2, 21) + SourceIndex(0) +10>Emitted(2, 36) Source(2, 21) + SourceIndex(0) +11>Emitted(2, 37) Source(2, 22) + SourceIndex(0) +12>Emitted(2, 39) Source(2, 21) + SourceIndex(0) +13>Emitted(2, 40) Source(2, 22) + SourceIndex(0) +14>Emitted(2, 41) Source(2, 23) + SourceIndex(0) +15>Emitted(2, 42) Source(2, 24) + SourceIndex(0) +16>Emitted(2, 43) Source(2, 25) + SourceIndex(0) +17>Emitted(2, 57) Source(2, 31) + SourceIndex(0) +18>Emitted(2, 64) Source(2, 31) + SourceIndex(0) +19>Emitted(2, 65) Source(2, 32) + SourceIndex(0) +20>Emitted(2, 67) Source(2, 31) + SourceIndex(0) +21>Emitted(2, 68) Source(2, 32) + SourceIndex(0) +22>Emitted(2, 69) Source(2, 33) + SourceIndex(0) --- >>>//# sourceMappingURL=ternaryExpressionSourceMap.js.map \ No newline at end of file diff --git a/tests/baselines/reference/typeGuardsInRightOperandOfAndAndOperator.js b/tests/baselines/reference/typeGuardsInRightOperandOfAndAndOperator.js index be1c497e3ea0d..5483f314fb9e4 100644 --- a/tests/baselines/reference/typeGuardsInRightOperandOfAndAndOperator.js +++ b/tests/baselines/reference/typeGuardsInRightOperandOfAndAndOperator.js @@ -85,6 +85,8 @@ function foo7(x) { return typeof x !== "string" && ((z = x) // number | boolean && (typeof x === "number" + // change value of x ? ((x = 10) && x.toString()) // x is number + // do not change value : ((y = x) && x.toString()))); // x is boolean } diff --git a/tests/baselines/reference/typeGuardsInRightOperandOfOrOrOperator.js b/tests/baselines/reference/typeGuardsInRightOperandOfOrOrOperator.js index a8d66dc5fa22c..c3143999d3a2c 100644 --- a/tests/baselines/reference/typeGuardsInRightOperandOfOrOrOperator.js +++ b/tests/baselines/reference/typeGuardsInRightOperandOfOrOrOperator.js @@ -87,6 +87,8 @@ function foo7(x) { return typeof x === "string" || ((z = x) // number | boolean || (typeof x === "number" + // change value of x ? ((x = 10) && x.toString()) // number | boolean | string + // do not change value : ((y = x) && x.toString()))); // number | boolean | string } diff --git a/tests/cases/fourslash/extract-method-formatting.ts b/tests/cases/fourslash/extract-method-formatting.ts new file mode 100644 index 0000000000000..1342e5632e800 --- /dev/null +++ b/tests/cases/fourslash/extract-method-formatting.ts @@ -0,0 +1,24 @@ +/// + +////function f(x: number): number { +//// /*start*/switch (x) {case 0: +////return 0;}/*end*/ +////} + +goTo.select('start', 'end') +edit.applyRefactor({ + refactorName: "Extract Method", + actionName: "scope_1", + actionDescription: "Extract function into global scope", +}); +verify.currentFileContentIs( +`function f(x: number): number { + return newFunction(x); +} +function newFunction(x: number) { + switch (x) { + case 0: + return 0; + } +} +`);