版博士V2.0程序
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

32 lines
580 B

  1. const { Transform } = require('stream')
  2. const constructTree = require('./construct-tree')
  3. class StreamTreeConstructor extends Transform {
  4. constructor (options) {
  5. super(Object.assign(
  6. {},
  7. options,
  8. {
  9. objectMode: true,
  10. readableObjectMode: true
  11. }
  12. ))
  13. this.currentState = undefined
  14. }
  15. _transform (tokensChunk, encoding, callback) {
  16. const { state, ast } = constructTree(
  17. tokensChunk,
  18. this.currentState
  19. )
  20. this.currentState = state
  21. callback(null, ast)
  22. }
  23. }
  24. module.exports = StreamTreeConstructor