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

Parsing doesn't support quoted JSON field names #81

Open
crhairr opened this issue Jan 21, 2018 · 0 comments
Open

Parsing doesn't support quoted JSON field names #81

crhairr opened this issue Jan 21, 2018 · 0 comments

Comments

@crhairr
Copy link

crhairr commented Jan 21, 2018

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant