UNPKG

climb-lookup

Version:

a lookup climbing recursively file like a require.

1,707 lines (1,706 loc) 177 kB
{ "type": "Program", "body": [ { "type": "ImportDeclaration", "specifiers": [ { "type": "ImportDefaultSpecifier", "local": { "type": "Identifier", "name": "fs", "range": [ 40, 42 ], "loc": { "start": { "line": 5, "column": 7 }, "end": { "line": 5, "column": 9 } } }, "range": [ 40, 42 ], "loc": { "start": { "line": 5, "column": 7 }, "end": { "line": 5, "column": 9 } } } ], "source": { "type": "Literal", "value": "fs", "raw": "'fs'", "range": [ 48, 52 ], "loc": { "start": { "line": 5, "column": 15 }, "end": { "line": 5, "column": 19 } } }, "range": [ 33, 53 ], "loc": { "start": { "line": 5, "column": 0 }, "end": { "line": 5, "column": 20 } }, "leadingComments": [ { "type": "Block", "value": "*\n * @module climb-lookup\n ", "range": [ 0, 31 ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 3, "column": 3 } } } ] }, { "type": "ImportDeclaration", "specifiers": [ { "type": "ImportDefaultSpecifier", "local": { "type": "Identifier", "name": "path", "range": [ 61, 65 ], "loc": { "start": { "line": 6, "column": 7 }, "end": { "line": 6, "column": 11 } } }, "range": [ 61, 65 ], "loc": { "start": { "line": 6, "column": 7 }, "end": { "line": 6, "column": 11 } } } ], "source": { "type": "Literal", "value": "path", "raw": "'path'", "range": [ 71, 77 ], "loc": { "start": { "line": 6, "column": 17 }, "end": { "line": 6, "column": 23 } } }, "range": [ 54, 78 ], "loc": { "start": { "line": 6, "column": 0 }, "end": { "line": 6, "column": 24 } } }, { "type": "ImportDeclaration", "specifiers": [ { "type": "ImportDefaultSpecifier", "local": { "type": "Identifier", "name": "objectAssign", "range": [ 86, 98 ], "loc": { "start": { "line": 7, "column": 7 }, "end": { "line": 7, "column": 19 } } }, "range": [ 86, 98 ], "loc": { "start": { "line": 7, "column": 7 }, "end": { "line": 7, "column": 19 } } } ], "source": { "type": "Literal", "value": "object-assign", "raw": "'object-assign'", "range": [ 104, 119 ], "loc": { "start": { "line": 7, "column": 25 }, "end": { "line": 7, "column": 40 } } }, "range": [ 79, 120 ], "loc": { "start": { "line": 7, "column": 0 }, "end": { "line": 7, "column": 41 } }, "trailingComments": [ { "type": "Block", "value": "*\n* Get recursively climbing paths.\n*\n* @function getPaths\n* @param {string} filePath - base path\n* @return {array} paths - an abosolute file paths from filePath to root\n", "range": [ 122, 296 ], "loc": { "start": { "line": 9, "column": 0 }, "end": { "line": 15, "column": 2 } } } ] }, { "type": "ExportNamedDeclaration", "declaration": { "type": "FunctionDeclaration", "id": { "type": "Identifier", "name": "getPaths", "range": [ 313, 321 ], "loc": { "start": { "line": 16, "column": 16 }, "end": { "line": 16, "column": 24 } } }, "params": [ { "type": "Identifier", "name": "filePath", "range": [ 322, 330 ], "loc": { "start": { "line": 16, "column": 25 }, "end": { "line": 16, "column": 33 } } } ], "body": { "type": "BlockStatement", "body": [ { "type": "VariableDeclaration", "declarations": [ { "type": "VariableDeclarator", "id": { "type": "Identifier", "name": "paths", "range": [ 342, 347 ], "loc": { "start": { "line": 17, "column": 8 }, "end": { "line": 17, "column": 13 } } }, "init": { "type": "ArrayExpression", "elements": [], "range": [ 350, 352 ], "loc": { "start": { "line": 17, "column": 16 }, "end": { "line": 17, "column": 18 } } }, "range": [ 342, 352 ], "loc": { "start": { "line": 17, "column": 8 }, "end": { "line": 17, "column": 18 } } } ], "kind": "const", "range": [ 336, 353 ], "loc": { "start": { "line": 17, "column": 2 }, "end": { "line": 17, "column": 19 } } }, { "type": "VariableDeclaration", "declarations": [ { "type": "VariableDeclarator", "id": { "type": "Identifier", "name": "fileName", "range": [ 363, 371 ], "loc": { "start": { "line": 19, "column": 8 }, "end": { "line": 19, "column": 16 } } }, "init": { "type": "CallExpression", "callee": { "type": "MemberExpression", "computed": false, "object": { "type": "Identifier", "name": "path", "range": [ 374, 378 ], "loc": { "start": { "line": 19, "column": 19 }, "end": { "line": 19, "column": 23 } } }, "property": { "type": "Identifier", "name": "basename", "range": [ 379, 387 ], "loc": { "start": { "line": 19, "column": 24 }, "end": { "line": 19, "column": 32 } } }, "range": [ 374, 387 ], "loc": { "start": { "line": 19, "column": 19 }, "end": { "line": 19, "column": 32 } } }, "arguments": [ { "type": "Identifier", "name": "filePath", "range": [ 388, 396 ], "loc": { "start": { "line": 19, "column": 33 }, "end": { "line": 19, "column": 41 } } } ], "range": [ 374, 397 ], "loc": { "start": { "line": 19, "column": 19 }, "end": { "line": 19, "column": 42 } } }, "range": [ 363, 397 ], "loc": { "start": { "line": 19, "column": 8 }, "end": { "line": 19, "column": 42 } } } ], "kind": "const", "range": [ 357, 398 ], "loc": { "start": { "line": 19, "column": 2 }, "end": { "line": 19, "column": 43 } } }, { "type": "VariableDeclaration", "declarations": [ { "type": "VariableDeclarator", "id": { "type": "Identifier", "name": "current", "range": [ 405, 412 ], "loc": { "start": { "line": 20, "column": 6 }, "end": { "line": 20, "column": 13 } } }, "init": { "type": "CallExpression", "callee": { "type": "MemberExpression", "computed": false, "object": { "type": "Identifier", "name": "path", "range": [ 415, 419 ], "loc": { "start": { "line": 20, "column": 16 }, "end": { "line": 20, "column": 20 } } }, "property": { "type": "Identifier", "name": "resolve", "range": [ 420, 427 ], "loc": { "start": { "line": 20, "column": 21 }, "end": { "line": 20, "column": 28 } } }, "range": [ 415, 427 ], "loc": { "start": { "line": 20, "column": 16 }, "end": { "line": 20, "column": 28 } } }, "arguments": [ { "type": "Identifier", "name": "filePath", "range": [ 428, 436 ], "loc": { "start": { "line": 20, "column": 29 }, "end": { "line": 20, "column": 37 } } } ], "range": [ 415, 437 ], "loc": { "start": { "line": 20, "column": 16 }, "end": { "line": 20, "column": 38 } } }, "range": [ 405, 437 ], "loc": { "start": { "line": 20, "column": 6 }, "end": { "line": 20, "column": 38 } } } ], "kind": "let", "range": [ 401, 438 ], "loc": { "start": { "line": 20, "column": 2 }, "end": { "line": 20, "column": 39 } } }, { "type": "WhileStatement", "test": { "type": "BinaryExpression", "operator": ">", "left": { "type": "MemberExpression", "computed": false, "object": { "type": "CallExpression", "callee": { "type": "MemberExpression", "computed": false, "object": { "type": "Identifier", "name": "current", "range": [ 448, 455 ], "loc": { "start": { "line": 21, "column": 9 }, "end": { "line": 21, "column": 16 } } }, "property": { "type": "Identifier", "name": "split", "range": [ 456, 461 ], "loc": { "start": { "line": 21, "column": 17 }, "end": { "line": 21, "column": 22 } } }, "range": [ 448, 461 ], "loc": { "start": { "line": 21, "column": 9 }, "end": { "line": 21, "column": 22 } } }, "arguments": [ { "type": "MemberExpression", "computed": false, "object": { "type": "Identifier", "name": "path", "range": [ 462, 466 ], "loc": { "start": { "line": 21, "column": 23 }, "end": { "line": 21, "column": 27 } } }, "property": { "type": "Identifier", "name": "sep", "range": [ 467, 470 ], "loc": { "start": { "line": 21, "column": 28 }, "end": { "line": 21, "column": 31 } } }, "range": [ 462, 470 ], "loc": { "start": { "line": 21, "column": 23 }, "end": { "line": 21, "column": 31 } } } ], "range": [ 448, 471 ], "loc": { "start": { "line": 21, "column": 9 }, "end": { "line": 21, "column": 32 } } }, "property": { "type": "Identifier", "name": "length", "range": [ 472, 478 ], "loc": { "start": { "line": 21, "column": 33 }, "end": { "line": 21, "column": 39 } } }, "range": [ 448, 478 ], "loc": { "start": { "line": 21, "column": 9 }, "end": { "line": 21, "column": 39 } } }, "right": { "type": "Literal", "value": 2, "raw": "2", "range": [ 481, 482 ], "loc": { "start": { "line": 21, "column": 42 }, "end": { "line": 21, "column": 43 } } }, "range": [ 448, 482 ], "loc": { "start": { "line": 21, "column": 9 }, "end": { "line": 21, "column": 43 } } }, "body": { "type": "BlockStatement", "body": [ { "type": "ExpressionStatement", "expression": { "type": "CallExpression", "callee": { "type": "MemberExpression", "computed": false, "object": { "type": "Identifier", "name": "paths", "range": [ 510, 515 ], "loc": { "start": { "line": 22, "column": 4 }, "end": { "line": 22, "column": 9 } } }, "property": { "type": "Identifier", "name": "push", "range": [ 516, 520 ], "loc": { "start": { "line": 22, "column": 10 }, "end": { "line": 22, "column": 14 } } }, "range": [ 510, 520 ], "loc": { "start": { "line": 22, "column": 4 }, "end": { "line": 22, "column": 14 } } }, "arguments": [ { "type": "Identifier", "name": "current", "range": [ 521, 528 ], "loc": { "start": { "line": 22, "column": 15 }, "end": { "line": 22, "column": 22 } } } ], "range": [ 510, 529 ], "loc": { "start": { "line": 22, "column": 4 }, "end": { "line": 22, "column": 23 } } }, "range": [ 510, 530 ], "loc": { "start": { "line": 22, "column": 4 }, "end": { "line": 22, "column": 24 } }, "leadingComments": [ { "type": "Line", "value": " unless `/${file}`", "range": [ 485, 505 ], "loc": { "start": { "line": 21, "column": 46 }, "end": { "line": 21, "column": 66 } } } ] }, { "type": "ExpressionStatement", "expression": { "type": "AssignmentExpression", "operator": "=", "left": { "type": "Identifier", "name": "current", "range": [ 536, 543 ], "loc": { "start": { "line": 24, "column": 4 }, "end": { "line": 24, "column": 11 } } }, "right": { "type": "CallExpression", "callee": { "type": "MemberExpression", "computed": false, "object": { "type": "Identifier", "name": "path", "range": [ 546, 550 ], "loc": { "start": { "line": 24, "column": 14 }, "end": { "line": 24, "column": 18 } } }, "property": { "type": "Identifier", "name": "join", "range": [ 551, 555 ], "loc": { "start": { "line": 24, "column": 19 }, "end": { "line": 24, "column": 23 } } }, "range": [ 546, 555 ], "loc": { "start": { "line": 24, "column": 14 }, "end": { "line": 24, "column": 23 } } }, "arguments": [ { "type": "CallExpression", "callee": { "type": "MemberExpression", "computed": false, "object": { "type": "Identifier", "name": "path", "range": [ 556, 560 ], "loc": { "start": { "line": 24, "column": 24 }, "end": { "line": 24, "column": 28 } } }, "property": { "type": "Identifier", "name": "join", "range": [ 561, 565 ], "loc": { "start": { "line": 24, "column": 29 }, "end": { "line": 24, "column": 33 } } }, "range": [ 556, 565 ], "loc": { "start": { "line": 24, "column": 24 }, "end": { "line": 24, "column": 33 } } }, "arguments": [ { "type": "Identifier", "name": "current", "range": [ 566, 573 ], "loc": { "start": { "line": 24, "column": 34 }, "end": { "line": 24, "column": 41 } } }, { "type": "Literal", "value": "..", "raw": "'..'", "range": [ 575, 579 ], "loc": { "start": { "line": 24, "column": 43 }, "end": { "line": 24, "column": 47 } } }, { "type": "Literal", "value": "..", "raw": "'..'", "range": [ 581, 585 ], "loc": { "start": { "line": 24, "column": 49 }, "end": { "line": 24, "column": 53 } } } ], "range": [ 556, 586 ], "loc": { "start": { "line": 24, "column": 24 }, "end": { "line": 24, "column": 54 } } }, { "type": "Identifier", "name": "fileName", "range": [ 588, 596 ], "loc": { "start": { "line": 24, "column": 56 }, "end": { "line": 24, "column": 64 } } } ], "range": [ 546, 597 ], "loc": { "start": { "line": 24, "column": 14 }, "end": { "line": 24, "column": 65 } } }, "range": [ 536, 597 ], "loc": { "start": { "line": 24, "column": 4 }, "end": { "line": 24, "column": 65 } } }, "range": [ 536, 598 ], "loc": { "start": { "line": 24, "column": 4 }, "end": { "line": 24, "column": 66 } } } ], "range": [ 484, 602 ], "loc": { "start": { "line": 21, "column": 45 }, "end": { "line": 25, "column": 3 } } }, "range": [ 441, 602 ], "loc": { "start": { "line": 21, "column": 2 }, "end": { "line": 25, "column": 3 } } }, { "type": "ExpressionStatement", "expression": { "type": "CallExpression", "callee": { "type": "MemberExpression", "computed": false, "object": { "type": "Identifier", "name": "paths", "range": [ 605, 610 ], "loc": { "start": { "line": 26, "column": 2 }, "end": { "line": 26, "column": 7 } } }, "property": { "type": "Identifier", "name": "push", "range": [ 611, 615 ], "loc": { "start": { "line": 26, "column": 8 }, "end": { "line": 26, "column": 12 } } }, "range": [ 605, 615 ], "loc": { "start": { "line": 26, "column": 2 }, "end": { "line": 26, "column": 12 } } }, "arguments": [ { "type": "Identifier", "name": "current", "range": [ 616, 623 ], "loc": { "start": { "line": 26, "column": 13 }, "end": { "line": 26, "column": 20 } } } ], "range": [ 605, 624 ], "loc": { "start": { "line": 26, "column": 2 }, "end": { "line": 26, "column": 21 } } }, "range": [ 605, 625 ], "loc": { "start": { "line": 26, "column": 2 }, "end": { "line": 26, "column": 22 } } }, { "type": "ReturnStatement", "argument": { "type": "Identifier", "name": "paths", "range": [ 636, 641 ], "loc": { "start": { "line": 28, "column": 9 }, "end": { "line": 28, "column": 14 } } }, "range": [ 629, 642 ], "loc": { "start": { "line": 28, "column": 2 }, "end": { "line": 28, "column": 15 } } } ], "range": [ 332, 644 ], "loc": { "start": { "line": 16, "column": 35 }, "end": { "line": 29, "column": 1 } } }, "generator": false, "expression": false, "range": [ 304, 644 ], "loc": { "start": { "line": 16, "column": 7 }, "end": { "line": 29, "column": 1 } }, "leadingComments": [ { "type": "Block", "value": "*\n* Get recursively climbing paths.\n*\n* @function getPaths\n* @param {string} filePath - base path\n* @return {array} paths - an abosolute file paths from filePath to root\n", "range": [ 122, 296 ], "loc": { "start": { "line": 9, "column": 0 }, "end": { "line": 15, "column": 2 } } } ], "trailingComments": [ { "type": "Block", "value": "*\n* lookup climbing recursively file like a `require`.\n*\n* @function lookup\n* @param {string} file - lookup file name\n* @param {object} [options] -\n* @param {object} [options.cwd=process.cwd()] - begin path\n* @param {object} [options.mode=null] - pass to fs.accessSync as 2nd argument\n* @param {lookedupAbsolutePath} callback -\n", "range": [ 646, 978 ], "loc": { "start": { "line": 31, "column": 0 }, "end": { "line": 40, "column": 2 } } } ] }, "specifiers": [], "source": null, "range": [ 297, 644 ], "loc": { "start": { "line": 16, "column": 0 }, "end": { "line": 29, "column": 1 } }, "leadingComments": [ { "type": "Block", "value": "*\n* Get recursively climbing paths.\n*\n* @function getPaths\n* @param {string} filePath - base path\n* @return {array} paths - an abosolute file paths from filePath to root\n", "range": [ 122, 296 ], "loc": { "start": { "line": 9, "column": 0 }, "end": { "line": 15, "column": 2 } } } ], "trailingComments": [ { "type": "Block", "value": "*\n* lookup climbing recursively file like a `require`.\n*\n* @function lookup\n* @param {string} file - lookup file name\n* @param {object} [options] -\n* @param {object} [options.cwd=process.cwd()] - begin path\n* @param {object} [options.mode=null] - pass to fs.accessSync as 2nd argument\n* @param {lookedupAbsolutePath} callback -\n", "range": [ 646, 978 ], "loc": { "start": { "line": 31, "column": 0 }, "end": { "line": 40, "column": 2 } } } ] }, { "type": "ExportNamedDeclaration", "declaration": { "type": "FunctionDeclaration", "id": { "type": "Identifier", "name": "lookup", "range": [ 995, 1001 ], "loc": { "start": { "line": 41, "column": 16 }, "end": { "line": 41, "column": 22 } } }, "params": [ { "type": "Identifier", "name": "file", "range": [ 1002, 1006 ], "loc": { "start": { "line": 41, "column": 23 }, "end": { "line": 41, "column": 27 } } }, { "type": "RestElement", "argument": { "type": "Identifier", "name": "params", "range": [ 1011, 1017 ], "loc": { "start": { "line": 41, "column": 32 }, "end": { "line": 41, "column": 38 } } }, "range": [ 1008, 1017 ], "loc": { "start": { "line": 41, "column": 29 }, "end": { "line": 41, "column": 38 } } } ], "body": { "type": "BlockStatement", "body": [ { "type": "VariableDeclaration", "declarations": [ { "type": "VariableDeclarator", "id": { "type": "ArrayPattern", "elements": [ { "type": "Identifier", "name": "options", "range": [ 1030, 1037 ], "loc": { "start": { "line": 42, "column": 9 }, "end": { "line": 42, "column": 16 } } }, { "type": "Identifier", "name": "callback", "range": [ 1039, 1047 ], "loc": { "start": { "line": 42, "column": 18 }, "end": { "line": 42, "column": 26 } } }