feature: babel-core: add cloneInputAst (#10241)
Co-authored-by: coderaiser <coderaiser@cloudcmd.io>
This commit is contained in:
@@ -81,6 +81,7 @@ export default function* loadPrivatePartialConfig(
|
||||
root: rootDir = ".",
|
||||
rootMode = "root",
|
||||
caller,
|
||||
cloneInputAst = true,
|
||||
} = args;
|
||||
const absoluteCwd = path.resolve(cwd);
|
||||
const absoluteRootDir = yield* resolveRootMode(
|
||||
@@ -110,6 +111,7 @@ export default function* loadPrivatePartialConfig(
|
||||
// Tack the passes onto the object itself so that, if this object is
|
||||
// passed back to Babel a second time, it will be in the right structure
|
||||
// to not change behavior.
|
||||
options.cloneInputAst = cloneInputAst;
|
||||
options.babelrc = false;
|
||||
options.configFile = false;
|
||||
options.passPerPreset = false;
|
||||
|
||||
@@ -51,6 +51,10 @@ const ROOT_VALIDATORS: ValidatorSet = {
|
||||
code: (assertBoolean: Validator<$PropertyType<ValidatedOptions, "code">>),
|
||||
ast: (assertBoolean: Validator<$PropertyType<ValidatedOptions, "ast">>),
|
||||
|
||||
cloneInputAst: (assertBoolean: Validator<
|
||||
$PropertyType<ValidatedOptions, "cloneInputAst">,
|
||||
>),
|
||||
|
||||
envName: (assertString: Validator<
|
||||
$PropertyType<ValidatedOptions, "envName">,
|
||||
>),
|
||||
@@ -184,6 +188,7 @@ export type ValidatedOptions = {
|
||||
rootMode?: RootMode,
|
||||
code?: boolean,
|
||||
ast?: boolean,
|
||||
cloneInputAst?: boolean,
|
||||
inputSourceMap?: RootInputSourceMapOption,
|
||||
envName?: string,
|
||||
caller?: CallerMetadata,
|
||||
|
||||
@@ -34,7 +34,11 @@ export default function* normalizeFile(
|
||||
} else if (ast.type !== "File") {
|
||||
throw new Error("AST root must be a Program or File node");
|
||||
}
|
||||
ast = cloneDeep(ast);
|
||||
|
||||
const { cloneInputAst } = options;
|
||||
if (cloneInputAst) {
|
||||
ast = cloneDeep(ast);
|
||||
}
|
||||
} else {
|
||||
ast = yield* parser(pluginPasses, options, code);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user