Skip to main content

@babel/plugin-syntax-module-string-names

Exampleโ€‹

This plugin enables @babel/parser to parse

JavaScript
export { smile as "๐Ÿ˜„" } from "./emojis.js";

It requires @babel/parser@^7.12.0. When used with @babel/plugin-transform-modules-commonjs, the example above will be transformed as

JavaScript
const emojis = require("./emojis.js");
Object.defineProperty(exports, "__esModule", {
value: true,
});

exports["๐Ÿ˜„"] = emojis.smile;

Note that it is not possible to transpile this syntax to ES2015-style imports and exports. They are supported in other module systems such as amd, systemjs and umd.

Installationโ€‹

npm install --save-dev @babel/plugin-syntax-module-string-names

Usageโ€‹

babel.config.json
{
"plugins": ["@babel/plugin-syntax-module-string-names"]
}

Via CLIโ€‹

Shell
babel --plugins @babel/plugin-syntax-module-string-names script.js

Via Node APIโ€‹

JavaScript
require("@babel/core").transformSync("code", {
plugins: ["@babel/plugin-syntax-module-string-names"],
});