Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
dfee3de
Add test case for #8229
sheetalkamat Apr 21, 2016
90d347e
Do not report errors during contextual typecheck
sheetalkamat Apr 21, 2016
34f7f2c
Handle the scenario when let [a=undefined]=[]
sheetalkamat Apr 22, 2016
448a480
Don't allow `.ts` to appear in an import
Jul 12, 2016
a8c05a9
Add specific error message for unwanted '.ts' extension
Jul 12, 2016
95e391e
Allow `await` in a simple unary expression
Jul 22, 2016
bc5c7b6
More tests
Jul 22, 2016
275dbc7
Forbid `await await`
Jul 22, 2016
52fd033
Allow `await await`
Jul 25, 2016
2821d98
Merge branch 'master' into no_ts_extension
Aug 2, 2016
0f134ed
Improve error message
Aug 2, 2016
359c8b1
Don't allow ".d.ts" extension in an import either.
Aug 3, 2016
3de8c22
Merge branch 'master' into no_ts_extension
Aug 15, 2016
2eb159e
Rename 'find' functions
Aug 15, 2016
02f908a
Merge branch 'master' into noImplicitAnyDestructuring
sheetalkamat Aug 16, 2016
8fc17af
Move supportedTypescriptExtensionsWithDtsFirst next to supportedTypeS…
Aug 18, 2016
952d2fe
Fix comment
Aug 18, 2016
a621c09
Merge pull request #8241 from Microsoft/noImplicitAnyDestructuring
mhegazy Aug 18, 2016
03dcdda
Treat special property access symbol differently
Aug 19, 2016
297cb50
Merge branch 'master' into no_ts_extension
Aug 19, 2016
b452469
Fix tests
Aug 19, 2016
b482fa5
Merge branch 'master' into cast_of_await
Aug 19, 2016
19cde06
Merge pull request #9890 from Microsoft/cast_of_await
Aug 19, 2016
d2d5d42
Merge pull request #9646 from Microsoft/no_ts_extension
Aug 19, 2016
7f6e36c
Update shim version to be 2.1 (#10424)
yuit Aug 19, 2016
0168ab2
Check return code paths on getters (#10102)
weswigham Aug 19, 2016
da6d951
Remove extraneous arguments from harness's runBaseline (#10419)
weswigham Aug 19, 2016
6c60e5b
Remove needless call to basename
RyanCavanaugh Aug 19, 2016
def29f6
Merge pull request #10439 from RyanCavanaugh/fixJakeBaselineAccept
RyanCavanaugh Aug 19, 2016
8ad2744
Refactor baseliners out of compiler runner (#10440)
weswigham Aug 19, 2016
057357b
CR feedback
Aug 19, 2016
a5bb13f
fix broken tests
Aug 19, 2016
a531b87
Pass in baselineOpts into types baselines so that RWC baselines can b…
yuit Aug 20, 2016
d8ab098
Merge pull request #10426 from zhengbli/9518
zhengbli Aug 20, 2016
5732908
Merge branch 'master' into release-2.0
Aug 20, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Don't allow ".d.ts" extension in an import either.
  • Loading branch information
Andy Hanson committed Aug 3, 2016
commit 359c8b12ef3a8339940edd9203dcb2a10c08615b
8 changes: 4 additions & 4 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1366,10 +1366,10 @@ namespace ts {

if (moduleNotFoundError) {
// report errors only if it was requested
const nonDtsExtension = tryExtractTypeScriptExtensionNonDts(moduleName);
if (nonDtsExtension) {
const diag = Diagnostics.An_import_path_should_not_end_with_a_0_extension_Consider_importing_1_instead;
error(moduleReferenceLiteral, diag, nonDtsExtension, removeExtension(moduleName, nonDtsExtension));
const tsExtension = tryExtractTypeScriptExtension(moduleName);
if (tsExtension) {
const diag = Diagnostics.An_import_path_cannot_end_with_a_0_extension_Consider_importing_1_instead;
error(moduleReferenceLiteral, diag, tsExtension, removeExtension(moduleName, tsExtension));
}
else {
error(moduleReferenceLiteral, moduleNotFoundError, moduleName);
Expand Down
3 changes: 1 addition & 2 deletions src/compiler/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1198,8 +1198,7 @@ namespace ts {
/**
* List of supported extensions in order of file resolution precedence.
*/
export const supportedTypeScriptExtensionsNonDts = [".ts", ".tsx"];
export const supportedTypeScriptExtensions = supportedTypeScriptExtensionsNonDts.concat([".d.ts"]);
export const supportedTypeScriptExtensions = [".ts", ".tsx", ".d.ts"];
export const supportedJavascriptExtensions = [".js", ".jsx"];
const allSupportedExtensions = supportedTypeScriptExtensions.concat(supportedJavascriptExtensions);

Expand Down
2 changes: 1 addition & 1 deletion src/compiler/diagnosticMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -1951,7 +1951,7 @@
"category": "Error",
"code": 2690
},
"An import path should not end with a '{0}' extension. Consider importing '{1}' instead.": {
"An import path cannot end with a '{0}' extension. Consider importing '{1}' instead.": {
"category": "Error",
"code": 2691
},
Expand Down
16 changes: 4 additions & 12 deletions src/compiler/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -669,17 +669,7 @@ namespace ts {
* in cases when we know upfront that all load attempts will fail (because containing folder does not exists) however we still need to record all failed lookup locations.
*/
function loadModuleFromFile(candidate: string, extensions: string[], failedLookupLocation: string[], onlyRecordFailures: boolean, state: ModuleResolutionState): string | undefined {
// If the candidate already has an extension load that or quit.
if (hasTypeScriptFileExtension(candidate)) {
// Don't allow `.ts` to appear at the end
if (!fileExtensionIs(candidate, ".d.ts")) {
return undefined;
}
return tryFile(candidate, failedLookupLocation, onlyRecordFailures, state);
}

// Next, try adding an extension.
// We don't allow an import of "foo.ts" to be matched by "foo.ts.ts", but we do allow "foo.js" to be matched by "foo.js.ts".
// First, try adding an extension. An import of "foo" could be matched by a file "foo.ts", or "foo.js" by "foo.js.ts"
const resolvedByAddingExtension = tryAddingExtensions(candidate, extensions, failedLookupLocation, onlyRecordFailures, state);
if (resolvedByAddingExtension) {
return resolvedByAddingExtension;
Expand Down Expand Up @@ -736,7 +726,9 @@ namespace ts {
}
const typesFile = tryReadTypesSection(packageJsonPath, candidate, state);
if (typesFile) {
const result = loadModuleFromFile(typesFile, extensions, failedLookupLocation, !directoryProbablyExists(getDirectoryPath(typesFile), state.host), state);
const onlyRecordFailures = !directoryProbablyExists(getDirectoryPath(typesFile), state.host);
// The package.json "typings" property must specify the file with extension, so just try that exact filename.
const result = tryFile(typesFile, failedLookupLocation, onlyRecordFailures, state);
if (result) {
return result;
}
Expand Down
6 changes: 4 additions & 2 deletions src/compiler/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2727,9 +2727,11 @@ namespace ts {
}

/** Return ".ts" or ".tsx" if that is the extension. */
export function tryExtractTypeScriptExtensionNonDts(fileName: string): string | undefined {
return find(supportedTypeScriptExtensionsNonDts, extension => fileExtensionIs(fileName, extension));
export function tryExtractTypeScriptExtension(fileName: string): string | undefined {
return find(supportedTypescriptExtensionsWithDtsFirst, extension => fileExtensionIs(fileName, extension));
}
// Must have '.d.ts' first because if '.ts' goes first, that will be detected as the extension instead of '.d.ts'.
const supportedTypescriptExtensionsWithDtsFirst = supportedTypeScriptExtensions.slice().reverse();

/**
* Replace each instance of non-ascii characters by one, two, three, or four escape sequences
Expand Down
2 changes: 1 addition & 1 deletion src/harness/compilerRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class CompilerBaselineRunner extends RunnerBase {
private makeUnitName(name: string, root: string) {
const path = ts.toPath(name, root, (fileName) => Harness.Compiler.getCanonicalFileName(fileName));
const pathStart = ts.toPath(Harness.IO.getCurrentDirectory(), "", (fileName) => Harness.Compiler.getCanonicalFileName(fileName));
return path.replace(pathStart, "/");
return pathStart === "" ? path : path.replace(pathStart, "/");
};

public checkTestCodeOutput(fileName: string) {
Expand Down
32 changes: 19 additions & 13 deletions tests/baselines/reference/moduleResolutionNoTs.errors.txt
Original file line number Diff line number Diff line change
@@ -1,25 +1,31 @@
tests/cases/compiler/user.ts(4,15): error TS2691: An import path should not end with a '.ts' extension. Consider importing './x' instead.
tests/cases/compiler/user.ts(5,15): error TS2691: An import path should not end with a '.tsx' extension. Consider importing './y' instead.
tests/cases/compiler/user.ts(1,15): error TS2691: An import path cannot end with a '.ts' extension. Consider importing './x' instead.
tests/cases/compiler/user.ts(2,15): error TS2691: An import path cannot end with a '.tsx' extension. Consider importing './y' instead.
tests/cases/compiler/user.ts(3,15): error TS2691: An import path cannot end with a '.d.ts' extension. Consider importing './z' instead.


==== tests/cases/compiler/user.ts (2 errors) ====
// '.ts' extension is OK in a reference
///<reference path="./x.ts"/>
==== tests/cases/compiler/x.ts (0 errors) ====
export default 0;

==== tests/cases/compiler/y.tsx (0 errors) ====
export default 0;

==== tests/cases/compiler/z.d.ts (0 errors) ====
declare const x: number;
export default x;

==== tests/cases/compiler/user.ts (3 errors) ====
import x from "./x.ts";
~~~~~~~~
!!! error TS2691: An import path should not end with a '.ts' extension. Consider importing './x' instead.
!!! error TS2691: An import path cannot end with a '.ts' extension. Consider importing './x' instead.
import y from "./y.tsx";
~~~~~~~~~
!!! error TS2691: An import path should not end with a '.tsx' extension. Consider importing './y' instead.
!!! error TS2691: An import path cannot end with a '.tsx' extension. Consider importing './y' instead.
import z from "./z.d.ts";
~~~~~~~~~~
!!! error TS2691: An import path cannot end with a '.d.ts' extension. Consider importing './z' instead.

// Making sure the suggested fixes are valid:
import x2 from "./x";
import y2 from "./y";

==== tests/cases/compiler/x.ts (0 errors) ====
export default 0;

==== tests/cases/compiler/y.tsx (0 errors) ====
export default 0;
import z2 from "./z";

11 changes: 6 additions & 5 deletions tests/baselines/reference/moduleResolutionNoTs.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,19 @@ export default 0;
//// [y.tsx]
export default 0;

//// [z.d.ts]
declare const x: number;
export default x;

//// [user.ts]
// '.ts' extension is OK in a reference
///<reference path="./x.ts"/>

import x from "./x.ts";
import y from "./y.tsx";
import z from "./z.d.ts";

// Making sure the suggested fixes are valid:
import x2 from "./x";
import y2 from "./y";
import z2 from "./z";


//// [x.js]
Expand All @@ -27,6 +30,4 @@ exports["default"] = 0;
exports.__esModule = true;
exports["default"] = 0;
//// [user.js]
// '.ts' extension is OK in a reference
///<reference path="./x.ts"/>
"use strict";
9 changes: 6 additions & 3 deletions tests/cases/compiler/moduleResolutionNoTs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@ export default 0;
// @filename: y.tsx
export default 0;

// @filename: user.ts
// '.ts' extension is OK in a reference
///<reference path="./x.ts"/>
// @filename: z.d.ts
declare const x: number;
export default x;

// @filename: user.ts
import x from "./x.ts";
import y from "./y.tsx";
import z from "./z.d.ts";

// Making sure the suggested fixes are valid:
import x2 from "./x";
import y2 from "./y";
import z2 from "./z";