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

Question : Is typescript compiler can compile javascript files instead typescript files? #14536

Closed
ifle opened this issue Mar 8, 2017 · 17 comments
Labels
Question An issue which isn't directly actionable in code

Comments

@ifle
Copy link

ifle commented Mar 8, 2017

Will be nice if typescript compiler can compile javascript code instead typescript.
We would like to start to use the async\await syntax only with ES5 target and use as input the js files.

@aluanhaddad
Copy link
Contributor

aluanhaddad commented Mar 8, 2017

It can. Have you tried --allowJs?

You will want to set --outDir otherwise it will fail with Error: would overwrite input file.

@RyanCavanaugh RyanCavanaugh added the Question An issue which isn't directly actionable in code label Mar 8, 2017
@ifle
Copy link
Author

ifle commented Mar 8, 2017

I tried allowJs flag, but it does not work in Visual Studio

@mhegazy
Copy link
Contributor

mhegazy commented Mar 9, 2017

I tried allowJs flag, but it does not work in Visual Studio

what do you mean by does not work? how are you calling the compiler?

@ifle
Copy link
Author

ifle commented Mar 9, 2017

I rechecked again. The allowJs flag does not works in saving a file in VS2015 Update3
I have following tsconfig

{
  "compileOnSave": true,
  "compilerOptions": {
    "noImplicitAny": false,
    "noEmitOnError": false,
    "removeComments": false,
    "sourceMap": true,
    "listEmittedFiles": true,
    "target": "es5",
	  "lib": [
              "dom",
              "es5",            
              "es2015.promise"
          ],
      "outDir": "./html/js",
      "allowJs": true
  },
  "include": [
        "./html/ts/*"
    ],
  "exclude": [
    "node_modules",
    "wwwroot"
  ]
}

@mhegazy
Copy link
Contributor

mhegazy commented Mar 9, 2017

Compile-on-save will not work for .js files in VS 2015; this should be supported in VS 2017 now.

Build should generate the files in both versions.

@ifle
Copy link
Author

ifle commented Mar 9, 2017

You are right. Build work, compile on save does not work. Is there any plans to fix this issue?

@mhegazy
Copy link
Contributor

mhegazy commented Mar 9, 2017

The fix requires some major rearchitecture of both the JS and TS language services in VS; something that we already have done in VS 2017, and have no plans to back-port to VS 2015 at the time being.

@ifle
Copy link
Author

ifle commented Mar 9, 2017

Thanks for your answer.

@styfle
Copy link
Contributor

styfle commented Mar 22, 2017

@mhegazy Is this enabled by default in VS 2017? I noticed a bunch of javascript files generated a corresponding .map.js and their formatting was changed a bit after compiling and existing VS 2015 project.

@mhegazy
Copy link
Contributor

mhegazy commented Mar 22, 2017

if your project has both --allowJs: true and compileOnSave enabled, then yes. the output should be the same though, if it is different then there is a miss configuration/compiler bug somewhere. If you can share more details we can investigate more.

@styfle
Copy link
Contributor

styfle commented Mar 22, 2017

I am not using the tsconfig.json or setting any command line flags myself. The property group looks like the following:

<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Build|AnyCPU'">
    <DebugSymbols>true</DebugSymbols>
    <OutputPath>bin\</OutputPath>
    <DefineConstants>TRACE</DefineConstants>
    <DebugType>full</DebugType>
    <PlatformTarget>AnyCPU</PlatformTarget>
    <ErrorReport>prompt</ErrorReport>
    <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
    <TypeScriptTarget>ES5</TypeScriptTarget>
    <TypeScriptJSXEmit>React</TypeScriptJSXEmit>
    <TypeScriptCompileOnSaveEnabled>True</TypeScriptCompileOnSaveEnabled>
    <TypeScriptNoImplicitAny>True</TypeScriptNoImplicitAny>
    <TypeScriptModuleKind>CommonJS</TypeScriptModuleKind>
    <TypeScriptRemoveComments>False</TypeScriptRemoveComments>
    <TypeScriptOutFile />
    <TypeScriptOutDir />
    <TypeScriptGeneratesDeclarations>False</TypeScriptGeneratesDeclarations>
    <TypeScriptNoEmitOnError>True</TypeScriptNoEmitOnError>
    <TypeScriptSourceMap>True</TypeScriptSourceMap>
    <TypeScriptMapRoot />
    <TypeScriptSourceRoot />
  </PropertyGroup>

I believe it might be related to #14565 but the other reason might be if the default is now true in VS 2017 when it was false in VS 2015 (TS 1.8).

@mhegazy
Copy link
Contributor

mhegazy commented Mar 22, 2017

@styfle can you elaborate on the details of the issues you are seeing? you have .js files in your project, when you save them, you see output generated for them in your bin\ dir, and no tsconfig.json? is this accurate?

@billti
Copy link
Member

billti commented Mar 23, 2017

<TypeScriptOutDir /> is empty above, so its likely not compiling as the output would overwrite the input. Can you specify a location to put the compiled files and see if that works?

@styfle
Copy link
Contributor

styfle commented Mar 23, 2017

I am not using a bin folder. The .js file gets generated next to the .ts file.

Steps to reproduce

I opened an existing 2015 project in VS 2017, edited a .d.ts file, saved, and VS started compiling a lot of files....files that do not have a .ts associated with them 😨

image

Then I looked at git changes in Team Explorer tab and I can see that a bunch of .js files were modified and a bunch of .js.map files were added.

image

@billti
Copy link
Member

billti commented Mar 23, 2017

@styfle VS should not be compiling those files on save. I'll try and repro the issue you are seeing, but in case I am unable to, if you have a repro project you can share that would be helpful. Thanks.

@billti
Copy link
Member

billti commented Mar 23, 2017

@styfle I just tried this with your project settings and didn't see the issue. A couple requests:

  1. Could you switch on Virtual Projects (Tools / Options / Text Editor / JavaScript/TypeScript / Project / Display Virtual Projects when a solution is loaded).
  2. Open a .js or .ts file in the affected project (so the language service loads the project) and get a screen shot of the virtual projects in Solution Explorer. (You should have one containing your .ts files, and another named "<ProjectName> JavaScript Content Files").
  3. Please open another issue for this problem and mention me so I see it (as this issue is for wanting to compile JavaScript files).

Thanks.

@mhegazy mhegazy closed this as completed Apr 21, 2017
@styfle
Copy link
Contributor

styfle commented Apr 21, 2017

For reference, I opened #14827

@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Question An issue which isn't directly actionable in code
Projects
None yet
Development

No branches or pull requests

6 participants