|
| 1 | +//// [tests/cases/conformance/jsx/inline/inlineJsxFactoryDeclarationsLocalTypes.tsx] //// |
| 2 | + |
| 3 | +//// [renderer.d.ts] |
| 4 | +export namespace dom { |
| 5 | + namespace JSX { |
| 6 | + interface IntrinsicElements { |
| 7 | + [e: string]: {}; |
| 8 | + } |
| 9 | + interface Element { |
| 10 | + __domBrand: void; |
| 11 | + props: { |
| 12 | + children?: Element[]; |
| 13 | + }; |
| 14 | + } |
| 15 | + interface ElementClass extends Element { |
| 16 | + render(): Element; |
| 17 | + } |
| 18 | + interface ElementAttributesProperty { props: any; } |
| 19 | + interface ElementChildrenAttribute { children: any; } |
| 20 | + } |
| 21 | +} |
| 22 | +export function dom(): dom.JSX.Element; |
| 23 | +//// [renderer2.d.ts] |
| 24 | +export namespace predom { |
| 25 | + namespace JSX { |
| 26 | + interface IntrinsicElements { |
| 27 | + [e: string]: {}; |
| 28 | + } |
| 29 | + interface Element { |
| 30 | + __predomBrand: void; |
| 31 | + props: { |
| 32 | + children?: Element[]; |
| 33 | + }; |
| 34 | + } |
| 35 | + interface ElementClass extends Element { |
| 36 | + render(): Element; |
| 37 | + } |
| 38 | + interface ElementAttributesProperty { props: any; } |
| 39 | + interface ElementChildrenAttribute { children: any; } |
| 40 | + } |
| 41 | +} |
| 42 | +export function predom(): predom.JSX.Element; |
| 43 | +//// [component.tsx] |
| 44 | +/** @jsx predom */ |
| 45 | +import { predom } from "./renderer2" |
| 46 | + |
| 47 | +export const MySFC = (props: {x: number, y: number, children?: predom.JSX.Element[]}) => <p>{props.x} + {props.y} = {props.x + props.y}{...this.props.children}</p>; |
| 48 | + |
| 49 | +export class MyClass implements predom.JSX.Element { |
| 50 | + __predomBrand!: void; |
| 51 | + constructor(public props: {x: number, y: number, children?: predom.JSX.Element[]}) {} |
| 52 | + render() { |
| 53 | + return <p> |
| 54 | + {this.props.x} + {this.props.y} = {this.props.x + this.props.y} |
| 55 | + {...this.props.children} |
| 56 | + </p>; |
| 57 | + } |
| 58 | +} |
| 59 | +export const tree = <MySFC x={1} y={2}><MyClass x={3} y={4} /><MyClass x={5} y={6} /></MySFC> |
| 60 | + |
| 61 | +export default <h></h> |
| 62 | + |
| 63 | +//// [index.tsx] |
| 64 | +/** @jsx dom */ |
| 65 | +import { dom } from "./renderer" |
| 66 | +import prerendered, {MySFC, MyClass, tree} from "./component"; |
| 67 | +let elem = prerendered; |
| 68 | +elem = <h></h>; // Expect assignability error here |
| 69 | + |
| 70 | +const DOMSFC = (props: {x: number, y: number, children?: dom.JSX.Element[]}) => <p>{props.x} + {props.y} = {props.x + props.y}{props.children}</p>; |
| 71 | + |
| 72 | +class DOMClass implements dom.JSX.Element { |
| 73 | + __domBrand!: void; |
| 74 | + constructor(public props: {x: number, y: number, children?: dom.JSX.Element[]}) {} |
| 75 | + render() { |
| 76 | + return <p>{this.props.x} + {this.props.y} = {this.props.x + this.props.y}{...this.props.children}</p>; |
| 77 | + } |
| 78 | +} |
| 79 | + |
| 80 | +// Should work, everything is a DOM element |
| 81 | +const _tree = <DOMSFC x={1} y={2}><DOMClass x={3} y={4} /><DOMClass x={5} y={6} /></DOMSFC> |
| 82 | + |
| 83 | +// Should fail, no dom elements |
| 84 | +const _brokenTree = <MySFC x={1} y={2}><MyClass x={3} y={4} /><MyClass x={5} y={6} /></MySFC> |
| 85 | + |
| 86 | +// Should fail, nondom isn't allowed as children of dom |
| 87 | +const _brokenTree2 = <DOMSFC x={1} y={2}>{tree}{tree}</DOMSFC> |
| 88 | + |
| 89 | + |
| 90 | +//// [component.js] |
| 91 | +"use strict"; |
| 92 | +var _this = this; |
| 93 | +exports.__esModule = true; |
| 94 | +/** @jsx predom */ |
| 95 | +var renderer2_1 = require("./renderer2"); |
| 96 | +exports.MySFC = function (props) { return renderer2_1.predom("p", null, |
| 97 | + props.x, |
| 98 | + " + ", |
| 99 | + props.y, |
| 100 | + " = ", |
| 101 | + props.x + props.y, |
| 102 | + _this.props.children); }; |
| 103 | +var MyClass = /** @class */ (function () { |
| 104 | + function MyClass(props) { |
| 105 | + this.props = props; |
| 106 | + } |
| 107 | + MyClass.prototype.render = function () { |
| 108 | + return renderer2_1.predom("p", null, |
| 109 | + this.props.x, |
| 110 | + " + ", |
| 111 | + this.props.y, |
| 112 | + " = ", |
| 113 | + this.props.x + this.props.y, |
| 114 | + this.props.children); |
| 115 | + }; |
| 116 | + return MyClass; |
| 117 | +}()); |
| 118 | +exports.MyClass = MyClass; |
| 119 | +exports.tree = renderer2_1.predom(exports.MySFC, { x: 1, y: 2 }, |
| 120 | + renderer2_1.predom(MyClass, { x: 3, y: 4 }), |
| 121 | + renderer2_1.predom(MyClass, { x: 5, y: 6 })); |
| 122 | +exports["default"] = renderer2_1.predom("h", null); |
| 123 | +//// [index.js] |
| 124 | +"use strict"; |
| 125 | +exports.__esModule = true; |
| 126 | +/** @jsx dom */ |
| 127 | +var renderer_1 = require("./renderer"); |
| 128 | +var component_1 = require("./component"); |
| 129 | +var elem = component_1["default"]; |
| 130 | +elem = renderer_1.dom("h", null); // Expect assignability error here |
| 131 | +var DOMSFC = function (props) { return renderer_1.dom("p", null, |
| 132 | + props.x, |
| 133 | + " + ", |
| 134 | + props.y, |
| 135 | + " = ", |
| 136 | + props.x + props.y, |
| 137 | + props.children); }; |
| 138 | +var DOMClass = /** @class */ (function () { |
| 139 | + function DOMClass(props) { |
| 140 | + this.props = props; |
| 141 | + } |
| 142 | + DOMClass.prototype.render = function () { |
| 143 | + return renderer_1.dom("p", null, |
| 144 | + this.props.x, |
| 145 | + " + ", |
| 146 | + this.props.y, |
| 147 | + " = ", |
| 148 | + this.props.x + this.props.y, |
| 149 | + this.props.children); |
| 150 | + }; |
| 151 | + return DOMClass; |
| 152 | +}()); |
| 153 | +// Should work, everything is a DOM element |
| 154 | +var _tree = renderer_1.dom(DOMSFC, { x: 1, y: 2 }, |
| 155 | + renderer_1.dom(DOMClass, { x: 3, y: 4 }), |
| 156 | + renderer_1.dom(DOMClass, { x: 5, y: 6 })); |
| 157 | +// Should fail, no dom elements |
| 158 | +var _brokenTree = renderer_1.dom(component_1.MySFC, { x: 1, y: 2 }, |
| 159 | + renderer_1.dom(component_1.MyClass, { x: 3, y: 4 }), |
| 160 | + renderer_1.dom(component_1.MyClass, { x: 5, y: 6 })); |
| 161 | +// Should fail, nondom isn't allowed as children of dom |
| 162 | +var _brokenTree2 = renderer_1.dom(DOMSFC, { x: 1, y: 2 }, |
| 163 | + component_1.tree, |
| 164 | + component_1.tree); |
0 commit comments