mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-18 16:34:36 -05:00
Resolve the .json file only if module name contains the extension
This commit is contained in:
@@ -2084,7 +2084,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
// May be an untyped module. If so, ignore resolutionDiagnostic.
|
||||
if (resolvedModule && !extensionIsTypeScript(resolvedModule.extension) && resolutionDiagnostic === undefined || resolutionDiagnostic === Diagnostics.Could_not_find_a_declaration_file_for_module_0_1_implicitly_has_an_any_type) {
|
||||
if (resolvedModule && !resolutionExtensionIsTypeScriptOrJson(resolvedModule.extension) && resolutionDiagnostic === undefined || resolutionDiagnostic === Diagnostics.Could_not_find_a_declaration_file_for_module_0_1_implicitly_has_an_any_type) {
|
||||
if (isForAugmentation) {
|
||||
const diag = Diagnostics.Invalid_module_name_in_augmentation_Module_0_resolves_to_an_untyped_module_at_1_which_cannot_be_augmented;
|
||||
error(errorNode, diag, moduleReference, resolvedModule.resolvedFileName);
|
||||
|
||||
@@ -2044,8 +2044,7 @@ namespace ts {
|
||||
|
||||
// Rather than requery this for each file and filespec, we query the supported extensions
|
||||
// once and store it on the expansion context.
|
||||
// When computing file names, do not include json files. Use only module resolution or explicit includes for them
|
||||
const supportedExtensions = getSupportedExtensions(options, extraFileExtensions, /*excludeJson*/ true);
|
||||
const supportedExtensions = getSupportedExtensions(options, extraFileExtensions);
|
||||
|
||||
// Literal files are always included verbatim. An "include" or "exclude" specification cannot
|
||||
// remove a literal file.
|
||||
|
||||
@@ -2674,21 +2674,14 @@ namespace ts {
|
||||
export const supportedTypescriptExtensionsForExtractExtension: ReadonlyArray<Extension> = [Extension.Dts, Extension.Ts, Extension.Tsx];
|
||||
export const supportedJavascriptExtensions: ReadonlyArray<Extension> = [Extension.Js, Extension.Jsx];
|
||||
const allSupportedExtensions: ReadonlyArray<Extension> = [...supportedTypeScriptExtensions, ...supportedJavascriptExtensions];
|
||||
let allSupportedExtensionsIncludingJson: ReadonlyArray<Extension> | undefined;
|
||||
function getAllSupportedExtensionsIncludingJson() {
|
||||
return allSupportedExtensionsIncludingJson || (allSupportedExtensionsIncludingJson = [...allSupportedExtensions, Extension.Json]);
|
||||
}
|
||||
|
||||
export function getSupportedExtensions(options?: CompilerOptions, extraFileExtensions?: ReadonlyArray<JsFileExtensionInfo>, excludeJson?: boolean): ReadonlyArray<string> {
|
||||
export function getSupportedExtensions(options?: CompilerOptions, extraFileExtensions?: ReadonlyArray<JsFileExtensionInfo>): ReadonlyArray<string> {
|
||||
const needAllExtensions = options && options.allowJs;
|
||||
const useJsonExtension = needAllExtensions && !excludeJson && getEmitModuleResolutionKind(options) === ModuleResolutionKind.NodeJs;
|
||||
if (!extraFileExtensions || extraFileExtensions.length === 0 || !needAllExtensions) {
|
||||
return useJsonExtension ?
|
||||
getAllSupportedExtensionsIncludingJson() :
|
||||
needAllExtensions ? allSupportedExtensions : supportedTypeScriptExtensions;
|
||||
return needAllExtensions ? allSupportedExtensions : supportedTypeScriptExtensions;
|
||||
}
|
||||
return deduplicate(
|
||||
[...(useJsonExtension ? getAllSupportedExtensionsIncludingJson() : allSupportedExtensions), ...extraFileExtensions.map(e => e.extension)],
|
||||
[...allSupportedExtensions, ...extraFileExtensions.map(e => e.extension)],
|
||||
equateStringsCaseSensitive,
|
||||
compareStringsCaseSensitive
|
||||
);
|
||||
@@ -2698,10 +2691,6 @@ namespace ts {
|
||||
return forEach(supportedJavascriptExtensions, extension => fileExtensionIs(fileName, extension));
|
||||
}
|
||||
|
||||
export function hasJavaScriptOrJsonFileExtension(fileName: string) {
|
||||
return hasJavaScriptFileExtension(fileName) || fileExtensionIs(fileName, Extension.Json);
|
||||
}
|
||||
|
||||
export function hasTypeScriptFileExtension(fileName: string) {
|
||||
return forEach(supportedTypeScriptExtensions, extension => fileExtensionIs(fileName, extension));
|
||||
}
|
||||
@@ -3102,6 +3091,10 @@ namespace ts {
|
||||
return ext === Extension.Ts || ext === Extension.Tsx || ext === Extension.Dts;
|
||||
}
|
||||
|
||||
export function resolutionExtensionIsTypeScriptOrJson(ext: Extension) {
|
||||
return extensionIsTypeScript(ext) || ext === Extension.Json;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the extension from a path.
|
||||
* Path must have a valid extension.
|
||||
@@ -3119,9 +3112,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
export function tryGetExtensionFromPath(path: string): Extension | undefined {
|
||||
return find<Extension>(supportedTypescriptExtensionsForExtractExtension, e => fileExtensionIs(path, e)) ||
|
||||
find(supportedJavascriptExtensions, e => fileExtensionIs(path, e)) ||
|
||||
(fileExtensionIs(path, Extension.Json) ? Extension.Json : undefined);
|
||||
return find<Extension>(supportedTypescriptExtensionsForExtractExtension, e => fileExtensionIs(path, e)) || find(supportedJavascriptExtensions, e => fileExtensionIs(path, e));
|
||||
}
|
||||
|
||||
// Retrieves any string from the final "." onwards from a base file name.
|
||||
|
||||
@@ -882,6 +882,11 @@ 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(extensions: Extensions, candidate: string, failedLookupLocations: Push<string>, onlyRecordFailures: boolean, state: ModuleResolutionState): PathAndExtension | undefined {
|
||||
if (extensions === Extensions.Json) {
|
||||
const extensionLess = tryRemoveExtension(candidate, Extension.Json);
|
||||
return extensionLess && tryAddingExtensions(extensionLess, extensions, failedLookupLocations, onlyRecordFailures, state);
|
||||
}
|
||||
|
||||
// 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, failedLookupLocations, onlyRecordFailures, state);
|
||||
if (resolvedByAddingExtension) {
|
||||
@@ -890,7 +895,7 @@ namespace ts {
|
||||
|
||||
// If that didn't work, try stripping a ".js" or ".jsx" extension and replacing it with a TypeScript one;
|
||||
// e.g. "./foo.js" can be matched by "./foo.ts" or "./foo.d.ts"
|
||||
if (hasJavaScriptOrJsonFileExtension(candidate)) {
|
||||
if (hasJavaScriptFileExtension(candidate)) {
|
||||
const extensionless = removeFileExtension(candidate);
|
||||
if (state.traceEnabled) {
|
||||
const extension = candidate.substring(extensionless.length);
|
||||
|
||||
@@ -1975,7 +1975,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
const isFromNodeModulesSearch = resolution.isExternalLibraryImport;
|
||||
const isJsFile = !extensionIsTypeScript(resolution.extension);
|
||||
const isJsFile = !resolutionExtensionIsTypeScriptOrJson(resolution.extension);
|
||||
const isJsFileFromNodeModules = isFromNodeModulesSearch && isJsFile;
|
||||
const resolvedFileName = resolution.resolvedFileName;
|
||||
|
||||
@@ -2405,6 +2405,7 @@ namespace ts {
|
||||
switch (extension) {
|
||||
case Extension.Ts:
|
||||
case Extension.Dts:
|
||||
case Extension.Json:
|
||||
// These are always allowed.
|
||||
return undefined;
|
||||
case Extension.Tsx:
|
||||
@@ -2412,7 +2413,6 @@ namespace ts {
|
||||
case Extension.Jsx:
|
||||
return needJsx() || needAllowJs();
|
||||
case Extension.Js:
|
||||
case Extension.Json:
|
||||
return needAllowJs();
|
||||
}
|
||||
|
||||
|
||||
@@ -511,9 +511,8 @@ namespace FourSlash {
|
||||
}
|
||||
|
||||
private getAllDiagnostics(): ts.Diagnostic[] {
|
||||
const options = this.languageService.getProgram().getCompilerOptions();
|
||||
return ts.flatMap(this.languageServiceAdapterHost.getFilenames(), fileName =>
|
||||
ts.fileExtensionIsOneOf(fileName, ts.getSupportedExtensions(options)) ? this.getDiagnostics(fileName) : []);
|
||||
ts.isAnySupportedFileExtension(fileName) ? this.getDiagnostics(fileName) : []);
|
||||
}
|
||||
|
||||
public verifyErrorExistsAfterMarker(markerName: string, shouldExist: boolean, after: boolean) {
|
||||
|
||||
@@ -473,8 +473,6 @@ namespace ts {
|
||||
"File 'node_modules/a/index.jsx' does not exist.",
|
||||
"Loading module 'a' from 'node_modules' folder, target file type 'Json'.",
|
||||
"File 'node_modules/a/package.json' does not exist.",
|
||||
"File 'node_modules/a.json' does not exist.",
|
||||
"File 'node_modules/a/index.json' does not exist.",
|
||||
"======== Module name 'a' was not resolved. ========"
|
||||
],
|
||||
"initialProgram: execute module resolution normally.");
|
||||
|
||||
@@ -98,7 +98,7 @@ namespace ts.JsTyping {
|
||||
// Only infer typings for .js and .jsx files
|
||||
fileNames = mapDefined(fileNames, fileName => {
|
||||
const path = normalizePath(fileName);
|
||||
if (hasJavaScriptOrJsonFileExtension(path)) {
|
||||
if (hasJavaScriptFileExtension(path)) {
|
||||
return path;
|
||||
}
|
||||
});
|
||||
@@ -193,7 +193,7 @@ namespace ts.JsTyping {
|
||||
*/
|
||||
function getTypingNamesFromSourceFileNames(fileNames: string[]) {
|
||||
const fromFileNames = mapDefined(fileNames, j => {
|
||||
if (!hasJavaScriptOrJsonFileExtension(j)) return undefined;
|
||||
if (!hasJavaScriptFileExtension(j)) return undefined;
|
||||
|
||||
const inferredTypingName = removeFileExtension(getBaseFileName(j.toLowerCase()));
|
||||
const cleanedTypingName = removeMinAndVersionNumbers(inferredTypingName);
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
error TS5055: Cannot write file 'tests/cases/compiler/b.js' because it would overwrite input file.
|
||||
Adding a tsconfig.json file will help organize projects that contain both TypeScript and JavaScript files. Learn more at https://aka.ms/tsconfig.
|
||||
error TS6054: File 'tests/cases/compiler/b.js.map' has unsupported extension. The only supported extensions are '.ts', '.tsx', '.d.ts', '.js', '.jsx', '.json'.
|
||||
error TS6054: File 'tests/cases/compiler/b.js.map' has unsupported extension. The only supported extensions are '.ts', '.tsx', '.d.ts', '.js', '.jsx'.
|
||||
|
||||
|
||||
!!! error TS5055: Cannot write file 'tests/cases/compiler/b.js' because it would overwrite input file.
|
||||
!!! error TS5055: Adding a tsconfig.json file will help organize projects that contain both TypeScript and JavaScript files. Learn more at https://aka.ms/tsconfig.
|
||||
!!! error TS6054: File 'tests/cases/compiler/b.js.map' has unsupported extension. The only supported extensions are '.ts', '.tsx', '.d.ts', '.js', '.jsx', '.json'.
|
||||
!!! error TS6054: File 'tests/cases/compiler/b.js.map' has unsupported extension. The only supported extensions are '.ts', '.tsx', '.d.ts', '.js', '.jsx'.
|
||||
==== tests/cases/compiler/a.ts (0 errors) ====
|
||||
class c {
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
error TS5055: Cannot write file 'tests/cases/compiler/b.js' because it would overwrite input file.
|
||||
Adding a tsconfig.json file will help organize projects that contain both TypeScript and JavaScript files. Learn more at https://aka.ms/tsconfig.
|
||||
error TS6054: File 'tests/cases/compiler/b.js.map' has unsupported extension. The only supported extensions are '.ts', '.tsx', '.d.ts', '.js', '.jsx', '.json'.
|
||||
error TS6054: File 'tests/cases/compiler/b.js.map' has unsupported extension. The only supported extensions are '.ts', '.tsx', '.d.ts', '.js', '.jsx'.
|
||||
|
||||
|
||||
!!! error TS5055: Cannot write file 'tests/cases/compiler/b.js' because it would overwrite input file.
|
||||
!!! error TS5055: Adding a tsconfig.json file will help organize projects that contain both TypeScript and JavaScript files. Learn more at https://aka.ms/tsconfig.
|
||||
!!! error TS6054: File 'tests/cases/compiler/b.js.map' has unsupported extension. The only supported extensions are '.ts', '.tsx', '.d.ts', '.js', '.jsx', '.json'.
|
||||
!!! error TS6054: File 'tests/cases/compiler/b.js.map' has unsupported extension. The only supported extensions are '.ts', '.tsx', '.d.ts', '.js', '.jsx'.
|
||||
==== tests/cases/compiler/a.ts (0 errors) ====
|
||||
class c {
|
||||
}
|
||||
|
||||
@@ -36,13 +36,10 @@
|
||||
"'package.json' does not have a 'types' field.",
|
||||
"'package.json' has 'main' field 'normalize.css' that references '/node_modules/normalize.css/normalize.css'.",
|
||||
"Found 'package.json' at '/node_modules/normalize.css/package.json'.",
|
||||
"File '/node_modules/normalize.css.json' does not exist.",
|
||||
"'package.json' has 'main' field 'normalize.css' that references '/node_modules/normalize.css/normalize.css'.",
|
||||
"File '/node_modules/normalize.css/normalize.css' exist - use it as a name resolution result.",
|
||||
"File '/node_modules/normalize.css/normalize.css' has an unsupported extension, so skipping it.",
|
||||
"Loading module as file / folder, candidate module location '/node_modules/normalize.css/normalize.css', target file type 'Json'.",
|
||||
"File '/node_modules/normalize.css/normalize.css.json' does not exist.",
|
||||
"Directory '/node_modules/normalize.css/normalize.css' does not exist, skipping all lookups in it.",
|
||||
"File '/node_modules/normalize.css/index.json' does not exist.",
|
||||
"======== Module name 'normalize.css' was not resolved. ========"
|
||||
]
|
||||
@@ -38,8 +38,6 @@
|
||||
"'package.json' does not have a 'typings' field.",
|
||||
"'package.json' has 'types' field 'foo.js' that references '/node_modules/foo/foo.js'.",
|
||||
"Found 'package.json' at '/node_modules/foo/package.json'.",
|
||||
"File '/node_modules/foo.json' does not exist.",
|
||||
"'package.json' does not have a 'main' field.",
|
||||
"File '/node_modules/foo/index.json' does not exist.",
|
||||
"======== Module name 'foo' was not resolved. ========"
|
||||
]
|
||||
@@ -36,12 +36,8 @@
|
||||
"'package.json' does not have a 'types' field.",
|
||||
"'package.json' has 'main' field 'oof' that references '/node_modules/foo/oof'.",
|
||||
"Found 'package.json' at '/node_modules/foo/package.json'.",
|
||||
"File '/node_modules/foo.json' does not exist.",
|
||||
"'package.json' has 'main' field 'oof' that references '/node_modules/foo/oof'.",
|
||||
"File '/node_modules/foo/oof' does not exist.",
|
||||
"Loading module as file / folder, candidate module location '/node_modules/foo/oof', target file type 'Json'.",
|
||||
"File '/node_modules/foo/oof.json' does not exist.",
|
||||
"File '/node_modules/foo/oof/index.json' does not exist.",
|
||||
"File '/node_modules/foo/index.json' does not exist.",
|
||||
"======== Module name 'foo' was not resolved. ========"
|
||||
]
|
||||
@@ -1,7 +1,7 @@
|
||||
//// [tests/cases/compiler/requireOfJsonFile.ts] ////
|
||||
|
||||
//// [file1.ts]
|
||||
import b1 = require('./b');
|
||||
import b1 = require('./b.json');
|
||||
let x = b1.a;
|
||||
import b2 = require('./b.json');
|
||||
if (x) {
|
||||
@@ -23,7 +23,7 @@ if (x) {
|
||||
//// [file1.js]
|
||||
"use strict";
|
||||
exports.__esModule = true;
|
||||
var b1 = require("./b");
|
||||
var b1 = require("./b.json");
|
||||
var x = b1.a;
|
||||
var b2 = require("./b.json");
|
||||
if (x) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
=== tests/cases/compiler/file1.ts ===
|
||||
import b1 = require('./b');
|
||||
import b1 = require('./b.json');
|
||||
>b1 : Symbol(b1, Decl(file1.ts, 0, 0))
|
||||
|
||||
let x = b1.a;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
=== tests/cases/compiler/file1.ts ===
|
||||
import b1 = require('./b');
|
||||
import b1 = require('./b.json');
|
||||
>b1 : { "a": boolean; "b": string; }
|
||||
|
||||
let x = b1.a;
|
||||
|
||||
33
tests/baselines/reference/requireOfJsonFileNonRelative.js
Normal file
33
tests/baselines/reference/requireOfJsonFileNonRelative.js
Normal file
@@ -0,0 +1,33 @@
|
||||
//// [tests/cases/compiler/requireOfJsonFileNonRelative.ts] ////
|
||||
|
||||
//// [file1.ts]
|
||||
import b1 = require('b.json');
|
||||
let x = b1.a;
|
||||
import b2 = require('c.json');
|
||||
if (x) {
|
||||
let b = b2.b;
|
||||
x = (b1.b === b);
|
||||
}
|
||||
|
||||
//// [b.json]
|
||||
{
|
||||
"a": true,
|
||||
"b": "hello"
|
||||
}
|
||||
|
||||
//// [c.json]
|
||||
{
|
||||
"a": true,
|
||||
"b": "hello"
|
||||
}
|
||||
|
||||
//// [file1.js]
|
||||
"use strict";
|
||||
exports.__esModule = true;
|
||||
var b1 = require("b.json");
|
||||
var x = b1.a;
|
||||
var b2 = require("c.json");
|
||||
if (x) {
|
||||
var b = b2.b;
|
||||
x = (b1.b === b);
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
=== /src/projects/file1.ts ===
|
||||
import b1 = require('b.json');
|
||||
>b1 : Symbol(b1, Decl(file1.ts, 0, 0))
|
||||
|
||||
let x = b1.a;
|
||||
>x : Symbol(x, Decl(file1.ts, 1, 3))
|
||||
>b1.a : Symbol("a", Decl(b.json, 0, 1))
|
||||
>b1 : Symbol(b1, Decl(file1.ts, 0, 0))
|
||||
>a : Symbol("a", Decl(b.json, 0, 1))
|
||||
|
||||
import b2 = require('c.json');
|
||||
>b2 : Symbol(b2, Decl(file1.ts, 1, 13))
|
||||
|
||||
if (x) {
|
||||
>x : Symbol(x, Decl(file1.ts, 1, 3))
|
||||
|
||||
let b = b2.b;
|
||||
>b : Symbol(b, Decl(file1.ts, 4, 7))
|
||||
>b2.b : Symbol("b", Decl(c.json, 1, 14))
|
||||
>b2 : Symbol(b2, Decl(file1.ts, 1, 13))
|
||||
>b : Symbol("b", Decl(c.json, 1, 14))
|
||||
|
||||
x = (b1.b === b);
|
||||
>x : Symbol(x, Decl(file1.ts, 1, 3))
|
||||
>b1.b : Symbol("b", Decl(b.json, 1, 14))
|
||||
>b1 : Symbol(b1, Decl(file1.ts, 0, 0))
|
||||
>b : Symbol("b", Decl(b.json, 1, 14))
|
||||
>b : Symbol(b, Decl(file1.ts, 4, 7))
|
||||
}
|
||||
|
||||
=== /src/projects/node_modules/b.json ===
|
||||
{
|
||||
"a": true,
|
||||
>"a" : Symbol("a", Decl(b.json, 0, 1))
|
||||
|
||||
"b": "hello"
|
||||
>"b" : Symbol("b", Decl(b.json, 1, 14))
|
||||
}
|
||||
|
||||
=== /src/node_modules/c.json ===
|
||||
{
|
||||
"a": true,
|
||||
>"a" : Symbol("a", Decl(c.json, 0, 1))
|
||||
|
||||
"b": "hello"
|
||||
>"b" : Symbol("b", Decl(c.json, 1, 14))
|
||||
}
|
||||
58
tests/baselines/reference/requireOfJsonFileNonRelative.types
Normal file
58
tests/baselines/reference/requireOfJsonFileNonRelative.types
Normal file
@@ -0,0 +1,58 @@
|
||||
=== /src/projects/file1.ts ===
|
||||
import b1 = require('b.json');
|
||||
>b1 : { "a": boolean; "b": string; }
|
||||
|
||||
let x = b1.a;
|
||||
>x : boolean
|
||||
>b1.a : boolean
|
||||
>b1 : { "a": boolean; "b": string; }
|
||||
>a : boolean
|
||||
|
||||
import b2 = require('c.json');
|
||||
>b2 : { "a": boolean; "b": string; }
|
||||
|
||||
if (x) {
|
||||
>x : boolean
|
||||
|
||||
let b = b2.b;
|
||||
>b : string
|
||||
>b2.b : string
|
||||
>b2 : { "a": boolean; "b": string; }
|
||||
>b : string
|
||||
|
||||
x = (b1.b === b);
|
||||
>x = (b1.b === b) : boolean
|
||||
>x : boolean
|
||||
>(b1.b === b) : boolean
|
||||
>b1.b === b : boolean
|
||||
>b1.b : string
|
||||
>b1 : { "a": boolean; "b": string; }
|
||||
>b : string
|
||||
>b : string
|
||||
}
|
||||
|
||||
=== /src/projects/node_modules/b.json ===
|
||||
{
|
||||
>{ "a": true, "b": "hello"} : { "a": boolean; "b": string; }
|
||||
|
||||
"a": true,
|
||||
>"a" : boolean
|
||||
>true : true
|
||||
|
||||
"b": "hello"
|
||||
>"b" : string
|
||||
>"hello" : "hello"
|
||||
}
|
||||
|
||||
=== /src/node_modules/c.json ===
|
||||
{
|
||||
>{ "a": true, "b": "hello"} : { "a": boolean; "b": string; }
|
||||
|
||||
"a": true,
|
||||
>"a" : boolean
|
||||
>true : true
|
||||
|
||||
"b": "hello"
|
||||
>"b" : string
|
||||
>"hello" : "hello"
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
/src/projects/file1.ts(1,20): error TS2307: Cannot find module 'd.json'.
|
||||
/src/projects/file1.ts(2,20): error TS2307: Cannot find module 'e'.
|
||||
|
||||
|
||||
==== /src/projects/file1.ts (2 errors) ====
|
||||
import d = require("d.json"); // Should fail
|
||||
~~~~~~~~
|
||||
!!! error TS2307: Cannot find module 'd.json'.
|
||||
import e = require("e"); // Should fail
|
||||
~~~
|
||||
!!! error TS2307: Cannot find module 'e'.
|
||||
|
||||
==== /src/projects/node_modules/b.json (0 errors) ====
|
||||
{
|
||||
"a": true,
|
||||
"b": "hello"
|
||||
}
|
||||
|
||||
==== /src/projects/node_modules/e.json (0 errors) ====
|
||||
{
|
||||
"a": true,
|
||||
"b": "hello"
|
||||
}
|
||||
|
||||
==== /src/node_modules/c.json (0 errors) ====
|
||||
{
|
||||
"a": true,
|
||||
"b": "hello"
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
//// [tests/cases/compiler/requireOfJsonFileNonRelativeWithoutExtension.ts] ////
|
||||
|
||||
//// [file1.ts]
|
||||
import d = require("d.json"); // Should fail
|
||||
import e = require("e"); // Should fail
|
||||
|
||||
//// [b.json]
|
||||
{
|
||||
"a": true,
|
||||
"b": "hello"
|
||||
}
|
||||
|
||||
//// [e.json]
|
||||
{
|
||||
"a": true,
|
||||
"b": "hello"
|
||||
}
|
||||
|
||||
//// [c.json]
|
||||
{
|
||||
"a": true,
|
||||
"b": "hello"
|
||||
}
|
||||
|
||||
//// [file1.js]
|
||||
"use strict";
|
||||
exports.__esModule = true;
|
||||
@@ -0,0 +1,7 @@
|
||||
=== /src/projects/file1.ts ===
|
||||
import d = require("d.json"); // Should fail
|
||||
>d : Symbol(d, Decl(file1.ts, 0, 0))
|
||||
|
||||
import e = require("e"); // Should fail
|
||||
>e : Symbol(e, Decl(file1.ts, 0, 29))
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
=== /src/projects/file1.ts ===
|
||||
import d = require("d.json"); // Should fail
|
||||
>d : any
|
||||
|
||||
import e = require("e"); // Should fail
|
||||
>e : any
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
//// [tests/cases/compiler/requireOfJsonFileNonRelativeWithoutExtensionResolvesToTs.ts] ////
|
||||
|
||||
//// [file1.ts]
|
||||
import f = require("f"); // should work to f.ts
|
||||
let fnumber: number = f;
|
||||
|
||||
//// [f.json]
|
||||
{
|
||||
"a": true,
|
||||
"b": "hello"
|
||||
}
|
||||
|
||||
//// [f.ts]
|
||||
export = 10;
|
||||
|
||||
//// [f.js]
|
||||
"use strict";
|
||||
module.exports = 10;
|
||||
//// [file1.js]
|
||||
"use strict";
|
||||
exports.__esModule = true;
|
||||
var f = require("f"); // should work to f.ts
|
||||
var fnumber = f;
|
||||
@@ -0,0 +1,11 @@
|
||||
=== /src/projects/file1.ts ===
|
||||
import f = require("f"); // should work to f.ts
|
||||
>f : Symbol(f, Decl(file1.ts, 0, 0))
|
||||
|
||||
let fnumber: number = f;
|
||||
>fnumber : Symbol(fnumber, Decl(file1.ts, 1, 3))
|
||||
>f : Symbol(f, Decl(file1.ts, 0, 0))
|
||||
|
||||
=== /src/node_modules/f.ts ===
|
||||
export = 10;
|
||||
No type information for this code.
|
||||
@@ -0,0 +1,11 @@
|
||||
=== /src/projects/file1.ts ===
|
||||
import f = require("f"); // should work to f.ts
|
||||
>f : 10
|
||||
|
||||
let fnumber: number = f;
|
||||
>fnumber : number
|
||||
>f : 10
|
||||
|
||||
=== /src/node_modules/f.ts ===
|
||||
export = 10;
|
||||
No type information for this code.
|
||||
@@ -1,7 +1,7 @@
|
||||
//// [tests/cases/compiler/requireOfJsonFileWithEmptyObject.ts] ////
|
||||
|
||||
//// [file1.ts]
|
||||
import b1 = require('./b');
|
||||
import b1 = require('./b.json');
|
||||
let x = b1;
|
||||
import b2 = require('./b.json');
|
||||
if (x) {
|
||||
@@ -17,7 +17,7 @@ if (x) {
|
||||
//// [file1.js]
|
||||
"use strict";
|
||||
exports.__esModule = true;
|
||||
var b1 = require("./b");
|
||||
var b1 = require("./b.json");
|
||||
var x = b1;
|
||||
var b2 = require("./b.json");
|
||||
if (x) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
=== tests/cases/compiler/file1.ts ===
|
||||
import b1 = require('./b');
|
||||
import b1 = require('./b.json');
|
||||
>b1 : Symbol(b1, Decl(file1.ts, 0, 0))
|
||||
|
||||
let x = b1;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
=== tests/cases/compiler/file1.ts ===
|
||||
import b1 = require('./b');
|
||||
import b1 = require('./b.json');
|
||||
>b1 : {}
|
||||
|
||||
let x = b1;
|
||||
|
||||
@@ -4,7 +4,7 @@ tests/cases/compiler/file1.ts(6,13): error TS2339: Property 'b' does not exist o
|
||||
|
||||
|
||||
==== tests/cases/compiler/file1.ts (3 errors) ====
|
||||
import b1 = require('./b');
|
||||
import b1 = require('./b.json');
|
||||
let x = b1.a;
|
||||
~
|
||||
!!! error TS2339: Property 'a' does not exist on type '{}'.
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//// [tests/cases/compiler/requireOfJsonFileWithEmptyObjectWithErrors.ts] ////
|
||||
|
||||
//// [file1.ts]
|
||||
import b1 = require('./b');
|
||||
import b1 = require('./b.json');
|
||||
let x = b1.a;
|
||||
import b2 = require('./b.json');
|
||||
if (x) {
|
||||
@@ -18,7 +18,7 @@ if (x) {
|
||||
//// [file1.js]
|
||||
"use strict";
|
||||
exports.__esModule = true;
|
||||
var b1 = require("./b");
|
||||
var b1 = require("./b.json");
|
||||
var x = b1.a;
|
||||
var b2 = require("./b.json");
|
||||
if (x) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
=== tests/cases/compiler/file1.ts ===
|
||||
import b1 = require('./b');
|
||||
import b1 = require('./b.json');
|
||||
>b1 : Symbol(b1, Decl(file1.ts, 0, 0))
|
||||
|
||||
let x = b1.a;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
=== tests/cases/compiler/file1.ts ===
|
||||
import b1 = require('./b');
|
||||
import b1 = require('./b.json');
|
||||
>b1 : {}
|
||||
|
||||
let x = b1.a;
|
||||
|
||||
@@ -4,7 +4,7 @@ tests/cases/compiler/file1.ts(6,13): error TS2339: Property 'b' does not exist o
|
||||
|
||||
|
||||
==== tests/cases/compiler/file1.ts (3 errors) ====
|
||||
import b1 = require('./b');
|
||||
import b1 = require('./b.json');
|
||||
let x = b1.a;
|
||||
~
|
||||
!!! error TS2339: Property 'a' does not exist on type '{}'.
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//// [tests/cases/compiler/requireOfJsonFileWithNoContent.ts] ////
|
||||
|
||||
//// [file1.ts]
|
||||
import b1 = require('./b');
|
||||
import b1 = require('./b.json');
|
||||
let x = b1.a;
|
||||
import b2 = require('./b.json');
|
||||
if (x) {
|
||||
@@ -16,7 +16,7 @@ if (x) {
|
||||
//// [file1.js]
|
||||
"use strict";
|
||||
exports.__esModule = true;
|
||||
var b1 = require("./b");
|
||||
var b1 = require("./b.json");
|
||||
var x = b1.a;
|
||||
var b2 = require("./b.json");
|
||||
if (x) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
=== tests/cases/compiler/file1.ts ===
|
||||
import b1 = require('./b');
|
||||
import b1 = require('./b.json');
|
||||
>b1 : Symbol(b1, Decl(file1.ts, 0, 0))
|
||||
|
||||
let x = b1.a;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
=== tests/cases/compiler/file1.ts ===
|
||||
import b1 = require('./b');
|
||||
import b1 = require('./b.json');
|
||||
>b1 : {}
|
||||
|
||||
let x = b1.a;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//// [tests/cases/compiler/requireOfJsonFileWithoutAllowJs.ts] ////
|
||||
|
||||
//// [file1.ts]
|
||||
import b1 = require('./b');
|
||||
import b1 = require('./b.json');
|
||||
let x = b1.a;
|
||||
import b2 = require('./b.json');
|
||||
if (x) {
|
||||
@@ -15,10 +15,15 @@ if (x) {
|
||||
"b": "hello"
|
||||
}
|
||||
|
||||
//// [b.json]
|
||||
{
|
||||
"a": true,
|
||||
"b": "hello"
|
||||
}
|
||||
//// [file1.js]
|
||||
"use strict";
|
||||
exports.__esModule = true;
|
||||
var b1 = require("./b");
|
||||
var b1 = require("./b.json");
|
||||
var x = b1.a;
|
||||
var b2 = require("./b.json");
|
||||
if (x) {
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
=== tests/cases/compiler/file1.ts ===
|
||||
import b1 = require('./b');
|
||||
import b1 = require('./b.json');
|
||||
>b1 : Symbol(b1, Decl(file1.ts, 0, 0))
|
||||
|
||||
let x = b1.a;
|
||||
>x : Symbol(x, Decl(file1.ts, 1, 3))
|
||||
>b1.a : Symbol("a", Decl(b.json, 0, 1))
|
||||
>b1 : Symbol(b1, Decl(file1.ts, 0, 0))
|
||||
>a : Symbol("a", Decl(b.json, 0, 1))
|
||||
|
||||
import b2 = require('./b.json');
|
||||
>b2 : Symbol(b2, Decl(file1.ts, 1, 13))
|
||||
@@ -14,11 +16,23 @@ if (x) {
|
||||
|
||||
let b = b2.b;
|
||||
>b : Symbol(b, Decl(file1.ts, 4, 7))
|
||||
>b2.b : Symbol("b", Decl(b.json, 1, 14))
|
||||
>b2 : Symbol(b2, Decl(file1.ts, 1, 13))
|
||||
>b : Symbol("b", Decl(b.json, 1, 14))
|
||||
|
||||
x = (b1.b === b);
|
||||
>x : Symbol(x, Decl(file1.ts, 1, 3))
|
||||
>b1.b : Symbol("b", Decl(b.json, 1, 14))
|
||||
>b1 : Symbol(b1, Decl(file1.ts, 0, 0))
|
||||
>b : Symbol("b", Decl(b.json, 1, 14))
|
||||
>b : Symbol(b, Decl(file1.ts, 4, 7))
|
||||
}
|
||||
|
||||
=== tests/cases/compiler/b.json ===
|
||||
{
|
||||
"a": true,
|
||||
>"a" : Symbol("a", Decl(b.json, 0, 1))
|
||||
|
||||
"b": "hello"
|
||||
>"b" : Symbol("b", Decl(b.json, 1, 14))
|
||||
}
|
||||
|
||||
@@ -1,33 +1,45 @@
|
||||
=== tests/cases/compiler/file1.ts ===
|
||||
import b1 = require('./b');
|
||||
>b1 : any
|
||||
import b1 = require('./b.json');
|
||||
>b1 : { "a": boolean; "b": string; }
|
||||
|
||||
let x = b1.a;
|
||||
>x : any
|
||||
>b1.a : any
|
||||
>b1 : any
|
||||
>a : any
|
||||
>x : boolean
|
||||
>b1.a : boolean
|
||||
>b1 : { "a": boolean; "b": string; }
|
||||
>a : boolean
|
||||
|
||||
import b2 = require('./b.json');
|
||||
>b2 : any
|
||||
>b2 : { "a": boolean; "b": string; }
|
||||
|
||||
if (x) {
|
||||
>x : any
|
||||
>x : boolean
|
||||
|
||||
let b = b2.b;
|
||||
>b : any
|
||||
>b2.b : any
|
||||
>b2 : any
|
||||
>b : any
|
||||
>b : string
|
||||
>b2.b : string
|
||||
>b2 : { "a": boolean; "b": string; }
|
||||
>b : string
|
||||
|
||||
x = (b1.b === b);
|
||||
>x = (b1.b === b) : boolean
|
||||
>x : any
|
||||
>x : boolean
|
||||
>(b1.b === b) : boolean
|
||||
>b1.b === b : boolean
|
||||
>b1.b : any
|
||||
>b1 : any
|
||||
>b : any
|
||||
>b : any
|
||||
>b1.b : string
|
||||
>b1 : { "a": boolean; "b": string; }
|
||||
>b : string
|
||||
>b : string
|
||||
}
|
||||
|
||||
=== tests/cases/compiler/b.json ===
|
||||
{
|
||||
>{ "a": true, "b": "hello"} : { "a": boolean; "b": string; }
|
||||
|
||||
"a": true,
|
||||
>"a" : boolean
|
||||
>true : true
|
||||
|
||||
"b": "hello"
|
||||
>"b" : string
|
||||
>"hello" : "hello"
|
||||
}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
tests/cases/compiler/file1.ts(1,21): error TS2307: Cannot find module './b'.
|
||||
|
||||
|
||||
==== tests/cases/compiler/file1.ts (1 errors) ====
|
||||
import b1 = require('./b'); // This should not resolve
|
||||
~~~~~
|
||||
!!! error TS2307: Cannot find module './b'.
|
||||
let x = b1.a;
|
||||
import b2 = require('./b.json');
|
||||
if (x) {
|
||||
let b = b2.b;
|
||||
x = (b1.b === b);
|
||||
}
|
||||
|
||||
==== tests/cases/compiler/b.json (0 errors) ====
|
||||
{
|
||||
"a": true,
|
||||
"b": "hello"
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
//// [tests/cases/compiler/requireOfJsonFileWithoutExtension.ts] ////
|
||||
|
||||
//// [file1.ts]
|
||||
import b1 = require('./b'); // This should not resolve
|
||||
let x = b1.a;
|
||||
import b2 = require('./b.json');
|
||||
if (x) {
|
||||
let b = b2.b;
|
||||
x = (b1.b === b);
|
||||
}
|
||||
|
||||
//// [b.json]
|
||||
{
|
||||
"a": true,
|
||||
"b": "hello"
|
||||
}
|
||||
|
||||
//// [b.json]
|
||||
{
|
||||
"a": true,
|
||||
"b": "hello"
|
||||
}
|
||||
//// [file1.js]
|
||||
"use strict";
|
||||
exports.__esModule = true;
|
||||
var b1 = require("./b"); // This should not resolve
|
||||
var x = b1.a;
|
||||
var b2 = require("./b.json");
|
||||
if (x) {
|
||||
var b = b2.b;
|
||||
x = (b1.b === b);
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
=== tests/cases/compiler/file1.ts ===
|
||||
import b1 = require('./b'); // This should not resolve
|
||||
>b1 : Symbol(b1, Decl(file1.ts, 0, 0))
|
||||
|
||||
let x = b1.a;
|
||||
>x : Symbol(x, Decl(file1.ts, 1, 3))
|
||||
>b1 : Symbol(b1, Decl(file1.ts, 0, 0))
|
||||
|
||||
import b2 = require('./b.json');
|
||||
>b2 : Symbol(b2, Decl(file1.ts, 1, 13))
|
||||
|
||||
if (x) {
|
||||
>x : Symbol(x, Decl(file1.ts, 1, 3))
|
||||
|
||||
let b = b2.b;
|
||||
>b : Symbol(b, Decl(file1.ts, 4, 7))
|
||||
>b2.b : Symbol("b", Decl(b.json, 1, 14))
|
||||
>b2 : Symbol(b2, Decl(file1.ts, 1, 13))
|
||||
>b : Symbol("b", Decl(b.json, 1, 14))
|
||||
|
||||
x = (b1.b === b);
|
||||
>x : Symbol(x, Decl(file1.ts, 1, 3))
|
||||
>b1 : Symbol(b1, Decl(file1.ts, 0, 0))
|
||||
>b : Symbol(b, Decl(file1.ts, 4, 7))
|
||||
}
|
||||
|
||||
=== tests/cases/compiler/b.json ===
|
||||
{
|
||||
"a": true,
|
||||
>"a" : Symbol("a", Decl(b.json, 0, 1))
|
||||
|
||||
"b": "hello"
|
||||
>"b" : Symbol("b", Decl(b.json, 1, 14))
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
=== tests/cases/compiler/file1.ts ===
|
||||
import b1 = require('./b'); // This should not resolve
|
||||
>b1 : any
|
||||
|
||||
let x = b1.a;
|
||||
>x : any
|
||||
>b1.a : any
|
||||
>b1 : any
|
||||
>a : any
|
||||
|
||||
import b2 = require('./b.json');
|
||||
>b2 : { "a": boolean; "b": string; }
|
||||
|
||||
if (x) {
|
||||
>x : any
|
||||
|
||||
let b = b2.b;
|
||||
>b : string
|
||||
>b2.b : string
|
||||
>b2 : { "a": boolean; "b": string; }
|
||||
>b : string
|
||||
|
||||
x = (b1.b === b);
|
||||
>x = (b1.b === b) : boolean
|
||||
>x : any
|
||||
>(b1.b === b) : boolean
|
||||
>b1.b === b : boolean
|
||||
>b1.b : any
|
||||
>b1 : any
|
||||
>b : any
|
||||
>b : string
|
||||
}
|
||||
|
||||
=== tests/cases/compiler/b.json ===
|
||||
{
|
||||
>{ "a": true, "b": "hello"} : { "a": boolean; "b": string; }
|
||||
|
||||
"a": true,
|
||||
>"a" : boolean
|
||||
>true : true
|
||||
|
||||
"b": "hello"
|
||||
>"b" : string
|
||||
>"hello" : "hello"
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
//// [tests/cases/compiler/requireOfJsonFileWithoutExtensionResolvesToTs.ts] ////
|
||||
|
||||
//// [file1.ts]
|
||||
import c1 = require('./c'); // resolves to c.ts
|
||||
let x2 = c1.a;
|
||||
import c2 = require('./c.json'); // resolves to c.json
|
||||
if (x2) {
|
||||
let b = c2.b;
|
||||
let x = (c1.b === b);
|
||||
}
|
||||
|
||||
//// [b.json]
|
||||
{
|
||||
"a": true,
|
||||
"b": "hello"
|
||||
}
|
||||
|
||||
//// [c.json]
|
||||
{
|
||||
"a": true,
|
||||
"b": "hello"
|
||||
}
|
||||
|
||||
//// [c.ts]
|
||||
export = { a: true, b: "hello" };
|
||||
|
||||
//// [c.js]
|
||||
"use strict";
|
||||
module.exports = { a: true, b: "hello" };
|
||||
//// [c.json]
|
||||
{
|
||||
"a": true,
|
||||
"b": "hello"
|
||||
}
|
||||
//// [file1.js]
|
||||
"use strict";
|
||||
exports.__esModule = true;
|
||||
var c1 = require("./c"); // resolves to c.ts
|
||||
var x2 = c1.a;
|
||||
var c2 = require("./c.json"); // resolves to c.json
|
||||
if (x2) {
|
||||
var b = c2.b;
|
||||
var x = (c1.b === b);
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
=== tests/cases/compiler/file1.ts ===
|
||||
import c1 = require('./c'); // resolves to c.ts
|
||||
>c1 : Symbol(c1, Decl(file1.ts, 0, 0))
|
||||
|
||||
let x2 = c1.a;
|
||||
>x2 : Symbol(x2, Decl(file1.ts, 1, 3))
|
||||
>c1.a : Symbol(a, Decl(c.ts, 0, 10))
|
||||
>c1 : Symbol(c1, Decl(file1.ts, 0, 0))
|
||||
>a : Symbol(a, Decl(c.ts, 0, 10))
|
||||
|
||||
import c2 = require('./c.json'); // resolves to c.json
|
||||
>c2 : Symbol(c2, Decl(file1.ts, 1, 14))
|
||||
|
||||
if (x2) {
|
||||
>x2 : Symbol(x2, Decl(file1.ts, 1, 3))
|
||||
|
||||
let b = c2.b;
|
||||
>b : Symbol(b, Decl(file1.ts, 4, 7))
|
||||
>c2.b : Symbol("b", Decl(c.json, 1, 14))
|
||||
>c2 : Symbol(c2, Decl(file1.ts, 1, 14))
|
||||
>b : Symbol("b", Decl(c.json, 1, 14))
|
||||
|
||||
let x = (c1.b === b);
|
||||
>x : Symbol(x, Decl(file1.ts, 5, 7))
|
||||
>c1.b : Symbol(b, Decl(c.ts, 0, 19))
|
||||
>c1 : Symbol(c1, Decl(file1.ts, 0, 0))
|
||||
>b : Symbol(b, Decl(c.ts, 0, 19))
|
||||
>b : Symbol(b, Decl(file1.ts, 4, 7))
|
||||
}
|
||||
|
||||
=== tests/cases/compiler/c.json ===
|
||||
{
|
||||
"a": true,
|
||||
>"a" : Symbol("a", Decl(c.json, 0, 1))
|
||||
|
||||
"b": "hello"
|
||||
>"b" : Symbol("b", Decl(c.json, 1, 14))
|
||||
}
|
||||
|
||||
=== tests/cases/compiler/c.ts ===
|
||||
export = { a: true, b: "hello" };
|
||||
>a : Symbol(a, Decl(c.ts, 0, 10))
|
||||
>b : Symbol(b, Decl(c.ts, 0, 19))
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
=== tests/cases/compiler/file1.ts ===
|
||||
import c1 = require('./c'); // resolves to c.ts
|
||||
>c1 : { a: boolean; b: string; }
|
||||
|
||||
let x2 = c1.a;
|
||||
>x2 : boolean
|
||||
>c1.a : boolean
|
||||
>c1 : { a: boolean; b: string; }
|
||||
>a : boolean
|
||||
|
||||
import c2 = require('./c.json'); // resolves to c.json
|
||||
>c2 : { "a": boolean; "b": string; }
|
||||
|
||||
if (x2) {
|
||||
>x2 : boolean
|
||||
|
||||
let b = c2.b;
|
||||
>b : string
|
||||
>c2.b : string
|
||||
>c2 : { "a": boolean; "b": string; }
|
||||
>b : string
|
||||
|
||||
let x = (c1.b === b);
|
||||
>x : boolean
|
||||
>(c1.b === b) : boolean
|
||||
>c1.b === b : boolean
|
||||
>c1.b : string
|
||||
>c1 : { a: boolean; b: string; }
|
||||
>b : string
|
||||
>b : string
|
||||
}
|
||||
|
||||
=== tests/cases/compiler/c.json ===
|
||||
{
|
||||
>{ "a": true, "b": "hello"} : { "a": boolean; "b": string; }
|
||||
|
||||
"a": true,
|
||||
>"a" : boolean
|
||||
>true : true
|
||||
|
||||
"b": "hello"
|
||||
>"b" : string
|
||||
>"hello" : "hello"
|
||||
}
|
||||
|
||||
=== tests/cases/compiler/c.ts ===
|
||||
export = { a: true, b: "hello" };
|
||||
>{ a: true, b: "hello" } : { a: boolean; b: string; }
|
||||
>a : boolean
|
||||
>true : true
|
||||
>b : string
|
||||
>"hello" : "hello"
|
||||
|
||||
@@ -19,8 +19,6 @@
|
||||
"File '/node_modules/xyz.jsx' does not exist.",
|
||||
"Loading module 'xyz' from 'node_modules' folder, target file type 'Json'.",
|
||||
"Directory '/foo/bar/node_modules' does not exist, skipping all lookups in it.",
|
||||
"File '/foo/node_modules/xyz.json' does not exist.",
|
||||
"File '/node_modules/xyz.json' does not exist.",
|
||||
"======== Module name 'xyz' was not resolved. ========",
|
||||
"======== Resolving module 'pdq' from '/foo/bar/a.ts'. ========",
|
||||
"Module resolution kind is not specified, using 'NodeJs'.",
|
||||
@@ -42,8 +40,6 @@
|
||||
"File '/node_modules/pdq.jsx' does not exist.",
|
||||
"Loading module 'pdq' from 'node_modules' folder, target file type 'Json'.",
|
||||
"Directory '/foo/bar/node_modules' does not exist, skipping all lookups in it.",
|
||||
"File '/foo/node_modules/pdq.json' does not exist.",
|
||||
"File '/node_modules/pdq.json' does not exist.",
|
||||
"======== Module name 'pdq' was not resolved. ========",
|
||||
"======== Resolving module 'abc' from '/foo/bar/a.ts'. ========",
|
||||
"Module resolution kind is not specified, using 'NodeJs'.",
|
||||
@@ -65,8 +61,6 @@
|
||||
"File '/node_modules/abc.jsx' does not exist.",
|
||||
"Loading module 'abc' from 'node_modules' folder, target file type 'Json'.",
|
||||
"Directory '/foo/bar/node_modules' does not exist, skipping all lookups in it.",
|
||||
"File '/foo/node_modules/abc.json' does not exist.",
|
||||
"File '/node_modules/abc.json' does not exist.",
|
||||
"======== Module name 'abc' was not resolved. ========",
|
||||
"======== Resolving type reference directive 'grumpy', containing file '/foo/bar/__inferred type names__.ts', root directory '/foo/node_modules/@types,/node_modules/@types'. ========",
|
||||
"Resolving with primary search path '/foo/node_modules/@types, /node_modules/@types'.",
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
"File '/node_modules/xyz.jsx' does not exist.",
|
||||
"Loading module 'xyz' from 'node_modules' folder, target file type 'Json'.",
|
||||
"Directory '/src/node_modules' does not exist, skipping all lookups in it.",
|
||||
"File '/node_modules/xyz.json' does not exist.",
|
||||
"======== Module name 'xyz' was not resolved. ========",
|
||||
"======== Resolving type reference directive 'foo', containing file '/src/__inferred type names__.ts', root directory '/node_modules/@types'. ========",
|
||||
"Resolving with primary search path '/node_modules/@types'.",
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// @allowJs: true
|
||||
|
||||
// @Filename: file1.ts
|
||||
import b1 = require('./b');
|
||||
import b1 = require('./b.json');
|
||||
let x = b1.a;
|
||||
import b2 = require('./b.json');
|
||||
if (x) {
|
||||
|
||||
24
tests/cases/compiler/requireOfJsonFileNonRelative.ts
Normal file
24
tests/cases/compiler/requireOfJsonFileNonRelative.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
// @module: commonjs
|
||||
// @outdir: out/
|
||||
// @allowJs: true
|
||||
|
||||
// @Filename: /src/projects/file1.ts
|
||||
import b1 = require('b.json');
|
||||
let x = b1.a;
|
||||
import b2 = require('c.json');
|
||||
if (x) {
|
||||
let b = b2.b;
|
||||
x = (b1.b === b);
|
||||
}
|
||||
|
||||
// @Filename: /src/projects/node_modules/b.json
|
||||
{
|
||||
"a": true,
|
||||
"b": "hello"
|
||||
}
|
||||
|
||||
// @Filename: /src/node_modules/c.json
|
||||
{
|
||||
"a": true,
|
||||
"b": "hello"
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
// @module: commonjs
|
||||
// @outdir: out/
|
||||
// @allowJs: true
|
||||
|
||||
// @Filename: /src/projects/file1.ts
|
||||
import d = require("d.json"); // Should fail
|
||||
import e = require("e"); // Should fail
|
||||
|
||||
// @Filename: /src/projects/node_modules/b.json
|
||||
{
|
||||
"a": true,
|
||||
"b": "hello"
|
||||
}
|
||||
|
||||
// @Filename: /src/projects/node_modules/e.json
|
||||
{
|
||||
"a": true,
|
||||
"b": "hello"
|
||||
}
|
||||
|
||||
// @Filename: /src/node_modules/c.json
|
||||
{
|
||||
"a": true,
|
||||
"b": "hello"
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
// @module: commonjs
|
||||
// @outdir: out/
|
||||
// @allowJs: true
|
||||
|
||||
// @Filename: /src/projects/file1.ts
|
||||
import f = require("f"); // should work to f.ts
|
||||
let fnumber: number = f;
|
||||
|
||||
// @Filename: /src/node_modules/f.json
|
||||
{
|
||||
"a": true,
|
||||
"b": "hello"
|
||||
}
|
||||
|
||||
// @Filename: /src/node_modules/f.ts
|
||||
export = 10;
|
||||
@@ -3,7 +3,7 @@
|
||||
// @allowJs: true
|
||||
|
||||
// @Filename: file1.ts
|
||||
import b1 = require('./b');
|
||||
import b1 = require('./b.json');
|
||||
let x = b1;
|
||||
import b2 = require('./b.json');
|
||||
if (x) {
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// @allowJs: true
|
||||
|
||||
// @Filename: file1.ts
|
||||
import b1 = require('./b');
|
||||
import b1 = require('./b.json');
|
||||
let x = b1.a;
|
||||
import b2 = require('./b.json');
|
||||
if (x) {
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// @allowJs: true
|
||||
|
||||
// @Filename: file1.ts
|
||||
import b1 = require('./b');
|
||||
import b1 = require('./b.json');
|
||||
let x = b1.a;
|
||||
import b2 = require('./b.json');
|
||||
if (x) {
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// @outdir: out/
|
||||
|
||||
// @Filename: file1.ts
|
||||
import b1 = require('./b');
|
||||
import b1 = require('./b.json');
|
||||
let x = b1.a;
|
||||
import b2 = require('./b.json');
|
||||
if (x) {
|
||||
|
||||
18
tests/cases/compiler/requireOfJsonFileWithoutExtension.ts
Normal file
18
tests/cases/compiler/requireOfJsonFileWithoutExtension.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
// @module: commonjs
|
||||
// @outdir: out/
|
||||
// @allowJs: true
|
||||
|
||||
// @Filename: file1.ts
|
||||
import b1 = require('./b'); // This should not resolve
|
||||
let x = b1.a;
|
||||
import b2 = require('./b.json');
|
||||
if (x) {
|
||||
let b = b2.b;
|
||||
x = (b1.b === b);
|
||||
}
|
||||
|
||||
// @Filename: b.json
|
||||
{
|
||||
"a": true,
|
||||
"b": "hello"
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
// @module: commonjs
|
||||
// @outdir: out/
|
||||
// @allowJs: true
|
||||
|
||||
// @Filename: file1.ts
|
||||
import c1 = require('./c'); // resolves to c.ts
|
||||
let x2 = c1.a;
|
||||
import c2 = require('./c.json'); // resolves to c.json
|
||||
if (x2) {
|
||||
let b = c2.b;
|
||||
let x = (c1.b === b);
|
||||
}
|
||||
|
||||
// @Filename: b.json
|
||||
{
|
||||
"a": true,
|
||||
"b": "hello"
|
||||
}
|
||||
|
||||
// @Filename: c.json
|
||||
{
|
||||
"a": true,
|
||||
"b": "hello"
|
||||
}
|
||||
|
||||
// @Filename: c.ts
|
||||
export = { a: true, b: "hello" };
|
||||
Reference in New Issue
Block a user