Remove the dynamic require() call in the standalone bundle (#5612)
* Remove the dynamic `require()` call in the standalone bundle * Liiiint * Just use `replaceStrings` * Reword error message
This commit is contained in:
1 parent
5e89969a9e
commit
b74f94d6dd
2 files changed
+21
-10
No files matched your search
+20
-10
@@ -42,16 +42,26 @@ function resolveParser(opts, parsers) {
|
||||
if (parsers.hasOwnProperty(opts.parser)) {
|
||||
return parsers[opts.parser];
|
||||
}
|
||||
try {
|
||||
return {
|
||||
parse: eval("require")(path.resolve(process.cwd(), opts.parser)),
|
||||
astFormat: "estree",
|
||||
locStart,
|
||||
locEnd
|
||||
};
|
||||
} catch (err) {
|
||||
/* istanbul ignore next */
|
||||
throw new ConfigError(`Couldn't resolve parser "${opts.parser}"`);
|
||||
|
||||
/* istanbul ignore next */
|
||||
if (process.env.PRETTIER_TARGET === "universal") {
|
||||
throw new ConfigError(
|
||||
`Couldn't resolve parser "${
|
||||
opts.parser
|
||||
}". Parsers must be explicitly added to the standalone bundle.`
|
||||
);
|
||||
} else {
|
||||
try {
|
||||
return {
|
||||
parse: eval("require")(path.resolve(process.cwd(), opts.parser)),
|
||||
astFormat: "estree",
|
||||
locStart,
|
||||
locEnd
|
||||
};
|
||||
} catch (err) {
|
||||
/* istanbul ignore next */
|
||||
throw new ConfigError(`Couldn't resolve parser "${opts.parser}"`);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user