PageSourceSearch

https://farese.com/node_modules/@babel/core/lib/transformation/file/file.js

js farese.com collected 2026-09-25 15:19:33 UTC 5,815 bytes, 249 lines download raw bytes

1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4  value: true
5});
6exports.default = void 0;
7
8function helpers() {
9  const data = require("@babel/helpers");
10
11  helpers = function () {
12    return data;
13  };
14
15  return data;
16}
17
18function _traverse() {
19  const data = require("@babel/traverse");
20
21  _traverse = function () {
22    return data;
23  };
24
25  return data;
26}
27
28function _codeFrame() {
29  const data = require("@babel/code-frame");
30
31  _codeFrame = function () {
32    return data;
33  };
34
35  return data;
36}
37
38function t() {
39  const data = require("@babel/types");
40
41  t = function () {
42    return data;
43  };
44
45  return data;
46}
47
48function _helperModuleTransforms() {
49  const data = require("@babel/helper-module-transforms");
50
51  _helperModuleTransforms = function () {
52    return data;
53  };
54
55  return data;
56}
57
58function _semver() {
59  const data = require("semver");
60
61  _semver = function () {
62    return data;
63  };
64
65  return data;
66}
67
68const errorVisitor = {
69  enter(path, state) {
70    const loc = path.node.loc;
71
72    if (loc) {
73      state.loc = loc;
74      path.stop();
75    }
76  }
77
78};
79
80class File {
81  constructor(options, {
82    code,
83    ast,
84    inputMap
85  }) {
86    this._map = new Map();
87    this.opts = void 0;
88    this.declarations = {};
89    this.path = null;
90    this.ast = {};
91    this.scope = void 0;
92    this.metadata = {};
93    this.code = "";
94    this.inputMap = null;
95    this.hub = {
96      file: this,
97      getCode: () => this.code,
98      getScope: () => this.scope,
99      addHelper: this.addHelper.bind(this),
100      buildError: this.buildCodeFrameError.bind(this)
101    };
102    this.opts = options;
103    this.code = code;
104    this.ast = ast;
105    this.inputMap = inputMap;
106    this.path = _traverse().NodePath.get({
107      hub: this.hub,
108      parentPath: null,
109      parent: this.ast,
110      container: this.ast,
111      key: "program"
112    }).setContext();
113    this.scope = this.path.scope;
114  }
115
116  get shebang() {
117    const {
118      interpreter
119    } = this.path.node;
120    return interpreter ? interpreter.value : "";
121  }
122
123  set shebang(value) {
124    if (value) {
125      this.path.get("interpreter").replaceWith(t().interpreterDirective(value));
126    } else {
127      this.path.get("interpreter").remove();
128    }
129  }
130
131  set(key, val) {
132    if (key === "helpersNamespace") {
133      throw new Error("Babel 7.0.0-beta.56 has dropped support for the 'helpersNamespace' utility." + "If you are using @babel/plugin-external-helpers you will need to use a newer " + "version than the one you currently have installed. " + "If you have your own implementation, you'll want to explore using 'helperGenerator' " + "alongside 'file.availableHelper()'.");
134    }
135
136    this._map.set(key, val);
137  }
138
139  get(key) {
140    return this._map.get(key);
141  }
142
143  has(key) {
144    return this._map.has(key);
145  }
146
147  getModuleName() {
148    return (0, _helperModuleTransforms().getModuleName)(this.opts, this.opts);
149  }
150
151  addImport() {
152    throw new Error("This API has been removed. If you're looking for this " + "functionality in Babel 7, you should import the " + "'@babel/helper-module-imports' module and use the functions exposed " + " from that module, such as 'addNamed' or 'addDefault'.");
153  }
154
155  availableHelper(name, versionRange) {
156    let minVersion;
157
158    try {
159      minVersion = helpers().minVersion(name);
160    } catch (err) {
161      if (err.code !== "BABEL_HELPER_UNKNOWN") throw err;
162      return false;
163    }
164
165    if (typeof versionRange !== "string") return true;
166    if (_semver().valid(versionRange)) versionRange = `^${versionRange}`;
167    return !_semver().intersects(`<${minVersion}`, versionRange) && !_semver().intersects(`>=8.0.0`, versionRange);
168  }
169
170  addHelper(name) {
171    const declar = this.declarations[name];
172    if (declar) return t().cloneNode(declar);
173    const generator = this.get("helperGenerator");
174
175    if (generator) {
176      const res = generator(name);
177      if (res) return res;
178    }
179
180    helpers().ensure(name, File);
181    const uid = this.declarations[name] = this.scope.generateUidIdentifier(name);
182    const dependencies = {};
183
184    for (const dep of helpers().getDependencies(name)) {
185      dependencies[dep] = this.addHelper(dep);
186    }
187
188    const {
189      nodes,
190      globals
191    } = helpers().get(name, dep => dependencies[dep], uid, Object.keys(this.scope.getAllBindings()));
192    globals.forEach(name => {
193      if (this.path.scope.hasBinding(name, true)) {
194        this.path.scope.rename(name);
195      }
196    });
197    nodes.forEach(node => {
198      node._compact = true;
199    });
200    this.path.unshiftContainer("body", nodes);
201    this.path.get("body").forEach(path => {
202      if (nodes.indexOf(path.node) === -1) return;
203      if (path.isVariableDeclaration()) this.scope.registerDeclaration(path);
204    });
205    return uid;
206  }
207
208  addTemplateObject() {
209    throw new Error("This function has been moved into the template literal transform itself.");
210  }
211
212  buildCodeFrameError(node, msg, _Error = SyntaxError) {
213    let loc = node && (node.loc || node._loc);
214
215    if (!loc && node) {
216      const state = {
217        loc: null
218      };
219      (0, _traverse().default)(node, errorVisitor, this.scope, state);
220      loc = state.loc;
221      let txt = "This is an error on an internal node. Probably an internal error.";
222      if (loc) txt += " Location has been estimated.";
223      msg += ` (${txt})`;
224    }
225
226    if (loc) {
227      const {
228        highlightCode = true
229      } = this.opts;
230      msg += "\n" + (0, _codeFrame().codeFrameColumns)(this.code, {
231        start: {
232          line: loc.start.line,
233          column: loc.start.column + 1
234        },
235        end: loc.end && loc.start.line === loc.end.line ? {
236          line: loc.end.line,
237          column: loc.end.column + 1
238        } : undefined
239      }, {
240        highlightCode
241      });
242    }
243
244    return new _Error(msg);
245  }
246
247}
248
249exports.default = File;

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.