Merge remote-tracking branch 'upstream/master' into jsDoc2

This commit is contained in:
Ryan Cavanaugh
2016-01-06 13:51:45 -08:00
76 changed files with 1622 additions and 343 deletions
+2 -21
View File
@@ -8228,31 +8228,12 @@ namespace ts {
return jsxElementType || anyType;
}
function tagNamesAreEquivalent(lhs: EntityName, rhs: EntityName): boolean {
if (lhs.kind !== rhs.kind) {
return false;
}
if (lhs.kind === SyntaxKind.Identifier) {
return (<Identifier>lhs).text === (<Identifier>rhs).text;
}
return (<QualifiedName>lhs).right.text === (<QualifiedName>rhs).right.text &&
tagNamesAreEquivalent((<QualifiedName>lhs).left, (<QualifiedName>rhs).left);
}
function checkJsxElement(node: JsxElement) {
// Check attributes
checkJsxOpeningLikeElement(node.openingElement);
// Check that the closing tag matches
if (!tagNamesAreEquivalent(node.openingElement.tagName, node.closingElement.tagName)) {
error(node.closingElement, Diagnostics.Expected_corresponding_JSX_closing_tag_for_0, getTextOfNode(node.openingElement.tagName));
}
else {
// Perform resolution on the closing tag so that rename/go to definition/etc work
getJsxElementTagSymbol(node.closingElement);
}
// Perform resolution on the closing tag so that rename/go to definition/etc work
getJsxElementTagSymbol(node.closingElement);
// Check children
for (const child of node.children) {
+4
View File
@@ -2586,5 +2586,9 @@
"A type assertion expression is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses.": {
"category": "Error",
"code": 17007
},
"JSX element '{0}' has no corresponding closing tag.": {
"category": "Error",
"code": 17008
}
}
+1 -1
View File
@@ -6990,7 +6990,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
write(text);
}
write(`], function(${exportFunctionForFile}, __moduleName) {`);
write(`], function(${exportFunctionForFile}) {`);
writeLine();
increaseIndent();
const startIndex = emitDirectivePrologues(node.statements, /*startWithNewLine*/ true, /*ensureUseStrict*/ true);
+23 -1
View File
@@ -3478,6 +3478,20 @@ namespace ts {
return finishNode(node);
}
function tagNamesAreEquivalent(lhs: EntityName, rhs: EntityName): boolean {
if (lhs.kind !== rhs.kind) {
return false;
}
if (lhs.kind === SyntaxKind.Identifier) {
return (<Identifier>lhs).text === (<Identifier>rhs).text;
}
return (<QualifiedName>lhs).right.text === (<QualifiedName>rhs).right.text &&
tagNamesAreEquivalent((<QualifiedName>lhs).left, (<QualifiedName>rhs).left);
}
function parseJsxElementOrSelfClosingElement(inExpressionContext: boolean): JsxElement | JsxSelfClosingElement {
const opening = parseJsxOpeningOrSelfClosingElement(inExpressionContext);
let result: JsxElement | JsxSelfClosingElement;
@@ -3487,6 +3501,11 @@ namespace ts {
node.children = parseJsxChildren(node.openingElement.tagName);
node.closingElement = parseJsxClosingElement(inExpressionContext);
if (!tagNamesAreEquivalent(node.openingElement.tagName, node.closingElement.tagName)) {
parseErrorAtPosition(node.closingElement.pos, node.closingElement.end - node.closingElement.pos, Diagnostics.Expected_corresponding_JSX_closing_tag_for_0, getTextOfNodeFromSourceText(sourceText, node.openingElement.tagName));
}
result = finishNode(node);
}
else {
@@ -3546,10 +3565,13 @@ namespace ts {
while (true) {
token = scanner.reScanJsxToken();
if (token === SyntaxKind.LessThanSlashToken) {
// Closing tag
break;
}
else if (token === SyntaxKind.EndOfFileToken) {
parseErrorAtCurrentToken(Diagnostics.Expected_corresponding_JSX_closing_tag_for_0, getTextOfNodeFromSourceText(sourceText, openingTagName));
// If we hit EOF, issue the error at the tag that lacks the closing element
// rather than at the end of the file (which is useless)
parseErrorAtPosition(openingTagName.pos, openingTagName.end - openingTagName.pos, Diagnostics.JSX_element_0_has_no_corresponding_closing_tag, getTextOfNodeFromSourceText(sourceText, openingTagName));
break;
}
result.push(parseJsxChild());
+25 -11
View File
@@ -53,13 +53,13 @@ namespace ts {
if (getRootLength(moduleName) !== 0 || nameStartsWithDotSlashOrDotDotSlash(moduleName)) {
const failedLookupLocations: string[] = [];
const candidate = normalizePath(combinePaths(containingDirectory, moduleName));
let resolvedFileName = loadNodeModuleFromFile(supportedExtensions, candidate, failedLookupLocations, host);
let resolvedFileName = loadNodeModuleFromFile(supportedExtensions, candidate, failedLookupLocations, /*onlyRecordFailures*/ false, host);
if (resolvedFileName) {
return { resolvedModule: { resolvedFileName }, failedLookupLocations };
}
resolvedFileName = loadNodeModuleFromDirectory(supportedExtensions, candidate, failedLookupLocations, host);
resolvedFileName = loadNodeModuleFromDirectory(supportedExtensions, candidate, failedLookupLocations, /*onlyRecordFailures*/ false, host);
return resolvedFileName
? { resolvedModule: { resolvedFileName }, failedLookupLocations }
: { resolvedModule: undefined, failedLookupLocations };
@@ -69,12 +69,22 @@ namespace ts {
}
}
function loadNodeModuleFromFile(extensions: string[], candidate: string, failedLookupLocation: string[], host: ModuleResolutionHost): string {
/* @internal */
export function directoryProbablyExists(directoryName: string, host: { directoryExists?: (directoryName: string) => boolean } ): boolean {
// if host does not support 'directoryExists' assume that directory will exist
return !host.directoryExists || host.directoryExists(directoryName);
}
/**
* @param {boolean} onlyRecordFailures - if true then function won't try to actually load files but instead record all attempts as failures. This flag is necessary
* 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 loadNodeModuleFromFile(extensions: string[], candidate: string, failedLookupLocation: string[], onlyRecordFailures: boolean, host: ModuleResolutionHost): string {
return forEach(extensions, tryLoad);
function tryLoad(ext: string): string {
const fileName = fileExtensionIs(candidate, ext) ? candidate : candidate + ext;
if (host.fileExists(fileName)) {
if (!onlyRecordFailures && host.fileExists(fileName)) {
return fileName;
}
else {
@@ -84,9 +94,10 @@ namespace ts {
}
}
function loadNodeModuleFromDirectory(extensions: string[], candidate: string, failedLookupLocation: string[], host: ModuleResolutionHost): string {
function loadNodeModuleFromDirectory(extensions: string[], candidate: string, failedLookupLocation: string[], onlyRecordFailures: boolean, host: ModuleResolutionHost): string {
const packageJsonPath = combinePaths(candidate, "package.json");
if (host.fileExists(packageJsonPath)) {
const directoryExists = !onlyRecordFailures && directoryProbablyExists(candidate, host);
if (directoryExists && host.fileExists(packageJsonPath)) {
let jsonContent: { typings?: string };
@@ -100,7 +111,8 @@ namespace ts {
}
if (typeof jsonContent.typings === "string") {
const result = loadNodeModuleFromFile(extensions, normalizePath(combinePaths(candidate, jsonContent.typings)), failedLookupLocation, host);
const path = normalizePath(combinePaths(candidate, jsonContent.typings));
const result = loadNodeModuleFromFile(extensions, path, failedLookupLocation, !directoryProbablyExists(getDirectoryPath(path), host), host);
if (result) {
return result;
}
@@ -111,7 +123,7 @@ namespace ts {
failedLookupLocation.push(packageJsonPath);
}
return loadNodeModuleFromFile(extensions, combinePaths(candidate, "index"), failedLookupLocation, host);
return loadNodeModuleFromFile(extensions, combinePaths(candidate, "index"), failedLookupLocation, !directoryExists, host);
}
function loadModuleFromNodeModules(moduleName: string, directory: string, host: ModuleResolutionHost): ResolvedModuleWithFailedLookupLocations {
@@ -121,14 +133,15 @@ namespace ts {
const baseName = getBaseFileName(directory);
if (baseName !== "node_modules") {
const nodeModulesFolder = combinePaths(directory, "node_modules");
const nodeModulesFolderExists = directoryProbablyExists(nodeModulesFolder, host);
const candidate = normalizePath(combinePaths(nodeModulesFolder, moduleName));
// Load only typescript files irrespective of allowJs option if loading from node modules
let result = loadNodeModuleFromFile(supportedTypeScriptExtensions, candidate, failedLookupLocations, host);
let result = loadNodeModuleFromFile(supportedTypeScriptExtensions, candidate, failedLookupLocations, !nodeModulesFolderExists, host);
if (result) {
return { resolvedModule: { resolvedFileName: result, isExternalLibraryImport: true }, failedLookupLocations };
}
result = loadNodeModuleFromDirectory(supportedTypeScriptExtensions, candidate, failedLookupLocations, host);
result = loadNodeModuleFromDirectory(supportedTypeScriptExtensions, candidate, failedLookupLocations, !nodeModulesFolderExists, host);
if (result) {
return { resolvedModule: { resolvedFileName: result, isExternalLibraryImport: true }, failedLookupLocations };
}
@@ -281,7 +294,8 @@ namespace ts {
getCanonicalFileName,
getNewLine: () => newLine,
fileExists: fileName => sys.fileExists(fileName),
readFile: fileName => sys.readFile(fileName)
readFile: fileName => sys.readFile(fileName),
directoryExists: directoryName => sys.directoryExists(directoryName)
};
}
+2
View File
@@ -2649,6 +2649,8 @@ namespace ts {
// readFile function is used to read arbitrary text files on disk, i.e. when resolution procedure needs the content of 'package.json'
// to determine location of bundled typings for node module
readFile(fileName: string): string;
directoryExists?(directoryName: string): boolean;
}
export interface ResolvedModule {
+4
View File
@@ -267,6 +267,10 @@ namespace Harness.LanguageService {
log(s: string): void { this.nativeHost.log(s); }
trace(s: string): void { this.nativeHost.trace(s); }
error(s: string): void { this.nativeHost.error(s); }
directoryExists(directoryName: string): boolean {
// for tests pessimistically assume that directory always exists
return true;
}
}
class ClassifierShimProxy implements ts.Classifier {
+5 -2
View File
@@ -321,6 +321,7 @@ interface AudioContext extends EventTarget {
destination: AudioDestinationNode;
listener: AudioListener;
sampleRate: number;
state: string;
createAnalyser(): AnalyserNode;
createBiquadFilter(): BiquadFilterNode;
createBuffer(numberOfChannels: number, length: number, sampleRate: number): AudioBuffer;
@@ -2774,6 +2775,7 @@ interface Element extends Node, GlobalEventHandlers, ElementTraversal, NodeSelec
tagName: string;
id: string;
className: string;
innerHTML: string;
getAttribute(name?: string): string;
getAttributeNS(namespaceURI: string, localName: string): string;
getAttributeNode(name: string): Attr;
@@ -2969,7 +2971,7 @@ interface Element extends Node, GlobalEventHandlers, ElementTraversal, NodeSelec
removeAttributeNode(oldAttr: Attr): Attr;
requestFullscreen(): void;
requestPointerLock(): void;
setAttribute(name?: string, value?: string): void;
setAttribute(name: string, value: string): void;
setAttributeNS(namespaceURI: string, qualifiedName: string, value: string): void;
setAttributeNode(newAttr: Attr): Attr;
setAttributeNodeNS(newAttr: Attr): Attr;
@@ -5512,7 +5514,7 @@ interface HTMLMediaElement extends HTMLElement {
* Gets or sets the current playback position, in seconds.
*/
preload: string;
readyState: any;
readyState: number;
/**
* Returns a TimeRanges object that represents the ranges of the current media resource that can be seeked.
*/
@@ -6169,6 +6171,7 @@ interface HTMLSelectElement extends HTMLElement {
* Returns whether an element will successfully validate based on forms validation rules and constraints.
*/
willValidate: boolean;
selectedOptions: HTMLCollection;
/**
* Adds an element to the areas, controlRange, or options collection.
* @param element Variant of type Number that specifies the index position in the collection where the element is placed. If no value is given, the method places the element at the end of the collection.
+20 -11
View File
@@ -7,7 +7,7 @@ interface Symbol {
/** Returns the primitive value of the specified object. */
valueOf(): Object;
[Symbol.toStringTag]: string;
[Symbol.toStringTag]: "Symbol";
}
interface SymbolConstructor {
@@ -565,7 +565,7 @@ interface IterableIterator<T> extends Iterator<T> {
}
interface GeneratorFunction extends Function {
[Symbol.toStringTag]: "GeneratorFunction";
}
interface GeneratorFunctionConstructor {
@@ -690,7 +690,7 @@ interface Math {
*/
cbrt(x: number): number;
[Symbol.toStringTag]: string;
[Symbol.toStringTag]: "Math";
}
interface Date {
@@ -807,7 +807,7 @@ interface Map<K, V> {
size: number;
values(): IterableIterator<V>;
[Symbol.iterator]():IterableIterator<[K,V]>;
[Symbol.toStringTag]: string;
[Symbol.toStringTag]: "Map";
}
interface MapConstructor {
@@ -824,7 +824,7 @@ interface WeakMap<K, V> {
get(key: K): V;
has(key: K): boolean;
set(key: K, value?: V): WeakMap<K, V>;
[Symbol.toStringTag]: string;
[Symbol.toStringTag]: "WeakMap";
}
interface WeakMapConstructor {
@@ -846,7 +846,7 @@ interface Set<T> {
size: number;
values(): IterableIterator<T>;
[Symbol.iterator]():IterableIterator<T>;
[Symbol.toStringTag]: string;
[Symbol.toStringTag]: "Set";
}
interface SetConstructor {
@@ -862,7 +862,7 @@ interface WeakSet<T> {
clear(): void;
delete(value: T): boolean;
has(value: T): boolean;
[Symbol.toStringTag]: string;
[Symbol.toStringTag]: "WeakSet";
}
interface WeakSetConstructor {
@@ -874,7 +874,7 @@ interface WeakSetConstructor {
declare var WeakSet: WeakSetConstructor;
interface JSON {
[Symbol.toStringTag]: string;
[Symbol.toStringTag]: "JSON";
}
/**
@@ -884,11 +884,11 @@ interface JSON {
* buffer as needed.
*/
interface ArrayBuffer {
[Symbol.toStringTag]: string;
[Symbol.toStringTag]: "ArrayBuffer";
}
interface DataView {
[Symbol.toStringTag]: string;
[Symbol.toStringTag]: "DataView";
}
/**
@@ -909,6 +909,7 @@ interface Int8Array {
*/
values(): IterableIterator<number>;
[Symbol.iterator](): IterableIterator<number>;
[Symbol.toStringTag]: "Int8Array";
}
interface Int8ArrayConstructor {
@@ -941,6 +942,7 @@ interface Uint8Array {
*/
values(): IterableIterator<number>;
[Symbol.iterator](): IterableIterator<number>;
[Symbol.toStringTag]: "UInt8Array";
}
interface Uint8ArrayConstructor {
@@ -976,6 +978,7 @@ interface Uint8ClampedArray {
values(): IterableIterator<number>;
[Symbol.iterator](): IterableIterator<number>;
[Symbol.toStringTag]: "Uint8ClampedArray";
}
interface Uint8ClampedArrayConstructor {
@@ -1013,6 +1016,7 @@ interface Int16Array {
[Symbol.iterator](): IterableIterator<number>;
[Symbol.toStringTag]: "Int16Array";
}
interface Int16ArrayConstructor {
@@ -1045,6 +1049,7 @@ interface Uint16Array {
*/
values(): IterableIterator<number>;
[Symbol.iterator](): IterableIterator<number>;
[Symbol.toStringTag]: "Uint16Array";
}
interface Uint16ArrayConstructor {
@@ -1077,6 +1082,7 @@ interface Int32Array {
*/
values(): IterableIterator<number>;
[Symbol.iterator](): IterableIterator<number>;
[Symbol.toStringTag]: "Int32Array";
}
interface Int32ArrayConstructor {
@@ -1109,6 +1115,7 @@ interface Uint32Array {
*/
values(): IterableIterator<number>;
[Symbol.iterator](): IterableIterator<number>;
[Symbol.toStringTag]: "Uint32Array";
}
interface Uint32ArrayConstructor {
@@ -1141,6 +1148,7 @@ interface Float32Array {
*/
values(): IterableIterator<number>;
[Symbol.iterator](): IterableIterator<number>;
[Symbol.toStringTag]: "Float32Array";
}
interface Float32ArrayConstructor {
@@ -1173,6 +1181,7 @@ interface Float64Array {
*/
values(): IterableIterator<number>;
[Symbol.iterator](): IterableIterator<number>;
[Symbol.toStringTag]: "Float64Array";
}
interface Float64ArrayConstructor {
@@ -1249,7 +1258,7 @@ interface Promise<T> {
catch(onrejected?: (reason: any) => T | PromiseLike<T>): Promise<T>;
catch(onrejected?: (reason: any) => void): Promise<T>;
[Symbol.toStringTag]: string;
[Symbol.toStringTag]: "Promise";
}
interface PromiseConstructor {
+2 -1
View File
@@ -100,7 +100,8 @@ namespace ts.server {
this.filenameToScript = createFileMap<ScriptInfo>();
this.moduleResolutionHost = {
fileExists: fileName => this.fileExists(fileName),
readFile: fileName => this.host.readFile(fileName)
readFile: fileName => this.host.readFile(fileName),
directoryExists: directoryName => this.host.directoryExists(directoryName)
};
}
+7 -1
View File
@@ -1034,6 +1034,7 @@ namespace ts {
* host specific questions using 'getScriptSnapshot'.
*/
resolveModuleNames?(moduleNames: string[], containingFile: string): ResolvedModule[];
directoryExists?(directoryName: string): boolean;
}
//
@@ -1911,7 +1912,8 @@ namespace ts {
getCurrentDirectory: () => "",
getNewLine: () => newLine,
fileExists: (fileName): boolean => fileName === inputFileName,
readFile: (fileName): string => ""
readFile: (fileName): string => "",
directoryExists: directoryExists => true
};
const program = createProgram([inputFileName], options, compilerHost);
@@ -2768,6 +2770,10 @@ namespace ts {
// stub missing host functionality
const entry = hostCache.getOrCreateEntry(fileName);
return entry && entry.scriptSnapshot.getText(0, entry.scriptSnapshot.getLength());
},
directoryExists: directoryName => {
Debug.assert(!host.resolveModuleNames);
return directoryProbablyExists(directoryName, host);
}
};
+13 -3
View File
@@ -62,6 +62,7 @@ namespace ts {
useCaseSensitiveFileNames?(): boolean;
getModuleResolutionsForFile?(fileName: string): string;
directoryExists(directoryName: string): boolean;
}
/** Public interface of the the of a config service shim instance.*/
@@ -274,6 +275,7 @@ namespace ts {
private tracingEnabled = false;
public resolveModuleNames: (moduleName: string[], containingFile: string) => ResolvedModule[];
public directoryExists: (directoryName: string) => boolean;
constructor(private shimHost: LanguageServiceShimHost) {
// if shimHost is a COM object then property check will become method call with no arguments.
@@ -287,6 +289,9 @@ namespace ts {
});
};
}
if ("directoryExists" in this.shimHost) {
this.directoryExists = directoryName => this.shimHost.directoryExists(directoryName);
}
}
public log(s: string): void {
@@ -405,9 +410,14 @@ namespace ts {
}
}
export class CoreServicesShimHostAdapter implements ParseConfigHost {
export class CoreServicesShimHostAdapter implements ParseConfigHost, ModuleResolutionHost {
public directoryExists: (directoryName: string) => boolean;
constructor(private shimHost: CoreServicesShimHost) {
if ("directoryExists" in this.shimHost) {
this.directoryExists = directoryName => this.shimHost.directoryExists(directoryName);
}
}
public readDirectory(rootDir: string, extension: string, exclude: string[]): string[] {
@@ -424,11 +434,11 @@ namespace ts {
}
return JSON.parse(encoded);
}
public fileExists(fileName: string): boolean {
return this.shimHost.fileExists(fileName);
}
public readFile(fileName: string): string {
return this.shimHost.readFile(fileName);
}