Allow JS files
This commit is contained in:
parent
240b474ba3
commit
a0e4ab94f1
|
@ -2210,17 +2210,13 @@ namespace ts {
|
|||
* Path must have a valid extension.
|
||||
*/
|
||||
export function extensionFromPath(path: string): Extension {
|
||||
const ts = tryGetTypeScriptExtensionFromPath(path);
|
||||
if (ts !== undefined) {
|
||||
return ts;
|
||||
}
|
||||
const js = tryGetJavaScriptExtensionFromPath(path);
|
||||
if (js !== undefined) {
|
||||
return js;
|
||||
const ext = tryGetExtensionFromPath(path);
|
||||
if (ext !== undefined) {
|
||||
return ext;
|
||||
}
|
||||
Debug.fail(`File ${path} has unknown extension.`);
|
||||
}
|
||||
export function tryGetTypeScriptExtensionFromPath(path: string): Extension | undefined {
|
||||
export function tryGetExtensionFromPath(path: string): Extension | undefined {
|
||||
if (fileExtensionIs(path, ".d.ts")) {
|
||||
return Extension.Dts;
|
||||
}
|
||||
|
@ -2230,8 +2226,6 @@ namespace ts {
|
|||
if (fileExtensionIs(path, ".tsx")) {
|
||||
return Extension.Tsx;
|
||||
}
|
||||
}
|
||||
function tryGetJavaScriptExtensionFromPath(path: string): Extension | undefined {
|
||||
if (fileExtensionIs(path, ".js")) {
|
||||
return Extension.Js;
|
||||
}
|
||||
|
|
|
@ -519,7 +519,7 @@ namespace ts {
|
|||
trace(state.host, Diagnostics.Trying_substitution_0_candidate_module_location_Colon_1, subst, path);
|
||||
}
|
||||
// A path mapping may have a ".ts" extension; in contrast to an import, which should omit it.
|
||||
const tsExtension = tryGetTypeScriptExtensionFromPath(candidate);
|
||||
const tsExtension = tryGetExtensionFromPath(candidate);
|
||||
if (tsExtension !== undefined) {
|
||||
const path = tryFile(candidate, failedLookupLocations, /*onlyRecordFailures*/false, state);
|
||||
return path && { path, extension: tsExtension };
|
||||
|
|
|
@ -4,13 +4,21 @@
|
|||
|
||||
export function foo() {}
|
||||
|
||||
//// [bar.js]
|
||||
export function bar() {}
|
||||
|
||||
//// [a.ts]
|
||||
import { foo } from "foo";
|
||||
import { bar } from "bar";
|
||||
|
||||
|
||||
//// [foo.js]
|
||||
"use strict";
|
||||
function foo() { }
|
||||
exports.foo = foo;
|
||||
//// [bar.js]
|
||||
"use strict";
|
||||
function bar() { }
|
||||
exports.bar = bar;
|
||||
//// [a.js]
|
||||
"use strict";
|
||||
|
|
|
@ -2,8 +2,15 @@
|
|||
import { foo } from "foo";
|
||||
>foo : Symbol(foo, Decl(a.ts, 0, 8))
|
||||
|
||||
import { bar } from "bar";
|
||||
>bar : Symbol(bar, Decl(a.ts, 1, 8))
|
||||
|
||||
=== /foo/foo.ts ===
|
||||
|
||||
export function foo() {}
|
||||
>foo : Symbol(foo, Decl(foo.ts, 0, 0))
|
||||
|
||||
=== /bar/bar.js ===
|
||||
export function bar() {}
|
||||
>bar : Symbol(bar, Decl(bar.js, 0, 0))
|
||||
|
||||
|
|
|
@ -7,5 +7,14 @@
|
|||
"Trying substitution 'foo/foo.ts', candidate module location: 'foo/foo.ts'.",
|
||||
"File '/foo/foo.ts' exist - use it as a name resolution result.",
|
||||
"Resolving real path for '/foo/foo.ts', result '/foo/foo.ts'",
|
||||
"======== Module name 'foo' was successfully resolved to '/foo/foo.ts'. ========"
|
||||
"======== Module name 'foo' was successfully resolved to '/foo/foo.ts'. ========",
|
||||
"======== Resolving module 'bar' from '/a.ts'. ========",
|
||||
"Module resolution kind is not specified, using 'NodeJs'.",
|
||||
"'baseUrl' option is set to '/', using this value to resolve non-relative module name 'bar'",
|
||||
"'paths' option is specified, looking for a pattern to match module name 'bar'.",
|
||||
"Module name 'bar', matched pattern 'bar'.",
|
||||
"Trying substitution 'bar/bar.js', candidate module location: 'bar/bar.js'.",
|
||||
"File '/bar/bar.js' exist - use it as a name resolution result.",
|
||||
"Resolving real path for '/bar/bar.js', result '/bar/bar.js'",
|
||||
"======== Module name 'bar' was successfully resolved to '/bar/bar.js'. ========"
|
||||
]
|
|
@ -2,8 +2,15 @@
|
|||
import { foo } from "foo";
|
||||
>foo : () => void
|
||||
|
||||
import { bar } from "bar";
|
||||
>bar : () => void
|
||||
|
||||
=== /foo/foo.ts ===
|
||||
|
||||
export function foo() {}
|
||||
>foo : () => void
|
||||
|
||||
=== /bar/bar.js ===
|
||||
export function bar() {}
|
||||
>bar : () => void
|
||||
|
||||
|
|
|
@ -14,12 +14,8 @@
|
|||
"File '/node_modules/foo/index.ts' does not exist.",
|
||||
"File '/node_modules/foo/index.tsx' does not exist.",
|
||||
"File '/node_modules/foo/index.d.ts' does not exist.",
|
||||
"File '/node_modules/@types/foo.ts' does not exist.",
|
||||
"File '/node_modules/@types/foo.tsx' does not exist.",
|
||||
"File '/node_modules/@types/foo.d.ts' does not exist.",
|
||||
"File '/node_modules/@types/foo/package.json' does not exist.",
|
||||
"File '/node_modules/@types/foo/index.ts' does not exist.",
|
||||
"File '/node_modules/@types/foo/index.tsx' does not exist.",
|
||||
"File '/node_modules/@types/foo/index.d.ts' does not exist.",
|
||||
"'baseUrl' option is set to '/', using this value to resolve non-relative module name 'foo'",
|
||||
"'paths' option is specified, looking for a pattern to match module name 'foo'.",
|
||||
|
@ -32,10 +28,5 @@
|
|||
"File '/node_modules/foo/package.json' does not exist.",
|
||||
"File '/node_modules/foo/index.js' does not exist.",
|
||||
"File '/node_modules/foo/index.jsx' does not exist.",
|
||||
"File '/node_modules/@types/foo.js' does not exist.",
|
||||
"File '/node_modules/@types/foo.jsx' does not exist.",
|
||||
"File '/node_modules/@types/foo/package.json' does not exist.",
|
||||
"File '/node_modules/@types/foo/index.js' does not exist.",
|
||||
"File '/node_modules/@types/foo/index.jsx' does not exist.",
|
||||
"======== Module name 'foo' was not resolved. ========"
|
||||
]
|
|
@ -1,18 +1,26 @@
|
|||
// @noImplicitReferences: true
|
||||
// @traceResolution: true
|
||||
// @allowJs: true
|
||||
|
||||
// @Filename: /foo/foo.ts
|
||||
export function foo() {}
|
||||
|
||||
// @Filename: /bar/bar.js
|
||||
export function bar() {}
|
||||
|
||||
// @Filename: /a.ts
|
||||
import { foo } from "foo";
|
||||
import { bar } from "bar";
|
||||
|
||||
// @Filename: /tsconfig.json
|
||||
{
|
||||
"compilerOptions": {
|
||||
"baseUrl": ".",
|
||||
"paths": {
|
||||
"foo": ["foo/foo.ts"]
|
||||
}
|
||||
"foo": ["foo/foo.ts"],
|
||||
"bar": ["bar/bar.js"]
|
||||
},
|
||||
"allowJs": true,
|
||||
"outDir": "bin"
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue