babel-plugin-transform-remove-dev.js 666 B

123456789101112131415161718192021222324252627282930313233
  1. /**
  2. * Both used by zrender and echarts.
  3. */
  4. module.exports = function ({types, template}, options) {
  5. return {
  6. visitor: {
  7. IfStatement: {
  8. exit(path) {
  9. removeDEV(path);
  10. }
  11. }
  12. }
  13. };
  14. };
  15. module.exports.recheckDEV = function (code) {
  16. let result = code.match(/.if\s*\([^()]*__DEV__/);
  17. if (result
  18. && result[0].indexOf('`if') < 0
  19. && result[0].indexOf('if (typeof __DEV__') < 0
  20. ) {
  21. throw new Error('__DEV__ is not removed.');
  22. }
  23. };
  24. function removeDEV(path) {
  25. if (path.node.test.name === '__DEV__') {
  26. path.remove();
  27. }
  28. }