Merge pull request #22167 from Microsoft/requireJson

Resolve the modue names with "modulename.json" to json files when doing node module resolution
This commit is contained in:
Sheetal Nandi
2018-05-04 12:42:10 -07:00
committed by GitHub
87 changed files with 2489 additions and 139 deletions
+11
View File
@@ -281,6 +281,10 @@ namespace ts {
return InternalSymbolName.Index;
case SyntaxKind.ExportDeclaration:
return InternalSymbolName.ExportStar;
case SyntaxKind.SourceFile:
// json file should behave as
// module.exports = ...
return InternalSymbolName.ExportEquals;
case SyntaxKind.BinaryExpression:
if (getSpecialPropertyAssignmentKind(node as BinaryExpression) === SpecialPropertyAssignmentKind.ModuleExports) {
// module.exports = ...
@@ -2234,6 +2238,13 @@ namespace ts {
if (isExternalModule(file)) {
bindSourceFileAsExternalModule();
}
else if (isJsonSourceFile(file)) {
bindSourceFileAsExternalModule();
// Create symbol equivalent for the module.exports = {}
const originalSymbol = file.symbol;
declareSymbol(file.symbol.exports, file.symbol, file, SymbolFlags.Property, SymbolFlags.All);
file.symbol = originalSymbol;
}
}
function bindSourceFileAsExternalModule() {
+6 -2
View File
@@ -2207,7 +2207,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);
@@ -4718,6 +4718,10 @@ namespace ts {
return links.type = anyType;
}
// Handle export default expressions
if (isSourceFile(declaration)) {
const jsonSourceFile = cast(declaration, isJsonSourceFile);
return links.type = jsonSourceFile.statements.length ? checkExpression(jsonSourceFile.statements[0].expression) : emptyObjectType;
}
if (declaration.kind === SyntaxKind.ExportAssignment) {
return links.type = checkExpression((<ExportAssignment>declaration).expression);
}
@@ -15597,7 +15601,7 @@ namespace ts {
const contextualType = getApparentTypeOfContextualType(node);
const contextualTypeHasPattern = contextualType && contextualType.pattern &&
(contextualType.pattern.kind === SyntaxKind.ObjectBindingPattern || contextualType.pattern.kind === SyntaxKind.ObjectLiteralExpression);
const isInJSFile = isInJavaScriptFile(node);
const isInJSFile = isInJavaScriptFile(node) && !isInJsonFile(node);
const isJSObjectLiteral = !contextualType && isInJSFile;
let typeFlags: TypeFlags = 0;
let patternWithComputedProperties = false;
+95 -84
View File
@@ -501,6 +501,12 @@ namespace ts {
category: Diagnostics.Advanced_Options,
description: Diagnostics.Enable_tracing_of_the_name_resolution_process
},
{
name: "resolveJsonModule",
type: "boolean",
category: Diagnostics.Advanced_Options,
description: Diagnostics.Include_modules_imported_with_json_extension
},
{
name: "listFiles",
type: "boolean",
@@ -953,9 +959,9 @@ namespace ts {
* Read tsconfig.json file
* @param fileName The path to the config file
*/
export function readJsonConfigFile(fileName: string, readFile: (path: string) => string | undefined): JsonSourceFile {
export function readJsonConfigFile(fileName: string, readFile: (path: string) => string | undefined): TsConfigSourceFile {
const textOrDiagnostic = tryReadFile(fileName, readFile);
return isString(textOrDiagnostic) ? parseJsonText(fileName, textOrDiagnostic) : <JsonSourceFile>{ parseDiagnostics: [textOrDiagnostic] };
return isString(textOrDiagnostic) ? parseJsonText(fileName, textOrDiagnostic) : <TsConfigSourceFile>{ parseDiagnostics: [textOrDiagnostic] };
}
function tryReadFile(fileName: string, readFile: (path: string) => string | undefined): string | Diagnostic {
@@ -973,58 +979,62 @@ namespace ts {
return arrayToMap(options, option => option.name);
}
let _tsconfigRootOptions: Map<CommandLineOption>;
let _tsconfigRootOptions: TsConfigOnlyOption;
function getTsconfigRootOptionsMap() {
if (_tsconfigRootOptions === undefined) {
_tsconfigRootOptions = commandLineOptionsToMap([
{
name: "compilerOptions",
type: "object",
elementOptions: commandLineOptionsToMap(optionDeclarations),
extraKeyDiagnosticMessage: Diagnostics.Unknown_compiler_option_0
},
{
name: "typingOptions",
type: "object",
elementOptions: commandLineOptionsToMap(typeAcquisitionDeclarations),
extraKeyDiagnosticMessage: Diagnostics.Unknown_type_acquisition_option_0
},
{
name: "typeAcquisition",
type: "object",
elementOptions: commandLineOptionsToMap(typeAcquisitionDeclarations),
extraKeyDiagnosticMessage: Diagnostics.Unknown_type_acquisition_option_0
},
{
name: "extends",
type: "string"
},
{
name: "files",
type: "list",
element: {
_tsconfigRootOptions = {
name: undefined, // should never be needed since this is root
type: "object",
elementOptions: commandLineOptionsToMap([
{
name: "compilerOptions",
type: "object",
elementOptions: commandLineOptionsToMap(optionDeclarations),
extraKeyDiagnosticMessage: Diagnostics.Unknown_compiler_option_0
},
{
name: "typingOptions",
type: "object",
elementOptions: commandLineOptionsToMap(typeAcquisitionDeclarations),
extraKeyDiagnosticMessage: Diagnostics.Unknown_type_acquisition_option_0
},
{
name: "typeAcquisition",
type: "object",
elementOptions: commandLineOptionsToMap(typeAcquisitionDeclarations),
extraKeyDiagnosticMessage: Diagnostics.Unknown_type_acquisition_option_0
},
{
name: "extends",
type: "string"
},
{
name: "files",
type: "string"
}
},
{
name: "include",
type: "list",
element: {
type: "list",
element: {
name: "files",
type: "string"
}
},
{
name: "include",
type: "string"
}
},
{
name: "exclude",
type: "list",
element: {
type: "list",
element: {
name: "include",
type: "string"
}
},
{
name: "exclude",
type: "string"
}
},
compileOnSaveCommandLineOption
]);
type: "list",
element: {
name: "exclude",
type: "string"
}
},
compileOnSaveCommandLineOption
])
};
}
return _tsconfigRootOptions;
}
@@ -1061,23 +1071,30 @@ namespace ts {
* Convert the json syntax tree into the json value
*/
export function convertToObject(sourceFile: JsonSourceFile, errors: Push<Diagnostic>): any {
return convertToObjectWorker(sourceFile, errors, /*knownRootOptions*/ undefined, /*jsonConversionNotifier*/ undefined);
return convertToObjectWorker(sourceFile, errors, /*returnValue*/ true, /*knownRootOptions*/ undefined, /*jsonConversionNotifier*/ undefined);
}
/**
* Convert the json syntax tree into the json value
* Convert the json syntax tree into the json value and report errors
* This returns the json value (apart from checking errors) only if returnValue provided is true.
* Otherwise it just checks the errors and returns undefined
*/
function convertToObjectWorker(
/*@internal*/
export function convertToObjectWorker(
sourceFile: JsonSourceFile,
errors: Push<Diagnostic>,
knownRootOptions: Map<CommandLineOption> | undefined,
returnValue: boolean,
knownRootOptions: CommandLineOption | undefined,
jsonConversionNotifier: JsonConversionNotifier | undefined): any {
if (!sourceFile.jsonObject) {
return {};
if (!sourceFile.statements.length) {
return returnValue ? {} : undefined;
}
return convertObjectLiteralExpressionToJson(sourceFile.jsonObject, knownRootOptions,
/*extraKeyDiagnosticMessage*/ undefined, /*parentOption*/ undefined);
return convertPropertyValueToJson(sourceFile.statements[0].expression, knownRootOptions);
function isRootOptionMap(knownOptions: Map<CommandLineOption> | undefined) {
return knownRootOptions && (knownRootOptions as TsConfigOnlyOption).elementOptions === knownOptions;
}
function convertObjectLiteralExpressionToJson(
node: ObjectLiteralExpression,
@@ -1085,7 +1102,7 @@ namespace ts {
extraKeyDiagnosticMessage: DiagnosticMessage | undefined,
parentOption: string | undefined
): any {
const result: any = {};
const result: any = returnValue ? {} : undefined;
for (const element of node.properties) {
if (element.kind !== SyntaxKind.PropertyAssignment) {
errors.push(createDiagnosticForNodeInSourceFile(sourceFile, element, Diagnostics.Property_assignment_expected));
@@ -1106,11 +1123,13 @@ namespace ts {
}
const value = convertPropertyValueToJson(element.initializer, option);
if (typeof keyText !== "undefined") {
result[keyText] = value;
if (returnValue) {
result[keyText] = value;
}
// Notify key value set, if user asked for it
if (jsonConversionNotifier &&
// Current callbacks are only on known parent option or if we are setting values in the root
(parentOption || knownOptions === knownRootOptions)) {
(parentOption || isRootOptionMap(knownOptions))) {
const isValidOptionValue = isCompilerOptionsValue(option, value);
if (parentOption) {
if (isValidOptionValue) {
@@ -1118,7 +1137,7 @@ namespace ts {
jsonConversionNotifier.onSetValidOptionKeyValueInParent(parentOption, option, value);
}
}
else if (knownOptions === knownRootOptions) {
else if (isRootOptionMap(knownOptions)) {
if (isValidOptionValue) {
// Notify about the valid root key value being set
jsonConversionNotifier.onSetValidOptionKeyValueInRoot(keyText, element.name, value, element.initializer);
@@ -1137,8 +1156,8 @@ namespace ts {
function convertArrayLiteralExpressionToJson(
elements: NodeArray<Expression>,
elementOption: CommandLineOption | undefined
): any[] {
return elements.map(element => convertPropertyValueToJson(element, elementOption));
): any[] | void {
return (returnValue ? elements.map : elements.forEach).call(elements, (element: Expression) => convertPropertyValueToJson(element, elementOption));
}
function convertPropertyValueToJson(valueExpression: Expression, option: CommandLineOption): any {
@@ -1433,12 +1452,12 @@ namespace ts {
* @param basePath A root directory to resolve relative path entries in the config
* file to. e.g. outDir
*/
export function parseJsonSourceFileConfigFileContent(sourceFile: JsonSourceFile, host: ParseConfigHost, basePath: string, existingOptions?: CompilerOptions, configFileName?: string, resolutionStack?: Path[], extraFileExtensions?: ReadonlyArray<FileExtensionInfo>): ParsedCommandLine {
export function parseJsonSourceFileConfigFileContent(sourceFile: TsConfigSourceFile, host: ParseConfigHost, basePath: string, existingOptions?: CompilerOptions, configFileName?: string, resolutionStack?: Path[], extraFileExtensions?: ReadonlyArray<FileExtensionInfo>): ParsedCommandLine {
return parseJsonConfigFileContentWorker(/*json*/ undefined, sourceFile, host, basePath, existingOptions, configFileName, resolutionStack, extraFileExtensions);
}
/*@internal*/
export function setConfigFileInOptions(options: CompilerOptions, configFile: JsonSourceFile) {
export function setConfigFileInOptions(options: CompilerOptions, configFile: TsConfigSourceFile) {
if (configFile) {
Object.defineProperty(options, "configFile", { enumerable: false, writable: false, value: configFile });
}
@@ -1466,7 +1485,7 @@ namespace ts {
*/
function parseJsonConfigFileContentWorker(
json: any,
sourceFile: JsonSourceFile,
sourceFile: TsConfigSourceFile,
host: ParseConfigHost,
basePath: string,
existingOptions: CompilerOptions = {},
@@ -1587,7 +1606,7 @@ namespace ts {
*/
function parseConfig(
json: any,
sourceFile: JsonSourceFile,
sourceFile: TsConfigSourceFile,
host: ParseConfigHost,
basePath: string,
configFileName: string,
@@ -1664,7 +1683,7 @@ namespace ts {
}
function parseOwnConfigOfJsonSourceFile(
sourceFile: JsonSourceFile,
sourceFile: TsConfigSourceFile,
host: ParseConfigHost,
basePath: string,
configFileName: string | undefined,
@@ -1711,7 +1730,7 @@ namespace ts {
}
}
};
const json = convertToObjectWorker(sourceFile, errors, getTsconfigRootOptionsMap(), optionsIterator);
const json = convertToObjectWorker(sourceFile, errors, /*returnValue*/ true, getTsconfigRootOptionsMap(), optionsIterator);
if (!typeAcquisition) {
if (typingOptionstypeAcquisition) {
typeAcquisition = (typingOptionstypeAcquisition.enableAutoDiscovery !== undefined) ?
@@ -1754,7 +1773,7 @@ namespace ts {
}
function getExtendedConfig(
sourceFile: JsonSourceFile,
sourceFile: TsConfigSourceFile,
extendedConfigPath: string,
host: ParseConfigHost,
basePath: string,
@@ -2006,7 +2025,7 @@ namespace ts {
host: ParseConfigHost,
errors: Push<Diagnostic>,
extraFileExtensions: ReadonlyArray<FileExtensionInfo>,
jsonSourceFile: JsonSourceFile
jsonSourceFile: TsConfigSourceFile
): ExpandResult {
basePath = normalizePath(basePath);
let validatedIncludeSpecs: ReadonlyArray<string>, validatedExcludeSpecs: ReadonlyArray<string>;
@@ -2107,7 +2126,7 @@ namespace ts {
};
}
function validateSpecs(specs: ReadonlyArray<string>, errors: Push<Diagnostic>, allowTrailingRecursion: boolean, jsonSourceFile: JsonSourceFile, specKey: string): ReadonlyArray<string> {
function validateSpecs(specs: ReadonlyArray<string>, errors: Push<Diagnostic>, allowTrailingRecursion: boolean, jsonSourceFile: TsConfigSourceFile, specKey: string): ReadonlyArray<string> {
return specs.filter(spec => {
const diag = specToDiagnostic(spec, allowTrailingRecursion);
if (diag !== undefined) {
@@ -2117,18 +2136,10 @@ namespace ts {
});
function createDiagnostic(message: DiagnosticMessage, spec: string): Diagnostic {
if (jsonSourceFile && jsonSourceFile.jsonObject) {
for (const property of getPropertyAssignment(jsonSourceFile.jsonObject, specKey)) {
if (isArrayLiteralExpression(property.initializer)) {
for (const element of property.initializer.elements) {
if (isStringLiteral(element) && element.text === spec) {
return createDiagnosticForNodeInSourceFile(jsonSourceFile, element, message, spec);
}
}
}
}
}
return createCompilerDiagnostic(message, spec);
const element = getTsConfigPropArrayElementValue(jsonSourceFile, specKey, spec);
return element ?
createDiagnosticForNodeInSourceFile(jsonSourceFile, element, message, spec) :
createCompilerDiagnostic(message, spec);
}
}
+5 -1
View File
@@ -2966,7 +2966,7 @@ namespace ts {
}
}
const extensionsToRemove = [Extension.Dts, Extension.Ts, Extension.Js, Extension.Tsx, Extension.Jsx];
const extensionsToRemove = [Extension.Dts, Extension.Ts, Extension.Js, Extension.Tsx, Extension.Jsx, Extension.Json];
export function removeFileExtension(path: string): string {
for (const ext of extensionsToRemove) {
const extensionless = tryRemoveExtension(path, ext);
@@ -3307,6 +3307,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.
+9
View File
@@ -2806,6 +2806,10 @@
"category": "Error",
"code": 5069
},
"Option '--resolveJsonModule' cannot be specified without 'node' module resolution strategy.": {
"category": "Error",
"code": 5070
},
"Generates a sourcemap for each corresponding '.d.ts' file.": {
"category": "Message",
@@ -3543,6 +3547,11 @@
"code": 6196,
"reportsUnnecessary": true
},
"Include modules imported with '.json' extension": {
"category": "Message",
"code": 6197
},
"Variable '{0}' implicitly has an '{1}' type.": {
"category": "Error",
"code": 7005
+7 -1
View File
@@ -67,6 +67,10 @@ namespace ts {
// For TypeScript, the only time to emit with a '.jsx' extension, is on JSX input, and JsxEmit.Preserve
/* @internal */
export function getOutputExtension(sourceFile: SourceFile, options: CompilerOptions): Extension {
if (isJsonSourceFile(sourceFile)) {
return Extension.Json;
}
if (options.jsx === JsxEmit.Preserve) {
if (isSourceFileJavaScript(sourceFile)) {
if (fileExtensionIs(sourceFile.fileName, Extension.Jsx)) {
@@ -1682,7 +1686,9 @@ namespace ts {
function emitExpressionStatement(node: ExpressionStatement) {
emitExpression(node.expression);
writeSemicolon();
if (!isJsonSourceFile(currentSourceFile)) {
writeSemicolon();
}
}
function emitIfStatement(node: IfStatement) {
+2 -4
View File
@@ -24,10 +24,8 @@ namespace ts {
if (!elements || elements === emptyArray) {
elements = [];
}
else {
if (isNodeArray(elements)) {
return elements;
}
else if (isNodeArray(elements)) {
return elements;
}
const array = <NodeArray<T>>elements;
+17 -3
View File
@@ -45,6 +45,7 @@ namespace ts {
enum Extensions {
TypeScript, /** '.ts', '.tsx', or '.d.ts' */
JavaScript, /** '.js' or '.jsx' */
Json, /** '.json' */
DtsOnly /** Only '.d.ts' */
}
@@ -746,7 +747,11 @@ namespace ts {
const failedLookupLocations: string[] = [];
const state: ModuleResolutionState = { compilerOptions, host, traceEnabled };
const result = jsOnly ? tryResolve(Extensions.JavaScript) : (tryResolve(Extensions.TypeScript) || tryResolve(Extensions.JavaScript));
const result = jsOnly ?
tryResolve(Extensions.JavaScript) :
(tryResolve(Extensions.TypeScript) ||
tryResolve(Extensions.JavaScript) ||
(compilerOptions.resolveJsonModule ? tryResolve(Extensions.Json) : undefined));
if (result && result.value) {
const { resolved, originalPath, isExternalLibraryImport } = result.value;
return createResolvedModuleWithFailedLookupLocations(resolved, originalPath, isExternalLibraryImport, failedLookupLocations);
@@ -898,6 +903,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) {
@@ -933,6 +943,8 @@ namespace ts {
return tryExtension(Extension.Ts) || tryExtension(Extension.Tsx) || tryExtension(Extension.Dts);
case Extensions.JavaScript:
return tryExtension(Extension.Js) || tryExtension(Extension.Jsx);
case Extensions.Json:
return tryExtension(Extension.Json);
}
function tryExtension(ext: Extension): PathAndExtension | undefined {
@@ -1030,7 +1042,7 @@ namespace ts {
}
function loadModuleFromPackageJson(jsonContent: PackageJsonPathFields, extensions: Extensions, candidate: string, failedLookupLocations: Push<string>, state: ModuleResolutionState): PathAndExtension | undefined {
const file = tryReadPackageJsonFields(extensions !== Extensions.JavaScript, jsonContent, candidate, state);
const file = tryReadPackageJsonFields(extensions !== Extensions.JavaScript && extensions !== Extensions.Json, jsonContent, candidate, state);
if (!file) {
return undefined;
}
@@ -1069,6 +1081,8 @@ namespace ts {
switch (extensions) {
case Extensions.JavaScript:
return extension === Extension.Js || extension === Extension.Jsx;
case Extensions.Json:
return extension === Extension.Json;
case Extensions.TypeScript:
return extension === Extension.Ts || extension === Extension.Tsx || extension === Extension.Dts;
case Extensions.DtsOnly:
@@ -1144,7 +1158,7 @@ namespace ts {
if (packageResult) {
return packageResult;
}
if (extensions !== Extensions.JavaScript) {
if (extensions !== Extensions.JavaScript && extensions !== Extensions.Json) {
const nodeModulesAtTypes = combinePaths(nodeModulesFolder, "@types");
let nodeModulesAtTypesExists = nodeModulesFolderExists;
if (nodeModulesFolderExists && !directoryProbablyExists(nodeModulesAtTypes, state.host)) {
+50 -9
View File
@@ -670,6 +670,13 @@ namespace ts {
export function parseSourceFile(fileName: string, sourceText: string, languageVersion: ScriptTarget, syntaxCursor: IncrementalParser.SyntaxCursor, setParentNodes?: boolean, scriptKind?: ScriptKind): SourceFile {
scriptKind = ensureScriptKind(fileName, scriptKind);
if (scriptKind === ScriptKind.JSON) {
const result = parseJsonText(fileName, sourceText, languageVersion, syntaxCursor, setParentNodes);
convertToObjectWorker(result, result.parseDiagnostics, /*returnValue*/ false, /*knownRootOptions*/ undefined, /*jsonConversionNotifier*/ undefined);
result.typeReferenceDirectives = emptyArray;
result.amdDependencies = emptyArray;
return result;
}
initializeState(sourceText, languageVersion, syntaxCursor, scriptKind);
@@ -691,27 +698,59 @@ namespace ts {
return isInvalid ? entityName : undefined;
}
export function parseJsonText(fileName: string, sourceText: string): JsonSourceFile {
initializeState(sourceText, ScriptTarget.ES2015, /*syntaxCursor*/ undefined, ScriptKind.JSON);
export function parseJsonText(fileName: string, sourceText: string, languageVersion: ScriptTarget = ScriptTarget.ES2015, syntaxCursor?: IncrementalParser.SyntaxCursor, setParentNodes?: boolean): JsonSourceFile {
initializeState(sourceText, languageVersion, syntaxCursor, ScriptKind.JSON);
// Set source file so that errors will be reported with this file name
sourceFile = createSourceFile(fileName, ScriptTarget.ES2015, ScriptKind.JSON, /*isDeclaration*/ false);
const result = <JsonSourceFile>sourceFile;
// Prime the scanner.
nextToken();
const pos = getNodePos();
if (token() === SyntaxKind.EndOfFileToken) {
sourceFile.statements = createNodeArray([], pos, pos);
sourceFile.endOfFileToken = parseTokenNode<EndOfFileToken>();
}
else if (token() === SyntaxKind.OpenBraceToken ||
lookAhead(() => token() === SyntaxKind.StringLiteral)) {
result.jsonObject = parseObjectLiteralExpression();
else {
const statement = createNode(SyntaxKind.ExpressionStatement) as JsonObjectExpressionStatement;
switch (token()) {
case SyntaxKind.OpenBracketToken:
statement.expression = parseArrayLiteralExpression();
break;
case SyntaxKind.TrueKeyword:
case SyntaxKind.FalseKeyword:
case SyntaxKind.NullKeyword:
statement.expression = parseTokenNode<BooleanLiteral | NullLiteral>();
break;
case SyntaxKind.MinusToken:
if (lookAhead(() => nextToken() === SyntaxKind.NumericLiteral && nextToken() !== SyntaxKind.ColonToken)) {
statement.expression = parsePrefixUnaryExpression() as JsonMinusNumericLiteral;
}
else {
statement.expression = parseObjectLiteralExpression();
}
break;
case SyntaxKind.NumericLiteral:
case SyntaxKind.StringLiteral:
if (lookAhead(() => nextToken() !== SyntaxKind.ColonToken)) {
statement.expression = parseLiteralNode() as StringLiteral | NumericLiteral;
break;
}
// falls through
default:
statement.expression = parseObjectLiteralExpression();
break;
}
finishNode(statement);
sourceFile.statements = createNodeArray([statement], pos);
sourceFile.endOfFileToken = parseExpectedToken(SyntaxKind.EndOfFileToken, Diagnostics.Unexpected_token);
}
else {
parseExpected(SyntaxKind.OpenBraceToken);
if (setParentNodes) {
fixupParentReferences(sourceFile);
}
sourceFile.parseDiagnostics = parseDiagnostics;
const result = sourceFile as JsonSourceFile;
clearState();
return result;
}
@@ -739,9 +778,11 @@ namespace ts {
switch (scriptKind) {
case ScriptKind.JS:
case ScriptKind.JSX:
case ScriptKind.JSON:
contextFlags = NodeFlags.JavaScriptFile;
break;
case ScriptKind.JSON:
contextFlags = NodeFlags.JavaScriptFile | NodeFlags.JsonFile;
break;
default:
contextFlags = NodeFlags.None;
break;
Executable → Regular
+11 -3
View File
@@ -1988,7 +1988,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;
@@ -2200,6 +2200,12 @@ namespace ts {
}
}
if (options.resolveJsonModule) {
if (getEmitModuleResolutionKind(options) !== ModuleResolutionKind.NodeJs) {
createDiagnosticForOptionName(Diagnostics.Option_resolveJsonModule_cannot_be_specified_without_node_module_resolution_strategy, "resolveJsonModule");
}
}
// there has to be common source directory if user specified --outdir || --sourceRoot
// if user specified --mapRoot, there needs to be common source directory if there would be multiple files being emitted
if (options.outDir || // there is --outDir specified
@@ -2355,8 +2361,9 @@ namespace ts {
function getCompilerOptionsObjectLiteralSyntax() {
if (_compilerOptionsObjectLiteralSyntax === undefined) {
_compilerOptionsObjectLiteralSyntax = null; // tslint:disable-line:no-null-keyword
if (options.configFile && options.configFile.jsonObject) {
for (const prop of getPropertyAssignment(options.configFile.jsonObject, "compilerOptions")) {
const jsonObjectLiteral = getTsConfigObjectLiteralExpression(options.configFile);
if (jsonObjectLiteral) {
for (const prop of getPropertyAssignment(jsonObjectLiteral, "compilerOptions")) {
if (isObjectLiteralExpression(prop.initializer)) {
_compilerOptionsObjectLiteralSyntax = prop.initializer;
break;
@@ -2426,6 +2433,7 @@ namespace ts {
switch (extension) {
case Extension.Ts:
case Extension.Dts:
case Extension.Json: // Since module is resolved to json file only when --resolveJsonModule, we dont need further check
// These are always allowed.
return undefined;
case Extension.Tsx:
+18 -3
View File
@@ -505,6 +505,7 @@ namespace ts {
JSDoc = 1 << 21, // If node was parsed inside jsdoc
/* @internal */ Ambient = 1 << 22, // If node was inside an ambient context -- a declaration file, or inside something with the `declare` modifier.
/* @internal */ InWithStatement = 1 << 23, // If any ancestor of node was the `statement` of a WithStatement (not the `expression`)
JsonFile = 1 << 24, // If node was parsed in a Json
BlockScoped = Let | Const,
@@ -2620,10 +2621,23 @@ namespace ts {
}
export interface JsonSourceFile extends SourceFile {
jsonObject?: ObjectLiteralExpression;
statements: NodeArray<JsonObjectExpressionStatement>;
}
export interface TsConfigSourceFile extends JsonSourceFile {
extendedSourceFiles?: string[];
}
export interface JsonMinusNumericLiteral extends PrefixUnaryExpression {
kind: SyntaxKind.PrefixUnaryExpression;
operator: SyntaxKind.MinusToken;
operand: NumericLiteral;
}
export interface JsonObjectExpressionStatement extends ExpressionStatement {
expression: ObjectLiteralExpression | ArrayLiteralExpression | JsonMinusNumericLiteral | NumericLiteral | StringLiteral | BooleanLiteral | NullLiteral;
}
export interface ScriptReferenceHost {
getCompilerOptions(): CompilerOptions;
getSourceFile(fileName: string): SourceFile | undefined;
@@ -4176,7 +4190,7 @@ namespace ts {
checkJs?: boolean;
/* @internal */ configFilePath?: string;
/** configFile is set as non enumerable property so as to avoid checking of json source files */
/* @internal */ readonly configFile?: JsonSourceFile;
/* @internal */ readonly configFile?: TsConfigSourceFile;
declaration?: boolean;
declarationMap?: boolean;
emitDeclarationOnly?: boolean;
@@ -4250,6 +4264,7 @@ namespace ts {
/* @internal */ suppressOutputPathCheck?: boolean;
target?: ScriptTarget;
traceResolution?: boolean;
resolveJsonModule?: boolean;
types?: string[];
/** Paths used to compute primary types search locations */
typeRoots?: string[];
@@ -4257,7 +4272,7 @@ namespace ts {
/*@internal*/ watch?: boolean;
esModuleInterop?: boolean;
[option: string]: CompilerOptionsValue | JsonSourceFile | undefined;
[option: string]: CompilerOptionsValue | TsConfigSourceFile | undefined;
}
export interface TypeAcquisition {
+25
View File
@@ -724,6 +724,11 @@ namespace ts {
return (file.externalModuleIndicator || file.commonJsModuleIndicator) !== undefined;
}
export function isJsonSourceFile(file: SourceFile): file is JsonSourceFile {
return file.scriptKind === ScriptKind.JSON;
}
export function isConstEnumDeclaration(node: Node): boolean {
return node.kind === SyntaxKind.EnumDeclaration && isConst(node);
}
@@ -1071,6 +1076,22 @@ namespace ts {
});
}
export function getTsConfigObjectLiteralExpression(tsConfigSourceFile: TsConfigSourceFile | undefined) {
if (tsConfigSourceFile && tsConfigSourceFile.statements.length) {
const expression = tsConfigSourceFile.statements[0].expression;
return isObjectLiteralExpression(expression) && expression;
}
}
export function getTsConfigPropArrayElementValue(tsConfigSourceFile: TsConfigSourceFile | undefined, propKey: string, elementValue: string): StringLiteral | undefined {
const jsonObjectLiteral = getTsConfigObjectLiteralExpression(tsConfigSourceFile);
return jsonObjectLiteral &&
firstDefined(getPropertyAssignment(jsonObjectLiteral, propKey), property =>
isArrayLiteralExpression(property.initializer) ?
find(property.initializer.elements, (element): element is StringLiteral => isStringLiteral(element) && element.text === elementValue) :
undefined);
}
export function getContainingFunction(node: Node): SignatureDeclaration {
return findAncestor(node.parent, isFunctionLike);
}
@@ -1467,6 +1488,10 @@ namespace ts {
return node && !!(node.flags & NodeFlags.JavaScriptFile);
}
export function isInJsonFile(node: Node | undefined): boolean {
return node && !!(node.flags & NodeFlags.JsonFile);
}
export function isInJSDoc(node: Node | undefined): boolean {
return node && !!(node.flags & NodeFlags.JSDoc);
}
+2 -2
View File
@@ -70,7 +70,7 @@ namespace compiler {
const dts = this.dts = new collections.SortedMap<string, documents.TextDocument>({ comparer: this.vfs.stringComparer, sort: "insertion" });
const maps = this.maps = new collections.SortedMap<string, documents.TextDocument>({ comparer: this.vfs.stringComparer, sort: "insertion" });
for (const document of this.host.outputs) {
if (vpath.isJavaScript(document.file)) {
if (vpath.isJavaScript(document.file) || ts.fileExtensionIs(document.file, ts.Extension.Json)) {
js.set(document.file, document);
}
else if (vpath.isDeclaration(document.file)) {
@@ -245,4 +245,4 @@ namespace compiler {
const errors = ts.getPreEmitDiagnostics(program);
return new CompilationResult(host, compilerOptions, program, emitResult, errors);
}
}
}
+1 -1
View File
@@ -1217,7 +1217,7 @@ namespace Harness {
}
const useCaseSensitiveFileNames = options.useCaseSensitiveFileNames !== undefined ? options.useCaseSensitiveFileNames : true;
const programFileNames = inputFiles.map(file => file.unitName);
const programFileNames = inputFiles.map(file => file.unitName).filter(fileName => !ts.fileExtensionIs(fileName, ts.Extension.Json));
// Files from built\local that are requested by test "@includeBuiltFiles" to be in the context.
// Treat them as library files, so include them in build, but not in baselines.
+8 -7
View File
@@ -10,12 +10,6 @@ namespace ts {
assert.equal(JSON.stringify(parsed), JSON.stringify(expectedConfigObject));
}
function assertParseError(jsonText: string) {
const parsed = parseConfigFileTextToJson("/apath/tsconfig.json", jsonText);
assert.deepEqual(parsed.config, {});
assert.isTrue(undefined !== parsed.error);
}
function assertParseErrorWithExcludesKeyword(jsonText: string) {
{
const parsed = parseConfigFileTextToJson("/apath/tsconfig.json", jsonText);
@@ -138,7 +132,14 @@ namespace ts {
});
it("returns object with error when json is invalid", () => {
assertParseError("invalid");
const parsed = parseConfigFileTextToJson("/apath/tsconfig.json", "invalid");
assert.deepEqual(parsed.config, { invalid: undefined });
const expected = createCompilerDiagnostic(Diagnostics._0_expected, "{");
assert.equal(parsed.error.messageText, expected.messageText);
assert.equal(parsed.error.category, expected.category);
assert.equal(parsed.error.code, expected.code);
assert.equal(parsed.error.start, 0);
assert.equal(parsed.error.length, "invalid".length);
});
it("returns object when users correctly specify library", () => {
+1
View File
@@ -2746,6 +2746,7 @@ namespace ts.server.protocol {
suppressImplicitAnyIndexErrors?: boolean;
target?: ScriptTarget | ts.ScriptTarget;
traceResolution?: boolean;
resolveJsonModule?: boolean;
types?: string[];
/** Paths used to used to compute primary types search locations */
typeRoots?: string[];
+3 -11
View File
@@ -15,21 +15,13 @@ namespace ts {
}
function updateTsconfigFiles(program: Program, changeTracker: textChanges.ChangeTracker, oldFilePath: string, newFilePath: string): void {
const cfg = program.getCompilerOptions().configFile;
if (!cfg) return;
const oldFile = cfg.jsonObject && getFilesEntry(cfg.jsonObject, oldFilePath);
const configFile = program.getCompilerOptions().configFile;
const oldFile = getTsConfigPropArrayElementValue(configFile, "files", oldFilePath);
if (oldFile) {
changeTracker.replaceRangeWithText(cfg, createStringRange(oldFile, cfg), newFilePath);
changeTracker.replaceRangeWithText(configFile, createStringRange(oldFile, configFile), newFilePath);
}
}
function getFilesEntry(cfg: ObjectLiteralExpression, fileName: string): StringLiteral | undefined {
const filesProp = find(cfg.properties, (prop): prop is PropertyAssignment =>
isPropertyAssignment(prop) && isStringLiteral(prop.name) && prop.name.text === "files");
const files = filesProp && filesProp.initializer;
return files && isArrayLiteralExpression(files) ? find(files.elements, (e): e is StringLiteral => isStringLiteral(e) && e.text === fileName) : undefined;
}
interface ToUpdate {
readonly sourceFile: SourceFile;
readonly toUpdate: StringLiteralLike | FileReference;
+17 -4
View File
@@ -415,6 +415,7 @@ declare namespace ts {
ThisNodeOrAnySubNodesHasError = 131072,
HasAggregatedChildData = 262144,
JSDoc = 2097152,
JsonFile = 16777216,
BlockScoped = 3,
ReachabilityCheckFlags = 384,
ReachabilityAndEmitFlags = 1408,
@@ -1647,9 +1648,19 @@ declare namespace ts {
sourceFiles: ReadonlyArray<SourceFile>;
}
interface JsonSourceFile extends SourceFile {
jsonObject?: ObjectLiteralExpression;
statements: NodeArray<JsonObjectExpressionStatement>;
}
interface TsConfigSourceFile extends JsonSourceFile {
extendedSourceFiles?: string[];
}
interface JsonMinusNumericLiteral extends PrefixUnaryExpression {
kind: SyntaxKind.PrefixUnaryExpression;
operator: SyntaxKind.MinusToken;
operand: NumericLiteral;
}
interface JsonObjectExpressionStatement extends ExpressionStatement {
expression: ObjectLiteralExpression | ArrayLiteralExpression | JsonMinusNumericLiteral | NumericLiteral | StringLiteral | BooleanLiteral | NullLiteral;
}
interface ScriptReferenceHost {
getCompilerOptions(): CompilerOptions;
getSourceFile(fileName: string): SourceFile | undefined;
@@ -2395,11 +2406,12 @@ declare namespace ts {
suppressImplicitAnyIndexErrors?: boolean;
target?: ScriptTarget;
traceResolution?: boolean;
resolveJsonModule?: boolean;
types?: string[];
/** Paths used to compute primary types search locations */
typeRoots?: string[];
esModuleInterop?: boolean;
[option: string]: CompilerOptionsValue | JsonSourceFile | undefined;
[option: string]: CompilerOptionsValue | TsConfigSourceFile | undefined;
}
interface TypeAcquisition {
enableAutoDiscovery?: boolean;
@@ -4220,7 +4232,7 @@ declare namespace ts {
* Read tsconfig.json file
* @param fileName The path to the config file
*/
function readJsonConfigFile(fileName: string, readFile: (path: string) => string | undefined): JsonSourceFile;
function readJsonConfigFile(fileName: string, readFile: (path: string) => string | undefined): TsConfigSourceFile;
/**
* Convert the json syntax tree into the json value
*/
@@ -4240,7 +4252,7 @@ declare namespace ts {
* @param basePath A root directory to resolve relative path entries in the config
* file to. e.g. outDir
*/
function parseJsonSourceFileConfigFileContent(sourceFile: JsonSourceFile, host: ParseConfigHost, basePath: string, existingOptions?: CompilerOptions, configFileName?: string, resolutionStack?: Path[], extraFileExtensions?: ReadonlyArray<FileExtensionInfo>): ParsedCommandLine;
function parseJsonSourceFileConfigFileContent(sourceFile: TsConfigSourceFile, host: ParseConfigHost, basePath: string, existingOptions?: CompilerOptions, configFileName?: string, resolutionStack?: Path[], extraFileExtensions?: ReadonlyArray<FileExtensionInfo>): ParsedCommandLine;
function convertCompilerOptionsFromJson(jsonOptions: any, basePath: string, configFileName?: string): {
options: CompilerOptions;
errors: Diagnostic[];
@@ -7555,6 +7567,7 @@ declare namespace ts.server.protocol {
suppressImplicitAnyIndexErrors?: boolean;
target?: ScriptTarget | ts.ScriptTarget;
traceResolution?: boolean;
resolveJsonModule?: boolean;
types?: string[];
/** Paths used to used to compute primary types search locations */
typeRoots?: string[];
+16 -4
View File
@@ -415,6 +415,7 @@ declare namespace ts {
ThisNodeOrAnySubNodesHasError = 131072,
HasAggregatedChildData = 262144,
JSDoc = 2097152,
JsonFile = 16777216,
BlockScoped = 3,
ReachabilityCheckFlags = 384,
ReachabilityAndEmitFlags = 1408,
@@ -1647,9 +1648,19 @@ declare namespace ts {
sourceFiles: ReadonlyArray<SourceFile>;
}
interface JsonSourceFile extends SourceFile {
jsonObject?: ObjectLiteralExpression;
statements: NodeArray<JsonObjectExpressionStatement>;
}
interface TsConfigSourceFile extends JsonSourceFile {
extendedSourceFiles?: string[];
}
interface JsonMinusNumericLiteral extends PrefixUnaryExpression {
kind: SyntaxKind.PrefixUnaryExpression;
operator: SyntaxKind.MinusToken;
operand: NumericLiteral;
}
interface JsonObjectExpressionStatement extends ExpressionStatement {
expression: ObjectLiteralExpression | ArrayLiteralExpression | JsonMinusNumericLiteral | NumericLiteral | StringLiteral | BooleanLiteral | NullLiteral;
}
interface ScriptReferenceHost {
getCompilerOptions(): CompilerOptions;
getSourceFile(fileName: string): SourceFile | undefined;
@@ -2395,11 +2406,12 @@ declare namespace ts {
suppressImplicitAnyIndexErrors?: boolean;
target?: ScriptTarget;
traceResolution?: boolean;
resolveJsonModule?: boolean;
types?: string[];
/** Paths used to compute primary types search locations */
typeRoots?: string[];
esModuleInterop?: boolean;
[option: string]: CompilerOptionsValue | JsonSourceFile | undefined;
[option: string]: CompilerOptionsValue | TsConfigSourceFile | undefined;
}
interface TypeAcquisition {
enableAutoDiscovery?: boolean;
@@ -4220,7 +4232,7 @@ declare namespace ts {
* Read tsconfig.json file
* @param fileName The path to the config file
*/
function readJsonConfigFile(fileName: string, readFile: (path: string) => string | undefined): JsonSourceFile;
function readJsonConfigFile(fileName: string, readFile: (path: string) => string | undefined): TsConfigSourceFile;
/**
* Convert the json syntax tree into the json value
*/
@@ -4240,7 +4252,7 @@ declare namespace ts {
* @param basePath A root directory to resolve relative path entries in the config
* file to. e.g. outDir
*/
function parseJsonSourceFileConfigFileContent(sourceFile: JsonSourceFile, host: ParseConfigHost, basePath: string, existingOptions?: CompilerOptions, configFileName?: string, resolutionStack?: Path[], extraFileExtensions?: ReadonlyArray<FileExtensionInfo>): ParsedCommandLine;
function parseJsonSourceFileConfigFileContent(sourceFile: TsConfigSourceFile, host: ParseConfigHost, basePath: string, existingOptions?: CompilerOptions, configFileName?: string, resolutionStack?: Path[], extraFileExtensions?: ReadonlyArray<FileExtensionInfo>): ParsedCommandLine;
function convertCompilerOptionsFromJson(jsonOptions: any, basePath: string, configFileName?: string): {
options: CompilerOptions;
errors: Diagnostic[];
@@ -0,0 +1,32 @@
//// [tests/cases/compiler/requireOfJsonFile.ts] ////
//// [file1.ts]
import b1 = require('./b.json');
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"
}
//// [out/b.json]
{
"a": true,
"b": "hello"
}
//// [out/file1.js]
"use strict";
exports.__esModule = true;
var b1 = require("./b.json");
var x = b1.a;
var b2 = require("./b.json");
if (x) {
var b = b2.b;
x = (b1.b === b);
}
@@ -0,0 +1,38 @@
=== tests/cases/compiler/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('./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.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))
}
@@ -0,0 +1,45 @@
=== tests/cases/compiler/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('./b.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
}
=== 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,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"
}
//// [out/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))
}
@@ -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"
}
//// [out/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;
//// [out/node_modules/f.js]
"use strict";
module.exports = 10;
//// [out/projects/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.
@@ -0,0 +1,85 @@
//// [tests/cases/compiler/requireOfJsonFileTypes.ts] ////
//// [file1.ts]
import b = require('./b.json');
import c = require('./c.json');
import d = require('./d.json');
import e = require('./e.json');
import f = require('./f.json');
import g = require('./g.json');
let booleanLiteral: boolean, nullLiteral: null;
let stringLiteral: string;
let numberLiteral: number;
booleanLiteral = b.a;
stringLiteral = b.b;
nullLiteral = b.c;
booleanLiteral = b.d;
const stringOrNumberOrNull: string | number | null = c[0];
stringLiteral = d;
numberLiteral = e;
numberLiteral = f[0];
booleanLiteral = g[0];
//// [b.json]
{
"a": true,
"b": "hello",
"c": null,
"d": false
}
//// [c.json]
["a", null, "string"]
//// [d.json]
"dConfig"
//// [e.json]
-10
//// [f.json]
[-10, 30]
//// [g.json]
[true, false]
//// [out/b.json]
{
"a": true,
"b": "hello",
"c": null,
"d": false
}
//// [out/c.json]
["a", null, "string"]
//// [out/d.json]
"dConfig"
//// [out/e.json]
-10
//// [out/f.json]
[-10, 30]
//// [out/g.json]
[true, false]
//// [out/file1.js]
"use strict";
exports.__esModule = true;
var b = require("./b.json");
var c = require("./c.json");
var d = require("./d.json");
var e = require("./e.json");
var f = require("./f.json");
var g = require("./g.json");
var booleanLiteral, nullLiteral;
var stringLiteral;
var numberLiteral;
booleanLiteral = b.a;
stringLiteral = b.b;
nullLiteral = b.c;
booleanLiteral = b.d;
var stringOrNumberOrNull = c[0];
stringLiteral = d;
numberLiteral = e;
numberLiteral = f[0];
booleanLiteral = g[0];
@@ -0,0 +1,103 @@
=== tests/cases/compiler/file1.ts ===
import b = require('./b.json');
>b : Symbol(b, Decl(file1.ts, 0, 0))
import c = require('./c.json');
>c : Symbol(c, Decl(file1.ts, 0, 31))
import d = require('./d.json');
>d : Symbol(d, Decl(file1.ts, 1, 31))
import e = require('./e.json');
>e : Symbol(e, Decl(file1.ts, 2, 31))
import f = require('./f.json');
>f : Symbol(f, Decl(file1.ts, 3, 31))
import g = require('./g.json');
>g : Symbol(g, Decl(file1.ts, 4, 31))
let booleanLiteral: boolean, nullLiteral: null;
>booleanLiteral : Symbol(booleanLiteral, Decl(file1.ts, 7, 3))
>nullLiteral : Symbol(nullLiteral, Decl(file1.ts, 7, 28))
let stringLiteral: string;
>stringLiteral : Symbol(stringLiteral, Decl(file1.ts, 8, 3))
let numberLiteral: number;
>numberLiteral : Symbol(numberLiteral, Decl(file1.ts, 9, 3))
booleanLiteral = b.a;
>booleanLiteral : Symbol(booleanLiteral, Decl(file1.ts, 7, 3))
>b.a : Symbol("a", Decl(b.json, 0, 1))
>b : Symbol(b, Decl(file1.ts, 0, 0))
>a : Symbol("a", Decl(b.json, 0, 1))
stringLiteral = b.b;
>stringLiteral : Symbol(stringLiteral, Decl(file1.ts, 8, 3))
>b.b : Symbol("b", Decl(b.json, 1, 14))
>b : Symbol(b, Decl(file1.ts, 0, 0))
>b : Symbol("b", Decl(b.json, 1, 14))
nullLiteral = b.c;
>nullLiteral : Symbol(nullLiteral, Decl(file1.ts, 7, 28))
>b.c : Symbol("c", Decl(b.json, 2, 17))
>b : Symbol(b, Decl(file1.ts, 0, 0))
>c : Symbol("c", Decl(b.json, 2, 17))
booleanLiteral = b.d;
>booleanLiteral : Symbol(booleanLiteral, Decl(file1.ts, 7, 3))
>b.d : Symbol("d", Decl(b.json, 3, 14))
>b : Symbol(b, Decl(file1.ts, 0, 0))
>d : Symbol("d", Decl(b.json, 3, 14))
const stringOrNumberOrNull: string | number | null = c[0];
>stringOrNumberOrNull : Symbol(stringOrNumberOrNull, Decl(file1.ts, 15, 5))
>c : Symbol(c, Decl(file1.ts, 0, 31))
stringLiteral = d;
>stringLiteral : Symbol(stringLiteral, Decl(file1.ts, 8, 3))
>d : Symbol(d, Decl(file1.ts, 1, 31))
numberLiteral = e;
>numberLiteral : Symbol(numberLiteral, Decl(file1.ts, 9, 3))
>e : Symbol(e, Decl(file1.ts, 2, 31))
numberLiteral = f[0];
>numberLiteral : Symbol(numberLiteral, Decl(file1.ts, 9, 3))
>f : Symbol(f, Decl(file1.ts, 3, 31))
booleanLiteral = g[0];
>booleanLiteral : Symbol(booleanLiteral, Decl(file1.ts, 7, 3))
>g : Symbol(g, Decl(file1.ts, 4, 31))
=== 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))
"c": null,
>"c" : Symbol("c", Decl(b.json, 2, 17))
"d": false
>"d" : Symbol("d", Decl(b.json, 3, 14))
}
=== tests/cases/compiler/c.json ===
["a", null, "string"]
No type information for this code.
No type information for this code.=== tests/cases/compiler/d.json ===
"dConfig"
No type information for this code.
No type information for this code.=== tests/cases/compiler/e.json ===
-10
No type information for this code.
No type information for this code.=== tests/cases/compiler/f.json ===
[-10, 30]
No type information for this code.
No type information for this code.=== tests/cases/compiler/g.json ===
[true, false]
No type information for this code.
@@ -0,0 +1,139 @@
=== tests/cases/compiler/file1.ts ===
import b = require('./b.json');
>b : { "a": boolean; "b": string; "c": null; "d": boolean; }
import c = require('./c.json');
>c : (string | null)[]
import d = require('./d.json');
>d : "dConfig"
import e = require('./e.json');
>e : -10
import f = require('./f.json');
>f : number[]
import g = require('./g.json');
>g : boolean[]
let booleanLiteral: boolean, nullLiteral: null;
>booleanLiteral : boolean
>nullLiteral : null
>null : null
let stringLiteral: string;
>stringLiteral : string
let numberLiteral: number;
>numberLiteral : number
booleanLiteral = b.a;
>booleanLiteral = b.a : boolean
>booleanLiteral : boolean
>b.a : boolean
>b : { "a": boolean; "b": string; "c": null; "d": boolean; }
>a : boolean
stringLiteral = b.b;
>stringLiteral = b.b : string
>stringLiteral : string
>b.b : string
>b : { "a": boolean; "b": string; "c": null; "d": boolean; }
>b : string
nullLiteral = b.c;
>nullLiteral = b.c : null
>nullLiteral : null
>b.c : null
>b : { "a": boolean; "b": string; "c": null; "d": boolean; }
>c : null
booleanLiteral = b.d;
>booleanLiteral = b.d : boolean
>booleanLiteral : boolean
>b.d : boolean
>b : { "a": boolean; "b": string; "c": null; "d": boolean; }
>d : boolean
const stringOrNumberOrNull: string | number | null = c[0];
>stringOrNumberOrNull : string | number | null
>null : null
>c[0] : string | null
>c : (string | null)[]
>0 : 0
stringLiteral = d;
>stringLiteral = d : "dConfig"
>stringLiteral : string
>d : "dConfig"
numberLiteral = e;
>numberLiteral = e : -10
>numberLiteral : number
>e : -10
numberLiteral = f[0];
>numberLiteral = f[0] : number
>numberLiteral : number
>f[0] : number
>f : number[]
>0 : 0
booleanLiteral = g[0];
>booleanLiteral = g[0] : boolean
>booleanLiteral : boolean
>g[0] : boolean
>g : boolean[]
>0 : 0
=== tests/cases/compiler/b.json ===
{
>{ "a": true, "b": "hello", "c": null, "d": false} : { "a": boolean; "b": string; "c": null; "d": boolean; }
"a": true,
>"a" : boolean
>true : true
"b": "hello",
>"b" : string
>"hello" : "hello"
"c": null,
>"c" : null
>null : null
"d": false
>"d" : boolean
>false : false
}
=== tests/cases/compiler/c.json ===
["a", null, "string"]
>["a", null, "string"] : (string | null)[]
>"a" : "a"
>null : null
>"string" : "string"
=== tests/cases/compiler/d.json ===
"dConfig"
>"dConfig" : "dConfig"
=== tests/cases/compiler/e.json ===
-10
>-10 : -10
>10 : 10
=== tests/cases/compiler/f.json ===
[-10, 30]
>[-10, 30] : number[]
>-10 : -10
>10 : 10
>30 : 30
=== tests/cases/compiler/g.json ===
[true, false]
>[true, false] : boolean[]
>true : true
>false : false
@@ -0,0 +1,24 @@
error TS5070: Option '--resolveJsonModule' cannot be specified without 'node' module resolution strategy.
tests/cases/compiler/file1.ts(1,21): error TS2307: Cannot find module './b'.
tests/cases/compiler/file1.ts(3,21): error TS2307: Cannot find module './b.json'.
!!! error TS5070: Option '--resolveJsonModule' cannot be specified without 'node' module resolution strategy.
==== tests/cases/compiler/file1.ts (2 errors) ====
import b1 = require('./b');
~~~~~
!!! error TS2307: Cannot find module './b'.
let x = b1.a;
import b2 = require('./b.json');
~~~~~~~~~~
!!! error TS2307: Cannot find module './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,27 @@
//// [tests/cases/compiler/requireOfJsonFileWithAmd.ts] ////
//// [file1.ts]
import b1 = require('./b');
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"
}
//// [out/file1.js]
define(["require", "exports", "./b", "./b.json"], function (require, exports, b1, b2) {
"use strict";
exports.__esModule = true;
var x = b1.a;
if (x) {
var b = b2.b;
x = (b1.b === b);
}
});
@@ -0,0 +1,24 @@
=== tests/cases/compiler/file1.ts ===
import b1 = require('./b');
>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 : Symbol(b2, Decl(file1.ts, 1, 13))
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))
}
@@ -0,0 +1,33 @@
=== tests/cases/compiler/file1.ts ===
import b1 = require('./b');
>b1 : any
let x = b1.a;
>x : any
>b1.a : any
>b1 : any
>a : any
import b2 = require('./b.json');
>b2 : any
if (x) {
>x : any
let b = b2.b;
>b : any
>b2.b : any
>b2 : any
>b : any
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 : any
}
@@ -0,0 +1,25 @@
//// [tests/cases/compiler/requireOfJsonFileWithEmptyObject.ts] ////
//// [file1.ts]
import b1 = require('./b.json');
let x = b1;
import b2 = require('./b.json');
if (x) {
x = b2;
}
//// [b.json]
{
}
//// [out/b.json]
{}
//// [out/file1.js]
"use strict";
exports.__esModule = true;
var b1 = require("./b.json");
var x = b1;
var b2 = require("./b.json");
if (x) {
x = b2;
}
@@ -0,0 +1,23 @@
=== tests/cases/compiler/file1.ts ===
import b1 = require('./b.json');
>b1 : Symbol(b1, Decl(file1.ts, 0, 0))
let x = b1;
>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, 11))
if (x) {
>x : Symbol(x, Decl(file1.ts, 1, 3))
x = b2;
>x : Symbol(x, Decl(file1.ts, 1, 3))
>b2 : Symbol(b2, Decl(file1.ts, 1, 11))
}
=== tests/cases/compiler/b.json ===
{
No type information for this code.}
No type information for this code.
@@ -0,0 +1,24 @@
=== tests/cases/compiler/file1.ts ===
import b1 = require('./b.json');
>b1 : {}
let x = b1;
>x : {}
>b1 : {}
import b2 = require('./b.json');
>b2 : {}
if (x) {
>x : {}
x = b2;
>x = b2 : {}
>x : {}
>b2 : {}
}
=== tests/cases/compiler/b.json ===
{
>{} : {}
}
@@ -0,0 +1,23 @@
tests/cases/compiler/file1.ts(2,12): error TS2339: Property 'a' does not exist on type '{}'.
tests/cases/compiler/file1.ts(5,16): error TS2339: Property 'b' does not exist on type '{}'.
tests/cases/compiler/file1.ts(6,13): error TS2339: Property 'b' does not exist on type '{}'.
==== tests/cases/compiler/file1.ts (3 errors) ====
import b1 = require('./b.json');
let x = b1.a;
~
!!! error TS2339: Property 'a' does not exist on type '{}'.
import b2 = require('./b.json');
if (x) {
let b = b2.b;
~
!!! error TS2339: Property 'b' does not exist on type '{}'.
x = (b1.b === b);
~
!!! error TS2339: Property 'b' does not exist on type '{}'.
}
==== tests/cases/compiler/b.json (0 errors) ====
{
}
@@ -0,0 +1,27 @@
//// [tests/cases/compiler/requireOfJsonFileWithEmptyObjectWithErrors.ts] ////
//// [file1.ts]
import b1 = require('./b.json');
let x = b1.a;
import b2 = require('./b.json');
if (x) {
let b = b2.b;
x = (b1.b === b);
}
//// [b.json]
{
}
//// [out/b.json]
{}
//// [out/file1.js]
"use strict";
exports.__esModule = true;
var b1 = require("./b.json");
var x = b1.a;
var b2 = require("./b.json");
if (x) {
var b = b2.b;
x = (b1.b === b);
}
@@ -0,0 +1,28 @@
=== tests/cases/compiler/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 : 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 : Symbol(b2, Decl(file1.ts, 1, 13))
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 ===
{
No type information for this code.}
No type information for this code.
@@ -0,0 +1,37 @@
=== tests/cases/compiler/file1.ts ===
import b1 = require('./b.json');
>b1 : {}
let x = b1.a;
>x : any
>b1.a : any
>b1 : {}
>a : any
import b2 = require('./b.json');
>b2 : {}
if (x) {
>x : any
let b = b2.b;
>b : any
>b2.b : any
>b2 : {}
>b : any
x = (b1.b === b);
>x = (b1.b === b) : boolean
>x : any
>(b1.b === b) : boolean
>b1.b === b : boolean
>b1.b : any
>b1 : {}
>b : any
>b : any
}
=== tests/cases/compiler/b.json ===
{
>{} : {}
}
@@ -0,0 +1,19 @@
tests/cases/compiler/b.json(2,5): error TS1327: String literal with double quotes expected.
==== tests/cases/compiler/file1.ts (0 errors) ====
import b1 = require('./b.json');
let x = b1.a;
import b2 = require('./b.json');
if (x) {
let b = b2.b;
x = (b1.b === b);
}
==== tests/cases/compiler/b.json (1 errors) ====
{
'a': true,
~~~
!!! error TS1327: String literal with double quotes expected.
"b": "hello"
}
@@ -0,0 +1,32 @@
//// [tests/cases/compiler/requireOfJsonFileWithErrors.ts] ////
//// [file1.ts]
import b1 = require('./b.json');
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"
}
//// [out/b.json]
{
'a': true,
"b": "hello"
}
//// [out/file1.js]
"use strict";
exports.__esModule = true;
var b1 = require("./b.json");
var x = b1.a;
var b2 = require("./b.json");
if (x) {
var b = b2.b;
x = (b1.b === b);
}
@@ -0,0 +1,38 @@
=== tests/cases/compiler/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('./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.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))
}
@@ -0,0 +1,45 @@
=== tests/cases/compiler/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('./b.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
}
=== 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,22 @@
tests/cases/compiler/file1.ts(2,12): error TS2339: Property 'a' does not exist on type '{}'.
tests/cases/compiler/file1.ts(5,16): error TS2339: Property 'b' does not exist on type '{}'.
tests/cases/compiler/file1.ts(6,13): error TS2339: Property 'b' does not exist on type '{}'.
==== tests/cases/compiler/file1.ts (3 errors) ====
import b1 = require('./b.json');
let x = b1.a;
~
!!! error TS2339: Property 'a' does not exist on type '{}'.
import b2 = require('./b.json');
if (x) {
let b = b2.b;
~
!!! error TS2339: Property 'b' does not exist on type '{}'.
x = (b1.b === b);
~
!!! error TS2339: Property 'b' does not exist on type '{}'.
}
==== tests/cases/compiler/b.json (0 errors) ====
@@ -0,0 +1,25 @@
//// [tests/cases/compiler/requireOfJsonFileWithNoContent.ts] ////
//// [file1.ts]
import b1 = require('./b.json');
let x = b1.a;
import b2 = require('./b.json');
if (x) {
let b = b2.b;
x = (b1.b === b);
}
//// [b.json]
//// [out/b.json]
//// [out/file1.js]
"use strict";
exports.__esModule = true;
var b1 = require("./b.json");
var x = b1.a;
var b2 = require("./b.json");
if (x) {
var b = b2.b;
x = (b1.b === b);
}
@@ -0,0 +1,27 @@
=== tests/cases/compiler/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 : 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 : Symbol(b2, Decl(file1.ts, 1, 13))
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 ===
No type information for this code.
@@ -0,0 +1,36 @@
=== tests/cases/compiler/file1.ts ===
import b1 = require('./b.json');
>b1 : {}
let x = b1.a;
>x : any
>b1.a : any
>b1 : {}
>a : any
import b2 = require('./b.json');
>b2 : {}
if (x) {
>x : any
let b = b2.b;
>b : any
>b2.b : any
>b2 : {}
>b : any
x = (b1.b === b);
>x = (b1.b === b) : boolean
>x : any
>(b1.b === b) : boolean
>b1.b === b : boolean
>b1.b : any
>b1 : {}
>b : any
>b : any
}
=== tests/cases/compiler/b.json ===
No type information for this code.
@@ -0,0 +1,32 @@
//// [tests/cases/compiler/requireOfJsonFileWithoutAllowJs.ts] ////
//// [file1.ts]
import b1 = require('./b.json');
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"
}
//// [out/b.json]
{
"a": true,
"b": "hello"
}
//// [out/file1.js]
"use strict";
exports.__esModule = true;
var b1 = require("./b.json");
var x = b1.a;
var b2 = require("./b.json");
if (x) {
var b = b2.b;
x = (b1.b === b);
}
@@ -0,0 +1,38 @@
=== tests/cases/compiler/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('./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.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))
}
@@ -0,0 +1,45 @@
=== tests/cases/compiler/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('./b.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
}
=== 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"
}
//// [out/b.json]
{
"a": true,
"b": "hello"
}
//// [out/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" };
//// [out/c.js]
"use strict";
module.exports = { a: true, b: "hello" };
//// [out/c.json]
{
"a": true,
"b": "hello"
}
//// [out/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"
@@ -0,0 +1,20 @@
error TS5055: Cannot write file 'tests/cases/compiler/b.json' 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 TS5055: Cannot write file 'tests/cases/compiler/b.json' 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.
==== tests/cases/compiler/file1.ts (0 errors) ====
import b1 = require('./b.json');
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,27 @@
//// [tests/cases/compiler/requireOfJsonFileWithoutOutDir.ts] ////
//// [file1.ts]
import b1 = require('./b.json');
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"
}
//// [tests/cases/compiler/file1.js]
"use strict";
exports.__esModule = true;
var b1 = require("./b.json");
var x = b1.a;
var b2 = require("./b.json");
if (x) {
var b = b2.b;
x = (b1.b === b);
}
@@ -0,0 +1,38 @@
=== tests/cases/compiler/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('./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.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))
}
@@ -0,0 +1,45 @@
=== tests/cases/compiler/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('./b.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
}
=== 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.json'.
tests/cases/compiler/file1.ts(3,21): error TS2307: Cannot find module './b.json'.
==== tests/cases/compiler/file1.ts (2 errors) ====
import b1 = require('./b.json'); // error
~~~~~~~~~~
!!! error TS2307: Cannot find module './b.json'.
let x = b1.a;
import b2 = require('./b.json'); // error
~~~~~~~~~~
!!! error TS2307: Cannot find module './b.json'.
if (x) {
let b = b2.b;
x = (b1.b === b);
}
==== tests/cases/compiler/b.json (0 errors) ====
contents Not read
@@ -0,0 +1,24 @@
//// [tests/cases/compiler/requireOfJsonFileWithoutResolveJsonModule.ts] ////
//// [file1.ts]
import b1 = require('./b.json'); // error
let x = b1.a;
import b2 = require('./b.json'); // error
if (x) {
let b = b2.b;
x = (b1.b === b);
}
//// [b.json]
contents Not read
//// [out/file1.js]
"use strict";
exports.__esModule = true;
var b1 = require("./b.json"); // error
var x = b1.a;
var b2 = require("./b.json"); // error
if (x) {
var b = b2.b;
x = (b1.b === b);
}
@@ -0,0 +1,24 @@
=== tests/cases/compiler/file1.ts ===
import b1 = require('./b.json'); // error
>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'); // error
>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 : Symbol(b2, Decl(file1.ts, 1, 13))
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))
}
@@ -0,0 +1,33 @@
=== tests/cases/compiler/file1.ts ===
import b1 = require('./b.json'); // error
>b1 : any
let x = b1.a;
>x : any
>b1.a : any
>b1 : any
>a : any
import b2 = require('./b.json'); // error
>b2 : any
if (x) {
>x : any
let b = b2.b;
>b : any
>b2.b : any
>b2 : any
>b : any
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 : any
}
+20
View File
@@ -0,0 +1,20 @@
// @module: commonjs
// @outdir: out/
// @allowJs: true
// @fullEmitPaths: true
// @resolveJsonModule: true
// @Filename: file1.ts
import b1 = require('./b.json');
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,26 @@
// @module: commonjs
// @outdir: out/
// @allowJs: true
// @fullEmitPaths: true
// @resolveJsonModule: 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,27 @@
// @module: commonjs
// @outdir: out/
// @allowJs: true
// @fullEmitPaths: true
// @resolveJsonModule: 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,18 @@
// @module: commonjs
// @outdir: out/
// @allowJs: true
// @fullEmitPaths: true
// @resolveJsonModule: 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;
@@ -0,0 +1,51 @@
// @module: commonjs
// @outdir: out/
// @allowJs: true
// @strictNullChecks: true
// @fullEmitPaths: true
// @resolveJsonModule: true
// @Filename: file1.ts
import b = require('./b.json');
import c = require('./c.json');
import d = require('./d.json');
import e = require('./e.json');
import f = require('./f.json');
import g = require('./g.json');
let booleanLiteral: boolean, nullLiteral: null;
let stringLiteral: string;
let numberLiteral: number;
booleanLiteral = b.a;
stringLiteral = b.b;
nullLiteral = b.c;
booleanLiteral = b.d;
const stringOrNumberOrNull: string | number | null = c[0];
stringLiteral = d;
numberLiteral = e;
numberLiteral = f[0];
booleanLiteral = g[0];
// @Filename: b.json
{
"a": true,
"b": "hello",
"c": null,
"d": false
}
// @Filename: c.json
["a", null, "string"]
// @Filename: d.json
"dConfig"
// @Filename: e.json
-10
// @Filename: f.json
[-10, 30]
// @Filename: g.json
[true, false]
@@ -0,0 +1,20 @@
// @module: amd
// @outdir: out/
// @allowJs: true
// @fullEmitPaths: true
// @resolveJsonModule: true
// @Filename: file1.ts
import b1 = require('./b');
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,17 @@
// @module: commonjs
// @outdir: out/
// @allowJs: true
// @fullEmitPaths: true
// @resolveJsonModule: true
// @Filename: file1.ts
import b1 = require('./b.json');
let x = b1;
import b2 = require('./b.json');
if (x) {
x = b2;
}
// @Filename: b.json
{
}
@@ -0,0 +1,18 @@
// @module: commonjs
// @outdir: out/
// @allowJs: true
// @fullEmitPaths: true
// @resolveJsonModule: true
// @Filename: file1.ts
import b1 = require('./b.json');
let x = b1.a;
import b2 = require('./b.json');
if (x) {
let b = b2.b;
x = (b1.b === b);
}
// @Filename: b.json
{
}
@@ -0,0 +1,20 @@
// @module: commonjs
// @outdir: out/
// @allowJs: true
// @fullEmitPaths: true
// @resolveJsonModule: true
// @Filename: file1.ts
import b1 = require('./b.json');
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,16 @@
// @module: commonjs
// @outdir: out/
// @allowJs: true
// @fullEmitPaths: true
// @resolveJsonModule: true
// @Filename: file1.ts
import b1 = require('./b.json');
let x = b1.a;
import b2 = require('./b.json');
if (x) {
let b = b2.b;
x = (b1.b === b);
}
// @Filename: b.json
@@ -0,0 +1,19 @@
// @module: commonjs
// @outdir: out/
// @fullEmitPaths: true
// @resolveJsonModule: true
// @Filename: file1.ts
import b1 = require('./b.json');
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,20 @@
// @module: commonjs
// @outdir: out/
// @allowJs: true
// @fullEmitPaths: true
// @resolveJsonModule: 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,29 @@
// @module: commonjs
// @outdir: out/
// @allowJs: true
// @fullEmitPaths: true
// @resolveJsonModule: 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" };
@@ -0,0 +1,18 @@
// @module: commonjs
// @fullEmitPaths: true
// @resolveJsonModule: true
// @Filename: file1.ts
import b1 = require('./b.json');
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,16 @@
// @module: commonjs
// @outdir: out/
// @allowJs: true
// @fullEmitPaths: true
// @Filename: file1.ts
import b1 = require('./b.json'); // error
let x = b1.a;
import b2 = require('./b.json'); // error
if (x) {
let b = b2.b;
x = (b1.b === b);
}
// @Filename: b.json
contents Not read