summaryrefslogtreecommitdiff
path: root/node_modules/@babel/template/lib/populate.js
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/@babel/template/lib/populate.js')
-rw-r--r--node_modules/@babel/template/lib/populate.js21
1 files changed, 18 insertions, 3 deletions
diff --git a/node_modules/@babel/template/lib/populate.js b/node_modules/@babel/template/lib/populate.js
index fb67269f..35e5f6f7 100644
--- a/node_modules/@babel/template/lib/populate.js
+++ b/node_modules/@babel/template/lib/populate.js
@@ -98,9 +98,24 @@ function applyReplacement(placeholder, ast, replacement) {
throw new Error("Cannot replace single expression with an array.");
}
}
+ function set(parent, key, value) {
+ const node = parent[key];
+ parent[key] = value;
+ if (node.type === "Identifier") {
+ if (node.typeAnnotation) {
+ value.typeAnnotation = node.typeAnnotation;
+ }
+ if (node.optional) {
+ value.optional = node.optional;
+ }
+ if (node.decorators) {
+ value.decorators = node.decorators;
+ }
+ }
+ }
if (index === undefined) {
validate(parent, key, replacement);
- parent[key] = replacement;
+ set(parent, key, replacement);
} else {
const items = parent[key].slice();
if (placeholder.type === "statement" || placeholder.type === "param") {
@@ -109,10 +124,10 @@ function applyReplacement(placeholder, ast, replacement) {
} else if (Array.isArray(replacement)) {
items.splice(index, 1, ...replacement);
} else {
- items[index] = replacement;
+ set(items, index, replacement);
}
} else {
- items[index] = replacement;
+ set(items, index, replacement);
}
validate(parent, key, items);
parent[key] = items;