-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Fix generated JSX pragmas for new babel #2438
Changes from all commits
156187c
634b6ba
d9e33f0
47b017e
220006b
dbc5164
ddfdf61
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -73,8 +73,6 @@ export function recmaDocument(options) { | |
const exportedIdentifiers = [] | ||
/** @type {Array<Directive | ModuleDeclaration | Statement>} */ | ||
const replacement = [] | ||
/** @type {Array<string>} */ | ||
const pragmas = [] | ||
let exportAllCount = 0 | ||
/** @type {ExportDefaultDeclaration | ExportSpecifier | undefined} */ | ||
let layout | ||
|
@@ -83,31 +81,20 @@ export function recmaDocument(options) { | |
/** @type {Node} */ | ||
let child | ||
|
||
if (jsxRuntime) { | ||
pragmas.push('@jsxRuntime ' + jsxRuntime) | ||
} | ||
|
||
if (jsxRuntime === 'automatic' && jsxImportSource) { | ||
pragmas.push('@jsxImportSource ' + jsxImportSource) | ||
if (jsxRuntime === 'classic' && pragmaFrag) { | ||
injectPragma(tree, '@jsxFrag', pragmaFrag) | ||
} | ||
|
||
if (jsxRuntime === 'classic' && pragma) { | ||
pragmas.push('@jsx ' + pragma) | ||
injectPragma(tree, '@jsx', pragma) | ||
} | ||
|
||
if (jsxRuntime === 'classic' && pragmaFrag) { | ||
pragmas.push('@jsxFrag ' + pragmaFrag) | ||
if (jsxRuntime === 'automatic' && jsxImportSource) { | ||
injectPragma(tree, '@jsxImportSource', jsxImportSource) | ||
} | ||
|
||
/* c8 ignore next -- comments can be missing in the types, we always have it. */ | ||
if (!tree.comments) tree.comments = [] | ||
|
||
if (pragmas.length > 0) { | ||
tree.comments.unshift({ | ||
type: 'Block', | ||
value: pragmas.join(' '), | ||
data: {_mdxIsPragmaComment: true} | ||
}) | ||
if (jsxRuntime) { | ||
injectPragma(tree, '@jsxRuntime', jsxRuntime) | ||
} | ||
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. Nitty, but I don‘t really like the reverse stuff. tree.comments.unshift(
...pragmas.map(function (d) {
return /** @type {const} */ ({
type: 'Block',
value: d,
data: {_mdxIsPragmaComment: true}
})
})
) Only don’t really like the 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. I tried this at first, but TS caught me too. I see the 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. Ahh. I dunno maybe a lot of repetition. Maybe more comments will be added in the future too. 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. I already applied this using a function to avoid repetition. I like it, but I can revert if you don’t. |
||
|
||
if (jsxRuntime === 'classic' && pragmaImportSource) { | ||
|
@@ -706,6 +693,20 @@ export function recmaDocument(options) { | |
} | ||
} | ||
|
||
/** | ||
* @param {Program} tree | ||
* @param {string} name | ||
* @param {string} value | ||
* @returns {undefined} | ||
*/ | ||
function injectPragma(tree, name, value) { | ||
tree.comments?.unshift({ | ||
type: 'Block', | ||
value: name + ' ' + value, | ||
data: {_mdxIsPragmaComment: true} | ||
}) | ||
} | ||
|
||
/** | ||
* @param {Expression} importMetaUrl | ||
* @returns {FunctionDeclaration} | ||
|
This comment was marked as spam.
Sorry, something went wrong.