add optional context parameter to NodePath#get
This commit is contained in:
parent
848909620c
commit
4c0b8599f1
@ -39,7 +39,7 @@ export function getOpposite() {
|
|||||||
* Description
|
* Description
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export function getCompletionRecords(): Array<NodePath> {
|
export function getCompletionRecords(): Array {
|
||||||
var paths = [];
|
var paths = [];
|
||||||
|
|
||||||
var add = function (path) {
|
var add = function (path) {
|
||||||
@ -80,12 +80,13 @@ export function getSibling(key) {
|
|||||||
* Description
|
* Description
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export function get(key: string): NodePath {
|
export function get(key: string, context?: boolean | TraversalContext): NodePath {
|
||||||
|
if (context === true) context = this.context;
|
||||||
var parts = key.split(".");
|
var parts = key.split(".");
|
||||||
if (parts.length === 1) { // "foo"
|
if (parts.length === 1) { // "foo"
|
||||||
return this._getKey(key);
|
return this._getKey(key, context);
|
||||||
} else { // "foo.bar"
|
} else { // "foo.bar"
|
||||||
return this._getPattern(parts);
|
return this._getPattern(parts, context);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -93,7 +94,7 @@ export function get(key: string): NodePath {
|
|||||||
* Description
|
* Description
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export function _getKey(key) {
|
export function _getKey(key, context?) {
|
||||||
var node = this.node;
|
var node = this.node;
|
||||||
var container = node[key];
|
var container = node[key];
|
||||||
|
|
||||||
@ -106,7 +107,7 @@ export function _getKey(key) {
|
|||||||
parent: node,
|
parent: node,
|
||||||
container: container,
|
container: container,
|
||||||
key: i
|
key: i
|
||||||
}).setContext();
|
}).setContext(context);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
return NodePath.get({
|
return NodePath.get({
|
||||||
@ -114,7 +115,7 @@ export function _getKey(key) {
|
|||||||
parent: node,
|
parent: node,
|
||||||
container: node,
|
container: node,
|
||||||
key: key
|
key: key
|
||||||
}).setContext();
|
}).setContext(context);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -122,7 +123,7 @@ export function _getKey(key) {
|
|||||||
* Description
|
* Description
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export function _getPattern(parts) {
|
export function _getPattern(parts, context) {
|
||||||
var path = this;
|
var path = this;
|
||||||
for (var part of (parts: Array)) {
|
for (var part of (parts: Array)) {
|
||||||
if (part === ".") {
|
if (part === ".") {
|
||||||
@ -131,7 +132,7 @@ export function _getPattern(parts) {
|
|||||||
if (Array.isArray(path)) {
|
if (Array.isArray(path)) {
|
||||||
path = path[part];
|
path = path[part];
|
||||||
} else {
|
} else {
|
||||||
path = path.get(part);
|
path = path.get(part, context);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user