From 2f01d5667d9b8ba76ee14d0dab94635b3c0f3915 Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Thu, 14 Dec 2017 15:28:12 -0800 Subject: [PATCH] make jsx attributes mutable locations --- src/compiler/checker.ts | 10 ++- .../checkJsxChildrenProperty14.errors.txt | 8 +-- .../checkJsxChildrenProperty2.errors.txt | 44 ++++++------ .../checkJsxChildrenProperty5.errors.txt | 28 ++++---- .../checkJsxChildrenProperty7.errors.txt | 24 +++---- .../reference/tsxAttributeErrors.errors.txt | 16 ++--- .../tsxAttributeResolution1.errors.txt | 36 +++++----- .../tsxAttributeResolution10.errors.txt | 8 +-- .../tsxAttributeResolution11.errors.txt | 4 +- .../tsxAttributeResolution14.errors.txt | 16 ++--- .../tsxAttributeResolution15.errors.txt | 4 +- .../tsxAttributeResolution6.errors.txt | 8 +-- .../tsxAttributeResolution7.errors.txt | 8 +-- .../tsxAttributeResolution9.errors.txt | 8 +-- .../tsxElementResolution11.errors.txt | 4 +- .../tsxElementResolution12.errors.txt | 8 +-- .../tsxElementResolution3.errors.txt | 8 +-- .../tsxElementResolution4.errors.txt | 8 +-- ...sxInferenceShouldNotYieldAnyOnUnions.types | 16 ++--- ...ponentWithDefaultTypeParameter2.errors.txt | 12 ++-- ...ponentWithDefaultTypeParameter3.errors.txt | 8 +-- ...tsxSpreadAttributesResolution10.errors.txt | 12 ++-- ...tsxSpreadAttributesResolution12.errors.txt | 24 +++---- .../tsxSpreadAttributesResolution2.errors.txt | 8 +-- .../tsxSpreadAttributesResolution6.errors.txt | 16 ++--- ...elessFunctionComponentOverload4.errors.txt | 72 +++++++++---------- ...elessFunctionComponentOverload5.errors.txt | 36 +++++----- ...ponentWithDefaultTypeParameter2.errors.txt | 12 ++-- ...tsxStatelessFunctionComponents1.errors.txt | 28 ++++---- ...tsxStatelessFunctionComponents2.errors.txt | 4 +- ...ionComponentsWithTypeArguments2.errors.txt | 12 ++-- .../reference/tsxUnionElementType2.errors.txt | 16 ++--- .../reference/tsxUnionElementType4.errors.txt | 4 +- .../reference/tsxUnionElementType6.errors.txt | 12 ++-- tests/cases/fourslash/tsxQuickInfo6.ts | 2 +- 35 files changed, 274 insertions(+), 270 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index c1b57e5def701..ca73d92e0c014 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -14802,6 +14802,12 @@ namespace ts { } } + function checkJsxAttribute(node: JsxAttribute, checkMode?: CheckMode) { + return node.initializer + ? checkExpressionForMutableLocation(node.initializer, checkMode) + : trueType; // is sugar for + } + /** * Get attributes type of the JSX opening-like element. The result is from resolving "attributes" property of the opening-like element. * @@ -14824,9 +14830,7 @@ namespace ts { for (const attributeDecl of attributes.properties) { const member = attributeDecl.symbol; if (isJsxAttribute(attributeDecl)) { - const exprType = attributeDecl.initializer ? - checkExpression(attributeDecl.initializer, checkMode) : - trueType; // is sugar for + const exprType = checkJsxAttribute(attributeDecl, checkMode); const attributeSymbol = createSymbol(SymbolFlags.Property | SymbolFlags.Transient | member.flags, member.escapedName); attributeSymbol.declarations = member.declarations; diff --git a/tests/baselines/reference/checkJsxChildrenProperty14.errors.txt b/tests/baselines/reference/checkJsxChildrenProperty14.errors.txt index ecae349e19e63..ca12d59c2fd99 100644 --- a/tests/baselines/reference/checkJsxChildrenProperty14.errors.txt +++ b/tests/baselines/reference/checkJsxChildrenProperty14.errors.txt @@ -1,5 +1,5 @@ -tests/cases/conformance/jsx/file.tsx(42,27): error TS2322: Type '{ a: 10; b: "hi"; children: Element[]; }' is not assignable to type 'IntrinsicAttributes & SingleChildProp'. - Type '{ a: 10; b: "hi"; children: Element[]; }' is not assignable to type 'SingleChildProp'. +tests/cases/conformance/jsx/file.tsx(42,27): error TS2322: Type '{ a: number; b: string; children: Element[]; }' is not assignable to type 'IntrinsicAttributes & SingleChildProp'. + Type '{ a: number; b: string; children: Element[]; }' is not assignable to type 'SingleChildProp'. Types of property 'children' are incompatible. Type 'Element[]' is not assignable to type 'Element'. Property 'type' is missing in type 'Element[]'. @@ -49,8 +49,8 @@ tests/cases/conformance/jsx/file.tsx(42,27): error TS2322: Type '{ a: 10; b: "hi // Error let k5 = <>