4

I am trying to start documenting my Ionic 2 app using JSDoc but I am having difficulty using it with Angular 2's syntax.

For example, I have the following code at the top of my app:

import {App, Events, IonicApp, Platform} from 'ionic-framework/ionic';
import {UserData} from './providers/user-data';

@App({
  templateUrl: 'build/app.html',
  providers: [UserData],
  config: {

  }
})

When trying to parse this file, JSDoc gives this error because of @App:

ERROR: Unable to parse /home/user/Projects/mobileApp/app/app.js: Line 4: Unexpected token ILLEGAL

Also, my constructors look like this (I used Ionic 2's tutorial template):

class MyApp {
  constructor(app: IonicApp, platform: Platform, events: Events, userData: UserData) {

  }
}

And this produces the error:

ERROR: Unable to parse /home/user/Projects/mobileApp/app/app.js: Line 27: Unexpected token :

Could someone please tell me how to get around these errors?

Thanks for any help.

Daniel Hutton
  • 1,455
  • 1
  • 17
  • 33

2 Answers2

5

Angular2 uses TypeScript that is augmented on ES6 but is not actually a JavaScript, so that why JSDoc doesn't understand it. Try using typedoc at: http://typedoc.org/

saschwarz
  • 1,123
  • 2
  • 13
  • 26
Rytis Alekna
  • 1,387
  • 7
  • 17
  • Thank you, I'll check it out. I am using the Javascript version of Ionic2 & Angular2 and not typescript, does it still apply? – Daniel Hutton Mar 31 '16 at 09:16
  • In your given examples you're using TypeScript (type annotations, decorators). Of course, your application during runtime (or deployment) is transpiled into raw JavaScript (no browser directly supports TypeScript). There is some more explanation about differences of TypeScript and JavaScript http://stackoverflow.com/questions/12694530/what-is-typescript-and-why-would-i-use-it-in-place-of-javascript – Rytis Alekna Mar 31 '16 at 12:42
  • TypeDoc works really well, thanks for the tip. Giving the typescript version of Ionic a go too, seems to be becoming more popular so may as well learn it. – Daniel Hutton Mar 31 '16 at 15:25
0

ES7 JS code should be transpiled to ES5 (via Babel) or ES6 (via TypeScript, with .js files renamed to .ts) before it will be fed to JSDoc.

Documentation building process may be independent of app bundling process.

Estus Flask
  • 206,104
  • 70
  • 425
  • 565