validateOutputAst.js 553 B

123456789101112131415161718192021
  1. /**
  2. * Copyright (c) 2013-present, Facebook, Inc.
  3. *
  4. * This source code is licensed under the MIT license found in the
  5. * LICENSE file in the root directory of this source tree.
  6. */
  7. 'use strict';
  8. const t = require('@babel/types');
  9. module.exports = function validateOutputAst(ast) {
  10. const seenNodes = new Set();
  11. t.traverseFast(ast, function enter(node) {
  12. if (seenNodes.has(node)) {
  13. throw new Error('Found a duplicate node in the output, which can cause'
  14. + ' undefined behavior in Babel.');
  15. }
  16. seenNodes.add(node);
  17. })
  18. }