1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 | var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
16 | return new (P || (P = Promise))(function (resolve, reject) {
|
17 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
18 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
19 | function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
20 | step((generator = generator.apply(thisArg, _arguments || [])).next());
|
21 | });
|
22 | };
|
23 | Object.defineProperty(exports, "__esModule", { value: true });
|
24 | const babel = require("@babel/types");
|
25 | const esutil = require("./esutil");
|
26 | const exportKinds = new Set(['export']);
|
27 | class Export {
|
28 | constructor(astNode, statementAst, sourceRange, nodePath, exportingAllFrom) {
|
29 | this.kinds = exportKinds;
|
30 | this.identifiers = new Set();
|
31 | this.warnings = [];
|
32 | this.astNode = astNode;
|
33 | this.statementAst = statementAst;
|
34 | let exportedIdentifiers;
|
35 | if (exportingAllFrom !== undefined) {
|
36 | exportedIdentifiers = flatMap(exportingAllFrom, (export_) => [...export_.identifiers].filter((i) => i !== 'default'));
|
37 | }
|
38 | else {
|
39 | exportedIdentifiers = esutil.getBindingNamesFromDeclaration(astNode.node);
|
40 | }
|
41 | for (const name of exportedIdentifiers) {
|
42 | this.identifiers.add(name);
|
43 | }
|
44 | this.astNodePath = nodePath;
|
45 | this.sourceRange = sourceRange;
|
46 | }
|
47 |
|
48 |
|
49 |
|
50 | resolve(document) {
|
51 | if (babel.isExportAllDeclaration(this.astNode.node)) {
|
52 | const [import_] = document.getFeatures({ kind: 'import', statement: this.statementAst });
|
53 | if (import_ === undefined || import_.document === undefined) {
|
54 |
|
55 | return undefined;
|
56 | }
|
57 | return new Export(this.astNode, this.statementAst, this.sourceRange, this.astNodePath, import_.document.getFeatures({ kind: 'export' }));
|
58 | }
|
59 |
|
60 |
|
61 |
|
62 | return this;
|
63 | }
|
64 | }
|
65 | exports.Export = Export;
|
66 | function* flatMap(inputs, map) {
|
67 | for (const input of inputs) {
|
68 | yield* map(input);
|
69 | }
|
70 | }
|
71 | class JavaScriptExportScanner {
|
72 | scan(document, visit) {
|
73 | return __awaiter(this, void 0, void 0, function* () {
|
74 | const exports = [];
|
75 | const warnings = [];
|
76 | yield visit({
|
77 | enterExportNamedDeclaration(node, _parent, path) {
|
78 | exports.push(new Export({ language: 'js', containingDocument: document, node }, esutil.getCanonicalStatement(path), document.sourceRangeForNode(node), path));
|
79 | },
|
80 | enterExportAllDeclaration(node, _parent, path) {
|
81 | exports.push(new Export({ language: 'js', containingDocument: document, node }, esutil.getCanonicalStatement(path), document.sourceRangeForNode(node), path));
|
82 | },
|
83 | enterExportDefaultDeclaration(node, _parent, path) {
|
84 | exports.push(new Export({ language: 'js', containingDocument: document, node }, esutil.getCanonicalStatement(path), document.sourceRangeForNode(node), path));
|
85 | }
|
86 | });
|
87 | return { features: exports, warnings };
|
88 | });
|
89 | }
|
90 | }
|
91 | exports.JavaScriptExportScanner = JavaScriptExportScanner;
|
92 |
|
\ | No newline at end of file |