angular2-template-loader
angular2-template-loader copied to clipboard
Parsing doesn't support quoted JSON field names
JSON names are supposed to be double-quoted according to the standard, however angular2-template-loader does not work. The templateUrl and styleUrls fields from the following Component directive aren't recognized:
@Component({
"selector": "my-app",
"styleUrls": [ "./my-app.component.ts.scss" ],
"templateUrl": "./my-app.component.ts.html",
"encapsulation": ViewEncapsulation.None
})
However, after removing the double-quotes from the directive, the loader finds the fields correctly:
@Component({
selector: "my-app",
styleUrls: [ "./my-app.component.ts.scss" ],
templateUrl: "./my-app.component.ts.html",
encapsulation: ViewEncapsulation.None
})
This is technically invalid JSON as the standard requires that object keys be strings (double-quoted tokens). I prefer to use syntactically correct JSON in my code to maximize the interoperability in browsers, and I don't like having to dumb it down just because lazily ignoring the standards is pervasive among web developers.
To fix the problem, you should just have to add a quote-balancing group to your regex.
FWIW: The official ECMA standard for JSON declares that object keys are strings, which it defines as tokens wrapped in quotes.