1 | /**
|
2 | * @fileoverview Import globals from head.js and from any files that were
|
3 | * imported by head.js (as far as we can correctly resolve the path).
|
4 | *
|
5 | * This Source Code Form is subject to the terms of the Mozilla Public
|
6 | * License, v. 2.0. If a copy of the MPL was not distributed with this
|
7 | * file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
8 | */
|
9 |
|
10 | ;
|
11 |
|
12 | // -----------------------------------------------------------------------------
|
13 | // Rule Definition
|
14 | // -----------------------------------------------------------------------------
|
15 |
|
16 | var fs = require("fs");
|
17 | var helpers = require("../helpers");
|
18 | var globals = require("../globals");
|
19 |
|
20 | module.exports = function(context) {
|
21 |
|
22 | function importHead(path, node) {
|
23 | try {
|
24 | let stats = fs.statSync(path);
|
25 | if (!stats.isFile()) {
|
26 | return;
|
27 | }
|
28 | } catch (e) {
|
29 | return;
|
30 | }
|
31 |
|
32 | let newGlobals = globals.getGlobalsForFile(path);
|
33 | helpers.addGlobals(newGlobals, context.getScope());
|
34 | }
|
35 |
|
36 | // ---------------------------------------------------------------------------
|
37 | // Public
|
38 | // ---------------------------------------------------------------------------
|
39 |
|
40 | return {
|
41 | Program(node) {
|
42 | let heads = helpers.getTestHeadFiles(context);
|
43 | for (let head of heads) {
|
44 | importHead(head, node);
|
45 | }
|
46 | }
|
47 | };
|
48 | };
|