Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Trailing commas throw error when parsing routes #192

Closed
benjamincharity opened this issue Jun 4, 2017 · 5 comments
Closed

[BUG] Trailing commas throw error when parsing routes #192

benjamincharity opened this issue Jun 4, 2017 · 5 comments

Comments

@benjamincharity
Copy link

Overview of the issue

If there are trailing commas in the routes definition, compodoc throws an error:

Routes parsing error, maybe a trailing comma or an external variable, trying to fix that later after sources scanning.

Operating System, Node.js, npm, compodoc version(s)
OS X 10.12.5
yarn: 0.24.6
npm: 5.0.1
@angular/cli: 1.1.0
node: 8.0.0
os: darwin x64
@angular/animations: 4.1.3
@angular/common: 4.1.3
@angular/compiler: 4.1.3
@angular/core: 4.1.3
@angular/forms: 4.1.3
@angular/http: 4.1.3
@angular/material: 2.0.0-beta.6
@angular/platform-browser: 4.1.3
@angular/platform-browser-dynamic: 4.1.3
@angular/router: 4.1.3
@angular/cli: 1.1.0
@angular/compiler-cli: 4.1.3
@angular/language-service: 4.1.3
Angular configuration, a package.json file in the root folder
{
  "name": "components-test",
  "version": "0.0.0",
  "license": "MIT",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e",
    "compodoc": "./node_modules/.bin/compodoc -p src/tsconfig.app.json --theme stripe --hideGenerator --coverageTest"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "^4.1.3",
    "@angular/common": "^4.0.0",
    "@angular/compiler": "^4.0.0",
    "@angular/core": "^4.0.0",
    "@angular/forms": "^4.0.0",
    "@angular/http": "^4.0.0",
    "@angular/material": "^2.0.0-beta.6",
    "@angular/platform-browser": "^4.0.0",
    "@angular/platform-browser-dynamic": "^4.0.0",
    "@angular/router": "^4.0.0",
    "angular2-ladda": "^1.2.1",
    "core-js": "^2.4.1",
    "ngx-messages": "^0.2.1",
    "rxjs": "^5.1.0",
    "zone.js": "^0.8.4"
  },
  "devDependencies": {
    "@angular/cli": "1.1.0",
    "@angular/compiler-cli": "^4.0.0",
    "@angular/language-service": "^4.0.0",
    "@compodoc/compodoc": "^1.0.0-beta.9",
    "@types/jasmine": "2.5.45",
    "@types/node": "~6.0.60",
    "codelyzer": "~3.0.1",
    "jasmine-core": "~2.6.2",
    "jasmine-spec-reporter": "~4.1.0",
    "karma": "~1.7.0",
    "karma-chrome-launcher": "~2.1.1",
    "karma-cli": "~1.0.1",
    "karma-coverage-istanbul-reporter": "^1.2.1",
    "karma-jasmine": "~1.1.0",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.1.2",
    "sass-material-colors": "^0.0.5",
    "ts-node": "~3.0.4",
    "tslint": "~5.3.2",
    "typescript": "~2.3.3"
  }
}
Compodoc installed globally or locally ?

Globally

Motivation for or Use Case

The project I am working on is using tslint to enforce styles. Part of the styleguide requires trailing commas. Changing the rule and entire repo is not possible at this time, so the only way to solve the error is to disable tslint around each of the routing declarations.

Reproduce the error
  1. Use trailing commas in your route declarations:
const INVENTORY_ROUTES: Routes = [
  {
    path: 'inventory',
    component: InventoryComponent,
  },
];
  1. Run compodoc: ./node_modules/.bin/compodoc -p src/tsconfig.app.json
@maxencefrenette
Copy link

maxencefrenette commented Jun 5, 2017

The issue seems to be fixed in the newest beta. Just install version 1.0.0-beta.9 (or newer) from @compodoc/compodoc and you should be alright.

Edit: I spoke too fast. Not only you are using the latest version, but it still doesn't work in 1.0.0-beta.9. This is most likely due to the usage of a JSON parser to parse the routes in route.parser.ts. I would recommend switching to the json5 parser. It is an unofficial superset of json that allows for trailing commas and comments. This is exactly what we want here.

If a project maintainer is ok with adding a dependency, I would be glad to work on a PR.

@benjamincharity
Copy link
Author

benjamincharity commented Jun 5, 2017

Hmm.. I'm currently on 1.0.0.0-beta.9 and seeing this error.

  • rm -rf node_modules/
  • yarn install

Looking into the actual files downloaded to node_modules shows the correct version:
screen shot 2017-06-05 at 12 20 34 pm

Code causing error

const INVENTORY_ROUTES: Routes = [
  {
    path: 'inventory',
    component: InventoryComponent, // adding this comma throws error
  }, // adding this comma throws error
];

Error

screen shot 2017-06-05 at 12 22 15 pm

@maxencefrenette
Copy link

I was completely wrong, sorry. I edited my comment above.

@vogloblinsky vogloblinsky changed the title Trailing commas throw error when parsing routes [BUG] Trailing commas throw error when parsing routes Jun 8, 2017
@vogloblinsky
Copy link
Contributor

@maxencefrenette
Thanks for JSON5 link. Works fine with route parser.
Bug fixed, coming in next release soon.

@vogloblinsky vogloblinsky added this to the 1.0.0 milestone Jul 2, 2017
@lock
Copy link

lock bot commented Oct 1, 2019

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem. Why locking ? Having issues with the most up-to-date context.

@lock lock bot locked as resolved and limited conversation to collaborators Oct 1, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants