
Security News
The Next Open Source Security Race: Triage at Machine Speed
Claude Opus 4.6 has uncovered more than 500 open source vulnerabilities, raising new considerations for disclosure, triage, and patching at scale.
babel-plugin-immutable
Advanced tools
Transforms JSX elements to a string literal.
The default behaviour is to convert only <heredoc> elements (see Configuration).
Input:
const foo = <heredoc>Hello, World!</heredoc>;
const bar = <heredoc>
Hello,
World!
</heredoc>;
Output:
const foo = "Hello, World!";
const bar = "\n Hello,\n World!\n";
My primary use case for this plugin is to enable writing multi-line MySQL queries.
In MySQL, if an identifier contains special characters or is a reserved word, you must quote it whenever you refer to it. The identifier quote character is the backtick (`).
Nonreserved keywords are permitted as identifiers without quoting. However, it is a healthy habit to quote all identifiers to prevent accidental collision with keywords, reserved words and names of built-in functions.
There is no problem writing single-line MySQL queries because you can use single or double quotes, e.g.
const = 'SELECT `p1`.`id`, `p1`.`name`, `t1`.`id` `tagId`, `t1`.`name` `tagName` FROM `page` `p1` INNER JOIN `page_tag` `pt1` ON `pt1`.`page_id` = `p1`.`id` GROUP BY `p1`.`id` HAVING COUNT(`pt1`.`id`) = 4';
However, writing a long query on a single line hurts the readability of the query. You cannot use template literals because the syntax clashes with the MySQL identifier quote character.
A proponent of the template literals syntax will argue that you can escape the backtick character, e.g.
const = `
SELECT
\`p1\`.\`id\`,
\`p1\`.\`name\`,
\`t1\`.\`id\` \`tagId\`,
\`t1\`.\`name\` \`tagName\`
FROM
\`page\` \`p1\`
INNER JOIN
\`page_tag\` \`pt1\`
ON
\`pt1\`.\`page_id\` = \`p1\`.\`id\`
GROUP BY
\`p1\`.\`id\`
HAVING
COUNT(\`pt1\`.\`id\`) = 4
`;
However, this approach has several disadvantages:
As a result, the established practise for writing MySQL queries that span multiple lines is to store them in a separate file. This is a good approach, esp. for very long queries. However, sometimes you want to have queries in-file, e.g. when prototyping or if you simply prefer to.
This is where the babel-plugin-transform-jsx-element-to-string-literal comes in. You can declare any query using JSX elements:
const = <sql>
SELECT
`p1`.`id`,
`p1`.`name`,
`t1`.`id` `tagId`,
`t1`.`name` `tagName`
FROM
`page` `p1`
INNER JOIN
`page_tag` `pt1`
ON
`pt1`.`page_id` = `p1`.`id`
GROUP BY
`p1`.`id`
HAVING
COUNT(`pt1`.`id`) = 4
</sql>;
Note: The above example is using
{"tagNames": ["sql"]}configuration.
| Name | Default | Description |
|---|---|---|
tagNames | ["heredoc"] | List of JSX element names that need to be transpiled to a string. |
FAQs
Uses Object.freeze to freeze all object and array expressions.
We found that babel-plugin-immutable demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Claude Opus 4.6 has uncovered more than 500 open source vulnerabilities, raising new considerations for disclosure, triage, and patching at scale.

Research
/Security News
Malicious dYdX client packages were published to npm and PyPI after a maintainer compromise, enabling wallet credential theft and remote code execution.

Security News
gem.coop is testing registry-level dependency cooldowns to limit exposure during the brief window when malicious gems are most likely to spread.