.gitignore added
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / parent-module / index.js
1 'use strict';
2 const callsites = require('callsites');
3
4 module.exports = filepath => {
5         const stacks = callsites();
6
7         if (!filepath) {
8                 return stacks[2].getFileName();
9         }
10
11         let seenVal = false;
12
13         // Skip the first stack as it's this function
14         stacks.shift();
15
16         for (const stack of stacks) {
17                 const parentFilepath = stack.getFileName();
18
19                 if (typeof parentFilepath !== 'string') {
20                         continue;
21                 }
22
23                 if (parentFilepath === filepath) {
24                         seenVal = true;
25                         continue;
26                 }
27
28                 // Skip native modules
29                 if (parentFilepath === 'module.js') {
30                         continue;
31                 }
32
33                 if (seenVal && parentFilepath !== filepath) {
34                         return parentFilepath;
35                 }
36         }
37 };