Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mark error type in type baselines if the baselines otherwise seem clean #26346

Merged
merged 1 commit into from
Aug 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/harness/harness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1493,7 +1493,7 @@ namespace Harness {
});
}

export function doTypeAndSymbolBaseline(baselinePath: string, program: ts.Program, allFiles: {unitName: string, content: string}[], opts?: Baseline.BaselineOptions, multifile?: boolean, skipTypeBaselines?: boolean, skipSymbolBaselines?: boolean) {
export function doTypeAndSymbolBaseline(baselinePath: string, program: ts.Program, allFiles: {unitName: string, content: string}[], opts?: Baseline.BaselineOptions, multifile?: boolean, skipTypeBaselines?: boolean, skipSymbolBaselines?: boolean, hasErrorBaseline?: boolean) {
// The full walker simulates the types that you would get from doing a full
// compile. The pull walker simulates the types you get when you just do
// a type query for a random node (like how the LS would do it). Most of the
Expand All @@ -1509,7 +1509,7 @@ namespace Harness {
// These types are equivalent, but depend on what order the compiler observed
// certain parts of the program.

const fullWalker = new TypeWriterWalker(program, /*fullTypeCheck*/ true);
const fullWalker = new TypeWriterWalker(program, /*fullTypeCheck*/ true, !!hasErrorBaseline);

// Produce baselines. The first gives the types for all expressions.
// The second gives symbols for all identifiers.
Expand Down
48 changes: 46 additions & 2 deletions src/harness/typeWriter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class TypeWriterWalker {

private checker: ts.TypeChecker;

constructor(private program: ts.Program, fullTypeCheck: boolean) {
constructor(private program: ts.Program, fullTypeCheck: boolean, private hadErrorBaseline: boolean) {
// Consider getting both the diagnostics checker and the non-diagnostics checker to verify
// they are consistent.
this.checker = fullTypeCheck
Expand Down Expand Up @@ -69,6 +69,26 @@ class TypeWriterWalker {
}
}

private isImportStatementName(node: ts.Node) {
if (ts.isImportSpecifier(node.parent) && (node.parent.name === node || node.parent.propertyName === node)) return true;
if (ts.isImportClause(node.parent) && node.parent.name === node) return true;
if (ts.isImportEqualsDeclaration(node.parent) && node.parent.name === node) return true;
return false;
}

private isExportStatementName(node: ts.Node) {
if (ts.isExportAssignment(node.parent) && node.parent.expression === node) return true;
if (ts.isExportSpecifier(node.parent) && (node.parent.name === node || node.parent.propertyName === node)) return true;
return false;
}

private isIntrinsicJsxTag(node: ts.Node) {
const p = node.parent;
if (!(ts.isJsxOpeningElement(p) || ts.isJsxClosingElement(p) || ts.isJsxSelfClosingElement(p))) return false;
if (p.tagName !== node) return false;
return ts.isIntrinsicJsxName(node.getText());
}

private writeTypeOrSymbol(node: ts.Node, isSymbolWalk: boolean): TypeWriterResult | undefined {
const actualPos = ts.skipTrivia(this.currentSourceFile.text, node.pos);
const lineAndCharacter = this.currentSourceFile.getLineAndCharacterOfPosition(actualPos);
Expand All @@ -85,7 +105,31 @@ class TypeWriterWalker {
// let type = this.checker.getTypeAtLocation(node);
let type = ts.isExpressionWithTypeArgumentsInClassExtendsClause(node.parent) ? this.checker.getTypeAtLocation(node.parent) : undefined;
if (!type || type.flags & ts.TypeFlags.Any) type = this.checker.getTypeAtLocation(node);
const typeString = this.checker.typeToString(type, node.parent, ts.TypeFormatFlags.NoTruncation | ts.TypeFormatFlags.AllowUniqueESSymbolType);
const typeString =
// Distinguish `errorType`s from `any`s; but only if the file has no errors.
// Additionally,
// * the LHS of a qualified name
// * a binding pattern name
// * labels
// * the "global" in "declare global"
// * the "target" in "new.target"
// * names in import statements
// * type-only names in export statements
// * and intrinsic jsx tag names
// return `error`s via `getTypeAtLocation`
// But this is generally expected, so we don't call those out, either
(!this.hadErrorBaseline &&
type.flags & ts.TypeFlags.Any &&
!ts.isBindingElement(node.parent) &&
!ts.isPropertyAccessOrQualifiedName(node.parent) &&
!ts.isLabelName(node) &&
!(ts.isModuleDeclaration(node.parent) && ts.isGlobalScopeAugmentation(node.parent)) &&
!ts.isMetaProperty(node.parent) &&
!this.isImportStatementName(node) &&
!this.isExportStatementName(node) &&
!this.isIntrinsicJsxTag(node)) ?
(type as ts.IntrinsicType).intrinsicName :
this.checker.typeToString(type, node.parent, ts.TypeFormatFlags.NoTruncation | ts.TypeFormatFlags.AllowUniqueESSymbolType);
return {
line: lineAndCharacter.line,
syntaxKind: node.kind,
Expand Down
8 changes: 7 additions & 1 deletion src/testRunner/compilerRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,13 @@ class CompilerTest {
Harness.Compiler.doTypeAndSymbolBaseline(
this.justName,
this.result.program!,
this.toBeCompiled.concat(this.otherFiles).filter(file => !!this.result.program!.getSourceFile(file.unitName)));
this.toBeCompiled.concat(this.otherFiles).filter(file => !!this.result.program!.getSourceFile(file.unitName)),
/*opts*/ undefined,
/*multifile*/ undefined,
/*skipTypeBaselines*/ undefined,
/*skipSymbolBaselines*/ undefined,
!!ts.length(this.result.diagnostics)
);
}

private makeUnitName(name: string, root: string) {
Expand Down
2 changes: 1 addition & 1 deletion tests/baselines/reference/acceptableAlias1.types
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module M {
}
export import X = N;
>X : any
>N : any
>N : error
}

import r = M.X;
Expand Down
2 changes: 1 addition & 1 deletion tests/baselines/reference/aliasInaccessibleModule.types
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ module M {
}
export import X = N;
>X : any
>N : any
>N : error
}
10 changes: 5 additions & 5 deletions tests/baselines/reference/checkJsFiles_skipDiagnostics.types
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ var x = 0;

/// @ts-ignore
x();
>x() : any
>x() : error
>x : number

/// @ts-ignore
x();
>x() : any
>x() : error
>x : number

/// @ts-ignore
x(
>x( 2, 3) : any
>x( 2, 3) : error
>x : number

2,
Expand All @@ -34,13 +34,13 @@ x(
// @another

x();
>x() : any
>x() : error
>x : number



// @ts-ignore: no call signature
x();
>x() : any
>x() : error
>x : number

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
export module C { export interface I { } }
export import v = C;
>v : any
>C : any
>C : error

export module M {
>M : typeof M
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ declare var __foot: any;
>__foot : any

const thing = <__foot />;
>thing : any
><__foot /> : any
>thing : error
><__foot /> : error
>__foot : any

export {}
Expand Down
2 changes: 1 addition & 1 deletion tests/baselines/reference/duplicateVarAndImport.types
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ var a;
module M { }
import a = M;
>a : any
>M : any
>M : error

4 changes: 2 additions & 2 deletions tests/baselines/reference/es3-jsx-preserve.types
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ const React: any = null;
>null : null

const elem = <div></div>;
>elem : any
><div></div> : any
>elem : error
><div></div> : error
>div : any
>div : any

Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/es3-jsx-react-native.types
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ const React: any = null;
>null : null

const elem = <div></div>;
>elem : any
><div></div> : any
>elem : error
><div></div> : error
>div : any
>div : any

Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/es3-jsx-react.types
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ const React: any = null;
>null : null

const elem = <div></div>;
>elem : any
><div></div> : any
>elem : error
><div></div> : error
>div : any
>div : any

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module B {

export import A1 = A
>A1 : any
>A : any
>A : error

}

Expand Down
8 changes: 4 additions & 4 deletions tests/baselines/reference/importHelpersInTsx.types
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ declare var o: any;
>o : any

export const x = <span {...o} />
>x : any
><span {...o} /> : any
>x : error
><span {...o} /> : error
>span : any
>o : any

Expand All @@ -19,8 +19,8 @@ declare var o: any;
>o : any

const x = <span {...o} />
>x : any
><span {...o} /> : any
>x : error
><span {...o} /> : error
>span : any
>o : any

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export declare const theme: { a: string }
=== tests/cases/compiler/test3.ts ===
export const a: import("./test1").T<typeof import("./test2").theme> = null as any;
>a : import("tests/cases/compiler/test1").T<{ a: string; }>
>theme : any
>theme : error
>null as any : any
>null : null

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
=== tests/cases/compiler/importedModuleClassNameClash.ts ===
import foo = m1;
>foo : typeof foo
>m1 : any
>m1 : error

export module m1 { }

Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/indexingTypesWithNever.types
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ declare function genericFn3<

// Should be never
const result5 = genericFn3({ g: "gtest", h: "htest" }, "g", "h"); // 'g' & 'h' will reduce to never
>result5 : any
>genericFn3({ g: "gtest", h: "htest" }, "g", "h") : any
>result5 : error
>genericFn3({ g: "gtest", h: "htest" }, "g", "h") : error
>genericFn3 : <T extends { [K in keyof T]: T[K]; }, U extends keyof T, V extends keyof T>(obj: T, u: U, v: V) => T[U & V]
>{ g: "gtest", h: "htest" } : { g: string; h: string; }
>g : string
Expand Down
16 changes: 8 additions & 8 deletions tests/baselines/reference/inlineJsxFactoryDeclarations.types
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import * as React from "./renderer";
>React : typeof React

<h></h>
><h></h> : any
><h></h> : error
>h : any
>h : any

Expand All @@ -39,8 +39,8 @@ import { dom as h } from "./renderer"
>h : () => void

export const prerendered = <h></h>;
>prerendered : any
><h></h> : any
>prerendered : error
><h></h> : error
>h : () => void
>h : () => void

Expand All @@ -50,8 +50,8 @@ import { otherdom } from "./renderer"
>otherdom : () => void

export const prerendered2 = <h></h>;
>prerendered2 : any
><h></h> : any
>prerendered2 : error
><h></h> : error
>h : any
>h : any

Expand All @@ -60,8 +60,8 @@ import React from "./renderer"
>React : () => void

export const prerendered3 = <h></h>;
>prerendered3 : any
><h></h> : any
>prerendered3 : error
><h></h> : error
>h : any
>h : any

Expand All @@ -71,7 +71,7 @@ import { dom } from "./renderer"
>dom : () => void

<h></h>
><h></h> : any
><h></h> : error
>h : any
>h : any

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {dom} from "./renderer";
>dom : () => void

<h></h>
><h></h> : any
><h></h> : error
>h : any
>h : any

Expand All @@ -31,7 +31,7 @@ import { p } from "./renderer";
>p : () => void

<h></h>
><h></h> : any
><h></h> : error
>h : any
>h : any

Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ module B {

import Y = A;
>Y : any
>A : any
>A : error
}

Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module.exports = function () {
c: A.b = 1,
>c : number
>A.b = 1 : 1
>A.b : any
>A.b : error
>A : typeof A
>b : any
>1 : 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ export class StackOverflowTest {

constructor () {
this.testStackOverflow = this.testStackOverflow.bind(this)
>this.testStackOverflow = this.testStackOverflow.bind(this) : any
>this.testStackOverflow = this.testStackOverflow.bind(this) : error
>this.testStackOverflow : any
>this : this
>testStackOverflow : any
>this.testStackOverflow.bind(this) : any
>this.testStackOverflow.bind(this) : error
>this.testStackOverflow.bind : any
>this.testStackOverflow : any
>this : this
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
=== tests/cases/compiler/a.js ===
@internal class C { }
>internal : any
>internal : error
>C : C

Loading