Merge branch 'master' into m-lambda-to-fn

This commit is contained in:
Jesse Trinity
2020-06-01 13:53:19 -07:00
committed by GitHub
41 changed files with 6350 additions and 5923 deletions
View File
+8 -1
View File
@@ -28769,7 +28769,14 @@ namespace ts {
}
case SyntaxKind.CommaToken:
if (!compilerOptions.allowUnreachableCode && isSideEffectFree(left) && !isEvalNode(right)) {
error(left, Diagnostics.Left_side_of_comma_operator_is_unused_and_has_no_side_effects);
const sf = getSourceFileOfNode(left);
const sourceText = sf.text;
const start = skipTrivia(sourceText, left.pos);
const isInDiag2657 = sf.parseDiagnostics.some(diag => {
if (diag.code !== Diagnostics.JSX_expressions_must_have_one_parent_element.code) return false;
return textSpanContainsPosition(diag, start);
});
if (!isInDiag2657) error(left, Diagnostics.Left_side_of_comma_operator_is_unused_and_has_no_side_effects);
}
return rightType;
File diff suppressed because it is too large Load Diff
+4 -3
View File
@@ -4503,7 +4503,7 @@ namespace ts {
return finishNode(node);
}
function parseJsxElementOrSelfClosingElementOrFragment(inExpressionContext: boolean): JsxElement | JsxSelfClosingElement | JsxFragment {
function parseJsxElementOrSelfClosingElementOrFragment(inExpressionContext: boolean, topInvalidNodePosition?: number): JsxElement | JsxSelfClosingElement | JsxFragment {
const opening = parseJsxOpeningOrSelfClosingElementOrOpeningFragment(inExpressionContext);
let result: JsxElement | JsxSelfClosingElement | JsxFragment;
if (opening.kind === SyntaxKind.JsxOpeningElement) {
@@ -4541,15 +4541,16 @@ namespace ts {
// Since JSX elements are invalid < operands anyway, this lookahead parse will only occur in error scenarios
// of one sort or another.
if (inExpressionContext && token() === SyntaxKind.LessThanToken) {
const invalidElement = tryParse(() => parseJsxElementOrSelfClosingElementOrFragment(/*inExpressionContext*/ true));
const topBadPos = typeof topInvalidNodePosition === "undefined" ? result.pos : topInvalidNodePosition;
const invalidElement = tryParse(() => parseJsxElementOrSelfClosingElementOrFragment(/*inExpressionContext*/ true, topBadPos));
if (invalidElement) {
parseErrorAtCurrentToken(Diagnostics.JSX_expressions_must_have_one_parent_element);
const badNode = <BinaryExpression>createNode(SyntaxKind.BinaryExpression, result.pos);
badNode.end = invalidElement.end;
badNode.left = result;
badNode.right = invalidElement;
badNode.operatorToken = createMissingNode(SyntaxKind.CommaToken, /*reportAtCurrentPosition*/ false);
badNode.operatorToken.pos = badNode.operatorToken.end = badNode.right.pos;
parseErrorAt(skipTrivia(sourceText, topBadPos), invalidElement.end, Diagnostics.JSX_expressions_must_have_one_parent_element);
return <JsxElement><Node>badNode;
}
}
+14 -14
View File
@@ -434,48 +434,48 @@ interface String {
startsWith(searchString: string, position?: number): boolean;
/**
* Returns an <a> HTML anchor element and sets the name attribute to the text value
* Returns an `<a>` HTML anchor element and sets the name attribute to the text value
* @param name
*/
anchor(name: string): string;
/** Returns a <big> HTML element */
/** Returns a `<big>` HTML element */
big(): string;
/** Returns a <blink> HTML element */
/** Returns a `<blink>` HTML element */
blink(): string;
/** Returns a <b> HTML element */
/** Returns a `<b>` HTML element */
bold(): string;
/** Returns a <tt> HTML element */
/** Returns a `<tt>` HTML element */
fixed(): string;
/** Returns a <font> HTML element and sets the color attribute value */
/** Returns a `<font>` HTML element and sets the color attribute value */
fontcolor(color: string): string;
/** Returns a <font> HTML element and sets the size attribute value */
/** Returns a `<font>` HTML element and sets the size attribute value */
fontsize(size: number): string;
/** Returns a <font> HTML element and sets the size attribute value */
/** Returns a `<font>` HTML element and sets the size attribute value */
fontsize(size: string): string;
/** Returns an <i> HTML element */
/** Returns an `<i>` HTML element */
italics(): string;
/** Returns an <a> HTML element and sets the href attribute value */
/** Returns an `<a>` HTML element and sets the href attribute value */
link(url: string): string;
/** Returns a <small> HTML element */
/** Returns a `<small>` HTML element */
small(): string;
/** Returns a <strike> HTML element */
/** Returns a `<strike>` HTML element */
strike(): string;
/** Returns a <sub> HTML element */
/** Returns a `<sub>` HTML element */
sub(): string;
/** Returns a <sup> HTML element */
/** Returns a `<sup>` HTML element */
sup(): string;
}
@@ -5376,6 +5376,15 @@
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";Generate_get_and_set_accessors_for_all_overriding_properties_95119" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Generate 'get' and 'set' accessors for all overriding properties]]></Val>
<Tgt Cat="Text" Stat="Loc" Orig="New">
<Val><![CDATA[为所有重写属性生成 "get" 和 "set" 访问器]]></Val>
</Tgt>
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";Generates_a_CPU_profile_6223" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Generates a CPU profile.]]></Val>
@@ -4759,7 +4759,7 @@
<Str Cat="Text">
<Val><![CDATA[Exponentiation cannot be performed on 'bigint' values unless the 'target' option is set to 'es2016' or later.]]></Val>
<Tgt Cat="Text" Stat="Loc" Orig="New">
<Val><![CDATA[除非 [目標]5D; 選項設定為 'es2016' 或更新版本,否則無法在 'bigint' 值執行指數運算。]]></Val>
<Val><![CDATA['target' 選項必須設定為 'es2016' 或更新版本,才可以對 'bigint' 值執行乘冪運算。]]></Val>
</Tgt>
</Str>
<Disp Icon="Str" />
@@ -5376,6 +5376,15 @@
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";Generate_get_and_set_accessors_for_all_overriding_properties_95119" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Generate 'get' and 'set' accessors for all overriding properties]]></Val>
<Tgt Cat="Text" Stat="Loc" Orig="New">
<Val><![CDATA[為所有覆寫屬性產生 'get' 和 'set' 存取子]]></Val>
</Tgt>
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";Generates_a_CPU_profile_6223" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Generates a CPU profile.]]></Val>
@@ -12748,7 +12757,7 @@
<Str Cat="Text">
<Val><![CDATA['export *' does not re-export a default.]]></Val>
<Tgt Cat="Text" Stat="Loc" Orig="New">
<Val><![CDATA['export *' 不會重新匯出預設。]]></Val>
<Val><![CDATA['export *' 不會重新匯出預設匯出。]]></Val>
</Tgt>
</Str>
<Disp Icon="Str" />
@@ -5385,6 +5385,15 @@
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";Generate_get_and_set_accessors_for_all_overriding_properties_95119" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Generate 'get' and 'set' accessors for all overriding properties]]></Val>
<Tgt Cat="Text" Stat="Loc" Orig="New">
<Val><![CDATA[Generovat přístupové objekty get a set pro všechny přepisující vlastnosti]]></Val>
</Tgt>
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";Generates_a_CPU_profile_6223" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Generates a CPU profile.]]></Val>
@@ -5373,6 +5373,15 @@
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";Generate_get_and_set_accessors_for_all_overriding_properties_95119" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Generate 'get' and 'set' accessors for all overriding properties]]></Val>
<Tgt Cat="Text" Stat="Loc" Orig="New">
<Val><![CDATA[get- und set-Zugriffsmethoden für alle überschreibenden Eigenschaften generieren]]></Val>
</Tgt>
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";Generates_a_CPU_profile_6223" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Generates a CPU profile.]]></Val>
@@ -5388,6 +5388,15 @@
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";Generate_get_and_set_accessors_for_all_overriding_properties_95119" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Generate 'get' and 'set' accessors for all overriding properties]]></Val>
<Tgt Cat="Text" Stat="Loc" Orig="New">
<Val><![CDATA[Generar los descriptores de acceso "get" y "set" para todas las propiedades de reemplazo]]></Val>
</Tgt>
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";Generates_a_CPU_profile_6223" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Generates a CPU profile.]]></Val>
@@ -5388,6 +5388,15 @@
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";Generate_get_and_set_accessors_for_all_overriding_properties_95119" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Generate 'get' and 'set' accessors for all overriding properties]]></Val>
<Tgt Cat="Text" Stat="Loc" Orig="New">
<Val><![CDATA[Générer des accesseurs 'get' et 'set' pour toutes les propriétés de remplacement]]></Val>
</Tgt>
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";Generates_a_CPU_profile_6223" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Generates a CPU profile.]]></Val>
@@ -3691,7 +3691,7 @@
<Str Cat="Text">
<Val><![CDATA[Declaration augments declaration in another file. This cannot be serialized.]]></Val>
<Tgt Cat="Text" Stat="Loc" Orig="New">
<Val><![CDATA[宣言は別のファイル内の宣言を拡張します。これをシリアル化できません。]]></Val>
<Val><![CDATA[この宣言は別のファイル内の宣言を拡張します。この操作はシリアル化できません。]]></Val>
</Tgt>
</Str>
<Disp Icon="Str" />
@@ -5376,6 +5376,15 @@
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";Generate_get_and_set_accessors_for_all_overriding_properties_95119" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Generate 'get' and 'set' accessors for all overriding properties]]></Val>
<Tgt Cat="Text" Stat="Loc" Orig="New">
<Val><![CDATA[すべてのオーバーライドするプロパティに対して 'get' および 'set' アクセサーを生成します]]></Val>
</Tgt>
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";Generates_a_CPU_profile_6223" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Generates a CPU profile.]]></Val>
@@ -12091,7 +12100,7 @@
<Str Cat="Text">
<Val><![CDATA['{0}' can only be imported by using 'import {1} = require({2})' or a default import.]]></Val>
<Tgt Cat="Text" Stat="Loc" Orig="New">
<Val><![CDATA['{0}' をインポートするには、'import {1} = require ({2})' または既定のインポートを使用する必要があります。]]></Val>
<Val><![CDATA['{0}' をインポートするには、'import {1} = require({2})' または既定のインポートを使用する必要があります。]]></Val>
</Tgt>
</Str>
<Disp Icon="Str" />
@@ -12748,7 +12757,7 @@
<Str Cat="Text">
<Val><![CDATA['export *' does not re-export a default.]]></Val>
<Tgt Cat="Text" Stat="Loc" Orig="New">
<Val><![CDATA['export *' では既定値が再エクスポートされません。]]></Val>
<Val><![CDATA['export *' では既定のものは再エクスポートされません。]]></Val>
</Tgt>
</Str>
<Disp Icon="Str" />
@@ -5376,6 +5376,15 @@
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";Generate_get_and_set_accessors_for_all_overriding_properties_95119" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Generate 'get' and 'set' accessors for all overriding properties]]></Val>
<Tgt Cat="Text" Stat="Loc" Orig="New">
<Val><![CDATA[모든 재정의 속성에 대한 'get' 및 'set' 접근자를 생성합니다.]]></Val>
</Tgt>
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";Generates_a_CPU_profile_6223" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Generates a CPU profile.]]></Val>
@@ -5366,6 +5366,15 @@
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";Generate_get_and_set_accessors_for_all_overriding_properties_95119" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Generate 'get' and 'set' accessors for all overriding properties]]></Val>
<Tgt Cat="Text" Stat="Loc" Orig="New">
<Val><![CDATA[Generuj metody dostępu „get” i „set” dla wszystkich właściwości przesłaniających]]></Val>
</Tgt>
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";Generates_a_CPU_profile_6223" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Generates a CPU profile.]]></Val>
@@ -5369,6 +5369,15 @@
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";Generate_get_and_set_accessors_for_all_overriding_properties_95119" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Generate 'get' and 'set' accessors for all overriding properties]]></Val>
<Tgt Cat="Text" Stat="Loc" Orig="New">
<Val><![CDATA[Gerar os acessadores 'get' e 'set' para todas as propriedades de substituição]]></Val>
</Tgt>
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";Generates_a_CPU_profile_6223" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Generates a CPU profile.]]></Val>
@@ -5369,6 +5369,15 @@
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";Generate_get_and_set_accessors_for_all_overriding_properties_95119" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Generate 'get' and 'set' accessors for all overriding properties]]></Val>
<Tgt Cat="Text" Stat="Loc" Orig="New">
<Val><![CDATA[Tüm geçersiz kılma özellikleri için 'get' ve 'set' erişimcileri oluşturun]]></Val>
</Tgt>
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";Generates_a_CPU_profile_6223" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Generates a CPU profile.]]></Val>
@@ -0,0 +1,71 @@
/* @internal */
namespace ts.codefix {
const fixID = "wrapJsxInFragment";
const errorCodes = [Diagnostics.JSX_expressions_must_have_one_parent_element.code];
registerCodeFix({
errorCodes,
getCodeActions: context => {
const { jsx } = context.program.getCompilerOptions();
if (jsx !== JsxEmit.React && jsx !== JsxEmit.ReactNative) {
return undefined;
}
const { sourceFile, span } = context;
const node = findNodeToFix(sourceFile, span.start);
if (!node) return undefined;
const changes = textChanges.ChangeTracker.with(context, t => doChange(t, sourceFile, node));
return [createCodeFixAction(fixID, changes, Diagnostics.Wrap_in_JSX_fragment, fixID, Diagnostics.Wrap_all_unparented_JSX_in_JSX_fragment)];
},
fixIds: [fixID],
getAllCodeActions: context => codeFixAll(context, errorCodes, (changes, diag) => {
const node = findNodeToFix(context.sourceFile, diag.start);
if (!node) return undefined;
doChange(changes, context.sourceFile, node);
}),
});
function findNodeToFix(sourceFile: SourceFile, pos: number): BinaryExpression | undefined {
// The error always at 1st token that is "<" in "<a /><a />"
const lessThanToken = getTokenAtPosition(sourceFile, pos);
const firstJsxElementOrOpenElement = lessThanToken.parent;
let binaryExpr = firstJsxElementOrOpenElement.parent;
if (!isBinaryExpression(binaryExpr)) {
// In case the start element is a JsxSelfClosingElement, it the end.
// For JsxOpenElement, find one more parent
binaryExpr = binaryExpr.parent;
if (!isBinaryExpression(binaryExpr)) return undefined;
}
if (!nodeIsMissing(binaryExpr.operatorToken)) return undefined;
return binaryExpr;
}
function doChange(changeTracker: textChanges.ChangeTracker, sf: SourceFile, node: Node) {
const jsx = flattenInvalidBinaryExpr(node);
if (jsx) changeTracker.replaceNode(sf, node, createJsxFragment(createJsxOpeningFragment(), jsx, createJsxJsxClosingFragment()));
}
// The invalid syntax is constructed as
// InvalidJsxTree :: One of
// JsxElement CommaToken InvalidJsxTree
// JsxElement CommaToken JsxElement
function flattenInvalidBinaryExpr(node: Node): JsxChild[] | undefined {
const children: JsxChild[] = [];
let current = node;
while (true) {
if (isBinaryExpression(current) && nodeIsMissing(current.operatorToken) && current.operatorToken.kind === SyntaxKind.CommaToken) {
children.push(<JsxChild>current.left);
if (isJsxChild(current.right)) {
children.push(current.right);
// Indicates the tree has go to the bottom
return children;
}
else if (isBinaryExpression(current.right)) {
current = current.right;
continue;
}
// Unreachable case
else return undefined;
}
// Unreachable case
else return undefined;
}
}
}
+27 -10
View File
@@ -399,23 +399,40 @@ namespace ts.FindAllReferences {
function getPrefixAndSuffixText(entry: Entry, originalNode: Node, checker: TypeChecker): PrefixAndSuffix {
if (entry.kind !== EntryKind.Span && isIdentifier(originalNode)) {
const { node, kind } = entry;
const parent = node.parent;
const name = originalNode.text;
const isShorthandAssignment = isShorthandPropertyAssignment(node.parent);
if (isShorthandAssignment || isObjectBindingElementWithoutPropertyName(node.parent) && node.parent.name === node) {
const isShorthandAssignment = isShorthandPropertyAssignment(parent);
if (isShorthandAssignment || isObjectBindingElementWithoutPropertyName(parent) && parent.name === node) {
const prefixColon: PrefixAndSuffix = { prefixText: name + ": " };
const suffixColon: PrefixAndSuffix = { suffixText: ": " + name };
return kind === EntryKind.SearchedLocalFoundProperty ? prefixColon
: kind === EntryKind.SearchedPropertyFoundLocal ? suffixColon
// In `const o = { x }; o.x`, symbolAtLocation at `x` in `{ x }` is the property symbol.
// For a binding element `const { x } = o;`, symbolAtLocation at `x` is the property symbol.
: isShorthandAssignment ? suffixColon : prefixColon;
if (kind === EntryKind.SearchedLocalFoundProperty) {
return prefixColon;
}
if (kind === EntryKind.SearchedPropertyFoundLocal) {
return suffixColon;
}
// In `const o = { x }; o.x`, symbolAtLocation at `x` in `{ x }` is the property symbol.
// For a binding element `const { x } = o;`, symbolAtLocation at `x` is the property symbol.
if (isShorthandAssignment) {
const grandParent = parent.parent;
if (isObjectLiteralExpression(grandParent) &&
isBinaryExpression(grandParent.parent) &&
isModuleExportsAccessExpression(grandParent.parent.left)) {
return prefixColon;
}
return suffixColon;
}
else {
return prefixColon;
}
}
else if (isImportSpecifier(entry.node.parent) && !entry.node.parent.propertyName) {
else if (isImportSpecifier(parent) && !parent.propertyName) {
// If the original symbol was using this alias, just rename the alias.
const originalSymbol = isExportSpecifier(originalNode.parent) ? checker.getExportSpecifierLocalTargetSymbol(originalNode.parent) : checker.getSymbolAtLocation(originalNode);
return contains(originalSymbol!.declarations, entry.node.parent) ? { prefixText: name + " as " } : emptyOptions;
return contains(originalSymbol!.declarations, parent) ? { prefixText: name + " as " } : emptyOptions;
}
else if (isExportSpecifier(entry.node.parent) && !entry.node.parent.propertyName) {
else if (isExportSpecifier(parent) && !parent.propertyName) {
// If the symbol for the node is same as declared node symbol use prefix text
return originalNode === entry.node || checker.getSymbolAtLocation(originalNode) === checker.getSymbolAtLocation(entry.node) ?
{ prefixText: name + " as " } :
+6 -2
View File
@@ -279,9 +279,9 @@ namespace ts.formatting {
rule("NoSpaceBetweenEmptyBraceBrackets", SyntaxKind.OpenBraceToken, SyntaxKind.CloseBraceToken, [isOptionDisabled("insertSpaceAfterOpeningAndBeforeClosingEmptyBraces"), isNonJsxSameLineTokenContext], RuleAction.DeleteSpace),
// Insert space after opening and before closing template string braces
rule("SpaceAfterTemplateHeadAndMiddle", [SyntaxKind.TemplateHead, SyntaxKind.TemplateMiddle], anyToken, [isOptionEnabled("insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces"), isNonJsxSameLineTokenContext], RuleAction.InsertSpace),
rule("SpaceAfterTemplateHeadAndMiddle", [SyntaxKind.TemplateHead, SyntaxKind.TemplateMiddle], anyToken, [isOptionEnabled("insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces"), isNonJsxTextContext], RuleAction.InsertSpace, RuleFlags.CanDeleteNewLines),
rule("SpaceBeforeTemplateMiddleAndTail", anyToken, [SyntaxKind.TemplateMiddle, SyntaxKind.TemplateTail], [isOptionEnabled("insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces"), isNonJsxSameLineTokenContext], RuleAction.InsertSpace),
rule("NoSpaceAfterTemplateHeadAndMiddle", [SyntaxKind.TemplateHead, SyntaxKind.TemplateMiddle], anyToken, [isOptionDisabledOrUndefined("insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces"), isNonJsxSameLineTokenContext], RuleAction.DeleteSpace),
rule("NoSpaceAfterTemplateHeadAndMiddle", [SyntaxKind.TemplateHead, SyntaxKind.TemplateMiddle], anyToken, [isOptionDisabledOrUndefined("insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces"), isNonJsxTextContext], RuleAction.DeleteSpace, RuleFlags.CanDeleteNewLines),
rule("NoSpaceBeforeTemplateMiddleAndTail", anyToken, [SyntaxKind.TemplateMiddle, SyntaxKind.TemplateTail], [isOptionDisabledOrUndefined("insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces"), isNonJsxSameLineTokenContext], RuleAction.DeleteSpace),
// No space after { and before } in JSX expression
@@ -690,6 +690,10 @@ namespace ts.formatting {
return context.TokensAreOnSameLine() && context.contextNode.kind !== SyntaxKind.JsxText;
}
function isNonJsxTextContext(context: FormattingContext): boolean {
return context.contextNode.kind !== SyntaxKind.JsxText;
}
function isNonJsxElementOrFragmentContext(context: FormattingContext): boolean {
return context.contextNode.kind !== SyntaxKind.JsxElement && context.contextNode.kind !== SyntaxKind.JsxFragment;
}
+15 -1
View File
@@ -405,6 +405,20 @@ namespace ts.refactor.extractSymbol {
rangeFacts |= RangeFacts.UsesThis;
}
break;
case SyntaxKind.ArrowFunction:
// check if arrow function uses this
forEachChild(node, function check(n) {
if (isThis(n)) {
rangeFacts |= RangeFacts.UsesThis;
}
else if (isClassLike(n) || (isFunctionLike(n) && !isArrowFunction(n))) {
return false;
}
else {
forEachChild(n, check);
}
});
// falls through
case SyntaxKind.ClassDeclaration:
case SyntaxKind.FunctionDeclaration:
if (isSourceFile(node.parent) && node.parent.externalModuleIndicator === undefined) {
@@ -418,7 +432,7 @@ namespace ts.refactor.extractSymbol {
case SyntaxKind.Constructor:
case SyntaxKind.GetAccessor:
case SyntaxKind.SetAccessor:
// do not dive into functions (except arrow functions) or classes
// do not dive into functions or classes
return false;
}
+2 -2
View File
@@ -159,14 +159,14 @@ namespace ts.SymbolDisplay {
}
// try get the call/construct signature from the type if it matches
let callExpressionLike: CallExpression | NewExpression | JsxOpeningLikeElement | undefined;
let callExpressionLike: CallExpression | NewExpression | JsxOpeningLikeElement | TaggedTemplateExpression | undefined;
if (isCallOrNewExpression(location)) {
callExpressionLike = location;
}
else if (isCallExpressionTarget(location) || isNewExpressionTarget(location)) {
callExpressionLike = <CallExpression | NewExpression>location.parent;
}
else if (location.parent && isJsxOpeningLikeElement(location.parent) && isFunctionLike(symbol.valueDeclaration)) {
else if (location.parent && (isJsxOpeningLikeElement(location.parent) || isTaggedTemplateExpression(location.parent)) && isFunctionLike(symbol.valueDeclaration)) {
callExpressionLike = location.parent;
}
+1
View File
@@ -97,6 +97,7 @@
"codefixes/useDefaultImport.ts",
"codefixes/useBigintLiteral.ts",
"codefixes/fixAddModuleReferTypeMissingTypeof.ts",
"codefixes/wrapJsxInFragment.ts",
"codefixes/convertToMappedObjectType.ts",
"codefixes/removeUnnecessaryAwait.ts",
"codefixes/splitTypeOnlyImport.ts",
@@ -1,7 +1,7 @@
tests/cases/conformance/jsx/jsxEsprimaFbTestSuite.tsx(39,1): error TS2695: Left side of comma operator is unused and has no side effects.
tests/cases/conformance/jsx/jsxEsprimaFbTestSuite.tsx(39,1): error TS2657: JSX expressions must have one parent element.
tests/cases/conformance/jsx/jsxEsprimaFbTestSuite.tsx(39,17): error TS1005: '{' expected.
tests/cases/conformance/jsx/jsxEsprimaFbTestSuite.tsx(39,23): error TS1005: ';' expected.
tests/cases/conformance/jsx/jsxEsprimaFbTestSuite.tsx(39,23): error TS2304: Cannot find name 'right'.
tests/cases/conformance/jsx/jsxEsprimaFbTestSuite.tsx(39,23): error TS2657: JSX expressions must have one parent element.
tests/cases/conformance/jsx/jsxEsprimaFbTestSuite.tsx(39,41): error TS1382: Unexpected token. Did you mean `{'>'}` or `&gt;`?
tests/cases/conformance/jsx/jsxEsprimaFbTestSuite.tsx(39,57): error TS1109: Expression expected.
tests/cases/conformance/jsx/jsxEsprimaFbTestSuite.tsx(39,58): error TS1109: Expression expected.
@@ -47,14 +47,14 @@ tests/cases/conformance/jsx/jsxEsprimaFbTestSuite.tsx(39,58): error TS1109: Expr
<div><br />7x invalid-js-identifier</div>;
<LeftRight left=<a /> right=<b>monkeys /> gorillas</b> />;
~~~~~~~~~~~~~~~~
!!! error TS2695: Left side of comma operator is unused and has no side effects.
~~~~~~~~~~~~~~~~~~~~~
!!! error TS2657: JSX expressions must have one parent element.
~
!!! error TS1005: '{' expected.
~~~~~
!!! error TS2304: Cannot find name 'right'.
!!! error TS1005: ';' expected.
~~~~~
!!! error TS2657: JSX expressions must have one parent element.
!!! error TS2304: Cannot find name 'right'.
~
!!! error TS1382: Unexpected token. Did you mean `{'>'}` or `&gt;`?
~
@@ -33,10 +33,8 @@ tests/cases/conformance/jsx/16.tsx(1,2): error TS17008: JSX element 'a' has no c
tests/cases/conformance/jsx/16.tsx(1,10): error TS1005: '</' expected.
tests/cases/conformance/jsx/17.tsx(1,2): error TS17008: JSX element 'a' has no corresponding closing tag.
tests/cases/conformance/jsx/17.tsx(1,10): error TS1005: '</' expected.
tests/cases/conformance/jsx/18.tsx(1,9): error TS2695: Left side of comma operator is unused and has no side effects.
tests/cases/conformance/jsx/18.tsx(1,37): error TS2657: JSX expressions must have one parent element.
tests/cases/conformance/jsx/19.tsx(1,9): error TS2695: Left side of comma operator is unused and has no side effects.
tests/cases/conformance/jsx/19.tsx(1,64): error TS2657: JSX expressions must have one parent element.
tests/cases/conformance/jsx/18.tsx(1,30): error TS2657: JSX expressions must have one parent element.
tests/cases/conformance/jsx/19.tsx(1,9): error TS2657: JSX expressions must have one parent element.
tests/cases/conformance/jsx/2.tsx(1,3): error TS1003: Identifier expected.
tests/cases/conformance/jsx/20.tsx(1,10): error TS1005: '}' expected.
tests/cases/conformance/jsx/20.tsx(1,11): error TS1381: Unexpected token. Did you mean `{'}'}` or `&rbrace;`?
@@ -61,7 +59,7 @@ tests/cases/conformance/jsx/27.tsx(1,5): error TS1382: Unexpected token. Did you
tests/cases/conformance/jsx/28.tsx(1,2): error TS17008: JSX element 'a' has no corresponding closing tag.
tests/cases/conformance/jsx/28.tsx(1,6): error TS1005: '{' expected.
tests/cases/conformance/jsx/28.tsx(2,1): error TS1005: '</' expected.
tests/cases/conformance/jsx/29.tsx(1,1): error TS2695: Left side of comma operator is unused and has no side effects.
tests/cases/conformance/jsx/29.tsx(1,1): error TS2657: JSX expressions must have one parent element.
tests/cases/conformance/jsx/29.tsx(1,6): error TS1005: '{' expected.
tests/cases/conformance/jsx/29.tsx(1,7): error TS1003: Identifier expected.
tests/cases/conformance/jsx/29.tsx(2,1): error TS1005: '</' expected.
@@ -228,17 +226,13 @@ tests/cases/conformance/jsx/9.tsx(1,16): error TS1109: Expression expected.
!!! error TS17008: JSX element 'a' has no corresponding closing tag.
!!! error TS1005: '</' expected.
==== tests/cases/conformance/jsx/18.tsx (2 errors) ====
var x = <div>one</div><div>two</div>;;
~~~~~~~~~~~~~~
!!! error TS2695: Left side of comma operator is unused and has no side effects.
~
==== tests/cases/conformance/jsx/18.tsx (1 errors) ====
var x = /* Leading trivia */ <div>one</div><div>two</div>;;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2657: JSX expressions must have one parent element.
==== tests/cases/conformance/jsx/19.tsx (2 errors) ====
==== tests/cases/conformance/jsx/19.tsx (1 errors) ====
var x = <div>one</div> /* intervening comment */ <div>two</div>;;
~~~~~~~~~~~~~~
!!! error TS2695: Left side of comma operator is unused and has no side effects.
~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2657: JSX expressions must have one parent element.
==== tests/cases/conformance/jsx/20.tsx (2 errors) ====
<a>{"str";}</a>;
@@ -313,14 +307,15 @@ tests/cases/conformance/jsx/9.tsx(1,16): error TS1109: Expression expected.
!!! error TS1005: '</' expected.
==== tests/cases/conformance/jsx/29.tsx (4 errors) ====
<a b=<}>;
~~~~~
!!! error TS2695: Left side of comma operator is unused and has no side effects.
~~~~~~~~~
~
!!! error TS1005: '{' expected.
~
!!! error TS1003: Identifier expected.
!!! error TS2657: JSX expressions must have one parent element.
!!! error TS1005: '</' expected.
==== tests/cases/conformance/jsx/30.tsx (1 errors) ====
<a>}</a>;
@@ -37,7 +37,7 @@ declare var React: any;
//// [17.tsx]
<a b={}>;
//// [18.tsx]
var x = <div>one</div><div>two</div>;;
var x = /* Leading trivia */ <div>one</div><div>two</div>;;
//// [19.tsx]
var x = <div>one</div> /* intervening comment */ <div>two</div>;;
//// [20.tsx]
@@ -117,7 +117,7 @@ a['foo'] > ;
//// [17.jsx]
<a b=>;</>;
//// [18.jsx]
var x = <div>one</div>, <div>two</div>;
var x = /* Leading trivia */ <div>one</div>, <div>two</div>;
;
//// [19.jsx]
var x = <div>one</div> /* intervening comment */, /* intervening comment */ <div>two</div>;
@@ -50,7 +50,7 @@ No type information for this code.=== tests/cases/conformance/jsx/17.tsx ===
>b : Symbol(b, Decl(17.tsx, 0, 2))
=== tests/cases/conformance/jsx/18.tsx ===
var x = <div>one</div><div>two</div>;;
var x = /* Leading trivia */ <div>one</div><div>two</div>;;
>x : Symbol(x, Decl(18.tsx, 0, 3), Decl(19.tsx, 0, 3))
=== tests/cases/conformance/jsx/19.tsx ===
@@ -159,7 +159,7 @@ declare var React: any;
> : any
=== tests/cases/conformance/jsx/18.tsx ===
var x = <div>one</div><div>two</div>;;
var x = /* Leading trivia */ <div>one</div><div>two</div>;;
>x : any
><div>one</div><div>two</div> : any
><div>one</div> : any
@@ -1,23 +1,18 @@
tests/cases/conformance/jsx/file1.tsx(3,1): error TS2695: Left side of comma operator is unused and has no side effects.
tests/cases/conformance/jsx/file1.tsx(5,1): error TS2657: JSX expressions must have one parent element.
tests/cases/conformance/jsx/file2.tsx(1,9): error TS2695: Left side of comma operator is unused and has no side effects.
tests/cases/conformance/jsx/file2.tsx(2,1): error TS2657: JSX expressions must have one parent element.
tests/cases/conformance/jsx/file1.tsx(3,1): error TS2657: JSX expressions must have one parent element.
tests/cases/conformance/jsx/file2.tsx(1,9): error TS2657: JSX expressions must have one parent element.
==== tests/cases/conformance/jsx/file1.tsx (2 errors) ====
==== tests/cases/conformance/jsx/file1.tsx (1 errors) ====
declare namespace JSX { interface Element { } }
<div></div>
~~~~~~~~~~~
!!! error TS2695: Left side of comma operator is unused and has no side effects.
<div></div>
~~~~~~~~~~~
!!! error TS2657: JSX expressions must have one parent element.
==== tests/cases/conformance/jsx/file2.tsx (2 errors) ====
==== tests/cases/conformance/jsx/file2.tsx (1 errors) ====
var x = <div></div><div></div>
~~~~~~~~~~~
!!! error TS2695: Left side of comma operator is unused and has no side effects.
!!! error TS2657: JSX expressions must have one parent element.
~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2657: JSX expressions must have one parent element.
@@ -1,35 +1,30 @@
tests/cases/conformance/jsx/file1.tsx(3,1): error TS2695: Left side of comma operator is unused and has no side effects.
tests/cases/conformance/jsx/file1.tsx(3,1): error TS2657: JSX expressions must have one parent element.
tests/cases/conformance/jsx/file1.tsx(3,2): error TS2304: Cannot find name 'React'.
tests/cases/conformance/jsx/file1.tsx(4,2): error TS2304: Cannot find name 'React'.
tests/cases/conformance/jsx/file1.tsx(5,1): error TS2657: JSX expressions must have one parent element.
tests/cases/conformance/jsx/file2.tsx(1,9): error TS2695: Left side of comma operator is unused and has no side effects.
tests/cases/conformance/jsx/file2.tsx(1,9): error TS2657: JSX expressions must have one parent element.
tests/cases/conformance/jsx/file2.tsx(1,10): error TS2304: Cannot find name 'React'.
tests/cases/conformance/jsx/file2.tsx(1,21): error TS2304: Cannot find name 'React'.
tests/cases/conformance/jsx/file2.tsx(2,1): error TS2657: JSX expressions must have one parent element.
==== tests/cases/conformance/jsx/file1.tsx (4 errors) ====
==== tests/cases/conformance/jsx/file1.tsx (3 errors) ====
declare namespace JSX { interface Element { } }
<div></div>
~~~~~~~~~~~
!!! error TS2695: Left side of comma operator is unused and has no side effects.
~~~
!!! error TS2304: Cannot find name 'React'.
<div></div>
~~~~~~~~~~~
!!! error TS2657: JSX expressions must have one parent element.
~~~
!!! error TS2304: Cannot find name 'React'.
!!! error TS2657: JSX expressions must have one parent element.
==== tests/cases/conformance/jsx/file2.tsx (4 errors) ====
==== tests/cases/conformance/jsx/file2.tsx (3 errors) ====
var x = <div></div><div></div>
~~~~~~~~~~~
!!! error TS2695: Left side of comma operator is unused and has no side effects.
~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2657: JSX expressions must have one parent element.
~~~
!!! error TS2304: Cannot find name 'React'.
~~~
!!! error TS2304: Cannot find name 'React'.
!!! error TS2657: JSX expressions must have one parent element.
@@ -1,9 +1,10 @@
tests/cases/conformance/jsx/file.tsx(9,1): error TS2657: JSX expressions must have one parent element.
tests/cases/conformance/jsx/file.tsx(9,7): error TS17015: Expected corresponding closing tag for JSX fragment.
tests/cases/conformance/jsx/file.tsx(9,11): error TS17014: JSX fragment has no corresponding closing tag.
tests/cases/conformance/jsx/file.tsx(11,17): error TS1005: '</' expected.
==== tests/cases/conformance/jsx/file.tsx (3 errors) ====
==== tests/cases/conformance/jsx/file.tsx (4 errors) ====
declare module JSX {
interface Element { }
interface IntrinsicElements {
@@ -13,12 +14,16 @@ tests/cases/conformance/jsx/file.tsx(11,17): error TS1005: '</' expected.
declare var React: any;
<>hi</div> // Error
~~~~~~~~~~~~~~~~~~~
~~~
!!! error TS17015: Expected corresponding closing tag for JSX fragment.
~~~~~~~~~
<>eof // Error
~~~~~~~~~~~~~~~~
!!! error TS2657: JSX expressions must have one parent element.
~~
!!! error TS17014: JSX fragment has no corresponding closing tag.
@@ -36,7 +36,7 @@ declare var React: any;
// @filename: 17.tsx
<a b={}>;
// @filename: 18.tsx
var x = <div>one</div><div>two</div>;;
var x = /* Leading trivia */ <div>one</div><div>two</div>;;
// @filename: 19.tsx
var x = <div>one</div> /* intervening comment */ <div>two</div>;;
// @filename: 20.tsx
@@ -0,0 +1,7 @@
/// <reference path='fourslash.ts' />
// @jsx: react
// @Filename: /a.tsx
////[|<a /><a />|]
verify.rangeAfterCodeFix(`<><a /><a /></>`, /*includeWhiteSpace*/false, /*errorCode*/ undefined, /*index*/ 0);
@@ -0,0 +1,7 @@
/// <reference path='fourslash.ts' />
// @jsx: react
// @Filename: /a.tsx
////[|<a></a><a />|]
verify.rangeAfterCodeFix(`<><a></a><a /></>`, /*includeWhiteSpace*/false, /*errorCode*/ undefined, /*index*/ 0);
+23
View File
@@ -0,0 +1,23 @@
/// <reference path='fourslash.ts' />
////const foo = /*start*/{
//// a: 1,
//// b: () => { return 1; }
////}/*end*/
goTo.select("start", "end");
edit.applyRefactor({
refactorName: "Extract Symbol",
actionName: "function_scope_0",
actionDescription: "Extract to function in global scope",
newContent:
`const foo = /*RENAME*/newFunction()
function newFunction() {
return {
a: 1,
b: () => { return 1; }
};
}
`
});
+20
View File
@@ -0,0 +1,20 @@
/// <reference path='fourslash.ts' />
////function bar(fn: () => void) {}
////
////class Foo {
//// x: number;
//// foo() {
//// /*start*/bar(() => {
//// () => {
//// () => {
//// this.x;
//// }
//// }
//// });/*end*/
//// }
////}
goTo.select("start", "end");
verify.refactorAvailable("Extract Symbol", "function_scope_1");
verify.not.refactorAvailable("Extract Symbol", "function_scope_2");
@@ -0,0 +1,52 @@
/// <reference path='fourslash.ts' />
////const a1 = `${ 1 }${ 1 }`;
////const a2 = `
//// ${ 1 }${ 1 }
////`;
////const a3 = `
////
////
//// ${ 1 }${ 1 }
////`;
////const a4 = `
////
//// ${ 1 }${ 1 }
////
////`;
////const a5 = `text ${ 1 } text ${ 1 } text`;
////const a6 = `
//// text ${ 1 }
//// text ${ 1 }
//// text
////`;
format.setOption("insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces", false);
format.document();
verify.currentFileContentIs(
"const a1 = `${1}${1}`;\n" +
"const a2 = `\n" +
" ${1}${1}\n" +
"`;\n" +
"const a3 = `\n" +
"\n" +
"\n" +
" ${1}${1}\n" +
"`;\n" +
"const a4 = `\n" +
"\n" +
" ${1}${1}\n" +
"\n" +
"`;\n" +
"const a5 = `text ${1} text ${1} text`;\n" +
"const a6 = `\n" +
" text ${1}\n" +
" text ${1}\n" +
" text\n" +
"`;"
);
@@ -0,0 +1,52 @@
/// <reference path='fourslash.ts' />
////const a1 = `${1}${1}`;
////const a2 = `
//// ${1}${1}
////`;
////const a3 = `
////
////
//// ${1}${1}
////`;
////const a4 = `
////
//// ${1}${1}
////
////`;
////const a5 = `text ${1} text ${1} text`;
////const a6 = `
//// text ${1}
//// text ${1}
//// text
////`;
format.setOption("insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces", true);
format.document();
verify.currentFileContentIs(
"const a1 = `${ 1 }${ 1 }`;\n" +
"const a2 = `\n" +
" ${ 1 }${ 1 }\n" +
"`;\n" +
"const a3 = `\n" +
"\n" +
"\n" +
" ${ 1 }${ 1 }\n" +
"`;\n" +
"const a4 = `\n" +
"\n" +
" ${ 1 }${ 1 }\n" +
"\n" +
"`;\n" +
"const a5 = `text ${ 1 } text ${ 1 } text`;\n" +
"const a6 = `\n" +
" text ${ 1 }\n" +
" text ${ 1 }\n" +
" text\n" +
"`;"
);
@@ -0,0 +1,28 @@
/// <reference path='fourslash.ts'/>
////interface T1 {}
////class T2 {}
////type T3 = "a" | "b";
////
////declare function foo<T>(strings: TemplateStringsArray, ...values: T[]): void;
////
/////*1*/foo<number>``;
/////*2*/foo<string | number>``;
/////*3*/foo<{ a: number }>``;
/////*4*/foo<T1>``;
/////*5*/foo<T2>``;
/////*6*/foo<T3>``;
/////*7*/foo``;
verify.quickInfoAt("1", "function foo<number>(strings: TemplateStringsArray, ...values: number[]): void");
verify.quickInfoAt("2", "function foo<string | number>(strings: TemplateStringsArray, ...values: (string | number)[]): void");
verify.quickInfoAt("3",
`function foo<{
a: number;
}>(strings: TemplateStringsArray, ...values: {
a: number;
}[]): void`);
verify.quickInfoAt("4", "function foo<T1>(strings: TemplateStringsArray, ...values: T1[]): void");
verify.quickInfoAt("5", "function foo<T2>(strings: TemplateStringsArray, ...values: T2[]): void");
verify.quickInfoAt("6", "function foo<T3>(strings: TemplateStringsArray, ...values: T3[]): void");
verify.quickInfoAt("7", "function foo<unknown>(strings: TemplateStringsArray, ...values: unknown[]): void");
@@ -0,0 +1,8 @@
/// <reference path='fourslash.ts' />
////[|class [|{| "contextRangeIndex": 0 |}A|] {}|]
////module.exports = { [|A|] }
const [r0Def, r0, r1] = test.ranges();
verify.renameLocations(r0, { ranges: [r0, { range: r1, prefixText: "A: " }], providePrefixAndSuffixTextForRename: true });
verify.renameLocations(r1, { ranges: [r0, { range: r1, prefixText: "A: " }], providePrefixAndSuffixTextForRename: true });
@@ -0,0 +1,8 @@
/// <reference path='fourslash.ts' />
////[|class [|{| "contextRangeIndex": 0 |}A|] {}|]
////module.exports = { B: [|A|] }
const [r0Def, r0, r1] = test.ranges();
verify.renameLocations(r0, [r0, r1]);
verify.renameLocations(r1, [r0, r1]);
@@ -0,0 +1,10 @@
/// <reference path='fourslash.ts' />
// @allowJs: true
// @Filename: a.js
////[|class [|{| "contextRangeIndex": 0 |}A|] {}|]
////module.exports = { [|A|] }
const [r0Def, r0, r1] = test.ranges();
verify.renameLocations(r0, { ranges: [r0, { range: r1, prefixText: "A: " }], providePrefixAndSuffixTextForRename: true });
verify.renameLocations(r1, { ranges: [r0, { range: r1, prefixText: "A: " }], providePrefixAndSuffixTextForRename: true });