You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

23 lines
687 B

4 years ago
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Tobias Koppers @sokra
  4. */
  5. "use strict";
  6. const RequireIncludeDependency = require("./RequireIncludeDependency");
  7. module.exports = class RequireIncludeDependencyParserPlugin {
  8. apply(parser) {
  9. parser.hooks.call
  10. .for("require.include")
  11. .tap("RequireIncludeDependencyParserPlugin", expr => {
  12. if (expr.arguments.length !== 1) return;
  13. const param = parser.evaluateExpression(expr.arguments[0]);
  14. if (!param.isString()) return;
  15. const dep = new RequireIncludeDependency(param.string, expr.range);
  16. dep.loc = expr.loc;
  17. parser.state.current.addDependency(dep);
  18. return true;
  19. });
  20. }
  21. };