@syntest/analysis-javascript
Version:
SynTest CFG JavaScript is a library for generating control flow graphs for the JavaScript language
55 lines • 2.47 kB
JavaScript
;
/*
* Copyright 2020-2023 Delft University of Technology and SynTest contributors
*
* This file is part of SynTest Framework - SynTest Javascript.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.ExportVisitor = void 0;
const ast_visitor_javascript_1 = require("@syntest/ast-visitor-javascript");
const ExportDefaultDeclaration_1 = require("./ExportDefaultDeclaration");
const ExportNamedDeclaration_1 = require("./ExportNamedDeclaration");
const ExpressionStatement_1 = require("./ExpressionStatement");
class ExportVisitor extends ast_visitor_javascript_1.AbstractSyntaxTreeVisitor {
constructor(filePath, syntaxForgiving) {
super(filePath, syntaxForgiving);
// e.g. export { foo, bar }
this.ExportNamedDeclaration = (path) => {
if (path.node.source) {
// this means that the export comes from another module
// we skip this because we already cover those through the original exporting module
return;
}
this._exports.push(...(0, ExportNamedDeclaration_1.extractExportsFromExportNamedDeclaration)(this, this.filePath, path));
};
// e.g. export default foo
this.ExportDefaultDeclaration = (path) => {
this._exports.push(...(0, ExportDefaultDeclaration_1.extractExportsFromExportDefaultDeclaration)(this, this.filePath, path));
};
// e.g. module.exports = ...
// e.g. exports.foo = ...
this.AssignmentExpression = (path) => {
const exports = (0, ExpressionStatement_1.extractExportsFromAssignmentExpression)(this, this.filePath, path);
this._exports.push(...exports);
};
this._exports = [];
}
// getters
get exports() {
return this._exports;
}
}
exports.ExportVisitor = ExportVisitor;
//# sourceMappingURL=ExportVisitor.js.map