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

JS beautify break the angular compile #1544

Closed
1011178l opened this issue Sep 10, 2018 · 2 comments
Closed

JS beautify break the angular compile #1544

1011178l opened this issue Sep 10, 2018 · 2 comments

Comments

@1011178l
Copy link

1011178l commented Sep 10, 2018

Description

I use the js-beautify to beauty my angular 6 code generated by angular-cli. However, for a file called 'test.ts', js-beautify will break a statement:

declare const require: any;

into two lines:

declare
const require: any;

which will break the angular compile:

ERROR in src/test.ts(12,1): error TS2304: Cannot find name 'declare'.
src/test.ts(13,7): error TS1155: 'const' declarations must be initialized.

Steps to Reproduce

  1. use angular-cli to create a new project

npm install angular-cli
ng new demo-project

  1. then use the js-beautify to beauty the file demo-project/src/test.ts
    compile the project

npm install
npm start

Then we will get the error message.

Environment

OS: Debian 9, Node 8.11.3 npm 6.3.0, angular 6.1.3

Settings

no settings, all default
run like

js-beautify -r [outputfile]

@1011178l 1011178l changed the title JS beautify broke the angular 6 compile JS beautify broke the angular compile Sep 10, 2018
@1011178l 1011178l changed the title JS beautify broke the angular compile JS beautify break the angular compile Sep 10, 2018
@bitwiseman
Copy link
Member

Yes, the problem is the TypeScript is not JavaScript. In JavaScript const starts on a new line. In this case, in TypeScript, it should not. It would be possible to add a special case for this, but this it has certainly reached a point where we should split out TypeScript into a separate language interpreter.

@bitwiseman
Copy link
Member

In the short term, we can add a special case for declare const, but these kinds of issue will continue to crop up. #1147

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

No branches or pull requests

2 participants