Improve RegExps in markdown printer (#15656)
This commit is contained in:
1 parent
3478719cc0
commit
99ecf47e1d
4 files changed
+53
-46
No files matched your search
@@ -14,12 +14,15 @@ export default function esbuildPluginEvaluate() {
|
||||
const module = await importModule(path);
|
||||
const text = Object.entries(module)
|
||||
.map(([specifier, value]) => {
|
||||
value = serialize(value, { space: 2 });
|
||||
const code =
|
||||
value instanceof RegExp
|
||||
? `/${value.source}/${value.flags}`
|
||||
: serialize(value, { space: 2 });
|
||||
|
||||
if (specifier === "default") {
|
||||
return format === "cjs"
|
||||
? `module.exports = ${value};`
|
||||
: `export default ${value};`;
|
||||
? `module.exports = ${code};`
|
||||
: `export default ${code};`;
|
||||
}
|
||||
|
||||
if (!isValidIdentifier(specifier)) {
|
||||
@@ -27,8 +30,8 @@ export default function esbuildPluginEvaluate() {
|
||||
}
|
||||
|
||||
return format === "cjs"
|
||||
? `exports.${specifier} = ${value};`
|
||||
: `export const ${specifier} = ${value};`;
|
||||
? `exports.${specifier} = ${code};`
|
||||
: `export const ${specifier} = ${code};`;
|
||||
})
|
||||
.join("\n");
|
||||
return { contents: text };
|
||||
|
||||
Reference in new issue
Block a user