From 3bd49e49a72ef42a9abc5b4d2630be6367018852 Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Tue, 29 Oct 2019 15:50:47 -0700 Subject: [PATCH] Add another test case and change condition for ns merge to require signature or export content --- src/compiler/checker.ts | 1 + .../jsDeclarationsReactComponents.js | 58 ++++++++++++++++++- .../jsDeclarationsReactComponents.symbols | 44 ++++++++++++++ .../jsDeclarationsReactComponents.types | 51 ++++++++++++++++ .../jsDeclarationsReactComponents.ts | 18 ++++++ 5 files changed, 170 insertions(+), 2 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 9162dd3e19e..23b9c4e5de3 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -5778,6 +5778,7 @@ namespace ts { return getObjectFlags(typeToSerialize) & (ObjectFlags.Anonymous | ObjectFlags.Mapped) && !getIndexInfoOfType(typeToSerialize, IndexKind.String) && !getIndexInfoOfType(typeToSerialize, IndexKind.Number) && + !!(length(getPropertiesOfType(typeToSerialize)) || length(getSignaturesOfType(typeToSerialize, SignatureKind.Call))) && !length(getSignaturesOfType(typeToSerialize, SignatureKind.Construct)) && // TODO: could probably serialize as function + ns + class, now that that's OK !getDeclarationWithTypeAnnotation(hostSymbol) && !(typeToSerialize.symbol && some(typeToSerialize.symbol.declarations, d => getSourceFileOfNode(d) !== ctxSrc)) && diff --git a/tests/baselines/reference/jsDeclarationsReactComponents.js b/tests/baselines/reference/jsDeclarationsReactComponents.js index 1e5aaea30a4..025a96addda 100644 --- a/tests/baselines/reference/jsDeclarationsReactComponents.js +++ b/tests/baselines/reference/jsDeclarationsReactComponents.js @@ -75,8 +75,25 @@ TabbedShowLayout.defaultProps = { tabs: "default value" }; -export default TabbedShowLayout; - +export default TabbedShowLayout; +//// [jsDeclarationsReactComponents5.jsx] +import React from 'react'; +import PropTypes from 'prop-types'; + +function Tree({ allowDropOnRoot }) { + return
+} + +Tree.propTypes = { + classes: PropTypes.object, +}; + +Tree.defaultProps = { + classes: {}, + parentSource: 'parent_id', +}; + +export default Tree; //// [jsDeclarationsReactComponents1.js] "use strict"; @@ -145,6 +162,26 @@ TabbedShowLayout.defaultProps = { tabs: "default value" }; exports.default = TabbedShowLayout; +//// [jsDeclarationsReactComponents5.js] +"use strict"; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +var react_1 = __importDefault(require("react")); +var prop_types_1 = __importDefault(require("prop-types")); +function Tree(_a) { + var allowDropOnRoot = _a.allowDropOnRoot; + return react_1.default.createElement("div", null); +} +Tree.propTypes = { + classes: prop_types_1.default.object, +}; +Tree.defaultProps = { + classes: {}, + parentSource: 'parent_id', +}; +exports.default = Tree; //// [jsDeclarationsReactComponents1.d.ts] @@ -190,3 +227,20 @@ declare namespace TabbedShowLayout { export const tabs: string; } } +//// [jsDeclarationsReactComponents5.d.ts] +/// +export default Tree; +declare function Tree({ allowDropOnRoot }: { + allowDropOnRoot: any; +}): JSX.Element; +declare namespace Tree { + export namespace propTypes { + export const classes: PropTypes.Requireable; + } + export namespace defaultProps { + const classes_1: {}; + export { classes_1 as classes }; + export const parentSource: string; + } +} +import PropTypes from "prop-types"; diff --git a/tests/baselines/reference/jsDeclarationsReactComponents.symbols b/tests/baselines/reference/jsDeclarationsReactComponents.symbols index 8534120b64d..43739a502a0 100644 --- a/tests/baselines/reference/jsDeclarationsReactComponents.symbols +++ b/tests/baselines/reference/jsDeclarationsReactComponents.symbols @@ -153,3 +153,47 @@ TabbedShowLayout.defaultProps = { export default TabbedShowLayout; >TabbedShowLayout : Symbol(TabbedShowLayout, Decl(jsDeclarationsReactComponents4.jsx, 1, 5), Decl(jsDeclarationsReactComponents4.jsx, 7, 2)) +=== tests/cases/conformance/jsdoc/declarations/jsDeclarationsReactComponents5.jsx === +import React from 'react'; +>React : Symbol(React, Decl(jsDeclarationsReactComponents5.jsx, 0, 6)) + +import PropTypes from 'prop-types'; +>PropTypes : Symbol(PropTypes, Decl(jsDeclarationsReactComponents5.jsx, 1, 6)) + +function Tree({ allowDropOnRoot }) { +>Tree : Symbol(Tree, Decl(jsDeclarationsReactComponents5.jsx, 1, 35), Decl(jsDeclarationsReactComponents5.jsx, 5, 1), Decl(jsDeclarationsReactComponents5.jsx, 9, 2)) +>allowDropOnRoot : Symbol(allowDropOnRoot, Decl(jsDeclarationsReactComponents5.jsx, 3, 15)) + + return
+>div : Symbol(JSX.IntrinsicElements.div, Decl(react16.d.ts, 2420, 114)) +} + +Tree.propTypes = { +>Tree.propTypes : Symbol(Tree.propTypes, Decl(jsDeclarationsReactComponents5.jsx, 5, 1)) +>Tree : Symbol(Tree, Decl(jsDeclarationsReactComponents5.jsx, 1, 35), Decl(jsDeclarationsReactComponents5.jsx, 5, 1), Decl(jsDeclarationsReactComponents5.jsx, 9, 2)) +>propTypes : Symbol(Tree.propTypes, Decl(jsDeclarationsReactComponents5.jsx, 5, 1)) + + classes: PropTypes.object, +>classes : Symbol(classes, Decl(jsDeclarationsReactComponents5.jsx, 7, 18)) +>PropTypes.object : Symbol(PropTypes.object, Decl(react16.d.ts, 65, 16)) +>PropTypes : Symbol(PropTypes, Decl(jsDeclarationsReactComponents5.jsx, 1, 6)) +>object : Symbol(PropTypes.object, Decl(react16.d.ts, 65, 16)) + +}; + +Tree.defaultProps = { +>Tree.defaultProps : Symbol(Tree.defaultProps, Decl(jsDeclarationsReactComponents5.jsx, 9, 2)) +>Tree : Symbol(Tree, Decl(jsDeclarationsReactComponents5.jsx, 1, 35), Decl(jsDeclarationsReactComponents5.jsx, 5, 1), Decl(jsDeclarationsReactComponents5.jsx, 9, 2)) +>defaultProps : Symbol(Tree.defaultProps, Decl(jsDeclarationsReactComponents5.jsx, 9, 2)) + + classes: {}, +>classes : Symbol(classes, Decl(jsDeclarationsReactComponents5.jsx, 11, 21)) + + parentSource: 'parent_id', +>parentSource : Symbol(parentSource, Decl(jsDeclarationsReactComponents5.jsx, 12, 16)) + +}; + +export default Tree; +>Tree : Symbol(Tree, Decl(jsDeclarationsReactComponents5.jsx, 1, 35), Decl(jsDeclarationsReactComponents5.jsx, 5, 1), Decl(jsDeclarationsReactComponents5.jsx, 9, 2)) + diff --git a/tests/baselines/reference/jsDeclarationsReactComponents.types b/tests/baselines/reference/jsDeclarationsReactComponents.types index fe60f314cc7..260eedaff26 100644 --- a/tests/baselines/reference/jsDeclarationsReactComponents.types +++ b/tests/baselines/reference/jsDeclarationsReactComponents.types @@ -182,3 +182,54 @@ TabbedShowLayout.defaultProps = { export default TabbedShowLayout; >TabbedShowLayout : { (prop: { className: string; }): JSX.Element; defaultProps: { tabs: string; }; } +=== tests/cases/conformance/jsdoc/declarations/jsDeclarationsReactComponents5.jsx === +import React from 'react'; +>React : typeof React + +import PropTypes from 'prop-types'; +>PropTypes : typeof PropTypes + +function Tree({ allowDropOnRoot }) { +>Tree : typeof Tree +>allowDropOnRoot : any + + return
+>
: JSX.Element +>div : any +} + +Tree.propTypes = { +>Tree.propTypes = { classes: PropTypes.object,} : { classes: PropTypes.Requireable; } +>Tree.propTypes : { classes: PropTypes.Requireable; } +>Tree : typeof Tree +>propTypes : { classes: PropTypes.Requireable; } +>{ classes: PropTypes.object,} : { classes: PropTypes.Requireable; } + + classes: PropTypes.object, +>classes : PropTypes.Requireable +>PropTypes.object : PropTypes.Requireable +>PropTypes : typeof PropTypes +>object : PropTypes.Requireable + +}; + +Tree.defaultProps = { +>Tree.defaultProps = { classes: {}, parentSource: 'parent_id',} : { classes: {}; parentSource: string; } +>Tree.defaultProps : { classes: {}; parentSource: string; } +>Tree : typeof Tree +>defaultProps : { classes: {}; parentSource: string; } +>{ classes: {}, parentSource: 'parent_id',} : { classes: {}; parentSource: string; } + + classes: {}, +>classes : {} +>{} : {} + + parentSource: 'parent_id', +>parentSource : string +>'parent_id' : "parent_id" + +}; + +export default Tree; +>Tree : typeof Tree + diff --git a/tests/cases/conformance/jsdoc/declarations/jsDeclarationsReactComponents.ts b/tests/cases/conformance/jsdoc/declarations/jsDeclarationsReactComponents.ts index 4b598f83ef1..ce09708e9c4 100644 --- a/tests/cases/conformance/jsdoc/declarations/jsDeclarationsReactComponents.ts +++ b/tests/cases/conformance/jsdoc/declarations/jsDeclarationsReactComponents.ts @@ -83,3 +83,21 @@ TabbedShowLayout.defaultProps = { }; export default TabbedShowLayout; +// @filename: jsDeclarationsReactComponents5.jsx +import React from 'react'; +import PropTypes from 'prop-types'; + +function Tree({ allowDropOnRoot }) { + return
+} + +Tree.propTypes = { + classes: PropTypes.object, +}; + +Tree.defaultProps = { + classes: {}, + parentSource: 'parent_id', +}; + +export default Tree; \ No newline at end of file