angular / dgeni-packages

A collection of dgeni packages for generating documentation from source code.
MIT License
142 stars 101 forks source link

typescript package: make getReturnType more robust. #187

Closed davidreher closed 8 years ago

davidreher commented 8 years ago

@petebacondarwin I have a typescript file, where I am reassigning some properties. This causes the current implementation to fail with:

TypeError: Cannot read property 'trim' of undefined
    at getReturnType (C:\...\node_modules\dgeni-packages\typescript\processors\readTypeScriptModules.js:386:55)
    at createMemberDoc (C:\...\node_modules\dgeni-packages\typescript\processors\readTypeScriptModules.js:288:30)
    at C:\...\node_modules\dgeni-packages\typescript\processors\readTypeScriptModules.js:90:31
    at Array.forEach (native)
    at C:\...\node_modules\dgeni-packages\typescript\processors\readTypeScriptModules.js:56:34
    at Array.forEach (native)
    at Object.$process (C:\...\node_modules\dgeni-packages\typescript\processors\readTypeScriptModules.js:47:21)
    at C:\...\node_modules\dgeni\lib\Dgeni.js:202:28
    at _fulfilled (C:\...\node_modules\q\q.js:834:54)
    at self.promiseDispatch.done (C:\...\node_modules\q\q.js:863:30)
    at Promise.promise.promiseDispatch (C:\...\node_modules\q\q.js:796:13)
    at C:\...\node_modules\q\q.js:857:14
    at runSingle (C:\...\node_modules\q\q.js:137:13)
    at flush (C:\...\node_modules\q\q.js:125:13)
    at _combinedTickCallback (internal/process/next_tick.js:67:7)
    at process._tickCallback (internal/process/next_tick.js:98:9)

reason is that declaration.initializer.expression is set, but not declaration.initializer.expression.text.

With this PR we optionally use the typeChecker to get some information about the property and if this fails as well we fall back to the previous else branch.

petebacondarwin commented 8 years ago

Thanks for this @davidreher - can you knock up a unit test for it in dgeni-packages/typescript/processors/readTypeScriptModules.spec.js - then we can merge it

davidreher commented 8 years ago

sure thing

davidreher commented 8 years ago

@petebacondarwin done

petebacondarwin commented 8 years ago

Landed and released as 0.13.1 - thanks

davidreher commented 8 years ago

thanks for the quick response and release :+1: