mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
More tests and also do not add index signature for json module
This commit is contained in:
@@ -14882,7 +14882,7 @@ namespace ts {
|
||||
const contextualType = getApparentTypeOfContextualType(node);
|
||||
const contextualTypeHasPattern = contextualType && contextualType.pattern &&
|
||||
(contextualType.pattern.kind === SyntaxKind.ObjectBindingPattern || contextualType.pattern.kind === SyntaxKind.ObjectLiteralExpression);
|
||||
const isJSObjectLiteral = !contextualType && isInJavaScriptFile(node);
|
||||
const isJSObjectLiteral = !contextualType && (isInJavaScriptFile(node) && !isInJsonFile(node));
|
||||
let typeFlags: TypeFlags = 0;
|
||||
let patternWithComputedProperties = false;
|
||||
let hasComputedStringProperty = false;
|
||||
|
||||
@@ -747,9 +747,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;
|
||||
|
||||
@@ -492,6 +492,7 @@ namespace ts {
|
||||
JSDoc = 1 << 20, // If node was parsed inside jsdoc
|
||||
/* @internal */ Ambient = 1 << 21, // If node was inside an ambient context -- a declaration file, or inside something with the `declare` modifier.
|
||||
/* @internal */ InWithStatement = 1 << 22, // If any ancestor of node was the `statement` of a WithStatement (not the `expression`)
|
||||
JsonFile = 1 << 23, // If node was parsed in a Json
|
||||
|
||||
BlockScoped = Let | Const,
|
||||
|
||||
|
||||
@@ -1432,6 +1432,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);
|
||||
}
|
||||
|
||||
@@ -413,6 +413,7 @@ declare namespace ts {
|
||||
ThisNodeOrAnySubNodesHasError = 131072,
|
||||
HasAggregatedChildData = 262144,
|
||||
JSDoc = 1048576,
|
||||
JsonFile = 8388608,
|
||||
BlockScoped = 3,
|
||||
ReachabilityCheckFlags = 384,
|
||||
ReachabilityAndEmitFlags = 1408,
|
||||
|
||||
@@ -413,6 +413,7 @@ declare namespace ts {
|
||||
ThisNodeOrAnySubNodesHasError = 131072,
|
||||
HasAggregatedChildData = 262144,
|
||||
JSDoc = 1048576,
|
||||
JsonFile = 8388608,
|
||||
BlockScoped = 3,
|
||||
ReachabilityCheckFlags = 384,
|
||||
ReachabilityAndEmitFlags = 1408,
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
=== tests/cases/compiler/file1.ts ===
|
||||
import b1 = require('./b');
|
||||
>b1 : { [x: string]: any; "a": boolean; "b": string; }
|
||||
>b1 : { "a": boolean; "b": string; }
|
||||
|
||||
let x = b1.a;
|
||||
>x : boolean
|
||||
>b1.a : boolean
|
||||
>b1 : { [x: string]: any; "a": boolean; "b": string; }
|
||||
>b1 : { "a": boolean; "b": string; }
|
||||
>a : boolean
|
||||
|
||||
import b2 = require('./b.json');
|
||||
>b2 : { [x: string]: any; "a": boolean; "b": string; }
|
||||
>b2 : { "a": boolean; "b": string; }
|
||||
|
||||
if (x) {
|
||||
>x : boolean
|
||||
@@ -17,7 +17,7 @@ if (x) {
|
||||
let b = b2.b;
|
||||
>b : string
|
||||
>b2.b : string
|
||||
>b2 : { [x: string]: any; "a": boolean; "b": string; }
|
||||
>b2 : { "a": boolean; "b": string; }
|
||||
>b : string
|
||||
|
||||
x = (b1.b === b);
|
||||
@@ -26,14 +26,14 @@ if (x) {
|
||||
>(b1.b === b) : boolean
|
||||
>b1.b === b : boolean
|
||||
>b1.b : string
|
||||
>b1 : { [x: string]: any; "a": boolean; "b": string; }
|
||||
>b1 : { "a": boolean; "b": string; }
|
||||
>b : string
|
||||
>b : string
|
||||
}
|
||||
|
||||
=== tests/cases/compiler/b.json ===
|
||||
{
|
||||
>{ "a": true, "b": "hello"} : { [x: string]: any; "a": boolean; "b": string; }
|
||||
>{ "a": true, "b": "hello"} : { "a": boolean; "b": string; }
|
||||
|
||||
"a": true,
|
||||
>"a" : boolean
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
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'.
|
||||
|
||||
|
||||
==== 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"
|
||||
}
|
||||
|
||||
//// [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');
|
||||
let x = b1;
|
||||
import b2 = require('./b.json');
|
||||
if (x) {
|
||||
x = b2;
|
||||
}
|
||||
|
||||
//// [b.json]
|
||||
{
|
||||
}
|
||||
|
||||
//// [b.json]
|
||||
{}
|
||||
//// [file1.js]
|
||||
"use strict";
|
||||
exports.__esModule = true;
|
||||
var b1 = require("./b");
|
||||
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');
|
||||
>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');
|
||||
>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');
|
||||
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');
|
||||
let x = b1.a;
|
||||
import b2 = require('./b.json');
|
||||
if (x) {
|
||||
let b = b2.b;
|
||||
x = (b1.b === b);
|
||||
}
|
||||
|
||||
//// [b.json]
|
||||
{
|
||||
}
|
||||
|
||||
//// [b.json]
|
||||
{}
|
||||
//// [file1.js]
|
||||
"use strict";
|
||||
exports.__esModule = true;
|
||||
var b1 = require("./b");
|
||||
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');
|
||||
>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');
|
||||
>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,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');
|
||||
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');
|
||||
let x = b1.a;
|
||||
import b2 = require('./b.json');
|
||||
if (x) {
|
||||
let b = b2.b;
|
||||
x = (b1.b === b);
|
||||
}
|
||||
|
||||
//// [b.json]
|
||||
|
||||
|
||||
//// [b.json]
|
||||
//// [file1.js]
|
||||
"use strict";
|
||||
exports.__esModule = true;
|
||||
var b1 = require("./b");
|
||||
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');
|
||||
>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');
|
||||
>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,17 @@
|
||||
// @module: amd
|
||||
// @outdir: out/
|
||||
|
||||
// @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,14 @@
|
||||
// @module: commonjs
|
||||
// @outdir: out/
|
||||
|
||||
// @Filename: file1.ts
|
||||
import b1 = require('./b');
|
||||
let x = b1;
|
||||
import b2 = require('./b.json');
|
||||
if (x) {
|
||||
x = b2;
|
||||
}
|
||||
|
||||
// @Filename: b.json
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
// @module: commonjs
|
||||
// @outdir: out/
|
||||
|
||||
// @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
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// @module: commonjs
|
||||
// @outdir: out/
|
||||
|
||||
// @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
|
||||
Reference in New Issue
Block a user