question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG] Can't handle enums in Routes

See original GitHub issue
Overview of the issue

When using an enum inside routes, I get an error on invoking compodoc:

Unhandled Rejection at: Promise {
  <rejected> { SyntaxError: Expected '}' instead of '.' at line 1 column 121 of the JSON5 data. Still to read: ".\"DOCUMENT\",},{\"canA"
    at error ($PROJECTROOT/node_modules/json5/lib/json5.js:56:25)
    at next ($PROJECTROOT/node_modules/json5/lib/json5.js:72:17)
    at object ($PROJECTROOT/node_modules/json5/lib/json5.js:464:25)
    at value ($PROJECTROOT/node_modules/json5/lib/json5.js:482:20)
    at array ($PROJECTROOT/node_modules/json5/lib/json5.js:417:36)
    at value ($PROJECTROOT/node_modules/json5/lib/json5.js:484:20)
    at Object.parse ($PROJECTROOT/node_modules/json5/lib/json5.js:508:18)
    at loopModulesParser ($PROJECTROOT/node_modules/@compodoc/compodoc/dist/index-cli.js:654:48)
    at RouterParserUtil.constructRoutesTree ($PROJECTROOT/node_modules/@compodoc/compodoc/dist/index-cli.js:692:13)
    at Dependencies.getDependencies ($PROJECTROOT/node_modules/@compodoc/compodoc/dist/index-cli.js:4260:45)
  message: 'Expected \'}\' instead of \'.\' at line 1 column 121 of the JSON5 data. Still to read: ".\\"DOCUMENT\\",},{\\"canA"',
  at: 120,
  lineNumber: 1,
  columnNumber: 121 } } reason: { SyntaxError: Expected '}' instead of '.' at line 1 column 121 of the JSON5 data. Still to read: ".\"DOCUMENT\",},{\"canA"
    at error ($PROJECTROOT/node_modules/json5/lib/json5.js:56:25)
    at next ($PROJECTROOT/node_modules/json5/lib/json5.js:72:17)
    at object ($PROJECTROOT/node_modules/json5/lib/json5.js:464:25)
    at value ($PROJECTROOT/node_modules/json5/lib/json5.js:482:20)
    at array ($PROJECTROOT/node_modules/json5/lib/json5.js:417:36)
    at value ($PROJECTROOT/node_modules/json5/lib/json5.js:484:20)
    at Object.parse ($PROJECTROOT/node_modules/json5/lib/json5.js:508:18)
    at loopModulesParser ($PROJECTROOT/node_modules/@compodoc/compodoc/dist/index-cli.js:654:48)
    at RouterParserUtil.constructRoutesTree ($PROJECTROOT/node_modules/@compodoc/compodoc/dist/index-cli.js:692:13)
    at Dependencies.getDependencies ($PROJECTROOT/node_modules/@compodoc/compodoc/dist/index-cli.js:4260:45)
  message: 'Expected \'}\' instead of \'.\' at line 1 column 121 of the JSON5 data. Still to read: ".\\"DOCUMENT\\",},{\\"canA"',
  at: 120,
  lineNumber: 1,
  columnNumber: 121 }

routes.ts:

import { NgModule } from '@angular/core';
import { PreloadAllModules, RouterModule, Routes } from '@angular/router';

import { EAPP_ROUTES } from './app-routes.enum';
import { AuthGuard } from './modules/+auth/auth.guard';
import { ErrorPageNotFoundComponent } from './modules/error/components/page-not-found/error-page-not-found.component';

const appRoutes: Routes = [
  {
    canActivate: [ AuthGuard ],
    loadChildren: 'app/modules/+document/document.module#DocumentModule',
    path: EAPP_ROUTES.DOCUMENT,
  }, {
    canActivate: [ AuthGuard ],
    loadChildren: 'app/modules/+profile/profile.module#ProfileModule',
    path: EAPP_ROUTES.PROFILE,
  }, {
    loadChildren: 'app/modules/+auth/auth.module#AuthModule',
    path: EAPP_ROUTES.AUTH,
  }, {
    path: '',
    pathMatch: 'full',
    redirectTo: EAPP_ROUTES.DOCUMENT,
  }, {
    component: ErrorPageNotFoundComponent,
    path: '**',
  },
];

@NgModule({
  exports: [
    RouterModule,
  ],
  imports: [
    RouterModule.forRoot(appRoutes, { useHash: true, preloadingStrategy: PreloadAllModules }),
  ],
  providers: [
    AuthGuard,
  ],
})
export class AppRoutingModule {}

tsconfig.json:

{
  "compileOnSave": false,
  "compilerOptions": {
    "outDir": "./dist/out-tsc",
    "sourceMap": true,
    "declaration": false,
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "es5",
    "typeRoots": [
      "node_modules/@types"
    ],
    "types": [
      "hammerjs",
      "jasmine",
      "node",
      "source-map",
      "uglify-js",
      "webpack"
    ],
    "lib": [
      "es2017",
      "dom"
    ]
  },
  "exclude": [
    "bin",
    "compiled",
    "dist",
    "dll",
    "node_modules",
    "src/generated/**/*"
  ]
}

npm run-script: "docs": "compodoc -p ./tsconfig.json -d docs/typedoc",

Operating System, Node.js, npm, compodoc version(s)
  • OS: Ubuntu Linux 16.04.3 64Bit, Linux Kernel 4.4.0
  • Node: v8.1.4
  • npm: v5.0.3
  • compodoc: v1.0.4
Angular configuration, a package.json file in the root folder

For compliance reasons I am not allowed to share the package.json in full. Here are the dependencies, though:

  "dependencies": {
    "@angular/animations": "5.0.2",
    "@angular/cdk": "5.0.0-rc0",
    "@angular/common": "5.0.2",
    "@angular/compiler": "5.0.2",
    "@angular/core": "5.0.2",
    "@angular/forms": "5.0.2",
    "@angular/http": "5.0.2",
    "@angular/platform-browser": "5.0.2",
    "@angular/platform-browser-dynamic": "5.0.2",
    "@angular/router": "5.0.2",
    "@ngx-translate/core": "8.0.0",
    "@ngx-translate/http-loader": "2.0.0",
    "core-js": "2.5.1",
    "deepequal": "0.0.1",
    "htmlhint": "0.9.13",
    "rxjs": "5.5.2",
    "stylelint": "8.2.0",
    "typescript": "2.4.2",
    "validate-commit-msg": "2.14.0",
    "zone.js": "0.8.18"
  },
  "devDependencies": {
    "@angular-redux/store": "6.5.7",
    "@angular/cli": "1.5.2",
    "@angular/compiler-cli": "5.0.2",
    "@angular/language-service": "5.0.2",
    "@compodoc/compodoc": "1.0.4",
    "@types/hammerjs": "2.0.35",
    "@types/jasmine": "2.8.2",
    "@types/jasminewd2": "2.0.3",
    "@types/node": "8.0.53",
    "@types/redux-devtools": "3.0.42",
    "@types/redux-storage": "4.0.10",
    "@types/webpack": "3.8.1",
    "codelyzer": "4.0.1",
    "date-fns": "1.29.0",
    "htmlhint": "0.9.13",
    "husky": "0.14.3",
    "ineeda": "0.11.0",
    "jasmine-core": "2.8.0",
    "jasmine-spec-reporter": "4.2.1",
    "js-yaml": "3.10.0",
    "karma": "1.7.1",
    "karma-chrome-launcher": "2.2.0",
    "karma-cli": "1.0.1",
    "karma-coverage-istanbul-reporter": "1.3.0",
    "karma-jasmine": "1.1.0",
    "karma-mocha-reporter": "2.2.5",
    "ng-swagger-gen": "0.9.0",
    "protractor": "5.2.0",
    "puppeteer": "0.13.0",
    "redux": "3.7.2",
    "redux-devtools-extension": "2.13.2",
    "redux-logger": "3.0.6",
    "redux-storage": "4.1.2",
    "redux-storage-engine-localstorage": "1.1.4",
    "rimraf": "2.6.2",
    "stylelint": "8.2.0",
    "stylelint-checkstyle-formatter": "0.1.0",
    "swagger-js-codegen": "1.12.0",
    "ts-keycode-enum": "1.0.4",
    "ts-node": "3.3.0",
    "tslint": "5.8.0",
    "tslint-jasmine-rules": "1.3.0",
    "typescript": "2.6.1",
    "validate-commit-msg": "2.14.0",
    "yamljs": "0.3.0"
  },
  "engines": {
    "node": ">= 8",
    "npm": ">= 5"
  }
Compodoc installed globally or locally ?

Compodoc is of course installed locally.

Motivation for or Use Case

Would be handy to use enums, because this saves us from writing the same paths in multiple places. When I turn it into a const object, it still fails.

Reproduce the error

What do you expect here? A gist? I would need some time to compile one.

Related issues

Similiar issue reported in #361.

Suggest a Fix

When I dump the text in https://github.com/json5/json5/blob/v0.5.1/lib/json5.js#L503 I see

{"canActivate":["AuthGuard"],"loadChildren":"app/modules/+document/document.module#DocumentModule","path":"EAPP_ROUTES"."DOCUMENT",/*snip*/}

So the enum is broken up in two strings. The dot is breaking, because the JSON is invalid.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
vogloblinskycommented, Jan 14, 2018

@attilacsanyi Ok duplicate of #400 I also add this one in the routing project issues tracking : https://github.com/compodoc/compodoc/projects/3

1reaction
vogloblinskycommented, Nov 29, 2017

Bug fixed for dynamic path and pathMatch for route definition. (https://github.com/compodoc/compodoc/commit/633ea2f834d26ed5d1edf638969a272e002b7691) Need to work on other parts of route description : angular.io/api/router/Routes#description It will come in next release very soon, hope this week.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Problem with implicit Enum Binding on route in laravel
I think you are confusing what enums in the route can bring. It is not about what is already saved, but more to...
Read more >
Is there a cleaner way of doing this? (Vue Router + TS) - Reddit
I always use enums for routenames in projects just to avoid writing error prone strings everywhere that I have to update in the...
Read more >
Defining an Enum - The Rust Programming Language - MIT
Let's look at a situation we might want to express in code and see why enums are useful and more appropriate than structs...
Read more >
Enum with negative member fail
I have a strange error with code that has worked with previous C18 ... when other simple code is substituted, it takes the...
Read more >
Why I don't love Swift Enums any more | by Robert j Chatfield
So what's the big deal? Benefit 1: Expression Problem == .solved. Now look at how easy it is to add a case: struct...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found