_drop-extra-top-level-nodes.js 265 B

12345678910111213141516
  1. module.exports = ast => {
  2. ast.directives = [];
  3. if (ast.type === 'Module') {
  4. if (ast.items.length > 1) {
  5. ast.items.length = 1;
  6. }
  7. } else if (ast.type === 'Script') {
  8. if (ast.statements.length > 1) {
  9. ast.statements.length = 1;
  10. }
  11. }
  12. return ast;
  13. };