mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-11-18 20:11:14 +00:00
Merge branch 'master' into m-lambda-to-fn
This commit is contained in:
41 files changed
+6350
-5923
No files matched your search
@@ -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;
|
||||
|
||||
|
||||
+5837
-5829
File diff suppressed because it is too large.
Load diff
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Vendored
+14
-14
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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 " } :
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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",
|
||||
|
||||
Reference in new issue
Block a user