Initial check in - Support other JSX factories Issue #3788

- added jsxNamespace compile option
- when jsx mode is "react", jsxNamespace optionally specifies the emit namespace for React calls, eg "--jsxNamespace MyDOMLib" will emit calls as MyDOMLib.createElement (instead of React.createElement)
- symbol specified by jsxNamespace must be present, else compile error is generated (same handling as is done for React symbol when no jsxNamespace is specified)
This commit is contained in:
Rowan Wyborn 2015-12-18 21:56:08 +11:00
parent bb1e5ab5ea
commit b7f60704bb
5 changed files with 17 additions and 6 deletions

View File

@ -8491,13 +8491,14 @@ namespace ts {
checkGrammarJsxElement(node);
checkJsxPreconditions(node);
// If we're compiling under --jsx react, the symbol 'React' should
// If we're compiling under --jsx react, the JSX namespace symbol should
// be marked as 'used' so we don't incorrectly elide its import. And if there
// is no 'React' symbol in scope, we should issue an error.
// is no JSX namespace symbol in scope, we should issue an error.
if (compilerOptions.jsx === JsxEmit.React) {
const reactSym = resolveName(node.tagName, "React", SymbolFlags.Value, Diagnostics.Cannot_find_name_0, "React");
if (reactSym) {
getSymbolLinks(reactSym).referenced = true;
const jsxNamespace = compilerOptions.jsxNamespace ? compilerOptions.jsxNamespace : "React";
const jsxSym = resolveName(node.tagName, jsxNamespace, SymbolFlags.Value, Diagnostics.Cannot_find_name_0, jsxNamespace);
if (jsxSym) {
getSymbolLinks(jsxSym).referenced = true;
}
}

View File

@ -54,6 +54,11 @@ namespace ts {
description: Diagnostics.Specify_JSX_code_generation_Colon_preserve_or_react,
error: Diagnostics.Argument_for_jsx_must_be_preserve_or_react
},
{
name: "jsxNamespace",
type: "string",
description: Diagnostics.Specify_JSX_emit_namespace_when_JSX_code_generation_mode_is_react
},
{
name: "listFiles",
type: "boolean",

View File

@ -2389,6 +2389,10 @@
"category": "Message",
"code": 6083
},
"Specify JSX emit namespace when JSX code generation mode is 'react'": {
"category": "Message",
"code": 6084
},
"Variable '{0}' implicitly has an '{1}' type.": {
"category": "Error",

View File

@ -1192,7 +1192,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
function emitJsxElement(openingNode: JsxOpeningLikeElement, children?: JsxChild[]) {
const syntheticReactRef = <Identifier>createSynthesizedNode(SyntaxKind.Identifier);
syntheticReactRef.text = "React";
syntheticReactRef.text = compilerOptions.jsxNamespace ? compilerOptions.jsxNamespace : "React";
syntheticReactRef.parent = openingNode;
// Call React.createElement(tag, ...

View File

@ -2382,6 +2382,7 @@ namespace ts {
inlineSourceMap?: boolean;
inlineSources?: boolean;
jsx?: JsxEmit;
jsxNamespace? : string;
listFiles?: boolean;
locale?: string;
mapRoot?: string;