Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 13.8k
Add support for transpiling per-file jsx pragmas#21218
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
f4d314352a6f22fa366403abda0a8d5c733File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -299,7 +299,7 @@ namespace ts { | ||
| resolveName(name, location, meaning, excludeGlobals) { | ||
| return resolveName(location, escapeLeadingUnderscores(name), meaning, /*nameNotFoundMessage*/ undefined, /*nameArg*/ undefined, /*isUse*/ false, excludeGlobals); | ||
| }, | ||
| getJsxNamespace: () => unescapeLeadingUnderscores(getJsxNamespace()), | ||
| getJsxNamespace: n => unescapeLeadingUnderscores(getJsxNamespace(n)), | ||
| getAccessibleSymbolChain, | ||
| getTypePredicateOfSignature, | ||
| resolveExternalModuleSymbol, | ||
| @@ -765,7 +765,23 @@ namespace ts { | ||
| } | ||
| } | ||
| function getJsxNamespace(): __String { | ||
| function getJsxNamespace(location: Node | undefined): __String { | ||
| if (location) { | ||
| const file = getSourceFileOfNode(location); | ||
| if (file) { | ||
| if (file.localJsxNamespace) { | ||
| return file.localJsxNamespace; | ||
| } | ||
| const jsxPragma = file.pragmas.get("jsx"); | ||
| if (jsxPragma) { | ||
| const chosenpragma = isArray(jsxPragma) ? jsxPragma[0] : jsxPragma; | ||
Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why not set this one in
| ||
| file.localJsxFactory = parseIsolatedEntityName(chosenpragma.arguments.factory, languageVersion); | ||
| if (file.localJsxFactory) { | ||
| return file.localJsxNamespace = getFirstIdentifier(file.localJsxFactory).escapedText; | ||
| } | ||
| } | ||
| } | ||
| } | ||
| if (!_jsxNamespace) { | ||
| _jsxNamespace = "React" as __String; | ||
| if (compilerOptions.jsxFactory) { | ||
| @@ -15082,8 +15098,10 @@ namespace ts { | ||
| function checkJsxFragment(node: JsxFragment, checkMode: CheckMode): Type { | ||
| checkJsxOpeningLikeElementOrOpeningFragment(node.openingFragment, checkMode); | ||
| if (compilerOptions.jsx === JsxEmit.React && compilerOptions.jsxFactory) { | ||
| error(node, Diagnostics.JSX_fragment_is_not_supported_when_using_jsxFactory); | ||
| if (compilerOptions.jsx === JsxEmit.React && (compilerOptions.jsxFactory || getSourceFileOfNode(node).pragmas.has("jsx"))) { | ||
| 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); | ||
| } | ||
| return getJsxGlobalElementType() || anyType; | ||
| @@ -15709,7 +15727,7 @@ namespace ts { | ||
| // 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(); | ||
| const reactNamespace = getJsxNamespace(node); | ||
| const reactLocation = isNodeOpeningLikeElement ? (<JsxOpeningLikeElement>node).tagName : node; | ||
| const reactSym = resolveName(reactLocation, reactNamespace, SymbolFlags.Value, reactRefErr, reactNamespace, /*isUse*/ true); | ||
| if (reactSym) { | ||
| @@ -25556,7 +25574,7 @@ namespace ts { | ||
| return !!(symbol && getCheckFlags(symbol) & CheckFlags.Late); | ||
| }, | ||
| writeLiteralConstValue, | ||
| getJsxFactoryEntity: () => _jsxFactoryEntity | ||
| getJsxFactoryEntity: location => location ? (getJsxNamespace(location), (getSourceFileOfNode(location).localJsxFactory || _jsxFactoryEntity)) : _jsxFactoryEntity | ||
| }; | ||
| // defined here to avoid outer scope pollution | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is it
jsxand notjsxNamespacelike the compiler option?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Babel supports
jsxand I figured we'd want to support the same thing - we can aliasjsxNamespace, if you'd like?