clear and inherit all symbols and underscore propertes in t.inherits and traverse.removeProperties
This commit is contained in:
parent
63cd3008d2
commit
e80c206591
@ -73,7 +73,6 @@ traverse.node = function (node: Object, opts: Object, scope: Object, state: Obje
|
|||||||
};
|
};
|
||||||
|
|
||||||
const CLEAR_KEYS: Array = t.COMMENT_KEYS.concat([
|
const CLEAR_KEYS: Array = t.COMMENT_KEYS.concat([
|
||||||
"_scopeInfo", "_paths",
|
|
||||||
"tokens", "comments",
|
"tokens", "comments",
|
||||||
"start", "end", "loc",
|
"start", "end", "loc",
|
||||||
"raw", "rawValue"
|
"raw", "rawValue"
|
||||||
@ -83,6 +82,15 @@ traverse.clearNode = function (node) {
|
|||||||
for (let key of CLEAR_KEYS) {
|
for (let key of CLEAR_KEYS) {
|
||||||
if (node[key] != null) node[key] = undefined;
|
if (node[key] != null) node[key] = undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (let key in node) {
|
||||||
|
if (key[0] === "_" && node[key] != null) node[key] = undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
let syms: Array<Symbol> = Object.getOwnPropertyNames(node);
|
||||||
|
for (let sym of syms) {
|
||||||
|
node[sym] = null;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
traverse.removeProperties = function (tree) {
|
traverse.removeProperties = function (tree) {
|
||||||
|
|||||||
@ -33,7 +33,7 @@ export const COMMENT_KEYS = ["leadingComments", "trailingComments", "
|
|||||||
|
|
||||||
export const INHERIT_KEYS = {
|
export const INHERIT_KEYS = {
|
||||||
optional: ["typeAnnotation", "typeParameters", "returnType"],
|
optional: ["typeAnnotation", "typeParameters", "returnType"],
|
||||||
force: ["_scopeInfo", "_paths", "start", "loc", "end"]
|
force: ["start", "loc", "end"]
|
||||||
};
|
};
|
||||||
|
|
||||||
export const BOOLEAN_NUMBER_BINARY_OPERATORS = [">", "<", ">=", "<="];
|
export const BOOLEAN_NUMBER_BINARY_OPERATORS = [">", "<", ">=", "<="];
|
||||||
@ -384,12 +384,25 @@ function _inheritComments(key, child, parent) {
|
|||||||
export function inherits(child: Object, parent: Object): Object {
|
export function inherits(child: Object, parent: Object): Object {
|
||||||
if (!child || !parent) return child;
|
if (!child || !parent) return child;
|
||||||
|
|
||||||
|
// optionally inherit specific properties if not null
|
||||||
for (let key of (t.INHERIT_KEYS.optional: Array<string>)) {
|
for (let key of (t.INHERIT_KEYS.optional: Array<string>)) {
|
||||||
if (child[key] == null) {
|
if (child[key] == null) {
|
||||||
child[key] = parent[key];
|
child[key] = parent[key];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// force inherit symbols
|
||||||
|
let parentSymbols: Array<Symbol> = Object.getOwnPropertyNames(parent);
|
||||||
|
for (let sym of parentSymbols) {
|
||||||
|
child[sym] = parent[sym];
|
||||||
|
}
|
||||||
|
|
||||||
|
// force inherit "private" properties
|
||||||
|
for (let key in parent) {
|
||||||
|
if (key[0] === "_") node[key] = parent[key];
|
||||||
|
}
|
||||||
|
|
||||||
|
// force inherit select properties
|
||||||
for (let key of (t.INHERIT_KEYS.force: Array<string>)) {
|
for (let key of (t.INHERIT_KEYS.force: Array<string>)) {
|
||||||
child[key] = parent[key];
|
child[key] = parent[key];
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user