Skip to content

Compilation of Js Files #5471

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

Merged
merged 105 commits into from
Nov 20, 2015
Merged
Show file tree
Hide file tree
Changes from 103 commits
Commits
Show all changes
105 commits
Select commit Hold shift + click to select a range
0a67ac3
Add .js as supported extension
sheetalkamat Sep 9, 2015
74a3f67
Emit the diagnostics for javascript file instead of doing semantic check
sheetalkamat Sep 9, 2015
279018d
Baseline updates
sheetalkamat Sep 9, 2015
e9688dd
Allow the js files to emit output
sheetalkamat Sep 9, 2015
fad0db2
Report error if output file is among the input files
sheetalkamat Sep 10, 2015
d3dfd2a
Add test cases for simple js file compilations
sheetalkamat Sep 10, 2015
1dc3414
Javascript files will emit declarations too so get declaration diagno…
sheetalkamat Sep 10, 2015
63de162
Let harness to name file even when single unit data specified but th…
sheetalkamat Sep 10, 2015
57e17d2
Test cases for different typescript syntax not supported errors durin…
sheetalkamat Sep 10, 2015
7e30827
Test for rest parameters(copied from language service tests)
sheetalkamat Sep 10, 2015
2252354
Verify syntax error in js file are reported
sheetalkamat Sep 10, 2015
3107bbb
Let tsconfig to pick up js files
sheetalkamat Sep 10, 2015
885babc
Merge branch 'master' into tscJsFiles
sheetalkamat Sep 14, 2015
60f295f
Cleanup of options of project runner
sheetalkamat Sep 14, 2015
8da3bd2
Project testcase to run tsconfig file
sheetalkamat Sep 15, 2015
8aeff92
Add tests when same named .ts and .js file exist with tsconfig file s…
sheetalkamat Sep 16, 2015
bc48c7c
Merge branch 'master' into tscJsFiles
sheetalkamat Sep 16, 2015
9daf635
Verify and fix scenario when .js and .ts files with same name are pre…
sheetalkamat Sep 16, 2015
70d3de4
When same named .d.ts and .js files are present and tscconfig contain…
sheetalkamat Sep 16, 2015
0f73c16
When folder contains .d.ts as well as .js of same name and tsconfig d…
sheetalkamat Sep 16, 2015
dbb2772
Tests when the .ts and .js files are mixed in compilation with tsccon…
sheetalkamat Sep 16, 2015
14b6082
Tests when the .ts and .js files are mixed in compilation with tsccon…
sheetalkamat Sep 16, 2015
2860435
Do not emit javascript files
sheetalkamat Sep 16, 2015
68c65cd
Test case when one of the input file is output file name
sheetalkamat Sep 16, 2015
fce9f32
When tsconfig file doesnt contain file names, consume .js files of di…
sheetalkamat Sep 16, 2015
e32c920
Corrected scenario names in the test cases
sheetalkamat Sep 16, 2015
60e15b2
Report error when emitting declarations if the reference is to .js file
sheetalkamat Sep 16, 2015
400b353
Merge branch 'master' into tscJsFiles
sheetalkamat Sep 18, 2015
c30104e
Add option --jsExtensions to handle extensions to treat as javascript
sheetalkamat Sep 21, 2015
1df341b
Merge branch 'master' into tscJsFilesxt
sheetalkamat Sep 21, 2015
7f09c81
Syntax changes if the extensions to treat as javascript change
sheetalkamat Sep 22, 2015
607564f
Parse all the javascript files with JSX grammer
sheetalkamat Sep 22, 2015
e044d3e
Merge branch 'master' into tscJsFiles
sheetalkamat Sep 22, 2015
0fe282e
Update the type assertion errors to jsx syntax error as we are treati…
sheetalkamat Sep 22, 2015
ce652dc
Fixing few code review comments
sheetalkamat Oct 5, 2015
460c597
Changes in harness to emit expected and actual
sheetalkamat Oct 5, 2015
108f856
Remove tsconfig files of failing testcases
sheetalkamat Oct 5, 2015
b3e4f8e
Create new tscconfig files for the failing testcases
sheetalkamat Oct 5, 2015
db9faf6
Temp change to investigate test failure
sheetalkamat Oct 5, 2015
938c533
Remove the failing testcases
sheetalkamat Oct 5, 2015
567d71c
Add new test cases
sheetalkamat Oct 5, 2015
756052a
Removing console logs that were for debugging
sheetalkamat Oct 5, 2015
b580c55
Merge branch 'master' into tscJsFiles
sheetalkamat Oct 5, 2015
17fca98
Fix tslint error
sheetalkamat Oct 6, 2015
242eb8b
Taken feedback into account and simplified the getFileNames logic to …
sheetalkamat Oct 6, 2015
f7b7204
Remove extension for emitting output should remove any of supported e…
sheetalkamat Oct 8, 2015
2d083f7
Use compilation options to get extensions to remove to get module name
sheetalkamat Oct 8, 2015
2c3c321
Merge branch 'master' into tscJsFiles
sheetalkamat Oct 8, 2015
5e14edb
Verify the emit file name is unique and doesnt overwrite input file
sheetalkamat Oct 12, 2015
a87dae1
Verify that when emit blocking error occurs rest of the emit occurs a…
sheetalkamat Oct 12, 2015
6882035
Verify if one or more files are emitting into same output file we pro…
sheetalkamat Oct 12, 2015
f28fbfd
Merge branch 'master' into tscJsFiles
sheetalkamat Oct 12, 2015
286fb3e
Fix the lint error
sheetalkamat Oct 12, 2015
b38a81b
Emit enabled for JS files
sheetalkamat Oct 12, 2015
d4d6e48
Adding test case for scenario in which error reported depends on orde…
sheetalkamat Oct 12, 2015
9f96f47
Added scenario when duplicate function implementation is reported
sheetalkamat Oct 12, 2015
11b270f
Add testcase - generating declaration file results in more errors in …
sheetalkamat Oct 12, 2015
8176354
Fix the duplicate function implementation error that depended on orde…
sheetalkamat Oct 14, 2015
5aa7086
Use ts.indexOf instead of Array.indexOf method
sheetalkamat Oct 15, 2015
1ae1464
Test cases for let declaration and its use order
sheetalkamat Oct 15, 2015
acf7de7
Merge branch 'master' into tscJsFiles
sheetalkamat Oct 15, 2015
0496bfe
Merge branch 'master' into tscJsFiles
sheetalkamat Oct 19, 2015
6804087
Refactoring to fix build issues
sheetalkamat Oct 19, 2015
3215438
Dont emit declaration file if there are errors in the source file
sheetalkamat Oct 20, 2015
d14934e
Tests update for emitting declarations if no errors
sheetalkamat Oct 20, 2015
c26d2da
Do not emit declarations file if we reported error about inaccessible…
sheetalkamat Oct 20, 2015
93cc1e5
Check source map files are being overwritten
sheetalkamat Oct 20, 2015
ff933be
Populate if emit was skipped correctly as part of emit result
sheetalkamat Oct 20, 2015
bf05ea3
Some test cases to verify that declaration file overwrite is reported…
sheetalkamat Oct 20, 2015
8f03d00
Test cases to verify that declaration file is not emitted if any of t…
sheetalkamat Oct 20, 2015
57362f6
Some tests to cover transpilation of different syntax
sheetalkamat Oct 21, 2015
ba3d34f
Instead of --jsExtensions support --allowJs with .js and .jsx as supp…
sheetalkamat Oct 28, 2015
382b86b
Test update for using allowJs instead of --jsExtensions
sheetalkamat Oct 28, 2015
ea57efa
Test baseline update because .map cannot be a valid js file anymore
sheetalkamat Oct 28, 2015
a8eb76f
Remove the logic for parsing compilation of comma seperated list of s…
sheetalkamat Oct 28, 2015
45b995d
Remove extensions doesnt need to depend on compiler options any more
sheetalkamat Oct 28, 2015
2d3a345
Since there arent any user given extensions, have extensions start wi…
sheetalkamat Oct 28, 2015
0c3c7f1
Treat the .jsx and .tsx files as jsx when parsing and .js files are p…
sheetalkamat Oct 28, 2015
fdb7a3e
Revert the change to block declaration emit in case of syntax or sema…
sheetalkamat Oct 28, 2015
38ebb1d
Tests update after declaration file emit revert
sheetalkamat Oct 28, 2015
b217b8b
Merge branch 'master' into jsFileCompilation
sheetalkamat Oct 30, 2015
94a647b
Do not emit declarations for javascript files
sheetalkamat Oct 30, 2015
daba901
Report error if --allowJs option is used along with --declaration
sheetalkamat Oct 30, 2015
6ea74ae
Update the error messages as per PR feedback
sheetalkamat Oct 30, 2015
67bed26
Since js extensions are not user specified, no need to check if sourc…
sheetalkamat Oct 30, 2015
4d3457c
Some refactoring as per PR feedback
sheetalkamat Oct 30, 2015
9f337bc
Merge branch 'master' into jsFileCompilation
sheetalkamat Oct 30, 2015
a0318c7
Create a utility to iterate over each emitFileName and use it in emitter
sheetalkamat Oct 30, 2015
c6d54d6
Simplify verification of emit file paths using utility to iterate ove…
sheetalkamat Oct 30, 2015
06bf08c
Simplify logic to get declaration diagnostis
sheetalkamat Oct 30, 2015
2b582a0
Simplifty declaration emitter logic by using forEachExpectedEmitFile
sheetalkamat Oct 30, 2015
62d4fd6
Take pr feedback into account
sheetalkamat Oct 30, 2015
51caf1a
Use of FileMap instead of Map as per PR feedback
sheetalkamat Oct 30, 2015
def7b66
PR feedback
sheetalkamat Nov 6, 2015
4c84259
Merge branch 'master' into jsFileCompilation
sheetalkamat Nov 6, 2015
d2445b6
PR feedback
sheetalkamat Nov 12, 2015
1ed67f4
Removed the TODO as created bug for it
sheetalkamat Nov 12, 2015
0b21540
Simplified logic of getting files if files werent suppplied in tsccon…
sheetalkamat Nov 12, 2015
3bdad8a
When excluding same base name file from compilation, check for all su…
sheetalkamat Nov 12, 2015
fc07763
Merge branch 'master' into jsFileCompilation
sheetalkamat Nov 13, 2015
0482afd
Load only typescript files if resolving from node modules
sheetalkamat Nov 13, 2015
1ee5022
Change the api for node name resolver to take compiler options instea…
sheetalkamat Nov 16, 2015
073b69a
Merge branch 'master' into jsFileCompilation
sheetalkamat Nov 16, 2015
5ac6eb2
PR feedback
sheetalkamat Nov 18, 2015
a19307d
Merge branch 'master' into jsFileCompilation
sheetalkamat Nov 18, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
10 changes: 0 additions & 10 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
node_modules/
built/*
tests/cases/*.js
tests/cases/*/*.js
tests/cases/*/*/*.js
tests/cases/*/*/*/*.js
tests/cases/*/*/*/*/*.js
tests/cases/*.js.map
tests/cases/*/*.js.map
tests/cases/*/*/*.js.map
tests/cases/*/*/*/*.js.map
tests/cases/*/*/*/*/*.js.map
tests/cases/rwc/*
tests/cases/test262/*
tests/cases/perf/*
Expand Down
7 changes: 6 additions & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11003,6 +11003,7 @@ namespace ts {

const symbol = getSymbolOfNode(node);
const firstDeclaration = getDeclarationOfKind(symbol, node.kind);

// Only type check the symbol once
if (node === firstDeclaration) {
checkFunctionOrConstructorSymbol(symbol);
Expand Down Expand Up @@ -12033,7 +12034,11 @@ namespace ts {
const symbol = getSymbolOfNode(node);
const localSymbol = node.localSymbol || symbol;

const firstDeclaration = getDeclarationOfKind(localSymbol, node.kind);
const firstDeclaration = forEach(symbol.declarations,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you please add a comment

  • why we are not picking the first declaration if it originates in javascript file
  • why we are using symbol instead of localSymbol
    ?

// Get first non javascript function declaration
declaration => declaration.kind === node.kind && !isSourceFileJavaScript(getSourceFile(declaration)) ?
declaration : undefined);

// Only type check the symbol once
if (node === firstDeclaration) {
checkFunctionOrConstructorSymbol(localSymbol);
Expand Down
49 changes: 32 additions & 17 deletions src/compiler/commandLineParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,11 @@ namespace ts {
name: "forceConsistentCasingInFileNames",
type: "boolean",
description: Diagnostics.Disallow_inconsistently_cased_references_to_the_same_file
},
{
name: "allowJs",
type: "boolean",
description: Diagnostics.Allow_javascript_files_to_be_compiled,
}
];

Expand Down Expand Up @@ -474,15 +479,16 @@ namespace ts {
* @param basePath A root directory to resolve relative path entries in the config
* file to. e.g. outDir
*/
export function parseJsonConfigFileContent(json: any, host: ParseConfigHost, basePath: string): ParsedCommandLine {
const { options, errors } = convertCompilerOptionsFromJson(json["compilerOptions"], basePath);
export function parseJsonConfigFileContent(json: any, host: ParseConfigHost, basePath: string, existingOptions: CompilerOptions = {}): ParsedCommandLine {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are we passing the existing options here? previously the caller has to call extend on them, so why is the change in the API?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

plus one to the question

const { options: optionsFromJsonConfigFile, errors } = convertCompilerOptionsFromJson(json["compilerOptions"], basePath);

const options = extend(existingOptions, optionsFromJsonConfigFile);
return {
options,
fileNames: getFileNames(),
errors
};

function getFileNames(): string[] {
let fileNames: string[] = [];
if (hasProperty(json, "files")) {
Expand All @@ -494,23 +500,32 @@ namespace ts {
}
}
else {
const filesSeen: Map<boolean> = {};
const exclude = json["exclude"] instanceof Array ? map(<string[]>json["exclude"], normalizeSlashes) : undefined;
const sysFiles = host.readDirectory(basePath, ".ts", exclude).concat(host.readDirectory(basePath, ".tsx", exclude));
for (let i = 0; i < sysFiles.length; i++) {
const name = sysFiles[i];
if (fileExtensionIs(name, ".d.ts")) {
const baseName = name.substr(0, name.length - ".d.ts".length);
if (!contains(sysFiles, baseName + ".tsx") && !contains(sysFiles, baseName + ".ts")) {
fileNames.push(name);
const supportedExtensions = getSupportedExtensions(options);
Debug.assert(indexOf(supportedExtensions, ".ts") < indexOf(supportedExtensions, ".d.ts"), "Changed priority of extensions to pick");

// Get files of supported extensions in their order of resolution
for (const extension of supportedExtensions) {
const filesInDirWithExtension = host.readDirectory(basePath, extension, exclude);
for (const fileName of filesInDirWithExtension) {
// .ts extension would read the .d.ts extension files too but since .d.ts is lower priority extension,
// lets pick them when its turn comes up
if (extension === ".ts" && fileExtensionIs(fileName, ".d.ts")) {
continue;
}
}
else if (fileExtensionIs(name, ".ts")) {
if (!contains(sysFiles, name + "x")) {
fileNames.push(name);

// If this is one of the output extension (which would be .d.ts and .js if we are allowing compilation of js files)
// do not include this file if we included .ts or .tsx file with same base name as it could be output of the earlier compilation
if (extension === ".d.ts" || (options.allowJs && contains(supportedJavascriptExtensions, extension))) {
const baseName = fileName.substr(0, fileName.length - extension.length);
if (hasProperty(filesSeen, baseName + ".ts") || hasProperty(filesSeen, baseName + ".tsx")) {
continue;
}
}
}
else {
fileNames.push(name);

filesSeen[fileName] = true;
fileNames.push(fileName);
}
}
}
Expand Down
21 changes: 13 additions & 8 deletions src/compiler/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,8 +297,8 @@ namespace ts {
return <T>result;
}

export function extend<T1, T2>(first: Map<T1>, second: Map<T2>): Map<T1 & T2> {
const result: Map<T1 & T2> = {};
export function extend<T1 extends Map<{}>, T2 extends Map<{}>>(first: T1 , second: T2): T1 & T2 {
const result: T1 & T2 = <any>{};
for (const id in first) {
(result as any)[id] = first[id];
}
Expand Down Expand Up @@ -714,7 +714,7 @@ namespace ts {
}

export function getBaseFileName(path: string) {
if (!path) {
if (path === undefined) {
return undefined;
}
const i = path.lastIndexOf(directorySeparator);
Expand All @@ -738,13 +738,18 @@ namespace ts {
/**
* List of supported extensions in order of file resolution precedence.
*/
export const supportedExtensions = [".ts", ".tsx", ".d.ts"];
export const supportedJsExtensions = supportedExtensions.concat(".js", ".jsx");
export const supportedTypeScriptExtensions = [".ts", ".tsx", ".d.ts"];
export const supportedJavascriptExtensions = [".js", ".jsx"];
const allSupportedExtensions = supportedTypeScriptExtensions.concat(supportedJavascriptExtensions);

export function isSupportedSourceFileName(fileName: string) {
export function getSupportedExtensions(options?: CompilerOptions): string[] {
return options && options.allowJs ? allSupportedExtensions : supportedTypeScriptExtensions;
}

export function isSupportedSourceFileName(fileName: string, compilerOptions?: CompilerOptions) {
if (!fileName) { return false; }

for (const extension of supportedExtensions) {
for (const extension of getSupportedExtensions(compilerOptions)) {
if (fileExtensionIs(fileName, extension)) {
return true;
}
Expand Down Expand Up @@ -855,4 +860,4 @@ namespace ts {
}
return copiedList;
}
}
}
Loading