mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-22 12:03:44 -05:00
Merge branch 'master' into restrictUseOfSys
This commit is contained in:
@@ -906,7 +906,7 @@ module ts {
|
||||
// Get qualified name
|
||||
if (enclosingDeclaration &&
|
||||
// Properties/methods/Signatures/Constructors/TypeParameters do not need qualification
|
||||
!(symbol.flags & SymbolFlags.PropertyOrAccessor & SymbolFlags.Signature & SymbolFlags.Constructor & SymbolFlags.Method & SymbolFlags.TypeParameter)) {
|
||||
!(symbol.flags & (SymbolFlags.PropertyOrAccessor | SymbolFlags.Signature | SymbolFlags.Constructor | SymbolFlags.Method | SymbolFlags.TypeParameter))) {
|
||||
var symbolName: string;
|
||||
while (symbol) {
|
||||
var isFirstName = !symbolName;
|
||||
@@ -2236,13 +2236,12 @@ module ts {
|
||||
return emptyObjectType;
|
||||
}
|
||||
var type = getDeclaredTypeOfSymbol(symbol);
|
||||
var name = symbol.name;
|
||||
if (!(type.flags & TypeFlags.ObjectType)) {
|
||||
error(getTypeDeclaration(symbol), Diagnostics.Global_type_0_must_be_a_class_or_interface_type, name);
|
||||
error(getTypeDeclaration(symbol), Diagnostics.Global_type_0_must_be_a_class_or_interface_type, symbol.name);
|
||||
return emptyObjectType;
|
||||
}
|
||||
if (((<InterfaceType>type).typeParameters ? (<InterfaceType>type).typeParameters.length : 0) !== arity) {
|
||||
error(getTypeDeclaration(symbol), Diagnostics.Global_type_0_must_have_1_type_parameter_s, name, arity);
|
||||
error(getTypeDeclaration(symbol), Diagnostics.Global_type_0_must_have_1_type_parameter_s, symbol.name, arity);
|
||||
return emptyObjectType;
|
||||
}
|
||||
return <ObjectType>type;
|
||||
@@ -3545,7 +3544,8 @@ module ts {
|
||||
return false;
|
||||
}
|
||||
|
||||
function checkSuperExpression(node: Node, isCallExpression: boolean): Type {
|
||||
function checkSuperExpression(node: Node): Type {
|
||||
var isCallExpression = node.parent.kind === SyntaxKind.CallExpression && (<CallExpression>node.parent).func === node;
|
||||
var enclosingClass = <ClassDeclaration>getAncestor(node, SyntaxKind.ClassDeclaration);
|
||||
var baseClass: Type;
|
||||
if (enclosingClass && enclosingClass.baseType) {
|
||||
@@ -4179,7 +4179,7 @@ module ts {
|
||||
|
||||
function resolveCallExpression(node: CallExpression): Signature {
|
||||
if (node.func.kind === SyntaxKind.SuperKeyword) {
|
||||
var superType = checkSuperExpression(node.func, true);
|
||||
var superType = checkSuperExpression(node.func);
|
||||
if (superType !== unknownType) {
|
||||
return resolveCall(node, getSignaturesOfType(superType, SignatureKind.Construct));
|
||||
}
|
||||
@@ -4827,7 +4827,7 @@ module ts {
|
||||
case SyntaxKind.ThisKeyword:
|
||||
return checkThisExpression(node);
|
||||
case SyntaxKind.SuperKeyword:
|
||||
return checkSuperExpression(node, false);
|
||||
return checkSuperExpression(node);
|
||||
case SyntaxKind.NullKeyword:
|
||||
return nullType;
|
||||
case SyntaxKind.TrueKeyword:
|
||||
@@ -6681,6 +6681,7 @@ module ts {
|
||||
case SyntaxKind.Parameter:
|
||||
case SyntaxKind.Property:
|
||||
case SyntaxKind.EnumMember:
|
||||
case SyntaxKind.PropertyAssignment:
|
||||
return (<VariableDeclaration>parent).initializer === node;
|
||||
case SyntaxKind.ExpressionStatement:
|
||||
case SyntaxKind.IfStatement:
|
||||
@@ -6810,6 +6811,11 @@ module ts {
|
||||
/*all meanings*/ SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace | SymbolFlags.Import);
|
||||
}
|
||||
|
||||
if (isInRightSideOfImportOrExportAssignment(entityName)) {
|
||||
// Since we already checked for ExportAssignment, this really could only be an Import
|
||||
return getSymbolOfPartOfRightHandSideOfImport(entityName);
|
||||
}
|
||||
|
||||
if (isRightSideOfQualifiedNameOrPropertyAccess(entityName)) {
|
||||
entityName = entityName.parent;
|
||||
}
|
||||
@@ -6920,11 +6926,7 @@ module ts {
|
||||
}
|
||||
|
||||
if (isInRightSideOfImportOrExportAssignment(node)) {
|
||||
var symbol: Symbol;
|
||||
symbol = node.parent.kind === SyntaxKind.ExportAssignment
|
||||
? getSymbolInfo(node)
|
||||
: getSymbolOfPartOfRightHandSideOfImport(node);
|
||||
|
||||
var symbol = getSymbolInfo(node);
|
||||
var declaredType = getDeclaredTypeOfSymbol(symbol);
|
||||
return declaredType !== unknownType ? declaredType : getTypeOfSymbol(symbol);
|
||||
}
|
||||
@@ -7094,7 +7096,20 @@ module ts {
|
||||
function isImplementationOfOverload(node: FunctionDeclaration) {
|
||||
if (node.body) {
|
||||
var symbol = getSymbolOfNode(node);
|
||||
return getSignaturesOfSymbol(symbol).length > 1;
|
||||
var signaturesOfSymbol = getSignaturesOfSymbol(symbol);
|
||||
// If this function body corresponds to function with multiple signature, it is implementation of overload
|
||||
// eg: function foo(a: string): string;
|
||||
// function foo(a: number): number;
|
||||
// function foo(a: any) { // This is implementation of the overloads
|
||||
// return a;
|
||||
// }
|
||||
return signaturesOfSymbol.length > 1 ||
|
||||
// If there is single signature for the symbol, it is overload if that signature isnt coming from the node
|
||||
// eg: function foo(a: string): string;
|
||||
// function foo(a: any) { // This is implementation of the overloads
|
||||
// return a;
|
||||
// }
|
||||
(signaturesOfSymbol.length === 1 && signaturesOfSymbol[0].declaration !== node);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -41,16 +41,16 @@ class CompilerBaselineRunner extends RunnerBase {
|
||||
describe('compiler tests for ' + fileName, () => {
|
||||
// Mocha holds onto the closure environment of the describe callback even after the test is done.
|
||||
// Everything declared here should be cleared out in the "after" callback.
|
||||
var justName = fileName.replace(/^.*[\\\/]/, ''); // strips the fileName from the path.
|
||||
var content = Harness.IO.readFile(fileName);
|
||||
var testCaseContent = Harness.TestCaseParser.makeUnitsFromTest(content, fileName);
|
||||
var justName: string;
|
||||
var content: string;
|
||||
var testCaseContent: { settings: Harness.TestCaseParser.CompilerSetting[]; testUnitData: Harness.TestCaseParser.TestUnitData[]; }
|
||||
|
||||
var units = testCaseContent.testUnitData;
|
||||
var tcSettings = testCaseContent.settings;
|
||||
var createNewInstance = false;
|
||||
var units: Harness.TestCaseParser.TestUnitData[];
|
||||
var tcSettings: Harness.TestCaseParser.CompilerSetting[];
|
||||
var createNewInstance: boolean;
|
||||
|
||||
var lastUnit = units[units.length - 1];
|
||||
var rootDir = lastUnit.originalFilePath.indexOf('conformance') === -1 ? 'tests/cases/compiler/' : lastUnit.originalFilePath.substring(0, lastUnit.originalFilePath.lastIndexOf('/')) + '/';
|
||||
var lastUnit: Harness.TestCaseParser.TestUnitData;
|
||||
var rootDir: string;
|
||||
|
||||
var result: Harness.Compiler.CompilerResult;
|
||||
var checker: ts.TypeChecker;
|
||||
@@ -68,6 +68,14 @@ class CompilerBaselineRunner extends RunnerBase {
|
||||
var createNewInstance = false;
|
||||
|
||||
before(() => {
|
||||
justName = fileName.replace(/^.*[\\\/]/, ''); // strips the fileName from the path.
|
||||
content = Harness.IO.readFile(fileName);
|
||||
testCaseContent = Harness.TestCaseParser.makeUnitsFromTest(content, fileName);
|
||||
units = testCaseContent.testUnitData;
|
||||
tcSettings = testCaseContent.settings;
|
||||
createNewInstance = false;
|
||||
lastUnit = units[units.length - 1];
|
||||
rootDir = lastUnit.originalFilePath.indexOf('conformance') === -1 ? 'tests/cases/compiler/' : lastUnit.originalFilePath.substring(0, lastUnit.originalFilePath.lastIndexOf('/')) + '/';
|
||||
harnessCompiler = Harness.Compiler.getCompiler();
|
||||
// We need to assemble the list of input files for the compiler and other related files on the 'filesystem' (ie in a multi-file test)
|
||||
// If the last file in a test uses require or a triple slash reference we'll assume all other files will be brought in via references,
|
||||
@@ -307,7 +315,7 @@ class CompilerBaselineRunner extends RunnerBase {
|
||||
allFiles.forEach(file => {
|
||||
var codeLines = file.content.split('\n');
|
||||
walker.getTypes(file.unitName).forEach(result => {
|
||||
var formattedLine = result.identifierName + " : " + result.type;
|
||||
var formattedLine = result.sourceText.replace(/\r?\n/g, "") + " : " + result.type;
|
||||
if (!typeMap[file.unitName]) {
|
||||
typeMap[file.unitName] = {};
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ interface TypeWriterResult {
|
||||
line: number;
|
||||
column: number;
|
||||
syntaxKind: string;
|
||||
identifierName: string;
|
||||
sourceText: string;
|
||||
type: string;
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ class TypeWriterWalker {
|
||||
// TODO: Ideally we should log all expressions, but to compare to the
|
||||
// old typeWriter baselines, suppress tokens
|
||||
case ts.SyntaxKind.ThisKeyword:
|
||||
case ts.SyntaxKind.RegularExpressionLiteral:
|
||||
case ts.SyntaxKind.SuperKeyword:
|
||||
case ts.SyntaxKind.ArrayLiteral:
|
||||
case ts.SyntaxKind.ObjectLiteral:
|
||||
case ts.SyntaxKind.PropertyAccess:
|
||||
@@ -77,7 +77,6 @@ class TypeWriterWalker {
|
||||
var actualPos = ts.skipTrivia(this.currentSourceFile.text, node.pos);
|
||||
var lineAndCharacter = this.currentSourceFile.getLineAndCharacterFromPosition(actualPos);
|
||||
var sourceText = ts.getSourceTextOfNodeFromSourceText(this.currentSourceFile.text, node);
|
||||
var isUnknownType = (<ts.IntrinsicType>type).intrinsicName === "unknown";
|
||||
|
||||
// If we got an unknown type, we temporarily want to fall back to just pretending the name
|
||||
// (source text) of the node is the type. This is to align with the old typeWriter to make
|
||||
@@ -86,8 +85,8 @@ class TypeWriterWalker {
|
||||
line: lineAndCharacter.line - 1,
|
||||
column: lineAndCharacter.character,
|
||||
syntaxKind: ts.SyntaxKind[node.kind],
|
||||
identifierName: sourceText,
|
||||
type: isUnknownType ? sourceText : this.checker.typeToString(type)
|
||||
sourceText: sourceText,
|
||||
type: this.checker.typeToString(type, node.parent, ts.TypeFormatFlags.None)
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user