diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 93b2834178eec..403fa62798501 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -954,16 +954,32 @@ namespace ts { if (location) { const file = getSourceFileOfNode(location); if (file) { - if (file.localJsxNamespace) { - return file.localJsxNamespace; + if (isJsxOpeningFragment(location)) { + if (file.localJsxFragmentNamespace) { + return file.localJsxFragmentNamespace; + } + const jsxFragmentPragma = file.pragmas.get("jsxfrag"); + if (jsxFragmentPragma) { + const chosenPragma = isArray(jsxFragmentPragma) ? jsxFragmentPragma[0] : jsxFragmentPragma; + file.localJsxFragmentFactory = parseIsolatedEntityName(chosenPragma.arguments.factory, languageVersion); + visitNode(file.localJsxFragmentFactory, markAsSynthetic); + if (file.localJsxFragmentFactory) { + return file.localJsxFragmentNamespace = getFirstIdentifier(file.localJsxFragmentFactory).escapedText; + } + } } - const jsxPragma = file.pragmas.get("jsx"); - if (jsxPragma) { - const chosenpragma = isArray(jsxPragma) ? jsxPragma[0] : jsxPragma; - file.localJsxFactory = parseIsolatedEntityName(chosenpragma.arguments.factory, languageVersion); - visitNode(file.localJsxFactory, markAsSynthetic); - if (file.localJsxFactory) { - return file.localJsxNamespace = getFirstIdentifier(file.localJsxFactory).escapedText; + else { + if (file.localJsxNamespace) { + return file.localJsxNamespace; + } + const jsxPragma = file.pragmas.get("jsx"); + if (jsxPragma) { + const chosenPragma = isArray(jsxPragma) ? jsxPragma[0] : jsxPragma; + file.localJsxFactory = parseIsolatedEntityName(chosenPragma.arguments.factory, languageVersion); + visitNode(file.localJsxFactory, markAsSynthetic); + if (file.localJsxFactory) { + return file.localJsxNamespace = getFirstIdentifier(file.localJsxFactory).escapedText; + } } } } @@ -23736,10 +23752,14 @@ namespace ts { function checkJsxFragment(node: JsxFragment): Type { checkJsxOpeningLikeElementOrOpeningFragment(node.openingFragment); - if (compilerOptions.jsx === JsxEmit.React && (compilerOptions.jsxFactory || getSourceFileOfNode(node).pragmas.has("jsx"))) { + // by default, jsx:'react' will use jsxFactory = React.createElement and jsxFragmentFactory = React.Fragment + // if jsxFactory compiler option is provided, ensure jsxFragmentFactory compiler option or @jsxFrag pragma is provided too + const nodeSourceFile = getSourceFileOfNode(node); + if (compilerOptions.jsx === JsxEmit.React && (compilerOptions.jsxFactory || nodeSourceFile.pragmas.has("jsx")) + && !compilerOptions.jsxFragmentFactory && !nodeSourceFile.pragmas.has("jsxfrag")) { error(node, compilerOptions.jsxFactory - ? Diagnostics.JSX_fragment_is_not_supported_when_using_jsxFactory - : Diagnostics.JSX_fragment_is_not_supported_when_using_an_inline_JSX_factory_pragma); + ? Diagnostics.The_jsxFragmentFactory_compiler_option_must_be_provided_to_use_JSX_fragments_with_the_jsxFactory_compiler_option + : Diagnostics.An_jsxFrag_pragma_is_required_when_using_an_jsx_pragma_with_JSX_fragments); } checkJsxChildren(node); @@ -24197,21 +24217,28 @@ namespace ts { if (isNodeOpeningLikeElement) { checkGrammarJsxElement(node); } + checkJsxPreconditions(node); // The reactNamespace/jsxFactory's root symbol should be marked as 'used' so we don't incorrectly elide its import. // And if there is no reactNamespace/jsxFactory's symbol in scope when targeting React emit, we should issue an error. - const reactRefErr = diagnostics && compilerOptions.jsx === JsxEmit.React ? Diagnostics.Cannot_find_name_0 : undefined; - const reactNamespace = getJsxNamespace(node); - const reactLocation = isNodeOpeningLikeElement ? (node).tagName : node; - const reactSym = resolveName(reactLocation, reactNamespace, SymbolFlags.Value, reactRefErr, reactNamespace, /*isUse*/ true); - if (reactSym) { + const jsxFactoryRefErr = diagnostics && compilerOptions.jsx === JsxEmit.React ? Diagnostics.Cannot_find_name_0 : undefined; + const jsxFactoryNamespace = getJsxNamespace(node); + const jsxFactoryLocation = isNodeOpeningLikeElement ? (node).tagName : node; + + // allow null as jsxFragmentFactory + let jsxFactorySym: Symbol | undefined; + if (!(isJsxOpeningFragment(node) && jsxFactoryNamespace === "null")) { + jsxFactorySym = resolveName(jsxFactoryLocation, jsxFactoryNamespace, SymbolFlags.Value, jsxFactoryRefErr, jsxFactoryNamespace, /*isUse*/ true); + } + + if (jsxFactorySym) { // Mark local symbol as referenced here because it might not have been marked - // if jsx emit was not react as there wont be error being emitted - reactSym.isReferenced = SymbolFlags.All; + // if jsx emit was not jsxFactory as there wont be error being emitted + jsxFactorySym.isReferenced = SymbolFlags.All; - // If react symbol is alias, mark it as referenced - if (reactSym.flags & SymbolFlags.Alias && !getTypeOnlyAliasDeclaration(reactSym)) { - markAliasSymbolAsReferenced(reactSym); + // If react/jsxFactory symbol is alias, mark it as refereced + if (jsxFactorySym.flags & SymbolFlags.Alias && !getTypeOnlyAliasDeclaration(jsxFactorySym)) { + markAliasSymbolAsReferenced(jsxFactorySym); } } @@ -36728,10 +36755,31 @@ namespace ts { return literalTypeToNode(type, node, tracker); } - function getJsxFactoryEntity(location: Node) { + function getJsxFactoryEntity(location: Node): EntityName | undefined { return location ? (getJsxNamespace(location), (getSourceFileOfNode(location).localJsxFactory || _jsxFactoryEntity)) : _jsxFactoryEntity; } + function getJsxFragmentFactoryEntity(location: Node): EntityName | undefined { + if (location) { + const file = getSourceFileOfNode(location); + if (file) { + if (file.localJsxFragmentFactory) { + return file.localJsxFragmentFactory; + } + const jsxFragPragmas = file.pragmas.get("jsxfrag"); + const jsxFragPragma = isArray(jsxFragPragmas) ? jsxFragPragmas[0] : jsxFragPragmas; + if (jsxFragPragma) { + file.localJsxFragmentFactory = parseIsolatedEntityName(jsxFragPragma.arguments.factory, languageVersion); + return file.localJsxFragmentFactory; + } + } + } + + if (compilerOptions.jsxFragmentFactory) { + return parseIsolatedEntityName(compilerOptions.jsxFragmentFactory, languageVersion); + } + } + function createResolver(): EmitResolver { // this variable and functions that use it are deliberately moved here from the outer scope // to avoid scope pollution @@ -36806,6 +36854,7 @@ namespace ts { return !!(symbol && getCheckFlags(symbol) & CheckFlags.Late); }, getJsxFactoryEntity, + getJsxFragmentFactoryEntity, getAllAccessorDeclarations(accessor: AccessorDeclaration): AllAccessorDeclarations { accessor = getParseTreeNode(accessor, isGetOrSetAccessorDeclaration)!; // TODO: GH#18217 const otherKind = accessor.kind === SyntaxKind.SetAccessor ? SyntaxKind.GetAccessor : SyntaxKind.SetAccessor; diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index f217bae5c1006..878737f49dde8 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -766,6 +766,12 @@ namespace ts { category: Diagnostics.Advanced_Options, description: Diagnostics.Specify_the_JSX_factory_function_to_use_when_targeting_react_JSX_emit_e_g_React_createElement_or_h }, + { + name: "jsxFragmentFactory", + type: "string", + category: Diagnostics.Advanced_Options, + description: Diagnostics.Specify_the_JSX_fragment_factory_function_to_use_when_targeting_react_JSX_emit_with_jsxFactory_compiler_option_is_specified_e_g_Fragment + }, { name: "resolveJsonModule", type: "boolean", diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index e863de12537d6..16dd1663fb5d5 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -5027,11 +5027,11 @@ "category": "Error", "code": 17015 }, - "JSX fragment is not supported when using --jsxFactory": { + "The 'jsxFragmentFactory' compiler option must be provided to use JSX fragments with the 'jsxFactory' compiler option.": { "category": "Error", "code": 17016 }, - "JSX fragment is not supported when using an inline JSX factory pragma": { + "An @jsxFrag pragma is required when using an @jsx pragma with JSX fragments.": { "category": "Error", "code": 17017 }, @@ -5837,5 +5837,13 @@ "Only numeric enums can have computed members, but this expression has type '{0}'. If you do not need exhaustiveness checks, consider using an object literal instead.": { "category": "Error", "code": 18033 + }, + "Specify the JSX fragment factory function to use when targeting 'react' JSX emit with 'jsxFactory' compiler option is specified, e.g. 'Fragment'.": { + "category": "Message", + "code": 18034 + }, + "Invalid value for 'jsxFragmentFactory'. '{0}' is not a valid identifier or qualified-name.": { + "category": "Error", + "code": 18035 } } diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index afbcb53f81612..4aba127441f36 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -660,6 +660,7 @@ namespace ts { getTypeReferenceDirectivesForSymbol: notImplemented, isLiteralConstDeclaration: notImplemented, getJsxFactoryEntity: notImplemented, + getJsxFragmentFactoryEntity: notImplemented, getAllAccessorDeclarations: notImplemented, getSymbolOfExternalModuleSpecifier: notImplemented, isBindingCapturedByNode: notImplemented, diff --git a/src/compiler/factory/utilities.ts b/src/compiler/factory/utilities.ts index 459b578936901..d52048e78e379 100644 --- a/src/compiler/factory/utilities.ts +++ b/src/compiler/factory/utilities.ts @@ -55,6 +55,15 @@ namespace ts { ); } + function createJsxFragmentFactoryExpression(factory: NodeFactory, jsxFragmentFactoryEntity: EntityName | undefined, reactNamespace: string, parent: JsxOpeningLikeElement | JsxOpeningFragment): Expression { + return jsxFragmentFactoryEntity ? + createJsxFactoryExpressionFromEntityName(factory, jsxFragmentFactoryEntity, parent) : + factory.createPropertyAccessExpression( + createReactNamespace(reactNamespace, parent), + "Fragment" + ); + } + export function createExpressionForJsxElement(factory: NodeFactory, jsxFactoryEntity: EntityName | undefined, reactNamespace: string, tagName: Expression, props: Expression | undefined, children: readonly Expression[] | undefined, parentElement: JsxOpeningLikeElement, location: TextRange): LeftHandSideExpression { const argumentsList = [tagName]; if (props) { @@ -87,14 +96,9 @@ namespace ts { ); } - export function createExpressionForJsxFragment(factory: NodeFactory, jsxFactoryEntity: EntityName | undefined, reactNamespace: string, children: readonly Expression[], parentElement: JsxOpeningFragment, location: TextRange): LeftHandSideExpression { - const tagName = factory.createPropertyAccessExpression( - createReactNamespace(reactNamespace, parentElement), - "Fragment" - ); - - const argumentsList = [tagName]; - argumentsList.push(factory.createNull()); + export function createExpressionForJsxFragment(factory: NodeFactory, jsxFactoryEntity: EntityName | undefined, jsxFragmentFactoryEntity: EntityName | undefined, reactNamespace: string, children: readonly Expression[], parentElement: JsxOpeningFragment, location: TextRange): LeftHandSideExpression { + const tagName = createJsxFragmentFactoryExpression(factory, jsxFragmentFactoryEntity, reactNamespace, parentElement); + const argumentsList = [tagName, factory.createNull()]; if (children && children.length > 0) { if (children.length > 1) { @@ -820,4 +824,4 @@ namespace ts { export function isStaticModifier(node: Modifier): node is StaticKeyword { return node.kind === SyntaxKind.StaticKeyword; } -} \ No newline at end of file +} diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 633b62905fba5..db6b562a70e20 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -8568,7 +8568,9 @@ namespace ts { }); break; } - case "jsx": return; // Accessed directly + case "jsx": + case "jsxfrag": + return; // Accessed directly default: Debug.fail("Unhandled pragma kind"); // Can this be made into an assertNever in the future? } }); diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 8cd92ddd285cd..25b5a87cdcd4e 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -3196,6 +3196,15 @@ namespace ts { createOptionValueDiagnostic("reactNamespace", Diagnostics.Invalid_value_for_reactNamespace_0_is_not_a_valid_identifier, options.reactNamespace); } + if (options.jsxFragmentFactory) { + if (!options.jsxFactory) { + createDiagnosticForOptionName(Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1, "jsxFragmentFactory", "jsxFactory"); + } + if (!parseIsolatedEntityName(options.jsxFragmentFactory, languageVersion)) { + createOptionValueDiagnostic("jsxFragmentFactory", Diagnostics.Invalid_value_for_jsxFragmentFactory_0_is_not_a_valid_identifier_or_qualified_name, options.jsxFragmentFactory); + } + } + // If the emit is enabled make sure that every output file is unique and not overwriting any of the input files if (!options.noEmit && !options.suppressOutputPathCheck) { const emitHost = getEmitHost(); diff --git a/src/compiler/transformers/jsx.ts b/src/compiler/transformers/jsx.ts index 37ed4eb901fa5..cc000666143c0 100644 --- a/src/compiler/transformers/jsx.ts +++ b/src/compiler/transformers/jsx.ts @@ -142,6 +142,7 @@ namespace ts { const element = createExpressionForJsxFragment( factory, context.getEmitResolver().getJsxFactoryEntity(currentSourceFile), + context.getEmitResolver().getJsxFragmentFactoryEntity(currentSourceFile), compilerOptions.reactNamespace!, // TODO: GH#18217 mapDefined(children, transformJsxChildToExpression), node, diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 5c4e6f0c1592b..eeed5829fb11c 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -3454,7 +3454,9 @@ namespace ts { /* @internal */ version: string; /* @internal */ pragmas: ReadonlyPragmaMap; /* @internal */ localJsxNamespace?: __String; + /* @internal */ localJsxFragmentNamespace?: __String; /* @internal */ localJsxFactory?: EntityName; + /* @internal */ localJsxFragmentFactory?: EntityName; /* @internal */ exportedModulesFromDeclarationEmit?: ExportedModulesFromDeclarationEmit; } @@ -4463,6 +4465,7 @@ namespace ts { getTypeReferenceDirectivesForSymbol(symbol: Symbol, meaning?: SymbolFlags): string[] | undefined; isLiteralConstDeclaration(node: VariableDeclaration | PropertyDeclaration | PropertySignature | ParameterDeclaration): boolean; getJsxFactoryEntity(location?: Node): EntityName | undefined; + getJsxFragmentFactoryEntity(location?: Node): EntityName | undefined; getAllAccessorDeclarations(declaration: AccessorDeclaration): AllAccessorDeclarations; getSymbolOfExternalModuleSpecifier(node: StringLiteralLike): Symbol | undefined; isBindingCapturedByNode(node: Node, decl: VariableDeclaration | BindingElement): boolean; @@ -5681,6 +5684,7 @@ namespace ts { /* @internal */ pretty?: boolean; reactNamespace?: string; jsxFactory?: string; + jsxFragmentFactory?: string; composite?: boolean; incremental?: boolean; tsBuildInfoFile?: string; @@ -7928,6 +7932,10 @@ namespace ts { args: [{ name: "factory" }], kind: PragmaKindFlags.MultiLine }, + "jsxfrag": { + args: [{ name: "factory" }], + kind: PragmaKindFlags.MultiLine + }, } as const; /* @internal */ diff --git a/src/testRunner/unittests/services/transpile.ts b/src/testRunner/unittests/services/transpile.ts index 83dd367a8656e..765b4f345e644 100644 --- a/src/testRunner/unittests/services/transpile.ts +++ b/src/testRunner/unittests/services/transpile.ts @@ -363,6 +363,10 @@ var x = 0;`, { options: { compilerOptions: { jsxFactory: "createElement" }, fileName: "input.js", reportDiagnostics: true } }); + transpilesCorrectly("Supports setting 'jsxFragmentFactory'", "x;", { + options: { compilerOptions: { jsxFactory: "x", jsxFragmentFactory: "frag" }, fileName: "input.js", reportDiagnostics: true } + }); + transpilesCorrectly("Supports setting 'removeComments'", "x;", { options: { compilerOptions: { removeComments: true }, fileName: "input.js", reportDiagnostics: true } }); diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index 012164ed997b3..f03ad8d3f6849 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -2770,6 +2770,7 @@ declare namespace ts { project?: string; reactNamespace?: string; jsxFactory?: string; + jsxFragmentFactory?: string; composite?: boolean; incremental?: boolean; tsBuildInfoFile?: string; diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index 0b62806635ec9..989a845468197 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -2770,6 +2770,7 @@ declare namespace ts { project?: string; reactNamespace?: string; jsxFactory?: string; + jsxFragmentFactory?: string; composite?: boolean; incremental?: boolean; tsBuildInfoFile?: string; diff --git a/tests/baselines/reference/inlineJsxAndJsxFragPragma.js b/tests/baselines/reference/inlineJsxAndJsxFragPragma.js new file mode 100644 index 0000000000000..06b263e35db84 --- /dev/null +++ b/tests/baselines/reference/inlineJsxAndJsxFragPragma.js @@ -0,0 +1,46 @@ +//// [tests/cases/conformance/jsx/inline/inlineJsxAndJsxFragPragma.tsx] //// + +//// [renderer.d.ts] +declare global { + namespace JSX { + interface IntrinsicElements { + [e: string]: any; + } + } +} +export function h(): void; +export function jsx(): void; +export function Fragment(): void; + +//// [preacty.tsx] +/** + * @jsx h + * @jsxFrag Fragment + */ +import {h, Fragment} from "./renderer"; +<>
+ +//// [snabbdomy.tsx] +/* @jsx jsx */ +/* @jsxfrag null */ +import {jsx} from "./renderer"; +<> + +//// [preacty.js] +"use strict"; +exports.__esModule = true; +/** + * @jsx h + * @jsxFrag Fragment + */ +var renderer_1 = require("./renderer"); +renderer_1.h(renderer_1.Fragment, null, + renderer_1.h("div", null)); +//// [snabbdomy.js] +"use strict"; +exports.__esModule = true; +/* @jsx jsx */ +/* @jsxfrag null */ +var renderer_1 = require("./renderer"); +renderer_1.jsx(null, null, + renderer_1.jsx("span", null)); diff --git a/tests/baselines/reference/inlineJsxAndJsxFragPragma.symbols b/tests/baselines/reference/inlineJsxAndJsxFragPragma.symbols new file mode 100644 index 0000000000000..dd5d7bb6abb4b --- /dev/null +++ b/tests/baselines/reference/inlineJsxAndJsxFragPragma.symbols @@ -0,0 +1,47 @@ +=== tests/cases/conformance/jsx/inline/renderer.d.ts === +declare global { +>global : Symbol(global, Decl(renderer.d.ts, 0, 0)) + + namespace JSX { +>JSX : Symbol(JSX, Decl(renderer.d.ts, 0, 16)) + + interface IntrinsicElements { +>IntrinsicElements : Symbol(IntrinsicElements, Decl(renderer.d.ts, 1, 19)) + + [e: string]: any; +>e : Symbol(e, Decl(renderer.d.ts, 3, 13)) + } + } +} +export function h(): void; +>h : Symbol(h, Decl(renderer.d.ts, 6, 1)) + +export function jsx(): void; +>jsx : Symbol(jsx, Decl(renderer.d.ts, 7, 26)) + +export function Fragment(): void; +>Fragment : Symbol(Fragment, Decl(renderer.d.ts, 8, 28)) + +=== tests/cases/conformance/jsx/inline/preacty.tsx === +/** + * @jsx h + * @jsxFrag Fragment + */ +import {h, Fragment} from "./renderer"; +>h : Symbol(h, Decl(preacty.tsx, 4, 8)) +>Fragment : Symbol(Fragment, Decl(preacty.tsx, 4, 10)) + +<>
+>div : Symbol(JSX.IntrinsicElements, Decl(renderer.d.ts, 1, 19)) +>div : Symbol(JSX.IntrinsicElements, Decl(renderer.d.ts, 1, 19)) + +=== tests/cases/conformance/jsx/inline/snabbdomy.tsx === +/* @jsx jsx */ +/* @jsxfrag null */ +import {jsx} from "./renderer"; +>jsx : Symbol(jsx, Decl(snabbdomy.tsx, 2, 8)) + +<> +>span : Symbol(JSX.IntrinsicElements, Decl(renderer.d.ts, 1, 19)) +>span : Symbol(JSX.IntrinsicElements, Decl(renderer.d.ts, 1, 19)) + diff --git a/tests/baselines/reference/inlineJsxAndJsxFragPragma.types b/tests/baselines/reference/inlineJsxAndJsxFragPragma.types new file mode 100644 index 0000000000000..d7fdf1b665255 --- /dev/null +++ b/tests/baselines/reference/inlineJsxAndJsxFragPragma.types @@ -0,0 +1,47 @@ +=== tests/cases/conformance/jsx/inline/renderer.d.ts === +declare global { +>global : any + + namespace JSX { + interface IntrinsicElements { + [e: string]: any; +>e : string + } + } +} +export function h(): void; +>h : () => void + +export function jsx(): void; +>jsx : () => void + +export function Fragment(): void; +>Fragment : () => void + +=== tests/cases/conformance/jsx/inline/preacty.tsx === +/** + * @jsx h + * @jsxFrag Fragment + */ +import {h, Fragment} from "./renderer"; +>h : () => void +>Fragment : () => void + +<>
+><>
: error +>
: error +>div : any +>div : any + +=== tests/cases/conformance/jsx/inline/snabbdomy.tsx === +/* @jsx jsx */ +/* @jsxfrag null */ +import {jsx} from "./renderer"; +>jsx : () => void + +<> +><> : error +> : error +>span : any +>span : any + diff --git a/tests/baselines/reference/inlineJsxAndJsxFragPragmaOverridesCompilerOptions.js b/tests/baselines/reference/inlineJsxAndJsxFragPragmaOverridesCompilerOptions.js new file mode 100644 index 0000000000000..91949b147857e --- /dev/null +++ b/tests/baselines/reference/inlineJsxAndJsxFragPragmaOverridesCompilerOptions.js @@ -0,0 +1,82 @@ +//// [tests/cases/conformance/jsx/inline/inlineJsxAndJsxFragPragmaOverridesCompilerOptions.tsx] //// + +//// [react.d.ts] +declare global { + namespace JSX { + interface IntrinsicElements { + [e: string]: any; + } + } +} +export function createElement(): void; +export function Fragment(): void; + +//// [preact.d.ts] +export function h(): void; +export function Frag(): void; + +//// [snabbdom.d.ts] +export function h(): void; + +//// [reacty.tsx] +import {createElement, Fragment} from "./react"; +<> + +//// [preacty.tsx] +/** + * @jsx h + * @jsxFrag Frag + */ +import {h, Frag} from "./preact"; +<>
+ +//// [snabbdomy.tsx] +/** + * @jsx h + * @jsxfrag null + */ +import {h} from "./snabbdom"; +<>
+ +//// [mix-n-match.tsx] +/* @jsx h */ +/* @jsxFrag Fragment */ +import {h} from "./preact"; +import {Fragment} from "./react"; +<> + +//// [reacty.js] +"use strict"; +exports.__esModule = true; +var react_1 = require("./react"); +react_1.createElement(react_1.Fragment, null, + react_1.createElement("span", null)); +//// [preacty.js] +"use strict"; +exports.__esModule = true; +/** + * @jsx h + * @jsxFrag Frag + */ +var preact_1 = require("./preact"); +preact_1.h(preact_1.Frag, null, + preact_1.h("div", null)); +//// [snabbdomy.js] +"use strict"; +exports.__esModule = true; +/** + * @jsx h + * @jsxfrag null + */ +var snabbdom_1 = require("./snabbdom"); +snabbdom_1.h(null, null, + snabbdom_1.h("div", null)); +//// [mix-n-match.js] +"use strict"; +exports.__esModule = true; +/* @jsx h */ +/* @jsxFrag Fragment */ +var preact_1 = require("./preact"); +var react_1 = require("./react"); +preact_1.h(react_1.Fragment, null, + preact_1.h("span", null)); diff --git a/tests/baselines/reference/inlineJsxAndJsxFragPragmaOverridesCompilerOptions.symbols b/tests/baselines/reference/inlineJsxAndJsxFragPragmaOverridesCompilerOptions.symbols new file mode 100644 index 0000000000000..4384dab20e2a8 --- /dev/null +++ b/tests/baselines/reference/inlineJsxAndJsxFragPragmaOverridesCompilerOptions.symbols @@ -0,0 +1,79 @@ +=== tests/cases/conformance/jsx/inline/react.d.ts === +declare global { +>global : Symbol(global, Decl(react.d.ts, 0, 0)) + + namespace JSX { +>JSX : Symbol(JSX, Decl(react.d.ts, 0, 16)) + + interface IntrinsicElements { +>IntrinsicElements : Symbol(IntrinsicElements, Decl(react.d.ts, 1, 19)) + + [e: string]: any; +>e : Symbol(e, Decl(react.d.ts, 3, 13)) + } + } +} +export function createElement(): void; +>createElement : Symbol(createElement, Decl(react.d.ts, 6, 1)) + +export function Fragment(): void; +>Fragment : Symbol(Fragment, Decl(react.d.ts, 7, 38)) + +=== tests/cases/conformance/jsx/inline/preact.d.ts === +export function h(): void; +>h : Symbol(h, Decl(preact.d.ts, 0, 0)) + +export function Frag(): void; +>Frag : Symbol(Frag, Decl(preact.d.ts, 0, 26)) + +=== tests/cases/conformance/jsx/inline/snabbdom.d.ts === +export function h(): void; +>h : Symbol(h, Decl(snabbdom.d.ts, 0, 0)) + +=== tests/cases/conformance/jsx/inline/reacty.tsx === +import {createElement, Fragment} from "./react"; +>createElement : Symbol(createElement, Decl(reacty.tsx, 0, 8)) +>Fragment : Symbol(Fragment, Decl(reacty.tsx, 0, 22)) + +<> +>span : Symbol(JSX.IntrinsicElements, Decl(react.d.ts, 1, 19)) +>span : Symbol(JSX.IntrinsicElements, Decl(react.d.ts, 1, 19)) + +=== tests/cases/conformance/jsx/inline/preacty.tsx === +/** + * @jsx h + * @jsxFrag Frag + */ +import {h, Frag} from "./preact"; +>h : Symbol(h, Decl(preacty.tsx, 4, 8)) +>Frag : Symbol(Frag, Decl(preacty.tsx, 4, 10)) + +<>
+>div : Symbol(JSX.IntrinsicElements, Decl(react.d.ts, 1, 19)) +>div : Symbol(JSX.IntrinsicElements, Decl(react.d.ts, 1, 19)) + +=== tests/cases/conformance/jsx/inline/snabbdomy.tsx === +/** + * @jsx h + * @jsxfrag null + */ +import {h} from "./snabbdom"; +>h : Symbol(h, Decl(snabbdomy.tsx, 4, 8)) + +<>
+>div : Symbol(JSX.IntrinsicElements, Decl(react.d.ts, 1, 19)) +>div : Symbol(JSX.IntrinsicElements, Decl(react.d.ts, 1, 19)) + +=== tests/cases/conformance/jsx/inline/mix-n-match.tsx === +/* @jsx h */ +/* @jsxFrag Fragment */ +import {h} from "./preact"; +>h : Symbol(h, Decl(mix-n-match.tsx, 2, 8)) + +import {Fragment} from "./react"; +>Fragment : Symbol(Fragment, Decl(mix-n-match.tsx, 3, 8)) + +<> +>span : Symbol(JSX.IntrinsicElements, Decl(react.d.ts, 1, 19)) +>span : Symbol(JSX.IntrinsicElements, Decl(react.d.ts, 1, 19)) + diff --git a/tests/baselines/reference/inlineJsxAndJsxFragPragmaOverridesCompilerOptions.types b/tests/baselines/reference/inlineJsxAndJsxFragPragmaOverridesCompilerOptions.types new file mode 100644 index 0000000000000..613ae44af0f47 --- /dev/null +++ b/tests/baselines/reference/inlineJsxAndJsxFragPragmaOverridesCompilerOptions.types @@ -0,0 +1,83 @@ +=== tests/cases/conformance/jsx/inline/react.d.ts === +declare global { +>global : any + + namespace JSX { + interface IntrinsicElements { + [e: string]: any; +>e : string + } + } +} +export function createElement(): void; +>createElement : () => void + +export function Fragment(): void; +>Fragment : () => void + +=== tests/cases/conformance/jsx/inline/preact.d.ts === +export function h(): void; +>h : () => void + +export function Frag(): void; +>Frag : () => void + +=== tests/cases/conformance/jsx/inline/snabbdom.d.ts === +export function h(): void; +>h : () => void + +=== tests/cases/conformance/jsx/inline/reacty.tsx === +import {createElement, Fragment} from "./react"; +>createElement : () => void +>Fragment : () => void + +<> +><> : error +> : error +>span : any +>span : any + +=== tests/cases/conformance/jsx/inline/preacty.tsx === +/** + * @jsx h + * @jsxFrag Frag + */ +import {h, Frag} from "./preact"; +>h : () => void +>Frag : () => void + +<>
+><>
: error +>
: error +>div : any +>div : any + +=== tests/cases/conformance/jsx/inline/snabbdomy.tsx === +/** + * @jsx h + * @jsxfrag null + */ +import {h} from "./snabbdom"; +>h : () => void + +<>
+><>
: error +>
: error +>div : any +>div : any + +=== tests/cases/conformance/jsx/inline/mix-n-match.tsx === +/* @jsx h */ +/* @jsxFrag Fragment */ +import {h} from "./preact"; +>h : () => void + +import {Fragment} from "./react"; +>Fragment : () => void + +<> +><> : error +> : error +>span : any +>span : any + diff --git a/tests/baselines/reference/inlineJsxFactoryWithFragmentIsError.errors.txt b/tests/baselines/reference/inlineJsxFactoryWithFragmentIsError.errors.txt index b70ddf5f9b9aa..d901a3916516c 100644 --- a/tests/baselines/reference/inlineJsxFactoryWithFragmentIsError.errors.txt +++ b/tests/baselines/reference/inlineJsxFactoryWithFragmentIsError.errors.txt @@ -1,5 +1,6 @@ -tests/cases/conformance/jsx/inline/index.tsx(3,1): error TS17017: JSX fragment is not supported when using an inline JSX factory pragma -tests/cases/conformance/jsx/inline/reacty.tsx(3,1): error TS17017: JSX fragment is not supported when using an inline JSX factory pragma +tests/cases/conformance/jsx/inline/index.tsx(3,1): error TS2304: Cannot find name 'React'. +tests/cases/conformance/jsx/inline/index.tsx(3,1): error TS17017: An @jsxFrag pragma is required when using an @jsx pragma with JSX fragments. +tests/cases/conformance/jsx/inline/reacty.tsx(3,1): error TS17017: An @jsxFrag pragma is required when using an @jsx pragma with JSX fragments. ==== tests/cases/conformance/jsx/inline/renderer.d.ts (0 errors) ==== @@ -17,10 +18,12 @@ tests/cases/conformance/jsx/inline/reacty.tsx(3,1): error TS17017: JSX fragment import * as React from "./renderer"; <> ~~~~~~~~~~~~ -!!! error TS17017: JSX fragment is not supported when using an inline JSX factory pragma -==== tests/cases/conformance/jsx/inline/index.tsx (1 errors) ==== +!!! error TS17017: An @jsxFrag pragma is required when using an @jsx pragma with JSX fragments. +==== tests/cases/conformance/jsx/inline/index.tsx (2 errors) ==== /** @jsx dom */ import { dom } from "./renderer"; <> + ~~ +!!! error TS2304: Cannot find name 'React'. ~~~~~~~~~~~~ -!!! error TS17017: JSX fragment is not supported when using an inline JSX factory pragma \ No newline at end of file +!!! error TS17017: An @jsxFrag pragma is required when using an @jsx pragma with JSX fragments. \ No newline at end of file diff --git a/tests/baselines/reference/jsxFactoryAndFragment.errors.txt b/tests/baselines/reference/jsxFactoryAndFragment.errors.txt index bec2ea5cc0fb6..135ecdb6bc837 100644 --- a/tests/baselines/reference/jsxFactoryAndFragment.errors.txt +++ b/tests/baselines/reference/jsxFactoryAndFragment.errors.txt @@ -1,6 +1,6 @@ -tests/cases/compiler/jsxFactoryAndFragment.tsx(3,1): error TS17016: JSX fragment is not supported when using --jsxFactory -tests/cases/compiler/jsxFactoryAndFragment.tsx(4,1): error TS17016: JSX fragment is not supported when using --jsxFactory -tests/cases/compiler/jsxFactoryAndFragment.tsx(4,17): error TS17016: JSX fragment is not supported when using --jsxFactory +tests/cases/compiler/jsxFactoryAndFragment.tsx(3,1): error TS17016: The 'jsxFragmentFactory' compiler option must be provided to use JSX fragments with the 'jsxFactory' compiler option. +tests/cases/compiler/jsxFactoryAndFragment.tsx(4,1): error TS17016: The 'jsxFragmentFactory' compiler option must be provided to use JSX fragments with the 'jsxFactory' compiler option. +tests/cases/compiler/jsxFactoryAndFragment.tsx(4,17): error TS17016: The 'jsxFragmentFactory' compiler option must be provided to use JSX fragments with the 'jsxFactory' compiler option. ==== tests/cases/compiler/jsxFactoryAndFragment.tsx (3 errors) ==== @@ -8,9 +8,9 @@ tests/cases/compiler/jsxFactoryAndFragment.tsx(4,17): error TS17016: JSX fragmen <>; ~~~~~ -!!! error TS17016: JSX fragment is not supported when using --jsxFactory +!!! error TS17016: The 'jsxFragmentFactory' compiler option must be provided to use JSX fragments with the 'jsxFactory' compiler option. <>1<>2.12.2; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS17016: JSX fragment is not supported when using --jsxFactory +!!! error TS17016: The 'jsxFragmentFactory' compiler option must be provided to use JSX fragments with the 'jsxFactory' compiler option. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS17016: JSX fragment is not supported when using --jsxFactory \ No newline at end of file +!!! error TS17016: The 'jsxFragmentFactory' compiler option must be provided to use JSX fragments with the 'jsxFactory' compiler option. \ No newline at end of file diff --git a/tests/baselines/reference/jsxFactoryAndJsxFragmentFactory.js b/tests/baselines/reference/jsxFactoryAndJsxFragmentFactory.js new file mode 100644 index 0000000000000..3bffa897aef87 --- /dev/null +++ b/tests/baselines/reference/jsxFactoryAndJsxFragmentFactory.js @@ -0,0 +1,13 @@ +//// [jsxFactoryAndJsxFragmentFactory.tsx] +declare var h: any; + +<>; +<>1<>2.12.2; + +//// [jsxFactoryAndJsxFragmentFactory.js] +h(Frag, null); +h(Frag, null, + h("span", null, "1"), + h(Frag, null, + h("span", null, "2.1"), + h("span", null, "2.2"))); diff --git a/tests/baselines/reference/jsxFactoryAndJsxFragmentFactory.symbols b/tests/baselines/reference/jsxFactoryAndJsxFragmentFactory.symbols new file mode 100644 index 0000000000000..e21f2fac91861 --- /dev/null +++ b/tests/baselines/reference/jsxFactoryAndJsxFragmentFactory.symbols @@ -0,0 +1,6 @@ +=== tests/cases/compiler/jsxFactoryAndJsxFragmentFactory.tsx === +declare var h: any; +>h : Symbol(h, Decl(jsxFactoryAndJsxFragmentFactory.tsx, 0, 11)) + +<>; +<>1<>2.12.2; diff --git a/tests/baselines/reference/jsxFactoryAndJsxFragmentFactory.types b/tests/baselines/reference/jsxFactoryAndJsxFragmentFactory.types new file mode 100644 index 0000000000000..01d2d3003c6b1 --- /dev/null +++ b/tests/baselines/reference/jsxFactoryAndJsxFragmentFactory.types @@ -0,0 +1,20 @@ +=== tests/cases/compiler/jsxFactoryAndJsxFragmentFactory.tsx === +declare var h: any; +>h : any + +<>; +><> : error + +<>1<>2.12.2; +><>1<>2.12.2 : error +>1 : error +>span : any +>span : any +><>2.12.2 : error +>2.1 : error +>span : any +>span : any +>2.2 : error +>span : any +>span : any + diff --git a/tests/baselines/reference/jsxFactoryAndJsxFragmentFactoryErrorNotIdentifier.errors.txt b/tests/baselines/reference/jsxFactoryAndJsxFragmentFactoryErrorNotIdentifier.errors.txt new file mode 100644 index 0000000000000..3380f7b5aabde --- /dev/null +++ b/tests/baselines/reference/jsxFactoryAndJsxFragmentFactoryErrorNotIdentifier.errors.txt @@ -0,0 +1,9 @@ +error TS18035: Invalid value for 'jsxFragmentFactory'. '234' is not a valid identifier or qualified-name. + + +!!! error TS18035: Invalid value for 'jsxFragmentFactory'. '234' is not a valid identifier or qualified-name. +==== tests/cases/compiler/jsxFactoryAndJsxFragmentFactoryErrorNotIdentifier.tsx (0 errors) ==== + declare var h: any; + + <>; + <>1<>2.12.2; \ No newline at end of file diff --git a/tests/baselines/reference/jsxFactoryAndJsxFragmentFactoryErrorNotIdentifier.js b/tests/baselines/reference/jsxFactoryAndJsxFragmentFactoryErrorNotIdentifier.js new file mode 100644 index 0000000000000..bb65dcd0e1478 --- /dev/null +++ b/tests/baselines/reference/jsxFactoryAndJsxFragmentFactoryErrorNotIdentifier.js @@ -0,0 +1,13 @@ +//// [jsxFactoryAndJsxFragmentFactoryErrorNotIdentifier.tsx] +declare var h: any; + +<>; +<>1<>2.12.2; + +//// [jsxFactoryAndJsxFragmentFactoryErrorNotIdentifier.js] +h(React.Fragment, null); +h(React.Fragment, null, + h("span", null, "1"), + h(React.Fragment, null, + h("span", null, "2.1"), + h("span", null, "2.2"))); diff --git a/tests/baselines/reference/jsxFactoryAndJsxFragmentFactoryErrorNotIdentifier.symbols b/tests/baselines/reference/jsxFactoryAndJsxFragmentFactoryErrorNotIdentifier.symbols new file mode 100644 index 0000000000000..490b73a4015cd --- /dev/null +++ b/tests/baselines/reference/jsxFactoryAndJsxFragmentFactoryErrorNotIdentifier.symbols @@ -0,0 +1,6 @@ +=== tests/cases/compiler/jsxFactoryAndJsxFragmentFactoryErrorNotIdentifier.tsx === +declare var h: any; +>h : Symbol(h, Decl(jsxFactoryAndJsxFragmentFactoryErrorNotIdentifier.tsx, 0, 11)) + +<>; +<>1<>2.12.2; diff --git a/tests/baselines/reference/jsxFactoryAndJsxFragmentFactoryErrorNotIdentifier.types b/tests/baselines/reference/jsxFactoryAndJsxFragmentFactoryErrorNotIdentifier.types new file mode 100644 index 0000000000000..23cbb14449c54 --- /dev/null +++ b/tests/baselines/reference/jsxFactoryAndJsxFragmentFactoryErrorNotIdentifier.types @@ -0,0 +1,20 @@ +=== tests/cases/compiler/jsxFactoryAndJsxFragmentFactoryErrorNotIdentifier.tsx === +declare var h: any; +>h : any + +<>; +><> : any + +<>1<>2.12.2; +><>1<>2.12.2 : any +>1 : any +>span : any +>span : any +><>2.12.2 : any +>2.1 : any +>span : any +>span : any +>2.2 : any +>span : any +>span : any + diff --git a/tests/baselines/reference/jsxFactoryAndJsxFragmentFactoryNull.js b/tests/baselines/reference/jsxFactoryAndJsxFragmentFactoryNull.js new file mode 100644 index 0000000000000..aad55296fe8b1 --- /dev/null +++ b/tests/baselines/reference/jsxFactoryAndJsxFragmentFactoryNull.js @@ -0,0 +1,13 @@ +//// [jsxFactoryAndJsxFragmentFactoryNull.tsx] +declare var h: any; + +<>; +<>1<>2.12.2; + +//// [jsxFactoryAndJsxFragmentFactoryNull.js] +h(null, null); +h(null, null, + h("span", null, "1"), + h(null, null, + h("span", null, "2.1"), + h("span", null, "2.2"))); diff --git a/tests/baselines/reference/jsxFactoryAndJsxFragmentFactoryNull.symbols b/tests/baselines/reference/jsxFactoryAndJsxFragmentFactoryNull.symbols new file mode 100644 index 0000000000000..102abc07fde66 --- /dev/null +++ b/tests/baselines/reference/jsxFactoryAndJsxFragmentFactoryNull.symbols @@ -0,0 +1,6 @@ +=== tests/cases/compiler/jsxFactoryAndJsxFragmentFactoryNull.tsx === +declare var h: any; +>h : Symbol(h, Decl(jsxFactoryAndJsxFragmentFactoryNull.tsx, 0, 11)) + +<>; +<>1<>2.12.2; diff --git a/tests/baselines/reference/jsxFactoryAndJsxFragmentFactoryNull.types b/tests/baselines/reference/jsxFactoryAndJsxFragmentFactoryNull.types new file mode 100644 index 0000000000000..59bc383c2aa4a --- /dev/null +++ b/tests/baselines/reference/jsxFactoryAndJsxFragmentFactoryNull.types @@ -0,0 +1,20 @@ +=== tests/cases/compiler/jsxFactoryAndJsxFragmentFactoryNull.tsx === +declare var h: any; +>h : any + +<>; +><> : error + +<>1<>2.12.2; +><>1<>2.12.2 : error +>1 : error +>span : any +>span : any +><>2.12.2 : error +>2.1 : error +>span : any +>span : any +>2.2 : error +>span : any +>span : any + diff --git a/tests/baselines/reference/jsxFactoryButNoJsxFragmentFactory.errors.txt b/tests/baselines/reference/jsxFactoryButNoJsxFragmentFactory.errors.txt new file mode 100644 index 0000000000000..ab8eaf927db3a --- /dev/null +++ b/tests/baselines/reference/jsxFactoryButNoJsxFragmentFactory.errors.txt @@ -0,0 +1,16 @@ +tests/cases/compiler/jsxFactoryButNoJsxFragmentFactory.tsx(3,1): error TS17016: The 'jsxFragmentFactory' compiler option must be provided to use JSX fragments with the 'jsxFactory' compiler option. +tests/cases/compiler/jsxFactoryButNoJsxFragmentFactory.tsx(4,1): error TS17016: The 'jsxFragmentFactory' compiler option must be provided to use JSX fragments with the 'jsxFactory' compiler option. +tests/cases/compiler/jsxFactoryButNoJsxFragmentFactory.tsx(4,17): error TS17016: The 'jsxFragmentFactory' compiler option must be provided to use JSX fragments with the 'jsxFactory' compiler option. + + +==== tests/cases/compiler/jsxFactoryButNoJsxFragmentFactory.tsx (3 errors) ==== + declare var h: any; + + <>; + ~~~~~ +!!! error TS17016: The 'jsxFragmentFactory' compiler option must be provided to use JSX fragments with the 'jsxFactory' compiler option. + <>1<>2.12.2; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS17016: The 'jsxFragmentFactory' compiler option must be provided to use JSX fragments with the 'jsxFactory' compiler option. + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS17016: The 'jsxFragmentFactory' compiler option must be provided to use JSX fragments with the 'jsxFactory' compiler option. \ No newline at end of file diff --git a/tests/baselines/reference/jsxFactoryButNoJsxFragmentFactory.js b/tests/baselines/reference/jsxFactoryButNoJsxFragmentFactory.js new file mode 100644 index 0000000000000..6babd1025bf96 --- /dev/null +++ b/tests/baselines/reference/jsxFactoryButNoJsxFragmentFactory.js @@ -0,0 +1,13 @@ +//// [jsxFactoryButNoJsxFragmentFactory.tsx] +declare var h: any; + +<>; +<>1<>2.12.2; + +//// [jsxFactoryButNoJsxFragmentFactory.js] +h(React.Fragment, null); +h(React.Fragment, null, + h("span", null, "1"), + h(React.Fragment, null, + h("span", null, "2.1"), + h("span", null, "2.2"))); diff --git a/tests/baselines/reference/jsxFactoryButNoJsxFragmentFactory.symbols b/tests/baselines/reference/jsxFactoryButNoJsxFragmentFactory.symbols new file mode 100644 index 0000000000000..1d6ca75f38d83 --- /dev/null +++ b/tests/baselines/reference/jsxFactoryButNoJsxFragmentFactory.symbols @@ -0,0 +1,6 @@ +=== tests/cases/compiler/jsxFactoryButNoJsxFragmentFactory.tsx === +declare var h: any; +>h : Symbol(h, Decl(jsxFactoryButNoJsxFragmentFactory.tsx, 0, 11)) + +<>; +<>1<>2.12.2; diff --git a/tests/baselines/reference/jsxFactoryButNoJsxFragmentFactory.types b/tests/baselines/reference/jsxFactoryButNoJsxFragmentFactory.types new file mode 100644 index 0000000000000..c6310dd56e707 --- /dev/null +++ b/tests/baselines/reference/jsxFactoryButNoJsxFragmentFactory.types @@ -0,0 +1,20 @@ +=== tests/cases/compiler/jsxFactoryButNoJsxFragmentFactory.tsx === +declare var h: any; +>h : any + +<>; +><> : any + +<>1<>2.12.2; +><>1<>2.12.2 : any +>1 : any +>span : any +>span : any +><>2.12.2 : any +>2.1 : any +>span : any +>span : any +>2.2 : any +>span : any +>span : any + diff --git a/tests/baselines/reference/showConfig/Shows tsconfig for single option/jsxFragmentFactory/tsconfig.json b/tests/baselines/reference/showConfig/Shows tsconfig for single option/jsxFragmentFactory/tsconfig.json new file mode 100644 index 0000000000000..bc59203b9634b --- /dev/null +++ b/tests/baselines/reference/showConfig/Shows tsconfig for single option/jsxFragmentFactory/tsconfig.json @@ -0,0 +1,5 @@ +{ + "compilerOptions": { + "jsxFragmentFactory": "someString" + } +} diff --git a/tests/baselines/reference/transpile/Supports setting jsxFragmentFactory.js b/tests/baselines/reference/transpile/Supports setting jsxFragmentFactory.js new file mode 100644 index 0000000000000..8394371f9081a --- /dev/null +++ b/tests/baselines/reference/transpile/Supports setting jsxFragmentFactory.js @@ -0,0 +1,2 @@ +x; +//# sourceMappingURL=input.js.map \ No newline at end of file diff --git a/tests/baselines/reference/transpile/Supports setting jsxFragmentFactory.oldTranspile.js b/tests/baselines/reference/transpile/Supports setting jsxFragmentFactory.oldTranspile.js new file mode 100644 index 0000000000000..8394371f9081a --- /dev/null +++ b/tests/baselines/reference/transpile/Supports setting jsxFragmentFactory.oldTranspile.js @@ -0,0 +1,2 @@ +x; +//# sourceMappingURL=input.js.map \ No newline at end of file diff --git a/tests/cases/compiler/jsxFactoryAndJsxFragmentFactory.tsx b/tests/cases/compiler/jsxFactoryAndJsxFragmentFactory.tsx new file mode 100644 index 0000000000000..c509ed5b46103 --- /dev/null +++ b/tests/cases/compiler/jsxFactoryAndJsxFragmentFactory.tsx @@ -0,0 +1,8 @@ +//@jsx: react +//@jsxFactory: h +//@jsxFragmentFactory: Frag + +declare var h: any; + +<>; +<>1<>2.12.2; \ No newline at end of file diff --git a/tests/cases/compiler/jsxFactoryAndJsxFragmentFactoryErrorNotIdentifier.tsx b/tests/cases/compiler/jsxFactoryAndJsxFragmentFactoryErrorNotIdentifier.tsx new file mode 100644 index 0000000000000..030ede2a31a2c --- /dev/null +++ b/tests/cases/compiler/jsxFactoryAndJsxFragmentFactoryErrorNotIdentifier.tsx @@ -0,0 +1,8 @@ +//@jsx: react +//@jsxFactory: h +//@jsxFragmentFactory: 234 + +declare var h: any; + +<>; +<>1<>2.12.2; \ No newline at end of file diff --git a/tests/cases/compiler/jsxFactoryAndJsxFragmentFactoryNull.tsx b/tests/cases/compiler/jsxFactoryAndJsxFragmentFactoryNull.tsx new file mode 100644 index 0000000000000..babd3cb713843 --- /dev/null +++ b/tests/cases/compiler/jsxFactoryAndJsxFragmentFactoryNull.tsx @@ -0,0 +1,8 @@ +//@jsx: react +//@jsxFactory: h +//@jsxFragmentFactory: null + +declare var h: any; + +<>; +<>1<>2.12.2; \ No newline at end of file diff --git a/tests/cases/compiler/jsxFactoryAndFragment.tsx b/tests/cases/compiler/jsxFactoryButNoJsxFragmentFactory.tsx similarity index 100% rename from tests/cases/compiler/jsxFactoryAndFragment.tsx rename to tests/cases/compiler/jsxFactoryButNoJsxFragmentFactory.tsx diff --git a/tests/cases/conformance/jsx/inline/inlineJsxAndJsxFragPragma.tsx b/tests/cases/conformance/jsx/inline/inlineJsxAndJsxFragPragma.tsx new file mode 100644 index 0000000000000..59fa10dbfbcaf --- /dev/null +++ b/tests/cases/conformance/jsx/inline/inlineJsxAndJsxFragPragma.tsx @@ -0,0 +1,26 @@ +// @jsx: react +// @filename: renderer.d.ts +declare global { + namespace JSX { + interface IntrinsicElements { + [e: string]: any; + } + } +} +export function h(): void; +export function jsx(): void; +export function Fragment(): void; + +// @filename: preacty.tsx +/** + * @jsx h + * @jsxFrag Fragment + */ +import {h, Fragment} from "./renderer"; +<>
+ +// @filename: snabbdomy.tsx +/* @jsx jsx */ +/* @jsxfrag null */ +import {jsx} from "./renderer"; +<> \ No newline at end of file diff --git a/tests/cases/conformance/jsx/inline/inlineJsxAndJsxFragPragmaOverridesCompilerOptions.tsx b/tests/cases/conformance/jsx/inline/inlineJsxAndJsxFragPragmaOverridesCompilerOptions.tsx new file mode 100644 index 0000000000000..7a65fc965aadf --- /dev/null +++ b/tests/cases/conformance/jsx/inline/inlineJsxAndJsxFragPragmaOverridesCompilerOptions.tsx @@ -0,0 +1,48 @@ +// @jsx: react +// @jsxFactory: createElement +// @jsxFragmentFactory: Fragment + +// @filename: react.d.ts +declare global { + namespace JSX { + interface IntrinsicElements { + [e: string]: any; + } + } +} +export function createElement(): void; +export function Fragment(): void; + +// @filename: preact.d.ts +export function h(): void; +export function Frag(): void; + +// @filename: snabbdom.d.ts +export function h(): void; + +// @filename: reacty.tsx +import {createElement, Fragment} from "./react"; +<> + +// @filename: preacty.tsx +/** + * @jsx h + * @jsxFrag Frag + */ +import {h, Frag} from "./preact"; +<>
+ +// @filename: snabbdomy.tsx +/** + * @jsx h + * @jsxfrag null + */ +import {h} from "./snabbdom"; +<>
+ +// @filename: mix-n-match.tsx +/* @jsx h */ +/* @jsxFrag Fragment */ +import {h} from "./preact"; +import {Fragment} from "./react"; +<> \ No newline at end of file