Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
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)
  • Loading branch information
Rowan Wyborn committed Dec 18, 2015
commit b7f60704bb7f6ad941148cab586afd3e26eff41e
11 changes: 6 additions & 5 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down
5 changes: 5 additions & 0 deletions src/compiler/commandLineParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 4 additions & 0 deletions src/compiler/diagnosticMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, ...
Expand Down
1 change: 1 addition & 0 deletions src/compiler/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2382,6 +2382,7 @@ namespace ts {
inlineSourceMap?: boolean;
inlineSources?: boolean;
jsx?: JsxEmit;
jsxNamespace? : string;
listFiles?: boolean;
locale?: string;
mapRoot?: string;
Expand Down